Skip to content

Commit

Permalink
Make test IUnknown conforming (#112566)
Browse files Browse the repository at this point in the history
* Actually allocate the test type.

* Use existing utilities to implement IUnknown.
  • Loading branch information
AaronRobinsonMSFT authored Feb 14, 2025
1 parent b93a981 commit 10532bf
Showing 1 changed file with 21 additions and 23 deletions.
44 changes: 21 additions & 23 deletions src/tests/Interop/COM/NativeClients/MiscTypes/MiscTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,23 @@ struct VariantMarshalTest
}
};

class InterfaceImpl :
public UnknownImpl,
public IInterface2
{
public: // IInterface1
public: // IInterface2
public: // IUnknown
STDMETHOD(QueryInterface)(
/* [in] */ REFIID riid,
/* [iid_is][out] */ _COM_Outptr_ void __RPC_FAR *__RPC_FAR *ppvObject)
{
return DoQueryInterface(riid, ppvObject, static_cast<IInterface1 *>(this), static_cast<IInterface2 *>(this));
}

DEFINE_REF_COUNTING();
};

void ValidationTests()
{
::printf(__FUNCTION__ "() through CoCreateInstance...\n");
Expand Down Expand Up @@ -334,30 +351,11 @@ void ValidationTests()

::printf("-- Interfaces...\n");
{
struct InterfaceImpl : IInterface2
{
STDMETHOD(QueryInterface)(REFIID riid, void** ppvObject) override
{
if (riid == __uuidof(IInterface1) || riid == __uuidof(IInterface2))
{
*ppvObject = static_cast<IInterface2*>(this);
}
else if (riid == __uuidof(IUnknown))
{
*ppvObject = static_cast<IUnknown*>(this);
}
else
{
*ppvObject = nullptr;
return E_NOINTERFACE;
}
return S_OK;
}
STDMETHOD_(ULONG, AddRef)() override { return 1; }
STDMETHOD_(ULONG, Release)() override { return 1; }
} iface{};
ComSmartPtr<InterfaceImpl> iface;
iface.Attach(new InterfaceImpl());

ComSmartPtr<IInterface2> result;
HRESULT hr = miscTypesTesting->Marshal_Interface(&iface, &result);
HRESULT hr = miscTypesTesting->Marshal_Interface(iface, &result);
THROW_IF_FAILED(hr);
}
}
Expand Down

0 comments on commit 10532bf

Please sign in to comment.