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)
647 if (!pSetupDiCreateDeviceInfoList
|| !pSetupDiDestroyDeviceInfoList
||
648 !pSetupDiCreateDeviceInfoA
|| !pSetupDiCreateDeviceInterfaceA
||
649 !pSetupDiGetDeviceInterfaceDetailA
)
651 skip("No SetupDiGetDeviceInterfaceDetailA\n");
654 SetLastError(0xdeadbeef);
655 ret
= pSetupDiGetDeviceInterfaceDetailA(NULL
, NULL
, NULL
, 0, NULL
, NULL
);
656 ok(!ret
&& GetLastError() == ERROR_INVALID_HANDLE
,
657 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
658 set
= pSetupDiCreateDeviceInfoList(&guid
, NULL
);
659 ok(set
!= NULL
, "SetupDiCreateDeviceInfoList failed: %d\n", GetLastError());
662 SP_DEVINFO_DATA devInfo
= { sizeof(devInfo
), { 0 } };
663 SP_DEVICE_INTERFACE_DATA interfaceData
= { sizeof(interfaceData
),
667 SetLastError(0xdeadbeef);
668 ret
= pSetupDiGetDeviceInterfaceDetailA(set
, NULL
, NULL
, 0, NULL
,
670 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
671 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
672 ret
= pSetupDiCreateDeviceInfoA(set
, "ROOT\\LEGACY_BOGUS\\0000", &guid
,
673 NULL
, NULL
, 0, &devInfo
);
674 ok(ret
, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
675 SetLastError(0xdeadbeef);
676 ret
= pSetupDiCreateDeviceInterfaceA(set
, &devInfo
, &guid
, NULL
, 0,
678 ok(ret
, "SetupDiCreateDeviceInterfaceA failed: %08x\n", GetLastError());
679 SetLastError(0xdeadbeef);
680 ret
= pSetupDiGetDeviceInterfaceDetailA(set
, &interfaceData
, NULL
,
682 ok(!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
683 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
684 SetLastError(0xdeadbeef);
685 ret
= pSetupDiGetDeviceInterfaceDetailA(set
, &interfaceData
, NULL
,
687 ok(!ret
&& GetLastError() == ERROR_INVALID_USER_BUFFER
,
688 "Expected ERROR_INVALID_USER_BUFFER, got %08x\n", GetLastError());
689 SetLastError(0xdeadbeef);
690 ret
= pSetupDiGetDeviceInterfaceDetailA(set
, &interfaceData
, NULL
,
692 ok(!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
693 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
694 if (!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
696 static const char path
[] =
697 "\\\\?\\root#legacy_bogus#0000#{6a55b5a4-3f65-11db-b704-0011955c2bdb}";
698 LPBYTE buf
= HeapAlloc(GetProcessHeap(), 0, size
);
699 SP_DEVICE_INTERFACE_DETAIL_DATA_A
*detail
=
700 (SP_DEVICE_INTERFACE_DETAIL_DATA_A
*)buf
;
701 DWORD expectedsize
= offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_W
, DevicePath
) + sizeof(WCHAR
)*(1 + strlen(path
));
704 SetLastError(0xdeadbeef);
705 ret
= pSetupDiGetDeviceInterfaceDetailA(set
, &interfaceData
, detail
,
707 ok(!ret
&& GetLastError() == ERROR_INVALID_USER_BUFFER
,
708 "Expected ERROR_INVALID_USER_BUFFER, got %08x\n", GetLastError());
709 detail
->cbSize
= size
;
710 SetLastError(0xdeadbeef);
711 ret
= pSetupDiGetDeviceInterfaceDetailA(set
, &interfaceData
, detail
,
713 ok(!ret
&& GetLastError() == ERROR_INVALID_USER_BUFFER
,
714 "Expected ERROR_INVALID_USER_BUFFER, got %08x\n", GetLastError());
715 detail
->cbSize
= sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_A
);
716 SetLastError(0xdeadbeef);
717 ret
= pSetupDiGetDeviceInterfaceDetailA(set
, &interfaceData
, detail
,
719 ok(!ret
&& GetLastError() == ERROR_INVALID_USER_BUFFER
,
720 "Expected ERROR_INVALID_USER_BUFFER, got %08x\n", GetLastError());
721 /* Windows 2000 and up check for the exact size. Win9x returns ERROR_INVALID_PARAMETER
722 * on every call (so doesn't get here) and NT4 doesn't have this function.
724 detail
->cbSize
= FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_A
, DevicePath
[1]);
725 ret
= pSetupDiGetDeviceInterfaceDetailA(set
, &interfaceData
, detail
,
727 ok(ret
, "SetupDiGetDeviceInterfaceDetailA failed: %d\n",
729 ok(!lstrcmpiA(path
, detail
->DevicePath
), "Unexpected path %s\n",
731 /* Check SetupDiGetDeviceInterfaceDetailW */
732 if (pSetupDiGetDeviceInterfaceDetailW
)
734 ret
= pSetupDiGetDeviceInterfaceDetailW(set
, &interfaceData
, NULL
, 0, &size
, NULL
);
735 ok(!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Expected ERROR_INSUFFICIENT_BUFFER, got error code: %d\n", GetLastError());
736 ok(expectedsize
== size
, "SetupDiGetDeviceInterfaceDetailW returned wrong reqsize: expected %d, got %d\n", expectedsize
, size
);
739 skip("SetupDiGetDeviceInterfaceDetailW is not available\n");
741 HeapFree(GetProcessHeap(), 0, buf
);
743 pSetupDiDestroyDeviceInfoList(set
);
747 static void testDevRegKey(void)
749 static const WCHAR classKey
[] = {'S','y','s','t','e','m','\\',
750 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
751 'C','o','n','t','r','o','l','\\','C','l','a','s','s','\\',
752 '{','6','a','5','5','b','5','a','4','-','3','f','6','5','-',
753 '1','1','d','b','-','b','7','0','4','-',
754 '0','0','1','1','9','5','5','c','2','b','d','b','}',0};
755 static const WCHAR bogus
[] = {'S','y','s','t','e','m','\\',
756 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
757 'E','n','u','m','\\','R','o','o','t','\\',
758 'L','E','G','A','C','Y','_','B','O','G','U','S',0};
763 if (!pSetupDiCreateDeviceInfoList
|| !pSetupDiDestroyDeviceInfoList
||
764 !pSetupDiCreateDeviceInfoA
|| !pSetupDiOpenDevRegKey
||
765 !pSetupDiRegisterDeviceInfo
|| !pSetupDiCreateDevRegKeyW
||
766 !pSetupDiCallClassInstaller
)
768 skip("No SetupDiOpenDevRegKey\n");
772 /* Check if we are on win9x */
773 SetLastError(0xdeadbeef);
774 key
= pSetupDiCreateDevRegKeyW(NULL
, NULL
, 0, 0, 0, NULL
, NULL
);
775 if (key
== INVALID_HANDLE_VALUE
&& GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
777 skip("We are on win9x where the tests introduce issues\n");
780 ok(key
== INVALID_HANDLE_VALUE
,
781 "Expected INVALID_HANDLE_VALUE, got %p\n", key
);
782 ok(GetLastError() == ERROR_INVALID_HANDLE
,
783 "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
785 set
= pSetupDiCreateDeviceInfoList(&guid
, NULL
);
786 ok(set
!= NULL
, "SetupDiCreateDeviceInfoList failed: %d\n", GetLastError());
789 SP_DEVINFO_DATA devInfo
= { sizeof(devInfo
), { 0 } };
792 /* The device info key shouldn't be there */
793 res
= RegOpenKeyW(HKEY_LOCAL_MACHINE
, bogus
, &key
);
794 /* Due to old winetests we could have leftovers and hence the
798 ok(res
!= ERROR_SUCCESS
, "Expected key to not exist\n");
800 /* Create the device information */
801 ret
= pSetupDiCreateDeviceInfoA(set
, "ROOT\\LEGACY_BOGUS\\0000", &guid
,
802 NULL
, NULL
, 0, &devInfo
);
803 ok(ret
, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
804 /* The device info key should have been created */
805 ok(!RegOpenKeyW(HKEY_LOCAL_MACHINE
, bogus
, &key
),
806 "Expected registry key to exist\n");
808 SetLastError(0xdeadbeef);
809 key
= pSetupDiOpenDevRegKey(NULL
, NULL
, 0, 0, 0, 0);
810 ok(!key
|| key
== INVALID_HANDLE_VALUE
,
811 "Expected INVALID_HANDLE_VALUE or a NULL key (NT4)\n");
812 ok(GetLastError() == ERROR_INVALID_HANDLE
,
813 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
814 SetLastError(0xdeadbeef);
815 key
= pSetupDiOpenDevRegKey(set
, NULL
, 0, 0, 0, 0);
816 ok(key
== INVALID_HANDLE_VALUE
&&
817 GetLastError() == ERROR_INVALID_PARAMETER
,
818 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
819 SetLastError(0xdeadbeef);
820 key
= pSetupDiOpenDevRegKey(set
, &devInfo
, 0, 0, 0, 0);
821 ok(key
== INVALID_HANDLE_VALUE
&&
822 GetLastError() == ERROR_INVALID_FLAGS
,
823 "Expected ERROR_INVALID_FLAGS, got %d\n", GetLastError());
824 SetLastError(0xdeadbeef);
825 key
= pSetupDiOpenDevRegKey(set
, &devInfo
, DICS_FLAG_GLOBAL
, 0, 0, 0);
826 ok(key
== INVALID_HANDLE_VALUE
&&
827 GetLastError() == ERROR_INVALID_FLAGS
,
828 "Expected ERROR_INVALID_FLAGS, got %d\n", GetLastError());
829 SetLastError(0xdeadbeef);
830 key
= pSetupDiOpenDevRegKey(set
, &devInfo
, DICS_FLAG_GLOBAL
, 0,
832 ok(key
== INVALID_HANDLE_VALUE
&&
833 GetLastError() == ERROR_INVALID_FLAGS
,
834 "Expected ERROR_INVALID_FLAGS, got %d\n", GetLastError());
835 SetLastError(0xdeadbeef);
836 key
= pSetupDiOpenDevRegKey(set
, &devInfo
, DICS_FLAG_GLOBAL
, 0,
838 ok(key
== INVALID_HANDLE_VALUE
&&
839 GetLastError() == ERROR_DEVINFO_NOT_REGISTERED
,
840 "Expected ERROR_DEVINFO_NOT_REGISTERED, got %08x\n", GetLastError());
841 SetLastError(0xdeadbeef);
842 ret
= pSetupDiRegisterDeviceInfo(set
, &devInfo
, 0, NULL
, NULL
, NULL
);
843 ok(ret
, "SetupDiRegisterDeviceInfo failed: %08x\n", GetLastError());
844 SetLastError(0xdeadbeef);
845 key
= pSetupDiOpenDevRegKey(set
, &devInfo
, DICS_FLAG_GLOBAL
, 0,
847 /* The software key isn't created by default */
849 ok(key
== INVALID_HANDLE_VALUE
&&
850 GetLastError() == ERROR_KEY_DOES_NOT_EXIST
,
851 "Expected ERROR_KEY_DOES_NOT_EXIST_EXIST, got %08x\n", GetLastError());
852 SetLastError(0xdeadbeef);
853 key
= pSetupDiOpenDevRegKey(set
, &devInfo
, DICS_FLAG_GLOBAL
, 0,
856 ok(key
== INVALID_HANDLE_VALUE
&&
857 GetLastError() == ERROR_KEY_DOES_NOT_EXIST
,
858 "Expected ERROR_KEY_DOES_NOT_EXIST_EXIST, got %08x\n", GetLastError());
859 SetLastError(0xdeadbeef);
860 /* The class key shouldn't be there */
861 res
= RegOpenKeyW(HKEY_LOCAL_MACHINE
, classKey
, &key
);
863 ok(res
!= ERROR_SUCCESS
, "Expected key to not exist\n");
865 /* Create the device reg key */
866 key
= pSetupDiCreateDevRegKeyW(set
, &devInfo
, DICS_FLAG_GLOBAL
, 0,
867 DIREG_DRV
, NULL
, NULL
);
868 ok(key
!= INVALID_HANDLE_VALUE
, "SetupDiCreateDevRegKey failed: %08x\n",
871 /* The class key should have been created */
872 ok(!RegOpenKeyW(HKEY_LOCAL_MACHINE
, classKey
, &key
),
873 "Expected registry key to exist\n");
875 SetLastError(0xdeadbeef);
876 key
= pSetupDiOpenDevRegKey(set
, &devInfo
, DICS_FLAG_GLOBAL
, 0,
879 ok(key
== INVALID_HANDLE_VALUE
&&
880 (GetLastError() == ERROR_INVALID_DATA
||
881 GetLastError() == ERROR_ACCESS_DENIED
), /* win2k3 */
882 "Expected ERROR_INVALID_DATA or ERROR_ACCESS_DENIED, got %08x\n", GetLastError());
883 key
= pSetupDiOpenDevRegKey(set
, &devInfo
, DICS_FLAG_GLOBAL
, 0,
884 DIREG_DRV
, KEY_READ
);
885 ok(key
!= INVALID_HANDLE_VALUE
, "SetupDiOpenDevRegKey failed: %08x\n",
887 ret
= remove_device();
889 ok(ret
, "Expected the device to be removed: %08x\n", GetLastError());
890 pSetupDiDestroyDeviceInfoList(set
);
892 /* FIXME: Only do the RegDeleteKey, once Wine is fixed */
895 /* Wine doesn't delete the information currently */
896 trace("We are most likely on Wine\n");
897 devinst_RegDeleteTreeW(HKEY_LOCAL_MACHINE
, bogus
);
898 devinst_RegDeleteTreeW(HKEY_LOCAL_MACHINE
, classKey
);
902 /* There should only be a class key entry, so a simple
903 * RegDeleteKey should work
905 * This could fail if it's the first time for this new test
906 * after running the old tests.
908 ok(!RegDeleteKeyW(HKEY_LOCAL_MACHINE
, classKey
),
909 "Couldn't delete classkey\n");
914 static void testRegisterAndGetDetail(void)
918 SP_DEVINFO_DATA devInfo
= { sizeof(SP_DEVINFO_DATA
), { 0 } };
919 SP_DEVICE_INTERFACE_DATA interfaceData
= { sizeof(interfaceData
), { 0 } };
922 SetLastError(0xdeadbeef);
923 set
= pSetupDiGetClassDevsA(&guid
, NULL
, 0, DIGCF_ALLCLASSES
);
924 ok(set
!= INVALID_HANDLE_VALUE
, "SetupDiGetClassDevsA failed: %08x\n",
927 SetLastError(0xdeadbeef);
928 ret
= pSetupDiCreateDeviceInfoA(set
, "LEGACY_BOGUS", &guid
, NULL
, 0,
929 DICD_GENERATE_ID
, &devInfo
);
930 ok(ret
, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
931 SetLastError(0xdeadbeef);
932 ret
= pSetupDiCreateDeviceInterfaceA(set
, &devInfo
, &guid
, NULL
, 0, &interfaceData
);
933 ok(ret
, "SetupDiCreateDeviceInterfaceA failed: %08x\n", GetLastError());
934 SetLastError(0xdeadbeef);
935 ret
= pSetupDiRegisterDeviceInfo(set
, &devInfo
, 0, NULL
, NULL
, NULL
);
936 ok(ret
, "SetupDiRegisterDeviceInfo failed: %08x\n", GetLastError());
938 pSetupDiDestroyDeviceInfoList(set
);
940 SetLastError(0xdeadbeef);
941 set
= pSetupDiGetClassDevsA(&guid
, NULL
, 0, DIGCF_DEVICEINTERFACE
);
942 ok(set
!= INVALID_HANDLE_VALUE
, "SetupDiGetClassDevsA failed: %08x\n",
945 SetLastError(0xdeadbeef);
946 ret
= pSetupDiEnumDeviceInterfaces(set
, NULL
, &guid
, 0, &interfaceData
);
947 ok(ret
, "SetupDiEnumDeviceInterfaces failed: %08x\n", GetLastError());
948 SetLastError(0xdeadbeef);
949 ret
= pSetupDiGetDeviceInterfaceDetailA(set
, &interfaceData
, NULL
, 0, &dwSize
, NULL
);
950 ok(!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
951 "Expected ERROR_INSUFFICIENT_BUFFER, got %08x\n", GetLastError());
952 if (!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
954 static const char path
[] =
955 "\\\\?\\root#legacy_bogus#0000#{6a55b5a4-3f65-11db-b704-0011955c2bdb}";
956 PSP_DEVICE_INTERFACE_DETAIL_DATA_A detail
= NULL
;
958 detail
= (PSP_DEVICE_INTERFACE_DETAIL_DATA_A
)HeapAlloc(GetProcessHeap(), 0, dwSize
);
961 detail
->cbSize
= offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_A
, DevicePath
) + sizeof(char);
962 SetLastError(0xdeadbeef);
963 ret
= pSetupDiGetDeviceInterfaceDetailA(set
, &interfaceData
,
964 detail
, dwSize
, &dwSize
, NULL
);
965 ok(ret
, "SetupDiGetDeviceInterfaceDetailA failed: %08x\n", GetLastError());
966 /* FIXME: This one only worked because old data wasn't removed properly. As soon
967 * as all the tests are cleaned up correctly this has to be (or should be) fixed
970 ok(!lstrcmpiA(path
, detail
->DevicePath
), "Unexpected path %s\n",
972 HeapFree(GetProcessHeap(), 0, detail
);
976 pSetupDiDestroyDeviceInfoList(set
);
979 static void testDeviceRegistryPropertyA()
982 SP_DEVINFO_DATA devInfo
= { sizeof(SP_DEVINFO_DATA
), { 0 } };
983 CHAR devName
[] = "LEGACY_BOGUS";
984 CHAR friendlyName
[] = "Bogus";
991 SetLastError(0xdeadbeef);
992 set
= pSetupDiGetClassDevsA(&guid
, NULL
, 0, DIGCF_DEVICEINTERFACE
);
993 ok(set
!= INVALID_HANDLE_VALUE
, "SetupDiGetClassDevsA failed: %08x\n",
995 SetLastError(0xdeadbeef);
996 ret
= pSetupDiCreateDeviceInfoA(set
, devName
, &guid
, NULL
, NULL
,
997 DICD_GENERATE_ID
, &devInfo
);
998 ok(ret
, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
999 SetLastError(0xdeadbeef);
1000 ret
= pSetupDiSetDeviceRegistryPropertyA(NULL
, NULL
, -1, NULL
, 0);
1001 ok(!ret
&& GetLastError() == ERROR_INVALID_HANDLE
,
1002 "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
1003 SetLastError(0xdeadbeef);
1004 ret
= pSetupDiSetDeviceRegistryPropertyA(set
, NULL
, -1, NULL
, 0);
1005 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
1006 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
1007 SetLastError(0xdeadbeef);
1008 ret
= pSetupDiSetDeviceRegistryPropertyA(set
, &devInfo
, -1, NULL
, 0);
1010 ok(!ret
&& GetLastError() == ERROR_INVALID_REG_PROPERTY
,
1011 "Expected ERROR_INVALID_REG_PROPERTY, got %08x\n", GetLastError());
1012 /* GetLastError() returns nonsense in win2k3 */
1013 ret
= pSetupDiSetDeviceRegistryPropertyA(set
, &devInfo
, SPDRP_FRIENDLYNAME
,
1016 ok(!ret
, "Expected failure, got %d\n", ret
);
1017 SetLastError(0xdeadbeef);
1018 ret
= pSetupDiSetDeviceRegistryPropertyA(set
, &devInfo
, SPDRP_FRIENDLYNAME
,
1019 (PBYTE
)friendlyName
, buflen
);
1020 ok(ret
, "SetupDiSetDeviceRegistryPropertyA failed: %08x\n", GetLastError());
1021 SetLastError(0xdeadbeef);
1022 ret
= pSetupDiGetDeviceRegistryPropertyA(NULL
, NULL
, -1, NULL
, NULL
, 0, NULL
);
1023 ok(!ret
&& GetLastError() == ERROR_INVALID_HANDLE
,
1024 "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
1025 SetLastError(0xdeadbeef);
1026 ret
= pSetupDiGetDeviceRegistryPropertyA(set
, NULL
, -1, NULL
, NULL
, 0, NULL
);
1027 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
1028 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
1029 SetLastError(0xdeadbeef);
1030 ret
= pSetupDiGetDeviceRegistryPropertyA(set
, &devInfo
, -1, NULL
, NULL
, 0, NULL
);
1032 ok(!ret
&& GetLastError() == ERROR_INVALID_REG_PROPERTY
,
1033 "Expected ERROR_INVALID_REG_PROPERTY, got %08x\n", GetLastError());
1034 /* GetLastError() returns nonsense in win2k3 */
1035 ret
= pSetupDiGetDeviceRegistryPropertyA(set
, &devInfo
, SPDRP_FRIENDLYNAME
,
1036 NULL
, NULL
, buflen
, NULL
);
1037 ok(!ret
, "Expected failure, got %d\n", ret
);
1038 SetLastError(0xdeadbeef);
1039 ret
= pSetupDiGetDeviceRegistryPropertyA(set
, &devInfo
, SPDRP_FRIENDLYNAME
,
1040 NULL
, NULL
, 0, &size
);
1041 ok(!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
1042 "Expected ERROR_INSUFFICIENT_BUFFER, got %08x\n", GetLastError());
1043 ok(buflen
== size
, "Unexpected size: %d\n", size
);
1044 SetLastError(0xdeadbeef);
1045 ret
= pSetupDiGetDeviceRegistryPropertyA(set
, &devInfo
, SPDRP_FRIENDLYNAME
,
1046 NULL
, (PBYTE
)buf
, buflen
, NULL
);
1047 ok(ret
, "SetupDiGetDeviceRegistryPropertyA failed: %08x\n", GetLastError());
1048 ok(!lstrcmpiA(friendlyName
, buf
), "Unexpected property\n");
1049 SetLastError(0xdeadbeef);
1050 ret
= pSetupDiGetDeviceRegistryPropertyA(set
, &devInfo
, SPDRP_FRIENDLYNAME
,
1051 ®Type
, (PBYTE
)buf
, buflen
, NULL
);
1052 ok(ret
, "SetupDiGetDeviceRegistryPropertyA failed: %08x\n", GetLastError());
1053 ok(!lstrcmpiA(friendlyName
, buf
), "Unexpected value of property\n");
1054 ok(regType
== REG_SZ
, "Unexpected type of property: %d\n", regType
);
1055 SetLastError(0xdeadbeef);
1056 ret
= pSetupDiSetDeviceRegistryPropertyA(set
, &devInfo
, SPDRP_FRIENDLYNAME
,
1058 ok(ret
, "SetupDiSetDeviceRegistryPropertyA failed: %08x\n", GetLastError());
1059 SetLastError(0xdeadbeef);
1060 ret
= pSetupDiGetDeviceRegistryPropertyA(set
, &devInfo
, SPDRP_FRIENDLYNAME
,
1061 NULL
, (PBYTE
)buf
, buflen
, &size
);
1063 ok(!ret
&& GetLastError() == ERROR_INVALID_DATA
,
1064 "Expected ERROR_INVALID_DATA, got %08x\n", GetLastError());
1065 pSetupDiDestroyDeviceInfoList(set
);
1068 static void testDeviceRegistryPropertyW()
1071 SP_DEVINFO_DATA devInfo
= { sizeof(SP_DEVINFO_DATA
), { 0 } };
1072 WCHAR devName
[] = {'L','E','G','A','C','Y','_','B','O','G','U','S',0};
1073 WCHAR friendlyName
[] = {'B','o','g','u','s',0};
1075 DWORD buflen
= 6 * sizeof(WCHAR
);
1080 SetLastError(0xdeadbeef);
1081 set
= pSetupDiGetClassDevsW(&guid
, NULL
, 0, DIGCF_DEVICEINTERFACE
);
1082 if (set
== INVALID_HANDLE_VALUE
&& GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1084 skip("W-functions are not implemented\n");
1087 ok(set
!= INVALID_HANDLE_VALUE
, "SetupDiGetClassDevsW failed: %08x\n",
1089 SetLastError(0xdeadbeef);
1090 ret
= pSetupDiCreateDeviceInfoW(set
, devName
, &guid
, NULL
, NULL
,
1091 DICD_GENERATE_ID
, &devInfo
);
1092 ok(ret
, "SetupDiCreateDeviceInfoW failed: %08x\n", GetLastError());
1093 SetLastError(0xdeadbeef);
1094 ret
= pSetupDiSetDeviceRegistryPropertyW(NULL
, NULL
, -1, NULL
, 0);
1095 ok(!ret
&& GetLastError() == ERROR_INVALID_HANDLE
,
1096 "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
1097 SetLastError(0xdeadbeef);
1098 ret
= pSetupDiSetDeviceRegistryPropertyW(set
, NULL
, -1, NULL
, 0);
1099 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
1100 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
1101 SetLastError(0xdeadbeef);
1102 ret
= pSetupDiSetDeviceRegistryPropertyW(set
, &devInfo
, -1, NULL
, 0);
1104 ok(!ret
&& GetLastError() == ERROR_INVALID_REG_PROPERTY
,
1105 "Expected ERROR_INVALID_REG_PROPERTY, got %08x\n", GetLastError());
1106 /* GetLastError() returns nonsense in win2k3 */
1107 ret
= pSetupDiSetDeviceRegistryPropertyW(set
, &devInfo
, SPDRP_FRIENDLYNAME
,
1110 ok(!ret
, "Expected failure, got %d\n", ret
);
1111 SetLastError(0xdeadbeef);
1112 ret
= pSetupDiSetDeviceRegistryPropertyW(set
, &devInfo
, SPDRP_FRIENDLYNAME
,
1113 (PBYTE
)friendlyName
, buflen
);
1114 ok(ret
, "SetupDiSetDeviceRegistryPropertyW failed: %08x\n", GetLastError());
1115 SetLastError(0xdeadbeef);
1116 ret
= pSetupDiGetDeviceRegistryPropertyW(NULL
, NULL
, -1, NULL
, NULL
, 0, NULL
);
1117 ok(!ret
&& GetLastError() == ERROR_INVALID_HANDLE
,
1118 "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
1119 SetLastError(0xdeadbeef);
1120 ret
= pSetupDiGetDeviceRegistryPropertyW(set
, NULL
, -1, NULL
, NULL
, 0, NULL
);
1121 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
1122 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
1123 SetLastError(0xdeadbeef);
1124 ret
= pSetupDiGetDeviceRegistryPropertyW(set
, &devInfo
, -1, NULL
, NULL
, 0, NULL
);
1126 ok(!ret
&& GetLastError() == ERROR_INVALID_REG_PROPERTY
,
1127 "Expected ERROR_INVALID_REG_PROPERTY, got %08x\n", GetLastError());
1128 /* GetLastError() returns nonsense in win2k3 */
1129 ret
= pSetupDiGetDeviceRegistryPropertyW(set
, &devInfo
, SPDRP_FRIENDLYNAME
,
1130 NULL
, NULL
, buflen
, NULL
);
1131 ok(!ret
, "Expected failure, got %d\n", ret
);
1132 SetLastError(0xdeadbeef);
1133 ret
= pSetupDiGetDeviceRegistryPropertyW(set
, &devInfo
, SPDRP_FRIENDLYNAME
,
1134 NULL
, NULL
, 0, &size
);
1135 ok(!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
1136 "Expected ERROR_INSUFFICIENT_BUFFER, got %08x\n", GetLastError());
1137 ok(buflen
== size
, "Unexpected size: %d\n", size
);
1138 SetLastError(0xdeadbeef);
1139 ret
= pSetupDiGetDeviceRegistryPropertyW(set
, &devInfo
, SPDRP_FRIENDLYNAME
,
1140 NULL
, (PBYTE
)buf
, buflen
, NULL
);
1141 ok(ret
, "SetupDiGetDeviceRegistryPropertyW failed: %08x\n", GetLastError());
1142 ok(!lstrcmpiW(friendlyName
, buf
), "Unexpected property\n");
1143 SetLastError(0xdeadbeef);
1144 ret
= pSetupDiGetDeviceRegistryPropertyW(set
, &devInfo
, SPDRP_FRIENDLYNAME
,
1145 ®Type
, (PBYTE
)buf
, buflen
, NULL
);
1146 ok(ret
, "SetupDiGetDeviceRegistryPropertyW failed: %08x\n", GetLastError());
1147 ok(!lstrcmpiW(friendlyName
, buf
), "Unexpected value of property\n");
1148 ok(regType
== REG_SZ
, "Unexpected type of property: %d\n", regType
);
1149 SetLastError(0xdeadbeef);
1150 ret
= pSetupDiSetDeviceRegistryPropertyW(set
, &devInfo
, SPDRP_FRIENDLYNAME
,
1152 ok(ret
, "SetupDiSetDeviceRegistryPropertyW failed: %08x\n", GetLastError());
1153 SetLastError(0xdeadbeef);
1154 ret
= pSetupDiGetDeviceRegistryPropertyW(set
, &devInfo
, SPDRP_FRIENDLYNAME
,
1155 NULL
, (PBYTE
)buf
, buflen
, &size
);
1157 ok(!ret
&& GetLastError() == ERROR_INVALID_DATA
,
1158 "Expected ERROR_INVALID_DATA, got %08x\n", GetLastError());
1159 pSetupDiDestroyDeviceInfoList(set
);
1164 init_function_pointers();
1166 if (pSetupDiCreateDeviceInfoListExW
&& pSetupDiDestroyDeviceInfoList
)
1167 test_SetupDiCreateDeviceInfoListEx();
1169 skip("SetupDiCreateDeviceInfoListExW and/or SetupDiDestroyDeviceInfoList not available\n");
1171 if (pSetupDiOpenClassRegKeyExA
)
1172 test_SetupDiOpenClassRegKeyExA();
1174 skip("SetupDiOpenClassRegKeyExA is not available\n");
1176 testCreateDeviceInfo();
1177 testGetDeviceInstanceId();
1178 testRegisterDeviceInfo();
1179 testCreateDeviceInterface();
1180 testGetDeviceInterfaceDetail();
1182 testRegisterAndGetDetail();
1183 testDeviceRegistryPropertyA();
1184 testDeviceRegistryPropertyW();