kernel32: No longer init the terminfo database nor application key mode when 0 or...
[wine] / dlls / kernel32 / tests / version.c
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 <assert.h>
22
23 #include "wine/test.h"
24 #include "winbase.h"
25
26 static BOOL (WINAPI * pVerifyVersionInfoA)(LPOSVERSIONINFOEXA, DWORD, DWORDLONG);
27 static ULONGLONG (WINAPI * pVerSetConditionMask)(ULONGLONG, DWORD, BYTE);
28
29 #define KERNEL32_GET_PROC(func)                                     \
30     p##func = (void *)GetProcAddress(hKernel32, #func);             \
31     if(!p##func) trace("GetProcAddress(hKernel32, '%s') failed\n", #func);
32
33 static void init_function_pointers(void)
34 {
35     HMODULE hKernel32;
36
37     pVerifyVersionInfoA = NULL;
38     pVerSetConditionMask = NULL;
39
40     hKernel32 = GetModuleHandleA("kernel32.dll");
41     assert(hKernel32);
42     KERNEL32_GET_PROC(VerifyVersionInfoA);
43     KERNEL32_GET_PROC(VerSetConditionMask);
44 }
45
46 static void test_GetVersionEx(void)
47 {
48     OSVERSIONINFOA infoA;
49     OSVERSIONINFOEXA infoExA;
50     BOOL ret;
51
52     if (0)
53     {
54         /* Silently crashes on XP */
55         ret = GetVersionExA(NULL);
56     }
57
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",
65         GetLastError());
66
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",
74         GetLastError());
75
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",
83         GetLastError());
84
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());
91
92     SetLastError(0xdeadbeef);
93     infoExA.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXA);
94     ret = GetVersionExA((OSVERSIONINFOA *)&infoExA);
95     ok(ret ||
96        broken(ret == 0), /* win95 */
97        "Expected GetVersionExA to succeed\n");
98     ok(GetLastError() == 0xdeadbeef,
99         "Expected 0xdeadbeef, got %d\n", GetLastError());
100 }
101
102 static void test_VerifyVersionInfo(void)
103 {
104     OSVERSIONINFOEX info;
105     BOOL ret;
106     DWORD servicepack, error;
107
108     if(!pVerifyVersionInfoA || !pVerSetConditionMask)
109     {
110         win_skip("Needed functions not available\n");
111         return;
112     }
113
114     /* Before we start doing some tests we should check what the version of
115      * the ServicePack is. Tests on a box with no ServicePack will fail otherwise.
116      */
117     info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
118     GetVersionExA((OSVERSIONINFO *)&info);
119     servicepack = info.wServicePackMajor;
120     memset(&info, 0, sizeof(info));
121
122     ret = pVerifyVersionInfoA(&info, VER_MAJORVERSION | VER_MINORVERSION,
123         pVerSetConditionMask(0, VER_MAJORVERSION, VER_GREATER_EQUAL));
124     ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
125
126     SetLastError(0xdeadbeef);
127     ret = pVerifyVersionInfoA(&info, VER_BUILDNUMBER | VER_MAJORVERSION |
128         VER_MINORVERSION/* | VER_PLATFORMID | VER_SERVICEPACKMAJOR |
129         VER_SERVICEPACKMINOR | VER_SUITENAME | VER_PRODUCT_TYPE */,
130         pVerSetConditionMask(0, VER_MAJORVERSION, VER_GREATER_EQUAL));
131     error = GetLastError();
132     ok(!ret, "VerifyVersionInfoA succeeded\n");
133     ok(error == ERROR_OLD_WIN_VERSION,
134        "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", error);
135
136     /* tests special handling of VER_SUITENAME */
137
138     ret = pVerifyVersionInfoA(&info, VER_SUITENAME,
139         pVerSetConditionMask(0, VER_SUITENAME, VER_AND));
140     ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
141
142     ret = pVerifyVersionInfoA(&info, VER_SUITENAME,
143         pVerSetConditionMask(0, VER_SUITENAME, VER_OR));
144     ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
145
146     /* test handling of version numbers */
147     
148     /* v3.10 is always less than v4.x even
149      * if the minor version is tested */
150     info.dwMajorVersion = 3;
151     info.dwMinorVersion = 10;
152     ret = pVerifyVersionInfoA(&info, VER_MAJORVERSION | 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());
156
157     info.dwMinorVersion = 0;
158     info.wServicePackMajor = 10;
159     ret = pVerifyVersionInfoA(&info, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
160         pVerSetConditionMask(pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL),
161             VER_MAJORVERSION, VER_GREATER_EQUAL));
162     ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
163
164     info.wServicePackMajor = 0;
165     info.wServicePackMinor = 10;
166     ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
167         pVerSetConditionMask(pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL),
168             VER_MAJORVERSION, VER_GREATER_EQUAL));
169
170     info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
171     GetVersionEx((OSVERSIONINFO *)&info);
172     info.wServicePackMinor++;
173     SetLastError(0xdeadbeef);
174     ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
175         pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL));
176     error = GetLastError();
177     ok(!ret, "VerifyVersionInfoA succeeded\n");
178     ok(error == ERROR_OLD_WIN_VERSION || broken(error == ERROR_BAD_ARGUMENTS) /* some wink2 */,
179        "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", error);
180
181     if (servicepack == 0)
182     {
183         skip("There is no ServicePack on this system\n");
184     }
185     else
186     {
187         info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
188         GetVersionEx((OSVERSIONINFO *)&info);
189         info.wServicePackMajor--;
190         ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
191             pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER));
192         ok(ret || broken(!ret) /* some win2k */, "VerifyVersionInfoA failed with error %d\n", GetLastError());
193
194         info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
195         GetVersionEx((OSVERSIONINFO *)&info);
196         info.wServicePackMajor--;
197         ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
198             pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL));
199         ok(ret || broken(!ret) /* some win2k */, "VerifyVersionInfoA failed with error %d\n", GetLastError());
200     }
201
202     info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
203     GetVersionEx((OSVERSIONINFO *)&info);
204     info.wServicePackMajor++;
205     ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
206         pVerSetConditionMask(0, VER_MINORVERSION, VER_LESS));
207     ok(ret || broken(!ret) /* some win2k */, "VerifyVersionInfoA failed with error %d\n", GetLastError());
208
209     info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
210     GetVersionEx((OSVERSIONINFO *)&info);
211     info.wServicePackMajor++;
212     ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
213         pVerSetConditionMask(0, VER_MINORVERSION, VER_LESS_EQUAL));
214     ok(ret || broken(!ret) /* some win2k */, "VerifyVersionInfoA failed with error %d\n", GetLastError());
215
216     info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
217     GetVersionEx((OSVERSIONINFO *)&info);
218     info.wServicePackMajor--;
219     SetLastError(0xdeadbeef);
220     ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
221         pVerSetConditionMask(0, VER_MINORVERSION, VER_EQUAL));
222     error = GetLastError();
223     ok(!ret, "VerifyVersionInfoA succeeded\n");
224     ok(error == ERROR_OLD_WIN_VERSION || broken(error == ERROR_BAD_ARGUMENTS) /* some win2k */,
225        "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", error);
226
227     /* test the failure hierarchy for the four version fields */
228
229     info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
230     GetVersionEx((OSVERSIONINFO *)&info);
231     info.wServicePackMajor++;
232     SetLastError(0xdeadbeef);
233     ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
234         pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL));
235     error = GetLastError();
236     ok(!ret, "VerifyVersionInfoA succeeded\n");
237     ok(error == ERROR_OLD_WIN_VERSION || broken(error == ERROR_BAD_ARGUMENTS) /* some win2k */,
238        "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", error);
239
240     info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
241     GetVersionEx((OSVERSIONINFO *)&info);
242     info.dwMinorVersion++;
243     SetLastError(0xdeadbeef);
244     ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
245         pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL));
246     error = GetLastError();
247     ok(!ret, "VerifyVersionInfoA succeeded\n");
248     ok(error == ERROR_OLD_WIN_VERSION || broken(error == ERROR_BAD_ARGUMENTS) /* some win2k */,
249        "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", error);
250
251     info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
252     GetVersionEx((OSVERSIONINFO *)&info);
253     info.dwMajorVersion++;
254     SetLastError(0xdeadbeef);
255     ret = pVerifyVersionInfoA(&info, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
256         pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL));
257     error = GetLastError();
258     ok(!ret, "VerifyVersionInfoA succeeded\n");
259     ok(error == ERROR_OLD_WIN_VERSION || broken(error == ERROR_BAD_ARGUMENTS) /* some win2k */,
260        "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", error);
261
262     ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
263         pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL));
264     ok(ret || broken(!ret) /* some win2k */, "VerifyVersionInfoA failed with error %d\n", GetLastError());
265
266     info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
267     GetVersionEx((OSVERSIONINFO *)&info);
268     info.dwBuildNumber++;
269     SetLastError(0xdeadbeef);
270     ret = pVerifyVersionInfoA(&info, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
271         pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL));
272     error = GetLastError();
273     ok(!ret, "VerifyVersionInfoA succeeded\n");
274     ok(error == ERROR_OLD_WIN_VERSION || broken(error == ERROR_BAD_ARGUMENTS) /* some win2k */,
275        "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", error);
276
277     ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
278         pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL));
279     ok(ret || broken(!ret) /* some win2k */, "VerifyVersionInfoA failed with error %d\n", GetLastError());
280
281     /* test bad dwOSVersionInfoSize */
282     info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
283     GetVersionEx((OSVERSIONINFO *)&info);
284     info.dwOSVersionInfoSize = 0;
285     ret = pVerifyVersionInfoA(&info, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
286         pVerSetConditionMask(0, VER_MAJORVERSION, VER_GREATER_EQUAL));
287     ok(ret || broken(!ret) /* some win2k */, "VerifyVersionInfoA failed with error %d\n", GetLastError());
288 }
289
290 START_TEST(version)
291 {
292     init_function_pointers();
293
294     test_GetVersionEx();
295     test_VerifyVersionInfo();
296 }