-
Notifications
You must be signed in to change notification settings - Fork 576
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #119 from BoltsFramework/nlutsenko.coverage
Add more tests, remove dead code to improve code coverage.
- Loading branch information
Showing
9 changed files
with
218 additions
and
92 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Copyright (c) 2014, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
*/ | ||
|
||
#import <XCTest/XCTest.h> | ||
|
||
#import "Bolts.h" | ||
|
||
@interface ExecutorTests : XCTestCase | ||
|
||
@end | ||
|
||
@implementation ExecutorTests | ||
|
||
- (void)testExecuteImmediately { | ||
__block BFTask *task = [BFTask taskWithResult:nil]; | ||
|
||
XCTestExpectation *expectation = [self expectationWithDescription:@"test immediate executor"]; | ||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ | ||
task = [task continueWithExecutor:[BFExecutor immediateExecutor] withBlock:^id(BFTask *task) { | ||
return nil; | ||
}]; | ||
XCTAssertTrue(task.completed); | ||
[expectation fulfill]; | ||
}); | ||
[self waitForExpectationsWithTimeout:10.0 handler:nil]; | ||
} | ||
|
||
- (void)testExecuteOnDispatchQueue { | ||
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0L); | ||
BFExecutor *queueExecutor = [BFExecutor executorWithDispatchQueue:queue]; | ||
|
||
BFTask *task = [BFTask taskWithResult:nil]; | ||
task = [task continueWithExecutor:queueExecutor withBlock:^id(BFTask *task) { | ||
XCTAssertEqual(queue, dispatch_get_current_queue()); | ||
return nil; | ||
}]; | ||
[task waitUntilFinished]; | ||
} | ||
|
||
- (void)testExecuteOnOperationQueue { | ||
NSOperationQueue *queue = [[NSOperationQueue alloc] init]; | ||
BFExecutor *queueExecutor = [BFExecutor executorWithOperationQueue:queue]; | ||
|
||
BFTask *task = [BFTask taskWithResult:nil]; | ||
task = [task continueWithExecutor:queueExecutor withBlock:^id(BFTask *task) { | ||
XCTAssertEqual(queue, [NSOperationQueue currentQueue]); | ||
return nil; | ||
}]; | ||
[task waitUntilFinished]; | ||
} | ||
|
||
- (void)testMainThreadExecutor { | ||
BFExecutor *executor = [BFExecutor mainThreadExecutor]; | ||
|
||
XCTestExpectation *immediateExpectation = [self expectationWithDescription:@"test main thread executor on main thread"]; | ||
[executor execute:^{ | ||
XCTAssertTrue([NSThread isMainThread]); | ||
[immediateExpectation fulfill]; | ||
}]; | ||
|
||
// Behaviour is different when running on main thread (runs immediately) vs running on the background queue. | ||
XCTestExpectation *backgroundExpectation = [self expectationWithDescription:@"test main thread executor on background thread"]; | ||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ | ||
[executor execute:^{ | ||
XCTAssertTrue([NSThread isMainThread]); | ||
[backgroundExpectation fulfill]; | ||
}]; | ||
}); | ||
|
||
[self waitForExpectationsWithTimeout:10.0 handler:nil]; | ||
} | ||
|
||
@end |
Oops, something went wrong.