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