ole32: Add a stub transacted storage type.
[wine] / dlls / version / tests / info.c
1 /*
2  * Copyright (C) 2004 Stefan Leichter
3  *
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.
8  *
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.
13  *
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
17  */
18
19 #include <stdarg.h>
20 #include <stdio.h>
21 #include <assert.h>
22
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winerror.h"
26 #include "winver.h"
27 #include "wine/test.h"
28
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         (ERROR_SUCCESS == GetLastError()), \
36         "Last error wrong! ERROR_RESOURCE_DATA_NOT_FOUND/ERROR_BAD_PATHNAME (98)/" \
37         "ERROR_PATH_NOT_FOUND (NT4)/ERROR_FILE_NOT_FOUND (2k3) " \
38         "ERROR_SUCCESS (2k) expected, got %u\n", GetLastError());
39 #define EXPECT_INVALID__NOT_FOUND \
40     ok( (ERROR_PATH_NOT_FOUND == GetLastError()) || \
41         (ERROR_RESOURCE_DATA_NOT_FOUND == GetLastError()) || \
42         (ERROR_FILE_NOT_FOUND == GetLastError()) || \
43         (ERROR_INVALID_PARAMETER == GetLastError()) || \
44         (ERROR_SUCCESS == GetLastError()), \
45         "Last error wrong! ERROR_RESOURCE_DATA_NOT_FOUND/ERROR_INVALID_PARAMETER (98)/" \
46         "ERROR_PATH_NOT_FOUND (NT4)/ERROR_FILE_NOT_FOUND (2k3) " \
47         "ERROR_SUCCESS (2k) expected, got %u\n", GetLastError());
48
49 static void create_file(const CHAR *name)
50 {
51     HANDLE file;
52     DWORD written;
53
54     file = CreateFileA(name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
55     ok(file != INVALID_HANDLE_VALUE, "Failure to open file %s\n", name);
56     WriteFile(file, name, strlen(name), &written, NULL);
57     WriteFile(file, "\n", strlen("\n"), &written, NULL);
58     CloseHandle(file);
59 }
60
61 static void test_info_size(void)
62 {   DWORD hdl, retval;
63     char mypath[MAX_PATH] = "";
64
65     SetLastError(MY_LAST_ERROR);
66     retval = GetFileVersionInfoSizeA( NULL, NULL);
67     ok( !retval,
68         "GetFileVersionInfoSizeA result wrong! 0L expected, got 0x%08x\n",
69         retval);
70     EXPECT_INVALID__NOT_FOUND;
71
72     hdl = 0x55555555;
73     SetLastError(MY_LAST_ERROR);
74     retval = GetFileVersionInfoSizeA( NULL, &hdl);
75     ok( !retval,
76         "GetFileVersionInfoSizeA result wrong! 0L expected, got 0x%08x\n",
77         retval);
78     EXPECT_INVALID__NOT_FOUND;
79     ok( hdl == 0L,
80         "Handle wrong! 0L expected, got 0x%08x\n", hdl);
81
82     SetLastError(MY_LAST_ERROR);
83     retval = GetFileVersionInfoSizeA( "", NULL);
84     ok( !retval,
85         "GetFileVersionInfoSizeA result wrong! 0L expected, got 0x%08x\n",
86         retval);
87     EXPECT_BAD_PATH__NOT_FOUND;
88
89     hdl = 0x55555555;
90     SetLastError(MY_LAST_ERROR);
91     retval = GetFileVersionInfoSizeA( "", &hdl);
92     ok( !retval,
93         "GetFileVersionInfoSizeA result wrong! 0L expected, got 0x%08x\n",
94         retval);
95     EXPECT_BAD_PATH__NOT_FOUND;
96     ok( hdl == 0L,
97         "Handle wrong! 0L expected, got 0x%08x\n", hdl);
98
99     SetLastError(MY_LAST_ERROR);
100     retval = GetFileVersionInfoSizeA( "kernel32.dll", NULL);
101     ok( retval,
102         "GetFileVersionInfoSizeA result wrong! <> 0L expected, got 0x%08x\n",
103         retval);
104     ok((NO_ERROR == GetLastError()) || (MY_LAST_ERROR == GetLastError()),
105         "Last error wrong! NO_ERROR/0x%08x (NT4)  expected, got %u\n",
106         MY_LAST_ERROR, GetLastError());
107
108     hdl = 0x55555555;
109     SetLastError(MY_LAST_ERROR);
110     retval = GetFileVersionInfoSizeA( "kernel32.dll", &hdl);
111     ok( retval,
112         "GetFileVersionInfoSizeA result wrong! <> 0L expected, got 0x%08x\n",
113         retval);
114     ok((NO_ERROR == GetLastError()) || (MY_LAST_ERROR == GetLastError()),
115         "Last error wrong! NO_ERROR/0x%08x (NT4)  expected, got %u\n",
116         MY_LAST_ERROR, GetLastError());
117     ok( hdl == 0L,
118         "Handle wrong! 0L expected, got 0x%08x\n", hdl);
119
120     SetLastError(MY_LAST_ERROR);
121     retval = GetFileVersionInfoSizeA( "notexist.dll", NULL);
122     ok( !retval,
123         "GetFileVersionInfoSizeA result wrong! 0L expected, got 0x%08x\n",
124         retval);
125     ok( (ERROR_FILE_NOT_FOUND == GetLastError()) ||
126         (ERROR_RESOURCE_DATA_NOT_FOUND == GetLastError()) ||
127         (MY_LAST_ERROR == GetLastError()) ||
128         (ERROR_SUCCESS == GetLastError()), /* win2k */
129         "Last error wrong! ERROR_FILE_NOT_FOUND/ERROR_RESOURCE_DATA_NOT_FOUND "
130         "(XP)/0x%08x (NT4) expected, got %u\n", MY_LAST_ERROR, GetLastError());
131
132     /* test a currently loaded executable */
133     if(GetModuleFileNameA(NULL, mypath, MAX_PATH)) {
134         hdl = 0x55555555;
135         SetLastError(MY_LAST_ERROR);
136         retval = GetFileVersionInfoSizeA( mypath, &hdl);
137         ok( retval,
138             "GetFileVersionInfoSizeA result wrong! <> 0L expected, got 0x%08x\n",
139             retval);
140         ok((NO_ERROR == GetLastError()) || (MY_LAST_ERROR == GetLastError()),
141             "Last error wrong! NO_ERROR/0x%08x (NT4)  expected, got %u\n",
142             MY_LAST_ERROR, GetLastError());
143         ok( hdl == 0L,
144             "Handle wrong! 0L expected, got 0x%08x\n", hdl);
145     }
146     else
147         trace("skipping GetModuleFileNameA(NULL,..) failed\n");
148
149     /* test a not loaded executable */
150     if(GetSystemDirectoryA(mypath, MAX_PATH)) {
151         lstrcatA(mypath, "\\regsvr32.exe");
152
153         if(INVALID_FILE_ATTRIBUTES == GetFileAttributesA(mypath))
154             trace("GetFileAttributesA(%s) failed\n", mypath);
155         else {
156             hdl = 0x55555555;
157             SetLastError(MY_LAST_ERROR);
158             retval = GetFileVersionInfoSizeA( mypath, &hdl);
159             ok( retval,
160                 "GetFileVersionInfoSizeA result wrong! <> 0L expected, got 0x%08x\n",
161                 retval);
162             ok((NO_ERROR == GetLastError()) || (MY_LAST_ERROR == GetLastError()),
163                 "Last error wrong! NO_ERROR/0x%08x (NT4)  expected, got %u\n",
164                 MY_LAST_ERROR, GetLastError());
165             ok( hdl == 0L,
166                 "Handle wrong! 0L expected, got 0x%08x\n", hdl);
167         }
168     }
169     else
170         trace("skipping GetSystemDirectoryA(mypath,..) failed\n");
171
172     create_file("test.txt");
173
174     /* no version info */
175     SetLastError(0xdeadbeef);
176     hdl = 0xcafe;
177     retval = GetFileVersionInfoSizeA("test.txt", &hdl);
178     ok(retval == 0, "Expected 0, got %d\n", retval);
179     ok(hdl == 0, "Expected 0, got %d\n", hdl);
180     ok(GetLastError() == ERROR_RESOURCE_DATA_NOT_FOUND ||
181        GetLastError() == ERROR_BAD_FORMAT || /* win9x */
182        GetLastError() == ERROR_SUCCESS, /* win2k */
183        "Expected ERROR_RESOURCE_DATA_NOT_FOUND, got %d\n", GetLastError());
184
185     DeleteFileA("test.txt");
186 }
187
188 static void VersionDwordLong2String(DWORDLONG Version, LPSTR lpszVerString)
189 {
190     WORD a, b, c, d;
191
192     a = (WORD)(Version >> 48);
193     b = (WORD)((Version >> 32) & 0xffff);
194     c = (WORD)((Version >> 16) & 0xffff);
195     d = (WORD)(Version & 0xffff);
196
197     sprintf(lpszVerString, "%d.%d.%d.%d", a, b, c, d);
198
199     return;
200 }
201
202 static void test_info(void)
203 {
204     DWORD hdl, retval;
205     PVOID pVersionInfo = NULL;
206     BOOL boolret;
207     VS_FIXEDFILEINFO *pFixedVersionInfo;
208     UINT uiLength;
209     char VersionString[MAX_PATH];
210     static CHAR backslash[] = "\\";
211     DWORDLONG dwlVersion;
212
213     hdl = 0x55555555;
214     SetLastError(MY_LAST_ERROR);
215     retval = GetFileVersionInfoSizeA( "kernel32.dll", &hdl);
216     ok( retval,
217         "GetFileVersionInfoSizeA result wrong! <> 0L expected, got 0x%08x\n",
218         retval);
219     ok((NO_ERROR == GetLastError()) || (MY_LAST_ERROR == GetLastError()),
220         "Last error wrong! NO_ERROR/0x%08x (NT4)  expected, got %u\n",
221         MY_LAST_ERROR, GetLastError());
222     ok( hdl == 0L,
223         "Handle wrong! 0L expected, got 0x%08x\n", hdl);
224
225     if ( retval == 0 || hdl != 0)
226         return;
227
228     pVersionInfo = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, retval );
229     ok(pVersionInfo != 0, "HeapAlloc failed\n" );
230     if (pVersionInfo == 0)
231         return;
232
233     if (0)
234     {
235     /* this test crashes on WinNT4
236      */
237     boolret = GetFileVersionInfoA( "kernel32.dll", 0, retval, 0);
238     ok (!boolret, "GetFileVersionInfoA should have failed: GetLastError = %u\n", GetLastError());
239     ok ((GetLastError() == ERROR_INVALID_DATA) || (GetLastError() == ERROR_BAD_PATHNAME) ||
240         (GetLastError() == NO_ERROR),
241         "Last error wrong! ERROR_INVALID_DATA/ERROR_BAD_PATHNAME (ME)/"
242         "NO_ERROR (95) expected, got %u\n",
243         GetLastError());
244     }
245
246     boolret = GetFileVersionInfoA( "kernel32.dll", 0, retval, pVersionInfo );
247     ok (boolret, "GetFileVersionInfoA failed: GetLastError = %u\n", GetLastError());
248     if (!boolret)
249         goto cleanup;
250
251     boolret = VerQueryValueA( pVersionInfo, NULL, (LPVOID *)&pFixedVersionInfo, &uiLength );
252     ok (boolret || GetLastError() == NO_ERROR /* Win98 */,
253        "VerQueryValueA failed: GetLastError = %u\n", GetLastError());
254
255     boolret = VerQueryValueA( pVersionInfo, "", (LPVOID *)&pFixedVersionInfo, &uiLength );
256     ok (boolret, "VerQueryValueA failed: GetLastError = %u\n", GetLastError());
257
258     boolret = VerQueryValueA( pVersionInfo, backslash, (LPVOID *)&pFixedVersionInfo, &uiLength );
259     ok (boolret, "VerQueryValueA failed: GetLastError = %u\n", GetLastError());
260     if (!boolret)
261         goto cleanup;
262
263     dwlVersion = (((DWORDLONG)pFixedVersionInfo->dwFileVersionMS) << 32) +
264         pFixedVersionInfo->dwFileVersionLS;
265
266     VersionDwordLong2String(dwlVersion, VersionString);
267
268     trace("kernel32.dll version: %s\n", VersionString);
269
270     if (0)
271     {
272     /* this test crashes on WinNT4
273      */
274     boolret = VerQueryValueA( pVersionInfo, backslash, (LPVOID *)&pFixedVersionInfo, 0);
275     ok (boolret, "VerQueryValue failed: GetLastError = %u\n", GetLastError());
276     }
277
278 cleanup:
279     HeapFree( GetProcessHeap(), 0, pVersionInfo);
280 }
281
282 static void test_32bit_win(void)
283 {
284     DWORD hdlA, retvalA;
285     DWORD hdlW, retvalW = 0;
286     BOOL retA,retW;
287     PVOID pVersionInfoA = NULL;
288     PVOID pVersionInfoW = NULL;
289     char *pBufA;
290     WCHAR *pBufW;
291     UINT uiLengthA, uiLengthW;
292     char mypathA[MAX_PATH];
293     WCHAR mypathW[MAX_PATH];
294     char rootA[] = "\\";
295     WCHAR rootW[] = { '\\', 0 };
296     WCHAR emptyW[] = { 0 };
297     char varfileinfoA[] = "\\VarFileInfo\\Translation";
298     WCHAR varfileinfoW[]    = { '\\','V','a','r','F','i','l','e','I','n','f','o',
299                                 '\\','T','r','a','n','s','l','a','t','i','o','n', 0 };
300     char WineVarFileInfoA[] = { 0x09, 0x04, 0xE4, 0x04 };
301     char FileDescriptionA[] = "\\StringFileInfo\\040904E4\\FileDescription";
302     WCHAR FileDescriptionW[] = { '\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o',
303                                 '\\','0','4','0','9','0','4','E','4',
304                                 '\\','F','i','l','e','D','e','s','c','r','i','p','t','i','o','n', 0 };
305     char WineFileDescriptionA[] = "FileDescription";
306     WCHAR WineFileDescriptionW[] = { 'F','i','l','e','D','e','s','c','r','i','p','t','i','o','n', 0 };
307     BOOL is_unicode_enabled = TRUE;
308
309     /* A copy from dlls/version/info.c */
310     typedef struct
311     {
312         WORD  wLength;
313         WORD  wValueLength;
314         WORD  wType;
315         WCHAR szKey[1];
316 #if 0   /* variable length structure */
317         /* DWORD aligned */
318         BYTE  Value[];
319         /* DWORD aligned */
320         VS_VERSION_INFO_STRUCT32 Children[];
321 #endif
322     } VS_VERSION_INFO_STRUCT32;
323
324     /* If we call GetFileVersionInfoA on a system that supports Unicode, NT/W2K/XP/W2K3 (by default) and Wine,
325      * the versioninfo will contain Unicode strings.
326      * Part of the test is to call both the A and W versions, which should have the same Version Information
327      * for some requests, on systems that support both calls.
328      */
329
330     /* First get the versioninfo via the W versions */
331     SetLastError(0xdeadbeef);
332     GetModuleFileNameW(NULL, mypathW, MAX_PATH);
333     if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
334     {
335         win_skip("GetModuleFileNameW not existing on this platform, skipping comparison between A- and W-calls\n");
336         is_unicode_enabled = FALSE;
337     }
338
339     if (is_unicode_enabled)
340     { 
341         retvalW = GetFileVersionInfoSizeW( mypathW, &hdlW);
342         pVersionInfoW = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, retvalW );
343         retW = GetFileVersionInfoW( mypathW, 0, retvalW, pVersionInfoW );
344     }
345
346     GetModuleFileNameA(NULL, mypathA, MAX_PATH);
347     retvalA = GetFileVersionInfoSizeA( mypathA, &hdlA);
348     pVersionInfoA = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, retvalA );
349     retA = GetFileVersionInfoA( mypathA, 0, retvalA, pVersionInfoA );
350
351     if (is_unicode_enabled)
352     { 
353         ok( retvalA == retvalW, "The size of the struct should be the same for both A/W calls, it is (%d) vs. (%d)\n",
354                                 retvalA, retvalW);
355         ok( !memcmp(pVersionInfoA, pVersionInfoW, retvalA), "Both structs should be the same, they aren't\n");
356     }
357
358     /* The structs on Windows are bigger than just the struct for the basic information. The total struct
359      * contains also an empty part, which is used for converted strings. The converted strings are a result
360      * of calling VerQueryValueA on a 32bit resource and calling VerQueryValueW on a 16bit resource.
361      * The first WORD of the structure (wLength) shows the size of the base struct. The total struct size depends
362      * on the Windows version:
363      *
364      * 16bits resource (numbers are from a sample app):
365      *
366      * Windows Version    Retrieved with A/W    wLength        StructSize
367      * ====================================================================================
368      * Win98              A                     0x01B4 (436)   436
369      * NT4                A/W                   0x01B4 (436)   2048 ???
370      * W2K/XP/W2K3        A/W                   0x01B4 (436)   1536 which is (436 - sizeof(VS_FIXEDFILEINFO)) * 4
371      *
372      * 32bits resource (numbers are from this test executable version_crosstest.exe):
373      * Windows Version    Retrieved with A/W    wLength        StructSize
374      * =============================================================
375      * Win98              A                     0x01E0 (480)   848 (structure data doesn't seem correct)
376      * NT4                A/W                   0x0350 (848)   1272 (848 * 1.5)
377      * W2K/XP/W2K3        A/W                   0x0350 (848)   1700 which is (848 * 2) + 4 
378      *
379      * Wine will follow the implementation (eventually) of W2K/XP/W2K3
380      */
381
382     /* Now some tests for the above (only if we are unicode enabled) */
383
384     if (is_unicode_enabled)
385     { 
386         VS_VERSION_INFO_STRUCT32 *vvis = pVersionInfoW;
387         ok ( retvalW == ((vvis->wLength * 2) + 4) || retvalW == (vvis->wLength * 1.5),
388              "Structure is not of the correct size\n");
389     }
390
391     /* Although the 32bit resource structures contain Unicode strings, VerQueryValueA will always return normal strings,
392      * VerQueryValueW will always return Unicode ones. (That means everything returned for StringFileInfo requests).
393      */
394
395     /* Get the VS_FIXEDFILEINFO information, this must be the same for both A- and W-Calls */ 
396
397     retA = VerQueryValueA( pVersionInfoA, rootA, (LPVOID *)&pBufA, &uiLengthA );
398     ok (retA, "VerQueryValueA failed: GetLastError = %u\n", GetLastError());
399     ok ( uiLengthA == sizeof(VS_FIXEDFILEINFO), "Size (%d) doesn't match the size of the VS_FIXEDFILEINFO struct\n", uiLengthA);
400
401     if (is_unicode_enabled)
402     { 
403         if(0)
404         {   /* This causes Vista and w2k8 to crash */
405             retW = VerQueryValueW( pVersionInfoW, NULL, (LPVOID *)&pBufW, &uiLengthW );
406             ok (retW, "VerQueryValueW failed: GetLastError = %u\n", GetLastError());
407         }
408
409         retW = VerQueryValueW( pVersionInfoW, emptyW, (LPVOID *)&pBufW, &uiLengthW );
410         ok (retW, "VerQueryValueW failed: GetLastError = %u\n", GetLastError());
411
412         retW = VerQueryValueW( pVersionInfoW, rootW, (LPVOID *)&pBufW, &uiLengthW );
413         ok (retW, "VerQueryValueW failed: GetLastError = %u\n", GetLastError());
414         ok ( uiLengthA == sizeof(VS_FIXEDFILEINFO), "Size (%d) doesn't match the size of the VS_FIXEDFILEINFO struct\n", uiLengthA);
415
416         ok( uiLengthA == uiLengthW, "The size of VS_FIXEDFILEINFO should be the same for both A/W calls, it is (%d) vs. (%d)\n",
417                                     uiLengthA, uiLengthW);
418         ok( !memcmp(pBufA, pBufW, uiLengthA), "Both values should be the same, they aren't\n");
419     }
420
421     /* Get some VarFileInfo information, this must be the same for both A- and W-Calls */
422
423     retA = VerQueryValueA( pVersionInfoA, varfileinfoA, (LPVOID *)&pBufA, &uiLengthA );
424     ok (retA, "VerQueryValueA failed: GetLastError = %u\n", GetLastError());
425     ok( !memcmp(pBufA, WineVarFileInfoA, uiLengthA), "The VarFileInfo should have matched 0904e404 (non case sensitive)\n");
426
427     if (is_unicode_enabled)
428     { 
429         retW = VerQueryValueW( pVersionInfoW, varfileinfoW, (LPVOID *)&pBufW, &uiLengthW );
430         ok (retW, "VerQueryValueW failed: GetLastError = %u\n", GetLastError());
431         ok( uiLengthA == uiLengthW, "The size of the VarFileInfo information should be the same for both A/W calls, it is (%d) vs. (%d)\n",
432                                     uiLengthA, uiLengthW);
433         ok( !memcmp(pBufA, pBufW, uiLengthA), "Both values should be the same, they aren't\n");
434     }
435
436     /* Get some StringFileInfo information, this will be ANSI for A-Calls and Unicode for W-Calls */
437
438     retA = VerQueryValueA( pVersionInfoA, FileDescriptionA, (LPVOID *)&pBufA, &uiLengthA );
439     ok (retA, "VerQueryValueA failed: GetLastError = %u\n", GetLastError());
440     ok( !lstrcmpA(WineFileDescriptionA, pBufA), "expected '%s' got '%s'\n",
441         WineFileDescriptionA, pBufA);
442
443     /* Test a second time */
444     retA = VerQueryValueA( pVersionInfoA, FileDescriptionA, (LPVOID *)&pBufA, &uiLengthA );
445     ok (retA, "VerQueryValueA failed: GetLastError = %u\n", GetLastError());
446     ok( !lstrcmpA(WineFileDescriptionA, pBufA), "expected '%s' got '%s'\n",
447         WineFileDescriptionA, pBufA);
448
449     if (is_unicode_enabled)
450     { 
451         retW = VerQueryValueW( pVersionInfoW, FileDescriptionW, (LPVOID *)&pBufW, &uiLengthW );
452         ok (retW, "VerQueryValueW failed: GetLastError = %u\n", GetLastError());
453         ok( !lstrcmpW(WineFileDescriptionW, pBufW), "FileDescription should have been '%s'\n", WineFileDescriptionA);
454     }
455
456     HeapFree( GetProcessHeap(), 0, pVersionInfoA);
457     if (is_unicode_enabled)
458         HeapFree( GetProcessHeap(), 0, pVersionInfoW);
459 }
460
461 static void test_VerQueryValue(void)
462 {
463     static const char * const value_name[] = {
464         "Product", "CompanyName", "FileDescription", "Internal",
465         "ProductVersion", "InternalName", "File", "LegalCopyright",
466         "FileVersion", "Legal", "OriginalFilename", "ProductName",
467         "Company", "Original" };
468     char *ver, *p;
469     UINT len, ret, translation, i;
470     char buf[MAX_PATH];
471
472     ret = GetModuleFileName(NULL, buf, sizeof(buf));
473     assert(ret);
474
475     SetLastError(0xdeadbeef);
476     len = GetFileVersionInfoSize(buf, NULL);
477     ok(len, "GetFileVersionInfoSize(%s) error %u\n", buf, GetLastError());
478
479     ver = HeapAlloc(GetProcessHeap(), 0, len);
480     assert(ver);
481
482     SetLastError(0xdeadbeef);
483     ret = GetFileVersionInfo(buf, 0, len, ver);
484     ok(ret, "GetFileVersionInfo error %u\n", GetLastError());
485
486     p = (char *)0xdeadbeef;
487     len = 0xdeadbeef;
488     SetLastError(0xdeadbeef);
489     ret = VerQueryValue(ver, "\\VarFileInfo\\Translation", (LPVOID*)&p, &len);
490     ok(ret, "VerQueryValue error %u\n", GetLastError());
491     ok(len == 4, "VerQueryValue returned %u, expected 4\n", len);
492
493     translation = *(UINT *)p;
494     translation = MAKELONG(HIWORD(translation), LOWORD(translation));
495
496     p = (char *)0xdeadbeef;
497     len = 0xdeadbeef;
498     SetLastError(0xdeadbeef);
499     ret = VerQueryValue(ver, "String", (LPVOID*)&p, &len);
500     ok(!ret, "VerQueryValue should fail\n");
501     ok(GetLastError() == ERROR_RESOURCE_TYPE_NOT_FOUND ||
502        GetLastError() == 0xdeadbeef /* Win9x, NT4, W2K */,
503        "VerQueryValue returned %u\n", GetLastError());
504     ok(p == (char *)0xdeadbeef, "expected 0xdeadbeef got %p\n", p);
505     ok(len == 0 ||
506        len == 0xbeef, /* win9x */
507        "expected 0 got %x\n", len);
508
509     p = (char *)0xdeadbeef;
510     len = 0xdeadbeef;
511     SetLastError(0xdeadbeef);
512     ret = VerQueryValue(ver, "StringFileInfo", (LPVOID*)&p, &len);
513     ok(ret, "VerQueryValue error %u\n", GetLastError());
514 todo_wine ok(len == 0, "VerQueryValue returned %u, expected 0\n", len);
515     ok(p != (char *)0xdeadbeef, "not expected 0xdeadbeef\n");
516
517     p = (char *)0xdeadbeef;
518     len = 0xdeadbeef;
519     SetLastError(0xdeadbeef);
520     ret = VerQueryValue(ver, "\\StringFileInfo", (LPVOID*)&p, &len);
521     ok(ret, "VerQueryValue error %u\n", GetLastError());
522 todo_wine ok(len == 0, "VerQueryValue returned %u, expected 0\n", len);
523     ok(p != (char *)0xdeadbeef, "not expected 0xdeadbeef\n");
524
525     p = (char *)0xdeadbeef;
526     len = 0xdeadbeef;
527     SetLastError(0xdeadbeef);
528     ret = VerQueryValue(ver, "\\\\StringFileInfo", (LPVOID*)&p, &len);
529     ok(ret, "VerQueryValue error %u\n", GetLastError());
530 todo_wine ok(len == 0, "VerQueryValue returned %u, expected 0\n", len);
531     ok(p != (char *)0xdeadbeef, "not expected 0xdeadbeef\n");
532
533     p = (char *)0xdeadbeef;
534     len = 0xdeadbeef;
535     SetLastError(0xdeadbeef);
536     ret = VerQueryValue(ver, "\\StringFileInfo\\\\", (LPVOID*)&p, &len);
537     ok(ret, "VerQueryValue error %u\n", GetLastError());
538 todo_wine ok(len == 0, "VerQueryValue returned %u, expected 0\n", len);
539     ok(p != (char *)0xdeadbeef, "not expected 0xdeadbeef\n");
540
541     sprintf(buf, "\\StringFileInfo\\%08x", translation);
542     p = (char *)0xdeadbeef;
543     len = 0xdeadbeef;
544     SetLastError(0xdeadbeef);
545     ret = VerQueryValue(ver, buf, (LPVOID*)&p, &len);
546     ok(ret, "VerQueryValue error %u\n", GetLastError());
547 todo_wine ok(len == 0, "VerQueryValue returned %u, expected 0\n", len);
548     ok(p != (char *)0xdeadbeef, "not expected 0xdeadbeef\n");
549
550     for (i = 0; i < sizeof(value_name)/sizeof(value_name[0]); i++)
551     {
552         sprintf(buf, "\\StringFileInfo\\%08x\\%s", translation, value_name[i]);
553         p = (char *)0xdeadbeef;
554         len = 0xdeadbeef;
555         SetLastError(0xdeadbeef);
556         ret = VerQueryValue(ver, buf, (LPVOID*)&p, &len);
557         ok(ret, "VerQueryValue(%s) error %u\n", buf, GetLastError());
558         ok(len == strlen(value_name[i]) + 1, "VerQueryValue returned %u\n", len);
559         ok(!strcmp(value_name[i], p), "expected \"%s\", got \"%s\"\n",
560            value_name[i], p);
561
562         /* test partial value names */
563         len = lstrlen(buf);
564         buf[len - 2] = 0;
565         p = (char *)0xdeadbeef;
566         len = 0xdeadbeef;
567         SetLastError(0xdeadbeef);
568         ret = VerQueryValue(ver, buf, (LPVOID*)&p, &len);
569         ok(!ret, "VerQueryValue(%s) succeeded\n", buf);
570         ok(GetLastError() == ERROR_RESOURCE_TYPE_NOT_FOUND ||
571            GetLastError() == 0xdeadbeef /* Win9x, NT4, W2K */,
572            "VerQueryValue returned %u\n", GetLastError());
573         ok(p == (char *)0xdeadbeef, "expected 0xdeadbeef got %p\n", p);
574         ok(len == 0 ||
575            len == 0xbeef, /* win9x */
576            "expected 0 or 0xbeef, got %x\n", len);
577     }
578
579     HeapFree(GetProcessHeap(), 0, ver);
580 }
581
582 START_TEST(info)
583 {
584     test_info_size();
585     test_info();
586     test_32bit_win();
587     test_VerQueryValue();
588 }