From eba02dc2256ac28b8d888c55fc8fba92cf499d05 Mon Sep 17 00:00:00 2001 From: dmaclach Date: Mon, 12 Nov 2018 07:58:27 -0800 Subject: Move GTMCarbonEvent over to XCTestExpectation (#188) --- AppKit/GTMCarbonEventTest.m | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/AppKit/GTMCarbonEventTest.m b/AppKit/GTMCarbonEventTest.m index ed18342..a9c6bf2 100644 --- a/AppKit/GTMCarbonEventTest.m +++ b/AppKit/GTMCarbonEventTest.m @@ -40,7 +40,7 @@ @interface GTMCarbonEventDispatcherHandlerTest : GTMTestCase { @private - GTMUnitTestingBooleanRunLoopContext *hotKeyHit_; + XCTestExpectation *hotKeyHitExpectation_; } @end @@ -257,15 +257,6 @@ extern EventTargetRef GetApplicationEventTarget(void); @implementation GTMCarbonEventDispatcherHandlerTest -- (void)setUp { - hotKeyHit_ = [[GTMUnitTestingBooleanRunLoopContext alloc] init]; -} - -- (void)tearDown { - [hotKeyHit_ release]; - hotKeyHit_ = nil; -} - - (void)testEventHandler { GTMCarbonEventDispatcherHandler *dispatcher = [GTMCarbonEventDispatcherHandler sharedEventDispatcherHandler]; @@ -274,12 +265,12 @@ extern EventTargetRef GetApplicationEventTarget(void); - (void)hitHotKey:(GTMCarbonHotKey *)key { XCTAssertEqualObjects([key userInfo], self); - [hotKeyHit_ setShouldStop:YES]; + [hotKeyHitExpectation_ fulfill]; } - (void)hitExceptionalHotKey:(GTMCarbonHotKey *)key { XCTAssertEqualObjects([key userInfo], self); - [hotKeyHit_ setShouldStop:YES]; + [hotKeyHitExpectation_ fulfill]; [NSException raise:@"foo" format:@"bar"]; } @@ -309,11 +300,12 @@ extern EventTargetRef GetApplicationEventTarget(void); XCTAssertNotNil(hotKey, @"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. + // correctly hitHotKey: should get called, and hotKeyHitExpecatation_ will + // be set for us. We run the event loop for a set amount of time waiting for + // this to happen. + hotKeyHitExpectation_ = [self expectationWithDescription:@"hotKey"]; [GTMAppKitUnitTestingUtilities postTypeCharacterEvent:'g' modifiers:keyMods]; - XCTAssertTrue([NSApp gtm_runUpToSixtySecondsWithContext:hotKeyHit_]); + [self waitForExpectationsWithTimeout:60 handler:NULL]; [dispatcher unregisterHotKey:hotKey]; } } @@ -338,11 +330,12 @@ extern EventTargetRef GetApplicationEventTarget(void); XCTAssertNotNil(hotKey, @"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. + // correctly hitHotKey: should get called, and hotKeyHitExpecatation_ will + // be set for us. We run the event loop for a set amount of time waiting for + // this to happen. + hotKeyHitExpectation_ = [self expectationWithDescription:@"hotKey"]; [GTMAppKitUnitTestingUtilities postTypeCharacterEvent:'g' modifiers:keyMods]; - XCTAssertTrue([NSApp gtm_runUpToSixtySecondsWithContext:hotKeyHit_]); + [self waitForExpectationsWithTimeout:60 handler:NULL]; [dispatcher unregisterHotKey:hotKey]; } } -- cgit v1.2.3