Michael Stefaniuc : ole32/tests: COM cleanup in compobj.c.
Alexandre Julliard
julliard at winehq.org
Wed Aug 3 12:48:11 CDT 2011
Module: wine
Branch: master
Commit: 3673f6b7c4651247e206e5cb9c852d974c8adc43
URL: http://source.winehq.org/git/wine.git/?a=commit;h=3673f6b7c4651247e206e5cb9c852d974c8adc43
Author: Michael Stefaniuc <mstefani at redhat.de>
Date: Wed Aug 3 12:13:03 2011 +0200
ole32/tests: COM cleanup in compobj.c.
---
dlls/ole32/tests/compobj.c | 47 +++++++++++++++++++++++++------------------
1 files changed, 27 insertions(+), 20 deletions(-)
diff --git a/dlls/ole32/tests/compobj.c b/dlls/ole32/tests/compobj.c
index 53a838e..b76c9d2 100644
--- a/dlls/ole32/tests/compobj.c
+++ b/dlls/ole32/tests/compobj.c
@@ -115,7 +115,7 @@ static ULONG WINAPI Test_IClassFactory_Release(LPCLASSFACTORY iface)
static HRESULT WINAPI Test_IClassFactory_CreateInstance(
LPCLASSFACTORY iface,
- LPUNKNOWN pUnkOuter,
+ IUnknown *pUnkOuter,
REFIID riid,
LPVOID *ppvObj)
{
@@ -570,7 +570,7 @@ static void test_CoRegisterMessageFilter(void)
}
static HRESULT WINAPI Test_IUnknown_QueryInterface(
- LPUNKNOWN iface,
+ IUnknown *iface,
REFIID riid,
LPVOID *ppvObj)
{
@@ -588,12 +588,12 @@ static HRESULT WINAPI Test_IUnknown_QueryInterface(
return E_NOINTERFACE;
}
-static ULONG WINAPI Test_IUnknown_AddRef(LPUNKNOWN iface)
+static ULONG WINAPI Test_IUnknown_AddRef(IUnknown *iface)
{
return 2; /* non-heap-based object */
}
-static ULONG WINAPI Test_IUnknown_Release(LPUNKNOWN iface)
+static ULONG WINAPI Test_IUnknown_Release(IUnknown *iface)
{
return 1; /* non-heap-based object */
}
@@ -1271,10 +1271,15 @@ static void test_CoGetObjectContext(void)
}
typedef struct {
- const IUnknownVtbl *lpVtbl;
+ IUnknown IUnknown_iface;
LONG refs;
} Test_CallContext;
+static inline Test_CallContext *impl_from_IUnknown(IUnknown *iface)
+{
+ return CONTAINING_RECORD(iface, Test_CallContext, IUnknown_iface);
+}
+
static HRESULT WINAPI Test_CallContext_QueryInterface(
IUnknown *iface,
REFIID riid,
@@ -1295,13 +1300,13 @@ static HRESULT WINAPI Test_CallContext_QueryInterface(
static ULONG WINAPI Test_CallContext_AddRef(IUnknown *iface)
{
- Test_CallContext *This = (Test_CallContext*)iface;
+ Test_CallContext *This = impl_from_IUnknown(iface);
return InterlockedIncrement(&This->refs);
}
static ULONG WINAPI Test_CallContext_Release(IUnknown *iface)
{
- Test_CallContext *This = (Test_CallContext*)iface;
+ Test_CallContext *This = impl_from_IUnknown(iface);
ULONG refs = InterlockedDecrement(&This->refs);
if (!refs)
HeapFree(GetProcessHeap(), 0, This);
@@ -1320,7 +1325,7 @@ static void test_CoGetCallContext(void)
HRESULT hr;
ULONG refs;
IUnknown *pUnk;
- IUnknown *test_object;
+ Test_CallContext *test_object;
if (!pCoSwitchCallContext)
{
@@ -1331,41 +1336,43 @@ static void test_CoGetCallContext(void)
CoInitialize(NULL);
test_object = HeapAlloc(GetProcessHeap(), 0, sizeof(Test_CallContext));
- ((Test_CallContext*)test_object)->lpVtbl = &TestCallContext_Vtbl;
- ((Test_CallContext*)test_object)->refs = 1;
+ test_object->IUnknown_iface.lpVtbl = &TestCallContext_Vtbl;
+ test_object->refs = 1;
hr = CoGetCallContext(&IID_IUnknown, (void**)&pUnk);
ok(hr == RPC_E_CALL_COMPLETE, "Expected RPC_E_CALL_COMPLETE, got 0x%08x\n", hr);
pUnk = (IUnknown*)0xdeadbeef;
- hr = pCoSwitchCallContext(test_object, &pUnk);
+ hr = pCoSwitchCallContext(&test_object->IUnknown_iface, &pUnk);
ok_ole_success(hr, "CoSwitchCallContext");
ok(pUnk == NULL, "expected NULL, got %p\n", pUnk);
- refs = IUnknown_AddRef(test_object);
+ refs = IUnknown_AddRef(&test_object->IUnknown_iface);
ok(refs == 2, "Expected refcount 2, got %d\n", refs);
- IUnknown_Release(test_object);
+ IUnknown_Release(&test_object->IUnknown_iface);
pUnk = (IUnknown*)0xdeadbeef;
hr = CoGetCallContext(&IID_IUnknown, (void**)&pUnk);
ok_ole_success(hr, "CoGetCallContext");
- ok(pUnk == test_object, "expected %p, got %p\n", test_object, pUnk);
- refs = IUnknown_AddRef(test_object);
+ ok(pUnk == &test_object->IUnknown_iface, "expected %p, got %p\n",
+ &test_object->IUnknown_iface, pUnk);
+ refs = IUnknown_AddRef(&test_object->IUnknown_iface);
ok(refs == 3, "Expected refcount 3, got %d\n", refs);
- IUnknown_Release(test_object);
+ IUnknown_Release(&test_object->IUnknown_iface);
IUnknown_Release(pUnk);
pUnk = (IUnknown*)0xdeadbeef;
hr = pCoSwitchCallContext(NULL, &pUnk);
ok_ole_success(hr, "CoSwitchCallContext");
- ok(pUnk == test_object, "expected %p, got %p\n", test_object, pUnk);
- refs = IUnknown_AddRef(test_object);
+ ok(pUnk == &test_object->IUnknown_iface, "expected %p, got %p\n",
+ &test_object->IUnknown_iface, pUnk);
+ refs = IUnknown_AddRef(&test_object->IUnknown_iface);
ok(refs == 2, "Expected refcount 2, got %d\n", refs);
- IUnknown_Release(test_object);
+ IUnknown_Release(&test_object->IUnknown_iface);
hr = CoGetCallContext(&IID_IUnknown, (void**)&pUnk);
ok(hr == RPC_E_CALL_COMPLETE, "Expected RPC_E_CALL_COMPLETE, got 0x%08x\n", hr);
- IUnknown_Release(test_object);
+ IUnknown_Release(&test_object->IUnknown_iface);
CoUninitialize();
}
More information about the wine-cvs
mailing list