Update test case

This commit is contained in:
DreamPiggy 2023-01-09 22:14:53 +08:00
parent e21e9f19e6
commit 397f851240
1 changed files with 22 additions and 9 deletions

View File

@ -157,35 +157,48 @@
- (void)testSDCallbackQueue {
XCTestExpectation *expectation1 = [self expectationWithDescription:@"SDCallbackQueue SafeExecute works"];
XCTestExpectation *expectation2 = [self expectationWithDescription:@"SDCallbackQueue Dispatch works"];
XCTestExpectation *expectation3 = [self expectationWithDescription:@"SDCallbackQueue Invoke works"];
dispatch_queue_t queue = dispatch_queue_create("testSDCallbackQueue", NULL);
SDCallbackQueue *callbackQueue = [[SDCallbackQueue alloc] initWithDispatchQueue:queue];
__block BOOL called1 = NO;
__block BOOL called = NO;
[callbackQueue sync:^{
called1 = YES;
called = YES;
}];
expect(called1).beTruthy();
expect(called).beTruthy();
__block BOOL called2 = NO;
__block BOOL called1 = NO;
callbackQueue.policy = SDCallbackPolicySafeExecute;
dispatch_async(queue, ^{
// Should execute in sync
[callbackQueue async:^{
called2 = YES;
called1 = YES;
[expectation1 fulfill];
}];
expect(called2).beTruthy();
expect(called1).beTruthy();
});
SDCallbackQueue *callbackQueue2 = [[SDCallbackQueue alloc] initWithDispatchQueue:queue];
__block BOOL called3 = NO;
__block BOOL called2 = NO;
callbackQueue2.policy = SDCallbackPolicyDispatch;
dispatch_async(queue, ^{
// Should execute in async
[callbackQueue2 async:^{
called3 = YES;
called2 = YES;
[expectation2 fulfill];
}];
expect(called3).beFalsy();
expect(called2).beFalsy();
});
SDCallbackQueue *callbackQueue3 = [[SDCallbackQueue alloc] initWithDispatchQueue:queue];
__block BOOL called3 = NO;
callbackQueue3.policy = SDCallbackPolicyInvoke;
dispatch_async(queue, ^{
// Should execute in sync
[callbackQueue3 async:^{
called3 = YES;
[expectation3 fulfill];
}];
expect(called3).beTruthy();
});
[self waitForExpectationsWithCommonTimeout];