-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathAggregationTests.swift
161 lines (130 loc) · 6.47 KB
/
AggregationTests.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import WinSDK
import XCTest
@_spi(WinRTInternal) import test_component
import Ctest_component
import Foundation
class AggregationTests : XCTestCase {
public func testAppOverridesFromBase() throws {
let derived = Derived()
try derived.doTheThing()
let appDerived = AppDerived()
print(type(of: appDerived))
let b: Base = appDerived as Base
print(type(of: b))
try appDerived.doTheThing()
XCTAssertEqual(appDerived.count, 1, "count not expected")
}
public func testAppOverridesFromDerived() throws {
let appDerived2 = AppDerived2()
try appDerived2.doTheThing()
XCTAssertEqual(appDerived2.count, 1, "count not expected")
}
public func testOverrideMultipleInterface() throws {
let appDerived3 = AppDerived3()
try appDerived3.doTheThing()
XCTAssertEqual(appDerived3.count, 1, "count not expected")
XCTAssertEqual(appDerived3.beforeCount, 1, "before count not expected")
}
public func testComposedTypesAsInput() throws {
let appDerived = AppDerived()
try StaticClass.takeBase(appDerived)
XCTAssertEqual(appDerived.count, 1, "derive from base count not expected")
let appDerived2 = AppDerived2()
try StaticClass.takeBase(appDerived2)
XCTAssertEqual(appDerived2.count, 1, "derived from derived count not expected")
let appDerived3 = AppDerived3()
try StaticClass.takeBase(appDerived3)
XCTAssertEqual(appDerived3.count, 1, "derived from multiple interfaces count not expected")
XCTAssertEqual(appDerived3.beforeCount, 1, "before count not expected")
}
public func testUnwrappingWinRTImplementedComposedType() throws {
let classy = Class()
let base_returned = classy.baseProperty!
XCTAssert(type(of: base_returned) == Derived.self)
}
public func testUnwrappingAppImplementedComposedTypeBase() throws {
let classy = Class()
let appDerived = AppDerived()
classy.baseProperty = appDerived
let base_returned = try XCTUnwrap(classy.baseProperty)
XCTAssert(type(of: base_returned) == AppDerived.self, "type doesn't match!")
XCTAssertIdentical(base_returned, appDerived)
}
public func testUnwrappingAppImplementedComposedTypeDerive() throws {
let classy = Class()
let appDerived2 = AppDerived2()
classy.baseProperty = appDerived2
let base_returned = try XCTUnwrap(classy.baseProperty)
XCTAssert(type(of: base_returned) == AppDerived2.self)
XCTAssertIdentical(base_returned, appDerived2)
}
public func testUnwrappingAppImplementedComposedTypeDerive3() throws {
let classy = Class()
let appDerived3 = AppDerived3()
classy.baseProperty = appDerived3
let base_returned = try XCTUnwrap(classy.baseProperty)
XCTAssert(type(of: base_returned) == AppDerived3.self)
XCTAssertIdentical(base_returned, appDerived3)
}
// Verifies that a composable type with no override interfaces still works
// as expected
public func testUnwrappingAppImplementedComposedFromBaseNoOverrides() throws {
let classy = Class()
let derivedNoOverrides = AppDerivedNoOverrides()
classy.baseNoOverridesProperty = derivedNoOverrides
let baseNoOverrides_returned = try XCTUnwrap(classy.baseNoOverridesProperty)
XCTAssert(type(of: baseNoOverrides_returned) == AppDerivedNoOverrides.self)
XCTAssertIdentical(baseNoOverrides_returned, derivedNoOverrides)
}
public func testUnwrappingAppImplementedComposedFromDerivedNoOverrides() throws {
let classy = Class()
let derivedNoOverrides2 = AppDerivedNoOverrides2()
classy.baseNoOverridesProperty = derivedNoOverrides2
let baseNoOverrides_returned = try XCTUnwrap(classy.baseNoOverridesProperty)
XCTAssert(type(of: baseNoOverrides_returned) == AppDerivedNoOverrides2.self)
XCTAssertIdentical(baseNoOverrides_returned, derivedNoOverrides2)
}
public func testCustomConstructorOnUnsealedType() throws {
let derived = UnsealedDerived(32)
XCTAssertEqual(derived.prop, 32)
}
public func runtimeClassName(_ base: Base) -> String {
return String(hString: base.GetRuntimeClassName())
}
public func testGetRuntimeClassNameReturnsBase() throws {
// WinUI calls GetRuntimeClassName when types are being constructed,
// so we need to return something that the runtime understands. Without an
// IXamlMetadataProvider implementation, returning custom type names will
// break the app.
let appDerived = AppDerived()
// In order to validate the test, we have to call GetRuntimeClassName on the base
// type. This will make the type check we had think we're being aggregated, where
// calling it directly on the AppDerived type won't
XCTAssertEqual(runtimeClassName(appDerived), "test_component.Base")
}
public func testAggregatedObjectUnwrappedAsAny() throws {
let derived = AppDerived()
try Class.takeBaseAndGiveToCallbackAsObject(derived) { sender in
let base = sender as? AppDerived
XCTAssertNotNil(derived)
XCTAssertIdentical(base, derived)
}
}
}
var aggregationTests: [XCTestCaseEntry] = [
testCase([
("testAppOverridesFromBase", AggregationTests.testAppOverridesFromBase),
("testAppOverridesFromDerived", AggregationTests.testAppOverridesFromDerived),
("testOverrideMultipleInterface", AggregationTests.testOverrideMultipleInterface),
("testComposedTypesAsInput", AggregationTests.testComposedTypesAsInput),
("testUnwrappingWinRTImplementedComposedType", AggregationTests.testUnwrappingWinRTImplementedComposedType),
("testUnwrappingAppImplementedComposedTypeBase", AggregationTests.testUnwrappingAppImplementedComposedTypeBase),
("testUnwrappingAppImplementedComposedTypeDerive", AggregationTests.testUnwrappingAppImplementedComposedTypeDerive),
("testUnwrappingAppImplementedComposedTypeDerive3", AggregationTests.testUnwrappingAppImplementedComposedTypeDerive3),
("testUnwrappingAppImplementedComposedFromBaseNoOverrides", AggregationTests.testUnwrappingAppImplementedComposedFromBaseNoOverrides),
("testUnwrappingAppImplementedComposedFromDerivedNoOverrides", AggregationTests.testUnwrappingAppImplementedComposedFromDerivedNoOverrides),
("testCustomConstructorOnUnsealedType", AggregationTests.testCustomConstructorOnUnsealedType),
("testGetRuntimeClassNameReturnsBase", AggregationTests.testGetRuntimeClassNameReturnsBase),
("testAggregatedObjectUnwrappedAsAny", AggregationTests.testAggregatedObjectUnwrappedAsAny),
])
]