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
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)
46 hmscoree
= LoadLibraryA("mscoree.dll");
49 pCLRCreateInstance
= (void *)GetProcAddress(hmscoree
, "CLRCreateInstance");
51 if (pCLRCreateInstance
)
52 hr
= pCLRCreateInstance(&CLSID_CLRMetaHost
, &IID_ICLRMetaHost
, (void**)&metahost
);
56 win_skip(".NET 4 is not installed\n");
57 FreeLibrary(hmscoree
);
64 static void cleanup(void)
66 ICLRMetaHost_Release(metahost
);
68 FreeLibrary(hmscoree
);
71 static WCHAR
*strrchrW( WCHAR
*str
, WCHAR ch
)
74 do { if (*str
== ch
) ret
= str
; } while (*str
++);
78 static void test_getruntime(WCHAR
*version
)
80 static const WCHAR dotzero
[] = {'.','0',0};
83 ICLRRuntimeInfo
*info
;
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;
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
;
114 ICLRRuntimeInfo
*runtime_info
;
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
);
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
);
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
);
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
)
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)
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)
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
);
223 if (!init_pointers())
228 test_notification_cb();