mshtml: Add tests for get_scrollLeft.
[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 = { sizeof(info) };
105     BOOL ret;
106     DWORD servicepack;
107
108     if(!pVerifyVersionInfoA || !pVerSetConditionMask)
109     {
110         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     GetVersionEx((OSVERSIONINFO *)&info);
118     servicepack = info.wServicePackMajor;
119     memset(&info, 0, sizeof(info));
120     info.dwOSVersionInfoSize = 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     ret = pVerifyVersionInfoA(&info, VER_BUILDNUMBER | VER_MAJORVERSION |
127         VER_MINORVERSION/* | VER_PLATFORMID | VER_SERVICEPACKMAJOR |
128         VER_SERVICEPACKMINOR | VER_SUITENAME | VER_PRODUCT_TYPE */,
129         pVerSetConditionMask(0, VER_MAJORVERSION, VER_GREATER_EQUAL));
130     ok(!ret && (GetLastError() == ERROR_OLD_WIN_VERSION),
131         "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", GetLastError());
132
133     /* tests special handling of VER_SUITENAME */
134
135     ret = pVerifyVersionInfoA(&info, VER_SUITENAME,
136         pVerSetConditionMask(0, VER_SUITENAME, VER_AND));
137     ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
138
139     ret = pVerifyVersionInfoA(&info, VER_SUITENAME,
140         pVerSetConditionMask(0, VER_SUITENAME, VER_OR));
141     ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
142
143     /* test handling of version numbers */
144     
145     /* v3.10 is always less than v4.x even
146      * if the minor version is tested */
147     info.dwMajorVersion = 3;
148     info.dwMinorVersion = 10;
149     ret = pVerifyVersionInfoA(&info, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
150         pVerSetConditionMask(pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL),
151             VER_MAJORVERSION, VER_GREATER_EQUAL));
152     ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
153
154     info.dwMinorVersion = 0;
155     info.wServicePackMajor = 10;
156     ret = pVerifyVersionInfoA(&info, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
157         pVerSetConditionMask(pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL),
158             VER_MAJORVERSION, VER_GREATER_EQUAL));
159     ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
160
161     info.wServicePackMajor = 0;
162     info.wServicePackMinor = 10;
163     ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
164         pVerSetConditionMask(pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL),
165             VER_MAJORVERSION, VER_GREATER_EQUAL));
166     if (servicepack == 0)
167     {
168         ok(!ret, "VerifyVersionInfoA should have failed\n");
169         ok(GetLastError() == ERROR_OLD_WIN_VERSION,
170             "Expected ERROR_OLD_WIN_VERSION instead of %d\n", GetLastError());
171     }
172     else
173         ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
174
175     GetVersionEx((OSVERSIONINFO *)&info);
176     info.wServicePackMinor++;
177     ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
178         pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL));
179     ok(!ret && (GetLastError() == ERROR_OLD_WIN_VERSION),
180         "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", GetLastError());
181
182     if (servicepack == 0)
183     {
184         skip("There is no ServicePack on this system\n");
185     }
186     else
187     {
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, "VerifyVersionInfoA failed with error %d\n", GetLastError());
193
194         GetVersionEx((OSVERSIONINFO *)&info);
195         info.wServicePackMajor--;
196         ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
197             pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL));
198         ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
199     }
200
201     GetVersionEx((OSVERSIONINFO *)&info);
202     info.wServicePackMajor++;
203     ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
204         pVerSetConditionMask(0, VER_MINORVERSION, VER_LESS));
205     ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
206
207     GetVersionEx((OSVERSIONINFO *)&info);
208     info.wServicePackMajor++;
209     ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
210         pVerSetConditionMask(0, VER_MINORVERSION, VER_LESS_EQUAL));
211     ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
212
213     GetVersionEx((OSVERSIONINFO *)&info);
214     info.wServicePackMajor--;
215     ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
216         pVerSetConditionMask(0, VER_MINORVERSION, VER_EQUAL));
217     ok(!ret && (GetLastError() == ERROR_OLD_WIN_VERSION),
218         "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", GetLastError());
219
220     /* test the failure hierarchy for the four version fields */
221
222     GetVersionEx((OSVERSIONINFO *)&info);
223     info.wServicePackMajor++;
224     ret = pVerifyVersionInfoA(&info, 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());
228
229     GetVersionEx((OSVERSIONINFO *)&info);
230     info.dwMinorVersion++;
231     ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
232         pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL));
233     ok(!ret && (GetLastError() == ERROR_OLD_WIN_VERSION),
234         "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", GetLastError());
235
236     GetVersionEx((OSVERSIONINFO *)&info);
237     info.dwMajorVersion++;
238     ret = pVerifyVersionInfoA(&info, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
239         pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL));
240     ok(!ret && (GetLastError() == ERROR_OLD_WIN_VERSION),
241         "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", GetLastError());
242
243     ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
244         pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL));
245     ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
246
247
248     GetVersionEx((OSVERSIONINFO *)&info);
249     info.dwBuildNumber++;
250     ret = pVerifyVersionInfoA(&info, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
251         pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL));
252     ok(!ret && (GetLastError() == ERROR_OLD_WIN_VERSION),
253         "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", GetLastError());
254
255     ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
256         pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL));
257     ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
258
259     /* test bad dwOSVersionInfoSize */
260     GetVersionEx((OSVERSIONINFO *)&info);
261     info.dwOSVersionInfoSize = 0;
262     ret = pVerifyVersionInfoA(&info, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
263         pVerSetConditionMask(0, VER_MAJORVERSION, VER_GREATER_EQUAL));
264     ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
265 }
266
267 START_TEST(version)
268 {
269     init_function_pointers();
270
271     test_GetVersionEx();
272     test_VerifyVersionInfo();
273 }