winealsa: Use "default" as the default card name instead of "default:0".
[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, "Expected GetVersionExA to succeed\n");
96     ok(GetLastError() == 0xdeadbeef,
97         "Expected 0xdeadbeef, got %d\n", GetLastError());
98 }
99
100 static void test_VerifyVersionInfo(void)
101 {
102     OSVERSIONINFOEX info = { sizeof(info) };
103     BOOL ret;
104
105     if(!pVerifyVersionInfoA || !pVerSetConditionMask)
106     {
107         skip("Needed functions not available\n");
108         return;
109     }
110
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());
114
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());
121
122     /* tests special handling of VER_SUITENAME */
123
124     ret = pVerifyVersionInfoA(&info, VER_SUITENAME,
125         pVerSetConditionMask(0, VER_SUITENAME, VER_AND));
126     ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
127
128     ret = pVerifyVersionInfoA(&info, VER_SUITENAME,
129         pVerSetConditionMask(0, VER_SUITENAME, VER_OR));
130     ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
131
132     /* test handling of version numbers */
133     
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());
142
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());
149
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());
156
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());
163
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());
169
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());
175
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());
181
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());
187
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());
194
195     /* test the failure hierarchy for the four version fields */
196
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());
203
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());
210
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());
217
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());
221
222
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());
229
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());
233
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());
240 }
241
242 START_TEST(version)
243 {
244     init_function_pointers();
245
246     test_GetVersionEx();
247     test_VerifyVersionInfo();
248 }