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