-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathInterfaceImplementationTests.swift
59 lines (51 loc) · 2.13 KB
/
InterfaceImplementationTests.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
import XCTest
import WindowsRuntime
import WinRTComponent
class InterfaceImplementationTests: WinRTTestCase {
func testWithSwiftObject() throws {
class Exported: WinRTExportBase<IInspectableBinding>, WinRTComponent_IMinimalInterfaceProtocol {
override class var queriableInterfaces: [any COMTwoWayBinding.Type] { [
WinRTComponent_IMinimalInterfaceBinding.self
] }
var callCount: Int = 0
func method() throws { callCount += 1 }
}
do {
let exported = Exported()
let minimalInterface = try exported.queryInterface(WinRTComponent_IMinimalInterfaceBinding.self)
XCTAssertEqual(exported.callCount, 0)
try minimalInterface.method()
XCTAssertEqual(exported.callCount, 1)
}
do {
let exported = Exported()
let minimalInterface = try WinRTComponent_InterfaceCasting.asMinimalInterface(exported)
XCTAssertEqual(exported.callCount, 0)
try minimalInterface.method()
XCTAssertEqual(exported.callCount, 1)
}
}
func testWithDerivedClass() throws {
class Derived: WinRTComponent_MinimalBaseClass, WinRTComponent_IMinimalInterfaceProtocol, @unchecked Sendable {
override class var queriableInterfaces: [any COMTwoWayBinding.Type] { [
WinRTComponent_IMinimalInterfaceBinding.self
] }
var callCount: Int = 0
func method() throws { callCount += 1 }
}
do {
let derived = try Derived()
let minimalInterface = try derived.queryInterface(WinRTComponent_IMinimalInterfaceBinding.self)
XCTAssertEqual(derived.callCount, 0)
try minimalInterface.method()
XCTAssertEqual(derived.callCount, 1)
}
do {
let derived = try Derived()
let minimalInterface = try WinRTComponent_InterfaceCasting.asMinimalInterface(derived)
XCTAssertEqual(derived.callCount, 0)
try minimalInterface.method()
XCTAssertEqual(derived.callCount, 1)
}
}
}