2 * Unit test suite for version functions
4 * Copyright 2006 Robert Shearman
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.
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.
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
23 #include "wine/test.h"
26 static BOOL (WINAPI
* pVerifyVersionInfoA
)(LPOSVERSIONINFOEXA
, DWORD
, DWORDLONG
);
27 static ULONGLONG (WINAPI
* pVerSetConditionMask
)(ULONGLONG
, DWORD
, BYTE
);
29 #define KERNEL32_GET_PROC(func) \
30 p##func = (void *)GetProcAddress(hKernel32, #func); \
31 if(!p##func) trace("GetProcAddress(hKernel32, '%s') failed\n", #func);
33 static void init_function_pointers(void)
37 pVerifyVersionInfoA
= NULL
;
38 pVerSetConditionMask
= NULL
;
40 hKernel32
= GetModuleHandleA("kernel32.dll");
42 KERNEL32_GET_PROC(VerifyVersionInfoA
);
43 KERNEL32_GET_PROC(VerSetConditionMask
);
46 static void test_GetVersionEx(void)
49 OSVERSIONINFOEXA infoExA
;
54 /* Silently crashes on XP */
55 ret
= GetVersionExA(NULL
);
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());
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());
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());
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());
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());
94 static void test_VerifyVersionInfo(void)
96 OSVERSIONINFOEX info
= { sizeof(info
) };
99 if(!pVerifyVersionInfoA
|| !pVerSetConditionMask
)
101 skip("Needed functions not available\n");
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());
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());
116 /* tests special handling of VER_SUITENAME */
118 ret
= pVerifyVersionInfoA(&info
, VER_SUITENAME
,
119 pVerSetConditionMask(0, VER_SUITENAME
, VER_AND
));
120 ok(ret
, "VerifyVersionInfoA failed with error %d\n", GetLastError());
122 ret
= pVerifyVersionInfoA(&info
, VER_SUITENAME
,
123 pVerSetConditionMask(0, VER_SUITENAME
, VER_OR
));
124 ok(ret
, "VerifyVersionInfoA failed with error %d\n", GetLastError());
126 /* test handling of version numbers */
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());
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());
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());
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());
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());
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());
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());
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());
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());
189 /* test the failure hierarchy for the four version fields */
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());
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());
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());
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());
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());
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());
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());
238 init_function_pointers();
241 test_VerifyVersionInfo();