ddraw/tests: Add another invalid arguments test for surface QI.
[wine.git] / dlls / mscoree / tests / metahost.c
blobfd97361a010ac5305a0889becc3f7d8ce6882c61
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 const WCHAR v4_0[] = {'v','4','.','0','.','3','0','3','1','9',0};
40 static DWORD expect_runtime_tid;
42 static BOOL init_pointers(void)
44 HRESULT hr = E_FAIL;
46 hmscoree = LoadLibraryA("mscoree.dll");
48 if (hmscoree)
49 pCLRCreateInstance = (void *)GetProcAddress(hmscoree, "CLRCreateInstance");
51 if (pCLRCreateInstance)
52 hr = pCLRCreateInstance(&CLSID_CLRMetaHost, &IID_ICLRMetaHost, (void**)&metahost);
54 if (FAILED(hr))
56 win_skip(".NET 4 is not installed\n");
57 FreeLibrary(hmscoree);
58 return FALSE;
61 return TRUE;
64 static void cleanup(void)
66 ICLRMetaHost_Release(metahost);
68 FreeLibrary(hmscoree);
71 static WCHAR *strrchrW( WCHAR *str, WCHAR ch )
73 WCHAR *ret = NULL;
74 do { if (*str == ch) ret = str; } while (*str++);
75 return ret;
78 static void test_getruntime(WCHAR *version)
80 static const WCHAR dotzero[] = {'.','0',0};
81 WCHAR *dot;
82 HRESULT hr;
83 ICLRRuntimeInfo *info;
84 DWORD count;
85 WCHAR buf[MAX_PATH];
87 hr = ICLRMetaHost_GetRuntime(metahost, NULL, &IID_ICLRRuntimeInfo, (void**)&info);
88 ok(hr == E_POINTER, "GetVersion failed, hr=%x\n", hr);
90 hr = ICLRMetaHost_GetRuntime(metahost, version, &IID_ICLRRuntimeInfo, (void**)&info);
91 ok(hr == S_OK, "GetVersion failed, hr=%x\n", hr);
92 if (hr != S_OK) return;
94 count = MAX_PATH;
95 hr = ICLRRuntimeInfo_GetVersionString(info, buf, &count);
96 ok(hr == S_OK, "GetVersionString returned %x\n", hr);
97 ok(count == lstrlenW(buf)+1, "GetVersionString returned count %u but string of length %u\n", count, lstrlenW(buf)+1);
98 ok(lstrcmpW(buf, version) == 0, "got unexpected version %s\n", wine_dbgstr_w(buf));
100 ICLRRuntimeInfo_Release(info);
102 /* Versions must match exactly. */
103 dot = strrchrW(version, '.');
104 lstrcpyW(dot, dotzero);
105 hr = ICLRMetaHost_GetRuntime(metahost, version, &IID_ICLRRuntimeInfo, (void**)&info);
106 ok(hr == CLR_E_SHIM_RUNTIME, "GetVersion failed, hr=%x\n", hr);
109 static void test_enumruntimes(void)
111 IEnumUnknown *runtime_enum;
112 IUnknown *unk;
113 DWORD count;
114 ICLRRuntimeInfo *runtime_info;
115 HRESULT hr;
116 WCHAR buf[MAX_PATH];
118 hr = ICLRMetaHost_EnumerateInstalledRuntimes(metahost, &runtime_enum);
119 ok(hr == S_OK, "EnumerateInstalledRuntimes returned %x\n", hr);
120 if (FAILED(hr)) return;
122 while ((hr = IEnumUnknown_Next(runtime_enum, 1, &unk, &count)) == S_OK)
124 hr = IUnknown_QueryInterface(unk, &IID_ICLRRuntimeInfo, (void**)&runtime_info);
125 ok(hr == S_OK, "QueryInterface returned %x\n", hr);
127 count = 1;
128 hr = ICLRRuntimeInfo_GetVersionString(runtime_info, buf, &count);
129 ok(hr == E_NOT_SUFFICIENT_BUFFER, "GetVersionString returned %x\n", hr);
130 ok(count > 1, "GetVersionString returned count %u\n", count);
132 count = 0xdeadbeef;
133 hr = ICLRRuntimeInfo_GetVersionString(runtime_info, NULL, &count);
134 ok(hr == S_OK, "GetVersionString returned %x\n", hr);
135 ok(count > 1 && count != 0xdeadbeef, "GetVersionString returned count %u\n", count);
137 count = MAX_PATH;
138 hr = ICLRRuntimeInfo_GetVersionString(runtime_info, buf, &count);
139 ok(hr == S_OK, "GetVersionString returned %x\n", hr);
140 ok(count > 1, "GetVersionString returned count %u\n", count);
142 trace("runtime found: %s\n", wine_dbgstr_w(buf));
144 ICLRRuntimeInfo_Release(runtime_info);
145 IUnknown_Release(unk);
147 test_getruntime(buf);
150 ok(hr == S_FALSE, "IEnumUnknown_Next returned %x\n", hr);
152 IEnumUnknown_Release(runtime_enum);
155 static void WINAPI notification_dummy_callback(ICLRRuntimeInfo *pRuntimeInfo, CallbackThreadSetFnPtr pfnCallbackThreadSet,
156 CallbackThreadUnsetFnPtr pfnCallbackThreadUnset)
158 ok(0, "unexpected call\n");
161 static void WINAPI notification_callback(ICLRRuntimeInfo *pRuntimeInfo, CallbackThreadSetFnPtr pfnCallbackThreadSet,
162 CallbackThreadUnsetFnPtr pfnCallbackThreadUnset)
164 HRESULT hr;
165 WCHAR buf[20];
166 DWORD buf_size = 20;
168 ok(expect_runtime_tid != 0, "unexpected call\n");
170 if (expect_runtime_tid != 0)
172 ok(GetCurrentThreadId() == expect_runtime_tid,
173 "expected call on thread %04x, got thread %04x\n", expect_runtime_tid, GetCurrentThreadId());
174 expect_runtime_tid = 0;
177 hr = ICLRRuntimeInfo_GetVersionString(pRuntimeInfo, buf, &buf_size);
178 ok(hr == S_OK, "GetVersion returned %x\n", hr);
179 ok(lstrcmpW(buf, v4_0) == 0, "GetVersion returned %s\n", wine_dbgstr_w(buf));
181 hr = pfnCallbackThreadSet();
182 ok(hr == S_OK, "pfnCallbackThreadSet returned %x\n", hr);
184 hr = pfnCallbackThreadUnset();
185 ok(hr == S_OK, "pfnCallbackThreadUnset returned %x\n", hr);
188 static void test_notification(void)
190 HRESULT hr;
192 hr = ICLRMetaHost_RequestRuntimeLoadedNotification(metahost, NULL);
193 ok(hr == E_POINTER, "RequestRuntimeLoadedNotification returned %x\n", hr);
195 hr = ICLRMetaHost_RequestRuntimeLoadedNotification(metahost,notification_callback);
196 ok(hr == S_OK, "RequestRuntimeLoadedNotification failed, hr=%x\n", hr);
198 hr = ICLRMetaHost_RequestRuntimeLoadedNotification(metahost,notification_dummy_callback);
199 ok(hr == HOST_E_INVALIDOPERATION, "RequestRuntimeLoadedNotification returned %x\n", hr);
202 static void test_notification_cb(void)
204 HRESULT hr;
205 ICLRRuntimeInfo *info;
206 ICLRRuntimeHost *host;
208 hr = ICLRMetaHost_GetRuntime(metahost, v4_0, &IID_ICLRRuntimeInfo, (void**)&info);
209 ok(hr == S_OK, "GetRuntime returned %x\n", hr);
211 expect_runtime_tid = GetCurrentThreadId();
212 hr = ICLRRuntimeInfo_GetInterface(info, &CLSID_CLRRuntimeHost, &IID_ICLRRuntimeHost, (void**)&host);
213 ok(hr == S_OK, "GetInterface returned %x\n", hr);
214 ok(expect_runtime_tid == 0, "notification_callback was not called\n");
216 ICLRRuntimeHost_Release(host);
218 ICLRRuntimeInfo_Release(info);
221 START_TEST(metahost)
223 if (!init_pointers())
224 return;
226 test_notification();
227 test_enumruntimes();
228 test_notification_cb();
230 cleanup();