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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #include "wine/test.h"
29 #define MY_LAST_ERROR ((DWORD)-1)
30 #define EXPECT_BAD_PATH__NOT_FOUND \
31 ok( (ERROR_PATH_NOT_FOUND == GetLastError()) || \
32 (ERROR_RESOURCE_DATA_NOT_FOUND == GetLastError()) || \
33 (ERROR_FILE_NOT_FOUND == GetLastError()) || \
34 (ERROR_BAD_PATHNAME == GetLastError()), \
35 "Last error wrong! ERROR_RESOURCE_DATA_NOT_FOUND/ERROR_BAD_PATHNAME (98)/" \
36 "ERROR_PATH_NOT_FOUND (NT4)/ERROR_FILE_NOT_FOUND (2k3)" \
37 "expected, got %u\n", GetLastError());
38 #define EXPECT_INVALID__NOT_FOUND \
39 ok( (ERROR_PATH_NOT_FOUND == GetLastError()) || \
40 (ERROR_RESOURCE_DATA_NOT_FOUND == GetLastError()) || \
41 (ERROR_FILE_NOT_FOUND == GetLastError()) || \
42 (ERROR_INVALID_PARAMETER == GetLastError()), \
43 "Last error wrong! ERROR_RESOURCE_DATA_NOT_FOUND/ERROR_INVALID_PARAMETER (98)/" \
44 "ERROR_PATH_NOT_FOUND (NT4)/ERROR_FILE_NOT_FOUND (2k3)" \
45 "expected, got %u\n", GetLastError());
47 static void test_info_size(void)
49 char mypath[MAX_PATH] = "";
51 SetLastError(MY_LAST_ERROR);
52 retval = GetFileVersionInfoSizeA( NULL, NULL);
54 "GetFileVersionInfoSizeA result wrong! 0L expected, got 0x%08x\n",
56 EXPECT_INVALID__NOT_FOUND;
59 SetLastError(MY_LAST_ERROR);
60 retval = GetFileVersionInfoSizeA( NULL, &hdl);
62 "GetFileVersionInfoSizeA result wrong! 0L expected, got 0x%08x\n",
64 EXPECT_INVALID__NOT_FOUND;
66 "Handle wrong! 0L expected, got 0x%08x\n", hdl);
68 SetLastError(MY_LAST_ERROR);
69 retval = GetFileVersionInfoSizeA( "", NULL);
71 "GetFileVersionInfoSizeA result wrong! 0L expected, got 0x%08x\n",
73 EXPECT_BAD_PATH__NOT_FOUND;
76 SetLastError(MY_LAST_ERROR);
77 retval = GetFileVersionInfoSizeA( "", &hdl);
79 "GetFileVersionInfoSizeA result wrong! 0L expected, got 0x%08x\n",
81 EXPECT_BAD_PATH__NOT_FOUND;
83 "Handle wrong! 0L expected, got 0x%08x\n", hdl);
85 SetLastError(MY_LAST_ERROR);
86 retval = GetFileVersionInfoSizeA( "kernel32.dll", NULL);
88 "GetFileVersionInfoSizeA result wrong! <> 0L expected, got 0x%08x\n",
90 ok((NO_ERROR == GetLastError()) || (MY_LAST_ERROR == GetLastError()),
91 "Last error wrong! NO_ERROR/0x%08x (NT4) expected, got %u\n",
92 MY_LAST_ERROR, GetLastError());
95 SetLastError(MY_LAST_ERROR);
96 retval = GetFileVersionInfoSizeA( "kernel32.dll", &hdl);
98 "GetFileVersionInfoSizeA result wrong! <> 0L expected, got 0x%08x\n",
100 ok((NO_ERROR == GetLastError()) || (MY_LAST_ERROR == GetLastError()),
101 "Last error wrong! NO_ERROR/0x%08x (NT4) expected, got %u\n",
102 MY_LAST_ERROR, GetLastError());
104 "Handle wrong! 0L expected, got 0x%08x\n", hdl);
106 SetLastError(MY_LAST_ERROR);
107 retval = GetFileVersionInfoSizeA( "notexist.dll", NULL);
109 "GetFileVersionInfoSizeA result wrong! 0L expected, got 0x%08x\n",
111 ok( (ERROR_FILE_NOT_FOUND == GetLastError()) ||
112 (ERROR_RESOURCE_DATA_NOT_FOUND == GetLastError()) ||
113 (MY_LAST_ERROR == GetLastError()),
114 "Last error wrong! ERROR_FILE_NOT_FOUND/ERROR_RESOURCE_DATA_NOT_FOUND "
115 "(XP)/0x%08x (NT4) expected, got %u\n", MY_LAST_ERROR, GetLastError());
117 /* test a currently loaded executable */
118 if(GetModuleFileNameA(NULL, mypath, MAX_PATH)) {
120 SetLastError(MY_LAST_ERROR);
121 retval = GetFileVersionInfoSizeA( mypath, &hdl);
123 "GetFileVersionInfoSizeA result wrong! <> 0L expected, got 0x%08x\n",
125 ok((NO_ERROR == GetLastError()) || (MY_LAST_ERROR == GetLastError()),
126 "Last error wrong! NO_ERROR/0x%08x (NT4) expected, got %u\n",
127 MY_LAST_ERROR, GetLastError());
129 "Handle wrong! 0L expected, got 0x%08x\n", hdl);
132 trace("skipping GetModuleFileNameA(NULL,..) failed\n");
134 /* test a not loaded executable */
135 if(GetSystemDirectoryA(mypath, MAX_PATH)) {
136 lstrcatA(mypath, "\\regsvr32.exe");
138 if(INVALID_FILE_ATTRIBUTES == GetFileAttributesA(mypath))
139 trace("GetFileAttributesA(%s) failed\n", mypath);
142 SetLastError(MY_LAST_ERROR);
143 retval = GetFileVersionInfoSizeA( mypath, &hdl);
145 "GetFileVersionInfoSizeA result wrong! <> 0L expected, got 0x%08x\n",
147 ok((NO_ERROR == GetLastError()) || (MY_LAST_ERROR == GetLastError()),
148 "Last error wrong! NO_ERROR/0x%08x (NT4) expected, got %u\n",
149 MY_LAST_ERROR, GetLastError());
151 "Handle wrong! 0L expected, got 0x%08x\n", hdl);
155 trace("skipping GetModuleFileNameA(NULL,..) failed\n");
158 static void VersionDwordLong2String(DWORDLONG Version, LPSTR lpszVerString)
162 a = (WORD)(Version >> 48);
163 b = (WORD)((Version >> 32) & 0xffff);
164 c = (WORD)((Version >> 16) & 0xffff);
165 d = (WORD)(Version & 0xffff);
167 sprintf(lpszVerString, "%d.%d.%d.%d", a, b, c, d);
172 static void test_info(void)
175 PVOID pVersionInfo = NULL;
177 VS_FIXEDFILEINFO *pFixedVersionInfo;
179 char VersionString[MAX_PATH];
180 static CHAR backslash[] = "\\";
181 DWORDLONG dwlVersion;
184 SetLastError(MY_LAST_ERROR);
185 retval = GetFileVersionInfoSizeA( "kernel32.dll", &hdl);
187 "GetFileVersionInfoSizeA result wrong! <> 0L expected, got 0x%08x\n",
189 ok((NO_ERROR == GetLastError()) || (MY_LAST_ERROR == GetLastError()),
190 "Last error wrong! NO_ERROR/0x%08x (NT4) expected, got %u\n",
191 MY_LAST_ERROR, GetLastError());
193 "Handle wrong! 0L expected, got 0x%08x\n", hdl);
195 if ( retval == 0 || hdl != 0)
198 pVersionInfo = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, retval );
199 ok(pVersionInfo != 0, "HeapAlloc failed\n" );
200 if (pVersionInfo == 0)
205 /* this test crashes on WinNT4
207 boolret = GetFileVersionInfoA( "kernel32.dll", 0, retval, 0);
208 ok (!boolret, "GetFileVersionInfoA should have failed: GetLastError = %u\n", GetLastError());
209 ok ((GetLastError() == ERROR_INVALID_DATA) || (GetLastError() == ERROR_BAD_PATHNAME) ||
210 (GetLastError() == NO_ERROR),
211 "Last error wrong! ERROR_INVALID_DATA/ERROR_BAD_PATHNAME (ME)/"
212 "NO_ERROR (95) expected, got %u\n",
216 boolret = GetFileVersionInfoA( "kernel32.dll", 0, retval, pVersionInfo );
217 ok (boolret, "GetFileVersionInfoA failed: GetLastError = %u\n", GetLastError());
221 boolret = VerQueryValueA( pVersionInfo, backslash, (LPVOID *)&pFixedVersionInfo, &uiLength );
222 ok (boolret, "VerQueryValueA failed: GetLastError = %u\n", GetLastError());
226 dwlVersion = (((DWORDLONG)pFixedVersionInfo->dwFileVersionMS) << 32) +
227 pFixedVersionInfo->dwFileVersionLS;
229 VersionDwordLong2String(dwlVersion, VersionString);
231 trace("kernel32.dll version: %s\n", VersionString);
235 /* this test crashes on WinNT4
237 boolret = VerQueryValueA( pVersionInfo, backslash, (LPVOID *)&pFixedVersionInfo, 0);
238 ok (boolret, "VerQueryValue failed: GetLastError = %u\n", GetLastError());
242 HeapFree( GetProcessHeap(), 0, pVersionInfo);
245 static void test_32bit_win(void)
248 DWORD hdlW, retvalW = 0;
250 PVOID pVersionInfoA = NULL;
251 PVOID pVersionInfoW = NULL;
254 UINT uiLengthA, uiLengthW;
255 char mypathA[MAX_PATH];
256 WCHAR mypathW[MAX_PATH];
258 WCHAR rootW[] = { '\\', 0 };
259 char varfileinfoA[] = "\\VarFileInfo\\Translation";
260 WCHAR varfileinfoW[] = { '\\','V','a','r','F','i','l','e','I','n','f','o',
261 '\\','T','r','a','n','s','l','a','t','i','o','n', 0 };
262 char WineVarFileInfoA[] = { 0x09, 0x04, 0xE4, 0x04 };
263 char FileDescriptionA[] = "\\StringFileInfo\\040904E4\\FileDescription";
264 WCHAR FileDescriptionW[] = { '\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o',
265 '\\','0','4','0','9','0','4','E','4',
266 '\\','F','i','l','e','D','e','s','c','r','i','p','t','i','o','n', 0 };
267 char WineFileDescriptionA[] = "FileDescription";
268 WCHAR WineFileDescriptionW[] = { 'F','i','l','e','D','e','s','c','r','i','p','t','i','o','n', 0 };
269 BOOL is_unicode_enabled = TRUE;
271 /* A copy from dlls/version/info.c */
278 #if 0 /* variable length structure */
282 VS_VERSION_INFO_STRUCT32 Children[];
284 } VS_VERSION_INFO_STRUCT32;
286 /* If we call GetFileVersionInfoA on a system that supports Unicode, NT/W2K/XP/W2K3 (by default) and Wine,
287 * the versioninfo will contain Unicode strings.
288 * Part of the test is to call both the A and W versions, which should have the same Version Information
289 * for some requests, on systems that support both calls.
292 /* First get the versioninfo via the W versions */
293 SetLastError(0xdeadbeef);
294 GetModuleFileNameW(NULL, mypathW, MAX_PATH);
295 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
297 trace("GetModuleFileNameW not existing on this platform, skipping comparison between A- and W-calls\n");
298 is_unicode_enabled = FALSE;
301 if (is_unicode_enabled)
303 retvalW = GetFileVersionInfoSizeW( mypathW, &hdlW);
304 pVersionInfoW = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, retvalW );
305 retW = GetFileVersionInfoW( mypathW, 0, retvalW, pVersionInfoW );
308 GetModuleFileNameA(NULL, mypathA, MAX_PATH);
309 retvalA = GetFileVersionInfoSizeA( mypathA, &hdlA);
310 pVersionInfoA = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, retvalA );
311 retA = GetFileVersionInfoA( mypathA, 0, retvalA, pVersionInfoA );
313 if (is_unicode_enabled)
315 ok( retvalA == retvalW, "The size of the struct should be the same for both A/W calls, it is (%d) vs. (%d)\n",
317 ok( !memcmp(pVersionInfoA, pVersionInfoW, retvalA), "Both structs should be the same, they aren't\n");
320 /* The structs on Windows are bigger then just the struct for the basic information. The total struct
321 * contains also an empty part, which is used for converted strings. The converted strings are a result
322 * of calling VerQueryValueA on a 32bit resource and calling VerQueryValueW on a 16bit resource.
323 * The first WORD of the structure (wLength) shows the size of the base struct. The total struct size depends
324 * on the Windows version:
326 * 16bits resource (numbers are from a sample app):
328 * Windows Version Retrieved with A/W wLength StructSize
329 * ====================================================================================
330 * Win98 A 0x01B4 (436) 436
331 * NT4 A/W 0x01B4 (436) 2048 ???
332 * W2K/XP/W2K3 A/W 0x01B4 (436) 1536 which is (436 - sizeof(VS_FIXEDFILEINFO)) * 4
334 * 32bits resource (numbers are from this test executable version_crosstest.exe):
335 * Windows Version Retrieved with A/W wLength StructSize
336 * =============================================================
337 * Win98 A 0x01E0 (480) 848 (structure data doesn't seem correct)
338 * NT4 A/W 0x0350 (848) 1272 (848 * 1.5)
339 * W2K/XP/W2K3 A/W 0x0350 (848) 1700 which is (848 * 2) + 4
341 * Wine will follow the implementation (eventually) of W2K/XP/W2K3
344 /* Now some tests for the above (only if we are unicode enabled) */
346 if (is_unicode_enabled)
348 VS_VERSION_INFO_STRUCT32 *vvis = (VS_VERSION_INFO_STRUCT32 *)pVersionInfoW;
349 ok ( retvalW == ((vvis->wLength * 2) + 4) || retvalW == (vvis->wLength * 1.5),
350 "Structure is not of the correct size\n");
353 /* Although the 32bit resource structures contain Unicode strings, VerQueryValueA will always return normal strings,
354 * VerQueryValueW will always return Unicode ones. (That means everything returned for StringFileInfo requests).
357 /* Get the VS_FIXEDFILEINFO information, this must be the same for both A- and W-Calls */
359 retA = VerQueryValueA( pVersionInfoA, rootA, (LPVOID *)&pBufA, &uiLengthA );
360 ok (retA, "VerQueryValueA failed: GetLastError = %u\n", GetLastError());
361 ok ( uiLengthA == sizeof(VS_FIXEDFILEINFO), "Size (%d) doesn't match the size of the VS_FIXEDFILEINFO struct\n", uiLengthA);
363 if (is_unicode_enabled)
365 retW = VerQueryValueW( pVersionInfoW, rootW, (LPVOID *)&pBufW, &uiLengthW );
366 ok (retW, "VerQueryValueW failed: GetLastError = %u\n", GetLastError());
367 ok ( uiLengthA == sizeof(VS_FIXEDFILEINFO), "Size (%d) doesn't match the size of the VS_FIXEDFILEINFO struct\n", uiLengthA);
369 ok( uiLengthA == uiLengthW, "The size of VS_FIXEDFILEINFO should be the same for both A/W calls, it is (%d) vs. (%d)\n",
370 uiLengthA, uiLengthW);
371 ok( !memcmp(pBufA, pBufW, uiLengthA), "Both values should be the same, they aren't\n");
374 /* Get some VarFileInfo information, this must be the same for both A- and W-Calls */
376 retA = VerQueryValueA( pVersionInfoA, varfileinfoA, (LPVOID *)&pBufA, &uiLengthA );
377 ok (retA, "VerQueryValueA failed: GetLastError = %u\n", GetLastError());
378 ok( !memcmp(pBufA, WineVarFileInfoA, uiLengthA), "The VarFileInfo should have matched 0904e404 (non case sensitive)\n");
380 if (is_unicode_enabled)
382 retW = VerQueryValueW( pVersionInfoW, varfileinfoW, (LPVOID *)&pBufW, &uiLengthW );
383 ok (retW, "VerQueryValueW failed: GetLastError = %u\n", GetLastError());
384 ok( uiLengthA == uiLengthW, "The size of the VarFileInfo information should be the same for both A/W calls, it is (%d) vs. (%d)\n",
385 uiLengthA, uiLengthW);
386 ok( !memcmp(pBufA, pBufW, uiLengthA), "Both values should be the same, they aren't\n");
389 /* Get some StringFileInfo information, this will be ANSI for A-Calls and Unicode for W-Calls */
391 retA = VerQueryValueA( pVersionInfoA, FileDescriptionA, (LPVOID *)&pBufA, &uiLengthA );
392 ok (retA, "VerQueryValueA failed: GetLastError = %u\n", GetLastError());
393 ok( !lstrcmpA(WineFileDescriptionA, pBufA), "expected '%s' got '%s'\n",
394 WineFileDescriptionA, pBufA);
396 /* Test a second time */
397 retA = VerQueryValueA( pVersionInfoA, FileDescriptionA, (LPVOID *)&pBufA, &uiLengthA );
398 ok (retA, "VerQueryValueA failed: GetLastError = %u\n", GetLastError());
399 ok( !lstrcmpA(WineFileDescriptionA, pBufA), "expected '%s' got '%s'\n",
400 WineFileDescriptionA, pBufA);
402 if (is_unicode_enabled)
404 retW = VerQueryValueW( pVersionInfoW, FileDescriptionW, (LPVOID *)&pBufW, &uiLengthW );
405 ok (retW, "VerQueryValueW failed: GetLastError = %u\n", GetLastError());
406 ok( !lstrcmpW(WineFileDescriptionW, pBufW), "FileDescription should have been '%s'\n", WineFileDescriptionA);
409 HeapFree( GetProcessHeap(), 0, pVersionInfoA);
410 if (is_unicode_enabled)
411 HeapFree( GetProcessHeap(), 0, pVersionInfoW);
414 static void test_VerQueryValue(void)
416 static const char * const value_name[] = {
417 "Product", "CompanyName", "FileDescription", "Internal",
418 "ProductVersion", "InternalName", "File", "LegalCopyright",
419 "FileVersion", "Legal", "OriginalFilename", "ProductName",
420 "Company", "Original" };
422 UINT len, ret, translation, i;
425 ret = GetModuleFileName(NULL, buf, sizeof(buf));
428 SetLastError(0xdeadbeef);
429 len = GetFileVersionInfoSize(buf, NULL);
430 ok(len, "GetFileVersionInfoSize(%s) error %u\n", buf, GetLastError());
432 ver = HeapAlloc(GetProcessHeap(), 0, len);
435 SetLastError(0xdeadbeef);
436 ret = GetFileVersionInfo(buf, 0, len, ver);
437 ok(ret, "GetFileVersionInfo error %u\n", GetLastError());
439 p = (char *)0xdeadbeef;
441 SetLastError(0xdeadbeef);
442 ret = VerQueryValue(ver, "\\VarFileInfo\\Translation", (LPVOID*)&p, &len);
443 ok(ret, "VerQueryValue error %u\n", GetLastError());
444 ok(len == 4, "VerQueryValue returned %u, expected 4\n", len);
446 translation = *(UINT *)p;
447 translation = MAKELONG(HIWORD(translation), LOWORD(translation));
449 p = (char *)0xdeadbeef;
451 SetLastError(0xdeadbeef);
452 ret = VerQueryValue(ver, "String", (LPVOID*)&p, &len);
453 ok(!ret, "VerQueryValue should fail\n");
454 ok(GetLastError() == ERROR_RESOURCE_TYPE_NOT_FOUND,
455 "VerQueryValue returned %u\n", GetLastError());
456 ok(p == (char *)0xdeadbeef, "expected 0xdeadbeef got %p\n", p);
457 ok(len == 0, "expected 0 got %x\n", len);
459 p = (char *)0xdeadbeef;
461 SetLastError(0xdeadbeef);
462 ret = VerQueryValue(ver, "StringFileInfo", (LPVOID*)&p, &len);
463 ok(ret, "VerQueryValue error %u\n", GetLastError());
464 todo_wine ok(len == 0, "VerQueryValue returned %u, expected 0\n", len);
465 ok(p != (char *)0xdeadbeef, "not expected 0xdeadbeef\n");
467 p = (char *)0xdeadbeef;
469 SetLastError(0xdeadbeef);
470 ret = VerQueryValue(ver, "\\StringFileInfo", (LPVOID*)&p, &len);
471 ok(ret, "VerQueryValue error %u\n", GetLastError());
472 todo_wine ok(len == 0, "VerQueryValue returned %u, expected 0\n", len);
473 ok(p != (char *)0xdeadbeef, "not expected 0xdeadbeef\n");
475 p = (char *)0xdeadbeef;
477 SetLastError(0xdeadbeef);
478 ret = VerQueryValue(ver, "\\\\StringFileInfo", (LPVOID*)&p, &len);
479 ok(ret, "VerQueryValue error %u\n", GetLastError());
480 todo_wine ok(len == 0, "VerQueryValue returned %u, expected 0\n", len);
481 ok(p != (char *)0xdeadbeef, "not expected 0xdeadbeef\n");
483 p = (char *)0xdeadbeef;
485 SetLastError(0xdeadbeef);
486 ret = VerQueryValue(ver, "\\StringFileInfo\\\\", (LPVOID*)&p, &len);
487 ok(ret, "VerQueryValue error %u\n", GetLastError());
488 todo_wine ok(len == 0, "VerQueryValue returned %u, expected 0\n", len);
489 ok(p != (char *)0xdeadbeef, "not expected 0xdeadbeef\n");
491 sprintf(buf, "\\StringFileInfo\\%08x", translation);
492 p = (char *)0xdeadbeef;
494 SetLastError(0xdeadbeef);
495 ret = VerQueryValue(ver, buf, (LPVOID*)&p, &len);
496 ok(ret, "VerQueryValue error %u\n", GetLastError());
497 todo_wine ok(len == 0, "VerQueryValue returned %u, expected 0\n", len);
498 ok(p != (char *)0xdeadbeef, "not expected 0xdeadbeef\n");
500 for (i = 0; i < sizeof(value_name)/sizeof(value_name[0]); i++)
502 sprintf(buf, "\\StringFileInfo\\%08x\\%s", translation, value_name[i]);
503 p = (char *)0xdeadbeef;
505 SetLastError(0xdeadbeef);
506 ret = VerQueryValue(ver, buf, (LPVOID*)&p, &len);
507 ok(ret, "VerQueryValue(%s) error %u\n", buf, GetLastError());
508 ok(len == strlen(value_name[i]) + 1, "VerQueryValue returned %u, expected %u\n",
509 len, strlen(value_name[i]) + 1);
510 ok(!strcmp(value_name[i], p), "expected \"%s\", got \"%s\"\n",
513 /* test partial value names */
516 p = (char *)0xdeadbeef;
518 SetLastError(0xdeadbeef);
519 ret = VerQueryValue(ver, buf, (LPVOID*)&p, &len);
520 ok(!ret, "VerQueryValue(%s) succeeded\n", buf);
521 ok(GetLastError() == ERROR_RESOURCE_TYPE_NOT_FOUND,
522 "VerQueryValue returned %u\n", GetLastError());
523 ok(p == (char *)0xdeadbeef, "expected 0xdeadbeef got %p\n", p);
524 ok(len == 0, "expected 0 got %x\n", len);
527 HeapFree(GetProcessHeap(), 0, ver);
535 test_VerQueryValue();