forked from microsoft/cppwinrt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathin_params_abi.cpp
More file actions
132 lines (124 loc) · 4.75 KB
/
in_params_abi.cpp
File metadata and controls
132 lines (124 loc) · 4.75 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
#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
{
struct Value : implements<Value, IStringable>
{
Value(int32_t value) :
m_value(value)
{
}
hstring ToString()
{
return hstring{ std::to_wstring(m_value) };
}
private:
int32_t m_value{};
};
}
TEST_CASE("in_params_abi")
{
Class object;
auto abi = object.as<ABI::test_component::IClass>();
{
HSTRING result{};
REQUIRE(S_OK == abi->InInt32(123, &result));
REQUIRE(WindowsGetStringRawBuffer(result, nullptr) == L"123"sv);
REQUIRE(S_OK == WindowsDeleteString(result));
}
{
hstring input = L"123";
HSTRING raw = static_cast<HSTRING>(get_abi(input));
HSTRING result{};
REQUIRE(S_OK == abi->InString(raw, &result));
REQUIRE(WindowsGetStringRawBuffer(result, nullptr) == L"123"sv);
REQUIRE(S_OK == WindowsDeleteString(result));
}
{
auto input = make<Value>(123);
auto raw = static_cast<::IInspectable*>(get_abi(input));
HSTRING result{};
REQUIRE(S_OK == abi->InObject(raw, &result));
REQUIRE(WindowsGetStringRawBuffer(result, nullptr) == L"123"sv);
REQUIRE(S_OK == WindowsDeleteString(result));
}
{
auto input = make<Value>(123);
auto raw = static_cast<ABI::Windows::Foundation::IStringable*>(get_abi(input));
HSTRING result{};
REQUIRE(S_OK == abi->InStringable(raw, &result));
REQUIRE(WindowsGetStringRawBuffer(result, nullptr) == L"123"sv);
REQUIRE(S_OK == WindowsDeleteString(result));
}
{
Struct input{ L"1",L"2" };
auto& raw = reinterpret_cast<ABI::test_component::Struct&>(input);
HSTRING result{};
REQUIRE(S_OK == abi->InStruct(raw, &result));
REQUIRE(WindowsGetStringRawBuffer(result, nullptr) == L"12"sv);
REQUIRE(S_OK == WindowsDeleteString(result));
}
{
Struct input{ L"1",L"2" };
auto& raw = reinterpret_cast<ABI::test_component::Struct&>(input);
HSTRING result{};
REQUIRE(S_OK == abi->InStructRef(&raw, &result));
REQUIRE(WindowsGetStringRawBuffer(result, nullptr) == L"12ref"sv);
REQUIRE(S_OK == WindowsDeleteString(result));
}
{
std::array<int32_t, 2> input{ 1,2 };
HSTRING result{};
REQUIRE(S_OK == abi->InInt32Array(static_cast<uint32_t>(input.size()), input.data(), &result));
REQUIRE(WindowsGetStringRawBuffer(result, nullptr) == L"12"sv);
REQUIRE(S_OK == WindowsDeleteString(result));
}
{
std::array<HSTRING, 2> input;
WindowsCreateString(L"1", 1, input.data());
WindowsCreateString(L"2", 1, input.data() + 1);
HSTRING result{};
REQUIRE(S_OK == abi->InStringArray(static_cast<uint32_t>(input.size()), input.data(), &result));
REQUIRE(WindowsGetStringRawBuffer(result, nullptr) == L"12"sv);
REQUIRE(S_OK == WindowsDeleteString(result));
REQUIRE(S_OK == WindowsDeleteString(input[0]));
REQUIRE(S_OK == WindowsDeleteString(input[1]));
}
{
std::array<::IInspectable*, 2> input;
input[0] = static_cast<::IInspectable*>(detach_abi(make<Value>(1)));
input[1] = static_cast<::IInspectable*>(detach_abi(make<Value>(2)));
HSTRING result{};
REQUIRE(S_OK == abi->InObjectArray(static_cast<uint32_t>(input.size()), input.data(), &result));
REQUIRE(WindowsGetStringRawBuffer(result, nullptr) == L"12"sv);
REQUIRE(S_OK == WindowsDeleteString(result));
input[0]->Release();
input[1]->Release();
}
{
std::array<ABI::Windows::Foundation::IStringable*, 2> input;
input[0] = static_cast<ABI::Windows::Foundation::IStringable*>(detach_abi(make<Value>(1)));
input[1] = static_cast<ABI::Windows::Foundation::IStringable*>(detach_abi(make<Value>(2)));
HSTRING result{};
REQUIRE(S_OK == abi->InStringableArray(static_cast<uint32_t>(input.size()), input.data(), &result));
REQUIRE(WindowsGetStringRawBuffer(result, nullptr) == L"12"sv);
REQUIRE(S_OK == WindowsDeleteString(result));
input[0]->Release();
input[1]->Release();
}
{
std::array<Struct, 2> input{ Struct{L"1",L"2"}, Struct{L"3",L"4"} };
auto raw = reinterpret_cast<ABI::test_component::Struct*>(input.data());
HSTRING result{};
REQUIRE(S_OK == abi->InStructArray(static_cast<uint32_t>(input.size()), raw, &result));
REQUIRE(WindowsGetStringRawBuffer(result, nullptr) == L"1234"sv);
REQUIRE(S_OK == WindowsDeleteString(result));
}
}