Skip to content

Commit e83f42e

Browse files
committed
Added tests from the main project + Travis CI trigger
1 parent 0ba845c commit e83f42e

File tree

10 files changed

+495
-19
lines changed

10 files changed

+495
-19
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ script:
3434
- pod install --project-directory=Example
3535
- xcodebuild build -workspace SDWebImageWebPCoder.xcworkspace -scheme SDWebImageWebPCoderExample -sdk iphonesimulator -destination 'name=iPhone 6s' -configuration Debug | xcpretty -c
3636

37-
# - echo Run the tests
38-
# - xcodebuild test -workspace Example/SDImageWebPCoderExample.xcworkspace -scheme 'SDImageWebPCoderTests' -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 8' -configuration Debug | xcpretty -c
37+
- echo Run the tests
38+
- xcodebuild test -workspace SDWebImageWebPCoder.xcworkspace -scheme 'SDWebImageWebPCoderTests' -sdk iphonesimulator -destination 'name=iPhone 6s' -configuration Debug | xcpretty -c

SDWebImageWebPCoder.xcodeproj/project.pbxproj

Lines changed: 220 additions & 17 deletions
Large diffs are not rendered by default.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "0940"
4+
version = "1.3">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES">
8+
</BuildAction>
9+
<TestAction
10+
buildConfiguration = "Debug"
11+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
12+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
13+
shouldUseLaunchSchemeArgsEnv = "YES">
14+
<Testables>
15+
<TestableReference
16+
skipped = "NO">
17+
<BuildableReference
18+
BuildableIdentifier = "primary"
19+
BlueprintIdentifier = "808C918A213FD130004B0F7C"
20+
BuildableName = "SDWebImageWebPCoderTests.xctest"
21+
BlueprintName = "SDWebImageWebPCoderTests"
22+
ReferencedContainer = "container:SDWebImageWebPCoder.xcodeproj">
23+
</BuildableReference>
24+
</TestableReference>
25+
</Testables>
26+
<AdditionalOptions>
27+
</AdditionalOptions>
28+
</TestAction>
29+
<LaunchAction
30+
buildConfiguration = "Debug"
31+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
32+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
33+
launchStyle = "0"
34+
useCustomWorkingDirectory = "NO"
35+
ignoresPersistentStateOnLaunch = "NO"
36+
debugDocumentVersioning = "YES"
37+
debugServiceExtension = "internal"
38+
allowLocationSimulation = "YES">
39+
<AdditionalOptions>
40+
</AdditionalOptions>
41+
</LaunchAction>
42+
<ProfileAction
43+
buildConfiguration = "Release"
44+
shouldUseLaunchSchemeArgsEnv = "YES"
45+
savedToolIdentifier = ""
46+
useCustomWorkingDirectory = "NO"
47+
debugDocumentVersioning = "YES">
48+
</ProfileAction>
49+
<AnalyzeAction
50+
buildConfiguration = "Debug">
51+
</AnalyzeAction>
52+
<ArchiveAction
53+
buildConfiguration = "Release"
54+
revealArchiveInOrganizer = "YES">
55+
</ArchiveAction>
56+
</Scheme>

SDWebImageWebPCoder.xcworkspace/contents.xcworkspacedata

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

SDWebImageWebPCoder/Module/SDWebImageWebPCoder.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
* file that was distributed with this source code.
77
*/
88

9+
#import <Foundation/Foundation.h>
10+
911
FOUNDATION_EXPORT double SDWebImageWebPCoderVersionNumber;
1012
FOUNDATION_EXPORT const unsigned char SDWebImageWebPCoderVersionString[];
1113

Binary file not shown.
Binary file not shown.

SDWebImageWebPCoderTests/Info.plist

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>$(DEVELOPMENT_LANGUAGE)</string>
7+
<key>CFBundleExecutable</key>
8+
<string>$(EXECUTABLE_NAME)</string>
9+
<key>CFBundleIdentifier</key>
10+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
11+
<key>CFBundleInfoDictionaryVersion</key>
12+
<string>6.0</string>
13+
<key>CFBundleName</key>
14+
<string>$(PRODUCT_NAME)</string>
15+
<key>CFBundlePackageType</key>
16+
<string>BNDL</string>
17+
<key>CFBundleShortVersionString</key>
18+
<string>1.0</string>
19+
<key>CFBundleVersion</key>
20+
<string>1</string>
21+
</dict>
22+
</plist>

