Browse Source

Fixed web-socket tests.

Damian Kołakowski 10 năm trước cách đây
mục cha
commit
48a97a30fd

+ 0 - 4
Swifter.xcodeproj/project.pbxproj

@@ -40,8 +40,6 @@
 		7C73C6BE1C261A2600AEF6CA /* String+Misc.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C73C69D1C2619E100AEF6CA /* String+Misc.swift */; };
 		7C76B6DE1D2BB1050030FC98 /* Scopes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C76B6DD1D2BB1050030FC98 /* Scopes.swift */; };
 		7C76B6DF1D2BB1050030FC98 /* Scopes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C76B6DD1D2BB1050030FC98 /* Scopes.swift */; };
-		7C76B6E01D2BB1050030FC98 /* Scopes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C76B6DD1D2BB1050030FC98 /* Scopes.swift */; };
-		7C76B6E11D2BB1050030FC98 /* Scopes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C76B6DD1D2BB1050030FC98 /* Scopes.swift */; };
 		7C76B6E31D2BB1320030FC98 /* Process.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C76B6E21D2BB1320030FC98 /* Process.swift */; };
 		7C76B6E41D2BB1320030FC98 /* Process.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C76B6E21D2BB1320030FC98 /* Process.swift */; };
 		7C76B6E51D2BB1320030FC98 /* Process.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C76B6E21D2BB1320030FC98 /* Process.swift */; };
@@ -625,7 +623,6 @@
 			files = (
 				7CCD87701C660B250068099B /* SwifterTestsHttpParser.swift in Sources */,
 				7C76B6E51D2BB1320030FC98 /* Process.swift in Sources */,
-				7C76B6E01D2BB1050030FC98 /* Scopes.swift in Sources */,
 				7C4785E91C71D15600A9FE73 /* SwifterTestsWebSocketSession.swift in Sources */,
 				7CCD87721C660B250068099B /* SwifterTestsStringExtensions.swift in Sources */,
 			);
@@ -637,7 +634,6 @@
 			files = (
 				7CCD87841C660ED60068099B /* SwifterTestsHttpParser.swift in Sources */,
 				7C76B6E61D2BB1320030FC98 /* Process.swift in Sources */,
-				7C76B6E11D2BB1050030FC98 /* Scopes.swift in Sources */,
 				7C4785EA1C71D15600A9FE73 /* SwifterTestsWebSocketSession.swift in Sources */,
 				7CCD87851C660ED60068099B /* SwifterTestsStringExtensions.swift in Sources */,
 			);

+ 28 - 19
SwifterTestsCommon/SwifterTestsWebSocketSession.swift

