2 * Unit test suite for version functions
4 * Copyright 2006 Robert Shearman
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 /* Needed for PRODUCT_* defines and GetProductInfo() */
22 #define _WIN32_WINNT 0x0600
26 #include "wine/test.h"
29 static BOOL (WINAPI
* pGetProductInfo
)(DWORD
, DWORD
, DWORD
, DWORD
, DWORD
*);
30 static BOOL (WINAPI
* pVerifyVersionInfoA
)(LPOSVERSIONINFOEXA
, DWORD
, DWORDLONG
);
31 static ULONGLONG (WINAPI
* pVerSetConditionMask
)(ULONGLONG
, DWORD
, BYTE
);
33 #define KERNEL32_GET_PROC(func) \
34 p##func = (void *)GetProcAddress(hKernel32, #func);
36 static void init_function_pointers(void)
40 hKernel32
= GetModuleHandleA("kernel32.dll");
42 KERNEL32_GET_PROC(GetProductInfo
);
43 KERNEL32_GET_PROC(VerifyVersionInfoA
);
44 KERNEL32_GET_PROC(VerSetConditionMask
);
47 static void test_GetProductInfo(void)
51 DWORD table
[] = {9,8,7,6,
73 /* Not present before Vista */
74 win_skip("GetProductInfo() not available\n");
80 /* SetLastError() / GetLastError(): value is untouched */
82 SetLastError(0xdeadbeef);
83 res
= pGetProductInfo(entry
[0], entry
[1], entry
[2], entry
[3], &product
);
86 ok(res
&& (product
> PRODUCT_UNDEFINED
) && (product
<= PRODUCT_PROFESSIONAL_WMC
),
87 "got %d and 0x%x (expected TRUE and a valid PRODUCT_* value)\n", res
, product
);
89 ok(!res
&& !product
&& (GetLastError() == 0xdeadbeef),
90 "got %d and 0x%x with 0x%x (expected FALSE and PRODUCT_UNDEFINED with LastError untouched)\n",
91 res
, product
, GetLastError());
96 /* NULL pointer is not a problem */
97 SetLastError(0xdeadbeef);
98 res
= pGetProductInfo(6, 1, 0, 0, NULL
);
99 ok( (!res
) && (GetLastError() == 0xdeadbeef),
100 "got %d with 0x%x (expected FALSE with LastError untouched\n", res
, GetLastError());
103 static void test_GetVersionEx(void)
105 OSVERSIONINFOA infoA
;
106 OSVERSIONINFOEXA infoExA
;
111 /* Silently crashes on XP */
115 SetLastError(0xdeadbeef);
116 memset(&infoA
,0,sizeof infoA
);
117 ret
= GetVersionExA(&infoA
);
118 ok(!ret
, "Expected GetVersionExA to fail\n");
119 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
||
120 GetLastError() == 0xdeadbeef /* Win9x */,
121 "Expected ERROR_INSUFFICIENT_BUFFER or 0xdeadbeef (Win9x), got %d\n",
124 SetLastError(0xdeadbeef);
125 infoA
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOA
) / 2;
126 ret
= GetVersionExA(&infoA
);
127 ok(!ret
, "Expected GetVersionExA to fail\n");
128 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
||
129 GetLastError() == 0xdeadbeef /* Win9x */,
130 "Expected ERROR_INSUFFICIENT_BUFFER or 0xdeadbeef (Win9x), got %d\n",
133 SetLastError(0xdeadbeef);
134 infoA
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOA
) * 2;
135 ret
= GetVersionExA(&infoA
);
136 ok(!ret
, "Expected GetVersionExA to fail\n");
137 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
||
138 GetLastError() == 0xdeadbeef /* Win9x */,
139 "Expected ERROR_INSUFFICIENT_BUFFER or 0xdeadbeef (Win9x), got %d\n",
142 SetLastError(0xdeadbeef);
143 infoA
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOA
);
144 ret
= GetVersionExA(&infoA
);
145 ok(ret
, "Expected GetVersionExA to succeed\n");
146 ok(GetLastError() == 0xdeadbeef,
147 "Expected 0xdeadbeef, got %d\n", GetLastError());
149 SetLastError(0xdeadbeef);
150 infoExA
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEXA
);
151 ret
= GetVersionExA((OSVERSIONINFOA
*)&infoExA
);
153 broken(ret
== 0), /* win95 */
154 "Expected GetVersionExA to succeed\n");
157 static void test_VerifyVersionInfo(void)
159 OSVERSIONINFOEX info
;
161 DWORD servicepack
, error
;
163 if(!pVerifyVersionInfoA
|| !pVerSetConditionMask
)
165 win_skip("Needed functions not available\n");
169 /* Before we start doing some tests we should check what the version of
170 * the ServicePack is. Tests on a box with no ServicePack will fail otherwise.
172 info
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEX
);
173 GetVersionExA((OSVERSIONINFO
*)&info
);
174 servicepack
= info
.wServicePackMajor
;
175 memset(&info
, 0, sizeof(info
));
177 ret
= pVerifyVersionInfoA(&info
, VER_MAJORVERSION
| VER_MINORVERSION
,
178 pVerSetConditionMask(0, VER_MAJORVERSION
, VER_GREATER_EQUAL
));
179 ok(ret
, "VerifyVersionInfoA failed with error %d\n", GetLastError());
181 SetLastError(0xdeadbeef);
182 ret
= pVerifyVersionInfoA(&info
, VER_BUILDNUMBER
| VER_MAJORVERSION
|
183 VER_MINORVERSION
/* | VER_PLATFORMID | VER_SERVICEPACKMAJOR |
184 VER_SERVICEPACKMINOR | VER_SUITENAME | VER_PRODUCT_TYPE */,
185 pVerSetConditionMask(0, VER_MAJORVERSION
, VER_GREATER_EQUAL
));
186 error
= GetLastError();
187 ok(!ret
, "VerifyVersionInfoA succeeded\n");
188 ok(error
== ERROR_OLD_WIN_VERSION
,
189 "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", error
);
191 /* tests special handling of VER_SUITENAME */
193 ret
= pVerifyVersionInfoA(&info
, VER_SUITENAME
,
194 pVerSetConditionMask(0, VER_SUITENAME
, VER_AND
));
195 ok(ret
, "VerifyVersionInfoA failed with error %d\n", GetLastError());
197 ret
= pVerifyVersionInfoA(&info
, VER_SUITENAME
,
198 pVerSetConditionMask(0, VER_SUITENAME
, VER_OR
));
199 ok(ret
, "VerifyVersionInfoA failed with error %d\n", GetLastError());
201 /* test handling of version numbers */
203 /* v3.10 is always less than v4.x even
204 * if the minor version is tested */
205 info
.dwMajorVersion
= 3;
206 info
.dwMinorVersion
= 10;
207 ret
= pVerifyVersionInfoA(&info
, VER_MAJORVERSION
| VER_MINORVERSION
| VER_SERVICEPACKMAJOR
| VER_SERVICEPACKMINOR
,
208 pVerSetConditionMask(pVerSetConditionMask(0, VER_MINORVERSION
, VER_GREATER_EQUAL
),
209 VER_MAJORVERSION
, VER_GREATER_EQUAL
));
210 ok(ret
, "VerifyVersionInfoA failed with error %d\n", GetLastError());
212 info
.dwMinorVersion
= 0;
213 info
.wServicePackMajor
= 10;
214 ret
= pVerifyVersionInfoA(&info
, VER_MAJORVERSION
| VER_MINORVERSION
| VER_SERVICEPACKMAJOR
| VER_SERVICEPACKMINOR
,
215 pVerSetConditionMask(pVerSetConditionMask(0, VER_MINORVERSION
, VER_GREATER_EQUAL
),
216 VER_MAJORVERSION
, VER_GREATER_EQUAL
));
217 ok(ret
, "VerifyVersionInfoA failed with error %d\n", GetLastError());
219 info
.wServicePackMajor
= 0;
220 info
.wServicePackMinor
= 10;
221 ret
= pVerifyVersionInfoA(&info
, VER_MINORVERSION
| VER_SERVICEPACKMAJOR
| VER_SERVICEPACKMINOR
,
222 pVerSetConditionMask(pVerSetConditionMask(0, VER_MINORVERSION
, VER_GREATER_EQUAL
),
223 VER_MAJORVERSION
, VER_GREATER_EQUAL
));
224 ok(ret
, "VerifyVersionInfoA failed with error %d\n", GetLastError());
226 info
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEX
);
227 GetVersionEx((OSVERSIONINFO
*)&info
);
228 info
.wServicePackMinor
++;
229 SetLastError(0xdeadbeef);
230 ret
= pVerifyVersionInfoA(&info
, VER_MINORVERSION
| VER_SERVICEPACKMAJOR
| VER_SERVICEPACKMINOR
,
231 pVerSetConditionMask(0, VER_MINORVERSION
, VER_GREATER_EQUAL
));
232 error
= GetLastError();
233 ok(!ret
, "VerifyVersionInfoA succeeded\n");
234 ok(error
== ERROR_OLD_WIN_VERSION
|| broken(error
== ERROR_BAD_ARGUMENTS
) /* some wink2 */,
235 "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", error
);
237 if (servicepack
== 0)
239 skip("There is no ServicePack on this system\n");
243 info
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEX
);
244 GetVersionEx((OSVERSIONINFO
*)&info
);
245 info
.wServicePackMajor
--;
246 ret
= pVerifyVersionInfoA(&info
, VER_MINORVERSION
| VER_SERVICEPACKMAJOR
| VER_SERVICEPACKMINOR
,
247 pVerSetConditionMask(0, VER_MINORVERSION
, VER_GREATER
));
248 ok(ret
|| broken(!ret
) /* some win2k */, "VerifyVersionInfoA failed with error %d\n", GetLastError());
250 info
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEX
);
251 GetVersionEx((OSVERSIONINFO
*)&info
);
252 info
.wServicePackMajor
--;
253 ret
= pVerifyVersionInfoA(&info
, VER_MINORVERSION
| VER_SERVICEPACKMAJOR
| VER_SERVICEPACKMINOR
,
254 pVerSetConditionMask(0, VER_MINORVERSION
, VER_GREATER_EQUAL
));
255 ok(ret
|| broken(!ret
) /* some win2k */, "VerifyVersionInfoA failed with error %d\n", GetLastError());
258 info
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEX
);
259 GetVersionEx((OSVERSIONINFO
*)&info
);
260 info
.wServicePackMajor
++;
261 ret
= pVerifyVersionInfoA(&info
, VER_MINORVERSION
| VER_SERVICEPACKMAJOR
| VER_SERVICEPACKMINOR
,
262 pVerSetConditionMask(0, VER_MINORVERSION
, VER_LESS
));
263 ok(ret
|| broken(!ret
) /* some win2k */, "VerifyVersionInfoA failed with error %d\n", GetLastError());
265 info
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEX
);
266 GetVersionEx((OSVERSIONINFO
*)&info
);
267 info
.wServicePackMajor
++;
268 ret
= pVerifyVersionInfoA(&info
, VER_MINORVERSION
| VER_SERVICEPACKMAJOR
| VER_SERVICEPACKMINOR
,
269 pVerSetConditionMask(0, VER_MINORVERSION
, VER_LESS_EQUAL
));
270 ok(ret
|| broken(!ret
) /* some win2k */, "VerifyVersionInfoA failed with error %d\n", GetLastError());
272 info
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEX
);
273 GetVersionEx((OSVERSIONINFO
*)&info
);
274 info
.wServicePackMajor
--;
275 SetLastError(0xdeadbeef);
276 ret
= pVerifyVersionInfoA(&info
, VER_MINORVERSION
| VER_SERVICEPACKMAJOR
| VER_SERVICEPACKMINOR
,
277 pVerSetConditionMask(0, VER_MINORVERSION
, VER_EQUAL
));
278 error
= GetLastError();
279 ok(!ret
, "VerifyVersionInfoA succeeded\n");
280 ok(error
== ERROR_OLD_WIN_VERSION
|| broken(error
== ERROR_BAD_ARGUMENTS
) /* some win2k */,
281 "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", error
);
283 /* test the failure hierarchy for the four version fields */
285 info
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEX
);
286 GetVersionEx((OSVERSIONINFO
*)&info
);
287 info
.wServicePackMajor
++;
288 SetLastError(0xdeadbeef);
289 ret
= pVerifyVersionInfoA(&info
, VER_MINORVERSION
| VER_SERVICEPACKMAJOR
| VER_SERVICEPACKMINOR
,
290 pVerSetConditionMask(0, VER_MINORVERSION
, VER_GREATER_EQUAL
));
291 error
= GetLastError();
292 ok(!ret
, "VerifyVersionInfoA succeeded\n");
293 ok(error
== ERROR_OLD_WIN_VERSION
|| broken(error
== ERROR_BAD_ARGUMENTS
) /* some win2k */,
294 "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", error
);
296 info
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEX
);
297 GetVersionEx((OSVERSIONINFO
*)&info
);
298 info
.dwMinorVersion
++;
299 SetLastError(0xdeadbeef);
300 ret
= pVerifyVersionInfoA(&info
, VER_MINORVERSION
| VER_SERVICEPACKMAJOR
| VER_SERVICEPACKMINOR
,
301 pVerSetConditionMask(0, VER_MINORVERSION
, VER_GREATER_EQUAL
));
302 error
= GetLastError();
303 ok(!ret
, "VerifyVersionInfoA succeeded\n");
304 ok(error
== ERROR_OLD_WIN_VERSION
|| broken(error
== ERROR_BAD_ARGUMENTS
) /* some win2k */,
305 "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", error
);
307 info
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEX
);
308 GetVersionEx((OSVERSIONINFO
*)&info
);
309 info
.dwMajorVersion
++;
310 SetLastError(0xdeadbeef);
311 ret
= pVerifyVersionInfoA(&info
, VER_MAJORVERSION
| VER_MINORVERSION
| VER_SERVICEPACKMAJOR
| VER_SERVICEPACKMINOR
,
312 pVerSetConditionMask(0, VER_MINORVERSION
, VER_GREATER_EQUAL
));
313 error
= GetLastError();
314 ok(!ret
, "VerifyVersionInfoA succeeded\n");
315 ok(error
== ERROR_OLD_WIN_VERSION
|| broken(error
== ERROR_BAD_ARGUMENTS
) /* some win2k */,
316 "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", error
);
318 ret
= pVerifyVersionInfoA(&info
, VER_MINORVERSION
| VER_SERVICEPACKMAJOR
| VER_SERVICEPACKMINOR
,
319 pVerSetConditionMask(0, VER_MINORVERSION
, VER_GREATER_EQUAL
));
320 ok(ret
|| broken(!ret
) /* some win2k */, "VerifyVersionInfoA failed with error %d\n", GetLastError());
322 info
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEX
);
323 GetVersionEx((OSVERSIONINFO
*)&info
);
324 info
.dwBuildNumber
++;
325 SetLastError(0xdeadbeef);
326 ret
= pVerifyVersionInfoA(&info
, VER_MAJORVERSION
| VER_MINORVERSION
| VER_SERVICEPACKMAJOR
| VER_SERVICEPACKMINOR
,
327 pVerSetConditionMask(0, VER_MINORVERSION
, VER_GREATER_EQUAL
));
328 error
= GetLastError();
329 ok(!ret
, "VerifyVersionInfoA succeeded\n");
330 ok(error
== ERROR_OLD_WIN_VERSION
|| broken(error
== ERROR_BAD_ARGUMENTS
) /* some win2k */,
331 "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", error
);
333 ret
= pVerifyVersionInfoA(&info
, VER_MINORVERSION
| VER_SERVICEPACKMAJOR
| VER_SERVICEPACKMINOR
,
334 pVerSetConditionMask(0, VER_MINORVERSION
, VER_GREATER_EQUAL
));
335 ok(ret
|| broken(!ret
) /* some win2k */, "VerifyVersionInfoA failed with error %d\n", GetLastError());
337 /* test bad dwOSVersionInfoSize */
338 info
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEX
);
339 GetVersionEx((OSVERSIONINFO
*)&info
);
340 info
.dwOSVersionInfoSize
= 0;
341 ret
= pVerifyVersionInfoA(&info
, VER_MAJORVERSION
| VER_MINORVERSION
| VER_SERVICEPACKMAJOR
| VER_SERVICEPACKMINOR
,
342 pVerSetConditionMask(0, VER_MAJORVERSION
, VER_GREATER_EQUAL
));
343 ok(ret
|| broken(!ret
) /* some win2k */, "VerifyVersionInfoA failed with error %d\n", GetLastError());
348 init_function_pointers();
350 test_GetProductInfo();
352 test_VerifyVersionInfo();