forked from microsoft/cppwinrt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelegates.cpp
More file actions
98 lines (92 loc) · 2.33 KB
/
delegates.cpp
File metadata and controls
98 lines (92 loc) · 2.33 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
#include "pch.h"
#include "winrt/test_component.Delegates.h"
using namespace winrt;
using namespace test_component::Delegates;
TEST_CASE("delegates")
{
{
bool run{};
AgileDelegate d = [&] {run = true; };
REQUIRE(!run);
d();
REQUIRE(run);
}
{
hstring value;
InDelegate d = [&](hstring const& in)
{
value = in;
};
REQUIRE(value.empty());
d(L"Test");
REQUIRE(value == L"Test");
}
{
ReturnStringDelegate d = [] {return L"Test"; };
REQUIRE(d() == L"Test");
}
{
ReturnInt32Delegate d = [] {return 123; };
REQUIRE(d() == 123);
}
{
OutStringDelegate d = [](hstring& value)
{
value = L"Test";
};
hstring value;
d(value);
REQUIRE(value == L"Test");
}
{
OutStringDelegate d = [](hstring&)
{
};
hstring value = L"old";
d(value);
REQUIRE(value == L"");
}
{
OutInt32Delegate d = [](int32_t & value)
{
value = 123;
};
int32_t value{ 0xCC };
d(value);
REQUIRE(value == 123);
}
{
OutInt32Delegate d = [](int32_t&)
{
};
int32_t value{ 123 };
d(value);
REQUIRE(value == 123);
}
{
ReturnStringArrayDelegate d = [] { return com_array<hstring>{ L"One", L"Two", L"Three" }; };
com_array<hstring> value = d();
REQUIRE(value.size() == 3);
REQUIRE(value[0] == L"One");
REQUIRE(value[1] == L"Two");
REQUIRE(value[2] == L"Three");
}
{
OutStringArrayDelegate d = [](com_array<hstring>& value) { value = { L"One", L"Two", L"Three" }; };
com_array<hstring> value;
d(value);
REQUIRE(value.size() == 3);
REQUIRE(value[0] == L"One");
REQUIRE(value[1] == L"Two");
REQUIRE(value[2] == L"Three");
}
{
RefStringArrayDelegate d = [](array_view<hstring> value) { value[0] = L"One"; value[1] = L"Two"; value[2] = L"Three"; };
std::array<hstring, 4> value{ L"r1", L"r2", L"r3", L"r4" };
d(value);
REQUIRE(value[0] == L"One");
REQUIRE(value[1] == L"Two");
REQUIRE(value[2] == L"Three");
REQUIRE(value[3] == L"");
}
}