ReactOS  0.4.13-dev-651-g5dbc677
initializespy.cpp File Reference
#include <stdio.h>
#include <wine/test.h>
#include <winuser.h>
#include <winreg.h>
#include <shlwapi.h>
#include <unknownbase.h>
Include dependency graph for initializespy.cpp:

Go to the source code of this file.

Classes

class  CTestSpy
 

Macros

#define WIN32_NO_STATUS
 
#define _INC_WINDOWS
 
#define COM_NO_WINDOWS_H
 
#define test_S_OK(hres, message)   ok((hres) == S_OK, "%s (0x%lx instead of S_OK)\n", (message), (hres))
 
#define test_HRES(hres, hresExpected, message)   ok((hres) == (hresExpected), "%s (0x%lx instead of 0x%lx)\n", (message), (hres), (hresExpected))
 
#define test_ref(spy, expectedRef)   ok((spy)->GetRef() == (expectedRef), "unexpected refcount, %ld instead of %d\n", (spy)->GetRef(), (expectedRef))
 

Typedefs

typedef HRESULT(WINAPIpCoRegisterInitializeSpy_t) (_In_ LPINITIALIZESPY pSpy, _Out_ ULARGE_INTEGER *puliCookie)
 
typedef HRESULT(WINAPIpCoRevokeInitializeSpy_t) (_In_ ULARGE_INTEGER uliCookie)
 

Functions

void test_IInitializeSpy_register2 ()
 
void test_IInitializeSpy_switch_apt ()
 
void test_IInitializeSpy_fail ()
 
void test_IInitializeSpy_twice ()
 
 START_TEST (initializespy)
 

Variables

pCoRegisterInitializeSpy_t pCoRegisterInitializeSpy
 
pCoRevokeInitializeSpy_t pCoRevokeInitializeSpy
 
const DWORD INVALID_VALUE = 0xdeadbeef
 

Macro Definition Documentation

◆ _INC_WINDOWS

#define _INC_WINDOWS

Definition at line 9 of file initializespy.cpp.

◆ COM_NO_WINDOWS_H

#define COM_NO_WINDOWS_H

Definition at line 10 of file initializespy.cpp.

◆ test_HRES

#define test_HRES (   hres,
  hresExpected,
  message 
)    ok((hres) == (hresExpected), "%s (0x%lx instead of 0x%lx)\n", (message), (hres), (hresExpected))

Definition at line 22 of file initializespy.cpp.

◆ test_ref

#define test_ref (   spy,
  expectedRef 
)    ok((spy)->GetRef() == (expectedRef), "unexpected refcount, %ld instead of %d\n", (spy)->GetRef(), (expectedRef))

Definition at line 23 of file initializespy.cpp.

◆ test_S_OK

#define test_S_OK (   hres,
  message 
)    ok((hres) == S_OK, "%s (0x%lx instead of S_OK)\n", (message), (hres))

Definition at line 21 of file initializespy.cpp.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 8 of file initializespy.cpp.

Typedef Documentation

◆ pCoRegisterInitializeSpy_t

typedef HRESULT(WINAPI * pCoRegisterInitializeSpy_t) (_In_ LPINITIALIZESPY pSpy, _Out_ ULARGE_INTEGER *puliCookie)

Definition at line 26 of file initializespy.cpp.

◆ pCoRevokeInitializeSpy_t

typedef HRESULT(WINAPI * pCoRevokeInitializeSpy_t) (_In_ ULARGE_INTEGER uliCookie)

Definition at line 27 of file initializespy.cpp.

Function Documentation

◆ START_TEST()

START_TEST ( initializespy  )

Definition at line 311 of file initializespy.cpp.

312 {
313  HMODULE ole32 = LoadLibraryA("ole32.dll");
314  pCoRegisterInitializeSpy = (pCoRegisterInitializeSpy_t)GetProcAddress(ole32, "CoRegisterInitializeSpy");
315  pCoRevokeInitializeSpy = (pCoRevokeInitializeSpy_t)GetProcAddress(ole32, "CoRevokeInitializeSpy");
316 
321 }
HRESULT(WINAPI * pCoRegisterInitializeSpy_t)(_In_ LPINITIALIZESPY pSpy, _Out_ ULARGE_INTEGER *puliCookie)
void test_IInitializeSpy_twice()
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
HRESULT(WINAPI * pCoRevokeInitializeSpy_t)(_In_ ULARGE_INTEGER uliCookie)
void test_IInitializeSpy_switch_apt()
pCoRegisterInitializeSpy_t pCoRegisterInitializeSpy
void test_IInitializeSpy_register2()
#define GetProcAddress(x, y)
Definition: compat.h:410
pCoRevokeInitializeSpy_t pCoRevokeInitializeSpy
void test_IInitializeSpy_fail()

◆ test_IInitializeSpy_fail()

void test_IInitializeSpy_fail ( )

Definition at line 260 of file initializespy.cpp.

