From 2097f9bcdf6c715d0a9759cefca427b901346ebb Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Sat, 24 Feb 2024 12:55:46 +0800 Subject: [PATCH] Move the test case `testWebPDecodeDoesNotTriggerCACopyImage` into the WebP repo Also, fix the min deployment target --- Podfile | 26 ++++++++++++++++++++++++-- Tests/SDWebImageWebPCoderTests.m | 25 ++++++++++++++++++++++--- 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/Podfile b/Podfile index 7fa787a..8e786c4 100644 --- a/Podfile +++ b/Podfile @@ -1,6 +1,5 @@ install! "cocoapods", - :generate_multiple_pod_projects => true, - :incremental_installation => true + :generate_multiple_pod_projects => true use_frameworks! @@ -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 \ No newline at end of file diff --git a/Tests/SDWebImageWebPCoderTests.m b/Tests/SDWebImageWebPCoderTests.m index 7107746..89a89a8 100644 --- a/Tests/SDWebImageWebPCoderTests.m +++ b/Tests/SDWebImageWebPCoderTests.m @@ -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]; @@ -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 }