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