diff options
author | gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3> | 2011-11-02 18:30:18 +0000 |
---|---|---|
committer | gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3> | 2011-11-02 18:30:18 +0000 |
commit | 1204639d4aeeac3d3dda7b0c53b8941266b9e685 (patch) | |
tree | 37db0dee0bdaad00e3c6faf9c50d2c3804b598b6 /UnitTesting/GTMAppKitUnitTestingUtilities.m | |
parent | fe8209a1d04223c70727a4e87cfe53d5bd4192c0 (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/GTMAppKitUnitTestingUtilities.m')
-rw-r--r-- | UnitTesting/GTMAppKitUnitTestingUtilities.m | 96 |
1 files changed, 48 insertions, 48 deletions
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]; |