This repository has been archived by the owner on May 24, 2023. It is now read-only.
/
WebPDecodeTests.swift
87 lines (71 loc) · 2.81 KB
/
WebPDecodeTests.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//
// WebPDecodeTests.swift
// Nuke-WebP-PluginTests iOS
//
// Created by nagisa-kosuge on 2018/01/25.
// Copyright © 2018年 RyoKosuge. All rights reserved.
//
import XCTest
import Nuke
@testable import NukeWebPPlugin
class WebPDecodeTests: XCTestCase {
private lazy var webpImagePath: URL = {
let webpImagePath = Bundle(for: type(of: self)).url(forResource: "sample", withExtension: "webp")!
return webpImagePath
}()
private lazy var gifImagePath: URL = {
let gifImagePath = Bundle(for: type(of: self)).url(forResource: "sample", withExtension: "gif")!
return gifImagePath
}()
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 testsDecodeWebPImage() {
let webpData = try! Data(contentsOf: self.webpImagePath)
let image: UIImage? = UIImage(data: webpData)
XCTAssertNil(image)
let decoder = NukeWebPPlugin.WebPDataDecoder();
let webpImage: UIImage? = decoder.decode(webpData)
XCTAssertNotNil(webpImage)
}
func testsDecodeNotWebPImage() {
let gifData = try! Data(contentsOf: self.gifImagePath)
let image: UIImage? = UIImage(data: gifData)
XCTAssertNotNil(image)
let decoder = NukeWebPPlugin.WebPDataDecoder();
let webpImage: UIImage? = decoder.decode(gifData)
XCTAssertNil(webpImage)
}
func testsProgressiveDecodeWebPImage() {
let webpData = try! Data(contentsOf: self.webpImagePath)
let decoder = NukeWebPPlugin.WebPDataDecoder();
// no image
XCTAssertNil(decoder.incrementallyDecode(webpData[0...500]))
// created image
let scan1 = decoder.incrementallyDecode(webpData[0...3702])
XCTAssertNotNil(scan1)
XCTAssertEqual(scan1!.size.width, 320)
XCTAssertEqual(scan1!.size.height, 235)
let scan2 = decoder.incrementallyDecode(webpData)
XCTAssertNotNil(scan2)
XCTAssertEqual(scan2!.size.width, 320)
XCTAssertEqual(scan2!.size.height, 235)
}
func testPerformanceDecodeWebP() {
// This is an example of a performance test case.
self.measure {
// Put the code you want to measure the time of here.
let webpData = try! Data(contentsOf: self.webpImagePath)
let image: UIImage? = UIImage(data: webpData)
XCTAssertNil(image)
let decoder = NukeWebPPlugin.WebPDataDecoder();
let webpImage: UIImage? = decoder.decode(webpData)
XCTAssertNotNil(webpImage)
}
}
}