onevcat 10 роки тому
батько
коміт
14727be7bd

+ 8 - 0
Kingfisher.xcodeproj/project.pbxproj

@@ -21,6 +21,8 @@
 		4BBA04C41AD7986100A5CF82 /* KingfisherTestHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BBA04C31AD7986100A5CF82 /* KingfisherTestHelper.swift */; };
 		D11250C11BAC4B6300B986EF /* ImageTransition.swift in Sources */ = {isa = PBXBuildFile; fileRef = D11250C01BAC4B6300B986EF /* ImageTransition.swift */; };
 		D151E72B1AD3C48D004FD4AE /* UIImage+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = D151E72A1AD3C48D004FD4AE /* UIImage+Extension.swift */; };
+		D1A7B6C81BDBC9310083A684 /* dancing-banana.gif in Resources */ = {isa = PBXBuildFile; fileRef = D1A7B6C71BDBC9310083A684 /* dancing-banana.gif */; };
+		D1A7B6CA1BDBC9C60083A684 /* ImageExtensionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1A7B6C91BDBC9C60083A684 /* ImageExtensionTests.swift */; };
 		D1B1B9901BC7EB7100DE20D8 /* ThreadHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1B1B98F1BC7EB7100DE20D8 /* ThreadHelper.swift */; };
 		D1ED2D111AD2CFA600CFC3EB /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1ED2D101AD2CFA600CFC3EB /* AppDelegate.swift */; };
 		D1ED2D131AD2CFA600CFC3EB /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1ED2D121AD2CFA600CFC3EB /* ViewController.swift */; };
@@ -105,6 +107,8 @@
 		A9E621E297FEFAD35D39C34E /* libPods-KingfisherTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-KingfisherTests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
 		D11250C01BAC4B6300B986EF /* ImageTransition.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImageTransition.swift; sourceTree = "<group>"; };
 		D151E72A1AD3C48D004FD4AE /* UIImage+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIImage+Extension.swift"; sourceTree = "<group>"; };
+		D1A7B6C71BDBC9310083A684 /* dancing-banana.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; name = "dancing-banana.gif"; path = "../../../../Desktop/dancing-banana.gif"; sourceTree = "<group>"; };
+		D1A7B6C91BDBC9C60083A684 /* ImageExtensionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImageExtensionTests.swift; sourceTree = "<group>"; };
 		D1B1B98F1BC7EB7100DE20D8 /* ThreadHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ThreadHelper.swift; sourceTree = "<group>"; };
 		D1ED2D0B1AD2CFA600CFC3EB /* Kingfisher-Demo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Kingfisher-Demo.app"; sourceTree = BUILT_PRODUCTS_DIR; };
 		D1ED2D0F1AD2CFA600CFC3EB /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@@ -249,6 +253,7 @@
 				4BBA04BD1AD77F7E00A5CF82 /* KingfisherTests-Bridging-Header.h */,
 				4BBA04C31AD7986100A5CF82 /* KingfisherTestHelper.swift */,
 				4B5083371BD88C3E00AEA807 /* KingfisherManagerTests.swift */,
+				D1A7B6C91BDBC9C60083A684 /* ImageExtensionTests.swift */,
 			);
 			path = KingfisherTests;
 			sourceTree = "<group>";
