| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- //
- // 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 = Image.kf_animatedImageWithGIFData(gifData: testImageGIFData)
- XCTAssertNotNil(image, "The image should be initiated.")
- XCTAssertEqual(image!.kf_images!.count, 8, "There should be 8 frames.")
-
- XCTAssertEqualWithAccuracy(image!.kf_duration, 0.8, accuracy: 0.001, "The image duration should be 0.8s")
- }
-
- func testGIFRepresentation() {
- let image = Image.kf_animatedImageWithGIFData(gifData: testImageGIFData)!
- let data = ImageGIFRepresentation(image)
-
- XCTAssertNotNil(data, "Data should not be nil")
- XCTAssertEqual(data?.kf_imageFormat, ImageFormat.GIF)
-
- let image1 = Image.kf_animatedImageWithGIFData(gifData: data!)!
- XCTAssertEqual(image1.kf_duration, image.kf_duration)
- XCTAssertEqual(image1.kf_images!.count, image.kf_images!.count)
- }
- }
|