aboutsummaryrefslogtreecommitdiff
path: root/Foundation/GTMStackTraceTest.m
diff options
context:
space:
mode:
authorGravatar thomasvl@gmail.com <thomasvl@gmail.com@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3>2008-11-04 20:10:52 +0000
committerGravatar thomasvl@gmail.com <thomasvl@gmail.com@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3>2008-11-04 20:10:52 +0000
commit8ddb49cefd01b220ad5e1d2f0060b2a0ad54efdb (patch)
treeb1cb7590d31d8086eb3929028303e1d16324e115 /Foundation/GTMStackTraceTest.m
parent750b28c89618586a0450cacb86e28cd709374c9d (diff)
- Added has ability to check if a script has an open handler to GTMNSAppleScript+Handler.
- GTMStackTrace support for building a trace from the call stack in an NSException (for 10.5+ and iPhone). - Added GTMUIFont+LineHeight. - Cleaned up some OS version checks to use constants instead of numbers directly.
Diffstat (limited to 'Foundation/GTMStackTraceTest.m')
-rw-r--r--Foundation/GTMStackTraceTest.m41
1 files changed, 41 insertions, 0 deletions
diff --git a/Foundation/GTMStackTraceTest.m b/Foundation/GTMStackTraceTest.m
index dc5ea57..01b02a3 100644
--- a/Foundation/GTMStackTraceTest.m
+++ b/Foundation/GTMStackTraceTest.m
@@ -25,6 +25,7 @@
@implementation GTMStackTraceTest
+#ifdef GTM_MACOS_SDK // currently not supported on iPhone
- (void)testStackTraceBasic {
NSString *stacktrace = GTMStackTrace();
NSArray *stacklines = [stacktrace componentsSeparatedByString:@"\n"];
@@ -44,7 +45,46 @@
@"First frame should contain #0, stack trace: %@",
stacktrace);
}
+#endif // GTM_MACOS_SDK
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
+
+- (void)helperThatThrows {
+ [NSException raise:@"TestException" format:@"TestExceptionDescription"];
+}
+
+- (void)testStackExceptionTrace {
+ NSException *exception = nil;
+ @try {
+ [self helperThatThrows];
+ }
+ @catch (NSException * e) {
+ exception = e;
+ }
+ STAssertNotNil(exception, nil);
+ NSString *stacktrace = GTMStackTraceFromException(exception);
+ NSArray *stacklines = [stacktrace componentsSeparatedByString:@"\n"];
+
+ STAssertGreaterThan([stacklines count], (NSUInteger)4,
+ @"stack trace must have > 4 lines");
+ STAssertLessThan([stacklines count], (NSUInteger)25,
+ @"stack trace must have < 25 lines");
+ STAssertEquals([stacklines count],
+ [[exception callStackReturnAddresses] count],
+ @"stack trace should have the same number of lines as the "
+ @" array of return addresses. stack trace: %@", stacktrace);
+
+ // we can't look for it on a specific frame because NSException doesn't
+ // really document how deep the stack will be
+ NSRange range = [stacktrace rangeOfString:@"testStackExceptionTrace"];
+ STAssertNotEquals(range.location, (NSUInteger)NSNotFound,
+ @"Stack trace should contain testStackExceptionTrace,"
+ " stack trace: %@", stacktrace);
+}
+
+#endif
+
+#ifdef GTM_MACOS_SDK // currently not supported on iPhone
- (void)testProgramCountersBasic {
void *pcs[10];
NSUInteger depth = 10;
@@ -80,5 +120,6 @@
void *current_pc = __builtin_return_address(0);
STAssertEquals(pcs2[1], current_pc, @"pcs[1] should equal the current PC");
}
+#endif // GTM_MACOS_SDK
@end