#include "pch.h"
namespace
{
template
void Verify(T const& otherValue)
{
T defaultValue{};
winrt::com_array ary{ otherValue, defaultValue };
auto box = winrt::box_value(ary);
winrt::com_array unbox = box.template try_as<:com_array>>().value();
REQUIRE(unbox.size() == 2);
REQUIRE(unbox.at(0) == otherValue);
REQUIRE(unbox.at(1) == defaultValue);
unbox = box.template as<:com_array>>();
REQUIRE(unbox.size() == 2);
REQUIRE(unbox.at(0) == otherValue);
REQUIRE(unbox.at(1) == defaultValue);
if constexpr (!std::is_same_v)
{
unbox = box.template as<:optional>>>().Value();
REQUIRE(unbox.size() == 2);
REQUIRE(unbox.at(0) == otherValue);
REQUIRE(unbox.at(1) == defaultValue);
}
unbox = winrt::unbox_value<:com_array>>(box);
REQUIRE(unbox.size() == 2);
REQUIRE(unbox.at(0) == otherValue);
REQUIRE(unbox.at(1) == defaultValue);
// Cannot use unbox_value_or with arrays because com_array is not copyable.
// unbox = winrt::unbox_value_or(box, winrt::com_array{});
}
}
TEST_CASE("box_array")
{
Verify(42);
Verify(42);
Verify(42);
Verify(42);
Verify(42);
Verify(42);
Verify(42);
Verify(42);
Verify(42);
Verify(42);
Verify(true);
Verify<:hstring>(L"42");
Verify<:windows::foundation::iinspectable>(winrt::Windows::Foundation::Uri{ L"https://www.microsoft.com/" });
Verify<:guid>({ 1,2,3, {4,5,6,7,8,9,10,11} });
Verify(winrt::guid{ 1,2,3, {4,5,6,7,8,9,10,11} });
Verify<:windows::foundation::datetime>((winrt::Windows::Foundation::DateTime::max)());
Verify<:windows::foundation::timespan>((winrt::Windows::Foundation::TimeSpan::max)());
Verify<:windows::foundation::point>({ 1,1 });
Verify<:windows::foundation::size>({ 1,1 });
Verify<:windows::foundation::rect>({ 1,1,1,1 });
}