From 30ac0ff87b594d7bca3a5cc2789ca415840ea0b1 Mon Sep 17 00:00:00 2001 From: "gtm.daemon" Date: Wed, 14 Apr 2010 17:08:30 +0000 Subject: [Author: dmaclach] Add utility code to make it faster, easier and more robust to spin runloops during tests. R=thomasvl DELTA=186 (140 added, 19 deleted, 27 changed) --- AppKit/GTMCarbonEventTest.m | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'AppKit/GTMCarbonEventTest.m') diff --git a/AppKit/GTMCarbonEventTest.m b/AppKit/GTMCarbonEventTest.m index ff7fca5..81acbd0 100644 --- a/AppKit/GTMCarbonEventTest.m +++ b/AppKit/GTMCarbonEventTest.m @@ -41,7 +41,7 @@ @interface GTMCarbonEventDispatcherHandlerTest : GTMTestCase { @private - BOOL hotKeyHit_; + GTMUnitTestingBooleanRunLoopContext *hotKeyHit_; } @end @@ -258,6 +258,15 @@ extern EventTargetRef GetApplicationEventTarget(void); @implementation GTMCarbonEventDispatcherHandlerTest +- (void)setUp { + hotKeyHit_ = [[GTMUnitTestingBooleanRunLoopContext alloc] init]; +} + +- (void)tearDown { + [hotKeyHit_ release]; + hotKeyHit_ = nil; +} + - (void)testEventHandler { GTMCarbonEventDispatcherHandler *dispatcher = [GTMCarbonEventDispatcherHandler sharedEventDispatcherHandler]; @@ -265,11 +274,11 @@ extern EventTargetRef GetApplicationEventTarget(void); } - (void)hitHotKey:(id)sender { - hotKeyHit_ = YES; - [NSApp stop:self]; + [hotKeyHit_ setShouldStop:YES]; } - (void)hitExceptionalHotKey:(id)sender { + [hotKeyHit_ setShouldStop:YES]; [NSException raise:@"foo" format:@"bar"]; } @@ -299,16 +308,12 @@ extern EventTargetRef GetApplicationEventTarget(void); whenPressed:YES]; STAssertNotNULL(hotKey, @"Unable to create hotkey"); - hotKeyHit_ = NO; - // Post the hotkey combo to the event queue. If everything is working // correctly hitHotKey: should get called, and hotKeyHit_ will be set for // us. We run the event loop for a set amount of time waiting for this to // happen. [GTMUnitTestingUtilities postTypeCharacterEvent:'g' modifiers:keyMods]; - NSDate* future = [NSDate dateWithTimeIntervalSinceNow:1.0f]; - [GTMUnitTestingUtilities runUntilDate:future]; - STAssertTrue(hotKeyHit_, @"Hot key never got fired."); + STAssertTrue([NSApp gtm_runUpToSixtySecondsWithContext:hotKeyHit_], nil); [dispatcher unregisterHotKey:hotKey]; } } @@ -330,13 +335,13 @@ extern EventTargetRef GetApplicationEventTarget(void); whenPressed:YES]; STAssertTrue(hotKey != nil, @"Unable to create hotkey"); - // Post the hotkey combo to the event queue. If everything is working correctly - // hitHotKey: should get called, and hotKeyHit_ will be set for us. - // We run the event loop for a set amount of time waiting for this to happen. + // Post the hotkey combo to the event queue. If everything is working + // correctly hitHotKey: should get called, and hotKeyHit_ will be set for + // us. We run the event loop for a set amount of time waiting for this to + // happen. [GTMUnitTestingUtilities postTypeCharacterEvent:'g' modifiers:keyMods]; - NSDate* future = [NSDate dateWithTimeIntervalSinceNow:1.0f]; [GTMUnitTestDevLog expectString:@"Exception fired in hotkey: foo (bar)"]; - [GTMUnitTestingUtilities runUntilDate:future]; + STAssertTrue([NSApp gtm_runUpToSixtySecondsWithContext:hotKeyHit_], nil); [dispatcher unregisterHotKey:hotKey]; } } -- cgit v1.2.3