OLD | NEW |
1 // | 1 // |
2 // GTMSenTestCase.m | 2 // GTMSenTestCase.m |
3 // | 3 // |
4 // Copyright 2007-2008 Google Inc. | 4 // Copyright 2007-2008 Google Inc. |
5 // | 5 // |
6 // Licensed under the Apache License, Version 2.0 (the "License"); you may not | 6 // Licensed under the Apache License, Version 2.0 (the "License"); you may not |
7 // use this file except in compliance with the License. You may obtain a copy | 7 // use this file except in compliance with the License. You may obtain a copy |
8 // of the License at | 8 // of the License at |
9 // | 9 // |
10 // http://www.apache.org/licenses/LICENSE-2.0 | 10 // http://www.apache.org/licenses/LICENSE-2.0 |
11 // | 11 // |
12 // Unless required by applicable law or agreed to in writing, software | 12 // Unless required by applicable law or agreed to in writing, software |
13 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | 13 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
14 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | 14 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
15 // License for the specific language governing permissions and limitations unde
r | 15 // License for the specific language governing permissions and limitations unde
r |
16 // the License. | 16 // the License. |
17 // | 17 // |
18 | 18 |
19 #import "GTMSenTestCase.h" | 19 #import "GTMSenTestCase.h" |
20 | 20 |
21 #import <unistd.h> | 21 #import <unistd.h> |
22 #if GTM_IPHONE_SIMULATOR | 22 #if GTM_IPHONE_SIMULATOR |
23 #import <objc/message.h> | 23 #import <objc/message.h> |
24 #endif | 24 #endif |
25 | 25 |
26 #import "GTMObjC2Runtime.h" | 26 #import "GTMObjC2Runtime.h" |
27 #import "GTMUnitTestDevLog.h" | 27 #import "GTMUnitTestDevLog.h" |
28 | 28 |
29 #if !GTM_IPHONE_SDK | |
30 #import "GTMGarbageCollection.h" | |
31 #endif // !GTM_IPHONE_SDK | |
32 | |
33 #if GTM_IPHONE_SDK && !GTM_IPHONE_USE_SENTEST | 29 #if GTM_IPHONE_SDK && !GTM_IPHONE_USE_SENTEST |
34 #import <stdarg.h> | 30 #import <stdarg.h> |
35 | 31 |
36 @interface NSException (GTMSenTestPrivateAdditions) | 32 @interface NSException (GTMSenTestPrivateAdditions) |
37 + (NSException *)failureInFile:(NSString *)filename | 33 + (NSException *)failureInFile:(NSString *)filename |
38 atLine:(int)lineNumber | 34 atLine:(int)lineNumber |
39 reason:(NSString *)reason; | 35 reason:(NSString *)reason; |
40 @end | 36 @end |
41 | 37 |
42 @implementation NSException (GTMSenTestPrivateAdditions) | 38 @implementation NSException (GTMSenTestPrivateAdditions) |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 | 419 |
424 + (NSArray *)testInvocations { | 420 + (NSArray *)testInvocations { |
425 NSArray *invocations = nil; | 421 NSArray *invocations = nil; |
426 if (![self isAbstractTestCase]) { | 422 if (![self isAbstractTestCase]) { |
427 invocations = [super testInvocations]; | 423 invocations = [super testInvocations]; |
428 } | 424 } |
429 return invocations; | 425 return invocations; |
430 } | 426 } |
431 | 427 |
432 @end | 428 @end |
433 | |
434 // Leak detection | |
435 #if !GTM_IPHONE_DEVICE && !GTM_SUPPRESS_RUN_LEAKS_HOOK | |
436 // Don't want to get leaks on the iPhone Device as the device doesn't | |
437 // have 'leaks'. The simulator does though. | |
438 | |
439 // COV_NF_START | |
440 // We don't have leak checking on by default, so this won't be hit. | |
441 static void _GTMRunLeaks(void) { | |
442 // This is an atexit handler. It runs leaks for us to check if we are | |
443 // leaking anything in our tests. | |
444 const char* cExclusionsEnv = getenv("GTM_LEAKS_SYMBOLS_TO_IGNORE"); | |
445 NSMutableString *exclusions = [NSMutableString string]; | |
446 if (cExclusionsEnv) { | |
447 NSString *exclusionsEnv = [NSString stringWithUTF8String:cExclusionsEnv]; | |
448 NSArray *exclusionsArray = [exclusionsEnv componentsSeparatedByString:@","]; | |
449 NSString *exclusion; | |
450 NSCharacterSet *wcSet = [NSCharacterSet whitespaceCharacterSet]; | |
451 GTM_FOREACH_OBJECT(exclusion, exclusionsArray) { | |
452 exclusion = [exclusion stringByTrimmingCharactersInSet:wcSet]; | |
453 [exclusions appendFormat:@"-exclude \"%@\" ", exclusion]; | |
454 } | |
455 } | |
456 // Clearing out DYLD_ROOT_PATH because iPhone Simulator framework libraries | |
457 // are different from regular OS X libraries and leaks will fail to run | |
458 // because of missing symbols. Also capturing the output of leaks and then | |
459 // pipe rather than a direct pipe, because otherwise if leaks failed, | |
460 // the system() call will still be successful. Bug: | |
461 // http://code.google.com/p/google-toolbox-for-mac/issues/detail?id=56 | |
462 NSString *string | |
463 = [NSString stringWithFormat: | |
464 @"LeakOut=`DYLD_ROOT_PATH='' /usr/bin/leaks %@%d` &&" | |
465 @"echo \"$LeakOut\"|/usr/bin/sed -e 's/Leak: /Leaks:0: warning: Leak /'", | |
466 exclusions, getpid()]; | |
467 int ret = system([string UTF8String]); | |
468 if (ret) { | |
469 fprintf(stderr, | |
470 "%s:%d: Error: Unable to run leaks. 'system' returned: %d\n", | |
471 __FILE__, __LINE__, ret); | |
472 fflush(stderr); | |
473 } | |
474 } | |
475 // COV_NF_END | |
476 | |
477 static __attribute__((constructor)) void _GTMInstallLeaks(void) { | |
478 BOOL checkLeaks = YES; | |
479 #if !GTM_IPHONE_SDK | |
480 checkLeaks = GTMIsGarbageCollectionEnabled() ? NO : YES; | |
481 #endif // !GTM_IPHONE_SDK | |
482 if (checkLeaks) { | |
483 checkLeaks = getenv("GTM_ENABLE_LEAKS") ? YES : NO; | |
484 if (checkLeaks) { | |
485 // COV_NF_START | |
486 // We don't have leak checking on by default, so this won't be hit. | |
487 fprintf(stderr, "Leak Checking Enabled\n"); | |
488 fflush(stderr); | |
489 int ret = atexit(&_GTMRunLeaks); | |
490 // To avoid unused variable warning when _GTMDevAssert is stripped. | |
491 (void)ret; | |
492 _GTMDevAssert(ret == 0, | |
493 @"Unable to install _GTMRunLeaks as an atexit handler (%d)", | |
494 errno); | |
495 // COV_NF_END | |
496 } | |
497 } | |
498 } | |
499 | |
500 #endif // !GTM_IPHONE_DEVICE && !GTM_SUPPRESS_RUN_LEAKS_HOOK | |
OLD | NEW |