Update SDAnimatedImage test and HEIC/HEIF test

This commit is contained in:
DreamPiggy 2018-08-10 14:50:25 +08:00
parent b0775361b5
commit 7187aff159
6 changed files with 72 additions and 16 deletions

View File

@ -23,8 +23,12 @@
3264FF30205D42CB00F6BD48 /* SDWebImageTestTransformer.m in Sources */ = {isa = PBXBuildFile; fileRef = 3264FF2E205D42CB00F6BD48 /* SDWebImageTestTransformer.m */; };
327054E2206CEFF3006EA328 /* TestImageAnimated.apng in Resources */ = {isa = PBXBuildFile; fileRef = 327054E1206CEFF3006EA328 /* TestImageAnimated.apng */; };
327054E3206CEFF3006EA328 /* TestImageAnimated.apng in Resources */ = {isa = PBXBuildFile; fileRef = 327054E1206CEFF3006EA328 /* TestImageAnimated.apng */; };
327A418C211D660600495442 /* TestImage.heic in Resources */ = {isa = PBXBuildFile; fileRef = 327A418B211D660600495442 /* TestImage.heic */; };
327A418D211D660600495442 /* TestImage.heic in Resources */ = {isa = PBXBuildFile; fileRef = 327A418B211D660600495442 /* TestImage.heic */; };
328BB6DD20825E9800760D6C /* SDWebImageTestCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 328BB6DC20825E9800760D6C /* SDWebImageTestCache.m */; };
328BB6DE20825E9800760D6C /* SDWebImageTestCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 328BB6DC20825E9800760D6C /* SDWebImageTestCache.m */; };
32905E64211D786E00460FCF /* TestImage.heif in Resources */ = {isa = PBXBuildFile; fileRef = 32905E63211D786E00460FCF /* TestImage.heif */; };
32905E65211D786E00460FCF /* TestImage.heif in Resources */ = {isa = PBXBuildFile; fileRef = 32905E63211D786E00460FCF /* TestImage.heif */; };
32A571562037DB2D002EDAAE /* SDAnimatedImageTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 32A571552037DB2D002EDAAE /* SDAnimatedImageTest.m */; };
32B99E8B203AF8690017FD66 /* SDCategoriesTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 32B99E8A203AF8690017FD66 /* SDCategoriesTests.m */; };
32B99E9B203B2EDD0017FD66 /* SDTestCase.m in Sources */ = {isa = PBXBuildFile; fileRef = 2D7AF05F1F329763000083C2 /* SDTestCase.m */; };
@ -78,8 +82,10 @@
3264FF2D205D42CB00F6BD48 /* SDWebImageTestTransformer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SDWebImageTestTransformer.h; sourceTree = "<group>"; };
3264FF2E205D42CB00F6BD48 /* SDWebImageTestTransformer.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SDWebImageTestTransformer.m; sourceTree = "<group>"; };
327054E1206CEFF3006EA328 /* TestImageAnimated.apng */ = {isa = PBXFileReference; lastKnownFileType = file; path = TestImageAnimated.apng; sourceTree = "<group>"; };
327A418B211D660600495442 /* TestImage.heic */ = {isa = PBXFileReference; lastKnownFileType = file; path = TestImage.heic; sourceTree = "<group>"; };
328BB6DB20825E9800760D6C /* SDWebImageTestCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDWebImageTestCache.h; sourceTree = "<group>"; };
328BB6DC20825E9800760D6C /* SDWebImageTestCache.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDWebImageTestCache.m; sourceTree = "<group>"; };
32905E63211D786E00460FCF /* TestImage.heif */ = {isa = PBXFileReference; lastKnownFileType = file; path = TestImage.heif; sourceTree = "<group>"; };
32A571552037DB2D002EDAAE /* SDAnimatedImageTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SDAnimatedImageTest.m; sourceTree = "<group>"; };
32B99E8A203AF8690017FD66 /* SDCategoriesTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SDCategoriesTests.m; sourceTree = "<group>"; };
32B99E92203B2DF90017FD66 /* Tests Mac.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Tests Mac.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
@ -151,6 +157,8 @@
5F7F38AC1AE2A77A00B0E330 /* TestImage.jpg */,
43828A441DA67F9900000E62 /* TestImageLarge.jpg */,
433BBBB81D7EF8260086B6E9 /* TestImage.png */,
327A418B211D660600495442 /* TestImage.heic */,
32905E63211D786E00460FCF /* TestImage.heif */,
321259ED1F39E4110096FE0E /* TestImageAnimated.webp */,
321259EB1F39E3240096FE0E /* TestImageStatic.webp */,
327054E1206CEFF3006EA328 /* TestImageAnimated.apng */,
@ -326,6 +334,8 @@
32B99EA4203B31360017FD66 /* TestImage.jpg in Resources */,
32B99EA6203B31360017FD66 /* TestImage.png in Resources */,
32B99EA2203B31360017FD66 /* MonochromeTestImage.jpg in Resources */,
32905E65211D786E00460FCF /* TestImage.heif in Resources */,
327A418D211D660600495442 /* TestImage.heic in Resources */,
32B99EA8203B31360017FD66 /* TestImageStatic.webp in Resources */,
32B99EA7203B31360017FD66 /* TestImageAnimated.webp in Resources */,
32B99EA5203B31360017FD66 /* TestImageLarge.jpg in Resources */,
@ -336,8 +346,10 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
327A418C211D660600495442 /* TestImage.heic in Resources */,
321259EE1F39E4110096FE0E /* TestImageAnimated.webp in Resources */,
5F7F38AD1AE2A77A00B0E330 /* TestImage.jpg in Resources */,
32905E64211D786E00460FCF /* TestImage.heif in Resources */,
43828A451DA67F9900000E62 /* TestImageLarge.jpg in Resources */,
433BBBB71D7EF8200086B6E9 /* TestImage.gif in Resources */,
321259EC1F39E3240096FE0E /* TestImageStatic.webp in Resources */,

