/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. #import <AppKit/AppKit.h>
  19. #import "GTMFoundationUnitTestingUtilities.h"
  20. // Collection of utilities for unit testing
  21. @interface GTMAppKitUnitTestingUtilities : NSObject
  22. // Sets up the user interface so that we can run consistent UI unittests on
  23. // it. This includes setting scroll bar types, setting selection colors
  24. // setting color spaces etc so that everything is consistent across machines.
  25. // This should be called in main, before NSApplicationMain is called.
  26. + (void)setUpForUIUnitTests;
  27. // Syntactic sugar combining that checks to see if we are running unittests
  28. // and then calls setUpForUIUnitTests wrapped up in a NSAutoreleasePool so that
  29. // your main can look like this:
  30. // int main(int argc, const char *argv[]) {
  31. // [UnitTestingUtilities setUpForUIUnitTestsIfBeingTested];
  32. // return NSApplicationMain(argc, argv);
  33. // }
  34. + (void)setUpForUIUnitTestsIfBeingTested;
  35. // Check if the screen saver is running. Some unit tests don't work when
  36. // the screen saver is active.
  37. + (BOOL)isScreenSaverActive;
  38. // Allows for posting either a keydown or a keyup with all the modifiers being
  39. // applied. Passing a 'g' with NSKeyDown and NSShiftKeyMask
  40. // generates two events (a shift key key down and a 'g' key keydown). Make sure
  41. // to balance this with a keyup, or things could get confused. Events get posted
  42. // using the CGRemoteOperation events which means that it gets posted in the
  43. // system event queue. Thus you can affect other applications if your app isn't
  44. // the active app (or in some cases, such as hotkeys, even if it is).
  45. // Arguments:
  46. // type - Event type. Currently accepts NSKeyDown and NSKeyUp
  47. // keyChar - character on the keyboard to type. Make sure it is lower case.
  48. // If you need upper case, pass in the NSShiftKeyMask in the
  49. // modifiers. i.e. to generate "G" pass in 'g' and NSShiftKeyMask.
  50. // to generate "+" pass in '=' and NSShiftKeyMask.
  51. // cocoaModifiers - an int made up of bit masks. Handles NSAlphaShiftKeyMask,
  52. // NSShiftKeyMask, NSControlKeyMask, NSAlternateKeyMask, and
  53. // NSCommandKeyMask
  54. + (void)postKeyEvent:(NSEventType)type
  55. character:(CGCharCode)keyChar
  56. modifiers:(UInt32)cocoaModifiers;
  57. // Syntactic sugar for posting a keydown immediately followed by a key up event
  58. // which is often what you really want.
  59. // Arguments:
  60. // keyChar - character on the keyboard to type. Make sure it is lower case.
  61. // If you need upper case, pass in the NSShiftKeyMask in the
  62. // modifiers. i.e. to generate "G" pass in 'g' and NSShiftKeyMask.
  63. // to generate "+" pass in '=' and NSShiftKeyMask.
  64. // cocoaModifiers - an int made up of bit masks. Handles NSAlphaShiftKeyMask,
  65. // NSShiftKeyMask, NSControlKeyMask, NSAlternateKeyMask, and
  66. // NSCommandKeyMask
  67. + (void)postTypeCharacterEvent:(CGCharCode)keyChar
  68. modifiers:(UInt32)cocoaModifiers;
  69. @end
  70. // Some category methods to simplify spinning the runloops in such a way as
  71. // to make tests less flaky, but have them complete as fast as possible.
  72. @interface NSApplication (GTMUnitTestingRunAdditions)
  73. // Has NSApplication call nextEventMatchingMask repeatedly until
  74. // [context shouldStop] returns YES or it returns nil because the current date
  75. // is greater than |date|.
  76. // Return YES if the runloop was stopped because [context shouldStop] returned
  77. // YES.
  78. - (BOOL)gtm_runUntilDate:(NSDate *)date
  79. context:(id<GTMUnitTestingRunLoopContext>)context;
  80. // Calls -gtm_runUntilDate:context: with the timeout date set to 60 seconds.
  81. - (BOOL)gtm_runUpToSixtySecondsWithContext:(id<GTMUnitTestingRunLoopContext>)context;
  82. @end