瀏覽代碼

Add tests for option fix

onevcat 9 年之前
父節點
當前提交
33611a1bfa
共有 1 個文件被更改,包括 43 次插入2 次删除
  1. 43 2
      Tests/KingfisherTests/ImageDownloaderTests.swift

+ 43 - 2
Tests/KingfisherTests/ImageDownloaderTests.swift

@@ -300,18 +300,59 @@ class ImageDownloaderTests: XCTestCase {
         _ = stubRequest("GET", URLString).andReturn(200)?.withBody(testImageData)
         
         let url = URL(string: URLString)!
+        
         let p = RoundCornerImageProcessor(cornerRadius: 40)
+        let roundcornered = testImage.kf.image(withRoundRadius: 40, fit: testImage.kf.size, scale: 1)
+        
         downloader.downloadImage(with: url, options: [.processor(p)], progressBlock: { (receivedSize, totalSize) -> () in
-            return
+            
         }) { (image, error, imageURL, data) -> () in
             expectation.fulfill()
             XCTAssert(image != nil, "Download should be able to finished for URL: \(imageURL)")
-            XCTAssert(image != testImage, "The processed image should not equal to the original one.")
+            XCTAssertFalse(image!.renderEqual(to: testImage), "The processed image should not equal to the original one.")
+            XCTAssertTrue(image!.renderEqual(to: roundcornered), "The processed image should equal to the one directly processed from original one.")
             XCTAssertEqual(NSData(data: data!), testImageData, "But the original data should equal each other.")
         }
         
         waitForExpectations(timeout: 5, handler: nil)
     }
+    
+    func testDownloadWithDifferentProcessors() {
+        let expectation = self.expectation(description: "wait for downloading image")
+        
+        let URLString = testKeys[0]
+        _ = stubRequest("GET", URLString).andReturn(200)?.withBody(testImageData)
+        
+        let url = URL(string: URLString)!
+        
+        let p1 = RoundCornerImageProcessor(cornerRadius: 40)
+        let roundcornered = testImage.kf.image(withRoundRadius: 40, fit: testImage.kf.size, scale: 1)
+
+        let p2 = BlurImageProcessor(blurRadius: 3.0)
+        let blurred = testImage.kf.blurred(withRadius: 3.0)
+        
+        var count = 0
+        
+        downloader.downloadImage(with: url, options: [.processor(p1)], progressBlock: { (receivedSize, totalSize) -> () in
+
+        }) { (image, error, imageURL, data) -> () in
+            XCTAssertTrue(image!.renderEqual(to: roundcornered), "The processed image should equal to the one directly processed from original one.")
+            
+            count += 1
+            if count == 2 { expectation.fulfill() }
+        }
+        
+        downloader.downloadImage(with: url, options: [.processor(p2)], progressBlock: { (receivedSize, totalSize) -> () in
+            
+        }) { (image, error, imageURL, data) -> () in
+            XCTAssertTrue(image!.renderEqual(to: blurred), "The processed image should equal to the one directly processed from original one.")
+            
+            count += 1
+            if count == 2 { expectation.fulfill() }
+        }
+
+        waitForExpectations(timeout: 5, handler: nil)
+    }
 }
 
 class URLModifier: ImageDownloadRequestModifier {