ole32/tests: Use an iface instead of a vtbl pointer in HeapUnknown.

This commit is contained in:
Michael Stefaniuc 2010-12-04 22:14:56 +01:00 committed by Alexandre Julliard
parent b8ef455d49
commit 46ebaa9be2
2 changed files with 27 additions and 17 deletions

View File

@ -1697,10 +1697,15 @@ static void test_proxy_interfaces(void)
typedef struct
{
const IUnknownVtbl *lpVtbl;
IUnknown IUnknown_iface;
ULONG refs;
} HeapUnknown;
static inline HeapUnknown *impl_from_IUnknown(IUnknown *iface)
{
return CONTAINING_RECORD(iface, HeapUnknown, IUnknown_iface);
}
static HRESULT WINAPI HeapUnknown_QueryInterface(IUnknown *iface, REFIID riid, void **ppv)
{
if (IsEqualIID(riid, &IID_IUnknown))
@ -1715,13 +1720,13 @@ static HRESULT WINAPI HeapUnknown_QueryInterface(IUnknown *iface, REFIID riid, v
static ULONG WINAPI HeapUnknown_AddRef(IUnknown *iface)
{
HeapUnknown *This = (HeapUnknown *)iface;
HeapUnknown *This = impl_from_IUnknown(iface);
return InterlockedIncrement((LONG*)&This->refs);
}
static ULONG WINAPI HeapUnknown_Release(IUnknown *iface)
{
HeapUnknown *This = (HeapUnknown *)iface;
HeapUnknown *This = impl_from_IUnknown(iface);
ULONG refs = InterlockedDecrement((LONG*)&This->refs);
if (!refs) HeapFree(GetProcessHeap(), 0, This);
return refs;
@ -1744,7 +1749,7 @@ static void test_proxybuffer(REFIID riid)
CLSID clsid;
HeapUnknown *pUnkOuter = HeapAlloc(GetProcessHeap(), 0, sizeof(*pUnkOuter));
pUnkOuter->lpVtbl = &HeapUnknown_Vtbl;
pUnkOuter->IUnknown_iface.lpVtbl = &HeapUnknown_Vtbl;
pUnkOuter->refs = 1;
hr = CoGetPSClsid(riid, &clsid);
@ -1753,13 +1758,13 @@ static void test_proxybuffer(REFIID riid)
hr = CoGetClassObject(&clsid, CLSCTX_INPROC_SERVER, NULL, &IID_IPSFactoryBuffer, (LPVOID*)&psfb);
ok_ole_success(hr, CoGetClassObject);
hr = IPSFactoryBuffer_CreateProxy(psfb, (IUnknown*)pUnkOuter, riid, &proxy, &lpvtbl);
hr = IPSFactoryBuffer_CreateProxy(psfb, &pUnkOuter->IUnknown_iface, riid, &proxy, &lpvtbl);
ok_ole_success(hr, IPSFactoryBuffer_CreateProxy);
ok(lpvtbl != NULL, "IPSFactoryBuffer_CreateProxy succeeded, but returned a NULL vtable!\n");
/* release our reference to the outer unknown object - the PS factory
* buffer will have AddRef's it in the CreateProxy call */
refs = IUnknown_Release((IUnknown *)pUnkOuter);
refs = IUnknown_Release(&pUnkOuter->IUnknown_iface);
ok(refs == 1, "Ref count of outer unknown should have been 1 instead of %d\n", refs);
refs = IPSFactoryBuffer_Release(psfb);

View File

@ -156,10 +156,15 @@ static IClassFactory Test_ClassFactory = { &TestClassFactory_Vtbl };
typedef struct
{
const IUnknownVtbl *lpVtbl;
IUnknown IUnknown_iface;
ULONG refs;
} HeapUnknown;
static inline HeapUnknown *impl_from_IUnknown(IUnknown *iface)
{
return CONTAINING_RECORD(iface, HeapUnknown, IUnknown_iface);
}
static HRESULT WINAPI HeapUnknown_QueryInterface(IUnknown *iface, REFIID riid, void **ppv)
{
if (IsEqualIID(riid, &IID_IUnknown))
@ -174,13 +179,13 @@ static HRESULT WINAPI HeapUnknown_QueryInterface(IUnknown *iface, REFIID riid, v
static ULONG WINAPI HeapUnknown_AddRef(IUnknown *iface)
{
HeapUnknown *This = (HeapUnknown *)iface;
HeapUnknown *This = impl_from_IUnknown(iface);
return InterlockedIncrement((LONG*)&This->refs);
}
static ULONG WINAPI HeapUnknown_Release(IUnknown *iface)
{
HeapUnknown *This = (HeapUnknown *)iface;
HeapUnknown *This = impl_from_IUnknown(iface);
ULONG refs = InterlockedDecrement((LONG*)&This->refs);
if (!refs) HeapFree(GetProcessHeap(), 0, This);
return refs;
@ -1880,9 +1885,9 @@ static void test_bind_context(void)
ok(hr == E_INVALIDARG, "IBindCtx_RegisterObjectParam should have returned E_INVALIDARG instead of 0x%08x\n", hr);
unknown = HeapAlloc(GetProcessHeap(), 0, sizeof(*unknown));
unknown->lpVtbl = &HeapUnknown_Vtbl;
unknown->IUnknown_iface.lpVtbl = &HeapUnknown_Vtbl;
unknown->refs = 1;
hr = IBindCtx_RegisterObjectParam(pBindCtx, (WCHAR *)wszParamName, (IUnknown *)&unknown->lpVtbl);
hr = IBindCtx_RegisterObjectParam(pBindCtx, (WCHAR *)wszParamName, &unknown->IUnknown_iface);
ok_ole_success(hr, "IBindCtx_RegisterObjectParam");
hr = IBindCtx_GetObjectParam(pBindCtx, (WCHAR *)wszParamName, &param_obj);
@ -1907,23 +1912,23 @@ static void test_bind_context(void)
ok(hr == E_INVALIDARG, "IBindCtx_RevokeObjectBound(NULL) should have return E_INVALIDARG instead of 0x%08x\n", hr);
unknown2 = HeapAlloc(GetProcessHeap(), 0, sizeof(*unknown));
unknown2->lpVtbl = &HeapUnknown_Vtbl;
unknown2->IUnknown_iface.lpVtbl = &HeapUnknown_Vtbl;
unknown2->refs = 1;
hr = IBindCtx_RegisterObjectBound(pBindCtx, (IUnknown *)&unknown2->lpVtbl);
hr = IBindCtx_RegisterObjectBound(pBindCtx, &unknown2->IUnknown_iface);
ok_ole_success(hr, "IBindCtx_RegisterObjectBound");
hr = IBindCtx_RevokeObjectBound(pBindCtx, (IUnknown *)&unknown2->lpVtbl);
hr = IBindCtx_RevokeObjectBound(pBindCtx, &unknown2->IUnknown_iface);
ok_ole_success(hr, "IBindCtx_RevokeObjectBound");
hr = IBindCtx_RevokeObjectBound(pBindCtx, (IUnknown *)&unknown2->lpVtbl);
hr = IBindCtx_RevokeObjectBound(pBindCtx, &unknown2->IUnknown_iface);
ok(hr == MK_E_NOTBOUND, "IBindCtx_RevokeObjectBound with not bound object should have returned MK_E_NOTBOUND instead of 0x%08x\n", hr);
IBindCtx_Release(pBindCtx);
refs = IUnknown_Release((IUnknown *)&unknown->lpVtbl);
refs = IUnknown_Release(&unknown->IUnknown_iface);
ok(!refs, "object param should have been destroyed, instead of having %d refs\n", refs);
refs = IUnknown_Release((IUnknown *)&unknown2->lpVtbl);
refs = IUnknown_Release(&unknown2->IUnknown_iface);
ok(!refs, "bound object should have been destroyed, instead of having %d refs\n", refs);
}