change tests to socketpacket tests
This commit is contained in:
parent
4c7a09cc8e
commit
aaefdd0a2e
@ -53,6 +53,8 @@
|
|||||||
7472A5EC1BB6ECE800CD4F59 /* SocketTypes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF861B51F254004FF46E /* SocketTypes.swift */; };
|
7472A5EC1BB6ECE800CD4F59 /* SocketTypes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF861B51F254004FF46E /* SocketTypes.swift */; };
|
||||||
7472A5ED1BB6ECE800CD4F59 /* SwiftRegex.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF871B51F254004FF46E /* SwiftRegex.swift */; };
|
7472A5ED1BB6ECE800CD4F59 /* SwiftRegex.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF871B51F254004FF46E /* SwiftRegex.swift */; };
|
||||||
7472A5EE1BB6ECE800CD4F59 /* WebSocket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF881B51F254004FF46E /* WebSocket.swift */; };
|
7472A5EE1BB6ECE800CD4F59 /* WebSocket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF881B51F254004FF46E /* WebSocket.swift */; };
|
||||||
|
7472C65C1BCAB53E003CA70D /* SocketNamespaceEmitTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7472C65B1BCAB53E003CA70D /* SocketNamespaceEmitTest.swift */; settings = {ASSET_TAGS = (); }; };
|
||||||
|
7472C65D1BCAB53E003CA70D /* SocketNamespaceEmitTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7472C65B1BCAB53E003CA70D /* SocketNamespaceEmitTest.swift */; settings = {ASSET_TAGS = (); }; };
|
||||||
74781D5A1B7E83930042CACA /* SocketIOClientStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74781D591B7E83930042CACA /* SocketIOClientStatus.swift */; };
|
74781D5A1B7E83930042CACA /* SocketIOClientStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74781D591B7E83930042CACA /* SocketIOClientStatus.swift */; };
|
||||||
74781D5B1B7E83930042CACA /* SocketIOClientStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74781D591B7E83930042CACA /* SocketIOClientStatus.swift */; };
|
74781D5B1B7E83930042CACA /* SocketIOClientStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74781D591B7E83930042CACA /* SocketIOClientStatus.swift */; };
|
||||||
74781D5C1B7E83930042CACA /* SocketIOClientStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74781D591B7E83930042CACA /* SocketIOClientStatus.swift */; };
|
74781D5C1B7E83930042CACA /* SocketIOClientStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74781D591B7E83930042CACA /* SocketIOClientStatus.swift */; };
|
||||||
@ -74,8 +76,8 @@
|
|||||||
74F124EB1BC56BFC002966F4 /* SocketEnginePacketType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74F124E71BC56BFC002966F4 /* SocketEnginePacketType.swift */; settings = {ASSET_TAGS = (); }; };
|
74F124EB1BC56BFC002966F4 /* SocketEnginePacketType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74F124E71BC56BFC002966F4 /* SocketEnginePacketType.swift */; settings = {ASSET_TAGS = (); }; };
|
||||||
74F124ED1BC572A8002966F4 /* SocketTestEngine.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74F124EC1BC572A8002966F4 /* SocketTestEngine.swift */; settings = {ASSET_TAGS = (); }; };
|
74F124ED1BC572A8002966F4 /* SocketTestEngine.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74F124EC1BC572A8002966F4 /* SocketTestEngine.swift */; settings = {ASSET_TAGS = (); }; };
|
||||||
74F124EE1BC572A8002966F4 /* SocketTestEngine.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74F124EC1BC572A8002966F4 /* SocketTestEngine.swift */; settings = {ASSET_TAGS = (); }; };
|
74F124EE1BC572A8002966F4 /* SocketTestEngine.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74F124EC1BC572A8002966F4 /* SocketTestEngine.swift */; settings = {ASSET_TAGS = (); }; };
|
||||||
74F124F01BC574CF002966F4 /* SocketBasicEmitTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74F124EF1BC574CF002966F4 /* SocketBasicEmitTest.swift */; settings = {ASSET_TAGS = (); }; };
|
74F124F01BC574CF002966F4 /* SocketBasicPacketTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74F124EF1BC574CF002966F4 /* SocketBasicPacketTest.swift */; settings = {ASSET_TAGS = (); }; };
|
||||||
74F124F11BC574CF002966F4 /* SocketBasicEmitTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74F124EF1BC574CF002966F4 /* SocketBasicEmitTest.swift */; settings = {ASSET_TAGS = (); }; };
|
74F124F11BC574CF002966F4 /* SocketBasicPacketTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74F124EF1BC574CF002966F4 /* SocketBasicPacketTest.swift */; settings = {ASSET_TAGS = (); }; };
|
||||||
945B65351B5FCEEA0081E995 /* SocketAckManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF7C1B51F254004FF46E /* SocketAckManager.swift */; };
|
945B65351B5FCEEA0081E995 /* SocketAckManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF7C1B51F254004FF46E /* SocketAckManager.swift */; };
|
||||||
945B65361B5FCEEA0081E995 /* SocketAnyEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF7D1B51F254004FF46E /* SocketAnyEvent.swift */; };
|
945B65361B5FCEEA0081E995 /* SocketAnyEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF7D1B51F254004FF46E /* SocketAnyEvent.swift */; };
|
||||||
945B65371B5FCEEA0081E995 /* SocketEngine.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF7E1B51F254004FF46E /* SocketEngine.swift */; };
|
945B65371B5FCEEA0081E995 /* SocketEngine.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF7E1B51F254004FF46E /* SocketEngine.swift */; };
|
||||||
@ -134,13 +136,14 @@
|
|||||||
5764DF861B51F254004FF46E /* SocketTypes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SocketTypes.swift; path = SocketIOClientSwift/SocketTypes.swift; sourceTree = "<group>"; };
|
5764DF861B51F254004FF46E /* SocketTypes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SocketTypes.swift; path = SocketIOClientSwift/SocketTypes.swift; sourceTree = "<group>"; };
|
||||||
5764DF871B51F254004FF46E /* SwiftRegex.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SwiftRegex.swift; path = SocketIOClientSwift/SwiftRegex.swift; sourceTree = "<group>"; };
|
5764DF871B51F254004FF46E /* SwiftRegex.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SwiftRegex.swift; path = SocketIOClientSwift/SwiftRegex.swift; sourceTree = "<group>"; };
|
||||||
5764DF881B51F254004FF46E /* WebSocket.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = WebSocket.swift; path = SocketIOClientSwift/WebSocket.swift; sourceTree = "<group>"; };
|
5764DF881B51F254004FF46E /* WebSocket.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = WebSocket.swift; path = SocketIOClientSwift/WebSocket.swift; sourceTree = "<group>"; };
|
||||||
|
7472C65B1BCAB53E003CA70D /* SocketNamespaceEmitTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SocketNamespaceEmitTest.swift; sourceTree = "<group>"; };
|
||||||
74781D591B7E83930042CACA /* SocketIOClientStatus.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SocketIOClientStatus.swift; path = SocketIOClientSwift/SocketIOClientStatus.swift; sourceTree = "<group>"; };
|
74781D591B7E83930042CACA /* SocketIOClientStatus.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SocketIOClientStatus.swift; path = SocketIOClientSwift/SocketIOClientStatus.swift; sourceTree = "<group>"; };
|
||||||
749A7F8A1BA9D42D00782993 /* SocketAckEmitter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SocketAckEmitter.swift; path = SocketIOClientSwift/SocketAckEmitter.swift; sourceTree = "<group>"; };
|
749A7F8A1BA9D42D00782993 /* SocketAckEmitter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SocketAckEmitter.swift; path = SocketIOClientSwift/SocketAckEmitter.swift; sourceTree = "<group>"; };
|
||||||
74D765611B9F0D870028551C /* SocketStringReader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = SocketStringReader.swift; path = SocketIOClientSwift/SocketStringReader.swift; sourceTree = "<group>"; };
|
74D765611B9F0D870028551C /* SocketStringReader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = SocketStringReader.swift; path = SocketIOClientSwift/SocketStringReader.swift; sourceTree = "<group>"; };
|
||||||
74F124E21BC5697B002966F4 /* SocketEngineSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SocketEngineSpec.swift; path = SocketIOClientSwift/SocketEngineSpec.swift; sourceTree = "<group>"; };
|
74F124E21BC5697B002966F4 /* SocketEngineSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SocketEngineSpec.swift; path = SocketIOClientSwift/SocketEngineSpec.swift; sourceTree = "<group>"; };
|
||||||
74F124E71BC56BFC002966F4 /* SocketEnginePacketType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SocketEnginePacketType.swift; path = SocketIOClientSwift/SocketEnginePacketType.swift; sourceTree = "<group>"; };
|
74F124E71BC56BFC002966F4 /* SocketEnginePacketType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SocketEnginePacketType.swift; path = SocketIOClientSwift/SocketEnginePacketType.swift; sourceTree = "<group>"; };
|
||||||
74F124EC1BC572A8002966F4 /* SocketTestEngine.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SocketTestEngine.swift; sourceTree = "<group>"; };
|
74F124EC1BC572A8002966F4 /* SocketTestEngine.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SocketTestEngine.swift; sourceTree = "<group>"; };
|
||||||
74F124EF1BC574CF002966F4 /* SocketBasicEmitTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SocketBasicEmitTest.swift; sourceTree = "<group>"; };
|
74F124EF1BC574CF002966F4 /* SocketBasicPacketTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SocketBasicPacketTest.swift; sourceTree = "<group>"; };
|
||||||
949FAE8C1B9B94E600073BE9 /* SocketParserTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SocketParserTest.swift; path = "../SocketIO-iOSTests/SocketParserTest.swift"; sourceTree = "<group>"; };
|
949FAE8C1B9B94E600073BE9 /* SocketParserTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SocketParserTest.swift; path = "../SocketIO-iOSTests/SocketParserTest.swift"; sourceTree = "<group>"; };
|
||||||
94A20D601B99E22F00BF9E44 /* SocketAckManagerTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SocketAckManagerTest.swift; path = "../SocketIO-iOSTests/SocketAckManagerTest.swift"; sourceTree = "<group>"; };
|
94A20D601B99E22F00BF9E44 /* SocketAckManagerTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SocketAckManagerTest.swift; path = "../SocketIO-iOSTests/SocketAckManagerTest.swift"; sourceTree = "<group>"; };
|
||||||
/* End PBXFileReference section */
|
/* End PBXFileReference section */
|
||||||
@ -256,7 +259,8 @@
|
|||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
94A20D601B99E22F00BF9E44 /* SocketAckManagerTest.swift */,
|
94A20D601B99E22F00BF9E44 /* SocketAckManagerTest.swift */,
|
||||||
74F124EF1BC574CF002966F4 /* SocketBasicEmitTest.swift */,
|
74F124EF1BC574CF002966F4 /* SocketBasicPacketTest.swift */,
|
||||||
|
7472C65B1BCAB53E003CA70D /* SocketNamespaceEmitTest.swift */,
|
||||||
949FAE8C1B9B94E600073BE9 /* SocketParserTest.swift */,
|
949FAE8C1B9B94E600073BE9 /* SocketParserTest.swift */,
|
||||||
74F124EC1BC572A8002966F4 /* SocketTestEngine.swift */,
|
74F124EC1BC572A8002966F4 /* SocketTestEngine.swift */,
|
||||||
572EF2471B51F18A00EEBB58 /* Supporting Files */,
|
572EF2471B51F18A00EEBB58 /* Supporting Files */,
|
||||||
@ -513,8 +517,9 @@
|
|||||||
945B653F1B5FCEEA0081E995 /* SocketTypes.swift in Sources */,
|
945B653F1B5FCEEA0081E995 /* SocketTypes.swift in Sources */,
|
||||||
74781D5B1B7E83930042CACA /* SocketIOClientStatus.swift in Sources */,
|
74781D5B1B7E83930042CACA /* SocketIOClientStatus.swift in Sources */,
|
||||||
945B653B1B5FCEEA0081E995 /* SocketIOClient.swift in Sources */,
|
945B653B1B5FCEEA0081E995 /* SocketIOClient.swift in Sources */,
|
||||||
74F124F01BC574CF002966F4 /* SocketBasicEmitTest.swift in Sources */,
|
74F124F01BC574CF002966F4 /* SocketBasicPacketTest.swift in Sources */,
|
||||||
949FAE8D1B9B94E600073BE9 /* SocketParserTest.swift in Sources */,
|
949FAE8D1B9B94E600073BE9 /* SocketParserTest.swift in Sources */,
|
||||||
|
7472C65C1BCAB53E003CA70D /* SocketNamespaceEmitTest.swift in Sources */,
|
||||||
945B65411B5FCEEA0081E995 /* WebSocket.swift in Sources */,
|
945B65411B5FCEEA0081E995 /* WebSocket.swift in Sources */,
|
||||||
74F124E91BC56BFC002966F4 /* SocketEnginePacketType.swift in Sources */,
|
74F124E91BC56BFC002966F4 /* SocketEnginePacketType.swift in Sources */,
|
||||||
);
|
);
|
||||||
@ -567,8 +572,9 @@
|
|||||||
7472A5EE1BB6ECE800CD4F59 /* WebSocket.swift in Sources */,
|
7472A5EE1BB6ECE800CD4F59 /* WebSocket.swift in Sources */,
|
||||||
745895381BB59A0A0050ACC8 /* SocketAckManagerTest.swift in Sources */,
|
745895381BB59A0A0050ACC8 /* SocketAckManagerTest.swift in Sources */,
|
||||||
7458953D1BB59A0A0050ACC8 /* SocketParserTest.swift in Sources */,
|
7458953D1BB59A0A0050ACC8 /* SocketParserTest.swift in Sources */,
|
||||||
74F124F11BC574CF002966F4 /* SocketBasicEmitTest.swift in Sources */,
|
74F124F11BC574CF002966F4 /* SocketBasicPacketTest.swift in Sources */,
|
||||||
74F124EB1BC56BFC002966F4 /* SocketEnginePacketType.swift in Sources */,
|
74F124EB1BC56BFC002966F4 /* SocketEnginePacketType.swift in Sources */,
|
||||||
|
7472C65D1BCAB53E003CA70D /* SocketNamespaceEmitTest.swift in Sources */,
|
||||||
749A7F901BA9D42D00782993 /* SocketAckEmitter.swift in Sources */,
|
749A7F901BA9D42D00782993 /* SocketAckEmitter.swift in Sources */,
|
||||||
74781D5D1B7E83930042CACA /* SocketIOClientStatus.swift in Sources */,
|
74781D5D1B7E83930042CACA /* SocketIOClientStatus.swift in Sources */,
|
||||||
);
|
);
|
||||||
|
|||||||
@ -1,136 +0,0 @@
|
|||||||
//
|
|
||||||
// SocketBasicEmitTest.swift
|
|
||||||
// Socket.IO-Client-Swift
|
|
||||||
//
|
|
||||||
// Created by Erik Little on 10/7/15.
|
|
||||||
//
|
|
||||||
//
|
|
||||||
|
|
||||||
import XCTest
|
|
||||||
|
|
||||||
class SocketBasicEmitTest: XCTestCase {
|
|
||||||
var socket: SocketIOClient!
|
|
||||||
|
|
||||||
override func setUp() {
|
|
||||||
super.setUp()
|
|
||||||
socket = SocketIOClient(socketURL: "")
|
|
||||||
socket.setTestable()
|
|
||||||
}
|
|
||||||
|
|
||||||
override func tearDown() {
|
|
||||||
// Put teardown code here. This method is called after the invocation of each test method in the class.
|
|
||||||
super.tearDown()
|
|
||||||
}
|
|
||||||
|
|
||||||
func testEmpyEmit() {
|
|
||||||
let engine = SocketTestEngine(client: socket,
|
|
||||||
expectedSendString: "2[\"test\"]",
|
|
||||||
expectedNumberOfBinary: 0,
|
|
||||||
expectedBinary: nil)
|
|
||||||
socket.setTestEngine(engine)
|
|
||||||
socket.emitTest("test")
|
|
||||||
XCTAssert(engine.socketDidCorrectlyCreatePacket())
|
|
||||||
}
|
|
||||||
|
|
||||||
func testNullEmit() {
|
|
||||||
let engine = SocketTestEngine(client: socket,
|
|
||||||
expectedSendString: "2[\"test\",null]",
|
|
||||||
expectedNumberOfBinary: 0,
|
|
||||||
expectedBinary: nil)
|
|
||||||
socket.setTestEngine(engine)
|
|
||||||
socket.emitTest("test", NSNull())
|
|
||||||
XCTAssert(engine.socketDidCorrectlyCreatePacket())
|
|
||||||
}
|
|
||||||
|
|
||||||
func testStringEmit() {
|
|
||||||
let engine = SocketTestEngine(client: socket,
|
|
||||||
expectedSendString: "2[\"test\",\"foo bar\"]",
|
|
||||||
expectedNumberOfBinary: 0,
|
|
||||||
expectedBinary: nil)
|
|
||||||
socket.setTestEngine(engine)
|
|
||||||
socket.emitTest("test", "foo bar")
|
|
||||||
XCTAssert(engine.socketDidCorrectlyCreatePacket())
|
|
||||||
}
|
|
||||||
|
|
||||||
func testJSONEmit() {
|
|
||||||
let engine = SocketTestEngine(client: socket,
|
|
||||||
expectedSendString: "2[\"test\",{\"test\":\"hello\",\"hello\":1,\"foobar\":true,\"null\":null}]",
|
|
||||||
expectedNumberOfBinary: 0,
|
|
||||||
expectedBinary: nil)
|
|
||||||
socket.setTestEngine(engine)
|
|
||||||
socket.emitTest("test", ["foobar": true, "hello": 1, "test": "hello", "null": NSNull()])
|
|
||||||
XCTAssert(engine.socketDidCorrectlyCreatePacket())
|
|
||||||
}
|
|
||||||
|
|
||||||
func testArrayEmit() {
|
|
||||||
let engine = SocketTestEngine(client: socket,
|
|
||||||
expectedSendString: "2[\"test\",[\"hello\",1,{\"test\":\"test\"}]]",
|
|
||||||
expectedNumberOfBinary: 0,
|
|
||||||
expectedBinary: nil)
|
|
||||||
socket.setTestEngine(engine)
|
|
||||||
socket.emitTest("test", ["hello", 1, ["test": "test"]])
|
|
||||||
XCTAssert(engine.socketDidCorrectlyCreatePacket())
|
|
||||||
}
|
|
||||||
|
|
||||||
func testBinaryEmit() {
|
|
||||||
let data = "test".dataUsingEncoding(NSUTF8StringEncoding)!
|
|
||||||
let engine = SocketTestEngine(client: socket,
|
|
||||||
expectedSendString: "51-[\"test\",{\"num\":0,\"_placeholder\":true}]",
|
|
||||||
expectedNumberOfBinary: 1,
|
|
||||||
expectedBinary: [data])
|
|
||||||
socket.setTestEngine(engine)
|
|
||||||
socket.emitTest("test", data)
|
|
||||||
XCTAssert(engine.socketDidCorrectlyCreatePacket())
|
|
||||||
}
|
|
||||||
|
|
||||||
func testMultipleBinaryEmit() {
|
|
||||||
let data = "test".dataUsingEncoding(NSUTF8StringEncoding)!
|
|
||||||
let data2 = "test2".dataUsingEncoding(NSUTF8StringEncoding)!
|
|
||||||
let engine = SocketTestEngine(client: socket,
|
|
||||||
expectedSendString: "52-[\"test\",{\"data2\":{\"num\":0,\"_placeholder\":true},\"data1\":{\"num\":1,\"_placeholder\":true}}]",
|
|
||||||
expectedNumberOfBinary: 2,
|
|
||||||
expectedBinary: [data2, data])
|
|
||||||
socket.setTestEngine(engine)
|
|
||||||
socket.emitTest("test", ["data1": data, "data2": data2])
|
|
||||||
XCTAssert(engine.socketDidCorrectlyCreatePacket())
|
|
||||||
}
|
|
||||||
|
|
||||||
func testEmitWithAck() {
|
|
||||||
let engine = SocketTestEngine(client: socket,
|
|
||||||
expectedSendString: "20[\"test\"]",
|
|
||||||
expectedNumberOfBinary: 0,
|
|
||||||
expectedBinary: nil)
|
|
||||||
|
|
||||||
engine.expectation = expectationWithDescription("emitWithAck")
|
|
||||||
socket.setTestEngine(engine)
|
|
||||||
socket.emitWithAck("test")(timeoutAfter: 0) {data in
|
|
||||||
engine.socketDidCorrectlyCreatePacket()
|
|
||||||
}
|
|
||||||
|
|
||||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 10000), dispatch_get_main_queue()) {
|
|
||||||
self.socket.parseSocketMessage("30[]")
|
|
||||||
}
|
|
||||||
|
|
||||||
waitForExpectationsWithTimeout(2, handler: nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testEmitDataWithAck() {
|
|
||||||
let data = "test".dataUsingEncoding(NSUTF8StringEncoding)!
|
|
||||||
let engine = SocketTestEngine(client: socket,
|
|
||||||
expectedSendString: "51-0[\"test\",{\"num\":0,\"_placeholder\":true}]",
|
|
||||||
expectedNumberOfBinary: 1,
|
|
||||||
expectedBinary: [data])
|
|
||||||
|
|
||||||
engine.expectation = expectationWithDescription("emitWithAck")
|
|
||||||
socket.setTestEngine(engine)
|
|
||||||
socket.emitWithAck("test", data)(timeoutAfter: 0) {data in
|
|
||||||
engine.socketDidCorrectlyCreatePacket()
|
|
||||||
}
|
|
||||||
|
|
||||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 10000), dispatch_get_main_queue()) {
|
|
||||||
self.socket.parseSocketMessage("30[]")
|
|
||||||
}
|
|
||||||
|
|
||||||
waitForExpectationsWithTimeout(3, handler: nil)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
139
SocketIO-MacTests/SocketBasicPacketTest.swift
Normal file
139
SocketIO-MacTests/SocketBasicPacketTest.swift
Normal file
@ -0,0 +1,139 @@
|
|||||||
|
//
|
||||||
|
// SocketBasicPacketTest.swift
|
||||||
|
// Socket.IO-Client-Swift
|
||||||
|
//
|
||||||
|
// Created by Erik Little on 10/7/15.
|
||||||
|
//
|
||||||
|
//
|
||||||
|
|
||||||
|
import XCTest
|
||||||
|
|
||||||
|
class SocketBasicPacketTest: XCTestCase {
|
||||||
|
let data = "test".dataUsingEncoding(NSUTF8StringEncoding)!
|
||||||
|
let data2 = "test2".dataUsingEncoding(NSUTF8StringEncoding)!
|
||||||
|
|
||||||
|
func testEmpyEmit() {
|
||||||
|
let expectedSendString = "2[\"test\"]"
|
||||||
|
let sendData = ["test"]
|
||||||
|
let packet = SocketPacket.packetFromEmit(sendData, id: -1, nsp: "/", ack: false)
|
||||||
|
|
||||||
|
XCTAssertEqual(packet.packetString, expectedSendString)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testNullEmit() {
|
||||||
|
let expectedSendString = "2[\"test\",null]"
|
||||||
|
let sendData = ["test", NSNull()]
|
||||||
|
let packet = SocketPacket.packetFromEmit(sendData, id: -1, nsp: "/", ack: false)
|
||||||
|
|
||||||
|
XCTAssertEqual(packet.packetString, expectedSendString)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testStringEmit() {
|
||||||
|
let expectedSendString = "2[\"test\",\"foo bar\"]"
|
||||||
|
let sendData = ["test", "foo bar"]
|
||||||
|
let packet = SocketPacket.packetFromEmit(sendData, id: -1, nsp: "/", ack: false)
|
||||||
|
|
||||||
|
XCTAssertEqual(packet.packetString, expectedSendString)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testJSONEmit() {
|
||||||
|
let expectedSendString = "2[\"test\",{\"test\":\"hello\",\"hello\":1,\"foobar\":true,\"null\":null}]"
|
||||||
|
let sendData = ["test", ["foobar": true, "hello": 1, "test": "hello", "null": NSNull()]]
|
||||||
|
let packet = SocketPacket.packetFromEmit(sendData, id: -1, nsp: "/", ack: false)
|
||||||
|
|
||||||
|
XCTAssertEqual(packet.packetString, expectedSendString)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testArrayEmit() {
|
||||||
|
let expectedSendString = "2[\"test\",[\"hello\",1,{\"test\":\"test\"}]]"
|
||||||
|
let sendData = ["test", ["hello", 1, ["test": "test"]]]
|
||||||
|
let packet = SocketPacket.packetFromEmit(sendData, id: -1, nsp: "/", ack: false)
|
||||||
|
|
||||||
|
XCTAssertEqual(packet.packetString, expectedSendString)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testBinaryEmit() {
|
||||||
|
let expectedSendString = "51-[\"test\",{\"num\":0,\"_placeholder\":true}]"
|
||||||
|
let sendData = ["test", data]
|
||||||
|
let packet = SocketPacket.packetFromEmit(sendData, id: -1, nsp: "/", ack: false)
|
||||||
|
|
||||||
|
XCTAssertEqual(packet.packetString, expectedSendString)
|
||||||
|
XCTAssertEqual(packet.binary, [data])
|
||||||
|
}
|
||||||
|
|
||||||
|
func testMultipleBinaryEmit() {
|
||||||
|
let expectedSendString = "52-[\"test\",{\"data1\":{\"num\":0,\"_placeholder\":true},\"data2\":{\"num\":1,\"_placeholder\":true}}]"
|
||||||
|
let sendData = ["test", ["data1": data, "data2": data2]]
|
||||||
|
let packet = SocketPacket.packetFromEmit(sendData, id: -1, nsp: "/", ack: false)
|
||||||
|
|
||||||
|
XCTAssertEqual(packet.packetString, expectedSendString)
|
||||||
|
XCTAssertEqual(packet.binary, [data, data2])
|
||||||
|
}
|
||||||
|
|
||||||
|
func testEmitWithAck() {
|
||||||
|
let expectedSendString = "20[\"test\"]"
|
||||||
|
let sendData = ["test"]
|
||||||
|
let packet = SocketPacket.packetFromEmit(sendData, id: 0, nsp: "/", ack: false)
|
||||||
|
|
||||||
|
XCTAssertEqual(packet.packetString, expectedSendString)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testEmitDataWithAck() {
|
||||||
|
let expectedSendString = "51-0[\"test\",{\"num\":0,\"_placeholder\":true}]"
|
||||||
|
let sendData = ["test", data]
|
||||||
|
let packet = SocketPacket.packetFromEmit(sendData, id: 0, nsp: "/", ack: false)
|
||||||
|
|
||||||
|
XCTAssertEqual(packet.packetString, expectedSendString)
|
||||||
|
XCTAssertEqual(packet.binary, [data])
|
||||||
|
}
|
||||||
|
|
||||||
|
// Acks
|
||||||
|
func testEmptyAck() {
|
||||||
|
let expectedSendString = "30[]"
|
||||||
|
let packet = SocketPacket.packetFromEmit([], id: 0, nsp: "/", ack: true)
|
||||||
|
|
||||||
|
XCTAssertEqual(packet.packetString, expectedSendString)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testNullAck() {
|
||||||
|
let expectedSendString = "30[null]"
|
||||||
|
let sendData = [NSNull()]
|
||||||
|
let packet = SocketPacket.packetFromEmit(sendData, id: 0, nsp: "/", ack: true)
|
||||||
|
|
||||||
|
XCTAssertEqual(packet.packetString, expectedSendString)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testStringAck() {
|
||||||
|
let expectedSendString = "30[\"test\"]"
|
||||||
|
let sendData = ["test"]
|
||||||
|
let packet = SocketPacket.packetFromEmit(sendData, id: 0, nsp: "/", ack: true)
|
||||||
|
|
||||||
|
XCTAssertEqual(packet.packetString, expectedSendString)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testJSONAck() {
|
||||||
|
let expectedSendString = "30[{\"test\":\"hello\",\"hello\":1,\"foobar\":true,\"null\":null}]"
|
||||||
|
let sendData = [["foobar": true, "hello": 1, "test": "hello", "null": NSNull()]]
|
||||||
|
let packet = SocketPacket.packetFromEmit(sendData, id: 0, nsp: "/", ack: true)
|
||||||
|
|
||||||
|
XCTAssertEqual(packet.packetString, expectedSendString)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testBinaryAck() {
|
||||||
|
let expectedSendString = "61-0[{\"num\":0,\"_placeholder\":true}]"
|
||||||
|
let sendData = [data]
|
||||||
|
let packet = SocketPacket.packetFromEmit(sendData, id: 0, nsp: "/", ack: true)
|
||||||
|
|
||||||
|
XCTAssertEqual(packet.packetString, expectedSendString)
|
||||||
|
XCTAssertEqual(packet.binary, [data])
|
||||||
|
}
|
||||||
|
|
||||||
|
func testMultipleBinaryAck() {
|
||||||
|
let expectedSendString = "62-0[{\"data2\":{\"num\":0,\"_placeholder\":true},\"data1\":{\"num\":1,\"_placeholder\":true}}]"
|
||||||
|
let sendData = [["data1": data, "data2": data2]]
|
||||||
|
let packet = SocketPacket.packetFromEmit(sendData, id: 0, nsp: "/", ack: true)
|
||||||
|
|
||||||
|
XCTAssertEqual(packet.packetString, expectedSendString)
|
||||||
|
XCTAssertEqual(packet.binary, [data2, data])
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -80,6 +80,7 @@ class SocketTestEngine: NSObject, SocketEngineSpec {
|
|||||||
expectation?.fulfill()
|
expectation?.fulfill()
|
||||||
return true
|
return true
|
||||||
} else {
|
} else {
|
||||||
|
print(sendString)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -151,7 +151,7 @@ struct SocketPacket {
|
|||||||
if nsp == "/" {
|
if nsp == "/" {
|
||||||
msg = "6\(binary.count)-\(id)["
|
msg = "6\(binary.count)-\(id)["
|
||||||
} else {
|
} else {
|
||||||
msg = "6\(binary.count)-/\(nsp),\(id)["
|
msg = "6\(binary.count)-\(nsp),\(id)["
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user