Added the test case `test42StoreCacheWithImageAndFormatWithoutImageData` to ensure this behavior

This commit is contained in:
DreamPiggy 2020-03-01 18:51:48 +08:00
parent 3df399508e
commit 12bdd57f31
1 changed files with 30 additions and 0 deletions

View File

@ -391,6 +391,36 @@ static NSString *kTestImageKeyPNG = @"TestImageKey.png";
[self waitForExpectationsWithCommonTimeout];
}
- (void)test42StoreCacheWithImageAndFormatWithoutImageData {
XCTestExpectation *expectation1 = [self expectationWithDescription:@"StoreImage with sd_imageFormat should use that format"];
XCTestExpectation *expectation2 = [self expectationWithDescription:@"StoreImage with SDAnimatedImage should use animatedImageData"];
NSData *gifData = [NSData dataWithContentsOfFile:[self testGIFPath]];
UIImage *gifImage = [UIImage sd_imageWithData:gifData]; // UIAnimatedImage
expect(gifImage.sd_isAnimated).beTruthy();
expect(gifImage.sd_imageFormat).equal(SDImageFormatGIF);
NSString *kAnimatedImageKey1 = @"kAnimatedImageKey1";
NSString *kAnimatedImageKey2 = @"kAnimatedImageKey2";
[SDImageCache.sharedImageCache storeImage:gifImage forKey:kAnimatedImageKey1 toDisk:YES completion:^{
UIImage *diskImage = [SDImageCache.sharedImageCache imageFromDiskCacheForKey:kAnimatedImageKey1];
// Should save to GIF
expect(diskImage.sd_isAnimated).beTruthy();
expect(diskImage.sd_imageFormat).equal(SDImageFormatGIF);
[expectation1 fulfill];
}];
SDAnimatedImage *animatedImage = [SDAnimatedImage imageWithData:gifData];
expect(animatedImage.animatedImageData).notTo.beNil();
[SDImageCache.sharedImageCache storeImage:animatedImage forKey:kAnimatedImageKey2 toDisk:YES completion:^{
NSData *data = [SDImageCache.sharedImageCache diskImageDataForKey:kAnimatedImageKey2];
// Should save with animatedImageData
expect(data).equal(animatedImage.animatedImageData);
[expectation2 fulfill];
}];
[self waitForExpectationsWithCommonTimeout];
}
#pragma mark - SDMemoryCache & SDDiskCache
- (void)test42CustomMemoryCache {
SDImageCacheConfig *config = [[SDImageCacheConfig alloc] init];