4 * Copyright 2006 Christian Gmeiner
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of 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 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
32 #include "wine/test.h"
34 /* function pointers */
35 static HMODULE hSetupAPI
;
36 static HDEVINFO (WINAPI
*pSetupDiCreateDeviceInfoList
)(GUID
*,HWND
);
37 static HDEVINFO (WINAPI
*pSetupDiCreateDeviceInfoListExW
)(GUID
*,HWND
,PCWSTR
,PVOID
);
38 static BOOL (WINAPI
*pSetupDiCreateDeviceInterfaceA
)(HDEVINFO
, PSP_DEVINFO_DATA
, const GUID
*, PCSTR
, DWORD
, PSP_DEVICE_INTERFACE_DATA
);
39 static BOOL (WINAPI
*pSetupDiCallClassInstaller
)(DI_FUNCTION
, HDEVINFO
, PSP_DEVINFO_DATA
);
40 static BOOL (WINAPI
*pSetupDiDestroyDeviceInfoList
)(HDEVINFO
);
41 static BOOL (WINAPI
*pSetupDiEnumDeviceInfo
)(HDEVINFO
, DWORD
, PSP_DEVINFO_DATA
);
42 static BOOL (WINAPI
*pSetupDiEnumDeviceInterfaces
)(HDEVINFO
, PSP_DEVINFO_DATA
, const GUID
*, DWORD
, PSP_DEVICE_INTERFACE_DATA
);
43 static BOOL (WINAPI
*pSetupDiInstallClassA
)(HWND
, PCSTR
, DWORD
, HSPFILEQ
);
44 static HKEY (WINAPI
*pSetupDiOpenClassRegKeyExA
)(GUID
*,REGSAM
,DWORD
,PCSTR
,PVOID
);
45 static HKEY (WINAPI
*pSetupDiOpenDevRegKey
)(HDEVINFO
, PSP_DEVINFO_DATA
, DWORD
, DWORD
, DWORD
, REGSAM
);
46 static HKEY (WINAPI
*pSetupDiCreateDevRegKeyW
)(HDEVINFO
, PSP_DEVINFO_DATA
, DWORD
, DWORD
, DWORD
, HINF
, PCWSTR
);
47 static BOOL (WINAPI
*pSetupDiCreateDeviceInfoA
)(HDEVINFO
, PCSTR
, GUID
*, PCSTR
, HWND
, DWORD
, PSP_DEVINFO_DATA
);
48 static BOOL (WINAPI
*pSetupDiCreateDeviceInfoW
)(HDEVINFO
, PCWSTR
, GUID
*, PCWSTR
, HWND
, DWORD
, PSP_DEVINFO_DATA
);
49 static BOOL (WINAPI
*pSetupDiGetDeviceInstanceIdA
)(HDEVINFO
, PSP_DEVINFO_DATA
, PSTR
, DWORD
, PDWORD
);
50 static BOOL (WINAPI
*pSetupDiGetDeviceInterfaceDetailA
)(HDEVINFO
, PSP_DEVICE_INTERFACE_DATA
, PSP_DEVICE_INTERFACE_DETAIL_DATA_A
, DWORD
, PDWORD
, PSP_DEVINFO_DATA
);
51 static BOOL (WINAPI
*pSetupDiGetDeviceInterfaceDetailW
)(HDEVINFO
, PSP_DEVICE_INTERFACE_DATA
, PSP_DEVICE_INTERFACE_DETAIL_DATA_W
, DWORD
, PDWORD
, PSP_DEVINFO_DATA
);
52 static BOOL (WINAPI
*pSetupDiRegisterDeviceInfo
)(HDEVINFO
, PSP_DEVINFO_DATA
, DWORD
, PSP_DETSIG_CMPPROC
, PVOID
, PSP_DEVINFO_DATA
);
53 static HDEVINFO (WINAPI
*pSetupDiGetClassDevsA
)(CONST GUID
*, LPCSTR
, HWND
, DWORD
);
54 static HDEVINFO (WINAPI
*pSetupDiGetClassDevsW
)(CONST GUID
*, LPCWSTR
, HWND
, DWORD
);
55 static BOOL (WINAPI
*pSetupDiSetDeviceRegistryPropertyA
)(HDEVINFO
, PSP_DEVINFO_DATA
, DWORD
, const BYTE
*, DWORD
);
56 static BOOL (WINAPI
*pSetupDiSetDeviceRegistryPropertyW
)(HDEVINFO
, PSP_DEVINFO_DATA
, DWORD
, const BYTE
*, DWORD
);
57 static BOOL (WINAPI
*pSetupDiGetDeviceRegistryPropertyA
)(HDEVINFO
, PSP_DEVINFO_DATA
, DWORD
, PDWORD
, PBYTE
, DWORD
, PDWORD
);
58 static BOOL (WINAPI
*pSetupDiGetDeviceRegistryPropertyW
)(HDEVINFO
, PSP_DEVINFO_DATA
, DWORD
, PDWORD
, PBYTE
, DWORD
, PDWORD
);
60 /* This is a unique guid for testing purposes */
61 static GUID guid
= {0x6a55b5a4, 0x3f65, 0x11db, {0xb7,0x04,0x00,0x11,0x95,0x5c,0x2b,0xdb}};
63 static void init_function_pointers(void)
65 hSetupAPI
= GetModuleHandleA("setupapi.dll");
67 pSetupDiCreateDeviceInfoA
= (void *)GetProcAddress(hSetupAPI
, "SetupDiCreateDeviceInfoA");
68 pSetupDiCreateDeviceInfoW
= (void *)GetProcAddress(hSetupAPI
, "SetupDiCreateDeviceInfoW");
69 pSetupDiCreateDeviceInfoList
= (void *)GetProcAddress(hSetupAPI
, "SetupDiCreateDeviceInfoList");
70 pSetupDiCreateDeviceInfoListExW
= (void *)GetProcAddress(hSetupAPI
, "SetupDiCreateDeviceInfoListExW");
71 pSetupDiCreateDeviceInterfaceA
= (void *)GetProcAddress(hSetupAPI
, "SetupDiCreateDeviceInterfaceA");
72 pSetupDiDestroyDeviceInfoList
= (void *)GetProcAddress(hSetupAPI
, "SetupDiDestroyDeviceInfoList");
73 pSetupDiCallClassInstaller
= (void *)GetProcAddress(hSetupAPI
, "SetupDiCallClassInstaller");
74 pSetupDiEnumDeviceInfo
= (void *)GetProcAddress(hSetupAPI
, "SetupDiEnumDeviceInfo");
75 pSetupDiEnumDeviceInterfaces
= (void *)GetProcAddress(hSetupAPI
, "SetupDiEnumDeviceInterfaces");
76 pSetupDiGetDeviceInstanceIdA
= (void *)GetProcAddress(hSetupAPI
, "SetupDiGetDeviceInstanceIdA");
77 pSetupDiGetDeviceInterfaceDetailA
= (void *)GetProcAddress(hSetupAPI
, "SetupDiGetDeviceInterfaceDetailA");
78 pSetupDiGetDeviceInterfaceDetailW
= (void *)GetProcAddress(hSetupAPI
, "SetupDiGetDeviceInterfaceDetailW");
79 pSetupDiInstallClassA
= (void *)GetProcAddress(hSetupAPI
, "SetupDiInstallClassA");
80 pSetupDiOpenClassRegKeyExA
= (void *)GetProcAddress(hSetupAPI
, "SetupDiOpenClassRegKeyExA");
81 pSetupDiOpenDevRegKey
= (void *)GetProcAddress(hSetupAPI
, "SetupDiOpenDevRegKey");
82 pSetupDiCreateDevRegKeyW
= (void *)GetProcAddress(hSetupAPI
, "SetupDiCreateDevRegKeyW");
83 pSetupDiRegisterDeviceInfo
= (void *)GetProcAddress(hSetupAPI
, "SetupDiRegisterDeviceInfo");
84 pSetupDiGetClassDevsA
= (void *)GetProcAddress(hSetupAPI
, "SetupDiGetClassDevsA");
85 pSetupDiGetClassDevsW
= (void *)GetProcAddress(hSetupAPI
, "SetupDiGetClassDevsW");
86 pSetupDiSetDeviceRegistryPropertyA
= (void *)GetProcAddress(hSetupAPI
, "SetupDiSetDeviceRegistryPropertyA");
87 pSetupDiSetDeviceRegistryPropertyW
= (void *)GetProcAddress(hSetupAPI
, "SetupDiSetDeviceRegistryPropertyW");
88 pSetupDiGetDeviceRegistryPropertyA
= (void *)GetProcAddress(hSetupAPI
, "SetupDiGetDeviceRegistryPropertyA");
89 pSetupDiGetDeviceRegistryPropertyW
= (void *)GetProcAddress(hSetupAPI
, "SetupDiGetDeviceRegistryPropertyW");
92 static BOOL
remove_device(void)
95 SP_DEVINFO_DATA devInfo
= { sizeof(devInfo
), { 0 } };
98 SetLastError(0xdeadbeef);
99 set
= pSetupDiGetClassDevsA(&guid
, NULL
, 0, 0);
100 ok(set
!= INVALID_HANDLE_VALUE
, "SetupDiGetClassDevsA failed: %08x\n",
103 SetLastError(0xdeadbeef);
104 ok(pSetupDiEnumDeviceInfo(set
, 0, &devInfo
),
105 "SetupDiEnumDeviceInfo failed: %08x\n", GetLastError());
107 SetLastError(0xdeadbeef);
108 ret
= pSetupDiCallClassInstaller(DIF_REMOVE
, set
, &devInfo
);
110 ok(ret
, "SetupDiCallClassInstaller(DIF_REMOVE...) failed: %08x\n", GetLastError());
112 SetLastError(0xdeadbeef);
113 ok(pSetupDiDestroyDeviceInfoList(set
),
114 "SetupDiDestroyDeviceInfoList failed: %08x\n", GetLastError());
119 /* RegDeleteTreeW from dlls/advapi32/registry.c */
120 LSTATUS WINAPI
devinst_RegDeleteTreeW(HKEY hKey
, LPCWSTR lpszSubKey
)
123 DWORD dwMaxSubkeyLen
, dwMaxValueLen
;
124 DWORD dwMaxLen
, dwSize
;
125 WCHAR szNameBuf
[MAX_PATH
], *lpszName
= szNameBuf
;
130 ret
= RegOpenKeyExW(hKey
, lpszSubKey
, 0, KEY_READ
, &hSubKey
);
134 /* Get highest length for keys, values */
135 ret
= RegQueryInfoKeyW(hSubKey
, NULL
, NULL
, NULL
, NULL
,
136 &dwMaxSubkeyLen
, NULL
, NULL
, &dwMaxValueLen
, NULL
, NULL
, NULL
);
137 if (ret
) goto cleanup
;
141 dwMaxLen
= max(dwMaxSubkeyLen
, dwMaxValueLen
);
142 if (dwMaxLen
> sizeof(szNameBuf
)/sizeof(WCHAR
))
144 /* Name too big: alloc a buffer for it */
145 if (!(lpszName
= HeapAlloc( GetProcessHeap(), 0, dwMaxLen
*sizeof(WCHAR
))))
147 ret
= ERROR_NOT_ENOUGH_MEMORY
;
153 /* Recursively delete all the subkeys */
157 if (RegEnumKeyExW(hSubKey
, 0, lpszName
, &dwSize
, NULL
,
158 NULL
, NULL
, NULL
)) break;
160 ret
= devinst_RegDeleteTreeW(hSubKey
, lpszName
);
161 if (ret
) goto cleanup
;
165 ret
= RegDeleteKeyW(hKey
, lpszSubKey
);
170 if (RegEnumValueW(hKey
, 0, lpszName
, &dwSize
,
171 NULL
, NULL
, NULL
, NULL
)) break;
173 ret
= RegDeleteValueW(hKey
, lpszName
);
174 if (ret
) goto cleanup
;
178 /* Free buffer if allocated */
179 if (lpszName
!= szNameBuf
)
180 HeapFree( GetProcessHeap(), 0, lpszName
);
182 RegCloseKey(hSubKey
);
187 static void test_SetupDiCreateDeviceInfoListEx(void)
192 static CHAR notnull
[] = "NotNull";
193 static const WCHAR machine
[] = { 'd','u','m','m','y',0 };
195 SetLastError(0xdeadbeef);
196 /* create empty DeviceInfoList, but set Reserved to a value, which is not NULL */
197 devlist
= pSetupDiCreateDeviceInfoListExW(NULL
, NULL
, NULL
, notnull
);
199 error
= GetLastError();
200 if (error
== ERROR_CALL_NOT_IMPLEMENTED
)
202 skip("SetupDiCreateDeviceInfoListExW is not implemented\n");
205 ok(devlist
== INVALID_HANDLE_VALUE
, "SetupDiCreateDeviceInfoListExW failed : %p %d (expected %p)\n", devlist
, error
, INVALID_HANDLE_VALUE
);
206 ok(error
== ERROR_INVALID_PARAMETER
, "GetLastError returned wrong value : %d, (expected %d)\n", error
, ERROR_INVALID_PARAMETER
);
208 SetLastError(0xdeadbeef);
209 /* create empty DeviceInfoList, but set MachineName to something */
210 devlist
= pSetupDiCreateDeviceInfoListExW(NULL
, NULL
, machine
, NULL
);
212 error
= GetLastError();
213 ok(devlist
== INVALID_HANDLE_VALUE
, "SetupDiCreateDeviceInfoListExW failed : %p %d (expected %p)\n", devlist
, error
, INVALID_HANDLE_VALUE
);
214 ok(error
== ERROR_INVALID_MACHINENAME
, "GetLastError returned wrong value : %d, (expected %d)\n", error
, ERROR_INVALID_MACHINENAME
);
216 /* create empty DeviceInfoList */
217 devlist
= pSetupDiCreateDeviceInfoListExW(NULL
, NULL
, NULL
, NULL
);
218 ok(devlist
&& devlist
!= INVALID_HANDLE_VALUE
, "SetupDiCreateDeviceInfoListExW failed : %p %d (expected != %p)\n", devlist
, error
, INVALID_HANDLE_VALUE
);
220 /* destroy DeviceInfoList */
221 ret
= pSetupDiDestroyDeviceInfoList(devlist
);
222 ok(ret
, "SetupDiDestroyDeviceInfoList failed : %d\n", error
);
225 static void test_SetupDiOpenClassRegKeyExA(void)
227 static const CHAR guidString
[] = "{6a55b5a4-3f65-11db-b704-0011955c2bdb}";
230 /* Check return value for nonexistent key */
231 hkey
= pSetupDiOpenClassRegKeyExA(&guid
, KEY_ALL_ACCESS
,
232 DIOCR_INSTALLER
, NULL
, NULL
);
233 ok(hkey
== INVALID_HANDLE_VALUE
,
234 "returned %p (expected INVALID_HANDLE_VALUE)\n", hkey
);
236 /* Test it for a key that exists */
237 hkey
= SetupDiOpenClassRegKey(NULL
, KEY_ALL_ACCESS
);
238 if (hkey
!= INVALID_HANDLE_VALUE
)
241 if (RegCreateKeyA(hkey
, guidString
, &classKey
) == ERROR_SUCCESS
)
243 RegCloseKey(classKey
);
244 SetLastError(0xdeadbeef);
245 classKey
= pSetupDiOpenClassRegKeyExA(&guid
, KEY_ALL_ACCESS
,
246 DIOCR_INSTALLER
, NULL
, NULL
);
247 ok(classKey
!= INVALID_HANDLE_VALUE
,
248 "opening class registry key failed with error %d\n",
250 if (classKey
!= INVALID_HANDLE_VALUE
)
251 RegCloseKey(classKey
);
252 RegDeleteKeyA(hkey
, guidString
);
255 trace("failed to create registry key for test\n");
260 trace("failed to open classes key\n");
263 static void append_str(char **str
, const char *data
)
266 *str
+= strlen(*str
);
269 static void create_inf_file(LPCSTR filename
)
273 DWORD dwNumberOfBytesWritten
;
274 HANDLE hf
= CreateFile(filename
, GENERIC_WRITE
, 0, NULL
,
275 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
277 append_str(&ptr
, "[Version]\n");
278 append_str(&ptr
, "Signature=\"$Chicago$\"\n");
279 append_str(&ptr
, "Class=Bogus\n");
280 append_str(&ptr
, "ClassGUID={6a55b5a4-3f65-11db-b704-0011955c2bdb}\n");
281 append_str(&ptr
, "[ClassInstall32]\n");
282 append_str(&ptr
, "AddReg=BogusClass.NT.AddReg\n");
283 append_str(&ptr
, "[BogusClass.NT.AddReg]\n");
284 append_str(&ptr
, "HKR,,,,\"Wine test devices\"\n");
286 WriteFile(hf
, data
, ptr
- data
, &dwNumberOfBytesWritten
, NULL
);
290 static void get_temp_filename(LPSTR path
)
292 static char curr
[MAX_PATH
] = { 0 };
297 GetCurrentDirectoryA(MAX_PATH
, curr
);
298 GetTempFileNameA(curr
, "set", 0, temp
);
299 ptr
= strrchr(temp
, '\\');
301 lstrcpyA(path
, ptr
+ 1);
304 static void testInstallClass(void)
306 static const WCHAR classKey
[] = {'S','y','s','t','e','m','\\',
307 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
308 'C','o','n','t','r','o','l','\\','C','l','a','s','s','\\',
309 '{','6','a','5','5','b','5','a','4','-','3','f','6','5','-',
310 '1','1','d','b','-','b','7','0','4','-',
311 '0','0','1','1','9','5','5','c','2','b','d','b','}',0};
312 static const CHAR classKey_win9x
[] =
313 "System\\CurrentControlSet\\Services\\Class\\"
314 "{6a55b5a4-3f65-11db-b704-0011955c2bdb}";
315 static const CHAR bogus_win9x
[] =
316 "System\\CurrentControlSet\\Services\\Class\\Bogus";
317 char tmpfile
[MAX_PATH
];
321 if (!pSetupDiInstallClassA
)
323 skip("No SetupDiInstallClassA\n");
328 get_temp_filename(tmpfile
+ 2);
329 create_inf_file(tmpfile
+ 2);
331 ret
= pSetupDiInstallClassA(NULL
, NULL
, 0, NULL
);
332 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
333 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
334 ret
= pSetupDiInstallClassA(NULL
, NULL
, DI_NOVCP
, NULL
);
335 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
336 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
337 ret
= pSetupDiInstallClassA(NULL
, tmpfile
+ 2, DI_NOVCP
, NULL
);
338 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
339 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
340 ret
= pSetupDiInstallClassA(NULL
, tmpfile
+ 2, 0, NULL
);
341 ok(!ret
&& GetLastError() == ERROR_FILE_NOT_FOUND
,
342 "Expected ERROR_FILE_NOT_FOUND, got %08x\n", GetLastError());
343 /* The next call will succeed. Information is put into the registry but the
344 * location(s) is/are depending on the Windows version.
346 ret
= pSetupDiInstallClassA(NULL
, tmpfile
, 0, NULL
);
347 ok(ret
, "SetupDiInstallClassA failed: %08x\n", GetLastError());
348 if (!RegOpenKeyA(HKEY_LOCAL_MACHINE
, classKey_win9x
, &hkey
))
350 /* We are on win9x */
352 ok(!RegDeleteKeyA(HKEY_LOCAL_MACHINE
, classKey_win9x
),
353 "Couldn't delete win9x classkey\n");
354 ok(!RegDeleteKeyA(HKEY_LOCAL_MACHINE
, bogus_win9x
),
355 "Couldn't delete win9x bogus services class\n");
360 ok(!RegDeleteKeyW(HKEY_LOCAL_MACHINE
, classKey
),
361 "Couldn't delete NT classkey\n");
366 static void testCreateDeviceInfo(void)
371 if (!pSetupDiCreateDeviceInfoList
|| !pSetupDiEnumDeviceInfo
||
372 !pSetupDiDestroyDeviceInfoList
|| !pSetupDiCreateDeviceInfoA
)
374 skip("No SetupDiCreateDeviceInfoA\n");
377 SetLastError(0xdeadbeef);
378 ret
= pSetupDiCreateDeviceInfoA(NULL
, NULL
, NULL
, NULL
, NULL
, 0, NULL
);
379 ok(!ret
, "Expected failure\n");
380 ok(GetLastError() == ERROR_INVALID_DEVINST_NAME
||
381 GetLastError() == ERROR_INVALID_PARAMETER
/* NT4 */ ||
382 GetLastError() == ERROR_INVALID_HANDLE
/* Win9x */,
383 "Unexpected last error, got %08x\n", GetLastError());
385 /* If we are running on win9x we should skip these tests. Win95
386 * fails most tests anyway and win98 pops up the "Add New Hardware
389 if (GetLastError() == ERROR_INVALID_HANDLE
)
391 skip("We are on win9x where the tests introduce issues\n");
395 SetLastError(0xdeadbeef);
396 ret
= pSetupDiCreateDeviceInfoA(NULL
, "Root\\LEGACY_BOGUS\\0000", NULL
,
397 NULL
, NULL
, 0, NULL
);
398 ok(!ret
&& GetLastError() == ERROR_INVALID_HANDLE
,
399 "Expected ERROR_INVALID_HANDLEHANDLE, got %08x\n", GetLastError());
400 set
= pSetupDiCreateDeviceInfoList(&guid
, NULL
);
401 ok(set
!= NULL
, "SetupDiCreateDeviceInfoList failed: %08x\n",
405 SP_DEVINFO_DATA devInfo
= { 0 };
408 SetLastError(0xdeadbeef);
409 ret
= pSetupDiCreateDeviceInfoA(set
, "Root\\LEGACY_BOGUS\\0000", NULL
,
410 NULL
, NULL
, 0, NULL
);
411 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
412 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
413 /* Finally, with all three required parameters, this succeeds: */
414 ret
= pSetupDiCreateDeviceInfoA(set
, "Root\\LEGACY_BOGUS\\0000", &guid
,
415 NULL
, NULL
, 0, NULL
);
416 ok(ret
, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
417 /* This fails because the device ID already exists.. */
418 SetLastError(0xdeadbeef);
419 ret
= pSetupDiCreateDeviceInfoA(set
, "Root\\LEGACY_BOGUS\\0000", &guid
,
420 NULL
, NULL
, 0, &devInfo
);
421 ok(!ret
&& GetLastError() == ERROR_DEVINST_ALREADY_EXISTS
,
422 "Expected ERROR_DEVINST_ALREADY_EXISTS, got %08x\n", GetLastError());
423 /* whereas this "fails" because cbSize is wrong.. */
424 SetLastError(0xdeadbeef);
425 ret
= pSetupDiCreateDeviceInfoA(set
, "LEGACY_BOGUS", &guid
, NULL
, NULL
,
426 DICD_GENERATE_ID
, &devInfo
);
427 ok(!ret
&& GetLastError() == ERROR_INVALID_USER_BUFFER
,
428 "Expected ERROR_INVALID_USER_BUFFER, got %08x\n", GetLastError());
429 devInfo
.cbSize
= sizeof(devInfo
);
430 ret
= pSetupDiCreateDeviceInfoA(set
, "LEGACY_BOGUS", &guid
, NULL
, NULL
,
431 DICD_GENERATE_ID
, &devInfo
);
432 /* and this finally succeeds. */
433 ok(ret
, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
434 /* There were three devices added, however - the second failure just
435 * resulted in the SP_DEVINFO_DATA not getting copied.
437 SetLastError(0xdeadbeef);
439 while (pSetupDiEnumDeviceInfo(set
, i
, &devInfo
))
441 ok(i
== 3, "Expected 3 devices, got %d\n", i
);
442 ok(GetLastError() == ERROR_NO_MORE_ITEMS
,
443 "SetupDiEnumDeviceInfo failed: %08x\n", GetLastError());
444 pSetupDiDestroyDeviceInfoList(set
);
448 static void testGetDeviceInstanceId(void)
452 SP_DEVINFO_DATA devInfo
= { 0 };
454 if (!pSetupDiCreateDeviceInfoList
|| !pSetupDiDestroyDeviceInfoList
||
455 !pSetupDiCreateDeviceInfoA
|| !pSetupDiGetDeviceInstanceIdA
)
457 skip("No SetupDiGetDeviceInstanceIdA\n");
460 SetLastError(0xdeadbeef);
461 ret
= pSetupDiGetDeviceInstanceIdA(NULL
, NULL
, NULL
, 0, NULL
);
462 ok(!ret
&& GetLastError() == ERROR_INVALID_HANDLE
,
463 "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
464 SetLastError(0xdeadbeef);
465 ret
= pSetupDiGetDeviceInstanceIdA(NULL
, &devInfo
, NULL
, 0, NULL
);
466 ok(!ret
&& GetLastError() == ERROR_INVALID_HANDLE
,
467 "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
468 set
= pSetupDiCreateDeviceInfoList(&guid
, NULL
);
469 ok(set
!= NULL
, "SetupDiCreateDeviceInfoList failed: %08x\n",
473 char instanceID
[MAX_PATH
];
476 SetLastError(0xdeadbeef);
477 ret
= pSetupDiGetDeviceInstanceIdA(set
, NULL
, NULL
, 0, NULL
);
478 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
479 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
480 SetLastError(0xdeadbeef);
481 ret
= pSetupDiGetDeviceInstanceIdA(set
, &devInfo
, NULL
, 0, NULL
);
482 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
483 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
484 SetLastError(0xdeadbeef);
485 ret
= pSetupDiGetDeviceInstanceIdA(set
, &devInfo
, NULL
, 0, &size
);
486 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
487 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
488 devInfo
.cbSize
= sizeof(devInfo
);
489 SetLastError(0xdeadbeef);
490 ret
= pSetupDiGetDeviceInstanceIdA(set
, &devInfo
, NULL
, 0, &size
);
491 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
492 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
493 ret
= pSetupDiCreateDeviceInfoA(set
, "Root\\LEGACY_BOGUS\\0000", &guid
,
494 NULL
, NULL
, 0, &devInfo
);
495 ok(ret
, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
496 SetLastError(0xdeadbeef);
497 ret
= pSetupDiGetDeviceInstanceIdA(set
, &devInfo
, NULL
, 0, &size
);
498 ok(!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
499 "Expected ERROR_INSUFFICIENT_BUFFER, got %08x\n", GetLastError());
500 ret
= pSetupDiGetDeviceInstanceIdA(set
, &devInfo
, instanceID
,
501 sizeof(instanceID
), NULL
);
502 ok(ret
, "SetupDiGetDeviceInstanceIdA failed: %08x\n", GetLastError());
503 ok(!lstrcmpA(instanceID
, "ROOT\\LEGACY_BOGUS\\0000"),
504 "Unexpected instance ID %s\n", instanceID
);
505 ret
= pSetupDiCreateDeviceInfoA(set
, "LEGACY_BOGUS", &guid
,
506 NULL
, NULL
, DICD_GENERATE_ID
, &devInfo
);
507 ok(ret
, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
508 ret
= pSetupDiGetDeviceInstanceIdA(set
, &devInfo
, instanceID
,
509 sizeof(instanceID
), NULL
);
510 ok(ret
, "SetupDiGetDeviceInstanceIdA failed: %08x\n", GetLastError());
511 ok(!lstrcmpA(instanceID
, "ROOT\\LEGACY_BOGUS\\0001"),
512 "Unexpected instance ID %s\n", instanceID
);
513 pSetupDiDestroyDeviceInfoList(set
);
517 static void testRegisterDeviceInfo(void)
522 if (!pSetupDiCreateDeviceInfoList
|| !pSetupDiDestroyDeviceInfoList
||
523 !pSetupDiRegisterDeviceInfo
)
525 skip("No SetupDiRegisterDeviceInfo\n");
528 SetLastError(0xdeadbeef);
529 ret
= pSetupDiRegisterDeviceInfo(NULL
, NULL
, 0, NULL
, NULL
, NULL
);
530 ok(!ret
&& GetLastError() == ERROR_INVALID_HANDLE
,
531 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
532 set
= pSetupDiCreateDeviceInfoList(&guid
, NULL
);
533 ok(set
!= NULL
, "SetupDiCreateDeviceInfoList failed: %d\n", GetLastError());
536 SP_DEVINFO_DATA devInfo
= { 0 };
538 SetLastError(0xdeadbeef);
539 ret
= pSetupDiRegisterDeviceInfo(set
, NULL
, 0, NULL
, NULL
, NULL
);
540 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
541 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
542 SetLastError(0xdeadbeef);
543 ret
= pSetupDiRegisterDeviceInfo(set
, &devInfo
, 0, NULL
, NULL
, NULL
);
544 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
545 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
546 devInfo
.cbSize
= sizeof(devInfo
);
547 SetLastError(0xdeadbeef);
548 ret
= pSetupDiRegisterDeviceInfo(set
, &devInfo
, 0, NULL
, NULL
, NULL
);
549 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
550 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
551 ret
= pSetupDiCreateDeviceInfoA(set
, "USB\\BOGUS\\0000", &guid
,
552 NULL
, NULL
, 0, &devInfo
);
553 ok(ret
|| GetLastError() == ERROR_DEVINST_ALREADY_EXISTS
,
554 "SetupDiCreateDeviceInfoA failed: %d\n", GetLastError());
557 /* If it already existed, registering it again will fail */
558 ret
= pSetupDiRegisterDeviceInfo(set
, &devInfo
, 0, NULL
, NULL
,
560 ok(ret
, "SetupDiCreateDeviceInfoA failed: %d\n", GetLastError());
562 /* FIXME: On Win2K+ systems, this is now persisted to registry in
563 * HKLM\System\CCS\Enum\USB\Bogus\0000. I don't check because the
564 * Win9x location is different.
565 * FIXME: the key also becomes undeletable. How to get rid of it?
567 pSetupDiDestroyDeviceInfoList(set
);
571 static void testCreateDeviceInterface(void)
576 if (!pSetupDiCreateDeviceInfoList
|| !pSetupDiDestroyDeviceInfoList
||
577 !pSetupDiCreateDeviceInfoA
|| !pSetupDiCreateDeviceInterfaceA
||
578 !pSetupDiEnumDeviceInterfaces
)
580 skip("No SetupDiCreateDeviceInterfaceA\n");
583 SetLastError(0xdeadbeef);
584 ret
= pSetupDiCreateDeviceInterfaceA(NULL
, NULL
, NULL
, NULL
, 0, NULL
);
585 ok(!ret
&& GetLastError() == ERROR_INVALID_HANDLE
,
586 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
587 SetLastError(0xdeadbeef);
588 ret
= pSetupDiCreateDeviceInterfaceA(NULL
, NULL
, &guid
, NULL
, 0, NULL
);
589 ok(!ret
&& GetLastError() == ERROR_INVALID_HANDLE
,
590 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
591 set
= pSetupDiCreateDeviceInfoList(&guid
, NULL
);
592 ok(set
!= NULL
, "SetupDiCreateDeviceInfoList failed: %d\n", GetLastError());
595 SP_DEVINFO_DATA devInfo
= { 0 };
596 SP_DEVICE_INTERFACE_DATA interfaceData
= { sizeof(interfaceData
),
600 SetLastError(0xdeadbeef);
601 ret
= pSetupDiCreateDeviceInterfaceA(set
, NULL
, NULL
, NULL
, 0, NULL
);
602 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
603 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
604 SetLastError(0xdeadbeef);
605 ret
= pSetupDiCreateDeviceInterfaceA(set
, &devInfo
, NULL
, NULL
, 0,
607 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
608 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
609 devInfo
.cbSize
= sizeof(devInfo
);
610 ret
= pSetupDiCreateDeviceInfoA(set
, "ROOT\\LEGACY_BOGUS\\0000", &guid
,
611 NULL
, NULL
, 0, &devInfo
);
612 ok(ret
, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
613 SetLastError(0xdeadbeef);
614 ret
= pSetupDiCreateDeviceInterfaceA(set
, &devInfo
, NULL
, NULL
, 0,
616 ok(!ret
&& GetLastError() == ERROR_INVALID_USER_BUFFER
,
617 "Expected ERROR_INVALID_USER_BUFFER, got %08x\n", GetLastError());
618 ret
= pSetupDiCreateDeviceInterfaceA(set
, &devInfo
, &guid
, NULL
, 0,
620 ok(ret
, "SetupDiCreateDeviceInterfaceA failed: %08x\n", GetLastError());
621 /* Creating the same interface a second time succeeds */
622 ret
= pSetupDiCreateDeviceInterfaceA(set
, &devInfo
, &guid
, NULL
, 0,
624 ok(ret
, "SetupDiCreateDeviceInterfaceA failed: %08x\n", GetLastError());
625 ret
= pSetupDiCreateDeviceInterfaceA(set
, &devInfo
, &guid
, "Oogah", 0,
627 ok(ret
, "SetupDiCreateDeviceInterfaceA failed: %08x\n", GetLastError());
628 ret
= pSetupDiEnumDeviceInterfaces(set
, &devInfo
, &guid
, 0,
630 ok(ret
, "SetupDiEnumDeviceInterfaces failed: %d\n", GetLastError());
632 while (pSetupDiEnumDeviceInterfaces(set
, &devInfo
, &guid
, i
,
635 ok(i
== 2, "expected 2 interfaces, got %d\n", i
);
636 ok(GetLastError() == ERROR_NO_MORE_ITEMS
,
637 "SetupDiEnumDeviceInterfaces failed: %08x\n", GetLastError());
638 pSetupDiDestroyDeviceInfoList(set
);
642 static void testGetDeviceInterfaceDetail(void)
646 static const WCHAR bogus
[] = {'S','y','s','t','e','m','\\',
647 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
648 'E','n','u','m','\\','R','o','o','t','\\',
649 'L','E','G','A','C','Y','_','B','O','G','U','S',0};
650 static const WCHAR devclass
[] = {'S','y','s','t','e','m','\\',
651 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
652 'C','o','n','t','r','o','l','\\','D','e','v','i','c','e','C','l','a','s','s','e','s','\\',
653 '{','6','a','5','5','b','5','a','4','-','3','f','6','5','-',
654 '1','1','d','b','-','b','7','0','4','-',
655 '0','0','1','1','9','5','5','c','2','b','d','b','}',0};
657 if (!pSetupDiCreateDeviceInfoList
|| !pSetupDiDestroyDeviceInfoList
||
658 !pSetupDiCreateDeviceInfoA
|| !pSetupDiCreateDeviceInterfaceA
||
659 !pSetupDiGetDeviceInterfaceDetailA
)
661 skip("No SetupDiGetDeviceInterfaceDetailA\n");
664 SetLastError(0xdeadbeef);
665 ret
= pSetupDiGetDeviceInterfaceDetailA(NULL
, NULL
, NULL
, 0, NULL
, NULL
);
666 ok(!ret
&& GetLastError() == ERROR_INVALID_HANDLE
,
667 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
668 set
= pSetupDiCreateDeviceInfoList(&guid
, NULL
);
669 ok(set
!= NULL
, "SetupDiCreateDeviceInfoList failed: %d\n", GetLastError());
672 SP_DEVINFO_DATA devInfo
= { sizeof(devInfo
), { 0 } };
673 SP_DEVICE_INTERFACE_DATA interfaceData
= { sizeof(interfaceData
),
678 SetLastError(0xdeadbeef);
679 ret
= pSetupDiGetDeviceInterfaceDetailA(set
, NULL
, NULL
, 0, NULL
,
681 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
682 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
683 ret
= pSetupDiCreateDeviceInfoA(set
, "ROOT\\LEGACY_BOGUS\\0000", &guid
,
684 NULL
, NULL
, 0, &devInfo
);
685 ok(ret
, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
686 SetLastError(0xdeadbeef);
687 ret
= pSetupDiCreateDeviceInterfaceA(set
, &devInfo
, &guid
, NULL
, 0,
689 ok(ret
, "SetupDiCreateDeviceInterfaceA failed: %08x\n", GetLastError());
690 SetLastError(0xdeadbeef);
691 ret
= pSetupDiGetDeviceInterfaceDetailA(set
, &interfaceData
, NULL
,
693 ok(!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
694 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
695 SetLastError(0xdeadbeef);
696 ret
= pSetupDiGetDeviceInterfaceDetailA(set
, &interfaceData
, NULL
,
698 ok(!ret
&& GetLastError() == ERROR_INVALID_USER_BUFFER
,
699 "Expected ERROR_INVALID_USER_BUFFER, got %08x\n", GetLastError());
700 SetLastError(0xdeadbeef);
701 ret
= pSetupDiGetDeviceInterfaceDetailA(set
, &interfaceData
, NULL
,
703 ok(!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
704 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
705 if (!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
707 static const char path
[] =
708 "\\\\?\\root#legacy_bogus#0000#{6a55b5a4-3f65-11db-b704-0011955c2bdb}";
709 LPBYTE buf
= HeapAlloc(GetProcessHeap(), 0, size
);
710 SP_DEVICE_INTERFACE_DETAIL_DATA_A
*detail
=
711 (SP_DEVICE_INTERFACE_DETAIL_DATA_A
*)buf
;
712 DWORD expectedsize
= offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_W
, DevicePath
) + sizeof(WCHAR
)*(1 + strlen(path
));
715 SetLastError(0xdeadbeef);
716 ret
= pSetupDiGetDeviceInterfaceDetailA(set
, &interfaceData
, detail
,
718 ok(!ret
&& GetLastError() == ERROR_INVALID_USER_BUFFER
,
719 "Expected ERROR_INVALID_USER_BUFFER, got %08x\n", GetLastError());
720 detail
->cbSize
= size
;
721 SetLastError(0xdeadbeef);
722 ret
= pSetupDiGetDeviceInterfaceDetailA(set
, &interfaceData
, detail
,
724 ok(!ret
&& GetLastError() == ERROR_INVALID_USER_BUFFER
,
725 "Expected ERROR_INVALID_USER_BUFFER, got %08x\n", GetLastError());
726 detail
->cbSize
= sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_A
);
727 SetLastError(0xdeadbeef);
728 ret
= pSetupDiGetDeviceInterfaceDetailA(set
, &interfaceData
, detail
,
730 ok(!ret
&& GetLastError() == ERROR_INVALID_USER_BUFFER
,
731 "Expected ERROR_INVALID_USER_BUFFER, got %08x\n", GetLastError());
732 /* Windows 2000 and up check for the exact size. Win9x returns ERROR_INVALID_PARAMETER
733 * on every call (so doesn't get here) and NT4 doesn't have this function.
735 detail
->cbSize
= FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_A
, DevicePath
[1]);
736 ret
= pSetupDiGetDeviceInterfaceDetailA(set
, &interfaceData
, detail
,
738 ok(ret
, "SetupDiGetDeviceInterfaceDetailA failed: %d\n",
740 ok(!lstrcmpiA(path
, detail
->DevicePath
), "Unexpected path %s\n",
742 /* Check SetupDiGetDeviceInterfaceDetailW */
743 if (pSetupDiGetDeviceInterfaceDetailW
)
745 ret
= pSetupDiGetDeviceInterfaceDetailW(set
, &interfaceData
, NULL
, 0, &size
, NULL
);
746 ok(!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Expected ERROR_INSUFFICIENT_BUFFER, got error code: %d\n", GetLastError());
747 ok(expectedsize
== size
, "SetupDiGetDeviceInterfaceDetailW returned wrong reqsize: expected %d, got %d\n", expectedsize
, size
);
750 skip("SetupDiGetDeviceInterfaceDetailW is not available\n");
752 HeapFree(GetProcessHeap(), 0, buf
);
754 pSetupDiDestroyDeviceInfoList(set
);
757 /* FIXME: On Wine we still have the bogus entry in Enum\Root and
758 * subkeys, as well as the deviceclass key with subkeys.
759 * Only do the RegDeleteKey, once Wine is fixed.
761 if (!RegOpenKeyW(HKEY_LOCAL_MACHINE
, bogus
, &key
))
763 /* Wine doesn't delete the information currently */
764 trace("We are most likely on Wine\n");
765 devinst_RegDeleteTreeW(HKEY_LOCAL_MACHINE
, bogus
);
766 devinst_RegDeleteTreeW(HKEY_LOCAL_MACHINE
, devclass
);
770 ok(!RegDeleteKeyW(HKEY_LOCAL_MACHINE
, devclass
),
771 "Couldn't delete deviceclass key\n");
776 static void testDevRegKey(void)
778 static const WCHAR classKey
[] = {'S','y','s','t','e','m','\\',
779 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
780 'C','o','n','t','r','o','l','\\','C','l','a','s','s','\\',
781 '{','6','a','5','5','b','5','a','4','-','3','f','6','5','-',
782 '1','1','d','b','-','b','7','0','4','-',
783 '0','0','1','1','9','5','5','c','2','b','d','b','}',0};
784 static const WCHAR bogus
[] = {'S','y','s','t','e','m','\\',
785 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
786 'E','n','u','m','\\','R','o','o','t','\\',
787 'L','E','G','A','C','Y','_','B','O','G','U','S',0};
792 if (!pSetupDiCreateDeviceInfoList
|| !pSetupDiDestroyDeviceInfoList
||
793 !pSetupDiCreateDeviceInfoA
|| !pSetupDiOpenDevRegKey
||
794 !pSetupDiRegisterDeviceInfo
|| !pSetupDiCreateDevRegKeyW
||
795 !pSetupDiCallClassInstaller
)
797 skip("No SetupDiOpenDevRegKey\n");
801 /* Check if we are on win9x */
802 SetLastError(0xdeadbeef);
803 key
= pSetupDiCreateDevRegKeyW(NULL
, NULL
, 0, 0, 0, NULL
, NULL
);
804 if (key
== INVALID_HANDLE_VALUE
&& GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
806 skip("We are on win9x where the tests introduce issues\n");
809 ok(key
== INVALID_HANDLE_VALUE
,
810 "Expected INVALID_HANDLE_VALUE, got %p\n", key
);
811 ok(GetLastError() == ERROR_INVALID_HANDLE
,
812 "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
814 set
= pSetupDiCreateDeviceInfoList(&guid
, NULL
);
815 ok(set
!= NULL
, "SetupDiCreateDeviceInfoList failed: %d\n", GetLastError());
818 SP_DEVINFO_DATA devInfo
= { sizeof(devInfo
), { 0 } };
821 /* The device info key shouldn't be there */
822 res
= RegOpenKeyW(HKEY_LOCAL_MACHINE
, bogus
, &key
);
823 ok(res
!= ERROR_SUCCESS
, "Expected key to not exist\n");
825 /* Create the device information */
826 ret
= pSetupDiCreateDeviceInfoA(set
, "ROOT\\LEGACY_BOGUS\\0000", &guid
,
827 NULL
, NULL
, 0, &devInfo
);
828 ok(ret
, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
829 /* The device info key should have been created */
830 ok(!RegOpenKeyW(HKEY_LOCAL_MACHINE
, bogus
, &key
),
831 "Expected registry key to exist\n");
833 SetLastError(0xdeadbeef);
834 key
= pSetupDiOpenDevRegKey(NULL
, NULL
, 0, 0, 0, 0);
835 ok(!key
|| key
== INVALID_HANDLE_VALUE
,
836 "Expected INVALID_HANDLE_VALUE or a NULL key (NT4)\n");
837 ok(GetLastError() == ERROR_INVALID_HANDLE
,
838 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
839 SetLastError(0xdeadbeef);
840 key
= pSetupDiOpenDevRegKey(set
, NULL
, 0, 0, 0, 0);
841 ok(key
== INVALID_HANDLE_VALUE
&&
842 GetLastError() == ERROR_INVALID_PARAMETER
,
843 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
844 SetLastError(0xdeadbeef);
845 key
= pSetupDiOpenDevRegKey(set
, &devInfo
, 0, 0, 0, 0);
846 ok(key
== INVALID_HANDLE_VALUE
&&
847 GetLastError() == ERROR_INVALID_FLAGS
,
848 "Expected ERROR_INVALID_FLAGS, got %d\n", GetLastError());
849 SetLastError(0xdeadbeef);
850 key
= pSetupDiOpenDevRegKey(set
, &devInfo
, DICS_FLAG_GLOBAL
, 0, 0, 0);
851 ok(key
== INVALID_HANDLE_VALUE
&&
852 GetLastError() == ERROR_INVALID_FLAGS
,
853 "Expected ERROR_INVALID_FLAGS, got %d\n", GetLastError());
854 SetLastError(0xdeadbeef);
855 key
= pSetupDiOpenDevRegKey(set
, &devInfo
, DICS_FLAG_GLOBAL
, 0,
857 ok(key
== INVALID_HANDLE_VALUE
&&
858 GetLastError() == ERROR_INVALID_FLAGS
,
859 "Expected ERROR_INVALID_FLAGS, got %d\n", GetLastError());
860 SetLastError(0xdeadbeef);
861 key
= pSetupDiOpenDevRegKey(set
, &devInfo
, DICS_FLAG_GLOBAL
, 0,
863 ok(key
== INVALID_HANDLE_VALUE
&&
864 GetLastError() == ERROR_DEVINFO_NOT_REGISTERED
,
865 "Expected ERROR_DEVINFO_NOT_REGISTERED, got %08x\n", GetLastError());
866 SetLastError(0xdeadbeef);
867 ret
= pSetupDiRegisterDeviceInfo(set
, &devInfo
, 0, NULL
, NULL
, NULL
);
868 ok(ret
, "SetupDiRegisterDeviceInfo failed: %08x\n", GetLastError());
869 SetLastError(0xdeadbeef);
870 key
= pSetupDiOpenDevRegKey(set
, &devInfo
, DICS_FLAG_GLOBAL
, 0,
872 /* The software key isn't created by default */
874 ok(key
== INVALID_HANDLE_VALUE
&&
875 GetLastError() == ERROR_KEY_DOES_NOT_EXIST
,
876 "Expected ERROR_KEY_DOES_NOT_EXIST_EXIST, got %08x\n", GetLastError());
877 SetLastError(0xdeadbeef);
878 key
= pSetupDiOpenDevRegKey(set
, &devInfo
, DICS_FLAG_GLOBAL
, 0,
881 ok(key
== INVALID_HANDLE_VALUE
&&
882 GetLastError() == ERROR_KEY_DOES_NOT_EXIST
,
883 "Expected ERROR_KEY_DOES_NOT_EXIST_EXIST, got %08x\n", GetLastError());
884 SetLastError(0xdeadbeef);
885 /* The class key shouldn't be there */
886 res
= RegOpenKeyW(HKEY_LOCAL_MACHINE
, classKey
, &key
);
888 ok(res
!= ERROR_SUCCESS
, "Expected key to not exist\n");
890 /* Create the device reg key */
891 key
= pSetupDiCreateDevRegKeyW(set
, &devInfo
, DICS_FLAG_GLOBAL
, 0,
892 DIREG_DRV
, NULL
, NULL
);
893 ok(key
!= INVALID_HANDLE_VALUE
, "SetupDiCreateDevRegKey failed: %08x\n",
896 /* The class key should have been created */
897 ok(!RegOpenKeyW(HKEY_LOCAL_MACHINE
, classKey
, &key
),
898 "Expected registry key to exist\n");
900 SetLastError(0xdeadbeef);
901 key
= pSetupDiOpenDevRegKey(set
, &devInfo
, DICS_FLAG_GLOBAL
, 0,
904 ok(key
== INVALID_HANDLE_VALUE
&&
905 (GetLastError() == ERROR_INVALID_DATA
||
906 GetLastError() == ERROR_ACCESS_DENIED
), /* win2k3 */
907 "Expected ERROR_INVALID_DATA or ERROR_ACCESS_DENIED, got %08x\n", GetLastError());
908 key
= pSetupDiOpenDevRegKey(set
, &devInfo
, DICS_FLAG_GLOBAL
, 0,
909 DIREG_DRV
, KEY_READ
);
910 ok(key
!= INVALID_HANDLE_VALUE
, "SetupDiOpenDevRegKey failed: %08x\n",
912 pSetupDiDestroyDeviceInfoList(set
);
915 ret
= remove_device();
917 ok(ret
, "Expected the device to be removed: %08x\n", GetLastError());
919 /* FIXME: Only do the RegDeleteKey, once Wine is fixed */
922 /* Wine doesn't delete the information currently */
923 trace("We are most likely on Wine\n");
924 devinst_RegDeleteTreeW(HKEY_LOCAL_MACHINE
, bogus
);
925 devinst_RegDeleteTreeW(HKEY_LOCAL_MACHINE
, classKey
);
929 /* There should only be a class key entry, so a simple
930 * RegDeleteKey should work
932 * This could fail if it's the first time for this new test
933 * after running the old tests.
935 ok(!RegDeleteKeyW(HKEY_LOCAL_MACHINE
, classKey
),
936 "Couldn't delete classkey\n");
941 static void testRegisterAndGetDetail(void)
945 SP_DEVINFO_DATA devInfo
= { sizeof(SP_DEVINFO_DATA
), { 0 } };
946 SP_DEVICE_INTERFACE_DATA interfaceData
= { sizeof(interfaceData
), { 0 } };
948 static const WCHAR bogus
[] = {'S','y','s','t','e','m','\\',
949 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
950 'E','n','u','m','\\','R','o','o','t','\\',
951 'L','E','G','A','C','Y','_','B','O','G','U','S',0};
952 static const WCHAR devclass
[] = {'S','y','s','t','e','m','\\',
953 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
954 'C','o','n','t','r','o','l','\\','D','e','v','i','c','e','C','l','a','s','s','e','s','\\',
955 '{','6','a','5','5','b','5','a','4','-','3','f','6','5','-',
956 '1','1','d','b','-','b','7','0','4','-',
957 '0','0','1','1','9','5','5','c','2','b','d','b','}',0};
959 SetLastError(0xdeadbeef);
960 set
= pSetupDiGetClassDevsA(&guid
, NULL
, 0, DIGCF_ALLCLASSES
);
961 ok(set
!= INVALID_HANDLE_VALUE
, "SetupDiGetClassDevsA failed: %08x\n",
964 SetLastError(0xdeadbeef);
965 ret
= pSetupDiCreateDeviceInfoA(set
, "LEGACY_BOGUS", &guid
, NULL
, 0,
966 DICD_GENERATE_ID
, &devInfo
);
967 ok(ret
, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
968 SetLastError(0xdeadbeef);
969 ret
= pSetupDiCreateDeviceInterfaceA(set
, &devInfo
, &guid
, NULL
, 0, &interfaceData
);
970 ok(ret
, "SetupDiCreateDeviceInterfaceA failed: %08x\n", GetLastError());
971 SetLastError(0xdeadbeef);
972 ret
= pSetupDiRegisterDeviceInfo(set
, &devInfo
, 0, NULL
, NULL
, NULL
);
973 ok(ret
, "SetupDiRegisterDeviceInfo failed: %08x\n", GetLastError());
975 pSetupDiDestroyDeviceInfoList(set
);
977 SetLastError(0xdeadbeef);
978 set
= pSetupDiGetClassDevsA(&guid
, NULL
, 0, DIGCF_DEVICEINTERFACE
);
979 ok(set
!= INVALID_HANDLE_VALUE
, "SetupDiGetClassDevsA failed: %08x\n",
982 SetLastError(0xdeadbeef);
983 ret
= pSetupDiEnumDeviceInterfaces(set
, NULL
, &guid
, 0, &interfaceData
);
984 ok(ret
, "SetupDiEnumDeviceInterfaces failed: %08x\n", GetLastError());
985 SetLastError(0xdeadbeef);
986 ret
= pSetupDiGetDeviceInterfaceDetailA(set
, &interfaceData
, NULL
, 0, &dwSize
, NULL
);
987 ok(!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
988 "Expected ERROR_INSUFFICIENT_BUFFER, got %08x\n", GetLastError());
989 if (!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
991 static const char path
[] =
992 "\\\\?\\root#legacy_bogus#0000#{6a55b5a4-3f65-11db-b704-0011955c2bdb}";
993 PSP_DEVICE_INTERFACE_DETAIL_DATA_A detail
= NULL
;
995 detail
= (PSP_DEVICE_INTERFACE_DETAIL_DATA_A
)HeapAlloc(GetProcessHeap(), 0, dwSize
);
998 detail
->cbSize
= offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_A
, DevicePath
) + sizeof(char);
999 SetLastError(0xdeadbeef);
1000 ret
= pSetupDiGetDeviceInterfaceDetailA(set
, &interfaceData
,
1001 detail
, dwSize
, &dwSize
, NULL
);
1002 ok(ret
, "SetupDiGetDeviceInterfaceDetailA failed: %08x\n", GetLastError());
1003 /* FIXME: This one only worked because old data wasn't removed properly. As soon
1004 * as all the tests are cleaned up correctly this has to be (or should be) fixed
1007 ok(!lstrcmpiA(path
, detail
->DevicePath
), "Unexpected path %s\n",
1008 detail
->DevicePath
);
1009 HeapFree(GetProcessHeap(), 0, detail
);
1013 pSetupDiDestroyDeviceInfoList(set
);
1016 ret
= remove_device();
1018 ok(ret
, "Expected the device to be removed: %08x\n", GetLastError());
1020 /* FIXME: Only do the RegDeleteKey, once Wine is fixed */
1023 /* Wine doesn't delete the information currently */
1024 trace("We are most likely on Wine\n");
1025 devinst_RegDeleteTreeW(HKEY_LOCAL_MACHINE
, bogus
);
1026 devinst_RegDeleteTreeW(HKEY_LOCAL_MACHINE
, devclass
);
1030 /* There should only be a class key entry, so a simple
1031 * RegDeleteKey should work
1033 ok(!RegDeleteKeyW(HKEY_LOCAL_MACHINE
, devclass
),
1034 "Couldn't delete classkey\n");
1038 static void testDeviceRegistryPropertyA()
1041 SP_DEVINFO_DATA devInfo
= { sizeof(SP_DEVINFO_DATA
), { 0 } };
1042 CHAR devName
[] = "LEGACY_BOGUS";
1043 CHAR friendlyName
[] = "Bogus";
1050 SetLastError(0xdeadbeef);
1051 set
= pSetupDiGetClassDevsA(&guid
, NULL
, 0, DIGCF_DEVICEINTERFACE
);
1052 ok(set
!= INVALID_HANDLE_VALUE
, "SetupDiGetClassDevsA failed: %08x\n",
1054 SetLastError(0xdeadbeef);
1055 ret
= pSetupDiCreateDeviceInfoA(set
, devName
, &guid
, NULL
, NULL
,
1056 DICD_GENERATE_ID
, &devInfo
);
1057 ok(ret
, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
1058 SetLastError(0xdeadbeef);
1059 ret
= pSetupDiSetDeviceRegistryPropertyA(NULL
, NULL
, -1, NULL
, 0);
1060 ok(!ret
&& GetLastError() == ERROR_INVALID_HANDLE
,
1061 "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
1062 SetLastError(0xdeadbeef);
1063 ret
= pSetupDiSetDeviceRegistryPropertyA(set
, NULL
, -1, NULL
, 0);
1064 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
1065 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
1066 SetLastError(0xdeadbeef);
1067 ret
= pSetupDiSetDeviceRegistryPropertyA(set
, &devInfo
, -1, NULL
, 0);
1069 ok(!ret
&& GetLastError() == ERROR_INVALID_REG_PROPERTY
,
1070 "Expected ERROR_INVALID_REG_PROPERTY, got %08x\n", GetLastError());
1071 /* GetLastError() returns nonsense in win2k3 */
1072 ret
= pSetupDiSetDeviceRegistryPropertyA(set
, &devInfo
, SPDRP_FRIENDLYNAME
,
1075 ok(!ret
, "Expected failure, got %d\n", ret
);
1076 SetLastError(0xdeadbeef);
1077 ret
= pSetupDiSetDeviceRegistryPropertyA(set
, &devInfo
, SPDRP_FRIENDLYNAME
,
1078 (PBYTE
)friendlyName
, buflen
);
1079 ok(ret
, "SetupDiSetDeviceRegistryPropertyA failed: %08x\n", GetLastError());
1080 SetLastError(0xdeadbeef);
1081 ret
= pSetupDiGetDeviceRegistryPropertyA(NULL
, NULL
, -1, NULL
, NULL
, 0, NULL
);
1082 ok(!ret
&& GetLastError() == ERROR_INVALID_HANDLE
,
1083 "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
1084 SetLastError(0xdeadbeef);
1085 ret
= pSetupDiGetDeviceRegistryPropertyA(set
, NULL
, -1, NULL
, NULL
, 0, NULL
);
1086 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
1087 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
1088 SetLastError(0xdeadbeef);
1089 ret
= pSetupDiGetDeviceRegistryPropertyA(set
, &devInfo
, -1, NULL
, NULL
, 0, NULL
);
1091 ok(!ret
&& GetLastError() == ERROR_INVALID_REG_PROPERTY
,
1092 "Expected ERROR_INVALID_REG_PROPERTY, got %08x\n", GetLastError());
1093 /* GetLastError() returns nonsense in win2k3 */
1094 ret
= pSetupDiGetDeviceRegistryPropertyA(set
, &devInfo
, SPDRP_FRIENDLYNAME
,
1095 NULL
, NULL
, buflen
, NULL
);
1096 ok(!ret
, "Expected failure, got %d\n", ret
);
1097 SetLastError(0xdeadbeef);
1098 ret
= pSetupDiGetDeviceRegistryPropertyA(set
, &devInfo
, SPDRP_FRIENDLYNAME
,
1099 NULL
, NULL
, 0, &size
);
1100 ok(!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
1101 "Expected ERROR_INSUFFICIENT_BUFFER, got %08x\n", GetLastError());
1102 ok(buflen
== size
, "Unexpected size: %d\n", size
);
1103 SetLastError(0xdeadbeef);
1104 ret
= pSetupDiGetDeviceRegistryPropertyA(set
, &devInfo
, SPDRP_FRIENDLYNAME
,
1105 NULL
, (PBYTE
)buf
, buflen
, NULL
);
1106 ok(ret
, "SetupDiGetDeviceRegistryPropertyA failed: %08x\n", GetLastError());
1107 ok(!lstrcmpiA(friendlyName
, buf
), "Unexpected property\n");
1108 SetLastError(0xdeadbeef);
1109 ret
= pSetupDiGetDeviceRegistryPropertyA(set
, &devInfo
, SPDRP_FRIENDLYNAME
,
1110 ®Type
, (PBYTE
)buf
, buflen
, NULL
);
1111 ok(ret
, "SetupDiGetDeviceRegistryPropertyA failed: %08x\n", GetLastError());
1112 ok(!lstrcmpiA(friendlyName
, buf
), "Unexpected value of property\n");
1113 ok(regType
== REG_SZ
, "Unexpected type of property: %d\n", regType
);
1114 SetLastError(0xdeadbeef);
1115 ret
= pSetupDiSetDeviceRegistryPropertyA(set
, &devInfo
, SPDRP_FRIENDLYNAME
,
1117 ok(ret
, "SetupDiSetDeviceRegistryPropertyA failed: %08x\n", GetLastError());
1118 SetLastError(0xdeadbeef);
1119 ret
= pSetupDiGetDeviceRegistryPropertyA(set
, &devInfo
, SPDRP_FRIENDLYNAME
,
1120 NULL
, (PBYTE
)buf
, buflen
, &size
);
1122 ok(!ret
&& GetLastError() == ERROR_INVALID_DATA
,
1123 "Expected ERROR_INVALID_DATA, got %08x\n", GetLastError());
1124 pSetupDiDestroyDeviceInfoList(set
);
1127 static void testDeviceRegistryPropertyW()
1130 SP_DEVINFO_DATA devInfo
= { sizeof(SP_DEVINFO_DATA
), { 0 } };
1131 WCHAR devName
[] = {'L','E','G','A','C','Y','_','B','O','G','U','S',0};
1132 WCHAR friendlyName
[] = {'B','o','g','u','s',0};
1134 DWORD buflen
= 6 * sizeof(WCHAR
);
1139 SetLastError(0xdeadbeef);
1140 set
= pSetupDiGetClassDevsW(&guid
, NULL
, 0, DIGCF_DEVICEINTERFACE
);
1141 if (set
== INVALID_HANDLE_VALUE
&& GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1143 skip("W-functions are not implemented\n");
1146 ok(set
!= INVALID_HANDLE_VALUE
, "SetupDiGetClassDevsW failed: %08x\n",
1148 SetLastError(0xdeadbeef);
1149 ret
= pSetupDiCreateDeviceInfoW(set
, devName
, &guid
, NULL
, NULL
,
1150 DICD_GENERATE_ID
, &devInfo
);
1151 ok(ret
, "SetupDiCreateDeviceInfoW failed: %08x\n", GetLastError());
1152 SetLastError(0xdeadbeef);
1153 ret
= pSetupDiSetDeviceRegistryPropertyW(NULL
, NULL
, -1, NULL
, 0);
1154 ok(!ret
&& GetLastError() == ERROR_INVALID_HANDLE
,
1155 "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
1156 SetLastError(0xdeadbeef);
1157 ret
= pSetupDiSetDeviceRegistryPropertyW(set
, NULL
, -1, NULL
, 0);
1158 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
1159 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
1160 SetLastError(0xdeadbeef);
1161 ret
= pSetupDiSetDeviceRegistryPropertyW(set
, &devInfo
, -1, NULL
, 0);
1163 ok(!ret
&& GetLastError() == ERROR_INVALID_REG_PROPERTY
,
1164 "Expected ERROR_INVALID_REG_PROPERTY, got %08x\n", GetLastError());
1165 /* GetLastError() returns nonsense in win2k3 */
1166 ret
= pSetupDiSetDeviceRegistryPropertyW(set
, &devInfo
, SPDRP_FRIENDLYNAME
,
1169 ok(!ret
, "Expected failure, got %d\n", ret
);
1170 SetLastError(0xdeadbeef);
1171 ret
= pSetupDiSetDeviceRegistryPropertyW(set
, &devInfo
, SPDRP_FRIENDLYNAME
,
1172 (PBYTE
)friendlyName
, buflen
);
1173 ok(ret
, "SetupDiSetDeviceRegistryPropertyW failed: %08x\n", GetLastError());
1174 SetLastError(0xdeadbeef);
1175 ret
= pSetupDiGetDeviceRegistryPropertyW(NULL
, NULL
, -1, NULL
, NULL
, 0, NULL
);
1176 ok(!ret
&& GetLastError() == ERROR_INVALID_HANDLE
,
1177 "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
1178 SetLastError(0xdeadbeef);
1179 ret
= pSetupDiGetDeviceRegistryPropertyW(set
, NULL
, -1, NULL
, NULL
, 0, NULL
);
1180 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
1181 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
1182 SetLastError(0xdeadbeef);
1183 ret
= pSetupDiGetDeviceRegistryPropertyW(set
, &devInfo
, -1, NULL
, NULL
, 0, NULL
);
1185 ok(!ret
&& GetLastError() == ERROR_INVALID_REG_PROPERTY
,
1186 "Expected ERROR_INVALID_REG_PROPERTY, got %08x\n", GetLastError());
1187 /* GetLastError() returns nonsense in win2k3 */
1188 ret
= pSetupDiGetDeviceRegistryPropertyW(set
, &devInfo
, SPDRP_FRIENDLYNAME
,
1189 NULL
, NULL
, buflen
, NULL
);
1190 ok(!ret
, "Expected failure, got %d\n", ret
);
1191 SetLastError(0xdeadbeef);
1192 ret
= pSetupDiGetDeviceRegistryPropertyW(set
, &devInfo
, SPDRP_FRIENDLYNAME
,
1193 NULL
, NULL
, 0, &size
);
1194 ok(!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
1195 "Expected ERROR_INSUFFICIENT_BUFFER, got %08x\n", GetLastError());
1196 ok(buflen
== size
, "Unexpected size: %d\n", size
);
1197 SetLastError(0xdeadbeef);
1198 ret
= pSetupDiGetDeviceRegistryPropertyW(set
, &devInfo
, SPDRP_FRIENDLYNAME
,
1199 NULL
, (PBYTE
)buf
, buflen
, NULL
);
1200 ok(ret
, "SetupDiGetDeviceRegistryPropertyW failed: %08x\n", GetLastError());
1201 ok(!lstrcmpiW(friendlyName
, buf
), "Unexpected property\n");
1202 SetLastError(0xdeadbeef);
1203 ret
= pSetupDiGetDeviceRegistryPropertyW(set
, &devInfo
, SPDRP_FRIENDLYNAME
,
1204 ®Type
, (PBYTE
)buf
, buflen
, NULL
);
1205 ok(ret
, "SetupDiGetDeviceRegistryPropertyW failed: %08x\n", GetLastError());
1206 ok(!lstrcmpiW(friendlyName
, buf
), "Unexpected value of property\n");
1207 ok(regType
== REG_SZ
, "Unexpected type of property: %d\n", regType
);
1208 SetLastError(0xdeadbeef);
1209 ret
= pSetupDiSetDeviceRegistryPropertyW(set
, &devInfo
, SPDRP_FRIENDLYNAME
,
1211 ok(ret
, "SetupDiSetDeviceRegistryPropertyW failed: %08x\n", GetLastError());
1212 SetLastError(0xdeadbeef);
1213 ret
= pSetupDiGetDeviceRegistryPropertyW(set
, &devInfo
, SPDRP_FRIENDLYNAME
,
1214 NULL
, (PBYTE
)buf
, buflen
, &size
);
1216 ok(!ret
&& GetLastError() == ERROR_INVALID_DATA
,
1217 "Expected ERROR_INVALID_DATA, got %08x\n", GetLastError());
1218 pSetupDiDestroyDeviceInfoList(set
);
1223 init_function_pointers();
1225 if (pSetupDiCreateDeviceInfoListExW
&& pSetupDiDestroyDeviceInfoList
)
1226 test_SetupDiCreateDeviceInfoListEx();
1228 skip("SetupDiCreateDeviceInfoListExW and/or SetupDiDestroyDeviceInfoList not available\n");
1230 if (pSetupDiOpenClassRegKeyExA
)
1231 test_SetupDiOpenClassRegKeyExA();
1233 skip("SetupDiOpenClassRegKeyExA is not available\n");
1235 testCreateDeviceInfo();
1236 testGetDeviceInstanceId();
1237 testRegisterDeviceInfo();
1238 testCreateDeviceInterface();
1239 testGetDeviceInterfaceDetail();
1241 testRegisterAndGetDetail();
1242 testDeviceRegistryPropertyA();
1243 testDeviceRegistryPropertyW();