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
23 #include "wine/test.h"
26 static BOOL (WINAPI
* pVerifyVersionInfoA
)(LPOSVERSIONINFOEXA
, DWORD
, DWORDLONG
);
27 static ULONGLONG (WINAPI
* pVerSetConditionMask
)(ULONGLONG
, DWORD
, BYTE
);
29 #define KERNEL32_GET_PROC(func) \
30 p##func = (void *)GetProcAddress(hKernel32, #func); \
31 if(!p##func) trace("GetProcAddress(hKernel32, '%s') failed\n", #func);
33 static void init_function_pointers(void)
37 pVerifyVersionInfoA
= NULL
;
38 pVerSetConditionMask
= NULL
;
40 hKernel32
= GetModuleHandleA("kernel32.dll");
42 KERNEL32_GET_PROC(VerifyVersionInfoA
);
43 KERNEL32_GET_PROC(VerSetConditionMask
);
46 static void test_GetVersionEx(void)
49 OSVERSIONINFOEXA infoExA
;
54 /* Silently crashes on XP */
55 ret
= GetVersionExA(NULL
);
58 SetLastError(0xdeadbeef);
59 memset(&infoA
,0,sizeof infoA
);
60 ret
= GetVersionExA(&infoA
);
61 ok(!ret
, "Expected GetVersionExA to fail\n");
62 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
||
63 GetLastError() == 0xdeadbeef /* Win9x */,
64 "Expected ERROR_INSUFFICIENT_BUFFER or 0xdeadbeef (Win9x), got %d\n",
67 SetLastError(0xdeadbeef);
68 infoA
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOA
) / 2;
69 ret
= GetVersionExA(&infoA
);
70 ok(!ret
, "Expected GetVersionExA to fail\n");
71 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
||
72 GetLastError() == 0xdeadbeef /* Win9x */,
73 "Expected ERROR_INSUFFICIENT_BUFFER or 0xdeadbeef (Win9x), got %d\n",
76 SetLastError(0xdeadbeef);
77 infoA
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOA
) * 2;
78 ret
= GetVersionExA(&infoA
);
79 ok(!ret
, "Expected GetVersionExA to fail\n");
80 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
||
81 GetLastError() == 0xdeadbeef /* Win9x */,
82 "Expected ERROR_INSUFFICIENT_BUFFER or 0xdeadbeef (Win9x), got %d\n",
85 SetLastError(0xdeadbeef);
86 infoA
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOA
);
87 ret
= GetVersionExA(&infoA
);
88 ok(ret
, "Expected GetVersionExA to succeed\n");
89 ok(GetLastError() == 0xdeadbeef,
90 "Expected 0xdeadbeef, got %d\n", GetLastError());
92 SetLastError(0xdeadbeef);
93 infoExA
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEXA
);
94 ret
= GetVersionExA((OSVERSIONINFOA
*)&infoExA
);
96 broken(ret
== 0), /* win95 */
97 "Expected GetVersionExA to succeed\n");
98 ok(GetLastError() == 0xdeadbeef,
99 "Expected 0xdeadbeef, got %d\n", GetLastError());
102 static void test_VerifyVersionInfo(void)
104 OSVERSIONINFOEX info
;
106 DWORD servicepack
, error
;
108 if(!pVerifyVersionInfoA
|| !pVerSetConditionMask
)
110 win_skip("Needed functions not available\n");
114 /* Before we start doing some tests we should check what the version of
115 * the ServicePack is. Tests on a box with no ServicePack will fail otherwise.
117 info
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEX
);
118 GetVersionExA((OSVERSIONINFO
*)&info
);
119 servicepack
= info
.wServicePackMajor
;
120 memset(&info
, 0, sizeof(info
));
122 ret
= pVerifyVersionInfoA(&info
, VER_MAJORVERSION
| VER_MINORVERSION
,
123 pVerSetConditionMask(0, VER_MAJORVERSION
, VER_GREATER_EQUAL
));
124 ok(ret
, "VerifyVersionInfoA failed with error %d\n", GetLastError());
126 SetLastError(0xdeadbeef);
127 ret
= pVerifyVersionInfoA(&info
, VER_BUILDNUMBER
| VER_MAJORVERSION
|
128 VER_MINORVERSION
/* | VER_PLATFORMID | VER_SERVICEPACKMAJOR |
129 VER_SERVICEPACKMINOR | VER_SUITENAME | VER_PRODUCT_TYPE */,
130 pVerSetConditionMask(0, VER_MAJORVERSION
, VER_GREATER_EQUAL
));
131 error
= GetLastError();
132 ok(!ret
, "VerifyVersionInfoA succeeded\n");
133 ok(error
== ERROR_OLD_WIN_VERSION
,
134 "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", error
);
136 /* tests special handling of VER_SUITENAME */
138 ret
= pVerifyVersionInfoA(&info
, VER_SUITENAME
,
139 pVerSetConditionMask(0, VER_SUITENAME
, VER_AND
));
140 ok(ret
, "VerifyVersionInfoA failed with error %d\n", GetLastError());
142 ret
= pVerifyVersionInfoA(&info
, VER_SUITENAME
,
143 pVerSetConditionMask(0, VER_SUITENAME
, VER_OR
));
144 ok(ret
, "VerifyVersionInfoA failed with error %d\n", GetLastError());
146 /* test handling of version numbers */
148 /* v3.10 is always less than v4.x even
149 * if the minor version is tested */
150 info
.dwMajorVersion
= 3;
151 info
.dwMinorVersion
= 10;
152 ret
= pVerifyVersionInfoA(&info
, VER_MAJORVERSION
| VER_MINORVERSION
| VER_SERVICEPACKMAJOR
| VER_SERVICEPACKMINOR
,
153 pVerSetConditionMask(pVerSetConditionMask(0, VER_MINORVERSION
, VER_GREATER_EQUAL
),
154 VER_MAJORVERSION
, VER_GREATER_EQUAL
));
155 ok(ret
, "VerifyVersionInfoA failed with error %d\n", GetLastError());
157 info
.dwMinorVersion
= 0;
158 info
.wServicePackMajor
= 10;
159 ret
= pVerifyVersionInfoA(&info
, VER_MAJORVERSION
| VER_MINORVERSION
| VER_SERVICEPACKMAJOR
| VER_SERVICEPACKMINOR
,
160 pVerSetConditionMask(pVerSetConditionMask(0, VER_MINORVERSION
, VER_GREATER_EQUAL
),
161 VER_MAJORVERSION
, VER_GREATER_EQUAL
));
162 ok(ret
, "VerifyVersionInfoA failed with error %d\n", GetLastError());
164 info
.wServicePackMajor
= 0;
165 info
.wServicePackMinor
= 10;
166 ret
= pVerifyVersionInfoA(&info
, VER_MINORVERSION
| VER_SERVICEPACKMAJOR
| VER_SERVICEPACKMINOR
,
167 pVerSetConditionMask(pVerSetConditionMask(0, VER_MINORVERSION
, VER_GREATER_EQUAL
),
168 VER_MAJORVERSION
, VER_GREATER_EQUAL
));
170 info
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEX
);
171 GetVersionEx((OSVERSIONINFO
*)&info
);
172 info
.wServicePackMinor
++;
173 SetLastError(0xdeadbeef);
174 ret
= pVerifyVersionInfoA(&info
, VER_MINORVERSION
| VER_SERVICEPACKMAJOR
| VER_SERVICEPACKMINOR
,
175 pVerSetConditionMask(0, VER_MINORVERSION
, VER_GREATER_EQUAL
));
176 error
= GetLastError();
177 ok(!ret
, "VerifyVersionInfoA succeeded\n");
178 ok(error
== ERROR_OLD_WIN_VERSION
|| broken(error
== ERROR_BAD_ARGUMENTS
) /* some wink2 */,
179 "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", error
);
181 if (servicepack
== 0)
183 skip("There is no ServicePack on this system\n");
187 info
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEX
);
188 GetVersionEx((OSVERSIONINFO
*)&info
);
189 info
.wServicePackMajor
--;
190 ret
= pVerifyVersionInfoA(&info
, VER_MINORVERSION
| VER_SERVICEPACKMAJOR
| VER_SERVICEPACKMINOR
,
191 pVerSetConditionMask(0, VER_MINORVERSION
, VER_GREATER
));
192 ok(ret
|| broken(!ret
) /* some win2k */, "VerifyVersionInfoA failed with error %d\n", GetLastError());
194 info
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEX
);
195 GetVersionEx((OSVERSIONINFO
*)&info
);
196 info
.wServicePackMajor
--;
197 ret
= pVerifyVersionInfoA(&info
, VER_MINORVERSION
| VER_SERVICEPACKMAJOR
| VER_SERVICEPACKMINOR
,
198 pVerSetConditionMask(0, VER_MINORVERSION
, VER_GREATER_EQUAL
));
199 ok(ret
|| broken(!ret
) /* some win2k */, "VerifyVersionInfoA failed with error %d\n", GetLastError());
202 info
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEX
);
203 GetVersionEx((OSVERSIONINFO
*)&info
);
204 info
.wServicePackMajor
++;
205 ret
= pVerifyVersionInfoA(&info
, VER_MINORVERSION
| VER_SERVICEPACKMAJOR
| VER_SERVICEPACKMINOR
,
206 pVerSetConditionMask(0, VER_MINORVERSION
, VER_LESS
));
207 ok(ret
|| broken(!ret
) /* some win2k */, "VerifyVersionInfoA failed with error %d\n", GetLastError());
209 info
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEX
);
210 GetVersionEx((OSVERSIONINFO
*)&info
);
211 info
.wServicePackMajor
++;
212 ret
= pVerifyVersionInfoA(&info
, VER_MINORVERSION
| VER_SERVICEPACKMAJOR
| VER_SERVICEPACKMINOR
,
213 pVerSetConditionMask(0, VER_MINORVERSION
, VER_LESS_EQUAL
));
214 ok(ret
|| broken(!ret
) /* some win2k */, "VerifyVersionInfoA failed with error %d\n", GetLastError());
216 info
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEX
);
217 GetVersionEx((OSVERSIONINFO
*)&info
);
218 info
.wServicePackMajor
--;
219 SetLastError(0xdeadbeef);
220 ret
= pVerifyVersionInfoA(&info
, VER_MINORVERSION
| VER_SERVICEPACKMAJOR
| VER_SERVICEPACKMINOR
,
221 pVerSetConditionMask(0, VER_MINORVERSION
, VER_EQUAL
));
222 error
= GetLastError();
223 ok(!ret
, "VerifyVersionInfoA succeeded\n");
224 ok(error
== ERROR_OLD_WIN_VERSION
|| broken(error
== ERROR_BAD_ARGUMENTS
) /* some win2k */,
225 "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", error
);
227 /* test the failure hierarchy for the four version fields */
229 info
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEX
);
230 GetVersionEx((OSVERSIONINFO
*)&info
);
231 info
.wServicePackMajor
++;
232 SetLastError(0xdeadbeef);
233 ret
= pVerifyVersionInfoA(&info
, VER_MINORVERSION
| VER_SERVICEPACKMAJOR
| VER_SERVICEPACKMINOR
,
234 pVerSetConditionMask(0, VER_MINORVERSION
, VER_GREATER_EQUAL
));
235 error
= GetLastError();
236 ok(!ret
, "VerifyVersionInfoA succeeded\n");
237 ok(error
== ERROR_OLD_WIN_VERSION
|| broken(error
== ERROR_BAD_ARGUMENTS
) /* some win2k */,
238 "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", error
);
240 info
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEX
);
241 GetVersionEx((OSVERSIONINFO
*)&info
);
242 info
.dwMinorVersion
++;
243 SetLastError(0xdeadbeef);
244 ret
= pVerifyVersionInfoA(&info
, VER_MINORVERSION
| VER_SERVICEPACKMAJOR
| VER_SERVICEPACKMINOR
,
245 pVerSetConditionMask(0, VER_MINORVERSION
, VER_GREATER_EQUAL
));
246 error
= GetLastError();
247 ok(!ret
, "VerifyVersionInfoA succeeded\n");
248 ok(error
== ERROR_OLD_WIN_VERSION
|| broken(error
== ERROR_BAD_ARGUMENTS
) /* some win2k */,
249 "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", error
);
251 info
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEX
);
252 GetVersionEx((OSVERSIONINFO
*)&info
);
253 info
.dwMajorVersion
++;
254 SetLastError(0xdeadbeef);
255 ret
= pVerifyVersionInfoA(&info
, VER_MAJORVERSION
| VER_MINORVERSION
| VER_SERVICEPACKMAJOR
| VER_SERVICEPACKMINOR
,
256 pVerSetConditionMask(0, VER_MINORVERSION
, VER_GREATER_EQUAL
));
257 error
= GetLastError();
258 ok(!ret
, "VerifyVersionInfoA succeeded\n");
259 ok(error
== ERROR_OLD_WIN_VERSION
|| broken(error
== ERROR_BAD_ARGUMENTS
) /* some win2k */,
260 "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", error
);
262 ret
= pVerifyVersionInfoA(&info
, VER_MINORVERSION
| VER_SERVICEPACKMAJOR
| VER_SERVICEPACKMINOR
,
263 pVerSetConditionMask(0, VER_MINORVERSION
, VER_GREATER_EQUAL
));
264 ok(ret
|| broken(!ret
) /* some win2k */, "VerifyVersionInfoA failed with error %d\n", GetLastError());
266 info
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEX
);
267 GetVersionEx((OSVERSIONINFO
*)&info
);
268 info
.dwBuildNumber
++;
269 SetLastError(0xdeadbeef);
270 ret
= pVerifyVersionInfoA(&info
, VER_MAJORVERSION
| VER_MINORVERSION
| VER_SERVICEPACKMAJOR
| VER_SERVICEPACKMINOR
,
271 pVerSetConditionMask(0, VER_MINORVERSION
, VER_GREATER_EQUAL
));
272 error
= GetLastError();
273 ok(!ret
, "VerifyVersionInfoA succeeded\n");
274 ok(error
== ERROR_OLD_WIN_VERSION
|| broken(error
== ERROR_BAD_ARGUMENTS
) /* some win2k */,
275 "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", error
);
277 ret
= pVerifyVersionInfoA(&info
, VER_MINORVERSION
| VER_SERVICEPACKMAJOR
| VER_SERVICEPACKMINOR
,
278 pVerSetConditionMask(0, VER_MINORVERSION
, VER_GREATER_EQUAL
));
279 ok(ret
|| broken(!ret
) /* some win2k */, "VerifyVersionInfoA failed with error %d\n", GetLastError());
281 /* test bad dwOSVersionInfoSize */
282 info
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEX
);
283 GetVersionEx((OSVERSIONINFO
*)&info
);
284 info
.dwOSVersionInfoSize
= 0;
285 ret
= pVerifyVersionInfoA(&info
, VER_MAJORVERSION
| VER_MINORVERSION
| VER_SERVICEPACKMAJOR
| VER_SERVICEPACKMINOR
,
286 pVerSetConditionMask(0, VER_MAJORVERSION
, VER_GREATER_EQUAL
));
287 ok(ret
|| broken(!ret
) /* some win2k */, "VerifyVersionInfoA failed with error %d\n", GetLastError());
292 init_function_pointers();
295 test_VerifyVersionInfo();