basic test structure / tests

This commit is contained in:
Lukas Schmidt 2015-07-24 19:55:35 +02:00
parent 94a3844181
commit 224c660e4c
2 changed files with 71 additions and 9 deletions

View File

@ -39,6 +39,19 @@
5764DFA01B51F254004FF46E /* SwiftRegex.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF871B51F254004FF46E /* SwiftRegex.swift */; };
5764DFA11B51F254004FF46E /* WebSocket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF881B51F254004FF46E /* WebSocket.swift */; };
5764DFA21B51F254004FF46E /* WebSocket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF881B51F254004FF46E /* WebSocket.swift */; };
945B65351B5FCEEA0081E995 /* SocketAckManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF7C1B51F254004FF46E /* SocketAckManager.swift */; };
945B65361B5FCEEA0081E995 /* SocketAnyEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF7D1B51F254004FF46E /* SocketAnyEvent.swift */; };
945B65371B5FCEEA0081E995 /* SocketEngine.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF7E1B51F254004FF46E /* SocketEngine.swift */; };
945B65381B5FCEEA0081E995 /* SocketEngineClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF7F1B51F254004FF46E /* SocketEngineClient.swift */; };
945B65391B5FCEEA0081E995 /* SocketEventHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF801B51F254004FF46E /* SocketEventHandler.swift */; };
945B653A1B5FCEEA0081E995 /* SocketFixUTF8.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF811B51F254004FF46E /* SocketFixUTF8.swift */; };
945B653B1B5FCEEA0081E995 /* SocketIOClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF821B51F254004FF46E /* SocketIOClient.swift */; };
945B653C1B5FCEEA0081E995 /* SocketLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF831B51F254004FF46E /* SocketLogger.swift */; };
945B653D1B5FCEEA0081E995 /* SocketPacket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF841B51F254004FF46E /* SocketPacket.swift */; };
945B653E1B5FCEEA0081E995 /* SocketParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF851B51F254004FF46E /* SocketParser.swift */; };
945B653F1B5FCEEA0081E995 /* SocketTypes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF861B51F254004FF46E /* SocketTypes.swift */; };
945B65401B5FCEEA0081E995 /* SwiftRegex.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF871B51F254004FF46E /* SwiftRegex.swift */; };
945B65411B5FCEEA0081E995 /* WebSocket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF881B51F254004FF46E /* WebSocket.swift */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@ -424,7 +437,20 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
945B653E1B5FCEEA0081E995 /* SocketParser.swift in Sources */,
945B653D1B5FCEEA0081E995 /* SocketPacket.swift in Sources */,
945B653A1B5FCEEA0081E995 /* SocketFixUTF8.swift in Sources */,
945B65391B5FCEEA0081E995 /* SocketEventHandler.swift in Sources */,
945B65371B5FCEEA0081E995 /* SocketEngine.swift in Sources */,
945B65351B5FCEEA0081E995 /* SocketAckManager.swift in Sources */,
945B65401B5FCEEA0081E995 /* SwiftRegex.swift in Sources */,
572EF22C1B51F16C00EEBB58 /* SocketIO_iOSTests.swift in Sources */,
945B653C1B5FCEEA0081E995 /* SocketLogger.swift in Sources */,
945B65381B5FCEEA0081E995 /* SocketEngineClient.swift in Sources */,
945B65361B5FCEEA0081E995 /* SocketAnyEvent.swift in Sources */,
945B653F1B5FCEEA0081E995 /* SocketTypes.swift in Sources */,
945B653B1B5FCEEA0081E995 /* SocketIOClient.swift in Sources */,
945B65411B5FCEEA0081E995 /* WebSocket.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@ -10,27 +10,63 @@ import UIKit
import XCTest
class SocketIO_iOSTests: XCTestCase {
var socketClient:SocketIOClient!
override func setUp() {
super.setUp()
// Put setup code here. This method is called before the invocation of each test method in the class.
self.socketClient = SocketIOClient(socketURL: "localhost:8080")
openConnection()
}
override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
super.tearDown()
}
func testExample() {
// This is an example of a functional test case.
XCTAssert(true, "Pass")
func testConnectionStatus() {
XCTAssertTrue(socketClient.connected)
XCTAssertFalse(socketClient.connecting)
XCTAssertFalse(socketClient.reconnecting)
XCTAssertFalse(socketClient.closed)
}
func testPerformanceExample() {
// This is an example of a performance test case.
self.measureBlock() {
// Put the code you want to measure the time of here.
func testeventWithAcknowledgements() {
let sendedValue = 15;
let expection = self.expectationWithDescription("AcknowledgementTestIncomming")
func didGetEmit(result:NSArray?) {
let resultValue = result?.firstObject as! Int
XCTAssertEqual(sendedValue + 20, resultValue)
expection.fulfill()
}
socketClient.emitWithAck("AcknowledgementTestIncomming", sendedValue)(timeout: 0, callback: didGetEmit)
waitForExpectationsWithTimeout(10, handler: nil)
}
func testoutGoingEmit() {
let sendedValue = 15;
let expection = self.expectationWithDescription("firstEmitTestIncomming")
func didGetEmit(result:NSArray?, ack:AckEmitter?) {
let resultValue = result?.firstObject as! Int
XCTAssertEqual(sendedValue + 10, resultValue)
expection.fulfill()
}
socketClient.on("firstEmitTestOutGoing", callback: didGetEmit)
socketClient.emit("firstEmitTestIncomming", sendedValue)
waitForExpectationsWithTimeout(10, handler: nil)
}
func openConnection() {
let expection = self.expectationWithDescription("connect")
socketClient.on("connect") {data, ack in
expection.fulfill()
}
socketClient.connect()
XCTAssertTrue(socketClient.connecting)
waitForExpectationsWithTimeout(10, handler: nil)
}
func testCloseConnection() {
socketClient.close(fast: false)
XCTAssertTrue(socketClient.closed)
}
}