|
2 | 2 | //
|
3 | 3 | // This source file is part of the Swift.org open source project
|
4 | 4 | //
|
5 |
| -// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors |
| 5 | +// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors |
6 | 6 | // Licensed under Apache License v2.0 with Runtime Library Exception
|
7 | 7 | //
|
8 | 8 | // See http://swift.org/LICENSE.txt for license information
|
|
13 | 13 | import XCTest
|
14 | 14 | import PlaygroundSupport
|
15 | 15 |
|
16 |
| -class PlaygroundTests_OSX: XCTestCase { |
17 |
| - |
| 16 | +#if os(macOS) |
| 17 | +import AppKit |
| 18 | + |
| 19 | +fileprivate typealias ViewType = NSView |
| 20 | +fileprivate typealias ViewControllerType = NSViewController |
| 21 | +#elseif os(iOS) || os(tvOS) |
| 22 | +import UIKit |
| 23 | + |
| 24 | +fileprivate typealias ViewType = UIView |
| 25 | +fileprivate typealias ViewControllerType = UIViewController |
| 26 | +#endif |
| 27 | + |
| 28 | +class LiveViewTests: XCTestCase { |
| 29 | + |
18 | 30 | override func setUp() {
|
19 | 31 | super.setUp()
|
20 | 32 | // Put setup code here. This method is called before the invocation of each test method in the class.
|
21 | 33 | }
|
22 |
| - |
| 34 | + |
23 | 35 | override func tearDown() {
|
24 | 36 | PlaygroundPage.current.liveView = nil
|
25 | 37 | super.tearDown()
|
26 | 38 | }
|
27 |
| - |
| 39 | + |
28 | 40 | func testLiveViewWithView() {
|
29 |
| - let view = NSView() |
30 |
| - |
| 41 | + let view = ViewType() |
| 42 | + |
31 | 43 | // Test setting to a view
|
32 | 44 | expectation(forNotification: "PlaygroundPageLiveViewDidChangeNotification", object: PlaygroundPage.current) { (notification) in
|
33 |
| - guard let userInfoView = notification.userInfo?["PlaygroundPageLiveView"] as? NSView else { return false } |
| 45 | + guard let userInfoView = notification.userInfo?["PlaygroundPageLiveView"] as? ViewType else { return false } |
34 | 46 | guard notification.userInfo?["PlaygroundPageLiveViewController"] == nil else { return false }
|
35 | 47 | XCTAssertEqual(userInfoView, view)
|
36 | 48 | return true
|
37 | 49 | }
|
38 | 50 | PlaygroundPage.current.liveView = view
|
39 |
| - waitForExpectations(withTimeout: 0.1, handler: nil) |
40 |
| - |
| 51 | + waitForExpectations(timeout: 0.1, handler: nil) |
| 52 | + |
41 | 53 | // Test setting back to nil
|
42 | 54 | expectation(forNotification: "PlaygroundPageLiveViewDidChangeNotification", object: PlaygroundPage.current) { (notification) in
|
43 | 55 | guard notification.userInfo?["PlaygroundPageLiveView"] == nil else { return false }
|
44 | 56 | guard notification.userInfo?["PlaygroundPageLiveViewController"] == nil else { return false }
|
45 | 57 | return true
|
46 | 58 | }
|
47 | 59 | PlaygroundPage.current.liveView = nil
|
48 |
| - waitForExpectations(withTimeout: 0.1, handler: nil) |
| 60 | + waitForExpectations(timeout: 0.1, handler: nil) |
49 | 61 | }
|
50 |
| - |
| 62 | + |
51 | 63 | func testLiveViewWithViewController() {
|
52 |
| - let viewController = NSViewController() |
53 |
| - |
| 64 | + let viewController = ViewControllerType() |
| 65 | + |
54 | 66 | // Test setting to a view controller
|
55 | 67 | expectation(forNotification: "PlaygroundPageLiveViewDidChangeNotification", object: PlaygroundPage.current) { (notification) in
|
56 |
| - guard let userInfoViewController = notification.userInfo?["PlaygroundPageLiveViewController"] as? NSViewController else { return false } |
| 68 | + guard let userInfoViewController = notification.userInfo?["PlaygroundPageLiveViewController"] as? ViewControllerType else { return false } |
57 | 69 | guard notification.userInfo?["PlaygroundPageLiveView"] == nil else { return false }
|
58 | 70 | XCTAssertEqual(userInfoViewController, viewController)
|
59 | 71 | return true
|
60 | 72 | }
|
61 | 73 | PlaygroundPage.current.liveView = viewController
|
62 |
| - waitForExpectations(withTimeout: 0.1, handler: nil) |
63 |
| - |
| 74 | + waitForExpectations(timeout: 0.1, handler: nil) |
| 75 | + |
64 | 76 | // Test setting back to nil
|
65 | 77 | expectation(forNotification: "PlaygroundPageLiveViewDidChangeNotification", object: PlaygroundPage.current) { (notification) in
|
66 | 78 | guard notification.userInfo?["PlaygroundPageLiveView"] == nil else { return false }
|
67 | 79 | guard notification.userInfo?["PlaygroundPageLiveViewController"] == nil else { return false }
|
68 | 80 | return true
|
69 | 81 | }
|
70 | 82 | PlaygroundPage.current.liveView = nil
|
71 |
| - waitForExpectations(withTimeout: 0.1, handler: nil) |
| 83 | + waitForExpectations(timeout: 0.1, handler: nil) |
72 | 84 | }
|
73 |
| - |
| 85 | + |
74 | 86 | }
|
0 commit comments