4 * Copyright 2006 Christian Gmeiner
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
32 #include "wine/test.h"
34 /* function pointers */
35 static HMODULE hSetupAPI;
36 static HDEVINFO (WINAPI *pSetupDiCreateDeviceInfoList)(GUID*,HWND);
37 static HDEVINFO (WINAPI *pSetupDiCreateDeviceInfoListExW)(GUID*,HWND,PCWSTR,PVOID);
38 static BOOL (WINAPI *pSetupDiCreateDeviceInterfaceA)(HDEVINFO, PSP_DEVINFO_DATA, const GUID *, PCSTR, DWORD, PSP_DEVICE_INTERFACE_DATA);
39 static BOOL (WINAPI *pSetupDiCallClassInstaller)(DI_FUNCTION, HDEVINFO, PSP_DEVINFO_DATA);
40 static BOOL (WINAPI *pSetupDiDestroyDeviceInfoList)(HDEVINFO);
41 static BOOL (WINAPI *pSetupDiEnumDeviceInfo)(HDEVINFO, DWORD, PSP_DEVINFO_DATA);
42 static BOOL (WINAPI *pSetupDiEnumDeviceInterfaces)(HDEVINFO, PSP_DEVINFO_DATA, const GUID *, DWORD, PSP_DEVICE_INTERFACE_DATA);
43 static BOOL (WINAPI *pSetupDiGetINFClassA)(PCSTR, LPGUID, PSTR, DWORD, PDWORD);
44 static BOOL (WINAPI *pSetupDiInstallClassA)(HWND, PCSTR, DWORD, HSPFILEQ);
45 static HKEY (WINAPI *pSetupDiOpenClassRegKeyExA)(GUID*,REGSAM,DWORD,PCSTR,PVOID);
46 static HKEY (WINAPI *pSetupDiOpenDevRegKey)(HDEVINFO, PSP_DEVINFO_DATA, DWORD, DWORD, DWORD, REGSAM);
47 static HKEY (WINAPI *pSetupDiCreateDevRegKeyW)(HDEVINFO, PSP_DEVINFO_DATA, DWORD, DWORD, DWORD, HINF, PCWSTR);
48 static BOOL (WINAPI *pSetupDiCreateDeviceInfoA)(HDEVINFO, PCSTR, GUID *, PCSTR, HWND, DWORD, PSP_DEVINFO_DATA);
49 static BOOL (WINAPI *pSetupDiCreateDeviceInfoW)(HDEVINFO, PCWSTR, GUID *, PCWSTR, HWND, DWORD, PSP_DEVINFO_DATA);
50 static BOOL (WINAPI *pSetupDiGetDeviceInstanceIdA)(HDEVINFO, PSP_DEVINFO_DATA, PSTR, DWORD, PDWORD);
51 static BOOL (WINAPI *pSetupDiGetDeviceInterfaceDetailA)(HDEVINFO, PSP_DEVICE_INTERFACE_DATA, PSP_DEVICE_INTERFACE_DETAIL_DATA_A, DWORD, PDWORD, PSP_DEVINFO_DATA);
52 static BOOL (WINAPI *pSetupDiGetDeviceInterfaceDetailW)(HDEVINFO, PSP_DEVICE_INTERFACE_DATA, PSP_DEVICE_INTERFACE_DETAIL_DATA_W, DWORD, PDWORD, PSP_DEVINFO_DATA);
53 static BOOL (WINAPI *pSetupDiRegisterDeviceInfo)(HDEVINFO, PSP_DEVINFO_DATA, DWORD, PSP_DETSIG_CMPPROC, PVOID, PSP_DEVINFO_DATA);
54 static HDEVINFO (WINAPI *pSetupDiGetClassDevsA)(CONST GUID *, LPCSTR, HWND, DWORD);
55 static HDEVINFO (WINAPI *pSetupDiGetClassDevsW)(CONST GUID *, LPCWSTR, HWND, DWORD);
56 static BOOL (WINAPI *pSetupDiSetDeviceRegistryPropertyA)(HDEVINFO, PSP_DEVINFO_DATA, DWORD, const BYTE *, DWORD);
57 static BOOL (WINAPI *pSetupDiSetDeviceRegistryPropertyW)(HDEVINFO, PSP_DEVINFO_DATA, DWORD, const BYTE *, DWORD);
58 static BOOL (WINAPI *pSetupDiGetDeviceRegistryPropertyA)(HDEVINFO, PSP_DEVINFO_DATA, DWORD, PDWORD, PBYTE, DWORD, PDWORD);
59 static BOOL (WINAPI *pSetupDiGetDeviceRegistryPropertyW)(HDEVINFO, PSP_DEVINFO_DATA, DWORD, PDWORD, PBYTE, DWORD, PDWORD);
61 /* This is a unique guid for testing purposes */
62 static GUID guid = {0x6a55b5a4, 0x3f65, 0x11db, {0xb7,0x04,0x00,0x11,0x95,0x5c,0x2b,0xdb}};
64 static void init_function_pointers(void)
66 hSetupAPI = GetModuleHandleA("setupapi.dll");
68 pSetupDiCreateDeviceInfoA = (void *)GetProcAddress(hSetupAPI, "SetupDiCreateDeviceInfoA");
69 pSetupDiCreateDeviceInfoW = (void *)GetProcAddress(hSetupAPI, "SetupDiCreateDeviceInfoW");
70 pSetupDiCreateDeviceInfoList = (void *)GetProcAddress(hSetupAPI, "SetupDiCreateDeviceInfoList");
71 pSetupDiCreateDeviceInfoListExW = (void *)GetProcAddress(hSetupAPI, "SetupDiCreateDeviceInfoListExW");
72 pSetupDiCreateDeviceInterfaceA = (void *)GetProcAddress(hSetupAPI, "SetupDiCreateDeviceInterfaceA");
73 pSetupDiDestroyDeviceInfoList = (void *)GetProcAddress(hSetupAPI, "SetupDiDestroyDeviceInfoList");
74 pSetupDiCallClassInstaller = (void *)GetProcAddress(hSetupAPI, "SetupDiCallClassInstaller");
75 pSetupDiEnumDeviceInfo = (void *)GetProcAddress(hSetupAPI, "SetupDiEnumDeviceInfo");
76 pSetupDiEnumDeviceInterfaces = (void *)GetProcAddress(hSetupAPI, "SetupDiEnumDeviceInterfaces");
77 pSetupDiGetDeviceInstanceIdA = (void *)GetProcAddress(hSetupAPI, "SetupDiGetDeviceInstanceIdA");
78 pSetupDiGetDeviceInterfaceDetailA = (void *)GetProcAddress(hSetupAPI, "SetupDiGetDeviceInterfaceDetailA");
79 pSetupDiGetDeviceInterfaceDetailW = (void *)GetProcAddress(hSetupAPI, "SetupDiGetDeviceInterfaceDetailW");
80 pSetupDiInstallClassA = (void *)GetProcAddress(hSetupAPI, "SetupDiInstallClassA");
81 pSetupDiOpenClassRegKeyExA = (void *)GetProcAddress(hSetupAPI, "SetupDiOpenClassRegKeyExA");
82 pSetupDiOpenDevRegKey = (void *)GetProcAddress(hSetupAPI, "SetupDiOpenDevRegKey");
83 pSetupDiCreateDevRegKeyW = (void *)GetProcAddress(hSetupAPI, "SetupDiCreateDevRegKeyW");
84 pSetupDiRegisterDeviceInfo = (void *)GetProcAddress(hSetupAPI, "SetupDiRegisterDeviceInfo");
85 pSetupDiGetClassDevsA = (void *)GetProcAddress(hSetupAPI, "SetupDiGetClassDevsA");
86 pSetupDiGetClassDevsW = (void *)GetProcAddress(hSetupAPI, "SetupDiGetClassDevsW");
87 pSetupDiGetINFClassA = (void *)GetProcAddress(hSetupAPI, "SetupDiGetINFClassA");
88 pSetupDiSetDeviceRegistryPropertyA = (void *)GetProcAddress(hSetupAPI, "SetupDiSetDeviceRegistryPropertyA");
89 pSetupDiSetDeviceRegistryPropertyW = (void *)GetProcAddress(hSetupAPI, "SetupDiSetDeviceRegistryPropertyW");
90 pSetupDiGetDeviceRegistryPropertyA = (void *)GetProcAddress(hSetupAPI, "SetupDiGetDeviceRegistryPropertyA");
91 pSetupDiGetDeviceRegistryPropertyW = (void *)GetProcAddress(hSetupAPI, "SetupDiGetDeviceRegistryPropertyW");
94 static void change_reg_permissions(const WCHAR *regkey)
97 SID_IDENTIFIER_AUTHORITY ident = { SECURITY_WORLD_SID_AUTHORITY };
98 SECURITY_DESCRIPTOR sd;
102 RegOpenKeyExW(HKEY_LOCAL_MACHINE, regkey, 0, WRITE_DAC, &hkey);
104 /* Initialize the 'Everyone' sid */
105 AllocateAndInitializeSid(&ident, 1, SECURITY_WORLD_RID, 0, 0, 0, 0, 0, 0, 0, &EveryoneSid);
107 pacl = HeapAlloc(GetProcessHeap(), 0, 256);
108 InitializeAcl(pacl, 256, ACL_REVISION);
110 /* Add 'Full Control' for 'Everyone' */
111 AddAccessAllowedAce(pacl, ACL_REVISION, KEY_ALL_ACCESS, EveryoneSid);
113 InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION);
115 SetSecurityDescriptorDacl(&sd, TRUE, pacl, FALSE);
117 /* Set the new security on the registry key */
118 RegSetKeySecurity(hkey, DACL_SECURITY_INFORMATION, &sd);
122 HeapFree(GetProcessHeap(), 0, pacl);
124 FreeSid(EveryoneSid);
127 static BOOL remove_device(void)
130 SP_DEVINFO_DATA devInfo = { sizeof(devInfo), { 0 } };
133 SetLastError(0xdeadbeef);
134 set = pSetupDiGetClassDevsA(&guid, NULL, 0, 0);
135 ok(set != INVALID_HANDLE_VALUE, "SetupDiGetClassDevsA failed: %08x\n",
138 SetLastError(0xdeadbeef);
139 ok(pSetupDiEnumDeviceInfo(set, 0, &devInfo),
140 "SetupDiEnumDeviceInfo failed: %08x\n", GetLastError());
142 SetLastError(0xdeadbeef);
143 ret = pSetupDiCallClassInstaller(DIF_REMOVE, set, &devInfo);
145 ok(ret, "SetupDiCallClassInstaller(DIF_REMOVE...) failed: %08x\n", GetLastError());
147 SetLastError(0xdeadbeef);
148 ok(pSetupDiDestroyDeviceInfoList(set),
149 "SetupDiDestroyDeviceInfoList failed: %08x\n", GetLastError());
154 /* RegDeleteTreeW from dlls/advapi32/registry.c */
155 static LSTATUS devinst_RegDeleteTreeW(HKEY hKey, LPCWSTR lpszSubKey)
158 DWORD dwMaxSubkeyLen, dwMaxValueLen;
159 DWORD dwMaxLen, dwSize;
160 WCHAR szNameBuf[MAX_PATH], *lpszName = szNameBuf;
165 ret = RegOpenKeyExW(hKey, lpszSubKey, 0, KEY_READ, &hSubKey);
169 /* Get highest length for keys, values */
170 ret = RegQueryInfoKeyW(hSubKey, NULL, NULL, NULL, NULL,
171 &dwMaxSubkeyLen, NULL, NULL, &dwMaxValueLen, NULL, NULL, NULL);
172 if (ret) goto cleanup;
176 dwMaxLen = max(dwMaxSubkeyLen, dwMaxValueLen);
177 if (dwMaxLen > sizeof(szNameBuf)/sizeof(WCHAR))
179 /* Name too big: alloc a buffer for it */
180 if (!(lpszName = HeapAlloc( GetProcessHeap(), 0, dwMaxLen*sizeof(WCHAR))))
182 ret = ERROR_NOT_ENOUGH_MEMORY;
188 /* Recursively delete all the subkeys */
192 if (RegEnumKeyExW(hSubKey, 0, lpszName, &dwSize, NULL,
193 NULL, NULL, NULL)) break;
195 ret = devinst_RegDeleteTreeW(hSubKey, lpszName);
196 if (ret) goto cleanup;
200 ret = RegDeleteKeyW(hKey, lpszSubKey);
205 if (RegEnumValueW(hKey, 0, lpszName, &dwSize,
206 NULL, NULL, NULL, NULL)) break;
208 ret = RegDeleteValueW(hKey, lpszName);
209 if (ret) goto cleanup;
213 /* Free buffer if allocated */
214 if (lpszName != szNameBuf)
215 HeapFree( GetProcessHeap(), 0, lpszName);
217 RegCloseKey(hSubKey);
221 static void clean_devclass_key(void)
223 static const WCHAR devclass[] = {'S','y','s','t','e','m','\\',
224 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
225 'C','o','n','t','r','o','l','\\','D','e','v','i','c','e','C','l','a','s','s','e','s','\\',
226 '{','6','a','5','5','b','5','a','4','-','3','f','6','5','-',
227 '1','1','d','b','-','b','7','0','4','-',
228 '0','0','1','1','9','5','5','c','2','b','d','b','}',0};
232 /* Check if we have subkeys as Windows 2000 doesn't delete
233 * the keys under the DeviceClasses key after a SetupDiDestroyDeviceInfoList.
235 RegOpenKeyW(HKEY_LOCAL_MACHINE, devclass, &key);
236 RegQueryInfoKey(key, NULL, NULL, NULL, &subkeys, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
239 trace("We are most likely on Windows 2000\n");
240 devinst_RegDeleteTreeW(HKEY_LOCAL_MACHINE, devclass);
244 ok(!RegDeleteKeyW(HKEY_LOCAL_MACHINE, devclass),
245 "Couldn't delete deviceclass key\n");
249 static void test_SetupDiCreateDeviceInfoListEx(void)
254 static CHAR notnull[] = "NotNull";
255 static const WCHAR machine[] = { 'd','u','m','m','y',0 };
257 SetLastError(0xdeadbeef);
258 /* create empty DeviceInfoList, but set Reserved to a value, which is not NULL */
259 devlist = pSetupDiCreateDeviceInfoListExW(NULL, NULL, NULL, notnull);
261 error = GetLastError();
262 if (error == ERROR_CALL_NOT_IMPLEMENTED)
264 win_skip("SetupDiCreateDeviceInfoListExW is not implemented\n");
267 ok(devlist == INVALID_HANDLE_VALUE, "SetupDiCreateDeviceInfoListExW failed : %p %d (expected %p)\n", devlist, error, INVALID_HANDLE_VALUE);
268 ok(error == ERROR_INVALID_PARAMETER, "GetLastError returned wrong value : %d, (expected %d)\n", error, ERROR_INVALID_PARAMETER);
270 SetLastError(0xdeadbeef);
271 /* create empty DeviceInfoList, but set MachineName to something */
272 devlist = pSetupDiCreateDeviceInfoListExW(NULL, NULL, machine, NULL);
274 error = GetLastError();
275 ok(devlist == INVALID_HANDLE_VALUE, "SetupDiCreateDeviceInfoListExW failed : %p %d (expected %p)\n", devlist, error, INVALID_HANDLE_VALUE);
276 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);
278 /* create empty DeviceInfoList */
279 devlist = pSetupDiCreateDeviceInfoListExW(NULL, NULL, NULL, NULL);
280 ok(devlist && devlist != INVALID_HANDLE_VALUE, "SetupDiCreateDeviceInfoListExW failed : %p %d (expected != %p)\n", devlist, error, INVALID_HANDLE_VALUE);
282 /* destroy DeviceInfoList */
283 ret = pSetupDiDestroyDeviceInfoList(devlist);
284 ok(ret, "SetupDiDestroyDeviceInfoList failed : %d\n", error);
287 static void test_SetupDiOpenClassRegKeyExA(void)
289 static const CHAR guidString[] = "{6a55b5a4-3f65-11db-b704-0011955c2bdb}";
292 /* Check return value for nonexistent key */
293 hkey = pSetupDiOpenClassRegKeyExA(&guid, KEY_ALL_ACCESS,
294 DIOCR_INSTALLER, NULL, NULL);
295 ok(hkey == INVALID_HANDLE_VALUE,
296 "returned %p (expected INVALID_HANDLE_VALUE)\n", hkey);
298 /* Test it for a key that exists */
299 hkey = SetupDiOpenClassRegKey(NULL, KEY_ALL_ACCESS);
300 if (hkey != INVALID_HANDLE_VALUE)
303 if (RegCreateKeyA(hkey, guidString, &classKey) == ERROR_SUCCESS)
305 RegCloseKey(classKey);
306 SetLastError(0xdeadbeef);
307 classKey = pSetupDiOpenClassRegKeyExA(&guid, KEY_ALL_ACCESS,
308 DIOCR_INSTALLER, NULL, NULL);
309 ok(classKey != INVALID_HANDLE_VALUE,
310 "opening class registry key failed with error %d\n",
312 if (classKey != INVALID_HANDLE_VALUE)
313 RegCloseKey(classKey);
314 RegDeleteKeyA(hkey, guidString);
317 trace("failed to create registry key for test\n");
322 trace("failed to open classes key\n");
325 static void create_inf_file(LPCSTR filename)
327 DWORD dwNumberOfBytesWritten;
328 HANDLE hf = CreateFile(filename, GENERIC_WRITE, 0, NULL,
329 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
331 static const char data[] =
333 "Signature=\"$Chicago$\"\n"
335 "ClassGUID={6a55b5a4-3f65-11db-b704-0011955c2bdb}\n"
337 "AddReg=BogusClass.NT.AddReg\n"
338 "[BogusClass.NT.AddReg]\n"
339 "HKR,,,,\"Wine test devices\"\n";
341 WriteFile(hf, data, sizeof(data) - 1, &dwNumberOfBytesWritten, NULL);
345 static void get_temp_filename(LPSTR path)
347 static char curr[MAX_PATH] = { 0 };
352 GetCurrentDirectoryA(MAX_PATH, curr);
353 GetTempFileNameA(curr, "set", 0, temp);
354 ptr = strrchr(temp, '\\');
356 lstrcpyA(path, ptr + 1);
359 static void testInstallClass(void)
361 static const WCHAR classKey[] = {'S','y','s','t','e','m','\\',
362 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
363 'C','o','n','t','r','o','l','\\','C','l','a','s','s','\\',
364 '{','6','a','5','5','b','5','a','4','-','3','f','6','5','-',
365 '1','1','d','b','-','b','7','0','4','-',
366 '0','0','1','1','9','5','5','c','2','b','d','b','}',0};
367 char tmpfile[MAX_PATH];
372 get_temp_filename(tmpfile + 2);
373 create_inf_file(tmpfile + 2);
375 ret = pSetupDiInstallClassA(NULL, NULL, 0, NULL);
376 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
377 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
378 ret = pSetupDiInstallClassA(NULL, NULL, DI_NOVCP, NULL);
379 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
380 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
381 ret = pSetupDiInstallClassA(NULL, tmpfile + 2, DI_NOVCP, NULL);
382 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
383 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
384 ret = pSetupDiInstallClassA(NULL, tmpfile + 2, 0, NULL);
385 ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND,
386 "Expected ERROR_FILE_NOT_FOUND, got %08x\n", GetLastError());
387 /* The next call will succeed. Information is put into the registry but the
388 * location(s) is/are depending on the Windows version.
390 ret = pSetupDiInstallClassA(NULL, tmpfile, 0, NULL);
391 ok(ret, "SetupDiInstallClassA failed: %08x\n", GetLastError());
393 ok(!RegDeleteKeyW(HKEY_LOCAL_MACHINE, classKey),
394 "Couldn't delete classkey\n");
399 static void testCreateDeviceInfo(void)
405 static const WCHAR bogus[] = {'S','y','s','t','e','m','\\',
406 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
407 'E','n','u','m','\\','R','o','o','t','\\',
408 'L','E','G','A','C','Y','_','B','O','G','U','S',0};
410 SetLastError(0xdeadbeef);
411 ret = pSetupDiCreateDeviceInfoA(NULL, NULL, NULL, NULL, NULL, 0, NULL);
412 ok(!ret, "Expected failure\n");
413 ok(GetLastError() == ERROR_INVALID_DEVINST_NAME ||
414 GetLastError() == ERROR_INVALID_PARAMETER /* NT4 */,
415 "Unexpected last error, got %08x\n", GetLastError());
417 SetLastError(0xdeadbeef);
418 ret = pSetupDiCreateDeviceInfoA(NULL, "Root\\LEGACY_BOGUS\\0000", NULL,
419 NULL, NULL, 0, NULL);
420 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
421 "Expected ERROR_INVALID_HANDLEHANDLE, got %08x\n", GetLastError());
422 set = pSetupDiCreateDeviceInfoList(&guid, NULL);
423 ok(set != NULL, "SetupDiCreateDeviceInfoList failed: %08x\n",
427 SP_DEVINFO_DATA devInfo = { 0 };
429 static GUID deadbeef =
430 {0xdeadbeef, 0xdead, 0xbeef, {0xde,0xad,0xbe,0xef,0xde,0xad,0xbe,0xef}};
433 static const WCHAR bogus0000[] = {'S','y','s','t','e','m','\\',
434 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
435 'E','n','u','m','\\','R','o','o','t','\\',
436 'L','E','G','A','C','Y','_','B','O','G','U','S','\\','0','0','0','0',0};
438 /* So we know we have a clean start */
439 res = RegOpenKeyW(HKEY_LOCAL_MACHINE, bogus0000, &key);
440 ok(res != ERROR_SUCCESS, "Expected key to not exist\n");
442 SetLastError(0xdeadbeef);
443 ret = pSetupDiCreateDeviceInfoA(set, "Root\\LEGACY_BOGUS\\0000", NULL,
444 NULL, NULL, 0, NULL);
445 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
446 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
447 /* Even though NT4 fails it still adds some stuff to the registry that
448 * can't be deleted via normal setupapi functions. As the registry is written
449 * by a different user (SYSTEM) we have to do some magic to get rid of the key
451 if (!RegOpenKeyW(HKEY_LOCAL_MACHINE, bogus0000, &key))
453 trace("NT4 created a bogus key on failure, will be removed now\n");
454 change_reg_permissions(bogus0000);
455 ok(!RegDeleteKeyW(HKEY_LOCAL_MACHINE, bogus0000),
456 "Could not delete LEGACY_BOGUS\\0000 key\n");
458 /* We can't add device information to the set with a different GUID */
459 SetLastError(0xdeadbeef);
460 ret = pSetupDiCreateDeviceInfoA(set, "Root\\LEGACY_BOGUS\\0000",
461 &deadbeef, NULL, NULL, 0, NULL);
462 ok(!ret && GetLastError() == ERROR_CLASS_MISMATCH,
463 "Expected ERROR_CLASS_MISMATCH, got %08x\n", GetLastError());
464 if (!RegOpenKeyW(HKEY_LOCAL_MACHINE, bogus0000, &key))
466 trace("NT4 created a bogus key on failure, will be removed now\n");
467 change_reg_permissions(bogus0000);
468 ok(!RegDeleteKeyW(HKEY_LOCAL_MACHINE, bogus0000),
469 "Could not delete LEGACY_BOGUS\\0000 key\n");
471 /* Finally, with all three required parameters, this succeeds: */
472 ret = pSetupDiCreateDeviceInfoA(set, "Root\\LEGACY_BOGUS\\0000", &guid,
473 NULL, NULL, 0, NULL);
474 ok(ret, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
475 /* This fails because the device ID already exists.. */
476 SetLastError(0xdeadbeef);
477 ret = pSetupDiCreateDeviceInfoA(set, "Root\\LEGACY_BOGUS\\0000", &guid,
478 NULL, NULL, 0, &devInfo);
479 ok(!ret && GetLastError() == ERROR_DEVINST_ALREADY_EXISTS,
480 "Expected ERROR_DEVINST_ALREADY_EXISTS, got %08x\n", GetLastError());
481 /* whereas this "fails" because cbSize is wrong.. */
482 SetLastError(0xdeadbeef);
483 ret = pSetupDiCreateDeviceInfoA(set, "LEGACY_BOGUS", &guid, NULL, NULL,
484 DICD_GENERATE_ID, &devInfo);
485 ok(!ret && GetLastError() == ERROR_INVALID_USER_BUFFER,
486 "Expected ERROR_INVALID_USER_BUFFER, got %08x\n", GetLastError());
487 /* and this finally succeeds. */
488 devInfo.cbSize = sizeof(devInfo);
489 ret = pSetupDiCreateDeviceInfoA(set, "LEGACY_BOGUS", &guid, NULL, NULL,
490 DICD_GENERATE_ID, &devInfo);
491 ok(ret, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
492 /* There were three devices added, however - the second failure just
493 * resulted in the SP_DEVINFO_DATA not getting copied.
495 SetLastError(0xdeadbeef);
497 while (pSetupDiEnumDeviceInfo(set, i, &devInfo))
499 ok(i == 3, "Expected 3 devices, got %d\n", i);
500 ok(GetLastError() == ERROR_NO_MORE_ITEMS,
501 "SetupDiEnumDeviceInfo failed: %08x\n", GetLastError());
502 pSetupDiDestroyDeviceInfoList(set);
505 /* The bogus registry key shouldn't be there after this test. The only
506 * reasons this key would still be present:
508 * - We are running on Wine which has to be fixed
509 * - We have leftovers from old tests
511 res = RegOpenKeyW(HKEY_LOCAL_MACHINE, bogus, &key);
513 ok(res == ERROR_FILE_NOT_FOUND, "Expected key to not exist\n");
514 if (res == ERROR_SUCCESS)
518 /* Check if we have subkeys */
519 RegQueryInfoKey(key, NULL, NULL, NULL, &subkeys, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
524 /* Leftovers from old tests */
525 trace("Going to remove %d devices\n", subkeys);
526 for (i = 0; i < subkeys; i++)
530 ret = remove_device();
531 ok(ret, "Expected a device to be removed\n");
536 /* Wine doesn't delete the bogus key itself currently */
537 trace("We are most likely on Wine\n");
538 RegDeleteKeyW(HKEY_LOCAL_MACHINE, bogus);
543 static void testGetDeviceInstanceId(void)
547 SP_DEVINFO_DATA devInfo = { 0 };
549 SetLastError(0xdeadbeef);
550 ret = pSetupDiGetDeviceInstanceIdA(NULL, NULL, NULL, 0, NULL);
551 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
552 "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
553 SetLastError(0xdeadbeef);
554 ret = pSetupDiGetDeviceInstanceIdA(NULL, &devInfo, NULL, 0, NULL);
555 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
556 "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
557 set = pSetupDiCreateDeviceInfoList(&guid, NULL);
558 ok(set != NULL, "SetupDiCreateDeviceInfoList failed: %08x\n",
562 char instanceID[MAX_PATH];
565 SetLastError(0xdeadbeef);
566 ret = pSetupDiGetDeviceInstanceIdA(set, NULL, NULL, 0, NULL);
567 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
568 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
569 SetLastError(0xdeadbeef);
570 ret = pSetupDiGetDeviceInstanceIdA(set, &devInfo, NULL, 0, NULL);
571 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
572 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
573 SetLastError(0xdeadbeef);
574 ret = pSetupDiGetDeviceInstanceIdA(set, &devInfo, NULL, 0, &size);
575 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
576 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
577 devInfo.cbSize = sizeof(devInfo);
578 SetLastError(0xdeadbeef);
579 ret = pSetupDiGetDeviceInstanceIdA(set, &devInfo, NULL, 0, &size);
580 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
581 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
582 ret = pSetupDiCreateDeviceInfoA(set, "Root\\LEGACY_BOGUS\\0000", &guid,
583 NULL, NULL, 0, &devInfo);
584 ok(ret, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
585 SetLastError(0xdeadbeef);
586 ret = pSetupDiGetDeviceInstanceIdA(set, &devInfo, NULL, 0, &size);
587 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
588 "Expected ERROR_INSUFFICIENT_BUFFER, got %08x\n", GetLastError());
589 ret = pSetupDiGetDeviceInstanceIdA(set, &devInfo, instanceID,
590 sizeof(instanceID), NULL);
591 ok(ret, "SetupDiGetDeviceInstanceIdA failed: %08x\n", GetLastError());
592 ok(!lstrcmpA(instanceID, "ROOT\\LEGACY_BOGUS\\0000"),
593 "Unexpected instance ID %s\n", instanceID);
594 ret = pSetupDiCreateDeviceInfoA(set, "LEGACY_BOGUS", &guid,
595 NULL, NULL, DICD_GENERATE_ID, &devInfo);
596 ok(ret, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
597 ret = pSetupDiGetDeviceInstanceIdA(set, &devInfo, instanceID,
598 sizeof(instanceID), NULL);
599 ok(ret, "SetupDiGetDeviceInstanceIdA failed: %08x\n", GetLastError());
600 /* NT4 returns 'Root' and W2K and above 'ROOT' */
601 ok(!lstrcmpiA(instanceID, "ROOT\\LEGACY_BOGUS\\0001"),
602 "Unexpected instance ID %s\n", instanceID);
603 pSetupDiDestroyDeviceInfoList(set);
607 static void testRegisterDeviceInfo(void)
612 SetLastError(0xdeadbeef);
613 ret = pSetupDiRegisterDeviceInfo(NULL, NULL, 0, NULL, NULL, NULL);
614 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
615 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
616 set = pSetupDiCreateDeviceInfoList(&guid, NULL);
617 ok(set != NULL, "SetupDiCreateDeviceInfoList failed: %d\n", GetLastError());
620 SP_DEVINFO_DATA devInfo = { 0 };
622 SetLastError(0xdeadbeef);
623 ret = pSetupDiRegisterDeviceInfo(set, NULL, 0, NULL, NULL, NULL);
624 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
625 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
626 SetLastError(0xdeadbeef);
627 ret = pSetupDiRegisterDeviceInfo(set, &devInfo, 0, NULL, NULL, NULL);
628 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
629 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
630 devInfo.cbSize = sizeof(devInfo);
631 SetLastError(0xdeadbeef);
632 ret = pSetupDiRegisterDeviceInfo(set, &devInfo, 0, NULL, NULL, NULL);
633 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
634 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
635 ret = pSetupDiCreateDeviceInfoA(set, "USB\\BOGUS\\0000", &guid,
636 NULL, NULL, 0, &devInfo);
637 ok(ret || GetLastError() == ERROR_DEVINST_ALREADY_EXISTS,
638 "SetupDiCreateDeviceInfoA failed: %d\n", GetLastError());
641 /* If it already existed, registering it again will fail */
642 ret = pSetupDiRegisterDeviceInfo(set, &devInfo, 0, NULL, NULL,
644 ok(ret, "SetupDiCreateDeviceInfoA failed: %d\n", GetLastError());
646 /* FIXME: On Win2K+ systems, this is now persisted to registry in
647 * HKLM\System\CCS\Enum\USB\Bogus\0000.
648 * FIXME: the key also becomes undeletable. How to get rid of it?
650 pSetupDiDestroyDeviceInfoList(set);
654 static void testCreateDeviceInterface(void)
659 static const WCHAR bogus[] = {'S','y','s','t','e','m','\\',
660 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
661 'E','n','u','m','\\','R','o','o','t','\\',
662 'L','E','G','A','C','Y','_','B','O','G','U','S',0};
663 static const WCHAR devclass[] = {'S','y','s','t','e','m','\\',
664 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
665 'C','o','n','t','r','o','l','\\','D','e','v','i','c','e','C','l','a','s','s','e','s','\\',
666 '{','6','a','5','5','b','5','a','4','-','3','f','6','5','-',
667 '1','1','d','b','-','b','7','0','4','-',
668 '0','0','1','1','9','5','5','c','2','b','d','b','}',0};
670 if (!pSetupDiCreateDeviceInterfaceA || !pSetupDiEnumDeviceInterfaces)
672 win_skip("SetupDiCreateDeviceInterfaceA and/or SetupDiEnumDeviceInterfaces are not available\n");
675 SetLastError(0xdeadbeef);
676 ret = pSetupDiCreateDeviceInterfaceA(NULL, NULL, NULL, NULL, 0, NULL);
677 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
678 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
679 SetLastError(0xdeadbeef);
680 ret = pSetupDiCreateDeviceInterfaceA(NULL, NULL, &guid, NULL, 0, NULL);
681 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
682 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
683 set = pSetupDiCreateDeviceInfoList(&guid, NULL);
684 ok(set != NULL, "SetupDiCreateDeviceInfoList failed: %d\n", GetLastError());
687 SP_DEVINFO_DATA devInfo = { 0 };
688 SP_DEVICE_INTERFACE_DATA interfaceData = { sizeof(interfaceData),
692 SetLastError(0xdeadbeef);
693 ret = pSetupDiCreateDeviceInterfaceA(set, NULL, NULL, NULL, 0, NULL);
694 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
695 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
696 SetLastError(0xdeadbeef);
697 ret = pSetupDiCreateDeviceInterfaceA(set, &devInfo, NULL, NULL, 0,
699 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
700 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
701 devInfo.cbSize = sizeof(devInfo);
702 ret = pSetupDiCreateDeviceInfoA(set, "ROOT\\LEGACY_BOGUS\\0000", &guid,
703 NULL, NULL, 0, &devInfo);
704 ok(ret, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
705 SetLastError(0xdeadbeef);
706 ret = pSetupDiCreateDeviceInterfaceA(set, &devInfo, NULL, NULL, 0,
708 ok(!ret && GetLastError() == ERROR_INVALID_USER_BUFFER,
709 "Expected ERROR_INVALID_USER_BUFFER, got %08x\n", GetLastError());
710 ret = pSetupDiCreateDeviceInterfaceA(set, &devInfo, &guid, NULL, 0,
712 ok(ret, "SetupDiCreateDeviceInterfaceA failed: %08x\n", GetLastError());
713 /* Creating the same interface a second time succeeds */
714 ret = pSetupDiCreateDeviceInterfaceA(set, &devInfo, &guid, NULL, 0,
716 ok(ret, "SetupDiCreateDeviceInterfaceA failed: %08x\n", GetLastError());
717 ret = pSetupDiCreateDeviceInterfaceA(set, &devInfo, &guid, "Oogah", 0,
719 ok(ret, "SetupDiCreateDeviceInterfaceA failed: %08x\n", GetLastError());
720 ret = pSetupDiEnumDeviceInterfaces(set, &devInfo, &guid, 0,
722 ok(ret, "SetupDiEnumDeviceInterfaces failed: %d\n", GetLastError());
724 while (pSetupDiEnumDeviceInterfaces(set, &devInfo, &guid, i,
727 ok(i == 2, "expected 2 interfaces, got %d\n", i);
728 ok(GetLastError() == ERROR_NO_MORE_ITEMS,
729 "SetupDiEnumDeviceInterfaces failed: %08x\n", GetLastError());
730 ret = pSetupDiDestroyDeviceInfoList(set);
731 ok(ret, "SetupDiDestroyDeviceInfoList failed: %08x\n", GetLastError());
734 /* FIXME: On Wine we still have the bogus entry in Enum\Root and
735 * subkeys, as well as the deviceclass key with subkeys.
736 * Only clean the deviceclass key once Wine if fixed.
738 if (!RegOpenKeyW(HKEY_LOCAL_MACHINE, bogus, &key))
740 /* Wine doesn't delete the information currently */
741 trace("We are most likely on Wine\n");
742 devinst_RegDeleteTreeW(HKEY_LOCAL_MACHINE, bogus);
743 devinst_RegDeleteTreeW(HKEY_LOCAL_MACHINE, devclass);
747 clean_devclass_key();
752 static void testGetDeviceInterfaceDetail(void)
756 static const WCHAR bogus[] = {'S','y','s','t','e','m','\\',
757 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
758 'E','n','u','m','\\','R','o','o','t','\\',
759 'L','E','G','A','C','Y','_','B','O','G','U','S',0};
760 static const WCHAR devclass[] = {'S','y','s','t','e','m','\\',
761 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
762 'C','o','n','t','r','o','l','\\','D','e','v','i','c','e','C','l','a','s','s','e','s','\\',
763 '{','6','a','5','5','b','5','a','4','-','3','f','6','5','-',
764 '1','1','d','b','-','b','7','0','4','-',
765 '0','0','1','1','9','5','5','c','2','b','d','b','}',0};
767 if (!pSetupDiCreateDeviceInterfaceA || !pSetupDiGetDeviceInterfaceDetailA)
769 win_skip("SetupDiCreateDeviceInterfaceA and/or SetupDiGetDeviceInterfaceDetailA are not available\n");
772 SetLastError(0xdeadbeef);
773 ret = pSetupDiGetDeviceInterfaceDetailA(NULL, NULL, NULL, 0, NULL, NULL);
774 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
775 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
776 set = pSetupDiCreateDeviceInfoList(&guid, NULL);
777 ok(set != NULL, "SetupDiCreateDeviceInfoList failed: %d\n", GetLastError());
780 SP_DEVINFO_DATA devInfo = { sizeof(devInfo), { 0 } };
781 SP_DEVICE_INTERFACE_DATA interfaceData = { sizeof(interfaceData),
786 SetLastError(0xdeadbeef);
787 ret = pSetupDiGetDeviceInterfaceDetailA(set, NULL, NULL, 0, NULL,
789 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
790 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
791 ret = pSetupDiCreateDeviceInfoA(set, "ROOT\\LEGACY_BOGUS\\0000", &guid,
792 NULL, NULL, 0, &devInfo);
793 ok(ret, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
794 SetLastError(0xdeadbeef);
795 ret = pSetupDiCreateDeviceInterfaceA(set, &devInfo, &guid, NULL, 0,
797 ok(ret, "SetupDiCreateDeviceInterfaceA failed: %08x\n", GetLastError());
798 SetLastError(0xdeadbeef);
799 ret = pSetupDiGetDeviceInterfaceDetailA(set, &interfaceData, NULL,
801 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
802 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
803 SetLastError(0xdeadbeef);
804 ret = pSetupDiGetDeviceInterfaceDetailA(set, &interfaceData, NULL,
806 ok(!ret && GetLastError() == ERROR_INVALID_USER_BUFFER,
807 "Expected ERROR_INVALID_USER_BUFFER, got %08x\n", GetLastError());
808 SetLastError(0xdeadbeef);
809 ret = pSetupDiGetDeviceInterfaceDetailA(set, &interfaceData, NULL,
811 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
812 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
813 if (!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER)
815 static const char path[] =
816 "\\\\?\\root#legacy_bogus#0000#{6a55b5a4-3f65-11db-b704-0011955c2bdb}";
817 static const char path_w2k[] =
818 "\\\\?\\root#legacy_bogus#0000#{6a55b5a4-3f65-11db-b704-0011955c2bdb}\\";
819 LPBYTE buf = HeapAlloc(GetProcessHeap(), 0, size);
820 SP_DEVICE_INTERFACE_DETAIL_DATA_A *detail =
821 (SP_DEVICE_INTERFACE_DETAIL_DATA_A *)buf;
822 DWORD expectedsize = FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_W, DevicePath) + sizeof(WCHAR)*(1 + strlen(path));
825 SetLastError(0xdeadbeef);
826 ret = pSetupDiGetDeviceInterfaceDetailA(set, &interfaceData, detail,
828 ok(!ret && GetLastError() == ERROR_INVALID_USER_BUFFER,
829 "Expected ERROR_INVALID_USER_BUFFER, got %08x\n", GetLastError());
830 detail->cbSize = size;
831 SetLastError(0xdeadbeef);
832 ret = pSetupDiGetDeviceInterfaceDetailA(set, &interfaceData, detail,
834 ok(!ret && GetLastError() == ERROR_INVALID_USER_BUFFER,
835 "Expected ERROR_INVALID_USER_BUFFER, got %08x\n", GetLastError());
836 detail->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_A);
837 SetLastError(0xdeadbeef);
838 ret = pSetupDiGetDeviceInterfaceDetailA(set, &interfaceData, detail,
840 ok(ret, "SetupDiGetDeviceInterfaceDetailA failed: %d\n",
842 ok(!lstrcmpiA(path, detail->DevicePath) ||
843 !lstrcmpiA(path_w2k, detail->DevicePath), "Unexpected path %s\n",
845 /* Check SetupDiGetDeviceInterfaceDetailW */
846 ret = pSetupDiGetDeviceInterfaceDetailW(set, &interfaceData, NULL, 0, &size, NULL);
847 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
848 "Expected ERROR_INSUFFICIENT_BUFFER, got error code: %d\n", GetLastError());
849 ok(expectedsize == size ||
850 (expectedsize + sizeof(WCHAR)) == size /* W2K adds a backslash */,
851 "SetupDiGetDeviceInterfaceDetailW returned wrong reqsize, got %d\n",
854 HeapFree(GetProcessHeap(), 0, buf);
856 pSetupDiDestroyDeviceInfoList(set);
859 /* FIXME: On Wine we still have the bogus entry in Enum\Root and
860 * subkeys, as well as the deviceclass key with subkeys.
861 * Only do the RegDeleteKey, once Wine is fixed.
863 if (!RegOpenKeyW(HKEY_LOCAL_MACHINE, bogus, &key))
865 /* Wine doesn't delete the information currently */
866 trace("We are most likely on Wine\n");
867 devinst_RegDeleteTreeW(HKEY_LOCAL_MACHINE, bogus);
868 devinst_RegDeleteTreeW(HKEY_LOCAL_MACHINE, devclass);
872 clean_devclass_key();
877 static void testDevRegKey(void)
879 static const WCHAR classKey[] = {'S','y','s','t','e','m','\\',
880 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
881 'C','o','n','t','r','o','l','\\','C','l','a','s','s','\\',
882 '{','6','a','5','5','b','5','a','4','-','3','f','6','5','-',
883 '1','1','d','b','-','b','7','0','4','-',
884 '0','0','1','1','9','5','5','c','2','b','d','b','}',0};
885 static const WCHAR bogus[] = {'S','y','s','t','e','m','\\',
886 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
887 'E','n','u','m','\\','R','o','o','t','\\',
888 'L','E','G','A','C','Y','_','B','O','G','U','S',0};
892 BOOL classKeyCreated;
894 SetLastError(0xdeadbeef);
895 key = pSetupDiCreateDevRegKeyW(NULL, NULL, 0, 0, 0, NULL, NULL);
896 ok(key == INVALID_HANDLE_VALUE,
897 "Expected INVALID_HANDLE_VALUE, got %p\n", key);
898 ok(GetLastError() == ERROR_INVALID_HANDLE,
899 "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
901 set = pSetupDiCreateDeviceInfoList(&guid, NULL);
902 ok(set != NULL, "SetupDiCreateDeviceInfoList failed: %d\n", GetLastError());
905 SP_DEVINFO_DATA devInfo = { sizeof(devInfo), { 0 } };
908 /* The device info key shouldn't be there */
909 res = RegOpenKeyW(HKEY_LOCAL_MACHINE, bogus, &key);
910 ok(res != ERROR_SUCCESS, "Expected key to not exist\n");
912 /* Create the device information */
913 ret = pSetupDiCreateDeviceInfoA(set, "ROOT\\LEGACY_BOGUS\\0000", &guid,
914 NULL, NULL, 0, &devInfo);
915 ok(ret, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
916 /* The device info key should have been created */
917 ok(!RegOpenKeyW(HKEY_LOCAL_MACHINE, bogus, &key),
918 "Expected registry key to exist\n");
920 SetLastError(0xdeadbeef);
921 key = pSetupDiOpenDevRegKey(NULL, NULL, 0, 0, 0, 0);
922 ok(!key || key == INVALID_HANDLE_VALUE,
923 "Expected INVALID_HANDLE_VALUE or a NULL key (NT4)\n");
924 ok(GetLastError() == ERROR_INVALID_HANDLE,
925 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
926 SetLastError(0xdeadbeef);
927 key = pSetupDiOpenDevRegKey(set, NULL, 0, 0, 0, 0);
928 ok(key == INVALID_HANDLE_VALUE &&
929 GetLastError() == ERROR_INVALID_PARAMETER,
930 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
931 SetLastError(0xdeadbeef);
932 key = pSetupDiOpenDevRegKey(set, &devInfo, 0, 0, 0, 0);
933 ok(key == INVALID_HANDLE_VALUE &&
934 GetLastError() == ERROR_INVALID_FLAGS,
935 "Expected ERROR_INVALID_FLAGS, got %d\n", GetLastError());
936 SetLastError(0xdeadbeef);
937 key = pSetupDiOpenDevRegKey(set, &devInfo, DICS_FLAG_GLOBAL, 0, 0, 0);
938 ok(key == INVALID_HANDLE_VALUE &&
939 GetLastError() == ERROR_INVALID_FLAGS,
940 "Expected ERROR_INVALID_FLAGS, got %d\n", GetLastError());
941 SetLastError(0xdeadbeef);
942 key = pSetupDiOpenDevRegKey(set, &devInfo, DICS_FLAG_GLOBAL, 0,
944 ok(key == INVALID_HANDLE_VALUE &&
945 GetLastError() == ERROR_INVALID_FLAGS,
946 "Expected ERROR_INVALID_FLAGS, got %d\n", GetLastError());
947 SetLastError(0xdeadbeef);
948 key = pSetupDiOpenDevRegKey(set, &devInfo, DICS_FLAG_GLOBAL, 0,
950 ok(key == INVALID_HANDLE_VALUE &&
951 GetLastError() == ERROR_DEVINFO_NOT_REGISTERED,
952 "Expected ERROR_DEVINFO_NOT_REGISTERED, got %08x\n", GetLastError());
953 SetLastError(0xdeadbeef);
954 ret = pSetupDiRegisterDeviceInfo(set, &devInfo, 0, NULL, NULL, NULL);
955 ok(ret, "SetupDiRegisterDeviceInfo failed: %08x\n", GetLastError());
956 SetLastError(0xdeadbeef);
957 key = pSetupDiOpenDevRegKey(set, &devInfo, DICS_FLAG_GLOBAL, 0,
959 /* The software key isn't created by default */
961 ok(key == INVALID_HANDLE_VALUE &&
962 GetLastError() == ERROR_KEY_DOES_NOT_EXIST,
963 "Expected ERROR_KEY_DOES_NOT_EXIST, got %08x\n", GetLastError());
964 SetLastError(0xdeadbeef);
965 key = pSetupDiOpenDevRegKey(set, &devInfo, DICS_FLAG_GLOBAL, 0,
968 ok(key == INVALID_HANDLE_VALUE &&
969 GetLastError() == ERROR_KEY_DOES_NOT_EXIST,
970 "Expected ERROR_KEY_DOES_NOT_EXIST, got %08x\n", GetLastError());
971 SetLastError(0xdeadbeef);
972 /* The class key shouldn't be there */
973 res = RegOpenKeyW(HKEY_LOCAL_MACHINE, classKey, &key);
975 ok(res != ERROR_SUCCESS, "Expected key to not exist\n");
977 /* Create the device reg key */
978 key = pSetupDiCreateDevRegKeyW(set, &devInfo, DICS_FLAG_GLOBAL, 0,
979 DIREG_DRV, NULL, NULL);
980 /* Vista and higher don't actually create the key */
981 ok(key != INVALID_HANDLE_VALUE || GetLastError() == ERROR_KEY_DOES_NOT_EXIST,
982 "SetupDiCreateDevRegKey failed: %08x\n", GetLastError());
983 if (key != INVALID_HANDLE_VALUE)
985 classKeyCreated = TRUE;
987 /* The class key should have been created */
988 ok(!RegOpenKeyW(HKEY_LOCAL_MACHINE, classKey, &key),
989 "Expected registry key to exist\n");
991 SetLastError(0xdeadbeef);
992 key = pSetupDiOpenDevRegKey(set, &devInfo, DICS_FLAG_GLOBAL, 0,
995 ok(key == INVALID_HANDLE_VALUE &&
996 (GetLastError() == ERROR_INVALID_DATA ||
997 GetLastError() == ERROR_ACCESS_DENIED), /* win2k3 */
998 "Expected ERROR_INVALID_DATA or ERROR_ACCESS_DENIED, got %08x\n", GetLastError());
999 key = pSetupDiOpenDevRegKey(set, &devInfo, DICS_FLAG_GLOBAL, 0,
1000 DIREG_DRV, KEY_READ);
1001 ok(key != INVALID_HANDLE_VALUE, "SetupDiOpenDevRegKey failed: %08x\n",
1003 pSetupDiDestroyDeviceInfoList(set);
1006 classKeyCreated = FALSE;
1009 ret = remove_device();
1011 ok(ret, "Expected the device to be removed: %08x\n", GetLastError());
1013 /* FIXME: Only do the RegDeleteKey, once Wine is fixed */
1016 /* Wine doesn't delete the information currently */
1017 trace("We are most likely on Wine\n");
1018 devinst_RegDeleteTreeW(HKEY_LOCAL_MACHINE, bogus);
1019 devinst_RegDeleteTreeW(HKEY_LOCAL_MACHINE, classKey);
1021 else if (classKeyCreated)
1023 /* There should only be a class key entry, so a simple
1024 * RegDeleteKey should work
1026 * This could fail if it's the first time for this new test
1027 * after running the old tests.
1029 ok(!RegDeleteKeyW(HKEY_LOCAL_MACHINE, classKey),
1030 "Couldn't delete classkey\n");
1035 static void testRegisterAndGetDetail(void)
1039 SP_DEVINFO_DATA devInfo = { sizeof(SP_DEVINFO_DATA), { 0 } };
1040 SP_DEVICE_INTERFACE_DATA interfaceData = { sizeof(interfaceData), { 0 } };
1042 static const WCHAR bogus[] = {'S','y','s','t','e','m','\\',
1043 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
1044 'E','n','u','m','\\','R','o','o','t','\\',
1045 'L','E','G','A','C','Y','_','B','O','G','U','S',0};
1046 static const WCHAR devclass[] = {'S','y','s','t','e','m','\\',
1047 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
1048 'C','o','n','t','r','o','l','\\','D','e','v','i','c','e','C','l','a','s','s','e','s','\\',
1049 '{','6','a','5','5','b','5','a','4','-','3','f','6','5','-',
1050 '1','1','d','b','-','b','7','0','4','-',
1051 '0','0','1','1','9','5','5','c','2','b','d','b','}',0};
1053 if (!pSetupDiCreateDeviceInterfaceA || !pSetupDiEnumDeviceInterfaces ||
1054 !pSetupDiGetDeviceInterfaceDetailA)
1056 win_skip("Needed functions are not available\n");
1060 SetLastError(0xdeadbeef);
1061 set = pSetupDiGetClassDevsA(&guid, NULL, 0, DIGCF_ALLCLASSES);
1062 ok(set != INVALID_HANDLE_VALUE, "SetupDiGetClassDevsA failed: %08x\n",
1065 SetLastError(0xdeadbeef);
1066 ret = pSetupDiCreateDeviceInfoA(set, "LEGACY_BOGUS", &guid, NULL, 0,
1067 DICD_GENERATE_ID, &devInfo);
1068 ok(ret, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
1069 SetLastError(0xdeadbeef);
1070 ret = pSetupDiCreateDeviceInterfaceA(set, &devInfo, &guid, NULL, 0, &interfaceData);
1071 ok(ret, "SetupDiCreateDeviceInterfaceA failed: %08x\n", GetLastError());
1072 SetLastError(0xdeadbeef);
1073 ret = pSetupDiRegisterDeviceInfo(set, &devInfo, 0, NULL, NULL, NULL);
1074 ok(ret, "SetupDiRegisterDeviceInfo failed: %08x\n", GetLastError());
1076 pSetupDiDestroyDeviceInfoList(set);
1078 SetLastError(0xdeadbeef);
1079 set = pSetupDiGetClassDevsA(&guid, NULL, 0, DIGCF_DEVICEINTERFACE);
1080 ok(set != INVALID_HANDLE_VALUE, "SetupDiGetClassDevsA failed: %08x\n",
1083 SetLastError(0xdeadbeef);
1084 ret = pSetupDiEnumDeviceInterfaces(set, NULL, &guid, 0, &interfaceData);
1085 ok(ret, "SetupDiEnumDeviceInterfaces failed: %08x\n", GetLastError());
1086 SetLastError(0xdeadbeef);
1087 ret = pSetupDiGetDeviceInterfaceDetailA(set, &interfaceData, NULL, 0, &dwSize, NULL);
1088 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
1089 "Expected ERROR_INSUFFICIENT_BUFFER, got %08x\n", GetLastError());
1090 if (!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER)
1092 static const char path[] =
1093 "\\\\?\\root#legacy_bogus#0000#{6a55b5a4-3f65-11db-b704-0011955c2bdb}";
1094 static const char path_w2k[] =
1095 "\\\\?\\root#legacy_bogus#0000#{6a55b5a4-3f65-11db-b704-0011955c2bdb}\\";
1096 PSP_DEVICE_INTERFACE_DETAIL_DATA_A detail = NULL;
1098 detail = HeapAlloc(GetProcessHeap(), 0, dwSize);
1101 detail->cbSize = sizeof(*detail);
1102 SetLastError(0xdeadbeef);
1103 ret = pSetupDiGetDeviceInterfaceDetailA(set, &interfaceData,
1104 detail, dwSize, &dwSize, NULL);
1105 ok(ret, "SetupDiGetDeviceInterfaceDetailA failed: %08x\n", GetLastError());
1106 /* FIXME: This one only worked because old data wasn't removed properly. As soon
1107 * as all the tests are cleaned up correctly this has to be (or should be) fixed
1110 ok(!lstrcmpiA(path, detail->DevicePath) ||
1111 !lstrcmpiA(path_w2k, detail->DevicePath), "Unexpected path %s\n",
1112 detail->DevicePath);
1113 HeapFree(GetProcessHeap(), 0, detail);
1117 pSetupDiDestroyDeviceInfoList(set);
1120 ret = remove_device();
1122 ok(ret, "Expected the device to be removed: %08x\n", GetLastError());
1124 /* FIXME: Only do the RegDeleteKey, once Wine is fixed */
1127 /* Wine doesn't delete the information currently */
1128 trace("We are most likely on Wine\n");
1129 devinst_RegDeleteTreeW(HKEY_LOCAL_MACHINE, bogus);
1130 devinst_RegDeleteTreeW(HKEY_LOCAL_MACHINE, devclass);
1134 clean_devclass_key();
1138 static void testDeviceRegistryPropertyA(void)
1141 SP_DEVINFO_DATA devInfo = { sizeof(SP_DEVINFO_DATA), { 0 } };
1142 CHAR devName[] = "LEGACY_BOGUS";
1143 CHAR friendlyName[] = "Bogus";
1151 static const CHAR bogus[] =
1152 "System\\CurrentControlSet\\Enum\\Root\\LEGACY_BOGUS";
1154 SetLastError(0xdeadbeef);
1155 set = pSetupDiGetClassDevsA(&guid, NULL, 0, DIGCF_DEVICEINTERFACE);
1156 ok(set != INVALID_HANDLE_VALUE, "SetupDiGetClassDevsA failed: %08x\n",
1158 SetLastError(0xdeadbeef);
1159 ret = pSetupDiCreateDeviceInfoA(set, devName, &guid, NULL, NULL,
1160 DICD_GENERATE_ID, &devInfo);
1161 ok(ret, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
1162 SetLastError(0xdeadbeef);
1163 ret = pSetupDiSetDeviceRegistryPropertyA(NULL, NULL, -1, NULL, 0);
1164 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
1165 "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
1166 SetLastError(0xdeadbeef);
1167 ret = pSetupDiSetDeviceRegistryPropertyA(set, NULL, -1, NULL, 0);
1168 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
1169 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
1170 SetLastError(0xdeadbeef);
1171 ret = pSetupDiSetDeviceRegistryPropertyA(set, &devInfo, -1, NULL, 0);
1173 ok(!ret && GetLastError() == ERROR_INVALID_REG_PROPERTY,
1174 "Expected ERROR_INVALID_REG_PROPERTY, got %08x\n", GetLastError());
1175 /* GetLastError() returns nonsense in win2k3 */
1176 ret = pSetupDiSetDeviceRegistryPropertyA(set, &devInfo, SPDRP_FRIENDLYNAME,
1179 ok(!ret, "Expected failure, got %d\n", ret);
1180 SetLastError(0xdeadbeef);
1181 ret = pSetupDiSetDeviceRegistryPropertyA(set, &devInfo, SPDRP_FRIENDLYNAME,
1182 (PBYTE)friendlyName, buflen);
1183 ok(ret, "SetupDiSetDeviceRegistryPropertyA failed: %08x\n", GetLastError());
1184 SetLastError(0xdeadbeef);
1185 ret = pSetupDiGetDeviceRegistryPropertyA(NULL, NULL, -1, NULL, NULL, 0, NULL);
1186 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
1187 "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
1188 SetLastError(0xdeadbeef);
1189 ret = pSetupDiGetDeviceRegistryPropertyA(set, NULL, -1, NULL, NULL, 0, NULL);
1190 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
1191 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
1192 SetLastError(0xdeadbeef);
1193 ret = pSetupDiGetDeviceRegistryPropertyA(set, &devInfo, -1, NULL, NULL, 0, NULL);
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 = pSetupDiGetDeviceRegistryPropertyA(set, &devInfo, SPDRP_FRIENDLYNAME,
1199 NULL, NULL, buflen, NULL);
1200 ok(!ret, "Expected failure, got %d\n", ret);
1201 SetLastError(0xdeadbeef);
1202 ret = pSetupDiGetDeviceRegistryPropertyA(set, &devInfo, SPDRP_FRIENDLYNAME,
1203 NULL, NULL, 0, &size);
1204 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
1205 "Expected ERROR_INSUFFICIENT_BUFFER, got %08x\n", GetLastError());
1206 ok(buflen == size, "Unexpected size: %d\n", size);
1207 SetLastError(0xdeadbeef);
1208 ret = pSetupDiGetDeviceRegistryPropertyA(set, &devInfo, SPDRP_FRIENDLYNAME,
1209 NULL, (PBYTE)buf, buflen, NULL);
1210 ok(ret, "SetupDiGetDeviceRegistryPropertyA failed: %08x\n", GetLastError());
1211 ok(!lstrcmpiA(friendlyName, buf), "Unexpected property\n");
1212 SetLastError(0xdeadbeef);
1213 ret = pSetupDiGetDeviceRegistryPropertyA(set, &devInfo, SPDRP_FRIENDLYNAME,
1214 ®Type, (PBYTE)buf, buflen, NULL);
1215 ok(ret, "SetupDiGetDeviceRegistryPropertyA failed: %08x\n", GetLastError());
1216 ok(!lstrcmpiA(friendlyName, buf), "Unexpected value of property\n");
1217 ok(regType == REG_SZ, "Unexpected type of property: %d\n", regType);
1218 SetLastError(0xdeadbeef);
1219 ret = pSetupDiSetDeviceRegistryPropertyA(set, &devInfo, SPDRP_FRIENDLYNAME,
1221 ok(ret, "SetupDiSetDeviceRegistryPropertyA failed: %08x\n", GetLastError());
1222 SetLastError(0xdeadbeef);
1223 ret = pSetupDiGetDeviceRegistryPropertyA(set, &devInfo, SPDRP_FRIENDLYNAME,
1224 NULL, (PBYTE)buf, buflen, &size);
1226 ok(!ret && GetLastError() == ERROR_INVALID_DATA,
1227 "Expected ERROR_INVALID_DATA, got %08x\n", GetLastError());
1228 pSetupDiDestroyDeviceInfoList(set);
1230 res = RegOpenKeyA(HKEY_LOCAL_MACHINE, bogus, &key);
1232 ok(res == ERROR_FILE_NOT_FOUND, "Expected key to not exist\n");
1233 /* FIXME: Remove when Wine is fixed */
1234 if (res == ERROR_SUCCESS)
1236 /* Wine doesn't delete the information currently */
1237 trace("We are most likely on Wine\n");
1238 RegDeleteKeyA(HKEY_LOCAL_MACHINE, bogus);
1242 static void testDeviceRegistryPropertyW(void)
1245 SP_DEVINFO_DATA devInfo = { sizeof(SP_DEVINFO_DATA), { 0 } };
1246 WCHAR devName[] = {'L','E','G','A','C','Y','_','B','O','G','U','S',0};
1247 WCHAR friendlyName[] = {'B','o','g','u','s',0};
1249 DWORD buflen = 6 * sizeof(WCHAR);
1255 static const WCHAR bogus[] = {'S','y','s','t','e','m','\\',
1256 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
1257 'E','n','u','m','\\','R','o','o','t','\\',
1258 'L','E','G','A','C','Y','_','B','O','G','U','S',0};
1260 SetLastError(0xdeadbeef);
1261 set = pSetupDiGetClassDevsW(&guid, NULL, 0, DIGCF_DEVICEINTERFACE);
1262 ok(set != INVALID_HANDLE_VALUE, "SetupDiGetClassDevsW failed: %08x\n",
1264 SetLastError(0xdeadbeef);
1265 ret = pSetupDiCreateDeviceInfoW(set, devName, &guid, NULL, NULL,
1266 DICD_GENERATE_ID, &devInfo);
1267 ok(ret, "SetupDiCreateDeviceInfoW failed: %08x\n", GetLastError());
1268 SetLastError(0xdeadbeef);
1269 ret = pSetupDiSetDeviceRegistryPropertyW(NULL, NULL, -1, NULL, 0);
1270 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
1271 "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
1272 SetLastError(0xdeadbeef);
1273 ret = pSetupDiSetDeviceRegistryPropertyW(set, NULL, -1, NULL, 0);
1274 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
1275 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
1276 SetLastError(0xdeadbeef);
1277 ret = pSetupDiSetDeviceRegistryPropertyW(set, &devInfo, -1, NULL, 0);
1279 ok(!ret && GetLastError() == ERROR_INVALID_REG_PROPERTY,
1280 "Expected ERROR_INVALID_REG_PROPERTY, got %08x\n", GetLastError());
1281 /* GetLastError() returns nonsense in win2k3 */
1282 ret = pSetupDiSetDeviceRegistryPropertyW(set, &devInfo, SPDRP_FRIENDLYNAME,
1285 ok(!ret, "Expected failure, got %d\n", ret);
1286 SetLastError(0xdeadbeef);
1287 ret = pSetupDiSetDeviceRegistryPropertyW(set, &devInfo, SPDRP_FRIENDLYNAME,
1288 (PBYTE)friendlyName, buflen);
1289 ok(ret, "SetupDiSetDeviceRegistryPropertyW failed: %08x\n", GetLastError());
1290 SetLastError(0xdeadbeef);
1291 ret = pSetupDiGetDeviceRegistryPropertyW(NULL, NULL, -1, NULL, NULL, 0, NULL);
1292 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
1293 "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
1294 SetLastError(0xdeadbeef);
1295 ret = pSetupDiGetDeviceRegistryPropertyW(set, NULL, -1, NULL, NULL, 0, NULL);
1296 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
1297 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
1298 SetLastError(0xdeadbeef);
1299 ret = pSetupDiGetDeviceRegistryPropertyW(set, &devInfo, -1, NULL, NULL, 0, NULL);
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 = pSetupDiGetDeviceRegistryPropertyW(set, &devInfo, SPDRP_FRIENDLYNAME,
1305 NULL, NULL, buflen, NULL);
1306 ok(!ret, "Expected failure, got %d\n", ret);
1307 SetLastError(0xdeadbeef);
1308 ret = pSetupDiGetDeviceRegistryPropertyW(set, &devInfo, SPDRP_FRIENDLYNAME,
1309 NULL, NULL, 0, &size);
1310 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
1311 "Expected ERROR_INSUFFICIENT_BUFFER, got %08x\n", GetLastError());
1312 ok(buflen == size, "Unexpected size: %d\n", size);
1313 SetLastError(0xdeadbeef);
1314 ret = pSetupDiGetDeviceRegistryPropertyW(set, &devInfo, SPDRP_FRIENDLYNAME,
1315 NULL, (PBYTE)buf, buflen, NULL);
1316 ok(ret, "SetupDiGetDeviceRegistryPropertyW failed: %08x\n", GetLastError());
1317 ok(!lstrcmpiW(friendlyName, buf), "Unexpected property\n");
1318 SetLastError(0xdeadbeef);
1319 ret = pSetupDiGetDeviceRegistryPropertyW(set, &devInfo, SPDRP_FRIENDLYNAME,
1320 ®Type, (PBYTE)buf, buflen, NULL);
1321 ok(ret, "SetupDiGetDeviceRegistryPropertyW failed: %08x\n", GetLastError());
1322 ok(!lstrcmpiW(friendlyName, buf), "Unexpected value of property\n");
1323 ok(regType == REG_SZ, "Unexpected type of property: %d\n", regType);
1324 SetLastError(0xdeadbeef);
1325 ret = pSetupDiSetDeviceRegistryPropertyW(set, &devInfo, SPDRP_FRIENDLYNAME,
1327 ok(ret, "SetupDiSetDeviceRegistryPropertyW failed: %08x\n", GetLastError());
1328 SetLastError(0xdeadbeef);
1329 ret = pSetupDiGetDeviceRegistryPropertyW(set, &devInfo, SPDRP_FRIENDLYNAME,
1330 NULL, (PBYTE)buf, buflen, &size);
1332 ok(!ret && GetLastError() == ERROR_INVALID_DATA,
1333 "Expected ERROR_INVALID_DATA, got %08x\n", GetLastError());
1334 pSetupDiDestroyDeviceInfoList(set);
1336 res = RegOpenKeyW(HKEY_LOCAL_MACHINE, bogus, &key);
1338 ok(res == ERROR_FILE_NOT_FOUND, "Expected key to not exist\n");
1339 /* FIXME: Remove when Wine is fixed */
1340 if (res == ERROR_SUCCESS)
1342 /* Wine doesn't delete the information currently */
1343 trace("We are most likely on Wine\n");
1344 RegDeleteKeyW(HKEY_LOCAL_MACHINE, bogus);
1348 static void testSetupDiGetINFClassA(void)
1350 static const char inffile[] = "winetest.inf";
1351 static const char content[] = "[Version]\r\n\r\n";
1354 char filename[MAX_PATH];
1360 if(!pSetupDiGetINFClassA)
1362 win_skip("SetupDiGetINFClassA not present\n");
1366 count = GetTempPathA(MAX_PATH, filename);
1369 win_skip("GetTempPathA failed\n");
1373 strcat(filename, inffile);
1374 DeleteFileA(filename);
1376 /* not existing file */
1377 SetLastError(0xdeadbeef);
1378 retval = SetupDiGetINFClassA(filename, &guid, cn, MAX_PATH, &count);
1379 ok(!retval, "expected SetupDiGetINFClassA to fail!\n");
1380 if (ERROR_CALL_NOT_IMPLEMENTED == GetLastError())
1382 skip("SetupDiGetINFClassA is not implemented\n");
1385 ok(ERROR_FILE_NOT_FOUND == GetLastError(),
1386 "expected error ERROR_FILE_NOT_FOUND, got %u\n", GetLastError());
1388 /* missing file wins against other invalid parameter */
1389 SetLastError(0xdeadbeef);
1390 retval = SetupDiGetINFClassA(filename, NULL, cn, MAX_PATH, &count);
1391 ok(!retval, "expected SetupDiGetINFClassA to fail!\n");
1392 ok(ERROR_FILE_NOT_FOUND == GetLastError(),
1393 "expected error ERROR_FILE_NOT_FOUND, got %u\n", GetLastError());
1395 SetLastError(0xdeadbeef);
1396 retval = SetupDiGetINFClassA(filename, &guid, NULL, MAX_PATH, &count);
1397 ok(!retval, "expected SetupDiGetINFClassA to fail!\n");
1398 ok(ERROR_FILE_NOT_FOUND == GetLastError(),
1399 "expected error ERROR_FILE_NOT_FOUND, got %u\n", GetLastError());
1401 SetLastError(0xdeadbeef);
1402 retval = SetupDiGetINFClassA(filename, &guid, cn, 0, &count);
1403 ok(!retval, "expected SetupDiGetINFClassA to fail!\n");
1404 ok(ERROR_FILE_NOT_FOUND == GetLastError(),
1405 "expected error ERROR_FILE_NOT_FOUND, got %u\n", GetLastError());
1407 SetLastError(0xdeadbeef);
1408 retval = SetupDiGetINFClassA(filename, &guid, cn, MAX_PATH, NULL);
1409 ok(!retval, "expected SetupDiGetINFClassA to fail!\n");
1410 ok(ERROR_FILE_NOT_FOUND == GetLastError(),
1411 "expected error ERROR_FILE_NOT_FOUND, got %u\n", GetLastError());
1413 /* test file content */
1414 h = CreateFileA(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
1415 FILE_ATTRIBUTE_NORMAL, NULL);
1416 if(h == INVALID_HANDLE_VALUE)
1418 win_skip("failed to create file %s (error %u)\n", filename, GetLastError());
1423 retval = SetupDiGetINFClassA(filename, &guid, cn, MAX_PATH, &count);
1424 ok(!retval, "expected SetupDiGetINFClassA to fail!\n");
1426 h = CreateFileA(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
1427 FILE_ATTRIBUTE_NORMAL, NULL);
1428 if(h == INVALID_HANDLE_VALUE)
1430 win_skip("failed to create file %s (error %u)\n", filename, GetLastError());
1433 WriteFile( h, content, sizeof(content), &count, NULL);
1436 retval = SetupDiGetINFClassA(filename, &guid, cn, MAX_PATH, &count);
1437 ok(!retval, "expected SetupDiGetINFClassA to fail!\n");
1439 WritePrivateProfileStringA("Version", "Signature", "\"$CHICAGO$\"", filename);
1441 retval = SetupDiGetINFClassA(filename, &guid, cn, MAX_PATH, &count);
1442 ok(!retval, "expected SetupDiGetINFClassA to fail!\n");
1444 WritePrivateProfileStringA("Version", "Class", "WINE", filename);
1446 retval = SetupDiGetINFClassA(filename, &guid, cn, MAX_PATH, &count);
1447 ok(retval, "expected SetupDiGetINFClassA to succeed! error %u\n", GetLastError());
1449 /* invalid parameter */
1450 SetLastError(0xdeadbeef);
1451 retval = SetupDiGetINFClassA(filename, NULL, cn, MAX_PATH, &count);
1452 ok(!retval, "expected SetupDiGetINFClassA to fail!\n");
1453 ok(ERROR_INVALID_PARAMETER == GetLastError(),
1454 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1456 SetLastError(0xdeadbeef);
1457 retval = SetupDiGetINFClassA(filename, &guid, NULL, MAX_PATH, &count);
1458 ok(!retval, "expected SetupDiGetINFClassA to fail!\n");
1459 ok(ERROR_INVALID_PARAMETER == GetLastError(),
1460 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1462 SetLastError(0xdeadbeef);
1463 retval = SetupDiGetINFClassA(filename, &guid, cn, 0, &count);
1464 ok(!retval, "expected SetupDiGetINFClassA to fail!\n");
1465 ok(ERROR_INSUFFICIENT_BUFFER == GetLastError() ||
1466 ERROR_INVALID_PARAMETER == GetLastError(),
1467 "expected error ERROR_INSUFFICIENT_BUFFER or ERROR_INVALID_PARAMETER, "
1468 "got %u\n", GetLastError());
1470 DeleteFileA(filename);
1472 WritePrivateProfileStringA("Version", "Signature", "\"$CHICAGO$\"", filename);
1473 WritePrivateProfileStringA("Version", "ClassGUID", "WINE", filename);
1475 SetLastError(0xdeadbeef);
1476 retval = SetupDiGetINFClassA(filename, &guid, cn, MAX_PATH, &count);
1477 ok(!retval, "expected SetupDiGetINFClassA to fail!\n");
1478 ok(RPC_S_INVALID_STRING_UUID == GetLastError() ||
1479 ERROR_INVALID_PARAMETER == GetLastError(),
1480 "expected error RPC_S_INVALID_STRING_UUID or ERROR_INVALID_PARAMETER, "
1481 "got %u\n", GetLastError());
1483 /* network adapter guid */
1484 WritePrivateProfileStringA("Version", "ClassGUID",
1485 "{4d36e972-e325-11ce-bfc1-08002be10318}", filename);
1487 /* this test succeeds only if the guid is known to the system */
1488 retval = SetupDiGetINFClassA(filename, &guid, cn, MAX_PATH, &count);
1489 ok(retval, "expected SetupDiGetINFClassA to succeed! error %u\n", GetLastError());
1491 DeleteFileA(filename);
1498 init_function_pointers();
1500 /* Win9x/WinMe does things totally different so we skip all the tests
1502 * We don't want to exclude NT4 so hence this check.
1504 SetLastError(0xdeadbeef);
1505 set = pSetupDiGetClassDevsW(NULL, NULL, 0, 0);
1506 if (set == INVALID_HANDLE_VALUE && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1508 win_skip("Win9x/WinMe has totally different behavior\n");
1512 if (pSetupDiCreateDeviceInfoListExW)
1513 test_SetupDiCreateDeviceInfoListEx();
1515 win_skip("SetupDiCreateDeviceInfoListExW is not available\n");
1517 if (pSetupDiOpenClassRegKeyExA)
1518 test_SetupDiOpenClassRegKeyExA();
1520 win_skip("SetupDiOpenClassRegKeyExA is not available\n");
1523 testCreateDeviceInfo();
1524 testGetDeviceInstanceId();
1525 testRegisterDeviceInfo();
1526 testCreateDeviceInterface();
1527 testGetDeviceInterfaceDetail();
1529 testRegisterAndGetDetail();
1530 testDeviceRegistryPropertyA();
1531 testDeviceRegistryPropertyW();
1532 testSetupDiGetINFClassA();