@@ -233,6 +233,21 @@ - (void)test46WebPEncodingMonochrome {
233
233
XCTAssert (data);
234
234
}
235
235
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
+
236
251
- (void )testWebPDecodeDoesNotTriggerCACopyImage {
237
252
NSURL *staticWebPURL = [[NSBundle bundleForClass: [self class ]] URLForResource: @" TestColorspaceStatic" withExtension: @" webp" ];
238
253
NSData *data = [NSData dataWithContentsOfURL: staticWebPURL];
@@ -241,11 +256,15 @@ - (void)testWebPDecodeDoesNotTriggerCACopyImage {
241
256
size_t bytesPerRow = CGImageGetBytesPerRow (cgImage);
242
257
XCTAssertEqual (bytesPerRow, 4096 );
243
258
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);
245
261
#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" );
247
263
#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
+ }
249
268
#endif
250
269
}
251
270
0 commit comments