explorerframe/tests: COM cleanup for INameSpaceTreeControlEventsImpl.

Michael Stefaniuc mstefani at redhat.de
Tue Dec 28 19:53:01 CST 2010


---
 dlls/explorerframe/tests/nstc.c |  103 +++++++++++++++++++++++++++-----------
 1 files changed, 73 insertions(+), 30 deletions(-)

diff --git a/dlls/explorerframe/tests/nstc.c b/dlls/explorerframe/tests/nstc.c
index e4d8443..4b23c95 100644
--- a/dlls/explorerframe/tests/nstc.c
+++ b/dlls/explorerframe/tests/nstc.c
@@ -21,6 +21,7 @@
 #include <stdio.h>
 
 #define COBJMACROS
+#define CONST_VTABLE
 
 #include "shlobj.h"
 #include "wine/test.h"
@@ -67,25 +68,28 @@ enum { OnItemClick = 0, OnPropertyItemCommit, OnItemStateChanging, OnItemStateCh
        LastEvent };
 
 typedef struct {
-    const INameSpaceTreeControlEventsVtbl *lpVtbl;
+    INameSpaceTreeControlEvents INameSpaceTreeControlEvents_iface;
     UINT qi_called_count;     /* Keep track of calls to QueryInterface */
     BOOL qi_enable_events;    /* If FALSE, QueryInterface returns only E_NOINTERFACE */
     UINT count[LastEvent];    /* Keep track of calls to all On* functions. */
     LONG ref;
 } INameSpaceTreeControlEventsImpl;
 
