GeezerVison is showing github.com — Update the test case `test15ThatQueryCacheTypeWork` to ensure the que… · SDWebImage/SDWebImage@b9f7757
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: Tests/Tests/SDWebImageManagerTests.m +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -377,16 +377,22 @@ - (void)test15ThatQueryCacheTypeWork { |
377 | 377 | NSURL *url = [NSURL URLWithString:@"https://placehold.co/101x101.png"]; |
378 | 378 | NSString *key = [SDWebImageManager.sharedManager cacheKeyForURL:url]; |
379 | 379 | NSData *testImageData = [NSData dataWithContentsOfFile:[self testJPEGPath]]; |
| 380 | + UIImage *testImage = [UIImage sd_imageWithData:testImageData]; |
380 | 381 | [SDImageCache.sharedImageCache storeImageDataToDisk:testImageData forKey:key]; |
381 | 382 |
|
382 | 383 | // Query memory first |
383 | 384 | [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) { |
384 | 385 | expect(image).beNil(); |
385 | 386 | expect(cacheType).equal(SDImageCacheTypeNone); |
| 387 | + // Store the image to memory |
| 388 | + [SDImageCache.sharedImageCache storeImageToMemory:testImage forKey:key]; |
386 | 389 | // Query disk secondly |
387 | 390 | [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) { |
388 | 391 | expect(image2).notTo.beNil(); |
389 | 392 | expect(cacheType2).equal(SDImageCacheTypeDisk); |
| 393 | + // We should ensure that this image is not the same memory address as image1 |
| 394 | + expect(image2 != testImage).beTruthy(); |
| 395 | + [SDImageCache.sharedImageCache removeImageFromMemoryForKey:key]; |
390 | 396 | [SDImageCache.sharedImageCache removeImageFromDiskForKey:key]; |
391 | 397 | [expectation fulfill]; |
392 | 398 | }]; |
|