aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--UnitTesting/GTMSenTestCase.h24
-rw-r--r--UnitTesting/GTMSenTestCase.m24
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]) {