Repository navigation
Expand file tree
/
Copy pathreturn_params_abi.cpp
More file actions
183 lines (176 loc) · 6.06 KB
/
Copy pathreturn_params_abi.cpp
File metadata and controls
183 lines (176 loc) · 6.06 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
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#include "pch.h"
#include "winrt/test_component.h"
#include "test_component.h"
namespace winrt
{
using namespace Windows::Foundation;
using namespace test_component;
}
using namespace winrt;
namespace
{
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-function"
#endif
hstring to_hstring(::IInspectable* raw)
{
winrt::IInspectable object;
copy_from_abi(object, raw);
return object.as<IStringable>().ToString();
}
#ifdef __clang__
#pragma clang diagnostic pop
#endif
}
TEST_CASE("return_params_abi")
{
Class object;
auto abi = object.as<ABI::test_component::IClass>();
{
int value{ 0xCC };
REQUIRE(S_OK == abi->ReturnInt32(&value));
REQUIRE(value == 123);
}
{
auto raw{ reinterpret_cast<HSTRING>(0xCC) };
REQUIRE(S_OK == abi->ReturnString(&raw));
hstring value{ raw, take_ownership_from_abi };
REQUIRE(value == L"123");
}
{
auto raw{ reinterpret_cast<::IInspectable*>(0xCC) };
REQUIRE(S_OK == abi->ReturnObject(&raw));
winrt::IInspectable value{ raw, take_ownership_from_abi };
REQUIRE(value.as<IStringable>().ToString() == L"123");
}
{
auto raw{ reinterpret_cast<ABI::Windows::Foundation::IStringable*>(0xCC) };
REQUIRE(S_OK == abi->ReturnStringable(&raw));
IStringable value{ raw, take_ownership_from_abi };
REQUIRE(value.ToString() == L"123");
}
{
ABI::test_component::Struct raw;
memset(&raw, 0xCC, sizeof(raw));
REQUIRE(S_OK == abi->ReturnStruct(&raw));
REQUIRE(WindowsGetStringRawBuffer(raw.First, nullptr) == L"1"sv);
REQUIRE(WindowsGetStringRawBuffer(raw.Second, nullptr) == L"2"sv);
REQUIRE(S_OK == WindowsDeleteString(raw.First));
REQUIRE(S_OK == WindowsDeleteString(raw.Second));
}
{
uint32_t length{ 0xCC };
auto raw{ reinterpret_cast<int32_t*>(0xCC) };
REQUIRE(S_OK == abi->ReturnInt32Array(&length, &raw));
com_array<int32_t> value{ raw, length, take_ownership_from_abi };
REQUIRE(value.size() == 3);
REQUIRE(value[0] == 1);
REQUIRE(value[1] == 2);
REQUIRE(value[2] == 3);
}
{
uint32_t length{ 0xCC };
auto raw{ reinterpret_cast<HSTRING*>(0xCC) };
REQUIRE(S_OK == abi->ReturnStringArray(&length, &raw));
com_array<hstring> value{ raw, length, take_ownership_from_abi };
REQUIRE(value.size() == 3);
REQUIRE(value[0] == L"1");
REQUIRE(value[1] == L"2");
REQUIRE(value[2] == L"3");
}
{
uint32_t length{ 0xCC };
auto raw{ reinterpret_cast<::IInspectable * *>(0xCC) };
REQUIRE(S_OK == abi->ReturnObjectArray(&length, &raw));
com_array<winrt::IInspectable> value{ raw, length, take_ownership_from_abi };
REQUIRE(value.size() == 3);
REQUIRE(value[0].as<IStringable>().ToString() == L"1");
REQUIRE(value[1].as<IStringable>().ToString() == L"2");
REQUIRE(value[2].as<IStringable>().ToString() == L"3");
}
{
uint32_t length{ 0xCC };
auto raw{ reinterpret_cast<ABI::Windows::Foundation::IStringable * *>(0xCC) };
REQUIRE(S_OK == abi->ReturnStringableArray(&length, &raw));
com_array<IStringable> value{ raw, length, take_ownership_from_abi };
REQUIRE(value.size() == 3);
REQUIRE(value[0].ToString() == L"1");
REQUIRE(value[1].ToString() == L"2");
REQUIRE(value[2].ToString() == L"3");
}
{
uint32_t length{ 0xCC };
auto raw{ reinterpret_cast<ABI::test_component::Struct*>(0xCC) };
REQUIRE(S_OK == abi->ReturnStructArray(&length, &raw));
com_array<Struct> value{ raw, length, take_ownership_from_abi };
REQUIRE(value.size() == 2);
REQUIRE(value[0].First == L"1");
REQUIRE(value[0].Second == L"2");
REQUIRE(value[1].First == L"10");
REQUIRE(value[1].Second == L"20");
}
object.Fail(true);
{
int value{ 0xCC };
REQUIRE(E_INVALIDARG == abi->ReturnInt32(&value));
REQUIRE(value == 0xCC);
}
{
auto raw{ reinterpret_cast<HSTRING>(0xCC) };
REQUIRE(E_INVALIDARG == abi->ReturnString(&raw));
REQUIRE(raw == nullptr);
}
{
auto raw{ reinterpret_cast<::IInspectable*>(0xCC) };
REQUIRE(E_INVALIDARG == abi->ReturnObject(&raw));
REQUIRE(raw == nullptr);
}
{
auto raw{ reinterpret_cast<ABI::Windows::Foundation::IStringable*>(0xCC) };
REQUIRE(E_INVALIDARG == abi->ReturnStringable(&raw));
REQUIRE(raw == nullptr);
}
{
ABI::test_component::Struct raw;
memset(&raw, 0xCC, sizeof(raw));
REQUIRE(E_INVALIDARG == abi->ReturnStruct(&raw));
REQUIRE(raw.First == nullptr);
REQUIRE(raw.Second == nullptr);
}
{
uint32_t length{ 0xCC };
auto raw{ reinterpret_cast<int32_t*>(0xCC) };
REQUIRE(E_INVALIDARG == abi->ReturnInt32Array(&length, &raw));
REQUIRE(length == 0xCC);
REQUIRE(raw == nullptr);
}
{
uint32_t length{ 0xCC };
auto raw{ reinterpret_cast<HSTRING*>(0xCC) };
REQUIRE(E_INVALIDARG == abi->ReturnStringArray(&length, &raw));
REQUIRE(length == 0xCC);
REQUIRE(raw == nullptr);
}
{
uint32_t length{ 0xCC };
auto raw{ reinterpret_cast<::IInspectable * *>(0xCC) };
REQUIRE(E_INVALIDARG == abi->ReturnObjectArray(&length, &raw));
REQUIRE(length == 0xCC);
REQUIRE(raw == nullptr);
}
{
uint32_t length{ 0xCC };
auto raw{ reinterpret_cast<ABI::Windows::Foundation::IStringable * *>(0xCC) };
REQUIRE(E_INVALIDARG == abi->ReturnStringableArray(&length, &raw));
REQUIRE(length == 0xCC);
REQUIRE(raw == nullptr);
}
{
uint32_t length{ 0xCC };
auto raw{ reinterpret_cast<ABI::test_component::Struct*>(0xCC) };
REQUIRE(E_INVALIDARG == abi->ReturnStructArray(&length, &raw));
REQUIRE(length == 0xCC);
REQUIRE(raw == nullptr);
}
}