Skip to content

Commit

Permalink
Kitura/Kitura#33 Added tests sending binary and text messages with a …
Browse files Browse the repository at this point in the history
…length that fits in one byte, two bytes, or eight bytes
  • Loading branch information
shmuelk committed Dec 21, 2016
1 parent c0775c4 commit 6d57539
Showing 1 changed file with 103 additions and 1 deletion.
104 changes: 103 additions & 1 deletion Tests/KituraWebSocketTests/BasicTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,16 @@ class BasicTests: XCTestCase {

static var allTests: [(String, (BasicTests) -> () throws -> Void)] {
return [
("testBinaryLongMessage", testBinaryLongMessage),
("testBinaryMediumMessage", testBinaryMediumMessage),
("testBinaryShortMessage", testBinaryShortMessage),
("testGracefullClose", testGracefullClose),
("testPing", testPing),
("testPingWithText", testPingWithText),
("testSuccessfullUpgrade", testSuccessfullUpgrade)
("testSuccessfullUpgrade", testSuccessfullUpgrade),
("testTextLongMessage", testTextLongMessage),
("testTextMediumMessage", testTextMediumMessage),
("testTextShortMessage", testTextShortMessage)
]
}

Expand All @@ -42,6 +48,55 @@ class BasicTests: XCTestCase {
doTearDown()
}

func testBinaryLongMessage() {
register(closeReason: .noReasonCodeSent)

performServerTest() { expectation in

var bytes = [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e]
let binaryPayload = NSMutableData(bytes: &bytes, length: bytes.count)
repeat {
binaryPayload.append(binaryPayload.bytes, length: binaryPayload.length)
} while binaryPayload.length < 100000
binaryPayload.append(&bytes, length: bytes.count)

self.performTest(framesToSend: [(true, self.opcodeBinary, binaryPayload)],
expectedFrames: [(true, self.opcodeBinary, binaryPayload)],
expectation: expectation)
}
}

func testBinaryMediumMessage() {
register(closeReason: .noReasonCodeSent)

performServerTest() { expectation in

var bytes = [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e]
let binaryPayload = NSMutableData(bytes: &bytes, length: bytes.count)
repeat {
binaryPayload.append(binaryPayload.bytes, length: binaryPayload.length)
} while binaryPayload.length < 1000

self.performTest(framesToSend: [(true, self.opcodeBinary, binaryPayload)],
expectedFrames: [(true, self.opcodeBinary, binaryPayload)],
expectation: expectation)
}
}

func testBinaryShortMessage() {
register(closeReason: .noReasonCodeSent)

performServerTest() { expectation in

var bytes = [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e]
let binaryPayload = NSMutableData(bytes: &bytes, length: bytes.count)

self.performTest(framesToSend: [(true, self.opcodeBinary, binaryPayload)],
expectedFrames: [(true, self.opcodeBinary, binaryPayload)],
expectation: expectation)
}
}

func testGracefullClose() {
register(closeReason: .normal)

Expand Down Expand Up @@ -107,4 +162,51 @@ class BasicTests: XCTestCase {
expectation.fulfill()
}
}

func testTextLongMessage() {
register(closeReason: .noReasonCodeSent)

performServerTest() { expectation in

var text = "Testing, testing 1, 2, 3."
repeat {
text += " " + text
} while text.characters.count < 100000
let textPayload = self.payload(text: text)

self.performTest(framesToSend: [(true, self.opcodeText, textPayload)],
expectedFrames: [(true, self.opcodeText, textPayload)],
expectation: expectation)
}
}

func testTextMediumMessage() {
register(closeReason: .noReasonCodeSent)

performServerTest() { expectation in

var text = ""
repeat {
text += "Testing, testing 1,2,3. "
} while text.characters.count < 1000
let textPayload = self.payload(text: text)

self.performTest(framesToSend: [(true, self.opcodeText, textPayload)],
expectedFrames: [(true, self.opcodeText, textPayload)],
expectation: expectation)
}
}

func testTextShortMessage() {
register(closeReason: .noReasonCodeSent)

performServerTest() { expectation in

let textPayload = self.payload(text: "Testing, testing 1,2,3")

self.performTest(framesToSend: [(true, self.opcodeText, textPayload)],
expectedFrames: [(true, self.opcodeText, textPayload)],
expectation: expectation)
}
}
}

0 comments on commit 6d57539

Please sign in to comment.