Permalink
Browse files

Moved some operations that worked solely on data into an additions cl…

…ass, and added some tests for it.
  • Loading branch information...
1 parent 278a876 commit 42dade8cd9744f257ad780e11851b7d2bf770aba @ccgus committed Feb 22, 2010
View
1 .gitignore
@@ -3,6 +3,7 @@
*.mode2v3
*.pbxuser
*.perspectivev3
+*.pyc
letterbox/TAGS
build/
*~
View
22 letterbox/LetterBox.xcodeproj/project.pbxproj
@@ -17,6 +17,9 @@
968D0F45111528AB0044BE1D /* LBAttachmentTests.m in Sources */ = {isa = PBXBuildFile; fileRef = CC877D3B110ABD32005ECF65 /* LBAttachmentTests.m */; };
96B8B0FB11153F4200A36A36 /* LBBareMessageTests.m in Sources */ = {isa = PBXBuildFile; fileRef = CC877D35110ABD32005ECF65 /* LBBareMessageTests.m */; };
CC220E981131BD5B000B46D8 /* LBIMAPConnectionTests.m in Sources */ = {isa = PBXBuildFile; fileRef = CC220E971131BD5B000B46D8 /* LBIMAPConnectionTests.m */; };
+ CC2212BB11320868000B46D8 /* LBNSDataAdditionsTests.m in Sources */ = {isa = PBXBuildFile; fileRef = CC2212BA11320868000B46D8 /* LBNSDataAdditionsTests.m */; };
+ CC22134511320C86000B46D8 /* LBNSDataAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = CC2212BE11320883000B46D8 /* LBNSDataAdditions.m */; };
+ CC22134611320C8F000B46D8 /* LBNSDataAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = CC2212BD11320883000B46D8 /* LBNSDataAdditions.h */; settings = {ATTRIBUTES = (Public, ); }; };
CC3D54231108E7F700EEEF77 /* FMDatabase.h in Headers */ = {isa = PBXBuildFile; fileRef = CC3D541D1108E7F700EEEF77 /* FMDatabase.h */; };
CC3D54241108E7F700EEEF77 /* FMDatabase.m in Sources */ = {isa = PBXBuildFile; fileRef = CC3D541E1108E7F700EEEF77 /* FMDatabase.m */; };
CC3D54251108E7F700EEEF77 /* FMDatabaseAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = CC3D541F1108E7F700EEEF77 /* FMDatabaseAdditions.h */; };
@@ -145,6 +148,10 @@
968D0EA71115267D0044BE1D /* Tests.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Tests.app; sourceTree = BUILT_PRODUCTS_DIR; };
CC220E961131BD5B000B46D8 /* LBIMAPConnectionTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LBIMAPConnectionTests.h; path = tests/LBIMAPConnectionTests.h; sourceTree = "<group>"; };
CC220E971131BD5B000B46D8 /* LBIMAPConnectionTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = LBIMAPConnectionTests.m; path = tests/LBIMAPConnectionTests.m; sourceTree = "<group>"; };
+ CC2212B911320868000B46D8 /* LBNSDataAdditionsTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LBNSDataAdditionsTests.h; path = tests/LBNSDataAdditionsTests.h; sourceTree = "<group>"; };
+ CC2212BA11320868000B46D8 /* LBNSDataAdditionsTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = LBNSDataAdditionsTests.m; path = tests/LBNSDataAdditionsTests.m; sourceTree = "<group>"; };
+ CC2212BD11320883000B46D8 /* LBNSDataAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LBNSDataAdditions.h; path = source/LBNSDataAdditions.h; sourceTree = "<group>"; };
+ CC2212BE11320883000B46D8 /* LBNSDataAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = LBNSDataAdditions.m; path = source/LBNSDataAdditions.m; sourceTree = "<group>"; };
CC3D541D1108E7F700EEEF77 /* FMDatabase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FMDatabase.h; path = source/FMDatabase.h; sourceTree = "<group>"; };
CC3D541E1108E7F700EEEF77 /* FMDatabase.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FMDatabase.m; path = source/FMDatabase.m; sourceTree = "<group>"; };
CC3D541F1108E7F700EEEF77 /* FMDatabaseAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FMDatabaseAdditions.h; path = source/FMDatabaseAdditions.h; sourceTree = "<group>"; };
@@ -314,6 +321,7 @@
08FB77AEFE84172EC02AAC07 /* Classes */ = {
isa = PBXGroup;
children = (
+ CC2212BC11320870000B46D8 /* Additions */,
CC8998D11118C2200024616B /* MooseYard */,
CC3D541C1108E7AC00EEEF77 /* FMDB */,
CC877CE3110ABC04005ECF65 /* LBAccount.h */,
@@ -385,6 +393,15 @@
name = "Other Sources";
sourceTree = "<group>";
};
+ CC2212BC11320870000B46D8 /* Additions */ = {
+ isa = PBXGroup;
+ children = (
+ CC2212BD11320883000B46D8 /* LBNSDataAdditions.h */,
+ CC2212BE11320883000B46D8 /* LBNSDataAdditions.m */,
+ );
+ name = Additions;
+ sourceTree = "<group>";
+ };
CC3D541C1108E7AC00EEEF77 /* FMDB */ = {
isa = PBXGroup;
children = (
@@ -485,6 +502,8 @@
CC877D35110ABD32005ECF65 /* LBBareMessageTests.m */,
CC220E961131BD5B000B46D8 /* LBIMAPConnectionTests.h */,
CC220E971131BD5B000B46D8 /* LBIMAPConnectionTests.m */,
+ CC2212B911320868000B46D8 /* LBNSDataAdditionsTests.h */,
+ CC2212BA11320868000B46D8 /* LBNSDataAdditionsTests.m */,
);
name = Tests;
sourceTree = "<group>";
@@ -535,6 +554,7 @@
CCA0E7E1112A0ADF00110E76 /* LBSMTPConnection.h in Headers */,
CCA0E821112A0F8B00110E76 /* LBTCPConnection.h in Headers */,
CCA0E825112A0FD800110E76 /* LBTCPReader.h in Headers */,
+ CC22134611320C8F000B46D8 /* LBNSDataAdditions.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -689,6 +709,7 @@
CCA0E7E2112A0ADF00110E76 /* LBSMTPConnection.m in Sources */,
CCA0E822112A0F8B00110E76 /* LBTCPConnection.m in Sources */,
CCA0E826112A0FD800110E76 /* LBTCPReader.m in Sources */,
+ CC22134511320C86000B46D8 /* LBNSDataAdditions.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -702,6 +723,7 @@
968D0F45111528AB0044BE1D /* LBAttachmentTests.m in Sources */,
96B8B0FB11153F4200A36A36 /* LBBareMessageTests.m in Sources */,
CC220E981131BD5B000B46D8 /* LBIMAPConnectionTests.m in Sources */,
+ CC2212BB11320868000B46D8 /* LBNSDataAdditionsTests.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
24 letterbox/source/LBIMAPConnection.m
@@ -76,7 +76,7 @@ - (void)loginWithUsername:(NSString *)username password:(NSString *)password blo
[self appendDataFromReader:reader];
- NSString *res = [[self class] singleLineResponseFromData:[self responseBytes]];
+ NSString *res = [[self responseBytes] lbSingleLineResponse];
if (!res) {
debug(@"slow auth?");
@@ -111,7 +111,7 @@ - (void)selectMailbox:(NSString*)mailbox block:(LBResponseBlock)block {
NSError *err = nil;
- if (!([[self class] endOfData:[self responseBytes] isEqualTo:expected] || [[self class] endOfData:[self responseBytes] isEqualTo:expected2])) {
+ if (!([[self responseBytes] lbEndIsEqualTo:expected] || [[self responseBytes] lbEndIsEqualTo:expected])) {
NSString *junk = [NSString stringWithFormat:@"Could not Select mailbox: %@", [self responseAsString]];
LBQuickError(&err, LBSELECT, 0, junk);
}
@@ -132,7 +132,7 @@ - (void)listMessagesWithBlock:(LBResponseBlock)block {
NSString *expected = [NSString stringWithFormat:@"%d OK", commandCount];
NSString *expectedErr = [NSString stringWithFormat:@"%d NO", commandCount];
NSString *expectedBad = [NSString stringWithFormat:@"%d BAD", commandCount];
- NSString *lastLine = [[self class] lastLineOfMultilineData:[self responseBytes]];
+ NSString *lastLine = [[self responseBytes] lbLastLineOfMultiline];
if ([lastLine hasPrefix:expected]) {
@@ -161,7 +161,7 @@ - (void)listSubscribedMailboxesWithBock:(LBResponseBlock)block {
NSString *expected = [NSString stringWithFormat:@"%d OK", commandCount];
- NSString *lastLine = [[self class] lastLineOfMultilineData:[self responseBytes]];
+ NSString *lastLine = [[self responseBytes] lbLastLineOfMultiline];
if ([lastLine hasPrefix:expected]) {
debug(@"yay?");
@@ -186,7 +186,7 @@ - (void)connectUsingBlock:(LBResponseBlock)block {
[self appendDataFromReader:reader];
- NSString *res = [[self class] singleLineResponseFromData:[self responseBytes]];
+ NSString *res = [[self responseBytes] lbSingleLineResponse];
if (!res) {
debug(@"slow connection?");
@@ -215,7 +215,7 @@ - (void)logoutWithBlock:(LBResponseBlock)block {
debug(@"[self responseBytes]: %@", [self responseAsString]);
- NSString *lastLine = [[self class] firstLineOfData:[self responseBytes]];
+ NSString *lastLine = [[self responseBytes] lbFirstLine];
NSString *expectedGood = [NSString stringWithFormat:@"%d OK ", commandCount, CRLF];
NSString *expectedBad = [NSString stringWithFormat:@"%d BAD ", commandCount, CRLF];
NSString *expectedErr = [NSString stringWithFormat:@"%d NO ", commandCount, CRLF];
@@ -246,7 +246,7 @@ - (void) simpleCommand:(NSString*)command withArgument:(NSString*)arg block:(LBR
[self appendDataFromReader:reader];
- NSString *res = [[self class] singleLineResponseFromData:[self responseBytes]];
+ NSString *res = [[self responseBytes] lbSingleLineResponse];
if (!res) {
return;
@@ -296,7 +296,7 @@ - (void)deleteMessages:(NSString*)seqIds withBlock:(LBResponseBlock)block {
[self sendCommand:LBSTORE withArgument:format readBlock:^(LBTCPReader *reader) {
[self appendDataFromReader:reader];
- NSString *lastLine = [[self class] lastLineOfMultilineData:[self responseBytes]];
+ NSString *lastLine = [[self responseBytes] lbLastLineOfMultiline];
if (!lastLine) {
return;
@@ -325,7 +325,7 @@ - (void)expungeWithBlock:(LBResponseBlock)block {
[self sendCommand:LBEXPUNGE withArgument:nil readBlock:^(LBTCPReader *reader) {
[self appendDataFromReader:reader];
- NSString *lastLine = [[self class] lastLineOfMultilineData:[self responseBytes]];
+ NSString *lastLine = [[self responseBytes] lbLastLineOfMultiline];
if (!lastLine) {
return;
@@ -353,7 +353,7 @@ - (void)fetchMessages:(NSString*)seqIds withBlock:(LBResponseBlock)block {
[self appendDataFromReader:reader];
- NSString *firstLine = [[self class] firstLineOfData:[self responseBytes]];
+ NSString *firstLine = [[self responseBytes] lbFirstLine];
if (firstLine) {
@@ -388,7 +388,7 @@ - (void)fetchMessages:(NSString*)seqIds withBlock:(LBResponseBlock)block {
if ([[self responseBytes] length] > atLeastLength) {
- NSString *lastLine = [[self class] lastLineOfMultilineData:[self responseBytes]];
+ NSString *lastLine = [[self responseBytes] lbLastLineOfMultiline];
NSString *expectedGood = [NSString stringWithFormat:@"%d OK FETCH", commandCount, CRLF];
//NSString *expectedNo = [NSString stringWithFormat:@"%d NO", commandCount, CRLF];
//NSString *expectedBad = [NSString stringWithFormat:@"%d BAD", commandCount, CRLF];
@@ -559,7 +559,7 @@ - (NSArray*)searchedResultSet {
list = [list substringFromIndex:9];
- NSString *lastLine = [[self class] lastLineOfMultilineData:[self responseBytes]];
+ NSString *lastLine = [[self responseBytes] lbLastLineOfMultiline];
// now, let's cut that last bit out.
// the -4 is for the 2 crlf's in there.
View
26 letterbox/source/LBNSDataAdditions.h
@@ -0,0 +1,26 @@
+//
+// LBNSDataAdditions.h
+// LetterBox
+//
+// Created by August Mueller on 2/21/10.
+// Copyright 2010 Flying Meat Inc. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@interface NSData (LetterBoxAdditions)
+
+- (NSString*)lbFirstLine;
+- (NSString*)lbLastLineOfMultiline;
+- (NSString*)lbSingleLineResponse;
+- (BOOL)lbEndIsEqualTo:(NSString*)string;
+
+- (NSString*)utf8String;
+
+@end
+
+@interface NSString (LetterBoxAdditions)
+
+- (NSData*)utf8Data;
+
+@end
View
124 letterbox/source/LBNSDataAdditions.m
@@ -0,0 +1,124 @@
+//
+// LBNSDataAdditions.m
+// LetterBox
+//
+// Created by August Mueller on 2/21/10.
+// Copyright 2010 Flying Meat Inc. All rights reserved.
+//
+
+#import "LBNSDataAdditions.h"
+
+#define CRLF "\r\n"
+
+@implementation NSData (LetterBoxAdditions)
+
+- (NSString*)lbSingleLineResponse {
+
+ // *something* + crlf
+ if ([self length] < 4) {
+ return nil;
+ }
+
+ const char *c = [self bytes];
+
+ // check for completion of command.
+ if (strncmp(&(c[[self length] - 2]), CRLF, 2)) {
+ return nil;
+ }
+
+ // er... what about this char set?
+ return [[[NSString alloc] initWithBytes:[self bytes] length:[self length] - 2 encoding:NSUTF8StringEncoding] autorelease];
+}
+
+
+- (BOOL)lbEndIsEqualTo:(NSString*)string; {
+
+ if ([self length] < ([string length])) {
+ return NO;
+ }
+
+ const char *c = [self bytes];
+
+ // check for completion of command.
+ if (strncmp(&(c[[self length] - [string length]]), [string UTF8String], [string length])) {
+ return NO;
+ }
+
+ return YES;
+}
+
+- (NSString*)lbLastLineOfMultiline {
+
+ if ([self length] < 3) { // something + crlf
+ return nil;
+ }
+
+ NSUInteger len = [self length];
+ char *cdata = (char *)[self bytes];
+ NSUInteger idx = len - 3;
+ char *pos = &cdata[idx];
+
+ // if it doesn't end with crlf, it's bad.
+ if (!(cdata[len - 1] == '\n' && cdata[len - 2] == '\r')) {
+ return nil;
+ }
+
+ while (idx > 0) {
+ // let's go backwards!
+
+ if (*pos == '\n') {
+ // get rid of the encountered lf, and the ending crlf
+ NSRange r = NSMakeRange(idx + 1, len - (idx + 3));
+ NSData *subData = [self subdataWithRange:r];
+ NSString *junk = [[[NSString alloc] initWithBytes:[subData bytes] length:[subData length] encoding:NSUTF8StringEncoding] autorelease];
+ return junk;
+ }
+
+ pos--;
+ idx--;
+ }
+
+ return nil;
+}
+
+- (NSString*)lbFirstLine {
+
+ if ([self length] < 3) { // something + crlf
+ return nil;
+ }
+
+ NSUInteger len = [self length];
+ NSUInteger idx = 0;
+ char *cdata = (char *)[self bytes];
+
+ while (idx < len) {
+
+ if (cdata[idx] == '\r') {
+ // get rid of the encountered lf, and the ending crlf
+ NSRange r = NSMakeRange(0, idx);
+ NSData *subData = [self subdataWithRange:r];
+ NSString *junk = [[[NSString alloc] initWithBytes:[subData bytes] length:[subData length] encoding:NSUTF8StringEncoding] autorelease];
+ return junk;
+ }
+
+ idx++;
+ }
+
+ return nil;
+}
+
+- (NSString*)utf8String {
+ return [[[NSString alloc] initWithData:self encoding:NSUTF8StringEncoding] autorelease];
+}
+
+
+@end
+
+
+@implementation NSString (LetterBoxAdditions)
+
+- (NSData*)utf8Data {
+ return [self dataUsingEncoding:NSUTF8StringEncoding];
+}
+
+@end
View
12 letterbox/source/LBSMTPConnection.m
@@ -48,7 +48,7 @@ - (void)connectUsingBlock:(LBResponseBlock)block {
[self appendDataFromReader:reader];
- NSString *res = [[self class] firstLineOfData:[self responseBytes]];
+ NSString *res = [[self responseBytes] lbFirstLine];
if (!res) {
// haven't gotten our crlf yet.
return;
@@ -72,7 +72,7 @@ - (void)connectUsingBlock:(LBResponseBlock)block {
[self appendDataFromReader:reader];
- NSString *res = [[self class] firstLineOfData:[self responseBytes]];
+ NSString *res = [[self responseBytes] lbFirstLine];
// check to see if we have our line, with a crlf
if (!res) {
@@ -104,7 +104,7 @@ - (void)sendMessage:(NSString*)message to:(NSString*)to from:(NSString*)from blo
[self appendDataFromReader:reader];
- NSString *res = [[self class] firstLineOfData:[self responseBytes]];
+ NSString *res = [[self responseBytes] lbFirstLine];
if (!res) {
return;
}
@@ -121,7 +121,7 @@ - (void)sendMessage:(NSString*)message to:(NSString*)to from:(NSString*)from blo
[self appendDataFromReader:reader];
- NSString *res = [[self class] firstLineOfData:[self responseBytes]];
+ NSString *res = [[self responseBytes] lbFirstLine];
if (!res) {
return;
}
@@ -138,7 +138,7 @@ - (void)sendMessage:(NSString*)message to:(NSString*)to from:(NSString*)from blo
[self appendDataFromReader:reader];
- NSString *res = [[self class] firstLineOfData:[self responseBytes]];
+ NSString *res = [[self responseBytes] lbFirstLine];
if (!res) {
return;
}
@@ -156,7 +156,7 @@ - (void)sendMessage:(NSString*)message to:(NSString*)to from:(NSString*)from blo
[self sendData:[fixedmessage dataUsingEncoding:NSUTF8StringEncoding] readBlock:^(LBTCPReader *reader) {
[self appendDataFromReader:reader];
- NSString *res = [[self class] firstLineOfData:[self responseBytes]];
+ NSString *res = [[self responseBytes] lbFirstLine];
if (!res) {
return;
}
View
5 letterbox/source/LBTCPConnection.h
@@ -11,6 +11,7 @@
#import "TCPConnection.h"
#import "LBTCPReader.h"
#import "LBServer.h" // for LBResponseBlock
+#import "LBNSDataAdditions.h"
extern NSString *LBCONNECTING;
@@ -41,10 +42,6 @@ extern NSString *LBCONNECTING;
// for subclassers
- (void)callBlockWithError:(NSError*)err;
- (void)callBlockWithError:(NSError*)err killReadBlock:(BOOL)killReadBlock;
-+ (NSString*)firstLineOfData:(NSData*)data;
-+ (NSString*)lastLineOfMultilineData:(NSData*)data;
-+ (BOOL)endOfData:(NSData*)data isEqualTo:(NSString*)string;
-+ (NSString*)singleLineResponseFromData:(NSData*)data;
- (void)sendCommand:(NSString*)command withArgument:(NSString*)arg;
- (void)sendCommand:(NSString*)command withArgument:(NSString*)arg readBlock:(void (^)(LBTCPReader *))block;
View
95 letterbox/source/LBTCPConnection.m
@@ -112,101 +112,6 @@ - (BOOL) connection: (TCPConnection*)connection authorizeSSLPeer: (SecCertificat
}
-+ (NSString*)singleLineResponseFromData:(NSData*)data {
-
- // *something* + crlf
- if ([data length] < 4) {
- return nil;
- }
-
- const char *c = [data bytes];
-
- // check for completion of command.
- if (strncmp(&(c[[data length] - 2]), CRLF, 2)) {
- return nil;
- }
-
- // er... what about this char set?
- return [[[NSString alloc] initWithBytes:[data bytes] length:[data length] encoding:NSUTF8StringEncoding] autorelease];
-}
-
-+ (BOOL)endOfData:(NSData*)data isEqualTo:(NSString*)string {
-
- if ([data length] < ([string length])) {
- return NO;
- }
-
- const char *c = [data bytes];
-
- // check for completion of command.
- if (strncmp(&(c[[data length] - [string length]]), [string UTF8String], [string length])) {
- return NO;
- }
-
- return YES;
-}
-
-+ (NSString*)lastLineOfMultilineData:(NSData*)data {
-
- if ([data length] < 3) { // something + crlf
- return nil;
- }
-
- NSUInteger len = [data length];
- char *cdata = (char *)[data bytes];
- NSUInteger idx = len - 3;
- char *pos = &cdata[idx];
-
- // if it doesn't end with crlf, it's bad.
- if (!(cdata[len - 1] == '\n' && cdata[len - 2] == '\r')) {
- return nil;
- }
-
- while (idx > 0) {
- // let's go backwards!
-
- if (*pos == '\n') {
- // get rid of the encountered lf, and the ending crlf
- NSRange r = NSMakeRange(idx + 1, len - (idx + 3));
- NSData *subData = [data subdataWithRange:r];
- NSString *junk = [[[NSString alloc] initWithBytes:[subData bytes] length:[subData length] encoding:NSUTF8StringEncoding] autorelease];
- return junk;
- }
-
- pos--;
- idx--;
- }
-
- return nil;
-}
-
-+ (NSString*)firstLineOfData:(NSData*)data {
-
- if ([data length] < 3) { // something + crlf
- return nil;
- }
-
- NSUInteger len = [data length];
- NSUInteger idx = 0;
- char *cdata = (char *)[data bytes];
-
- while (idx < len) {
-
- if (cdata[idx] == '\r') {
- // get rid of the encountered lf, and the ending crlf
- NSRange r = NSMakeRange(0, idx);
- NSData *subData = [data subdataWithRange:r];
- NSString *junk = [[[NSString alloc] initWithBytes:[subData bytes] length:[subData length] encoding:NSUTF8StringEncoding] autorelease];
- return junk;
- }
-
- idx++;
- }
-
- return nil;
-}
-
-
- (void)callBlockWithError:(NSError*)err {
[self callBlockWithError:err killReadBlock:NO];
View
16 letterbox/tests/LBNSDataAdditionsTests.h
@@ -0,0 +1,16 @@
+//
+// LBNSDataAdditionsTests.h
+// LetterBox
+//
+// Created by August Mueller on 2/21/10.
+// Copyright 2010 Flying Meat Inc. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+#import <GHUnit/GHUnit.h>
+
+@interface LBNSDataAdditionsTests : GHTestCase {
+
+}
+
+@end
View
84 letterbox/tests/LBNSDataAdditionsTests.m
@@ -0,0 +1,84 @@
+//
+// LBNSDataAdditionsTests.m
+// LetterBox
+//
+// Created by August Mueller on 2/21/10.
+// Copyright 2010 Flying Meat Inc. All rights reserved.
+//
+
+#import "LBNSDataAdditionsTests.h"
+#import "LBNSDataAdditions.h"
+
+@implementation LBNSDataAdditionsTests
+
+- (void)testDataStuffA {
+
+ NSString *foo = @"Hello World,\r\nHow is it going?\r\n";
+ NSString *expected = @"Hello World,";
+ NSString *got = [[foo utf8Data] lbFirstLine];
+
+ GHAssertTrue([got isEqualToString:expected], @"lbFirstLine failed");
+}
+
+- (void)testDataStuffB {
+
+ NSString *foo = @"Hello World,\r\n";
+ NSString *expected = @"Hello World,";
+ NSString *got = [[foo utf8Data] lbFirstLine];
+
+ GHAssertTrue([got isEqualToString:expected], @"lbFirstLine failed");
+}
+
+- (void)testDataStuffC {
+
+ NSString *foo = @"Hello World,";
+ NSString *expected = @"Hello World,";
+ NSString *got = [[foo utf8Data] lbFirstLine];
+
+ // there's no crlf on this bit, so it should be nil.
+ GHAssertTrue(!got, @"lbFirstLine failed");
+}
+
+- (void)testDataStuffD {
+
+ NSString *foo = @"* LSUB (\\HasNoChildren) \".\" \"INBOX.zero\"\r\n\
+...\r\n\
+2 OK LSUB completed\r\n";
+
+ NSString *expected = @"2 OK LSUB completed\r\n";
+
+ GHAssertTrue([[foo utf8Data] lbEndIsEqualTo:expected], @"lbEndIsEqualTo failed");
+}
+
+
+- (void)testDataStuffE {
+
+ NSString *foo = @"* LSUB (\\HasNoChildren) \".\" \"INBOX.zero\"\r\n\
+...\r\n\
+2 OK LSUB completed\r\n";
+
+ NSString *expected = @"2 OK LSUB completed";
+
+ GHAssertEqualStrings([[foo utf8Data] lbLastLineOfMultiline], expected, @"lbLastLineOfMultiline failed");
+}
+
+
+
+- (void)testDataStuffF {
+
+ NSString *foo = @"2 OK LOGIN\r\n";
+ NSString *expected = @"2 OK LOGIN";
+
+ GHAssertEqualStrings([[foo utf8Data] lbSingleLineResponse], expected, @"lbSingleLineResponse failed");
+}
+
+- (void)testDataStuffG {
+
+ NSString *foo = @"2 OK LOG..";
+
+ GHAssertNil([[foo utf8Data] lbSingleLineResponse], @"lbSingleLineResponse nil failed");
+}
+
+
+
+@end

0 comments on commit 42dade8

Please sign in to comment.