winejoystick: Fix a crash on accessing a CFArray past its end due to an off-by-one...
[wine/multimedia.git] / dlls / mscoree / tests / debugging.c
blob251579396a9dcf4c639b77fbb79f5edc0bb77562
1 /*
2 * Copyright 2011 Alistair Leslie-Hughes
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #define COBJMACROS
20 #include <stdio.h>
22 #include "windows.h"
23 #include "ole2.h"
24 #include "corerror.h"
25 #include "mscoree.h"
26 #include "corhdr.h"
28 #include "wine/test.h"
30 #include "initguid.h"
31 #include "cordebug.h"
33 static HMODULE hmscoree;
35 static HRESULT (WINAPI *pCreateDebuggingInterfaceFromVersion)(int, LPCWSTR, IUnknown **);
37 const WCHAR v2_0[] = {'v','2','.','0','.','5','0','7','2','7',0};
39 static HRESULT WINAPI ManagedCallback2_QueryInterface(ICorDebugManagedCallback2 *iface, REFIID riid, void **ppv)
41 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_ICorDebugManagedCallback2, riid))
43 *ppv = iface;
44 return S_OK;
47 ok(0, "unexpected riid %s\n", wine_dbgstr_guid(riid));
49 *ppv = NULL;
50 return E_NOINTERFACE;
53 static ULONG WINAPI ManagedCallback2_AddRef(ICorDebugManagedCallback2 *iface)
55 return 2;
58 static ULONG WINAPI ManagedCallback2_Release(ICorDebugManagedCallback2 *iface)
60 return 1;
63 static HRESULT WINAPI ManagedCallback2_FunctionRemapOpportunity(ICorDebugManagedCallback2 *iface,
64 ICorDebugAppDomain *pAppDomain, ICorDebugThread *pThread,
65 ICorDebugFunction *pOldFunction, ICorDebugFunction *pNewFunction,
66 ULONG32 oldILOffset)
68 ok(0, "unexpected call\n");
69 return E_NOTIMPL;
72 static HRESULT WINAPI ManagedCallback2_CreateConnection(ICorDebugManagedCallback2 *iface,
73 ICorDebugProcess *pProcess, CONNID dwConnectionId, WCHAR *pConnName)
75 ok(0, "unexpected call\n");
76 return E_NOTIMPL;
79 static HRESULT WINAPI ManagedCallback2_ChangeConnection(ICorDebugManagedCallback2 *iface,
80 ICorDebugProcess *pProcess, CONNID dwConnectionId)
82 ok(0, "unexpected call\n");
83 return E_NOTIMPL;
86 static HRESULT WINAPI ManagedCallback2_DestroyConnection(ICorDebugManagedCallback2 *iface,
87 ICorDebugProcess *pProcess, CONNID dwConnectionId)
89 ok(0, "unexpected call\n");
90 return E_NOTIMPL;
93 static HRESULT WINAPI ManagedCallback2_Exception(ICorDebugManagedCallback2 *iface,
94 ICorDebugAppDomain *pAppDomain, ICorDebugThread *pThread,
95 ICorDebugFrame *pFrame, ULONG32 nOffset,
96 CorDebugExceptionCallbackType dwEventType, DWORD dwFlags)
98 ok(0, "unexpected call\n");
99 return E_NOTIMPL;
102 static HRESULT WINAPI ManagedCallback2_ExceptionUnwind(ICorDebugManagedCallback2 *iface,
103 ICorDebugAppDomain *pAppDomain, ICorDebugThread *pThread,
104 CorDebugExceptionUnwindCallbackType dwEventType, DWORD dwFlags)
106 ok(0, "unexpected call\n");
107 return E_NOTIMPL;
110 static HRESULT WINAPI ManagedCallback2_FunctionRemapComplete(ICorDebugManagedCallback2 *iface,
111 ICorDebugAppDomain *pAppDomain, ICorDebugThread *pThread,
112 ICorDebugFunction *pFunction)
114 ok(0, "unexpected call\n");
115 return E_NOTIMPL;
118 static HRESULT WINAPI ManagedCallback2_MDANotification(ICorDebugManagedCallback2 *iface,
119 ICorDebugController *pController, ICorDebugThread *pThread,
120 ICorDebugMDA *pMDA)
122 ok(0, "unexpected call\n");
123 return E_NOTIMPL;
126 static struct ICorDebugManagedCallback2Vtbl managedCallback2Vtbl = {
127 ManagedCallback2_QueryInterface,
128 ManagedCallback2_AddRef,
129 ManagedCallback2_Release,
130 ManagedCallback2_FunctionRemapOpportunity,
131 ManagedCallback2_CreateConnection,
132 ManagedCallback2_ChangeConnection,
133 ManagedCallback2_DestroyConnection,
134 ManagedCallback2_Exception,
135 ManagedCallback2_ExceptionUnwind,
136 ManagedCallback2_FunctionRemapComplete,
137 ManagedCallback2_MDANotification
140 static ICorDebugManagedCallback2 ManagedCallback2 = { &managedCallback2Vtbl };
142 static HRESULT WINAPI ManagedCallback_QueryInterface(ICorDebugManagedCallback *iface, REFIID riid, void **ppv)
144 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_ICorDebugManagedCallback, riid))
146 *ppv = iface;
147 return S_OK;
149 else if(IsEqualGUID(&IID_ICorDebugManagedCallback2, riid))
151 *ppv = (void**)&ManagedCallback2;
152 return S_OK;
155 ok(0, "unexpected riid %s\n", wine_dbgstr_guid(riid));
156 *ppv = NULL;
157 return E_NOINTERFACE;
160 static ULONG WINAPI ManagedCallback_AddRef(ICorDebugManagedCallback *iface)
162 return 2;
165 static ULONG WINAPI ManagedCallback_Release(ICorDebugManagedCallback *iface)
167 return 1;
170 static HRESULT WINAPI ManagedCallback_Breakpoint(ICorDebugManagedCallback *iface, ICorDebugAppDomain *pAppDomain,
171 ICorDebugThread *pThread, ICorDebugBreakpoint *pBreakpoint)
173 ok(0, "unexpected call\n");
174 return E_NOTIMPL;
177 static HRESULT WINAPI ManagedCallback_StepComplete(ICorDebugManagedCallback *iface, ICorDebugAppDomain *pAppDomain,
178 ICorDebugThread *pThread, ICorDebugStepper *pStepper, CorDebugStepReason reason)
180 ok(0, "unexpected call\n");
181 return E_NOTIMPL;
184 static HRESULT WINAPI ManagedCallback_Break(ICorDebugManagedCallback *iface, ICorDebugAppDomain *pAppDomain,
185 ICorDebugThread *thread)
187 ok(0, "unexpected call\n");
188 return E_NOTIMPL;
191 static HRESULT WINAPI ManagedCallback_Exception(ICorDebugManagedCallback *iface, ICorDebugAppDomain *pAppDomain,
192 ICorDebugThread *pThread, BOOL unhandled)
194 ok(0, "unexpected call\n");
195 return E_NOTIMPL;
198 static HRESULT WINAPI ManagedCallback_EvalComplete(ICorDebugManagedCallback *iface, ICorDebugAppDomain *pAppDomain,
199 ICorDebugThread *pThread, ICorDebugEval *pEval)
201 ok(0, "unexpected call\n");
202 return E_NOTIMPL;
205 static HRESULT WINAPI ManagedCallback_EvalException(ICorDebugManagedCallback *iface, ICorDebugAppDomain *pAppDomain,
206 ICorDebugThread *pThread, ICorDebugEval *pEval)
208 ok(0, "unexpected call\n");
209 return E_NOTIMPL;
212 static HRESULT WINAPI ManagedCallback_CreateProcess(ICorDebugManagedCallback *iface, ICorDebugProcess *pProcess)
214 ok(0, "unexpected call\n");
215 return E_NOTIMPL;
218 static HRESULT WINAPI ManagedCallback_ExitProcess(ICorDebugManagedCallback *iface, ICorDebugProcess *pProcess)
220 ok(0, "unexpected call\n");
221 return E_NOTIMPL;
224 static HRESULT WINAPI ManagedCallback_CreateThread(ICorDebugManagedCallback *iface, ICorDebugAppDomain *pAppDomain,
225 ICorDebugThread *thread)
227 ok(0, "unexpected call\n");
228 return E_NOTIMPL;
231 static HRESULT WINAPI ManagedCallback_ExitThread(ICorDebugManagedCallback *iface, ICorDebugAppDomain *pAppDomain,
232 ICorDebugThread *thread)
234 ok(0, "unexpected call\n");
235 return E_NOTIMPL;
238 static HRESULT WINAPI ManagedCallback_LoadModule(ICorDebugManagedCallback *iface, ICorDebugAppDomain *pAppDomain,
239 ICorDebugModule *pModule)
241 ok(0, "unexpected call\n");
242 return E_NOTIMPL;
245 static HRESULT WINAPI ManagedCallback_UnloadModule(ICorDebugManagedCallback *iface, ICorDebugAppDomain *pAppDomain,
246 ICorDebugModule *pModule)
248 ok(0, "unexpected call\n");
249 return E_NOTIMPL;
252 static HRESULT WINAPI ManagedCallback_LoadClass(ICorDebugManagedCallback *iface, ICorDebugAppDomain *pAppDomain,
253 ICorDebugClass *c)
255 ok(0, "unexpected call\n");
256 return E_NOTIMPL;
259 static HRESULT WINAPI ManagedCallback_UnloadClass(ICorDebugManagedCallback *iface, ICorDebugAppDomain *pAppDomain,
260 ICorDebugClass *c)
262 ok(0, "unexpected call\n");
263 return E_NOTIMPL;
266 static HRESULT WINAPI ManagedCallback_DebuggerError(ICorDebugManagedCallback *iface, ICorDebugProcess *pProcess,
267 HRESULT errorHR, DWORD errorCode)
269 ok(0, "unexpected call\n");
270 return E_NOTIMPL;
273 static HRESULT WINAPI ManagedCallback_LogMessage(ICorDebugManagedCallback *iface, ICorDebugAppDomain *pAppDomain,
274 ICorDebugThread *pThread, LONG lLevel, WCHAR *pLogSwitchName, WCHAR *pMessage)
276 ok(0, "unexpected call\n");
277 return E_NOTIMPL;
280 static HRESULT WINAPI ManagedCallback_LogSwitch(ICorDebugManagedCallback *iface, ICorDebugAppDomain *pAppDomain,
281 ICorDebugThread *pThread, LONG lLevel, ULONG ulReason,
282 WCHAR *pLogSwitchName, WCHAR *pParentName)
284 ok(0, "unexpected call\n");
285 return E_NOTIMPL;
288 static HRESULT WINAPI ManagedCallback_CreateAppDomain(ICorDebugManagedCallback *iface, ICorDebugProcess *pProcess,
289 ICorDebugAppDomain *pAppDomain)
291 ok(0, "unexpected call\n");
292 return E_NOTIMPL;
295 static HRESULT WINAPI ManagedCallback_ExitAppDomain(ICorDebugManagedCallback *iface, ICorDebugProcess *pProcess,
296 ICorDebugAppDomain *pAppDomain)
298 ok(0, "unexpected call\n");
299 return E_NOTIMPL;
302 static HRESULT WINAPI ManagedCallback_LoadAssembly(ICorDebugManagedCallback *iface, ICorDebugAppDomain *pAppDomain,
303 ICorDebugAssembly *pAssembly)
305 ok(0, "unexpected call\n");
306 return E_NOTIMPL;
309 static HRESULT WINAPI ManagedCallback_UnloadAssembly(ICorDebugManagedCallback *iface, ICorDebugAppDomain *pAppDomain,
310 ICorDebugAssembly *pAssembly)
312 ok(0, "unexpected call\n");
313 return E_NOTIMPL;
316 static HRESULT WINAPI ManagedCallback_ControlCTrap(ICorDebugManagedCallback *iface, ICorDebugProcess *pProcess)
318 ok(0, "unexpected call\n");
319 return E_NOTIMPL;
322 static HRESULT WINAPI ManagedCallback_NameChange(ICorDebugManagedCallback *iface, ICorDebugAppDomain *pAppDomain,
323 ICorDebugThread *pThread)
325 ok(0, "unexpected call\n");
326 return E_NOTIMPL;
329 static HRESULT WINAPI ManagedCallback_UpdateModuleSymbols(ICorDebugManagedCallback *iface, ICorDebugAppDomain *pAppDomain,
330 ICorDebugModule *pModule, IStream *pSymbolStream)
332 ok(0, "unexpected call\n");
333 return E_NOTIMPL;
336 static HRESULT WINAPI ManagedCallback_EditAndContinueRemap(ICorDebugManagedCallback *iface, ICorDebugAppDomain *pAppDomain,
337 ICorDebugThread *pThread, ICorDebugFunction *pFunction, BOOL fAccurate)
339 ok(0, "unexpected call\n");
340 return E_NOTIMPL;
343 static HRESULT WINAPI ManagedCallback_BreakpointSetError(ICorDebugManagedCallback *iface, ICorDebugAppDomain *pAppDomain,
344 ICorDebugThread *pThread, ICorDebugBreakpoint *pBreakpoint, DWORD dwError)
346 ok(0, "unexpected call\n");
347 return E_NOTIMPL;
350 static ICorDebugManagedCallbackVtbl managedCallbackVtbl = {
351 ManagedCallback_QueryInterface,
352 ManagedCallback_AddRef,
353 ManagedCallback_Release,
354 ManagedCallback_Breakpoint,
355 ManagedCallback_StepComplete,
356 ManagedCallback_Break,
357 ManagedCallback_Exception,
358 ManagedCallback_EvalComplete,
359 ManagedCallback_EvalException,
360 ManagedCallback_CreateProcess,
361 ManagedCallback_ExitProcess,
362 ManagedCallback_CreateThread,
363 ManagedCallback_ExitThread,
364 ManagedCallback_LoadModule,
365 ManagedCallback_UnloadModule,
366 ManagedCallback_LoadClass,
367 ManagedCallback_UnloadClass,
368 ManagedCallback_DebuggerError,
369 ManagedCallback_LogMessage,
370 ManagedCallback_LogSwitch,
371 ManagedCallback_CreateAppDomain,
372 ManagedCallback_ExitAppDomain,
373 ManagedCallback_LoadAssembly,
374 ManagedCallback_UnloadAssembly,
375 ManagedCallback_ControlCTrap,
376 ManagedCallback_NameChange,
377 ManagedCallback_UpdateModuleSymbols,
378 ManagedCallback_EditAndContinueRemap,
379 ManagedCallback_BreakpointSetError
382 static ICorDebugManagedCallback ManagedCallback = { &managedCallbackVtbl };
384 static BOOL init_functionpointers(void)
386 hmscoree = LoadLibraryA("mscoree.dll");
388 if (!hmscoree)
390 win_skip("mscoree.dll not available\n");
391 return FALSE;
394 pCreateDebuggingInterfaceFromVersion = (void *)GetProcAddress(hmscoree, "CreateDebuggingInterfaceFromVersion");
396 if (!pCreateDebuggingInterfaceFromVersion)
398 win_skip("functions not available\n");
399 FreeLibrary(hmscoree);
400 return FALSE;
403 return TRUE;
406 #define check_process_enum(core, e) _check_process_enum(__LINE__, core, e)
407 static void _check_process_enum(unsigned line, ICorDebug *pCorDebug, ULONG nExpected)
409 HRESULT hr;
410 ICorDebugProcessEnum *pProcessEnum = NULL;
412 hr = ICorDebug_EnumerateProcesses(pCorDebug, NULL);
413 ok_(__FILE__,line) (hr == E_INVALIDARG, "expected E_INVALIDARG got %08x\n", hr);
415 hr = ICorDebug_EnumerateProcesses(pCorDebug, &pProcessEnum);
416 ok_(__FILE__,line) (hr == S_OK, "expected S_OK got %08x\n", hr);
417 if(hr == S_OK)
419 ULONG cnt;
421 hr = ICorDebugProcessEnum_GetCount(pProcessEnum, &cnt);
422 ok_(__FILE__,line) (hr == S_OK, "expected S_OK got %08x\n", hr);
423 ok_(__FILE__,line) (cnt == nExpected, "expected %d got %d\n", nExpected, cnt);
425 ICorDebugProcessEnum_Release(pProcessEnum);
429 static void test_createDebugger(void)
431 HRESULT hr;
432 IUnknown *pUnk;
433 ICorDebug *pCorDebug;
435 hr = pCreateDebuggingInterfaceFromVersion(0, v2_0, &pUnk);
436 ok(hr == E_INVALIDARG, "CreateDebuggingInterfaceFromVersion returned %08x\n", hr);
438 hr = pCreateDebuggingInterfaceFromVersion(1, v2_0, &pUnk);
439 ok(hr == E_INVALIDARG, "CreateDebuggingInterfaceFromVersion returned %08x\n", hr);
441 hr = pCreateDebuggingInterfaceFromVersion(2, v2_0, &pUnk);
442 ok(hr == E_INVALIDARG, "CreateDebuggingInterfaceFromVersion returned %08x\n", hr);
444 hr = pCreateDebuggingInterfaceFromVersion(4, v2_0, &pUnk);
445 ok(hr == E_INVALIDARG, "CreateDebuggingInterfaceFromVersion returned %08x\n", hr);
447 hr = pCreateDebuggingInterfaceFromVersion(3, v2_0, NULL);
448 ok(hr == E_INVALIDARG, "CreateDebuggingInterfaceFromVersion returned %08x\n", hr);
450 hr = pCreateDebuggingInterfaceFromVersion(3, v2_0, &pUnk);
451 if(hr == S_OK)
453 hr = IUnknown_QueryInterface(pUnk, &IID_ICorDebug, (void**)&pCorDebug);
454 ok(hr == S_OK, "expected S_OK got %08x\n", hr);
455 if(hr == S_OK)
457 hr = ICorDebug_Initialize(pCorDebug);
458 ok(hr == S_OK, "expected S_OK got %08x\n", hr);
459 if(hr == S_OK)
461 hr = ICorDebug_SetManagedHandler(pCorDebug, NULL);
462 ok(hr == E_INVALIDARG, "expected E_INVALIDARG got %08x\n", hr);
464 hr = ICorDebug_SetManagedHandler(pCorDebug, &ManagedCallback);
465 ok(hr == S_OK, "expected S_OK got %08x\n", hr);
467 /* We should have no processes */
468 check_process_enum(pCorDebug, 0);
471 ICorDebug_Release(pCorDebug);
473 IUnknown_Release(pUnk);
475 else
477 skip(".NET 2.0 or mono not installed.\n");
481 START_TEST(debugging)
483 CoInitialize(NULL);
485 if (!init_functionpointers())
486 return;
488 test_createDebugger();
490 FreeLibrary(hmscoree);
491 CoUninitialize();