Skip to content

Commit 10532bf

Browse files
Make test IUnknown conforming (#112566)
* Actually allocate the test type. * Use existing utilities to implement IUnknown.
1 parent b93a981 commit 10532bf

File tree

1 file changed

+21
-23
lines changed

1 file changed

+21
-23
lines changed

src/tests/Interop/COM/NativeClients/MiscTypes/MiscTypes.cpp

+21-23
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,23 @@ struct VariantMarshalTest
8989
}
9090
};
9191

92+
class InterfaceImpl :
93+
public UnknownImpl,
94+
public IInterface2
95+
{
96+
public: // IInterface1
97+
public: // IInterface2
98+
public: // IUnknown
99+
STDMETHOD(QueryInterface)(
100+
/* [in] */ REFIID riid,
101+
/* [iid_is][out] */ _COM_Outptr_ void __RPC_FAR *__RPC_FAR *ppvObject)
102+
{
103+
return DoQueryInterface(riid, ppvObject, static_cast<IInterface1 *>(this), static_cast<IInterface2 *>(this));
104+
}
105+
106+
DEFINE_REF_COUNTING();
107+
};
108+
92109
void ValidationTests()
93110
{
94111
::printf(__FUNCTION__ "() through CoCreateInstance...\n");
@@ -334,30 +351,11 @@ void ValidationTests()
334351

335352
::printf("-- Interfaces...\n");
336353
{
337-
struct InterfaceImpl : IInterface2
338-
{
339-
STDMETHOD(QueryInterface)(REFIID riid, void** ppvObject) override
340-
{
341-
if (riid == __uuidof(IInterface1) || riid == __uuidof(IInterface2))
342-
{
343-
*ppvObject = static_cast<IInterface2*>(this);
344-
}
345-
else if (riid == __uuidof(IUnknown))
346-
{
347-
*ppvObject = static_cast<IUnknown*>(this);
348-
}
349-
else
350-
{
351-
*ppvObject = nullptr;
352-
return E_NOINTERFACE;
353-
}
354-
return S_OK;
355-
}
356-
STDMETHOD_(ULONG, AddRef)() override { return 1; }
357-
STDMETHOD_(ULONG, Release)() override { return 1; }
358-
} iface{};
354+
ComSmartPtr<InterfaceImpl> iface;
355+
iface.Attach(new InterfaceImpl());
356+
359357
ComSmartPtr<IInterface2> result;
360-
HRESULT hr = miscTypesTesting->Marshal_Interface(&iface, &result);
358+
HRESULT hr = miscTypesTesting->Marshal_Interface(iface, &result);
361359
THROW_IF_FAILED(hr);
362360
}
363361
}

0 commit comments

Comments
 (0)