2 * Copyright 2010 Louis Lenders
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
22 #include "wine/test.h"
24 static HMODULE hmscoree;
26 static HRESULT (WINAPI *pGetCORVersion)(LPWSTR, DWORD, DWORD*);
27 static HRESULT (WINAPI *pGetCORSystemDirectory)(LPWSTR, DWORD, DWORD*);
28 static HRESULT (WINAPI *pGetRequestedRuntimeInfo)(LPCWSTR, LPCWSTR, LPCWSTR, DWORD, DWORD, LPWSTR, DWORD, DWORD*, LPWSTR, DWORD, DWORD*);
29 static HRESULT (WINAPI *pLoadLibraryShim)(LPCWSTR, LPCWSTR, LPVOID, HMODULE*);
31 static BOOL init_functionpointers(void)
33 hmscoree = LoadLibraryA("mscoree.dll");
37 win_skip("mscoree.dll not available\n");
41 pGetCORVersion = (void *)GetProcAddress(hmscoree, "GetCORVersion");
42 pGetCORSystemDirectory = (void *)GetProcAddress(hmscoree, "GetCORSystemDirectory");
43 pGetRequestedRuntimeInfo = (void *)GetProcAddress(hmscoree, "GetRequestedRuntimeInfo");
44 pLoadLibraryShim = (void *)GetProcAddress(hmscoree, "LoadLibraryShim");
46 if (!pGetCORVersion || !pGetCORSystemDirectory || !pGetRequestedRuntimeInfo || !pLoadLibraryShim)
48 win_skip("functions not available\n");
49 FreeLibrary(hmscoree);
56 static void test_versioninfo(void)
58 const WCHAR v2_0[] = {'v','2','.','0','.','5','0','7','2','7',0};
59 const WCHAR v1_1[] = {'v','1','.','1','.','4','3','2','2',0};
61 WCHAR version[MAX_PATH];
66 if (0) /* crashes on <= w2k3 */
68 hr = pGetCORVersion(NULL, MAX_PATH, &size);
69 ok(hr == E_POINTER,"GetCORVersion returned %08x\n", hr);
72 hr = pGetCORVersion(version, 1, &size);
73 if (hr == CLR_E_SHIM_RUNTIME)
75 /* FIXME: Get Mono packaged properly so we can fail here. */
76 todo_wine ok(hr == HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER),"GetCORVersion returned %08x\n", hr);
77 skip("No .NET runtimes are installed\n");
81 ok(hr == HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER),"GetCORVersion returned %08x\n", hr);
83 hr = pGetCORVersion(version, MAX_PATH, &size);
84 ok(hr == S_OK,"GetCORVersion returned %08x\n", hr);
86 trace("latest installed .net runtime: %s\n", wine_dbgstr_w(version));
88 hr = pGetCORSystemDirectory(path, MAX_PATH , &size);
89 ok(hr == S_OK, "GetCORSystemDirectory returned %08x\n", hr);
90 /* size includes terminating null-character */
91 ok(size == (lstrlenW(path) + 1),"size is %d instead of %d\n", size, (lstrlenW(path) + 1));
95 hr = pGetCORSystemDirectory(path, path_len-1 , &size);
96 ok(hr == HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), "GetCORSystemDirectory returned %08x\n", hr);
98 if (0) /* crashes on <= w2k3 */
100 hr = pGetCORSystemDirectory(NULL, MAX_PATH , &size);
101 ok(hr == HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), "GetCORSystemDirectory returned %08x\n", hr);
104 hr = pGetCORSystemDirectory(path, MAX_PATH , NULL);
105 ok(hr == E_POINTER,"GetCORSystemDirectory returned %08x\n", hr);
107 trace("latest installed .net installed in directory: %s\n", wine_dbgstr_w(path));
109 /* test GetRequestedRuntimeInfo, first get info about different versions of runtime */
110 hr = pGetRequestedRuntimeInfo( NULL, v2_0, NULL, 0, 0, path, MAX_PATH, &path_len, version, MAX_PATH, &size);
112 if(hr == CLR_E_SHIM_RUNTIME) return; /* skipping rest of tests on win2k as .net 2.0 not installed */
114 ok(hr == S_OK, "GetRequestedRuntimeInfo returned %08x\n", hr);
115 trace(" installed in directory %s is .net version %s\n", wine_dbgstr_w(path), wine_dbgstr_w(version));
117 hr = pGetRequestedRuntimeInfo( NULL, v1_1, NULL, 0, 0, path, MAX_PATH, &path_len, version, MAX_PATH, &size);
118 ok(hr == S_OK || hr == CLR_E_SHIM_RUNTIME /*v1_1 not installed*/, "GetRequestedRuntimeInfo returned %08x\n", hr);
120 trace(" installed in directory %s is .net version %s\n", wine_dbgstr_w(path), wine_dbgstr_w(version));
121 /* version number NULL not allowed without RUNTIME_INFO_UPGRADE_VERSION flag */
122 hr = pGetRequestedRuntimeInfo( NULL, NULL, NULL, 0, 0, path, MAX_PATH, &path_len, version, MAX_PATH, &size);
123 ok(hr == CLR_E_SHIM_RUNTIME, "GetRequestedRuntimeInfo returned %08x\n", hr);
124 /* with RUNTIME_INFO_UPGRADE_VERSION flag and version number NULL, latest installed version is returned */
125 hr = pGetRequestedRuntimeInfo( NULL, NULL, NULL, 0, RUNTIME_INFO_UPGRADE_VERSION, path, MAX_PATH, &path_len, version, MAX_PATH, &size);
126 ok(hr == S_OK, "GetRequestedRuntimeInfo returned %08x\n", hr);
128 hr = pGetRequestedRuntimeInfo( NULL, v2_0, NULL, 0, 0, path, 1, &path_len, version, MAX_PATH, &size);
129 ok(hr == HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), "GetRequestedRuntimeInfo returned %08x\n", hr);
131 /* if one of the buffers is NULL, the other one is still happily filled */
132 memset(version, 0, sizeof(version));
133 hr = pGetRequestedRuntimeInfo( NULL, v2_0, NULL, 0, 0, NULL, MAX_PATH, &path_len, version, MAX_PATH, &size);
134 ok(hr == S_OK, "GetRequestedRuntimeInfo returned %08x\n", hr);
135 ok(!winetest_strcmpW(version, v2_0), "version is %s , expected %s\n", wine_dbgstr_w(version), wine_dbgstr_w(v2_0));
136 /* With NULL-pointer for bufferlength, the buffer itsself still gets filled with correct string */
137 memset(version, 0, sizeof(version));
138 hr = pGetRequestedRuntimeInfo( NULL, v2_0, NULL, 0, 0, path, MAX_PATH, &path_len, version, MAX_PATH, NULL);
139 ok(hr == S_OK, "GetRequestedRuntimeInfo returned %08x\n", hr);
140 ok(!winetest_strcmpW(version, v2_0), "version is %s , expected %s\n", wine_dbgstr_w(version), wine_dbgstr_w(v2_0));
143 static void test_loadlibraryshim(void)
145 const WCHAR v4_0[] = {'v','4','.','0','.','3','0','3','1','9',0};
146 const WCHAR v2_0[] = {'v','2','.','0','.','5','0','7','2','7',0};
147 const WCHAR v1_1[] = {'v','1','.','1','.','4','3','2','2',0};
148 const WCHAR vbogus[] = {'v','b','o','g','u','s',0};
149 const WCHAR fusion[] = {'f','u','s','i','o','n',0};
150 const WCHAR fusiondll[] = {'f','u','s','i','o','n','.','d','l','l',0};
151 const WCHAR nosuchdll[] = {'j','n','v','n','l','.','d','l','l',0};
152 const WCHAR gdidll[] = {'g','d','i','3','2','.','d','l','l',0};
154 const WCHAR *latest = NULL;
155 CHAR latestA[MAX_PATH];
157 CHAR dllpath[MAX_PATH];
159 hr = pLoadLibraryShim(fusion, v1_1, NULL, &hdll);
160 ok(hr == S_OK || hr == E_HANDLE, "LoadLibraryShim failed, hr=%x\n", hr);
165 GetModuleFileNameA(hdll, dllpath, MAX_PATH);
167 todo_wine ok(StrStrIA(dllpath, "v1.1.4322") != 0, "incorrect fusion.dll path %s\n", dllpath);
168 ok(StrStrIA(dllpath, "fusion.dll") != 0, "incorrect fusion.dll path %s\n", dllpath);
173 hr = pLoadLibraryShim(fusion, v2_0, NULL, &hdll);
174 ok(hr == S_OK || hr == E_HANDLE, "LoadLibraryShim failed, hr=%x\n", hr);
179 GetModuleFileNameA(hdll, dllpath, MAX_PATH);
181 todo_wine ok(StrStrIA(dllpath, "v2.0.50727") != 0, "incorrect fusion.dll path %s\n", dllpath);
182 ok(StrStrIA(dllpath, "fusion.dll") != 0, "incorrect fusion.dll path %s\n", dllpath);
187 hr = pLoadLibraryShim(fusion, v4_0, NULL, &hdll);
188 ok(hr == S_OK || hr == E_HANDLE, "LoadLibraryShim failed, hr=%x\n", hr);
191 /* LoadLibraryShim with a NULL version prefers 2.0 and earlier */
195 GetModuleFileNameA(hdll, dllpath, MAX_PATH);
197 todo_wine ok(StrStrIA(dllpath, "v4.0.30319") != 0, "incorrect fusion.dll path %s\n", dllpath);
198 ok(StrStrIA(dllpath, "fusion.dll") != 0, "incorrect fusion.dll path %s\n", dllpath);
203 hr = pLoadLibraryShim(fusion, vbogus, NULL, &hdll);
204 todo_wine ok(hr == E_HANDLE, "LoadLibraryShim failed, hr=%x\n", hr);
208 WideCharToMultiByte(CP_ACP, 0, latest, -1, latestA, MAX_PATH, NULL, NULL);
210 hr = pLoadLibraryShim(fusion, NULL, NULL, &hdll);
211 ok(hr == S_OK, "LoadLibraryShim failed, hr=%x\n", hr);
214 GetModuleFileNameA(hdll, dllpath, MAX_PATH);
217 todo_wine ok(StrStrIA(dllpath, latestA) != 0, "incorrect fusion.dll path %s\n", dllpath);
218 ok(StrStrIA(dllpath, "fusion.dll") != 0, "incorrect fusion.dll path %s\n", dllpath);
223 hr = pLoadLibraryShim(fusiondll, NULL, NULL, &hdll);
224 ok(hr == S_OK, "LoadLibraryShim failed, hr=%x\n", hr);
227 GetModuleFileNameA(hdll, dllpath, MAX_PATH);
230 todo_wine ok(StrStrIA(dllpath, latestA) != 0, "incorrect fusion.dll path %s\n", dllpath);
231 ok(StrStrIA(dllpath, "fusion.dll") != 0, "incorrect fusion.dll path %s\n", dllpath);
236 hr = pLoadLibraryShim(nosuchdll, latest, NULL, &hdll);
237 ok(hr == E_HANDLE, "LoadLibraryShim failed, hr=%x\n", hr);
241 hr = pLoadLibraryShim(gdidll, latest, NULL, &hdll);
242 todo_wine ok(hr == E_HANDLE, "LoadLibraryShim failed, hr=%x\n", hr);
249 if (!init_functionpointers())
253 test_loadlibraryshim();
255 FreeLibrary(hmscoree);