Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move the test case testWebPDecodeDoesNotTriggerCACopyImage into the WebP repo #104

Merged
merged 1 commit into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading