aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar thomasvl@gmail.com <thomasvl@gmail.com@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3>2009-03-11 17:24:33 +0000
committerGravatar thomasvl@gmail.com <thomasvl@gmail.com@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3>2009-03-11 17:24:33 +0000
commit483e8d866b40a298fcc28f7a8b670ff74f11c5ab (patch)
tree5582fa69ad5301c450e213db2cd36d7727af60f2
parenta5ada143459a5858341030c33180b36f7542e4d1 (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.
-rw-r--r--AppKit/GTMNSWorkspace+Running.m7
-rw-r--r--AppKit/GTMTheme.h2
-rw-r--r--Foundation/GTMSQLite.m12
-rw-r--r--Foundation/GTMSQLiteTest.m61
-rw-r--r--Foundation/GTMTransientRootProxy.m4
-rw-r--r--Foundation/GTMTransientRootProxyTest.m24
-rw-r--r--Foundation/GTMTransientRootSocketProxyTest.m19
-rw-r--r--UnitTesting/GTMUnitTestDevLog.h3
-rw-r--r--UnitTesting/GTMUnitTestDevLog.m9
-rw-r--r--XcodeConfig/subconfig/GTMMerge.xcconfig17
10 files changed, 127 insertions, 31 deletions
diff --git a/AppKit/GTMNSWorkspace+Running.m b/AppKit/GTMNSWorkspace+Running.m
index 3c31e6b..973ad22 100644
--- a/AppKit/GTMNSWorkspace+Running.m
+++ b/AppKit/GTMNSWorkspace+Running.m
@@ -150,6 +150,10 @@ NSString *const kGTMWorkspaceRunningBundleVersion = @"CFBundleVersion";
long long temp = [number longLongValue];
UInt32 hi = (UInt32)((temp >> 32) & 0x00000000FFFFFFFFLL);
UInt32 lo = (UInt32)((temp >> 0) & 0x00000000FFFFFFFFLL);
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
+ outPSN.highLongOfPSN = hi;
+ outPSN.lowLongOfPSN = lo;
+#else // MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4
if ([GTMSystemVersion isLeopardOrGreater]) {
outPSN.highLongOfPSN = hi;
outPSN.lowLongOfPSN = lo;
@@ -160,8 +164,9 @@ NSString *const kGTMWorkspaceRunningBundleVersion = @"CFBundleVersion";
#else
outPSN.highLongOfPSN = lo;
outPSN.lowLongOfPSN = hi;
-#endif
+#endif // TARGET_RT_BIG_ENDIAN
}
+#endif // MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4
}
return outPSN;
}
diff --git a/AppKit/GTMTheme.h b/AppKit/GTMTheme.h
index 484e8dc..5f4700e 100644
--- a/AppKit/GTMTheme.h
+++ b/AppKit/GTMTheme.h
@@ -17,7 +17,7 @@
//
#import "GTMDefines.h"
-#import <Foundation/Foundation.h>
+#import <AppKit/AppKit.h>
#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
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
diff --git a/UnitTesting/GTMUnitTestDevLog.h b/UnitTesting/GTMUnitTestDevLog.h
index d88ef2e..30c7077 100644
--- a/UnitTesting/GTMUnitTestDevLog.h
+++ b/UnitTesting/GTMUnitTestDevLog.h
@@ -27,6 +27,9 @@
// test to spit out, and it will cause any that don't match to appear as errors
// in your unittest run output. You can match on exact strings or standard
// regexps.
+// Set GTM_SHOW_UNITTEST_DEVLOGS in the environment to show the logs that that
+// are expected and encountered. Otherwise they aren't display to keep the
+// unit test results easier to read.
@interface GTMUnitTestDevLog : NSObject
// Log a message
diff --git a/UnitTesting/GTMUnitTestDevLog.m b/UnitTesting/GTMUnitTestDevLog.m
index 35e29ae..f2f9418 100644
--- a/UnitTesting/GTMUnitTestDevLog.m
+++ b/UnitTesting/GTMUnitTestDevLog.m
@@ -177,7 +177,14 @@ static BOOL gTrackingEnabled = NO;
format:@"Unexpected log: %@", logString];
}
} else {
- NSLog(@"Expected Log: %@", logString);
+ static BOOL envChecked = NO;
+ static BOOL showExpectedLogs = YES;
+ if (!envChecked) {
+ showExpectedLogs = getenv("GTM_SHOW_UNITTEST_DEVLOGS") ? YES : NO;
+ }
+ if (showExpectedLogs) {
+ NSLog(@"Expected Log: %@", logString);
+ }
}
}
} else {
diff --git a/XcodeConfig/subconfig/GTMMerge.xcconfig b/XcodeConfig/subconfig/GTMMerge.xcconfig
index 33d3e70..5ab141e 100644
--- a/XcodeConfig/subconfig/GTMMerge.xcconfig
+++ b/XcodeConfig/subconfig/GTMMerge.xcconfig
@@ -28,8 +28,15 @@
// C++ files. OTHER_CFLAGS is the only way to set C specific settings on our
// C files that we don't want to have applied to our C++ files such as
// -Wold-style-definition
-WARNING_CFLAGS = $(inherited) $(GTM_GENERAL_WARNING_CFLAGS) $(GTM_PLATFORM_WARNING_CFLAGS) $(GTM_CONFIGURATION_WARNING_CFLAGS)
-OTHER_CFLAGS = $(inherited) $(GTM_GENERAL_OTHER_CFLAGS) $(GTM_PLATFORM_OTHER_CFLAGS) $(GTM_CONFIGURATION_OTHER_CFLAGS)
-OTHER_CPLUSPLUSFLAGS = $(GTM_GENERAL_OTHER_CPLUSPLUSFLAGS) $(GTM_PLATFORM_OTHER_CPLUSPLUSFLAGS) $(GTM_CONFIGURATION_OTHER_CPLUSPLUSFLAGS)
-GCC_PREPROCESSOR_DEFINITIONS = $(inherited) $(GTM_GENERAL_GCC_PREPROCESSOR_DEFINITIONS) $(GTM_PLATFORM_GCC_PREPROCESSOR_DEFINITIONS) $(GTM_CONFIGURATION_GCC_PREPROCESSOR_DEFINITIONS)
-OTHER_LDFLAGS = $(inherited) $(GTM_GENERAL_OTHER_LDFLAGS) $(GTM_PLATFORM_OTHER_LDFLAGS) $(GTM_CONFIGURATION_OTHER_LDFLAGS)
+// If you would like to add your own custom settings to the base GTM ones
+// please use the GTM_HOST_* settings. These are left empty by GTM and are
+// for the host app to fill in. For example if you wanted to have stack
+// protection turned on for both debug and release builds you could set
+// GTM_HOST_OTHER_CFLAGS = -fstack-protector -fstack-protector-all
+// in your own settings files, and then include the QSB ones.
+
+WARNING_CFLAGS = $(inherited) $(GTM_GENERAL_WARNING_CFLAGS) $(GTM_PLATFORM_WARNING_CFLAGS) $(GTM_CONFIGURATION_WARNING_CFLAGS) $(GTM_HOST_WARNING_CFLAGS)
+OTHER_CFLAGS = $(inherited) $(GTM_GENERAL_OTHER_CFLAGS) $(GTM_PLATFORM_OTHER_CFLAGS) $(GTM_CONFIGURATION_OTHER_CFLAGS) $(GTM_HOST_OTHER_CFLAGS)
+OTHER_CPLUSPLUSFLAGS = $(GTM_GENERAL_OTHER_CPLUSPLUSFLAGS) $(GTM_PLATFORM_OTHER_CPLUSPLUSFLAGS) $(GTM_CONFIGURATION_OTHER_CPLUSPLUSFLAGS) $(GTM_HOST_OTHER_CPLUSPLUSFLAGS)
+GCC_PREPROCESSOR_DEFINITIONS = $(inherited) $(GTM_GENERAL_GCC_PREPROCESSOR_DEFINITIONS) $(GTM_PLATFORM_GCC_PREPROCESSOR_DEFINITIONS) $(GTM_CONFIGURATION_GCC_PREPROCESSOR_DEFINITIONS) $(GTM_HOST_GCC_PREPROCESSOR_DEFINITIONS)
+OTHER_LDFLAGS = $(inherited) $(GTM_GENERAL_OTHER_LDFLAGS) $(GTM_PLATFORM_OTHER_LDFLAGS) $(GTM_CONFIGURATION_OTHER_LDFLAGS) $(GTM_HOST_OTHER_LDFLAGS)