browseui/tests: COM cleanup in autocomplete.c.

This commit is contained in:
Michael Stefaniuc 2011-03-24 13:44:14 +01:00 committed by Alexandre Julliard
parent 94462664c5
commit 4c98182a5b
1 changed files with 26 additions and 18 deletions

View File

@ -55,8 +55,8 @@ static LPWSTR strdup_AtoW(LPCSTR str)
typedef struct typedef struct
{ {
IEnumStringVtbl *vtbl; IEnumString IEnumString_iface;
IACListVtbl *aclVtbl; IACList IACList_iface;
LONG ref; LONG ref;
HRESULT expret; HRESULT expret;
INT expcount; INT expcount;
@ -68,17 +68,22 @@ typedef struct
extern IEnumStringVtbl TestACLVtbl; extern IEnumStringVtbl TestACLVtbl;
extern IACListVtbl TestACL_ACListVtbl; extern IACListVtbl TestACL_ACListVtbl;
static inline TestACL *impl_from_IEnumString(IEnumString *iface)
{
return CONTAINING_RECORD(iface, TestACL, IEnumString_iface);
}
static TestACL *impl_from_IACList(IACList *iface) static TestACL *impl_from_IACList(IACList *iface)
{ {
return (TestACL *)((char *)iface - FIELD_OFFSET(TestACL, aclVtbl)); return CONTAINING_RECORD(iface, TestACL, IACList_iface);
} }
static TestACL *TestACL_Constructor(int limit, const char **strings) static TestACL *TestACL_Constructor(int limit, const char **strings)
{ {
TestACL *This = CoTaskMemAlloc(sizeof(TestACL)); TestACL *This = CoTaskMemAlloc(sizeof(TestACL));
ZeroMemory(This, sizeof(*This)); ZeroMemory(This, sizeof(*This));
This->vtbl = &TestACLVtbl; This->IEnumString_iface.lpVtbl = &TestACLVtbl;
This->aclVtbl = &TestACL_ACListVtbl; This->IACList_iface.lpVtbl = &TestACL_ACListVtbl;
This->ref = 1; This->ref = 1;
This->expret = S_OK; This->expret = S_OK;
This->limit = limit; This->limit = limit;
@ -88,14 +93,14 @@ static TestACL *TestACL_Constructor(int limit, const char **strings)
static ULONG STDMETHODCALLTYPE TestACL_AddRef(IEnumString *iface) static ULONG STDMETHODCALLTYPE TestACL_AddRef(IEnumString *iface)
{ {
TestACL *This = (TestACL *)iface; TestACL *This = impl_from_IEnumString(iface);
trace("ACL(%p): addref (%d)\n", This, This->ref+1); trace("ACL(%p): addref (%d)\n", This, This->ref+1);
return InterlockedIncrement(&This->ref); return InterlockedIncrement(&This->ref);
} }
static ULONG STDMETHODCALLTYPE TestACL_Release(IEnumString *iface) static ULONG STDMETHODCALLTYPE TestACL_Release(IEnumString *iface)
{ {
TestACL *This = (TestACL *)iface; TestACL *This = impl_from_IEnumString(iface);
ULONG res; ULONG res;
res = InterlockedDecrement(&This->ref); res = InterlockedDecrement(&This->ref);
@ -105,7 +110,7 @@ static ULONG STDMETHODCALLTYPE TestACL_Release(IEnumString *iface)
static HRESULT STDMETHODCALLTYPE TestACL_QueryInterface(IEnumString *iface, REFIID iid, LPVOID *ppvOut) static HRESULT STDMETHODCALLTYPE TestACL_QueryInterface(IEnumString *iface, REFIID iid, LPVOID *ppvOut)
{ {
TestACL *This = (TestACL *)iface; TestACL *This = impl_from_IEnumString(iface);
*ppvOut = NULL; *ppvOut = NULL;
if (IsEqualGUID(iid, &IID_IUnknown) || IsEqualGUID(iid, &IID_IEnumString)) if (IsEqualGUID(iid, &IID_IUnknown) || IsEqualGUID(iid, &IID_IEnumString))
{ {
@ -113,7 +118,7 @@ static HRESULT STDMETHODCALLTYPE TestACL_QueryInterface(IEnumString *iface, REFI
} }
else if (IsEqualGUID(iid, &IID_IACList)) else if (IsEqualGUID(iid, &IID_IACList))
{ {
*ppvOut = &This->aclVtbl; *ppvOut = &This->IACList_iface;
} }
if (*ppvOut) if (*ppvOut)
@ -131,7 +136,7 @@ static HRESULT STDMETHODCALLTYPE TestACL_QueryInterface(IEnumString *iface, REFI
static HRESULT STDMETHODCALLTYPE TestACL_Next(IEnumString *iface, ULONG celt, LPOLESTR *rgelt, ULONG *pceltFetched) static HRESULT STDMETHODCALLTYPE TestACL_Next(IEnumString *iface, ULONG celt, LPOLESTR *rgelt, ULONG *pceltFetched)
{ {
TestACL *This = (TestACL *)iface; TestACL *This = impl_from_IEnumString(iface);
ULONG i; ULONG i;
trace("ACL(%p): read %d item(s)\n", This, celt); trace("ACL(%p): read %d item(s)\n", This, celt);
@ -164,7 +169,7 @@ static HRESULT STDMETHODCALLTYPE TestACL_Clone(IEnumString *iface, IEnumString *
static HRESULT STDMETHODCALLTYPE TestACL_Reset(IEnumString *iface) static HRESULT STDMETHODCALLTYPE TestACL_Reset(IEnumString *iface)
{ {
TestACL *This = (TestACL *)iface; TestACL *This = impl_from_IEnumString(iface);
trace("ACL(%p): Reset\n", This); trace("ACL(%p): Reset\n", This);
This->pos = 0; This->pos = 0;
return S_OK; return S_OK;
@ -173,7 +178,7 @@ static HRESULT STDMETHODCALLTYPE TestACL_Reset(IEnumString *iface)
static HRESULT STDMETHODCALLTYPE TestACL_Expand(IACList *iface, LPCOLESTR str) static HRESULT STDMETHODCALLTYPE TestACL_Expand(IACList *iface, LPCOLESTR str)
{ {
TestACL *This = impl_from_IACList(iface); TestACL *This = impl_from_IACList(iface);
trace("ACL(%p): Expand\n", impl_from_IACList(iface)); trace("ACL(%p): Expand\n", This);
This->expcount++; This->expcount++;
return This->expret; return This->expret;
} }
@ -192,17 +197,20 @@ IEnumStringVtbl TestACLVtbl =
static ULONG STDMETHODCALLTYPE TestACL_ACList_AddRef(IACList *iface) static ULONG STDMETHODCALLTYPE TestACL_ACList_AddRef(IACList *iface)
{ {
return TestACL_AddRef((IEnumString *)impl_from_IACList(iface)); TestACL *This = impl_from_IACList(iface);
return TestACL_AddRef(&This->IEnumString_iface);
} }
static ULONG STDMETHODCALLTYPE TestACL_ACList_Release(IACList *iface) static ULONG STDMETHODCALLTYPE TestACL_ACList_Release(IACList *iface)
{ {
return TestACL_Release((IEnumString *)impl_from_IACList(iface)); TestACL *This = impl_from_IACList(iface);
return TestACL_Release(&This->IEnumString_iface);
} }
static HRESULT STDMETHODCALLTYPE TestACL_ACList_QueryInterface(IACList *iface, REFIID iid, LPVOID *ppvout) static HRESULT STDMETHODCALLTYPE TestACL_ACList_QueryInterface(IACList *iface, REFIID iid, LPVOID *ppvout)
{ {
return TestACL_QueryInterface((IEnumString *)impl_from_IACList(iface), iid, ppvout); TestACL *This = impl_from_IACList(iface);
return TestACL_QueryInterface(&This->IEnumString_iface, iid, ppvout);
} }
IACListVtbl TestACL_ACListVtbl = IACListVtbl TestACL_ACListVtbl =
@ -259,8 +267,8 @@ static void test_ACLMulti(void)
acl1 = TestACL_Constructor(3, strings1); acl1 = TestACL_Constructor(3, strings1);
acl2 = TestACL_Constructor(3, strings2); acl2 = TestACL_Constructor(3, strings2);
stop_on_error(mgr->lpVtbl->Append(mgr, (IUnknown *)acl1)); stop_on_error(mgr->lpVtbl->Append(mgr, (IUnknown *)&acl1->IACList_iface));
stop_on_error(mgr->lpVtbl->Append(mgr, (IUnknown *)acl2)); stop_on_error(mgr->lpVtbl->Append(mgr, (IUnknown *)&acl2->IACList_iface));
ok(mgr->lpVtbl->Append(mgr, NULL) == E_FAIL, "Unexpected return from Append\n"); ok(mgr->lpVtbl->Append(mgr, NULL) == E_FAIL, "Unexpected return from Append\n");
expect_str(obj, "a"); expect_str(obj, "a");
expect_str(obj, "c"); expect_str(obj, "c");
@ -307,7 +315,7 @@ static void test_ACLMulti(void)
acl2->expret = E_FAIL; acl2->expret = E_FAIL;
ok(acl->lpVtbl->Expand(acl, exp) == E_FAIL, "Unexpected Expand return\n"); ok(acl->lpVtbl->Expand(acl, exp) == E_FAIL, "Unexpected Expand return\n");
stop_on_error(mgr->lpVtbl->Remove(mgr, (IUnknown *)acl1)); stop_on_error(mgr->lpVtbl->Remove(mgr, (IUnknown *)&acl1->IACList_iface));
ok(acl1->ref == 1, "acl1 not released\n"); ok(acl1->ref == 1, "acl1 not released\n");
expect_end(obj); expect_end(obj);
obj->lpVtbl->Reset(obj); obj->lpVtbl->Reset(obj);