- Undefine __ROS_LONG64__ for ReactOS' extensions to kernel32 and setupapi Winetests...
[reactos.git] / rostests / winetests / setupapi / devclass.c
1 /*
2 * SetupAPI device class-related functions tests
3 *
4 * Copyright 2006 Hervé Poussineau
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public Licence as
8 * published by the Free Software Foundation; either version 2 of
9 * 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 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this library; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21 #include <assert.h>
22 #include <stdarg.h>
23 #include <stdio.h>
24
25 #undef __ROS_LONG64__
26 #include "windef.h"
27 #include "winbase.h"
28 #include "wingdi.h"
29 #include "winuser.h"
30 #include "winreg.h"
31 #include "cfgmgr32.h"
32 #include "setupapi.h"
33
34 #include "wine/test.h"
35
36 static GUID test_class_guid = { 0x4d36e967, 0xe325, 0x11ce, { 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 } };
37 static char test_class_name[MAX_CLASS_NAME_LEN] = "DiskDrive";
38
39 static const char *debugstr_guid(const GUID *guid)
40 {
41 static char guidSTR1[39];
42 static char guidSTR2[39];
43 char* guidSTR;
44 static BOOL index;
45
46 if (!guid) return NULL;
47
48 index = !index;
49 guidSTR = index ? guidSTR1 : guidSTR2;
50
51 snprintf(guidSTR, sizeof(guidSTR1),
52 "{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
53 guid->Data1, guid->Data2, guid->Data3,
54 guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
55 guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]);
56 return guidSTR;
57 }
58
59 static void test_SetupDiBuildClassInfoList(void)
60 {
61 LPGUID guid_list = NULL;
62 DWORD required_size, size;
63
64 SetLastError( 0xdeadbeef );
65 ok( !SetupDiBuildClassInfoList( 0, NULL, 0, NULL ),
66 "Fail expected" );
67 ok( GetLastError() == ERROR_INVALID_PARAMETER,
68 "Expected error %lx, got %lx", ERROR_INVALID_PARAMETER, GetLastError() );
69
70 SetLastError( 0xdeadbeef );
71 ok( !SetupDiBuildClassInfoList( 0, NULL, 0, &required_size ),
72 "Fail expected\n" );
73 ok( GetLastError() == ERROR_INSUFFICIENT_BUFFER,
74 "Expected error %lx, got %lx\n", ERROR_INSUFFICIENT_BUFFER, GetLastError() );
75
76 guid_list = HeapAlloc( GetProcessHeap(), 0, ( required_size + 1 ) * sizeof( GUID ) );
77 if ( !guid_list )
78 return;
79
80 SetLastError( 0xdeadbeef );
81 ok( SetupDiBuildClassInfoList( 0, guid_list, required_size, &size ),
82 "Error reported %lx\n", GetLastError() );
83 ok( size == required_size, "Expected size %lu, got %lu\n", required_size, size );
84 SetLastError( 0xdeadbeef );
85 ok( SetupDiBuildClassInfoList( 0, guid_list, required_size + 1, &size ),
86 "Error reported %lx\n", GetLastError() );
87 ok( size == required_size, "Expected size %lu, got %lu\n", required_size, size );
88
89 if ( size > 0 )
90 {
91 /* That's better to use the first class found, as we know for sure that it exists */
92 memcpy(&test_class_guid, &guid_list[0], sizeof( GUID ) );
93 SetupDiClassNameFromGuidA( &test_class_guid, test_class_name, sizeof( test_class_name ), NULL );
94 }
95 HeapFree( GetProcessHeap(), 0, guid_list );
96 }
97
98 static void test_SetupDiClassGuidsFromNameA(void)
99 {
100 LPGUID guid_list = NULL;
101 DWORD required_size, size;
102
103 SetLastError( 0xdeadbeef );
104 ok( !SetupDiClassGuidsFromNameA( NULL, NULL, 0, NULL ),
105 "Fail expected\n" );
106 ok( GetLastError() == ERROR_INVALID_PARAMETER,
107 "Expected error %lx, got %lx\n", ERROR_INVALID_PARAMETER, GetLastError() );
108
109 SetLastError( 0xdeadbeef );
110 ok( !SetupDiClassGuidsFromNameA( NULL, NULL, 0, &required_size ),
111 "Fail expected\n" );
112 ok( GetLastError() == ERROR_INVALID_PARAMETER,
113 "Expected error %lx, got %lx\n", ERROR_INVALID_PARAMETER, GetLastError() );
114
115 SetLastError( 0xdeadbeef );
116 ok( SetupDiClassGuidsFromNameA( "", NULL, 0, &required_size ),
117 "Error reported %lx\n", GetLastError() );
118 ok( required_size == 0, "Expected 0, got %lu\n", required_size );
119
120 SetLastError( 0xdeadbeef );
121 ok( !SetupDiClassGuidsFromNameA( test_class_name, NULL, 0, &required_size ),
122 "Fail expected\n" );
123 ok( GetLastError() == ERROR_INSUFFICIENT_BUFFER,
124 "Expected error %lx, got %lx\n", ERROR_INSUFFICIENT_BUFFER, GetLastError() );
125 ok( required_size > 0, "Expected > 0, got %lu\n", required_size );
126
127 guid_list = HeapAlloc( GetProcessHeap(), 0, ( required_size + 1 ) * sizeof( GUID ) );
128 if ( !guid_list )
129 return;
130
131 SetLastError( 0xdeadbeef );
132 ok( SetupDiClassGuidsFromNameA( test_class_name, guid_list, required_size, &size ),
133 "Error reported %lx\n", GetLastError() );
134 ok( size == required_size, "Expected size %lu, got %lu\n", required_size, size );
135 ok( IsEqualIID( &guid_list[0], &test_class_guid ),
136 "Expected %s, got %s\n", debugstr_guid( &test_class_guid ), debugstr_guid( &guid_list[0] ) );
137 SetLastError( 0xdeadbeef );
138 ok( SetupDiClassGuidsFromNameA( test_class_name, guid_list, required_size + 1, &size ),
139 "Error reported %lx\n", GetLastError() );
140 ok( size == required_size, "Expected size %lu, got %lu\n", required_size, size );
141 ok( IsEqualIID( &guid_list[0], &test_class_guid ),
142 "Expected %s, got %s\n", debugstr_guid( &test_class_guid ), debugstr_guid( &guid_list[0] ) );
143
144 HeapFree( GetProcessHeap(), 0, guid_list );
145 }
146
147 static void test_SetupDiClassNameFromGuidA(void)
148 {
149 CHAR* class_name = NULL;
150 DWORD required_size, size;
151
152 SetLastError( 0xdeadbeef );
153 ok( !SetupDiClassNameFromGuidA( NULL, NULL, 0, NULL ),
154 "Fail expected\n" );
155 ok( GetLastError() == ERROR_INVALID_CLASS,
156 "Expected error %x, got %lx\n", ERROR_INVALID_CLASS, GetLastError() );
157
158 SetLastError( 0xdeadbeef );
159 ok( !SetupDiClassNameFromGuidA( NULL, NULL, 0, &required_size ),
160 "Fail expected\n" );
161 ok( GetLastError() == ERROR_INVALID_CLASS,
162 "Expected error %x, got %lx\n", ERROR_INVALID_CLASS, GetLastError() );
163
164 SetLastError( 0xdeadbeef );
165 ok( !SetupDiClassNameFromGuidA( &test_class_guid, NULL, 0, &required_size ),
166 "Fail expected\n" );
167 ok( GetLastError() == ERROR_INSUFFICIENT_BUFFER,
168 "Expected error %lx, got %lx\n", ERROR_INSUFFICIENT_BUFFER, GetLastError() );
169 ok( required_size > 0, "Expected > 0, got %lu\n", required_size );
170 ok( required_size < MAX_CLASS_NAME_LEN, "Expected < %u, got %lu\n", MAX_CLASS_NAME_LEN, required_size );
171
172 class_name = HeapAlloc( GetProcessHeap(), 0, required_size );
173 if ( !class_name )
174 return;
175
176 SetLastError( 0xdeadbeef );
177 ok( SetupDiClassNameFromGuidA( &test_class_guid, class_name, required_size, &size ),
178 "Error reported %lx\n", GetLastError() );
179 ok( size == required_size, "Expected size %lu, got %lu\n", required_size, size );
180 ok( !strcmp( class_name, test_class_name ),
181 "Expected %s, got %s\n", test_class_name, class_name );
182 SetLastError( 0xdeadbeef );
183 ok( SetupDiClassNameFromGuidA( &test_class_guid, class_name, required_size + 1, &size ),
184 "Error reported %lx\n", GetLastError() );
185 ok( size == required_size, "Expected size %lu, got %lu\n", required_size, size );
186 ok( !strcmp( class_name, test_class_name ),
187 "Expected %s, got %s\n", test_class_name, class_name );
188
189 HeapFree( GetProcessHeap(), 0, class_name );
190 }
191
192 static void test_SetupDiGetClassDescriptionA(void)
193 {
194 CHAR* class_desc = NULL;
195 DWORD required_size, size;
196
197 SetLastError( 0xdeadbeef );
198 ok( !SetupDiGetClassDescriptionA( NULL, NULL, 0, NULL ),
199 "Fail expected\n" );
200 ok( GetLastError() == ERROR_INVALID_PARAMETER,
201 "Expected error %lx, got %lx\n", ERROR_INVALID_PARAMETER, GetLastError() );
202
203 SetLastError( 0xdeadbeef );
204 ok( !SetupDiGetClassDescriptionA( NULL, NULL, 0, &required_size ),
205 "Fail expected\n" );
206 ok( GetLastError() == ERROR_INVALID_PARAMETER,
207 "Expected error %lx, got %lx\n", ERROR_INVALID_PARAMETER, GetLastError() );
208
209 SetLastError( 0xdeadbeef );
210 ok( !SetupDiGetClassDescriptionA( &test_class_guid, NULL, 0, &required_size ),
211 "Fail expected\n" );
212 ok( GetLastError() == ERROR_INSUFFICIENT_BUFFER,
213 "Expected error %lx, got %lx\n", ERROR_INSUFFICIENT_BUFFER, GetLastError() );
214 ok( required_size > 0, "Expected > 0, got %lu\n", required_size );
215 ok( required_size < LINE_LEN, "Expected < %u, got %lu\n", LINE_LEN, required_size );
216
217 class_desc = HeapAlloc( GetProcessHeap(), 0, required_size );
218 if ( !class_desc )
219 return;
220
221 SetLastError( 0xdeadbeef );
222 ok( SetupDiGetClassDescriptionA( &test_class_guid, class_desc, required_size, &size ),
223 "Error reported %lx\n", GetLastError() );
224 ok( size == required_size, "Expected size %lu, got %lu\n", required_size, size );
225 SetLastError( 0xdeadbeef );
226 ok( SetupDiGetClassDescriptionA( &test_class_guid, class_desc, required_size + 1, &size ),
227 "Error reported %lx\n", GetLastError() );
228 ok( size == required_size, "Expected size %lu, got %lu\n", required_size, size );
229
230 HeapFree( GetProcessHeap(), 0, class_desc );
231 }
232
233 static void test_SetupDiGetClassDevsA(void)
234 {
235 HDEVINFO device_info;
236
237 SetLastError( 0xdeadbeef );
238 device_info = SetupDiGetClassDevs( NULL, NULL, NULL, 0 );
239 ok( device_info == INVALID_HANDLE_VALUE,
240 "Fail expected\n" );
241 ok( GetLastError() == ERROR_INVALID_PARAMETER,
242 "Expected error %lx, got %lx\n", ERROR_INVALID_PARAMETER, GetLastError() );
243
244 SetLastError( 0xdeadbeef );
245 device_info = SetupDiGetClassDevs( NULL, NULL, NULL, DIGCF_ALLCLASSES );
246 ok( device_info != INVALID_HANDLE_VALUE,
247 "Error reported %lx\n", GetLastError() );
248 SetLastError( 0xdeadbeef );
249 ok( SetupDiDestroyDeviceInfoList( device_info ),
250 "Error reported %lx\n", GetLastError() );
251
252 SetLastError( 0xdeadbeef );
253 device_info = SetupDiGetClassDevs( NULL, NULL, NULL, DIGCF_DEVICEINTERFACE );
254 ok( device_info == INVALID_HANDLE_VALUE,
255 "Fail expected\n" );
256 ok( GetLastError() == ERROR_INVALID_PARAMETER,
257 "Expected error %lx, got %lx\n", ERROR_INVALID_PARAMETER, GetLastError() );
258
259 SetLastError( 0xdeadbeef );
260 device_info = SetupDiGetClassDevs( &test_class_guid, NULL, NULL, 0 );
261 ok( device_info != INVALID_HANDLE_VALUE,
262 "Error reported %lx\n", GetLastError() );
263 SetLastError( 0xdeadbeef );
264 ok( SetupDiDestroyDeviceInfoList( device_info ),
265 "Error reported %lx\n", GetLastError() );
266
267 SetLastError( 0xdeadbeef );
268 device_info = SetupDiGetClassDevs( NULL, "(invalid enumerator)", NULL, DIGCF_ALLCLASSES );
269 ok( device_info == INVALID_HANDLE_VALUE,
270 "Fail expected\n" );
271 ok( GetLastError() == ERROR_INVALID_DATA,
272 "Expected error %lx, got %lx\n", ERROR_INVALID_DATA, GetLastError() );
273
274 SetLastError( 0xdeadbeef );
275 device_info = SetupDiGetClassDevs( NULL, "Root", NULL, DIGCF_ALLCLASSES );
276 ok( device_info != INVALID_HANDLE_VALUE,
277 "Error reported %lx\n", GetLastError() );
278 SetLastError( 0xdeadbeef );
279 ok( SetupDiDestroyDeviceInfoList( device_info ),
280 "Error reported %lx\n", GetLastError() );
281 }
282
283 static void test_SetupDiOpenClassRegKeyExA(void)
284 {
285 HKEY hkey;
286 LONG err;
287
288 SetLastError( 0xdeadbeef );
289 hkey = SetupDiOpenClassRegKeyExA( NULL, 0, 0, NULL, NULL );
290 ok( hkey == INVALID_HANDLE_VALUE,
291 "Fail expected\n" );
292 ok( GetLastError() == ERROR_INVALID_FLAGS,
293 "Expected error %lx, got %lx\n", ERROR_INVALID_FLAGS, GetLastError() );
294
295 SetLastError( 0xdeadbeef );
296 hkey = SetupDiOpenClassRegKeyExA( NULL, 0, DIOCR_INSTALLER | DIOCR_INTERFACE, NULL, NULL );
297 ok( hkey == INVALID_HANDLE_VALUE,
298 "Fail expected\n" );
299 ok( GetLastError() == ERROR_INVALID_FLAGS,
300 "Expected error %lx, got %lx\n", ERROR_INVALID_FLAGS, GetLastError() );
301
302 SetLastError( 0xdeadbeef );
303 hkey = SetupDiOpenClassRegKeyExA( NULL, 0, DIOCR_INSTALLER, NULL, NULL );
304 ok( hkey == INVALID_HANDLE_VALUE,
305 "Fail expected\n" );
306 ok( GetLastError() == ERROR_INVALID_CLASS,
307 "Expected error %x, got %lx\n", ERROR_INVALID_CLASS, GetLastError() );
308
309 SetLastError( 0xdeadbeef );
310 hkey = SetupDiOpenClassRegKeyExA( NULL, 0, DIOCR_INTERFACE, NULL, NULL );
311 ok( hkey == INVALID_HANDLE_VALUE,
312 "Fail expected\n" );
313 ok( GetLastError() == ERROR_INVALID_CLASS,
314 "Expected error %x, got %lx\n", ERROR_INVALID_CLASS, GetLastError() );
315
316 SetLastError( 0xdeadbeef );
317 hkey = SetupDiOpenClassRegKeyExA( NULL, KEY_QUERY_VALUE, DIOCR_INSTALLER, NULL, NULL );
318 ok( hkey != INVALID_HANDLE_VALUE, "Got error %lx\n", GetLastError() );
319 err = RegCloseKey( hkey );
320 ok( err == ERROR_SUCCESS, "Got error %lx\n", err );
321
322 SetLastError( 0xdeadbeef );
323 hkey = SetupDiOpenClassRegKeyExA( NULL, KEY_QUERY_VALUE, DIOCR_INTERFACE, NULL, NULL );
324 ok( hkey != INVALID_HANDLE_VALUE, "Got error %lx\n", GetLastError() );
325 err = RegCloseKey( hkey );
326 ok( err == ERROR_SUCCESS, "Got error %lx\n", err );
327
328 SetLastError( 0xdeadbeef );
329 hkey = SetupDiOpenClassRegKeyExA( &test_class_guid, KEY_QUERY_VALUE, DIOCR_INSTALLER, NULL, NULL );
330 ok( hkey != INVALID_HANDLE_VALUE, "Got error %lx\n", GetLastError() );
331 err = RegCloseKey( hkey );
332 ok( err == ERROR_SUCCESS, "Got error %lx\n", err );
333
334 err = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "System\\CurrentControlSet\\Control\\Class", 0, KEY_SET_VALUE, &hkey);
335 ok( err == ERROR_SUCCESS, "Got error %lx\n", err );
336 }
337
338 START_TEST(devclass)
339 {
340 test_SetupDiBuildClassInfoList();
341 test_SetupDiClassGuidsFromNameA();
342 test_SetupDiClassNameFromGuidA();
343 test_SetupDiGetClassDescriptionA();
344 test_SetupDiGetClassDevsA();
345 test_SetupDiOpenClassRegKeyExA();
346 }