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);
95 ok(ret, "Expected GetVersionExA to succeed\n");
96 ok(GetLastError() == 0xdeadbeef,
97 "Expected 0xdeadbeef, got %d\n", GetLastError());
100 static void test_VerifyVersionInfo(void)
102 OSVERSIONINFOEX info = { sizeof(info) };
105 if(!pVerifyVersionInfoA || !pVerSetConditionMask)
107 skip("Needed functions not available\n");
111 ret = pVerifyVersionInfoA(&info, VER_MAJORVERSION | VER_MINORVERSION,
112 pVerSetConditionMask(0, VER_MAJORVERSION, VER_GREATER_EQUAL));
113 ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
115 ret = pVerifyVersionInfoA(&info, VER_BUILDNUMBER | VER_MAJORVERSION |
116 VER_MINORVERSION/* | VER_PLATFORMID | VER_SERVICEPACKMAJOR |
117 VER_SERVICEPACKMINOR | VER_SUITENAME | VER_PRODUCT_TYPE */,
118 pVerSetConditionMask(0, VER_MAJORVERSION, VER_GREATER_EQUAL));
119 ok(!ret && (GetLastError() == ERROR_OLD_WIN_VERSION),
120 "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", GetLastError());
122 /* tests special handling of VER_SUITENAME */
124 ret = pVerifyVersionInfoA(&info, VER_SUITENAME,
125 pVerSetConditionMask(0, VER_SUITENAME, VER_AND));
126 ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
128 ret = pVerifyVersionInfoA(&info, VER_SUITENAME,
129 pVerSetConditionMask(0, VER_SUITENAME, VER_OR));
130 ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
132 /* test handling of version numbers */
134 /* v3.10 is always less than v4.x even
135 * if the minor version is tested */
136 info.dwMajorVersion = 3;
137 info.dwMinorVersion = 10;
138 ret = pVerifyVersionInfoA(&info, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
139 pVerSetConditionMask(pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL),
140 VER_MAJORVERSION, VER_GREATER_EQUAL));
141 ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
143 info.dwMinorVersion = 0;
144 info.wServicePackMajor = 10;
145 ret = pVerifyVersionInfoA(&info, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
146 pVerSetConditionMask(pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL),
147 VER_MAJORVERSION, VER_GREATER_EQUAL));
148 ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
150 info.wServicePackMajor = 0;
151 info.wServicePackMinor = 10;
152 ret = pVerifyVersionInfoA(&info, 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 GetVersionEx((OSVERSIONINFO *)&info);
158 info.wServicePackMinor++;
159 ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
160 pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL));
161 ok(!ret && (GetLastError() == ERROR_OLD_WIN_VERSION),
162 "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", GetLastError());
164 GetVersionEx((OSVERSIONINFO *)&info);
165 info.wServicePackMajor--;
166 ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
167 pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER));
168 ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
170 GetVersionEx((OSVERSIONINFO *)&info);
171 info.wServicePackMajor--;
172 ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
173 pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL));
174 ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
176 GetVersionEx((OSVERSIONINFO *)&info);
177 info.wServicePackMajor++;
178 ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
179 pVerSetConditionMask(0, VER_MINORVERSION, VER_LESS));
180 ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
182 GetVersionEx((OSVERSIONINFO *)&info);
183 info.wServicePackMajor++;
184 ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
185 pVerSetConditionMask(0, VER_MINORVERSION, VER_LESS_EQUAL));
186 ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
188 GetVersionEx((OSVERSIONINFO *)&info);
189 info.wServicePackMajor--;
190 ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
191 pVerSetConditionMask(0, VER_MINORVERSION, VER_EQUAL));
192 ok(!ret && (GetLastError() == ERROR_OLD_WIN_VERSION),
193 "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", GetLastError());
195 /* test the failure hierarchy for the four version fields */
197 GetVersionEx((OSVERSIONINFO *)&info);
198 info.wServicePackMajor++;
199 ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
200 pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL));
201 ok(!ret && (GetLastError() == ERROR_OLD_WIN_VERSION),
202 "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", GetLastError());
204 GetVersionEx((OSVERSIONINFO *)&info);
205 info.dwMinorVersion++;
206 ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
207 pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL));
208 ok(!ret && (GetLastError() == ERROR_OLD_WIN_VERSION),
209 "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", GetLastError());
211 GetVersionEx((OSVERSIONINFO *)&info);
212 info.dwMajorVersion++;
213 ret = pVerifyVersionInfoA(&info, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
214 pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL));
215 ok(!ret && (GetLastError() == ERROR_OLD_WIN_VERSION),
216 "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", GetLastError());
218 ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
219 pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL));
220 ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
223 GetVersionEx((OSVERSIONINFO *)&info);
224 info.dwBuildNumber++;
225 ret = pVerifyVersionInfoA(&info, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
226 pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL));
227 ok(!ret && (GetLastError() == ERROR_OLD_WIN_VERSION),
228 "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", GetLastError());
230 ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
231 pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL));
232 ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
234 /* test bad dwOSVersionInfoSize */
235 GetVersionEx((OSVERSIONINFO *)&info);
236 info.dwOSVersionInfoSize = 0;
237 ret = pVerifyVersionInfoA(&info, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
238 pVerSetConditionMask(0, VER_MAJORVERSION, VER_GREATER_EQUAL));
239 ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
244 init_function_pointers();
247 test_VerifyVersionInfo();