Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
  • 4 commits
  • 8 files changed
  • 0 commit comments
  • 1 contributor
View
4 PKWebSocket.xcodeproj/project.pbxproj
@@ -41,6 +41,7 @@
E994C289153C3DF10078AA11 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = E994C287153C3DF10078AA11 /* InfoPlist.strings */; };
E994C28C153C3DF10078AA11 /* PKWebSocketTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E994C28B153C3DF10078AA11 /* PKWebSocketTests.m */; };
E9B6D9C71544A9B600DF3D4A /* PKWebSocketCryptoTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E9B6D9C61544A9B600DF3D4A /* PKWebSocketCryptoTests.m */; };
+ E9B6D9CB1544C45900DF3D4A /* PKWebSocketMessageTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E9B6D9CA1544C45900DF3D4A /* PKWebSocketMessageTests.m */; };
E9CCF385154172390019878B /* PKWebSocketFrameParser-Hixie76.h in Headers */ = {isa = PBXBuildFile; fileRef = E9CCF383154172390019878B /* PKWebSocketFrameParser-Hixie76.h */; settings = {ATTRIBUTES = (Public, ); }; };
E9CCF386154172390019878B /* PKWebSocketFrameParser-Hixie76.m in Sources */ = {isa = PBXBuildFile; fileRef = E9CCF384154172390019878B /* PKWebSocketFrameParser-Hixie76.m */; };
E9CCF3A0154199150019878B /* PKWebSocketFrameParser.h in Headers */ = {isa = PBXBuildFile; fileRef = E9CCF39E154199150019878B /* PKWebSocketFrameParser.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -103,6 +104,7 @@
E994C288153C3DF10078AA11 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
E994C28B153C3DF10078AA11 /* PKWebSocketTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PKWebSocketTests.m; sourceTree = "<group>"; };
E9B6D9C61544A9B600DF3D4A /* PKWebSocketCryptoTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = PKWebSocketCryptoTests.m; path = Categories/PKWebSocketCryptoTests.m; sourceTree = "<group>"; };
+ E9B6D9CA1544C45900DF3D4A /* PKWebSocketMessageTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PKWebSocketMessageTests.m; sourceTree = "<group>"; };
E9CCF383154172390019878B /* PKWebSocketFrameParser-Hixie76.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "PKWebSocketFrameParser-Hixie76.h"; path = "Frames/PKWebSocketFrameParser-Hixie76.h"; sourceTree = "<group>"; };
E9CCF384154172390019878B /* PKWebSocketFrameParser-Hixie76.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "PKWebSocketFrameParser-Hixie76.m"; path = "Frames/PKWebSocketFrameParser-Hixie76.m"; sourceTree = "<group>"; };
E9CCF39E154199150019878B /* PKWebSocketFrameParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PKWebSocketFrameParser.h; path = Frames/PKWebSocketFrameParser.h; sourceTree = "<group>"; };
@@ -249,6 +251,7 @@
E9B6D9C91544A9BC00DF3D4A /* Categories */,
E9CCF3A615419A010019878B /* Frames */,
E9008DC5153DD5880038591B /* Handlers */,
+ E9B6D9CA1544C45900DF3D4A /* PKWebSocketMessageTests.m */,
E9E0668B153F7935008AC7EF /* PKWebSocketURLTests.m */,
E9008DBE153DBB170038591B /* PKHTTPRequestTests.m */,
E994C28B153C3DF10078AA11 /* PKWebSocketTests.m */,
@@ -466,6 +469,7 @@
E9E0668C153F7935008AC7EF /* PKWebSocketURLTests.m in Sources */,
E9CCF3A5154199FD0019878B /* PKWebSocketFrameParser-Hixie76Tests.m in Sources */,
E9B6D9C71544A9B600DF3D4A /* PKWebSocketCryptoTests.m in Sources */,
+ E9B6D9CB1544C45900DF3D4A /* PKWebSocketMessageTests.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
10 PKWebSocket/Handlers/PKWebSocketHandler.m
@@ -67,6 +67,7 @@ - (void)setStatus:(PKWebSocketStatus)aStatus {
- (BOOL)connectWithURL:(PKWebSocketURL *)anURL error:(NSError **)outError {
if (self.status != PKWebSocketDisconnectedStatus) return YES;
+ self->_url = anURL;
self.status = PKWebSocketConnectingStatus;
if ([anURL isSecure] && self.tlsSettings != nil) {
@@ -78,7 +79,6 @@ - (BOOL)connectWithURL:(PKWebSocketURL *)anURL error:(NSError **)outError {
withTimeout:self.timeout
error:outError];
if (status) {
- self->_url = anURL;
if (self.runLoopModes) {
[self.socket setRunLoopModes:self.runLoopModes];
}
@@ -163,12 +163,10 @@ - (void)onSocket:(AsyncSocket *)sock didConnectToHost:(NSString *)host port:(UIn
}
- (void)onSocket:(AsyncSocket *)sock willDisconnectWithError:(NSError *)outError {
- if (self.status == PKWebSocketOpenedStatus) {
- self.status = PKWebSocketClosedStatus;
- } else {
- NSLog(@"");
- //[self.delegate _dispatchFailure:[NSNumber numberWithInt:1]];
+ if (self.status != PKWebSocketOpenedStatus) {
+ [self.delegate handler:self didFailWithError:outError];
}
+ self.status = PKWebSocketClosedStatus;
}
- (void)onSocketDidDisconnect:(AsyncSocket *)sock {
View
2 PKWebSocket/PKWebSocketMessage.h
@@ -22,8 +22,6 @@ typedef enum {
+ (id)messageWithData:(NSData *)data;
+ (id)messageWithString:(NSString *)string;
-- (id)initWithContent:(id)content type:(PKWebSocketMessageType)type;
-
- (BOOL)isBinary;
@end
View
3 PKWebSocket/PKWebSocketMessage.m
@@ -8,6 +8,9 @@
#import "PKWebSocketMessage.h"
+@interface PKWebSocketMessage ()
+@end
+
@implementation PKWebSocketMessage
@synthesize data = _data;
View
4 PKWebSocketTests/Handlers/PKWebSocketHandler-Hixie75Tests.m
@@ -67,8 +67,8 @@ - (PKWebSocketURL *)URL {
- (void)testCreateVaidOpeningHandshakeRequest {
PKHTTPRequest *request = [_handler handshakeRequestWithURL:[self URL] error:NULL];
STAssertNotNil(request, nil);
- STAssertNotNil([request valueForHTTPHeaderField:@"Upgrade"],nil);
- STAssertNotNil([request valueForHTTPHeaderField:@"Connection"],nil);
+ STAssertEqualObjects([request valueForHTTPHeaderField:@"Upgrade"], @"WebSocket", nil);
+ STAssertEqualObjects([request valueForHTTPHeaderField:@"Connection"], @"Upgrade", nil);
}
- (void)testAcceptsCorrectOpeningHandshakeResponse {
View
10 PKWebSocketTests/Handlers/PKWebSocketHandler-Hixie76Tests.m
@@ -73,11 +73,11 @@ - (PKWebSocketURL *)URL {
- (void)testCreateVaidOpeningHandshakeRequest {
PKHTTPRequest *request = [_handler handshakeRequestWithURL:[self URL] error:NULL];
STAssertNotNil(request, nil);
- STAssertNotNil([request valueForHTTPHeaderField:@"Upgrade"],nil);
- STAssertNotNil([request valueForHTTPHeaderField:@"Connection"],nil);
- STAssertNotNil([request valueForHTTPHeaderField:@"Sec-WebSocket-Key1"],nil);
- STAssertNotNil([request valueForHTTPHeaderField:@"Sec-WebSocket-Key2"],nil);
- STAssertNotNil(request.body, nil);
+ STAssertEqualObjects([request valueForHTTPHeaderField:@"Upgrade"], @"WebSocket", nil);
+ STAssertEqualObjects([request valueForHTTPHeaderField:@"Connection"], @"Upgrade", nil);
+ STAssertNotNil([request valueForHTTPHeaderField:@"Sec-WebSocket-Key1"], @"There must be frst key.");
+ STAssertNotNil([request valueForHTTPHeaderField:@"Sec-WebSocket-Key2"], @"There must be second key.");
+ STAssertNotNil(request.body, @"There must be third key");
}
- (void)testAcceptsCorrectOpeningHandshakeResponse {
View
41 PKWebSocketTests/PKWebSocketMessageTests.m
@@ -0,0 +1,41 @@
+//
+// PKWebSocketMessageTests.m
+// PKWebSocketMessageTests
+//
+// Created by Pavel Kunc on 16/04/2012.
+// Copyright (c) 2012 Pavel Kunc. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+#import <SenTestingKit/SenTestingKit.h>
+#import "PKWebSocketMessage.h"
+
+@interface PKWebSocketMessageTests : SenTestCase
+@end
+
+@implementation PKWebSocketMessageTests
+
+- (void)setUp {
+ [super setUp];
+}
+
+- (void)tearDown {
+ [super tearDown];
+}
+
+- (void)testMessageWithDataCreateBinaryMessage {
+ NSData *data = [NSData dataWithBytes:"\x48\x65\x6C\x6C\x6F" length:5];
+ PKWebSocketMessage *msg = [PKWebSocketMessage messageWithData:data];
+ STAssertTrue([msg isBinary], @"Must be binary");
+ STAssertTrue([msg.data isEqualToData:data], @"What you put in you get back");
+ STAssertNil(msg.string, @"No string can be set");
+}
+
+- (void)testMessageWithDataCreateStringMessage {
+ PKWebSocketMessage *msg = [PKWebSocketMessage messageWithString:@"foo-bar"];
+ STAssertFalse([msg isBinary], @"Must be string");
+ STAssertTrue([msg.string isEqualToString:@"foo-bar"], @"What you put in you get back.");
+ STAssertNil(msg.data, @"No data can be set");
+}
+
+@end
View
22 PKWebSocketTests/PKWebSocketTests.m
@@ -61,19 +61,18 @@ - (void)webSocket:(PKWebSocket *)webSocket didReceiveMessage:(PKWebSocketMessage
}
-- (void)testTestStandardConnectionShouldBeSuccessful {
+- (void)testStandardConnectionShouldBeSuccessful {
NSError *error;
PKWebSocket *ws = [[PKWebSocket alloc] initWithHandler:_handler delegate:self];
STAssertTrue([ws openWithURLString:[self standardURL] error:&error],nil);
NSRunLoop *theRL = [NSRunLoop currentRunLoop];
- // Begin a run loop terminated when the downloadComplete it set to true
- NSDate *date = [[NSDate date] dateByAddingTimeInterval:6];
+ // Begin a run loop terminated when the finished it set to true
+ NSDate *date = [[NSDate date] dateByAddingTimeInterval:1];
while (!_finished && [theRL runMode:NSDefaultRunLoopMode beforeDate:date]);
}
-/*
-- (void)testTestSecureConnectionShouldBeSuccessful {
+- (void)testSecureConnectionShouldBeSuccessful {
NSMutableDictionary *tlsSettings = [NSMutableDictionary dictionaryWithCapacity:4];
[tlsSettings setObject:@"echo.websocket.org" forKey:(NSString *)kCFStreamSSLPeerName];
@@ -90,17 +89,16 @@ - (void)testTestSecureConnectionShouldBeSuccessful {
forKey:(NSString *)kCFStreamSSLValidatesCertificateChain];
NSError *error;
- PKWebSocket *ws = [[PKWebSocket alloc] initWithURLString:[self secureURL]
- handler:_handler
- delegate:self];
+ PKWebSocket *ws = [[PKWebSocket alloc] initWithHandler:_handler
+ delegate:self];
[ws setTLSSettings:tlsSettings];
- STAssertTrue([ws openWithError:&error],nil);
+ STAssertTrue([ws openWithURLString:[self secureURL] error:&error],nil);
NSRunLoop *theRL = [NSRunLoop currentRunLoop];
- // Begin a run loop terminated when the downloadComplete it set to true
- NSDate *date = [[NSDate date] dateByAddingTimeInterval:15];
+ // Begin a run loop terminated when the finished it set to true
+ NSDate *date = [[NSDate date] dateByAddingTimeInterval:1];
while (!_finished && [theRL runMode:NSDefaultRunLoopMode beforeDate:date]);
}
-*/
+
@end

No commit comments for this range

Something went wrong with that request. Please try again.