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