kernel32/tests: Use '%d' to print GetLastError().
[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 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     ok(ret, "VerifyVersionInfoA failed with error %d\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     ok(!ret && (GetLastError() == ERROR_OLD_WIN_VERSION),
63         "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\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 %d\n", GetLastError());
70
71     ret = pVerifyVersionInfoA(&info, VER_SUITENAME,
72         pVerSetConditionMask(0, VER_SUITENAME, VER_OR));
73     ok(ret, "VerifyVersionInfoA failed with error %d\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     ok(ret, "VerifyVersionInfoA failed with error %d\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     ok(ret, "VerifyVersionInfoA failed with error %d\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     ok(ret, "VerifyVersionInfoA failed with error %d\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     ok(!ret && (GetLastError() == ERROR_OLD_WIN_VERSION),
105         "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", GetLastError());
106
107     GetVersionEx((OSVERSIONINFO *)&info);
108     info.wServicePackMajor--;
109     ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
110         pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER));
111     ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
112
113     GetVersionEx((OSVERSIONINFO *)&info);
114     info.wServicePackMajor--;
115     ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
116         pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL));
117     ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
118
119     GetVersionEx((OSVERSIONINFO *)&info);
120     info.wServicePackMajor++;
121     ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
122         pVerSetConditionMask(0, VER_MINORVERSION, VER_LESS));
123     ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
124
125     GetVersionEx((OSVERSIONINFO *)&info);
126     info.wServicePackMajor++;
127     ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
128         pVerSetConditionMask(0, VER_MINORVERSION, VER_LESS_EQUAL));
129     ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
130
131     GetVersionEx((OSVERSIONINFO *)&info);
132     info.wServicePackMajor--;
133     ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
134         pVerSetConditionMask(0, VER_MINORVERSION, VER_EQUAL));
135     ok(!ret && (GetLastError() == ERROR_OLD_WIN_VERSION),
136         "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", GetLastError());
137
138     /* test the failure hierarchy for the four version fields */
139
140     GetVersionEx((OSVERSIONINFO *)&info);
141     info.wServicePackMajor++;
142     ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
143         pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL));
144     ok(!ret && (GetLastError() == ERROR_OLD_WIN_VERSION),
145         "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", GetLastError());
146
147     GetVersionEx((OSVERSIONINFO *)&info);
148     info.dwMinorVersion++;
149     ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
150         pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL));
151     ok(!ret && (GetLastError() == ERROR_OLD_WIN_VERSION),
152         "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", GetLastError());
153
154     GetVersionEx((OSVERSIONINFO *)&info);
155     info.dwMajorVersion++;
156     ret = pVerifyVersionInfoA(&info, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
157         pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL));
158     ok(!ret && (GetLastError() == ERROR_OLD_WIN_VERSION),
159         "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", GetLastError());
160
161     ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
162         pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL));
163     ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
164
165
166     GetVersionEx((OSVERSIONINFO *)&info);
167     info.dwBuildNumber++;
168     ret = pVerifyVersionInfoA(&info, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
169         pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL));
170     ok(!ret && (GetLastError() == ERROR_OLD_WIN_VERSION),
171         "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", GetLastError());
172
173     ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
174         pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL));
175     ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
176
177     /* test bad dwOSVersionInfoSize */
178     GetVersionEx((OSVERSIONINFO *)&info);
179     info.dwOSVersionInfoSize = 0;
180     ret = pVerifyVersionInfoA(&info, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
181         pVerSetConditionMask(0, VER_MAJORVERSION, VER_GREATER_EQUAL));
182     ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError());
183 }