diff options
author | thomasvl@gmail.com <thomasvl@gmail.com@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3> | 2009-03-11 17:24:33 +0000 |
---|---|---|
committer | thomasvl@gmail.com <thomasvl@gmail.com@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3> | 2009-03-11 17:24:33 +0000 |
commit | 483e8d866b40a298fcc28f7a8b670ff74f11c5ab (patch) | |
tree | 5582fa69ad5301c450e213db2cd36d7727af60f2 /Foundation | |
parent | a5ada143459a5858341030c33180b36f7542e4d1 (diff) |
- increase some test coverage
- fixed system include in GTMTheme
- put the logging of execected dev logs under env control and default it to
off to make unittest output a little easier to read.
Diffstat (limited to 'Foundation')
-rw-r--r-- | Foundation/GTMSQLite.m | 12 | ||||
-rw-r--r-- | Foundation/GTMSQLiteTest.m | 61 | ||||
-rw-r--r-- | Foundation/GTMTransientRootProxy.m | 4 | ||||
-rw-r--r-- | Foundation/GTMTransientRootProxyTest.m | 24 | ||||
-rw-r--r-- | Foundation/GTMTransientRootSocketProxyTest.m | 19 |
5 files changed, 97 insertions, 23 deletions
diff --git a/Foundation/GTMSQLite.m b/Foundation/GTMSQLite.m index 73f6a22..0c7df2e 100644 --- a/Foundation/GTMSQLite.m +++ b/Foundation/GTMSQLite.m @@ -172,7 +172,7 @@ static CFLocaleRef gCurrentLocale = NULL; rc = sqlite3_open([path_ fileSystemRepresentation], &db_); } else { CFStringEncoding cfEncoding; -#if __BIG_ENDIAN__ +#if TARGET_RT_BIG_ENDIAN cfEncoding = kCFStringEncodingUTF16BE; #else cfEncoding = kCFStringEncodingUTF16LE; @@ -982,12 +982,10 @@ static int Collate16(void *userContext, int length1, const void *str1, // we must. CFStringRef string1 = NULL, string2 = NULL; if ((userArgs->textRep == SQLITE_UTF16) || -#if defined __BIG_ENDIAN__ +#if TARGET_RT_BIG_ENDIAN (userArgs->textRep == SQLITE_UTF16BE) -#elif defined __LITTLE_ENDIAN__ - (userArgs->textRep == SQLITE_UTF16LE) #else -#error Not big or little endian? + (userArgs->textRep == SQLITE_UTF16LE) #endif ) { string1 = CFStringCreateWithCharactersNoCopy(kCFAllocatorDefault, @@ -1379,9 +1377,11 @@ static void Like8(sqlite3_context *context, int argc, sqlite3_value **argv) { const char *pattern = (const char *)sqlite3_value_text(argv[0]); const char *target = (const char *)sqlite3_value_text(argv[1]); if (!pattern || !target) { + // COV_NF_START sqlite3_result_error(context, "LIKE CF implementation missing pattern or value", -1); return; + // COV_NF_END } CFStringRef patternString = CFStringCreateWithCStringNoCopy(kCFAllocatorDefault, @@ -1469,9 +1469,11 @@ static void Like16(sqlite3_context *context, int argc, sqlite3_value **argv) { int targetByteCount = sqlite3_value_bytes16(argv[1]); const UniChar *targetText = (void *)sqlite3_value_text16(argv[1]); if (!patternByteCount || !patternText || !targetByteCount || !targetText) { + // COV_NF_START sqlite3_result_error(context, "LIKE CF implementation missing pattern or value", -1); return; + // COV_NF_END } CFStringRef patternString = CFStringCreateWithCharactersNoCopy(kCFAllocatorDefault, diff --git a/Foundation/GTMSQLiteTest.m b/Foundation/GTMSQLiteTest.m index 578f6b7..493493a 100644 --- a/Foundation/GTMSQLiteTest.m +++ b/Foundation/GTMSQLiteTest.m @@ -496,7 +496,14 @@ static void TestUpperLower16Impl(sqlite3_context *context, STAssertTrue([db likeComparisonOptions] == 0, @"LIKE Comparison options setter/getter does not work!"); - err = [db executeSQL:@"CREATE TABLE foo (bar TEXT);"]; + NSString *createString = nil; +#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 + createString = @"CREATE TABLE foo (bar NODIACRITIC_WIDTHINSENSITIVE TEXT);"; +#else + createString = @"CREATE TABLE foo (bar TEXT);"; +#endif // MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 + + err = [db executeSQL:createString]; STAssertEquals(err, SQLITE_OK, @"Failed to create table for like comparison options test"); @@ -523,6 +530,24 @@ static void TestUpperLower16Impl(sqlite3_context *context, err = [statement stepRow]; STAssertEquals(err, SQLITE_ROW, @"failed to retrieve row!"); +#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 + // Now try adding in 10.5 only flags + c |= (kCFCompareDiacriticInsensitive | kCFCompareWidthInsensitive); + [db setLikeComparisonOptions:c]; + // Make a new statement + [statement finalizeStatement]; + statement = + [GTMSQLiteStatement statementWithSQL:@"select * from foo where bar like '%LIKE%'" + inDatabase:db + errorCode:&err]; + + STAssertNotNil(statement, @"failed to create statement"); + STAssertEquals(err, SQLITE_OK, @"failed to create statement"); + + err = [statement stepRow]; + STAssertEquals(err, SQLITE_ROW, @"failed to retrieve row!"); +#endif // MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 + // Now reset comparison options [db setLikeComparisonOptions:oldFlags]; @@ -740,10 +765,10 @@ static void TestUpperLower16Impl(sqlite3_context *context, } -// Diacritic & width insensitive collations are not supported -// on Tiger -#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 - (void)testDiacriticAndWidthInsensitiveCollations { + // Diacritic & width insensitive collations are not supported + // on Tiger, so most of the test is Leopard or later +#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 int err; GTMSQLiteDatabase *db = [[[GTMSQLiteDatabase alloc] initInMemoryWithCFAdditions:YES @@ -793,8 +818,30 @@ static void TestUpperLower16Impl(sqlite3_context *context, STAssertEquals([statement stepRow], SQLITE_ROW, @"Comparison ignoring diacritics did not succeed"); [statement finalizeStatement]; +#else + // On Tiger just make sure it causes the dev log. + int err; + GTMSQLiteDatabase *db = + [[[GTMSQLiteDatabase alloc] initInMemoryWithCFAdditions:YES + utf8:YES + errorCode:&err] autorelease]; + STAssertNotNil(db, @"Failed to create DB"); + STAssertEquals(err, SQLITE_OK, @"Failed to create DB"); + + NSString *tableSQL = + @"CREATE TABLE FOOBAR (collated TEXT" + @" COLLATE NODIACRITIC_WIDTHINSENSITIVE_NOCASE," + @" noncollated TEXT);"; + + // Expect one log for each unsupported flag + [GTMUnitTestDevLog expect:2 + casesOfString:@"GTMSQLiteDatabase 10.5 collating not available " + @"on 10.4 or earlier"]; + err = [db executeSQL:tableSQL]; + STAssertEquals(err, SQLITE_OK, @"error creating table"); + +#endif // MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 } -#endif // MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_ - (void)testCFStringLikeGlob { @@ -1119,9 +1166,7 @@ static NSArray* LikeGlobTestHelper(GTMSQLiteDatabase *db, NSString *sql) { id result = [statement resultFoundationObjectAtPosition:0]; if (result) [resultArray addObject:result]; } - if (err != SQLITE_DONE && err != SQLITE_OK) { - resultArray = nil; - } + if (err != SQLITE_DONE && err != SQLITE_OK) resultArray = nil; [statement finalizeStatement]; return resultArray; diff --git a/Foundation/GTMTransientRootProxy.m b/Foundation/GTMTransientRootProxy.m index 4da4eec..33be603 100644 --- a/Foundation/GTMTransientRootProxy.m +++ b/Foundation/GTMTransientRootProxy.m @@ -23,7 +23,7 @@ // been available since 10.0, but Apple didn't add it to the headers until 10.5 #if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4 @interface NSMethodSignature (UndeclaredMethods) -+ (NSMethodSignature *)signatureWithObjCTypes:(const char *)fp8; ++ (NSMethodSignature *)signatureWithObjCTypes:(const char *)types; @end #endif // MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4 @@ -105,8 +105,10 @@ mdesc = protocol_getMethodDescription(protocol_, selector, YES, YES); NSMethodSignature *returnValue = nil; if (mdesc.types == NULL) { + // COV_NF_START _GTMDevLog(@"Unable to get the protocol method description. Returning " @"nil."); + // COV_NF_END } else { returnValue = [NSMethodSignature signatureWithObjCTypes:mdesc.types]; } diff --git a/Foundation/GTMTransientRootProxyTest.m b/Foundation/GTMTransientRootProxyTest.m index e4e7017..063f33f 100644 --- a/Foundation/GTMTransientRootProxyTest.m +++ b/Foundation/GTMTransientRootProxyTest.m @@ -125,7 +125,6 @@ static NSString *const kTestServerName = @"gtm_test_server"; } - (void)testTransientRootProxy { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // Register for server notifications NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; [nc addObserver:self @@ -146,6 +145,23 @@ static NSString *const kTestServerName = @"gtm_test_server"; // Sleep for 1 second to give the new thread time to set stuff up [NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]]; + GTMTransientRootProxy<DOTestProtocol> *failProxy = + [GTMTransientRootProxy rootProxyWithRegisteredName:nil + host:nil + protocol:@protocol(DOTestProtocol) + requestTimeout:kDefaultTimeout + replyTimeout:kDefaultTimeout]; + STAssertNil(failProxy, @"should have failed w/o a name"); + failProxy = + [GTMTransientRootProxy rootProxyWithRegisteredName:serverName + host:nil + protocol:nil + requestTimeout:kDefaultTimeout + replyTimeout:kDefaultTimeout]; + STAssertNil(failProxy, @"should have failed w/o a protocol"); + failProxy = [[[GTMTransientRootProxy alloc] init] autorelease]; + STAssertNil(failProxy, @"should have failed just calling init"); + GTMTransientRootProxy<DOTestProtocol> *proxy = [GTMTransientRootProxy rootProxyWithRegisteredName:serverName host:nil @@ -206,9 +222,9 @@ static NSString *const kTestServerName = @"gtm_test_server"; // Wait for the server to shutdown so we clean up nicely. // The max amount of time we will wait until we abort this test. - NSDate *timeout = [NSDate dateWithTimeIntervalSinceNow:30.0]; + id timeout = [NSDate dateWithTimeIntervalSinceNow:30.0]; while (![self serverStatus] && - ([[[NSDate date] laterDate:timeout] isEqualToDate:timeout])) { + ([[NSDate date] compare:timeout] != NSOrderedDescending)) { NSDate *runUntil = [NSDate dateWithTimeIntervalSinceNow:2.0]; [[NSRunLoop currentRunLoop] runUntilDate:runUntil]; } @@ -216,8 +232,6 @@ static NSString *const kTestServerName = @"gtm_test_server"; // The server did not shutdown and we want to capture this as an error STAssertTrue([self serverStatus], @"The server did not shutdown gracefully " @"before the timeout."); - - [pool drain]; } @end diff --git a/Foundation/GTMTransientRootSocketProxyTest.m b/Foundation/GTMTransientRootSocketProxyTest.m index e14c9c5..dcb5cff 100644 --- a/Foundation/GTMTransientRootSocketProxyTest.m +++ b/Foundation/GTMTransientRootSocketProxyTest.m @@ -133,7 +133,6 @@ } - (void)testTransientRootSocketProxy { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // Register for server notifications NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; [nc addObserver:self @@ -155,6 +154,19 @@ [[NSSocketPort alloc] initRemoteWithTCPPort:[server_ listeningPort] host:@"localhost"]; + GTMTransientRootSocketProxy<DOSocketTestProtocol> *failProxy = + [GTMTransientRootSocketProxy rootProxyWithSocketPort:nil + protocol:@protocol(DOSocketTestProtocol) + requestTimeout:kDefaultTimeout + replyTimeout:kDefaultTimeout]; + STAssertNil(failProxy, @"should have failed w/o a port"); + failProxy = + [GTMTransientRootSocketProxy rootProxyWithSocketPort:receivePort + protocol:nil + requestTimeout:kDefaultTimeout + replyTimeout:kDefaultTimeout]; + STAssertNil(failProxy, @"should have failed w/o a protocol"); + GTMTransientRootSocketProxy<DOSocketTestProtocol> *proxy = [GTMTransientRootSocketProxy rootProxyWithSocketPort:receivePort protocol:@protocol(DOSocketTestProtocol) @@ -181,14 +193,13 @@ // Wait for the server to shutdown so we clean up nicely. The max amount of // time we will wait until we abort this test. - NSDate *timeout = [NSDate dateWithTimeIntervalSinceNow:30.0]; + id timeout = [NSDate dateWithTimeIntervalSinceNow:30.0]; while (![self serverStatus] && - ([[[NSDate date] laterDate:timeout] isEqualToDate:timeout])) { + ([[NSDate date] compare:timeout] != NSOrderedDescending)) { NSDate *runUntil = [NSDate dateWithTimeIntervalSinceNow:2.0]; [[NSRunLoop currentRunLoop] runUntilDate:runUntil]; } - [pool drain]; } @end |