Merge pull request #2434 from dreampiggy/test_coder

Add more tests for image decoding/encoding part
This commit is contained in:
DreamPiggy 2018-08-17 14:56:39 +08:00 committed by GitHub
commit 3966200d6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 168 additions and 46 deletions

View File

@ -1,6 +1,6 @@
language: objective-c
osx_image: xcode9
osx_image: xcode9.4
env:
global:
@ -40,9 +40,9 @@ script:
- echo Build the Demo apps
- xcodebuild build -workspace SDWebImage.xcworkspace -scheme 'SDWebImage OSX Demo' -sdk macosx -configuration Debug | xcpretty -c
- xcodebuild build -workspace SDWebImage.xcworkspace -scheme 'SDWebImage iOS Demo' -configuration Debug -destination 'name=iPhone 6s' | xcpretty -c
- xcodebuild build -workspace SDWebImage.xcworkspace -scheme 'SDWebImage iOS Demo' -configuration Debug -destination 'name=iPhone 8' | xcpretty -c
- xcodebuild build -workspace SDWebImage.xcworkspace -scheme 'SDWebImage TV Demo' -sdk appletvsimulator -configuration Debug | xcpretty -c
- xcodebuild build -workspace SDWebImage.xcworkspace -scheme 'SDWebImage Watch Demo' -configuration Debug -destination 'name=iPhone 6s' | xcpretty -c
- xcodebuild build -workspace SDWebImage.xcworkspace -scheme 'SDWebImage Watch Demo' -configuration Debug -destination 'name=iPhone 8' | xcpretty -c
- echo Clean DerivedData
- mkdir DerivedData
@ -50,7 +50,7 @@ script:
- echo Run the tests
- pod install --project-directory=Tests
- xcodebuild test -workspace SDWebImage.xcworkspace -scheme 'Tests' -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 6s' -configuration Debug | xcpretty -c
- xcodebuild test -workspace SDWebImage.xcworkspace -scheme 'Tests' -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 8' -configuration Debug | xcpretty -c
- mv ~/Library/Developer/Xcode/DerivedData/ ./DerivedData/iOS
- xcodebuild test -workspace SDWebImage.xcworkspace -scheme 'Tests Mac' -sdk macosx -destination 'platform=OS X,arch=x86_64' -configuration Debug | xcpretty -c
- mv ~/Library/Developer/Xcode/DerivedData/ ./DerivedData/macOS

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

