ImageExtensionTests.swift 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //
  2. // ImageExtensionTests.swift
  3. // Kingfisher
  4. //
  5. // Created by Wei Wang on 15/10/24.
  6. // Copyright © 2015年 Wei Wang. All rights reserved.
  7. //
  8. import XCTest
  9. @testable import Kingfisher
  10. class ImageExtensionTests: XCTestCase {
  11. override func setUp() {
  12. super.setUp()
  13. // Put setup code here. This method is called before the invocation of each test method in the class.
  14. }
  15. override func tearDown() {
  16. // Put teardown code here. This method is called after the invocation of each test method in the class.
  17. super.tearDown()
  18. }
  19. func testImageFormat() {
  20. var format: ImageFormat
  21. format = testImageJEPGData.kf_imageFormat
  22. XCTAssertEqual(format, ImageFormat.JPEG)
  23. format = testImagePNGData.kf_imageFormat
  24. XCTAssertEqual(format, ImageFormat.PNG)
  25. format = testImageGIFData.kf_imageFormat
  26. XCTAssertEqual(format, ImageFormat.GIF)
  27. let raw = [1, 2, 3, 4, 5, 6, 7, 8]
  28. format = NSData(bytes: raw, length: 8) .kf_imageFormat
  29. XCTAssertEqual(format, ImageFormat.Unknown)
  30. }
  31. func testGenerateGIFImage() {
  32. let image = Image.kf_animatedImageWithGIFData(gifData: testImageGIFData)
  33. XCTAssertNotNil(image, "The image should be initiated.")
  34. XCTAssertEqual(image!.kf_images!.count, 8, "There should be 8 frames.")
  35. XCTAssertEqualWithAccuracy(image!.kf_duration, 0.8, accuracy: 0.001, "The image duration should be 0.8s")
  36. }
  37. func testGIFRepresentation() {
  38. let image = Image.kf_animatedImageWithGIFData(gifData: testImageGIFData)!
  39. let data = ImageGIFRepresentation(image)
  40. XCTAssertNotNil(data, "Data should not be nil")
  41. XCTAssertEqual(data?.kf_imageFormat, ImageFormat.GIF)
  42. let image1 = Image.kf_animatedImageWithGIFData(gifData: data!)!
  43. XCTAssertEqual(image1.kf_duration, image.kf_duration)
  44. XCTAssertEqual(image1.kf_images!.count, image.kf_images!.count)
  45. }
  46. }