@@ -7,6 +7,10 @@ using namespace Windows::Foundation;
77
88namespace
99{
10+ struct IClassicComInterface : ::IUnknown {};
11+
12+ struct ClassicCom : implements<ClassicCom, IClassicComInterface> {};
13+
1014 struct Stringable : implements<Stringable, IStringable>
1115 {
1216 Stringable (std::wstring_view const & value = L" Stringable" ) : m_value(value)
@@ -30,8 +34,16 @@ namespace
3034 object->AddRef ();
3135 return object->Release ();
3236 }
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+ }
3343}
3444
45+ template <> inline constexpr winrt::guid winrt::impl::guid_v<IClassicComInterface>{ 0xc136bb75 , 0xbc03 , 0x41a6 , { 0xa5 , 0xdc , 0x5e , 0xfa , 0x67 , 0x92 , 0x4e , 0xbf } };
46+
3547TEST_CASE (" interop" )
3648{
3749 uint32_t const before = get_module_lock ();
@@ -108,6 +120,43 @@ TEST_CASE("self")
108120 REQUIRE (get_ref_count (object) == 1 );
109121 object = nullptr ;
110122
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+
111160 strong = weak.get ();
112161 REQUIRE (!strong);
113162}
0 commit comments