add linebreaks
[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 SetLastError( 0xdeadbeef );
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 }