@@ -256,6 +261,7 @@
 		D1ED2D461AD2D09F00CFC3EB /* Supporting Files */ = {
 			isa = PBXGroup;
 			children = (
+				D1A7B6C71BDBC9310083A684 /* dancing-banana.gif */,
 				D1ED2D471AD2D09F00CFC3EB /* Info.plist */,
 			);
 			name = "Supporting Files";
@@ -409,6 +415,7 @@
 			isa = PBXResourcesBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
+				D1A7B6C81BDBC9310083A684 /* dancing-banana.gif in Resources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -499,6 +506,7 @@
 				4B6D4F651AE0A46D0084D15B /* UIImageViewExtensionTests.swift in Sources */,
 				4B5083381BD88C3E00AEA807 /* KingfisherManagerTests.swift in Sources */,
 				4BBA04C41AD7986100A5CF82 /* KingfisherTestHelper.swift in Sources */,
+				D1A7B6CA1BDBC9C60083A684 /* ImageExtensionTests.swift in Sources */,
 				4B6D4F671AE0B82A0084D15B /* UIButtonExtensionTests.swift in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;

+ 1 - 1
Kingfisher/Info.plist

@@ -19,7 +19,7 @@
 	<key>CFBundleSignature</key>
 	<string>????</string>
 	<key>CFBundleVersion</key>
-	<string>290</string>
+	<string>292</string>
 	<key>NSPrincipalClass</key>
 	<string></string>
 </dict>

+ 4 - 4
Kingfisher/UIImage+Extension.swift

@@ -107,7 +107,7 @@ extension UIImage {
         switch data.kf_imageFormat {
         case .JPEG: image = UIImage(data: data, scale: scale)
         case .PNG: image = UIImage(data: data, scale: scale)
-        case .GIF: image = UIImage.animatedImageWithGIFData(gifData: data, scale: scale, duration: 0.0)
+        case .GIF: image = UIImage.kf_animatedImageWithGIFData(gifData: data, scale: scale, duration: 0.0)
         case .Unknown: image = nil
         }
         return image
@@ -145,11 +145,11 @@ func UIImageGIFRepresentation(image: UIImage, duration: NSTimeInterval, repeatCo
 }
 
 extension UIImage {
-    static func animatedImageWithGIFData(gifData data: NSData) -> UIImage? {
-        return animatedImageWithGIFData(gifData: data, scale: UIScreen.mainScreen().scale, duration: 0.0)
+    static func kf_animatedImageWithGIFData(gifData data: NSData) -> UIImage? {
+        return kf_animatedImageWithGIFData(gifData: data, scale: UIScreen.mainScreen().scale, duration: 0.0)
     }
     
-    static func animatedImageWithGIFData(gifData data: NSData, scale: CGFloat, duration: NSTimeInterval) -> UIImage? {
+    static func kf_animatedImageWithGIFData(gifData data: NSData, scale: CGFloat, duration: NSTimeInterval) -> UIImage? {
         
         let options: NSDictionary = [kCGImageSourceShouldCache as String: NSNumber(bool: true), kCGImageSourceTypeIdentifierHint as String: kUTTypeGIF]
         guard let imageSource = CGImageSourceCreateWithData(data, options) else {

+ 0 - 13
KingfisherTests/ImageCacheTests.swift

@@ -202,19 +202,6 @@ class ImageCacheTests: XCTestCase {
         
         waitForExpectationsWithTimeout(5, handler: nil)
     }
-    
-    func testImageFormat() {
-        var format: ImageFormat
-        format = testImageJEPGData.kf_imageFormat
-        XCTAssertEqual(format, ImageFormat.JPEG)
-        
-        format = testImagePNGData.kf_imageFormat
-        XCTAssertEqual(format, ImageFormat.PNG)
-        
-        let raw = [1,2,3,4,5,6,7,8]
-        format = NSData(bytes: raw, length: 8) .kf_imageFormat
-        XCTAssertEqual(format, ImageFormat.Unknown)
-    }
 
     // MARK: - Helper
     func storeMultipleImages(completionHandler:()->()) {

+ 59 - 0
KingfisherTests/ImageExtensionTests.swift

@@ -0,0 +1,59 @@
+//
+//  ImageExtensionTests.swift
+//  Kingfisher
+//
+//  Created by Wei Wang on 15/10/24.
+//  Copyright © 2015年 Wei Wang. All rights reserved.
+//
+
+import XCTest
+@testable import Kingfisher
+
+class ImageExtensionTests: XCTestCase {
+    
+    override func setUp() {
+        super.setUp()
+        // Put setup code here. This method is called before the invocation of each test method in the class.
+    }
+    
+    override func tearDown() {
+        // Put teardown code here. This method is called after the invocation of each test method in the class.
+        super.tearDown()
+    }
+    
+    func testImageFormat() {
+        var format: ImageFormat
+        format = testImageJEPGData.kf_imageFormat
+        XCTAssertEqual(format, ImageFormat.JPEG)
+        
+        format = testImagePNGData.kf_imageFormat
+        XCTAssertEqual(format, ImageFormat.PNG)
+        
+        format = testImageGIFData.kf_imageFormat
+        XCTAssertEqual(format, ImageFormat.GIF)
+        
+        let raw = [1,2,3,4,5,6,7,8]
+        format = NSData(bytes: raw, length: 8) .kf_imageFormat
+        XCTAssertEqual(format, ImageFormat.Unknown)
+    }
+    
+    func testGenerateGIFImage() {
+        let image = UIImage.kf_animatedImageWithGIFData(gifData: testImageGIFData)
+        XCTAssertNotNil(image, "The image should be initiated.")
+        XCTAssertEqual(image!.images!.count, 8, "There should be 8 frames.")
+        
+        XCTAssertEqualWithAccuracy(image!.duration, 0.8, accuracy: 0.001, "The image duration should be 0.8s")
+    }
+    
+    func testGIFRepresentation() {
+        let image = UIImage.kf_animatedImageWithGIFData(gifData: testImageGIFData)!
+        let data = UIImageGIFRepresentation(image)
+        
+        XCTAssertNotNil(data, "Data should not be nil")
+        XCTAssertEqual(data?.kf_imageFormat, ImageFormat.GIF)
+        
+        let image1 = UIImage.kf_animatedImageWithGIFData(gifData: data!)!
+        XCTAssertEqual(image1.duration, image.duration)
+        XCTAssertEqual(image1.images!.count, image.images!.count)
+    }
+}

+ 2 - 0
KingfisherTests/KingfisherTestHelper.swift

@@ -35,6 +35,8 @@ let testImageData = NSData(base64EncodedString:testImageString, options: NSDataB
 let testImagePNGData = UIImagePNGRepresentation(testImage)!
 let testImageJEPGData = UIImageJPEGRepresentation(testImage, 1.0)!
 
+var testImageGIFData = NSData(contentsOfFile: NSBundle(forClass: KingfisherManagerTests.self).pathForResource("dancing-banana", ofType: "gif")!)!
+
 let testKeys = ["http://stackoverflow.com/questions/11251340/convert-image-to-base64-string-in-ios-swift","https://onevcat.com","http://onevcat.com/content/images/2014/May/200.jpg","http://onevcat.com/content/images/2014/May/200.jpg?fads#kj1asf"]
 
 func == (left: UIImage, right: UIImage) -> Bool {