forked from swiftlang/swift-corelibs-foundation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestNotification.swift
49 lines (40 loc) · 1.9 KB
/
TestNotification.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
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
class TestNotification : XCTestCase {
static var allTests: [(String, (TestNotification) -> () throws -> Void)] {
return [
("test_customReflection", test_customReflection),
("test_NotificationNameInit", test_NotificationNameInit),
]
}
func test_customReflection() {
let someName = "somenotifname"
let targetObject = NSObject()
let userInfo = ["hello": "world", "indexThis": 350] as [AnyHashable: Any]
let notif = Notification(name: Notification.Name(rawValue: someName), object: targetObject, userInfo: userInfo)
let mirror = notif.customMirror
XCTAssertEqual(mirror.displayStyle, .class)
XCTAssertNil(mirror.superclassMirror)
var children = Array(mirror.children).makeIterator()
let firstChild = children.next()
let secondChild = children.next()
let thirdChild = children.next()
XCTAssertEqual(firstChild?.label, "name")
XCTAssertEqual(firstChild?.value as? String, someName)
XCTAssertEqual(secondChild?.label, "object")
XCTAssertEqual(secondChild?.value as? NSObject, targetObject)
XCTAssertEqual(thirdChild?.label, "userInfo")
XCTAssertEqual((thirdChild?.value as? [AnyHashable: Any])?["hello"] as? String, "world")
XCTAssertEqual((thirdChild?.value as? [AnyHashable: Any])?["indexThis"] as? Int, 350)
}
func test_NotificationNameInit() {
let name = "TestNotificationNameInit"
XCTAssertEqual(Notification.Name(name), Notification.Name(rawValue: name))
}
}