Binary file not shown.

Binary file not shown.

View File

@ -126,7 +126,24 @@ static const NSUInteger kTestGIFFrameCount = 5; // local TestImage.gif loop coun
expect(imageView.currentFrame).notTo.beNil(); // current frame
}
- (void)test10AnimatedImageViewRendering {
- (void)test10AnimatedImageInitWithCoder {
SDAnimatedImage *image1 = [SDAnimatedImage imageWithContentsOfFile:[self testGIFPath]];
expect(image1).notTo.beNil();
NSData *encodedData = [NSKeyedArchiver archivedDataWithRootObject:image1];
expect(encodedData).notTo.beNil();
SDAnimatedImage *image2 = [NSKeyedUnarchiver unarchiveObjectWithData:encodedData];
expect(image2).notTo.beNil();
// Check each property
expect(image1.scale).equal(image2.scale);
expect(image1.size).equal(image2.size);
expect(image1.animatedImageFormat).equal(image2.animatedImageFormat);
expect(image1.animatedImageData).equal(image2.animatedImageData);
expect(image1.animatedImageLoopCount).equal(image2.animatedImageLoopCount);
expect(image1.animatedImageFrameCount).equal(image2.animatedImageFrameCount);
}
- (void)test20AnimatedImageViewRendering {
XCTestExpectation *expectation = [self expectationWithDescription:@"test SDAnimatedImageView rendering"];
SDAnimatedImageView *imageView = [[SDAnimatedImageView alloc] init];
#if SD_UIKIT
@ -168,7 +185,7 @@ static const NSUInteger kTestGIFFrameCount = 5; // local TestImage.gif loop coun
[self waitForExpectationsWithCommonTimeout];
}
- (void)test11AnimatedImageViewSetProgressiveAnimatedImage {
- (void)test21AnimatedImageViewSetProgressiveAnimatedImage {
NSData *gifData = [self testGIFData];
SDImageGIFCoder *progressiveCoder = [[SDImageGIFCoder alloc] initIncrementalWithOptions:nil];
// simulate progressive decode, pass partial data
@ -195,7 +212,7 @@ static const NSUInteger kTestGIFFrameCount = 5; // local TestImage.gif loop coun
expect(isProgressive).equal(NO);
}
- (void)test12AnimatedImageViewCategory {
- (void)test22AnimatedImageViewCategory {
XCTestExpectation *expectation = [self expectationWithDescription:@"test SDAnimatedImageView view category"];
SDAnimatedImageView *imageView = [SDAnimatedImageView new];
NSURL *testURL = [NSURL URLWithString:kTestWebPURL];
@ -208,7 +225,7 @@ static const NSUInteger kTestGIFFrameCount = 5; // local TestImage.gif loop coun
[self waitForExpectationsWithCommonTimeout];
}
- (void)test13AnimatedImageViewCategoryProgressive {
- (void)test23AnimatedImageViewCategoryProgressive {
XCTestExpectation *expectation = [self expectationWithDescription:@"test SDAnimatedImageView view category"];
SDAnimatedImageView *imageView = [SDAnimatedImageView new];
NSURL *testURL = [NSURL URLWithString:kTestGIFURL];

View File

@ -83,6 +83,7 @@
NSURL *staticWebPURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"TestImageStatic" withExtension:@"webp"];
[self verifyCoder:[SDImageWebPCoder sharedCoder]
withLocalImageURL:staticWebPURL
supportsEncoding:YES
isAnimatedImage:NO];
}
@ -90,6 +91,7 @@
NSURL *animatedWebPURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"TestImageAnimated" withExtension:@"webp"];
[self verifyCoder:[SDImageWebPCoder sharedCoder]
withLocalImageURL:animatedWebPURL
supportsEncoding:YES
isAnimatedImage:YES];
}
@ -97,18 +99,41 @@
NSURL *animatedWebPURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"TestImageAnimated" withExtension:@"apng"];
[self verifyCoder:[SDImageAPNGCoder sharedCoder]
withLocalImageURL:animatedWebPURL
supportsEncoding:YES
isAnimatedImage:YES];
}
- (void)test20ThatOurGIFCoderWorks {
- (void)test12ThatGIFCoderWorks {
NSURL *gifURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"TestImage" withExtension:@"gif"];
[self verifyCoder:[SDImageGIFCoder sharedCoder]
withLocalImageURL:gifURL
supportsEncoding:YES
isAnimatedImage:YES];
}
- (void)test13ThatHEICWorks {
if (@available(iOS 11, macOS 10.13, *)) {
NSURL *heicURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"TestImage" withExtension:@"heic"];
[self verifyCoder:[SDImageIOCoder sharedCoder]
withLocalImageURL:heicURL
supportsEncoding:YES
isAnimatedImage:NO];
}
}
- (void)test14ThatHEIFWorks {
if (@available(iOS 11, macOS 10.13, *)) {
NSURL *heifURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"TestImage" withExtension:@"heif"];
[self verifyCoder:[SDImageIOCoder sharedCoder]
withLocalImageURL:heifURL
supportsEncoding:NO
isAnimatedImage:NO];
}
}
- (void)verifyCoder:(id<SDImageCoder>)coder
withLocalImageURL:(NSURL *)imageUrl
supportsEncoding:(BOOL)supportsEncoding
isAnimatedImage:(BOOL)isAnimated {
NSData *inputImageData = [NSData dataWithContentsOfURL:imageUrl];
expect(inputImageData).toNot.beNil();
@ -137,18 +162,20 @@
#endif
}
// 3 - check if we can encode to the original format
expect([coder canEncodeToFormat:inputImageFormat]).to.beTruthy();
// 4 - encode from UIImage to NSData using the inputImageFormat and check it
NSData *outputImageData = [coder encodedDataWithImage:inputImage format:inputImageFormat options:nil];
expect(outputImageData).toNot.beNil();
UIImage *outputImage = [coder decodedImageWithData:outputImageData options:nil];
expect(outputImage.size).to.equal(inputImage.size);
expect(outputImage.scale).to.equal(inputImage.scale);
if (supportsEncoding) {
// 3 - check if we can encode to the original format
expect([coder canEncodeToFormat:inputImageFormat]).to.beTruthy();
// 4 - encode from UIImage to NSData using the inputImageFormat and check it
NSData *outputImageData = [coder encodedDataWithImage:inputImage format:inputImageFormat options:nil];
expect(outputImageData).toNot.beNil();
UIImage *outputImage = [coder decodedImageWithData:outputImageData options:nil];
expect(outputImage.size).to.equal(inputImage.size);
expect(outputImage.scale).to.equal(inputImage.scale);
#if SD_UIKIT
expect(outputImage.images.count).to.equal(inputImage.images.count);
expect(outputImage.images.count).to.equal(inputImage.images.count);
#endif
}
}
@end

View File

@ -16,7 +16,7 @@ NSString *const kTestProgressiveJPEGURL = @"https://raw.githubusercontent.com/ib
NSString *const kTestPNGURL = @"http://via.placeholder.com/50x50.png";
NSString *const kTestGIFURL = @"https://media.giphy.com/media/UEsrLdv7ugRTq/giphy.gif";
NSString *const kTestWebPURL = @"http://littlesvr.ca/apng/images/SteamEngine.webp";
NSString *const kTestAPNGPURL = @"https:raw.githubusercontent.com/onevcat/APNGKit/master/TestImages/APNG-cube.apng";
NSString *const kTestAPNGPURL = @"https://upload.wikimedia.org/wikipedia/commons/1/14/Animated_PNG_example_bouncing_beach_ball.png";
@implementation SDTestCase