SDWebImageWebPCoderTests/Podfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
platform :ios, '8.0'
2+
use_frameworks!
3+
4+
project '../SDWebImageWebPCoder'
5+
workspace '../SDWebImageWebPCoder'
6+
7+
target 'SDWebImageWebPCoderTests' do
8+
pod 'SDWebImageWebPCoder', :path => '../'
9+
end
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
/*
2+
* This file is part of the SDWebImage package.
3+
* (c) Olivier Poitrey <[email protected]>
4+
*
5+
* For the full copyright and license information, please view the LICENSE
6+
* file that was distributed with this source code.
7+
*/
8+
9+
@import Foundation;
10+
@import XCTest;
11+
#import <SDWebImage/SDWebImage.h>
12+
#import <SDWebImageWebPCoder/SDWebImageWebPCoder.h>
13+
14+
const int64_t kAsyncTestTimeout = 5;
15+
16+
@interface SDWebImageWebPCoderTests : XCTestCase
17+
@end
18+
19+
@interface SDWebImageWebPCoderTests (Helpers)
20+
- (void)verifyCoder:(id<SDImageCoder>)coder
21+
withLocalImageURL:(NSURL *)imageUrl
22+
supportsEncoding:(BOOL)supportsEncoding
23+
isAnimatedImage:(BOOL)isAnimated;
24+
@end
25+
26+
// Internal header
27+
@interface SDAnimatedImageView ()
28+
@property (nonatomic, assign) BOOL isProgressive;
29+
@end
30+
31+
@implementation SDWebImageWebPCoderTests
32+
33+
+ (void)setUp {
34+
[[SDImageCodersManager sharedManager] addCoder:[SDImageWebPCoder sharedCoder]];
35+
}
36+
37+
+ (void)tearDown {
38+
[[SDImageCodersManager sharedManager] removeCoder:[SDImageWebPCoder sharedCoder]];
39+
}
40+
41+
- (void)test01ThatWEBPWorks {
42+
XCTestExpectation *expectation = [self expectationWithDescription:@"WEBP"];
43+
NSURL *imageURL = [NSURL URLWithString:@"http://www.ioncannon.net/wp-content/uploads/2011/06/test2.webp"];
44+
[[SDWebImageDownloader sharedDownloader] downloadImageWithURL:imageURL options:0 progress:nil completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
45+
if (image && data && !error && finished) {
46+
[expectation fulfill];
47+
} else {
48+
XCTFail(@"Something went wrong");
49+
}
50+
}];
51+
[self waitForExpectationsWithTimeout:kAsyncTestTimeout handler:nil];
52+
}
53+
54+
- (void)test02ThatProgressiveWebPWorks {
55+
XCTestExpectation *expectation = [self expectationWithDescription:@"Progressive WebP download"];
56+
NSURL *imageURL = [NSURL URLWithString:@"http://www.ioncannon.net/wp-content/uploads/2011/06/test9.webp"];
57+
[[SDWebImageDownloader sharedDownloader] downloadImageWithURL:imageURL options:SDWebImageDownloaderProgressiveLoad progress:nil completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
58+
if (image && data && !error && finished) {
59+
[expectation fulfill];
60+
} else if (finished) {
61+
XCTFail(@"Something went wrong");
62+
} else {
63+
// progressive updates
64+
}
65+
}];
66+
[self waitForExpectationsWithTimeout:kAsyncTestTimeout handler:nil];
67+
}
68+
69+
- (void)test11ThatStaticWebPCoderWorks {
70+
NSURL *staticWebPURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"TestImageStatic" withExtension:@"webp"];
71+
[self verifyCoder:[SDImageWebPCoder sharedCoder]
72+
withLocalImageURL:staticWebPURL
73+
supportsEncoding:YES
74+
isAnimatedImage:NO];
75+
}
76+
77+
- (void)test12ThatAnimatedWebPCoderWorks {
78+
NSURL *animatedWebPURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"TestImageAnimated" withExtension:@"webp"];
79+
[self verifyCoder:[SDImageWebPCoder sharedCoder]
80+
withLocalImageURL:animatedWebPURL
81+
supportsEncoding:YES
82+
isAnimatedImage:YES];
83+
}
84+
85+
- (void)test21UIImageWebPCategory {
86+
// Test invalid image data
87+
UIImage *image = [UIImage sd_imageWithWebPData:nil];
88+
XCTAssertNil(image);
89+
// Test valid image data
90+
NSURL *staticWebPURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"TestImageStatic" withExtension:@"webp"];
91+
NSData *data = [NSData dataWithContentsOfURL:staticWebPURL];
92+
image = [UIImage sd_imageWithWebPData:data];
93+
XCTAssertNotNil(image);
94+
}
95+
96+
- (void)test31AnimatedImageViewSetAnimatedImageWEBP {
97+
SDAnimatedImageView *imageView = [SDAnimatedImageView new];
98+
NSURL *animatedWebPURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"TestImageAnimated" withExtension:@"webp"];
99+
NSData *animatedImageData = [NSData dataWithContentsOfURL:animatedWebPURL];
100+
SDAnimatedImage *image = [SDAnimatedImage imageWithData:animatedImageData];
101+
imageView.image = image;
102+
XCTAssertNotNil(imageView.image);
103+
XCTAssertNotNil(imageView.currentFrame); // current frame
104+
}
105+
106+
- (void)test32AnimatedImageViewCategoryProgressive {
107+
XCTestExpectation *expectation = [self expectationWithDescription:@"test SDAnimatedImageView view category"];
108+
SDAnimatedImageView *imageView = [SDAnimatedImageView new];
109+
NSURL *testURL = [NSURL URLWithString:@"http://littlesvr.ca/apng/images/SteamEngine.webp"];
110+
[imageView sd_setImageWithURL:testURL placeholderImage:nil options:SDWebImageProgressiveLoad progress:^(NSInteger receivedSize, NSInteger expectedSize, NSURL * _Nullable targetURL) {
111+
dispatch_async(dispatch_get_main_queue(), ^{
112+
UIImage *image = imageView.image;
113+
// Progressive image may be nil when download data is not enough
114+
if (image) {
115+
XCTAssertTrue(image.sd_isIncremental);
116+
XCTAssertTrue([image conformsToProtocol:@protocol(SDAnimatedImage)]);
117+
XCTAssertTrue(imageView.isProgressive);
118+
}
119+
});
120+
} completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
121+
XCTAssertNil(error);
122+
XCTAssertNotNil(image);
123+
XCTAssertTrue([image isKindOfClass:[SDAnimatedImage class]]);
124+
[expectation fulfill];
125+
}];
126+
[self waitForExpectationsWithTimeout:kAsyncTestTimeout handler:nil];
127+
}
128+
129+
130+
@end
131+
132+
@implementation SDWebImageWebPCoderTests (Helpers)
133+
134+
- (void)verifyCoder:(id<SDImageCoder>)coder
135+
withLocalImageURL:(NSURL *)imageUrl
136+
supportsEncoding:(BOOL)supportsEncoding
137+
isAnimatedImage:(BOOL)isAnimated {
138+
NSData *inputImageData = [NSData dataWithContentsOfURL:imageUrl];
139+
XCTAssertNotNil(inputImageData, @"Input image data should not be nil");
140+
SDImageFormat inputImageFormat = [NSData sd_imageFormatForImageData:inputImageData];
141+
XCTAssert(inputImageFormat != SDImageFormatUndefined, @"Input image format should not be undefined");
142+
143+
// 1 - check if we can decode - should be true
144+
XCTAssertTrue([coder canDecodeFromData:inputImageData]);
145+
146+
// 2 - decode from NSData to UIImage and check it
147+
UIImage *inputImage = [coder decodedImageWithData:inputImageData options:nil];
148+
XCTAssertNotNil(inputImage, @"The decoded image from input data should not be nil");
149+
150+
if (isAnimated) {
151+
// 2a - check images count > 0 (only for animated images)
152+
XCTAssertTrue(inputImage.sd_isAnimated, @"The decoded image should be animated");
153+
154+
// 2b - check image size and scale for each frameImage (only for animated images)
155+
#if SD_UIKIT
156+
CGSize imageSize = inputImage.size;
157+
CGFloat imageScale = inputImage.scale;
158+
[inputImage.images enumerateObjectsUsingBlock:^(UIImage * frameImage, NSUInteger idx, BOOL * stop) {
159+
XCTAssertTrue(CGSizeEqualToSize(imageSize, frameImage.size), @"Each frame size should match the image size");
160+
XCTAssertEqual(imageScale, frameImage.scale, @"Each frame scale should match the image scale");
161+
}];
162+
#endif
163+
}
164+
165+
if (supportsEncoding) {
166+
// 3 - check if we can encode to the original format
167+
XCTAssertTrue([coder canEncodeToFormat:inputImageFormat], @"Coder should be able to encode");
168+
169+
// 4 - encode from UIImage to NSData using the inputImageFormat and check it
170+
NSData *outputImageData = [coder encodedDataWithImage:inputImage format:inputImageFormat options:nil];
171+
XCTAssertNotNil(outputImageData, @"The encoded image data should not be nil");
172+
UIImage *outputImage = [coder decodedImageWithData:outputImageData options:nil];
173+
XCTAssertTrue(CGSizeEqualToSize(outputImage.size, inputImage.size), @"Output and input image size should match");
174+
XCTAssertEqual(outputImage.scale, inputImage.scale, @"Output and input image scale should match");
175+
#if SD_UIKIT
176+
XCTAssertEqual(outputImage.images.count, inputImage.images.count, @"Output and input image frame count should match");
177+
#endif
178+
}
179+
}
180+
181+
@end

0 commit comments

Comments
 (0)