2 * Copyright (C) 2004 Stefan Leichter
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "wine/test.h"
28 #define MY_LAST_ERROR -1L
29 #define EXPECT_BAD_PATH__NOT_FOUND \
30 ok( (ERROR_PATH_NOT_FOUND == GetLastError()) || \
31 (ERROR_RESOURCE_DATA_NOT_FOUND == GetLastError()) || \
32 (ERROR_FILE_NOT_FOUND == GetLastError()) || \
33 (ERROR_BAD_PATHNAME == GetLastError()), \
34 "Last error wrong! ERROR_RESOURCE_DATA_NOT_FOUND/ERROR_BAD_PATHNAME (98)/" \
35 "ERROR_PATH_NOT_FOUND (NT4)/ERROR_FILE_NOT_FOUND (2k3)" \
36 "expected, got 0x%08lx\n", GetLastError());
37 #define EXPECT_INVALID__NOT_FOUND \
38 ok( (ERROR_PATH_NOT_FOUND == GetLastError()) || \
39 (ERROR_RESOURCE_DATA_NOT_FOUND == GetLastError()) || \
40 (ERROR_FILE_NOT_FOUND == GetLastError()) || \
41 (ERROR_INVALID_PARAMETER == GetLastError()), \
42 "Last error wrong! ERROR_RESOURCE_DATA_NOT_FOUND/ERROR_INVALID_PARAMETER (98)/" \
43 "ERROR_PATH_NOT_FOUND (NT4)/ERROR_FILE_NOT_FOUND (2k3)" \
44 "expected, got 0x%08lx\n", GetLastError());
46 static void test_info_size(void)
48 char mypath[MAX_PATH] = "";
50 SetLastError(MY_LAST_ERROR);
51 retval = GetFileVersionInfoSizeA( NULL, NULL);
53 "GetFileVersionInfoSizeA result wrong! 0L expected, got 0x%08lx\n",
55 EXPECT_INVALID__NOT_FOUND;
58 SetLastError(MY_LAST_ERROR);
59 retval = GetFileVersionInfoSizeA( NULL, &hdl);
61 "GetFileVersionInfoSizeA result wrong! 0L expected, got 0x%08lx\n",
63 EXPECT_INVALID__NOT_FOUND;
65 "Handle wrong! 0L expected, got 0x%08lx\n", hdl);
67 SetLastError(MY_LAST_ERROR);
68 retval = GetFileVersionInfoSizeA( "", NULL);
70 "GetFileVersionInfoSizeA result wrong! 0L expected, got 0x%08lx\n",
72 EXPECT_BAD_PATH__NOT_FOUND;
75 SetLastError(MY_LAST_ERROR);
76 retval = GetFileVersionInfoSizeA( "", &hdl);
78 "GetFileVersionInfoSizeA result wrong! 0L expected, got 0x%08lx\n",
80 EXPECT_BAD_PATH__NOT_FOUND;
82 "Handle wrong! 0L expected, got 0x%08lx\n", hdl);
84 SetLastError(MY_LAST_ERROR);
85 retval = GetFileVersionInfoSizeA( "kernel32.dll", NULL);
87 "GetFileVersionInfoSizeA result wrong! <> 0L expected, got 0x%08lx\n",
89 ok((NO_ERROR == GetLastError()) || (MY_LAST_ERROR == GetLastError()),
90 "Last error wrong! NO_ERROR/0x%08lx (NT4) expected, got 0x%08lx\n",
91 MY_LAST_ERROR, GetLastError());
94 SetLastError(MY_LAST_ERROR);
95 retval = GetFileVersionInfoSizeA( "kernel32.dll", &hdl);
97 "GetFileVersionInfoSizeA result wrong! <> 0L expected, got 0x%08lx\n",
99 ok((NO_ERROR == GetLastError()) || (MY_LAST_ERROR == GetLastError()),
100 "Last error wrong! NO_ERROR/0x%08lx (NT4) expected, got 0x%08lx\n",
101 MY_LAST_ERROR, GetLastError());
103 "Handle wrong! 0L expected, got 0x%08lx\n", hdl);
105 SetLastError(MY_LAST_ERROR);
106 retval = GetFileVersionInfoSizeA( "notexist.dll", NULL);
108 "GetFileVersionInfoSizeA result wrong! 0L expected, got 0x%08lx\n",
110 ok( (ERROR_FILE_NOT_FOUND == GetLastError()) ||
111 (ERROR_RESOURCE_DATA_NOT_FOUND == GetLastError()) ||
112 (MY_LAST_ERROR == GetLastError()),
113 "Last error wrong! ERROR_FILE_NOT_FOUND/ERROR_RESOURCE_DATA_NOT_FOUND "
114 "(XP)/0x%08lx (NT4) expected, got 0x%08lx\n", MY_LAST_ERROR, GetLastError());
116 /* test a currently loaded executable */
117 if(GetModuleFileNameA(NULL, mypath, MAX_PATH)) {
119 SetLastError(MY_LAST_ERROR);
120 retval = GetFileVersionInfoSizeA( mypath, &hdl);
122 "GetFileVersionInfoSizeA result wrong! <> 0L expected, got 0x%08lx\n",
124 ok((NO_ERROR == GetLastError()) || (MY_LAST_ERROR == GetLastError()),
125 "Last error wrong! NO_ERROR/0x%08lx (NT4) expected, got 0x%08lx\n",
126 MY_LAST_ERROR, GetLastError());
128 "Handle wrong! 0L expected, got 0x%08lx\n", hdl);
131 trace("skipping GetModuleFileNameA(NULL,..) failed\n");
133 /* test a not loaded executable */
134 if(GetSystemDirectoryA(mypath, MAX_PATH)) {
135 lstrcatA(mypath, "\\regsvr32.exe");
137 if(INVALID_FILE_ATTRIBUTES == GetFileAttributesA(mypath))
138 trace("GetFileAttributesA(%s) failed\n", mypath);
141 SetLastError(MY_LAST_ERROR);
142 retval = GetFileVersionInfoSizeA( mypath, &hdl);
144 "GetFileVersionInfoSizeA result wrong! <> 0L expected, got 0x%08lx\n",
146 ok((NO_ERROR == GetLastError()) || (MY_LAST_ERROR == GetLastError()),
147 "Last error wrong! NO_ERROR/0x%08lx (NT4) expected, got 0x%08lx\n",
148 MY_LAST_ERROR, GetLastError());
150 "Handle wrong! 0L expected, got 0x%08lx\n", hdl);
154 trace("skipping GetModuleFileNameA(NULL,..) failed\n");
157 static void VersionDwordLong2String(DWORDLONG Version, LPSTR lpszVerString)
161 a = (WORD)(Version >> 48);
162 b = (WORD)((Version >> 32) & 0xffff);
163 c = (WORD)((Version >> 16) & 0xffff);
164 d = (WORD)(Version & 0xffff);
166 sprintf(lpszVerString, "%d.%d.%d.%d", a, b, c, d);
171 static void test_info(void)
174 PVOID pVersionInfo = NULL;
176 VS_FIXEDFILEINFO *pFixedVersionInfo;
178 char VersionString[MAX_PATH];
179 DWORDLONG dwlVersion;
182 SetLastError(MY_LAST_ERROR);
183 retval = GetFileVersionInfoSizeA( "kernel32.dll", &hdl);
185 "GetFileVersionInfoSizeA result wrong! <> 0L expected, got 0x%08lx\n",
187 ok((NO_ERROR == GetLastError()) || (MY_LAST_ERROR == GetLastError()),
188 "Last error wrong! NO_ERROR/0x%08lx (NT4) expected, got 0x%08lx\n",
189 MY_LAST_ERROR, GetLastError());
191 "Handle wrong! 0L expected, got 0x%08lx\n", hdl);
193 if ( retval == 0 || hdl != 0)
196 pVersionInfo = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, retval );
197 ok(pVersionInfo != 0, "HeapAlloc failed\n" );
198 if (pVersionInfo == 0)
202 /* this test crashes on WinNT4
204 boolret = GetFileVersionInfoA( "kernel32.dll", 0, retval, 0);
205 ok (!boolret, "GetFileVersionInfoA should have failed: GetLastError = 0x%08lx\n", GetLastError());
206 ok ((GetLastError() == ERROR_INVALID_DATA) || (GetLastError() == ERROR_BAD_PATHNAME) ||
207 (GetLastError() == NO_ERROR),
208 "Last error wrong! ERROR_INVALID_DATA/ERROR_BAD_PATHNAME (ME)/"
209 "NO_ERROR (95) expected, got 0x%08lx\n",
213 boolret = GetFileVersionInfoA( "kernel32.dll", 0, retval, pVersionInfo );
214 ok (boolret, "GetFileVersionInfoA failed: GetLastError = 0x%08lx\n", GetLastError());
218 boolret = VerQueryValueA( pVersionInfo, "\\", (LPVOID *)&pFixedVersionInfo, &uiLength );
219 ok (boolret, "VerQueryValueA failed: GetLastError = 0x%08lx\n", GetLastError());
223 dwlVersion = (((DWORDLONG)pFixedVersionInfo->dwFileVersionMS) << 32) +
224 pFixedVersionInfo->dwFileVersionLS;
226 VersionDwordLong2String(dwlVersion, VersionString);
228 trace("kernel32.dll version: %s\n", VersionString);
231 /* this test crashes on WinNT4
233 boolret = VerQueryValueA( pVersionInfo, "\\", (LPVOID *)&pFixedVersionInfo, 0);
234 ok (boolret, "VerQueryValue failed: GetLastError = 0x%08lx\n", GetLastError());
238 static void test_32bit_win(void)
241 DWORD hdlW, retvalW = 0;
243 PVOID pVersionInfoA = NULL;
244 PVOID pVersionInfoW = NULL;
247 UINT uiLengthA, uiLengthW;
248 char mypathA[MAX_PATH];
249 WCHAR mypathW[MAX_PATH];
251 WCHAR rootW[] = { '\\', 0 };
252 char varfileinfoA[] = "\\VarFileInfo\\Translation";
253 WCHAR varfileinfoW[] = { '\\','V','a','r','F','i','l','e','I','n','f','o',
254 '\\','T','r','a','n','s','l','a','t','i','o','n', 0 };
255 char WineVarFileInfoA[] = { 0x09, 0x04, 0xE4, 0x04 };
256 char FileDescriptionA[] = "\\StringFileInfo\\040904E4\\FileDescription";
257 WCHAR FileDescriptionW[] = { '\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o',
258 '\\','0','4','0','9','0','4','E','4',
259 '\\','F','i','l','e','D','e','s','c','r','i','p','t','i','o','n', 0 };
260 char WineFileDescriptionA[] = "Wine version test";
261 WCHAR WineFileDescriptionW[] = { 'W','i','n','e',' ','v','e','r','s','i','o','n',' ','t','e','s','t', 0 };
262 BOOL is_unicode_enabled = TRUE;
264 /* If we call GetFileVersionInfoA on a system that supports Unicode (NT/W2K/XP/W2K3 by default)
265 * then the versioninfo will contain Unicode strings.
266 * Wine however always converts a VersionInfo32 to VersionInfo16 when called through GetFileVersionInfoA
267 * regardless of Windows version
268 * Part of the test is to call both the A and W versions, which should have the same Version Information
269 * for some requests, on systems that support both calls.
272 /* First get the versioninfo via the W versions */
273 GetModuleFileNameW(NULL, mypathW, MAX_PATH);
274 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
276 trace("GetModuleFileNameW not existing on this platform, skipping comparison between A- and W-calls\n");
277 is_unicode_enabled = FALSE;
280 if (is_unicode_enabled)
282 retvalW = GetFileVersionInfoSizeW( mypathW, &hdlW);
283 pVersionInfoW = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, retvalW );
284 retW = GetFileVersionInfoW( mypathW, 0, retvalW, pVersionInfoW );
287 GetModuleFileNameA(NULL, mypathA, MAX_PATH);
288 retvalA = GetFileVersionInfoSizeA( mypathA, &hdlA);
289 pVersionInfoA = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, retvalA );
290 retA = GetFileVersionInfoA( mypathA, 0, retvalA, pVersionInfoA );
292 if (is_unicode_enabled)
294 ok( retvalA == retvalW, "The size of the struct should be the same for both A/W calls, it is (%ld) vs. (%ld)\n",
296 ok( !memcmp(pVersionInfoA, pVersionInfoW, retvalA), "Both structs should be the same, they aren't\n");
299 /* The structs are the same but that will mysteriously change with the next calls on Windows (not on Wine).
300 * The structure on windows is way bigger then needed, so there must be something to it. As we do not
301 * seem to need this bigger structure, we can leave that as is.
302 * The change in the Windows structure is in this not needed part.
304 * Although the structures contain Unicode strings, VerQueryValueA will always return normal strings,
305 * VerQueryValueW will always return Unicode ones. (That means everything returned for StringFileInfo requests).
308 /* Get the VS_FIXEDFILEINFO information, this must be the same for both A- and W-Calls */
310 retA = VerQueryValueA( pVersionInfoA, rootA, (LPVOID *)&pBufA, &uiLengthA );
311 ok (retA, "VerQueryValueA failed: GetLastError = 0x%08lx\n", GetLastError());
312 ok ( uiLengthA == sizeof(VS_FIXEDFILEINFO), "Size (%d) doesn't match the size of the VS_FIXEDFILEINFO struct (%d)\n",
313 uiLengthA, sizeof(VS_FIXEDFILEINFO));
315 if (is_unicode_enabled)
317 retW = VerQueryValueW( pVersionInfoW, rootW, (LPVOID *)&pBufW, &uiLengthW );
318 ok (retW, "VerQueryValueW failed: GetLastError = 0x%08lx\n", GetLastError());
319 ok ( uiLengthA == sizeof(VS_FIXEDFILEINFO), "Size (%d) doesn't match the size of the VS_FIXEDFILEINFO struct (%d)\n",
320 uiLengthA, sizeof(VS_FIXEDFILEINFO));
322 ok( uiLengthA == uiLengthW, "The size of VS_FIXEDFILEINFO should be the same for both A/W calls, it is (%d) vs. (%d)\n",
323 uiLengthA, uiLengthW);
324 ok( !memcmp(pBufA, pBufW, uiLengthA), "Both values should be the same, they aren't\n");
327 /* Get some VarFileInfo information, this must be the same for both A- and W-Calls */
329 retA = VerQueryValueA( pVersionInfoA, varfileinfoA, (LPVOID *)&pBufA, &uiLengthA );
330 ok (retA, "VerQueryValueA failed: GetLastError = 0x%08lx\n", GetLastError());
331 ok( !memcmp(pBufA, WineVarFileInfoA, uiLengthA), "The VarFileInfo should have matched 0904e404 (non case sensitive)\n");
333 if (is_unicode_enabled)
335 retW = VerQueryValueW( pVersionInfoW, varfileinfoW, (LPVOID *)&pBufW, &uiLengthW );
336 ok (retW, "VerQueryValueW failed: GetLastError = 0x%08lx\n", GetLastError());
337 ok( uiLengthA == uiLengthW, "The size of the VarFileInfo information should be the same for both A/W calls, it is (%d) vs. (%d)\n",
338 uiLengthA, uiLengthW);
339 ok( !memcmp(pBufA, pBufW, uiLengthA), "Both values should be the same, they aren't\n");
342 /* Get some StringFileInfo information, this will be ANSI for A-Calls and Unicode for W-Calls */
344 retA = VerQueryValueA( pVersionInfoA, FileDescriptionA, (LPVOID *)&pBufA, &uiLengthA );
345 ok (retA, "VerQueryValueA failed: GetLastError = 0x%08lx\n", GetLastError());
346 ok( !lstrcmpA(WineFileDescriptionA, pBufA), "FileDescription should have been 'Wine version test'\n");
348 if (is_unicode_enabled)
350 retW = VerQueryValueW( pVersionInfoW, FileDescriptionW, (LPVOID *)&pBufW, &uiLengthW );
351 ok (retW, "VerQueryValueW failed: GetLastError = 0x%08lx\n", GetLastError());
352 ok( !lstrcmpW(WineFileDescriptionW, pBufW), "FileDescription should have been 'Wine version test' (unicode)\n");
355 HeapFree( GetProcessHeap(), 0, pVersionInfoA);
356 if (is_unicode_enabled)
357 HeapFree( GetProcessHeap(), 0, pVersionInfoW);
365 /* Test GetFileVersionInfoSize[AW] and GetFileVersionInfo[AW] on a 32 bit windows executable */
366 trace("Testing 32 bit windows application\n");