From 110a62389023afde25d4082e73acd0494f6d9cb3 Mon Sep 17 00:00:00 2001 From: Kenny Kerr Date: Fri, 15 Nov 2019 07:01:16 -0800 Subject: [PATCH 1/4] guid --- test/test/box_guid.cpp | 11 +++++++++++ test/test/test.vcxproj | 1 + 2 files changed, 12 insertions(+) create mode 100644 test/test/box_guid.cpp diff --git a/test/test/box_guid.cpp b/test/test/box_guid.cpp new file mode 100644 index 000000000..cca49dd28 --- /dev/null +++ b/test/test/box_guid.cpp @@ -0,0 +1,11 @@ +#include "pch.h" + +TEST_CASE("box_guid") +{ + winrt::guid const guid_a = winrt::guid_of(); + GUID const guid_b = guid_a; + + auto box_a = winrt::box_value(guid_a); + auto box_b = winrt::box_value(guid_b); +} + diff --git a/test/test/test.vcxproj b/test/test/test.vcxproj index 2129464d5..89323600c 100644 --- a/test/test/test.vcxproj +++ b/test/test/test.vcxproj @@ -286,6 +286,7 @@ + From 401df27d017fab5c7e454dfd4bb0be8e7422ad0d Mon Sep 17 00:00:00 2001 From: Kenny Kerr Date: Fri, 15 Nov 2019 08:09:47 -0800 Subject: [PATCH 2/4] guid --- strings/base_reference_produce.h | 23 +++++++++++++++++++++++ test/test/box_guid.cpp | 20 ++++++++++++++++---- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/strings/base_reference_produce.h b/strings/base_reference_produce.h index 3b0b9864b..b246f6823 100644 --- a/strings/base_reference_produce.h +++ b/strings/base_reference_produce.h @@ -197,6 +197,14 @@ namespace winrt::impl static auto make(guid const& value) { return Windows::Foundation::PropertyValue::CreateGuid(value); } }; +#ifdef __IUnknown_INTERFACE_DEFINED__ + template <> + struct reference_traits + { + static auto make(GUID const& value) { return Windows::Foundation::PropertyValue::CreateGuid(value); } + }; +#endif + template <> struct reference_traits { @@ -291,6 +299,12 @@ WINRT_EXPORT namespace winrt return static_cast(value.as>>().Value()); } } +#ifdef __IUnknown_INTERFACE_DEFINED__ + else if constexpr (std::is_same_v) + { + return value.as>().Value(); + } +#endif else { return value.as>().Value(); @@ -335,6 +349,15 @@ WINRT_EXPORT namespace winrt return static_cast(temp.Value()); } } +#ifdef __IUnknown_INTERFACE_DEFINED__ + else if constexpr (std::is_same_v) + { + if (auto temp = value.try_as>()) + { + return temp.Value(); + } + } +#endif else { if (auto temp = value.try_as>()) diff --git a/test/test/box_guid.cpp b/test/test/box_guid.cpp index cca49dd28..9c72a9d9f 100644 --- a/test/test/box_guid.cpp +++ b/test/test/box_guid.cpp @@ -2,10 +2,22 @@ TEST_CASE("box_guid") { - winrt::guid const guid_a = winrt::guid_of(); - GUID const guid_b = guid_a; + winrt::guid const winrt_guid = __uuidof(::IUnknown); + GUID const sdk_guid = winrt_guid; - auto box_a = winrt::box_value(guid_a); - auto box_b = winrt::box_value(guid_b); + auto box_a = winrt::box_value(winrt_guid); + auto box_b = winrt::box_value(sdk_guid); + + auto unbox_a = winrt::unbox_value(box_a); + auto unbox_b = winrt::unbox_value(box_a); + + REQUIRE(unbox_a == winrt_guid); + REQUIRE(unbox_b == sdk_guid); + + unbox_a = winrt::unbox_value_or(box_a, {}); + unbox_b = winrt::unbox_value_or(box_a, {}); + + REQUIRE(unbox_a == winrt_guid); + REQUIRE(unbox_b == sdk_guid); } From c4fe5e60d73b16e95b6ebd7c022a09f687dd70ee Mon Sep 17 00:00:00 2001 From: Kenny Kerr Date: Fri, 15 Nov 2019 08:17:34 -0800 Subject: [PATCH 3/4] guid --- test/test/box_guid.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/test/box_guid.cpp b/test/test/box_guid.cpp index 9c72a9d9f..56f904748 100644 --- a/test/test/box_guid.cpp +++ b/test/test/box_guid.cpp @@ -8,14 +8,14 @@ TEST_CASE("box_guid") auto box_a = winrt::box_value(winrt_guid); auto box_b = winrt::box_value(sdk_guid); - auto unbox_a = winrt::unbox_value(box_a); - auto unbox_b = winrt::unbox_value(box_a); + winrt::guid unbox_a = winrt::unbox_value(box_a); + GUID unbox_b = winrt::unbox_value(box_a); REQUIRE(unbox_a == winrt_guid); REQUIRE(unbox_b == sdk_guid); - unbox_a = winrt::unbox_value_or(box_a, {}); - unbox_b = winrt::unbox_value_or(box_a, {}); + unbox_a = winrt::unbox_value_or(box_a, winrt::guid{}); + unbox_b = winrt::unbox_value_or(box_a, GUID{}); REQUIRE(unbox_a == winrt_guid); REQUIRE(unbox_b == sdk_guid); From b9bfde816ae2cb210763b8e87051fa92936e34b1 Mon Sep 17 00:00:00 2001 From: Kenny Kerr Date: Fri, 15 Nov 2019 08:18:11 -0800 Subject: [PATCH 4/4] guid --- test/test/box_guid.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/test/test/box_guid.cpp b/test/test/box_guid.cpp index 56f904748..883c6e8e1 100644 --- a/test/test/box_guid.cpp +++ b/test/test/box_guid.cpp @@ -20,4 +20,3 @@ TEST_CASE("box_guid") REQUIRE(unbox_a == winrt_guid); REQUIRE(unbox_b == sdk_guid); } -