-
Notifications
You must be signed in to change notification settings - Fork 2
/
StructTests.swift
48 lines (44 loc) · 2.02 KB
/
StructTests.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
import XCTest
import WinRTComponent
class StructTests: WinRTTestCase {
func testAsReturnValue() throws {
let result = try Structs.make(1, "a", 11, LeafStruct(int32: 2, string: "b", reference: 22))
XCTAssertEqual(result.int32, 1)
XCTAssertEqual(result.string, "a")
XCTAssertEqual(result.reference, 11)
XCTAssertEqual(result.nested.int32, 2)
XCTAssertEqual(result.nested.string, "b")
XCTAssertEqual(result.nested.reference, 22)
}
func testAsArgument() throws {
let value = Struct(int32: 1, string: "a", reference: 11, nested: LeafStruct(int32: 2, string: "b", reference: 22))
XCTAssertEqual(try Structs.getInt32(value), 1)
XCTAssertEqual(try Structs.getString(value), "a")
XCTAssertEqual(try Structs.getReference(value), 11)
let nested = try Structs.getNested(value)
XCTAssertEqual(nested.int32, 2)
XCTAssertEqual(nested.string, "b")
XCTAssertEqual(nested.reference, 22)
}
func testAsOutParam() throws {
var result: Struct = .init()
try Structs.output(1, "a", 11, LeafStruct(int32: 2, string: "b", reference: 22), &result)
XCTAssertEqual(result.int32, 1)
XCTAssertEqual(result.string, "a")
XCTAssertEqual(result.reference, 11)
XCTAssertEqual(result.nested.int32, 2)
XCTAssertEqual(result.nested.string, "b")
XCTAssertEqual(result.nested.reference, 22)
}
func testAsConstByRefArgument() throws {
// Currently "ref const" maps to in params
let value = Struct(int32: 1, string: "a", reference: 11, nested: LeafStruct(int32: 2, string: "b", reference: 22))
let roundtripped = try Structs.returnRefConstArgument(value)
XCTAssertEqual(roundtripped.int32, 1)
XCTAssertEqual(roundtripped.string, "a")
XCTAssertEqual(roundtripped.reference, 11)
XCTAssertEqual(roundtripped.nested.int32, 2)
XCTAssertEqual(roundtripped.nested.string, "b")
XCTAssertEqual(roundtripped.nested.reference, 22)
}
}