Switch to Xcode 6 async tests

This commit is contained in:
Matt Galloway 2014-09-15 12:03:50 +01:00
parent f773870d2c
commit a02aa42256
1 changed files with 8 additions and 32 deletions

View File

@ -32,21 +32,9 @@
[super tearDown];
}
- (BOOL)spinRunLoopWithTimeout:(NSTimeInterval)timeout untilBlockIsTrue:(BOOL(^)())block {
CFTimeInterval timeoutDate = CACurrentMediaTime() + 5.;
while (true) {
if (block()) {
return YES;
}
if (CACurrentMediaTime() > timeoutDate) {
return NO;
}
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1., true);
}
return NO;
}
- (void)testThatDownloadingSameURLTwiceAndCancellingFirstWorks {
XCTestExpectation *expectation = [self expectationWithDescription:@"Correct image downloads"];
NSURL *imageURL = [NSURL URLWithString:@"http://static2.dmcdn.net/static/video/656/177/44771656:jpeg_preview_small.jpg?20120509154705"];
id token1 = [[SDWebImageDownloader sharedDownloader] downloadImageWithURL:imageURL
@ -57,27 +45,22 @@
}];
expect(token1).toNot.beNil();
__block BOOL success = NO;
id token2 = [[SDWebImageDownloader sharedDownloader] downloadImageWithURL:imageURL
options:0
progress:nil
completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
success = YES;
[expectation fulfill];
}];
expect(token2).toNot.beNil();
[[SDWebImageDownloader sharedDownloader] cancel:token1];
success = [self spinRunLoopWithTimeout:5. untilBlockIsTrue:^BOOL{
return success;
}];
if (!success) {
XCTFail(@"Failed to download image");
}
[self waitForExpectationsWithTimeout:5. handler:nil];
}
- (void)testThatCancelingDownloadThenRequestingAgainWorks {
XCTestExpectation *expectation = [self expectationWithDescription:@"Correct image downloads"];
NSURL *imageURL = [NSURL URLWithString:@"http://static2.dmcdn.net/static/video/656/177/44771656:jpeg_preview_small.jpg?20120509154705"];
id token1 = [[SDWebImageDownloader sharedDownloader] downloadImageWithURL:imageURL
@ -90,22 +73,15 @@
[[SDWebImageDownloader sharedDownloader] cancel:token1];
__block BOOL success = NO;
id token2 = [[SDWebImageDownloader sharedDownloader] downloadImageWithURL:imageURL
options:0
progress:nil
completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
success = YES;
[expectation fulfill];
}];
expect(token2).toNot.beNil();
success = [self spinRunLoopWithTimeout:5. untilBlockIsTrue:^BOOL{
return success;
}];
if (!success) {
XCTFail(@"Failed to download image");
}
[self waitForExpectationsWithTimeout:5. handler:nil];
}
@end