aboutsummaryrefslogtreecommitdiff
path: root/UnitTesting
diff options
context:
space:
mode:
authorGravatar gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3>2011-11-02 18:30:18 +0000
committerGravatar gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3>2011-11-02 18:30:18 +0000
commit1204639d4aeeac3d3dda7b0c53b8941266b9e685 (patch)
tree37db0dee0bdaad00e3c6faf9c50d2c3804b598b6 /UnitTesting
parentfe8209a1d04223c70727a4e87cfe53d5bd4192c0 (diff)
[Author: thomasvl]
- Support for localizing non datasource versions of NSComboxBox (http://code.google.com/p/google-toolbox-for-mac/issues/detail?id=77). - Fix up some category names. - Avoid conflicting category names. - Move placeholder string support down to NSTextField instead of NSSearchField. - Support for NSTextField placeholder in unittesting state. - Support for non datasource combobox values in unittesting state. - Fix NSSegmentControl localization support. - Add explicit tests for no localized values and document it in the strings file. - Unittesting for as much as possible of the above. R=dmaclach DELTA=762 (660 added, 55 deleted, 47 changed)
Diffstat (limited to 'UnitTesting')
-rw-r--r--UnitTesting/GTMAppKit+UnitTesting.h51
-rw-r--r--UnitTesting/GTMAppKit+UnitTesting.m197
-rw-r--r--UnitTesting/GTMAppKitUnitTestingUtilities.h30
-rw-r--r--UnitTesting/GTMAppKitUnitTestingUtilities.m96
4 files changed, 220 insertions, 154 deletions
diff --git a/UnitTesting/GTMAppKit+UnitTesting.h b/UnitTesting/GTMAppKit+UnitTesting.h
index 7ef5512..7f6bd26 100644
--- a/UnitTesting/GTMAppKit+UnitTesting.h
+++ b/UnitTesting/GTMAppKit+UnitTesting.h
@@ -1,16 +1,16 @@
//
// GTMAppKit+UnitTesting.m
-//
+//
// Categories for making unit testing of graphics/UI easier.
-//
+//
// Copyright 2006-2008 Google Inc.
//
// 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
@@ -31,13 +31,13 @@
@interface NSWindow (GTMUnitTestingAdditions) <GTMUnitTestingImaging>
@end
-@interface NSControl (GTMUnitTestingAdditions)
+@interface NSControl (GTMUnitTestingAdditions)
@end
-@interface NSTextField (GTMUnitTestingAdditions)
+@interface NSButton (GTMUnitTestingAdditions)
@end
-@interface NSButton (GTMUnitTestingAdditions)
+@interface NSTextField (GTMUnitTestingAdditions)
@end
@interface NSCell (GTMUnitTestingAdditions)
@@ -46,7 +46,7 @@
@interface NSImage (GTMUnitTestingAdditions) <GTMUnitTestingImaging>
@end
-@interface NSMenu (GTMUnitTestingAdditions)
+@interface NSMenu (GTMUnitTestingAdditions)
@end
@interface NSMenuItem (GTMUnitTestingAdditions)
@@ -58,9 +58,24 @@
@interface NSTabViewItem (GTMUnitTestingAdditions)
@end
+@interface NSToolbar (GTMUnitTestingAdditions)
+@end
+
+@interface NSToolbarItem (GTMUnitTestingAdditions)
+@end
+
@interface NSMatrix (GTMUnitTestingAdditions)
@end
+@interface NSBox (GTMUnitTestingAdditions)
+@end
+
+@interface NSSegmentedControl (GTMUnitTestingAdditions)
+@end
+
+@interface NSComboBox (GTMUnitTestingAdditions)
+@end
+
@protocol GTMUnitTestViewDrawer;
// Fails when the |a1|'s drawing in an area |a2| does not equal the image file named |a3|.
@@ -77,8 +92,8 @@
// a3: The name of the image file to check against.
// Do not include the extension
// a4: contextInfo to pass to drawer
-// description: A format string as in the printf() function.
-// Can be nil or an empty string but must be present.
+// description: A format string as in the printf() function.
+// Can be nil or an empty string but must be present.
// ...: A variable number of arguments to the format string. Can be absent.
//
@@ -99,11 +114,11 @@
// See NSObject+UnitTesting.h for details.
@interface NSView (GTMUnitTestingAdditions) <GTMUnitTestingImaging>
// Returns whether unitTestEncodeState should recurse into subviews
-//
-// If you have "Full keyboard access" in the
-// Keyboard & Mouse > Keyboard Shortcuts preferences pane set to "Text boxes
-// and Lists only" that Apple adds a set of subviews to NSTextFields. So in the
-// case of NSTextFields we don't want to recurse into their subviews. There may
+//
+// If you have "Full keyboard access" in the
+// Keyboard & Mouse > Keyboard Shortcuts preferences pane set to "Text boxes
+// and Lists only" that Apple adds a set of subviews to NSTextFields. So in the
+// case of NSTextFields we don't want to recurse into their subviews. There may
// be other cases like this, so instead of specializing unitTestEncodeState: to
// look for NSTextFields, NSTextFields will just not allow us to recurse into
// their subviews.
@@ -114,7 +129,7 @@
@end
-// A view that allows you to delegate out drawing using the formal
+// A view that allows you to delegate out drawing using the formal
// GTMUnitTestViewDelegate protocol
// This is useful when writing up unit tests for visual elements.
// Your test will often end up looking like this:
@@ -127,7 +142,7 @@
// the contents of the file Foo.tif to make sure it's valid
@interface GTMUnitTestView : NSView {
@private
- id<GTMUnitTestViewDrawer> drawer_; // delegate for doing drawing (STRONG)
+ id<GTMUnitTestViewDrawer> drawer_; // delegate for doing drawing (STRONG)
void* contextInfo_; // info passed in by user for them to use when drawing
}
@@ -137,7 +152,7 @@
// rect: the area to draw.
// drawer: the object that will do the drawing via the GTMUnitTestViewDrawer
// protocol
-// contextInfo:
+// contextInfo:
- (id)initWithFrame:(NSRect)frame drawer:(id<GTMUnitTestViewDrawer>)drawer contextInfo:(void*)contextInfo;
@end
diff --git a/UnitTesting/GTMAppKit+UnitTesting.m b/UnitTesting/GTMAppKit+UnitTesting.m
index 1fc0dc1..8bca7ca 100644
--- a/UnitTesting/GTMAppKit+UnitTesting.m
+++ b/UnitTesting/GTMAppKit+UnitTesting.m
@@ -1,16 +1,16 @@
//
// GTMAppKit+UnitTesting.m
-//
+//
// Categories for making unit testing of graphics/UI easier.
-//
+//
// Copyright 2006-2008 Google Inc.
//
// 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
@@ -30,13 +30,13 @@
#define ENCODE_NSINTEGER(coder, i, key) [(coder) encodeInteger:(i) forKey:(key)]
#endif
-@implementation NSApplication (GMUnitTestingAdditions)
+@implementation NSApplication (GTMUnitTestingAdditions)
GTM_METHOD_CHECK(NSObject, gtm_unitTestEncodeState:);
- (void)gtm_unitTestEncodeState:(NSCoder*)inCoder {
[super gtm_unitTestEncodeState:inCoder];
ENCODE_NSINTEGER(inCoder, [[self mainWindow] windowNumber], @"ApplicationMainWindow");
-
+
// Descend down into the windows allowing them to store their state
NSWindow *window = nil;
int i = 0;
@@ -44,15 +44,15 @@ GTM_METHOD_CHECK(NSObject, gtm_unitTestEncodeState:);
if ([window isVisible]) {
// Only record visible windows because invisible windows may be closing on us
// This appears to happen differently in 64 bit vs 32 bit, and items
- // in the window may hold an extra retain count for a while until the
+ // in the window may hold an extra retain count for a while until the
// event loop is spun. To avoid all this, we just don't record non
// visible windows.
- // See rdar://5851458 for details.
+ // See rdar://5851458 for details.
[inCoder encodeObject:window forKey:[NSString stringWithFormat:@"Window %d", i]];
i = i + 1;
}
}
-
+
// and encode the menu bar
NSMenu *mainMenu = [self mainMenu];
if (mainMenu) {
@@ -61,9 +61,9 @@ GTM_METHOD_CHECK(NSObject, gtm_unitTestEncodeState:);
}
@end
-@implementation NSWindow (GMUnitTestingAdditions)
+@implementation NSWindow (GTMUnitTestingAdditions)
-- (CGImageRef)gtm_unitTestImage {
+- (CGImageRef)gtm_unitTestImage {
return [[[self contentView] superview] gtm_unitTestImage];
}
@@ -71,8 +71,8 @@ GTM_METHOD_CHECK(NSObject, gtm_unitTestEncodeState:);
[super gtm_unitTestEncodeState:inCoder];
[inCoder encodeObject:[self title] forKey:@"WindowTitle"];
[inCoder encodeBool:[self isVisible] forKey:@"WindowIsVisible"];
- // Do not record if window is key, because users running unit tests
- // and clicking around to other apps, could change this mid test causing
+ // Do not record if window is key, because users running unit tests
+ // and clicking around to other apps, could change this mid test causing
// issues.
// [inCoder encodeBool:[self isKeyWindow] forKey:@"WindowIsKey"];
[inCoder encodeBool:[self isMainWindow] forKey:@"WindowIsMain"];
@@ -84,7 +84,7 @@ GTM_METHOD_CHECK(NSObject, gtm_unitTestEncodeState:);
@end
-@implementation NSControl (GTMUnitTestingAdditions)
+@implementation NSControl (GTMUnitTestingAdditions)
// Encodes the state of an object in a manner suitable for comparing
// against a master state file so we can determine whether the
@@ -103,7 +103,7 @@ GTM_METHOD_CHECK(NSObject, gtm_unitTestEncodeState:);
@end
-@implementation NSButton (GTMUnitTestingAdditions)
+@implementation NSButton (GTMUnitTestingAdditions)
// Encodes the state of an object in a manner suitable for comparing
// against a master state file so we can determine whether the
@@ -127,9 +127,25 @@ GTM_METHOD_CHECK(NSObject, gtm_unitTestEncodeState:);
return NO;
}
+// Encodes the state of an object in a manner suitable for comparing
+// against a master state file so we can determine whether the
+// object is in a suitable state.
+//
+// Arguments:
+// inCoder - the coder to encode our state into
+- (void)gtm_unitTestEncodeState:(NSCoder*)inCoder {
+ [super gtm_unitTestEncodeState:inCoder];
+ id controlCell = [self cell];
+ if ([controlCell isKindOfClass:[NSTextFieldCell class]]) {
+ NSTextFieldCell *textFieldCell = controlCell;
+ [inCoder encodeObject:[textFieldCell placeholderString]
+ forKey:@"PlaceHolderString"];
+ }
+}
+
@end
-@implementation NSCell (GTMUnitTestingAdditions)
+@implementation NSCell (GTMUnitTestingAdditions)
// Encodes the state of an object in a manner suitable for comparing
// against a master state file so we can determine whether the
@@ -157,7 +173,7 @@ GTM_METHOD_CHECK(NSObject, gtm_unitTestEncodeState:);
@end
-@implementation NSImage (GTMUnitTestingAdditions)
+@implementation NSImage (GTMUnitTestingAdditions)
- (void)gtm_unitTestEncodeState:(NSCoder*)inCoder {
[super gtm_unitTestEncodeState:inCoder];
@@ -172,14 +188,14 @@ GTM_METHOD_CHECK(NSObject, gtm_unitTestEncodeState:);
CGSize cgSize = GTMNSSizeToCGSize(size);
CGContextRef contextRef = GTMCreateUnitTestBitmapContextOfSizeWithData(cgSize,
NULL);
- NSGraphicsContext *bitmapContext
+ NSGraphicsContext *bitmapContext
= [NSGraphicsContext graphicsContextWithGraphicsPort:contextRef flipped:NO];
_GTMDevAssert(bitmapContext, @"Couldn't create ns bitmap context");
-
+
[NSGraphicsContext saveGraphicsState];
[NSGraphicsContext setCurrentContext:bitmapContext];
[self drawInRect:rect fromRect:rect operation:NSCompositeCopy fraction:1.0];
-
+
CGImageRef image = CGBitmapContextCreateImage(contextRef);
CFRelease(contextRef);
[NSGraphicsContext restoreGraphicsState];
@@ -201,7 +217,7 @@ GTM_METHOD_CHECK(NSObject, gtm_unitTestEncodeState:);
// Hack here to work around
// rdar://5881796 Application menu item title wrong when accessed programatically
// which causes us to have different results on x86_64 vs x386.
- // Hack is braced intentionally. We don't record the title of the
+ // Hack is braced intentionally. We don't record the title of the
// "application" menu or it's menu title because they are wrong on 32 bit.
// They appear to work right on 64bit.
{
@@ -246,7 +262,7 @@ GTM_METHOD_CHECK(NSObject, gtm_unitTestEncodeState:);
[inCoder encodeObject:[self toolTip] forKey:@"MenuItemTooltip"];
ENCODE_NSINTEGER(inCoder, [self tag], @"MenuItemTag");
ENCODE_NSINTEGER(inCoder, [self indentationLevel], @"MenuItemIndentationLevel");
-
+
// Do our submenu if neccessary
if ([self hasSubmenu]) {
[inCoder encodeObject:[self submenu] forKey:@"MenuItemSubmenu"];
@@ -255,7 +271,7 @@ GTM_METHOD_CHECK(NSObject, gtm_unitTestEncodeState:);
@end
-@implementation NSTabView (GTMUnitTestingAdditions)
+@implementation NSTabView (GTMUnitTestingAdditions)
// Encodes the state of an object in a manner suitable for comparing
// against a master state file so we can determine whether the
@@ -276,7 +292,7 @@ GTM_METHOD_CHECK(NSObject, gtm_unitTestEncodeState:);
@end
-@implementation NSTabViewItem (GTMUnitTestingAdditions)
+@implementation NSTabViewItem (GTMUnitTestingAdditions)
// Encodes the state of an object in a manner suitable for comparing
// against a master state file so we can determine whether the
@@ -292,7 +308,7 @@ GTM_METHOD_CHECK(NSObject, gtm_unitTestEncodeState:);
@end
-@implementation NSToolbar (GTMUnitTestingAdditions)
+@implementation NSToolbar (GTMUnitTestingAdditions)
// Encodes the state of an object in a manner suitable for comparing
// against a master state file so we can determine whether the
@@ -313,7 +329,7 @@ GTM_METHOD_CHECK(NSObject, gtm_unitTestEncodeState:);
@end
-@implementation NSToolbarItem (GTMUnitTestingAdditions)
+@implementation NSToolbarItem (GTMUnitTestingAdditions)
// Encodes the state of an object in a manner suitable for comparing
// against a master state file so we can determine whether the
@@ -334,7 +350,7 @@ GTM_METHOD_CHECK(NSObject, gtm_unitTestEncodeState:);
@end
-@implementation NSMatrix (GTMUnitTestingAdditions)
+@implementation NSMatrix (GTMUnitTestingAdditions)
// Encodes the state of an object in a manner suitable for comparing
// against a master state file so we can determine whether the
@@ -355,7 +371,7 @@ GTM_METHOD_CHECK(NSObject, gtm_unitTestEncodeState:);
[inCoder encodeSize:[self intercellSpacing] forKey:@"MatrixIntercellSpacing"];
[inCoder encodeObject:[self prototype] forKey:@"MatrixCellPrototype"];
-
+
// Dump the list of cells
NSCell *cell;
long i = 0;
@@ -368,43 +384,6 @@ GTM_METHOD_CHECK(NSObject, gtm_unitTestEncodeState:);
@end
-// A view that allows you to delegate out drawing using the formal
-// GTMUnitTestViewDelegate protocol above. This is useful when writing up unit
-// tests for visual elements.
-// Your test will often end up looking like this:
-// - (void)testFoo {
-// GTMAssertDrawingEqualToFile(self, NSMakeSize(200, 200), @"Foo", nil, nil);
-// }
-// and your testSuite will also implement the unitTestViewDrawRect method to do
-// it's actual drawing. The above creates a view of size 200x200 that draws
-// it's content using |self|'s unitTestViewDrawRect method and compares it to
-// the contents of the file Foo.tif to make sure it's valid
-@implementation GTMUnitTestView
-
-- (id)initWithFrame:(NSRect)frame
- drawer:(id<GTMUnitTestViewDrawer>)drawer
- contextInfo:(void*)contextInfo {
- self = [super initWithFrame:frame];
- if (self != nil) {
- drawer_ = [drawer retain];
- contextInfo_ = contextInfo;
- }
- return self;
-}
-
-- (void)dealloc {
- [drawer_ release];
- [super dealloc];
-}
-
-
-- (void)drawRect:(NSRect)rect {
- [drawer_ gtm_unitTestViewDrawRect:rect contextInfo:contextInfo_];
-}
-
-
-@end
-
@implementation NSBox (GTMUnitTestingAdditions)
// Encodes the state of an object in a manner suitable for comparing
@@ -445,7 +424,79 @@ GTM_METHOD_CHECK(NSObject, gtm_unitTestEncodeState:);
@end
-@implementation NSView (GTMUnitTestingAdditions)
+@implementation NSComboBox (GTMUnitTestingAdditions)
+
+- (BOOL)gtm_shouldEncodeStateForSubviews {
+ // Subclass of NSTextView, don't want subviews for the same reason.
+ return NO;
+}
+
+// Encodes the state of an NSSegmentedControl and all its segments.
+//
+// Arguments:
+// inCoder - the coder to encode state into
+- (void)gtm_unitTestEncodeState:(NSCoder*)inCoder {
+ [super gtm_unitTestEncodeState:inCoder];
+
+ NSInteger aCount = [self numberOfItems];
+ ENCODE_NSINTEGER(inCoder, aCount, @"ComboBoxNumberOfItems");
+ aCount = [self numberOfVisibleItems];
+ ENCODE_NSINTEGER(inCoder, aCount, @"ComboBoxNumberOfVisibleItems");
+
+ // Include the objectValues if it doesn't use a data source.
+ if (![self usesDataSource]) {
+ NSArray *objectValues = [self objectValues];
+ for (NSUInteger i = 0; i < [objectValues count]; ++i) {
+ id value = [objectValues objectAtIndex:i];
+ if ([value isKindOfClass:[NSString class]]) {
+ NSString *key = [NSString stringWithFormat:@"ComboBoxObjectValue %u", i];
+ [inCoder encodeObject:value forKey:key];
+ }
+ }
+ }
+}
+
+@end
+
+
+// A view that allows you to delegate out drawing using the formal
+// GTMUnitTestViewDelegate protocol above. This is useful when writing up unit
+// tests for visual elements.
+// Your test will often end up looking like this:
+// - (void)testFoo {
+// GTMAssertDrawingEqualToFile(self, NSMakeSize(200, 200), @"Foo", nil, nil);
+// }
+// and your testSuite will also implement the unitTestViewDrawRect method to do
+// it's actual drawing. The above creates a view of size 200x200 that draws
+// it's content using |self|'s unitTestViewDrawRect method and compares it to
+// the contents of the file Foo.tif to make sure it's valid
+@implementation GTMUnitTestView
+
+- (id)initWithFrame:(NSRect)frame
+ drawer:(id<GTMUnitTestViewDrawer>)drawer
+ contextInfo:(void*)contextInfo {
+ self = [super initWithFrame:frame];
+ if (self != nil) {
+ drawer_ = [drawer retain];
+ contextInfo_ = contextInfo;
+ }
+ return self;
+}
+
+- (void)dealloc {
+ [drawer_ release];
+ [super dealloc];
+}
+
+
+- (void)drawRect:(NSRect)rect {
+ [drawer_ gtm_unitTestViewDrawRect:rect contextInfo:contextInfo_];
+}
+
+
+@end
+
+@implementation NSView (GTMUnitTestingAdditions)
// Returns an image containing a representation of the object
// suitable for use in comparing against a master image.
@@ -461,10 +512,10 @@ GTM_METHOD_CHECK(NSObject, gtm_unitTestEncodeState:);
CGSize cgSize = GTMNSSizeToCGSize(bounds.size);
CGContextRef contextRef = GTMCreateUnitTestBitmapContextOfSizeWithData(cgSize,
NULL);
- NSGraphicsContext *bitmapContext
+ NSGraphicsContext *bitmapContext
= [NSGraphicsContext graphicsContextWithGraphicsPort:contextRef flipped:NO];
_GTMDevAssert(bitmapContext, @"Couldn't create ns bitmap context");
-
+
// Save our state and turn off font smoothing and antialias.
CGContextSaveGState(contextRef);
CGContextSetShouldSmoothFonts(contextRef, false);
@@ -479,9 +530,9 @@ GTM_METHOD_CHECK(NSObject, gtm_unitTestEncodeState:);
// Returns whether gtm_unitTestEncodeState should recurse into subviews
// of a particular view.
// If you have "Full keyboard access" in the
-// Keyboard & Mouse > Keyboard Shortcuts preferences pane set to "Text boxes
-// and Lists only" that Apple adds a set of subviews to NSTextFields. So in the
-// case of NSTextFields we don't want to recurse into their subviews. There may
+// Keyboard & Mouse > Keyboard Shortcuts preferences pane set to "Text boxes
+// and Lists only" that Apple adds a set of subviews to NSTextFields. So in the
+// case of NSTextFields we don't want to recurse into their subviews. There may
// be other cases like this, so instead of specializing gtm_unitTestEncodeState: to
// look for NSTextFields, NSTextFields will just not allow us to recurse into
// their subviews.
@@ -504,12 +555,12 @@ GTM_METHOD_CHECK(NSObject, gtm_unitTestEncodeState:);
[inCoder encodeObject:[self toolTip] forKey:@"ViewToolTip"];
NSArray *supportedAttrs = [self accessibilityAttributeNames];
if ([supportedAttrs containsObject:NSAccessibilityHelpAttribute]) {
- NSString *help
+ NSString *help
= [self accessibilityAttributeValue:NSAccessibilityHelpAttribute];
[inCoder encodeObject:help forKey:@"ViewAccessibilityHelp"];
}
if ([supportedAttrs containsObject:NSAccessibilityDescriptionAttribute]) {
- NSString *description
+ NSString *description
= [self accessibilityAttributeValue:NSAccessibilityDescriptionAttribute];
[inCoder encodeObject:description forKey:@"ViewAccessibilityDescription"];
}
diff --git a/UnitTesting/GTMAppKitUnitTestingUtilities.h b/UnitTesting/GTMAppKitUnitTestingUtilities.h
index d29f63a..1edccd7 100644
--- a/UnitTesting/GTMAppKitUnitTestingUtilities.h
+++ b/UnitTesting/GTMAppKitUnitTestingUtilities.h
@@ -6,9 +6,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 @@
// This should be called in main, before NSApplicationMain is called.
+ (void)setUpForUIUnitTests;
-// Syntactic sugar combining that checks to see if we are running unittests
+// Syntactic sugar combining that checks to see if we are running unittests
// and then calls setUpForUIUnitTests wrapped up in a NSAutoreleasePool so that
// your main can look like this:
// int main(int argc, const char *argv[]) {
@@ -42,11 +42,11 @@
// the screen saver is active.
+ (BOOL)isScreenSaverActive;
-// Allows for posting either a keydown or a keyup with all the modifiers being
-// applied. Passing a 'g' with NSKeyDown and NSShiftKeyMask
+// Allows for posting either a keydown or a keyup with all the modifiers being
+// applied. Passing a 'g' with NSKeyDown and NSShiftKeyMask
// generates two events (a shift key key down and a 'g' key keydown). Make sure
-// to balance this with a keyup, or things could get confused. Events get posted
-// using the CGRemoteOperation events which means that it gets posted in the
+// to balance this with a keyup, or things could get confused. Events get posted
+// using the CGRemoteOperation events which means that it gets posted in the
// system event queue. Thus you can affect other applications if your app isn't
// the active app (or in some cases, such as hotkeys, even if it is).
// Arguments:
@@ -58,12 +58,12 @@
// cocoaModifiers - an int made up of bit masks. Handles NSAlphaShiftKeyMask,
// NSShiftKeyMask, NSControlKeyMask, NSAlternateKeyMask, and
// NSCommandKeyMask
-+ (void)postKeyEvent:(NSEventType)type
- character:(CGCharCode)keyChar
++ (void)postKeyEvent:(NSEventType)type
+ character:(CGCharCode)keyChar
modifiers:(UInt32)cocoaModifiers;
// Syntactic sugar for posting a keydown immediately followed by a key up event
-// which is often what you really want.
+// which is often what you really want.
// Arguments:
// keyChar - character on the keyboard to type. Make sure it is lower case.
// If you need upper case, pass in the NSShiftKeyMask in the
@@ -72,20 +72,20 @@
// cocoaModifiers - an int made up of bit masks. Handles NSAlphaShiftKeyMask,
// NSShiftKeyMask, NSControlKeyMask, NSAlternateKeyMask, and
// NSCommandKeyMask
-+ (void)postTypeCharacterEvent:(CGCharCode)keyChar
++ (void)postTypeCharacterEvent:(CGCharCode)keyChar
modifiers:(UInt32)cocoaModifiers;
@end
// Some category methods to simplify spinning the runloops in such a way as
// to make tests less flaky, but have them complete as fast as possible.
-@interface NSApplication (GTMUnitTestingAdditions)
-// Has NSApplication call nextEventMatchingMask repeatedly until
-// [context shouldStop] returns YES or it returns nil because the current date
+@interface NSApplication (GTMUnitTestingRunAdditions)
+// Has NSApplication call nextEventMatchingMask repeatedly until
+// [context shouldStop] returns YES or it returns nil because the current date
// is greater than |date|.
// Return YES if the runloop was stopped because [context shouldStop] returned
// YES.
-- (BOOL)gtm_runUntilDate:(NSDate *)date
+- (BOOL)gtm_runUntilDate:(NSDate *)date
context:(id<GTMUnitTestingRunLoopContext>)context;
// Calls -gtm_runUntilDate:context: with the timeout date set to 60 seconds.
diff --git a/UnitTesting/GTMAppKitUnitTestingUtilities.m b/UnitTesting/GTMAppKitUnitTestingUtilities.m
index 551738e..ff9442e 100644
--- a/UnitTesting/GTMAppKitUnitTestingUtilities.m
+++ b/UnitTesting/GTMAppKitUnitTestingUtilities.m
@@ -6,9 +6,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
@@ -44,7 +44,7 @@ static CGKeyCode GTMKeyCodeForCharCode(CGCharCode charCode);
// Give some names to undocumented defaults values
const NSInteger MediumFontSmoothing = 2;
const NSInteger BlueTintedAppearance = 1;
-
+
// This sets up some basic values that we want as our defaults for doing pixel
// based user interface tests. These defaults only apply to the unit test app,
// except or the color profile which will be set system wide, and then
@@ -59,17 +59,17 @@ static CGKeyCode GTMKeyCodeForCharCode(CGCharCode charCode);
// Blue aqua
[defaults setInteger:BlueTintedAppearance forKey:@"AppleAquaColorVariant"];
// Standard highlight colors
- [defaults setObject:@"0.709800 0.835300 1.000000"
+ [defaults setObject:@"0.709800 0.835300 1.000000"
forKey:@"AppleHighlightColor"];
- [defaults setObject:@"0.500000 0.500000 0.500000"
+ [defaults setObject:@"0.500000 0.500000 0.500000"
forKey:@"AppleOtherHighlightColor"];
// Use english plz
[defaults setObject:[NSArray arrayWithObject:@"en"] forKey:@"AppleLanguages"];
// How fast should we draw sheets. This speeds up the sheet tests considerably
[defaults setFloat:.001f forKey:@"NSWindowResizeTime"];
- // Switch over the screen profile to "generic rgb". This installs an
+ // Switch over the screen profile to "generic rgb". This installs an
// atexit handler to return our profile back when we are done.
- GTMSetColorProfileToGenericRGB();
+ GTMSetColorProfileToGenericRGB();
}
+ (void)setUpForUIUnitTestsIfBeingTested {
@@ -84,27 +84,27 @@ static CGKeyCode GTMKeyCodeForCharCode(CGCharCode charCode);
BOOL answer = NO;
ProcessSerialNumber psn;
if (GetFrontProcess(&psn) == noErr) {
- CFDictionaryRef cfProcessInfo
- = ProcessInformationCopyDictionary(&psn,
+ CFDictionaryRef cfProcessInfo
+ = ProcessInformationCopyDictionary(&psn,
kProcessDictionaryIncludeAllInformationMask);
NSDictionary *processInfo = GTMCFAutorelease(cfProcessInfo);
-
+
NSString *bundlePath = [processInfo objectForKey:@"BundlePath"];
// ScreenSaverEngine is the frontmost app if the screen saver is actually
// running Security Agent is the frontmost app if the "enter password"
// dialog is showing
NSString *bundleName = [bundlePath lastPathComponent];
- answer = ([bundleName isEqualToString:@"ScreenSaverEngine.app"]
+ answer = ([bundleName isEqualToString:@"ScreenSaverEngine.app"]
|| [bundleName isEqualToString:@"SecurityAgent.app"]);
}
return answer;
}
-// Allows for posting either a keydown or a keyup with all the modifiers being
-// applied. Passing a 'g' with NSKeyDown and NSShiftKeyMask
+// Allows for posting either a keydown or a keyup with all the modifiers being
+// applied. Passing a 'g' with NSKeyDown and NSShiftKeyMask
// generates two events (a shift key key down and a 'g' key keydown). Make sure
-// to balance this with a keyup, or things could get confused. Events get posted
-// using the CGRemoteOperation events which means that it gets posted in the
+// to balance this with a keyup, or things could get confused. Events get posted
+// using the CGRemoteOperation events which means that it gets posted in the
// system event queue. Thus you can affect other applications if your app isn't
// the active app (or in some cases, such as hotkeys, even if it is).
// Arguments:
@@ -116,8 +116,8 @@ static CGKeyCode GTMKeyCodeForCharCode(CGCharCode charCode);
// cocoaModifiers - an int made up of bit masks. Handles NSAlphaShiftKeyMask,
// NSShiftKeyMask, NSControlKeyMask, NSAlternateKeyMask, and
// NSCommandKeyMask
-+ (void)postKeyEvent:(NSEventType)type
- character:(CGCharCode)keyChar
++ (void)postKeyEvent:(NSEventType)type
+ character:(CGCharCode)keyChar
modifiers:(UInt32)cocoaModifiers {
require(![self isScreenSaverActive], CantWorkWithScreenSaver);
require(type == NSKeyDown || type == NSKeyUp, CantDoEvent);
@@ -135,7 +135,7 @@ CantWorkWithScreenSaver:
}
// Syntactic sugar for posting a keydown immediately followed by a key up event
-// which is often what you really want.
+// which is often what you really want.
// Arguments:
// keyChar - character on the keyboard to type. Make sure it is lower case.
// If you need upper case, pass in the NSShiftKeyMask in the
@@ -158,8 +158,8 @@ BOOL GTMAreCMProfilesEqual(CMProfileRef a, CMProfileRef b) {
CMProfileMD5 bMD5;
CMError aMD5Err = CMGetProfileMD5(a, aMD5);
CMError bMD5Err = CMGetProfileMD5(b, bMD5);
- equal = (!aMD5Err &&
- !bMD5Err &&
+ equal = (!aMD5Err &&
+ !bMD5Err &&
!memcmp(aMD5, bMD5, sizeof(CMProfileMD5))) ? YES : NO;
}
return equal;
@@ -168,7 +168,7 @@ BOOL GTMAreCMProfilesEqual(CMProfileRef a, CMProfileRef b) {
void GTMRestoreColorProfile(void) {
if (gGTMCurrentColorProfile) {
CGDirectDisplayID displayID = CGMainDisplayID();
- CMError error = CMSetProfileByAVID((UInt32)displayID,
+ CMError error = CMSetProfileByAVID((UInt32)displayID,
gGTMCurrentColorProfile);
CMCloseProfile(gGTMCurrentColorProfile);
if (error) {
@@ -177,7 +177,7 @@ void GTMRestoreColorProfile(void) {
_GTMDevLog(@"Failed to restore previous color profile! "
"You may need to open System Preferences : Displays : Color "
"and manually restore your color settings. (Error: %i)", error);
- // COV_NF_END
+ // COV_NF_END
} else {
_GTMDevLog(@"Color profile restored");
}
@@ -204,7 +204,7 @@ void GTMSetColorProfileToGenericRGB(void) {
// No way to force this case in a unittest.
_GTMDevLog(@"Failed to get current color profile. "
"I will not be able to restore your current profile, thus I'm "
- "not changing it. Many unit tests may fail as a result. (Error: %i)",
+ "not changing it. Many unit tests may fail as a result. (Error: %i)",
error);
return;
// COV_NF_END
@@ -217,14 +217,14 @@ void GTMSetColorProfileToGenericRGB(void) {
CFStringRef genericProfileName;
CMCopyProfileDescriptionString(previousProfile, &previousProfileName);
CMCopyProfileDescriptionString(genericProfile, &genericProfileName);
-
- _GTMDevLog(@"Temporarily changing your system color profile from \"%@\" to \"%@\".",
+
+ _GTMDevLog(@"Temporarily changing your system color profile from \"%@\" to \"%@\".",
previousProfileName, genericProfileName);
_GTMDevLog(@"This allows the pixel-based unit-tests to have consistent color "
"values across all machines.");
_GTMDevLog(@"The colors on your screen will change for the duration of the testing.");
-
-
+
+
if ((error = CMSetProfileByAVID((UInt32)displayID, genericProfile))) {
// COV_NF_START
// No way to force this case in a unittest.
@@ -256,30 +256,30 @@ void GTMSetColorProfileToGenericRGB(void) {
// NS*FunctionKeys as well.
static CGKeyCode GTMKeyCodeForCharCode(CGCharCode charCode) {
// character map taken from http://classicteck.com/rbarticles/mackeyboard.php
- int characters[] = {
- 'a', 's', 'd', 'f', 'h', 'g', 'z', 'x', 'c', 'v', 256, 'b', 'q', 'w',
- 'e', 'r', 'y', 't', '1', '2', '3', '4', '6', '5', '=', '9', '7', '-',
- '8', '0', ']', 'o', 'u', '[', 'i', 'p', '\n', 'l', 'j', '\'', 'k', ';',
- '\\', ',', '/', 'n', 'm', '.', '\t', ' ', '`', '\b', 256, '\e'
+ int characters[] = {
+ 'a', 's', 'd', 'f', 'h', 'g', 'z', 'x', 'c', 'v', 256, 'b', 'q', 'w',
+ 'e', 'r', 'y', 't', '1', '2', '3', '4', '6', '5', '=', '9', '7', '-',
+ '8', '0', ']', 'o', 'u', '[', 'i', 'p', '\n', 'l', 'j', '\'', 'k', ';',
+ '\\', ',', '/', 'n', 'm', '.', '\t', ' ', '`', '\b', 256, '\e'
};
-
- // function key map taken from
+
+ // function key map taken from
// file:///Developer/ADC%20Reference%20Library/documentation/Cocoa/Reference/ApplicationKit/ObjC_classic/Classes/NSEvent.html
- int functionKeys[] = {
+ int functionKeys[] = {
// NSUpArrowFunctionKey - NSF12FunctionKey
- 126, 125, 123, 124, 122, 120, 99, 118, 96, 97, 98, 100, 101, 109, 103, 111,
+ 126, 125, 123, 124, 122, 120, 99, 118, 96, 97, 98, 100, 101, 109, 103, 111,
// NSF13FunctionKey - NSF28FunctionKey
- 105, 107, 113, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
- // NSF29FunctionKey - NSScrollLockFunctionKey
- 256, 256, 256, 256, 256, 256, 256, 256, 117, 115, 256, 119, 116, 121, 256, 256,
+ 105, 107, 113, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
+ // NSF29FunctionKey - NSScrollLockFunctionKey
+ 256, 256, 256, 256, 256, 256, 256, 256, 117, 115, 256, 119, 116, 121, 256, 256,
// NSPauseFunctionKey - NSPrevFunctionKey
256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
// NSNextFunctionKey - NSModeSwitchFunctionKey
- 256, 256, 256, 256, 256, 256, 114, 1
- };
-
+ 256, 256, 256, 256, 256, 256, 114, 1
+ };
+
CGKeyCode outCode = 0;
-
+
// Look in the function keys
if (charCode >= NSUpArrowFunctionKey && charCode <= NSModeSwitchFunctionKey) {
outCode = functionKeys[charCode - NSUpArrowFunctionKey];
@@ -295,18 +295,18 @@ static CGKeyCode GTMKeyCodeForCharCode(CGCharCode charCode) {
return outCode;
}
-@implementation NSApplication (GTMUnitTestingAdditions)
+@implementation NSApplication (GTMUnitTestingRunAdditions)
-- (BOOL)gtm_runUntilDate:(NSDate *)date
+- (BOOL)gtm_runUntilDate:(NSDate *)date
context:(id<GTMUnitTestingRunLoopContext>)context {
BOOL contextShouldStop = NO;
while (1) {
contextShouldStop = [context shouldStop];
if (contextShouldStop) break;
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- NSEvent *event = [NSApp nextEventMatchingMask:NSAnyEventMask
- untilDate:date
- inMode:NSDefaultRunLoopMode
+ NSEvent *event = [NSApp nextEventMatchingMask:NSAnyEventMask
+ untilDate:date
+ inMode:NSDefaultRunLoopMode
dequeue:YES];
if (!event) {
[pool drain];