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)
49 SetLastError(MY_LAST_ERROR
);
50 retval
= GetFileVersionInfoSizeA( NULL
, NULL
);
52 "GetFileVersionInfoSizeA result wrong! 0L expected, got 0x%08lx\n",
54 EXPECT_INVALID__NOT_FOUND
;
57 SetLastError(MY_LAST_ERROR
);
58 retval
= GetFileVersionInfoSizeA( NULL
, &hdl
);
60 "GetFileVersionInfoSizeA result wrong! 0L expected, got 0x%08lx\n",
62 EXPECT_INVALID__NOT_FOUND
;
64 "Handle wrong! 0L expected, got 0x%08lx\n", hdl
);
66 SetLastError(MY_LAST_ERROR
);
67 retval
= GetFileVersionInfoSizeA( "", NULL
);
69 "GetFileVersionInfoSizeA result wrong! 0L expected, got 0x%08lx\n",
71 EXPECT_BAD_PATH__NOT_FOUND
;
74 SetLastError(MY_LAST_ERROR
);
75 retval
= GetFileVersionInfoSizeA( "", &hdl
);
77 "GetFileVersionInfoSizeA result wrong! 0L expected, got 0x%08lx\n",
79 EXPECT_BAD_PATH__NOT_FOUND
;
81 "Handle wrong! 0L expected, got 0x%08lx\n", hdl
);
83 SetLastError(MY_LAST_ERROR
);
84 retval
= GetFileVersionInfoSizeA( "kernel32.dll", NULL
);
86 "GetFileVersionInfoSizeA result wrong! <> 0L expected, got 0x%08lx\n",
88 ok((NO_ERROR
== GetLastError()) || (MY_LAST_ERROR
== GetLastError()),
89 "Last error wrong! NO_ERROR/0x%08lx (NT4) expected, got 0x%08lx\n",
90 MY_LAST_ERROR
, GetLastError());
93 SetLastError(MY_LAST_ERROR
);
94 retval
= GetFileVersionInfoSizeA( "kernel32.dll", &hdl
);
96 "GetFileVersionInfoSizeA result wrong! <> 0L expected, got 0x%08lx\n",
98 ok((NO_ERROR
== GetLastError()) || (MY_LAST_ERROR
== GetLastError()),
99 "Last error wrong! NO_ERROR/0x%08lx (NT4) expected, got 0x%08lx\n",
100 MY_LAST_ERROR
, GetLastError());
102 "Handle wrong! 0L expected, got 0x%08lx\n", hdl
);
104 SetLastError(MY_LAST_ERROR
);
105 retval
= GetFileVersionInfoSizeA( "notexist.dll", NULL
);
107 "GetFileVersionInfoSizeA result wrong! 0L expected, got 0x%08lx\n",
109 ok( (ERROR_FILE_NOT_FOUND
== GetLastError()) ||
110 (ERROR_RESOURCE_DATA_NOT_FOUND
== GetLastError()) ||
111 (MY_LAST_ERROR
== GetLastError()),
112 "Last error wrong! ERROR_FILE_NOT_FOUND/ERROR_RESOURCE_DATA_NOT_FOUND "
113 "(XP)/0x%08lx (NT4) expected, got 0x%08lx\n", MY_LAST_ERROR
, GetLastError());
116 static void VersionDwordLong2String(DWORDLONG Version
, LPSTR lpszVerString
)
120 a
= (WORD
)(Version
>> 48);
121 b
= (WORD
)((Version
>> 32) & 0xffff);
122 c
= (WORD
)((Version
>> 16) & 0xffff);
123 d
= (WORD
)(Version
& 0xffff);
125 sprintf(lpszVerString
, "%d.%d.%d.%d", a
, b
, c
, d
);
130 static void test_info(void)
133 PVOID pVersionInfo
= NULL
;
135 VS_FIXEDFILEINFO
*pFixedVersionInfo
;
137 char VersionString
[MAX_PATH
];
138 DWORDLONG dwlVersion
;
141 SetLastError(MY_LAST_ERROR
);
142 retval
= GetFileVersionInfoSizeA( "kernel32.dll", &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
);
152 if ( retval
== 0 || hdl
!= 0)
155 pVersionInfo
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, retval
);
156 ok(pVersionInfo
!= 0, "HeapAlloc failed\n" );
157 if (pVersionInfo
== 0)
161 /* this test crashes on WinNT4
163 boolret
= GetFileVersionInfoA( "kernel32.dll", 0, retval
, 0);
164 ok (!boolret
, "GetFileVersionInfoA should have failed: GetLastError = 0x%08lx\n", GetLastError());
165 ok ((GetLastError() == ERROR_INVALID_DATA
) || (GetLastError() == ERROR_BAD_PATHNAME
) ||
166 (GetLastError() == NO_ERROR
),
167 "Last error wrong! ERROR_INVALID_DATA/ERROR_BAD_PATHNAME (ME)/"
168 "NO_ERROR (95) expected, got 0x%08lx\n",
172 boolret
= GetFileVersionInfoA( "kernel32.dll", 0, retval
, pVersionInfo
);
173 ok (boolret
, "GetFileVersionInfoA failed: GetLastError = 0x%08lx\n", GetLastError());
177 boolret
= VerQueryValueA( pVersionInfo
, "\\", (LPVOID
*)&pFixedVersionInfo
, &uiLength
);
178 ok (boolret
, "VerQueryValueA failed: GetLastError = 0x%08lx\n", GetLastError());
182 dwlVersion
= (((DWORDLONG
)pFixedVersionInfo
->dwFileVersionMS
) << 32) +
183 pFixedVersionInfo
->dwFileVersionLS
;
185 VersionDwordLong2String(dwlVersion
, VersionString
);
187 trace("kernel32.dll version: %s\n", VersionString
);
190 /* this test crashes on WinNT4
192 boolret
= VerQueryValueA( pVersionInfo
, "\\", (LPVOID
*)&pFixedVersionInfo
, 0);
193 ok (boolret
, "VerQueryValue failed: GetLastError = 0x%08lx\n", GetLastError());