setupapi/tests: Cleanup after testDevRegKey.
[wine/gsoc_dplay.git] / dlls / setupapi / tests / devinst.c
blob0078dfbf1b9cd958dcd6398c9d08753e7139c1d1
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 BOOL remove_device(void)
94 HDEVINFO set;
95 SP_DEVINFO_DATA devInfo = { sizeof(devInfo), { 0 } };
96 BOOL ret;
98 SetLastError(0xdeadbeef);
99 set = pSetupDiGetClassDevsA(&guid, NULL, 0, 0);
100 ok(set != INVALID_HANDLE_VALUE, "SetupDiGetClassDevsA failed: %08x\n",
101 GetLastError());
103 SetLastError(0xdeadbeef);
104 ok(pSetupDiEnumDeviceInfo(set, 0, &devInfo),
105 "SetupDiEnumDeviceInfo failed: %08x\n", GetLastError());
107 SetLastError(0xdeadbeef);
108 ret = pSetupDiCallClassInstaller(DIF_REMOVE, set, &devInfo);
109 todo_wine
110 ok(ret, "SetupDiCallClassInstaller(DIF_REMOVE...) failed: %08x\n", GetLastError());
112 SetLastError(0xdeadbeef);
113 ok(pSetupDiDestroyDeviceInfoList(set),
114 "SetupDiDestroyDeviceInfoList failed: %08x\n", GetLastError());
116 return ret;
119 /* RegDeleteTreeW from dlls/advapi32/registry.c */
120 LSTATUS WINAPI devinst_RegDeleteTreeW(HKEY hKey, LPCWSTR lpszSubKey)
122 LONG ret;
123 DWORD dwMaxSubkeyLen, dwMaxValueLen;
124 DWORD dwMaxLen, dwSize;
125 WCHAR szNameBuf[MAX_PATH], *lpszName = szNameBuf;
126 HKEY hSubKey = hKey;
128 if(lpszSubKey)
130 ret = RegOpenKeyExW(hKey, lpszSubKey, 0, KEY_READ, &hSubKey);
131 if (ret) return ret;
134 /* Get highest length for keys, values */
135 ret = RegQueryInfoKeyW(hSubKey, NULL, NULL, NULL, NULL,
136 &dwMaxSubkeyLen, NULL, NULL, &dwMaxValueLen, NULL, NULL, NULL);
137 if (ret) goto cleanup;
139 dwMaxSubkeyLen++;
140 dwMaxValueLen++;
141 dwMaxLen = max(dwMaxSubkeyLen, dwMaxValueLen);
142 if (dwMaxLen > sizeof(szNameBuf)/sizeof(WCHAR))
144 /* Name too big: alloc a buffer for it */
145 if (!(lpszName = HeapAlloc( GetProcessHeap(), 0, dwMaxLen*sizeof(WCHAR))))
147 ret = ERROR_NOT_ENOUGH_MEMORY;
148 goto cleanup;
153 /* Recursively delete all the subkeys */
154 while (TRUE)
156 dwSize = dwMaxLen;
157 if (RegEnumKeyExW(hSubKey, 0, lpszName, &dwSize, NULL,
158 NULL, NULL, NULL)) break;
160 ret = devinst_RegDeleteTreeW(hSubKey, lpszName);
161 if (ret) goto cleanup;
164 if (lpszSubKey)
165 ret = RegDeleteKeyW(hKey, lpszSubKey);
166 else
167 while (TRUE)
169 dwSize = dwMaxLen;
170 if (RegEnumValueW(hKey, 0, lpszName, &dwSize,
171 NULL, NULL, NULL, NULL)) break;
173 ret = RegDeleteValueW(hKey, lpszName);
174 if (ret) goto cleanup;
177 cleanup:
178 /* Free buffer if allocated */
179 if (lpszName != szNameBuf)
180 HeapFree( GetProcessHeap(), 0, lpszName);
181 if(lpszSubKey)
182 RegCloseKey(hSubKey);
183 return ret;
187 static void test_SetupDiCreateDeviceInfoListEx(void)
189 HDEVINFO devlist;
190 BOOL ret;
191 DWORD error;
192 static CHAR notnull[] = "NotNull";
193 static const WCHAR machine[] = { 'd','u','m','m','y',0 };
195 SetLastError(0xdeadbeef);
196 /* create empty DeviceInfoList, but set Reserved to a value, which is not NULL */
197 devlist = pSetupDiCreateDeviceInfoListExW(NULL, NULL, NULL, notnull);
199 error = GetLastError();
200 if (error == ERROR_CALL_NOT_IMPLEMENTED)
202 skip("SetupDiCreateDeviceInfoListExW is not implemented\n");
203 return;
205 ok(devlist == INVALID_HANDLE_VALUE, "SetupDiCreateDeviceInfoListExW failed : %p %d (expected %p)\n", devlist, error, INVALID_HANDLE_VALUE);
206 ok(error == ERROR_INVALID_PARAMETER, "GetLastError returned wrong value : %d, (expected %d)\n", error, ERROR_INVALID_PARAMETER);
208 SetLastError(0xdeadbeef);
209 /* create empty DeviceInfoList, but set MachineName to something */
210 devlist = pSetupDiCreateDeviceInfoListExW(NULL, NULL, machine, NULL);
212 error = GetLastError();
213 ok(devlist == INVALID_HANDLE_VALUE, "SetupDiCreateDeviceInfoListExW failed : %p %d (expected %p)\n", devlist, error, INVALID_HANDLE_VALUE);
214 ok(error == ERROR_INVALID_MACHINENAME, "GetLastError returned wrong value : %d, (expected %d)\n", error, ERROR_INVALID_MACHINENAME);
216 /* create empty DeviceInfoList */
217 devlist = pSetupDiCreateDeviceInfoListExW(NULL, NULL, NULL, NULL);
218 ok(devlist && devlist != INVALID_HANDLE_VALUE, "SetupDiCreateDeviceInfoListExW failed : %p %d (expected != %p)\n", devlist, error, INVALID_HANDLE_VALUE);
220 /* destroy DeviceInfoList */
221 ret = pSetupDiDestroyDeviceInfoList(devlist);
222 ok(ret, "SetupDiDestroyDeviceInfoList failed : %d\n", error);
225 static void test_SetupDiOpenClassRegKeyExA(void)
227 static const CHAR guidString[] = "{6a55b5a4-3f65-11db-b704-0011955c2bdb}";
228 HKEY hkey;
230 /* Check return value for nonexistent key */
231 hkey = pSetupDiOpenClassRegKeyExA(&guid, KEY_ALL_ACCESS,
232 DIOCR_INSTALLER, NULL, NULL);
233 ok(hkey == INVALID_HANDLE_VALUE,
234 "returned %p (expected INVALID_HANDLE_VALUE)\n", hkey);
236 /* Test it for a key that exists */
237 hkey = SetupDiOpenClassRegKey(NULL, KEY_ALL_ACCESS);
238 if (hkey != INVALID_HANDLE_VALUE)
240 HKEY classKey;
241 if (RegCreateKeyA(hkey, guidString, &classKey) == ERROR_SUCCESS)
243 RegCloseKey(classKey);
244 SetLastError(0xdeadbeef);
245 classKey = pSetupDiOpenClassRegKeyExA(&guid, KEY_ALL_ACCESS,
246 DIOCR_INSTALLER, NULL, NULL);
247 ok(classKey != INVALID_HANDLE_VALUE,
248 "opening class registry key failed with error %d\n",
249 GetLastError());
250 if (classKey != INVALID_HANDLE_VALUE)
251 RegCloseKey(classKey);
252 RegDeleteKeyA(hkey, guidString);
254 else
255 trace("failed to create registry key for test\n");
257 RegCloseKey(hkey);
259 else
260 trace("failed to open classes key\n");
263 static void append_str(char **str, const char *data)
265 sprintf(*str, data);
266 *str += strlen(*str);
269 static void create_inf_file(LPCSTR filename)
271 char data[1024];
272 char *ptr = data;
273 DWORD dwNumberOfBytesWritten;
274 HANDLE hf = CreateFile(filename, GENERIC_WRITE, 0, NULL,
275 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
277 append_str(&ptr, "[Version]\n");
278 append_str(&ptr, "Signature=\"$Chicago$\"\n");
279 append_str(&ptr, "Class=Bogus\n");
280 append_str(&ptr, "ClassGUID={6a55b5a4-3f65-11db-b704-0011955c2bdb}\n");
281 append_str(&ptr, "[ClassInstall32]\n");
282 append_str(&ptr, "AddReg=BogusClass.NT.AddReg\n");
283 append_str(&ptr, "[BogusClass.NT.AddReg]\n");
284 append_str(&ptr, "HKR,,,,\"Wine test devices\"\n");
286 WriteFile(hf, data, ptr - data, &dwNumberOfBytesWritten, NULL);
287 CloseHandle(hf);
290 static void get_temp_filename(LPSTR path)
292 static char curr[MAX_PATH] = { 0 };
293 char temp[MAX_PATH];
294 LPSTR ptr;
296 if (!*curr)
297 GetCurrentDirectoryA(MAX_PATH, curr);
298 GetTempFileNameA(curr, "set", 0, temp);
299 ptr = strrchr(temp, '\\');
301 lstrcpyA(path, ptr + 1);
304 static void testInstallClass(void)
306 static const WCHAR classKey[] = {'S','y','s','t','e','m','\\',
307 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
308 'C','o','n','t','r','o','l','\\','C','l','a','s','s','\\',
309 '{','6','a','5','5','b','5','a','4','-','3','f','6','5','-',
310 '1','1','d','b','-','b','7','0','4','-',
311 '0','0','1','1','9','5','5','c','2','b','d','b','}',0};
312 static const CHAR classKey_win9x[] =
313 "System\\CurrentControlSet\\Services\\Class\\"
314 "{6a55b5a4-3f65-11db-b704-0011955c2bdb}";
315 static const CHAR bogus_win9x[] =
316 "System\\CurrentControlSet\\Services\\Class\\Bogus";
317 char tmpfile[MAX_PATH];
318 BOOL ret;
319 HKEY hkey;
321 if (!pSetupDiInstallClassA)
323 skip("No SetupDiInstallClassA\n");
324 return;
326 tmpfile[0] = '.';
327 tmpfile[1] = '\\';
328 get_temp_filename(tmpfile + 2);
329 create_inf_file(tmpfile + 2);
331 ret = pSetupDiInstallClassA(NULL, NULL, 0, NULL);
332 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
333 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
334 ret = pSetupDiInstallClassA(NULL, NULL, DI_NOVCP, NULL);
335 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
336 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
337 ret = pSetupDiInstallClassA(NULL, tmpfile + 2, DI_NOVCP, NULL);
338 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
339 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
340 ret = pSetupDiInstallClassA(NULL, tmpfile + 2, 0, NULL);
341 ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND,
342 "Expected ERROR_FILE_NOT_FOUND, got %08x\n", GetLastError());
343 /* The next call will succeed. Information is put into the registry but the
344 * location(s) is/are depending on the Windows version.
346 ret = pSetupDiInstallClassA(NULL, tmpfile, 0, NULL);
347 ok(ret, "SetupDiInstallClassA failed: %08x\n", GetLastError());
348 if (!RegOpenKeyA(HKEY_LOCAL_MACHINE, classKey_win9x, &hkey))
350 /* We are on win9x */
351 RegCloseKey(hkey);
352 ok(!RegDeleteKeyA(HKEY_LOCAL_MACHINE, classKey_win9x),
353 "Couldn't delete win9x classkey\n");
354 ok(!RegDeleteKeyA(HKEY_LOCAL_MACHINE, bogus_win9x),
355 "Couldn't delete win9x bogus services class\n");
357 else
359 /* NT4 and above */
360 ok(!RegDeleteKeyW(HKEY_LOCAL_MACHINE, classKey),
361 "Couldn't delete NT classkey\n");
363 DeleteFile(tmpfile);
366 static void testCreateDeviceInfo(void)
368 BOOL ret;
369 HDEVINFO set;
371 if (!pSetupDiCreateDeviceInfoList || !pSetupDiEnumDeviceInfo ||
372 !pSetupDiDestroyDeviceInfoList || !pSetupDiCreateDeviceInfoA)
374 skip("No SetupDiCreateDeviceInfoA\n");
375 return;
377 SetLastError(0xdeadbeef);
378 ret = pSetupDiCreateDeviceInfoA(NULL, NULL, NULL, NULL, NULL, 0, NULL);
379 ok(!ret, "Expected failure\n");
380 ok(GetLastError() == ERROR_INVALID_DEVINST_NAME ||
381 GetLastError() == ERROR_INVALID_PARAMETER /* NT4 */ ||
382 GetLastError() == ERROR_INVALID_HANDLE /* Win9x */,
383 "Unexpected last error, got %08x\n", GetLastError());
385 /* If we are running on win9x we should skip these tests. Win95
386 * fails most tests anyway and win98 pops up the "Add New Hardware
387 * Wizard".
389 if (GetLastError() == ERROR_INVALID_HANDLE)
391 skip("We are on win9x where the tests introduce issues\n");
392 return;
395 SetLastError(0xdeadbeef);
396 ret = pSetupDiCreateDeviceInfoA(NULL, "Root\\LEGACY_BOGUS\\0000", NULL,
397 NULL, NULL, 0, NULL);
398 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
399 "Expected ERROR_INVALID_HANDLEHANDLE, got %08x\n", GetLastError());
400 set = pSetupDiCreateDeviceInfoList(&guid, NULL);
401 ok(set != NULL, "SetupDiCreateDeviceInfoList failed: %08x\n",
402 GetLastError());
403 if (set)
405 SP_DEVINFO_DATA devInfo = { 0 };
406 DWORD i;
408 SetLastError(0xdeadbeef);
409 ret = pSetupDiCreateDeviceInfoA(set, "Root\\LEGACY_BOGUS\\0000", NULL,
410 NULL, NULL, 0, NULL);
411 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
412 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
413 /* Finally, with all three required parameters, this succeeds: */
414 ret = pSetupDiCreateDeviceInfoA(set, "Root\\LEGACY_BOGUS\\0000", &guid,
415 NULL, NULL, 0, NULL);
416 ok(ret, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
417 /* This fails because the device ID already exists.. */
418 SetLastError(0xdeadbeef);
419 ret = pSetupDiCreateDeviceInfoA(set, "Root\\LEGACY_BOGUS\\0000", &guid,
420 NULL, NULL, 0, &devInfo);
421 ok(!ret && GetLastError() == ERROR_DEVINST_ALREADY_EXISTS,
422 "Expected ERROR_DEVINST_ALREADY_EXISTS, got %08x\n", GetLastError());
423 /* whereas this "fails" because cbSize is wrong.. */
424 SetLastError(0xdeadbeef);
425 ret = pSetupDiCreateDeviceInfoA(set, "LEGACY_BOGUS", &guid, NULL, NULL,
426 DICD_GENERATE_ID, &devInfo);
427 ok(!ret && GetLastError() == ERROR_INVALID_USER_BUFFER,
428 "Expected ERROR_INVALID_USER_BUFFER, got %08x\n", GetLastError());
429 devInfo.cbSize = sizeof(devInfo);
430 ret = pSetupDiCreateDeviceInfoA(set, "LEGACY_BOGUS", &guid, NULL, NULL,
431 DICD_GENERATE_ID, &devInfo);
432 /* and this finally succeeds. */
433 ok(ret, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
434 /* There were three devices added, however - the second failure just
435 * resulted in the SP_DEVINFO_DATA not getting copied.
437 SetLastError(0xdeadbeef);
438 i = 0;
439 while (pSetupDiEnumDeviceInfo(set, i, &devInfo))
440 i++;
441 ok(i == 3, "Expected 3 devices, got %d\n", i);
442 ok(GetLastError() == ERROR_NO_MORE_ITEMS,
443 "SetupDiEnumDeviceInfo failed: %08x\n", GetLastError());
444 pSetupDiDestroyDeviceInfoList(set);
448 static void testGetDeviceInstanceId(void)
450 BOOL ret;
451 HDEVINFO set;
452 SP_DEVINFO_DATA devInfo = { 0 };
454 if (!pSetupDiCreateDeviceInfoList || !pSetupDiDestroyDeviceInfoList ||
455 !pSetupDiCreateDeviceInfoA || !pSetupDiGetDeviceInstanceIdA)
457 skip("No SetupDiGetDeviceInstanceIdA\n");
458 return;
460 SetLastError(0xdeadbeef);
461 ret = pSetupDiGetDeviceInstanceIdA(NULL, NULL, NULL, 0, NULL);
462 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
463 "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
464 SetLastError(0xdeadbeef);
465 ret = pSetupDiGetDeviceInstanceIdA(NULL, &devInfo, NULL, 0, NULL);
466 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
467 "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
468 set = pSetupDiCreateDeviceInfoList(&guid, NULL);
469 ok(set != NULL, "SetupDiCreateDeviceInfoList failed: %08x\n",
470 GetLastError());
471 if (set)
473 char instanceID[MAX_PATH];
474 DWORD size;
476 SetLastError(0xdeadbeef);
477 ret = pSetupDiGetDeviceInstanceIdA(set, NULL, NULL, 0, NULL);
478 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
479 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
480 SetLastError(0xdeadbeef);
481 ret = pSetupDiGetDeviceInstanceIdA(set, &devInfo, NULL, 0, NULL);
482 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
483 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
484 SetLastError(0xdeadbeef);
485 ret = pSetupDiGetDeviceInstanceIdA(set, &devInfo, NULL, 0, &size);
486 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
487 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
488 devInfo.cbSize = sizeof(devInfo);
489 SetLastError(0xdeadbeef);
490 ret = pSetupDiGetDeviceInstanceIdA(set, &devInfo, NULL, 0, &size);
491 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
492 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
493 ret = pSetupDiCreateDeviceInfoA(set, "Root\\LEGACY_BOGUS\\0000", &guid,
494 NULL, NULL, 0, &devInfo);
495 ok(ret, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
496 SetLastError(0xdeadbeef);
497 ret = pSetupDiGetDeviceInstanceIdA(set, &devInfo, NULL, 0, &size);
498 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
499 "Expected ERROR_INSUFFICIENT_BUFFER, got %08x\n", GetLastError());
500 ret = pSetupDiGetDeviceInstanceIdA(set, &devInfo, instanceID,
501 sizeof(instanceID), NULL);
502 ok(ret, "SetupDiGetDeviceInstanceIdA failed: %08x\n", GetLastError());
503 ok(!lstrcmpA(instanceID, "ROOT\\LEGACY_BOGUS\\0000"),
504 "Unexpected instance ID %s\n", instanceID);
505 ret = pSetupDiCreateDeviceInfoA(set, "LEGACY_BOGUS", &guid,
506 NULL, NULL, DICD_GENERATE_ID, &devInfo);
507 ok(ret, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
508 ret = pSetupDiGetDeviceInstanceIdA(set, &devInfo, instanceID,
509 sizeof(instanceID), NULL);
510 ok(ret, "SetupDiGetDeviceInstanceIdA failed: %08x\n", GetLastError());
511 ok(!lstrcmpA(instanceID, "ROOT\\LEGACY_BOGUS\\0001"),
512 "Unexpected instance ID %s\n", instanceID);
513 pSetupDiDestroyDeviceInfoList(set);
517 static void testRegisterDeviceInfo(void)
519 BOOL ret;
520 HDEVINFO set;
522 if (!pSetupDiCreateDeviceInfoList || !pSetupDiDestroyDeviceInfoList ||
523 !pSetupDiRegisterDeviceInfo)
525 skip("No SetupDiRegisterDeviceInfo\n");
526 return;
528 SetLastError(0xdeadbeef);
529 ret = pSetupDiRegisterDeviceInfo(NULL, NULL, 0, NULL, NULL, NULL);
530 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
531 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
532 set = pSetupDiCreateDeviceInfoList(&guid, NULL);
533 ok(set != NULL, "SetupDiCreateDeviceInfoList failed: %d\n", GetLastError());
534 if (set)
536 SP_DEVINFO_DATA devInfo = { 0 };
538 SetLastError(0xdeadbeef);
539 ret = pSetupDiRegisterDeviceInfo(set, NULL, 0, NULL, NULL, NULL);
540 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
541 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
542 SetLastError(0xdeadbeef);
543 ret = pSetupDiRegisterDeviceInfo(set, &devInfo, 0, NULL, NULL, NULL);
544 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
545 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
546 devInfo.cbSize = sizeof(devInfo);
547 SetLastError(0xdeadbeef);
548 ret = pSetupDiRegisterDeviceInfo(set, &devInfo, 0, NULL, NULL, NULL);
549 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
550 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
551 ret = pSetupDiCreateDeviceInfoA(set, "USB\\BOGUS\\0000", &guid,
552 NULL, NULL, 0, &devInfo);
553 ok(ret || GetLastError() == ERROR_DEVINST_ALREADY_EXISTS,
554 "SetupDiCreateDeviceInfoA failed: %d\n", GetLastError());
555 if (ret)
557 /* If it already existed, registering it again will fail */
558 ret = pSetupDiRegisterDeviceInfo(set, &devInfo, 0, NULL, NULL,
559 NULL);
560 ok(ret, "SetupDiCreateDeviceInfoA failed: %d\n", GetLastError());
562 /* FIXME: On Win2K+ systems, this is now persisted to registry in
563 * HKLM\System\CCS\Enum\USB\Bogus\0000. I don't check because the
564 * Win9x location is different.
565 * FIXME: the key also becomes undeletable. How to get rid of it?
567 pSetupDiDestroyDeviceInfoList(set);
571 static void testCreateDeviceInterface(void)
573 BOOL ret;
574 HDEVINFO set;
576 if (!pSetupDiCreateDeviceInfoList || !pSetupDiDestroyDeviceInfoList ||
577 !pSetupDiCreateDeviceInfoA || !pSetupDiCreateDeviceInterfaceA ||
578 !pSetupDiEnumDeviceInterfaces)
580 skip("No SetupDiCreateDeviceInterfaceA\n");
581 return;
583 SetLastError(0xdeadbeef);
584 ret = pSetupDiCreateDeviceInterfaceA(NULL, NULL, NULL, NULL, 0, NULL);
585 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
586 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
587 SetLastError(0xdeadbeef);
588 ret = pSetupDiCreateDeviceInterfaceA(NULL, NULL, &guid, NULL, 0, NULL);
589 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
590 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
591 set = pSetupDiCreateDeviceInfoList(&guid, NULL);
592 ok(set != NULL, "SetupDiCreateDeviceInfoList failed: %d\n", GetLastError());
593 if (set)
595 SP_DEVINFO_DATA devInfo = { 0 };
596 SP_DEVICE_INTERFACE_DATA interfaceData = { sizeof(interfaceData),
597 { 0 } };
598 DWORD i;
600 SetLastError(0xdeadbeef);
601 ret = pSetupDiCreateDeviceInterfaceA(set, NULL, NULL, NULL, 0, NULL);
602 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
603 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
604 SetLastError(0xdeadbeef);
605 ret = pSetupDiCreateDeviceInterfaceA(set, &devInfo, NULL, NULL, 0,
606 NULL);
607 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
608 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
609 devInfo.cbSize = sizeof(devInfo);
610 ret = pSetupDiCreateDeviceInfoA(set, "ROOT\\LEGACY_BOGUS\\0000", &guid,
611 NULL, NULL, 0, &devInfo);
612 ok(ret, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
613 SetLastError(0xdeadbeef);
614 ret = pSetupDiCreateDeviceInterfaceA(set, &devInfo, NULL, NULL, 0,
615 NULL);
616 ok(!ret && GetLastError() == ERROR_INVALID_USER_BUFFER,
617 "Expected ERROR_INVALID_USER_BUFFER, got %08x\n", GetLastError());
618 ret = pSetupDiCreateDeviceInterfaceA(set, &devInfo, &guid, NULL, 0,
619 NULL);
620 ok(ret, "SetupDiCreateDeviceInterfaceA failed: %08x\n", GetLastError());
621 /* Creating the same interface a second time succeeds */
622 ret = pSetupDiCreateDeviceInterfaceA(set, &devInfo, &guid, NULL, 0,
623 NULL);
624 ok(ret, "SetupDiCreateDeviceInterfaceA failed: %08x\n", GetLastError());
625 ret = pSetupDiCreateDeviceInterfaceA(set, &devInfo, &guid, "Oogah", 0,
626 NULL);
627 ok(ret, "SetupDiCreateDeviceInterfaceA failed: %08x\n", GetLastError());
628 ret = pSetupDiEnumDeviceInterfaces(set, &devInfo, &guid, 0,
629 &interfaceData);
630 ok(ret, "SetupDiEnumDeviceInterfaces failed: %d\n", GetLastError());
631 i = 0;
632 while (pSetupDiEnumDeviceInterfaces(set, &devInfo, &guid, i,
633 &interfaceData))
634 i++;
635 ok(i == 2, "expected 2 interfaces, got %d\n", i);
636 ok(GetLastError() == ERROR_NO_MORE_ITEMS,
637 "SetupDiEnumDeviceInterfaces failed: %08x\n", GetLastError());
638 pSetupDiDestroyDeviceInfoList(set);
642 static void testGetDeviceInterfaceDetail(void)
644 BOOL ret;
645 HDEVINFO set;
647 if (!pSetupDiCreateDeviceInfoList || !pSetupDiDestroyDeviceInfoList ||
648 !pSetupDiCreateDeviceInfoA || !pSetupDiCreateDeviceInterfaceA ||
649 !pSetupDiGetDeviceInterfaceDetailA)
651 skip("No SetupDiGetDeviceInterfaceDetailA\n");
652 return;
654 SetLastError(0xdeadbeef);
655 ret = pSetupDiGetDeviceInterfaceDetailA(NULL, NULL, NULL, 0, NULL, NULL);
656 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
657 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
658 set = pSetupDiCreateDeviceInfoList(&guid, NULL);
659 ok(set != NULL, "SetupDiCreateDeviceInfoList failed: %d\n", GetLastError());
660 if (set)
662 SP_DEVINFO_DATA devInfo = { sizeof(devInfo), { 0 } };
663 SP_DEVICE_INTERFACE_DATA interfaceData = { sizeof(interfaceData),
664 { 0 } };
665 DWORD size = 0;
667 SetLastError(0xdeadbeef);
668 ret = pSetupDiGetDeviceInterfaceDetailA(set, NULL, NULL, 0, NULL,
669 NULL);
670 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
671 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
672 ret = pSetupDiCreateDeviceInfoA(set, "ROOT\\LEGACY_BOGUS\\0000", &guid,
673 NULL, NULL, 0, &devInfo);
674 ok(ret, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
675 SetLastError(0xdeadbeef);
676 ret = pSetupDiCreateDeviceInterfaceA(set, &devInfo, &guid, NULL, 0,
677 &interfaceData);
678 ok(ret, "SetupDiCreateDeviceInterfaceA failed: %08x\n", GetLastError());
679 SetLastError(0xdeadbeef);
680 ret = pSetupDiGetDeviceInterfaceDetailA(set, &interfaceData, NULL,
681 0, NULL, NULL);
682 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
683 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
684 SetLastError(0xdeadbeef);
685 ret = pSetupDiGetDeviceInterfaceDetailA(set, &interfaceData, NULL,
686 100, NULL, NULL);
687 ok(!ret && GetLastError() == ERROR_INVALID_USER_BUFFER,
688 "Expected ERROR_INVALID_USER_BUFFER, got %08x\n", GetLastError());
689 SetLastError(0xdeadbeef);
690 ret = pSetupDiGetDeviceInterfaceDetailA(set, &interfaceData, NULL,
691 0, &size, NULL);
692 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
693 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
694 if (!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER)
696 static const char path[] =
697 "\\\\?\\root#legacy_bogus#0000#{6a55b5a4-3f65-11db-b704-0011955c2bdb}";
698 LPBYTE buf = HeapAlloc(GetProcessHeap(), 0, size);
699 SP_DEVICE_INTERFACE_DETAIL_DATA_A *detail =
700 (SP_DEVICE_INTERFACE_DETAIL_DATA_A *)buf;
701 DWORD expectedsize = offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_W, DevicePath) + sizeof(WCHAR)*(1 + strlen(path));
703 detail->cbSize = 0;
704 SetLastError(0xdeadbeef);
705 ret = pSetupDiGetDeviceInterfaceDetailA(set, &interfaceData, detail,
706 size, &size, NULL);
707 ok(!ret && GetLastError() == ERROR_INVALID_USER_BUFFER,
708 "Expected ERROR_INVALID_USER_BUFFER, got %08x\n", GetLastError());
709 detail->cbSize = size;
710 SetLastError(0xdeadbeef);
711 ret = pSetupDiGetDeviceInterfaceDetailA(set, &interfaceData, detail,
712 size, &size, NULL);
713 ok(!ret && GetLastError() == ERROR_INVALID_USER_BUFFER,
714 "Expected ERROR_INVALID_USER_BUFFER, got %08x\n", GetLastError());
715 detail->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_A);
716 SetLastError(0xdeadbeef);
717 ret = pSetupDiGetDeviceInterfaceDetailA(set, &interfaceData, detail,
718 size, &size, NULL);
719 ok(!ret && GetLastError() == ERROR_INVALID_USER_BUFFER,
720 "Expected ERROR_INVALID_USER_BUFFER, got %08x\n", GetLastError());
721 /* Windows 2000 and up check for the exact size. Win9x returns ERROR_INVALID_PARAMETER
722 * on every call (so doesn't get here) and NT4 doesn't have this function.
724 detail->cbSize = FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_A, DevicePath[1]);
725 ret = pSetupDiGetDeviceInterfaceDetailA(set, &interfaceData, detail,
726 size, &size, NULL);
727 ok(ret, "SetupDiGetDeviceInterfaceDetailA failed: %d\n",
728 GetLastError());
729 ok(!lstrcmpiA(path, detail->DevicePath), "Unexpected path %s\n",
730 detail->DevicePath);
731 /* Check SetupDiGetDeviceInterfaceDetailW */
732 if (pSetupDiGetDeviceInterfaceDetailW)
734 ret = pSetupDiGetDeviceInterfaceDetailW(set, &interfaceData, NULL, 0, &size, NULL);
735 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Expected ERROR_INSUFFICIENT_BUFFER, got error code: %d\n", GetLastError());
736 ok(expectedsize == size, "SetupDiGetDeviceInterfaceDetailW returned wrong reqsize: expected %d, got %d\n", expectedsize, size);
738 else
739 skip("SetupDiGetDeviceInterfaceDetailW is not available\n");
741 HeapFree(GetProcessHeap(), 0, buf);
743 pSetupDiDestroyDeviceInfoList(set);
747 static void testDevRegKey(void)
749 static const WCHAR classKey[] = {'S','y','s','t','e','m','\\',
750 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
751 'C','o','n','t','r','o','l','\\','C','l','a','s','s','\\',
752 '{','6','a','5','5','b','5','a','4','-','3','f','6','5','-',
753 '1','1','d','b','-','b','7','0','4','-',
754 '0','0','1','1','9','5','5','c','2','b','d','b','}',0};
755 static const WCHAR bogus[] = {'S','y','s','t','e','m','\\',
756 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
757 'E','n','u','m','\\','R','o','o','t','\\',
758 'L','E','G','A','C','Y','_','B','O','G','U','S',0};
759 BOOL ret;
760 HDEVINFO set;
761 HKEY key = NULL;
763 if (!pSetupDiCreateDeviceInfoList || !pSetupDiDestroyDeviceInfoList ||
764 !pSetupDiCreateDeviceInfoA || !pSetupDiOpenDevRegKey ||
765 !pSetupDiRegisterDeviceInfo || !pSetupDiCreateDevRegKeyW ||
766 !pSetupDiCallClassInstaller)
768 skip("No SetupDiOpenDevRegKey\n");
769 return;
772 /* Check if we are on win9x */
773 SetLastError(0xdeadbeef);
774 key = pSetupDiCreateDevRegKeyW(NULL, NULL, 0, 0, 0, NULL, NULL);
775 if (key == INVALID_HANDLE_VALUE && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
777 skip("We are on win9x where the tests introduce issues\n");
778 return;
780 ok(key == INVALID_HANDLE_VALUE,
781 "Expected INVALID_HANDLE_VALUE, got %p\n", key);
782 ok(GetLastError() == ERROR_INVALID_HANDLE,
783 "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
785 set = pSetupDiCreateDeviceInfoList(&guid, NULL);
786 ok(set != NULL, "SetupDiCreateDeviceInfoList failed: %d\n", GetLastError());
787 if (set)
789 SP_DEVINFO_DATA devInfo = { sizeof(devInfo), { 0 } };
790 LONG res;
792 /* The device info key shouldn't be there */
793 res = RegOpenKeyW(HKEY_LOCAL_MACHINE, bogus, &key);
794 /* Due to old winetests we could have leftovers and hence the
795 * todo_wine.
797 todo_wine
798 ok(res != ERROR_SUCCESS, "Expected key to not exist\n");
799 RegCloseKey(key);
800 /* Create the device information */
801 ret = pSetupDiCreateDeviceInfoA(set, "ROOT\\LEGACY_BOGUS\\0000", &guid,
802 NULL, NULL, 0, &devInfo);
803 ok(ret, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
804 /* The device info key should have been created */
805 ok(!RegOpenKeyW(HKEY_LOCAL_MACHINE, bogus, &key),
806 "Expected registry key to exist\n");
807 RegCloseKey(key);
808 SetLastError(0xdeadbeef);
809 key = pSetupDiOpenDevRegKey(NULL, NULL, 0, 0, 0, 0);
810 ok(!key || key == INVALID_HANDLE_VALUE,
811 "Expected INVALID_HANDLE_VALUE or a NULL key (NT4)\n");
812 ok(GetLastError() == ERROR_INVALID_HANDLE,
813 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
814 SetLastError(0xdeadbeef);
815 key = pSetupDiOpenDevRegKey(set, NULL, 0, 0, 0, 0);
816 ok(key == INVALID_HANDLE_VALUE &&
817 GetLastError() == ERROR_INVALID_PARAMETER,
818 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
819 SetLastError(0xdeadbeef);
820 key = pSetupDiOpenDevRegKey(set, &devInfo, 0, 0, 0, 0);
821 ok(key == INVALID_HANDLE_VALUE &&
822 GetLastError() == ERROR_INVALID_FLAGS,
823 "Expected ERROR_INVALID_FLAGS, got %d\n", GetLastError());
824 SetLastError(0xdeadbeef);
825 key = pSetupDiOpenDevRegKey(set, &devInfo, DICS_FLAG_GLOBAL, 0, 0, 0);
826 ok(key == INVALID_HANDLE_VALUE &&
827 GetLastError() == ERROR_INVALID_FLAGS,
828 "Expected ERROR_INVALID_FLAGS, got %d\n", GetLastError());
829 SetLastError(0xdeadbeef);
830 key = pSetupDiOpenDevRegKey(set, &devInfo, DICS_FLAG_GLOBAL, 0,
831 DIREG_BOTH, 0);
832 ok(key == INVALID_HANDLE_VALUE &&
833 GetLastError() == ERROR_INVALID_FLAGS,
834 "Expected ERROR_INVALID_FLAGS, got %d\n", GetLastError());
835 SetLastError(0xdeadbeef);
836 key = pSetupDiOpenDevRegKey(set, &devInfo, DICS_FLAG_GLOBAL, 0,
837 DIREG_DRV, 0);
838 ok(key == INVALID_HANDLE_VALUE &&
839 GetLastError() == ERROR_DEVINFO_NOT_REGISTERED,
840 "Expected ERROR_DEVINFO_NOT_REGISTERED, got %08x\n", GetLastError());
841 SetLastError(0xdeadbeef);
842 ret = pSetupDiRegisterDeviceInfo(set, &devInfo, 0, NULL, NULL, NULL);
843 ok(ret, "SetupDiRegisterDeviceInfo failed: %08x\n", GetLastError());
844 SetLastError(0xdeadbeef);
845 key = pSetupDiOpenDevRegKey(set, &devInfo, DICS_FLAG_GLOBAL, 0,
846 DIREG_DRV, 0);
847 /* The software key isn't created by default */
848 todo_wine
849 ok(key == INVALID_HANDLE_VALUE &&
850 GetLastError() == ERROR_KEY_DOES_NOT_EXIST,
851 "Expected ERROR_KEY_DOES_NOT_EXIST_EXIST, got %08x\n", GetLastError());
852 SetLastError(0xdeadbeef);
853 key = pSetupDiOpenDevRegKey(set, &devInfo, DICS_FLAG_GLOBAL, 0,
854 DIREG_DEV, 0);
855 todo_wine
856 ok(key == INVALID_HANDLE_VALUE &&
857 GetLastError() == ERROR_KEY_DOES_NOT_EXIST,
858 "Expected ERROR_KEY_DOES_NOT_EXIST_EXIST, got %08x\n", GetLastError());
859 SetLastError(0xdeadbeef);
860 /* The class key shouldn't be there */
861 res = RegOpenKeyW(HKEY_LOCAL_MACHINE, classKey, &key);
862 todo_wine
863 ok(res != ERROR_SUCCESS, "Expected key to not exist\n");
864 RegCloseKey(key);
865 /* Create the device reg key */
866 key = pSetupDiCreateDevRegKeyW(set, &devInfo, DICS_FLAG_GLOBAL, 0,
867 DIREG_DRV, NULL, NULL);
868 ok(key != INVALID_HANDLE_VALUE, "SetupDiCreateDevRegKey failed: %08x\n",
869 GetLastError());
870 RegCloseKey(key);
871 /* The class key should have been created */
872 ok(!RegOpenKeyW(HKEY_LOCAL_MACHINE, classKey, &key),
873 "Expected registry key to exist\n");
874 RegCloseKey(key);
875 SetLastError(0xdeadbeef);
876 key = pSetupDiOpenDevRegKey(set, &devInfo, DICS_FLAG_GLOBAL, 0,
877 DIREG_DRV, 0);
878 todo_wine
879 ok(key == INVALID_HANDLE_VALUE &&
880 (GetLastError() == ERROR_INVALID_DATA ||
881 GetLastError() == ERROR_ACCESS_DENIED), /* win2k3 */
882 "Expected ERROR_INVALID_DATA or ERROR_ACCESS_DENIED, got %08x\n", GetLastError());
883 key = pSetupDiOpenDevRegKey(set, &devInfo, DICS_FLAG_GLOBAL, 0,
884 DIREG_DRV, KEY_READ);
885 ok(key != INVALID_HANDLE_VALUE, "SetupDiOpenDevRegKey failed: %08x\n",
886 GetLastError());
887 ret = remove_device();
888 todo_wine
889 ok(ret, "Expected the device to be removed: %08x\n", GetLastError());
890 pSetupDiDestroyDeviceInfoList(set);
892 /* FIXME: Only do the RegDeleteKey, once Wine is fixed */
893 if (!ret)
895 /* Wine doesn't delete the information currently */
896 trace("We are most likely on Wine\n");
897 devinst_RegDeleteTreeW(HKEY_LOCAL_MACHINE, bogus);
898 devinst_RegDeleteTreeW(HKEY_LOCAL_MACHINE, classKey);
900 else
902 /* There should only be a class key entry, so a simple
903 * RegDeleteKey should work
905 * This could fail if it's the first time for this new test
906 * after running the old tests.
908 ok(!RegDeleteKeyW(HKEY_LOCAL_MACHINE, classKey),
909 "Couldn't delete classkey\n");
914 static void testRegisterAndGetDetail(void)
916 HDEVINFO set;
917 BOOL ret;
918 SP_DEVINFO_DATA devInfo = { sizeof(SP_DEVINFO_DATA), { 0 } };
919 SP_DEVICE_INTERFACE_DATA interfaceData = { sizeof(interfaceData), { 0 } };
920 DWORD dwSize = 0;
922 SetLastError(0xdeadbeef);
923 set = pSetupDiGetClassDevsA(&guid, NULL, 0, DIGCF_ALLCLASSES);
924 ok(set != INVALID_HANDLE_VALUE, "SetupDiGetClassDevsA failed: %08x\n",
925 GetLastError());
927 SetLastError(0xdeadbeef);
928 ret = pSetupDiCreateDeviceInfoA(set, "LEGACY_BOGUS", &guid, NULL, 0,
929 DICD_GENERATE_ID, &devInfo);
930 ok(ret, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
931 SetLastError(0xdeadbeef);
932 ret = pSetupDiCreateDeviceInterfaceA(set, &devInfo, &guid, NULL, 0, &interfaceData);
933 ok(ret, "SetupDiCreateDeviceInterfaceA failed: %08x\n", GetLastError());
934 SetLastError(0xdeadbeef);
935 ret = pSetupDiRegisterDeviceInfo(set, &devInfo, 0, NULL, NULL, NULL);
936 ok(ret, "SetupDiRegisterDeviceInfo failed: %08x\n", GetLastError());
938 pSetupDiDestroyDeviceInfoList(set);
940 SetLastError(0xdeadbeef);
941 set = pSetupDiGetClassDevsA(&guid, NULL, 0, DIGCF_DEVICEINTERFACE);
942 ok(set != INVALID_HANDLE_VALUE, "SetupDiGetClassDevsA failed: %08x\n",
943 GetLastError());
945 SetLastError(0xdeadbeef);
946 ret = pSetupDiEnumDeviceInterfaces(set, NULL, &guid, 0, &interfaceData);
947 ok(ret, "SetupDiEnumDeviceInterfaces failed: %08x\n", GetLastError());
948 SetLastError(0xdeadbeef);
949 ret = pSetupDiGetDeviceInterfaceDetailA(set, &interfaceData, NULL, 0, &dwSize, NULL);
950 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
951 "Expected ERROR_INSUFFICIENT_BUFFER, got %08x\n", GetLastError());
952 if (!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER)
954 static const char path[] =
955 "\\\\?\\root#legacy_bogus#0000#{6a55b5a4-3f65-11db-b704-0011955c2bdb}";
956 PSP_DEVICE_INTERFACE_DETAIL_DATA_A detail = NULL;
958 detail = (PSP_DEVICE_INTERFACE_DETAIL_DATA_A)HeapAlloc(GetProcessHeap(), 0, dwSize);
959 if (detail)
961 detail->cbSize = offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_A, DevicePath) + sizeof(char);
962 SetLastError(0xdeadbeef);
963 ret = pSetupDiGetDeviceInterfaceDetailA(set, &interfaceData,
964 detail, dwSize, &dwSize, NULL);
965 ok(ret, "SetupDiGetDeviceInterfaceDetailA failed: %08x\n", GetLastError());
966 /* FIXME: This one only worked because old data wasn't removed properly. As soon
967 * as all the tests are cleaned up correctly this has to be (or should be) fixed
969 todo_wine
970 ok(!lstrcmpiA(path, detail->DevicePath), "Unexpected path %s\n",
971 detail->DevicePath);
972 HeapFree(GetProcessHeap(), 0, detail);
976 pSetupDiDestroyDeviceInfoList(set);
979 static void testDeviceRegistryPropertyA()
981 HDEVINFO set;
982 SP_DEVINFO_DATA devInfo = { sizeof(SP_DEVINFO_DATA), { 0 } };
983 CHAR devName[] = "LEGACY_BOGUS";
984 CHAR friendlyName[] = "Bogus";
985 CHAR buf[6] = "";
986 DWORD buflen = 6;
987 DWORD size;
988 DWORD regType;
989 BOOL ret;
991 SetLastError(0xdeadbeef);
992 set = pSetupDiGetClassDevsA(&guid, NULL, 0, DIGCF_DEVICEINTERFACE);
993 ok(set != INVALID_HANDLE_VALUE, "SetupDiGetClassDevsA failed: %08x\n",
994 GetLastError());
995 SetLastError(0xdeadbeef);
996 ret = pSetupDiCreateDeviceInfoA(set, devName, &guid, NULL, NULL,
997 DICD_GENERATE_ID, &devInfo);
998 ok(ret, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
999 SetLastError(0xdeadbeef);
1000 ret = pSetupDiSetDeviceRegistryPropertyA(NULL, NULL, -1, NULL, 0);
1001 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
1002 "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
1003 SetLastError(0xdeadbeef);
1004 ret = pSetupDiSetDeviceRegistryPropertyA(set, NULL, -1, NULL, 0);
1005 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
1006 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
1007 SetLastError(0xdeadbeef);
1008 ret = pSetupDiSetDeviceRegistryPropertyA(set, &devInfo, -1, NULL, 0);
1009 todo_wine
1010 ok(!ret && GetLastError() == ERROR_INVALID_REG_PROPERTY,
1011 "Expected ERROR_INVALID_REG_PROPERTY, got %08x\n", GetLastError());
1012 /* GetLastError() returns nonsense in win2k3 */
1013 ret = pSetupDiSetDeviceRegistryPropertyA(set, &devInfo, SPDRP_FRIENDLYNAME,
1014 NULL, 0);
1015 todo_wine
1016 ok(!ret, "Expected failure, got %d\n", ret);
1017 SetLastError(0xdeadbeef);
1018 ret = pSetupDiSetDeviceRegistryPropertyA(set, &devInfo, SPDRP_FRIENDLYNAME,
1019 (PBYTE)friendlyName, buflen);
1020 ok(ret, "SetupDiSetDeviceRegistryPropertyA failed: %08x\n", GetLastError());
1021 SetLastError(0xdeadbeef);
1022 ret = pSetupDiGetDeviceRegistryPropertyA(NULL, NULL, -1, NULL, NULL, 0, NULL);
1023 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
1024 "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
1025 SetLastError(0xdeadbeef);
1026 ret = pSetupDiGetDeviceRegistryPropertyA(set, NULL, -1, NULL, NULL, 0, NULL);
1027 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
1028 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
1029 SetLastError(0xdeadbeef);
1030 ret = pSetupDiGetDeviceRegistryPropertyA(set, &devInfo, -1, NULL, NULL, 0, NULL);
1031 todo_wine
1032 ok(!ret && GetLastError() == ERROR_INVALID_REG_PROPERTY,
1033 "Expected ERROR_INVALID_REG_PROPERTY, got %08x\n", GetLastError());
1034 /* GetLastError() returns nonsense in win2k3 */
1035 ret = pSetupDiGetDeviceRegistryPropertyA(set, &devInfo, SPDRP_FRIENDLYNAME,
1036 NULL, NULL, buflen, NULL);
1037 ok(!ret, "Expected failure, got %d\n", ret);
1038 SetLastError(0xdeadbeef);
1039 ret = pSetupDiGetDeviceRegistryPropertyA(set, &devInfo, SPDRP_FRIENDLYNAME,
1040 NULL, NULL, 0, &size);
1041 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
1042 "Expected ERROR_INSUFFICIENT_BUFFER, got %08x\n", GetLastError());
1043 ok(buflen == size, "Unexpected size: %d\n", size);
1044 SetLastError(0xdeadbeef);
1045 ret = pSetupDiGetDeviceRegistryPropertyA(set, &devInfo, SPDRP_FRIENDLYNAME,
1046 NULL, (PBYTE)buf, buflen, NULL);
1047 ok(ret, "SetupDiGetDeviceRegistryPropertyA failed: %08x\n", GetLastError());
1048 ok(!lstrcmpiA(friendlyName, buf), "Unexpected property\n");
1049 SetLastError(0xdeadbeef);
1050 ret = pSetupDiGetDeviceRegistryPropertyA(set, &devInfo, SPDRP_FRIENDLYNAME,
1051 &regType, (PBYTE)buf, buflen, NULL);
1052 ok(ret, "SetupDiGetDeviceRegistryPropertyA failed: %08x\n", GetLastError());
1053 ok(!lstrcmpiA(friendlyName, buf), "Unexpected value of property\n");
1054 ok(regType == REG_SZ, "Unexpected type of property: %d\n", regType);
1055 SetLastError(0xdeadbeef);
1056 ret = pSetupDiSetDeviceRegistryPropertyA(set, &devInfo, SPDRP_FRIENDLYNAME,
1057 NULL, 0);
1058 ok(ret, "SetupDiSetDeviceRegistryPropertyA failed: %08x\n", GetLastError());
1059 SetLastError(0xdeadbeef);
1060 ret = pSetupDiGetDeviceRegistryPropertyA(set, &devInfo, SPDRP_FRIENDLYNAME,
1061 NULL, (PBYTE)buf, buflen, &size);
1062 todo_wine
1063 ok(!ret && GetLastError() == ERROR_INVALID_DATA,
1064 "Expected ERROR_INVALID_DATA, got %08x\n", GetLastError());
1065 pSetupDiDestroyDeviceInfoList(set);
1068 static void testDeviceRegistryPropertyW()
1070 HDEVINFO set;
1071 SP_DEVINFO_DATA devInfo = { sizeof(SP_DEVINFO_DATA), { 0 } };
1072 WCHAR devName[] = {'L','E','G','A','C','Y','_','B','O','G','U','S',0};
1073 WCHAR friendlyName[] = {'B','o','g','u','s',0};
1074 WCHAR buf[6] = {0};
1075 DWORD buflen = 6 * sizeof(WCHAR);
1076 DWORD size;
1077 DWORD regType;
1078 BOOL ret;
1080 SetLastError(0xdeadbeef);
1081 set = pSetupDiGetClassDevsW(&guid, NULL, 0, DIGCF_DEVICEINTERFACE);
1082 if (set == INVALID_HANDLE_VALUE && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1084 skip("W-functions are not implemented\n");
1085 return;
1087 ok(set != INVALID_HANDLE_VALUE, "SetupDiGetClassDevsW failed: %08x\n",
1088 GetLastError());
1089 SetLastError(0xdeadbeef);
1090 ret = pSetupDiCreateDeviceInfoW(set, devName, &guid, NULL, NULL,
1091 DICD_GENERATE_ID, &devInfo);
1092 ok(ret, "SetupDiCreateDeviceInfoW failed: %08x\n", GetLastError());
1093 SetLastError(0xdeadbeef);
1094 ret = pSetupDiSetDeviceRegistryPropertyW(NULL, NULL, -1, NULL, 0);
1095 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
1096 "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
1097 SetLastError(0xdeadbeef);
1098 ret = pSetupDiSetDeviceRegistryPropertyW(set, NULL, -1, NULL, 0);
1099 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
1100 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
1101 SetLastError(0xdeadbeef);
1102 ret = pSetupDiSetDeviceRegistryPropertyW(set, &devInfo, -1, NULL, 0);
1103 todo_wine
1104 ok(!ret && GetLastError() == ERROR_INVALID_REG_PROPERTY,
1105 "Expected ERROR_INVALID_REG_PROPERTY, got %08x\n", GetLastError());
1106 /* GetLastError() returns nonsense in win2k3 */
1107 ret = pSetupDiSetDeviceRegistryPropertyW(set, &devInfo, SPDRP_FRIENDLYNAME,
1108 NULL, 0);
1109 todo_wine
1110 ok(!ret, "Expected failure, got %d\n", ret);
1111 SetLastError(0xdeadbeef);
1112 ret = pSetupDiSetDeviceRegistryPropertyW(set, &devInfo, SPDRP_FRIENDLYNAME,
1113 (PBYTE)friendlyName, buflen);
1114 ok(ret, "SetupDiSetDeviceRegistryPropertyW failed: %08x\n", GetLastError());
1115 SetLastError(0xdeadbeef);
1116 ret = pSetupDiGetDeviceRegistryPropertyW(NULL, NULL, -1, NULL, NULL, 0, NULL);
1117 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
1118 "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
1119 SetLastError(0xdeadbeef);
1120 ret = pSetupDiGetDeviceRegistryPropertyW(set, NULL, -1, NULL, NULL, 0, NULL);
1121 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
1122 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
1123 SetLastError(0xdeadbeef);
1124 ret = pSetupDiGetDeviceRegistryPropertyW(set, &devInfo, -1, NULL, NULL, 0, NULL);
1125 todo_wine
1126 ok(!ret && GetLastError() == ERROR_INVALID_REG_PROPERTY,
1127 "Expected ERROR_INVALID_REG_PROPERTY, got %08x\n", GetLastError());
1128 /* GetLastError() returns nonsense in win2k3 */
1129 ret = pSetupDiGetDeviceRegistryPropertyW(set, &devInfo, SPDRP_FRIENDLYNAME,
1130 NULL, NULL, buflen, NULL);
1131 ok(!ret, "Expected failure, got %d\n", ret);
1132 SetLastError(0xdeadbeef);
1133 ret = pSetupDiGetDeviceRegistryPropertyW(set, &devInfo, SPDRP_FRIENDLYNAME,
1134 NULL, NULL, 0, &size);
1135 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
1136 "Expected ERROR_INSUFFICIENT_BUFFER, got %08x\n", GetLastError());
1137 ok(buflen == size, "Unexpected size: %d\n", size);
1138 SetLastError(0xdeadbeef);
1139 ret = pSetupDiGetDeviceRegistryPropertyW(set, &devInfo, SPDRP_FRIENDLYNAME,
1140 NULL, (PBYTE)buf, buflen, NULL);
1141 ok(ret, "SetupDiGetDeviceRegistryPropertyW failed: %08x\n", GetLastError());
1142 ok(!lstrcmpiW(friendlyName, buf), "Unexpected property\n");
1143 SetLastError(0xdeadbeef);
1144 ret = pSetupDiGetDeviceRegistryPropertyW(set, &devInfo, SPDRP_FRIENDLYNAME,
1145 &regType, (PBYTE)buf, buflen, NULL);
1146 ok(ret, "SetupDiGetDeviceRegistryPropertyW failed: %08x\n", GetLastError());
1147 ok(!lstrcmpiW(friendlyName, buf), "Unexpected value of property\n");
1148 ok(regType == REG_SZ, "Unexpected type of property: %d\n", regType);
1149 SetLastError(0xdeadbeef);
1150 ret = pSetupDiSetDeviceRegistryPropertyW(set, &devInfo, SPDRP_FRIENDLYNAME,
1151 NULL, 0);
1152 ok(ret, "SetupDiSetDeviceRegistryPropertyW failed: %08x\n", GetLastError());
1153 SetLastError(0xdeadbeef);
1154 ret = pSetupDiGetDeviceRegistryPropertyW(set, &devInfo, SPDRP_FRIENDLYNAME,
1155 NULL, (PBYTE)buf, buflen, &size);
1156 todo_wine
1157 ok(!ret && GetLastError() == ERROR_INVALID_DATA,
1158 "Expected ERROR_INVALID_DATA, got %08x\n", GetLastError());
1159 pSetupDiDestroyDeviceInfoList(set);
1162 START_TEST(devinst)
1164 init_function_pointers();
1166 if (pSetupDiCreateDeviceInfoListExW && pSetupDiDestroyDeviceInfoList)
1167 test_SetupDiCreateDeviceInfoListEx();
1168 else
1169 skip("SetupDiCreateDeviceInfoListExW and/or SetupDiDestroyDeviceInfoList not available\n");
1171 if (pSetupDiOpenClassRegKeyExA)
1172 test_SetupDiOpenClassRegKeyExA();
1173 else
1174 skip("SetupDiOpenClassRegKeyExA is not available\n");
1175 testInstallClass();
1176 testCreateDeviceInfo();
1177 testGetDeviceInstanceId();
1178 testRegisterDeviceInfo();
1179 testCreateDeviceInterface();
1180 testGetDeviceInterfaceDetail();
1181 testDevRegKey();
1182 testRegisterAndGetDetail();
1183 testDeviceRegistryPropertyA();
1184 testDeviceRegistryPropertyW();