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 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
65 SetLastError(0xdeadbeef);
66 infoA.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA) / 2;
67 ret = GetVersionExA(&infoA);
68 ok(!ret, "Expected GetVersionExA to fail\n");
69 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
70 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
72 SetLastError(0xdeadbeef);
73 infoA.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA) * 2;
74 ret = GetVersionExA(&infoA);
75 ok(!ret, "Expected GetVersionExA to fail\n");
76 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
77 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
79 SetLastError(0xdeadbeef);
80 infoA.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
81 ret = GetVersionExA(&infoA);
82 ok(ret, "Expected GetVersionExA to succeed\n");
83 ok(GetLastError() == 0xdeadbeef,
84 "Expected 0xdeadbeef, got %d\n", GetLastError());
86 SetLastError(0xdeadbeef);
87 infoExA.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXA);
88 ret = GetVersionExA((OSVERSIONINFOA *)&infoExA);
89 ok(ret, "Expected GetVersionExA to succeed\n");
90 ok(GetLastError() == 0xdeadbeef,
91 "Expected 0xdeadbeef, got %d\n", GetLastError());
97 OSVERSIONINFOEX info = { sizeof(info) };
100 init_function_pointers();
104 if(!pVerifyVersionInfoA || !pVerSetConditionMask)
106 skip("Needed functions not available\n");
110 ret = pVerifyVersionInfoA(&info, VER_MAJORVERSION | VER_MINORVERSION,
111 pVerSetConditionMask(0, VER_MAJORVERSION, VER_GREATER_EQUAL));
112 ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
114 ret = pVerifyVersionInfoA(&info, VER_BUILDNUMBER | VER_MAJORVERSION |
115 VER_MINORVERSION/* | VER_PLATFORMID | VER_SERVICEPACKMAJOR |
116 VER_SERVICEPACKMINOR | VER_SUITENAME | VER_PRODUCT_TYPE */,
117 pVerSetConditionMask(0, VER_MAJORVERSION, VER_GREATER_EQUAL));
118 ok(!ret && (GetLastError() == ERROR_OLD_WIN_VERSION),
119 "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", GetLastError());
121 /* tests special handling of VER_SUITENAME */
123 ret = pVerifyVersionInfoA(&info, VER_SUITENAME,
124 pVerSetConditionMask(0, VER_SUITENAME, VER_AND));
125 ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
127 ret = pVerifyVersionInfoA(&info, VER_SUITENAME,
128 pVerSetConditionMask(0, VER_SUITENAME, VER_OR));
129 ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
131 /* test handling of version numbers */
133 /* v3.10 is always less than v4.x even
134 * if the minor version is tested */
135 info.dwMajorVersion = 3;
136 info.dwMinorVersion = 10;
137 ret = pVerifyVersionInfoA(&info, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
138 pVerSetConditionMask(pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL),
139 VER_MAJORVERSION, VER_GREATER_EQUAL));
140 ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
142 info.dwMinorVersion = 0;
143 info.wServicePackMajor = 10;
144 ret = pVerifyVersionInfoA(&info, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
145 pVerSetConditionMask(pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL),
146 VER_MAJORVERSION, VER_GREATER_EQUAL));
147 ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
149 info.wServicePackMajor = 0;
150 info.wServicePackMinor = 10;
151 ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
152 pVerSetConditionMask(pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL),
153 VER_MAJORVERSION, VER_GREATER_EQUAL));
154 ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
156 GetVersionEx((OSVERSIONINFO *)&info);
157 info.wServicePackMinor++;
158 ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
159 pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL));
160 ok(!ret && (GetLastError() == ERROR_OLD_WIN_VERSION),
161 "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", GetLastError());
163 GetVersionEx((OSVERSIONINFO *)&info);
164 info.wServicePackMajor--;
165 ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
166 pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER));
167 ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
169 GetVersionEx((OSVERSIONINFO *)&info);
170 info.wServicePackMajor--;
171 ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
172 pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL));
173 ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
175 GetVersionEx((OSVERSIONINFO *)&info);
176 info.wServicePackMajor++;
177 ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
178 pVerSetConditionMask(0, VER_MINORVERSION, VER_LESS));
179 ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
181 GetVersionEx((OSVERSIONINFO *)&info);
182 info.wServicePackMajor++;
183 ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
184 pVerSetConditionMask(0, VER_MINORVERSION, VER_LESS_EQUAL));
185 ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
187 GetVersionEx((OSVERSIONINFO *)&info);
188 info.wServicePackMajor--;
189 ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
190 pVerSetConditionMask(0, VER_MINORVERSION, VER_EQUAL));
191 ok(!ret && (GetLastError() == ERROR_OLD_WIN_VERSION),
192 "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", GetLastError());
194 /* test the failure hierarchy for the four version fields */
196 GetVersionEx((OSVERSIONINFO *)&info);
197 info.wServicePackMajor++;
198 ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
199 pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL));
200 ok(!ret && (GetLastError() == ERROR_OLD_WIN_VERSION),
201 "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", GetLastError());
203 GetVersionEx((OSVERSIONINFO *)&info);
204 info.dwMinorVersion++;
205 ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
206 pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL));
207 ok(!ret && (GetLastError() == ERROR_OLD_WIN_VERSION),
208 "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", GetLastError());
210 GetVersionEx((OSVERSIONINFO *)&info);
211 info.dwMajorVersion++;
212 ret = pVerifyVersionInfoA(&info, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
213 pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL));
214 ok(!ret && (GetLastError() == ERROR_OLD_WIN_VERSION),
215 "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", GetLastError());
217 ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
218 pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL));
219 ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
222 GetVersionEx((OSVERSIONINFO *)&info);
223 info.dwBuildNumber++;
224 ret = pVerifyVersionInfoA(&info, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
225 pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL));
226 ok(!ret && (GetLastError() == ERROR_OLD_WIN_VERSION),
227 "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", GetLastError());
229 ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
230 pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL));
231 ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
233 /* test bad dwOSVersionInfoSize */
234 GetVersionEx((OSVERSIONINFO *)&info);
235 info.dwOSVersionInfoSize = 0;
236 ret = pVerifyVersionInfoA(&info, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
237 pVerSetConditionMask(0, VER_MAJORVERSION, VER_GREATER_EQUAL));
238 ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());