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
21 #include "wine/test.h"
23 static HMODULE hmscoree
;
25 static HRESULT (WINAPI
*pGetCORVersion
)(LPWSTR
, DWORD
, DWORD
*);
26 static HRESULT (WINAPI
*pGetCORSystemDirectory
)(LPWSTR
, DWORD
, DWORD
*);
27 static HRESULT (WINAPI
*pGetRequestedRuntimeInfo
)(LPCWSTR
, LPCWSTR
, LPCWSTR
, DWORD
, DWORD
, LPWSTR
, DWORD
, DWORD
*, LPWSTR
, DWORD
, DWORD
*);
28 static HRESULT (WINAPI
*pLoadLibraryShim
)(LPCWSTR
, LPCWSTR
, LPVOID
, HMODULE
*);
30 static WCHAR
tolowerW( WCHAR ch
)
32 if (ch
>= 'A' && ch
<= 'Z') return ch
|32;
36 static WCHAR
*strstriW( const WCHAR
*str
, const WCHAR
*sub
)
40 const WCHAR
*p1
= str
, *p2
= sub
;
41 while (*p1
&& *p2
&& tolowerW(*p1
) == tolowerW(*p2
)) { p1
++; p2
++; }
42 if (!*p2
) return (WCHAR
*)str
;
48 static BOOL
init_functionpointers(void)
50 hmscoree
= LoadLibraryA("mscoree.dll");
54 win_skip("mscoree.dll not available\n");
58 pGetCORVersion
= (void *)GetProcAddress(hmscoree
, "GetCORVersion");
59 pGetCORSystemDirectory
= (void *)GetProcAddress(hmscoree
, "GetCORSystemDirectory");
60 pGetRequestedRuntimeInfo
= (void *)GetProcAddress(hmscoree
, "GetRequestedRuntimeInfo");
61 pLoadLibraryShim
= (void *)GetProcAddress(hmscoree
, "LoadLibraryShim");
63 if (!pGetCORVersion
|| !pGetCORSystemDirectory
|| !pGetRequestedRuntimeInfo
|| !pLoadLibraryShim
)
65 win_skip("functions not available\n");
66 FreeLibrary(hmscoree
);
73 static void test_versioninfo(void)
75 const WCHAR v2_0
[] = {'v','2','.','0','.','5','0','7','2','7',0};
76 const WCHAR v1_1
[] = {'v','1','.','1','.','4','3','2','2',0};
78 WCHAR version
[MAX_PATH
];
83 if (0) /* crashes on <= w2k3 */
85 hr
= pGetCORVersion(NULL
, MAX_PATH
, &size
);
86 ok(hr
== E_POINTER
,"GetCORVersion returned %08x\n", hr
);
89 hr
= pGetCORVersion(version
, 1, &size
);
90 ok(hr
== HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER
),"GetCORVersion returned %08x\n", hr
);
92 hr
= pGetCORVersion(version
, MAX_PATH
, &size
);
93 ok(hr
== S_OK
,"GetCORVersion returned %08x\n", hr
);
95 trace("latest installed .net runtime: %s\n", wine_dbgstr_w(version
));
97 hr
= pGetCORSystemDirectory(path
, MAX_PATH
, &size
);
98 ok(hr
== S_OK
, "GetCORSystemDirectory returned %08x\n", hr
);
99 /* size includes terminating null-character */
100 ok(size
== (lstrlenW(path
) + 1),"size is %d instead of %d\n", size
, (lstrlenW(path
) + 1));
104 hr
= pGetCORSystemDirectory(path
, path_len
-1 , &size
);
105 ok(hr
== HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER
), "GetCORSystemDirectory returned %08x\n", hr
);
107 if (0) /* crashes on <= w2k3 */
109 hr
= pGetCORSystemDirectory(NULL
, MAX_PATH
, &size
);
110 ok(hr
== HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER
), "GetCORSystemDirectory returned %08x\n", hr
);
113 hr
= pGetCORSystemDirectory(path
, MAX_PATH
, NULL
);
114 ok(hr
== E_POINTER
,"GetCORSystemDirectory returned %08x\n", hr
);
116 trace("latest installed .net installed in directory: %s\n", wine_dbgstr_w(path
));
118 /* test GetRequestedRuntimeInfo, first get info about different versions of runtime */
119 hr
= pGetRequestedRuntimeInfo( NULL
, v2_0
, NULL
, 0, 0, path
, MAX_PATH
, &path_len
, version
, MAX_PATH
, &size
);
121 if(hr
== CLR_E_SHIM_RUNTIME
) return; /* skipping rest of tests on win2k as .net 2.0 not installed */
123 ok(hr
== S_OK
, "GetRequestedRuntimeInfo returned %08x\n", hr
);
124 trace(" installed in directory %s is .net version %s\n", wine_dbgstr_w(path
), wine_dbgstr_w(version
));
126 hr
= pGetRequestedRuntimeInfo( NULL
, v1_1
, NULL
, 0, 0, path
, MAX_PATH
, &path_len
, version
, MAX_PATH
, &size
);
127 ok(hr
== S_OK
|| CLR_E_SHIM_RUNTIME
/*v1_1 not installed*/, "GetRequestedRuntimeInfo returned %08x\n", hr
);
129 trace(" installed in directory %s is .net version %s\n", wine_dbgstr_w(path
), wine_dbgstr_w(version
));
130 /* version number NULL not allowed without RUNTIME_INFO_UPGRADE_VERSION flag */
131 hr
= pGetRequestedRuntimeInfo( NULL
, NULL
, NULL
, 0, 0, path
, MAX_PATH
, &path_len
, version
, MAX_PATH
, &size
);
132 ok(hr
== CLR_E_SHIM_RUNTIME
, "GetRequestedRuntimeInfo returned %08x\n", hr
);
133 /* with RUNTIME_INFO_UPGRADE_VERSION flag and version number NULL, latest installed version is returned */
134 hr
= pGetRequestedRuntimeInfo( NULL
, NULL
, NULL
, 0, RUNTIME_INFO_UPGRADE_VERSION
, path
, MAX_PATH
, &path_len
, version
, MAX_PATH
, &size
);
135 ok(hr
== S_OK
, "GetRequestedRuntimeInfo returned %08x\n", hr
);
137 hr
= pGetRequestedRuntimeInfo( NULL
, v2_0
, NULL
, 0, 0, path
, 1, &path_len
, version
, MAX_PATH
, &size
);
138 ok(hr
== HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER
), "GetRequestedRuntimeInfo returned %08x\n", hr
);
140 /* if one of the buffers is NULL, the other one is still happily filled */
141 memset(version
, 0, sizeof(version
));
142 hr
= pGetRequestedRuntimeInfo( NULL
, v2_0
, NULL
, 0, 0, NULL
, MAX_PATH
, &path_len
, version
, MAX_PATH
, &size
);
143 ok(hr
== S_OK
, "GetRequestedRuntimeInfo returned %08x\n", hr
);
144 ok(!lstrcmpW(version
, v2_0
), "version is %s , expected %s\n", wine_dbgstr_w(version
), wine_dbgstr_w(v2_0
));
145 /* With NULL-pointer for bufferlength, the buffer itsself still gets filled with correct string */
146 memset(version
, 0, sizeof(version
));
147 hr
= pGetRequestedRuntimeInfo( NULL
, v2_0
, NULL
, 0, 0, path
, MAX_PATH
, &path_len
, version
, MAX_PATH
, NULL
);
148 ok(hr
== S_OK
, "GetRequestedRuntimeInfo returned %08x\n", hr
);
149 ok(!lstrcmpW(version
, v2_0
), "version is %s , expected %s\n", wine_dbgstr_w(version
), wine_dbgstr_w(v2_0
));
152 static void test_loadlibraryshim(void)
154 const WCHAR v4_0
[] = {'v','4','.','0','.','3','0','3','1','9',0};
155 const WCHAR v2_0
[] = {'v','2','.','0','.','5','0','7','2','7',0};
156 const WCHAR v1_1
[] = {'v','1','.','1','.','4','3','2','2',0};
157 const WCHAR vbogus
[] = {'v','b','o','g','u','s',0};
158 const WCHAR fusion
[] = {'f','u','s','i','o','n',0};
159 const WCHAR fusiondll
[] = {'f','u','s','i','o','n','.','d','l','l',0};
160 const WCHAR nosuchdll
[] = {'j','n','v','n','l','.','d','l','l',0};
161 const WCHAR gdipdll
[] = {'g','d','i','p','l','u','s','.','d','l','l',0};
162 const WCHAR gdidll
[] = {'g','d','i','3','2','.','d','l','l',0};
164 const WCHAR
*latest
= NULL
;
166 WCHAR dllpath
[MAX_PATH
];
168 hr
= pLoadLibraryShim(fusion
, v1_1
, NULL
, &hdll
);
169 ok(hr
== S_OK
|| hr
== E_HANDLE
, "LoadLibraryShim failed, hr=%x\n", hr
);
174 GetModuleFileNameW(hdll
, dllpath
, MAX_PATH
);
176 todo_wine
ok(strstriW(dllpath
, v1_1
) != 0, "incorrect fusion.dll path %s\n", wine_dbgstr_w(dllpath
));
177 ok(strstriW(dllpath
, fusiondll
) != 0, "incorrect fusion.dll path %s\n", wine_dbgstr_w(dllpath
));
182 hr
= pLoadLibraryShim(fusion
, v2_0
, NULL
, &hdll
);
183 ok(hr
== S_OK
|| hr
== E_HANDLE
, "LoadLibraryShim failed, hr=%x\n", hr
);
188 GetModuleFileNameW(hdll
, dllpath
, MAX_PATH
);
190 todo_wine
ok(strstriW(dllpath
, v2_0
) != 0, "incorrect fusion.dll path %s\n", wine_dbgstr_w(dllpath
));
191 ok(strstriW(dllpath
, fusiondll
) != 0, "incorrect fusion.dll path %s\n", wine_dbgstr_w(dllpath
));
196 hr
= pLoadLibraryShim(fusion
, v4_0
, NULL
, &hdll
);
197 ok(hr
== S_OK
|| hr
== E_HANDLE
, "LoadLibraryShim failed, hr=%x\n", hr
);
200 /* LoadLibraryShim with a NULL version prefers 2.0 and earlier */
204 GetModuleFileNameW(hdll
, dllpath
, MAX_PATH
);
206 todo_wine
ok(strstriW(dllpath
, v4_0
) != 0, "incorrect fusion.dll path %s\n", wine_dbgstr_w(dllpath
));
207 ok(strstriW(dllpath
, fusiondll
) != 0, "incorrect fusion.dll path %s\n", wine_dbgstr_w(dllpath
));
212 hr
= pLoadLibraryShim(fusion
, vbogus
, NULL
, &hdll
);
213 todo_wine
ok(hr
== E_HANDLE
, "LoadLibraryShim failed, hr=%x\n", hr
);
217 hr
= pLoadLibraryShim(fusion
, NULL
, NULL
, &hdll
);
218 ok(hr
== S_OK
, "LoadLibraryShim failed, hr=%x\n", hr
);
221 GetModuleFileNameW(hdll
, dllpath
, MAX_PATH
);
224 todo_wine
ok(strstriW(dllpath
, latest
) != 0, "incorrect fusion.dll path %s\n", wine_dbgstr_w(dllpath
));
225 ok(strstriW(dllpath
, fusiondll
) != 0, "incorrect fusion.dll path %s\n", wine_dbgstr_w(dllpath
));
230 hr
= pLoadLibraryShim(fusiondll
, NULL
, NULL
, &hdll
);
231 ok(hr
== S_OK
, "LoadLibraryShim failed, hr=%x\n", hr
);
234 GetModuleFileNameW(hdll
, dllpath
, MAX_PATH
);
237 todo_wine
ok(strstriW(dllpath
, latest
) != 0, "incorrect fusion.dll path %s\n", wine_dbgstr_w(dllpath
));
238 ok(strstriW(dllpath
, fusiondll
) != 0, "incorrect fusion.dll path %s\n", wine_dbgstr_w(dllpath
));
243 hr
= pLoadLibraryShim(nosuchdll
, latest
, NULL
, &hdll
);
244 ok(hr
== E_HANDLE
, "LoadLibraryShim failed, hr=%x\n", hr
);
248 hr
= pLoadLibraryShim(gdipdll
, latest
, NULL
, &hdll
);
249 todo_wine
ok(hr
== E_HANDLE
, "LoadLibraryShim failed, hr=%x\n", hr
);
253 hr
= pLoadLibraryShim(gdidll
, latest
, NULL
, &hdll
);
254 todo_wine
ok(hr
== E_HANDLE
, "LoadLibraryShim failed, hr=%x\n", hr
);
261 if (!init_functionpointers())
265 test_loadlibraryshim();
267 FreeLibrary(hmscoree
);