|
|
@@ -219,9 +219,9 @@ class KingfisherManagerTests: XCTestCase {
|
|
|
let expectation = self.expectation(description: "running on main queue")
|
|
|
let URLString = testKeys[0]
|
|
|
_ = stubRequest("GET", URLString).andReturn(404)
|
|
|
-
|
|
|
+
|
|
|
let url = URL(string: URLString)!
|
|
|
-
|
|
|
+
|
|
|
manager.retrieveImage(with: url, options: nil, progressBlock: { _, _ in
|
|
|
//won't be called
|
|
|
}, completionHandler: { _, error, _, _ in
|
|
|
@@ -231,7 +231,7 @@ class KingfisherManagerTests: XCTestCase {
|
|
|
})
|
|
|
waitForExpectations(timeout: 5, handler: nil)
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
func testSucessCompletionHandlerRunningOnCustomQueue() {
|
|
|
let progressExpectation = expectation(description: "progressBlock running on custom queue")
|
|
|
let completionExpectation = expectation(description: "completionHandler running on custom queue")
|
|
|
@@ -250,8 +250,10 @@ class KingfisherManagerTests: XCTestCase {
|
|
|
if #available(iOS 10.0, tvOS 10.0, macOS 10.12, *) {
|
|
|
dispatchPrecondition(condition: .onQueue(customQueue))
|
|
|
}
|
|
|
-
|
|
|
- completionExpectation.fulfill()
|
|
|
+
|
|
|
+ DispatchQueue.main.async {
|
|
|
+ completionExpectation.fulfill()
|
|
|
+ }
|
|
|
})
|
|
|
waitForExpectations(timeout: 5, handler: nil)
|
|
|
}
|
|
|
@@ -271,13 +273,15 @@ class KingfisherManagerTests: XCTestCase {
|
|
|
if #available(iOS 10.0, tvOS 10.0, macOS 10.12, *) {
|
|
|
dispatchPrecondition(condition: .onQueue(customQueue))
|
|
|
}
|
|
|
- expectation.fulfill()
|
|
|
+ DispatchQueue.main.async {
|
|
|
+ expectation.fulfill()
|
|
|
+ }
|
|
|
})
|
|
|
waitForExpectations(timeout: 5, handler: nil)
|
|
|
}
|
|
|
|
|
|
func testDefaultOptionCouldApply() {
|
|
|
- let expectation = self.expectation(description: "running on custom queue")
|
|
|
+ let expectation = self.expectation(description: "Default options")
|
|
|
let URLString = testKeys[0]
|
|
|
_ = stubRequest("GET", URLString).andReturn(200)?.withBody(testImageData)
|
|
|
|
|
|
@@ -295,34 +299,33 @@ class KingfisherManagerTests: XCTestCase {
|
|
|
|
|
|
func testOriginalImageCouldBeStored() {
|
|
|
let expectation = self.expectation(description: "waiting for cache finished")
|
|
|
- delay(0.1) {
|
|
|
- let URLString = testKeys[0]
|
|
|
- _ = stubRequest("GET", URLString).andReturn(200)?.withBody(testImageData)
|
|
|
- let url = URL(string: URLString)!
|
|
|
-
|
|
|
- let p = SimpleProcessor()
|
|
|
- let options: KingfisherOptionsInfo = [.processor(p), .cacheOriginalImage]
|
|
|
- self.manager.downloadAndCacheImage(with: url, forKey: URLString, retrieveImageTask: RetrieveImageTask(), progressBlock: nil, completionHandler: {
|
|
|
- (image, error, cacheType, url) in
|
|
|
- delay(0.1) {
|
|
|
- var imageCached = self.manager.cache.imageCachedType(forKey: URLString, processorIdentifier: p.identifier)
|
|
|
- var originalCached = self.manager.cache.imageCachedType(forKey: URLString)
|
|
|
-
|
|
|
- XCTAssertEqual(imageCached, .memory)
|
|
|
- XCTAssertEqual(originalCached, .memory)
|
|
|
-
|
|
|
- self.manager.cache.clearMemoryCache()
|
|
|
-
|
|
|
- imageCached = self.manager.cache.imageCachedType(forKey: URLString, processorIdentifier: p.identifier)
|
|
|
- originalCached = self.manager.cache.imageCachedType(forKey: URLString)
|
|
|
- XCTAssertEqual(imageCached, .disk)
|
|
|
- XCTAssertEqual(originalCached, .disk)
|
|
|
-
|
|
|
- expectation.fulfill()
|
|
|
- }
|
|
|
- }, options: options)
|
|
|
-
|
|
|
- }
|
|
|
+
|
|
|
+ let URLString = testKeys[0]
|
|
|
+ _ = stubRequest("GET", URLString).andReturn(200)?.withBody(testImageData)
|
|
|
+ let url = URL(string: URLString)!
|
|
|
+
|
|
|
+ let p = SimpleProcessor()
|
|
|
+ let options: KingfisherOptionsInfo = [.processor(p), .cacheOriginalImage]
|
|
|
+ self.manager.downloadAndCacheImage(with: url, forKey: URLString, retrieveImageTask: RetrieveImageTask(), progressBlock: nil, completionHandler: {
|
|
|
+ (image, error, cacheType, url) in
|
|
|
+ delay(0.1) {
|
|
|
+ var imageCached = self.manager.cache.imageCachedType(forKey: URLString, processorIdentifier: p.identifier)
|
|
|
+ var originalCached = self.manager.cache.imageCachedType(forKey: URLString)
|
|
|
+
|
|
|
+ XCTAssertEqual(imageCached, .memory)
|
|
|
+ XCTAssertEqual(originalCached, .memory)
|
|
|
+
|
|
|
+ self.manager.cache.clearMemoryCache()
|
|
|
+
|
|
|
+ imageCached = self.manager.cache.imageCachedType(forKey: URLString, processorIdentifier: p.identifier)
|
|
|
+ originalCached = self.manager.cache.imageCachedType(forKey: URLString)
|
|
|
+ XCTAssertEqual(imageCached, .disk)
|
|
|
+ XCTAssertEqual(originalCached, .disk)
|
|
|
+
|
|
|
+ expectation.fulfill()
|
|
|
+ }
|
|
|
+ }, options: options)
|
|
|
+
|
|
|
self.waitForExpectations(timeout: 5, handler: nil)
|
|
|
}
|
|
|
|