Revision control

1
/* This Source Code Form is subject to the terms of the Mozilla Public
2
* License, v. 2.0. If a copy of the MPL was not distributed with this
3
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5
import MobileCoreServices
6
import UIKit
7
import XCTest
8
9
class UIPasteboardExtensionsTests: XCTestCase {
10
11
fileprivate var pasteboard: UIPasteboard!
12
13
override func setUp() {
14
super.setUp()
15
pasteboard = UIPasteboard.withUniqueName()
16
}
17
18
override func tearDown() {
19
super.tearDown()
20
UIPasteboard.remove(withName: pasteboard.name)
21
}
22
23
func testAddPNGImage() {
24
let path = Bundle(for: self.classForCoder).path(forResource: "image", ofType: "png")!
25
let data = try! Data(contentsOf: URL(fileURLWithPath: path))
26
let url = URL(string: "http://foo.bar")!
27
pasteboard.addImageWithData(data, forURL: url)
28
verifyPasteboard(expectedURL: url, expectedImageTypeKey: kUTTypePNG)
29
}
30
31
func testAddGIFImage() {
32
let path = Bundle(for: self.classForCoder).path(forResource: "image", ofType: "gif")!
33
let data = try! Data(contentsOf: URL(fileURLWithPath: path))
34
let url = URL(string: "http://foo.bar")!
35
pasteboard.addImageWithData(data, forURL: url)
36
verifyPasteboard(expectedURL: url, expectedImageTypeKey: kUTTypeGIF)
37
}
38
39
fileprivate func verifyPasteboard(expectedURL: URL, expectedImageTypeKey: CFString) {
40
XCTAssertEqual(pasteboard.items.count, 1)
41
XCTAssertEqual(pasteboard.items[0].count, 2)
42
XCTAssertEqual(pasteboard.items[0][kUTTypeURL as String] as? URL, expectedURL)
43
XCTAssertNotNil(pasteboard.items[0][expectedImageTypeKey as String])
44
}
45
46
}