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
35 #include "wine/test.h"
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";
40 static const char *debugstr_guid(const GUID
*guid
)
42 static char guidSTR1
[39];
43 static char guidSTR2
[39];
47 if (!guid
) return NULL
;
50 guidSTR
= index
? guidSTR1
: guidSTR2
;
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]);
60 static void test_SetupDiBuildClassInfoList(void)
62 LPGUID guid_list
= NULL
;
63 DWORD required_size
, size
;
65 SetLastError( 0xdeadbeef );
66 ok( !SetupDiBuildClassInfoList( 0, NULL
, 0, NULL
),
68 ok( GetLastError() == ERROR_INVALID_PARAMETER
,
69 "Expected error %lx, got %lx", ERROR_INVALID_PARAMETER
, GetLastError() );
71 SetLastError( 0xdeadbeef );
72 ok( !SetupDiBuildClassInfoList( 0, NULL
, 0, &required_size
),
74 ok( GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
75 "Expected error %lx, got %lx\n", ERROR_INSUFFICIENT_BUFFER
, GetLastError() );
77 guid_list
= HeapAlloc( GetProcessHeap(), 0, ( required_size
+ 1 ) * sizeof( GUID
) );
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
);
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
);
96 HeapFree( GetProcessHeap(), 0, guid_list
);
99 static void test_SetupDiClassGuidsFromNameA(void)
101 LPGUID guid_list
= NULL
;
102 DWORD required_size
, size
;
104 SetLastError( 0xdeadbeef );
105 ok( !SetupDiClassGuidsFromNameA( NULL
, NULL
, 0, NULL
),
107 ok( GetLastError() == ERROR_INVALID_PARAMETER
,
108 "Expected error %lx, got %lx\n", ERROR_INVALID_PARAMETER
, GetLastError() );
110 SetLastError( 0xdeadbeef );
111 ok( !SetupDiClassGuidsFromNameA( NULL
, NULL
, 0, &required_size
),
113 ok( GetLastError() == ERROR_INVALID_PARAMETER
,
114 "Expected error %lx, got %lx\n", ERROR_INVALID_PARAMETER
, GetLastError() );
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
);
121 SetLastError( 0xdeadbeef );
122 ok( !SetupDiClassGuidsFromNameA( test_class_name
, NULL
, 0, &required_size
),
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
);
128 guid_list
= HeapAlloc( GetProcessHeap(), 0, ( required_size
+ 1 ) * sizeof( GUID
) );
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] ) );
145 HeapFree( GetProcessHeap(), 0, guid_list
);
148 static void test_SetupDiClassNameFromGuidA(void)
150 CHAR
* class_name
= NULL
;
151 DWORD required_size
, size
;
153 SetLastError( 0xdeadbeef );
154 ok( !SetupDiClassNameFromGuidA( NULL
, NULL
, 0, NULL
),
156 ok( GetLastError() == ERROR_INVALID_CLASS
,
157 "Expected error %x, got %lx\n", ERROR_INVALID_CLASS
, GetLastError() );
159 SetLastError( 0xdeadbeef );
160 ok( !SetupDiClassNameFromGuidA( NULL
, NULL
, 0, &required_size
),
162 ok( GetLastError() == ERROR_INVALID_CLASS
,
163 "Expected error %x, got %lx\n", ERROR_INVALID_CLASS
, GetLastError() );
165 SetLastError( 0xdeadbeef );
166 ok( !SetupDiClassNameFromGuidA( &test_class_guid
, NULL
, 0, &required_size
),
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
);
173 class_name
= HeapAlloc( GetProcessHeap(), 0, required_size
);
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
);
190 HeapFree( GetProcessHeap(), 0, class_name
);
193 static void test_SetupDiGetClassDescriptionA(void)
195 CHAR
* class_desc
= NULL
;
196 DWORD required_size
, size
;
198 SetLastError( 0xdeadbeef );
199 ok( !SetupDiGetClassDescriptionA( NULL
, NULL
, 0, NULL
),
201 ok( GetLastError() == ERROR_INVALID_PARAMETER
,
202 "Expected error %lx, got %lx\n", ERROR_INVALID_PARAMETER
, GetLastError() );
204 SetLastError( 0xdeadbeef );
205 ok( !SetupDiGetClassDescriptionA( NULL
, NULL
, 0, &required_size
),
207 ok( GetLastError() == ERROR_INVALID_PARAMETER
,
208 "Expected error %lx, got %lx\n", ERROR_INVALID_PARAMETER
, GetLastError() );
210 SetLastError( 0xdeadbeef );
211 ok( !SetupDiGetClassDescriptionA( &test_class_guid
, NULL
, 0, &required_size
),
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
);
218 class_desc
= HeapAlloc( GetProcessHeap(), 0, required_size
);
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
);
231 HeapFree( GetProcessHeap(), 0, class_desc
);
234 static void test_SetupDiGetClassDevsA(void)
236 HDEVINFO device_info
;
238 SetLastError( 0xdeadbeef );
239 device_info
= SetupDiGetClassDevs( NULL
, NULL
, NULL
, 0 );
240 ok( device_info
== INVALID_HANDLE_VALUE
,
242 ok( GetLastError() == ERROR_INVALID_PARAMETER
,
243 "Expected error %lx, got %lx\n", ERROR_INVALID_PARAMETER
, GetLastError() );
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() );
253 SetLastError( 0xdeadbeef );
254 device_info
= SetupDiGetClassDevs( NULL
, NULL
, NULL
, DIGCF_DEVICEINTERFACE
);
255 ok( device_info
== INVALID_HANDLE_VALUE
,
257 ok( GetLastError() == ERROR_INVALID_PARAMETER
,
258 "Expected error %lx, got %lx\n", ERROR_INVALID_PARAMETER
, GetLastError() );
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() );
268 SetLastError( 0xdeadbeef );
269 device_info
= SetupDiGetClassDevs( NULL
, "(invalid enumerator)", NULL
, DIGCF_ALLCLASSES
);
270 ok( device_info
== INVALID_HANDLE_VALUE
,
272 ok( GetLastError() == ERROR_INVALID_DATA
,
273 "Expected error %lx, got %lx\n", ERROR_INVALID_DATA
, GetLastError() );
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() );
284 static void test_SetupDiOpenClassRegKeyExA(void)
289 SetLastError( 0xdeadbeef );
290 hkey
= SetupDiOpenClassRegKeyExA( NULL
, 0, 0, NULL
, NULL
);
291 ok( hkey
== INVALID_HANDLE_VALUE
,
293 ok( GetLastError() == ERROR_INVALID_FLAGS
,
294 "Expected error %lx, got %lx\n", ERROR_INVALID_FLAGS
, GetLastError() );
296 SetLastError( 0xdeadbeef );
297 hkey
= SetupDiOpenClassRegKeyExA( NULL
, 0, DIOCR_INSTALLER
| DIOCR_INTERFACE
, NULL
, NULL
);
298 ok( hkey
== INVALID_HANDLE_VALUE
,
300 ok( GetLastError() == ERROR_INVALID_FLAGS
,
301 "Expected error %lx, got %lx\n", ERROR_INVALID_FLAGS
, GetLastError() );
303 SetLastError( 0xdeadbeef );
304 hkey
= SetupDiOpenClassRegKeyExA( NULL
, 0, DIOCR_INSTALLER
, NULL
, NULL
);
305 ok( hkey
== INVALID_HANDLE_VALUE
,
307 ok( GetLastError() == ERROR_INVALID_CLASS
,
308 "Expected error %x, got %lx\n", ERROR_INVALID_CLASS
, GetLastError() );
310 SetLastError( 0xdeadbeef );
311 hkey
= SetupDiOpenClassRegKeyExA( NULL
, 0, DIOCR_INTERFACE
, NULL
, NULL
);
312 ok( hkey
== INVALID_HANDLE_VALUE
,
314 ok( GetLastError() == ERROR_INVALID_CLASS
,
315 "Expected error %x, got %lx\n", ERROR_INVALID_CLASS
, GetLastError() );
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
);
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
);
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
);
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
);
341 test_SetupDiBuildClassInfoList();
342 test_SetupDiClassGuidsFromNameA();
343 test_SetupDiClassNameFromGuidA();
344 test_SetupDiGetClassDescriptionA();
345 test_SetupDiGetClassDevsA();
346 test_SetupDiOpenClassRegKeyExA();