Update test case to make clear that transformed image and thumbnailed image will callback without data
This commit is contained in:
parent
980e0dd14a
commit
e3c6cfa066
|
@ -241,6 +241,7 @@ FOUNDATION_EXPORT SDWebImageContextOption _Nonnull const SDWebImageContextImageC
|
|||
|
||||
/**
|
||||
A id<SDImageTransformer> instance which conforms `SDImageTransformer` protocol. It's used for image transform after the image load finished and store the transformed image to cache. If you provide one, it will ignore the `transformer` in manager and use provided one instead. If you pass NSNull, the transformer feature will be disabled. (id<SDImageTransformer>)
|
||||
@note When this value is used, we will trigger image transform after downloaded, and the callback's data **will be nil** (because this time the data saved to disk does not match the image return to you. If you need full size data, query the cache with full size url key)
|
||||
*/
|
||||
FOUNDATION_EXPORT SDWebImageContextOption _Nonnull const SDWebImageContextImageTransformer;
|
||||
|
||||
|
|
|
@ -74,8 +74,9 @@
|
|||
/**
|
||||
A dictionary value contains the decode options when decoded from SDWebImage loading system (say, `SDImageCacheDecodeImageData/SDImageLoaderDecode[Progressive]ImageData`)
|
||||
It may not always available and only image decoding related options will be saved. (including [.decodeScaleFactor, .decodeThumbnailPixelSize, .decodePreserveAspectRatio, .decodeFirstFrameOnly])
|
||||
@note This is used to identify and check the image from downloader when multiple different request (which want different image thumbnail size, image class, etc) share the same URLOperation.
|
||||
@warning This API exist only because of current SDWebImageDownloader bad design which does not callback the context we call it. There will be refactory in future (API break) and you SHOULD NOT rely on this property at all.
|
||||
@note This is used to identify and check the image is from thumbnail decoding, and the callback's data **will be nil** (because this time the data saved to disk does not match the image return to you. If you need full size data, query the cache with full size url key)
|
||||
@warning You should not store object inside which keep strong reference to image itself, which will cause retain cycle.
|
||||
@warning This API exist only because of current SDWebImageDownloader bad design which does not callback the context we call it. There will be refactor in future (API break), use with caution.
|
||||
*/
|
||||
@property (nonatomic, copy) SDImageCoderOptions *sd_decodeOptions;
|
||||
|
||||
|
|
|
@ -389,6 +389,7 @@
|
|||
[SDWebImageManager.sharedManager loadImageWithURL:url options:SDWebImageFromCacheOnly context:@{SDWebImageContextImageTransformer : transformer, SDWebImageContextOriginalQueryCacheType : @(SDImageCacheTypeAll)} progress:nil completed:^(UIImage * _Nullable image2, NSData * _Nullable data2, NSError * _Nullable error2, SDImageCacheType cacheType2, BOOL finished2, NSURL * _Nullable imageURL2) {
|
||||
// Get the transformed image
|
||||
expect(image2).equal(transformer.testImage);
|
||||
expect(data).beNil(); // Currently, the thumbnailed and transformed image always data is nil, to avoid confuse user (the image and data represent no longer match)
|
||||
[SDImageCache.sharedImageCache removeImageFromMemoryForKey:originalKey];
|
||||
[SDImageCache.sharedImageCache removeImageFromDiskForKey:originalKey];
|
||||
[expectation fulfill];
|
||||
|
@ -417,6 +418,7 @@
|
|||
SDWebImageContextStoreCacheType: @(SDImageCacheTypeMemory)} progress:nil completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) {
|
||||
// Get the transformed image
|
||||
expect(image).equal(transformer.testImage);
|
||||
expect(data).beNil(); // Currently, the thumbnailed and transformed image always data is nil, to avoid confuse user (the image and data represent no longer match)
|
||||
// Now, the original image is stored into originalCache
|
||||
UIImage *originalImage = [originalCache imageFromMemoryCacheForKey:originalKey];
|
||||
expect(originalImage.size).equal(CGSizeMake(103, 103));
|
||||
|
@ -487,7 +489,8 @@
|
|||
expect(fullSizeImage.size).equal(fullSize);
|
||||
NSURL *url = [NSURL URLWithString:@"http://via.placeholder.com/500x500.png"];
|
||||
NSString *fullSizeKey = [SDWebImageManager.sharedManager cacheKeyForURL:url];
|
||||
[SDImageCache.sharedImageCache storeImageDataToDisk:fullSizeImage.sd_imageData forKey:fullSizeKey];
|
||||
NSData *fullSizeData = fullSizeImage.sd_imageData;
|
||||
[SDImageCache.sharedImageCache storeImageDataToDisk:fullSizeData forKey:fullSizeKey];
|
||||
|
||||
CGSize thumbnailSize = CGSizeMake(100, 100);
|
||||
NSString *thumbnailKey = SDThumbnailedKeyForKey(fullSizeKey, thumbnailSize, YES);
|
||||
|
@ -495,6 +498,7 @@
|
|||
// Load with thumbnail, should use full size cache instead to decode and scale down
|
||||
[SDWebImageManager.sharedManager loadImageWithURL:url options:0 context:@{SDWebImageContextImageThumbnailPixelSize : @(thumbnailSize)} progress:nil completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) {
|
||||
expect(image.size).equal(thumbnailSize);
|
||||
expect(data).beNil(); // Currently, the thumbnailed and transformed image always data is nil, to avoid confuse user (the image and data represent no longer match)
|
||||
expect(cacheType).equal(SDImageCacheTypeDisk);
|
||||
expect(finished).beTruthy();
|
||||
|
||||
|
@ -526,6 +530,7 @@
|
|||
__block SDWebImageCombinedOperation *operation;
|
||||
operation = [SDWebImageManager.sharedManager loadImageWithURL:url options:0 context:@{SDWebImageContextImageThumbnailPixelSize : @(thumbnailSize)} progress:nil completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) {
|
||||
expect(image.size).equal(thumbnailSize);
|
||||
expect(data).beNil(); // Currently, the thumbnailed and transformed image always data is nil, to avoid confuse user (the image and data represent no longer match)
|
||||
expect(cacheType).equal(SDImageCacheTypeNone);
|
||||
expect(finished).beTruthy();
|
||||
|
||||
|
|
Loading…
Reference in New Issue