ntdll: The FileMailslotSetInformation and FileCompletionInformation cases of NtSetInf...
[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 static void test_VerifyVersionInfo(void)
95 {
96     OSVERSIONINFOEX info = { sizeof(info) };
97     BOOL ret;
98
99     if(!pVerifyVersionInfoA || !pVerSetConditionMask)
100     {
101         skip("Needed functions not available\n");
102         return;
103     }
104
105     ret = pVerifyVersionInfoA(&info, VER_MAJORVERSION | VER_MINORVERSION,
106         pVerSetConditionMask(0, VER_MAJORVERSION, VER_GREATER_EQUAL));
107     ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
108
109     ret = pVerifyVersionInfoA(&info, VER_BUILDNUMBER | VER_MAJORVERSION |
110         VER_MINORVERSION/* | VER_PLATFORMID | VER_SERVICEPACKMAJOR |
111         VER_SERVICEPACKMINOR | VER_SUITENAME | VER_PRODUCT_TYPE */,
112         pVerSetConditionMask(0, VER_MAJORVERSION, VER_GREATER_EQUAL));
113     ok(!ret && (GetLastError() == ERROR_OLD_WIN_VERSION),
114         "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", GetLastError());
115
116     /* tests special handling of VER_SUITENAME */
117
118     ret = pVerifyVersionInfoA(&info, VER_SUITENAME,
119         pVerSetConditionMask(0, VER_SUITENAME, VER_AND));
120     ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
121
122     ret = pVerifyVersionInfoA(&info, VER_SUITENAME,
123         pVerSetConditionMask(0, VER_SUITENAME, VER_OR));
124     ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
125
126     /* test handling of version numbers */
127     
128     /* v3.10 is always less than v4.x even
129      * if the minor version is tested */
130     info.dwMajorVersion = 3;
131     info.dwMinorVersion = 10;
132     ret = pVerifyVersionInfoA(&info, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
133         pVerSetConditionMask(pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL),
134             VER_MAJORVERSION, VER_GREATER_EQUAL));
135     ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
136
137     info.dwMinorVersion = 0;
138     info.wServicePackMajor = 10;
139     ret = pVerifyVersionInfoA(&info, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
140         pVerSetConditionMask(pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL),
141             VER_MAJORVERSION, VER_GREATER_EQUAL));
142     ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
143
144     info.wServicePackMajor = 0;
145     info.wServicePackMinor = 10;
146     ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
147         pVerSetConditionMask(pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL),
148             VER_MAJORVERSION, VER_GREATER_EQUAL));
149     ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
150
151     GetVersionEx((OSVERSIONINFO *)&info);
152     info.wServicePackMinor++;
153     ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
154         pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL));
155     ok(!ret && (GetLastError() == ERROR_OLD_WIN_VERSION),
156         "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", GetLastError());
157
158     GetVersionEx((OSVERSIONINFO *)&info);
159     info.wServicePackMajor--;
160     ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
161         pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER));
162     ok(ret, "VerifyVersionInfoA failed with error %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_EQUAL));
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_LESS));
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_EQUAL));
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_EQUAL));
186     ok(!ret && (GetLastError() == ERROR_OLD_WIN_VERSION),
187         "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", GetLastError());
188
189     /* test the failure hierarchy for the four version fields */
190
191     GetVersionEx((OSVERSIONINFO *)&info);
192     info.wServicePackMajor++;
193     ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
194         pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL));
195     ok(!ret && (GetLastError() == ERROR_OLD_WIN_VERSION),
196         "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", GetLastError());
197
198     GetVersionEx((OSVERSIONINFO *)&info);
199     info.dwMinorVersion++;
200     ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
201         pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL));
202     ok(!ret && (GetLastError() == ERROR_OLD_WIN_VERSION),
203         "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", GetLastError());
204
205     GetVersionEx((OSVERSIONINFO *)&info);
206     info.dwMajorVersion++;
207     ret = pVerifyVersionInfoA(&info, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
208         pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL));
209     ok(!ret && (GetLastError() == ERROR_OLD_WIN_VERSION),
210         "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", GetLastError());
211
212     ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
213         pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL));
214     ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
215
216
217     GetVersionEx((OSVERSIONINFO *)&info);
218     info.dwBuildNumber++;
219     ret = pVerifyVersionInfoA(&info, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
220         pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL));
221     ok(!ret && (GetLastError() == ERROR_OLD_WIN_VERSION),
222         "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", GetLastError());
223
224     ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
225         pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL));
226     ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
227
228     /* test bad dwOSVersionInfoSize */
229     GetVersionEx((OSVERSIONINFO *)&info);
230     info.dwOSVersionInfoSize = 0;
231     ret = pVerifyVersionInfoA(&info, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
232         pVerSetConditionMask(0, VER_MAJORVERSION, VER_GREATER_EQUAL));
233     ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
234 }
235
236 START_TEST(version)
237 {
238     init_function_pointers();
239
240     test_GetVersionEx();
241     test_VerifyVersionInfo();
242 }