@@ -30,78 +30,87 @@ class SwifterTestsWebSocketSession: XCTestCase {
     }
     
     func testParser() {
-        let session = HttpHandlers.WebSocketSession(TestSocket([]))
         
         do {
-            try session.readFrame(TestSocket([0]))
+            let session = WebSocketSession(TestSocket([0]))
+            try session.readFrame()
             XCTAssert(false, "Parser should throw an error if socket has not enough data for a frame.")
         } catch {
             XCTAssert(true, "Parser should throw an error if socket has not enough data for a frame.")
         }
         
         do {
-            try session.readFrame(TestSocket([0b0000_0001, 0b0000_0000, 0, 0, 0, 0]))
+            let session = WebSocketSession(TestSocket([0b0000_0001, 0b0000_0000, 0, 0, 0, 0]))
+            try session.readFrame()
             XCTAssert(false, "Parser should not accept unmasked frames.")
-        } catch HttpHandlers.WebSocketSession.Error.UnMaskedFrame {
+        } catch WebSocketSession.Error.UnMaskedFrame {
             XCTAssert(true, "Parse should throw UnMaskedFrame error for unmasked message.")
         } catch {
             XCTAssert(false, "Parse should throw UnMaskedFrame error for unmasked message.")
         }
         
         do {
-            let frame = try session.readFrame(TestSocket([0b1000_0001, 0b1000_0000, 0, 0, 0, 0]))
+            let session = WebSocketSession(TestSocket([0b1000_0001, 0b1000_0000, 0, 0, 0, 0]))
+            let frame = try session.readFrame()
             XCTAssert(frame.fin, "Parser should detect fin flag set.")
         } catch {
             XCTAssert(false, "Parser should not throw an error for a frame with fin flag set (\(error)")
         }
         
         do {
-            let frame = try session.readFrame(TestSocket([0b0000_0000, 0b1000_0000, 0, 0, 0, 0]))
-            XCTAssertEqual(frame.opcode, HttpHandlers.WebSocketSession.OpCode.Continue, "Parser should accept Continue opcode.")
+            let session = WebSocketSession(TestSocket([0b0000_0000, 0b1000_0000, 0, 0, 0, 0]))
+            let frame = try session.readFrame()
+            XCTAssertEqual(frame.opcode, WebSocketSession.OpCode.Continue, "Parser should accept Continue opcode.")
         } catch {
             XCTAssertTrue(true, "Parser should accept Continue opcode without any errors.")
         }
         
         do {
-            let frame = try session.readFrame(TestSocket([0b0000_0001, 0b1000_0000, 0, 0, 0, 0]))
-            XCTAssertEqual(frame.opcode, HttpHandlers.WebSocketSession.OpCode.Text, "Parser should accept Text opcode.")
+            let session = WebSocketSession(TestSocket([0b0000_0001, 0b1000_0000, 0, 0, 0, 0]))
+            let frame = try session.readFrame()
+            XCTAssertEqual(frame.opcode, WebSocketSession.OpCode.Text, "Parser should accept Text opcode.")
         } catch {
             XCTAssert(false, "Parser should accept Text opcode without any errors.")
         }
         
         do {
-            let frame = try session.readFrame(TestSocket([0b0000_0010, 0b1000_0000, 0, 0, 0, 0]))
-            XCTAssertEqual(frame.opcode, HttpHandlers.WebSocketSession.OpCode.Binary, "Parser should accept Binary opcode.")
+            let session = WebSocketSession(TestSocket([0b0000_0010, 0b1000_0000, 0, 0, 0, 0]))
+            let frame = try session.readFrame()
+            XCTAssertEqual(frame.opcode, WebSocketSession.OpCode.Binary, "Parser should accept Binary opcode.")
         } catch {
             XCTAssert(false, "Parser should accept Binary opcode without any errors.")
         }
         
         do {
-            let frame = try session.readFrame(TestSocket([0b0000_1000, 0b1000_0000, 0, 0, 0, 0]))
-            XCTAssertEqual(frame.opcode, HttpHandlers.WebSocketSession.OpCode.Close, "Parser should accept Close opcode.")
+            let session = WebSocketSession(TestSocket([0b0000_1000, 0b1000_0000, 0, 0, 0, 0]))
+            let frame = try session.readFrame()
+            XCTAssertEqual(frame.opcode, WebSocketSession.OpCode.Close, "Parser should accept Close opcode.")
         } catch {
             XCTAssert(false, "Parser should accept Close opcode without any errors.")
         }
         
         do {
-            let frame = try session.readFrame(TestSocket([0b0000_1001, 0b1000_0000, 0, 0, 0, 0]))
-            XCTAssertEqual(frame.opcode, HttpHandlers.WebSocketSession.OpCode.Ping, "Parser should accept Ping opcode.")
+            let session = WebSocketSession(TestSocket([0b0000_1001, 0b1000_0000, 0, 0, 0, 0]))
+            let frame = try session.readFrame()
+            XCTAssertEqual(frame.opcode, WebSocketSession.OpCode.Ping, "Parser should accept Ping opcode.")
         } catch {
             XCTAssert(false, "Parser should accept Ping opcode without any errors.")
         }
         
         do {
-            let frame = try session.readFrame(TestSocket([0b0000_1010, 0b1000_0000, 0, 0, 0, 0]))
-            XCTAssertEqual(frame.opcode, HttpHandlers.WebSocketSession.OpCode.Pong, "Parser should accept Pong opcode.")
+            let session = WebSocketSession(TestSocket([0b0000_1010, 0b1000_0000, 0, 0, 0, 0]))
+            let frame = try session.readFrame()
+            XCTAssertEqual(frame.opcode, WebSocketSession.OpCode.Pong, "Parser should accept Pong opcode.")
         } catch {
             XCTAssert(false, "Parser should accept Pong opcode without any errors.")
         }
         
         for opcode in [3, 4, 5, 6, 7, 11, 12, 13, 14, 15] {
             do {
-                try session.readFrame(TestSocket([UInt8(opcode), 0b1000_0000, 0, 0, 0, 0]))
+                let session = WebSocketSession(TestSocket([UInt8(opcode), 0b1000_0000, 0, 0, 0, 0]))
+                try session.readFrame()
                 XCTAssert(false, "Parse should throw an error for unknown opcode: \(opcode)")
-            } catch HttpHandlers.WebSocketSession.Error.UnknownOpCode(_) {
+            } catch WebSocketSession.Error.UnknownOpCode(_) {
                 XCTAssert(true, "Parse should throw UnknownOpCode error for unknown opcode.")
             } catch {
                 XCTAssert(false, "Parse should throw UnknownOpCode error for unknown opcode (was \(error)).")