Authored by Bogdan Poplauschi

Improved the code coverage of our unit tests (given that we disabled test40InsertionOfImageData).

Also updated the Tests Podfile so we don't get a warning (xcodeproj was renamed to project)
... ... @@ -2,7 +2,7 @@ source 'https://github.com/CocoaPods/Specs.git'
use_frameworks!
xcodeproj 'SDWebImage Tests'
project 'SDWebImage Tests'
workspace '../SDWebImage'
target 'Tests' do
... ...
... ... @@ -46,11 +46,15 @@ NSString *kImageTestKey = @"TestImageKey.jpg";
[self.sharedImageCache clearDiskOnCompletion:^{
[self.sharedImageCache diskImageExistsWithKey:kImageTestKey completion:^(BOOL isInCache) {
if (!isInCache) {
[self.sharedImageCache calculateSizeWithCompletionBlock:^(NSUInteger fileCount, NSUInteger totalSize) {
expect(fileCount).to.beLessThan(100);
[expectation fulfill];
}];
} else {
XCTFail(@"Image should not be in cache");
}
}];
expect([self.sharedImageCache imageFromMemoryCacheForKey:kImageTestKey]).to.equal([self imageForTesting]);
}];
[self waitForExpectationsWithCommonTimeout];
... ...
... ... @@ -11,6 +11,7 @@
#import <SDWebImage/SDWebImageImageIOCoder.h>
#import <SDWebImage/SDWebImageWebPCoder.h>
#import <SDWebImage/UIImage+ForceDecode.h>
#import <SDWebImage/SDWebImageGIFCoder.h>
@interface SDWebImageDecoderTests : SDTestCase
... ... @@ -97,9 +98,13 @@
- (void)test09ThatStaticWebPCoderWorks {
NSURL *staticWebPURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"TestImageStatic" withExtension:@"webp"];
NSData *staticWebPData = [NSData dataWithContentsOfURL:staticWebPURL];
expect([[SDWebImageWebPCoder sharedCoder] canDecodeFromData:staticWebPData]).to.beTruthy();
expect([[SDWebImageImageIOCoder sharedCoder] canDecodeFromData:staticWebPData]).to.beFalsy();
UIImage *staticWebPImage = [[SDWebImageWebPCoder sharedCoder] decodedImageWithData:staticWebPData];
expect(staticWebPImage).toNot.beNil();
expect([[SDWebImageWebPCoder sharedCoder] canEncodeToFormat:SDImageFormatWebP]).to.beTruthy();
expect([[SDWebImageImageIOCoder sharedCoder] canEncodeToFormat:SDImageFormatWebP]).to.beFalsy();
NSData *outputData = [[SDWebImageWebPCoder sharedCoder] encodedDataWithImage:staticWebPImage format:SDImageFormatWebP];
expect(outputData).toNot.beNil();
}
... ... @@ -107,6 +112,7 @@
- (void)test10ThatAnimatedWebPCoderWorks {
NSURL *animatedWebPURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"TestImageAnimated" withExtension:@"webp"];
NSData *animatedWebPData = [NSData dataWithContentsOfURL:animatedWebPURL];
expect([[SDWebImageWebPCoder sharedCoder] canDecodeFromData:animatedWebPData]).to.beTruthy();
UIImage *animatedWebPImage = [[SDWebImageWebPCoder sharedCoder] decodedImageWithData:animatedWebPData];
expect(animatedWebPImage).toNot.beNil();
expect(animatedWebPImage.images.count).to.beGreaterThan(0);
... ... @@ -120,8 +126,36 @@
expect(imageScale).to.equal(scale);
}];
expect([[SDWebImageWebPCoder sharedCoder] canEncodeToFormat:SDImageFormatWebP]).to.beTruthy();
NSData *outputData = [[SDWebImageWebPCoder sharedCoder] encodedDataWithImage:animatedWebPImage format:SDImageFormatWebP];
expect(outputData).toNot.beNil();
}
- (void)test20ThatOurGIFCoderWorksNotFLAnimatedImage {
NSURL *gifURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"TestImage" withExtension:@"gif"];
NSData *gifData = [NSData dataWithContentsOfURL:gifURL];
expect([[SDWebImageGIFCoder sharedCoder] canDecodeFromData:gifData]).to.beTruthy();
// the IOCoder can also decode GIF
expect([[SDWebImageImageIOCoder sharedCoder] canDecodeFromData:gifData]).to.beTruthy();
UIImage *gifImage = [[SDWebImageGIFCoder sharedCoder] decodedImageWithData:gifData];
expect(gifImage).toNot.beNil();
expect(gifImage.images.count).to.beGreaterThan(0);
CGSize imageSize = gifImage.size;
CGFloat imageScale = gifImage.scale;
[gifImage.images enumerateObjectsUsingBlock:^(UIImage * _Nonnull image, NSUInteger idx, BOOL * _Nonnull stop) {
CGSize size = image.size;
CGFloat scale = image.scale;
expect(imageSize.width).to.equal(size.width);
expect(imageSize.height).to.equal(size.height);
expect(imageScale).to.equal(scale);
}];
expect([[SDWebImageGIFCoder sharedCoder] decompressedImageWithImage:gifImage data:nil options:nil]).to.equal(gifImage);
expect([[SDWebImageGIFCoder sharedCoder] canEncodeToFormat:SDImageFormatGIF]).to.beTruthy();
expect([[SDWebImageImageIOCoder sharedCoder] canEncodeToFormat:SDImageFormatGIF]).to.beTruthy();
NSData *outputData = [[SDWebImageGIFCoder sharedCoder] encodedDataWithImage:gifImage format:SDImageFormatGIF];
expect(outputData).toNot.beNil();
}
@end
... ...