aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3>2012-01-03 16:30:21 +0000
committerGravatar gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3>2012-01-03 16:30:21 +0000
commit9c4dda3b1ce8a1acbb5fa8d31a03dae84e8ab301 (patch)
tree3061f70e5c6e553b4cb32f7662508ca0fabfa736
parent6069593554038b2806f6fa73c0aabcea80b24749 (diff)
[Author: thomasvl]
Add the 10.7 SDK for unit testing support. Add SDK support for iOS unit testing. Map 'arch' to "iPhone"/"iPad" to allow different images/states based on the unit testing form factor. R=dmaclach
-rw-r--r--GTMDefines.h15
-rw-r--r--UnitTesting/GTMNSObject+UnitTesting.h3
-rw-r--r--UnitTesting/GTMNSObject+UnitTesting.m240
3 files changed, 148 insertions, 110 deletions
diff --git a/GTMDefines.h b/GTMDefines.h
index e4e3286..3936daf 100644
--- a/GTMDefines.h
+++ b/GTMDefines.h
@@ -32,14 +32,11 @@
#ifndef MAC_OS_X_VERSION_10_6
#define MAC_OS_X_VERSION_10_6 1060
#endif
+#ifndef MAC_OS_X_VERSION_10_7
+ #define MAC_OS_X_VERSION_10_7 1070
+#endif
// Not all __IPHONE_X macros defined in past SDKs
-#ifndef __IPHONE_2_1
- #define __IPHONE_2_1 20100
-#endif
-#ifndef __IPHONE_2_2
- #define __IPHONE_2_2 20200
-#endif
#ifndef __IPHONE_3_0
#define __IPHONE_3_0 30000
#endif
@@ -52,6 +49,12 @@
#ifndef __IPHONE_4_0
#define __IPHONE_4_0 40000
#endif
+#ifndef __IPHONE_4_3
+ #define __IPHONE_4_3 40300
+#endif
+#ifndef __IPHONE_5_0
+ #define __IPHONE_5_0 50000
+#endif
// ----------------------------------------------------------------------------
// CPP symbols that can be overridden in a prefix to control how the toolbox
diff --git a/UnitTesting/GTMNSObject+UnitTesting.h b/UnitTesting/GTMNSObject+UnitTesting.h
index 3a1d00b..e98828a 100644
--- a/UnitTesting/GTMNSObject+UnitTesting.h
+++ b/UnitTesting/GTMNSObject+UnitTesting.h
@@ -29,6 +29,9 @@
#import "GTMSenTestCase.h"
+// NOTE: for "arch" in the file names on iOS, it is not CPU (armv6, armv7), but
+// instead is "iPhone" or "iPad" for the device form factor.
+
// Utility functions for GTMAssert* Macros. Don't use them directly
// but use the macros below instead
BOOL GTMIsObjectImageEqualToImageNamed(id object,
diff --git a/UnitTesting/GTMNSObject+UnitTesting.m b/UnitTesting/GTMNSObject+UnitTesting.m
index 5e628d3..6bbc2e3 100644
--- a/UnitTesting/GTMNSObject+UnitTesting.m
+++ b/UnitTesting/GTMNSObject+UnitTesting.m
@@ -1,6 +1,6 @@
//
// GTMNSObject+UnitTesting.m
-//
+//
// An informal protocol for doing advanced unittesting with objects.
//
// Copyright 2006-2008 Google Inc.
@@ -8,9 +8,9 @@
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
// use this file except in compliance with the License. You may obtain a copy
// of the License at
-//
+//
// http://www.apache.org/licenses/LICENSE-2.0
-//
+//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -29,7 +29,7 @@
#import <AppKit/AppKit.h>
#endif
-NSString *const GTMUnitTestingEncodedObjectNotification
+NSString *const GTMUnitTestingEncodedObjectNotification
= @"GTMUnitTestingEncodedObjectNotification";
NSString *const GTMUnitTestingEncoderKey = @"GTMUnitTestingEncoderKey";
@@ -48,12 +48,29 @@ const CFStringRef kUTTypeJPEG = CFSTR("public.jpeg");
// or here
@end
-@implementation GTMUnitTestingAdditionsBundleFinder
+@implementation GTMUnitTestingAdditionsBundleFinder
// Nothing here. We're just interested in the name for finding our bundle.
@end
-BOOL GTMIsObjectImageEqualToImageNamed(id object,
- NSString* filename,
+#if GTM_IPHONE_SDK
+static NSString *iOS_Idiom(void) {
+ UIUserInterfaceIdiom idiom;
+#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_3_2
+ idiom = [[UIDevice currentDevice] userInterfaceIdiom];
+#else
+ idiom = UI_USER_INTERFACE_IDIOM();
+#endif
+ if (idiom == UIUserInterfaceIdiomPad) {
+ return @"iPad";
+ }
+ _GTMDevAssert((idiom == UIUserInterfaceIdiomPhone),
+ @"unknown idiom %d", idiom);
+ return @"iPhone";
+}
+#endif // GTM_IPHONE_SDK
+
+BOOL GTMIsObjectImageEqualToImageNamed(id object,
+ NSString* filename,
NSString **error) {
NSString *failString = nil;
if (error) {
@@ -73,24 +90,24 @@ BOOL GTMIsObjectImageEqualToImageNamed(id object,
filename = [filename stringByAppendingString:@"_Failed"];
}
BOOL aSaved = [object gtm_saveToImageNamed:filename];
- NSString *fileNameWithExtension
+ NSString *fileNameWithExtension
= [NSString stringWithFormat:@"%@.%@",
filename, [object gtm_imageExtension]];
NSString *fullSavePath = [object gtm_saveToPathForImageNamed:filename];
if (NO == aSaved) {
if (!aPath) {
failString = [NSString stringWithFormat:@"File %@ did not exist in "
- @"bundle. Tried to save as %@ and failed.",
+ @"bundle. Tried to save as %@ and failed.",
fileNameWithExtension, fullSavePath];
} else {
failString = [NSString stringWithFormat:@"Object image different "
- @"than file %@. Tried to save as %@ and failed.",
+ @"than file %@. Tried to save as %@ and failed.",
aPath, fullSavePath];
}
} else {
if (!aPath) {
failString = [NSString stringWithFormat:@"File %@ did not exist in "
- @" bundle. Saved to %@", fileNameWithExtension,
+ @" bundle. Saved to %@", fileNameWithExtension,
fullSavePath];
} else {
NSString *diffPath = [filename stringByAppendingString:@"_Diff"];
@@ -102,13 +119,13 @@ BOOL GTMIsObjectImageEqualToImageNamed(id object,
if ([data writeToFile:diffPath atomically:YES]) {
failString = [NSString stringWithFormat:@"Object image different "
@"than file %@. Saved image to %@. "
- @"Saved diff to %@",
+ @"Saved diff to %@",
aPath, fullSavePath, diffPath];
} else {
failString = [NSString stringWithFormat:@"Object image different "
@"than file %@. Saved image to %@. Unable to save "
@"diff. Most likely the image and diff are "
- @"different sizes.",
+ @"different sizes.",
aPath, fullSavePath];
}
}
@@ -127,8 +144,8 @@ BOOL GTMIsObjectImageEqualToImageNamed(id object,
return isGood;
}
-BOOL GTMIsObjectStateEqualToStateNamed(id object,
- NSString* filename,
+BOOL GTMIsObjectStateEqualToStateNamed(id object,
+ NSString* filename,
NSString **error) {
NSString *failString = nil;
if (error) {
@@ -152,17 +169,17 @@ BOOL GTMIsObjectStateEqualToStateNamed(id object,
if (NO == aSaved) {
if (!aPath) {
failString = [NSString stringWithFormat:@"File %@ did not exist in "
- @"bundle. Tried to save as %@ and failed.",
+ @"bundle. Tried to save as %@ and failed.",
fileNameWithExtension, fullSavePath];
} else {
failString = [NSString stringWithFormat:@"Object state different "
- @"than file %@. Tried to save as %@ and failed.",
+ @"than file %@. Tried to save as %@ and failed.",
aPath, fullSavePath];
}
} else {
if (!aPath) {
failString = [NSString stringWithFormat:@"File %@ did not exist in "
- @ "bundle. Saved to %@", fileNameWithExtension,
+ @ "bundle. Saved to %@", fileNameWithExtension,
fullSavePath];
} else {
failString = [NSString stringWithFormat:@"Object state different "
@@ -171,7 +188,7 @@ BOOL GTMIsObjectStateEqualToStateNamed(id object,
}
}
} else {
- failString = @"Object does not conform to GTMUnitTestingEncoding protocol";
+ failString = @"Object does not conform to GTMUnitTestingEncoding protocol";
}
if (error) {
*error = failString;
@@ -193,13 +210,13 @@ CGContextRef GTMCreateUnitTestBitmapContextOfSizeWithData(CGSize size,
cs = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
#endif
_GTMDevAssert(cs, @"Couldn't create colorspace");
- CGBitmapInfo info
+ CGBitmapInfo info
= kCGImageAlphaPremultipliedLast | kCGBitmapByteOrderDefault;
if (data) {
*data = (unsigned char*)calloc(bytesPerRow, height);
_GTMDevAssert(*data, @"Couldn't create bitmap");
}
- context = CGBitmapContextCreate(data ? *data : NULL, width, height,
+ context = CGBitmapContextCreate(data ? *data : NULL, width, height,
bitsPerComponent, bytesPerRow, cs, info);
_GTMDevAssert(context, @"Couldn't create an context");
if (!data) {
@@ -211,14 +228,14 @@ CGContextRef GTMCreateUnitTestBitmapContextOfSizeWithData(CGSize size,
CGContextSetAllowsAntialiasing(context, NO);
CGContextSetShouldSmoothFonts(context, NO);
CGColorSpaceRelease(cs);
- return context;
+ return context;
}
@interface NSObject (GTMUnitTestingAdditionsPrivate)
/// Find the path for a file named name.extension in your bundle.
// Searches for the following:
-// "name.extension",
-// "name.arch.extension",
+// "name.extension",
+// "name.arch.extension",
// "name.arch.OSVersionMajor.extension"
// "name.arch.OSVersionMajor.OSVersionMinor.extension"
// "name.arch.OSVersionMajor.OSVersionMinor.OSVersion.bugfix.extension"
@@ -239,9 +256,9 @@ CGContextRef GTMCreateUnitTestBitmapContextOfSizeWithData(CGSize size,
// the path if the file exists in your bundle
// or nil if no file is found
//
-- (NSString *)gtm_pathForFileNamed:(NSString*)name
+- (NSString *)gtm_pathForFileNamed:(NSString*)name
extension:(NSString*)extension;
-- (NSString *)gtm_saveToPathForFileNamed:(NSString*)name
+- (NSString *)gtm_saveToPathForFileNamed:(NSString*)name
extension:(NSString*)extension;
- (CGImageRef)gtm_unitTestImage;
// Returns nil if there is no override
@@ -259,7 +276,7 @@ CGContextRef GTMCreateUnitTestBitmapContextOfSizeWithData(CGSize size,
//
// Returns:
// NSDictionary with currently stored data.
-- (NSDictionary*)dictionary;
+- (NSDictionary*)dictionary;
@end
// Small utility function for checking to see if a is b +/- 1.
@@ -273,7 +290,7 @@ GTM_INLINE BOOL almostEqual(unsigned char a, unsigned char b) {
// Set up storage for coder. Stores type and version.
// Version 1
-//
+//
// Returns:
// self
- (id)init {
@@ -281,7 +298,7 @@ GTM_INLINE BOOL almostEqual(unsigned char a, unsigned char b) {
if (self != nil) {
dictionary_ = [[NSMutableDictionary alloc] initWithCapacity:2];
[dictionary_ setObject:@"GTMUnitTestingArchive" forKey:@"$GTMArchive"];
-
+
// Version number can be changed here.
[dictionary_ setObject:[NSNumber numberWithInt:1] forKey:@"$GTMVersion"];
}
@@ -301,14 +318,14 @@ GTM_INLINE BOOL almostEqual(unsigned char a, unsigned char b) {
// Arguments:
// key - key to check for in dictionary
- (void)checkForKey:(NSString*)key {
- _GTMDevAssert(![dictionary_ objectForKey:key],
+ _GTMDevAssert(![dictionary_ objectForKey:key],
@"Key already exists for %@", key);
}
// Key routine for the encoder. We store objects in our dictionary based on
// their key. As we encode objects we send out notifications to let other
// classes doing tests add their specific data to the base types. If we can't
-// encode the object (it doesn't support gtm_unitTestEncodeState) and we don't
+// encode the object (it doesn't support gtm_unitTestEncodeState) and we don't
// get any info back from the notifier, we attempt to store it's description.
//
// Arguments:
@@ -319,26 +336,26 @@ GTM_INLINE BOOL almostEqual(unsigned char a, unsigned char b) {
// Sanity checks
if (!objv) return;
[self checkForKey:key];
-
+
// Set up a new dictionary for the current object
NSMutableDictionary *curDictionary = dictionary_;
dictionary_ = [[NSMutableDictionary alloc] initWithCapacity:0];
-
+
// If objv responds to gtm_unitTestEncodeState get it to record
// its data.
if ([objv respondsToSelector:@selector(gtm_unitTestEncodeState:)]) {
[objv gtm_unitTestEncodeState:self];
}
-
+
// We then send out a notification to let other folks
// add data for this object
- NSDictionary *notificationDict
+ NSDictionary *notificationDict
= [NSDictionary dictionaryWithObject:self forKey:GTMUnitTestingEncoderKey];
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc postNotificationName:GTMUnitTestingEncodedObjectNotification
object:objv
userInfo:notificationDict];
-
+
// If we got anything from the object, or from the notification, store it in
// our dictionary. Otherwise store the description.
if ([dictionary_ count] > 0) {
@@ -393,17 +410,17 @@ GTM_INLINE BOOL almostEqual(unsigned char a, unsigned char b) {
[dictionary_ setObject:[NSNumber numberWithDouble:realv] forKey:key];
}
-- (void)encodeBytes:(const uint8_t *)bytesp
- length:(NSUInteger)lenv
+- (void)encodeBytes:(const uint8_t *)bytesp
+ length:(NSUInteger)lenv
forKey:(NSString *)key {
[self checkForKey:key];
- [dictionary_ setObject:[NSData dataWithBytes:bytesp
- length:lenv]
+ [dictionary_ setObject:[NSData dataWithBytes:bytesp
+ length:lenv]
forKey:key];
}
// Get our storage back as an NSDictionary
-//
+//
// Returns:
// NSDictionary containing our encoded info
-(NSDictionary*)dictionary {
@@ -434,12 +451,12 @@ static NSString *gGTMUnitTestSaveToDirectory = nil;
NSUserDomainMask, YES);
gGTMUnitTestSaveToDirectory = [documentsDirs objectAtIndex:0];
#else
- NSArray *desktopDirs
- = NSSearchPathForDirectoriesInDomains(NSDesktopDirectory,
+ NSArray *desktopDirs
+ = NSSearchPathForDirectoriesInDomains(NSDesktopDirectory,
NSUserDomainMask,
YES);
gGTMUnitTestSaveToDirectory = [desktopDirs objectAtIndex:0];
-#endif
+#endif
// Did we get overridden?
NSString *override = [self gtm_getOverrideDefaultUnitTestSaveToDirectory];
if (override) {
@@ -449,7 +466,7 @@ static NSString *gGTMUnitTestSaveToDirectory = nil;
}
result = gGTMUnitTestSaveToDirectory;
}
-
+
return result;
}
@@ -470,7 +487,7 @@ static NSString *gGTMUnitTestSaveToDirectory = nil;
if (key) {
result = [env objectForKey:@"BUILT_PRODUCTS_DIR"];
}
-
+
if (result && [result length] == 0) {
result = nil;
}
@@ -505,34 +522,41 @@ static NSString *gGTMUnitTestSaveToDirectory = nil;
// the path if the file exists in your bundle
// or nil if no file is found
//
-- (NSString *)gtm_pathForFileNamed:(NSString*)name
+- (NSString *)gtm_pathForFileNamed:(NSString*)name
extension:(NSString*)extension {
NSString *thePath = nil;
Class bundleClass = [GTMUnitTestingAdditionsBundleFinder class];
NSBundle *myBundle = [NSBundle bundleForClass:bundleClass];
- _GTMDevAssert(myBundle,
- @"Couldn't find bundle for class: %@ searching for file:%@.%@",
+ _GTMDevAssert(myBundle,
+ @"Couldn't find bundle for class: %@ searching for file:%@.%@",
NSStringFromClass(bundleClass), name, extension);
// System Version
SInt32 major, minor, bugFix;
[GTMSystemVersion getMajor:&major minor:&minor bugFix:&bugFix];
NSString *systemVersions[4];
- systemVersions[0] = [NSString stringWithFormat:@".%d.%d.%d",
+ systemVersions[0] = [NSString stringWithFormat:@".%d.%d.%d",
major, minor, bugFix];
systemVersions[1] = [NSString stringWithFormat:@".%d.%d", major, minor];
systemVersions[2] = [NSString stringWithFormat:@".%d", major];
systemVersions[3] = @"";
// Architecture
NSString *architecture[2];
- architecture[0]
- = [NSString stringWithFormat:@".%@",
+#if GTM_IPHONE_SDK
+ architecture[0]
+ = [NSString stringWithFormat:@".%@", iOS_Idiom()];
+#else
+ architecture[0]
+ = [NSString stringWithFormat:@".%@",
[GTMSystemVersion runtimeArchitecture]];
+#endif
architecture[1] = @"";
// Compiler SDK
-#if GTM_MACOS_SDK
// Some times Apple changes how things work based on the SDK built against.
NSString *sdks[2];
-# if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_6
+#if GTM_MACOS_SDK
+# if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_7
+ sdks[0] = @".10_7_SDK";
+# elif MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_6
sdks[0] = @".10_6_SDK";
# elif MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
sdks[0] = @".10_5_SDK";
@@ -547,45 +571,53 @@ static NSString *gGTMUnitTestSaveToDirectory = nil;
# else
sdks[0] = @".10_0_SDK";
# endif
- sdks[1] = @"";
#else // !GTM_MACOS_SDK
- // iPhone doesn't current support SDK specific images (hopefully it won't
- // be needed.
- NSString *sdks[] = { @"" };
+# if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_5_0
+ sdks[0] = @".5_0_SDK";
+# elif __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_3
+ sdks[0] = @".4_3_SDK";
+# else
+ sdks[0] = @"";
+# endif
#endif // GTM_MACOS_SDK
-
+ sdks[1] = @"";
+
// Note that we are searching for the most exact match first.
- for (size_t i = 0;
- !thePath && i < sizeof(sdks) / sizeof(*sdks);
+ for (size_t i = 0;
+ !thePath && i < sizeof(sdks) / sizeof(*sdks);
++i) {
- for (size_t j = 0;
- !thePath && j < sizeof(architecture) / sizeof(*architecture);
+ for (size_t j = 0;
+ !thePath && j < sizeof(architecture) / sizeof(*architecture);
j++) {
for (size_t k = 0;
- !thePath && k < sizeof(systemVersions) / sizeof(*systemVersions);
+ !thePath && k < sizeof(systemVersions) / sizeof(*systemVersions);
k++) {
- NSString *fullName = [NSString stringWithFormat:@"%@%@%@%@",
+ NSString *fullName = [NSString stringWithFormat:@"%@%@%@%@",
name, sdks[i], systemVersions[k], architecture[j]];
thePath = [myBundle pathForResource:fullName ofType:extension];
}
}
}
-
+
return thePath;
-}
+}
-- (NSString *)gtm_saveToPathForFileNamed:(NSString*)name
- extension:(NSString*)extension {
+- (NSString *)gtm_saveToPathForFileNamed:(NSString*)name
+ extension:(NSString*)extension {
+#if GTM_IPHONE_SDK
+ NSString *systemArchitecture = iOS_Idiom();
+#else
NSString *systemArchitecture = [GTMSystemVersion runtimeArchitecture];
-
+#endif
+
SInt32 major, minor, bugFix;
[GTMSystemVersion getMajor:&major minor:&minor bugFix:&bugFix];
-
+
// We don't include the CompilerSDK in here because it is not something that
// that is commonly needed.
- NSString *fullName = [NSString stringWithFormat:@"%@.%d.%d.%d.%@",
+ NSString *fullName = [NSString stringWithFormat:@"%@.%d.%d.%d.%@",
name, major, minor, bugFix, systemArchitecture];
-
+
NSString *basePath = [[self class] gtm_getUnitTestSaveToDirectory];
return [[basePath stringByAppendingPathComponent:fullName]
stringByAppendingPathExtension:extension];
@@ -627,10 +659,10 @@ static NSString *gGTMUnitTestSaveToDirectory = nil;
}
return nil;
#else
- CFStringRef extension
+ CFStringRef extension
= UTTypeCopyPreferredTagWithClass(uti, kUTTagClassFilenameExtension);
_GTMDevAssert(extension, @"No extension for uti: %@", uti);
-
+
return GTMCFAutorelease(extension);
#endif
}
@@ -655,20 +687,20 @@ static NSString *gGTMUnitTestSaveToDirectory = nil;
}
#else
data = [NSMutableData data];
- CGImageDestinationRef dest
+ CGImageDestinationRef dest
= CGImageDestinationCreateWithData((CFMutableDataRef)data,
[self gtm_imageUTI],
1,
NULL);
// LZW Compression for TIFF
- NSDictionary *tiffDict
+ NSDictionary *tiffDict
= [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber gtm_numberWithUnsignedInteger:NSTIFFCompressionLZW],
(const NSString*)kCGImagePropertyTIFFCompression,
nil];
- NSDictionary *destProps
+ NSDictionary *destProps
= [NSDictionary dictionaryWithObjectsAndKeys:
- [NSNumber numberWithFloat:1.0f],
+ [NSNumber numberWithFloat:1.0f],
(const NSString*)kCGImageDestinationLossyCompressionQuality,
tiffDict,
(const NSString*)kCGImagePropertyTIFFDictionary,
@@ -678,11 +710,11 @@ static NSString *gGTMUnitTestSaveToDirectory = nil;
CFRelease(dest);
#endif
return data;
-
+
}
// Save the unitTestImage to an image file with name |name| at
-// ~/Desktop/|name|.extension.
+// ~/Desktop/|name|.extension.
//
// Note: When running under Pulse automation output is redirected to the
// Pulse base directory.
@@ -726,7 +758,7 @@ static NSString *gGTMUnitTestSaveToDirectory = nil;
imageRef = CGImageRetain(image.CGImage);
}
#else
- CFURLRef url = CFURLCreateWithFileSystemPath(NULL, (CFStringRef)path,
+ CFURLRef url = CFURLCreateWithFileSystemPath(NULL, (CFStringRef)path,
kCFURLPOSIXPathStyle, NO);
if (url) {
CGImageSourceRef imageSource = CGImageSourceCreateWithURL(url, NULL);
@@ -757,7 +789,7 @@ static NSString *gGTMUnitTestSaveToDirectory = nil;
}
CGImageRef fileRep = [self gtm_imageWithContentsOfFile:path];
_GTMDevAssert(fileRep, @"Unable to create imagerep from %@", path);
-
+
CGImageRef imageRep = [self gtm_unitTestImage];
_GTMDevAssert(imageRep, @"Unable to create imagerep for %@", self);
@@ -768,16 +800,16 @@ static NSString *gGTMUnitTestSaveToDirectory = nil;
if (fileHeight == imageHeight && fileWidth == imageWidth) {
// if all the sizes are equal, run through the bytes and compare
// them for equality.
- // Do an initial fast check, if this fails and the caller wants a
+ // Do an initial fast check, if this fails and the caller wants a
// diff, we'll do the slow path and create the diff. The diff path
// could be optimized, but probably not necessary at this point.
answer = YES;
-
+
CGSize imageSize = CGSizeMake(fileWidth, fileHeight);
CGRect imageRect = CGRectMake(0, 0, fileWidth, fileHeight);
unsigned char *fileData;
unsigned char *imageData;
- CGContextRef fileContext
+ CGContextRef fileContext
= GTMCreateUnitTestBitmapContextOfSizeWithData(imageSize, &fileData);
_GTMDevAssert(fileContext, @"Unable to create filecontext");
CGContextDrawImage(fileContext, imageRect, fileRep);
@@ -785,14 +817,14 @@ static NSString *gGTMUnitTestSaveToDirectory = nil;
= GTMCreateUnitTestBitmapContextOfSizeWithData(imageSize, &imageData);
_GTMDevAssert(imageContext, @"Unable to create imageContext");
CGContextDrawImage(imageContext, imageRect, imageRep);
-
+
size_t fileBytesPerRow = CGBitmapContextGetBytesPerRow(fileContext);
size_t imageBytesPerRow = CGBitmapContextGetBytesPerRow(imageContext);
size_t row, col;
-
- _GTMDevAssert(imageWidth * 4 <= imageBytesPerRow,
+
+ _GTMDevAssert(imageWidth * 4 <= imageBytesPerRow,
@"We expect image data to be 32bit RGBA");
-
+
for (row = 0; row < fileHeight && answer; row++) {
answer = memcmp(fileData + fileBytesPerRow * row,
imageData + imageBytesPerRow * row,
@@ -801,7 +833,7 @@ static NSString *gGTMUnitTestSaveToDirectory = nil;
if (!answer && diff) {
answer = YES;
unsigned char *diffData;
- CGContextRef diffContext
+ CGContextRef diffContext
= GTMCreateUnitTestBitmapContextOfSizeWithData(imageSize, &diffData);
_GTMDevAssert(diffContext, @"Can't make diff context");
size_t diffRowBytes = CGBitmapContextGetBytesPerRow(diffContext);
@@ -812,7 +844,7 @@ static NSString *gGTMUnitTestSaveToDirectory = nil;
for (col = 0; col < imageWidth; col++) {
uint32_t imageColor = imageRow[col];
uint32_t fileColor = fileRow[col];
-
+
unsigned char imageAlpha = imageColor & 0xF;
unsigned char imageBlue = imageColor >> 8 & 0xF;
unsigned char imageGreen = imageColor >> 16 & 0xF;
@@ -821,7 +853,7 @@ static NSString *gGTMUnitTestSaveToDirectory = nil;
unsigned char fileBlue = fileColor >> 8 & 0xF;
unsigned char fileGreen = fileColor >> 16 & 0xF;
unsigned char fileRed = fileColor >> 24 & 0xF;
-
+
// Check to see if color is almost right.
// No matter how hard I've tried, I've still gotten occasionally
// screwed over by colorspaces not mapping correctly, and small
@@ -835,9 +867,9 @@ static NSString *gGTMUnitTestSaveToDirectory = nil;
if (diff) {
uint32_t newColor;
if (equal) {
- newColor = (((uint32_t)imageRed) << 24) +
- (((uint32_t)imageGreen) << 16) +
- (((uint32_t)imageBlue) << 8) +
+ newColor = (((uint32_t)imageRed) << 24) +
+ (((uint32_t)imageGreen) << 16) +
+ (((uint32_t)imageBlue) << 8) +
(((uint32_t)imageAlpha) / 2);
} else {
newColor = 0xFF0000FF;
@@ -849,7 +881,7 @@ static NSString *gGTMUnitTestSaveToDirectory = nil;
*diff = CGBitmapContextCreateImage(diffContext);
free(diffData);
CFRelease(diffContext);
- }
+ }
free(fileData);
CFRelease(fileContext);
free(imageData);
@@ -869,12 +901,12 @@ static NSString *gGTMUnitTestSaveToDirectory = nil;
// or nil if no image to be found
//
- (NSString *)gtm_pathForImageNamed:(NSString*)name {
- return [self gtm_pathForFileNamed:name
+ return [self gtm_pathForFileNamed:name
extension:[self gtm_imageExtension]];
}
- (NSString *)gtm_saveToPathForImageNamed:(NSString*)name {
- return [self gtm_saveToPathForFileNamed:name
+ return [self gtm_saveToPathForFileNamed:name
extension:[self gtm_imageExtension]];
}
@@ -887,7 +919,7 @@ static NSString *gGTMUnitTestSaveToDirectory = nil;
- (NSData *)gtm_imageRepresentation {
CGImageRef imageRep = [self gtm_unitTestImage];
NSData *data = [self gtm_imageDataForImage:imageRep];
- _GTMDevAssert(data, @"unable to create %@ from %@",
+ _GTMDevAssert(data, @"unable to create %@ from %@",
[self gtm_imageExtension], self);
return data;
}
@@ -964,7 +996,7 @@ static NSString *gGTMUnitTestSaveToDirectory = nil;
}
- (NSString *)gtm_saveToPathForStateNamed:(NSString*)name {
- return [self gtm_saveToPathForFileNamed:name
+ return [self gtm_saveToPathForFileNamed:name
extension:[self gtm_stateExtension]];
}
@@ -996,13 +1028,13 @@ static NSString *gGTMUnitTestSaveToDirectory = nil;
- (void)gtm_unitTestEncodeState:(NSCoder*)inCoder {
// All impls of gtm_unitTestEncodeState
// should be calling [super gtm_unitTestEncodeState] as their first action.
- _GTMDevAssert([inCoder isKindOfClass:[GTMUnitTestingKeyedCoder class]],
+ _GTMDevAssert([inCoder isKindOfClass:[GTMUnitTestingKeyedCoder class]],
@"Coder must be of kind GTMUnitTestingKeyedCoder");
-
+
// If the object has a delegate, give it a chance to respond
if ([self respondsToSelector:@selector(delegate)]) {
id delegate = [self performSelector:@selector(delegate)];
- if (delegate &&
+ if (delegate &&
[delegate respondsToSelector:@selector(gtm_unitTestEncoderWillEncode:inCoder:)]) {
[delegate gtm_unitTestEncoderWillEncode:self inCoder:inCoder];
}