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:
parent
7cdf484fdd
commit
a8177c1327
|
@ -121,7 +121,7 @@
|
||||||
SDWebImageManager *manager = [[SDWebImageManager alloc] initWithCache:[SDImageCache sharedImageCache] loader:[SDWebImageDownloader sharedDownloader]];
|
SDWebImageManager *manager = [[SDWebImageManager alloc] initWithCache:[SDImageCache sharedImageCache] loader:[SDWebImageDownloader sharedDownloader]];
|
||||||
manager.transformer = transformer;
|
manager.transformer = transformer;
|
||||||
[[SDImageCache sharedImageCache] removeImageForKey:kTestJPEGURL withCompletion:^{
|
[[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);
|
expect(image).equal(transformer.testImage);
|
||||||
[expectation fulfill];
|
[expectation fulfill];
|
||||||
}];
|
}];
|
||||||
|
@ -228,21 +228,30 @@
|
||||||
|
|
||||||
// test: original image -> disk only, transformed image -> memory only
|
// test: original image -> disk only, transformed image -> memory only
|
||||||
SDWebImageContext *context = @{SDWebImageContextOriginalStoreCacheType : @(SDImageCacheTypeDisk), SDWebImageContextStoreCacheType : @(SDImageCacheTypeMemory)};
|
SDWebImageContext *context = @{SDWebImageContextOriginalStoreCacheType : @(SDImageCacheTypeDisk), SDWebImageContextStoreCacheType : @(SDImageCacheTypeMemory)};
|
||||||
NSURL *url = [NSURL URLWithString:kTestJPEGURL];
|
NSURL *url = [NSURL URLWithString:kTestAPNGPURL];
|
||||||
NSString *originalKey = [manager cacheKeyForURL:url];
|
NSString *originalKey = [manager cacheKeyForURL:url];
|
||||||
NSString *transformedKey = [manager cacheKeyForURL:url context:context];
|
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) {
|
[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);
|
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(), ^{
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 2*kMinDelayNanosecond), dispatch_get_main_queue(), ^{
|
||||||
// original -> disk only
|
// original -> disk only
|
||||||
[manager.imageCache containsImageForKey:originalKey cacheType:SDImageCacheTypeAll completion:^(SDImageCacheType originalCacheType) {
|
UIImage *originalImage = [cache imageFromMemoryCacheForKey:originalKey];
|
||||||
expect(originalCacheType).equal(SDImageCacheTypeDisk);
|
expect(originalImage).beNil();
|
||||||
// transformed -> memory only
|
NSData *originalData = [cache diskImageDataForKey:originalKey];
|
||||||
[manager.imageCache containsImageForKey:transformedKey cacheType:SDImageCacheTypeAll completion:^(SDImageCacheType transformedCacheType) {
|
expect(originalData).notTo.beNil();
|
||||||
expect(transformedCacheType).equal(SDImageCacheTypeMemory);
|
originalImage = [UIImage sd_imageWithData:originalData];
|
||||||
[expectation fulfill];
|
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];
|
||||||
}];
|
}];
|
||||||
});
|
});
|
||||||
}];
|
}];
|
||||||
|
|
Loading…
Reference in New Issue