-
Notifications
You must be signed in to change notification settings - Fork 27
/
UIPasteboardExtensionsTests.swift
47 lines (38 loc) · 1.67 KB
/
UIPasteboardExtensionsTests.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
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import Foundation
import MobileCoreServices
import UIKit
import XCTest
class UIPasteboardExtensionsTests: XCTestCase {
private var pasteboard: UIPasteboard!
override func setUp() {
super.setUp()
pasteboard = UIPasteboard.pasteboardWithUniqueName()
}
override func tearDown() {
super.tearDown()
UIPasteboard.removePasteboardWithName(pasteboard.name)
}
func testAddPNGImage() {
let path = NSBundle(forClass: self.classForCoder).pathForResource("image", ofType: "png")!
let data = NSData(contentsOfFile: path)!
let url = URL(string: "http://foo.bar")!
pasteboard.addImageWithData(data, forURL: url)
verifyPasteboard(expectedURL: url, expectedImageTypeKey: kUTTypePNG)
}
func testAddGIFImage() {
let path = NSBundle(forClass: self.classForCoder).pathForResource("image", ofType: "gif")!
let data = NSData(contentsOfFile: path)!
let url = URL(string: "http://foo.bar")!
pasteboard.addImageWithData(data, forURL: url)
verifyPasteboard(expectedURL: url, expectedImageTypeKey: kUTTypeGIF)
}
private func verifyPasteboard(expectedURL expectedURL: URL, expectedImageTypeKey: CFString) {
XCTAssertEqual(pasteboard.items.count, 1)
XCTAssertEqual(pasteboard.items[0].count, 2)
XCTAssertEqual(pasteboard.items[0][kUTTypeURL as String], expectedURL)
XCTAssertNotNil(pasteboard.items[0][expectedImageTypeKey as String])
}
}