@@ -7,6 +7,10 @@ using namespace Windows::Foundation;
7
7
8
8
namespace
9
9
{
10
+ struct IClassicComInterface : ::IUnknown {};
11
+
12
+ struct ClassicCom : implements<ClassicCom, IClassicComInterface> {};
13
+
10
14
struct Stringable : implements<Stringable, IStringable>
11
15
{
12
16
Stringable (std::wstring_view const & value = L" Stringable" ) : m_value(value)
@@ -30,8 +34,16 @@ namespace
30
34
object->AddRef ();
31
35
return object->Release ();
32
36
}
37
+
38
+ template <typename T>
39
+ uint32_t get_ref_count (com_ptr<T> const & object)
40
+ {
41
+ return get_ref_count (object.get ());
42
+ }
33
43
}
34
44
45
+ template <> inline constexpr winrt::guid winrt::impl::guid_v<IClassicComInterface>{ 0xc136bb75 , 0xbc03 , 0x41a6 , { 0xa5 , 0xdc , 0x5e , 0xfa , 0x67 , 0x92 , 0x4e , 0xbf } };
46
+
35
47
TEST_CASE (" interop" )
36
48
{
37
49
uint32_t const before = get_module_lock ();
@@ -108,6 +120,43 @@ TEST_CASE("self")
108
120
REQUIRE (get_ref_count (object) == 1 );
109
121
object = nullptr ;
110
122
123
+ strong = weak.get ();
124
+ REQUIRE (!strong);
125
+ }
126
+
127
+ TEST_CASE (" self_classic_com" )
128
+ {
129
+ com_ptr<ClassicCom> strong = make_self<ClassicCom>();
130
+
131
+ REQUIRE (get_ref_count (strong.get ()) == 1 );
132
+
133
+ com_ptr<IClassicComInterface> object = strong.as <IClassicComInterface>();
134
+
135
+ REQUIRE (get_ref_count (strong.get ()) == 2 );
136
+
137
+ ClassicCom* ptr = get_self<ClassicCom>(object);
138
+ REQUIRE (ptr == strong.get ());
139
+
140
+ REQUIRE (get_ref_count (strong.get ()) == 2 );
141
+ strong = nullptr ;
142
+ REQUIRE (get_ref_count (object) == 1 );
143
+
144
+ strong = get_self<ClassicCom>(object)->get_strong ();
145
+ REQUIRE (get_ref_count (object) == 2 );
146
+ strong = nullptr ;
147
+ REQUIRE (get_ref_count (object) == 1 );
148
+
149
+ weak_ref<ClassicCom> weak = get_self<ClassicCom>(object)->get_weak ();
150
+ REQUIRE (get_ref_count (object) == 1 ); // <-- still just one!
151
+
152
+ strong = weak.get ();
153
+ REQUIRE (strong);
154
+ REQUIRE (get_ref_count (object) == 2 );
155
+
156
+ strong = nullptr ;
157
+ REQUIRE (get_ref_count (object) == 1 );
158
+ object = nullptr ;
159
+
111
160
strong = weak.get ();
112
161
REQUIRE (!strong);
113
162
}
0 commit comments