-#define NSTCE_IMPL(iface)                       \
-    ((INameSpaceTreeControlEventsImpl*)iface)
+static inline INameSpaceTreeControlEventsImpl *impl_from_INameSpaceTreeControlEvents(INameSpaceTreeControlEvents *iface)
+{
+    return CONTAINING_RECORD(iface, INameSpaceTreeControlEventsImpl, INameSpaceTreeControlEvents_iface);
+}
 
 static HRESULT WINAPI NSTCEvents_fnQueryInterface(
     INameSpaceTreeControlEvents* iface,
     REFIID riid,
     void **ppvObject)
 {
-    NSTCE_IMPL(iface)->qi_called_count++;
+    INameSpaceTreeControlEventsImpl *This = impl_from_INameSpaceTreeControlEvents(iface);
+
+    This->qi_called_count++;
 
-    if(NSTCE_IMPL(iface)->qi_enable_events &&
-       IsEqualIID(riid, &IID_INameSpaceTreeControlEvents))
+    if(This->qi_enable_events && IsEqualIID(riid, &IID_INameSpaceTreeControlEvents))
     {
         IUnknown_AddRef(iface);
         *ppvObject = iface;
@@ -98,13 +102,17 @@ static HRESULT WINAPI NSTCEvents_fnQueryInterface(
 static ULONG WINAPI NSTCEvents_fnAddRef(
     INameSpaceTreeControlEvents* iface)
 {
-    return InterlockedIncrement(&NSTCE_IMPL(iface)->ref);
+    INameSpaceTreeControlEventsImpl *This = impl_from_INameSpaceTreeControlEvents(iface);
+
+    return InterlockedIncrement(&This->ref);
 }
 
 static ULONG WINAPI NSTCEvents_fnRelease(
     INameSpaceTreeControlEvents* iface)
 {
-    return InterlockedDecrement(&NSTCE_IMPL(iface)->ref);
+    INameSpaceTreeControlEventsImpl *This = impl_from_INameSpaceTreeControlEvents(iface);
+
+    return InterlockedDecrement(&This->ref);
 }
 
 static HRESULT WINAPI NSTCEvents_fnOnItemClick(
@@ -113,8 +121,10 @@ static HRESULT WINAPI NSTCEvents_fnOnItemClick(
     NSTCEHITTEST nstceHitTest,
     NSTCECLICKTYPE nstceClickType)
 {
+    INameSpaceTreeControlEventsImpl *This = impl_from_INameSpaceTreeControlEvents(iface);
+
     ok(psi != NULL, "NULL IShellItem\n");
-    NSTCE_IMPL(iface)->count[OnItemClick]++;
+    This->count[OnItemClick]++;
     return E_NOTIMPL;
 }
 
@@ -122,8 +132,10 @@ static HRESULT WINAPI NSTCEvents_fnOnPropertyItemCommit(
     INameSpaceTreeControlEvents* iface,
     IShellItem *psi)
 {
+    INameSpaceTreeControlEventsImpl *This = impl_from_INameSpaceTreeControlEvents(iface);
+
     ok(psi != NULL, "NULL IShellItem\n");
-    NSTCE_IMPL(iface)->count[OnPropertyItemCommit]++;
+    This->count[OnPropertyItemCommit]++;
     return E_NOTIMPL;
 }
 
@@ -133,8 +145,10 @@ static HRESULT WINAPI NSTCEvents_fnOnItemStateChanging(
     NSTCITEMSTATE nstcisMask,
     NSTCITEMSTATE nstcisState)
 {
+    INameSpaceTreeControlEventsImpl *This = impl_from_INameSpaceTreeControlEvents(iface);
+
     ok(psi != NULL, "NULL IShellItem\n");
-    NSTCE_IMPL(iface)->count[OnItemStateChanging]++;
+    This->count[OnItemStateChanging]++;
     return E_NOTIMPL;
 }
 
@@ -144,8 +158,10 @@ static HRESULT WINAPI NSTCEvents_fnOnItemStateChanged(
     NSTCITEMSTATE nstcisMask,
     NSTCITEMSTATE nstcisState)
 {
+    INameSpaceTreeControlEventsImpl *This = impl_from_INameSpaceTreeControlEvents(iface);
+
     ok(psi != NULL, "NULL IShellItem\n");
-    NSTCE_IMPL(iface)->count[OnItemStateChanged]++;
+    This->count[OnItemStateChanged]++;
     return E_NOTIMPL;
 }
 
@@ -153,6 +169,8 @@ static HRESULT WINAPI NSTCEvents_fnOnSelectionChanged(
     INameSpaceTreeControlEvents* iface,
     IShellItemArray *psiaSelection)
 {
+    INameSpaceTreeControlEventsImpl *This = impl_from_INameSpaceTreeControlEvents(iface);
+
     ok(psiaSelection != NULL, "IShellItemArray was NULL.\n");
     if(psiaSelection)
     {
@@ -162,7 +180,7 @@ static HRESULT WINAPI NSTCEvents_fnOnSelectionChanged(
         ok(hr == S_OK, "Got 0x%08x\n", hr);
         ok(count == 1, "Got count 0x%x\n", count);
     }
-    NSTCE_IMPL(iface)->count[OnSelectionChanged]++;
+    This->count[OnSelectionChanged]++;
     return E_NOTIMPL;
 }
 
@@ -172,7 +190,9 @@ static HRESULT WINAPI NSTCEvents_fnOnKeyboardInput(
     WPARAM wParam,
     LPARAM lParam)
 {
-    NSTCE_IMPL(iface)->count[OnKeyboardInput]++;
+    INameSpaceTreeControlEventsImpl *This = impl_from_INameSpaceTreeControlEvents(iface);
+
+    This->count[OnKeyboardInput]++;
     ok(wParam == 0x1234, "Got unexpected wParam %lx\n", wParam);
     ok(lParam == 0x1234, "Got unexpected lParam %lx\n", lParam);
     return E_NOTIMPL;
@@ -182,8 +202,10 @@ static HRESULT WINAPI NSTCEvents_fnOnBeforeExpand(
     INameSpaceTreeControlEvents* iface,
     IShellItem *psi)
 {
+    INameSpaceTreeControlEventsImpl *This = impl_from_INameSpaceTreeControlEvents(iface);
+
     ok(psi != NULL, "NULL IShellItem\n");
-    NSTCE_IMPL(iface)->count[OnBeforeExpand]++;
+    This->count[OnBeforeExpand]++;
     return E_NOTIMPL;
 }
 
@@ -191,8 +213,10 @@ static HRESULT WINAPI NSTCEvents_fnOnAfterExpand(
     INameSpaceTreeControlEvents* iface,
     IShellItem *psi)
 {
+    INameSpaceTreeControlEventsImpl *This = impl_from_INameSpaceTreeControlEvents(iface);
+
     ok(psi != NULL, "NULL IShellItem\n");
-    NSTCE_IMPL(iface)->count[OnAfterExpand]++;
+    This->count[OnAfterExpand]++;
     return E_NOTIMPL;
 }
 
@@ -200,8 +224,10 @@ static HRESULT WINAPI NSTCEvents_fnOnBeginLabelEdit(
     INameSpaceTreeControlEvents* iface,
     IShellItem *psi)
 {
+    INameSpaceTreeControlEventsImpl *This = impl_from_INameSpaceTreeControlEvents(iface);
+
     ok(psi != NULL, "NULL IShellItem\n");
-    NSTCE_IMPL(iface)->count[OnBeginLabelEdit]++;
+    This->count[OnBeginLabelEdit]++;
     return E_NOTIMPL;
 }
 
@@ -209,8 +235,10 @@ static HRESULT WINAPI NSTCEvents_fnOnEndLabelEdit(
     INameSpaceTreeControlEvents* iface,
     IShellItem *psi)
 {
+    INameSpaceTreeControlEventsImpl *This = impl_from_INameSpaceTreeControlEvents(iface);
+
     ok(psi != NULL, "NULL IShellItem\n");
-    NSTCE_IMPL(iface)->count[OnEndLabelEdit]++;
+    This->count[OnEndLabelEdit]++;
     return E_NOTIMPL;
 }
 
@@ -220,8 +248,10 @@ static HRESULT WINAPI NSTCEvents_fnOnGetToolTip(
     LPWSTR pszTip,
     int cchTip)
 {
+    INameSpaceTreeControlEventsImpl *This = impl_from_INameSpaceTreeControlEvents(iface);
+
     ok(psi != NULL, "NULL IShellItem\n");
-    NSTCE_IMPL(iface)->count[OnGetToolTip]++;
+    This->count[OnGetToolTip]++;
     return E_NOTIMPL;
 }
 
@@ -229,8 +259,10 @@ static HRESULT WINAPI NSTCEvents_fnOnBeforeItemDelete(
     INameSpaceTreeControlEvents* iface,
     IShellItem *psi)
 {
+    INameSpaceTreeControlEventsImpl *This = impl_from_INameSpaceTreeControlEvents(iface);
+
     ok(psi != NULL, "NULL IShellItem\n");
-    NSTCE_IMPL(iface)->count[OnBeforeItemDelete]++;
+    This->count[OnBeforeItemDelete]++;
     return E_NOTIMPL;
 }
 
@@ -239,8 +271,10 @@ static HRESULT WINAPI NSTCEvents_fnOnItemAdded(
     IShellItem *psi,
     BOOL fIsRoot)
 {
+    INameSpaceTreeControlEventsImpl *This = impl_from_INameSpaceTreeControlEvents(iface);
+
     ok(psi != NULL, "NULL IShellItem\n");
-    NSTCE_IMPL(iface)->count[OnItemAdded]++;
+    This->count[OnItemAdded]++;
     return S_OK;
 }
 
@@ -249,8 +283,10 @@ static HRESULT WINAPI NSTCEvents_fnOnItemDeleted(
     IShellItem *psi,
     BOOL fIsRoot)
 {
+    INameSpaceTreeControlEventsImpl *This = impl_from_INameSpaceTreeControlEvents(iface);
+
     ok(psi != NULL, "NULL IShellItem\n");
-    NSTCE_IMPL(iface)->count[OnItemDeleted]++;
+    This->count[OnItemDeleted]++;
     return S_OK;
 }
 
@@ -260,7 +296,9 @@ static HRESULT WINAPI NSTCEvents_fnOnBeforeContextMenu(
     REFIID riid,
     void **ppv)
 {
-    NSTCE_IMPL(iface)->count[OnBeforeContextMenu]++;
+    INameSpaceTreeControlEventsImpl *This = impl_from_INameSpaceTreeControlEvents(iface);
+
+    This->count[OnBeforeContextMenu]++;
     return E_NOTIMPL;
 }
 
@@ -271,7 +309,9 @@ static HRESULT WINAPI NSTCEvents_fnOnAfterContextMenu(
     REFIID riid,
     void **ppv)
 {
-    NSTCE_IMPL(iface)->count[OnAfterContextMenu]++;
+    INameSpaceTreeControlEventsImpl *This = impl_from_INameSpaceTreeControlEvents(iface);
+
+    This->count[OnAfterContextMenu]++;
     return E_NOTIMPL;
 }
 
@@ -279,8 +319,10 @@ static HRESULT WINAPI NSTCEvents_fnOnBeforeStateImageChange(
     INameSpaceTreeControlEvents* iface,
     IShellItem *psi)
 {
+    INameSpaceTreeControlEventsImpl *This = impl_from_INameSpaceTreeControlEvents(iface);
+
     ok(psi != NULL, "NULL IShellItem\n");
-    NSTCE_IMPL(iface)->count[OnBeforeStateImageChange]++;
+    This->count[OnBeforeStateImageChange]++;
     return E_NOTIMPL;
 }
 
@@ -290,8 +332,10 @@ static HRESULT WINAPI NSTCEvents_fnOnGetDefaultIconIndex(
     int *piDefaultIcon,
     int *piOpenIcon)
 {
+    INameSpaceTreeControlEventsImpl *This = impl_from_INameSpaceTreeControlEvents(iface);
+
     ok(psi != NULL, "NULL IShellItem\n");
-    NSTCE_IMPL(iface)->count[OnGetDefaultIconIndex]++;
+    This->count[OnGetDefaultIconIndex]++;
     return E_NOTIMPL;
 }
 
@@ -318,13 +362,12 @@ static const INameSpaceTreeControlEventsVtbl vt_NSTCEvents = {
     NSTCEvents_fnOnBeforeStateImageChange,
     NSTCEvents_fnOnGetDefaultIconIndex
 };
-#undef NSTCE_IMPL
 
 static INameSpaceTreeControlEventsImpl *create_nstc_events(void)
 {
     INameSpaceTreeControlEventsImpl *This;
     This = HeapAlloc(GetProcessHeap(), 0, sizeof(INameSpaceTreeControlEventsImpl));
-    This->lpVtbl = &vt_NSTCEvents;
+    This->INameSpaceTreeControlEvents_iface.lpVtbl = &vt_NSTCEvents;
     This->ref = 1;
 
     return This;
@@ -1755,10 +1798,10 @@ static void test_events(void)
 
     /* Create two instances of INameSpaceTreeControlEvents */
     pnstceimpl = create_nstc_events();
-    pnstce = (INameSpaceTreeControlEvents*)pnstceimpl;
+    pnstce = &pnstceimpl->INameSpaceTreeControlEvents_iface;
     ZeroMemory(&pnstceimpl->count, sizeof(UINT)*LastEvent);
     pnstceimpl2 = create_nstc_events();
-    pnstce2 = (INameSpaceTreeControlEvents*)pnstceimpl2;
+    pnstce2 = &pnstceimpl2->INameSpaceTreeControlEvents_iface;
 
     if(0)
     {
-- 
1.7.3.4



More information about the wine-patches mailing list