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 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
);
127 guid_list
= HeapAlloc( GetProcessHeap(), 0, ( required_size
+ 1 ) * sizeof( GUID
) );
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] ) );
144 HeapFree( GetProcessHeap(), 0, guid_list
);
147 static void test_SetupDiClassNameFromGuidA(void)
149 CHAR
* class_name
= NULL
;
150 DWORD required_size
, size
;
152 SetLastError( 0xdeadbeef );
153 ok( !SetupDiClassNameFromGuidA( NULL
, NULL
, 0, NULL
),
155 ok( GetLastError() == ERROR_INVALID_CLASS
,
156 "Expected error %x, got %lx\n", ERROR_INVALID_CLASS
, GetLastError() );
158 SetLastError( 0xdeadbeef );
159 ok( !SetupDiClassNameFromGuidA( NULL
, NULL
, 0, &required_size
),
161 ok( GetLastError() == ERROR_INVALID_CLASS
,
162 "Expected error %x, got %lx\n", ERROR_INVALID_CLASS
, GetLastError() );
164 SetLastError( 0xdeadbeef );
165 ok( !SetupDiClassNameFromGuidA( &test_class_guid
, NULL
, 0, &required_size
),
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
);
172 class_name
= HeapAlloc( GetProcessHeap(), 0, required_size
);
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
);
189 HeapFree( GetProcessHeap(), 0, class_name
);
192 static void test_SetupDiGetClassDescriptionA(void)
194 CHAR
* class_desc
= NULL
;
195 DWORD required_size
, size
;
197 SetLastError( 0xdeadbeef );
198 ok( !SetupDiGetClassDescriptionA( NULL
, NULL
, 0, NULL
),
200 ok( GetLastError() == ERROR_INVALID_PARAMETER
,
201 "Expected error %lx, got %lx\n", ERROR_INVALID_PARAMETER
, GetLastError() );
203 SetLastError( 0xdeadbeef );
204 ok( !SetupDiGetClassDescriptionA( NULL
, NULL
, 0, &required_size
),
206 ok( GetLastError() == ERROR_INVALID_PARAMETER
,
207 "Expected error %lx, got %lx\n", ERROR_INVALID_PARAMETER
, GetLastError() );
209 SetLastError( 0xdeadbeef );
210 ok( !SetupDiGetClassDescriptionA( &test_class_guid
, NULL
, 0, &required_size
),
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
);
217 class_desc
= HeapAlloc( GetProcessHeap(), 0, required_size
);
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
);
230 HeapFree( GetProcessHeap(), 0, class_desc
);
233 static void test_SetupDiGetClassDevsA(void)
235 HDEVINFO device_info
;
237 SetLastError( 0xdeadbeef );
238 device_info
= SetupDiGetClassDevs( NULL
, NULL
, NULL
, 0 );
239 ok( device_info
== INVALID_HANDLE_VALUE
,
241 ok( GetLastError() == ERROR_INVALID_PARAMETER
,
242 "Expected error %lx, got %lx\n", ERROR_INVALID_PARAMETER
, GetLastError() );
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() );
252 SetLastError( 0xdeadbeef );
253 device_info
= SetupDiGetClassDevs( NULL
, NULL
, NULL
, DIGCF_DEVICEINTERFACE
);
254 ok( device_info
== INVALID_HANDLE_VALUE
,
256 ok( GetLastError() == ERROR_INVALID_PARAMETER
,
257 "Expected error %lx, got %lx\n", ERROR_INVALID_PARAMETER
, GetLastError() );
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() );
267 SetLastError( 0xdeadbeef );
268 device_info
= SetupDiGetClassDevs( NULL
, "(invalid enumerator)", NULL
, DIGCF_ALLCLASSES
);
269 ok( device_info
== INVALID_HANDLE_VALUE
,
271 ok( GetLastError() == ERROR_INVALID_DATA
,
272 "Expected error %lx, got %lx\n", ERROR_INVALID_DATA
, GetLastError() );
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() );
283 static void test_SetupDiOpenClassRegKeyExA(void)
288 SetLastError( 0xdeadbeef );
289 hkey
= SetupDiOpenClassRegKeyExA( NULL
, 0, 0, NULL
, NULL
);
290 ok( hkey
== INVALID_HANDLE_VALUE
,
292 ok( GetLastError() == ERROR_INVALID_FLAGS
,
293 "Expected error %lx, got %lx\n", ERROR_INVALID_FLAGS
, GetLastError() );
295 SetLastError( 0xdeadbeef );
296 hkey
= SetupDiOpenClassRegKeyExA( NULL
, 0, DIOCR_INSTALLER
| DIOCR_INTERFACE
, NULL
, NULL
);
297 ok( hkey
== INVALID_HANDLE_VALUE
,
299 ok( GetLastError() == ERROR_INVALID_FLAGS
,
300 "Expected error %lx, got %lx\n", ERROR_INVALID_FLAGS
, GetLastError() );
302 SetLastError( 0xdeadbeef );
303 hkey
= SetupDiOpenClassRegKeyExA( NULL
, 0, DIOCR_INSTALLER
, NULL
, NULL
);
304 ok( hkey
== INVALID_HANDLE_VALUE
,
306 ok( GetLastError() == ERROR_INVALID_CLASS
,
307 "Expected error %x, got %lx\n", ERROR_INVALID_CLASS
, GetLastError() );
309 SetLastError( 0xdeadbeef );
310 hkey
= SetupDiOpenClassRegKeyExA( NULL
, 0, DIOCR_INTERFACE
, NULL
, NULL
);
311 ok( hkey
== INVALID_HANDLE_VALUE
,
313 ok( GetLastError() == ERROR_INVALID_CLASS
,
314 "Expected error %x, got %lx\n", ERROR_INVALID_CLASS
, GetLastError() );
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
);
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
);
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
);
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
);
340 test_SetupDiBuildClassInfoList();
341 test_SetupDiClassGuidsFromNameA();
342 test_SetupDiClassNameFromGuidA();
343 test_SetupDiGetClassDescriptionA();
344 test_SetupDiGetClassDevsA();
345 test_SetupDiOpenClassRegKeyExA();