ReactOS 0.4.16-dev-2354-g16de117
metahost.c
Go to the documentation of this file.
1/*
2 * Copyright 2010 Vincent Povirk
3 *
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.
8 *
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.
13 *
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
17 */
18
19#define COBJMACROS
20
21#include <stdarg.h>
22
23#include "windef.h"
24#include "ole2.h"
25
26#include "corerror.h"
27#include "ocidl.h"
28#include "initguid.h"
29#include "metahost.h"
30#include "wine/test.h"
31
32#if !defined(__i386__) && !defined(__x86_64__)
33static int has_mono = 0;
34#else
35static int has_mono = 1;
36#endif
37
39
40static HRESULT (WINAPI *pCLRCreateInstance)(REFCLSID clsid, REFIID riid, LPVOID *ppInterface);
41
43
44static const WCHAR v4_0[] = {'v','4','.','0','.','3','0','3','1','9',0};
45
47
48static BOOL init_pointers(void)
49{
51
52 hmscoree = LoadLibraryA("mscoree.dll");
53
54 if (hmscoree)
55 pCLRCreateInstance = (void *)GetProcAddress(hmscoree, "CLRCreateInstance");
56
57 if (pCLRCreateInstance)
58 hr = pCLRCreateInstance(&CLSID_CLRMetaHost, &IID_ICLRMetaHost, (void**)&metahost);
59
60 if (FAILED(hr))
61 {
62 win_skip(".NET 4 is not installed\n");
64 return FALSE;
65 }
66
67 return TRUE;
68}
69
70static void cleanup(void)
71{
72 ICLRMetaHost_Release(metahost);
73
75}
76
78{
79 static const WCHAR dotzero[] = {'.','0',0};
80 WCHAR *dot;
81 HRESULT hr;
82 ICLRRuntimeInfo *info;
85
86 hr = ICLRMetaHost_GetRuntime(metahost, NULL, &IID_ICLRRuntimeInfo, (void**)&info);
87 ok(hr == E_POINTER, "GetVersion failed, hr=%lx\n", hr);
88
89 hr = ICLRMetaHost_GetRuntime(metahost, version, &IID_ICLRRuntimeInfo, (void**)&info);
90 ok(hr == S_OK, "GetVersion failed, hr=%lx\n", hr);
91 if (hr != S_OK) return;
92
94 hr = ICLRRuntimeInfo_GetVersionString(info, buf, &count);
95 ok(hr == S_OK, "GetVersionString returned %lx\n", hr);
96 ok(count == lstrlenW(buf)+1, "GetVersionString returned count %lu but string of length %u\n", count, lstrlenW(buf)+1);
97 ok(lstrcmpW(buf, version) == 0, "got unexpected version %s\n", wine_dbgstr_w(buf));
98
99 ICLRRuntimeInfo_Release(info);
100
101 /* Versions must match exactly. */
102 dot = wcsrchr(version, '.');
103 lstrcpyW(dot, dotzero);
104 hr = ICLRMetaHost_GetRuntime(metahost, version, &IID_ICLRRuntimeInfo, (void**)&info);
105 ok(hr == CLR_E_SHIM_RUNTIME, "GetVersion failed, hr=%lx\n", hr);
106}
107
108static void test_enumruntimes(void)
109{
110 IEnumUnknown *runtime_enum;
111 IUnknown *unk;
112 DWORD count;
113 ICLRRuntimeInfo *runtime_info;
114 HRESULT hr;
116
117 hr = ICLRMetaHost_EnumerateInstalledRuntimes(metahost, &runtime_enum);
118 ok(hr == S_OK, "EnumerateInstalledRuntimes returned %lx\n", hr);
119 if (FAILED(hr)) return;
120
121 while ((hr = IEnumUnknown_Next(runtime_enum, 1, &unk, &count)) == S_OK)
122 {
123 hr = IUnknown_QueryInterface(unk, &IID_ICLRRuntimeInfo, (void**)&runtime_info);
124 ok(hr == S_OK, "QueryInterface returned %lx\n", hr);
125
126 count = 1;
127 hr = ICLRRuntimeInfo_GetVersionString(runtime_info, buf, &count);
128 ok(hr == E_NOT_SUFFICIENT_BUFFER, "GetVersionString returned %lx\n", hr);
129 ok(count > 1, "GetVersionString returned count %lu\n", count);
130
131 count = 0xdeadbeef;
132 hr = ICLRRuntimeInfo_GetVersionString(runtime_info, NULL, &count);
133 ok(hr == S_OK, "GetVersionString returned %lx\n", hr);
134 ok(count > 1 && count != 0xdeadbeef, "GetVersionString returned count %lu\n", count);
135
136 count = MAX_PATH;
137 hr = ICLRRuntimeInfo_GetVersionString(runtime_info, buf, &count);
138 ok(hr == S_OK, "GetVersionString returned %lx\n", hr);
139 ok(count > 1, "GetVersionString returned count %lu\n", count);
140
141 trace("runtime found: %s\n", wine_dbgstr_w(buf));
142
143 ICLRRuntimeInfo_Release(runtime_info);
144 IUnknown_Release(unk);
145
147 }
148
149 ok(hr == S_FALSE, "IEnumUnknown_Next returned %lx\n", hr);
150
151 IEnumUnknown_Release(runtime_enum);
152}
153
154static void WINAPI notification_dummy_callback(ICLRRuntimeInfo *pRuntimeInfo, CallbackThreadSetFnPtr pfnCallbackThreadSet,
155 CallbackThreadUnsetFnPtr pfnCallbackThreadUnset)
156{
157 ok(0, "unexpected call\n");
158}
159
160static void WINAPI notification_callback(ICLRRuntimeInfo *pRuntimeInfo, CallbackThreadSetFnPtr pfnCallbackThreadSet,
161 CallbackThreadUnsetFnPtr pfnCallbackThreadUnset)
162{
163 HRESULT hr;
164 WCHAR buf[20];
165 DWORD buf_size = 20;
166
167 ok(expect_runtime_tid != 0, "unexpected call\n");
168
169 if (expect_runtime_tid != 0)
170 {
172 "expected call on thread %04lx, got thread %04lx\n", expect_runtime_tid, GetCurrentThreadId());
174 }
175
176 hr = ICLRRuntimeInfo_GetVersionString(pRuntimeInfo, buf, &buf_size);
177 ok(hr == S_OK, "GetVersion returned %lx\n", hr);
178 ok(lstrcmpW(buf, v4_0) == 0, "GetVersion returned %s\n", wine_dbgstr_w(buf));
179
180 hr = pfnCallbackThreadSet();
181 ok(hr == S_OK, "pfnCallbackThreadSet returned %lx\n", hr);
182
183 hr = pfnCallbackThreadUnset();
184 ok(hr == S_OK, "pfnCallbackThreadUnset returned %lx\n", hr);
185}
186
187static void test_notification(void)
188{
189 HRESULT hr;
190
191 hr = ICLRMetaHost_RequestRuntimeLoadedNotification(metahost, NULL);
192 ok(hr == E_POINTER, "RequestRuntimeLoadedNotification returned %lx\n", hr);
193
194 hr = ICLRMetaHost_RequestRuntimeLoadedNotification(metahost,notification_callback);
195 ok(hr == S_OK, "RequestRuntimeLoadedNotification failed, hr=%lx\n", hr);
196
197 hr = ICLRMetaHost_RequestRuntimeLoadedNotification(metahost,notification_dummy_callback);
198 ok(hr == HOST_E_INVALIDOPERATION, "RequestRuntimeLoadedNotification returned %lx\n", hr);
199}
200
201static void test_notification_cb(void)
202{
203 HRESULT hr;
204 ICLRRuntimeInfo *info;
206
207 hr = ICLRMetaHost_GetRuntime(metahost, v4_0, &IID_ICLRRuntimeInfo, (void**)&info);
208 ok(hr == S_OK, "GetRuntime returned %lx\n", hr);
209
211 hr = ICLRRuntimeInfo_GetInterface(info, &CLSID_CLRRuntimeHost, &IID_ICLRRuntimeHost, (void**)&host);
212#ifdef __REACTOS__
213 if (hr != S_OK)
214 {
215 // skip test if mono is not installed
216 win_skip("mono runtime is not installed\n");
217 return;
218 }
219#endif
220
221 todo_wine_if(!has_mono) ok(hr == S_OK, "GetInterface returned %lx\n", hr);
222 todo_wine if(!has_mono) ok(expect_runtime_tid == 0, "notification_callback was not called\n");
223
224 if(has_mono)
225 ICLRRuntimeHost_Release(host);
226
227 ICLRRuntimeInfo_Release(info);
228}
229
231{
232 if (!init_pointers())
233 return;
234
238
239 cleanup();
240}
#define trace
Definition: atltest.h:70
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
#define CLR_E_SHIM_RUNTIME
Definition: corerror.h:226
#define HOST_E_INVALIDOPERATION
Definition: corerror.h:914
#define E_FAIL
Definition: ddrawi.h:102
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define wcsrchr
Definition: compat.h:16
#define GetProcAddress(x, y)
Definition: compat.h:753
#define FreeLibrary(x)
Definition: compat.h:748
#define MAX_PATH
Definition: compat.h:34
#define lstrcpyW
Definition: compat.h:749
#define lstrlenW
Definition: compat.h:750
static const WCHAR version[]
Definition: asmname.c:66
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
int WINAPI lstrcmpW(LPCWSTR str1, LPCWSTR str2)
Definition: locale.c:4152
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define S_OK
Definition: intsafe.h:52
#define FAILED(hr)
Definition: intsafe.h:51
#define wine_dbgstr_w
Definition: kernel32.h:34
HRESULT(__stdcall * CallbackThreadUnsetFnPtr)()
Definition: metahost.idl:110
#define win_skip
Definition: minitest.h:67
#define todo_wine_if(is_todo)
Definition: minitest.h:81
#define todo_wine
Definition: minitest.h:80
static void test_getruntime(WCHAR *version)
Definition: metahost.c:77
static ICLRMetaHost * metahost
Definition: metahost.c:42
static REFIID LPVOID * ppInterface
Definition: metahost.c:40
static DWORD expect_runtime_tid
Definition: metahost.c:46
static void cleanup(void)
Definition: metahost.c:70
static HMODULE hmscoree
Definition: metahost.c:38
static void test_enumruntimes(void)
Definition: metahost.c:108
static void test_notification(void)
Definition: metahost.c:187
static BOOL init_pointers(void)
Definition: metahost.c:48
static int has_mono
Definition: metahost.c:33
static void WINAPI notification_callback(ICLRRuntimeInfo *pRuntimeInfo, CallbackThreadSetFnPtr pfnCallbackThreadSet, CallbackThreadUnsetFnPtr pfnCallbackThreadUnset)
Definition: metahost.c:160
static void WINAPI notification_dummy_callback(ICLRRuntimeInfo *pRuntimeInfo, CallbackThreadSetFnPtr pfnCallbackThreadSet, CallbackThreadUnsetFnPtr pfnCallbackThreadUnset)
Definition: metahost.c:154
static void test_notification_cb(void)
Definition: metahost.c:201
static REFIID riid
Definition: metahost.c:40
static const WCHAR v4_0[]
Definition: metahost.c:44
const CLSID * clsid
Definition: msctf.cpp:50
#define REFIID
Definition: guiddef.h:118
#define REFCLSID
Definition: guiddef.h:117
HRESULT hr
Definition: shlfolder.c:183
Definition: txthost.c:37
DWORD WINAPI GetCurrentThreadId(void)
Definition: thread.c:459
#define HRESULT
Definition: msvc.h:7
#define WINAPI
Definition: msvc.h:6
#define S_FALSE
Definition: winerror.h:3451
#define E_NOT_SUFFICIENT_BUFFER
Definition: winerror.h:3437
#define E_POINTER
Definition: winerror.h:3480
__wchar_t WCHAR
Definition: xmlstorage.h:180