@@ -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