Skip to content

Commit

Permalink
Merge pull request #104 from SDWebImage/project/unit-test-update
Browse files Browse the repository at this point in the history
Move the test case `testWebPDecodeDoesNotTriggerCACopyImage` into the WebP repo
  • Loading branch information
dreampiggy authored Feb 24, 2024
2 parents 8a33fb3 + 2097f9b commit 11e7ea4
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 5 deletions.
26 changes: 24 additions & 2 deletions Podfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
install! "cocoapods",
:generate_multiple_pod_projects => true,
:incremental_installation => true
:generate_multiple_pod_projects => true

use_frameworks!

Expand Down Expand Up @@ -33,3 +32,26 @@ target 'SDWebImageWebPCoderTests-macOS' do
pod 'Expecta'
pod 'SDWebImageWebPCoder', :path => './'
end


# Inject macro during SDWebImage Demo and Tests
post_install do |installer_representation|
installer_representation.generated_projects.each do |project|
project.targets.each do |target|
if target.product_name == 'SDWebImageWebPCoder'
target.build_configurations.each do |config|
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] = '$(inherited) SD_CHECK_CGIMAGE_RETAIN_SOURCE=1'
end
else
target.build_configurations.each do |config|
# Override the min deployment target for some test specs to workaround `libarclite.a` missing issue
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '9.0'
config.build_settings['MACOSX_DEPLOYMENT_TARGET'] = '10.11'
config.build_settings['TVOS_DEPLOYMENT_TARGET'] = '9.0'
config.build_settings['WATCHOS_DEPLOYMENT_TARGET'] = '2.0'
config.build_settings['XROS_DEPLOYMENT_TARGET'] = '1.0'
end
end
end
end
end
25 changes: 22 additions & 3 deletions Tests/SDWebImageWebPCoderTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,21 @@ - (void)test46WebPEncodingMonochrome {
XCTAssert(data);
}

- (void)test22ThatForceDecodePolicyAlways {
XCTestExpectation *expectation = [self expectationWithDescription:@"Always policy with WebP image (libwebp) should force-decode"];
NSURL *url = [NSURL URLWithString:@"https://www.gstatic.com/webp/gallery/4.webp"];
[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) {
expect(image).notTo.beNil();
expect(image.sd_isDecoded).beTruthy();
CGImageRef cgImage = image.CGImage;
CGColorSpaceRef colorspace = CGImageGetColorSpace(cgImage);
expect(colorspace).equal([SDImageCoderHelper colorSpaceGetDeviceRGB]);

[expectation fulfill];
}];
[self waitForExpectationsWithTimeout:5 handler:nil];
}

- (void)testWebPDecodeDoesNotTriggerCACopyImage {
NSURL *staticWebPURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"TestColorspaceStatic" withExtension:@"webp"];
NSData *data = [NSData dataWithContentsOfURL:staticWebPURL];
Expand All @@ -241,11 +256,15 @@ - (void)testWebPDecodeDoesNotTriggerCACopyImage {
size_t bytesPerRow = CGImageGetBytesPerRow(cgImage);
XCTAssertEqual(bytesPerRow, 4096);
CGColorSpaceRef colorspace = CGImageGetColorSpace(cgImage);
NSString *colorspaceName = (__bridge_transfer NSString *)CGColorSpaceCopyName(colorspace);
if (@available(iOS 10.0, macOS 10.6, *)) {
NSString *colorspaceName = (__bridge_transfer NSString *)CGColorSpaceCopyName(colorspace);
#if SD_MAC
XCTAssertEqual(colorspace, NSScreen.mainScreen.colorSpace.CGColorSpace, @"Color space is not screen");
XCTAssertEqual(colorspace, NSScreen.mainScreen.colorSpace.CGColorSpace, @"Color space is not screen");
#else
XCTAssertEqual(colorspaceName, (__bridge NSString *)kCGColorSpaceSRGB, @"Color space is not sRGB");
XCTAssertEqual(colorspaceName, (__bridge NSString *)kCGColorSpaceSRGB, @"Color space is not sRGB");
} else {
// Fallback on earlier versions
}
#endif
}

Expand Down

0 comments on commit 11e7ea4

Please sign in to comment.