aboutsummaryrefslogtreecommitdiff
path: root/UnitTesting
diff options
context:
space:
mode:
Diffstat (limited to 'UnitTesting')
-rw-r--r--UnitTesting/GTMAppKit+UnitTesting.m14
-rw-r--r--UnitTesting/GTMNSObject+BindingUnitTesting.h3
-rw-r--r--UnitTesting/GTMNSObject+BindingUnitTesting.m6
-rw-r--r--UnitTesting/GTMNSObject+UnitTesting.m13
-rw-r--r--UnitTesting/GTMSenTestCase.m6
-rw-r--r--UnitTesting/GTMUIKit+UnitTesting.m6
-rw-r--r--UnitTesting/GTMUnitTestDevLog.m71
-rw-r--r--UnitTesting/GTMUnitTestingBindingTest.m3
-rwxr-xr-xUnitTesting/RunMacOSUnitTests.sh9
9 files changed, 94 insertions, 37 deletions
diff --git a/UnitTesting/GTMAppKit+UnitTesting.m b/UnitTesting/GTMAppKit+UnitTesting.m
index 0e21491..23c44e3 100644
--- a/UnitTesting/GTMAppKit+UnitTesting.m
+++ b/UnitTesting/GTMAppKit+UnitTesting.m
@@ -37,10 +37,9 @@ GTM_METHOD_CHECK(NSObject, gtm_unitTestEncodeState:);
ENCODE_NSINTEGER(inCoder, [[self mainWindow] windowNumber], @"ApplicationMainWindow");
// Descend down into the windows allowing them to store their state
- NSEnumerator *windowEnum = [[self windows] objectEnumerator];
NSWindow *window = nil;
int i = 0;
- while ((window = [windowEnum nextObject])) {
+ GTM_FOREACH_OBJECT(window, [self windows]) {
if ([window isVisible]) {
// Only record visible windows because invisible windows may be closing on us
// This appears to happen differently in 64 bit vs 32 bit, and items
@@ -190,10 +189,12 @@ GTM_METHOD_CHECK(NSObject, gtm_unitTestEncodeState:);
}
}
// Descend down into the menuitems allowing them to store their state
- NSEnumerator *menuItemEnum = [[self itemArray] objectEnumerator];
NSMenuItem *menuItem = nil;
- for (int i = 0; (menuItem = [menuItemEnum nextObject]); ++i) {
- [inCoder encodeObject:menuItem forKey:[NSString stringWithFormat:@"MenuItem %d", i]];
+ int i = 0;
+ GTM_FOREACH_OBJECT(menuItem, [self itemArray]) {
+ [inCoder encodeObject:menuItem
+ forKey:[NSString stringWithFormat:@"MenuItem %d", i]];
+ ++i;
}
}
@@ -324,10 +325,9 @@ GTM_METHOD_CHECK(NSObject, gtm_unitTestEncodeState:);
[super gtm_unitTestEncodeState:inCoder];
[inCoder encodeBool:[self isHidden] forKey:@"ViewIsHidden"];
if ([self gtm_shouldEncodeStateForSubviews]) {
- NSEnumerator *subviewEnum = [[self subviews] objectEnumerator];
NSView *subview = nil;
int i = 0;
- while ((subview = [subviewEnum nextObject])) {
+ GTM_FOREACH_OBJECT(subview, [self subviews]) {
[inCoder encodeObject:subview forKey:[NSString stringWithFormat:@"ViewSubView %d", i]];
i = i + 1;
}
diff --git a/UnitTesting/GTMNSObject+BindingUnitTesting.h b/UnitTesting/GTMNSObject+BindingUnitTesting.h
index 462bb9b..55c3dfe 100644
--- a/UnitTesting/GTMNSObject+BindingUnitTesting.h
+++ b/UnitTesting/GTMNSObject+BindingUnitTesting.h
@@ -46,9 +46,8 @@ do { \
NSArray *errors = nil; \
BOOL isGood = GTMDoExposedBindingsFunctionCorrectly(a1Object, &errors); \
if (!isGood) { \
- NSEnumerator *errorEnum = [errors objectEnumerator]; \
NSString *failString; \
- while ((failString = [errorEnum nextObject])) { \
+ GTM_FOREACH_OBJECT(failString, errors) { \
if (description) { \
STFail(@"%@: %@", failString, STComposeString(description, ##__VA_ARGS__)); \
} else { \
diff --git a/UnitTesting/GTMNSObject+BindingUnitTesting.m b/UnitTesting/GTMNSObject+BindingUnitTesting.m
index 7a14ad6..d064a47 100644
--- a/UnitTesting/GTMNSObject+BindingUnitTesting.m
+++ b/UnitTesting/GTMNSObject+BindingUnitTesting.m
@@ -31,9 +31,8 @@ BOOL GTMDoExposedBindingsFunctionCorrectly(NSObject *object,
NSArray *bindings = [object exposedBindings];
if ([bindings count]) {
NSArray *bindingsToIgnore = [object gtm_unitTestExposedBindingsToIgnore];
- NSEnumerator *bindingsEnum = [bindings objectEnumerator];
NSString *bindingKey;
- while ((bindingKey = [bindingsEnum nextObject])) {
+ GTM_FOREACH_OBJECT(bindingKey, bindings) {
if (![bindingsToIgnore containsObject:bindingKey]) {
Class theClass = [object valueClassForBinding:bindingKey];
if (!theClass) {
@@ -54,9 +53,8 @@ BOOL GTMDoExposedBindingsFunctionCorrectly(NSObject *object,
} // COV_NF_LINE - compiler bug
NSArray *testValues
= [object gtm_unitTestExposedBindingsTestValues:bindingKey];
- NSEnumerator *testEnum = [testValues objectEnumerator];
GTMBindingUnitTestData *testData;
- while ((testData = [testEnum nextObject])) {
+ GTM_FOREACH_OBJECT(testData, testValues) {
id valueToSet = [testData valueToSet];
[object setValue:valueToSet forKey:bindingKey];
id valueReceived = [object valueForKey:bindingKey];
diff --git a/UnitTesting/GTMNSObject+UnitTesting.m b/UnitTesting/GTMNSObject+UnitTesting.m
index bc94729..f3bfbb1 100644
--- a/UnitTesting/GTMNSObject+UnitTesting.m
+++ b/UnitTesting/GTMNSObject+UnitTesting.m
@@ -417,11 +417,14 @@ static NSString *gGTMUnitTestSaveToDirectory = nil;
// we're on an automated build system, so use the build products dir as an
// override instead of writing on the desktop.
NSDictionary *env = [[NSProcessInfo processInfo] environment];
- NSEnumerator *enumerator = [env keyEnumerator];
- NSString *key = nil;
- while (((key = [enumerator nextObject]) != nil) &&
- ![key hasSuffix:@"BUILD_NUMBER"])
- ;
+ BOOL foundBuildNumber = NO;
+ NSString *key;
+ GTM_FOREACH_KEY(key, env) {
+ if ([key hasSuffix:@"BUILD_NUMBER"]) {
+ foundBuildNumber = YES;
+ break;
+ }
+ }
if (key) {
result = [env objectForKey:@"BUILT_PRODUCTS_DIR"];
}
diff --git a/UnitTesting/GTMSenTestCase.m b/UnitTesting/GTMSenTestCase.m
index 8d45dab..dbd137a 100644
--- a/UnitTesting/GTMSenTestCase.m
+++ b/UnitTesting/GTMSenTestCase.m
@@ -314,10 +314,9 @@ static void _GTMRunLeaks(void) {
if (cExclusionsEnv) {
NSString *exclusionsEnv = [NSString stringWithUTF8String:cExclusionsEnv];
NSArray *exclusionsArray = [exclusionsEnv componentsSeparatedByString:@","];
- NSEnumerator *exclusionsEnum = [exclusionsArray objectEnumerator];
NSString *exclusion;
NSCharacterSet *wcSet = [NSCharacterSet whitespaceCharacterSet];
- while ((exclusion = [exclusionsEnum nextObject])) {
+ GTM_FOREACH_OBJECT(exclusion, exclusionsArray) {
exclusion = [exclusion stringByTrimmingCharactersInSet:wcSet];
[exclusions appendFormat:@"-exclude \"%@\" ", exclusion];
}
@@ -345,7 +344,8 @@ static __attribute__((constructor)) void _GTMInstallLeaks(void) {
if (checkLeaks) {
fprintf(stderr, "Leak Checking Enabled\n");
fflush(stderr);
- _GTMDevAssert(atexit(&_GTMRunLeaks) == 0,
+ int ret = atexit(&_GTMRunLeaks);
+ _GTMDevAssert(ret == 0,
@"Unable to install _GTMRunLeaks as an atexit handler (%d)",
errno);
}
diff --git a/UnitTesting/GTMUIKit+UnitTesting.m b/UnitTesting/GTMUIKit+UnitTesting.m
index d1cf2b2..56460be 100644
--- a/UnitTesting/GTMUIKit+UnitTesting.m
+++ b/UnitTesting/GTMUIKit+UnitTesting.m
@@ -93,13 +93,11 @@
[layer gtm_unitTestEncodeState:inCoder];
}
if ([self gtm_shouldEncodeStateForSubviews]) {
- NSEnumerator *subviewEnum = [[self subviews] objectEnumerator];
- UIView *subview = nil;
int i = 0;
- while ((subview = [subviewEnum nextObject])) {
+ for (UIView *subview in [self subviews]) {
[inCoder encodeObject:subview
forKey:[NSString stringWithFormat:@"ViewSubView %d", i]];
- i = i + 1;
+ i++;
}
}
}
diff --git a/UnitTesting/GTMUnitTestDevLog.m b/UnitTesting/GTMUnitTestDevLog.m
index 227eb11..35e29ae 100644
--- a/UnitTesting/GTMUnitTestDevLog.m
+++ b/UnitTesting/GTMUnitTestDevLog.m
@@ -38,7 +38,7 @@ static void GTMDevLogDebugAssert(OSType componentSignature,
length:StrLength(outputMsg)
encoding:NSMacOSRomanStringEncoding]
autorelease];
- _GTMDevLog(outLog);
+ _GTMDevLog(@"%@", outLog); // Don't want any percents in outLog honored
}
static inline void GTMInstallDebugAssertOutputHandler(void) {
InstallDebugAssertOutputHandler(GTMDevLogDebugAssert);
@@ -51,6 +51,57 @@ static inline void GTMInstallDebugAssertOutputHandler(void) {};
static inline void GTMUninstallDebugAssertOutputHandler(void) {};
#endif // GTM_IPHONE_SDK
+@interface GTMUnttestDevLogAssertionHandler : NSAssertionHandler
+@end
+
+@implementation GTMUnttestDevLogAssertionHandler
+- (void)handleFailureInMethod:(SEL)selector
+ object:(id)object
+ file:(NSString *)fileName
+ lineNumber:(NSInteger)line
+ description:(NSString *)format, ... {
+ va_list argList;
+ va_start(argList, format);
+ NSString *descStr
+ = [[[NSString alloc] initWithFormat:format arguments:argList] autorelease];
+ va_end(argList);
+
+ // You need a format that will be useful in logs, but won't trip up Xcode or
+ // any other build systems parsing of the output.
+ NSString *outLog
+ = [NSString stringWithFormat:@"RecordedNSAssert in %@ - %@ (%@:%ld)",
+ NSStringFromSelector(selector),
+ descStr,
+ fileName, (long)line];
+ _GTMDevLog(@"%@", outLog); // Don't want any percents in outLog honored
+ [NSException raise:NSInternalInconsistencyException
+ format:@"NSAssert raised"];
+}
+
+- (void)handleFailureInFunction:(NSString *)functionName
+ file:(NSString *)fileName
+ lineNumber:(NSInteger)line
+ description:(NSString *)format, ... {
+ va_list argList;
+ va_start(argList, format);
+ NSString *descStr
+ = [[[NSString alloc] initWithFormat:format arguments:argList] autorelease];
+ va_end(argList);
+
+ // You need a format that will be useful in logs, but won't trip up Xcode or
+ // any other build systems parsing of the output.
+ NSString *outLog
+ = [NSString stringWithFormat:@"RecordedNSAssert in %@ - %@ (%@:%ld)",
+ functionName,
+ descStr,
+ fileName, (long)line];
+ _GTMDevLog(@"%@", outLog); // Don't want any percents in outLog honored
+ [NSException raise:NSInternalInconsistencyException
+ format:@"NSAssert raised"];
+}
+
+@end
+
@implementation GTMUnitTestDevLog
// If unittests are ever being run on separate threads, this may need to be
// made a thread local variable.
@@ -70,11 +121,29 @@ static BOOL gTrackingEnabled = NO;
+ (void)enableTracking {
GTMInstallDebugAssertOutputHandler();
+
+ NSMutableDictionary *threadDictionary
+ = [[NSThread currentThread] threadDictionary];
+ if ([threadDictionary objectForKey:@"NSAssertionHandler"] != nil) {
+ NSLog(@"Warning: replacing NSAssertionHandler to capture assertions");
+ }
+
+ // Install an assertion handler to capture those.
+ GTMUnttestDevLogAssertionHandler *handler =
+ [[[GTMUnttestDevLogAssertionHandler alloc] init] autorelease];
+ [threadDictionary setObject:handler forKey:@"NSAssertionHandler"];
+
gTrackingEnabled = YES;
}
+ (void)disableTracking {
GTMUninstallDebugAssertOutputHandler();
+
+ // Clear our assertion handler back out.
+ NSMutableDictionary *threadDictionary
+ = [[NSThread currentThread] threadDictionary];
+ [threadDictionary removeObjectForKey:@"NSAssertionHandler"];
+
gTrackingEnabled = NO;
}
diff --git a/UnitTesting/GTMUnitTestingBindingTest.m b/UnitTesting/GTMUnitTestingBindingTest.m
index aabac43..19ab5b0 100644
--- a/UnitTesting/GTMUnitTestingBindingTest.m
+++ b/UnitTesting/GTMUnitTestingBindingTest.m
@@ -33,9 +33,8 @@
// Iterates through all of our subviews testing the exposed bindings
- (void)doSubviewBindingTest:(NSView*)view {
NSArray *subviews = [view subviews];
- NSEnumerator *subviewEnum = [subviews objectEnumerator];
NSView *subview;
- while ((subview = [subviewEnum nextObject])) {
+ GTM_FOREACH_OBJECT(subview, subviews) {
GTMTestExposedBindings(subview, @"testing %@", subview);
[self doSubviewBindingTest:subview];
}
diff --git a/UnitTesting/RunMacOSUnitTests.sh b/UnitTesting/RunMacOSUnitTests.sh
index f35092b..23897f0 100755
--- a/UnitTesting/RunMacOSUnitTests.sh
+++ b/UnitTesting/RunMacOSUnitTests.sh
@@ -189,15 +189,6 @@ if [ ! $GTM_DISABLE_ZOMBIES ]; then
export NSZombieEnabled=YES
fi
-# If we have debug libraries on the machine, we'll use them
-# unless a target has specifically turned them off
-if [ ! $GTM_NO_DEBUG_FRAMEWORKS ]; then
- if [ -f "/System/Library/Frameworks/CoreFoundation.framework/Versions/Current/CoreFoundation_debug" ]; then
- GTMXcodeNote ${LINENO} "Using _debug frameworks"
- export DYLD_IMAGE_SUFFIX=_debug
- fi
-fi
-
# If leaks testing is enabled, we have to go through our convoluted path
# to handle architectures that don't allow us to do leak testing.
if [ GTM_ENABLE_LEAKS ]; then