ntdll: Suspend the process before attaching dlls, using the process initial context.
[wine.git] / dlls / kernel32 / tests / version.c
blob4182c06f5ce0cdbc04aa3b1cde1029fc0fbea242
1 /*
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
24 #include "wine/test.h"
25 #include "winbase.h"
26 #include "winternl.h"
28 static BOOL (WINAPI * pGetProductInfo)(DWORD, DWORD, DWORD, DWORD, DWORD *);
29 static BOOL (WINAPI * pVerifyVersionInfoA)(LPOSVERSIONINFOEXA, DWORD, DWORDLONG);
30 static ULONGLONG (WINAPI * pVerSetConditionMask)(ULONGLONG, DWORD, BYTE);
31 static NTSTATUS (WINAPI * pRtlGetVersion)(RTL_OSVERSIONINFOEXW *);
33 #define GET_PROC(func) \
34 p##func = (void *)GetProcAddress(hmod, #func);
36 static void init_function_pointers(void)
38 HMODULE hmod;
40 hmod = GetModuleHandleA("kernel32.dll");
42 GET_PROC(GetProductInfo);
43 GET_PROC(VerifyVersionInfoA);
44 GET_PROC(VerSetConditionMask);
46 hmod = GetModuleHandleA("ntdll.dll");
48 GET_PROC(RtlGetVersion);
51 static void test_GetProductInfo(void)
53 DWORD product;
54 DWORD res;
55 DWORD table[] = {9,8,7,6,
56 7,0,0,0,
57 6,2,0,0,
58 6,1,2,0,
59 6,1,1,0,
60 6,1,0,2,
61 6,1,0,0,
62 6,0,3,0,
63 6,0,2,0,
64 6,0,1,5,
65 6,0,1,0,
66 6,0,0,0,
67 5,3,0,0,
68 5,2,0,0,
69 5,1,0,0,
70 5,0,0,0,
71 0};
73 DWORD *entry = table;
75 if (!pGetProductInfo)
77 /* Not present before Vista */
78 win_skip("GetProductInfo() not available\n");
79 return;
82 while (*entry)
84 /* SetLastError() / GetLastError(): value is untouched */
85 product = 0xdeadbeef;
86 SetLastError(0xdeadbeef);
87 res = pGetProductInfo(entry[0], entry[1], entry[2], entry[3], &product);
89 if (entry[0] >= 6)
90 ok(res && (product > PRODUCT_UNDEFINED) && (product <= PRODUCT_PROFESSIONAL_WMC),
91 "got %d and 0x%x (expected TRUE and a valid PRODUCT_* value)\n", res, product);
92 else
93 ok(!res && !product && (GetLastError() == 0xdeadbeef),
94 "got %d and 0x%x with 0x%x (expected FALSE and PRODUCT_UNDEFINED with LastError untouched)\n",
95 res, product, GetLastError());
97 entry+= 4;
100 /* NULL pointer is not a problem */
101 SetLastError(0xdeadbeef);
102 res = pGetProductInfo(6, 1, 0, 0, NULL);
103 ok( (!res) && (GetLastError() == 0xdeadbeef),
104 "got %d with 0x%x (expected FALSE with LastError untouched\n", res, GetLastError());
107 static void test_GetVersionEx(void)
109 OSVERSIONINFOA infoA;
110 OSVERSIONINFOEXA infoExA;
111 BOOL ret;
113 if (0)
115 /* Silently crashes on XP */
116 GetVersionExA(NULL);
119 SetLastError(0xdeadbeef);
120 memset(&infoA,0,sizeof infoA);
121 ret = GetVersionExA(&infoA);
122 ok(!ret, "Expected GetVersionExA to fail\n");
123 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER ||
124 GetLastError() == 0xdeadbeef /* Win9x */,
125 "Expected ERROR_INSUFFICIENT_BUFFER or 0xdeadbeef (Win9x), got %d\n",
126 GetLastError());
128 SetLastError(0xdeadbeef);
129 infoA.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA) / 2;
130 ret = GetVersionExA(&infoA);
131 ok(!ret, "Expected GetVersionExA to fail\n");
132 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER ||
133 GetLastError() == 0xdeadbeef /* Win9x */,
134 "Expected ERROR_INSUFFICIENT_BUFFER or 0xdeadbeef (Win9x), got %d\n",
135 GetLastError());
137 SetLastError(0xdeadbeef);
138 infoA.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA) * 2;
139 ret = GetVersionExA(&infoA);
140 ok(!ret, "Expected GetVersionExA to fail\n");
141 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER ||
142 GetLastError() == 0xdeadbeef /* Win9x */,
143 "Expected ERROR_INSUFFICIENT_BUFFER or 0xdeadbeef (Win9x), got %d\n",
144 GetLastError());
146 SetLastError(0xdeadbeef);
147 infoA.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
148 ret = GetVersionExA(&infoA);
149 ok(ret, "Expected GetVersionExA to succeed\n");
150 ok(GetLastError() == 0xdeadbeef,
151 "Expected 0xdeadbeef, got %d\n", GetLastError());
153 SetLastError(0xdeadbeef);
154 infoExA.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXA);
155 ret = GetVersionExA((OSVERSIONINFOA *)&infoExA);
156 ok(ret ||
157 broken(ret == 0), /* win95 */
158 "Expected GetVersionExA to succeed\n");
160 if (!infoExA.wServicePackMajor && !infoExA.wServicePackMinor)
161 ok(!infoExA.szCSDVersion[0], "got '%s'\n", infoExA.szCSDVersion);
164 static void test_VerifyVersionInfo(void)
166 OSVERSIONINFOEXA info;
167 BOOL ret;
168 DWORD servicepack, error;
170 if(!pVerifyVersionInfoA || !pVerSetConditionMask)
172 win_skip("Needed functions not available\n");
173 return;
176 /* Before we start doing some tests we should check what the version of
177 * the ServicePack is. Tests on a box with no ServicePack will fail otherwise.
179 info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXA);
180 GetVersionExA((OSVERSIONINFOA *)&info);
181 servicepack = info.wServicePackMajor;
183 /* Win8.1+ returns Win8 version in GetVersionEx when there's no app manifest targeting 8.1 */
184 if (info.dwMajorVersion == 6 && info.dwMinorVersion == 2)
186 RTL_OSVERSIONINFOEXW rtlinfo;
187 rtlinfo.dwOSVersionInfoSize = sizeof(RTL_OSVERSIONINFOEXW);
188 ok(SUCCEEDED(pRtlGetVersion(&rtlinfo)), "RtlGetVersion failed\n");
190 if (rtlinfo.dwMajorVersion != 6 || rtlinfo.dwMinorVersion != 2)
192 win_skip("GetVersionEx and VerifyVersionInfo are faking values\n");
193 return;
197 memset(&info, 0, sizeof(info));
199 ret = pVerifyVersionInfoA(&info, VER_MAJORVERSION | VER_MINORVERSION,
200 pVerSetConditionMask(0, VER_MAJORVERSION, VER_GREATER_EQUAL));
201 ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
203 SetLastError(0xdeadbeef);
204 ret = pVerifyVersionInfoA(&info, VER_BUILDNUMBER | VER_MAJORVERSION |
205 VER_MINORVERSION/* | VER_PLATFORMID | VER_SERVICEPACKMAJOR |
206 VER_SERVICEPACKMINOR | VER_SUITENAME | VER_PRODUCT_TYPE */,
207 pVerSetConditionMask(0, VER_MAJORVERSION, VER_GREATER_EQUAL));
208 error = GetLastError();
209 ok(!ret, "VerifyVersionInfoA succeeded\n");
210 ok(error == ERROR_OLD_WIN_VERSION,
211 "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", error);
213 /* tests special handling of VER_SUITENAME */
215 ret = pVerifyVersionInfoA(&info, VER_SUITENAME,
216 pVerSetConditionMask(0, VER_SUITENAME, VER_AND));
217 ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
219 ret = pVerifyVersionInfoA(&info, VER_SUITENAME,
220 pVerSetConditionMask(0, VER_SUITENAME, VER_OR));
221 ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
223 /* test handling of version numbers */
225 /* v3.10 is always less than v4.x even
226 * if the minor version is tested */
227 info.dwMajorVersion = 3;
228 info.dwMinorVersion = 10;
229 ret = pVerifyVersionInfoA(&info, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
230 pVerSetConditionMask(pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL),
231 VER_MAJORVERSION, VER_GREATER_EQUAL));
232 ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
234 info.dwMinorVersion = 0;
235 info.wServicePackMajor = 10;
236 ret = pVerifyVersionInfoA(&info, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
237 pVerSetConditionMask(pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL),
238 VER_MAJORVERSION, VER_GREATER_EQUAL));
239 ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
241 info.wServicePackMajor = 0;
242 info.wServicePackMinor = 10;
243 ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
244 pVerSetConditionMask(pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL),
245 VER_MAJORVERSION, VER_GREATER_EQUAL));
246 ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
248 info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXA);
249 GetVersionExA((OSVERSIONINFOA *)&info);
250 info.wServicePackMinor++;
251 SetLastError(0xdeadbeef);
252 ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
253 pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL));
254 error = GetLastError();
255 ok(!ret, "VerifyVersionInfoA succeeded\n");
256 ok(error == ERROR_OLD_WIN_VERSION || broken(error == ERROR_BAD_ARGUMENTS) /* some wink2 */,
257 "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", error);
259 if (servicepack == 0)
261 skip("There is no ServicePack on this system\n");
263 else
265 info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXA);
266 GetVersionExA((OSVERSIONINFOA *)&info);
267 info.wServicePackMajor--;
268 ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
269 pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER));
270 ok(ret || broken(!ret) /* some win2k */, "VerifyVersionInfoA failed with error %d\n", GetLastError());
272 info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXA);
273 GetVersionExA((OSVERSIONINFOA *)&info);
274 info.wServicePackMajor--;
275 ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
276 pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL));
277 ok(ret || broken(!ret) /* some win2k */, "VerifyVersionInfoA failed with error %d\n", GetLastError());
280 info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXA);
281 GetVersionExA((OSVERSIONINFOA *)&info);
282 info.wServicePackMajor++;
283 ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
284 pVerSetConditionMask(0, VER_MINORVERSION, VER_LESS));
285 ok(ret || broken(!ret) /* some win2k */, "VerifyVersionInfoA failed with error %d\n", GetLastError());
287 info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXA);
288 GetVersionExA((OSVERSIONINFOA *)&info);
289 info.wServicePackMajor++;
290 ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
291 pVerSetConditionMask(0, VER_MINORVERSION, VER_LESS_EQUAL));
292 ok(ret || broken(!ret) /* some win2k */, "VerifyVersionInfoA failed with error %d\n", GetLastError());
294 info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXA);
295 GetVersionExA((OSVERSIONINFOA *)&info);
296 info.wServicePackMajor--;
297 SetLastError(0xdeadbeef);
298 ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
299 pVerSetConditionMask(0, VER_MINORVERSION, VER_EQUAL));
300 error = GetLastError();
301 ok(!ret, "VerifyVersionInfoA succeeded\n");
302 ok(error == ERROR_OLD_WIN_VERSION || broken(error == ERROR_BAD_ARGUMENTS) /* some win2k */,
303 "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", error);
305 /* test the failure hierarchy for the four version fields */
307 info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXA);
308 GetVersionExA((OSVERSIONINFOA *)&info);
309 info.wServicePackMajor++;
310 SetLastError(0xdeadbeef);
311 ret = pVerifyVersionInfoA(&info, 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 info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXA);
319 GetVersionExA((OSVERSIONINFOA *)&info);
320 info.dwMinorVersion++;
321 SetLastError(0xdeadbeef);
322 ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
323 pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL));
324 error = GetLastError();
325 ok(!ret, "VerifyVersionInfoA succeeded\n");
326 ok(error == ERROR_OLD_WIN_VERSION || broken(error == ERROR_BAD_ARGUMENTS) /* some win2k */,
327 "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", error);
329 info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXA);
330 GetVersionExA((OSVERSIONINFOA *)&info);
331 info.dwMajorVersion++;
332 SetLastError(0xdeadbeef);
333 ret = pVerifyVersionInfoA(&info, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
334 pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL));
335 error = GetLastError();
336 ok(!ret, "VerifyVersionInfoA succeeded\n");
337 ok(error == ERROR_OLD_WIN_VERSION || broken(error == ERROR_BAD_ARGUMENTS) /* some win2k */,
338 "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", error);
340 ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
341 pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL));
342 ok(ret || broken(!ret) /* some win2k */, "VerifyVersionInfoA failed with error %d\n", GetLastError());
344 info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXA);
345 GetVersionExA((OSVERSIONINFOA *)&info);
346 info.dwBuildNumber++;
347 SetLastError(0xdeadbeef);
348 ret = pVerifyVersionInfoA(&info, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
349 pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL));
350 error = GetLastError();
351 ok(!ret, "VerifyVersionInfoA succeeded\n");
352 ok(error == ERROR_OLD_WIN_VERSION || broken(error == ERROR_BAD_ARGUMENTS) /* some win2k */,
353 "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", error);
355 ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
356 pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL));
357 ok(ret || broken(!ret) /* some win2k */, "VerifyVersionInfoA failed with error %d\n", GetLastError());
359 /* test bad dwOSVersionInfoSize */
360 info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXA);
361 GetVersionExA((OSVERSIONINFOA *)&info);
362 info.dwOSVersionInfoSize = 0;
363 ret = pVerifyVersionInfoA(&info, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
364 pVerSetConditionMask(0, VER_MAJORVERSION, VER_GREATER_EQUAL));
365 ok(ret || broken(!ret) /* some win2k */, "VerifyVersionInfoA failed with error %d\n", GetLastError());
368 START_TEST(version)
370 init_function_pointers();
372 test_GetProductInfo();
373 test_GetVersionEx();
374 test_VerifyVersionInfo();