Update the test case `test12ThatStoreCacheTypeWork` to ensure the transformed image does not inherit the image format or any attributes from original one

This commit is contained in:
DreamPiggy 2020-04-08 11:18:03 +08:00
parent 7cdf484fdd
commit a8177c1327
1 changed files with 18 additions and 9 deletions

View File

@ -121,7 +121,7 @@
SDWebImageManager *manager = [[SDWebImageManager alloc] initWithCache:[SDImageCache sharedImageCache] loader:[SDWebImageDownloader sharedDownloader]];
manager.transformer = transformer;
[[SDImageCache sharedImageCache] removeImageForKey:kTestJPEGURL withCompletion:^{
[manager loadImageWithURL:url options:SDWebImageTransformAnimatedImage progress:nil completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) {
[manager loadImageWithURL:url options:SDWebImageTransformAnimatedImage | SDWebImageTransformVectorImage progress:nil completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) {
expect(image).equal(transformer.testImage);
[expectation fulfill];
}];
@ -228,22 +228,31 @@
// test: original image -> disk only, transformed image -> memory only
SDWebImageContext *context = @{SDWebImageContextOriginalStoreCacheType : @(SDImageCacheTypeDisk), SDWebImageContextStoreCacheType : @(SDImageCacheTypeMemory)};
NSURL *url = [NSURL URLWithString:kTestJPEGURL];
NSURL *url = [NSURL URLWithString:kTestAPNGPURL];
NSString *originalKey = [manager cacheKeyForURL:url];
NSString *transformedKey = [manager cacheKeyForURL:url context:context];
[manager loadImageWithURL:url options:SDWebImageTransformAnimatedImage context:context progress:nil completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) {
expect(image).equal(transformer.testImage);
// the transformed image should not inherite any attribute from original one
expect(image.sd_imageFormat).equal(SDImageFormatJPEG);
expect(image.sd_isAnimated).beFalsy();
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 2*kMinDelayNanosecond), dispatch_get_main_queue(), ^{
// original -> disk only
[manager.imageCache containsImageForKey:originalKey cacheType:SDImageCacheTypeAll completion:^(SDImageCacheType originalCacheType) {
expect(originalCacheType).equal(SDImageCacheTypeDisk);
UIImage *originalImage = [cache imageFromMemoryCacheForKey:originalKey];
expect(originalImage).beNil();
NSData *originalData = [cache diskImageDataForKey:originalKey];
expect(originalData).notTo.beNil();
originalImage = [UIImage sd_imageWithData:originalData];
expect(originalImage).notTo.beNil();
expect(originalImage.sd_imageFormat).equal(SDImageFormatPNG);
expect(originalImage.sd_isAnimated).beTruthy();
// transformed -> memory only
[manager.imageCache containsImageForKey:transformedKey cacheType:SDImageCacheTypeAll completion:^(SDImageCacheType transformedCacheType) {
expect(transformedCacheType).equal(SDImageCacheTypeMemory);
[cache clearDiskOnCompletion:nil];
[expectation fulfill];
}];
}];
});
}];