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 };
264 static const WCHAR empty[] = { 0 };
266 SetLastError(0xdeadbeef);
267 /* create empty DeviceInfoList, but set Reserved to a value, which is not NULL */
268 devlist = pSetupDiCreateDeviceInfoListExW(NULL, NULL, NULL, notnull);
270 error = GetLastError();
271 if (error == ERROR_CALL_NOT_IMPLEMENTED)
273 win_skip("SetupDiCreateDeviceInfoListExW is not implemented\n");
276 ok(devlist == INVALID_HANDLE_VALUE, "SetupDiCreateDeviceInfoListExW failed : %p %d (expected %p)\n", devlist, error, INVALID_HANDLE_VALUE);
277 ok(error == ERROR_INVALID_PARAMETER, "GetLastError returned wrong value : %d, (expected %d)\n", error, ERROR_INVALID_PARAMETER);
279 SetLastError(0xdeadbeef);
280 /* create empty DeviceInfoList, but set MachineName to something */
281 devlist = pSetupDiCreateDeviceInfoListExW(NULL, NULL, machine, NULL);
283 error = GetLastError();
284 ok(devlist == INVALID_HANDLE_VALUE, "SetupDiCreateDeviceInfoListExW failed : %p %d (expected %p)\n", devlist, error, INVALID_HANDLE_VALUE);
285 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);
287 /* create empty DeviceInfoList */
288 devlist = pSetupDiCreateDeviceInfoListExW(NULL, NULL, NULL, NULL);
289 ok(devlist && devlist != INVALID_HANDLE_VALUE, "SetupDiCreateDeviceInfoListExW failed : %p %d (expected != %p)\n", devlist, error, INVALID_HANDLE_VALUE);
291 /* destroy DeviceInfoList */
292 ret = pSetupDiDestroyDeviceInfoList(devlist);
293 ok(ret, "SetupDiDestroyDeviceInfoList failed : %d\n", error);
295 /* create empty DeviceInfoList with empty machine name */
296 devlist = pSetupDiCreateDeviceInfoListExW(NULL, NULL, empty, NULL);
297 ok(devlist && devlist != INVALID_HANDLE_VALUE, "SetupDiCreateDeviceInfoListExW failed : %p %d (expected != %p)\n", devlist, error, INVALID_HANDLE_VALUE);
299 /* destroy DeviceInfoList */
300 ret = pSetupDiDestroyDeviceInfoList(devlist);
301 ok(ret, "SetupDiDestroyDeviceInfoList failed : %d\n", error);
304 static void test_SetupDiOpenClassRegKeyExA(void)
306 static const CHAR guidString[] = "{6a55b5a4-3f65-11db-b704-0011955c2bdb}";
309 /* Check return value for nonexistent key */
310 hkey = pSetupDiOpenClassRegKeyExA(&guid, KEY_ALL_ACCESS,
311 DIOCR_INSTALLER, NULL, NULL);
312 ok(hkey == INVALID_HANDLE_VALUE,
313 "returned %p (expected INVALID_HANDLE_VALUE)\n", hkey);
315 /* Test it for a key that exists */
316 hkey = SetupDiOpenClassRegKey(NULL, KEY_ALL_ACCESS);
317 if (hkey != INVALID_HANDLE_VALUE)
320 if (RegCreateKeyA(hkey, guidString, &classKey) == ERROR_SUCCESS)
322 RegCloseKey(classKey);
323 SetLastError(0xdeadbeef);
324 classKey = pSetupDiOpenClassRegKeyExA(&guid, KEY_ALL_ACCESS,
325 DIOCR_INSTALLER, NULL, NULL);
326 ok(classKey != INVALID_HANDLE_VALUE,
327 "opening class registry key failed with error %d\n",
329 if (classKey != INVALID_HANDLE_VALUE)
330 RegCloseKey(classKey);
331 RegDeleteKeyA(hkey, guidString);
334 trace("failed to create registry key for test\n");
339 trace("failed to open classes key\n");
342 static void create_inf_file(LPCSTR filename)
344 DWORD dwNumberOfBytesWritten;
345 HANDLE hf = CreateFile(filename, GENERIC_WRITE, 0, NULL,
346 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
348 static const char data[] =
350 "Signature=\"$Chicago$\"\n"
352 "ClassGUID={6a55b5a4-3f65-11db-b704-0011955c2bdb}\n"
354 "AddReg=BogusClass.NT.AddReg\n"
355 "[BogusClass.NT.AddReg]\n"
356 "HKR,,,,\"Wine test devices\"\n";
358 WriteFile(hf, data, sizeof(data) - 1, &dwNumberOfBytesWritten, NULL);
362 static void get_temp_filename(LPSTR path)
364 static char curr[MAX_PATH] = { 0 };
369 GetCurrentDirectoryA(MAX_PATH, curr);
370 GetTempFileNameA(curr, "set", 0, temp);
371 ptr = strrchr(temp, '\\');
373 lstrcpyA(path, ptr + 1);
376 static void testInstallClass(void)
378 static const WCHAR classKey[] = {'S','y','s','t','e','m','\\',
379 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
380 'C','o','n','t','r','o','l','\\','C','l','a','s','s','\\',
381 '{','6','a','5','5','b','5','a','4','-','3','f','6','5','-',
382 '1','1','d','b','-','b','7','0','4','-',
383 '0','0','1','1','9','5','5','c','2','b','d','b','}',0};
384 char tmpfile[MAX_PATH];
389 get_temp_filename(tmpfile + 2);
390 create_inf_file(tmpfile + 2);
392 ret = pSetupDiInstallClassA(NULL, NULL, 0, NULL);
393 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
394 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
395 ret = pSetupDiInstallClassA(NULL, NULL, DI_NOVCP, NULL);
396 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
397 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
398 ret = pSetupDiInstallClassA(NULL, tmpfile + 2, DI_NOVCP, NULL);
399 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
400 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
401 ret = pSetupDiInstallClassA(NULL, tmpfile + 2, 0, NULL);
402 ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND,
403 "Expected ERROR_FILE_NOT_FOUND, got %08x\n", GetLastError());
404 /* The next call will succeed. Information is put into the registry but the
405 * location(s) is/are depending on the Windows version.
407 ret = pSetupDiInstallClassA(NULL, tmpfile, 0, NULL);
408 ok(ret, "SetupDiInstallClassA failed: %08x\n", GetLastError());
410 ok(!RegDeleteKeyW(HKEY_LOCAL_MACHINE, classKey),
411 "Couldn't delete classkey\n");
416 static void testCreateDeviceInfo(void)
422 static const WCHAR bogus[] = {'S','y','s','t','e','m','\\',
423 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
424 'E','n','u','m','\\','R','o','o','t','\\',
425 'L','E','G','A','C','Y','_','B','O','G','U','S',0};
427 SetLastError(0xdeadbeef);
428 ret = pSetupDiCreateDeviceInfoA(NULL, NULL, NULL, NULL, NULL, 0, NULL);
429 ok(!ret, "Expected failure\n");
430 ok(GetLastError() == ERROR_INVALID_DEVINST_NAME ||
431 GetLastError() == ERROR_INVALID_PARAMETER /* NT4 */,
432 "Unexpected last error, got %08x\n", GetLastError());
434 SetLastError(0xdeadbeef);
435 ret = pSetupDiCreateDeviceInfoA(NULL, "Root\\LEGACY_BOGUS\\0000", NULL,
436 NULL, NULL, 0, NULL);
437 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
438 "Expected ERROR_INVALID_HANDLEHANDLE, got %08x\n", GetLastError());
439 set = pSetupDiCreateDeviceInfoList(&guid, NULL);
440 ok(set != NULL, "SetupDiCreateDeviceInfoList failed: %08x\n",
444 SP_DEVINFO_DATA devInfo = { 0 };
446 static GUID deadbeef =
447 {0xdeadbeef, 0xdead, 0xbeef, {0xde,0xad,0xbe,0xef,0xde,0xad,0xbe,0xef}};
450 static const WCHAR bogus0000[] = {'S','y','s','t','e','m','\\',
451 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
452 'E','n','u','m','\\','R','o','o','t','\\',
453 'L','E','G','A','C','Y','_','B','O','G','U','S','\\','0','0','0','0',0};
455 /* So we know we have a clean start */
456 res = RegOpenKeyW(HKEY_LOCAL_MACHINE, bogus0000, &key);
457 ok(res != ERROR_SUCCESS, "Expected key to not exist\n");
459 SetLastError(0xdeadbeef);
460 ret = pSetupDiCreateDeviceInfoA(set, "Root\\LEGACY_BOGUS\\0000", NULL,
461 NULL, NULL, 0, NULL);
462 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
463 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
464 /* Even though NT4 fails it still adds some stuff to the registry that
465 * can't be deleted via normal setupapi functions. As the registry is written
466 * by a different user (SYSTEM) we have to do some magic to get rid of the key
468 if (!RegOpenKeyW(HKEY_LOCAL_MACHINE, bogus0000, &key))
470 trace("NT4 created a bogus key on failure, will be removed now\n");
471 change_reg_permissions(bogus0000);
472 ok(!RegDeleteKeyW(HKEY_LOCAL_MACHINE, bogus0000),
473 "Could not delete LEGACY_BOGUS\\0000 key\n");
475 /* We can't add device information to the set with a different GUID */
476 SetLastError(0xdeadbeef);
477 ret = pSetupDiCreateDeviceInfoA(set, "Root\\LEGACY_BOGUS\\0000",
478 &deadbeef, NULL, NULL, 0, NULL);
479 ok(!ret && GetLastError() == ERROR_CLASS_MISMATCH,
480 "Expected ERROR_CLASS_MISMATCH, got %08x\n", GetLastError());
481 if (!RegOpenKeyW(HKEY_LOCAL_MACHINE, bogus0000, &key))
483 trace("NT4 created a bogus key on failure, will be removed now\n");
484 change_reg_permissions(bogus0000);
485 ok(!RegDeleteKeyW(HKEY_LOCAL_MACHINE, bogus0000),
486 "Could not delete LEGACY_BOGUS\\0000 key\n");
488 /* Finally, with all three required parameters, this succeeds: */
489 ret = pSetupDiCreateDeviceInfoA(set, "Root\\LEGACY_BOGUS\\0000", &guid,
490 NULL, NULL, 0, NULL);
491 ok(ret, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
492 /* This fails because the device ID already exists.. */
493 SetLastError(0xdeadbeef);
494 ret = pSetupDiCreateDeviceInfoA(set, "Root\\LEGACY_BOGUS\\0000", &guid,
495 NULL, NULL, 0, &devInfo);
496 ok(!ret && GetLastError() == ERROR_DEVINST_ALREADY_EXISTS,
497 "Expected ERROR_DEVINST_ALREADY_EXISTS, got %08x\n", GetLastError());
498 /* whereas this "fails" because cbSize is wrong.. */
499 SetLastError(0xdeadbeef);
500 ret = pSetupDiCreateDeviceInfoA(set, "LEGACY_BOGUS", &guid, NULL, NULL,
501 DICD_GENERATE_ID, &devInfo);
502 ok(!ret && GetLastError() == ERROR_INVALID_USER_BUFFER,
503 "Expected ERROR_INVALID_USER_BUFFER, got %08x\n", GetLastError());
504 /* and this finally succeeds. */
505 devInfo.cbSize = sizeof(devInfo);
506 ret = pSetupDiCreateDeviceInfoA(set, "LEGACY_BOGUS", &guid, NULL, NULL,
507 DICD_GENERATE_ID, &devInfo);
508 ok(ret, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
509 /* There were three devices added, however - the second failure just
510 * resulted in the SP_DEVINFO_DATA not getting copied.
512 SetLastError(0xdeadbeef);
514 while (pSetupDiEnumDeviceInfo(set, i, &devInfo))
516 ok(i == 3, "Expected 3 devices, got %d\n", i);
517 ok(GetLastError() == ERROR_NO_MORE_ITEMS,
518 "SetupDiEnumDeviceInfo failed: %08x\n", GetLastError());
519 pSetupDiDestroyDeviceInfoList(set);
522 /* The bogus registry key shouldn't be there after this test. The only
523 * reasons this key would still be present:
525 * - We are running on Wine which has to be fixed
526 * - We have leftovers from old tests
528 res = RegOpenKeyW(HKEY_LOCAL_MACHINE, bogus, &key);
530 ok(res == ERROR_FILE_NOT_FOUND, "Expected key to not exist\n");
531 if (res == ERROR_SUCCESS)
535 /* Check if we have subkeys */
536 RegQueryInfoKey(key, NULL, NULL, NULL, &subkeys, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
541 /* Leftovers from old tests */
542 trace("Going to remove %d devices\n", subkeys);
543 for (i = 0; i < subkeys; i++)
547 ret = remove_device();
548 ok(ret, "Expected a device to be removed\n");
553 /* Wine doesn't delete the bogus key itself currently */
554 trace("We are most likely on Wine\n");
555 RegDeleteKeyW(HKEY_LOCAL_MACHINE, bogus);
560 static void testGetDeviceInstanceId(void)
564 SP_DEVINFO_DATA devInfo = { 0 };
566 SetLastError(0xdeadbeef);
567 ret = pSetupDiGetDeviceInstanceIdA(NULL, NULL, NULL, 0, NULL);
568 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
569 "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
570 SetLastError(0xdeadbeef);
571 ret = pSetupDiGetDeviceInstanceIdA(NULL, &devInfo, NULL, 0, NULL);
572 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
573 "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
574 set = pSetupDiCreateDeviceInfoList(&guid, NULL);
575 ok(set != NULL, "SetupDiCreateDeviceInfoList failed: %08x\n",
579 char instanceID[MAX_PATH];
582 SetLastError(0xdeadbeef);
583 ret = pSetupDiGetDeviceInstanceIdA(set, NULL, NULL, 0, NULL);
584 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
585 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
586 SetLastError(0xdeadbeef);
587 ret = pSetupDiGetDeviceInstanceIdA(set, &devInfo, NULL, 0, NULL);
588 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
589 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
590 SetLastError(0xdeadbeef);
591 ret = pSetupDiGetDeviceInstanceIdA(set, &devInfo, NULL, 0, &size);
592 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
593 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
594 devInfo.cbSize = sizeof(devInfo);
595 SetLastError(0xdeadbeef);
596 ret = pSetupDiGetDeviceInstanceIdA(set, &devInfo, NULL, 0, &size);
597 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
598 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
599 ret = pSetupDiCreateDeviceInfoA(set, "Root\\LEGACY_BOGUS\\0000", &guid,
600 NULL, NULL, 0, &devInfo);
601 ok(ret, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
602 SetLastError(0xdeadbeef);
603 ret = pSetupDiGetDeviceInstanceIdA(set, &devInfo, NULL, 0, &size);
604 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
605 "Expected ERROR_INSUFFICIENT_BUFFER, got %08x\n", GetLastError());
606 ret = pSetupDiGetDeviceInstanceIdA(set, &devInfo, instanceID,
607 sizeof(instanceID), NULL);
608 ok(ret, "SetupDiGetDeviceInstanceIdA failed: %08x\n", GetLastError());
609 ok(!lstrcmpA(instanceID, "ROOT\\LEGACY_BOGUS\\0000"),
610 "Unexpected instance ID %s\n", instanceID);
611 ret = pSetupDiCreateDeviceInfoA(set, "LEGACY_BOGUS", &guid,
612 NULL, NULL, DICD_GENERATE_ID, &devInfo);
613 ok(ret, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
614 ret = pSetupDiGetDeviceInstanceIdA(set, &devInfo, instanceID,
615 sizeof(instanceID), NULL);
616 ok(ret, "SetupDiGetDeviceInstanceIdA failed: %08x\n", GetLastError());
617 /* NT4 returns 'Root' and W2K and above 'ROOT' */
618 ok(!lstrcmpiA(instanceID, "ROOT\\LEGACY_BOGUS\\0001"),
619 "Unexpected instance ID %s\n", instanceID);
620 pSetupDiDestroyDeviceInfoList(set);
624 static void testRegisterDeviceInfo(void)
629 SetLastError(0xdeadbeef);
630 ret = pSetupDiRegisterDeviceInfo(NULL, NULL, 0, NULL, NULL, NULL);
631 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
632 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
633 set = pSetupDiCreateDeviceInfoList(&guid, NULL);
634 ok(set != NULL, "SetupDiCreateDeviceInfoList failed: %d\n", GetLastError());
637 SP_DEVINFO_DATA devInfo = { 0 };
639 SetLastError(0xdeadbeef);
640 ret = pSetupDiRegisterDeviceInfo(set, NULL, 0, NULL, NULL, NULL);
641 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
642 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
643 SetLastError(0xdeadbeef);
644 ret = pSetupDiRegisterDeviceInfo(set, &devInfo, 0, NULL, NULL, NULL);
645 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
646 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
647 devInfo.cbSize = sizeof(devInfo);
648 SetLastError(0xdeadbeef);
649 ret = pSetupDiRegisterDeviceInfo(set, &devInfo, 0, NULL, NULL, NULL);
650 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
651 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
652 ret = pSetupDiCreateDeviceInfoA(set, "USB\\BOGUS\\0000", &guid,
653 NULL, NULL, 0, &devInfo);
654 ok(ret || GetLastError() == ERROR_DEVINST_ALREADY_EXISTS,
655 "SetupDiCreateDeviceInfoA failed: %d\n", GetLastError());
658 /* If it already existed, registering it again will fail */
659 ret = pSetupDiRegisterDeviceInfo(set, &devInfo, 0, NULL, NULL,
661 ok(ret, "SetupDiCreateDeviceInfoA failed: %d\n", GetLastError());
663 /* FIXME: On Win2K+ systems, this is now persisted to registry in
664 * HKLM\System\CCS\Enum\USB\Bogus\0000.
665 * FIXME: the key also becomes undeletable. How to get rid of it?
667 pSetupDiDestroyDeviceInfoList(set);
671 static void testCreateDeviceInterface(void)
676 static const WCHAR bogus[] = {'S','y','s','t','e','m','\\',
677 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
678 'E','n','u','m','\\','R','o','o','t','\\',
679 'L','E','G','A','C','Y','_','B','O','G','U','S',0};
680 static const WCHAR devclass[] = {'S','y','s','t','e','m','\\',
681 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
682 'C','o','n','t','r','o','l','\\','D','e','v','i','c','e','C','l','a','s','s','e','s','\\',
683 '{','6','a','5','5','b','5','a','4','-','3','f','6','5','-',
684 '1','1','d','b','-','b','7','0','4','-',
685 '0','0','1','1','9','5','5','c','2','b','d','b','}',0};
687 if (!pSetupDiCreateDeviceInterfaceA || !pSetupDiEnumDeviceInterfaces)
689 win_skip("SetupDiCreateDeviceInterfaceA and/or SetupDiEnumDeviceInterfaces are not available\n");
692 SetLastError(0xdeadbeef);
693 ret = pSetupDiCreateDeviceInterfaceA(NULL, NULL, NULL, NULL, 0, NULL);
694 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
695 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
696 SetLastError(0xdeadbeef);
697 ret = pSetupDiCreateDeviceInterfaceA(NULL, NULL, &guid, NULL, 0, NULL);
698 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
699 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
700 set = pSetupDiCreateDeviceInfoList(&guid, NULL);
701 ok(set != NULL, "SetupDiCreateDeviceInfoList failed: %d\n", GetLastError());
704 SP_DEVINFO_DATA devInfo = { 0 };
705 SP_DEVICE_INTERFACE_DATA interfaceData = { sizeof(interfaceData),
709 SetLastError(0xdeadbeef);
710 ret = pSetupDiCreateDeviceInterfaceA(set, NULL, NULL, NULL, 0, NULL);
711 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
712 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
713 SetLastError(0xdeadbeef);
714 ret = pSetupDiCreateDeviceInterfaceA(set, &devInfo, NULL, NULL, 0,
716 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
717 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
718 devInfo.cbSize = sizeof(devInfo);
719 ret = pSetupDiCreateDeviceInfoA(set, "ROOT\\LEGACY_BOGUS\\0000", &guid,
720 NULL, NULL, 0, &devInfo);
721 ok(ret, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
722 SetLastError(0xdeadbeef);
723 ret = pSetupDiCreateDeviceInterfaceA(set, &devInfo, NULL, NULL, 0,
725 ok(!ret && GetLastError() == ERROR_INVALID_USER_BUFFER,
726 "Expected ERROR_INVALID_USER_BUFFER, got %08x\n", GetLastError());
727 ret = pSetupDiCreateDeviceInterfaceA(set, &devInfo, &guid, NULL, 0,
729 ok(ret, "SetupDiCreateDeviceInterfaceA failed: %08x\n", GetLastError());
730 /* Creating the same interface a second time succeeds */
731 ret = pSetupDiCreateDeviceInterfaceA(set, &devInfo, &guid, NULL, 0,
733 ok(ret, "SetupDiCreateDeviceInterfaceA failed: %08x\n", GetLastError());
734 ret = pSetupDiCreateDeviceInterfaceA(set, &devInfo, &guid, "Oogah", 0,
736 ok(ret, "SetupDiCreateDeviceInterfaceA failed: %08x\n", GetLastError());
737 ret = pSetupDiEnumDeviceInterfaces(set, &devInfo, &guid, 0,
739 ok(ret, "SetupDiEnumDeviceInterfaces failed: %d\n", GetLastError());
741 while (pSetupDiEnumDeviceInterfaces(set, &devInfo, &guid, i,
744 ok(i == 2, "expected 2 interfaces, got %d\n", i);
745 ok(GetLastError() == ERROR_NO_MORE_ITEMS,
746 "SetupDiEnumDeviceInterfaces failed: %08x\n", GetLastError());
747 ret = pSetupDiDestroyDeviceInfoList(set);
748 ok(ret, "SetupDiDestroyDeviceInfoList failed: %08x\n", GetLastError());
751 /* FIXME: On Wine we still have the bogus entry in Enum\Root and
752 * subkeys, as well as the deviceclass key with subkeys.
753 * Only clean the deviceclass key once Wine if fixed.
755 if (!RegOpenKeyW(HKEY_LOCAL_MACHINE, bogus, &key))
757 /* Wine doesn't delete the information currently */
758 trace("We are most likely on Wine\n");
759 devinst_RegDeleteTreeW(HKEY_LOCAL_MACHINE, bogus);
760 devinst_RegDeleteTreeW(HKEY_LOCAL_MACHINE, devclass);
764 clean_devclass_key();
769 static void testGetDeviceInterfaceDetail(void)
773 static const WCHAR bogus[] = {'S','y','s','t','e','m','\\',
774 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
775 'E','n','u','m','\\','R','o','o','t','\\',
776 'L','E','G','A','C','Y','_','B','O','G','U','S',0};
777 static const WCHAR devclass[] = {'S','y','s','t','e','m','\\',
778 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
779 'C','o','n','t','r','o','l','\\','D','e','v','i','c','e','C','l','a','s','s','e','s','\\',
780 '{','6','a','5','5','b','5','a','4','-','3','f','6','5','-',
781 '1','1','d','b','-','b','7','0','4','-',
782 '0','0','1','1','9','5','5','c','2','b','d','b','}',0};
784 if (!pSetupDiCreateDeviceInterfaceA || !pSetupDiGetDeviceInterfaceDetailA)
786 win_skip("SetupDiCreateDeviceInterfaceA and/or SetupDiGetDeviceInterfaceDetailA are not available\n");
789 SetLastError(0xdeadbeef);
790 ret = pSetupDiGetDeviceInterfaceDetailA(NULL, NULL, NULL, 0, NULL, NULL);
791 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
792 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
793 set = pSetupDiCreateDeviceInfoList(&guid, NULL);
794 ok(set != NULL, "SetupDiCreateDeviceInfoList failed: %d\n", GetLastError());
797 SP_DEVINFO_DATA devInfo = { sizeof(devInfo), { 0 } };
798 SP_DEVICE_INTERFACE_DATA interfaceData = { sizeof(interfaceData),
803 SetLastError(0xdeadbeef);
804 ret = pSetupDiGetDeviceInterfaceDetailA(set, NULL, NULL, 0, NULL,
806 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
807 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
808 ret = pSetupDiCreateDeviceInfoA(set, "ROOT\\LEGACY_BOGUS\\0000", &guid,
809 NULL, NULL, 0, &devInfo);
810 ok(ret, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
811 SetLastError(0xdeadbeef);
812 ret = pSetupDiCreateDeviceInterfaceA(set, &devInfo, &guid, NULL, 0,
814 ok(ret, "SetupDiCreateDeviceInterfaceA failed: %08x\n", GetLastError());
815 SetLastError(0xdeadbeef);
816 ret = pSetupDiGetDeviceInterfaceDetailA(set, &interfaceData, NULL,
818 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
819 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
820 SetLastError(0xdeadbeef);
821 ret = pSetupDiGetDeviceInterfaceDetailA(set, &interfaceData, NULL,
823 ok(!ret && GetLastError() == ERROR_INVALID_USER_BUFFER,
824 "Expected ERROR_INVALID_USER_BUFFER, got %08x\n", GetLastError());
825 SetLastError(0xdeadbeef);
826 ret = pSetupDiGetDeviceInterfaceDetailA(set, &interfaceData, NULL,
828 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
829 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
830 if (!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER)
832 static const char path[] =
833 "\\\\?\\root#legacy_bogus#0000#{6a55b5a4-3f65-11db-b704-0011955c2bdb}";
834 static const char path_w2k[] =
835 "\\\\?\\root#legacy_bogus#0000#{6a55b5a4-3f65-11db-b704-0011955c2bdb}\\";
836 LPBYTE buf = HeapAlloc(GetProcessHeap(), 0, size);
837 SP_DEVICE_INTERFACE_DETAIL_DATA_A *detail =
838 (SP_DEVICE_INTERFACE_DETAIL_DATA_A *)buf;
839 DWORD expectedsize = FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_W, DevicePath) + sizeof(WCHAR)*(1 + strlen(path));
842 SetLastError(0xdeadbeef);
843 ret = pSetupDiGetDeviceInterfaceDetailA(set, &interfaceData, detail,
845 ok(!ret && GetLastError() == ERROR_INVALID_USER_BUFFER,
846 "Expected ERROR_INVALID_USER_BUFFER, got %08x\n", GetLastError());
847 detail->cbSize = size;
848 SetLastError(0xdeadbeef);
849 ret = pSetupDiGetDeviceInterfaceDetailA(set, &interfaceData, detail,
851 ok(!ret && GetLastError() == ERROR_INVALID_USER_BUFFER,
852 "Expected ERROR_INVALID_USER_BUFFER, got %08x\n", GetLastError());
853 detail->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_A);
854 SetLastError(0xdeadbeef);
855 ret = pSetupDiGetDeviceInterfaceDetailA(set, &interfaceData, detail,
857 ok(ret, "SetupDiGetDeviceInterfaceDetailA failed: %d\n",
859 ok(!lstrcmpiA(path, detail->DevicePath) ||
860 !lstrcmpiA(path_w2k, detail->DevicePath), "Unexpected path %s\n",
862 /* Check SetupDiGetDeviceInterfaceDetailW */
863 ret = pSetupDiGetDeviceInterfaceDetailW(set, &interfaceData, NULL, 0, &size, NULL);
864 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
865 "Expected ERROR_INSUFFICIENT_BUFFER, got error code: %d\n", GetLastError());
866 ok(expectedsize == size ||
867 (expectedsize + sizeof(WCHAR)) == size /* W2K adds a backslash */,
868 "SetupDiGetDeviceInterfaceDetailW returned wrong reqsize, got %d\n",
871 HeapFree(GetProcessHeap(), 0, buf);
873 pSetupDiDestroyDeviceInfoList(set);
876 /* FIXME: On Wine we still have the bogus entry in Enum\Root and
877 * subkeys, as well as the deviceclass key with subkeys.
878 * Only do the RegDeleteKey, once Wine is fixed.
880 if (!RegOpenKeyW(HKEY_LOCAL_MACHINE, bogus, &key))
882 /* Wine doesn't delete the information currently */
883 trace("We are most likely on Wine\n");
884 devinst_RegDeleteTreeW(HKEY_LOCAL_MACHINE, bogus);
885 devinst_RegDeleteTreeW(HKEY_LOCAL_MACHINE, devclass);
889 clean_devclass_key();
894 static void testDevRegKey(void)
896 static const WCHAR classKey[] = {'S','y','s','t','e','m','\\',
897 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
898 'C','o','n','t','r','o','l','\\','C','l','a','s','s','\\',
899 '{','6','a','5','5','b','5','a','4','-','3','f','6','5','-',
900 '1','1','d','b','-','b','7','0','4','-',
901 '0','0','1','1','9','5','5','c','2','b','d','b','}',0};
902 static const WCHAR bogus[] = {'S','y','s','t','e','m','\\',
903 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
904 'E','n','u','m','\\','R','o','o','t','\\',
905 'L','E','G','A','C','Y','_','B','O','G','U','S',0};
909 BOOL classKeyCreated;
911 SetLastError(0xdeadbeef);
912 key = pSetupDiCreateDevRegKeyW(NULL, NULL, 0, 0, 0, NULL, NULL);
913 ok(key == INVALID_HANDLE_VALUE,
914 "Expected INVALID_HANDLE_VALUE, got %p\n", key);
915 ok(GetLastError() == ERROR_INVALID_HANDLE,
916 "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
918 set = pSetupDiCreateDeviceInfoList(&guid, NULL);
919 ok(set != NULL, "SetupDiCreateDeviceInfoList failed: %d\n", GetLastError());
922 SP_DEVINFO_DATA devInfo = { sizeof(devInfo), { 0 } };
925 /* The device info key shouldn't be there */
926 res = RegOpenKeyW(HKEY_LOCAL_MACHINE, bogus, &key);
927 ok(res != ERROR_SUCCESS, "Expected key to not exist\n");
929 /* Create the device information */
930 ret = pSetupDiCreateDeviceInfoA(set, "ROOT\\LEGACY_BOGUS\\0000", &guid,
931 NULL, NULL, 0, &devInfo);
932 ok(ret, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
933 /* The device info key should have been created */
934 ok(!RegOpenKeyW(HKEY_LOCAL_MACHINE, bogus, &key),
935 "Expected registry key to exist\n");
937 SetLastError(0xdeadbeef);
938 key = pSetupDiOpenDevRegKey(NULL, NULL, 0, 0, 0, 0);
939 ok(!key || key == INVALID_HANDLE_VALUE,
940 "Expected INVALID_HANDLE_VALUE or a NULL key (NT4)\n");
941 ok(GetLastError() == ERROR_INVALID_HANDLE,
942 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
943 SetLastError(0xdeadbeef);
944 key = pSetupDiOpenDevRegKey(set, NULL, 0, 0, 0, 0);
945 ok(key == INVALID_HANDLE_VALUE &&
946 GetLastError() == ERROR_INVALID_PARAMETER,
947 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
948 SetLastError(0xdeadbeef);
949 key = pSetupDiOpenDevRegKey(set, &devInfo, 0, 0, 0, 0);
950 ok(key == INVALID_HANDLE_VALUE &&
951 GetLastError() == ERROR_INVALID_FLAGS,
952 "Expected ERROR_INVALID_FLAGS, got %d\n", GetLastError());
953 SetLastError(0xdeadbeef);
954 key = pSetupDiOpenDevRegKey(set, &devInfo, DICS_FLAG_GLOBAL, 0, 0, 0);
955 ok(key == INVALID_HANDLE_VALUE &&
956 GetLastError() == ERROR_INVALID_FLAGS,
957 "Expected ERROR_INVALID_FLAGS, got %d\n", GetLastError());
958 SetLastError(0xdeadbeef);
959 key = pSetupDiOpenDevRegKey(set, &devInfo, DICS_FLAG_GLOBAL, 0,
961 ok(key == INVALID_HANDLE_VALUE &&
962 GetLastError() == ERROR_INVALID_FLAGS,
963 "Expected ERROR_INVALID_FLAGS, got %d\n", GetLastError());
964 SetLastError(0xdeadbeef);
965 key = pSetupDiOpenDevRegKey(set, &devInfo, DICS_FLAG_GLOBAL, 0,
967 ok(key == INVALID_HANDLE_VALUE &&
968 GetLastError() == ERROR_DEVINFO_NOT_REGISTERED,
969 "Expected ERROR_DEVINFO_NOT_REGISTERED, got %08x\n", GetLastError());
970 SetLastError(0xdeadbeef);
971 ret = pSetupDiRegisterDeviceInfo(set, &devInfo, 0, NULL, NULL, NULL);
972 ok(ret, "SetupDiRegisterDeviceInfo failed: %08x\n", GetLastError());
973 SetLastError(0xdeadbeef);
974 key = pSetupDiOpenDevRegKey(set, &devInfo, DICS_FLAG_GLOBAL, 0,
976 /* The software key isn't created by default */
978 ok(key == INVALID_HANDLE_VALUE &&
979 GetLastError() == ERROR_KEY_DOES_NOT_EXIST,
980 "Expected ERROR_KEY_DOES_NOT_EXIST, got %08x\n", GetLastError());
981 SetLastError(0xdeadbeef);
982 key = pSetupDiOpenDevRegKey(set, &devInfo, DICS_FLAG_GLOBAL, 0,
985 ok(key == INVALID_HANDLE_VALUE &&
986 GetLastError() == ERROR_KEY_DOES_NOT_EXIST,
987 "Expected ERROR_KEY_DOES_NOT_EXIST, got %08x\n", GetLastError());
988 SetLastError(0xdeadbeef);
989 /* The class key shouldn't be there */
990 res = RegOpenKeyW(HKEY_LOCAL_MACHINE, classKey, &key);
992 ok(res != ERROR_SUCCESS, "Expected key to not exist\n");
994 /* Create the device reg key */
995 key = pSetupDiCreateDevRegKeyW(set, &devInfo, DICS_FLAG_GLOBAL, 0,
996 DIREG_DRV, NULL, NULL);
997 /* Vista and higher don't actually create the key */
998 ok(key != INVALID_HANDLE_VALUE || GetLastError() == ERROR_KEY_DOES_NOT_EXIST,
999 "SetupDiCreateDevRegKey failed: %08x\n", GetLastError());
1000 if (key != INVALID_HANDLE_VALUE)
1002 classKeyCreated = TRUE;
1004 /* The class key should have been created */
1005 ok(!RegOpenKeyW(HKEY_LOCAL_MACHINE, classKey, &key),
1006 "Expected registry key to exist\n");
1008 SetLastError(0xdeadbeef);
1009 key = pSetupDiOpenDevRegKey(set, &devInfo, DICS_FLAG_GLOBAL, 0,
1012 ok(key == INVALID_HANDLE_VALUE &&
1013 (GetLastError() == ERROR_INVALID_DATA ||
1014 GetLastError() == ERROR_ACCESS_DENIED), /* win2k3 */
1015 "Expected ERROR_INVALID_DATA or ERROR_ACCESS_DENIED, got %08x\n", GetLastError());
1016 key = pSetupDiOpenDevRegKey(set, &devInfo, DICS_FLAG_GLOBAL, 0,
1017 DIREG_DRV, KEY_READ);
1018 ok(key != INVALID_HANDLE_VALUE, "SetupDiOpenDevRegKey failed: %08x\n",
1020 pSetupDiDestroyDeviceInfoList(set);
1023 classKeyCreated = FALSE;
1026 ret = remove_device();
1028 todo_wine ok(ret, "Expected the device to be removed: %08x\n", GetLastError());
1030 /* FIXME: Only do the RegDeleteKey, once Wine is fixed */
1033 /* Wine doesn't delete the information currently */
1034 trace("We are most likely on Wine\n");
1035 devinst_RegDeleteTreeW(HKEY_LOCAL_MACHINE, bogus);
1036 devinst_RegDeleteTreeW(HKEY_LOCAL_MACHINE, classKey);
1038 else if (classKeyCreated)
1040 /* There should only be a class key entry, so a simple
1041 * RegDeleteKey should work
1043 * This could fail if it's the first time for this new test
1044 * after running the old tests.
1046 ok(!RegDeleteKeyW(HKEY_LOCAL_MACHINE, classKey),
1047 "Couldn't delete classkey\n");
1052 static void testRegisterAndGetDetail(void)
1056 SP_DEVINFO_DATA devInfo = { sizeof(SP_DEVINFO_DATA), { 0 } };
1057 SP_DEVICE_INTERFACE_DATA interfaceData = { sizeof(interfaceData), { 0 } };
1059 static const WCHAR bogus[] = {'S','y','s','t','e','m','\\',
1060 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
1061 'E','n','u','m','\\','R','o','o','t','\\',
1062 'L','E','G','A','C','Y','_','B','O','G','U','S',0};
1063 static const WCHAR devclass[] = {'S','y','s','t','e','m','\\',
1064 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
1065 'C','o','n','t','r','o','l','\\','D','e','v','i','c','e','C','l','a','s','s','e','s','\\',
1066 '{','6','a','5','5','b','5','a','4','-','3','f','6','5','-',
1067 '1','1','d','b','-','b','7','0','4','-',
1068 '0','0','1','1','9','5','5','c','2','b','d','b','}',0};
1070 if (!pSetupDiCreateDeviceInterfaceA || !pSetupDiEnumDeviceInterfaces ||
1071 !pSetupDiGetDeviceInterfaceDetailA)
1073 win_skip("Needed functions are not available\n");
1077 SetLastError(0xdeadbeef);
1078 set = pSetupDiGetClassDevsA(&guid, NULL, 0, DIGCF_ALLCLASSES);
1079 ok(set != INVALID_HANDLE_VALUE, "SetupDiGetClassDevsA failed: %08x\n",
1082 SetLastError(0xdeadbeef);
1083 ret = pSetupDiCreateDeviceInfoA(set, "LEGACY_BOGUS", &guid, NULL, 0,
1084 DICD_GENERATE_ID, &devInfo);
1085 ok(ret, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
1086 SetLastError(0xdeadbeef);
1087 ret = pSetupDiCreateDeviceInterfaceA(set, &devInfo, &guid, NULL, 0, &interfaceData);
1088 ok(ret, "SetupDiCreateDeviceInterfaceA failed: %08x\n", GetLastError());
1089 SetLastError(0xdeadbeef);
1090 ret = pSetupDiRegisterDeviceInfo(set, &devInfo, 0, NULL, NULL, NULL);
1091 ok(ret, "SetupDiRegisterDeviceInfo failed: %08x\n", GetLastError());
1093 pSetupDiDestroyDeviceInfoList(set);
1095 SetLastError(0xdeadbeef);
1096 set = pSetupDiGetClassDevsA(&guid, NULL, 0, DIGCF_DEVICEINTERFACE);
1097 ok(set != INVALID_HANDLE_VALUE, "SetupDiGetClassDevsA failed: %08x\n",
1100 SetLastError(0xdeadbeef);
1101 ret = pSetupDiEnumDeviceInterfaces(set, NULL, &guid, 0, &interfaceData);
1102 ok(ret, "SetupDiEnumDeviceInterfaces failed: %08x\n", GetLastError());
1103 SetLastError(0xdeadbeef);
1104 ret = pSetupDiGetDeviceInterfaceDetailA(set, &interfaceData, NULL, 0, &dwSize, NULL);
1105 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
1106 "Expected ERROR_INSUFFICIENT_BUFFER, got %08x\n", GetLastError());
1107 if (!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER)
1109 static const char path[] =
1110 "\\\\?\\root#legacy_bogus#0000#{6a55b5a4-3f65-11db-b704-0011955c2bdb}";
1111 static const char path_wow64[] =
1112 "\\\\?\\root#legacy_bogus#0001#{6a55b5a4-3f65-11db-b704-0011955c2bdb}";
1113 static const char path_w2k[] =
1114 "\\\\?\\root#legacy_bogus#0000#{6a55b5a4-3f65-11db-b704-0011955c2bdb}\\";
1115 PSP_DEVICE_INTERFACE_DETAIL_DATA_A detail = NULL;
1117 detail = HeapAlloc(GetProcessHeap(), 0, dwSize);
1120 detail->cbSize = sizeof(*detail);
1121 SetLastError(0xdeadbeef);
1122 ret = pSetupDiGetDeviceInterfaceDetailA(set, &interfaceData,
1123 detail, dwSize, &dwSize, NULL);
1124 ok(ret, "SetupDiGetDeviceInterfaceDetailA failed: %08x\n", GetLastError());
1125 /* FIXME: This one only worked because old data wasn't removed properly. As soon
1126 * as all the tests are cleaned up correctly this has to be (or should be) fixed
1129 ok(!lstrcmpiA(path_wow64, detail->DevicePath),
1130 "Unexpected path %s\n", detail->DevicePath);
1132 todo_wine ok(!lstrcmpiA(path, detail->DevicePath) ||
1133 !lstrcmpiA(path_w2k, detail->DevicePath),
1134 "Unexpected path %s\n", detail->DevicePath);
1135 HeapFree(GetProcessHeap(), 0, detail);
1139 pSetupDiDestroyDeviceInfoList(set);
1142 ret = remove_device();
1144 todo_wine ok(ret, "Expected the device to be removed: %08x\n", GetLastError());
1146 /* FIXME: Only do the RegDeleteKey, once Wine is fixed */
1149 /* Wine doesn't delete the information currently */
1150 trace("We are most likely on Wine\n");
1151 devinst_RegDeleteTreeW(HKEY_LOCAL_MACHINE, bogus);
1152 devinst_RegDeleteTreeW(HKEY_LOCAL_MACHINE, devclass);
1156 clean_devclass_key();
1160 static void testDeviceRegistryPropertyA(void)
1163 SP_DEVINFO_DATA devInfo = { sizeof(SP_DEVINFO_DATA), { 0 } };
1164 CHAR devName[] = "LEGACY_BOGUS";
1165 CHAR friendlyName[] = "Bogus";
1173 static const CHAR bogus[] =
1174 "System\\CurrentControlSet\\Enum\\Root\\LEGACY_BOGUS";
1176 SetLastError(0xdeadbeef);
1177 set = pSetupDiGetClassDevsA(&guid, NULL, 0, DIGCF_DEVICEINTERFACE);
1178 ok(set != INVALID_HANDLE_VALUE, "SetupDiGetClassDevsA failed: %08x\n",
1180 SetLastError(0xdeadbeef);
1181 ret = pSetupDiCreateDeviceInfoA(set, devName, &guid, NULL, NULL,
1182 DICD_GENERATE_ID, &devInfo);
1183 ok(ret, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
1184 SetLastError(0xdeadbeef);
1185 ret = pSetupDiSetDeviceRegistryPropertyA(NULL, NULL, -1, NULL, 0);
1186 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
1187 "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
1188 SetLastError(0xdeadbeef);
1189 ret = pSetupDiSetDeviceRegistryPropertyA(set, NULL, -1, NULL, 0);
1190 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
1191 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
1192 SetLastError(0xdeadbeef);
1193 ret = pSetupDiSetDeviceRegistryPropertyA(set, &devInfo, -1, NULL, 0);
1195 ok(!ret && GetLastError() == ERROR_INVALID_REG_PROPERTY,
1196 "Expected ERROR_INVALID_REG_PROPERTY, got %08x\n", GetLastError());
1197 /* GetLastError() returns nonsense in win2k3 */
1198 ret = pSetupDiSetDeviceRegistryPropertyA(set, &devInfo, SPDRP_FRIENDLYNAME,
1201 ok(!ret, "Expected failure, got %d\n", ret);
1202 SetLastError(0xdeadbeef);
1203 ret = pSetupDiSetDeviceRegistryPropertyA(set, &devInfo, SPDRP_FRIENDLYNAME,
1204 (PBYTE)friendlyName, buflen);
1205 ok(ret, "SetupDiSetDeviceRegistryPropertyA failed: %08x\n", GetLastError());
1206 SetLastError(0xdeadbeef);
1207 ret = pSetupDiGetDeviceRegistryPropertyA(NULL, NULL, -1, NULL, NULL, 0, NULL);
1208 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
1209 "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
1210 SetLastError(0xdeadbeef);
1211 ret = pSetupDiGetDeviceRegistryPropertyA(set, NULL, -1, NULL, NULL, 0, NULL);
1212 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
1213 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
1214 SetLastError(0xdeadbeef);
1215 ret = pSetupDiGetDeviceRegistryPropertyA(set, &devInfo, -1, NULL, NULL, 0, NULL);
1217 ok(!ret && GetLastError() == ERROR_INVALID_REG_PROPERTY,
1218 "Expected ERROR_INVALID_REG_PROPERTY, got %08x\n", GetLastError());
1219 /* GetLastError() returns nonsense in win2k3 */
1220 ret = pSetupDiGetDeviceRegistryPropertyA(set, &devInfo, SPDRP_FRIENDLYNAME,
1221 NULL, NULL, buflen, NULL);
1222 ok(!ret, "Expected failure, got %d\n", ret);
1223 SetLastError(0xdeadbeef);
1224 ret = pSetupDiGetDeviceRegistryPropertyA(set, &devInfo, SPDRP_FRIENDLYNAME,
1225 NULL, NULL, 0, &size);
1226 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
1227 "Expected ERROR_INSUFFICIENT_BUFFER, got %08x\n", GetLastError());
1228 ok(buflen == size, "Unexpected size: %d\n", size);
1229 SetLastError(0xdeadbeef);
1230 ret = pSetupDiGetDeviceRegistryPropertyA(set, &devInfo, SPDRP_FRIENDLYNAME,
1231 NULL, (PBYTE)buf, buflen, NULL);
1232 ok(ret, "SetupDiGetDeviceRegistryPropertyA failed: %08x\n", GetLastError());
1233 ok(!lstrcmpiA(friendlyName, buf), "Unexpected property\n");
1234 SetLastError(0xdeadbeef);
1235 ret = pSetupDiGetDeviceRegistryPropertyA(set, &devInfo, SPDRP_FRIENDLYNAME,
1236 ®Type, (PBYTE)buf, buflen, NULL);
1237 ok(ret, "SetupDiGetDeviceRegistryPropertyA failed: %08x\n", GetLastError());
1238 ok(!lstrcmpiA(friendlyName, buf), "Unexpected value of property\n");
1239 ok(regType == REG_SZ, "Unexpected type of property: %d\n", regType);
1240 SetLastError(0xdeadbeef);
1241 ret = pSetupDiSetDeviceRegistryPropertyA(set, &devInfo, SPDRP_FRIENDLYNAME,
1243 ok(ret, "SetupDiSetDeviceRegistryPropertyA failed: %08x\n", GetLastError());
1244 SetLastError(0xdeadbeef);
1245 ret = pSetupDiGetDeviceRegistryPropertyA(set, &devInfo, SPDRP_FRIENDLYNAME,
1246 NULL, (PBYTE)buf, buflen, &size);
1248 ok(!ret && GetLastError() == ERROR_INVALID_DATA,
1249 "Expected ERROR_INVALID_DATA, got %08x\n", GetLastError());
1250 pSetupDiDestroyDeviceInfoList(set);
1252 res = RegOpenKeyA(HKEY_LOCAL_MACHINE, bogus, &key);
1254 todo_wine ok(res == ERROR_FILE_NOT_FOUND, "Expected key to not exist\n");
1255 /* FIXME: Remove when Wine is fixed */
1256 if (res == ERROR_SUCCESS)
1258 /* Wine doesn't delete the information currently */
1259 trace("We are most likely on Wine\n");
1260 RegDeleteKeyA(HKEY_LOCAL_MACHINE, bogus);
1264 static void testDeviceRegistryPropertyW(void)
1267 SP_DEVINFO_DATA devInfo = { sizeof(SP_DEVINFO_DATA), { 0 } };
1268 WCHAR devName[] = {'L','E','G','A','C','Y','_','B','O','G','U','S',0};
1269 WCHAR friendlyName[] = {'B','o','g','u','s',0};
1271 DWORD buflen = 6 * sizeof(WCHAR);
1277 static const WCHAR bogus[] = {'S','y','s','t','e','m','\\',
1278 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
1279 'E','n','u','m','\\','R','o','o','t','\\',
1280 'L','E','G','A','C','Y','_','B','O','G','U','S',0};
1282 SetLastError(0xdeadbeef);
1283 set = pSetupDiGetClassDevsW(&guid, NULL, 0, DIGCF_DEVICEINTERFACE);
1284 ok(set != INVALID_HANDLE_VALUE, "SetupDiGetClassDevsW failed: %08x\n",
1286 SetLastError(0xdeadbeef);
1287 ret = pSetupDiCreateDeviceInfoW(set, devName, &guid, NULL, NULL,
1288 DICD_GENERATE_ID, &devInfo);
1289 ok(ret, "SetupDiCreateDeviceInfoW failed: %08x\n", GetLastError());
1290 SetLastError(0xdeadbeef);
1291 ret = pSetupDiSetDeviceRegistryPropertyW(NULL, NULL, -1, NULL, 0);
1292 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
1293 "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
1294 SetLastError(0xdeadbeef);
1295 ret = pSetupDiSetDeviceRegistryPropertyW(set, NULL, -1, NULL, 0);
1296 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
1297 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
1298 SetLastError(0xdeadbeef);
1299 ret = pSetupDiSetDeviceRegistryPropertyW(set, &devInfo, -1, NULL, 0);
1301 ok(!ret && GetLastError() == ERROR_INVALID_REG_PROPERTY,
1302 "Expected ERROR_INVALID_REG_PROPERTY, got %08x\n", GetLastError());
1303 /* GetLastError() returns nonsense in win2k3 */
1304 ret = pSetupDiSetDeviceRegistryPropertyW(set, &devInfo, SPDRP_FRIENDLYNAME,
1307 ok(!ret, "Expected failure, got %d\n", ret);
1308 SetLastError(0xdeadbeef);
1309 ret = pSetupDiSetDeviceRegistryPropertyW(set, &devInfo, SPDRP_FRIENDLYNAME,
1310 (PBYTE)friendlyName, buflen);
1311 ok(ret, "SetupDiSetDeviceRegistryPropertyW failed: %08x\n", GetLastError());
1312 SetLastError(0xdeadbeef);
1313 ret = pSetupDiGetDeviceRegistryPropertyW(NULL, NULL, -1, NULL, NULL, 0, NULL);
1314 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
1315 "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
1316 SetLastError(0xdeadbeef);
1317 ret = pSetupDiGetDeviceRegistryPropertyW(set, NULL, -1, NULL, NULL, 0, NULL);
1318 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
1319 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
1320 SetLastError(0xdeadbeef);
1321 ret = pSetupDiGetDeviceRegistryPropertyW(set, &devInfo, -1, NULL, NULL, 0, NULL);
1323 ok(!ret && GetLastError() == ERROR_INVALID_REG_PROPERTY,
1324 "Expected ERROR_INVALID_REG_PROPERTY, got %08x\n", GetLastError());
1325 /* GetLastError() returns nonsense in win2k3 */
1326 ret = pSetupDiGetDeviceRegistryPropertyW(set, &devInfo, SPDRP_FRIENDLYNAME,
1327 NULL, NULL, buflen, NULL);
1328 ok(!ret, "Expected failure, got %d\n", ret);
1329 SetLastError(0xdeadbeef);
1330 ret = pSetupDiGetDeviceRegistryPropertyW(set, &devInfo, SPDRP_FRIENDLYNAME,
1331 NULL, NULL, 0, &size);
1332 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
1333 "Expected ERROR_INSUFFICIENT_BUFFER, got %08x\n", GetLastError());
1334 ok(buflen == size, "Unexpected size: %d\n", size);
1335 SetLastError(0xdeadbeef);
1336 ret = pSetupDiGetDeviceRegistryPropertyW(set, &devInfo, SPDRP_FRIENDLYNAME,
1337 NULL, (PBYTE)buf, buflen, NULL);
1338 ok(ret, "SetupDiGetDeviceRegistryPropertyW failed: %08x\n", GetLastError());
1339 ok(!lstrcmpiW(friendlyName, buf), "Unexpected property\n");
1340 SetLastError(0xdeadbeef);
1341 ret = pSetupDiGetDeviceRegistryPropertyW(set, &devInfo, SPDRP_FRIENDLYNAME,
1342 ®Type, (PBYTE)buf, buflen, NULL);
1343 ok(ret, "SetupDiGetDeviceRegistryPropertyW failed: %08x\n", GetLastError());
1344 ok(!lstrcmpiW(friendlyName, buf), "Unexpected value of property\n");
1345 ok(regType == REG_SZ, "Unexpected type of property: %d\n", regType);
1346 SetLastError(0xdeadbeef);
1347 ret = pSetupDiSetDeviceRegistryPropertyW(set, &devInfo, SPDRP_FRIENDLYNAME,
1349 ok(ret, "SetupDiSetDeviceRegistryPropertyW failed: %08x\n", GetLastError());
1350 SetLastError(0xdeadbeef);
1351 ret = pSetupDiGetDeviceRegistryPropertyW(set, &devInfo, SPDRP_FRIENDLYNAME,
1352 NULL, (PBYTE)buf, buflen, &size);
1354 ok(!ret && GetLastError() == ERROR_INVALID_DATA,
1355 "Expected ERROR_INVALID_DATA, got %08x\n", GetLastError());
1356 pSetupDiDestroyDeviceInfoList(set);
1358 res = RegOpenKeyW(HKEY_LOCAL_MACHINE, bogus, &key);
1360 todo_wine ok(res == ERROR_FILE_NOT_FOUND, "Expected key to not exist\n");
1361 /* FIXME: Remove when Wine is fixed */
1362 if (res == ERROR_SUCCESS)
1364 /* Wine doesn't delete the information currently */
1365 trace("We are most likely on Wine\n");
1366 RegDeleteKeyW(HKEY_LOCAL_MACHINE, bogus);
1370 static void testSetupDiGetINFClassA(void)
1372 static const char inffile[] = "winetest.inf";
1373 static const char content[] = "[Version]\r\n\r\n";
1376 char filename[MAX_PATH];
1382 if(!pSetupDiGetINFClassA)
1384 win_skip("SetupDiGetINFClassA not present\n");
1388 count = GetTempPathA(MAX_PATH, filename);
1391 win_skip("GetTempPathA failed\n");
1395 strcat(filename, inffile);
1396 DeleteFileA(filename);
1398 /* not existing file */
1399 SetLastError(0xdeadbeef);
1400 retval = SetupDiGetINFClassA(filename, &guid, cn, MAX_PATH, &count);
1401 ok(!retval, "expected SetupDiGetINFClassA to fail!\n");
1402 if (ERROR_CALL_NOT_IMPLEMENTED == GetLastError())
1404 skip("SetupDiGetINFClassA is not implemented\n");
1407 ok(ERROR_FILE_NOT_FOUND == GetLastError(),
1408 "expected error ERROR_FILE_NOT_FOUND, got %u\n", GetLastError());
1410 /* missing file wins against other invalid parameter */
1411 SetLastError(0xdeadbeef);
1412 retval = SetupDiGetINFClassA(filename, NULL, cn, MAX_PATH, &count);
1413 ok(!retval, "expected SetupDiGetINFClassA to fail!\n");
1414 ok(ERROR_FILE_NOT_FOUND == GetLastError(),
1415 "expected error ERROR_FILE_NOT_FOUND, got %u\n", GetLastError());
1417 SetLastError(0xdeadbeef);
1418 retval = SetupDiGetINFClassA(filename, &guid, NULL, MAX_PATH, &count);
1419 ok(!retval, "expected SetupDiGetINFClassA to fail!\n");
1420 ok(ERROR_FILE_NOT_FOUND == GetLastError(),
1421 "expected error ERROR_FILE_NOT_FOUND, got %u\n", GetLastError());
1423 SetLastError(0xdeadbeef);
1424 retval = SetupDiGetINFClassA(filename, &guid, cn, 0, &count);
1425 ok(!retval, "expected SetupDiGetINFClassA to fail!\n");
1426 ok(ERROR_FILE_NOT_FOUND == GetLastError(),
1427 "expected error ERROR_FILE_NOT_FOUND, got %u\n", GetLastError());
1429 SetLastError(0xdeadbeef);
1430 retval = SetupDiGetINFClassA(filename, &guid, cn, MAX_PATH, NULL);
1431 ok(!retval, "expected SetupDiGetINFClassA to fail!\n");
1432 ok(ERROR_FILE_NOT_FOUND == GetLastError(),
1433 "expected error ERROR_FILE_NOT_FOUND, got %u\n", GetLastError());
1435 /* test file content */
1436 h = CreateFileA(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
1437 FILE_ATTRIBUTE_NORMAL, NULL);
1438 if(h == INVALID_HANDLE_VALUE)
1440 win_skip("failed to create file %s (error %u)\n", filename, GetLastError());
1445 retval = SetupDiGetINFClassA(filename, &guid, cn, MAX_PATH, &count);
1446 ok(!retval, "expected SetupDiGetINFClassA to fail!\n");
1448 h = CreateFileA(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
1449 FILE_ATTRIBUTE_NORMAL, NULL);
1450 if(h == INVALID_HANDLE_VALUE)
1452 win_skip("failed to create file %s (error %u)\n", filename, GetLastError());
1455 WriteFile( h, content, sizeof(content), &count, NULL);
1458 retval = SetupDiGetINFClassA(filename, &guid, cn, MAX_PATH, &count);
1459 ok(!retval, "expected SetupDiGetINFClassA to fail!\n");
1461 WritePrivateProfileStringA("Version", "Signature", "\"$CHICAGO$\"", filename);
1463 retval = SetupDiGetINFClassA(filename, &guid, cn, MAX_PATH, &count);
1464 ok(!retval, "expected SetupDiGetINFClassA to fail!\n");
1466 WritePrivateProfileStringA("Version", "Class", "WINE", filename);
1469 retval = SetupDiGetINFClassA(filename, &guid, cn, MAX_PATH, &count);
1470 ok(retval, "expected SetupDiGetINFClassA to succeed! error %u\n", GetLastError());
1471 ok(count == 5, "expected count==5, got %u\n", count);
1474 retval = SetupDiGetINFClassA(filename, &guid, cn, 5, &count);
1475 ok(retval, "expected SetupDiGetINFClassA to succeed! error %u\n", GetLastError());
1476 ok(count == 5, "expected count==5, got %u\n", count);
1479 SetLastError(0xdeadbeef);
1480 retval = SetupDiGetINFClassA(filename, &guid, cn, 4, &count);
1481 ok(!retval, "expected SetupDiGetINFClassA to fail!\n");
1482 ok(ERROR_INSUFFICIENT_BUFFER == GetLastError(),
1483 "expected error ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
1484 ok(count == 5, "expected count==5, got %u\n", count);
1486 /* invalid parameter */
1487 SetLastError(0xdeadbeef);
1488 retval = SetupDiGetINFClassA(NULL, &guid, cn, MAX_PATH, &count);
1489 ok(!retval, "expected SetupDiGetINFClassA to fail!\n");
1490 ok(ERROR_INVALID_PARAMETER == GetLastError(),
1491 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1493 SetLastError(0xdeadbeef);
1494 retval = SetupDiGetINFClassA(filename, NULL, cn, MAX_PATH, &count);
1495 ok(!retval, "expected SetupDiGetINFClassA to fail!\n");
1496 ok(ERROR_INVALID_PARAMETER == GetLastError(),
1497 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1499 SetLastError(0xdeadbeef);
1500 retval = SetupDiGetINFClassA(filename, &guid, NULL, MAX_PATH, &count);
1501 ok(!retval, "expected SetupDiGetINFClassA to fail!\n");
1502 ok(ERROR_INVALID_PARAMETER == GetLastError(),
1503 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1505 SetLastError(0xdeadbeef);
1506 retval = SetupDiGetINFClassA(filename, &guid, cn, 0, &count);
1507 ok(!retval, "expected SetupDiGetINFClassA to fail!\n");
1508 ok(ERROR_INSUFFICIENT_BUFFER == GetLastError() ||
1509 ERROR_INVALID_PARAMETER == GetLastError(),
1510 "expected error ERROR_INSUFFICIENT_BUFFER or ERROR_INVALID_PARAMETER, "
1511 "got %u\n", GetLastError());
1513 DeleteFileA(filename);
1515 WritePrivateProfileStringA("Version", "Signature", "\"$CHICAGO$\"", filename);
1516 WritePrivateProfileStringA("Version", "ClassGUID", "WINE", filename);
1518 SetLastError(0xdeadbeef);
1519 retval = SetupDiGetINFClassA(filename, &guid, cn, MAX_PATH, &count);
1520 ok(!retval, "expected SetupDiGetINFClassA to fail!\n");
1521 ok(RPC_S_INVALID_STRING_UUID == GetLastError() ||
1522 ERROR_INVALID_PARAMETER == GetLastError(),
1523 "expected error RPC_S_INVALID_STRING_UUID or ERROR_INVALID_PARAMETER, "
1524 "got %u\n", GetLastError());
1526 /* network adapter guid */
1527 WritePrivateProfileStringA("Version", "ClassGUID",
1528 "{4d36e972-e325-11ce-bfc1-08002be10318}", filename);
1530 /* this test succeeds only if the guid is known to the system */
1532 retval = SetupDiGetINFClassA(filename, &guid, cn, MAX_PATH, &count);
1533 ok(retval, "expected SetupDiGetINFClassA to succeed! error %u\n", GetLastError());
1535 ok(count == 4, "expected count==4, got %u(%s)\n", count, cn);
1537 DeleteFileA(filename);
1542 init_function_pointers();
1544 if (pIsWow64Process)
1545 pIsWow64Process(GetCurrentProcess(), &is_wow64);
1547 if (pSetupDiCreateDeviceInfoListExW)
1548 test_SetupDiCreateDeviceInfoListEx();
1550 win_skip("SetupDiCreateDeviceInfoListExW is not available\n");
1552 if (pSetupDiOpenClassRegKeyExA)
1553 test_SetupDiOpenClassRegKeyExA();
1555 win_skip("SetupDiOpenClassRegKeyExA is not available\n");
1558 testCreateDeviceInfo();
1559 testGetDeviceInstanceId();
1560 testRegisterDeviceInfo();
1561 testCreateDeviceInterface();
1562 testGetDeviceInterfaceDetail();
1564 testRegisterAndGetDetail();
1565 testDeviceRegistryPropertyA();
1566 testDeviceRegistryPropertyW();
1567 testSetupDiGetINFClassA();