ReactOS 0.4.15-dev-5669-g09dde2c
devclass.c
Go to the documentation of this file.
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#define ok_lasterr(err) \
36 ok( GetLastError() == (err), \
37 "Expected error %lx, got %lx\n", (DWORD)(err), GetLastError() )
38
39static GUID test_class_guid = { 0x4d36e967, 0xe325, 0x11ce, { 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 } };
40static char test_class_name[MAX_CLASS_NAME_LEN] = "DiskDrive";
41
42static const char *debugstr_guid(const GUID *guid)
43{
44 static char guidSTR1[39];
45 static char guidSTR2[39];
46 char* guidSTR;
47 static BOOL index;
48
49 if (!guid) return NULL;
50
51 index = !index;
52 guidSTR = index ? guidSTR1 : guidSTR2;
53
54 snprintf(guidSTR, sizeof(guidSTR1),
55 "{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
56 guid->Data1, guid->Data2, guid->Data3,
57 guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
58 guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]);
59 return guidSTR;
60}
61
63{
65 DWORD required_size, size;
66
67 SetLastError( 0xdeadbeef );
69 "Fail expected" );
71
72 SetLastError( 0xdeadbeef );
73 ok( !SetupDiBuildClassInfoList( 0, NULL, 0, &required_size ),
74 "Fail expected\n" );
76
77 guid_list = HeapAlloc( GetProcessHeap(), 0, ( required_size + 1 ) * sizeof( GUID ) );
78 if ( !guid_list )
79 return;
80
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 );
89
90 if ( size > 0 )
91 {
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 ) );
95 "Error reported %lx\n", GetLastError() );
96 }
98}
99
101{
103 DWORD required_size, size;
104
105 SetLastError( 0xdeadbeef );
107 "Fail expected\n" );
109
110 SetLastError( 0xdeadbeef );
111 ok( !SetupDiClassGuidsFromNameA( NULL, NULL, 0, &required_size ),
112 "Fail expected\n" );
114
115 SetLastError( 0xdeadbeef );
116 ok( SetupDiClassGuidsFromNameA( "", NULL, 0, &required_size ),
117 "Error reported %lx\n", GetLastError() );
118 ok( required_size == 0, "Expected 0, got %lu\n", required_size );
119
120 SetLastError( 0xdeadbeef );
121 ok( !SetupDiClassGuidsFromNameA( test_class_name, NULL, 0, &required_size ),
122 "Fail expected\n" );
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 );
132 "Error reported %lx\n", GetLastError() );
133 ok( size == required_size, "Expected size %lu, got %lu\n", required_size, size );
135 "Expected %s, got %s for class %s\n", debugstr_guid( &test_class_guid ), debugstr_guid( &guid_list[0] ), test_class_name );
136 SetLastError( 0xdeadbeef );
138 "Error reported %lx\n", GetLastError() );
139 ok( size == required_size, "Expected size %lu, got %lu\n", required_size, size );
141 "Expected %s, got %s for class %s\n", debugstr_guid( &test_class_guid ), debugstr_guid( &guid_list[0] ), test_class_name );
142
144}
145
147{
148 CHAR* class_name = NULL;
149 DWORD required_size, size;
150
151 SetLastError( 0xdeadbeef );
153 "Fail expected\n" );
155
156 SetLastError( 0xdeadbeef );
157 ok( !SetupDiClassNameFromGuidA( NULL, NULL, 0, &required_size ),
158 "Fail expected\n" );
160
161 SetLastError( 0xdeadbeef );
162 ok( !SetupDiClassNameFromGuidA( &test_class_guid, NULL, 0, &required_size ),
163 "Fail expected\n" );
165 ok( required_size > 0, "Expected > 0, got %lu\n", required_size );
166 ok( required_size < MAX_CLASS_NAME_LEN, "Expected < %u, got %lu for GUID %s\n", MAX_CLASS_NAME_LEN, required_size, debugstr_guid( &test_class_guid ) );
167
168 class_name = HeapAlloc( GetProcessHeap(), 0, required_size );
169 if ( !class_name )
170 return;
171
172 SetLastError( 0xdeadbeef );
173 ok( SetupDiClassNameFromGuidA( &test_class_guid, class_name, required_size, &size ),
174 "Error reported %lx\n", GetLastError() );
175 ok( size == required_size, "Expected size %lu, got %lu\n", required_size, size );
176 ok( !strcmp( class_name, test_class_name ),
177 "Expected %s, got %s\n", test_class_name, class_name );
178 SetLastError( 0xdeadbeef );
179 ok( SetupDiClassNameFromGuidA( &test_class_guid, class_name, required_size + 1, &size ),
180 "Error reported %lx\n", GetLastError() );
181 ok( size == required_size, "Expected size %lu, got %lu\n", required_size, size );
182 ok( !strcmp( class_name, test_class_name ),
183 "Expected %s, got %s\n", test_class_name, class_name );
184
185 HeapFree( GetProcessHeap(), 0, class_name );
186}
187
189{
190 CHAR* class_desc = NULL;
191 DWORD required_size, size;
192
193 SetLastError( 0xdeadbeef );
195 "Fail expected\n" );
197
198 SetLastError( 0xdeadbeef );
199 ok( !SetupDiGetClassDescriptionA( NULL, NULL, 0, &required_size ),
200 "Fail expected\n" );
202
203 SetLastError( 0xdeadbeef );
204 ok( !SetupDiGetClassDescriptionA( &test_class_guid, NULL, 0, &required_size ),
205 "Fail expected\n" );
207 ok( required_size > 0, "Expected > 0, got %lu\n", required_size );
208 ok( required_size < LINE_LEN, "Expected < %u, got %lu\n", LINE_LEN, required_size );
209
210 class_desc = HeapAlloc( GetProcessHeap(), 0, required_size );
211 if ( !class_desc )
212 return;
213
214 SetLastError( 0xdeadbeef );
215 ok( SetupDiGetClassDescriptionA( &test_class_guid, class_desc, required_size, &size ),
216 "Error reported %lx\n", GetLastError() );
217 ok( size == required_size, "Expected size %lu, got %lu\n", required_size, size );
218 SetLastError( 0xdeadbeef );
219 ok( SetupDiGetClassDescriptionA( &test_class_guid, class_desc, required_size + 1, &size ),
220 "Error reported %lx\n", GetLastError() );
221 ok( size == required_size, "Expected size %lu, got %lu\n", required_size, size );
222
223 HeapFree( GetProcessHeap(), 0, class_desc );
224}
225
227{
228 HDEVINFO device_info;
229
230 SetLastError( 0xdeadbeef );
231 device_info = SetupDiGetClassDevs( NULL, NULL, NULL, 0 );
232 ok( device_info == INVALID_HANDLE_VALUE,
233 "Fail expected\n" );
235
236 SetLastError( 0xdeadbeef );
238 ok( device_info != INVALID_HANDLE_VALUE,
239 "Error reported %lx\n", GetLastError() );
240 SetLastError( 0xdeadbeef );
241 ok( SetupDiDestroyDeviceInfoList( device_info ),
242 "Error reported %lx\n", GetLastError() );
243
244 SetLastError( 0xdeadbeef );
246 ok( device_info == INVALID_HANDLE_VALUE,
247 "Fail expected\n" );
249
250 SetLastError( 0xdeadbeef );
251 device_info = SetupDiGetClassDevs( &test_class_guid, NULL, NULL, 0 );
252 ok( device_info != INVALID_HANDLE_VALUE,
253 "Error reported %lx\n", GetLastError() );
254 SetLastError( 0xdeadbeef );
255 ok( SetupDiDestroyDeviceInfoList( device_info ),
256 "Error reported %lx\n", GetLastError() );
257
258 SetLastError( 0xdeadbeef );
259 device_info = SetupDiGetClassDevs( NULL, "(invalid enumerator)", NULL, DIGCF_ALLCLASSES );
260 ok( device_info == INVALID_HANDLE_VALUE,
261 "Fail expected\n" );
263
264 SetLastError( 0xdeadbeef );
265 device_info = SetupDiGetClassDevs( NULL, "Root", NULL, DIGCF_ALLCLASSES );
266 ok( device_info != INVALID_HANDLE_VALUE,
267 "Error reported %lx\n", GetLastError() );
268 SetLastError( 0xdeadbeef );
269 ok( SetupDiDestroyDeviceInfoList( device_info ),
270 "Error reported %lx\n", GetLastError() );
271}
272
274{
275 const GUID not_existing_guid = { 0xdeadbeef, 0xdead, 0xbeef, { 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff } };
276 HDEVINFO dev_info;
277 BOOL ret;
279
280 dev_info = SetupDiGetClassDevsExW(&not_existing_guid, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE, NULL, NULL, NULL);
281 ok(dev_info != INVALID_HANDLE_VALUE, "Expected success\n");
282
283 ZeroMemory(&info, sizeof(info));
284 info.cbSize = sizeof(info);
285 ret = SetupDiEnumDeviceInfo(dev_info, 0, &info);
286 ok (!ret, "Expected failure.\n");
288
290}
291
293{
294 HKEY hkey;
295 LONG err;
296
297 SetLastError( 0xdeadbeef );
298 hkey = SetupDiOpenClassRegKeyExA( NULL, 0, 0, NULL, NULL );
299 ok( hkey == INVALID_HANDLE_VALUE,
300 "Fail expected\n" );
302
303 SetLastError( 0xdeadbeef );
305 ok( hkey == INVALID_HANDLE_VALUE,
306 "Fail expected\n" );
308
309 SetLastError( 0xdeadbeef );
311 ok( hkey == INVALID_HANDLE_VALUE,
312 "Fail expected\n" );
314
315 SetLastError( 0xdeadbeef );
317 ok( hkey == INVALID_HANDLE_VALUE,
318 "Fail expected\n" );
320
321 SetLastError( 0xdeadbeef );
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 );
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 SetLastError( 0xdeadbeef );
335 ok( hkey != INVALID_HANDLE_VALUE, "Got error %lx\n", GetLastError() );
336 err = RegCloseKey( hkey );
337 ok( err == ERROR_SUCCESS, "Got error %lx\n", err );
338
339 err = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "System\\CurrentControlSet\\Control\\Class", 0, KEY_SET_VALUE, &hkey);
340 ok( err == ERROR_SUCCESS, "Got error %lx\n", err );
341}
342
343START_TEST(devclass)
344{
352}
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
#define index(s, c)
Definition: various.h:29
#define RegCloseKey(hKey)
Definition: registry.h:47
#define MAX_CLASS_NAME_LEN
Definition: cfgmgr32.h:52
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
LONG WINAPI RegOpenKeyExA(_In_ HKEY hKey, _In_ LPCSTR lpSubKey, _In_ DWORD ulOptions, _In_ REGSAM samDesired, _Out_ PHKEY phkResult)
Definition: reg.c:3321
#define GetProcessHeap()
Definition: compat.h:736
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define SetLastError(x)
Definition: compat.h:752
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define HeapAlloc
Definition: compat.h:733
#define ERROR_NO_MORE_ITEMS
Definition: compat.h:105
#define HeapFree(x, y, z)
Definition: compat.h:735
BOOL WINAPI SetupDiBuildClassInfoList(DWORD Flags, LPGUID ClassGuidList, DWORD ClassGuidListSize, PDWORD RequiredSize)
Definition: devinst.c:645
BOOL WINAPI SetupDiEnumDeviceInfo(HDEVINFO devinfo, DWORD index, PSP_DEVINFO_DATA info)
Definition: devinst.c:1787
BOOL WINAPI SetupDiClassNameFromGuidA(const GUID *ClassGuid, PSTR ClassName, DWORD ClassNameSize, PDWORD RequiredSize)
Definition: devinst.c:1053
BOOL WINAPI SetupDiGetClassDescriptionA(const GUID *ClassGuid, PSTR ClassDescription, DWORD ClassDescriptionSize, PDWORD RequiredSize)
Definition: devinst.c:2058
BOOL WINAPI SetupDiClassGuidsFromNameA(LPCSTR ClassName, LPGUID ClassGuidList, DWORD ClassGuidListSize, PDWORD RequiredSize)
Definition: devinst.c:854
HDEVINFO WINAPI SetupDiGetClassDevsExW(CONST GUID *class, PCWSTR enumstr, HWND parent, DWORD flags, HDEVINFO deviceset, PCWSTR machine, PVOID reserved)
Definition: devinst.c:2305
BOOL WINAPI SetupDiDestroyDeviceInfoList(HDEVINFO devinfo)
Definition: devinst.c:2893
HKEY WINAPI SetupDiOpenClassRegKeyExA(const GUID *ClassGuid, REGSAM samDesired, DWORD Flags, PCSTR MachineName, PVOID Reserved)
Definition: devinst.c:3630
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLsizeiptr size
Definition: glext.h:5919
GLuint index
Definition: glext.h:6031
#define debugstr_guid
Definition: kernel32.h:35
const GUID * guid
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static void test_SetupDiGetClassDevsA(void)
Definition: devclass.c:226
static void test_SetupDiBuildClassInfoList(void)
Definition: devclass.c:62
static char test_class_name[MAX_CLASS_NAME_LEN]
Definition: devclass.c:40
static void test_SetupDiOpenClassRegKeyExA(void)
Definition: devclass.c:292
static void test_SetupDiGetClassDevsExW(void)
Definition: devclass.c:273
static void test_SetupDiGetClassDescriptionA(void)
Definition: devclass.c:188
static void test_SetupDiClassNameFromGuidA(void)
Definition: devclass.c:146
static void test_SetupDiClassGuidsFromNameA(void)
Definition: devclass.c:100
static GUID test_class_guid
Definition: devclass.c:39
#define ok_lasterr(err)
Definition: devclass.c:35
static const GUID * guid_list[]
Definition: metadata.c:2260
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
#define KEY_SET_VALUE
Definition: nt_native.h:1017
long LONG
Definition: pedump.c:60
#define IsEqualIID(riid1, riid2)
Definition: guiddef.h:95
#define err(...)
#define ERROR_INVALID_CLASS
Definition: setupapi.h:302
#define LINE_LEN
Definition: setupapi.h:20
#define DIOCR_INTERFACE
Definition: setupapi.h:177
#define DIGCF_DEVICEINTERFACE
Definition: setupapi.h:174
#define DIGCF_ALLCLASSES
Definition: setupapi.h:172
#define SetupDiGetClassDevs
Definition: setupapi.h:2593
#define DIGCF_PRESENT
Definition: setupapi.h:171
#define DIOCR_INSTALLER
Definition: setupapi.h:176
int ret
#define ZeroMemory
Definition: winbase.h:1670
DWORD WINAPI GetLastError(void)
Definition: except.c:1040
#define ERROR_INVALID_FLAGS
Definition: winerror.h:583
#define ERROR_INVALID_DATA
Definition: winerror.h:116
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define snprintf
Definition: wintirpc.h:48
char CHAR
Definition: xmlstorage.h:175