Created
December 4, 2013 12:15
-
-
Save rsaunders100/7786566 to your computer and use it in GitHub Desktop.
How to unit an objective C class with an async callback.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)testAsyncExample | |
{ | |
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); | |
__block BOOL hasRunBlock = NO; | |
[MyClass asyncCallback:^{ | |
hasRunBlock = YES; | |
dispatch_semaphore_signal(semaphore); | |
}]; | |
double timeoutDelayInSeconds = 1.0; | |
dispatch_time_t timeout = dispatch_time(DISPATCH_TIME_NOW, | |
(int64_t)(timeoutDelayInSeconds * NSEC_PER_SEC)); | |
long result = dispatch_semaphore_wait(semaphore, timeout); | |
XCTAssertTrue(result == 0, @"Timed out waiting for semaphore"); | |
XCTAssertTrue(hasRunBlock, @""); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment