Skip to content

Commit 3797c8c

Browse files
committed
Update the test case test15ThatQueryCacheTypeWork to ensure the query from disk only semantic
1 parent 066163f commit 3797c8c

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

Tests/Tests/SDWebImageManagerTests.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,16 +377,22 @@ - (void)test15ThatQueryCacheTypeWork {
377377
NSURL *url = [NSURL URLWithString:@"https://placehold.co/101x101.png"];
378378
NSString *key = [SDWebImageManager.sharedManager cacheKeyForURL:url];
379379
NSData *testImageData = [NSData dataWithContentsOfFile:[self testJPEGPath]];
380+
UIImage *testImage = [UIImage sd_imageWithData:testImageData];
380381
[SDImageCache.sharedImageCache storeImageDataToDisk:testImageData forKey:key];
381382

382383
// Query memory first
383384
[SDWebImageManager.sharedManager loadImageWithURL:url options:SDWebImageFromCacheOnly context:@{SDWebImageContextQueryCacheType : @(SDImageCacheTypeMemory)} progress:nil completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) {
384385
expect(image).beNil();
385386
expect(cacheType).equal(SDImageCacheTypeNone);
387+
// Store the image to memory
388+
[SDImageCache.sharedImageCache storeImageToMemory:testImage forKey:key];
386389
// Query disk secondly
387390
[SDWebImageManager.sharedManager loadImageWithURL:url options:SDWebImageFromCacheOnly context:@{SDWebImageContextQueryCacheType : @(SDImageCacheTypeDisk)} progress:nil completed:^(UIImage * _Nullable image2, NSData * _Nullable data2, NSError * _Nullable error2, SDImageCacheType cacheType2, BOOL finished2, NSURL * _Nullable imageURL2) {
388391
expect(image2).notTo.beNil();
389392
expect(cacheType2).equal(SDImageCacheTypeDisk);
393+
// We should ensure that this disk image is not the same one in-memory
394+
expect(image2 != testImage).beTruthy();
395+
[SDImageCache.sharedImageCache removeImageFromMemoryForKey:key];
390396
[SDImageCache.sharedImageCache removeImageFromDiskForKey:key];
391397
[expectation fulfill];
392398
}];

0 commit comments

Comments
 (0)