Fixed a few prototypes in the USER driver.
[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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18
19 #include <stdarg.h>
20 #include <stdio.h>
21
22 #include "wine/test.h"
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winerror.h"
26 #include "winver.h"
27
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());
45
46 static void test_info_size(void)
47 {   DWORD hdl, retval;
48     char mypath[MAX_PATH] = "";
49
50     SetLastError(MY_LAST_ERROR);
51     retval = GetFileVersionInfoSizeA( NULL, NULL);
52     ok( !retval,
53         "GetFileVersionInfoSizeA result wrong! 0L expected, got 0x%08lx\n",
54         retval);
55     EXPECT_INVALID__NOT_FOUND;
56
57     hdl = 0x55555555;
58     SetLastError(MY_LAST_ERROR);
59     retval = GetFileVersionInfoSizeA( NULL, &hdl);
60     ok( !retval,
61         "GetFileVersionInfoSizeA result wrong! 0L expected, got 0x%08lx\n",
62         retval);
63     EXPECT_INVALID__NOT_FOUND;
64     ok( hdl == 0L,
65         "Handle wrong! 0L expected, got 0x%08lx\n", hdl);
66
67     SetLastError(MY_LAST_ERROR);
68     retval = GetFileVersionInfoSizeA( "", NULL);
69     ok( !retval,
70         "GetFileVersionInfoSizeA result wrong! 0L expected, got 0x%08lx\n",
71         retval);
72     EXPECT_BAD_PATH__NOT_FOUND;
73
74     hdl = 0x55555555;
75     SetLastError(MY_LAST_ERROR);
76     retval = GetFileVersionInfoSizeA( "", &hdl);
77     ok( !retval,
78         "GetFileVersionInfoSizeA result wrong! 0L expected, got 0x%08lx\n",
79         retval);
80     EXPECT_BAD_PATH__NOT_FOUND;
81     ok( hdl == 0L,
82         "Handle wrong! 0L expected, got 0x%08lx\n", hdl);
83
84     SetLastError(MY_LAST_ERROR);
85     retval = GetFileVersionInfoSizeA( "kernel32.dll", NULL);
86     ok( retval,
87         "GetFileVersionInfoSizeA result wrong! <> 0L expected, got 0x%08lx\n",
88         retval);
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());
92
93     hdl = 0x55555555;
94     SetLastError(MY_LAST_ERROR);
95     retval = GetFileVersionInfoSizeA( "kernel32.dll", &hdl);
96     ok( retval,
97         "GetFileVersionInfoSizeA result wrong! <> 0L expected, got 0x%08lx\n",
98         retval);
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());
102     ok( hdl == 0L,
103         "Handle wrong! 0L expected, got 0x%08lx\n", hdl);
104
105     SetLastError(MY_LAST_ERROR);
106     retval = GetFileVersionInfoSizeA( "notexist.dll", NULL);
107     ok( !retval,
108         "GetFileVersionInfoSizeA result wrong! 0L expected, got 0x%08lx\n",
109         retval);
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());
115
116     /* test a currently loaded executable */
117     if(GetModuleFileNameA(NULL, mypath, MAX_PATH)) {
118         hdl = 0x55555555;
119         SetLastError(MY_LAST_ERROR);
120         retval = GetFileVersionInfoSizeA( mypath, &hdl);
121         ok( retval,
122             "GetFileVersionInfoSizeA result wrong! <> 0L expected, got 0x%08lx\n",
123             retval);
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());
127         ok( hdl == 0L,
128             "Handle wrong! 0L expected, got 0x%08lx\n", hdl);
129     }
130     else
131         trace("skipping GetModuleFileNameA(NULL,..) failed\n");
132
133     /* test a not loaded executable */
134     if(GetSystemDirectoryA(mypath, MAX_PATH)) {
135         lstrcatA(mypath, "\\regsvr32.exe");
136
137         if(INVALID_FILE_ATTRIBUTES == GetFileAttributesA(mypath))
138             trace("GetFileAttributesA(%s) failed\n", mypath);
139         else {
140             hdl = 0x55555555;
141             SetLastError(MY_LAST_ERROR);
142             retval = GetFileVersionInfoSizeA( mypath, &hdl);
143             ok( retval,
144                 "GetFileVersionInfoSizeA result wrong! <> 0L expected, got 0x%08lx\n",
145                 retval);
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());
149             ok( hdl == 0L,
150                 "Handle wrong! 0L expected, got 0x%08lx\n", hdl);
151         }
152     }
153     else
154         trace("skipping GetModuleFileNameA(NULL,..) failed\n");
155 }
156
157 static void VersionDwordLong2String(DWORDLONG Version, LPSTR lpszVerString)
158 {
159     WORD a, b, c, d;
160
161     a = (WORD)(Version >> 48);
162     b = (WORD)((Version >> 32) & 0xffff);
163     c = (WORD)((Version >> 16) & 0xffff);
164     d = (WORD)(Version & 0xffff);
165
166     sprintf(lpszVerString, "%d.%d.%d.%d", a, b, c, d);
167
168     return;
169 }
170
171 static void test_info(void)
172 {
173     DWORD hdl, retval;
174     PVOID pVersionInfo = NULL;
175     BOOL boolret;
176     VS_FIXEDFILEINFO *pFixedVersionInfo;
177     UINT uiLength;
178     char VersionString[MAX_PATH];
179     DWORDLONG dwlVersion;
180
181     hdl = 0x55555555;
182     SetLastError(MY_LAST_ERROR);
183     retval = GetFileVersionInfoSizeA( "kernel32.dll", &hdl);
184     ok( retval,
185         "GetFileVersionInfoSizeA result wrong! <> 0L expected, got 0x%08lx\n",
186         retval);
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());
190     ok( hdl == 0L,
191         "Handle wrong! 0L expected, got 0x%08lx\n", hdl);
192
193     if ( retval == 0 || hdl != 0)
194         return;
195
196     pVersionInfo = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, retval );
197     ok(pVersionInfo != 0, "HeapAlloc failed\n" );
198     if (pVersionInfo == 0)
199         return;
200
201 #if 0
202     /* this test crashes on WinNT4
203      */
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",
210         GetLastError());
211 #endif
212
213     boolret = GetFileVersionInfoA( "kernel32.dll", 0, retval, pVersionInfo );
214     ok (boolret, "GetFileVersionInfoA failed: GetLastError = 0x%08lx\n", GetLastError());
215     if (!boolret)
216         return;
217
218     boolret = VerQueryValueA( pVersionInfo, "\\", (LPVOID *)&pFixedVersionInfo, &uiLength );
219     ok (boolret, "VerQueryValueA failed: GetLastError = 0x%08lx\n", GetLastError());
220     if (!boolret)
221         return;
222
223     dwlVersion = (((DWORDLONG)pFixedVersionInfo->dwFileVersionMS) << 32) +
224         pFixedVersionInfo->dwFileVersionLS;
225
226     VersionDwordLong2String(dwlVersion, VersionString);
227
228     trace("kernel32.dll version: %s\n", VersionString);
229
230 #if 0
231     /* this test crashes on WinNT4
232      */
233     boolret = VerQueryValueA( pVersionInfo, "\\", (LPVOID *)&pFixedVersionInfo, 0);
234     ok (boolret, "VerQueryValue failed: GetLastError = 0x%08lx\n", GetLastError());
235 #endif
236 }
237
238 static void test_unicode(void)
239 {
240     DWORD hdlA, retvalA;
241     DWORD hdlW, retvalW;
242     BOOL retA,retW;
243     PVOID pVersionInfoA = NULL;
244     PVOID pVersionInfoW = NULL;
245     char mypathA[MAX_PATH] = "";
246     WCHAR mypathW[MAX_PATH];
247
248     /* If we call GetFileVersionInfoA on a system that supports Unicode (NT/W2K/XP/W2K3 by default)
249      * then the versioninfo will contain Unicode strings.
250      * Wine however always converts a VersionInfo32 to VersionInfo16 when called through GetFileVersionInfoA
251      * regardless of Windows version
252      * The test is to call both the A and W versions, which should have the same Version Information,
253      * on systems that support both calls.
254      */
255
256     /* First get the versioninfo via the W versions */
257     GetModuleFileNameW(NULL, mypathW, MAX_PATH);
258     if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
259     {
260         trace("GetModuleFileNameW not existing on this platform, skipping rest of test\n");
261         return;
262     }
263
264     retvalW = GetFileVersionInfoSizeW( mypathW, &hdlW);
265     pVersionInfoW = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, retvalW );
266     retW = GetFileVersionInfoW( mypathW, 0, retvalW, pVersionInfoW );
267
268     /* And now via the A versions */
269     GetModuleFileNameA(NULL, mypathA, MAX_PATH);
270     retvalA = GetFileVersionInfoSizeA( mypathA, &hdlA);
271     pVersionInfoA = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, retvalA );
272     retA = GetFileVersionInfoA( mypathA, 0, retvalA, pVersionInfoA );
273
274     ok( retvalA == retvalW, "The size of the struct should be the same for both A/W calls, it is (%ld) vs. (%ld)\n",
275                             retvalA, retvalW);
276
277     todo_wine
278     {
279         ok( !memcmp(pVersionInfoA, pVersionInfoW, retvalA), "Both structs should be the same, they aren't\n");
280     }
281
282     HeapFree( GetProcessHeap(), 0, pVersionInfoA);
283     HeapFree( GetProcessHeap(), 0, pVersionInfoW);
284 }
285
286 START_TEST(info)
287 {
288     test_info_size();
289     test_info();
290     test_unicode();
291 }