Last active
December 13, 2017 06:41
-
-
Save levantAJ/839542deb121c4c644f87e81049050d2 to your computer and use it in GitHub Desktop.
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)applicationDidEnterBackground:(UIApplication *)application { | |
@weakify(self); | |
self.backgroundTaskIdentifier = [application beginBackgroundTaskWithExpirationHandler:^{ | |
@strongify(self); | |
[application endBackgroundTask:self.backgroundTaskIdentifier]; | |
self.backgroundTaskIdentifier = UIBackgroundTaskInvalid; | |
}]; | |
} | |
- (void)testApplicationDidEnterBackgroundExpirationHandler { | |
//Given: | |
NSUInteger identifier = 1; | |
__block void (^expirationHandler)(void); | |
OCMStub([self.application beginBackgroundTaskWithExpirationHandler:OCMOCK_ANY]).andDo(^(NSInvocation *invocation) { | |
void (^handler)(void); | |
[invocation getArgument:&handler atIndex:2]; | |
expirationHandler = [handler copy]; | |
// NSValue *returnValue = [NSValue valueWithBytes:&identifier objCType:@encode(NSUInteger)]; | |
void *value = (void *)identifier; | |
[invocation setReturnValue:&value]; | |
}); | |
//When: | |
[self.appDelegate applicationDidEnterBackground:self.application]; | |
expirationHandler(); | |
//Then: | |
OCMVerify([self.application endBackgroundTask:identifier]); | |
XCTAssertEqual(self.appDelegate.backgroundTaskIdentifier, UIBackgroundTaskInvalid); | |
XCTAssertNotEqual(self.appDelegate.backgroundTaskIdentifier, identifier); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment