forked from microsoft/cppwinrt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterop.cpp
More file actions
80 lines (69 loc) · 1.98 KB
/
Copy pathinterop.cpp
File metadata and controls
80 lines (69 loc) · 1.98 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
#include "pch.h"
#include <inspectable.h>
struct __declspec(uuid("5040a5f4-796a-42ff-9f06-be89137a518f")) IBase : IUnknown
{
};
struct __declspec(uuid("529fed32-514f-4150-b1ba-15b47df700b7")) IDerived : IBase
{
};
struct __declspec(uuid("b81fb2a2-eab4-488a-96a7-434873c2c20b")) IMoreDerived : IDerived
{
};
namespace winrt
{
template<> bool is_guid_of<IDerived>(guid const& id) noexcept
{
return is_guid_of<IDerived, IBase>(id);
}
template<> bool is_guid_of<IMoreDerived>(guid const& id) noexcept
{
return is_guid_of<IMoreDerived, IDerived, IBase>(id);
}
}
using namespace winrt;
struct MyBase : implements<MyBase, IBase>
{
};
struct MyDerived : implements<MyDerived, IDerived>
{
};
struct MyMoreDerived : implements<MyMoreDerived, IMoreDerived, Windows::Foundation::IInspectable>
{
};
Windows::Foundation::IAsyncAction Async()
{
co_return;
}
TEST_CASE("interop")
{
{
Windows::Foundation::IAsyncAction a = Async();
com_ptr<::IInspectable> b = a.as<::IInspectable>();
Windows::Foundation::IAsyncAction c = b.as<Windows::Foundation::IAsyncAction>();
REQUIRE(a == c);
}
{
com_ptr<IBase> a = make<MyBase>();
REQUIRE(a);
REQUIRE(a.try_as<IBase>() != nullptr);
REQUIRE(a.try_as<IDerived>() == nullptr);
REQUIRE(a.try_as<IMoreDerived>() == nullptr);
REQUIRE(a.try_as<::IInspectable>() == nullptr);
}
{
com_ptr<IDerived> a = make<MyDerived>();
REQUIRE(a);
REQUIRE(a.try_as<IBase>() != nullptr);
REQUIRE(a.try_as<IDerived>() != nullptr);
REQUIRE(a.try_as<IMoreDerived>() == nullptr);
REQUIRE(a.try_as<::IInspectable>() == nullptr);
}
{
com_ptr<IMoreDerived> a = make<MyMoreDerived>();
REQUIRE(a);
REQUIRE(a.try_as<IBase>() != nullptr);
REQUIRE(a.try_as<IDerived>() != nullptr);
REQUIRE(a.try_as<IMoreDerived>() != nullptr);
REQUIRE(a.try_as<::IInspectable>() != nullptr);
}
}