Sfoglia il codice sorgente

Add test cases for `matchAnimatedImageClass` options

DreamPiggy 6 anni fa
parent
commit
cd2e36f7a5
1 ha cambiato i file con 24 aggiunte e 0 eliminazioni
  1. 24 0
      Tests/Tests/SDImageCacheTests.m

+ 24 - 0
Tests/Tests/SDImageCacheTests.m

@@ -367,6 +367,30 @@ static NSString *kTestImageKeyPNG = @"TestImageKey.png";
     expect(fileManager.lastError).equal(targetError);
 }
 
+- (void)test41MatchAnimatedImageClassWorks {
+    XCTestExpectation *expectation = [self expectationWithDescription:@"MatchAnimatedImageClass option should work"];
+    UIImage *image = [[UIImage alloc] initWithContentsOfFile:self.testGIFPath];
+    
+    NSString *kAnimatedImageKey = @"kAnimatedImageKey";
+    
+    // Store UIImage into cache
+    [[SDImageCache sharedImageCache] storeImageToMemory:image forKey:kAnimatedImageKey];
+    
+    // `MatchAnimatedImageClass` will cause query failed because class does not match
+    [SDImageCache.sharedImageCache queryCacheOperationForKey:kAnimatedImageKey options:SDImageCacheMatchAnimatedImageClass context:@{SDWebImageContextAnimatedImageClass : SDAnimatedImage.class} done:^(UIImage * _Nullable image1, NSData * _Nullable data1, SDImageCacheType cacheType1) {
+        expect(image1).beNil();
+        // This should query success with UIImage
+        [SDImageCache.sharedImageCache queryCacheOperationForKey:kAnimatedImageKey options:0 context:@{SDWebImageContextAnimatedImageClass : SDAnimatedImage.class} done:^(UIImage * _Nullable image2, NSData * _Nullable data2, SDImageCacheType cacheType2) {
+            expect(image2).notTo.beNil();
+            expect(image2).equal(image);
+            
+            [expectation fulfill];
+        }];
+    }];
+    
+    [self waitForExpectationsWithCommonTimeout];
+}
+
 #pragma mark - SDMemoryCache & SDDiskCache
 - (void)test42CustomMemoryCache {
     SDImageCacheConfig *config = [[SDImageCacheConfig alloc] init];