wined3d: Move the GL info structure into the adapter.
[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         "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
64
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());
71
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());
78
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());
85
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());
92
93 }
94
95 START_TEST(version)
96 {
97     OSVERSIONINFOEX info = { sizeof(info) };
98     BOOL ret;
99
100     init_function_pointers();
101
102     test_GetVersionEx();
103
104     if(!pVerifyVersionInfoA || !pVerSetConditionMask)
105     {
106         skip("Needed functions not available\n");
107         return;
108     }
109
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());
113
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());
120
121     /* tests special handling of VER_SUITENAME */
122
123     ret = pVerifyVersionInfoA(&info, VER_SUITENAME,
124         pVerSetConditionMask(0, VER_SUITENAME, VER_AND));
125     ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
126
127     ret = pVerifyVersionInfoA(&info, VER_SUITENAME,
128         pVerSetConditionMask(0, VER_SUITENAME, VER_OR));
129     ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
130
131     /* test handling of version numbers */
132     
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());
141
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());
148
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());
155
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());
162
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());
168
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());
174
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());
180
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());
186
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());
193
194     /* test the failure hierarchy for the four version fields */
195
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());
202
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());
209
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());
216
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());
220
221
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());
228
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());
232
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());
239 }