ReactOS 0.4.15-dev-8119-g4fb2fdb
version.c
Go to the documentation of this file.
1/*
2 * Unit test suite for version functions
3 *
4 * Copyright 2006 Robert Shearman
5 *
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.
10 *
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.
15 *
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
19 */
20
21#include "wine/test.h"
22#include "winbase.h"
23#include "winternl.h"
24
25static BOOL (WINAPI * pGetProductInfo)(DWORD, DWORD, DWORD, DWORD, DWORD *);
26static NTSTATUS (WINAPI * pRtlGetVersion)(RTL_OSVERSIONINFOEXW *);
27
28#define GET_PROC(func) \
29 p##func = (void *)GetProcAddress(hmod, #func);
30
31static void init_function_pointers(void)
32{
34
35 hmod = GetModuleHandleA("kernel32.dll");
36
37 GET_PROC(GetProductInfo);
38
39 hmod = GetModuleHandleA("ntdll.dll");
40
42}
43
44static void test_GetProductInfo(void)
45{
46 DWORD product;
47 DWORD res;
48 DWORD table[] = {9,8,7,6,
49 7,0,0,0,
50 6,2,0,0,
51 6,1,2,0,
52 6,1,1,0,
53 6,1,0,2,
54 6,1,0,0,
55 6,0,3,0,
56 6,0,2,0,
57 6,0,1,5,
58 6,0,1,0,
59 6,0,0,0,
60 5,3,0,0,
61 5,2,0,0,
62 5,1,0,0,
63 5,0,0,0,
64 0};
65
66 DWORD *entry = table;
67
68 if (!pGetProductInfo)
69 {
70 /* Not present before Vista */
71 win_skip("GetProductInfo() not available\n");
72 return;
73 }
74
75 while (*entry)
76 {
77 /* SetLastError() / GetLastError(): value is untouched */
78 product = 0xdeadbeef;
79 SetLastError(0xdeadbeef);
80 res = pGetProductInfo(entry[0], entry[1], entry[2], entry[3], &product);
81
82 if (entry[0] >= 6)
83 ok(res && (product > PRODUCT_UNDEFINED) && (product <= PRODUCT_ENTERPRISE_S_N_EVALUATION),
84 "got %d and 0x%x (expected TRUE and a valid PRODUCT_* value)\n", res, product);
85 else
86 ok(!res && !product && (GetLastError() == 0xdeadbeef),
87 "got %d and 0x%x with 0x%x (expected FALSE and PRODUCT_UNDEFINED with LastError untouched)\n",
88 res, product, GetLastError());
89
90 entry+= 4;
91 }
92
93 /* NULL pointer is not a problem */
94 SetLastError(0xdeadbeef);
95 res = pGetProductInfo(6, 1, 0, 0, NULL);
96 ok( (!res) && (GetLastError() == 0xdeadbeef),
97 "got %d with 0x%x (expected FALSE with LastError untouched\n", res, GetLastError());
98}
99
100static void test_GetVersionEx(void)
101{
103 OSVERSIONINFOEXA infoExA;
104 BOOL ret;
105
106 if (0)
107 {
108 /* Silently crashes on XP */
110 }
111
112 SetLastError(0xdeadbeef);
113 memset(&infoA,0,sizeof infoA);
115 ok(!ret, "Expected GetVersionExA to fail\n");
117 GetLastError() == 0xdeadbeef /* Win9x */,
118 "Expected ERROR_INSUFFICIENT_BUFFER or 0xdeadbeef (Win9x), got %d\n",
119 GetLastError());
120
121 SetLastError(0xdeadbeef);
122 infoA.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA) / 2;
124 ok(!ret, "Expected GetVersionExA to fail\n");
126 GetLastError() == 0xdeadbeef /* Win9x */,
127 "Expected ERROR_INSUFFICIENT_BUFFER or 0xdeadbeef (Win9x), got %d\n",
128 GetLastError());
129
130 SetLastError(0xdeadbeef);
131 infoA.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA) * 2;
133 ok(!ret, "Expected GetVersionExA to fail\n");
135 GetLastError() == 0xdeadbeef /* Win9x */,
136 "Expected ERROR_INSUFFICIENT_BUFFER or 0xdeadbeef (Win9x), got %d\n",
137 GetLastError());
138
139 SetLastError(0xdeadbeef);
140 infoA.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
142 ok(ret, "Expected GetVersionExA to succeed\n");
143 ok(GetLastError() == 0xdeadbeef,
144 "Expected 0xdeadbeef, got %d\n", GetLastError());
145
146 SetLastError(0xdeadbeef);
147 infoExA.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXA);
148 ret = GetVersionExA((OSVERSIONINFOA *)&infoExA);
149 ok(ret, "GetVersionExA failed.\n");
150
151 if (!infoExA.wServicePackMajor && !infoExA.wServicePackMinor)
152 ok(!infoExA.szCSDVersion[0], "got '%s'\n", infoExA.szCSDVersion);
153}
154
155static void test_VerifyVersionInfo(void)
156{
157 enum srcversion_mode
158 {
159 SRCVERSION_ZERO = 0,
160 SRCVERSION_CURRENT = 1,
161 SRCVERSION_INC_MINOR = 2,
162 SRCVERSION_INC_SP_MINOR = 3,
163 SRCVERSION_INC_SP_MAJOR = 4,
164 SRCVERSION_DEC_SP_MAJOR = 5,
165 SRCVERSION_DEC_MAJOR = 6,
166 SRCVERSION_INC_BUILD = 7,
167 SRCVERSION_REQUIRES_SP = 0x1000,
168 };
169
170 struct verify_version_test
171 {
172 DWORD verifymask; /* Type mask for VerifyVersionInfo() */
173 DWORD srcinfo; /* The way current version info is modified. */
174 DWORD err; /* Error code on failure, 0 on success. */
175
176 DWORD typemask1;
177 DWORD condition1;
178 DWORD typemask2;
179 DWORD condition2;
180 DWORD typemask3;
181 DWORD condition3;
182 DWORD typemask4;
183 DWORD condition4;
184
185 BOOL todo;
186 } verify_version_tests[] =
187 {
188 {
190 SRCVERSION_INC_MINOR,
191 0,
192
195 },
196 {
198 SRCVERSION_INC_MINOR,
200
203 },
204 {
206 SRCVERSION_CURRENT,
207 0,
208
211 },
212 {
214 SRCVERSION_CURRENT,
215 0,
216
219 },
220 {
222 SRCVERSION_INC_MINOR,
223 0,
224
227 },
228 {
230 SRCVERSION_INC_MINOR,
232
235 },
236 {
238 SRCVERSION_INC_MINOR,
240
243 },
244 {
246 SRCVERSION_INC_SP_MINOR,
248
251 },
252 {
254 SRCVERSION_INC_SP_MINOR,
256
259 },
260 {
262 SRCVERSION_INC_SP_MAJOR,
264
267 },
268 {
270 SRCVERSION_INC_SP_MINOR,
271 0,
272
275 },
276 {
278 SRCVERSION_INC_SP_MINOR,
280
283 },
284 {
286 SRCVERSION_INC_SP_MINOR,
287 0,
288
292 },
293 {
295 SRCVERSION_INC_SP_MINOR,
297
301 },
302 {
304 SRCVERSION_INC_SP_MINOR,
305 0,
306
311 },
312 {
314 SRCVERSION_INC_SP_MINOR,
316
321 },
322 {
324 SRCVERSION_INC_SP_MAJOR,
325 0,
326
329 },
330 {
332 SRCVERSION_INC_SP_MAJOR,
334
337 },
338 {
340 SRCVERSION_INC_SP_MAJOR,
342
345 },
346 {
348 SRCVERSION_INC_SP_MAJOR,
349 0,
350
353 },
354 {
356 SRCVERSION_INC_SP_MAJOR,
358
361 },
362 {
364 SRCVERSION_INC_SP_MAJOR,
365 0,
366
370 },
371 {
373 SRCVERSION_INC_SP_MAJOR,
375
378 },
379 {
381 SRCVERSION_DEC_MAJOR,
382 0,
383
386 },
387 {
389 SRCVERSION_CURRENT,
390 0,
391
394 },
395 {
397 SRCVERSION_INC_SP_MAJOR,
399
403 },
404 {
406 SRCVERSION_INC_SP_MAJOR,
408
412 },
413 {
415 SRCVERSION_INC_SP_MAJOR,
417
420 },
421 {
423 SRCVERSION_ZERO,
424 0,
425
427 },
428 {
430 SRCVERSION_ZERO,
432
434 },
435 {
437 SRCVERSION_ZERO,
438 0,
439
441 },
442 {
444 SRCVERSION_ZERO,
445 0,
446
448 },
449 {
451 SRCVERSION_INC_SP_MINOR,
453
455 },
456 {
458 SRCVERSION_INC_SP_MAJOR,
459 0,
460
462 },
463 {
465 SRCVERSION_INC_SP_MAJOR,
466 0,
467
469 },
470 {
472 SRCVERSION_INC_SP_MAJOR,
474
476 },
477 {
479 SRCVERSION_INC_SP_MAJOR,
481
483 },
484 {
486 SRCVERSION_INC_MINOR,
488
490 },
491 {
493 SRCVERSION_INC_MINOR,
495
497 },
498 {
500 SRCVERSION_CURRENT,
501 0,
502
504 },
505 {
507 SRCVERSION_INC_BUILD,
509
511 },
512 {
514 SRCVERSION_INC_BUILD,
515 0,
516
518 },
519 {
521 SRCVERSION_DEC_SP_MAJOR | SRCVERSION_REQUIRES_SP,
522 0,
523
525 },
526 {
528 SRCVERSION_DEC_SP_MAJOR | SRCVERSION_REQUIRES_SP,
529 0,
530
532 },
533 {
535 SRCVERSION_DEC_SP_MAJOR | SRCVERSION_REQUIRES_SP,
537
540 },
541 {
543 SRCVERSION_DEC_SP_MAJOR | SRCVERSION_REQUIRES_SP,
544 0,
545
549 },
550 {
552 SRCVERSION_DEC_SP_MAJOR | SRCVERSION_REQUIRES_SP,
553 0,
554
558 },
559 {
561 SRCVERSION_DEC_SP_MAJOR | SRCVERSION_REQUIRES_SP,
562 0,
563
567 },
568 {
570 SRCVERSION_DEC_SP_MAJOR | SRCVERSION_REQUIRES_SP,
572
575 },
576 };
577
579 DWORD servicepack;
580 unsigned int i;
581 BOOL ret;
582
583 /* Before we start doing some tests we should check what the version of
584 * the ServicePack is. Tests on a box with no ServicePack will fail otherwise.
585 */
586 info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXA);
588 servicepack = info.wServicePackMajor;
589 if (servicepack == 0)
590 skip("There is no ServicePack on this system. Some tests will be skipped.\n");
591
592 /* Win8.1+ returns Win8 version in GetVersionEx when there's no app manifest targeting 8.1 */
593 if (info.dwMajorVersion == 6 && info.dwMinorVersion == 2)
594 {
595 RTL_OSVERSIONINFOEXW rtlinfo;
597 ok(!pRtlGetVersion(&rtlinfo), "RtlGetVersion failed\n");
598
599 if (rtlinfo.dwMajorVersion != 6 || rtlinfo.dwMinorVersion != 2)
600 {
601 win_skip("GetVersionEx and VerifyVersionInfo are faking values\n");
602 return;
603 }
604 }
605
606 for (i = 0; i < sizeof(verify_version_tests)/sizeof(verify_version_tests[0]); i++)
607 {
608 struct verify_version_test *test = &verify_version_tests[i];
609 DWORD srcinfo = test->srcinfo;
611
612 if (servicepack == 0 && srcinfo & SRCVERSION_REQUIRES_SP)
613 continue;
614 srcinfo &= ~SRCVERSION_REQUIRES_SP;
615
616 info.dwOSVersionInfoSize = sizeof(info);
618
619 switch (srcinfo)
620 {
621 case SRCVERSION_ZERO:
622 memset(&info, 0, sizeof(info));
623 break;
624 case SRCVERSION_INC_MINOR:
625 info.dwMinorVersion++;
626 break;
627 case SRCVERSION_INC_SP_MINOR:
628 info.wServicePackMinor++;
629 break;
630 case SRCVERSION_INC_SP_MAJOR:
631 info.wServicePackMajor++;
632 break;
633 case SRCVERSION_DEC_SP_MAJOR:
634 info.wServicePackMajor--;
635 break;
636 case SRCVERSION_DEC_MAJOR:
637 info.dwMajorVersion--;
638 break;
639 case SRCVERSION_INC_BUILD:
640 info.dwBuildNumber++;
641 break;
642 default:
643 ;
644 }
645
646 mask = VerSetConditionMask(0, test->typemask1, test->condition1);
647 if (test->typemask2)
648 mask = VerSetConditionMask(mask, test->typemask2, test->condition2);
649 if (test->typemask3)
650 mask = VerSetConditionMask(mask, test->typemask3, test->condition3);
651 if (test->typemask4)
652 mask = VerSetConditionMask(mask, test->typemask4, test->condition4);
653
654 SetLastError(0xdeadbeef);
655 ret = VerifyVersionInfoA(&info, test->verifymask, mask);
656 todo_wine_if(test->todo)
657 {
658 ok(test->err ? !ret : ret, "%u: unexpected return value %d.\n", i, ret);
659 if (!ret)
660 ok(GetLastError() == test->err, "%u: unexpected error code %d, expected %d.\n", i, GetLastError(), test->err);
661 }
662 }
663
664 /* test handling of version numbers */
665 /* v3.10 is always less than v4.x even
666 * if the minor version is tested */
667 info.dwMajorVersion = 3;
668 info.dwMinorVersion = 10;
672 ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
673
674 info.dwMinorVersion = 0;
675 info.wServicePackMajor = 10;
679 ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
680
681 info.wServicePackMajor = 0;
682 info.wServicePackMinor = 10;
686 ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
687
688 /* test bad dwOSVersionInfoSize */
689 info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXA);
691 info.dwOSVersionInfoSize = 0;
694 ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
695}
696
698{
700
704}
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define START_TEST(x)
Definition: atltest.h:75
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
#define NULL
Definition: types.h:112
NTSTATUS NTAPI RtlGetVersion(IN OUT PRTL_OSVERSIONINFOW lpVersionInformation)
Definition: version.c:158
#define NTSTATUS
Definition: precomp.h:21
#define SetLastError(x)
Definition: compat.h:752
static const WCHAR version[]
Definition: asmname.c:66
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
BOOL WINAPI VerifyVersionInfoA(IN LPOSVERSIONINFOEXA lpVersionInformation, IN DWORD dwTypeMask, IN DWORDLONG dwlConditionMask)
Definition: version.c:161
BOOL WINAPI GetVersionExA(IN LPOSVERSIONINFOA lpVersionInformation)
Definition: version.c:69
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint res
Definition: glext.h:9613
GLenum GLint GLuint mask
Definition: glext.h:6028
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
uint32_t entry
Definition: isohybrid.c:63
static const SecPkgInfoA infoA
Definition: kerberos.c:302
static PEXPLICIT_ACCESSW *static HMODULE hmod
Definition: security.c:143
BOOL todo
Definition: filedlg.c:313
static void init_function_pointers(void)
Definition: version.c:31
static void test_VerifyVersionInfo(void)
Definition: version.c:155
static DWORD
Definition: version.c:25
#define GET_PROC(func)
Definition: version.c:28
static void test_GetVersionEx(void)
Definition: version.c:100
static void test_GetProductInfo(void)
Definition: version.c:44
#define todo_wine_if(is_todo)
Definition: custom.c:76
#define VER_AND
Definition: rtltypes.h:244
#define VER_OR
Definition: rtltypes.h:245
#define VER_SERVICEPACKMINOR
Definition: rtltypes.h:232
#define VER_LESS_EQUAL
Definition: rtltypes.h:243
#define VER_BUILDNUMBER
Definition: rtltypes.h:230
#define VER_SUITENAME
Definition: rtltypes.h:234
#define VER_EQUAL
Definition: rtltypes.h:239
#define VER_LESS
Definition: rtltypes.h:242
#define VER_GREATER
Definition: rtltypes.h:240
#define VER_MAJORVERSION
Definition: rtltypes.h:229
#define VER_GREATER_EQUAL
Definition: rtltypes.h:241
#define VER_MINORVERSION
Definition: rtltypes.h:228
#define VER_SERVICEPACKMAJOR
Definition: rtltypes.h:233
#define BOOL
Definition: nt_native.h:43
#define PRODUCT_ENTERPRISE_S_N_EVALUATION
#define PRODUCT_UNDEFINED
#define err(...)
#define test
Definition: rosglue.h:37
#define win_skip
Definition: test.h:163
#define memset(x, y, z)
Definition: compat.h:39
ULONGLONG NTAPI VerSetConditionMask(IN ULONGLONG ConditionMask, IN ULONG TypeMask, IN UCHAR Condition)
Definition: version.c:262
ULONG dwOSVersionInfoSize
Definition: rtltypes.h:255
USHORT wServicePackMajor
Definition: rtltypes.h:261
CHAR szCSDVersion[128]
Definition: rtltypes.h:260
USHORT wServicePackMinor
Definition: rtltypes.h:262
ULONG dwMajorVersion
Definition: rtltypes.h:270
ULONG dwMinorVersion
Definition: rtltypes.h:271
ULONG dwOSVersionInfoSize
Definition: rtltypes.h:269
uint64_t ULONGLONG
Definition: typedefs.h:67
int ret
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define WINAPI
Definition: msvc.h:6
#define ERROR_OLD_WIN_VERSION
Definition: winerror.h:672
struct _OSVERSIONINFOA OSVERSIONINFOA
struct _OSVERSIONINFOEXA OSVERSIONINFOEXA
struct _OSVERSIONINFOEXW RTL_OSVERSIONINFOEXW