@ -97,7 +97,7 @@ static const NSUInteger kTestGIFFrameCount = 5; // local TestImage.gif loop coun
expect(imageView.currentFrame).beNil(); // current frame
}
- (void)test07AnimatedImageViewSetAnimatedImage {
- (void)test07AnimatedImageViewSetAnimatedImageWEBP {
SDAnimatedImageView *imageView = [SDAnimatedImageView new];
SDAnimatedImage *image = [SDAnimatedImage imageWithData:[self testAnimatedWebPData]];
imageView.image = image;
@ -105,7 +105,40 @@ static const NSUInteger kTestGIFFrameCount = 5; // local TestImage.gif loop coun
expect(imageView.currentFrame).notTo.beNil(); // current frame
}
- (void)test08AnimatedImageViewRendering {
- (void)test08AnimatedImageViewSetAnimatedImageGIF {
SDAnimatedImageView *imageView = [SDAnimatedImageView new];
SDAnimatedImage *image = [SDAnimatedImage imageWithData:[self testGIFData]];
imageView.image = image;
expect(imageView.image).notTo.beNil();
expect(imageView.currentFrame).notTo.beNil(); // current frame
}
- (void)test09AnimatedImageViewSetAnimatedImageAPNG {
SDAnimatedImageView *imageView = [SDAnimatedImageView new];
SDAnimatedImage *image = [SDAnimatedImage imageWithData:[self testAPNGPData]];
imageView.image = image;
expect(imageView.image).notTo.beNil();
expect(imageView.currentFrame).notTo.beNil(); // current frame
}
- (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
@ -147,7 +180,7 @@ static const NSUInteger kTestGIFFrameCount = 5; // local TestImage.gif loop coun
[self waitForExpectationsWithCommonTimeout];
}
- (void)test09AnimatedImageViewSetProgressiveAnimatedImage {
- (void)test21AnimatedImageViewSetProgressiveAnimatedImage {
NSData *gifData = [self testGIFData];
SDImageGIFCoder *progressiveCoder = [[SDImageGIFCoder alloc] initIncrementalWithOptions:nil];
// simulate progressive decode, pass partial data
@ -174,7 +207,7 @@ static const NSUInteger kTestGIFFrameCount = 5; // local TestImage.gif loop coun
expect(isProgressive).equal(NO);
}
- (void)test10AnimatedImageViewCategory {
- (void)test22AnimatedImageViewCategory {
XCTestExpectation *expectation = [self expectationWithDescription:@"test SDAnimatedImageView view category"];
SDAnimatedImageView *imageView = [SDAnimatedImageView new];
NSURL *testURL = [NSURL URLWithString:kTestWebPURL];
@ -187,7 +220,7 @@ static const NSUInteger kTestGIFFrameCount = 5; // local TestImage.gif loop coun
[self waitForExpectationsWithCommonTimeout];
}
- (void)test11AnimatedImageViewCategoryProgressive {
- (void)test23AnimatedImageViewCategoryProgressive {
XCTestExpectation *expectation = [self expectationWithDescription:@"test SDAnimatedImageView view category"];
SDAnimatedImageView *imageView = [SDAnimatedImageView new];
NSURL *testURL = [NSURL URLWithString:kTestGIFURL];
@ -197,6 +230,7 @@ static const NSUInteger kTestGIFFrameCount = 5; // local TestImage.gif loop coun
// Progressive image may be nil when download data is not enough
if (image) {
expect(image.sd_isIncremental).beTruthy();
expect([image conformsToProtocol:@protocol(SDAnimatedImage)]).beTruthy();
BOOL isProgressive = imageView.isProgressive;
expect(isProgressive).equal(YES);
}
@ -244,6 +278,16 @@ static const NSUInteger kTestGIFFrameCount = 5; // local TestImage.gif loop coun
return [NSData dataWithContentsOfFile:[self testAnimatedWebPPath]];
}
- (NSString *)testAPNGPPath {
NSBundle *testBundle = [NSBundle bundleForClass:[self class]];
NSString *testPath = [testBundle pathForResource:@"TestImageAnimated" ofType:@"apng"];
return testPath;
}
- (NSData *)testAPNGPData {
return [NSData dataWithContentsOfFile:[self testAPNGPPath]];
}
- (NSString *)testJPEGPath {
NSBundle *testBundle = [NSBundle bundleForClass:[self class]];
NSString *testPath = [testBundle pathForResource:@"TestImage" ofType:@"jpg"];

View File

@ -232,7 +232,7 @@ static NSString *kTestImageKeyPNG = @"TestImageKey.png";
}
- (void)test34CachePathForSimpleKeyWithExtension {
NSString *cachePath = [[SDImageCache sharedImageCache] cachePathForKey:kTestJpegURL];
NSString *cachePath = [[SDImageCache sharedImageCache] cachePathForKey:kTestJPEGURL];
expect(cachePath).toNot.beNil();
expect([cachePath pathExtension]).to.equal(@"jpg");
}

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,46 @@
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"];
#if SD_UIKIT
BOOL supportsEncoding = YES; // iPhone Simulator after Xcode 9.3 support HEIC encoding
#else
BOOL supportsEncoding = NO; // Travis-CI Mac env currently does not support HEIC encoding
#endif
[self verifyCoder:[SDImageIOCoder sharedCoder]
withLocalImageURL:heicURL
supportsEncoding:supportsEncoding
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 +167,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

@ -21,10 +21,12 @@
FOUNDATION_EXPORT const int64_t kAsyncTestTimeout;
FOUNDATION_EXPORT const int64_t kMinDelayNanosecond;
FOUNDATION_EXPORT NSString * _Nonnull const kTestJpegURL;
FOUNDATION_EXPORT NSString * _Nonnull const kTestJPEGURL;
FOUNDATION_EXPORT NSString * _Nonnull const kTestProgressiveJPEGURL;
FOUNDATION_EXPORT NSString * _Nonnull const kTestPNGURL;
FOUNDATION_EXPORT NSString * _Nonnull const kTestGIFURL;
FOUNDATION_EXPORT NSString * _Nonnull const kTestWebPURL;
FOUNDATION_EXPORT NSString * _Nonnull const kTestAPNGPURL;
@interface SDTestCase : XCTestCase

View File

@ -11,10 +11,12 @@
const int64_t kAsyncTestTimeout = 5;
const int64_t kMinDelayNanosecond = NSEC_PER_MSEC * 100; // 0.1s
NSString *const kTestJpegURL = @"http://via.placeholder.com/50x50.jpg";
NSString *const kTestJPEGURL = @"http://via.placeholder.com/50x50.jpg";
NSString *const kTestProgressiveJPEGURL = @"https://raw.githubusercontent.com/ibireme/YYImage/master/Demo/YYImageDemo/mew_progressive.jpg";
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://upload.wikimedia.org/wikipedia/commons/1/14/Animated_PNG_example_bouncing_beach_ball.png";
@implementation SDTestCase

View File

@ -22,7 +22,7 @@
XCTestExpectation *expectation = [self expectationWithDescription:@"UIImageView setImageWithURL"];
UIImageView *imageView = [[UIImageView alloc] init];
NSURL *originalImageURL = [NSURL URLWithString:kTestJpegURL];
NSURL *originalImageURL = [NSURL URLWithString:kTestJPEGURL];
[imageView sd_setImageWithURL:originalImageURL
completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
expect(image).toNot.beNil();
@ -39,7 +39,7 @@
XCTestExpectation *expectation = [self expectationWithDescription:@"UIImageView setHighlightedImageWithURL"];
UIImageView *imageView = [[UIImageView alloc] init];
NSURL *originalImageURL = [NSURL URLWithString:kTestJpegURL];
NSURL *originalImageURL = [NSURL URLWithString:kTestJPEGURL];
[imageView sd_setHighlightedImageWithURL:originalImageURL
completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
expect(image).toNot.beNil();
@ -56,7 +56,7 @@
XCTestExpectation *expectation = [self expectationWithDescription:@"MKAnnotationView setImageWithURL"];
MKAnnotationView *annotationView = [[MKAnnotationView alloc] init];
NSURL *originalImageURL = [NSURL URLWithString:kTestJpegURL];
NSURL *originalImageURL = [NSURL URLWithString:kTestJPEGURL];
[annotationView sd_setImageWithURL:originalImageURL
completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
expect(image).toNot.beNil();
@ -73,7 +73,7 @@
XCTestExpectation *expectation = [self expectationWithDescription:@"UIButton setImageWithURL normalState"];
UIButton *button = [[UIButton alloc] init];
NSURL *originalImageURL = [NSURL URLWithString:kTestJpegURL];
NSURL *originalImageURL = [NSURL URLWithString:kTestJPEGURL];
[button sd_setImageWithURL:originalImageURL
forState:UIControlStateNormal
completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
@ -90,7 +90,7 @@
XCTestExpectation *expectation = [self expectationWithDescription:@"UIButton setImageWithURL highlightedState"];
UIButton *button = [[UIButton alloc] init];
NSURL *originalImageURL = [NSURL URLWithString:kTestJpegURL];
NSURL *originalImageURL = [NSURL URLWithString:kTestJPEGURL];
[button sd_setImageWithURL:originalImageURL
forState:UIControlStateHighlighted
completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
@ -107,7 +107,7 @@
XCTestExpectation *expectation = [self expectationWithDescription:@"UIButton setBackgroundImageWithURL normalState"];
UIButton *button = [[UIButton alloc] init];
NSURL *originalImageURL = [NSURL URLWithString:kTestJpegURL];
NSURL *originalImageURL = [NSURL URLWithString:kTestJPEGURL];
[button sd_setBackgroundImageWithURL:originalImageURL
forState:UIControlStateNormal
completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
@ -158,7 +158,7 @@
- (void)testUIViewImageProgressKVOWork {
XCTestExpectation *expectation = [self expectationWithDescription:@"UIView imageProgressKVO failed"];
UIView *view = [[UIView alloc] init];
NSURL *originalImageURL = [NSURL URLWithString:kTestJpegURL];
NSURL *originalImageURL = [NSURL URLWithString:kTestJPEGURL];
[self.KVOController observe:view.sd_imageProgress keyPath:NSStringFromSelector(@selector(fractionCompleted)) options:NSKeyValueObservingOptionNew block:^(id _Nullable observer, id _Nonnull object, NSDictionary<NSString *,id> * _Nonnull change) {
NSProgress *progress = object;
@ -169,7 +169,7 @@
}];
// Clear the disk cache to force download from network
[[SDImageCache sharedImageCache] removeImageForKey:kTestJpegURL withCompletion:^{
[[SDImageCache sharedImageCache] removeImageForKey:kTestJPEGURL withCompletion:^{
[view sd_internalSetImageWithURL:originalImageURL placeholderImage:nil options:0 context:nil setImageBlock:nil progress:nil completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) {
expect(view.sd_imageProgress.fractionCompleted).equal(1.0);
expect([view.sd_imageProgress.userInfo[NSStringFromSelector(_cmd)] boolValue]).equal(YES);

View File

@ -53,7 +53,7 @@
- (void)test04ThatASimpleDownloadWorks {
XCTestExpectation *expectation = [self expectationWithDescription:@"Simple download"];
NSURL *imageURL = [NSURL URLWithString:kTestJpegURL];
NSURL *imageURL = [NSURL URLWithString:kTestJPEGURL];
[[SDWebImageDownloader sharedDownloader] downloadImageWithURL:imageURL options:0 progress:nil completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
if (image && data && !error && finished) {
[expectation fulfill];
@ -75,7 +75,7 @@
- (void)test06ThatUsingACustomDownloaderOperationWorks {
SDWebImageDownloader *downloader = [[SDWebImageDownloader alloc] initWithConfig:nil];
NSURL *imageURL1 = [NSURL URLWithString:kTestJpegURL];
NSURL *imageURL1 = [NSURL URLWithString:kTestJPEGURL];
NSURL *imageURL2 = [NSURL URLWithString:kTestPNGURL];
NSURL *imageURL3 = [NSURL URLWithString:kTestGIFURL];
// we try to set a usual NSOperation as operation class. Should not work
@ -131,7 +131,7 @@
- (void)test09ThatProgressiveJPEGWorks {
XCTestExpectation *expectation = [self expectationWithDescription:@"Progressive JPEG download"];
NSURL *imageURL = [NSURL URLWithString:kTestJpegURL];
NSURL *imageURL = [NSURL URLWithString:kTestProgressiveJPEGURL];
[[SDWebImageDownloader sharedDownloader] downloadImageWithURL:imageURL options:SDWebImageDownloaderProgressiveLoad progress:nil completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
if (image && data && !error && finished) {
[expectation fulfill];
@ -161,7 +161,7 @@
- (void)test11ThatCancelWorks {
XCTestExpectation *expectation = [self expectationWithDescription:@"Cancel"];
NSURL *imageURL = [NSURL URLWithString:kTestJpegURL];
NSURL *imageURL = [NSURL URLWithString:kTestJPEGURL];
SDWebImageDownloadToken *token = [[SDWebImageDownloader sharedDownloader]
downloadImageWithURL:imageURL options:0 progress:nil completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
XCTFail(@"Should not get here");
@ -181,7 +181,7 @@
- (void)test12ThatWeCanUseAnotherSessionForEachDownloadOperation {
XCTestExpectation *expectation = [self expectationWithDescription:@"Owned session"];
NSURL *imageURL = [NSURL URLWithString:kTestJpegURL];
NSURL *imageURL = [NSURL URLWithString:kTestJPEGURL];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:imageURL cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:15];
request.HTTPShouldUsePipelining = YES;
@ -207,7 +207,7 @@
- (void)test13ThatDownloadCanContinueWhenTheAppEntersBackground {
XCTestExpectation *expectation = [self expectationWithDescription:@"Simple download"];
NSURL *imageURL = [NSURL URLWithString:kTestJpegURL];
NSURL *imageURL = [NSURL URLWithString:kTestJPEGURL];
[[SDWebImageDownloader sharedDownloader] downloadImageWithURL:imageURL options:SDWebImageDownloaderContinueInBackground progress:nil completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
if (image && data && !error && finished) {
[expectation fulfill];
@ -287,6 +287,36 @@
}];
}
- (void)test18ThatProgressiveGIFWorks {
XCTestExpectation *expectation = [self expectationWithDescription:@"Progressive GIF download"];
NSURL *imageURL = [NSURL URLWithString:kTestGIFURL];
[[SDWebImageDownloader sharedDownloader] downloadImageWithURL:imageURL options:SDWebImageDownloaderProgressiveLoad progress:nil completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
if (image && data && !error && finished) {
[expectation fulfill];
} else if (finished) {
XCTFail(@"Something went wrong");
} else {
// progressive updates
}
}];
[self waitForExpectationsWithCommonTimeout];
}
- (void)test19ThatProgressiveAPNGWorks {
XCTestExpectation *expectation = [self expectationWithDescription:@"Progressive APNG download"];
NSURL *imageURL = [NSURL URLWithString:kTestAPNGPURL];
[[SDWebImageDownloader sharedDownloader] downloadImageWithURL:imageURL options:SDWebImageDownloaderProgressiveLoad progress:nil completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
if (image && data && !error && finished) {
[expectation fulfill];
} else if (finished) {
XCTFail(@"Something went wrong");
} else {
// progressive updates
}
}];
[self waitForExpectationsWithCommonTimeout];
}
/**
* Per #883 - Fix multiple requests for same image and then canceling one
* Old SDWebImage (3.x) could not handle correctly multiple requests for the same image + cancel
@ -296,7 +326,7 @@
- (void)test20ThatDownloadingSameURLTwiceAndCancellingFirstWorks {
XCTestExpectation *expectation = [self expectationWithDescription:@"Correct image downloads"];
NSURL *imageURL = [NSURL URLWithString:kTestJpegURL];
NSURL *imageURL = [NSURL URLWithString:kTestJPEGURL];
SDWebImageDownloadToken *token1 = [[SDWebImageDownloader sharedDownloader]
downloadImageWithURL:imageURL
@ -334,7 +364,7 @@
- (void)test21ThatCancelingDownloadThenRequestingAgainWorks {
XCTestExpectation *expectation = [self expectationWithDescription:@"Correct image downloads"];
NSURL *imageURL = [NSURL URLWithString:kTestJpegURL];
NSURL *imageURL = [NSURL URLWithString:kTestJPEGURL];
SDWebImageDownloadToken *token1 = [[SDWebImageDownloader sharedDownloader]
downloadImageWithURL:imageURL
@ -403,7 +433,7 @@
components.query = @"text=Hello+World";
mutableRequest.URL = components.URL;
return mutableRequest;
} else if ([request.URL.absoluteString isEqualToString:kTestJpegURL]) {
} else if ([request.URL.absoluteString isEqualToString:kTestJPEGURL]) {
// Test that return nil request will treat as error
return nil;
} else {
@ -415,7 +445,7 @@
__block BOOL firstCheck = NO;
__block BOOL secondCheck = NO;
[downloader downloadImageWithURL:[NSURL URLWithString:kTestJpegURL] options:0 progress:nil completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
[downloader downloadImageWithURL:[NSURL URLWithString:kTestJPEGURL] options:0 progress:nil completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
// Except error
expect(error).notTo.beNil();
firstCheck = YES;
@ -440,7 +470,7 @@
- (void)test30CustomImageLoaderWorks {
XCTestExpectation *expectation = [self expectationWithDescription:@"Custom image not works"];
SDWebImageTestLoader *loader = [[SDWebImageTestLoader alloc] init];
NSURL *imageURL = [NSURL URLWithString:kTestJpegURL];
NSURL *imageURL = [NSURL URLWithString:kTestJPEGURL];
[loader loadImageWithURL:imageURL options:0 context:nil progress:^(NSInteger receivedSize, NSInteger expectedSize, NSURL * _Nullable targetURL) {
expect(targetURL).notTo.beNil();
} completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
@ -454,7 +484,7 @@
- (void)test31ThatLoadersManagerWorks {
XCTestExpectation *expectation = [self expectationWithDescription:@"Loaders manager not works"];
NSURL *imageURL = [NSURL URLWithString:kTestJpegURL];
NSURL *imageURL = [NSURL URLWithString:kTestJPEGURL];
[[SDImageLoadersManager sharedManager] loadImageWithURL:imageURL options:0 context:nil progress:^(NSInteger receivedSize, NSInteger expectedSize, NSURL * _Nullable targetURL) {
expect(targetURL).notTo.beNil();
} completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {

View File

@ -23,7 +23,7 @@
- (void)test02ThatDownloadInvokesCompletionBlockWithCorrectParamsAsync {
__block XCTestExpectation *expectation = [self expectationWithDescription:@"Image download completes"];
NSURL *originalImageURL = [NSURL URLWithString:kTestJpegURL];
NSURL *originalImageURL = [NSURL URLWithString:kTestJPEGURL];
[[SDWebImageManager sharedManager] loadImageWithURL:originalImageURL
options:SDWebImageRefreshCached
@ -111,14 +111,14 @@
- (void)test08ThatImageTransformerWork {
XCTestExpectation *expectation = [self expectationWithDescription:@"Image transformer work"];
NSURL *imageURL = [NSURL URLWithString:kTestJpegURL];
NSURL *imageURL = [NSURL URLWithString:kTestJPEGURL];
SDWebImageTestTransformer *transformer = [[SDWebImageTestTransformer alloc] init];
NSBundle *testBundle = [NSBundle bundleForClass:[self class]];
NSString *testImagePath = [testBundle pathForResource:@"TestImage" ofType:@"jpg"];
transformer.testImage = [[UIImage alloc] initWithContentsOfFile:testImagePath];
SDWebImageManager *manager = [[SDWebImageManager alloc] initWithCache:[SDImageCache sharedImageCache] loader:[SDWebImageDownloader sharedDownloader]];
manager.transformer = transformer;
[[SDImageCache sharedImageCache] removeImageForKey:kTestJpegURL withCompletion:^{
[[SDImageCache sharedImageCache] removeImageForKey:kTestJPEGURL withCompletion:^{
[manager loadImageWithURL:imageURL options:SDWebImageTransformAnimatedImage progress:nil completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) {
expect(image).equal(transformer.testImage);
[expectation fulfill];