261 {
262  CTestSpy spy;
263 
264  spy.m_FailQueryInterface = true;
265 
266  spy.hr = pCoRegisterInitializeSpy(&spy, &spy.Cookie);
267  test_HRES(spy.hr, E_NOINTERFACE, "Unexpected hr while registering invalid interface");
268  test_ref(&spy, 0);
269  ok(spy.Cookie.HighPart == 0xffffffff, "Unexpected Cookie.HighPart, expected 0xffffffff got: 0x%08lx\n", spy.Cookie.HighPart);
270  ok(spy.Cookie.LowPart == 0xffffffff, "Unexpected Cookie.HighPart, expected 0xffffffff got: 0x%08lx\n", spy.Cookie.LowPart);
271 
272  spy.Cookie.HighPart = spy.Cookie.LowPart = 0xffffffff;
274  test_HRES(hr, E_INVALIDARG, "Unexpected hr while unregistering invalid interface");
275  test_ref(&spy, 0);
276 
277  spy.Cookie.HighPart = spy.Cookie.LowPart = 0;
279  test_HRES(hr, E_INVALIDARG, "Unexpected hr while unregistering invalid interface");
280  test_ref(&spy, 0);
281 
282  /* we should not crash here, just return E_NOINTERFACE
283  do note the Cookie is not even being touched at all, compared to calling this with an interface
284  that does not respond to IID_IInitializeSpy */
287  test_HRES(spy.hr, E_NOINTERFACE, "Unexpected hr while registering NULL interface");
288  ok(spy.Cookie.HighPart == INVALID_VALUE, "Unexpected Cookie.HighPart, expected 0xdeadbeef got: %lx\n", spy.Cookie.HighPart);
289  ok(spy.Cookie.LowPart == INVALID_VALUE, "Unexpected Cookie.HighPart, expected 0xdeadbeef got: %lx\n", spy.Cookie.LowPart);
290 }
#define E_NOINTERFACE
Definition: winerror.h:2364
HRESULT hr
Definition: shlfolder.c:183
#define test_HRES(hres, hresExpected, message)
$ULONG LowPart
Definition: ntbasedef.h:576
ULARGE_INTEGER Cookie
#define ok(value,...)
#define E_INVALIDARG
Definition: ddrawi.h:101
smooth NULL
Definition: ftsmooth.c:416
bool m_FailQueryInterface
#define test_ref(spy, expectedRef)
$ULONG HighPart
Definition: ntbasedef.h:577
const DWORD INVALID_VALUE
LONG HRESULT
Definition: typedefs.h:77
pCoRegisterInitializeSpy_t pCoRegisterInitializeSpy
pCoRevokeInitializeSpy_t pCoRevokeInitializeSpy
HRESULT hr

Referenced by START_TEST().

◆ test_IInitializeSpy_register2()

void test_IInitializeSpy_register2 ( )

Definition at line 159 of file initializespy.cpp.

160 {
161  CTestSpy spy, spy2;
162 
163  // first we register 2 spies
164  spy.hr = pCoRegisterInitializeSpy(&spy, &spy.Cookie);
165  test_S_OK(spy.hr, "CoRegisterInitializeSpy");
166  test_ref(&spy, 1);
167 
168  spy2.hr = pCoRegisterInitializeSpy(&spy2, &spy2.Cookie);
169  test_S_OK(spy2.hr, "CoRegisterInitializeSpy");
170  test_ref(&spy, 1);
171 
172  // tell them what we expect
175 
176  // Call CoInitializeEx and validate the results
178  test_S_OK(hr, "CoInitializeEx");
179  spy.Check(1, 1, 0, 0);
180  spy2.Check(1, 1, 0, 0);
181 
182  // Calling CoInit twice with the same apartment makes it return S_FALSE but still increment count
185 
187  test_HRES(hr, S_FALSE, "CoInitializeEx");
188  spy.Check(2, 2, 0, 0);
189  spy2.Check(2, 2, 0, 0);
190 
191  /* the order we registered the spies in is important here.
192  we have the second one to forcibly return S_OK, which makes the first spy see
193  S_OK instead of S_FALSE.. */
195  spy2.m_AlwaysReturnOK = true;
197 
198  // and the S_OK also influences the returned value from CoInit.
200  test_S_OK(hr, "CoInitializeEx");
201  spy.Check(3, 3, 0, 0);
202  spy2.Check(3, 3, 0, 0);
203 
204  CoUninitialize();
205  spy.Check(3, 3, 1, 1);
206  spy2.Check(3, 3, 1, 1);
207 
208  spy.m_CurAptRefs = spy2.m_CurAptRefs = 2;
209 
210  CoUninitialize();
211  spy.Check(3, 3, 2, 2);
212  spy2.Check(3, 3, 2, 2);
213 
214  spy.m_CurAptRefs = spy2.m_CurAptRefs = 1;
215 
216  CoUninitialize();
217  spy.Check(3, 3, 3, 3);
218  spy2.Check(3, 3, 3, 3);
219 
220  spy.m_CurAptRefs = spy2.m_CurAptRefs = 0;
221 
222  CoUninitialize();
223  spy.Check(3, 3, 4, 4);
224  spy2.Check(3, 3, 4, 4);
225 }
#define test_S_OK(hres, message)
HRESULT hr
Definition: shlfolder.c:183
#define test_HRES(hres, hresExpected, message)
ULARGE_INTEGER Cookie
#define S_FALSE
Definition: winerror.h:2357
smooth NULL
Definition: ftsmooth.c:416
#define test_ref(spy, expectedRef)
LONG HRESULT
Definition: typedefs.h:77
pCoRegisterInitializeSpy_t pCoRegisterInitializeSpy
#define S_OK
Definition: intsafe.h:59
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: compobj.c:1991
void Check(LONG PreInit, LONG PostInit, LONG PreUninit, LONG PostUninit)
HRESULT WINAPI DECLSPEC_HOTPATCH CoInitializeEx(LPVOID lpReserved, DWORD dwCoInit)
Definition: compobj.c:1935
HRESULT hr
void Expect(HRESULT hrCoInit, DWORD CoInit, DWORD CurAptRefs)
bool m_AlwaysReturnOK
DWORD m_CurAptRefs

