winejoystick: Fix a crash on accessing a CFArray past its end due to an off-by-one...
[wine/multimedia.git] / dlls / mscoree / tests / metahost.c
blob5a8b3e09272b7e2dfd035d28c9f41331732e2089
1 /*
2 * Copyright 2010 Vincent Povirk
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
21 #include <stdarg.h>
23 #include "windef.h"
24 #include "ole2.h"
26 #include "corerror.h"
27 #include "ocidl.h"
28 #include "initguid.h"
29 #include "metahost.h"
30 #include "wine/test.h"
32 static HMODULE hmscoree;
34 static HRESULT (WINAPI *pCLRCreateInstance)(REFCLSID clsid, REFIID riid, LPVOID *ppInterface);
36 static ICLRMetaHost *metahost;
38 static BOOL init_pointers(void)
40 HRESULT hr = E_FAIL;
42 hmscoree = LoadLibraryA("mscoree.dll");
44 if (hmscoree)
45 pCLRCreateInstance = (void *)GetProcAddress(hmscoree, "CLRCreateInstance");
47 if (pCLRCreateInstance)
48 hr = pCLRCreateInstance(&CLSID_CLRMetaHost, &IID_ICLRMetaHost, (void**)&metahost);
50 if (FAILED(hr))
52 win_skip(".NET 4 is not installed\n");
53 FreeLibrary(hmscoree);
54 return FALSE;
57 return TRUE;
60 static void cleanup(void)
62 ICLRMetaHost_Release(metahost);
64 FreeLibrary(hmscoree);
67 static WCHAR *strrchrW( WCHAR *str, WCHAR ch )
69 WCHAR *ret = NULL;
70 do { if (*str == ch) ret = str; } while (*str++);
71 return ret;
74 static void test_getruntime(WCHAR *version)
76 static const WCHAR dotzero[] = {'.','0',0};
77 WCHAR *dot;
78 HRESULT hr;
79 ICLRRuntimeInfo *info;
80 DWORD count;
81 WCHAR buf[MAX_PATH];
83 hr = ICLRMetaHost_GetRuntime(metahost, NULL, &IID_ICLRRuntimeInfo, (void**)&info);
84 ok(hr == E_POINTER, "GetVersion failed, hr=%x\n", hr);
86 hr = ICLRMetaHost_GetRuntime(metahost, version, &IID_ICLRRuntimeInfo, (void**)&info);
87 ok(hr == S_OK, "GetVersion failed, hr=%x\n", hr);
88 if (hr != S_OK) return;
90 count = MAX_PATH;
91 hr = ICLRRuntimeInfo_GetVersionString(info, buf, &count);
92 ok(hr == S_OK, "GetVersionString returned %x\n", hr);
93 ok(count == lstrlenW(buf)+1, "GetVersionString returned count %u but string of length %u\n", count, lstrlenW(buf)+1);
94 ok(lstrcmpW(buf, version) == 0, "got unexpected version %s\n", wine_dbgstr_w(buf));
96 ICLRRuntimeInfo_Release(info);
98 /* Versions must match exactly. */
99 dot = strrchrW(version, '.');
100 lstrcpyW(dot, dotzero);
101 hr = ICLRMetaHost_GetRuntime(metahost, version, &IID_ICLRRuntimeInfo, (void**)&info);
102 ok(hr == CLR_E_SHIM_RUNTIME, "GetVersion failed, hr=%x\n", hr);
105 static void test_enumruntimes(void)
107 IEnumUnknown *runtime_enum;
108 IUnknown *unk;
109 DWORD count;
110 ICLRRuntimeInfo *runtime_info;
111 HRESULT hr;
112 WCHAR buf[MAX_PATH];
114 hr = ICLRMetaHost_EnumerateInstalledRuntimes(metahost, &runtime_enum);
115 ok(hr == S_OK, "EnumerateInstalledRuntimes returned %x\n", hr);
116 if (FAILED(hr)) return;
118 while ((hr = IEnumUnknown_Next(runtime_enum, 1, &unk, &count)) == S_OK)
120 hr = IUnknown_QueryInterface(unk, &IID_ICLRRuntimeInfo, (void**)&runtime_info);
121 ok(hr == S_OK, "QueryInterface returned %x\n", hr);
123 count = 1;
124 hr = ICLRRuntimeInfo_GetVersionString(runtime_info, buf, &count);
125 ok(hr == E_NOT_SUFFICIENT_BUFFER, "GetVersionString returned %x\n", hr);
126 ok(count > 1, "GetVersionString returned count %u\n", count);
128 count = 0xdeadbeef;
129 hr = ICLRRuntimeInfo_GetVersionString(runtime_info, NULL, &count);
130 ok(hr == S_OK, "GetVersionString returned %x\n", hr);
131 ok(count > 1 && count != 0xdeadbeef, "GetVersionString returned count %u\n", count);
133 count = MAX_PATH;
134 hr = ICLRRuntimeInfo_GetVersionString(runtime_info, buf, &count);
135 ok(hr == S_OK, "GetVersionString returned %x\n", hr);
136 ok(count > 1, "GetVersionString returned count %u\n", count);
138 trace("runtime found: %s\n", wine_dbgstr_w(buf));
140 ICLRRuntimeInfo_Release(runtime_info);
141 IUnknown_Release(unk);
143 test_getruntime(buf);
146 ok(hr == S_FALSE, "IEnumUnknown_Next returned %x\n", hr);
148 IEnumUnknown_Release(runtime_enum);
151 static void WINAPI notification_callback(ICLRRuntimeInfo *pRuntimeInfo, CallbackThreadSetFnPtr pfnCallbackThreadSet,
152 CallbackThreadUnsetFnPtr pfnCallbackThreadUnset)
154 ok(0, "Unexpected call\n");
157 static void test_notification(void)
159 HRESULT hr;
161 hr = ICLRMetaHost_RequestRuntimeLoadedNotification(metahost, NULL);
162 ok(hr == E_POINTER, "GetVersion failed, hr=%x\n", hr);
164 hr = ICLRMetaHost_RequestRuntimeLoadedNotification(metahost,notification_callback);
165 ok(hr == S_OK, "GetVersion failed, hr=%x\n", hr);
168 START_TEST(metahost)
170 if (!init_pointers())
171 return;
173 test_enumruntimes();
174 test_notification();
176 cleanup();