diff options
author | gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3> | 2013-01-22 21:00:16 +0000 |
---|---|---|
committer | gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3> | 2013-01-22 21:00:16 +0000 |
commit | 8febd97bcda82909cf52f10860e8b2675c26b4eb (patch) | |
tree | dae2b9b00280b67ab9f64f175327837b81a32b35 /UnitTesting | |
parent | 8b801a69e266d8dbb189ae6a9b890344df5c4bf0 (diff) |
[Author: thorogood]
Adds [GTMTestCase imageFromResource:], as a helper method during tests.
R=thomasvl
APPROVED=thomasvl
DELTA=46 (44 added, 0 deleted, 2 changed)
Diffstat (limited to 'UnitTesting')
-rw-r--r-- | UnitTesting/GTMSenTestCase.h | 24 | ||||
-rw-r--r-- | UnitTesting/GTMSenTestCase.m | 24 |
2 files changed, 46 insertions, 2 deletions
diff --git a/UnitTesting/GTMSenTestCase.h b/UnitTesting/GTMSenTestCase.h index ce3d902..683dc76 100644 --- a/UnitTesting/GTMSenTestCase.h +++ b/UnitTesting/GTMSenTestCase.h @@ -1080,6 +1080,12 @@ GTM_EXTERN NSString *const SenTestLineNumberKey; #endif // GTM_IPHONE_SDK && !GTM_IPHONE_USE_SENTEST +#if GTM_IPHONE_SDK + +@class UIImage; + +#endif // GTM_IPHONE_SDK + // All unittest cases in GTM should inherit from GTMTestCase. It makes sure // to set up our logging system correctly to verify logging calls. // See GTMUnitTestDevLog.h for details @@ -1107,4 +1113,22 @@ GTM_EXTERN NSString *const SenTestLineNumberKey; // "AbstractTest" (case sensitive). + (BOOL)isAbstractTestCase; +#if GTM_IPHONE_SDK +// Returns the UIImage for the the named |resource|. Asserts that the image is +// loaded (is non-nil). +// +// This is required as while under test, [UIImage imageNamed:...] does not +// correctly load images from the resources associated with a test class. +- (UIImage *)imageFromResource:(NSString *)resource; + +#else +// Returns the NSImage for the the named |resource|. Asserts that the image is +// loaded (is non-nil). +// +// This is required as while under test, [NSImage imageNamed:...] does not +// correctly load images from the resources associated with a test class. +- (NSImage *)imageFromResource:(NSString *)resource; + +#endif // GTM_IPHONE_SDK + @end diff --git a/UnitTesting/GTMSenTestCase.m b/UnitTesting/GTMSenTestCase.m index 81724b0..4a7ae8f 100644 --- a/UnitTesting/GTMSenTestCase.m +++ b/UnitTesting/GTMSenTestCase.m @@ -26,9 +26,11 @@ #import "GTMObjC2Runtime.h" #import "GTMUnitTestDevLog.h" -#if !GTM_IPHONE_SDK +#if GTM_IPHONE_SDK +#import <UIKit/UIKit.h> +#else #import "GTMGarbageCollection.h" -#endif // !GTM_IPHONE_SDK +#endif // GTM_IPHONE_SDK #if GTM_IPHONE_SDK && !GTM_IPHONE_USE_SENTEST #import <stdarg.h> @@ -422,6 +424,24 @@ static int MethodSort(id a, id b, void *context) { return [name rangeOfString:@"AbstractTest"].location != NSNotFound; } +#if GTM_IPHONE_SDK +- (UIImage *)imageFromResource:(NSString *)resource { + NSBundle *bundle = [NSBundle bundleForClass:[self class]]; + NSString *path = [bundle pathForResource:resource ofType:nil]; + UIImage *image = [UIImage imageWithContentsOfFile:path]; + STAssertNotNil(image, @"Could not load image from resource: %@", path); + return image; +} +#else +- (NSImage *)imageFromResource:(NSString *)resource { + NSBundle *bundle = [NSBundle bundleForClass:[self class]]; + NSString *path = [bundle pathForResource:resource ofType:nil]; + NSImage *image = [NSImage imageWithContentsOfFile:path]; + STAssertNotNil(image, @"Could not load image from resource: %@", path); + return image; +} +#endif + + (NSArray *)testInvocations { NSArray *invocations = nil; if (![self isAbstractTestCase]) { |