forked from microsoft/cppwinrt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathabi_args.cpp
More file actions
111 lines (98 loc) · 2.97 KB
/
abi_args.cpp
File metadata and controls
111 lines (98 loc) · 2.97 KB
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
#include "pch.h"
using namespace winrt;
using namespace Windows::Foundation;
using namespace Windows::Foundation::Numerics;
TEST_CASE("abi_args")
{
//
// "%.size(), get_abi(%)"
//
// generic, in, array, object
{
auto a = single_threaded_vector<IInspectable>();
a.ReplaceAll({ box_value(1), box_value(2) });
REQUIRE(a.Size() == 2);
REQUIRE(unbox_value<int32_t>(a.GetAt(0)) == 1);
REQUIRE(unbox_value<int32_t>(a.GetAt(1)) == 2);
}
// generic, in, array, string
{
auto a = single_threaded_vector<hstring>();
a.ReplaceAll({ L"1", L"2" });
REQUIRE(a.Size() == 2);
REQUIRE(a.GetAt(0) == L"1");
REQUIRE(a.GetAt(1) == L"2");
}
// generic, in, array, enum
{
auto a = single_threaded_vector<PropertyType>();
a.ReplaceAll({ PropertyType::Int16, PropertyType::Int32 });
REQUIRE(a.Size() == 2);
REQUIRE(a.GetAt(0) == PropertyType::Int16);
REQUIRE(a.GetAt(1) == PropertyType::Int32);
}
// generic, in, array, struct
{
auto a = single_threaded_vector<Rational>();
a.ReplaceAll({ {1,1}, {2,2} });
REQUIRE(a.Size() == 2);
REQUIRE(a.GetAt(0) == Rational{1, 1});
REQUIRE(a.GetAt(1) == Rational{2, 2});
}
// generic, in, array, fundamental
{
auto a = single_threaded_vector<int32_t>();
a.ReplaceAll({ 1, 2 });
REQUIRE(a.Size() == 2);
REQUIRE(a.GetAt(0) == 1);
REQUIRE(a.GetAt(1) == 2);
}
//
// "%.size(), put_abi(%)"
//
// generic, out, array, object
{
auto a = single_threaded_vector<IInspectable>();
a.ReplaceAll({ box_value(1), box_value(2) });
std::array<IInspectable, 2> b;
a.GetMany(0, b);
REQUIRE(unbox_value<int32_t>(b[0]) == 1);
REQUIRE(unbox_value<int32_t>(b[1]) == 2);
}
// generic, out, array, string
{
auto a = single_threaded_vector<hstring>();
a.ReplaceAll({ L"1", L"2" });
std::array<hstring, 2> b;
a.GetMany(0, b);
REQUIRE(b[0] == L"1");
REQUIRE(b[1] == L"2");
}
// generic, out, array, enum
{
auto a = single_threaded_vector<PropertyType>();
a.ReplaceAll({ PropertyType::Int16, PropertyType::Int32 });
std::array<PropertyType, 2> b;
a.GetMany(0, b);
REQUIRE(b[0] == PropertyType::Int16);
REQUIRE(b[1] == PropertyType::Int32);
}
// generic, out, array, struct
{
auto a = single_threaded_vector<Rational>();
a.ReplaceAll({ {1,1}, {2,2} });
std::array<Rational, 2> b;
a.GetMany(0, b);
REQUIRE(b[0] == Rational{ 1, 1 });
REQUIRE(b[1] == Rational{ 2, 2 });
}
// generic, out, array, fundamental
{
auto a = single_threaded_vector<int32_t>();
a.ReplaceAll({ 1, 2 });
std::array<int32_t, 2> b;
a.GetMany(0, b);
REQUIRE(b[0] == 1);
REQUIRE(b[1] == 2);
}
}