Add the test cases for SDImageCacheDecodeFirstFrameOnly on memory cache

This commit is contained in:
DreamPiggy 2019-05-16 17:42:17 +08:00
parent daad5338e2
commit 8adfe3faeb
1 changed files with 32 additions and 0 deletions

View File

@ -199,6 +199,23 @@ static NSString *kTestImageKeyPNG = @"TestImageKey.png";
[self waitForExpectationsWithCommonTimeout];
}
- (void)test14QueryCacheFirstFrameOnlyHitMemoryCache {
NSString *key = kTestGIFURL;
UIImage *animatedImage = [self testGIFImage];
[[SDImageCache sharedImageCache] storeImageToMemory:animatedImage forKey:key];
[[SDImageCache sharedImageCache] queryCacheOperationForKey:key done:^(UIImage * _Nullable image, NSData * _Nullable data, SDImageCacheType cacheType) {
expect(cacheType).equal(SDImageCacheTypeMemory);
expect(image.sd_isAnimated).beTruthy();
expect(image == animatedImage).beTruthy();
}];
[[SDImageCache sharedImageCache] queryCacheOperationForKey:key options:SDImageCacheDecodeFirstFrameOnly done:^(UIImage * _Nullable image, NSData * _Nullable data, SDImageCacheType cacheType) {
expect(cacheType).equal(SDImageCacheTypeMemory);
expect(image.sd_isAnimated).beFalsy();
expect(image == animatedImage).beFalsy();
}];
[[SDImageCache sharedImageCache] removeImageFromMemoryForKey:kTestGIFURL];
}
- (void)test20InitialCacheSize{
expect([[SDImageCache sharedImageCache] totalDiskSize]).to.equal(0);
}
@ -662,6 +679,15 @@ static NSString *kTestImageKeyPNG = @"TestImageKey.png";
return reusableImage;
}
- (UIImage *)testGIFImage {
static UIImage *reusableImage = nil;
if (!reusableImage) {
NSData *data = [NSData dataWithContentsOfFile:[self testGIFPath]];
reusableImage = [UIImage sd_imageWithData:data];
}
return reusableImage;
}
- (NSString *)testJPEGPath {
NSBundle *testBundle = [NSBundle bundleForClass:[self class]];
return [testBundle pathForResource:@"TestImage" ofType:@"jpg"];
@ -672,6 +698,12 @@ static NSString *kTestImageKeyPNG = @"TestImageKey.png";
return [testBundle pathForResource:@"TestImage" ofType:@"png"];
}
- (NSString *)testGIFPath {
NSBundle *testBundle = [NSBundle bundleForClass:[self class]];
NSString *testPath = [testBundle pathForResource:@"TestImage" ofType:@"gif"];
return testPath;
}
- (nullable NSString *)userCacheDirectory {
NSArray<NSString *> *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
return paths.firstObject;