-
Notifications
You must be signed in to change notification settings - Fork 275
Expand file tree
/
Copy pathbox_string.cpp
More file actions
53 lines (46 loc) · 1.48 KB
/
box_string.cpp
File metadata and controls
53 lines (46 loc) · 1.48 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
#include "pch.h"
TEST_CASE("box_string")
{
// hstring
{
winrt::hstring value = L"hstring";
auto boxed = winrt::box_value(value);
REQUIRE(winrt::unbox_value<winrt::hstring>(boxed) == L"hstring");
}
// wchar_t const* (string literal)
{
auto boxed = winrt::box_value(L"literal");
REQUIRE(winrt::unbox_value<winrt::hstring>(boxed) == L"literal");
}
// std::wstring
{
std::wstring value = L"wstring";
auto boxed = winrt::box_value(value);
REQUIRE(winrt::unbox_value<winrt::hstring>(boxed) == L"wstring");
}
// std::wstring_view (null-terminated)
{
std::wstring_view value = L"view";
auto boxed = winrt::box_value(value);
REQUIRE(winrt::unbox_value<winrt::hstring>(boxed) == L"view");
}
// std::wstring_view (not null-terminated)
// Regression test for https://github.com/microsoft/cppwinrt/issues/1527
{
std::wstring source = L"ABCDE";
std::wstring_view value(source.data(), 3); // "ABC"
auto boxed = winrt::box_value(value);
REQUIRE(winrt::unbox_value<winrt::hstring>(boxed) == L"ABC");
}
// Empty string
{
auto boxed = winrt::box_value(winrt::hstring{});
REQUIRE(winrt::unbox_value<winrt::hstring>(boxed) == L"");
}
// Empty wstring_view
{
std::wstring_view value;
auto boxed = winrt::box_value(value);
REQUIRE(winrt::unbox_value<winrt::hstring>(boxed) == L"");
}
}