From 324783ad09bf766097f8602c09b74f33113fb780 Mon Sep 17 00:00:00 2001 From: Detlef Riekenberg Date: Mon, 19 Apr 2010 00:45:18 +0200 Subject: [PATCH] shlwapi/tests: Add tests for SHSetThreadRef. --- dlls/shlwapi/tests/thread.c | 76 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/dlls/shlwapi/tests/thread.c b/dlls/shlwapi/tests/thread.c index b34560422a9..90e87f52014 100644 --- a/dlls/shlwapi/tests/thread.c +++ b/dlls/shlwapi/tests/thread.c @@ -30,6 +30,48 @@ #include "wine/test.h" static HRESULT (WINAPI *pSHGetThreadRef)(IUnknown**); +static HRESULT (WINAPI *pSHSetThreadRef)(IUnknown*); + +static DWORD AddRef_called; + +typedef struct +{ + void* lpVtbl; + LONG *ref; +} threadref; + +static HRESULT WINAPI threadref_QueryInterface(threadref *This, REFIID riid, LPVOID *ppvObj) +{ + trace("unexpected QueryInterface(%p, %p, %p) called\n", This, riid, ppvObj); + *ppvObj = NULL; + return E_NOINTERFACE; +} + +static ULONG WINAPI threadref_AddRef(threadref *This) +{ + AddRef_called++; + return InterlockedIncrement(This->ref); +} + +static ULONG WINAPI threadref_Release(threadref *This) +{ + trace("unexpected Release(%p) called\n", This); + return InterlockedDecrement(This->ref); +} + +/* VTable */ +static void* threadref_vt[] = +{ + threadref_QueryInterface, + threadref_AddRef, + threadref_Release +}; + +static void init_threadref(threadref* iface, LONG *refcount) +{ + iface->lpVtbl = (void*)threadref_vt; + iface->ref = refcount; +} /* ##### */ @@ -55,12 +97,46 @@ static void test_SHGetThreadRef(void) } } +static void test_SHSetThreadRef(void) +{ + threadref ref; + IUnknown *punk; + HRESULT hr; + LONG refcount; + + /* Not present before IE 5 */ + if (!pSHSetThreadRef) { + win_skip("SHSetThreadRef not found\n"); + return; + } + + init_threadref(&ref, &refcount); + AddRef_called = 0; + refcount = 1; + hr = pSHSetThreadRef( (IUnknown *)&ref); + ok( (hr == S_OK) && (refcount == 1) && (!AddRef_called), + "got 0x%x with %d, %d (expected S_OK with 1, 0)\n", + hr, refcount, AddRef_called); + + /* Read back IUnkonwn */ + AddRef_called = 0; + refcount = 1; + punk = NULL; + hr = pSHGetThreadRef(&punk); + ok( (hr == S_OK) && (punk == (IUnknown *)&ref) && (refcount == 2) && (AddRef_called == 1), + "got 0x%x and %p with %d, %d (expected S_OK and %p with 2, 1)\n", + hr, punk, refcount, AddRef_called, &ref); + +} + START_TEST(thread) { HMODULE hshlwapi = GetModuleHandleA("shlwapi.dll"); pSHGetThreadRef = (void *) GetProcAddress(hshlwapi, "SHGetThreadRef"); + pSHSetThreadRef = (void *) GetProcAddress(hshlwapi, "SHSetThreadRef"); test_SHGetThreadRef(); + test_SHSetThreadRef(); } -- 2.11.4.GIT