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"
36 /* function pointers */
37 static HDEVINFO (WINAPI
*pSetupDiCreateDeviceInfoList
)(GUID
*,HWND
);
38 static HDEVINFO (WINAPI
*pSetupDiCreateDeviceInfoListExW
)(GUID
*,HWND
,PCWSTR
,PVOID
);
39 static BOOL (WINAPI
*pSetupDiCreateDeviceInterfaceA
)(HDEVINFO
, PSP_DEVINFO_DATA
, const GUID
*, PCSTR
, DWORD
, PSP_DEVICE_INTERFACE_DATA
);
40 static BOOL (WINAPI
*pSetupDiCallClassInstaller
)(DI_FUNCTION
, HDEVINFO
, PSP_DEVINFO_DATA
);
41 static BOOL (WINAPI
*pSetupDiDestroyDeviceInfoList
)(HDEVINFO
);
42 static BOOL (WINAPI
*pSetupDiEnumDeviceInfo
)(HDEVINFO
, DWORD
, PSP_DEVINFO_DATA
);
43 static BOOL (WINAPI
*pSetupDiEnumDeviceInterfaces
)(HDEVINFO
, PSP_DEVINFO_DATA
, const GUID
*, DWORD
, PSP_DEVICE_INTERFACE_DATA
);
44 static BOOL (WINAPI
*pSetupDiGetINFClassA
)(PCSTR
, LPGUID
, PSTR
, DWORD
, PDWORD
);
45 static BOOL (WINAPI
*pSetupDiInstallClassA
)(HWND
, PCSTR
, DWORD
, HSPFILEQ
);
46 static HKEY (WINAPI
*pSetupDiOpenClassRegKeyExA
)(GUID
*,REGSAM
,DWORD
,PCSTR
,PVOID
);
47 static HKEY (WINAPI
*pSetupDiOpenDevRegKey
)(HDEVINFO
, PSP_DEVINFO_DATA
, DWORD
, DWORD
, DWORD
, REGSAM
);
48 static HKEY (WINAPI
*pSetupDiCreateDevRegKeyW
)(HDEVINFO
, PSP_DEVINFO_DATA
, DWORD
, DWORD
, DWORD
, HINF
, PCWSTR
);
49 static BOOL (WINAPI
*pSetupDiCreateDeviceInfoA
)(HDEVINFO
, PCSTR
, GUID
*, PCSTR
, HWND
, DWORD
, PSP_DEVINFO_DATA
);
50 static BOOL (WINAPI
*pSetupDiCreateDeviceInfoW
)(HDEVINFO
, PCWSTR
, GUID
*, PCWSTR
, HWND
, DWORD
, PSP_DEVINFO_DATA
);
51 static BOOL (WINAPI
*pSetupDiGetDeviceInstanceIdA
)(HDEVINFO
, PSP_DEVINFO_DATA
, PSTR
, DWORD
, PDWORD
);
52 static BOOL (WINAPI
*pSetupDiGetDeviceInterfaceDetailA
)(HDEVINFO
, PSP_DEVICE_INTERFACE_DATA
, PSP_DEVICE_INTERFACE_DETAIL_DATA_A
, DWORD
, PDWORD
, PSP_DEVINFO_DATA
);
53 static BOOL (WINAPI
*pSetupDiGetDeviceInterfaceDetailW
)(HDEVINFO
, PSP_DEVICE_INTERFACE_DATA
, PSP_DEVICE_INTERFACE_DETAIL_DATA_W
, DWORD
, PDWORD
, PSP_DEVINFO_DATA
);
54 static BOOL (WINAPI
*pSetupDiRegisterDeviceInfo
)(HDEVINFO
, PSP_DEVINFO_DATA
, DWORD
, PSP_DETSIG_CMPPROC
, PVOID
, PSP_DEVINFO_DATA
);
55 static HDEVINFO (WINAPI
*pSetupDiGetClassDevsA
)(CONST GUID
*, LPCSTR
, HWND
, DWORD
);
56 static HDEVINFO (WINAPI
*pSetupDiGetClassDevsW
)(CONST GUID
*, LPCWSTR
, HWND
, DWORD
);
57 static BOOL (WINAPI
*pSetupDiSetDeviceRegistryPropertyA
)(HDEVINFO
, PSP_DEVINFO_DATA
, DWORD
, const BYTE
*, DWORD
);
58 static BOOL (WINAPI
*pSetupDiSetDeviceRegistryPropertyW
)(HDEVINFO
, PSP_DEVINFO_DATA
, DWORD
, const BYTE
*, DWORD
);
59 static BOOL (WINAPI
*pSetupDiGetDeviceRegistryPropertyA
)(HDEVINFO
, PSP_DEVINFO_DATA
, DWORD
, PDWORD
, PBYTE
, DWORD
, PDWORD
);
60 static BOOL (WINAPI
*pSetupDiGetDeviceRegistryPropertyW
)(HDEVINFO
, PSP_DEVINFO_DATA
, DWORD
, PDWORD
, PBYTE
, DWORD
, PDWORD
);
61 static BOOL (WINAPI
*pIsWow64Process
)(HANDLE
, PBOOL
);
63 /* This is a unique guid for testing purposes */
64 static GUID guid
= {0x6a55b5a4, 0x3f65, 0x11db, {0xb7,0x04,0x00,0x11,0x95,0x5c,0x2b,0xdb}};
66 static void init_function_pointers(void)
68 HMODULE hSetupAPI
= GetModuleHandleA("setupapi.dll");
69 HMODULE hKernel32
= GetModuleHandleA("kernel32.dll");
71 pSetupDiCreateDeviceInfoA
= (void *)GetProcAddress(hSetupAPI
, "SetupDiCreateDeviceInfoA");
72 pSetupDiCreateDeviceInfoW
= (void *)GetProcAddress(hSetupAPI
, "SetupDiCreateDeviceInfoW");
73 pSetupDiCreateDeviceInfoList
= (void *)GetProcAddress(hSetupAPI
, "SetupDiCreateDeviceInfoList");
74 pSetupDiCreateDeviceInfoListExW
= (void *)GetProcAddress(hSetupAPI
, "SetupDiCreateDeviceInfoListExW");
75 pSetupDiCreateDeviceInterfaceA
= (void *)GetProcAddress(hSetupAPI
, "SetupDiCreateDeviceInterfaceA");
76 pSetupDiDestroyDeviceInfoList
= (void *)GetProcAddress(hSetupAPI
, "SetupDiDestroyDeviceInfoList");
77 pSetupDiCallClassInstaller
= (void *)GetProcAddress(hSetupAPI
, "SetupDiCallClassInstaller");
78 pSetupDiEnumDeviceInfo
= (void *)GetProcAddress(hSetupAPI
, "SetupDiEnumDeviceInfo");
79 pSetupDiEnumDeviceInterfaces
= (void *)GetProcAddress(hSetupAPI
, "SetupDiEnumDeviceInterfaces");
80 pSetupDiGetDeviceInstanceIdA
= (void *)GetProcAddress(hSetupAPI
, "SetupDiGetDeviceInstanceIdA");
81 pSetupDiGetDeviceInterfaceDetailA
= (void *)GetProcAddress(hSetupAPI
, "SetupDiGetDeviceInterfaceDetailA");
82 pSetupDiGetDeviceInterfaceDetailW
= (void *)GetProcAddress(hSetupAPI
, "SetupDiGetDeviceInterfaceDetailW");
83 pSetupDiInstallClassA
= (void *)GetProcAddress(hSetupAPI
, "SetupDiInstallClassA");
84 pSetupDiOpenClassRegKeyExA
= (void *)GetProcAddress(hSetupAPI
, "SetupDiOpenClassRegKeyExA");
85 pSetupDiOpenDevRegKey
= (void *)GetProcAddress(hSetupAPI
, "SetupDiOpenDevRegKey");
86 pSetupDiCreateDevRegKeyW
= (void *)GetProcAddress(hSetupAPI
, "SetupDiCreateDevRegKeyW");
87 pSetupDiRegisterDeviceInfo
= (void *)GetProcAddress(hSetupAPI
, "SetupDiRegisterDeviceInfo");
88 pSetupDiGetClassDevsA
= (void *)GetProcAddress(hSetupAPI
, "SetupDiGetClassDevsA");
89 pSetupDiGetClassDevsW
= (void *)GetProcAddress(hSetupAPI
, "SetupDiGetClassDevsW");
90 pSetupDiGetINFClassA
= (void *)GetProcAddress(hSetupAPI
, "SetupDiGetINFClassA");
91 pSetupDiSetDeviceRegistryPropertyA
= (void *)GetProcAddress(hSetupAPI
, "SetupDiSetDeviceRegistryPropertyA");
92 pSetupDiSetDeviceRegistryPropertyW
= (void *)GetProcAddress(hSetupAPI
, "SetupDiSetDeviceRegistryPropertyW");
93 pSetupDiGetDeviceRegistryPropertyA
= (void *)GetProcAddress(hSetupAPI
, "SetupDiGetDeviceRegistryPropertyA");
94 pSetupDiGetDeviceRegistryPropertyW
= (void *)GetProcAddress(hSetupAPI
, "SetupDiGetDeviceRegistryPropertyW");
95 pIsWow64Process
= (void *)GetProcAddress(hKernel32
, "IsWow64Process");
98 static void change_reg_permissions(const WCHAR
*regkey
)
101 SID_IDENTIFIER_AUTHORITY ident
= { SECURITY_WORLD_SID_AUTHORITY
};
102 SECURITY_DESCRIPTOR sd
;
106 RegOpenKeyExW(HKEY_LOCAL_MACHINE
, regkey
, 0, WRITE_DAC
, &hkey
);
108 /* Initialize the 'Everyone' sid */
109 AllocateAndInitializeSid(&ident
, 1, SECURITY_WORLD_RID
, 0, 0, 0, 0, 0, 0, 0, &EveryoneSid
);
111 pacl
= HeapAlloc(GetProcessHeap(), 0, 256);
112 InitializeAcl(pacl
, 256, ACL_REVISION
);
114 /* Add 'Full Control' for 'Everyone' */
115 AddAccessAllowedAce(pacl
, ACL_REVISION
, KEY_ALL_ACCESS
, EveryoneSid
);
117 InitializeSecurityDescriptor(&sd
, SECURITY_DESCRIPTOR_REVISION
);
119 SetSecurityDescriptorDacl(&sd
, TRUE
, pacl
, FALSE
);
121 /* Set the new security on the registry key */
122 RegSetKeySecurity(hkey
, DACL_SECURITY_INFORMATION
, &sd
);
126 HeapFree(GetProcessHeap(), 0, pacl
);
128 FreeSid(EveryoneSid
);
131 static BOOL
remove_device(void)
134 SP_DEVINFO_DATA devInfo
= { sizeof(devInfo
), { 0 } };
137 SetLastError(0xdeadbeef);
138 set
= pSetupDiGetClassDevsA(&guid
, NULL
, 0, 0);
139 ok(set
!= INVALID_HANDLE_VALUE
, "SetupDiGetClassDevsA failed: %08x\n",
142 SetLastError(0xdeadbeef);
143 ret
= pSetupDiEnumDeviceInfo(set
, 0, &devInfo
);
144 ok(ret
, "SetupDiEnumDeviceInfo failed: %08x\n", GetLastError());
146 SetLastError(0xdeadbeef);
147 retval
= pSetupDiCallClassInstaller(DIF_REMOVE
, set
, &devInfo
);
149 todo_wine
ok(!retval
&& GetLastError() == ERROR_IN_WOW64
,
150 "SetupDiCallClassInstaller(DIF_REMOVE...) succeeded: %08x\n", GetLastError());
153 "SetupDiCallClassInstaller(DIF_REMOVE...) failed: %08x\n", GetLastError());
155 SetLastError(0xdeadbeef);
156 ret
= pSetupDiDestroyDeviceInfoList(set
);
157 ok(ret
, "SetupDiDestroyDeviceInfoList failed: %08x\n", GetLastError());
162 /* RegDeleteTreeW from dlls/advapi32/registry.c */
163 static LSTATUS
devinst_RegDeleteTreeW(HKEY hKey
, LPCWSTR lpszSubKey
)
166 DWORD dwMaxSubkeyLen
, dwMaxValueLen
;
167 DWORD dwMaxLen
, dwSize
;
168 WCHAR szNameBuf
[MAX_PATH
], *lpszName
= szNameBuf
;
173 ret
= RegOpenKeyExW(hKey
, lpszSubKey
, 0, KEY_READ
, &hSubKey
);
177 /* Get highest length for keys, values */
178 ret
= RegQueryInfoKeyW(hSubKey
, NULL
, NULL
, NULL
, NULL
,
179 &dwMaxSubkeyLen
, NULL
, NULL
, &dwMaxValueLen
, NULL
, NULL
, NULL
);
180 if (ret
) goto cleanup
;
184 dwMaxLen
= max(dwMaxSubkeyLen
, dwMaxValueLen
);
185 if (dwMaxLen
> sizeof(szNameBuf
)/sizeof(WCHAR
))
187 /* Name too big: alloc a buffer for it */
188 if (!(lpszName
= HeapAlloc( GetProcessHeap(), 0, dwMaxLen
*sizeof(WCHAR
))))
190 ret
= ERROR_NOT_ENOUGH_MEMORY
;
196 /* Recursively delete all the subkeys */
200 if (RegEnumKeyExW(hSubKey
, 0, lpszName
, &dwSize
, NULL
,
201 NULL
, NULL
, NULL
)) break;
203 ret
= devinst_RegDeleteTreeW(hSubKey
, lpszName
);
204 if (ret
) goto cleanup
;
208 ret
= RegDeleteKeyW(hKey
, lpszSubKey
);
213 if (RegEnumValueW(hKey
, 0, lpszName
, &dwSize
,
214 NULL
, NULL
, NULL
, NULL
)) break;
216 ret
= RegDeleteValueW(hKey
, lpszName
);
217 if (ret
) goto cleanup
;
221 /* Free buffer if allocated */
222 if (lpszName
!= szNameBuf
)
223 HeapFree( GetProcessHeap(), 0, lpszName
);
225 RegCloseKey(hSubKey
);
229 static void clean_devclass_key(void)
231 static const WCHAR devclass
[] = {'S','y','s','t','e','m','\\',
232 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
233 'C','o','n','t','r','o','l','\\','D','e','v','i','c','e','C','l','a','s','s','e','s','\\',
234 '{','6','a','5','5','b','5','a','4','-','3','f','6','5','-',
235 '1','1','d','b','-','b','7','0','4','-',
236 '0','0','1','1','9','5','5','c','2','b','d','b','}',0};
240 /* Check if we have subkeys as Windows 2000 doesn't delete
241 * the keys under the DeviceClasses key after a SetupDiDestroyDeviceInfoList.
243 RegOpenKeyW(HKEY_LOCAL_MACHINE
, devclass
, &key
);
244 RegQueryInfoKey(key
, NULL
, NULL
, NULL
, &subkeys
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
247 trace("We are most likely on Windows 2000\n");
248 devinst_RegDeleteTreeW(HKEY_LOCAL_MACHINE
, devclass
);
252 ok(!RegDeleteKeyW(HKEY_LOCAL_MACHINE
, devclass
),
253 "Couldn't delete deviceclass key\n");
257 static void test_SetupDiCreateDeviceInfoListEx(void)
262 static CHAR notnull
[] = "NotNull";
263 static const WCHAR machine
[] = { 'd','u','m','m','y',0 };
265 SetLastError(0xdeadbeef);
266 /* create empty DeviceInfoList, but set Reserved to a value, which is not NULL */
267 devlist
= pSetupDiCreateDeviceInfoListExW(NULL
, NULL
, NULL
, notnull
);
269 error
= GetLastError();
270 if (error
== ERROR_CALL_NOT_IMPLEMENTED
)
272 win_skip("SetupDiCreateDeviceInfoListExW is not implemented\n");
275 ok(devlist
== INVALID_HANDLE_VALUE
, "SetupDiCreateDeviceInfoListExW failed : %p %d (expected %p)\n", devlist
, error
, INVALID_HANDLE_VALUE
);
276 ok(error
== ERROR_INVALID_PARAMETER
, "GetLastError returned wrong value : %d, (expected %d)\n", error
, ERROR_INVALID_PARAMETER
);
278 SetLastError(0xdeadbeef);
279 /* create empty DeviceInfoList, but set MachineName to something */
280 devlist
= pSetupDiCreateDeviceInfoListExW(NULL
, NULL
, machine
, NULL
);
282 error
= GetLastError();
283 ok(devlist
== INVALID_HANDLE_VALUE
, "SetupDiCreateDeviceInfoListExW failed : %p %d (expected %p)\n", devlist
, error
, INVALID_HANDLE_VALUE
);
284 ok(error
== ERROR_INVALID_MACHINENAME
|| error
== ERROR_MACHINE_UNAVAILABLE
, "GetLastError returned wrong value : %d, (expected %d or %d)\n", error
, ERROR_INVALID_MACHINENAME
, ERROR_MACHINE_UNAVAILABLE
);
286 /* create empty DeviceInfoList */
287 devlist
= pSetupDiCreateDeviceInfoListExW(NULL
, NULL
, NULL
, NULL
);
288 ok(devlist
&& devlist
!= INVALID_HANDLE_VALUE
, "SetupDiCreateDeviceInfoListExW failed : %p %d (expected != %p)\n", devlist
, error
, INVALID_HANDLE_VALUE
);
290 /* destroy DeviceInfoList */
291 ret
= pSetupDiDestroyDeviceInfoList(devlist
);
292 ok(ret
, "SetupDiDestroyDeviceInfoList failed : %d\n", error
);
295 static void test_SetupDiOpenClassRegKeyExA(void)
297 static const CHAR guidString
[] = "{6a55b5a4-3f65-11db-b704-0011955c2bdb}";
300 /* Check return value for nonexistent key */
301 hkey
= pSetupDiOpenClassRegKeyExA(&guid
, KEY_ALL_ACCESS
,
302 DIOCR_INSTALLER
, NULL
, NULL
);
303 ok(hkey
== INVALID_HANDLE_VALUE
,
304 "returned %p (expected INVALID_HANDLE_VALUE)\n", hkey
);
306 /* Test it for a key that exists */
307 hkey
= SetupDiOpenClassRegKey(NULL
, KEY_ALL_ACCESS
);
308 if (hkey
!= INVALID_HANDLE_VALUE
)
311 if (RegCreateKeyA(hkey
, guidString
, &classKey
) == ERROR_SUCCESS
)
313 RegCloseKey(classKey
);
314 SetLastError(0xdeadbeef);
315 classKey
= pSetupDiOpenClassRegKeyExA(&guid
, KEY_ALL_ACCESS
,
316 DIOCR_INSTALLER
, NULL
, NULL
);
317 ok(classKey
!= INVALID_HANDLE_VALUE
,
318 "opening class registry key failed with error %d\n",
320 if (classKey
!= INVALID_HANDLE_VALUE
)
321 RegCloseKey(classKey
);
322 RegDeleteKeyA(hkey
, guidString
);
325 trace("failed to create registry key for test\n");
330 trace("failed to open classes key\n");
333 static void create_inf_file(LPCSTR filename
)
335 DWORD dwNumberOfBytesWritten
;
336 HANDLE hf
= CreateFile(filename
, GENERIC_WRITE
, 0, NULL
,
337 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
339 static const char data
[] =
341 "Signature=\"$Chicago$\"\n"
343 "ClassGUID={6a55b5a4-3f65-11db-b704-0011955c2bdb}\n"
345 "AddReg=BogusClass.NT.AddReg\n"
346 "[BogusClass.NT.AddReg]\n"
347 "HKR,,,,\"Wine test devices\"\n";
349 WriteFile(hf
, data
, sizeof(data
) - 1, &dwNumberOfBytesWritten
, NULL
);
353 static void get_temp_filename(LPSTR path
)
355 static char curr
[MAX_PATH
] = { 0 };
360 GetCurrentDirectoryA(MAX_PATH
, curr
);
361 GetTempFileNameA(curr
, "set", 0, temp
);
362 ptr
= strrchr(temp
, '\\');
364 lstrcpyA(path
, ptr
+ 1);
367 static void testInstallClass(void)
369 static const WCHAR classKey
[] = {'S','y','s','t','e','m','\\',
370 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
371 'C','o','n','t','r','o','l','\\','C','l','a','s','s','\\',
372 '{','6','a','5','5','b','5','a','4','-','3','f','6','5','-',
373 '1','1','d','b','-','b','7','0','4','-',
374 '0','0','1','1','9','5','5','c','2','b','d','b','}',0};
375 char tmpfile
[MAX_PATH
];
380 get_temp_filename(tmpfile
+ 2);
381 create_inf_file(tmpfile
+ 2);
383 ret
= pSetupDiInstallClassA(NULL
, NULL
, 0, NULL
);
384 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
385 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
386 ret
= pSetupDiInstallClassA(NULL
, NULL
, DI_NOVCP
, NULL
);
387 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
388 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
389 ret
= pSetupDiInstallClassA(NULL
, tmpfile
+ 2, DI_NOVCP
, NULL
);
390 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
391 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
392 ret
= pSetupDiInstallClassA(NULL
, tmpfile
+ 2, 0, NULL
);
393 ok(!ret
&& GetLastError() == ERROR_FILE_NOT_FOUND
,
394 "Expected ERROR_FILE_NOT_FOUND, got %08x\n", GetLastError());
395 /* The next call will succeed. Information is put into the registry but the
396 * location(s) is/are depending on the Windows version.
398 ret
= pSetupDiInstallClassA(NULL
, tmpfile
, 0, NULL
);
399 ok(ret
, "SetupDiInstallClassA failed: %08x\n", GetLastError());
401 ok(!RegDeleteKeyW(HKEY_LOCAL_MACHINE
, classKey
),
402 "Couldn't delete classkey\n");
407 static void testCreateDeviceInfo(void)
413 static const WCHAR bogus
[] = {'S','y','s','t','e','m','\\',
414 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
415 'E','n','u','m','\\','R','o','o','t','\\',
416 'L','E','G','A','C','Y','_','B','O','G','U','S',0};
418 SetLastError(0xdeadbeef);
419 ret
= pSetupDiCreateDeviceInfoA(NULL
, NULL
, NULL
, NULL
, NULL
, 0, NULL
);
420 ok(!ret
, "Expected failure\n");
421 ok(GetLastError() == ERROR_INVALID_DEVINST_NAME
||
422 GetLastError() == ERROR_INVALID_PARAMETER
/* NT4 */,
423 "Unexpected last error, got %08x\n", GetLastError());
425 SetLastError(0xdeadbeef);
426 ret
= pSetupDiCreateDeviceInfoA(NULL
, "Root\\LEGACY_BOGUS\\0000", NULL
,
427 NULL
, NULL
, 0, NULL
);
428 ok(!ret
&& GetLastError() == ERROR_INVALID_HANDLE
,
429 "Expected ERROR_INVALID_HANDLEHANDLE, got %08x\n", GetLastError());
430 set
= pSetupDiCreateDeviceInfoList(&guid
, NULL
);
431 ok(set
!= NULL
, "SetupDiCreateDeviceInfoList failed: %08x\n",
435 SP_DEVINFO_DATA devInfo
= { 0 };
437 static GUID deadbeef
=
438 {0xdeadbeef, 0xdead, 0xbeef, {0xde,0xad,0xbe,0xef,0xde,0xad,0xbe,0xef}};
441 static const WCHAR bogus0000
[] = {'S','y','s','t','e','m','\\',
442 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
443 'E','n','u','m','\\','R','o','o','t','\\',
444 'L','E','G','A','C','Y','_','B','O','G','U','S','\\','0','0','0','0',0};
446 /* So we know we have a clean start */
447 res
= RegOpenKeyW(HKEY_LOCAL_MACHINE
, bogus0000
, &key
);
448 ok(res
!= ERROR_SUCCESS
, "Expected key to not exist\n");
450 SetLastError(0xdeadbeef);
451 ret
= pSetupDiCreateDeviceInfoA(set
, "Root\\LEGACY_BOGUS\\0000", NULL
,
452 NULL
, NULL
, 0, NULL
);
453 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
454 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
455 /* Even though NT4 fails it still adds some stuff to the registry that
456 * can't be deleted via normal setupapi functions. As the registry is written
457 * by a different user (SYSTEM) we have to do some magic to get rid of the key
459 if (!RegOpenKeyW(HKEY_LOCAL_MACHINE
, bogus0000
, &key
))
461 trace("NT4 created a bogus key on failure, will be removed now\n");
462 change_reg_permissions(bogus0000
);
463 ok(!RegDeleteKeyW(HKEY_LOCAL_MACHINE
, bogus0000
),
464 "Could not delete LEGACY_BOGUS\\0000 key\n");
466 /* We can't add device information to the set with a different GUID */
467 SetLastError(0xdeadbeef);
468 ret
= pSetupDiCreateDeviceInfoA(set
, "Root\\LEGACY_BOGUS\\0000",
469 &deadbeef
, NULL
, NULL
, 0, NULL
);
470 ok(!ret
&& GetLastError() == ERROR_CLASS_MISMATCH
,
471 "Expected ERROR_CLASS_MISMATCH, got %08x\n", GetLastError());
472 if (!RegOpenKeyW(HKEY_LOCAL_MACHINE
, bogus0000
, &key
))
474 trace("NT4 created a bogus key on failure, will be removed now\n");
475 change_reg_permissions(bogus0000
);
476 ok(!RegDeleteKeyW(HKEY_LOCAL_MACHINE
, bogus0000
),
477 "Could not delete LEGACY_BOGUS\\0000 key\n");
479 /* Finally, with all three required parameters, this succeeds: */
480 ret
= pSetupDiCreateDeviceInfoA(set
, "Root\\LEGACY_BOGUS\\0000", &guid
,
481 NULL
, NULL
, 0, NULL
);
482 ok(ret
, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
483 /* This fails because the device ID already exists.. */
484 SetLastError(0xdeadbeef);
485 ret
= pSetupDiCreateDeviceInfoA(set
, "Root\\LEGACY_BOGUS\\0000", &guid
,
486 NULL
, NULL
, 0, &devInfo
);
487 ok(!ret
&& GetLastError() == ERROR_DEVINST_ALREADY_EXISTS
,
488 "Expected ERROR_DEVINST_ALREADY_EXISTS, got %08x\n", GetLastError());
489 /* whereas this "fails" because cbSize is wrong.. */
490 SetLastError(0xdeadbeef);
491 ret
= pSetupDiCreateDeviceInfoA(set
, "LEGACY_BOGUS", &guid
, NULL
, NULL
,
492 DICD_GENERATE_ID
, &devInfo
);
493 ok(!ret
&& GetLastError() == ERROR_INVALID_USER_BUFFER
,
494 "Expected ERROR_INVALID_USER_BUFFER, got %08x\n", GetLastError());
495 /* and this finally succeeds. */
496 devInfo
.cbSize
= sizeof(devInfo
);
497 ret
= pSetupDiCreateDeviceInfoA(set
, "LEGACY_BOGUS", &guid
, NULL
, NULL
,
498 DICD_GENERATE_ID
, &devInfo
);
499 ok(ret
, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
500 /* There were three devices added, however - the second failure just
501 * resulted in the SP_DEVINFO_DATA not getting copied.
503 SetLastError(0xdeadbeef);
505 while (pSetupDiEnumDeviceInfo(set
, i
, &devInfo
))
507 ok(i
== 3, "Expected 3 devices, got %d\n", i
);
508 ok(GetLastError() == ERROR_NO_MORE_ITEMS
,
509 "SetupDiEnumDeviceInfo failed: %08x\n", GetLastError());
510 pSetupDiDestroyDeviceInfoList(set
);
513 /* The bogus registry key shouldn't be there after this test. The only
514 * reasons this key would still be present:
516 * - We are running on Wine which has to be fixed
517 * - We have leftovers from old tests
519 res
= RegOpenKeyW(HKEY_LOCAL_MACHINE
, bogus
, &key
);
521 ok(res
== ERROR_FILE_NOT_FOUND
, "Expected key to not exist\n");
522 if (res
== ERROR_SUCCESS
)
526 /* Check if we have subkeys */
527 RegQueryInfoKey(key
, NULL
, NULL
, NULL
, &subkeys
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
532 /* Leftovers from old tests */
533 trace("Going to remove %d devices\n", subkeys
);
534 for (i
= 0; i
< subkeys
; i
++)
538 ret
= remove_device();
539 ok(ret
, "Expected a device to be removed\n");
544 /* Wine doesn't delete the bogus key itself currently */
545 trace("We are most likely on Wine\n");
546 RegDeleteKeyW(HKEY_LOCAL_MACHINE
, bogus
);
551 static void testGetDeviceInstanceId(void)
555 SP_DEVINFO_DATA devInfo
= { 0 };
557 SetLastError(0xdeadbeef);
558 ret
= pSetupDiGetDeviceInstanceIdA(NULL
, NULL
, NULL
, 0, NULL
);
559 ok(!ret
&& GetLastError() == ERROR_INVALID_HANDLE
,
560 "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
561 SetLastError(0xdeadbeef);
562 ret
= pSetupDiGetDeviceInstanceIdA(NULL
, &devInfo
, NULL
, 0, NULL
);
563 ok(!ret
&& GetLastError() == ERROR_INVALID_HANDLE
,
564 "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
565 set
= pSetupDiCreateDeviceInfoList(&guid
, NULL
);
566 ok(set
!= NULL
, "SetupDiCreateDeviceInfoList failed: %08x\n",
570 char instanceID
[MAX_PATH
];
573 SetLastError(0xdeadbeef);
574 ret
= pSetupDiGetDeviceInstanceIdA(set
, NULL
, NULL
, 0, NULL
);
575 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
576 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
577 SetLastError(0xdeadbeef);
578 ret
= pSetupDiGetDeviceInstanceIdA(set
, &devInfo
, NULL
, 0, NULL
);
579 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
580 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
581 SetLastError(0xdeadbeef);
582 ret
= pSetupDiGetDeviceInstanceIdA(set
, &devInfo
, NULL
, 0, &size
);
583 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
584 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
585 devInfo
.cbSize
= sizeof(devInfo
);
586 SetLastError(0xdeadbeef);
587 ret
= pSetupDiGetDeviceInstanceIdA(set
, &devInfo
, NULL
, 0, &size
);
588 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
589 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
590 ret
= pSetupDiCreateDeviceInfoA(set
, "Root\\LEGACY_BOGUS\\0000", &guid
,
591 NULL
, NULL
, 0, &devInfo
);
592 ok(ret
, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
593 SetLastError(0xdeadbeef);
594 ret
= pSetupDiGetDeviceInstanceIdA(set
, &devInfo
, NULL
, 0, &size
);
595 ok(!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
596 "Expected ERROR_INSUFFICIENT_BUFFER, got %08x\n", GetLastError());
597 ret
= pSetupDiGetDeviceInstanceIdA(set
, &devInfo
, instanceID
,
598 sizeof(instanceID
), NULL
);
599 ok(ret
, "SetupDiGetDeviceInstanceIdA failed: %08x\n", GetLastError());
600 ok(!lstrcmpA(instanceID
, "ROOT\\LEGACY_BOGUS\\0000"),
601 "Unexpected instance ID %s\n", instanceID
);
602 ret
= pSetupDiCreateDeviceInfoA(set
, "LEGACY_BOGUS", &guid
,
603 NULL
, NULL
, DICD_GENERATE_ID
, &devInfo
);
604 ok(ret
, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
605 ret
= pSetupDiGetDeviceInstanceIdA(set
, &devInfo
, instanceID
,
606 sizeof(instanceID
), NULL
);
607 ok(ret
, "SetupDiGetDeviceInstanceIdA failed: %08x\n", GetLastError());
608 /* NT4 returns 'Root' and W2K and above 'ROOT' */
609 ok(!lstrcmpiA(instanceID
, "ROOT\\LEGACY_BOGUS\\0001"),
610 "Unexpected instance ID %s\n", instanceID
);
611 pSetupDiDestroyDeviceInfoList(set
);
615 static void testRegisterDeviceInfo(void)
620 SetLastError(0xdeadbeef);
621 ret
= pSetupDiRegisterDeviceInfo(NULL
, NULL
, 0, NULL
, NULL
, NULL
);
622 ok(!ret
&& GetLastError() == ERROR_INVALID_HANDLE
,
623 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
624 set
= pSetupDiCreateDeviceInfoList(&guid
, NULL
);
625 ok(set
!= NULL
, "SetupDiCreateDeviceInfoList failed: %d\n", GetLastError());
628 SP_DEVINFO_DATA devInfo
= { 0 };
630 SetLastError(0xdeadbeef);
631 ret
= pSetupDiRegisterDeviceInfo(set
, NULL
, 0, NULL
, NULL
, NULL
);
632 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
633 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
634 SetLastError(0xdeadbeef);
635 ret
= pSetupDiRegisterDeviceInfo(set
, &devInfo
, 0, NULL
, NULL
, NULL
);
636 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
637 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
638 devInfo
.cbSize
= sizeof(devInfo
);
639 SetLastError(0xdeadbeef);
640 ret
= pSetupDiRegisterDeviceInfo(set
, &devInfo
, 0, NULL
, NULL
, NULL
);
641 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
642 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
643 ret
= pSetupDiCreateDeviceInfoA(set
, "USB\\BOGUS\\0000", &guid
,
644 NULL
, NULL
, 0, &devInfo
);
645 ok(ret
|| GetLastError() == ERROR_DEVINST_ALREADY_EXISTS
,
646 "SetupDiCreateDeviceInfoA failed: %d\n", GetLastError());
649 /* If it already existed, registering it again will fail */
650 ret
= pSetupDiRegisterDeviceInfo(set
, &devInfo
, 0, NULL
, NULL
,
652 ok(ret
, "SetupDiCreateDeviceInfoA failed: %d\n", GetLastError());
654 /* FIXME: On Win2K+ systems, this is now persisted to registry in
655 * HKLM\System\CCS\Enum\USB\Bogus\0000.
656 * FIXME: the key also becomes undeletable. How to get rid of it?
658 pSetupDiDestroyDeviceInfoList(set
);
662 static void testCreateDeviceInterface(void)
667 static const WCHAR bogus
[] = {'S','y','s','t','e','m','\\',
668 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
669 'E','n','u','m','\\','R','o','o','t','\\',
670 'L','E','G','A','C','Y','_','B','O','G','U','S',0};
671 static const WCHAR devclass
[] = {'S','y','s','t','e','m','\\',
672 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
673 'C','o','n','t','r','o','l','\\','D','e','v','i','c','e','C','l','a','s','s','e','s','\\',
674 '{','6','a','5','5','b','5','a','4','-','3','f','6','5','-',
675 '1','1','d','b','-','b','7','0','4','-',
676 '0','0','1','1','9','5','5','c','2','b','d','b','}',0};
678 if (!pSetupDiCreateDeviceInterfaceA
|| !pSetupDiEnumDeviceInterfaces
)
680 win_skip("SetupDiCreateDeviceInterfaceA and/or SetupDiEnumDeviceInterfaces are not available\n");
683 SetLastError(0xdeadbeef);
684 ret
= pSetupDiCreateDeviceInterfaceA(NULL
, NULL
, NULL
, NULL
, 0, NULL
);
685 ok(!ret
&& GetLastError() == ERROR_INVALID_HANDLE
,
686 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
687 SetLastError(0xdeadbeef);
688 ret
= pSetupDiCreateDeviceInterfaceA(NULL
, NULL
, &guid
, NULL
, 0, NULL
);
689 ok(!ret
&& GetLastError() == ERROR_INVALID_HANDLE
,
690 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
691 set
= pSetupDiCreateDeviceInfoList(&guid
, NULL
);
692 ok(set
!= NULL
, "SetupDiCreateDeviceInfoList failed: %d\n", GetLastError());
695 SP_DEVINFO_DATA devInfo
= { 0 };
696 SP_DEVICE_INTERFACE_DATA interfaceData
= { sizeof(interfaceData
),
700 SetLastError(0xdeadbeef);
701 ret
= pSetupDiCreateDeviceInterfaceA(set
, NULL
, NULL
, NULL
, 0, NULL
);
702 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
703 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
704 SetLastError(0xdeadbeef);
705 ret
= pSetupDiCreateDeviceInterfaceA(set
, &devInfo
, NULL
, NULL
, 0,
707 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
708 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
709 devInfo
.cbSize
= sizeof(devInfo
);
710 ret
= pSetupDiCreateDeviceInfoA(set
, "ROOT\\LEGACY_BOGUS\\0000", &guid
,
711 NULL
, NULL
, 0, &devInfo
);
712 ok(ret
, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
713 SetLastError(0xdeadbeef);
714 ret
= pSetupDiCreateDeviceInterfaceA(set
, &devInfo
, NULL
, NULL
, 0,
716 ok(!ret
&& GetLastError() == ERROR_INVALID_USER_BUFFER
,
717 "Expected ERROR_INVALID_USER_BUFFER, got %08x\n", GetLastError());
718 ret
= pSetupDiCreateDeviceInterfaceA(set
, &devInfo
, &guid
, NULL
, 0,
720 ok(ret
, "SetupDiCreateDeviceInterfaceA failed: %08x\n", GetLastError());
721 /* Creating the same interface a second time succeeds */
722 ret
= pSetupDiCreateDeviceInterfaceA(set
, &devInfo
, &guid
, NULL
, 0,
724 ok(ret
, "SetupDiCreateDeviceInterfaceA failed: %08x\n", GetLastError());
725 ret
= pSetupDiCreateDeviceInterfaceA(set
, &devInfo
, &guid
, "Oogah", 0,
727 ok(ret
, "SetupDiCreateDeviceInterfaceA failed: %08x\n", GetLastError());
728 ret
= pSetupDiEnumDeviceInterfaces(set
, &devInfo
, &guid
, 0,
730 ok(ret
, "SetupDiEnumDeviceInterfaces failed: %d\n", GetLastError());
732 while (pSetupDiEnumDeviceInterfaces(set
, &devInfo
, &guid
, i
,
735 ok(i
== 2, "expected 2 interfaces, got %d\n", i
);
736 ok(GetLastError() == ERROR_NO_MORE_ITEMS
,
737 "SetupDiEnumDeviceInterfaces failed: %08x\n", GetLastError());
738 ret
= pSetupDiDestroyDeviceInfoList(set
);
739 ok(ret
, "SetupDiDestroyDeviceInfoList failed: %08x\n", GetLastError());
742 /* FIXME: On Wine we still have the bogus entry in Enum\Root and
743 * subkeys, as well as the deviceclass key with subkeys.
744 * Only clean the deviceclass key once Wine if fixed.
746 if (!RegOpenKeyW(HKEY_LOCAL_MACHINE
, bogus
, &key
))
748 /* Wine doesn't delete the information currently */
749 trace("We are most likely on Wine\n");
750 devinst_RegDeleteTreeW(HKEY_LOCAL_MACHINE
, bogus
);
751 devinst_RegDeleteTreeW(HKEY_LOCAL_MACHINE
, devclass
);
755 clean_devclass_key();
760 static void testGetDeviceInterfaceDetail(void)
764 static const WCHAR bogus
[] = {'S','y','s','t','e','m','\\',
765 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
766 'E','n','u','m','\\','R','o','o','t','\\',
767 'L','E','G','A','C','Y','_','B','O','G','U','S',0};
768 static const WCHAR devclass
[] = {'S','y','s','t','e','m','\\',
769 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
770 'C','o','n','t','r','o','l','\\','D','e','v','i','c','e','C','l','a','s','s','e','s','\\',
771 '{','6','a','5','5','b','5','a','4','-','3','f','6','5','-',
772 '1','1','d','b','-','b','7','0','4','-',
773 '0','0','1','1','9','5','5','c','2','b','d','b','}',0};
775 if (!pSetupDiCreateDeviceInterfaceA
|| !pSetupDiGetDeviceInterfaceDetailA
)
777 win_skip("SetupDiCreateDeviceInterfaceA and/or SetupDiGetDeviceInterfaceDetailA are not available\n");
780 SetLastError(0xdeadbeef);
781 ret
= pSetupDiGetDeviceInterfaceDetailA(NULL
, NULL
, NULL
, 0, NULL
, NULL
);
782 ok(!ret
&& GetLastError() == ERROR_INVALID_HANDLE
,
783 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
784 set
= pSetupDiCreateDeviceInfoList(&guid
, NULL
);
785 ok(set
!= NULL
, "SetupDiCreateDeviceInfoList failed: %d\n", GetLastError());
788 SP_DEVINFO_DATA devInfo
= { sizeof(devInfo
), { 0 } };
789 SP_DEVICE_INTERFACE_DATA interfaceData
= { sizeof(interfaceData
),
794 SetLastError(0xdeadbeef);
795 ret
= pSetupDiGetDeviceInterfaceDetailA(set
, NULL
, NULL
, 0, NULL
,
797 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
798 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
799 ret
= pSetupDiCreateDeviceInfoA(set
, "ROOT\\LEGACY_BOGUS\\0000", &guid
,
800 NULL
, NULL
, 0, &devInfo
);
801 ok(ret
, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
802 SetLastError(0xdeadbeef);
803 ret
= pSetupDiCreateDeviceInterfaceA(set
, &devInfo
, &guid
, NULL
, 0,
805 ok(ret
, "SetupDiCreateDeviceInterfaceA failed: %08x\n", GetLastError());
806 SetLastError(0xdeadbeef);
807 ret
= pSetupDiGetDeviceInterfaceDetailA(set
, &interfaceData
, NULL
,
809 ok(!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
810 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
811 SetLastError(0xdeadbeef);
812 ret
= pSetupDiGetDeviceInterfaceDetailA(set
, &interfaceData
, NULL
,
814 ok(!ret
&& GetLastError() == ERROR_INVALID_USER_BUFFER
,
815 "Expected ERROR_INVALID_USER_BUFFER, got %08x\n", GetLastError());
816 SetLastError(0xdeadbeef);
817 ret
= pSetupDiGetDeviceInterfaceDetailA(set
, &interfaceData
, NULL
,
819 ok(!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
820 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
821 if (!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
823 static const char path
[] =
824 "\\\\?\\root#legacy_bogus#0000#{6a55b5a4-3f65-11db-b704-0011955c2bdb}";
825 static const char path_w2k
[] =
826 "\\\\?\\root#legacy_bogus#0000#{6a55b5a4-3f65-11db-b704-0011955c2bdb}\\";
827 LPBYTE buf
= HeapAlloc(GetProcessHeap(), 0, size
);
828 SP_DEVICE_INTERFACE_DETAIL_DATA_A
*detail
=
829 (SP_DEVICE_INTERFACE_DETAIL_DATA_A
*)buf
;
830 DWORD expectedsize
= FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_W
, DevicePath
) + sizeof(WCHAR
)*(1 + strlen(path
));
833 SetLastError(0xdeadbeef);
834 ret
= pSetupDiGetDeviceInterfaceDetailA(set
, &interfaceData
, detail
,
836 ok(!ret
&& GetLastError() == ERROR_INVALID_USER_BUFFER
,
837 "Expected ERROR_INVALID_USER_BUFFER, got %08x\n", GetLastError());
838 detail
->cbSize
= size
;
839 SetLastError(0xdeadbeef);
840 ret
= pSetupDiGetDeviceInterfaceDetailA(set
, &interfaceData
, detail
,
842 ok(!ret
&& GetLastError() == ERROR_INVALID_USER_BUFFER
,
843 "Expected ERROR_INVALID_USER_BUFFER, got %08x\n", GetLastError());
844 detail
->cbSize
= sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_A
);
845 SetLastError(0xdeadbeef);
846 ret
= pSetupDiGetDeviceInterfaceDetailA(set
, &interfaceData
, detail
,
848 ok(ret
, "SetupDiGetDeviceInterfaceDetailA failed: %d\n",
850 ok(!lstrcmpiA(path
, detail
->DevicePath
) ||
851 !lstrcmpiA(path_w2k
, detail
->DevicePath
), "Unexpected path %s\n",
853 /* Check SetupDiGetDeviceInterfaceDetailW */
854 ret
= pSetupDiGetDeviceInterfaceDetailW(set
, &interfaceData
, NULL
, 0, &size
, NULL
);
855 ok(!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
856 "Expected ERROR_INSUFFICIENT_BUFFER, got error code: %d\n", GetLastError());
857 ok(expectedsize
== size
||
858 (expectedsize
+ sizeof(WCHAR
)) == size
/* W2K adds a backslash */,
859 "SetupDiGetDeviceInterfaceDetailW returned wrong reqsize, got %d\n",
862 HeapFree(GetProcessHeap(), 0, buf
);
864 pSetupDiDestroyDeviceInfoList(set
);
867 /* FIXME: On Wine we still have the bogus entry in Enum\Root and
868 * subkeys, as well as the deviceclass key with subkeys.
869 * Only do the RegDeleteKey, once Wine is fixed.
871 if (!RegOpenKeyW(HKEY_LOCAL_MACHINE
, bogus
, &key
))
873 /* Wine doesn't delete the information currently */
874 trace("We are most likely on Wine\n");
875 devinst_RegDeleteTreeW(HKEY_LOCAL_MACHINE
, bogus
);
876 devinst_RegDeleteTreeW(HKEY_LOCAL_MACHINE
, devclass
);
880 clean_devclass_key();
885 static void testDevRegKey(void)
887 static const WCHAR classKey
[] = {'S','y','s','t','e','m','\\',
888 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
889 'C','o','n','t','r','o','l','\\','C','l','a','s','s','\\',
890 '{','6','a','5','5','b','5','a','4','-','3','f','6','5','-',
891 '1','1','d','b','-','b','7','0','4','-',
892 '0','0','1','1','9','5','5','c','2','b','d','b','}',0};
893 static const WCHAR bogus
[] = {'S','y','s','t','e','m','\\',
894 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
895 'E','n','u','m','\\','R','o','o','t','\\',
896 'L','E','G','A','C','Y','_','B','O','G','U','S',0};
900 BOOL classKeyCreated
;
902 SetLastError(0xdeadbeef);
903 key
= pSetupDiCreateDevRegKeyW(NULL
, NULL
, 0, 0, 0, NULL
, NULL
);
904 ok(key
== INVALID_HANDLE_VALUE
,
905 "Expected INVALID_HANDLE_VALUE, got %p\n", key
);
906 ok(GetLastError() == ERROR_INVALID_HANDLE
,
907 "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
909 set
= pSetupDiCreateDeviceInfoList(&guid
, NULL
);
910 ok(set
!= NULL
, "SetupDiCreateDeviceInfoList failed: %d\n", GetLastError());
913 SP_DEVINFO_DATA devInfo
= { sizeof(devInfo
), { 0 } };
916 /* The device info key shouldn't be there */
917 res
= RegOpenKeyW(HKEY_LOCAL_MACHINE
, bogus
, &key
);
918 ok(res
!= ERROR_SUCCESS
, "Expected key to not exist\n");
920 /* Create the device information */
921 ret
= pSetupDiCreateDeviceInfoA(set
, "ROOT\\LEGACY_BOGUS\\0000", &guid
,
922 NULL
, NULL
, 0, &devInfo
);
923 ok(ret
, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
924 /* The device info key should have been created */
925 ok(!RegOpenKeyW(HKEY_LOCAL_MACHINE
, bogus
, &key
),
926 "Expected registry key to exist\n");
928 SetLastError(0xdeadbeef);
929 key
= pSetupDiOpenDevRegKey(NULL
, NULL
, 0, 0, 0, 0);
930 ok(!key
|| key
== INVALID_HANDLE_VALUE
,
931 "Expected INVALID_HANDLE_VALUE or a NULL key (NT4)\n");
932 ok(GetLastError() == ERROR_INVALID_HANDLE
,
933 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
934 SetLastError(0xdeadbeef);
935 key
= pSetupDiOpenDevRegKey(set
, NULL
, 0, 0, 0, 0);
936 ok(key
== INVALID_HANDLE_VALUE
&&
937 GetLastError() == ERROR_INVALID_PARAMETER
,
938 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
939 SetLastError(0xdeadbeef);
940 key
= pSetupDiOpenDevRegKey(set
, &devInfo
, 0, 0, 0, 0);
941 ok(key
== INVALID_HANDLE_VALUE
&&
942 GetLastError() == ERROR_INVALID_FLAGS
,
943 "Expected ERROR_INVALID_FLAGS, got %d\n", GetLastError());
944 SetLastError(0xdeadbeef);
945 key
= pSetupDiOpenDevRegKey(set
, &devInfo
, DICS_FLAG_GLOBAL
, 0, 0, 0);
946 ok(key
== INVALID_HANDLE_VALUE
&&
947 GetLastError() == ERROR_INVALID_FLAGS
,
948 "Expected ERROR_INVALID_FLAGS, got %d\n", GetLastError());
949 SetLastError(0xdeadbeef);
950 key
= pSetupDiOpenDevRegKey(set
, &devInfo
, DICS_FLAG_GLOBAL
, 0,
952 ok(key
== INVALID_HANDLE_VALUE
&&
953 GetLastError() == ERROR_INVALID_FLAGS
,
954 "Expected ERROR_INVALID_FLAGS, got %d\n", GetLastError());
955 SetLastError(0xdeadbeef);
956 key
= pSetupDiOpenDevRegKey(set
, &devInfo
, DICS_FLAG_GLOBAL
, 0,
958 ok(key
== INVALID_HANDLE_VALUE
&&
959 GetLastError() == ERROR_DEVINFO_NOT_REGISTERED
,
960 "Expected ERROR_DEVINFO_NOT_REGISTERED, got %08x\n", GetLastError());
961 SetLastError(0xdeadbeef);
962 ret
= pSetupDiRegisterDeviceInfo(set
, &devInfo
, 0, NULL
, NULL
, NULL
);
963 ok(ret
, "SetupDiRegisterDeviceInfo failed: %08x\n", GetLastError());
964 SetLastError(0xdeadbeef);
965 key
= pSetupDiOpenDevRegKey(set
, &devInfo
, DICS_FLAG_GLOBAL
, 0,
967 /* The software key isn't created by default */
969 ok(key
== INVALID_HANDLE_VALUE
&&
970 GetLastError() == ERROR_KEY_DOES_NOT_EXIST
,
971 "Expected ERROR_KEY_DOES_NOT_EXIST, got %08x\n", GetLastError());
972 SetLastError(0xdeadbeef);
973 key
= pSetupDiOpenDevRegKey(set
, &devInfo
, DICS_FLAG_GLOBAL
, 0,
976 ok(key
== INVALID_HANDLE_VALUE
&&
977 GetLastError() == ERROR_KEY_DOES_NOT_EXIST
,
978 "Expected ERROR_KEY_DOES_NOT_EXIST, got %08x\n", GetLastError());
979 SetLastError(0xdeadbeef);
980 /* The class key shouldn't be there */
981 res
= RegOpenKeyW(HKEY_LOCAL_MACHINE
, classKey
, &key
);
983 ok(res
!= ERROR_SUCCESS
, "Expected key to not exist\n");
985 /* Create the device reg key */
986 key
= pSetupDiCreateDevRegKeyW(set
, &devInfo
, DICS_FLAG_GLOBAL
, 0,
987 DIREG_DRV
, NULL
, NULL
);
988 /* Vista and higher don't actually create the key */
989 ok(key
!= INVALID_HANDLE_VALUE
|| GetLastError() == ERROR_KEY_DOES_NOT_EXIST
,
990 "SetupDiCreateDevRegKey failed: %08x\n", GetLastError());
991 if (key
!= INVALID_HANDLE_VALUE
)
993 classKeyCreated
= TRUE
;
995 /* The class key should have been created */
996 ok(!RegOpenKeyW(HKEY_LOCAL_MACHINE
, classKey
, &key
),
997 "Expected registry key to exist\n");
999 SetLastError(0xdeadbeef);
1000 key
= pSetupDiOpenDevRegKey(set
, &devInfo
, DICS_FLAG_GLOBAL
, 0,
1003 ok(key
== INVALID_HANDLE_VALUE
&&
1004 (GetLastError() == ERROR_INVALID_DATA
||
1005 GetLastError() == ERROR_ACCESS_DENIED
), /* win2k3 */
1006 "Expected ERROR_INVALID_DATA or ERROR_ACCESS_DENIED, got %08x\n", GetLastError());
1007 key
= pSetupDiOpenDevRegKey(set
, &devInfo
, DICS_FLAG_GLOBAL
, 0,
1008 DIREG_DRV
, KEY_READ
);
1009 ok(key
!= INVALID_HANDLE_VALUE
, "SetupDiOpenDevRegKey failed: %08x\n",
1011 pSetupDiDestroyDeviceInfoList(set
);
1014 classKeyCreated
= FALSE
;
1017 ret
= remove_device();
1019 todo_wine
ok(ret
, "Expected the device to be removed: %08x\n", GetLastError());
1021 /* FIXME: Only do the RegDeleteKey, once Wine is fixed */
1024 /* Wine doesn't delete the information currently */
1025 trace("We are most likely on Wine\n");
1026 devinst_RegDeleteTreeW(HKEY_LOCAL_MACHINE
, bogus
);
1027 devinst_RegDeleteTreeW(HKEY_LOCAL_MACHINE
, classKey
);
1029 else if (classKeyCreated
)
1031 /* There should only be a class key entry, so a simple
1032 * RegDeleteKey should work
1034 * This could fail if it's the first time for this new test
1035 * after running the old tests.
1037 ok(!RegDeleteKeyW(HKEY_LOCAL_MACHINE
, classKey
),
1038 "Couldn't delete classkey\n");
1043 static void testRegisterAndGetDetail(void)
1047 SP_DEVINFO_DATA devInfo
= { sizeof(SP_DEVINFO_DATA
), { 0 } };
1048 SP_DEVICE_INTERFACE_DATA interfaceData
= { sizeof(interfaceData
), { 0 } };
1050 static const WCHAR bogus
[] = {'S','y','s','t','e','m','\\',
1051 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
1052 'E','n','u','m','\\','R','o','o','t','\\',
1053 'L','E','G','A','C','Y','_','B','O','G','U','S',0};
1054 static const WCHAR devclass
[] = {'S','y','s','t','e','m','\\',
1055 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
1056 'C','o','n','t','r','o','l','\\','D','e','v','i','c','e','C','l','a','s','s','e','s','\\',
1057 '{','6','a','5','5','b','5','a','4','-','3','f','6','5','-',
1058 '1','1','d','b','-','b','7','0','4','-',
1059 '0','0','1','1','9','5','5','c','2','b','d','b','}',0};
1061 if (!pSetupDiCreateDeviceInterfaceA
|| !pSetupDiEnumDeviceInterfaces
||
1062 !pSetupDiGetDeviceInterfaceDetailA
)
1064 win_skip("Needed functions are not available\n");
1068 SetLastError(0xdeadbeef);
1069 set
= pSetupDiGetClassDevsA(&guid
, NULL
, 0, DIGCF_ALLCLASSES
);
1070 ok(set
!= INVALID_HANDLE_VALUE
, "SetupDiGetClassDevsA failed: %08x\n",
1073 SetLastError(0xdeadbeef);
1074 ret
= pSetupDiCreateDeviceInfoA(set
, "LEGACY_BOGUS", &guid
, NULL
, 0,
1075 DICD_GENERATE_ID
, &devInfo
);
1076 ok(ret
, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
1077 SetLastError(0xdeadbeef);
1078 ret
= pSetupDiCreateDeviceInterfaceA(set
, &devInfo
, &guid
, NULL
, 0, &interfaceData
);
1079 ok(ret
, "SetupDiCreateDeviceInterfaceA failed: %08x\n", GetLastError());
1080 SetLastError(0xdeadbeef);
1081 ret
= pSetupDiRegisterDeviceInfo(set
, &devInfo
, 0, NULL
, NULL
, NULL
);
1082 ok(ret
, "SetupDiRegisterDeviceInfo failed: %08x\n", GetLastError());
1084 pSetupDiDestroyDeviceInfoList(set
);
1086 SetLastError(0xdeadbeef);
1087 set
= pSetupDiGetClassDevsA(&guid
, NULL
, 0, DIGCF_DEVICEINTERFACE
);
1088 ok(set
!= INVALID_HANDLE_VALUE
, "SetupDiGetClassDevsA failed: %08x\n",
1091 SetLastError(0xdeadbeef);
1092 ret
= pSetupDiEnumDeviceInterfaces(set
, NULL
, &guid
, 0, &interfaceData
);
1093 ok(ret
, "SetupDiEnumDeviceInterfaces failed: %08x\n", GetLastError());
1094 SetLastError(0xdeadbeef);
1095 ret
= pSetupDiGetDeviceInterfaceDetailA(set
, &interfaceData
, NULL
, 0, &dwSize
, NULL
);
1096 ok(!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
1097 "Expected ERROR_INSUFFICIENT_BUFFER, got %08x\n", GetLastError());
1098 if (!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
1100 static const char path
[] =
1101 "\\\\?\\root#legacy_bogus#0000#{6a55b5a4-3f65-11db-b704-0011955c2bdb}";
1102 static const char path_wow64
[] =
1103 "\\\\?\\root#legacy_bogus#0001#{6a55b5a4-3f65-11db-b704-0011955c2bdb}";
1104 static const char path_w2k
[] =
1105 "\\\\?\\root#legacy_bogus#0000#{6a55b5a4-3f65-11db-b704-0011955c2bdb}\\";
1106 PSP_DEVICE_INTERFACE_DETAIL_DATA_A detail
= NULL
;
1108 detail
= HeapAlloc(GetProcessHeap(), 0, dwSize
);
1111 detail
->cbSize
= sizeof(*detail
);
1112 SetLastError(0xdeadbeef);
1113 ret
= pSetupDiGetDeviceInterfaceDetailA(set
, &interfaceData
,
1114 detail
, dwSize
, &dwSize
, NULL
);
1115 ok(ret
, "SetupDiGetDeviceInterfaceDetailA failed: %08x\n", GetLastError());
1116 /* FIXME: This one only worked because old data wasn't removed properly. As soon
1117 * as all the tests are cleaned up correctly this has to be (or should be) fixed
1120 ok(!lstrcmpiA(path_wow64
, detail
->DevicePath
),
1121 "Unexpected path %s\n", detail
->DevicePath
);
1123 todo_wine
ok(!lstrcmpiA(path
, detail
->DevicePath
) ||
1124 !lstrcmpiA(path_w2k
, detail
->DevicePath
),
1125 "Unexpected path %s\n", detail
->DevicePath
);
1126 HeapFree(GetProcessHeap(), 0, detail
);
1130 pSetupDiDestroyDeviceInfoList(set
);
1133 ret
= remove_device();
1135 todo_wine
ok(ret
, "Expected the device to be removed: %08x\n", GetLastError());
1137 /* FIXME: Only do the RegDeleteKey, once Wine is fixed */
1140 /* Wine doesn't delete the information currently */
1141 trace("We are most likely on Wine\n");
1142 devinst_RegDeleteTreeW(HKEY_LOCAL_MACHINE
, bogus
);
1143 devinst_RegDeleteTreeW(HKEY_LOCAL_MACHINE
, devclass
);
1147 clean_devclass_key();
1151 static void testDeviceRegistryPropertyA(void)
1154 SP_DEVINFO_DATA devInfo
= { sizeof(SP_DEVINFO_DATA
), { 0 } };
1155 CHAR devName
[] = "LEGACY_BOGUS";
1156 CHAR friendlyName
[] = "Bogus";
1164 static const CHAR bogus
[] =
1165 "System\\CurrentControlSet\\Enum\\Root\\LEGACY_BOGUS";
1167 SetLastError(0xdeadbeef);
1168 set
= pSetupDiGetClassDevsA(&guid
, NULL
, 0, DIGCF_DEVICEINTERFACE
);
1169 ok(set
!= INVALID_HANDLE_VALUE
, "SetupDiGetClassDevsA failed: %08x\n",
1171 SetLastError(0xdeadbeef);
1172 ret
= pSetupDiCreateDeviceInfoA(set
, devName
, &guid
, NULL
, NULL
,
1173 DICD_GENERATE_ID
, &devInfo
);
1174 ok(ret
, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
1175 SetLastError(0xdeadbeef);
1176 ret
= pSetupDiSetDeviceRegistryPropertyA(NULL
, NULL
, -1, NULL
, 0);
1177 ok(!ret
&& GetLastError() == ERROR_INVALID_HANDLE
,
1178 "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
1179 SetLastError(0xdeadbeef);
1180 ret
= pSetupDiSetDeviceRegistryPropertyA(set
, NULL
, -1, NULL
, 0);
1181 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
1182 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
1183 SetLastError(0xdeadbeef);
1184 ret
= pSetupDiSetDeviceRegistryPropertyA(set
, &devInfo
, -1, NULL
, 0);
1186 ok(!ret
&& GetLastError() == ERROR_INVALID_REG_PROPERTY
,
1187 "Expected ERROR_INVALID_REG_PROPERTY, got %08x\n", GetLastError());
1188 /* GetLastError() returns nonsense in win2k3 */
1189 ret
= pSetupDiSetDeviceRegistryPropertyA(set
, &devInfo
, SPDRP_FRIENDLYNAME
,
1192 ok(!ret
, "Expected failure, got %d\n", ret
);
1193 SetLastError(0xdeadbeef);
1194 ret
= pSetupDiSetDeviceRegistryPropertyA(set
, &devInfo
, SPDRP_FRIENDLYNAME
,
1195 (PBYTE
)friendlyName
, buflen
);
1196 ok(ret
, "SetupDiSetDeviceRegistryPropertyA failed: %08x\n", GetLastError());
1197 SetLastError(0xdeadbeef);
1198 ret
= pSetupDiGetDeviceRegistryPropertyA(NULL
, NULL
, -1, NULL
, NULL
, 0, NULL
);
1199 ok(!ret
&& GetLastError() == ERROR_INVALID_HANDLE
,
1200 "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
1201 SetLastError(0xdeadbeef);
1202 ret
= pSetupDiGetDeviceRegistryPropertyA(set
, NULL
, -1, NULL
, NULL
, 0, NULL
);
1203 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
1204 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
1205 SetLastError(0xdeadbeef);
1206 ret
= pSetupDiGetDeviceRegistryPropertyA(set
, &devInfo
, -1, NULL
, NULL
, 0, NULL
);
1208 ok(!ret
&& GetLastError() == ERROR_INVALID_REG_PROPERTY
,
1209 "Expected ERROR_INVALID_REG_PROPERTY, got %08x\n", GetLastError());
1210 /* GetLastError() returns nonsense in win2k3 */
1211 ret
= pSetupDiGetDeviceRegistryPropertyA(set
, &devInfo
, SPDRP_FRIENDLYNAME
,
1212 NULL
, NULL
, buflen
, NULL
);
1213 ok(!ret
, "Expected failure, got %d\n", ret
);
1214 SetLastError(0xdeadbeef);
1215 ret
= pSetupDiGetDeviceRegistryPropertyA(set
, &devInfo
, SPDRP_FRIENDLYNAME
,
1216 NULL
, NULL
, 0, &size
);
1217 ok(!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
1218 "Expected ERROR_INSUFFICIENT_BUFFER, got %08x\n", GetLastError());
1219 ok(buflen
== size
, "Unexpected size: %d\n", size
);
1220 SetLastError(0xdeadbeef);
1221 ret
= pSetupDiGetDeviceRegistryPropertyA(set
, &devInfo
, SPDRP_FRIENDLYNAME
,
1222 NULL
, (PBYTE
)buf
, buflen
, NULL
);
1223 ok(ret
, "SetupDiGetDeviceRegistryPropertyA failed: %08x\n", GetLastError());
1224 ok(!lstrcmpiA(friendlyName
, buf
), "Unexpected property\n");
1225 SetLastError(0xdeadbeef);
1226 ret
= pSetupDiGetDeviceRegistryPropertyA(set
, &devInfo
, SPDRP_FRIENDLYNAME
,
1227 ®Type
, (PBYTE
)buf
, buflen
, NULL
);
1228 ok(ret
, "SetupDiGetDeviceRegistryPropertyA failed: %08x\n", GetLastError());
1229 ok(!lstrcmpiA(friendlyName
, buf
), "Unexpected value of property\n");
1230 ok(regType
== REG_SZ
, "Unexpected type of property: %d\n", regType
);
1231 SetLastError(0xdeadbeef);
1232 ret
= pSetupDiSetDeviceRegistryPropertyA(set
, &devInfo
, SPDRP_FRIENDLYNAME
,
1234 ok(ret
, "SetupDiSetDeviceRegistryPropertyA failed: %08x\n", GetLastError());
1235 SetLastError(0xdeadbeef);
1236 ret
= pSetupDiGetDeviceRegistryPropertyA(set
, &devInfo
, SPDRP_FRIENDLYNAME
,
1237 NULL
, (PBYTE
)buf
, buflen
, &size
);
1239 ok(!ret
&& GetLastError() == ERROR_INVALID_DATA
,
1240 "Expected ERROR_INVALID_DATA, got %08x\n", GetLastError());
1241 pSetupDiDestroyDeviceInfoList(set
);
1243 res
= RegOpenKeyA(HKEY_LOCAL_MACHINE
, bogus
, &key
);
1245 todo_wine
ok(res
== ERROR_FILE_NOT_FOUND
, "Expected key to not exist\n");
1246 /* FIXME: Remove when Wine is fixed */
1247 if (res
== ERROR_SUCCESS
)
1249 /* Wine doesn't delete the information currently */
1250 trace("We are most likely on Wine\n");
1251 RegDeleteKeyA(HKEY_LOCAL_MACHINE
, bogus
);
1255 static void testDeviceRegistryPropertyW(void)
1258 SP_DEVINFO_DATA devInfo
= { sizeof(SP_DEVINFO_DATA
), { 0 } };
1259 WCHAR devName
[] = {'L','E','G','A','C','Y','_','B','O','G','U','S',0};
1260 WCHAR friendlyName
[] = {'B','o','g','u','s',0};
1262 DWORD buflen
= 6 * sizeof(WCHAR
);
1268 static const WCHAR bogus
[] = {'S','y','s','t','e','m','\\',
1269 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
1270 'E','n','u','m','\\','R','o','o','t','\\',
1271 'L','E','G','A','C','Y','_','B','O','G','U','S',0};
1273 SetLastError(0xdeadbeef);
1274 set
= pSetupDiGetClassDevsW(&guid
, NULL
, 0, DIGCF_DEVICEINTERFACE
);
1275 ok(set
!= INVALID_HANDLE_VALUE
, "SetupDiGetClassDevsW failed: %08x\n",
1277 SetLastError(0xdeadbeef);
1278 ret
= pSetupDiCreateDeviceInfoW(set
, devName
, &guid
, NULL
, NULL
,
1279 DICD_GENERATE_ID
, &devInfo
);
1280 ok(ret
, "SetupDiCreateDeviceInfoW failed: %08x\n", GetLastError());
1281 SetLastError(0xdeadbeef);
1282 ret
= pSetupDiSetDeviceRegistryPropertyW(NULL
, NULL
, -1, NULL
, 0);
1283 ok(!ret
&& GetLastError() == ERROR_INVALID_HANDLE
,
1284 "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
1285 SetLastError(0xdeadbeef);
1286 ret
= pSetupDiSetDeviceRegistryPropertyW(set
, NULL
, -1, NULL
, 0);
1287 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
1288 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
1289 SetLastError(0xdeadbeef);
1290 ret
= pSetupDiSetDeviceRegistryPropertyW(set
, &devInfo
, -1, NULL
, 0);
1292 ok(!ret
&& GetLastError() == ERROR_INVALID_REG_PROPERTY
,
1293 "Expected ERROR_INVALID_REG_PROPERTY, got %08x\n", GetLastError());
1294 /* GetLastError() returns nonsense in win2k3 */
1295 ret
= pSetupDiSetDeviceRegistryPropertyW(set
, &devInfo
, SPDRP_FRIENDLYNAME
,
1298 ok(!ret
, "Expected failure, got %d\n", ret
);
1299 SetLastError(0xdeadbeef);
1300 ret
= pSetupDiSetDeviceRegistryPropertyW(set
, &devInfo
, SPDRP_FRIENDLYNAME
,
1301 (PBYTE
)friendlyName
, buflen
);
1302 ok(ret
, "SetupDiSetDeviceRegistryPropertyW failed: %08x\n", GetLastError());
1303 SetLastError(0xdeadbeef);
1304 ret
= pSetupDiGetDeviceRegistryPropertyW(NULL
, NULL
, -1, NULL
, NULL
, 0, NULL
);
1305 ok(!ret
&& GetLastError() == ERROR_INVALID_HANDLE
,
1306 "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
1307 SetLastError(0xdeadbeef);
1308 ret
= pSetupDiGetDeviceRegistryPropertyW(set
, NULL
, -1, NULL
, NULL
, 0, NULL
);
1309 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
1310 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
1311 SetLastError(0xdeadbeef);
1312 ret
= pSetupDiGetDeviceRegistryPropertyW(set
, &devInfo
, -1, NULL
, NULL
, 0, NULL
);
1314 ok(!ret
&& GetLastError() == ERROR_INVALID_REG_PROPERTY
,
1315 "Expected ERROR_INVALID_REG_PROPERTY, got %08x\n", GetLastError());
1316 /* GetLastError() returns nonsense in win2k3 */
1317 ret
= pSetupDiGetDeviceRegistryPropertyW(set
, &devInfo
, SPDRP_FRIENDLYNAME
,
1318 NULL
, NULL
, buflen
, NULL
);
1319 ok(!ret
, "Expected failure, got %d\n", ret
);
1320 SetLastError(0xdeadbeef);
1321 ret
= pSetupDiGetDeviceRegistryPropertyW(set
, &devInfo
, SPDRP_FRIENDLYNAME
,
1322 NULL
, NULL
, 0, &size
);
1323 ok(!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
1324 "Expected ERROR_INSUFFICIENT_BUFFER, got %08x\n", GetLastError());
1325 ok(buflen
== size
, "Unexpected size: %d\n", size
);
1326 SetLastError(0xdeadbeef);
1327 ret
= pSetupDiGetDeviceRegistryPropertyW(set
, &devInfo
, SPDRP_FRIENDLYNAME
,
1328 NULL
, (PBYTE
)buf
, buflen
, NULL
);
1329 ok(ret
, "SetupDiGetDeviceRegistryPropertyW failed: %08x\n", GetLastError());
1330 ok(!lstrcmpiW(friendlyName
, buf
), "Unexpected property\n");
1331 SetLastError(0xdeadbeef);
1332 ret
= pSetupDiGetDeviceRegistryPropertyW(set
, &devInfo
, SPDRP_FRIENDLYNAME
,
1333 ®Type
, (PBYTE
)buf
, buflen
, NULL
);
1334 ok(ret
, "SetupDiGetDeviceRegistryPropertyW failed: %08x\n", GetLastError());
1335 ok(!lstrcmpiW(friendlyName
, buf
), "Unexpected value of property\n");
1336 ok(regType
== REG_SZ
, "Unexpected type of property: %d\n", regType
);
1337 SetLastError(0xdeadbeef);
1338 ret
= pSetupDiSetDeviceRegistryPropertyW(set
, &devInfo
, SPDRP_FRIENDLYNAME
,
1340 ok(ret
, "SetupDiSetDeviceRegistryPropertyW failed: %08x\n", GetLastError());
1341 SetLastError(0xdeadbeef);
1342 ret
= pSetupDiGetDeviceRegistryPropertyW(set
, &devInfo
, SPDRP_FRIENDLYNAME
,
1343 NULL
, (PBYTE
)buf
, buflen
, &size
);
1345 ok(!ret
&& GetLastError() == ERROR_INVALID_DATA
,
1346 "Expected ERROR_INVALID_DATA, got %08x\n", GetLastError());
1347 pSetupDiDestroyDeviceInfoList(set
);
1349 res
= RegOpenKeyW(HKEY_LOCAL_MACHINE
, bogus
, &key
);
1351 todo_wine
ok(res
== ERROR_FILE_NOT_FOUND
, "Expected key to not exist\n");
1352 /* FIXME: Remove when Wine is fixed */
1353 if (res
== ERROR_SUCCESS
)
1355 /* Wine doesn't delete the information currently */
1356 trace("We are most likely on Wine\n");
1357 RegDeleteKeyW(HKEY_LOCAL_MACHINE
, bogus
);
1361 static void testSetupDiGetINFClassA(void)
1363 static const char inffile
[] = "winetest.inf";
1364 static const char content
[] = "[Version]\r\n\r\n";
1367 char filename
[MAX_PATH
];
1373 if(!pSetupDiGetINFClassA
)
1375 win_skip("SetupDiGetINFClassA not present\n");
1379 count
= GetTempPathA(MAX_PATH
, filename
);
1382 win_skip("GetTempPathA failed\n");
1386 strcat(filename
, inffile
);
1387 DeleteFileA(filename
);
1389 /* not existing file */
1390 SetLastError(0xdeadbeef);
1391 retval
= SetupDiGetINFClassA(filename
, &guid
, cn
, MAX_PATH
, &count
);
1392 ok(!retval
, "expected SetupDiGetINFClassA to fail!\n");
1393 if (ERROR_CALL_NOT_IMPLEMENTED
== GetLastError())
1395 skip("SetupDiGetINFClassA is not implemented\n");
1398 ok(ERROR_FILE_NOT_FOUND
== GetLastError(),
1399 "expected error ERROR_FILE_NOT_FOUND, got %u\n", GetLastError());
1401 /* missing file wins against other invalid parameter */
1402 SetLastError(0xdeadbeef);
1403 retval
= SetupDiGetINFClassA(filename
, NULL
, cn
, MAX_PATH
, &count
);
1404 ok(!retval
, "expected SetupDiGetINFClassA to fail!\n");
1405 ok(ERROR_FILE_NOT_FOUND
== GetLastError(),
1406 "expected error ERROR_FILE_NOT_FOUND, got %u\n", GetLastError());
1408 SetLastError(0xdeadbeef);
1409 retval
= SetupDiGetINFClassA(filename
, &guid
, NULL
, MAX_PATH
, &count
);
1410 ok(!retval
, "expected SetupDiGetINFClassA to fail!\n");
1411 ok(ERROR_FILE_NOT_FOUND
== GetLastError(),
1412 "expected error ERROR_FILE_NOT_FOUND, got %u\n", GetLastError());
1414 SetLastError(0xdeadbeef);
1415 retval
= SetupDiGetINFClassA(filename
, &guid
, cn
, 0, &count
);
1416 ok(!retval
, "expected SetupDiGetINFClassA to fail!\n");
1417 ok(ERROR_FILE_NOT_FOUND
== GetLastError(),
1418 "expected error ERROR_FILE_NOT_FOUND, got %u\n", GetLastError());
1420 SetLastError(0xdeadbeef);
1421 retval
= SetupDiGetINFClassA(filename
, &guid
, cn
, MAX_PATH
, NULL
);
1422 ok(!retval
, "expected SetupDiGetINFClassA to fail!\n");
1423 ok(ERROR_FILE_NOT_FOUND
== GetLastError(),
1424 "expected error ERROR_FILE_NOT_FOUND, got %u\n", GetLastError());
1426 /* test file content */
1427 h
= CreateFileA(filename
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
1428 FILE_ATTRIBUTE_NORMAL
, NULL
);
1429 if(h
== INVALID_HANDLE_VALUE
)
1431 win_skip("failed to create file %s (error %u)\n", filename
, GetLastError());
1436 retval
= SetupDiGetINFClassA(filename
, &guid
, cn
, MAX_PATH
, &count
);
1437 ok(!retval
, "expected SetupDiGetINFClassA to fail!\n");
1439 h
= CreateFileA(filename
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
1440 FILE_ATTRIBUTE_NORMAL
, NULL
);
1441 if(h
== INVALID_HANDLE_VALUE
)
1443 win_skip("failed to create file %s (error %u)\n", filename
, GetLastError());
1446 WriteFile( h
, content
, sizeof(content
), &count
, NULL
);
1449 retval
= SetupDiGetINFClassA(filename
, &guid
, cn
, MAX_PATH
, &count
);
1450 ok(!retval
, "expected SetupDiGetINFClassA to fail!\n");
1452 WritePrivateProfileStringA("Version", "Signature", "\"$CHICAGO$\"", filename
);
1454 retval
= SetupDiGetINFClassA(filename
, &guid
, cn
, MAX_PATH
, &count
);
1455 ok(!retval
, "expected SetupDiGetINFClassA to fail!\n");
1457 WritePrivateProfileStringA("Version", "Class", "WINE", filename
);
1460 retval
= SetupDiGetINFClassA(filename
, &guid
, cn
, MAX_PATH
, &count
);
1461 ok(retval
, "expected SetupDiGetINFClassA to succeed! error %u\n", GetLastError());
1462 ok(count
== 5, "expected count==5, got %u\n", count
);
1465 retval
= SetupDiGetINFClassA(filename
, &guid
, cn
, 5, &count
);
1466 ok(retval
, "expected SetupDiGetINFClassA to succeed! error %u\n", GetLastError());
1467 ok(count
== 5, "expected count==5, got %u\n", count
);
1470 SetLastError(0xdeadbeef);
1471 retval
= SetupDiGetINFClassA(filename
, &guid
, cn
, 4, &count
);
1472 ok(!retval
, "expected SetupDiGetINFClassA to fail!\n");
1473 ok(ERROR_INSUFFICIENT_BUFFER
== GetLastError(),
1474 "expected error ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
1475 ok(count
== 5, "expected count==5, got %u\n", count
);
1477 /* invalid parameter */
1478 SetLastError(0xdeadbeef);
1479 retval
= SetupDiGetINFClassA(NULL
, &guid
, cn
, MAX_PATH
, &count
);
1480 ok(!retval
, "expected SetupDiGetINFClassA to fail!\n");
1481 ok(ERROR_INVALID_PARAMETER
== GetLastError(),
1482 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1484 SetLastError(0xdeadbeef);
1485 retval
= SetupDiGetINFClassA(filename
, NULL
, cn
, MAX_PATH
, &count
);
1486 ok(!retval
, "expected SetupDiGetINFClassA to fail!\n");
1487 ok(ERROR_INVALID_PARAMETER
== GetLastError(),
1488 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1490 SetLastError(0xdeadbeef);
1491 retval
= SetupDiGetINFClassA(filename
, &guid
, NULL
, MAX_PATH
, &count
);
1492 ok(!retval
, "expected SetupDiGetINFClassA to fail!\n");
1493 ok(ERROR_INVALID_PARAMETER
== GetLastError(),
1494 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1496 SetLastError(0xdeadbeef);
1497 retval
= SetupDiGetINFClassA(filename
, &guid
, cn
, 0, &count
);
1498 ok(!retval
, "expected SetupDiGetINFClassA to fail!\n");
1499 ok(ERROR_INSUFFICIENT_BUFFER
== GetLastError() ||
1500 ERROR_INVALID_PARAMETER
== GetLastError(),
1501 "expected error ERROR_INSUFFICIENT_BUFFER or ERROR_INVALID_PARAMETER, "
1502 "got %u\n", GetLastError());
1504 DeleteFileA(filename
);
1506 WritePrivateProfileStringA("Version", "Signature", "\"$CHICAGO$\"", filename
);
1507 WritePrivateProfileStringA("Version", "ClassGUID", "WINE", filename
);
1509 SetLastError(0xdeadbeef);
1510 retval
= SetupDiGetINFClassA(filename
, &guid
, cn
, MAX_PATH
, &count
);
1511 ok(!retval
, "expected SetupDiGetINFClassA to fail!\n");
1512 ok(RPC_S_INVALID_STRING_UUID
== GetLastError() ||
1513 ERROR_INVALID_PARAMETER
== GetLastError(),
1514 "expected error RPC_S_INVALID_STRING_UUID or ERROR_INVALID_PARAMETER, "
1515 "got %u\n", GetLastError());
1517 /* network adapter guid */
1518 WritePrivateProfileStringA("Version", "ClassGUID",
1519 "{4d36e972-e325-11ce-bfc1-08002be10318}", filename
);
1521 /* this test succeeds only if the guid is known to the system */
1523 retval
= SetupDiGetINFClassA(filename
, &guid
, cn
, MAX_PATH
, &count
);
1524 ok(retval
, "expected SetupDiGetINFClassA to succeed! error %u\n", GetLastError());
1526 ok(count
== 4, "expected count==4, got %u(%s)\n", count
, cn
);
1528 DeleteFileA(filename
);
1533 init_function_pointers();
1535 if (pIsWow64Process
)
1536 pIsWow64Process(GetCurrentProcess(), &is_wow64
);
1538 if (pSetupDiCreateDeviceInfoListExW
)
1539 test_SetupDiCreateDeviceInfoListEx();
1541 win_skip("SetupDiCreateDeviceInfoListExW is not available\n");
1543 if (pSetupDiOpenClassRegKeyExA
)
1544 test_SetupDiOpenClassRegKeyExA();
1546 win_skip("SetupDiOpenClassRegKeyExA is not available\n");
1549 testCreateDeviceInfo();
1550 testGetDeviceInstanceId();
1551 testRegisterDeviceInfo();
1552 testCreateDeviceInterface();
1553 testGetDeviceInterfaceDetail();
1555 testRegisterAndGetDetail();
1556 testDeviceRegistryPropertyA();
1557 testDeviceRegistryPropertyW();
1558 testSetupDiGetINFClassA();