includes: Fix alignment for 64-bits
[wine/wine64.git] / dlls / setupapi / tests / devinst.c
blob78b2ca3ec3a40c768aa46efcffb4bb7ae79f064f
1 /*
2 * Devinst tests
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
21 #include <assert.h>
22 #include <stdarg.h>
23 #include <stdio.h>
24 #include "windef.h"
25 #include "winbase.h"
26 #include "wingdi.h"
27 #include "winuser.h"
28 #include "winreg.h"
29 #include "guiddef.h"
30 #include "setupapi.h"
32 #include "wine/test.h"
34 /* function pointers */
35 static HMODULE hSetupAPI;
36 static HDEVINFO (WINAPI *pSetupDiCreateDeviceInfoList)(GUID*,HWND);
37 static HDEVINFO (WINAPI *pSetupDiCreateDeviceInfoListExW)(GUID*,HWND,PCWSTR,PVOID);
38 static BOOL (WINAPI *pSetupDiCreateDeviceInterfaceA)(HDEVINFO, PSP_DEVINFO_DATA, const GUID *, PCSTR, DWORD, PSP_DEVICE_INTERFACE_DATA);
39 static BOOL (WINAPI *pSetupDiCallClassInstaller)(DI_FUNCTION, HDEVINFO, PSP_DEVINFO_DATA);
40 static BOOL (WINAPI *pSetupDiDestroyDeviceInfoList)(HDEVINFO);
41 static BOOL (WINAPI *pSetupDiEnumDeviceInfo)(HDEVINFO, DWORD, PSP_DEVINFO_DATA);
42 static BOOL (WINAPI *pSetupDiEnumDeviceInterfaces)(HDEVINFO, PSP_DEVINFO_DATA, const GUID *, DWORD, PSP_DEVICE_INTERFACE_DATA);
43 static BOOL (WINAPI *pSetupDiInstallClassA)(HWND, PCSTR, DWORD, HSPFILEQ);
44 static HKEY (WINAPI *pSetupDiOpenClassRegKeyExA)(GUID*,REGSAM,DWORD,PCSTR,PVOID);
45 static HKEY (WINAPI *pSetupDiOpenDevRegKey)(HDEVINFO, PSP_DEVINFO_DATA, DWORD, DWORD, DWORD, REGSAM);
46 static HKEY (WINAPI *pSetupDiCreateDevRegKeyW)(HDEVINFO, PSP_DEVINFO_DATA, DWORD, DWORD, DWORD, HINF, PCWSTR);
47 static BOOL (WINAPI *pSetupDiCreateDeviceInfoA)(HDEVINFO, PCSTR, GUID *, PCSTR, HWND, DWORD, PSP_DEVINFO_DATA);
48 static BOOL (WINAPI *pSetupDiCreateDeviceInfoW)(HDEVINFO, PCWSTR, GUID *, PCWSTR, HWND, DWORD, PSP_DEVINFO_DATA);
49 static BOOL (WINAPI *pSetupDiGetDeviceInstanceIdA)(HDEVINFO, PSP_DEVINFO_DATA, PSTR, DWORD, PDWORD);
50 static BOOL (WINAPI *pSetupDiGetDeviceInterfaceDetailA)(HDEVINFO, PSP_DEVICE_INTERFACE_DATA, PSP_DEVICE_INTERFACE_DETAIL_DATA_A, DWORD, PDWORD, PSP_DEVINFO_DATA);
51 static BOOL (WINAPI *pSetupDiGetDeviceInterfaceDetailW)(HDEVINFO, PSP_DEVICE_INTERFACE_DATA, PSP_DEVICE_INTERFACE_DETAIL_DATA_W, DWORD, PDWORD, PSP_DEVINFO_DATA);
52 static BOOL (WINAPI *pSetupDiRegisterDeviceInfo)(HDEVINFO, PSP_DEVINFO_DATA, DWORD, PSP_DETSIG_CMPPROC, PVOID, PSP_DEVINFO_DATA);
53 static HDEVINFO (WINAPI *pSetupDiGetClassDevsA)(CONST GUID *, LPCSTR, HWND, DWORD);
54 static HDEVINFO (WINAPI *pSetupDiGetClassDevsW)(CONST GUID *, LPCWSTR, HWND, DWORD);
55 static BOOL (WINAPI *pSetupDiSetDeviceRegistryPropertyA)(HDEVINFO, PSP_DEVINFO_DATA, DWORD, const BYTE *, DWORD);
56 static BOOL (WINAPI *pSetupDiSetDeviceRegistryPropertyW)(HDEVINFO, PSP_DEVINFO_DATA, DWORD, const BYTE *, DWORD);
57 static BOOL (WINAPI *pSetupDiGetDeviceRegistryPropertyA)(HDEVINFO, PSP_DEVINFO_DATA, DWORD, PDWORD, PBYTE, DWORD, PDWORD);
58 static BOOL (WINAPI *pSetupDiGetDeviceRegistryPropertyW)(HDEVINFO, PSP_DEVINFO_DATA, DWORD, PDWORD, PBYTE, DWORD, PDWORD);
60 /* This is a unique guid for testing purposes */
61 static GUID guid = {0x6a55b5a4, 0x3f65, 0x11db, {0xb7,0x04,0x00,0x11,0x95,0x5c,0x2b,0xdb}};
63 static void init_function_pointers(void)
65 hSetupAPI = GetModuleHandleA("setupapi.dll");
67 pSetupDiCreateDeviceInfoA = (void *)GetProcAddress(hSetupAPI, "SetupDiCreateDeviceInfoA");
68 pSetupDiCreateDeviceInfoW = (void *)GetProcAddress(hSetupAPI, "SetupDiCreateDeviceInfoW");
69 pSetupDiCreateDeviceInfoList = (void *)GetProcAddress(hSetupAPI, "SetupDiCreateDeviceInfoList");
70 pSetupDiCreateDeviceInfoListExW = (void *)GetProcAddress(hSetupAPI, "SetupDiCreateDeviceInfoListExW");
71 pSetupDiCreateDeviceInterfaceA = (void *)GetProcAddress(hSetupAPI, "SetupDiCreateDeviceInterfaceA");
72 pSetupDiDestroyDeviceInfoList = (void *)GetProcAddress(hSetupAPI, "SetupDiDestroyDeviceInfoList");
73 pSetupDiCallClassInstaller = (void *)GetProcAddress(hSetupAPI, "SetupDiCallClassInstaller");
74 pSetupDiEnumDeviceInfo = (void *)GetProcAddress(hSetupAPI, "SetupDiEnumDeviceInfo");
75 pSetupDiEnumDeviceInterfaces = (void *)GetProcAddress(hSetupAPI, "SetupDiEnumDeviceInterfaces");
76 pSetupDiGetDeviceInstanceIdA = (void *)GetProcAddress(hSetupAPI, "SetupDiGetDeviceInstanceIdA");
77 pSetupDiGetDeviceInterfaceDetailA = (void *)GetProcAddress(hSetupAPI, "SetupDiGetDeviceInterfaceDetailA");
78 pSetupDiGetDeviceInterfaceDetailW = (void *)GetProcAddress(hSetupAPI, "SetupDiGetDeviceInterfaceDetailW");
79 pSetupDiInstallClassA = (void *)GetProcAddress(hSetupAPI, "SetupDiInstallClassA");
80 pSetupDiOpenClassRegKeyExA = (void *)GetProcAddress(hSetupAPI, "SetupDiOpenClassRegKeyExA");
81 pSetupDiOpenDevRegKey = (void *)GetProcAddress(hSetupAPI, "SetupDiOpenDevRegKey");
82 pSetupDiCreateDevRegKeyW = (void *)GetProcAddress(hSetupAPI, "SetupDiCreateDevRegKeyW");
83 pSetupDiRegisterDeviceInfo = (void *)GetProcAddress(hSetupAPI, "SetupDiRegisterDeviceInfo");
84 pSetupDiGetClassDevsA = (void *)GetProcAddress(hSetupAPI, "SetupDiGetClassDevsA");
85 pSetupDiGetClassDevsW = (void *)GetProcAddress(hSetupAPI, "SetupDiGetClassDevsW");
86 pSetupDiSetDeviceRegistryPropertyA = (void *)GetProcAddress(hSetupAPI, "SetupDiSetDeviceRegistryPropertyA");
87 pSetupDiSetDeviceRegistryPropertyW = (void *)GetProcAddress(hSetupAPI, "SetupDiSetDeviceRegistryPropertyW");
88 pSetupDiGetDeviceRegistryPropertyA = (void *)GetProcAddress(hSetupAPI, "SetupDiGetDeviceRegistryPropertyA");
89 pSetupDiGetDeviceRegistryPropertyW = (void *)GetProcAddress(hSetupAPI, "SetupDiGetDeviceRegistryPropertyW");
92 static void change_reg_permissions(const WCHAR *regkey)
94 HKEY hkey;
95 SID_IDENTIFIER_AUTHORITY ident = { SECURITY_WORLD_SID_AUTHORITY };
96 SECURITY_DESCRIPTOR sd;
97 PSID EveryoneSid;
98 PACL pacl = NULL;
100 RegOpenKeyExW(HKEY_LOCAL_MACHINE, regkey, 0, WRITE_DAC, &hkey);
102 /* Initialize the 'Everyone' sid */
103 AllocateAndInitializeSid(&ident, 1, SECURITY_WORLD_RID, 0, 0, 0, 0, 0, 0, 0, &EveryoneSid);
105 pacl = HeapAlloc(GetProcessHeap(), 0, 256);
106 InitializeAcl(pacl, 256, ACL_REVISION);
108 /* Add 'Full Control' for 'Everyone' */
109 AddAccessAllowedAce(pacl, ACL_REVISION, KEY_ALL_ACCESS, EveryoneSid);
111 InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION);
113 SetSecurityDescriptorDacl(&sd, TRUE, pacl, FALSE);
115 /* Set the new security on the registry key */
116 RegSetKeySecurity(hkey, DACL_SECURITY_INFORMATION, &sd);
118 RegCloseKey(hkey);
120 HeapFree(GetProcessHeap(), 0, pacl);
121 if (EveryoneSid)
122 FreeSid(EveryoneSid);
125 static BOOL remove_device(void)
127 HDEVINFO set;
128 SP_DEVINFO_DATA devInfo = { sizeof(devInfo), { 0 } };
129 BOOL ret;
131 SetLastError(0xdeadbeef);
132 set = pSetupDiGetClassDevsA(&guid, NULL, 0, 0);
133 ok(set != INVALID_HANDLE_VALUE, "SetupDiGetClassDevsA failed: %08x\n",
134 GetLastError());
136 SetLastError(0xdeadbeef);
137 ok(pSetupDiEnumDeviceInfo(set, 0, &devInfo),
138 "SetupDiEnumDeviceInfo failed: %08x\n", GetLastError());
140 SetLastError(0xdeadbeef);
141 ret = pSetupDiCallClassInstaller(DIF_REMOVE, set, &devInfo);
142 todo_wine
143 ok(ret, "SetupDiCallClassInstaller(DIF_REMOVE...) failed: %08x\n", GetLastError());
145 SetLastError(0xdeadbeef);
146 ok(pSetupDiDestroyDeviceInfoList(set),
147 "SetupDiDestroyDeviceInfoList failed: %08x\n", GetLastError());
149 return ret;
152 /* RegDeleteTreeW from dlls/advapi32/registry.c */
153 static LSTATUS devinst_RegDeleteTreeW(HKEY hKey, LPCWSTR lpszSubKey)
155 LONG ret;
156 DWORD dwMaxSubkeyLen, dwMaxValueLen;
157 DWORD dwMaxLen, dwSize;
158 WCHAR szNameBuf[MAX_PATH], *lpszName = szNameBuf;
159 HKEY hSubKey = hKey;
161 if(lpszSubKey)
163 ret = RegOpenKeyExW(hKey, lpszSubKey, 0, KEY_READ, &hSubKey);
164 if (ret) return ret;
167 /* Get highest length for keys, values */
168 ret = RegQueryInfoKeyW(hSubKey, NULL, NULL, NULL, NULL,
169 &dwMaxSubkeyLen, NULL, NULL, &dwMaxValueLen, NULL, NULL, NULL);
170 if (ret) goto cleanup;
172 dwMaxSubkeyLen++;
173 dwMaxValueLen++;
174 dwMaxLen = max(dwMaxSubkeyLen, dwMaxValueLen);
175 if (dwMaxLen > sizeof(szNameBuf)/sizeof(WCHAR))
177 /* Name too big: alloc a buffer for it */
178 if (!(lpszName = HeapAlloc( GetProcessHeap(), 0, dwMaxLen*sizeof(WCHAR))))
180 ret = ERROR_NOT_ENOUGH_MEMORY;
181 goto cleanup;
186 /* Recursively delete all the subkeys */
187 while (TRUE)
189 dwSize = dwMaxLen;
190 if (RegEnumKeyExW(hSubKey, 0, lpszName, &dwSize, NULL,
191 NULL, NULL, NULL)) break;
193 ret = devinst_RegDeleteTreeW(hSubKey, lpszName);
194 if (ret) goto cleanup;
197 if (lpszSubKey)
198 ret = RegDeleteKeyW(hKey, lpszSubKey);
199 else
200 while (TRUE)
202 dwSize = dwMaxLen;
203 if (RegEnumValueW(hKey, 0, lpszName, &dwSize,
204 NULL, NULL, NULL, NULL)) break;
206 ret = RegDeleteValueW(hKey, lpszName);
207 if (ret) goto cleanup;
210 cleanup:
211 /* Free buffer if allocated */
212 if (lpszName != szNameBuf)
213 HeapFree( GetProcessHeap(), 0, lpszName);
214 if(lpszSubKey)
215 RegCloseKey(hSubKey);
216 return ret;
219 static void clean_devclass_key(void)
221 static const WCHAR devclass[] = {'S','y','s','t','e','m','\\',
222 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
223 'C','o','n','t','r','o','l','\\','D','e','v','i','c','e','C','l','a','s','s','e','s','\\',
224 '{','6','a','5','5','b','5','a','4','-','3','f','6','5','-',
225 '1','1','d','b','-','b','7','0','4','-',
226 '0','0','1','1','9','5','5','c','2','b','d','b','}',0};
227 HKEY key;
228 DWORD subkeys;
230 /* Check if we have subkeys as Windows 2000 doesn't delete
231 * the keys under the DeviceClasses key after a SetupDiDestroyDeviceInfoList.
233 RegOpenKeyW(HKEY_LOCAL_MACHINE, devclass, &key);
234 RegQueryInfoKey(key, NULL, NULL, NULL, &subkeys, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
235 if (subkeys > 0)
237 trace("We are most likely on Windows 2000\n");
238 devinst_RegDeleteTreeW(HKEY_LOCAL_MACHINE, devclass);
240 else
242 ok(!RegDeleteKeyW(HKEY_LOCAL_MACHINE, devclass),
243 "Couldn't delete deviceclass key\n");
247 static void test_SetupDiCreateDeviceInfoListEx(void)
249 HDEVINFO devlist;
250 BOOL ret;
251 DWORD error;
252 static CHAR notnull[] = "NotNull";
253 static const WCHAR machine[] = { 'd','u','m','m','y',0 };
255 SetLastError(0xdeadbeef);
256 /* create empty DeviceInfoList, but set Reserved to a value, which is not NULL */
257 devlist = pSetupDiCreateDeviceInfoListExW(NULL, NULL, NULL, notnull);
259 error = GetLastError();
260 if (error == ERROR_CALL_NOT_IMPLEMENTED)
262 skip("SetupDiCreateDeviceInfoListExW is not implemented\n");
263 return;
265 ok(devlist == INVALID_HANDLE_VALUE, "SetupDiCreateDeviceInfoListExW failed : %p %d (expected %p)\n", devlist, error, INVALID_HANDLE_VALUE);
266 ok(error == ERROR_INVALID_PARAMETER, "GetLastError returned wrong value : %d, (expected %d)\n", error, ERROR_INVALID_PARAMETER);
268 SetLastError(0xdeadbeef);
269 /* create empty DeviceInfoList, but set MachineName to something */
270 devlist = pSetupDiCreateDeviceInfoListExW(NULL, NULL, machine, NULL);
272 error = GetLastError();
273 ok(devlist == INVALID_HANDLE_VALUE, "SetupDiCreateDeviceInfoListExW failed : %p %d (expected %p)\n", devlist, error, INVALID_HANDLE_VALUE);
274 ok(error == ERROR_INVALID_MACHINENAME, "GetLastError returned wrong value : %d, (expected %d)\n", error, ERROR_INVALID_MACHINENAME);
276 /* create empty DeviceInfoList */
277 devlist = pSetupDiCreateDeviceInfoListExW(NULL, NULL, NULL, NULL);
278 ok(devlist && devlist != INVALID_HANDLE_VALUE, "SetupDiCreateDeviceInfoListExW failed : %p %d (expected != %p)\n", devlist, error, INVALID_HANDLE_VALUE);
280 /* destroy DeviceInfoList */
281 ret = pSetupDiDestroyDeviceInfoList(devlist);
282 ok(ret, "SetupDiDestroyDeviceInfoList failed : %d\n", error);
285 static void test_SetupDiOpenClassRegKeyExA(void)
287 static const CHAR guidString[] = "{6a55b5a4-3f65-11db-b704-0011955c2bdb}";
288 HKEY hkey;
290 /* Check return value for nonexistent key */
291 hkey = pSetupDiOpenClassRegKeyExA(&guid, KEY_ALL_ACCESS,
292 DIOCR_INSTALLER, NULL, NULL);
293 ok(hkey == INVALID_HANDLE_VALUE,
294 "returned %p (expected INVALID_HANDLE_VALUE)\n", hkey);
296 /* Test it for a key that exists */
297 hkey = SetupDiOpenClassRegKey(NULL, KEY_ALL_ACCESS);
298 if (hkey != INVALID_HANDLE_VALUE)
300 HKEY classKey;
301 if (RegCreateKeyA(hkey, guidString, &classKey) == ERROR_SUCCESS)
303 RegCloseKey(classKey);
304 SetLastError(0xdeadbeef);
305 classKey = pSetupDiOpenClassRegKeyExA(&guid, KEY_ALL_ACCESS,
306 DIOCR_INSTALLER, NULL, NULL);
307 ok(classKey != INVALID_HANDLE_VALUE,
308 "opening class registry key failed with error %d\n",
309 GetLastError());
310 if (classKey != INVALID_HANDLE_VALUE)
311 RegCloseKey(classKey);
312 RegDeleteKeyA(hkey, guidString);
314 else
315 trace("failed to create registry key for test\n");
317 RegCloseKey(hkey);
319 else
320 trace("failed to open classes key\n");
323 static void create_inf_file(LPCSTR filename)
325 DWORD dwNumberOfBytesWritten;
326 HANDLE hf = CreateFile(filename, GENERIC_WRITE, 0, NULL,
327 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
329 static const char data[] =
330 "[Version]\n"
331 "Signature=\"$Chicago$\"\n"
332 "Class=Bogus\n"
333 "ClassGUID={6a55b5a4-3f65-11db-b704-0011955c2bdb}\n"
334 "[ClassInstall32]\n"
335 "AddReg=BogusClass.NT.AddReg\n"
336 "[BogusClass.NT.AddReg]\n"
337 "HKR,,,,\"Wine test devices\"\n";
339 WriteFile(hf, data, sizeof(data) - 1, &dwNumberOfBytesWritten, NULL);
340 CloseHandle(hf);
343 static void get_temp_filename(LPSTR path)
345 static char curr[MAX_PATH] = { 0 };
346 char temp[MAX_PATH];
347 LPSTR ptr;
349 if (!*curr)
350 GetCurrentDirectoryA(MAX_PATH, curr);
351 GetTempFileNameA(curr, "set", 0, temp);
352 ptr = strrchr(temp, '\\');
354 lstrcpyA(path, ptr + 1);
357 static void testInstallClass(void)
359 static const WCHAR classKey[] = {'S','y','s','t','e','m','\\',
360 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
361 'C','o','n','t','r','o','l','\\','C','l','a','s','s','\\',
362 '{','6','a','5','5','b','5','a','4','-','3','f','6','5','-',
363 '1','1','d','b','-','b','7','0','4','-',
364 '0','0','1','1','9','5','5','c','2','b','d','b','}',0};
365 char tmpfile[MAX_PATH];
366 BOOL ret;
368 tmpfile[0] = '.';
369 tmpfile[1] = '\\';
370 get_temp_filename(tmpfile + 2);
371 create_inf_file(tmpfile + 2);
373 ret = pSetupDiInstallClassA(NULL, NULL, 0, NULL);
374 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
375 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
376 ret = pSetupDiInstallClassA(NULL, NULL, DI_NOVCP, NULL);
377 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
378 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
379 ret = pSetupDiInstallClassA(NULL, tmpfile + 2, DI_NOVCP, NULL);
380 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
381 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
382 ret = pSetupDiInstallClassA(NULL, tmpfile + 2, 0, NULL);
383 ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND,
384 "Expected ERROR_FILE_NOT_FOUND, got %08x\n", GetLastError());
385 /* The next call will succeed. Information is put into the registry but the
386 * location(s) is/are depending on the Windows version.
388 ret = pSetupDiInstallClassA(NULL, tmpfile, 0, NULL);
389 ok(ret, "SetupDiInstallClassA failed: %08x\n", GetLastError());
391 ok(!RegDeleteKeyW(HKEY_LOCAL_MACHINE, classKey),
392 "Couldn't delete classkey\n");
394 DeleteFile(tmpfile);
397 static void testCreateDeviceInfo(void)
399 BOOL ret;
400 HDEVINFO set;
401 HKEY key;
402 LONG res;
403 static const WCHAR bogus[] = {'S','y','s','t','e','m','\\',
404 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
405 'E','n','u','m','\\','R','o','o','t','\\',
406 'L','E','G','A','C','Y','_','B','O','G','U','S',0};
408 SetLastError(0xdeadbeef);
409 ret = pSetupDiCreateDeviceInfoA(NULL, NULL, NULL, NULL, NULL, 0, NULL);
410 ok(!ret, "Expected failure\n");
411 ok(GetLastError() == ERROR_INVALID_DEVINST_NAME ||
412 GetLastError() == ERROR_INVALID_PARAMETER /* NT4 */,
413 "Unexpected last error, got %08x\n", GetLastError());
415 SetLastError(0xdeadbeef);
416 ret = pSetupDiCreateDeviceInfoA(NULL, "Root\\LEGACY_BOGUS\\0000", NULL,
417 NULL, NULL, 0, NULL);
418 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
419 "Expected ERROR_INVALID_HANDLEHANDLE, got %08x\n", GetLastError());
420 set = pSetupDiCreateDeviceInfoList(&guid, NULL);
421 ok(set != NULL, "SetupDiCreateDeviceInfoList failed: %08x\n",
422 GetLastError());
423 if (set)
425 SP_DEVINFO_DATA devInfo = { 0 };
426 DWORD i;
427 static GUID deadbeef =
428 {0xdeadbeef, 0xdead, 0xbeef, {0xde,0xad,0xbe,0xef,0xde,0xad,0xbe,0xef}};
429 LONG res;
430 HKEY key;
431 static const WCHAR bogus0000[] = {'S','y','s','t','e','m','\\',
432 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
433 'E','n','u','m','\\','R','o','o','t','\\',
434 'L','E','G','A','C','Y','_','B','O','G','U','S','\\','0','0','0','0',0};
436 /* So we know we have a clean start */
437 res = RegOpenKeyW(HKEY_LOCAL_MACHINE, bogus0000, &key);
438 ok(res != ERROR_SUCCESS, "Expected key to not exist\n");
439 /* No GUID given */
440 SetLastError(0xdeadbeef);
441 ret = pSetupDiCreateDeviceInfoA(set, "Root\\LEGACY_BOGUS\\0000", NULL,
442 NULL, NULL, 0, NULL);
443 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
444 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
445 /* Even though NT4 fails it still adds some stuff to the registry that
446 * can't be deleted via normal setupapi functions. As the registry is written
447 * by a different user (SYSTEM) we have to do some magic to get rid of the key
449 if (!RegOpenKeyW(HKEY_LOCAL_MACHINE, bogus0000, &key))
451 trace("NT4 created a bogus key on failure, will be removed now\n");
452 change_reg_permissions(bogus0000);
453 ok(!RegDeleteKeyW(HKEY_LOCAL_MACHINE, bogus0000),
454 "Could not delete LEGACY_BOGUS\\0000 key\n");
456 /* We can't add device information to the set with a different GUID */
457 SetLastError(0xdeadbeef);
458 ret = pSetupDiCreateDeviceInfoA(set, "Root\\LEGACY_BOGUS\\0000",
459 &deadbeef, NULL, NULL, 0, NULL);
460 ok(!ret && GetLastError() == ERROR_CLASS_MISMATCH,
461 "Expected ERROR_CLASS_MISMATCH, got %08x\n", GetLastError());
462 if (!RegOpenKeyW(HKEY_LOCAL_MACHINE, bogus0000, &key))
464 trace("NT4 created a bogus key on failure, will be removed now\n");
465 change_reg_permissions(bogus0000);
466 ok(!RegDeleteKeyW(HKEY_LOCAL_MACHINE, bogus0000),
467 "Could not delete LEGACY_BOGUS\\0000 key\n");
469 /* Finally, with all three required parameters, this succeeds: */
470 ret = pSetupDiCreateDeviceInfoA(set, "Root\\LEGACY_BOGUS\\0000", &guid,
471 NULL, NULL, 0, NULL);
472 ok(ret, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
473 /* This fails because the device ID already exists.. */
474 SetLastError(0xdeadbeef);
475 ret = pSetupDiCreateDeviceInfoA(set, "Root\\LEGACY_BOGUS\\0000", &guid,
476 NULL, NULL, 0, &devInfo);
477 ok(!ret && GetLastError() == ERROR_DEVINST_ALREADY_EXISTS,
478 "Expected ERROR_DEVINST_ALREADY_EXISTS, got %08x\n", GetLastError());
479 /* whereas this "fails" because cbSize is wrong.. */
480 SetLastError(0xdeadbeef);
481 ret = pSetupDiCreateDeviceInfoA(set, "LEGACY_BOGUS", &guid, NULL, NULL,
482 DICD_GENERATE_ID, &devInfo);
483 ok(!ret && GetLastError() == ERROR_INVALID_USER_BUFFER,
484 "Expected ERROR_INVALID_USER_BUFFER, got %08x\n", GetLastError());
485 /* and this finally succeeds. */
486 devInfo.cbSize = sizeof(devInfo);
487 ret = pSetupDiCreateDeviceInfoA(set, "LEGACY_BOGUS", &guid, NULL, NULL,
488 DICD_GENERATE_ID, &devInfo);
489 ok(ret, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
490 /* There were three devices added, however - the second failure just
491 * resulted in the SP_DEVINFO_DATA not getting copied.
493 SetLastError(0xdeadbeef);
494 i = 0;
495 while (pSetupDiEnumDeviceInfo(set, i, &devInfo))
496 i++;
497 ok(i == 3, "Expected 3 devices, got %d\n", i);
498 ok(GetLastError() == ERROR_NO_MORE_ITEMS,
499 "SetupDiEnumDeviceInfo failed: %08x\n", GetLastError());
500 pSetupDiDestroyDeviceInfoList(set);
503 /* The bogus registry key shouldn't be there after this test. The only
504 * reasons this key would still be present:
506 * - We are running on Wine which has to be fixed
507 * - We have leftovers from old tests
509 res = RegOpenKeyW(HKEY_LOCAL_MACHINE, bogus, &key);
510 todo_wine
511 ok(res == ERROR_FILE_NOT_FOUND, "Expected key to not exist\n");
512 if (res == ERROR_SUCCESS)
514 DWORD subkeys;
516 /* Check if we have subkeys */
517 RegQueryInfoKey(key, NULL, NULL, NULL, &subkeys, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
518 if (subkeys > 0)
520 int i;
522 /* Leftovers from old tests */
523 trace("Going to remove %d devices\n", subkeys);
524 for (i = 0; i < subkeys; i++)
526 BOOL ret;
528 ret = remove_device();
529 ok(ret, "Expected a device to be removed\n");
532 else
534 /* Wine doesn't delete the bogus key itself currently */
535 trace("We are most likely on Wine\n");
536 RegDeleteKeyW(HKEY_LOCAL_MACHINE, bogus);
541 static void testGetDeviceInstanceId(void)
543 BOOL ret;
544 HDEVINFO set;
545 SP_DEVINFO_DATA devInfo = { 0 };
547 SetLastError(0xdeadbeef);
548 ret = pSetupDiGetDeviceInstanceIdA(NULL, NULL, NULL, 0, NULL);
549 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
550 "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
551 SetLastError(0xdeadbeef);
552 ret = pSetupDiGetDeviceInstanceIdA(NULL, &devInfo, NULL, 0, NULL);
553 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
554 "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
555 set = pSetupDiCreateDeviceInfoList(&guid, NULL);
556 ok(set != NULL, "SetupDiCreateDeviceInfoList failed: %08x\n",
557 GetLastError());
558 if (set)
560 char instanceID[MAX_PATH];
561 DWORD size;
563 SetLastError(0xdeadbeef);
564 ret = pSetupDiGetDeviceInstanceIdA(set, NULL, NULL, 0, NULL);
565 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
566 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
567 SetLastError(0xdeadbeef);
568 ret = pSetupDiGetDeviceInstanceIdA(set, &devInfo, NULL, 0, NULL);
569 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
570 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
571 SetLastError(0xdeadbeef);
572 ret = pSetupDiGetDeviceInstanceIdA(set, &devInfo, NULL, 0, &size);
573 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
574 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
575 devInfo.cbSize = sizeof(devInfo);
576 SetLastError(0xdeadbeef);
577 ret = pSetupDiGetDeviceInstanceIdA(set, &devInfo, NULL, 0, &size);
578 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
579 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
580 ret = pSetupDiCreateDeviceInfoA(set, "Root\\LEGACY_BOGUS\\0000", &guid,
581 NULL, NULL, 0, &devInfo);
582 ok(ret, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
583 SetLastError(0xdeadbeef);
584 ret = pSetupDiGetDeviceInstanceIdA(set, &devInfo, NULL, 0, &size);
585 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
586 "Expected ERROR_INSUFFICIENT_BUFFER, got %08x\n", GetLastError());
587 ret = pSetupDiGetDeviceInstanceIdA(set, &devInfo, instanceID,
588 sizeof(instanceID), NULL);
589 ok(ret, "SetupDiGetDeviceInstanceIdA failed: %08x\n", GetLastError());
590 ok(!lstrcmpA(instanceID, "ROOT\\LEGACY_BOGUS\\0000"),
591 "Unexpected instance ID %s\n", instanceID);
592 ret = pSetupDiCreateDeviceInfoA(set, "LEGACY_BOGUS", &guid,
593 NULL, NULL, DICD_GENERATE_ID, &devInfo);
594 ok(ret, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
595 ret = pSetupDiGetDeviceInstanceIdA(set, &devInfo, instanceID,
596 sizeof(instanceID), NULL);
597 ok(ret, "SetupDiGetDeviceInstanceIdA failed: %08x\n", GetLastError());
598 /* NT4 returns 'Root' and W2K and above 'ROOT' */
599 ok(!lstrcmpiA(instanceID, "ROOT\\LEGACY_BOGUS\\0001"),
600 "Unexpected instance ID %s\n", instanceID);
601 pSetupDiDestroyDeviceInfoList(set);
605 static void testRegisterDeviceInfo(void)
607 BOOL ret;
608 HDEVINFO set;
610 SetLastError(0xdeadbeef);
611 ret = pSetupDiRegisterDeviceInfo(NULL, NULL, 0, NULL, NULL, NULL);
612 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
613 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
614 set = pSetupDiCreateDeviceInfoList(&guid, NULL);
615 ok(set != NULL, "SetupDiCreateDeviceInfoList failed: %d\n", GetLastError());
616 if (set)
618 SP_DEVINFO_DATA devInfo = { 0 };
620 SetLastError(0xdeadbeef);
621 ret = pSetupDiRegisterDeviceInfo(set, NULL, 0, NULL, NULL, NULL);
622 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
623 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
624 SetLastError(0xdeadbeef);
625 ret = pSetupDiRegisterDeviceInfo(set, &devInfo, 0, NULL, NULL, NULL);
626 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
627 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
628 devInfo.cbSize = sizeof(devInfo);
629 SetLastError(0xdeadbeef);
630 ret = pSetupDiRegisterDeviceInfo(set, &devInfo, 0, NULL, NULL, NULL);
631 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
632 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
633 ret = pSetupDiCreateDeviceInfoA(set, "USB\\BOGUS\\0000", &guid,
634 NULL, NULL, 0, &devInfo);
635 ok(ret || GetLastError() == ERROR_DEVINST_ALREADY_EXISTS,
636 "SetupDiCreateDeviceInfoA failed: %d\n", GetLastError());
637 if (ret)
639 /* If it already existed, registering it again will fail */
640 ret = pSetupDiRegisterDeviceInfo(set, &devInfo, 0, NULL, NULL,
641 NULL);
642 ok(ret, "SetupDiCreateDeviceInfoA failed: %d\n", GetLastError());
644 /* FIXME: On Win2K+ systems, this is now persisted to registry in
645 * HKLM\System\CCS\Enum\USB\Bogus\0000.
646 * FIXME: the key also becomes undeletable. How to get rid of it?
648 pSetupDiDestroyDeviceInfoList(set);
652 static void testCreateDeviceInterface(void)
654 BOOL ret;
655 HDEVINFO set;
656 HKEY key;
657 static const WCHAR bogus[] = {'S','y','s','t','e','m','\\',
658 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
659 'E','n','u','m','\\','R','o','o','t','\\',
660 'L','E','G','A','C','Y','_','B','O','G','U','S',0};
661 static const WCHAR devclass[] = {'S','y','s','t','e','m','\\',
662 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
663 'C','o','n','t','r','o','l','\\','D','e','v','i','c','e','C','l','a','s','s','e','s','\\',
664 '{','6','a','5','5','b','5','a','4','-','3','f','6','5','-',
665 '1','1','d','b','-','b','7','0','4','-',
666 '0','0','1','1','9','5','5','c','2','b','d','b','}',0};
668 if (!pSetupDiCreateDeviceInterfaceA || !pSetupDiEnumDeviceInterfaces)
670 skip("SetupDiCreateDeviceInterfaceA and/or SetupDiEnumDeviceInterfaces are not available\n");
671 return;
673 SetLastError(0xdeadbeef);
674 ret = pSetupDiCreateDeviceInterfaceA(NULL, NULL, NULL, NULL, 0, NULL);
675 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
676 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
677 SetLastError(0xdeadbeef);
678 ret = pSetupDiCreateDeviceInterfaceA(NULL, NULL, &guid, NULL, 0, NULL);
679 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
680 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
681 set = pSetupDiCreateDeviceInfoList(&guid, NULL);
682 ok(set != NULL, "SetupDiCreateDeviceInfoList failed: %d\n", GetLastError());
683 if (set)
685 SP_DEVINFO_DATA devInfo = { 0 };
686 SP_DEVICE_INTERFACE_DATA interfaceData = { sizeof(interfaceData),
687 { 0 } };
688 DWORD i;
690 SetLastError(0xdeadbeef);
691 ret = pSetupDiCreateDeviceInterfaceA(set, NULL, NULL, NULL, 0, NULL);
692 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
693 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
694 SetLastError(0xdeadbeef);
695 ret = pSetupDiCreateDeviceInterfaceA(set, &devInfo, NULL, NULL, 0,
696 NULL);
697 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
698 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
699 devInfo.cbSize = sizeof(devInfo);
700 ret = pSetupDiCreateDeviceInfoA(set, "ROOT\\LEGACY_BOGUS\\0000", &guid,
701 NULL, NULL, 0, &devInfo);
702 ok(ret, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
703 SetLastError(0xdeadbeef);
704 ret = pSetupDiCreateDeviceInterfaceA(set, &devInfo, NULL, NULL, 0,
705 NULL);
706 ok(!ret && GetLastError() == ERROR_INVALID_USER_BUFFER,
707 "Expected ERROR_INVALID_USER_BUFFER, got %08x\n", GetLastError());
708 ret = pSetupDiCreateDeviceInterfaceA(set, &devInfo, &guid, NULL, 0,
709 NULL);
710 ok(ret, "SetupDiCreateDeviceInterfaceA failed: %08x\n", GetLastError());
711 /* Creating the same interface a second time succeeds */
712 ret = pSetupDiCreateDeviceInterfaceA(set, &devInfo, &guid, NULL, 0,
713 NULL);
714 ok(ret, "SetupDiCreateDeviceInterfaceA failed: %08x\n", GetLastError());
715 ret = pSetupDiCreateDeviceInterfaceA(set, &devInfo, &guid, "Oogah", 0,
716 NULL);
717 ok(ret, "SetupDiCreateDeviceInterfaceA failed: %08x\n", GetLastError());
718 ret = pSetupDiEnumDeviceInterfaces(set, &devInfo, &guid, 0,
719 &interfaceData);
720 ok(ret, "SetupDiEnumDeviceInterfaces failed: %d\n", GetLastError());
721 i = 0;
722 while (pSetupDiEnumDeviceInterfaces(set, &devInfo, &guid, i,
723 &interfaceData))
724 i++;
725 ok(i == 2, "expected 2 interfaces, got %d\n", i);
726 ok(GetLastError() == ERROR_NO_MORE_ITEMS,
727 "SetupDiEnumDeviceInterfaces failed: %08x\n", GetLastError());
728 ret = pSetupDiDestroyDeviceInfoList(set);
729 ok(ret, "SetupDiDestroyDeviceInfoList failed: %08x\n", GetLastError());
731 /* Cleanup */
732 /* FIXME: On Wine we still have the bogus entry in Enum\Root and
733 * subkeys, as well as the deviceclass key with subkeys.
734 * Only clean the deviceclass key once Wine if fixed.
736 if (!RegOpenKeyW(HKEY_LOCAL_MACHINE, bogus, &key))
738 /* Wine doesn't delete the information currently */
739 trace("We are most likely on Wine\n");
740 devinst_RegDeleteTreeW(HKEY_LOCAL_MACHINE, bogus);
741 devinst_RegDeleteTreeW(HKEY_LOCAL_MACHINE, devclass);
743 else
745 clean_devclass_key();
750 static void testGetDeviceInterfaceDetail(void)
752 BOOL ret;
753 HDEVINFO set;
754 static const WCHAR bogus[] = {'S','y','s','t','e','m','\\',
755 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
756 'E','n','u','m','\\','R','o','o','t','\\',
757 'L','E','G','A','C','Y','_','B','O','G','U','S',0};
758 static const WCHAR devclass[] = {'S','y','s','t','e','m','\\',
759 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
760 'C','o','n','t','r','o','l','\\','D','e','v','i','c','e','C','l','a','s','s','e','s','\\',
761 '{','6','a','5','5','b','5','a','4','-','3','f','6','5','-',
762 '1','1','d','b','-','b','7','0','4','-',
763 '0','0','1','1','9','5','5','c','2','b','d','b','}',0};
765 if (!pSetupDiCreateDeviceInterfaceA || !pSetupDiGetDeviceInterfaceDetailA)
767 skip("SetupDiCreateDeviceInterfaceA and/or SetupDiGetDeviceInterfaceDetailA are not available\n");
768 return;
770 SetLastError(0xdeadbeef);
771 ret = pSetupDiGetDeviceInterfaceDetailA(NULL, NULL, NULL, 0, NULL, NULL);
772 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
773 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
774 set = pSetupDiCreateDeviceInfoList(&guid, NULL);
775 ok(set != NULL, "SetupDiCreateDeviceInfoList failed: %d\n", GetLastError());
776 if (set)
778 SP_DEVINFO_DATA devInfo = { sizeof(devInfo), { 0 } };
779 SP_DEVICE_INTERFACE_DATA interfaceData = { sizeof(interfaceData),
780 { 0 } };
781 DWORD size = 0;
782 HKEY key;
784 SetLastError(0xdeadbeef);
785 ret = pSetupDiGetDeviceInterfaceDetailA(set, NULL, NULL, 0, NULL,
786 NULL);
787 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
788 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
789 ret = pSetupDiCreateDeviceInfoA(set, "ROOT\\LEGACY_BOGUS\\0000", &guid,
790 NULL, NULL, 0, &devInfo);
791 ok(ret, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
792 SetLastError(0xdeadbeef);
793 ret = pSetupDiCreateDeviceInterfaceA(set, &devInfo, &guid, NULL, 0,
794 &interfaceData);
795 ok(ret, "SetupDiCreateDeviceInterfaceA failed: %08x\n", GetLastError());
796 SetLastError(0xdeadbeef);
797 ret = pSetupDiGetDeviceInterfaceDetailA(set, &interfaceData, NULL,
798 0, NULL, NULL);
799 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
800 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
801 SetLastError(0xdeadbeef);
802 ret = pSetupDiGetDeviceInterfaceDetailA(set, &interfaceData, NULL,
803 100, NULL, NULL);
804 ok(!ret && GetLastError() == ERROR_INVALID_USER_BUFFER,
805 "Expected ERROR_INVALID_USER_BUFFER, got %08x\n", GetLastError());
806 SetLastError(0xdeadbeef);
807 ret = pSetupDiGetDeviceInterfaceDetailA(set, &interfaceData, NULL,
808 0, &size, NULL);
809 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
810 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
811 if (!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER)
813 static const char path[] =
814 "\\\\?\\root#legacy_bogus#0000#{6a55b5a4-3f65-11db-b704-0011955c2bdb}";
815 static const char path_w2k[] =
816 "\\\\?\\root#legacy_bogus#0000#{6a55b5a4-3f65-11db-b704-0011955c2bdb}\\";
817 LPBYTE buf = HeapAlloc(GetProcessHeap(), 0, size);
818 SP_DEVICE_INTERFACE_DETAIL_DATA_A *detail =
819 (SP_DEVICE_INTERFACE_DETAIL_DATA_A *)buf;
820 DWORD expectedsize = FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_W, DevicePath) + sizeof(WCHAR)*(1 + strlen(path));
822 detail->cbSize = 0;
823 SetLastError(0xdeadbeef);
824 ret = pSetupDiGetDeviceInterfaceDetailA(set, &interfaceData, detail,
825 size, &size, NULL);
826 ok(!ret && GetLastError() == ERROR_INVALID_USER_BUFFER,
827 "Expected ERROR_INVALID_USER_BUFFER, got %08x\n", GetLastError());
828 detail->cbSize = size;
829 SetLastError(0xdeadbeef);
830 ret = pSetupDiGetDeviceInterfaceDetailA(set, &interfaceData, detail,
831 size, &size, NULL);
832 ok(!ret && GetLastError() == ERROR_INVALID_USER_BUFFER,
833 "Expected ERROR_INVALID_USER_BUFFER, got %08x\n", GetLastError());
834 detail->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_A);
835 SetLastError(0xdeadbeef);
836 ret = pSetupDiGetDeviceInterfaceDetailA(set, &interfaceData, detail,
837 size, &size, NULL);
838 ok(!ret && GetLastError() == ERROR_INVALID_USER_BUFFER,
839 "Expected ERROR_INVALID_USER_BUFFER, got %08x\n", GetLastError());
840 /* Windows 2000 and up check for the exact size */
841 detail->cbSize = FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_A, DevicePath[1]);
842 ret = pSetupDiGetDeviceInterfaceDetailA(set, &interfaceData, detail,
843 size, &size, NULL);
844 ok(ret, "SetupDiGetDeviceInterfaceDetailA failed: %d\n",
845 GetLastError());
846 ok(!lstrcmpiA(path, detail->DevicePath) ||
847 !lstrcmpiA(path_w2k, detail->DevicePath), "Unexpected path %s\n",
848 detail->DevicePath);
849 /* Check SetupDiGetDeviceInterfaceDetailW */
850 ret = pSetupDiGetDeviceInterfaceDetailW(set, &interfaceData, NULL, 0, &size, NULL);
851 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
852 "Expected ERROR_INSUFFICIENT_BUFFER, got error code: %d\n", GetLastError());
853 ok(expectedsize == size ||
854 (expectedsize + sizeof(WCHAR)) == size /* W2K adds a backslash */,
855 "SetupDiGetDeviceInterfaceDetailW returned wrong reqsize, got %d\n",
856 size);
858 HeapFree(GetProcessHeap(), 0, buf);
860 pSetupDiDestroyDeviceInfoList(set);
862 /* Cleanup */
863 /* FIXME: On Wine we still have the bogus entry in Enum\Root and
864 * subkeys, as well as the deviceclass key with subkeys.
865 * Only do the RegDeleteKey, once Wine is fixed.
867 if (!RegOpenKeyW(HKEY_LOCAL_MACHINE, bogus, &key))
869 /* Wine doesn't delete the information currently */
870 trace("We are most likely on Wine\n");
871 devinst_RegDeleteTreeW(HKEY_LOCAL_MACHINE, bogus);
872 devinst_RegDeleteTreeW(HKEY_LOCAL_MACHINE, devclass);
874 else
876 clean_devclass_key();
881 static void testDevRegKey(void)
883 static const WCHAR classKey[] = {'S','y','s','t','e','m','\\',
884 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
885 'C','o','n','t','r','o','l','\\','C','l','a','s','s','\\',
886 '{','6','a','5','5','b','5','a','4','-','3','f','6','5','-',
887 '1','1','d','b','-','b','7','0','4','-',
888 '0','0','1','1','9','5','5','c','2','b','d','b','}',0};
889 static const WCHAR bogus[] = {'S','y','s','t','e','m','\\',
890 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
891 'E','n','u','m','\\','R','o','o','t','\\',
892 'L','E','G','A','C','Y','_','B','O','G','U','S',0};
893 BOOL ret;
894 HDEVINFO set;
895 HKEY key = NULL;
897 SetLastError(0xdeadbeef);
898 key = pSetupDiCreateDevRegKeyW(NULL, NULL, 0, 0, 0, NULL, NULL);
899 ok(key == INVALID_HANDLE_VALUE,
900 "Expected INVALID_HANDLE_VALUE, got %p\n", key);
901 ok(GetLastError() == ERROR_INVALID_HANDLE,
902 "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
904 set = pSetupDiCreateDeviceInfoList(&guid, NULL);
905 ok(set != NULL, "SetupDiCreateDeviceInfoList failed: %d\n", GetLastError());
906 if (set)
908 SP_DEVINFO_DATA devInfo = { sizeof(devInfo), { 0 } };
909 LONG res;
911 /* The device info key shouldn't be there */
912 res = RegOpenKeyW(HKEY_LOCAL_MACHINE, bogus, &key);
913 ok(res != ERROR_SUCCESS, "Expected key to not exist\n");
914 RegCloseKey(key);
915 /* Create the device information */
916 ret = pSetupDiCreateDeviceInfoA(set, "ROOT\\LEGACY_BOGUS\\0000", &guid,
917 NULL, NULL, 0, &devInfo);
918 ok(ret, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
919 /* The device info key should have been created */
920 ok(!RegOpenKeyW(HKEY_LOCAL_MACHINE, bogus, &key),
921 "Expected registry key to exist\n");
922 RegCloseKey(key);
923 SetLastError(0xdeadbeef);
924 key = pSetupDiOpenDevRegKey(NULL, NULL, 0, 0, 0, 0);
925 ok(!key || key == INVALID_HANDLE_VALUE,
926 "Expected INVALID_HANDLE_VALUE or a NULL key (NT4)\n");
927 ok(GetLastError() == ERROR_INVALID_HANDLE,
928 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
929 SetLastError(0xdeadbeef);
930 key = pSetupDiOpenDevRegKey(set, NULL, 0, 0, 0, 0);
931 ok(key == INVALID_HANDLE_VALUE &&
932 GetLastError() == ERROR_INVALID_PARAMETER,
933 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
934 SetLastError(0xdeadbeef);
935 key = pSetupDiOpenDevRegKey(set, &devInfo, 0, 0, 0, 0);
936 ok(key == INVALID_HANDLE_VALUE &&
937 GetLastError() == ERROR_INVALID_FLAGS,
938 "Expected ERROR_INVALID_FLAGS, got %d\n", GetLastError());
939 SetLastError(0xdeadbeef);
940 key = pSetupDiOpenDevRegKey(set, &devInfo, DICS_FLAG_GLOBAL, 0, 0, 0);
941 ok(key == INVALID_HANDLE_VALUE &&
942 GetLastError() == ERROR_INVALID_FLAGS,
943 "Expected ERROR_INVALID_FLAGS, got %d\n", GetLastError());
944 SetLastError(0xdeadbeef);
945 key = pSetupDiOpenDevRegKey(set, &devInfo, DICS_FLAG_GLOBAL, 0,
946 DIREG_BOTH, 0);
947 ok(key == INVALID_HANDLE_VALUE &&
948 GetLastError() == ERROR_INVALID_FLAGS,
949 "Expected ERROR_INVALID_FLAGS, got %d\n", GetLastError());
950 SetLastError(0xdeadbeef);
951 key = pSetupDiOpenDevRegKey(set, &devInfo, DICS_FLAG_GLOBAL, 0,
952 DIREG_DRV, 0);
953 ok(key == INVALID_HANDLE_VALUE &&
954 GetLastError() == ERROR_DEVINFO_NOT_REGISTERED,
955 "Expected ERROR_DEVINFO_NOT_REGISTERED, got %08x\n", GetLastError());
956 SetLastError(0xdeadbeef);
957 ret = pSetupDiRegisterDeviceInfo(set, &devInfo, 0, NULL, NULL, NULL);
958 ok(ret, "SetupDiRegisterDeviceInfo failed: %08x\n", GetLastError());
959 SetLastError(0xdeadbeef);
960 key = pSetupDiOpenDevRegKey(set, &devInfo, DICS_FLAG_GLOBAL, 0,
961 DIREG_DRV, 0);
962 /* The software key isn't created by default */
963 todo_wine
964 ok(key == INVALID_HANDLE_VALUE &&
965 GetLastError() == ERROR_KEY_DOES_NOT_EXIST,
966 "Expected ERROR_KEY_DOES_NOT_EXIST, got %08x\n", GetLastError());
967 SetLastError(0xdeadbeef);
968 key = pSetupDiOpenDevRegKey(set, &devInfo, DICS_FLAG_GLOBAL, 0,
969 DIREG_DEV, 0);
970 todo_wine
971 ok(key == INVALID_HANDLE_VALUE &&
972 GetLastError() == ERROR_KEY_DOES_NOT_EXIST,
973 "Expected ERROR_KEY_DOES_NOT_EXIST, got %08x\n", GetLastError());
974 SetLastError(0xdeadbeef);
975 /* The class key shouldn't be there */
976 res = RegOpenKeyW(HKEY_LOCAL_MACHINE, classKey, &key);
977 todo_wine
978 ok(res != ERROR_SUCCESS, "Expected key to not exist\n");
979 RegCloseKey(key);
980 /* Create the device reg key */
981 key = pSetupDiCreateDevRegKeyW(set, &devInfo, DICS_FLAG_GLOBAL, 0,
982 DIREG_DRV, NULL, NULL);
983 ok(key != INVALID_HANDLE_VALUE, "SetupDiCreateDevRegKey failed: %08x\n",
984 GetLastError());
985 RegCloseKey(key);
986 /* The class key should have been created */
987 ok(!RegOpenKeyW(HKEY_LOCAL_MACHINE, classKey, &key),
988 "Expected registry key to exist\n");
989 RegCloseKey(key);
990 SetLastError(0xdeadbeef);
991 key = pSetupDiOpenDevRegKey(set, &devInfo, DICS_FLAG_GLOBAL, 0,
992 DIREG_DRV, 0);
993 todo_wine
994 ok(key == INVALID_HANDLE_VALUE &&
995 (GetLastError() == ERROR_INVALID_DATA ||
996 GetLastError() == ERROR_ACCESS_DENIED), /* win2k3 */
997 "Expected ERROR_INVALID_DATA or ERROR_ACCESS_DENIED, got %08x\n", GetLastError());
998 key = pSetupDiOpenDevRegKey(set, &devInfo, DICS_FLAG_GLOBAL, 0,
999 DIREG_DRV, KEY_READ);
1000 ok(key != INVALID_HANDLE_VALUE, "SetupDiOpenDevRegKey failed: %08x\n",
1001 GetLastError());
1002 pSetupDiDestroyDeviceInfoList(set);
1004 /* Cleanup */
1005 ret = remove_device();
1006 todo_wine
1007 ok(ret, "Expected the device to be removed: %08x\n", GetLastError());
1009 /* FIXME: Only do the RegDeleteKey, once Wine is fixed */
1010 if (!ret)
1012 /* Wine doesn't delete the information currently */
1013 trace("We are most likely on Wine\n");
1014 devinst_RegDeleteTreeW(HKEY_LOCAL_MACHINE, bogus);
1015 devinst_RegDeleteTreeW(HKEY_LOCAL_MACHINE, classKey);
1017 else
1019 /* There should only be a class key entry, so a simple
1020 * RegDeleteKey should work
1022 * This could fail if it's the first time for this new test
1023 * after running the old tests.
1025 ok(!RegDeleteKeyW(HKEY_LOCAL_MACHINE, classKey),
1026 "Couldn't delete classkey\n");
1031 static void testRegisterAndGetDetail(void)
1033 HDEVINFO set;
1034 BOOL ret;
1035 SP_DEVINFO_DATA devInfo = { sizeof(SP_DEVINFO_DATA), { 0 } };
1036 SP_DEVICE_INTERFACE_DATA interfaceData = { sizeof(interfaceData), { 0 } };
1037 DWORD dwSize = 0;
1038 static const WCHAR bogus[] = {'S','y','s','t','e','m','\\',
1039 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
1040 'E','n','u','m','\\','R','o','o','t','\\',
1041 'L','E','G','A','C','Y','_','B','O','G','U','S',0};
1042 static const WCHAR devclass[] = {'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 'C','o','n','t','r','o','l','\\','D','e','v','i','c','e','C','l','a','s','s','e','s','\\',
1045 '{','6','a','5','5','b','5','a','4','-','3','f','6','5','-',
1046 '1','1','d','b','-','b','7','0','4','-',
1047 '0','0','1','1','9','5','5','c','2','b','d','b','}',0};
1049 if (!pSetupDiCreateDeviceInterfaceA || !pSetupDiEnumDeviceInterfaces ||
1050 !pSetupDiGetDeviceInterfaceDetailA)
1052 skip("Needed functions are not available\n");
1053 return;
1056 SetLastError(0xdeadbeef);
1057 set = pSetupDiGetClassDevsA(&guid, NULL, 0, DIGCF_ALLCLASSES);
1058 ok(set != INVALID_HANDLE_VALUE, "SetupDiGetClassDevsA failed: %08x\n",
1059 GetLastError());
1061 SetLastError(0xdeadbeef);
1062 ret = pSetupDiCreateDeviceInfoA(set, "LEGACY_BOGUS", &guid, NULL, 0,
1063 DICD_GENERATE_ID, &devInfo);
1064 ok(ret, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
1065 SetLastError(0xdeadbeef);
1066 ret = pSetupDiCreateDeviceInterfaceA(set, &devInfo, &guid, NULL, 0, &interfaceData);
1067 ok(ret, "SetupDiCreateDeviceInterfaceA failed: %08x\n", GetLastError());
1068 SetLastError(0xdeadbeef);
1069 ret = pSetupDiRegisterDeviceInfo(set, &devInfo, 0, NULL, NULL, NULL);
1070 ok(ret, "SetupDiRegisterDeviceInfo failed: %08x\n", GetLastError());
1072 pSetupDiDestroyDeviceInfoList(set);
1074 SetLastError(0xdeadbeef);
1075 set = pSetupDiGetClassDevsA(&guid, NULL, 0, DIGCF_DEVICEINTERFACE);
1076 ok(set != INVALID_HANDLE_VALUE, "SetupDiGetClassDevsA failed: %08x\n",
1077 GetLastError());
1079 SetLastError(0xdeadbeef);
1080 ret = pSetupDiEnumDeviceInterfaces(set, NULL, &guid, 0, &interfaceData);
1081 ok(ret, "SetupDiEnumDeviceInterfaces failed: %08x\n", GetLastError());
1082 SetLastError(0xdeadbeef);
1083 ret = pSetupDiGetDeviceInterfaceDetailA(set, &interfaceData, NULL, 0, &dwSize, NULL);
1084 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
1085 "Expected ERROR_INSUFFICIENT_BUFFER, got %08x\n", GetLastError());
1086 if (!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER)
1088 static const char path[] =
1089 "\\\\?\\root#legacy_bogus#0000#{6a55b5a4-3f65-11db-b704-0011955c2bdb}";
1090 static const char path_w2k[] =
1091 "\\\\?\\root#legacy_bogus#0000#{6a55b5a4-3f65-11db-b704-0011955c2bdb}\\";
1092 PSP_DEVICE_INTERFACE_DETAIL_DATA_A detail = NULL;
1094 detail = HeapAlloc(GetProcessHeap(), 0, dwSize);
1095 if (detail)
1097 detail->cbSize = FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_A, DevicePath) + sizeof(char);
1098 SetLastError(0xdeadbeef);
1099 ret = pSetupDiGetDeviceInterfaceDetailA(set, &interfaceData,
1100 detail, dwSize, &dwSize, NULL);
1101 ok(ret, "SetupDiGetDeviceInterfaceDetailA failed: %08x\n", GetLastError());
1102 /* FIXME: This one only worked because old data wasn't removed properly. As soon
1103 * as all the tests are cleaned up correctly this has to be (or should be) fixed
1105 todo_wine
1106 ok(!lstrcmpiA(path, detail->DevicePath) ||
1107 !lstrcmpiA(path_w2k, detail->DevicePath), "Unexpected path %s\n",
1108 detail->DevicePath);
1109 HeapFree(GetProcessHeap(), 0, detail);
1113 pSetupDiDestroyDeviceInfoList(set);
1115 /* Cleanup */
1116 ret = remove_device();
1117 todo_wine
1118 ok(ret, "Expected the device to be removed: %08x\n", GetLastError());
1120 /* FIXME: Only do the RegDeleteKey, once Wine is fixed */
1121 if (!ret)
1123 /* Wine doesn't delete the information currently */
1124 trace("We are most likely on Wine\n");
1125 devinst_RegDeleteTreeW(HKEY_LOCAL_MACHINE, bogus);
1126 devinst_RegDeleteTreeW(HKEY_LOCAL_MACHINE, devclass);
1128 else
1130 clean_devclass_key();
1134 static void testDeviceRegistryPropertyA()
1136 HDEVINFO set;
1137 SP_DEVINFO_DATA devInfo = { sizeof(SP_DEVINFO_DATA), { 0 } };
1138 CHAR devName[] = "LEGACY_BOGUS";
1139 CHAR friendlyName[] = "Bogus";
1140 CHAR buf[6] = "";
1141 DWORD buflen = 6;
1142 DWORD size;
1143 DWORD regType;
1144 BOOL ret;
1145 LONG res;
1146 HKEY key;
1147 static const CHAR bogus[] =
1148 "System\\CurrentControlSet\\Enum\\Root\\LEGACY_BOGUS";
1150 SetLastError(0xdeadbeef);
1151 set = pSetupDiGetClassDevsA(&guid, NULL, 0, DIGCF_DEVICEINTERFACE);
1152 ok(set != INVALID_HANDLE_VALUE, "SetupDiGetClassDevsA failed: %08x\n",
1153 GetLastError());
1154 SetLastError(0xdeadbeef);
1155 ret = pSetupDiCreateDeviceInfoA(set, devName, &guid, NULL, NULL,
1156 DICD_GENERATE_ID, &devInfo);
1157 ok(ret, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
1158 SetLastError(0xdeadbeef);
1159 ret = pSetupDiSetDeviceRegistryPropertyA(NULL, NULL, -1, NULL, 0);
1160 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
1161 "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
1162 SetLastError(0xdeadbeef);
1163 ret = pSetupDiSetDeviceRegistryPropertyA(set, NULL, -1, NULL, 0);
1164 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
1165 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
1166 SetLastError(0xdeadbeef);
1167 ret = pSetupDiSetDeviceRegistryPropertyA(set, &devInfo, -1, NULL, 0);
1168 todo_wine
1169 ok(!ret && GetLastError() == ERROR_INVALID_REG_PROPERTY,
1170 "Expected ERROR_INVALID_REG_PROPERTY, got %08x\n", GetLastError());
1171 /* GetLastError() returns nonsense in win2k3 */
1172 ret = pSetupDiSetDeviceRegistryPropertyA(set, &devInfo, SPDRP_FRIENDLYNAME,
1173 NULL, 0);
1174 todo_wine
1175 ok(!ret, "Expected failure, got %d\n", ret);
1176 SetLastError(0xdeadbeef);
1177 ret = pSetupDiSetDeviceRegistryPropertyA(set, &devInfo, SPDRP_FRIENDLYNAME,
1178 (PBYTE)friendlyName, buflen);
1179 ok(ret, "SetupDiSetDeviceRegistryPropertyA failed: %08x\n", GetLastError());
1180 SetLastError(0xdeadbeef);
1181 ret = pSetupDiGetDeviceRegistryPropertyA(NULL, NULL, -1, NULL, NULL, 0, NULL);
1182 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
1183 "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
1184 SetLastError(0xdeadbeef);
1185 ret = pSetupDiGetDeviceRegistryPropertyA(set, NULL, -1, NULL, NULL, 0, NULL);
1186 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
1187 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
1188 SetLastError(0xdeadbeef);
1189 ret = pSetupDiGetDeviceRegistryPropertyA(set, &devInfo, -1, NULL, NULL, 0, NULL);
1190 todo_wine
1191 ok(!ret && GetLastError() == ERROR_INVALID_REG_PROPERTY,
1192 "Expected ERROR_INVALID_REG_PROPERTY, got %08x\n", GetLastError());
1193 /* GetLastError() returns nonsense in win2k3 */
1194 ret = pSetupDiGetDeviceRegistryPropertyA(set, &devInfo, SPDRP_FRIENDLYNAME,
1195 NULL, NULL, buflen, NULL);
1196 ok(!ret, "Expected failure, got %d\n", ret);
1197 SetLastError(0xdeadbeef);
1198 ret = pSetupDiGetDeviceRegistryPropertyA(set, &devInfo, SPDRP_FRIENDLYNAME,
1199 NULL, NULL, 0, &size);
1200 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
1201 "Expected ERROR_INSUFFICIENT_BUFFER, got %08x\n", GetLastError());
1202 ok(buflen == size, "Unexpected size: %d\n", size);
1203 SetLastError(0xdeadbeef);
1204 ret = pSetupDiGetDeviceRegistryPropertyA(set, &devInfo, SPDRP_FRIENDLYNAME,
1205 NULL, (PBYTE)buf, buflen, NULL);
1206 ok(ret, "SetupDiGetDeviceRegistryPropertyA failed: %08x\n", GetLastError());
1207 ok(!lstrcmpiA(friendlyName, buf), "Unexpected property\n");
1208 SetLastError(0xdeadbeef);
1209 ret = pSetupDiGetDeviceRegistryPropertyA(set, &devInfo, SPDRP_FRIENDLYNAME,
1210 &regType, (PBYTE)buf, buflen, NULL);
1211 ok(ret, "SetupDiGetDeviceRegistryPropertyA failed: %08x\n", GetLastError());
1212 ok(!lstrcmpiA(friendlyName, buf), "Unexpected value of property\n");
1213 ok(regType == REG_SZ, "Unexpected type of property: %d\n", regType);
1214 SetLastError(0xdeadbeef);
1215 ret = pSetupDiSetDeviceRegistryPropertyA(set, &devInfo, SPDRP_FRIENDLYNAME,
1216 NULL, 0);
1217 ok(ret, "SetupDiSetDeviceRegistryPropertyA failed: %08x\n", GetLastError());
1218 SetLastError(0xdeadbeef);
1219 ret = pSetupDiGetDeviceRegistryPropertyA(set, &devInfo, SPDRP_FRIENDLYNAME,
1220 NULL, (PBYTE)buf, buflen, &size);
1221 todo_wine
1222 ok(!ret && GetLastError() == ERROR_INVALID_DATA,
1223 "Expected ERROR_INVALID_DATA, got %08x\n", GetLastError());
1224 pSetupDiDestroyDeviceInfoList(set);
1226 res = RegOpenKeyA(HKEY_LOCAL_MACHINE, bogus, &key);
1227 todo_wine
1228 ok(res == ERROR_FILE_NOT_FOUND, "Expected key to not exist\n");
1229 /* FIXME: Remove when Wine is fixed */
1230 if (res == ERROR_SUCCESS)
1232 /* Wine doesn't delete the information currently */
1233 trace("We are most likely on Wine\n");
1234 RegDeleteKeyA(HKEY_LOCAL_MACHINE, bogus);
1238 static void testDeviceRegistryPropertyW()
1240 HDEVINFO set;
1241 SP_DEVINFO_DATA devInfo = { sizeof(SP_DEVINFO_DATA), { 0 } };
1242 WCHAR devName[] = {'L','E','G','A','C','Y','_','B','O','G','U','S',0};
1243 WCHAR friendlyName[] = {'B','o','g','u','s',0};
1244 WCHAR buf[6] = {0};
1245 DWORD buflen = 6 * sizeof(WCHAR);
1246 DWORD size;
1247 DWORD regType;
1248 BOOL ret;
1249 LONG res;
1250 HKEY key;
1251 static const WCHAR bogus[] = {'S','y','s','t','e','m','\\',
1252 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
1253 'E','n','u','m','\\','R','o','o','t','\\',
1254 'L','E','G','A','C','Y','_','B','O','G','U','S',0};
1256 SetLastError(0xdeadbeef);
1257 set = pSetupDiGetClassDevsW(&guid, NULL, 0, DIGCF_DEVICEINTERFACE);
1258 ok(set != INVALID_HANDLE_VALUE, "SetupDiGetClassDevsW failed: %08x\n",
1259 GetLastError());
1260 SetLastError(0xdeadbeef);
1261 ret = pSetupDiCreateDeviceInfoW(set, devName, &guid, NULL, NULL,
1262 DICD_GENERATE_ID, &devInfo);
1263 ok(ret, "SetupDiCreateDeviceInfoW failed: %08x\n", GetLastError());
1264 SetLastError(0xdeadbeef);
1265 ret = pSetupDiSetDeviceRegistryPropertyW(NULL, NULL, -1, NULL, 0);
1266 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
1267 "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
1268 SetLastError(0xdeadbeef);
1269 ret = pSetupDiSetDeviceRegistryPropertyW(set, NULL, -1, NULL, 0);
1270 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
1271 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
1272 SetLastError(0xdeadbeef);
1273 ret = pSetupDiSetDeviceRegistryPropertyW(set, &devInfo, -1, NULL, 0);
1274 todo_wine
1275 ok(!ret && GetLastError() == ERROR_INVALID_REG_PROPERTY,
1276 "Expected ERROR_INVALID_REG_PROPERTY, got %08x\n", GetLastError());
1277 /* GetLastError() returns nonsense in win2k3 */
1278 ret = pSetupDiSetDeviceRegistryPropertyW(set, &devInfo, SPDRP_FRIENDLYNAME,
1279 NULL, 0);
1280 todo_wine
1281 ok(!ret, "Expected failure, got %d\n", ret);
1282 SetLastError(0xdeadbeef);
1283 ret = pSetupDiSetDeviceRegistryPropertyW(set, &devInfo, SPDRP_FRIENDLYNAME,
1284 (PBYTE)friendlyName, buflen);
1285 ok(ret, "SetupDiSetDeviceRegistryPropertyW failed: %08x\n", GetLastError());
1286 SetLastError(0xdeadbeef);
1287 ret = pSetupDiGetDeviceRegistryPropertyW(NULL, NULL, -1, NULL, NULL, 0, NULL);
1288 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
1289 "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
1290 SetLastError(0xdeadbeef);
1291 ret = pSetupDiGetDeviceRegistryPropertyW(set, NULL, -1, NULL, NULL, 0, NULL);
1292 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
1293 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
1294 SetLastError(0xdeadbeef);
1295 ret = pSetupDiGetDeviceRegistryPropertyW(set, &devInfo, -1, NULL, NULL, 0, NULL);
1296 todo_wine
1297 ok(!ret && GetLastError() == ERROR_INVALID_REG_PROPERTY,
1298 "Expected ERROR_INVALID_REG_PROPERTY, got %08x\n", GetLastError());
1299 /* GetLastError() returns nonsense in win2k3 */
1300 ret = pSetupDiGetDeviceRegistryPropertyW(set, &devInfo, SPDRP_FRIENDLYNAME,
1301 NULL, NULL, buflen, NULL);
1302 ok(!ret, "Expected failure, got %d\n", ret);
1303 SetLastError(0xdeadbeef);
1304 ret = pSetupDiGetDeviceRegistryPropertyW(set, &devInfo, SPDRP_FRIENDLYNAME,
1305 NULL, NULL, 0, &size);
1306 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
1307 "Expected ERROR_INSUFFICIENT_BUFFER, got %08x\n", GetLastError());
1308 ok(buflen == size, "Unexpected size: %d\n", size);
1309 SetLastError(0xdeadbeef);
1310 ret = pSetupDiGetDeviceRegistryPropertyW(set, &devInfo, SPDRP_FRIENDLYNAME,
1311 NULL, (PBYTE)buf, buflen, NULL);
1312 ok(ret, "SetupDiGetDeviceRegistryPropertyW failed: %08x\n", GetLastError());
1313 ok(!lstrcmpiW(friendlyName, buf), "Unexpected property\n");
1314 SetLastError(0xdeadbeef);
1315 ret = pSetupDiGetDeviceRegistryPropertyW(set, &devInfo, SPDRP_FRIENDLYNAME,
1316 &regType, (PBYTE)buf, buflen, NULL);
1317 ok(ret, "SetupDiGetDeviceRegistryPropertyW failed: %08x\n", GetLastError());
1318 ok(!lstrcmpiW(friendlyName, buf), "Unexpected value of property\n");
1319 ok(regType == REG_SZ, "Unexpected type of property: %d\n", regType);
1320 SetLastError(0xdeadbeef);
1321 ret = pSetupDiSetDeviceRegistryPropertyW(set, &devInfo, SPDRP_FRIENDLYNAME,
1322 NULL, 0);
1323 ok(ret, "SetupDiSetDeviceRegistryPropertyW failed: %08x\n", GetLastError());
1324 SetLastError(0xdeadbeef);
1325 ret = pSetupDiGetDeviceRegistryPropertyW(set, &devInfo, SPDRP_FRIENDLYNAME,
1326 NULL, (PBYTE)buf, buflen, &size);
1327 todo_wine
1328 ok(!ret && GetLastError() == ERROR_INVALID_DATA,
1329 "Expected ERROR_INVALID_DATA, got %08x\n", GetLastError());
1330 pSetupDiDestroyDeviceInfoList(set);
1332 res = RegOpenKeyW(HKEY_LOCAL_MACHINE, bogus, &key);
1333 todo_wine
1334 ok(res == ERROR_FILE_NOT_FOUND, "Expected key to not exist\n");
1335 /* FIXME: Remove when Wine is fixed */
1336 if (res == ERROR_SUCCESS)
1338 /* Wine doesn't delete the information currently */
1339 trace("We are most likely on Wine\n");
1340 RegDeleteKeyW(HKEY_LOCAL_MACHINE, bogus);
1344 START_TEST(devinst)
1346 HDEVINFO set;
1348 init_function_pointers();
1350 /* Win9x/WinMe does things totally different so we skip all the tests
1352 * We don't want to exclude NT4 so hence this check.
1354 SetLastError(0xdeadbeef);
1355 set = pSetupDiGetClassDevsW(NULL, NULL, 0, 0);
1356 if (set == INVALID_HANDLE_VALUE && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1358 skip("Win9x/WinMe has totally different behavior\n");
1359 return;
1362 if (pSetupDiCreateDeviceInfoListExW)
1363 test_SetupDiCreateDeviceInfoListEx();
1364 else
1365 skip("SetupDiCreateDeviceInfoListExW is not available\n");
1367 if (pSetupDiOpenClassRegKeyExA)
1368 test_SetupDiOpenClassRegKeyExA();
1369 else
1370 skip("SetupDiOpenClassRegKeyExA is not available\n");
1372 testInstallClass();
1373 testCreateDeviceInfo();
1374 testGetDeviceInstanceId();
1375 testRegisterDeviceInfo();
1376 testCreateDeviceInterface();
1377 testGetDeviceInterfaceDetail();
1378 testDevRegKey();
1379 testRegisterAndGetDetail();
1380 testDeviceRegistryPropertyA();
1381 testDeviceRegistryPropertyW();