From b557de276de9ab86fb426186046ac5483bb63304 Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Mon, 25 Mar 2024 15:40:33 +0800 Subject: [PATCH] Update test case function `SDAssertCGImagePixelFormatEqual` to avoid assert on iOS 17.0 --- Tests/Tests/SDImageTransformerTests.m | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Tests/Tests/SDImageTransformerTests.m b/Tests/Tests/SDImageTransformerTests.m index 17a06ee8..7ad802f9 100644 --- a/Tests/Tests/SDImageTransformerTests.m +++ b/Tests/Tests/SDImageTransformerTests.m @@ -14,8 +14,20 @@ static void SDAssertCGImagePixelFormatEqual(CGImageRef image1, CGImageRef image2) { CGBitmapInfo bitmapInfo1 = CGImageGetBitmapInfo(image1); CGBitmapInfo bitmapInfo2 = CGImageGetBitmapInfo(image2); - XCTAssertEqual(bitmapInfo1, bitmapInfo2); - // alphaInfo && byteOrderInfo && pixelFomat are just calculation of bitmapInfo +// XCTAssertEqual(bitmapInfo1, bitmapInfo2); + CGImageAlphaInfo alphaInfo1 = bitmapInfo1 & kCGBitmapAlphaInfoMask; + CGImageAlphaInfo alphaInfo2 = bitmapInfo2 & kCGBitmapAlphaInfoMask; + XCTAssertEqual(alphaInfo1, alphaInfo2); + CGImageByteOrderInfo byteOrderInfo1 = bitmapInfo1 & kCGBitmapByteOrderMask; + CGImageByteOrderInfo byteOrderInfo2 = bitmapInfo2 & kCGBitmapByteOrderMask; + // Note: Known issue that iOS 17.0~17.2 contains BUG that vImage convert CGImage does not keep byteOrder for 16bit + // The Buggy API is: `vImageCreateCGImageFromBuffer`, the `format`'s bitmap info will be ignored. + if (byteOrderInfo1 != byteOrderInfo2) { + NSLog(@"SDAssertCGImagePixelFormatEqual: mismatched byte order info, maybe Apple's Bug on iOS 17.0-17.2"); + } + if (@available(iOS 12.0, tvOS 12.0, macOS 10.14, watchOS 5.0, *)) { + XCTAssertEqual(CGImageGetPixelFormatInfo(image1), CGImageGetPixelFormatInfo(image2)); + } XCTAssertEqual(CGImageGetColorSpace(image1), CGImageGetColorSpace(image2)); XCTAssertEqual(CGImageGetBitsPerPixel(image1), CGImageGetBitsPerPixel(image2)); XCTAssertEqual(CGImageGetBitsPerComponent(image1), CGImageGetBitsPerComponent(image2));