wininet: Use a blank password if none is provided in FTP_Connect.
[wine] / dlls / kernel / 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 START_TEST(version)
47 {
48     OSVERSIONINFOEX info = { sizeof(info) };
49     BOOL ret;
50
51     init_function_pointers();
52     if(!pVerifyVersionInfoA || !pVerSetConditionMask) return;
53
54     ret = pVerifyVersionInfoA(&info, VER_MAJORVERSION | VER_MINORVERSION,
55         pVerSetConditionMask(0, VER_MAJORVERSION, VER_GREATER_EQUAL));
56     todo_wine ok(ret, "VerifyVersionInfoA failed with error %ld\n", GetLastError());
57
58     ret = pVerifyVersionInfoA(&info, VER_BUILDNUMBER | VER_MAJORVERSION |
59         VER_MINORVERSION/* | VER_PLATFORMID | VER_SERVICEPACKMAJOR |
60         VER_SERVICEPACKMINOR | VER_SUITENAME | VER_PRODUCT_TYPE */,
61         pVerSetConditionMask(0, VER_MAJORVERSION, VER_GREATER_EQUAL));
62     todo_wine ok(!ret && (GetLastError() == ERROR_OLD_WIN_VERSION),
63         "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %ld\n", GetLastError());
64
65     /* tests special handling of VER_SUITENAME */
66
67     ret = pVerifyVersionInfoA(&info, VER_SUITENAME,
68         pVerSetConditionMask(0, VER_SUITENAME, VER_AND));
69     ok(ret, "VerifyVersionInfoA failed with error %ld\n", GetLastError());
70
71     ret = pVerifyVersionInfoA(&info, VER_SUITENAME,
72         pVerSetConditionMask(0, VER_SUITENAME, VER_OR));
73     ok(ret, "VerifyVersionInfoA failed with error %ld\n", GetLastError());
74
75     /* test handling of version numbers */
76     
77     /* v3.10 is always less than v4.x even
78      * if the minor version is tested */
79     info.dwMajorVersion = 3;
80     info.dwMinorVersion = 10;
81     ret = pVerifyVersionInfoA(&info, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
82         pVerSetConditionMask(pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL),
83             VER_MAJORVERSION, VER_GREATER_EQUAL));
84     todo_wine ok(ret, "VerifyVersionInfoA failed with error %ld\n", GetLastError());
85
86     info.dwMinorVersion = 0;
87     info.wServicePackMajor = 10;
88     ret = pVerifyVersionInfoA(&info, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
89         pVerSetConditionMask(pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL),
90             VER_MAJORVERSION, VER_GREATER_EQUAL));
91     todo_wine ok(ret, "VerifyVersionInfoA failed with error %ld\n", GetLastError());
92
93     info.wServicePackMajor = 0;
94     info.wServicePackMinor = 10;
95     ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
96         pVerSetConditionMask(pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL),
97             VER_MAJORVERSION, VER_GREATER_EQUAL));
98     todo_wine ok(ret, "VerifyVersionInfoA failed with error %ld\n", GetLastError());
99
100     GetVersionEx((OSVERSIONINFO *)&info);
101     info.wServicePackMinor++;
102     ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
103         pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL));
104     todo_wine ok(!ret && (GetLastError() == ERROR_OLD_WIN_VERSION),
105         "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %ld\n", GetLastError());
106
107     /* test the failure hierarchy for the four version fields */
108
109     GetVersionEx((OSVERSIONINFO *)&info);
110     info.wServicePackMajor++;
111     ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
112         pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL));
113     todo_wine ok(!ret && (GetLastError() == ERROR_OLD_WIN_VERSION),
114         "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %ld\n", GetLastError());
115
116     GetVersionEx((OSVERSIONINFO *)&info);
117     info.dwMinorVersion++;
118     ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
119         pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL));
120     ok(!ret && (GetLastError() == ERROR_OLD_WIN_VERSION),
121         "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %ld\n", GetLastError());
122
123     GetVersionEx((OSVERSIONINFO *)&info);
124     info.dwMajorVersion++;
125     ret = pVerifyVersionInfoA(&info, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
126         pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL));
127     todo_wine ok(!ret && (GetLastError() == ERROR_OLD_WIN_VERSION),
128         "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %ld\n", GetLastError());
129
130     ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
131         pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL));
132     todo_wine ok(ret, "VerifyVersionInfoA failed with error %ld\n", GetLastError());
133
134
135     /* shows that build number fits into the hierarchy after major version, but before minor version */
136     GetVersionEx((OSVERSIONINFO *)&info);
137     info.dwBuildNumber++;
138     ret = pVerifyVersionInfoA(&info, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
139         pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL));
140     todo_wine ok(!ret && (GetLastError() == ERROR_OLD_WIN_VERSION),
141         "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %ld\n", GetLastError());
142
143     ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
144         pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL));
145     todo_wine ok(ret, "VerifyVersionInfoA failed with error %ld\n", GetLastError());
146
147     /* test bad dwOSVersionInfoSize */
148     GetVersionEx((OSVERSIONINFO *)&info);
149     info.dwOSVersionInfoSize = 0;
150     ret = pVerifyVersionInfoA(&info, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
151         pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL));
152     todo_wine ok(!ret && (GetLastError() == ERROR_OLD_WIN_VERSION),
153         "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %ld\n", GetLastError());
154 }