Update the test case for the CGImage based

This commit is contained in:
DreamPiggy 2021-03-10 17:09:37 +08:00
parent 77f21c7ed9
commit f6074c2e5d
1 changed files with 13 additions and 16 deletions

View File

@ -22,10 +22,10 @@ class WebImageTests: XCTestCase {
let imageUrl = URL(string: "https://nr-platform.s3.amazonaws.com/uploads/platform/published_extension/branding_icon/275/AmazonS3.png") let imageUrl = URL(string: "https://nr-platform.s3.amazonaws.com/uploads/platform/published_extension/branding_icon/275/AmazonS3.png")
let imageView = WebImage(url: imageUrl) let imageView = WebImage(url: imageUrl)
let introspectView = imageView.onSuccess { image, data, cacheType in let introspectView = imageView.onSuccess { image, data, cacheType in
#if os(iOS) || os(tvOS) #if os(macOS)
let displayImage = try? imageView.inspect().group().image(0).uiImage()
#else
let displayImage = try? imageView.inspect().group().image(0).nsImage() let displayImage = try? imageView.inspect().group().image(0).nsImage()
#else
let displayImage = try? imageView.inspect().group().image(0).cgImage()
#endif #endif
XCTAssertNotNil(displayImage) XCTAssertNotNil(displayImage)
expectation.fulfill() expectation.fulfill()
@ -46,15 +46,17 @@ class WebImageTests: XCTestCase {
let introspectView = imageView.onSuccess { image, data, cacheType in let introspectView = imageView.onSuccess { image, data, cacheType in
if let animatedImage = image as? SDAnimatedImage { if let animatedImage = image as? SDAnimatedImage {
XCTAssertTrue(imageView.isAnimating) XCTAssertTrue(imageView.isAnimating)
#if os(iOS) || os(tvOS) #if os(macOS)
let displayImage = try? imageView.inspect().group().image(0).uiImage()
#else
let displayImage = try? imageView.inspect().group().image(0).nsImage() let displayImage = try? imageView.inspect().group().image(0).nsImage()
let size = displayImage?.size
#else
let displayImage = try? imageView.inspect().group().image(0).cgImage()
let size = CGSize(width: displayImage?.width ?? 0, height: displayImage?.height ?? 0)
#endif #endif
XCTAssertNotNil(displayImage) XCTAssertNotNil(displayImage)
// Check display image should match the animated poster frame // Check display image should match the animated poster frame
let posterImage = animatedImage.animatedImageFrame(at: 0) let posterImage = animatedImage.animatedImageFrame(at: 0)
XCTAssertEqual(displayImage?.size, posterImage?.size) XCTAssertEqual(size, posterImage?.size)
expectation.fulfill() expectation.fulfill()
} else { } else {
XCTFail("WebImage animated image invalid") XCTFail("WebImage animated image invalid")
@ -162,15 +164,10 @@ class WebImageTests: XCTestCase {
let displayImage = try? imageView.inspect().group().image(0).nsImage() let displayImage = try? imageView.inspect().group().image(0).nsImage()
XCTAssertNotNil(displayImage) XCTAssertNotNil(displayImage)
#else #else
if #available(iOS 14.0, watchOS 7.0, tvOS 14.0, *) { let displayImage = try? imageView.inspect().group().image(0).cgImage()
let displayImage = try? imageView.inspect().group().image(0).uiImage() let orientation = try? imageView.inspect().group().image(0).orientation()
XCTAssertEqual(displayImage, image) XCTAssertNotNil(displayImage)
} else { XCTAssertEqual(orientation, .leftMirrored)
let displayImage = try? imageView.inspect().group().image(0).cgImage()
let orientation = try? imageView.inspect().group().image(0).orientation()
XCTAssertNotNil(displayImage)
XCTAssertEqual(orientation, .leftMirrored)
}
#endif #endif
expectation.fulfill() expectation.fulfill()
}.onFailure { error in }.onFailure { error in