2 * SetupAPI device class-related functions tests
4 * Copyright 2006 Hervé Poussineau
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.
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.
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
33 #include "wine/test.h"
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";
38 static const char *debugstr_guid(const GUID
*guid
)
40 static char guidSTR1
[39];
41 static char guidSTR2
[39];
45 if (!guid
) return NULL
;
48 guidSTR
= index
? guidSTR1
: guidSTR2
;
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]);
58 static void test_SetupDiBuildClassInfoList(void)
60 LPGUID guid_list
= NULL
;
61 DWORD required_size
, size
;
63 SetLastError( 0xdeadbeef );
64 ok( !SetupDiBuildClassInfoList( 0, NULL
, 0, NULL
),
66 ok( GetLastError() == ERROR_INVALID_PARAMETER
,
67 "Expected error %lx, got %lx", ERROR_INVALID_PARAMETER
, GetLastError() );
69 SetLastError( 0xdeadbeef );
70 ok( !SetupDiBuildClassInfoList( 0, NULL
, 0, &required_size
),
72 ok( GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
73 "Expected error %lx, got %lx\n", ERROR_INSUFFICIENT_BUFFER
, GetLastError() );
75 guid_list
= HeapAlloc( GetProcessHeap(), 0, ( required_size
+ 1 ) * sizeof( GUID
) );
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
);
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
);
94 HeapFree( GetProcessHeap(), 0, guid_list
);
97 static void test_SetupDiClassGuidsFromNameA(void)
99 LPGUID guid_list
= NULL
;
100 DWORD required_size
, size
;
102 SetLastError( 0xdeadbeef );
103 ok( !SetupDiClassGuidsFromNameA( NULL
, NULL
, 0, NULL
),
105 ok( GetLastError() == ERROR_INVALID_PARAMETER
,
106 "Expected error %lx, got %lx\n", ERROR_INVALID_PARAMETER
, GetLastError() );
108 SetLastError( 0xdeadbeef );
109 ok( !SetupDiClassGuidsFromNameA( NULL
, NULL
, 0, &required_size
),
111 ok( GetLastError() == ERROR_INVALID_PARAMETER
,
112 "Expected error %lx, got %lx\n", ERROR_INVALID_PARAMETER
, GetLastError() );
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
);
119 SetLastError( 0xdeadbeef );
120 ok( !SetupDiClassGuidsFromNameA( test_class_name
, NULL
, 0, &required_size
),
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
);
126 guid_list
= HeapAlloc( GetProcessHeap(), 0, ( required_size
+ 1 ) * sizeof( GUID
) );
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] ) );
143 HeapFree( GetProcessHeap(), 0, guid_list
);
146 static void test_SetupDiClassNameFromGuidA(void)
148 CHAR
* class_name
= NULL
;
149 DWORD required_size
, size
;
151 SetLastError( 0xdeadbeef );
152 ok( !SetupDiClassNameFromGuidA( NULL
, NULL
, 0, NULL
),
154 ok( GetLastError() == ERROR_INVALID_CLASS
,
155 "Expected error %x, got %lx\n", ERROR_INVALID_CLASS
, GetLastError() );
157 SetLastError( 0xdeadbeef );
158 ok( !SetupDiClassNameFromGuidA( NULL
, NULL
, 0, &required_size
),
160 ok( GetLastError() == ERROR_INVALID_CLASS
,
161 "Expected error %x, got %lx\n", ERROR_INVALID_CLASS
, GetLastError() );
163 SetLastError( 0xdeadbeef );
164 ok( !SetupDiClassNameFromGuidA( &test_class_guid
, NULL
, 0, &required_size
),
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
);
171 class_name
= HeapAlloc( GetProcessHeap(), 0, required_size
);
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
);
188 HeapFree( GetProcessHeap(), 0, class_name
);
191 static void test_SetupDiGetClassDescriptionA(void)
193 CHAR
* class_desc
= NULL
;
194 DWORD required_size
, size
;
196 SetLastError( 0xdeadbeef );
197 ok( !SetupDiGetClassDescriptionA( NULL
, NULL
, 0, NULL
),
199 ok( GetLastError() == ERROR_INVALID_PARAMETER
,
200 "Expected error %lx, got %lx\n", ERROR_INVALID_PARAMETER
, GetLastError() );
202 SetLastError( 0xdeadbeef );
203 ok( !SetupDiGetClassDescriptionA( NULL
, NULL
, 0, &required_size
),
205 ok( GetLastError() == ERROR_INVALID_PARAMETER
,
206 "Expected error %lx, got %lx\n", ERROR_INVALID_PARAMETER
, GetLastError() );
208 SetLastError( 0xdeadbeef );
209 ok( !SetupDiGetClassDescriptionA( &test_class_guid
, NULL
, 0, &required_size
),
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
);
216 class_desc
= HeapAlloc( GetProcessHeap(), 0, required_size
);
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
);
229 HeapFree( GetProcessHeap(), 0, class_desc
);
232 static void test_SetupDiGetClassDevsA(void)
234 HDEVINFO device_info
;
236 SetLastError( 0xdeadbeef );
237 device_info
= SetupDiGetClassDevs( NULL
, NULL
, NULL
, 0 );
238 ok( device_info
== INVALID_HANDLE_VALUE
,
240 ok( GetLastError() == ERROR_INVALID_PARAMETER
,
241 "Expected error %lx, got %lx\n", ERROR_INVALID_PARAMETER
, GetLastError() );
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() );
251 SetLastError( 0xdeadbeef );
252 device_info
= SetupDiGetClassDevs( NULL
, NULL
, NULL
, DIGCF_DEVICEINTERFACE
);
253 ok( device_info
== INVALID_HANDLE_VALUE
,
255 ok( GetLastError() == ERROR_INVALID_PARAMETER
,
256 "Expected error %lx, got %lx\n", ERROR_INVALID_PARAMETER
, GetLastError() );
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() );
266 SetLastError( 0xdeadbeef );
267 device_info
= SetupDiGetClassDevs( NULL
, "(invalid enumerator)", NULL
, DIGCF_ALLCLASSES
);
268 ok( device_info
== INVALID_HANDLE_VALUE
,
270 ok( GetLastError() == ERROR_INVALID_DATA
,
271 "Expected error %lx, got %lx\n", ERROR_INVALID_DATA
, GetLastError() );
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() );
282 static void test_SetupDiOpenClassRegKeyExA(void)
287 SetLastError( 0xdeadbeef );
288 hkey
= SetupDiOpenClassRegKeyExA( NULL
, 0, 0, NULL
, NULL
);
289 ok( hkey
== INVALID_HANDLE_VALUE
,
291 ok( GetLastError() == ERROR_INVALID_FLAGS
,
292 "Expected error %lx, got %lx\n", ERROR_INVALID_FLAGS
, GetLastError() );
294 SetLastError( 0xdeadbeef );
295 hkey
= SetupDiOpenClassRegKeyExA( NULL
, 0, DIOCR_INSTALLER
| DIOCR_INTERFACE
, NULL
, NULL
);
296 ok( hkey
== INVALID_HANDLE_VALUE
,
298 ok( GetLastError() == ERROR_INVALID_FLAGS
,
299 "Expected error %lx, got %lx\n", ERROR_INVALID_FLAGS
, GetLastError() );
301 SetLastError( 0xdeadbeef );
302 hkey
= SetupDiOpenClassRegKeyExA( NULL
, 0, DIOCR_INSTALLER
, NULL
, NULL
);
303 ok( hkey
== INVALID_HANDLE_VALUE
,
305 ok( GetLastError() == ERROR_INVALID_CLASS
,
306 "Expected error %x, got %lx\n", ERROR_INVALID_CLASS
, GetLastError() );
308 SetLastError( 0xdeadbeef );
309 hkey
= SetupDiOpenClassRegKeyExA( NULL
, 0, DIOCR_INTERFACE
, NULL
, NULL
);
310 ok( hkey
== INVALID_HANDLE_VALUE
,
312 ok( GetLastError() == ERROR_INVALID_CLASS
,
313 "Expected error %x, got %lx\n", ERROR_INVALID_CLASS
, GetLastError() );
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
);
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
);
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
);
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
);
339 test_SetupDiBuildClassInfoList();
340 test_SetupDiClassGuidsFromNameA();
341 test_SetupDiClassNameFromGuidA();
342 test_SetupDiGetClassDescriptionA();
343 test_SetupDiGetClassDevsA();
344 test_SetupDiOpenClassRegKeyExA();