Permalink
Browse files

Adding tests for message and put some parts to private API.

  • Loading branch information...
pk committed Apr 22, 2012
1 parent 16d9bc4 commit 4ae0d03b51a8f2b0dcfc4438b84f90c70d560d13
@@ -22,8 +22,6 @@ typedef enum {
+ (id)messageWithData:(NSData *)data;
+ (id)messageWithString:(NSString *)string;
-- (id)initWithContent:(id)content type:(PKWebSocketMessageType)type;
-
- (BOOL)isBinary;
@end
@@ -8,6 +8,9 @@
#import "PKWebSocketMessage.h"
+@interface PKWebSocketMessage ()
+@end
+
@implementation PKWebSocketMessage
@synthesize data = _data;
@@ -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

0 comments on commit 4ae0d03

Please sign in to comment.