Added test case test30ThatDifferentThumbnailLoadShouldCallbackDifferentSize

This commit is contained in:
DreamPiggy 2022-10-31 22:54:38 +08:00
parent 2fd75638fe
commit 980e0dd14a
2 changed files with 26 additions and 2 deletions

View File

@ -768,6 +768,30 @@
}];
}
- (void)test30ThatDifferentThumbnailLoadShouldCallbackDifferentSize {
// We move the logic into SDWebImageDownloaderOperation, which decode each callback's thumbnail size with different decoding pipeline, and callback independently
// Note the progressiveLoad does not support this and always callback first size
NSURL *url = [NSURL URLWithString:@"http://via.placeholder.com/501x501.png"];
NSString *fullSizeKey = [SDWebImageManager.sharedManager cacheKeyForURL:url];
[SDImageCache.sharedImageCache removeImageFromDiskForKey:fullSizeKey];
for (int i = 490; i < 500; i++) {
// 490x490, ..., 499x499
CGSize thumbnailSize = CGSizeMake(i, i);
NSString *thumbnailKey = SDThumbnailedKeyForKey(fullSizeKey, thumbnailSize, YES);
[SDImageCache.sharedImageCache removeImageFromDiskForKey:thumbnailKey];
XCTestExpectation *expectation = [self expectationWithDescription:[NSString stringWithFormat:@"Different thumbnail loading for same URL should callback different image size: (%dx%d)", i, i]];
[SDImageCache.sharedImageCache removeImageFromDiskForKey:url.absoluteString];
[SDWebImageDownloader.sharedDownloader downloadImageWithURL:url options:0 context:@{SDWebImageContextImageThumbnailPixelSize : @(thumbnailSize)} progress:nil completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
expect(image.size).equal(thumbnailSize);
[expectation fulfill];
}];
}
[self waitForExpectationsWithTimeout:kAsyncTestTimeout * 5 handler:nil];
}
#pragma mark - SDWebImageLoader
- (void)test30CustomImageLoaderWorks {
XCTestExpectation *expectation = [self expectationWithDescription:@"Custom image not works"];

View File

@ -510,8 +510,8 @@
- (void)test19ThatDifferentThumbnailLoadShouldCallbackDifferentSize {
// 3. Current SDWebImageDownloader use the **URL** as primiary key to bind operation, however, different loading pipeline may ask different image size for same URL, this design does not match
// We use a hack logic to do a re-decode check when the callback image's decode options does not match the loading pipeline provided, it will re-decode the full data with global queue :)
// Ugly unless we re-define the design of SDWebImageDownloader, maybe change that `addHandlersForProgress` with context options args as well. Different context options need different callback image
// We move the logic into SDWebImageDownloaderOperation, which decode each callback's thumbnail size with different decoding pipeline, and callback independently
// Note the progressiveLoad does not support this and always callback first size
NSURL *url = [NSURL URLWithString:@"http://via.placeholder.com/501x501.png"];
NSString *fullSizeKey = [SDWebImageManager.sharedManager cacheKeyForURL:url];