Handle wParam in WM_PAINT properly: if non-null, it is the hdc we are
[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
49     SetLastError(MY_LAST_ERROR);
50     retval = GetFileVersionInfoSizeA( NULL, NULL);
51     ok( !retval,
52         "GetFileVersionInfoSizeA result wrong! 0L expected, got 0x%08lx\n",
53         retval);
54     EXPECT_INVALID__NOT_FOUND;
55
56     hdl = 0x55555555;
57     SetLastError(MY_LAST_ERROR);
58     retval = GetFileVersionInfoSizeA( NULL, &hdl);
59     ok( !retval,
60         "GetFileVersionInfoSizeA result wrong! 0L expected, got 0x%08lx\n",
61         retval);
62     EXPECT_INVALID__NOT_FOUND;
63     ok( hdl == 0L,
64         "Handle wrong! 0L expected, got 0x%08lx\n", hdl);
65
66     SetLastError(MY_LAST_ERROR);
67     retval = GetFileVersionInfoSizeA( "", NULL);
68     ok( !retval,
69         "GetFileVersionInfoSizeA result wrong! 0L expected, got 0x%08lx\n",
70         retval);
71     EXPECT_BAD_PATH__NOT_FOUND;
72
73     hdl = 0x55555555;
74     SetLastError(MY_LAST_ERROR);
75     retval = GetFileVersionInfoSizeA( "", &hdl);
76     ok( !retval,
77         "GetFileVersionInfoSizeA result wrong! 0L expected, got 0x%08lx\n",
78         retval);
79     EXPECT_BAD_PATH__NOT_FOUND;
80     ok( hdl == 0L,
81         "Handle wrong! 0L expected, got 0x%08lx\n", hdl);
82
83     SetLastError(MY_LAST_ERROR);
84     retval = GetFileVersionInfoSizeA( "kernel32.dll", NULL);
85     ok( retval,
86         "GetFileVersionInfoSizeA result wrong! <> 0L expected, got 0x%08lx\n",
87         retval);
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());
91
92     hdl = 0x55555555;
93     SetLastError(MY_LAST_ERROR);
94     retval = GetFileVersionInfoSizeA( "kernel32.dll", &hdl);
95     ok( retval,
96         "GetFileVersionInfoSizeA result wrong! <> 0L expected, got 0x%08lx\n",
97         retval);
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());
101     ok( hdl == 0L,
102         "Handle wrong! 0L expected, got 0x%08lx\n", hdl);
103
104     SetLastError(MY_LAST_ERROR);
105     retval = GetFileVersionInfoSizeA( "notexist.dll", NULL);
106     ok( !retval,
107         "GetFileVersionInfoSizeA result wrong! 0L expected, got 0x%08lx\n",
108         retval);
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());
114 }
115
116 static void VersionDwordLong2String(DWORDLONG Version, LPSTR lpszVerString)
117 {
118     WORD a, b, c, d;
119
120     a = (WORD)(Version >> 48);
121     b = (WORD)((Version >> 32) & 0xffff);
122     c = (WORD)((Version >> 16) & 0xffff);
123     d = (WORD)(Version & 0xffff);
124
125     sprintf(lpszVerString, "%d.%d.%d.%d", a, b, c, d);
126
127     return;
128 }
129
130 static void test_info(void)
131 {
132     DWORD hdl, retval;
133     PVOID pVersionInfo = NULL;
134     BOOL boolret;
135     VS_FIXEDFILEINFO *pFixedVersionInfo;
136     UINT uiLength;
137     char VersionString[MAX_PATH];
138     DWORDLONG dwlVersion;
139
140     hdl = 0x55555555;
141     SetLastError(MY_LAST_ERROR);
142     retval = GetFileVersionInfoSizeA( "kernel32.dll", &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     if ( retval == 0 || hdl != 0)
153         return;
154
155     pVersionInfo = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, retval );
156     ok(pVersionInfo != 0, "HeapAlloc failed\n" );
157     if (pVersionInfo == 0)
158         return;
159
160 #if 0
161     /* this test crashes on WinNT4
162      */
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",
169         GetLastError());
170 #endif
171
172     boolret = GetFileVersionInfoA( "kernel32.dll", 0, retval, pVersionInfo );
173     ok (boolret, "GetFileVersionInfoA failed: GetLastError = 0x%08lx\n", GetLastError());
174     if (!boolret)
175         return;
176
177     boolret = VerQueryValueA( pVersionInfo, "\\", (LPVOID *)&pFixedVersionInfo, &uiLength );
178     ok (boolret, "VerQueryValueA failed: GetLastError = 0x%08lx\n", GetLastError());
179     if (!boolret)
180         return;
181
182     dwlVersion = (((DWORDLONG)pFixedVersionInfo->dwFileVersionMS) << 32) +
183         pFixedVersionInfo->dwFileVersionLS;
184
185     VersionDwordLong2String(dwlVersion, VersionString);
186
187     trace("kernel32.dll version: %s\n", VersionString);
188
189 #if 0
190     /* this test crashes on WinNT4
191      */
192     boolret = VerQueryValueA( pVersionInfo, "\\", (LPVOID *)&pFixedVersionInfo, 0);
193     ok (boolret, "VerQueryValue failed: GetLastError = 0x%08lx\n", GetLastError());
194 #endif
195 }
196
197 START_TEST(info)
198 {
199     test_info_size();
200     test_info();
201 }