ReactOS  0.4.13-dev-52-g0efcfec
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 /* Needed for PRODUCT_* defines and GetProductInfo() */
22 #ifndef __REACTOS__
23 #define _WIN32_WINNT 0x0600
24 #endif
25 
26 #include "wine/test.h"
27 #include "winbase.h"
28 #include "winternl.h"
29 
30 static BOOL (WINAPI * pGetProductInfo)(DWORD, DWORD, DWORD, DWORD, DWORD *);
31 static NTSTATUS (WINAPI * pRtlGetVersion)(RTL_OSVERSIONINFOEXW *);
32 
33 #define GET_PROC(func) \
34  p##func = (void *)GetProcAddress(hmod, #func);
35 
36 static void init_function_pointers(void)
37 {
38  HMODULE hmod;
39 
40  hmod = GetModuleHandleA("kernel32.dll");
41 
42  GET_PROC(GetProductInfo);
43 
44  hmod = GetModuleHandleA("ntdll.dll");
45 
47 }
48 
49 static void test_GetProductInfo(void)
50 {
51  DWORD product;
52  DWORD res;
53  DWORD table[] = {9,8,7,6,
54  7,0,0,0,
55  6,2,0,0,
56  6,1,2,0,
57  6,1,1,0,
58  6,1,0,2,
59  6,1,0,0,
60  6,0,3,0,
61  6,0,2,0,
62  6,0,1,5,
63  6,0,1,0,
64  6,0,0,0,
65  5,3,0,0,
66  5,2,0,0,
67  5,1,0,0,
68  5,0,0,0,
69  0};
70 
71  DWORD *entry = table;
72 
73  if (!pGetProductInfo)
74  {
75  /* Not present before Vista */
76  win_skip("GetProductInfo() not available\n");
77  return;
78  }
79 
80  while (*entry)
81  {
82  /* SetLastError() / GetLastError(): value is untouched */
83  product = 0xdeadbeef;
84  SetLastError(0xdeadbeef);
85  res = pGetProductInfo(entry[0], entry[1], entry[2], entry[3], &product);
86 
87  if (entry[0] >= 6)
88  ok(res && (product > PRODUCT_UNDEFINED) && (product <= PRODUCT_ENTERPRISE_S_N_EVALUATION),
89  "got %d and 0x%x (expected TRUE and a valid PRODUCT_* value)\n", res, product);
90  else
91  ok(!res && !product && (GetLastError() == 0xdeadbeef),
92  "got %d and 0x%x with 0x%x (expected FALSE and PRODUCT_UNDEFINED with LastError untouched)\n",
93  res, product, GetLastError());
94 
95  entry+= 4;
96  }
97 
98  /* NULL pointer is not a problem */
99  SetLastError(0xdeadbeef);
100  res = pGetProductInfo(6, 1, 0, 0, NULL);
101  ok( (!res) && (GetLastError() == 0xdeadbeef),
102  "got %d with 0x%x (expected FALSE with LastError untouched\n", res, GetLastError());
103 }
104 
105 static void test_GetVersionEx(void)
106 {
108  OSVERSIONINFOEXA infoExA;
109  BOOL ret;
110 
111  if (0)
112  {
113  /* Silently crashes on XP */
115  }
116 
117  SetLastError(0xdeadbeef);
118  memset(&infoA,0,sizeof infoA);
119  ret = GetVersionExA(&infoA);
120  ok(!ret, "Expected GetVersionExA to fail\n");
122  GetLastError() == 0xdeadbeef /* Win9x */,
123  "Expected ERROR_INSUFFICIENT_BUFFER or 0xdeadbeef (Win9x), got %d\n",
124  GetLastError());
125 
126  SetLastError(0xdeadbeef);
127  infoA.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA) / 2;
128  ret = GetVersionExA(&infoA);
129  ok(!ret, "Expected GetVersionExA to fail\n");
131  GetLastError() == 0xdeadbeef /* Win9x */,
132  "Expected ERROR_INSUFFICIENT_BUFFER or 0xdeadbeef (Win9x), got %d\n",
133  GetLastError());
134 
135  SetLastError(0xdeadbeef);
136  infoA.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA) * 2;
137  ret = GetVersionExA(&infoA);
138  ok(!ret, "Expected GetVersionExA to fail\n");
140  GetLastError() == 0xdeadbeef /* Win9x */,
141  "Expected ERROR_INSUFFICIENT_BUFFER or 0xdeadbeef (Win9x), got %d\n",
142  GetLastError());
143 
144  SetLastError(0xdeadbeef);
145  infoA.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
146  ret = GetVersionExA(&infoA);
147  ok(ret, "Expected GetVersionExA to succeed\n");
148  ok(GetLastError() == 0xdeadbeef,
149  "Expected 0xdeadbeef, got %d\n", GetLastError());
150 
151  SetLastError(0xdeadbeef);
152  infoExA.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXA);
153  ret = GetVersionExA((OSVERSIONINFOA *)&infoExA);
154  ok(ret, "GetVersionExA failed.\n");
155 
156  if (!infoExA.wServicePackMajor && !infoExA.wServicePackMinor)
157  ok(!infoExA.szCSDVersion[0], "got '%s'\n", infoExA.szCSDVersion);
158 }
159 
160 static void test_VerifyVersionInfo(void)
161 {
162  enum srcversion_mode
163  {
164  SRCVERSION_ZERO = 0,
165  SRCVERSION_CURRENT = 1,
166  SRCVERSION_INC_MINOR = 2,
167  SRCVERSION_INC_SP_MINOR = 3,
168  SRCVERSION_INC_SP_MAJOR = 4,
169  SRCVERSION_DEC_SP_MAJOR = 5,
170  SRCVERSION_DEC_MAJOR = 6,
171  SRCVERSION_INC_BUILD = 7,
172  SRCVERSION_REQUIRES_SP = 0x1000,
173  };
174 
175  struct verify_version_test
176  {
177  DWORD verifymask; /* Type mask for VerifyVersionInfo() */
178  DWORD srcinfo; /* The way current version info is modified. */
179  DWORD err; /* Error code on failure, 0 on success. */
180 
181  DWORD typemask1;
182  DWORD condition1;
183  DWORD typemask2;
184  DWORD condition2;
185  DWORD typemask3;
186  DWORD condition3;
187  DWORD typemask4;
188  DWORD condition4;
189 
190  BOOL todo;
191  } verify_version_tests[] =
192  {
193  {
195  SRCVERSION_INC_MINOR,
196  0,
197 
200  },
201  {
203  SRCVERSION_INC_MINOR,
205 
208  },
209  {
211  SRCVERSION_CURRENT,
212  0,
213 
216  },
217  {
219  SRCVERSION_CURRENT,
220  0,
221 
224  },
225  {
227  SRCVERSION_INC_MINOR,
228  0,
229 
232  },
233  {
235  SRCVERSION_INC_MINOR,
237 
240  },
241  {
243  SRCVERSION_INC_MINOR,
245 
248  },
249  {
251  SRCVERSION_INC_SP_MINOR,
253 
256  },
257  {
259  SRCVERSION_INC_SP_MINOR,
261 
264  },
265  {
267  SRCVERSION_INC_SP_MAJOR,
269 
272  },
273  {
275  SRCVERSION_INC_SP_MINOR,
276  0,
277 
280  },
281  {
283  SRCVERSION_INC_SP_MINOR,
285 
288  },
289  {
291  SRCVERSION_INC_SP_MINOR,
292  0,
293 
297  },
298  {
300  SRCVERSION_INC_SP_MINOR,
302 
306  },
307  {
309  SRCVERSION_INC_SP_MINOR,
310  0,
311 
316  },
317  {
319  SRCVERSION_INC_SP_MINOR,
321 
326  },
327  {
329  SRCVERSION_INC_SP_MAJOR,
330  0,
331 
334  },
335  {
337  SRCVERSION_INC_SP_MAJOR,
339 
342  },
343  {
345  SRCVERSION_INC_SP_MAJOR,
347 
350  },
351  {
353  SRCVERSION_INC_SP_MAJOR,
354  0,
355 
358  },
359  {
361  SRCVERSION_INC_SP_MAJOR,
363 
366  },
367  {
369  SRCVERSION_INC_SP_MAJOR,
370  0,
371 
375  },
376  {
378  SRCVERSION_INC_SP_MAJOR,
380 
383  },
384  {
386  SRCVERSION_DEC_MAJOR,
387  0,
388 
391  },
392  {
394  SRCVERSION_CURRENT,
395  0,
396 
399  },
400  {
402  SRCVERSION_INC_SP_MAJOR,
404 
408  },
409  {
411  SRCVERSION_INC_SP_MAJOR,
413 
417  },
418  {
420  SRCVERSION_INC_SP_MAJOR,
422 
425  },
426  {
428  SRCVERSION_ZERO,
429  0,
430 
432  },
433  {
435  SRCVERSION_ZERO,
437 
439  },
440  {
442  SRCVERSION_ZERO,
443  0,
444 
446  },
447  {
449  SRCVERSION_ZERO,
450  0,
451 
453  },
454  {
456  SRCVERSION_INC_SP_MINOR,
458 
460  },
461  {
463  SRCVERSION_INC_SP_MAJOR,
464  0,
465 
467  },
468  {
470  SRCVERSION_INC_SP_MAJOR,
471  0,
472 
474  },
475  {
477  SRCVERSION_INC_SP_MAJOR,
479 
481  },
482  {
484  SRCVERSION_INC_SP_MAJOR,
486 
488  },
489  {
491  SRCVERSION_INC_MINOR,
493 
495  },
496  {
498  SRCVERSION_INC_MINOR,
500 
502  },
503  {
505  SRCVERSION_CURRENT,
506  0,
507 
509  },
510  {
512  SRCVERSION_INC_BUILD,
514 
516  },
517  {
519  SRCVERSION_INC_BUILD,
520  0,
521 
523  },
524  {
526  SRCVERSION_DEC_SP_MAJOR | SRCVERSION_REQUIRES_SP,
527  0,
528 
530  },
531  {
533  SRCVERSION_DEC_SP_MAJOR | SRCVERSION_REQUIRES_SP,
534  0,
535 
537  },
538  {
540  SRCVERSION_DEC_SP_MAJOR | SRCVERSION_REQUIRES_SP,
542 
545  },
546  {
548  SRCVERSION_DEC_SP_MAJOR | SRCVERSION_REQUIRES_SP,
549  0,
550 
554  },
555  {
557  SRCVERSION_DEC_SP_MAJOR | SRCVERSION_REQUIRES_SP,
558  0,
559 
563  },
564  {
566  SRCVERSION_DEC_SP_MAJOR | SRCVERSION_REQUIRES_SP,
567  0,
568 
572  },
573  {
575  SRCVERSION_DEC_SP_MAJOR | SRCVERSION_REQUIRES_SP,
577 
580  },
581  };
582 
584  DWORD servicepack;
585  unsigned int i;
586  BOOL ret;
587 
588  /* Before we start doing some tests we should check what the version of
589  * the ServicePack is. Tests on a box with no ServicePack will fail otherwise.
590  */
591  info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXA);
593  servicepack = info.wServicePackMajor;
594  if (servicepack == 0)
595  skip("There is no ServicePack on this system. Some tests will be skipped.\n");
596 
597  /* Win8.1+ returns Win8 version in GetVersionEx when there's no app manifest targeting 8.1 */
598  if (info.dwMajorVersion == 6 && info.dwMinorVersion == 2)
599  {
600  RTL_OSVERSIONINFOEXW rtlinfo;
601  rtlinfo.dwOSVersionInfoSize = sizeof(RTL_OSVERSIONINFOEXW);
602  ok(!pRtlGetVersion(&rtlinfo), "RtlGetVersion failed\n");
603 
604  if (rtlinfo.dwMajorVersion != 6 || rtlinfo.dwMinorVersion != 2)
605  {
606  win_skip("GetVersionEx and VerifyVersionInfo are faking values\n");
607  return;
608  }
609  }
610 
611  for (i = 0; i < sizeof(verify_version_tests)/sizeof(verify_version_tests[0]); i++)
612  {
613  struct verify_version_test *test = &verify_version_tests[i];
614  DWORD srcinfo = test->srcinfo;
615  ULONGLONG mask;
616 
617  if (servicepack == 0 && srcinfo & SRCVERSION_REQUIRES_SP)
618  continue;
619  srcinfo &= ~SRCVERSION_REQUIRES_SP;
620 
621  info.dwOSVersionInfoSize = sizeof(info);
623 
624  switch (srcinfo)
625  {
626  case SRCVERSION_ZERO:
627  memset(&info, 0, sizeof(info));
628  break;
629  case SRCVERSION_INC_MINOR:
630  info.dwMinorVersion++;
631  break;
632  case SRCVERSION_INC_SP_MINOR:
633  info.wServicePackMinor++;
634  break;
635  case SRCVERSION_INC_SP_MAJOR:
636  info.wServicePackMajor++;
637  break;
638  case SRCVERSION_DEC_SP_MAJOR:
639  info.wServicePackMajor--;
640  break;
641  case SRCVERSION_DEC_MAJOR:
642  info.dwMajorVersion--;
643  break;
644  case SRCVERSION_INC_BUILD:
645  info.dwBuildNumber++;
646  break;
647  default:
648  ;
649  }
650 
651  mask = VerSetConditionMask(0, test->typemask1, test->condition1);
652  if (test->typemask2)
653  mask = VerSetConditionMask(mask, test->typemask2, test->condition2);
654  if (test->typemask3)
655  mask = VerSetConditionMask(mask, test->typemask3, test->condition3);
656  if (test->typemask4)
657  mask = VerSetConditionMask(mask, test->typemask4, test->condition4);
658 
659  SetLastError(0xdeadbeef);
660  ret = VerifyVersionInfoA(&info, test->verifymask, mask);
661  todo_wine_if(test->todo)
662  {
663  ok(test->err ? !ret : ret, "%u: unexpected return value %d.\n", i, ret);
664  if (!ret)
665  ok(GetLastError() == test->err, "%u: unexpected error code %d, expected %d.\n", i, GetLastError(), test->err);
666  }
667  }
668 
669  /* test handling of version numbers */
670  /* v3.10 is always less than v4.x even
671  * if the minor version is tested */
672  info.dwMajorVersion = 3;
673  info.dwMinorVersion = 10;
677  ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
678 
679  info.dwMinorVersion = 0;
680  info.wServicePackMajor = 10;
684  ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
685 
686  info.wServicePackMajor = 0;
687  info.wServicePackMinor = 10;
691  ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
692 
693  /* test bad dwOSVersionInfoSize */
694  info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXA);
696  info.dwOSVersionInfoSize = 0;
699  ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
700 }
701 
703 {
705 
709 }
#define PRODUCT_ENTERPRISE_S_N_EVALUATION
#define VER_MINORVERSION
Definition: rtltypes.h:226
ULONG dwOSVersionInfoSize
Definition: rtltypes.h:265
static DWORD
Definition: version.c:30
#define VER_SUITENAME
Definition: rtltypes.h:232
#define VER_AND
Definition: rtltypes.h:242
#define PRODUCT_UNDEFINED
ULONGLONG NTAPI VerSetConditionMask(IN ULONGLONG ConditionMask, IN ULONG TypeMask, IN UCHAR Condition)
Definition: version.c:262
#define VER_BUILDNUMBER
Definition: rtltypes.h:228
NTSTATUS NTAPI RtlGetVersion(IN OUT PRTL_OSVERSIONINFOW lpVersionInformation)
Definition: version.c:158
static void init_function_pointers(void)
Definition: version.c:36
ULONG dwMinorVersion
Definition: rtltypes.h:267
static const SecPkgInfoA infoA
Definition: kerberos.c:302
uint8_t entry
Definition: isohybrid.c:63
BOOL todo
Definition: filedlg.c:313
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
GLenum GLsizei GLenum GLenum const GLvoid * table
Definition: glext.h:5644
#define test
Definition: rosglue.h:37
BOOL WINAPI VerifyVersionInfoA(IN LPOSVERSIONINFOEXA lpVersionInformation, IN DWORD dwTypeMask, IN DWORDLONG dwlConditionMask)
Definition: version.c:161
struct _test_info info[]
Definition: SetCursorPos.c:19
ULONG dwMajorVersion
Definition: rtltypes.h:266
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
GLenum GLint GLuint mask
Definition: glext.h:6028
unsigned int BOOL
Definition: ntddk_ex.h:94
#define ok(value,...)
smooth NULL
Definition: ftsmooth.c:416
struct _OSVERSIONINFOEXW RTL_OSVERSIONINFOEXW
static const WCHAR version[]
Definition: asmname.c:64
#define VER_LESS_EQUAL
Definition: rtltypes.h:241
BOOL WINAPI GetVersionExA(IN LPOSVERSIONINFOA lpVersionInformation)
Definition: version.c:69
struct _OSVERSIONINFOEXA OSVERSIONINFOEXA
#define VER_OR
Definition: rtltypes.h:243
#define todo_wine_if(is_todo)
Definition: test.h:155
#define VER_EQUAL
Definition: rtltypes.h:237
ULONG dwOSVersionInfoSize
Definition: rtltypes.h:251
uint64_t ULONGLONG
Definition: typedefs.h:65
#define VER_MAJORVERSION
Definition: rtltypes.h:227
#define WINAPI
Definition: msvc.h:8
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:409
int ret
#define VER_SERVICEPACKMAJOR
Definition: rtltypes.h:231
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:819
#define err(...)
#define VER_GREATER
Definition: rtltypes.h:238
static PEXPLICIT_ACCESSW *static HMODULE hmod
Definition: security.c:141
#define VER_GREATER_EQUAL
Definition: rtltypes.h:239
struct _OSVERSIONINFOA OSVERSIONINFOA
static void test_GetVersionEx(void)
Definition: version.c:105
#define VER_SERVICEPACKMINOR
Definition: rtltypes.h:230
#define GET_PROC(func)
Definition: version.c:33
static void test_VerifyVersionInfo(void)
Definition: version.c:160
#define skip(...)
#define ERROR_OLD_WIN_VERSION
Definition: winerror.h:672
GLuint res
Definition: glext.h:9613
CHAR szCSDVersion[128]
Definition: rtltypes.h:238
static void test_GetProductInfo(void)
Definition: version.c:49
#define memset(x, y, z)
Definition: compat.h:39
static BOOL(WINAPI *pGetProductInfo)(DWORD
#define win_skip
Definition: test.h:141
static DWORD *static NTSTATUS(WINAPI *pRtlGetVersion)(RTL_OSVERSIONINFOEXW *)
START_TEST(version)
Definition: version.c:702
#define VER_LESS
Definition: rtltypes.h:240
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10