Skip to content

Commit 11e7ea4

Browse files
authored
Merge pull request #104 from SDWebImage/project/unit-test-update
Move the test case `testWebPDecodeDoesNotTriggerCACopyImage` into the WebP repo
2 parents 8a33fb3 + 2097f9b commit 11e7ea4

File tree

2 files changed

+46
-5
lines changed

2 files changed

+46
-5
lines changed

Diff for: Podfile

+24-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
install! "cocoapods",
2-
:generate_multiple_pod_projects => true,
3-
:incremental_installation => true
2+
:generate_multiple_pod_projects => true
43

54
use_frameworks!
65

@@ -33,3 +32,26 @@ target 'SDWebImageWebPCoderTests-macOS' do
3332
pod 'Expecta'
3433
pod 'SDWebImageWebPCoder', :path => './'
3534
end
35+
36+
37+
# Inject macro during SDWebImage Demo and Tests
38+
post_install do |installer_representation|
39+
installer_representation.generated_projects.each do |project|
40+
project.targets.each do |target|
41+
if target.product_name == 'SDWebImageWebPCoder'
42+
target.build_configurations.each do |config|
43+
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] = '$(inherited) SD_CHECK_CGIMAGE_RETAIN_SOURCE=1'
44+
end
45+
else
46+
target.build_configurations.each do |config|
47+
# Override the min deployment target for some test specs to workaround `libarclite.a` missing issue
48+
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '9.0'
49+
config.build_settings['MACOSX_DEPLOYMENT_TARGET'] = '10.11'
50+
config.build_settings['TVOS_DEPLOYMENT_TARGET'] = '9.0'
51+
config.build_settings['WATCHOS_DEPLOYMENT_TARGET'] = '2.0'
52+
config.build_settings['XROS_DEPLOYMENT_TARGET'] = '1.0'
53+
end
54+
end
55+
end
56+
end
57+
end

Diff for: Tests/SDWebImageWebPCoderTests.m

+22-3
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,21 @@ - (void)test46WebPEncodingMonochrome {
233233
XCTAssert(data);
234234
}
235235

236+
- (void)test22ThatForceDecodePolicyAlways {
237+
XCTestExpectation *expectation = [self expectationWithDescription:@"Always policy with WebP image (libwebp) should force-decode"];
238+
NSURL *url = [NSURL URLWithString:@"https://www.gstatic.com/webp/gallery/4.webp"];
239+
[SDWebImageManager.sharedManager loadImageWithURL:url options:SDWebImageFromLoaderOnly context:@{SDWebImageContextImageCoder : SDImageWebPCoder.sharedCoder, SDWebImageContextImageForceDecodePolicy : @(SDImageForceDecodePolicyAlways)} progress:nil completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) {
240+
expect(image).notTo.beNil();
241+
expect(image.sd_isDecoded).beTruthy();
242+
CGImageRef cgImage = image.CGImage;
243+
CGColorSpaceRef colorspace = CGImageGetColorSpace(cgImage);
244+
expect(colorspace).equal([SDImageCoderHelper colorSpaceGetDeviceRGB]);
245+
246+
[expectation fulfill];
247+
}];
248+
[self waitForExpectationsWithTimeout:5 handler:nil];
249+
}
250+
236251
- (void)testWebPDecodeDoesNotTriggerCACopyImage {
237252
NSURL *staticWebPURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"TestColorspaceStatic" withExtension:@"webp"];
238253
NSData *data = [NSData dataWithContentsOfURL:staticWebPURL];
@@ -241,11 +256,15 @@ - (void)testWebPDecodeDoesNotTriggerCACopyImage {
241256
size_t bytesPerRow = CGImageGetBytesPerRow(cgImage);
242257
XCTAssertEqual(bytesPerRow, 4096);
243258
CGColorSpaceRef colorspace = CGImageGetColorSpace(cgImage);
244-
NSString *colorspaceName = (__bridge_transfer NSString *)CGColorSpaceCopyName(colorspace);
259+
if (@available(iOS 10.0, macOS 10.6, *)) {
260+
NSString *colorspaceName = (__bridge_transfer NSString *)CGColorSpaceCopyName(colorspace);
245261
#if SD_MAC
246-
XCTAssertEqual(colorspace, NSScreen.mainScreen.colorSpace.CGColorSpace, @"Color space is not screen");
262+
XCTAssertEqual(colorspace, NSScreen.mainScreen.colorSpace.CGColorSpace, @"Color space is not screen");
247263
#else
248-
XCTAssertEqual(colorspaceName, (__bridge NSString *)kCGColorSpaceSRGB, @"Color space is not sRGB");
264+
XCTAssertEqual(colorspaceName, (__bridge NSString *)kCGColorSpaceSRGB, @"Color space is not sRGB");
265+
} else {
266+
// Fallback on earlier versions
267+
}
249268
#endif
250269
}
251270

0 commit comments

Comments
 (0)