PageRenderTime 50ms CodeModel.GetById 37ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/core/externals/google-toolbox-for-mac/UnitTesting/GTMAppKitUnitTestingUtilities.h

http://macfuse.googlecode.com/
C++ Header | 93 lines | 17 code | 11 blank | 65 comment | 0 complexity | e8319451851832e4d1a7f8b1f7f2eaca MD5 | raw file
 1//
 2//  GTMAppKitUnitTestingUtilities.h
 3//
 4//  Copyright 2006-2010 Google Inc.
 5//
 6//  Licensed under the Apache License, Version 2.0 (the "License"); you may not
 7//  use this file except in compliance with the License.  You may obtain a copy
 8//  of the License at
 9//
10//  http://www.apache.org/licenses/LICENSE-2.0
11//
12//  Unless required by applicable law or agreed to in writing, software
13//  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14//  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
15//  License for the specific language governing permissions and limitations under
16//  the License.
17//
18
19#import <AppKit/AppKit.h>
20
21#import "GTMFoundationUnitTestingUtilities.h"
22
23// Collection of utilities for unit testing
24@interface GTMAppKitUnitTestingUtilities : NSObject
25
26// Sets up the user interface so that we can run consistent UI unittests on
27// it. This includes setting scroll bar types, setting selection colors
28// setting color spaces etc so that everything is consistent across machines.
29// This should be called in main, before NSApplicationMain is called.
30+ (void)setUpForUIUnitTests;
31
32// Syntactic sugar combining that checks to see if we are running unittests
33// and then calls setUpForUIUnitTests wrapped up in a NSAutoreleasePool so that
34// your main can look like this:
35// int main(int argc, const char *argv[]) {
36//   [UnitTestingUtilities setUpForUIUnitTestsIfBeingTested];
37//   return NSApplicationMain(argc, argv);
38// }
39+ (void)setUpForUIUnitTestsIfBeingTested;
40
41// Check if the screen saver is running. Some unit tests don't work when
42// the screen saver is active.
43+ (BOOL)isScreenSaverActive;
44
45// Allows for posting either a keydown or a keyup with all the modifiers being
46// applied. Passing a 'g' with NSKeyDown and NSShiftKeyMask
47// generates two events (a shift key key down and a 'g' key keydown). Make sure
48// to balance this with a keyup, or things could get confused. Events get posted
49// using the CGRemoteOperation events which means that it gets posted in the
50// system event queue. Thus you can affect other applications if your app isn't
51// the active app (or in some cases, such as hotkeys, even if it is).
52//  Arguments:
53//    type - Event type. Currently accepts NSKeyDown and NSKeyUp
54//    keyChar - character on the keyboard to type. Make sure it is lower case.
55//              If you need upper case, pass in the NSShiftKeyMask in the
56//              modifiers. i.e. to generate "G" pass in 'g' and NSShiftKeyMask.
57//              to generate "+" pass in '=' and NSShiftKeyMask.
58//    cocoaModifiers - an int made up of bit masks. Handles NSAlphaShiftKeyMask,
59//                    NSShiftKeyMask, NSControlKeyMask, NSAlternateKeyMask, and
60//                    NSCommandKeyMask
61+ (void)postKeyEvent:(NSEventType)type
62           character:(CGCharCode)keyChar
63           modifiers:(UInt32)cocoaModifiers;
64
65// Syntactic sugar for posting a keydown immediately followed by a key up event
66// which is often what you really want.
67//  Arguments:
68//    keyChar - character on the keyboard to type. Make sure it is lower case.
69//              If you need upper case, pass in the NSShiftKeyMask in the
70//              modifiers. i.e. to generate "G" pass in 'g' and NSShiftKeyMask.
71//              to generate "+" pass in '=' and NSShiftKeyMask.
72//    cocoaModifiers - an int made up of bit masks. Handles NSAlphaShiftKeyMask,
73//                    NSShiftKeyMask, NSControlKeyMask, NSAlternateKeyMask, and
74//                    NSCommandKeyMask
75+ (void)postTypeCharacterEvent:(CGCharCode)keyChar
76                     modifiers:(UInt32)cocoaModifiers;
77
78@end
79
80// Some category methods to simplify spinning the runloops in such a way as
81// to make tests less flaky, but have them complete as fast as possible.
82@interface NSApplication (GTMUnitTestingRunAdditions)
83// Has NSApplication call nextEventMatchingMask repeatedly until
84// [context shouldStop] returns YES or it returns nil because the current date
85// is greater than |date|.
86// Return YES if the runloop was stopped because [context shouldStop] returned
87// YES.
88- (BOOL)gtm_runUntilDate:(NSDate *)date
89                 context:(id<GTMUnitTestingRunLoopContext>)context;
90
91// Calls -gtm_runUntilDate:context: with the timeout date set to 60 seconds.
92- (BOOL)gtm_runUpToSixtySecondsWithContext:(id<GTMUnitTestingRunLoopContext>)context;
93@end