forked from WeTransfer/WeScan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUIImageTests.swift
95 lines (70 loc) · 3.74 KB
/
UIImageTests.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
88
89
90
91
92
93
94
95
//
// UIImageTests.swift
// WeScanTests
//
// Created by James Campbell on 8/8/18.
// Copyright © 2018 WeTransfer. All rights reserved.
//
import XCTest
import FBSnapshotTestCase
@testable import WeScan
final class UIImageTests: FBSnapshotTestCase {
override func setUp() {
super.setUp()
recordMode = false
}
func testRotateUpFacingImageCorrectly() {
let image = UIImage(named: ResourceImage.rect2.rawValue, in: Bundle(for: ImageFeatureTestHelpers.self), compatibleWith: nil)
let orientatedImage = UIImage(cgImage: image!.cgImage!, scale: 1.0, orientation: .up)
let view = UIImageView(image: orientatedImage.applyingPortraitOrientation())
view.sizeToFit()
FBSnapshotVerifyView(view)
}
func testRotateDownFacingImageCorrectly() {
let image = UIImage(named: ResourceImage.rect2.rawValue, in: Bundle(for: ImageFeatureTestHelpers.self), compatibleWith: nil)
let orientatedImage = UIImage(cgImage: image!.cgImage!, scale: 1.0, orientation: .down)
let view = UIImageView(image: orientatedImage.applyingPortraitOrientation())
view.sizeToFit()
FBSnapshotVerifyView(view)
}
func testRotateLeftFacingImageCorrectly() {
let image = UIImage(named: ResourceImage.rect2.rawValue, in: Bundle(for: ImageFeatureTestHelpers.self), compatibleWith: nil)
let orientatedImage = UIImage(cgImage: image!.cgImage!, scale: 1.0, orientation: .left)
let view = UIImageView(image: orientatedImage.applyingPortraitOrientation())
view.sizeToFit()
FBSnapshotVerifyView(view)
}
func testRotateRightFacingImageCorrectly() {
let image = UIImage(named: ResourceImage.rect2.rawValue, in: Bundle(for: ImageFeatureTestHelpers.self), compatibleWith: nil)
let orientatedImage = UIImage(cgImage: image!.cgImage!, scale: 1.0, orientation: .right)
let view = UIImageView(image: orientatedImage.applyingPortraitOrientation())
view.sizeToFit()
FBSnapshotVerifyView(view)
}
func testRotateDefaultFacingImageCorrectly() {
let image = UIImage(named: ResourceImage.rect2.rawValue, in: Bundle(for: ImageFeatureTestHelpers.self), compatibleWith: nil)
let orientatedImage = UIImage(cgImage: image!.cgImage!, scale: 1.0, orientation: .rightMirrored)
let view = UIImageView(image: orientatedImage.applyingPortraitOrientation())
view.sizeToFit()
FBSnapshotVerifyView(view)
}
func testRotateImageCorrectly() {
let image = UIImage(named: ResourceImage.rect2.rawValue, in: Bundle(for: ImageFeatureTestHelpers.self), compatibleWith: nil)
let view = UIImageView(image: image!.rotated(by: Measurement(value: Double.pi * 0.2, unit: .radians), options: []))
view.sizeToFit()
FBSnapshotVerifyView(view)
}
func testScaledImageSuccessfully() {
let image = UIImage(named: ResourceImage.rect2.rawValue, in: Bundle(for: ImageFeatureTestHelpers.self), compatibleWith: nil)!
XCTAssertNotNil(image.scaledImage(scaleFactor: 0.2))
}
func testScaledImageCorrectly() {
let image = UIImage(named: ResourceImage.rect2.rawValue, in: Bundle(for: ImageFeatureTestHelpers.self), compatibleWith: nil)!
XCTAssertEqual(image.size, CGSize(width: 500, height: 500))
XCTAssertEqual(image.scaledImage(scaleFactor: 0.2)!.size, CGSize(width: 100, height: 100))
}
func testPDFDataCreationSuccessful() {
let image = UIImage(named: ResourceImage.rect2.rawValue, in: Bundle(for: ImageFeatureTestHelpers.self), compatibleWith: nil)!
XCTAssertNotNil(image.pdfData())
}
}