Update the test case about the new image data arg

This commit is contained in:
DreamPiggy 2020-05-06 23:19:28 +08:00
parent b174fee26b
commit f36440f508
2 changed files with 28 additions and 8 deletions

View File

@ -74,7 +74,8 @@ class AnimatedImageTests: XCTestCase {
let expectation = self.expectation(description: "AnimatedImage url initializer") let expectation = self.expectation(description: "AnimatedImage url initializer")
let imageUrl = URL(string: "https://raw.githubusercontent.com/liyong03/YLGIFImage/master/YLGIFImageDemo/YLGIFImageDemo/joy.gif") let imageUrl = URL(string: "https://raw.githubusercontent.com/liyong03/YLGIFImage/master/YLGIFImageDemo/YLGIFImageDemo/joy.gif")
let imageView = AnimatedImage(url: imageUrl) let imageView = AnimatedImage(url: imageUrl)
.onSuccess { image, cacheType in .onSuccess { image, data, cacheType in
XCTAssertNotNil(image)
if let animatedImage = image as? SDAnimatedImage { if let animatedImage = image as? SDAnimatedImage {
XCTAssertEqual(animatedImage.animatedImageLoopCount, 0) XCTAssertEqual(animatedImage.animatedImageLoopCount, 0)
XCTAssertEqual(animatedImage.animatedImageFrameCount, 389) XCTAssertEqual(animatedImage.animatedImageFrameCount, 389)
@ -88,7 +89,7 @@ class AnimatedImageTests: XCTestCase {
ViewHosting.host(view: imageView) ViewHosting.host(view: imageView)
let animatedImageView = try imageView.inspect().actualView().platformView().wrapped let animatedImageView = try imageView.inspect().actualView().platformView().wrapped
XCTAssertEqual(animatedImageView.sd_imageURL, imageUrl) XCTAssertEqual(animatedImageView.sd_imageURL, imageUrl)
self.waitForExpectations(timeout: 5, handler: nil) self.waitForExpectations(timeout: 10, handler: nil)
ViewHosting.expel() ViewHosting.expel()
} }

View File

@ -21,7 +21,7 @@ class WebImageTests: XCTestCase {
let expectation = self.expectation(description: "WebImage static url initializer") let expectation = self.expectation(description: "WebImage static url initializer")
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, cacheType in let introspectView = imageView.onSuccess { image, data, cacheType in
#if os(iOS) || os(tvOS) #if os(iOS) || os(tvOS)
let displayImage = try? imageView.inspect().group().image(0).uiImage() let displayImage = try? imageView.inspect().group().image(0).uiImage()
#else #else
@ -43,7 +43,7 @@ class WebImageTests: XCTestCase {
let imageUrl = URL(string: "https://apng.onevcat.com/assets/elephant.png") let imageUrl = URL(string: "https://apng.onevcat.com/assets/elephant.png")
let binding = Binding<Bool>(wrappedValue: true) let binding = Binding<Bool>(wrappedValue: true)
let imageView = WebImage(url: imageUrl, isAnimating: binding) let imageView = WebImage(url: imageUrl, isAnimating: binding)
let introspectView = imageView.onSuccess { image, 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(iOS) || os(tvOS)
@ -73,7 +73,7 @@ class WebImageTests: XCTestCase {
let imageUrl = URL(string: "https://raw.githubusercontent.com/ibireme/YYImage/master/Demo/YYImageDemo/mew_baseline.jpg") let imageUrl = URL(string: "https://raw.githubusercontent.com/ibireme/YYImage/master/Demo/YYImageDemo/mew_baseline.jpg")
let imageView = WebImage(url: imageUrl, options: [.progressiveLoad], context: [.imageScaleFactor: 1]) let imageView = WebImage(url: imageUrl, options: [.progressiveLoad], context: [.imageScaleFactor: 1])
let introspectView = imageView let introspectView = imageView
.onSuccess { _, _ in .onSuccess { _, _, _ in
expectation.fulfill() expectation.fulfill()
} }
.onFailure { _ in .onFailure { _ in
@ -111,7 +111,7 @@ class WebImageTests: XCTestCase {
} }
func testWebImageOnSuccessWhenMemoryCacheHit() throws { func testWebImageOnSuccessWhenMemoryCacheHit() throws {
let expectation = self.expectation(description: "WebImage onSuccess when memory hit") let expectation = self.expectation(description: "WebImage onSuccess when memory cache hit")
let imageUrl = URL(string: "https://foo.bar/buzz.png") let imageUrl = URL(string: "https://foo.bar/buzz.png")
let cacheKey = SDWebImageManager.shared.cacheKey(for: imageUrl) let cacheKey = SDWebImageManager.shared.cacheKey(for: imageUrl)
#if os(macOS) #if os(macOS)
@ -121,7 +121,7 @@ class WebImageTests: XCTestCase {
#endif #endif
SDImageCache.shared.storeImage(toMemory: testImage, forKey: cacheKey) SDImageCache.shared.storeImage(toMemory: testImage, forKey: cacheKey)
let imageView = WebImage(url: imageUrl) let imageView = WebImage(url: imageUrl)
let introspectView = imageView.onSuccess { image, cacheType in let introspectView = imageView.onSuccess { image, data, cacheType in
XCTAssert(cacheType == .memory) XCTAssert(cacheType == .memory)
XCTAssertNotNil(image) XCTAssertNotNil(image)
XCTAssertEqual(image, testImage) XCTAssertEqual(image, testImage)
@ -133,12 +133,31 @@ class WebImageTests: XCTestCase {
ViewHosting.expel() ViewHosting.expel()
} }
func testWebImageOnSuccessWhenCacheMiss() throws {
let expectation = self.expectation(description: "WebImage onSuccess when cache miss")
let imageUrl = URL(string: "http://via.placeholder.com/100x100.png")
let cacheKey = SDWebImageManager.shared.cacheKey(for: imageUrl)
SDImageCache.shared.removeImageFromMemory(forKey: cacheKey)
SDImageCache.shared.removeImageFromDisk(forKey: cacheKey)
let imageView = WebImage(url: imageUrl)
let introspectView = imageView.onSuccess { image, data, cacheType in
XCTAssert(cacheType == .none)
XCTAssertNotNil(image)
XCTAssertNotNil(data)
expectation.fulfill()
}
_ = try introspectView.inspect()
ViewHosting.host(view: introspectView)
self.waitForExpectations(timeout: 5, handler: nil)
ViewHosting.expel()
}
func testWebImageEXIFImage() throws { func testWebImageEXIFImage() throws {
let expectation = self.expectation(description: "WebImage EXIF image url") let expectation = self.expectation(description: "WebImage EXIF image url")
// EXIF 5, Left Mirrored // EXIF 5, Left Mirrored
let imageUrl = URL(string: "https://raw.githubusercontent.com/recurser/exif-orientation-examples/master/Landscape_5.jpg") let imageUrl = URL(string: "https://raw.githubusercontent.com/recurser/exif-orientation-examples/master/Landscape_5.jpg")
let imageView = WebImage(url: imageUrl) let imageView = WebImage(url: imageUrl)
let introspectView = imageView.onSuccess { image, cacheType in let introspectView = imageView.onSuccess { image, data, cacheType in
let displayImage = try? imageView.inspect().group().image(0).cgImage() let displayImage = try? imageView.inspect().group().image(0).cgImage()
let orientation = try! imageView.inspect().group().image(0).orientation() let orientation = try! imageView.inspect().group().image(0).orientation()
XCTAssertNotNil(displayImage) XCTAssertNotNil(displayImage)