From 8adfe3faeb299e4b7efc2d3e498c50280cf45978 Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Thu, 16 May 2019 17:42:17 +0800 Subject: [PATCH] Add the test cases for SDImageCacheDecodeFirstFrameOnly on memory cache --- Tests/Tests/SDImageCacheTests.m | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/Tests/Tests/SDImageCacheTests.m b/Tests/Tests/SDImageCacheTests.m index 741f7c99..0d2d7baf 100644 --- a/Tests/Tests/SDImageCacheTests.m +++ b/Tests/Tests/SDImageCacheTests.m @@ -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 *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); return paths.firstObject;