From 74566aeb98e9f0e49b3ef0c61e8f0cb63e9f878e Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Sat, 23 Sep 2017 20:34:08 +0800 Subject: [PATCH] Add a test for SDWebImageRefreshCached --- Tests/Tests/SDWebImageManagerTests.m | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/Tests/Tests/SDWebImageManagerTests.m b/Tests/Tests/SDWebImageManagerTests.m index eb5986fc..87a0ccb1 100644 --- a/Tests/Tests/SDWebImageManagerTests.m +++ b/Tests/Tests/SDWebImageManagerTests.m @@ -73,7 +73,7 @@ NSString *workingImageURL = @"http://s3.amazonaws.com/fast-image-cache/demo-imag XCTFail(@"Image should be in cache"); } }]; - [self waitForExpectationsWithTimeout:kAsyncTestTimeout handler:nil]; + [self waitForExpectationsWithCommonTimeout]; } - (void)test05DiskImageExistsForURL { @@ -108,4 +108,23 @@ NSString *workingImageURL = @"http://s3.amazonaws.com/fast-image-cache/demo-imag [self waitForExpectationsWithCommonTimeout]; } +- (void)test07ThatLoadImageWithSDWebImageRefreshCachedWorks { + XCTestExpectation *expectation = [self expectationWithDescription:@"Image download twice with SDWebImageRefresh failed"]; + NSURL *originalImageURL = [NSURL URLWithString:@"http://s3.amazonaws.com/fast-image-cache/demo-images/FICDDemoImage007.jpg"]; + [[SDImageCache sharedImageCache] clearDiskOnCompletion:nil]; + + [[SDWebImageManager sharedManager] loadImageWithURL:originalImageURL options:SDWebImageRefreshCached progress:nil completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) { + expect(image).toNot.beNil(); + expect(error).to.beNil(); + // #1993, load image with SDWebImageRefreshCached twice should not fail if the first time success. + + [[SDWebImageManager sharedManager] loadImageWithURL:originalImageURL options:SDWebImageRefreshCached progress:nil completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) { + expect(image).toNot.beNil(); + expect(error).to.beNil(); + [expectation fulfill]; + }]; + }]; + [self waitForExpectationsWithCommonTimeout]; +} + @end