Referenced by START_TEST().

◆ test_IInitializeSpy_switch_apt()

void test_IInitializeSpy_switch_apt ( )

Definition at line 227 of file initializespy.cpp.

228 {
229  CTestSpy spy;
230 
231  spy.hr = pCoRegisterInitializeSpy(&spy, &spy.Cookie);
232  test_S_OK(spy.hr, "CoRegisterInitializeSpy");
233  test_ref(&spy, 1);
234 
236 
238  test_S_OK(hr, "CoInitializeEx");
239  spy.Check(1, 1, 0, 0);
240 
242 
244  test_HRES(hr, RPC_E_CHANGED_MODE, "CoInitializeEx");
245  spy.Check(2, 2, 0, 0);
246 
247 
248  CoUninitialize();
249  spy.Check(2, 2, 1, 1);
250 
251  spy.m_CurAptRefs = 0;
252 
253  CoUninitialize();
254  spy.Check(2, 2, 2, 2);
255 
256  CoUninitialize();
257  spy.Check(2, 2, 3, 3);
258 }
#define test_S_OK(hres, message)
HRESULT hr
Definition: shlfolder.c:183
#define test_HRES(hres, hresExpected, message)
ULARGE_INTEGER Cookie
smooth NULL
Definition: ftsmooth.c:416
#define test_ref(spy, expectedRef)
LONG HRESULT
Definition: typedefs.h:77
#define RPC_E_CHANGED_MODE
Definition: winerror.h:2482
pCoRegisterInitializeSpy_t pCoRegisterInitializeSpy
#define S_OK
Definition: intsafe.h:59
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: compobj.c:1991
void Check(LONG PreInit, LONG PostInit, LONG PreUninit, LONG PostUninit)
HRESULT WINAPI DECLSPEC_HOTPATCH CoInitializeEx(LPVOID lpReserved, DWORD dwCoInit)
Definition: compobj.c:1935
HRESULT hr
void Expect(HRESULT hrCoInit, DWORD CoInit, DWORD CurAptRefs)
DWORD m_CurAptRefs

Referenced by START_TEST().

◆ test_IInitializeSpy_twice()

void test_IInitializeSpy_twice ( )

Definition at line 292 of file initializespy.cpp.

293 {
294  CTestSpy spy;
295 
296  spy.hr = pCoRegisterInitializeSpy(&spy, &spy.Cookie);
297  test_S_OK(spy.hr, "CoRegisterInitializeSpy");
298  test_ref(&spy, 1);
299 
302  test_S_OK(hr, "CoRegisterInitializeSpy");
303  test_ref(&spy, 2);
304 
306  test_S_OK(hr, "CoRevokeInitializeSpy");
307  test_ref(&spy, 1);
308 }
#define test_S_OK(hres, message)
HRESULT hr
Definition: shlfolder.c:183
ULARGE_INTEGER Cookie
#define test_ref(spy, expectedRef)
const DWORD INVALID_VALUE
LONG HRESULT
Definition: typedefs.h:77
_In_opt_ PVOID _Out_ PLARGE_INTEGER Cookie
Definition: cmfuncs.h:13
pCoRegisterInitializeSpy_t pCoRegisterInitializeSpy
pCoRevokeInitializeSpy_t pCoRevokeInitializeSpy
HRESULT hr

Referenced by START_TEST().

Variable Documentation

◆ INVALID_VALUE

const DWORD INVALID_VALUE = 0xdeadbeef

◆ pCoRegisterInitializeSpy

◆ pCoRevokeInitializeSpy