setupapi/tests: Fix a test on NT4.
[wine/gsoc_dplay.git] / dlls / setupapi / tests / devinst.c
blobf29ce341fe61f9113388d1b1bf21e839aa9a6117
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 static void init_function_pointers(void)
62 hSetupAPI = GetModuleHandleA("setupapi.dll");
64 pSetupDiCreateDeviceInfoA = (void *)GetProcAddress(hSetupAPI, "SetupDiCreateDeviceInfoA");
65 pSetupDiCreateDeviceInfoW = (void *)GetProcAddress(hSetupAPI, "SetupDiCreateDeviceInfoW");
66 pSetupDiCreateDeviceInfoList = (void *)GetProcAddress(hSetupAPI, "SetupDiCreateDeviceInfoList");
67 pSetupDiCreateDeviceInfoListExW = (void *)GetProcAddress(hSetupAPI, "SetupDiCreateDeviceInfoListExW");
68 pSetupDiCreateDeviceInterfaceA = (void *)GetProcAddress(hSetupAPI, "SetupDiCreateDeviceInterfaceA");
69 pSetupDiDestroyDeviceInfoList = (void *)GetProcAddress(hSetupAPI, "SetupDiDestroyDeviceInfoList");
70 pSetupDiCallClassInstaller = (void *)GetProcAddress(hSetupAPI, "SetupDiCallClassInstaller");
71 pSetupDiEnumDeviceInfo = (void *)GetProcAddress(hSetupAPI, "SetupDiEnumDeviceInfo");
72 pSetupDiEnumDeviceInterfaces = (void *)GetProcAddress(hSetupAPI, "SetupDiEnumDeviceInterfaces");
73 pSetupDiGetDeviceInstanceIdA = (void *)GetProcAddress(hSetupAPI, "SetupDiGetDeviceInstanceIdA");
74 pSetupDiGetDeviceInterfaceDetailA = (void *)GetProcAddress(hSetupAPI, "SetupDiGetDeviceInterfaceDetailA");
75 pSetupDiGetDeviceInterfaceDetailW = (void *)GetProcAddress(hSetupAPI, "SetupDiGetDeviceInterfaceDetailW");
76 pSetupDiInstallClassA = (void *)GetProcAddress(hSetupAPI, "SetupDiInstallClassA");
77 pSetupDiOpenClassRegKeyExA = (void *)GetProcAddress(hSetupAPI, "SetupDiOpenClassRegKeyExA");
78 pSetupDiOpenDevRegKey = (void *)GetProcAddress(hSetupAPI, "SetupDiOpenDevRegKey");
79 pSetupDiCreateDevRegKeyW = (void *)GetProcAddress(hSetupAPI, "SetupDiCreateDevRegKeyW");
80 pSetupDiRegisterDeviceInfo = (void *)GetProcAddress(hSetupAPI, "SetupDiRegisterDeviceInfo");
81 pSetupDiGetClassDevsA = (void *)GetProcAddress(hSetupAPI, "SetupDiGetClassDevsA");
82 pSetupDiGetClassDevsW = (void *)GetProcAddress(hSetupAPI, "SetupDiGetClassDevsW");
83 pSetupDiSetDeviceRegistryPropertyA = (void *)GetProcAddress(hSetupAPI, "SetupDiSetDeviceRegistryPropertyA");
84 pSetupDiSetDeviceRegistryPropertyW = (void *)GetProcAddress(hSetupAPI, "SetupDiSetDeviceRegistryPropertyW");
85 pSetupDiGetDeviceRegistryPropertyA = (void *)GetProcAddress(hSetupAPI, "SetupDiGetDeviceRegistryPropertyA");
86 pSetupDiGetDeviceRegistryPropertyW = (void *)GetProcAddress(hSetupAPI, "SetupDiGetDeviceRegistryPropertyW");
89 /* RegDeleteTreeW from dlls/advapi32/registry.c */
90 LSTATUS WINAPI devinst_RegDeleteTreeW(HKEY hKey, LPCWSTR lpszSubKey)
92 LONG ret;
93 DWORD dwMaxSubkeyLen, dwMaxValueLen;
94 DWORD dwMaxLen, dwSize;
95 WCHAR szNameBuf[MAX_PATH], *lpszName = szNameBuf;
96 HKEY hSubKey = hKey;
98 if(lpszSubKey)
100 ret = RegOpenKeyExW(hKey, lpszSubKey, 0, KEY_READ, &hSubKey);
101 if (ret) return ret;
104 /* Get highest length for keys, values */
105 ret = RegQueryInfoKeyW(hSubKey, NULL, NULL, NULL, NULL,
106 &dwMaxSubkeyLen, NULL, NULL, &dwMaxValueLen, NULL, NULL, NULL);
107 if (ret) goto cleanup;
109 dwMaxSubkeyLen++;
110 dwMaxValueLen++;
111 dwMaxLen = max(dwMaxSubkeyLen, dwMaxValueLen);
112 if (dwMaxLen > sizeof(szNameBuf)/sizeof(WCHAR))
114 /* Name too big: alloc a buffer for it */
115 if (!(lpszName = HeapAlloc( GetProcessHeap(), 0, dwMaxLen*sizeof(WCHAR))))
117 ret = ERROR_NOT_ENOUGH_MEMORY;
118 goto cleanup;
123 /* Recursively delete all the subkeys */
124 while (TRUE)
126 dwSize = dwMaxLen;
127 if (RegEnumKeyExW(hSubKey, 0, lpszName, &dwSize, NULL,
128 NULL, NULL, NULL)) break;
130 ret = devinst_RegDeleteTreeW(hSubKey, lpszName);
131 if (ret) goto cleanup;
134 if (lpszSubKey)
135 ret = RegDeleteKeyW(hKey, lpszSubKey);
136 else
137 while (TRUE)
139 dwSize = dwMaxLen;
140 if (RegEnumValueW(hKey, 0, lpszName, &dwSize,
141 NULL, NULL, NULL, NULL)) break;
143 ret = RegDeleteValueW(hKey, lpszName);
144 if (ret) goto cleanup;
147 cleanup:
148 /* Free buffer if allocated */
149 if (lpszName != szNameBuf)
150 HeapFree( GetProcessHeap(), 0, lpszName);
151 if(lpszSubKey)
152 RegCloseKey(hSubKey);
153 return ret;
157 static void test_SetupDiCreateDeviceInfoListEx(void)
159 HDEVINFO devlist;
160 BOOL ret;
161 DWORD error;
162 static CHAR notnull[] = "NotNull";
163 static const WCHAR machine[] = { 'd','u','m','m','y',0 };
165 SetLastError(0xdeadbeef);
166 /* create empty DeviceInfoList, but set Reserved to a value, which is not NULL */
167 devlist = pSetupDiCreateDeviceInfoListExW(NULL, NULL, NULL, notnull);
169 error = GetLastError();
170 if (error == ERROR_CALL_NOT_IMPLEMENTED)
172 skip("SetupDiCreateDeviceInfoListExW is not implemented\n");
173 return;
175 ok(devlist == INVALID_HANDLE_VALUE, "SetupDiCreateDeviceInfoListExW failed : %p %d (expected %p)\n", devlist, error, INVALID_HANDLE_VALUE);
176 ok(error == ERROR_INVALID_PARAMETER, "GetLastError returned wrong value : %d, (expected %d)\n", error, ERROR_INVALID_PARAMETER);
178 SetLastError(0xdeadbeef);
179 /* create empty DeviceInfoList, but set MachineName to something */
180 devlist = pSetupDiCreateDeviceInfoListExW(NULL, NULL, machine, NULL);
182 error = GetLastError();
183 ok(devlist == INVALID_HANDLE_VALUE, "SetupDiCreateDeviceInfoListExW failed : %p %d (expected %p)\n", devlist, error, INVALID_HANDLE_VALUE);
184 ok(error == ERROR_INVALID_MACHINENAME, "GetLastError returned wrong value : %d, (expected %d)\n", error, ERROR_INVALID_MACHINENAME);
186 /* create empty DeviceInfoList */
187 devlist = pSetupDiCreateDeviceInfoListExW(NULL, NULL, NULL, NULL);
188 ok(devlist && devlist != INVALID_HANDLE_VALUE, "SetupDiCreateDeviceInfoListExW failed : %p %d (expected != %p)\n", devlist, error, INVALID_HANDLE_VALUE);
190 /* destroy DeviceInfoList */
191 ret = pSetupDiDestroyDeviceInfoList(devlist);
192 ok(ret, "SetupDiDestroyDeviceInfoList failed : %d\n", error);
195 static void test_SetupDiOpenClassRegKeyExA(void)
197 /* This is a unique guid for testing purposes */
198 GUID guid = {0x6a55b5a4, 0x3f65, 0x11db, {0xb7,0x04,
199 0x00,0x11,0x95,0x5c,0x2b,0xdb}};
200 static const CHAR guidString[] = "{6a55b5a4-3f65-11db-b704-0011955c2bdb}";
201 HKEY hkey;
203 /* Check return value for nonexistent key */
204 hkey = pSetupDiOpenClassRegKeyExA(&guid, KEY_ALL_ACCESS,
205 DIOCR_INSTALLER, NULL, NULL);
206 ok(hkey == INVALID_HANDLE_VALUE,
207 "returned %p (expected INVALID_HANDLE_VALUE)\n", hkey);
209 /* Test it for a key that exists */
210 hkey = SetupDiOpenClassRegKey(NULL, KEY_ALL_ACCESS);
211 if (hkey != INVALID_HANDLE_VALUE)
213 HKEY classKey;
214 if (RegCreateKeyA(hkey, guidString, &classKey) == ERROR_SUCCESS)
216 RegCloseKey(classKey);
217 SetLastError(0xdeadbeef);
218 classKey = pSetupDiOpenClassRegKeyExA(&guid, KEY_ALL_ACCESS,
219 DIOCR_INSTALLER, NULL, NULL);
220 ok(classKey != INVALID_HANDLE_VALUE,
221 "opening class registry key failed with error %d\n",
222 GetLastError());
223 if (classKey != INVALID_HANDLE_VALUE)
224 RegCloseKey(classKey);
225 RegDeleteKeyA(hkey, guidString);
227 else
228 trace("failed to create registry key for test\n");
230 RegCloseKey(hkey);
232 else
233 trace("failed to open classes key\n");
236 static void append_str(char **str, const char *data)
238 sprintf(*str, data);
239 *str += strlen(*str);
242 static void create_inf_file(LPCSTR filename)
244 char data[1024];
245 char *ptr = data;
246 DWORD dwNumberOfBytesWritten;
247 HANDLE hf = CreateFile(filename, GENERIC_WRITE, 0, NULL,
248 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
250 append_str(&ptr, "[Version]\n");
251 append_str(&ptr, "Signature=\"$Chicago$\"\n");
252 append_str(&ptr, "Class=Bogus\n");
253 append_str(&ptr, "ClassGUID={6a55b5a4-3f65-11db-b704-0011955c2bdb}\n");
254 append_str(&ptr, "[ClassInstall32]\n");
255 append_str(&ptr, "AddReg=BogusClass.NT.AddReg\n");
256 append_str(&ptr, "[BogusClass.NT.AddReg]\n");
257 append_str(&ptr, "HKR,,,,\"Wine test devices\"\n");
259 WriteFile(hf, data, ptr - data, &dwNumberOfBytesWritten, NULL);
260 CloseHandle(hf);
263 static void get_temp_filename(LPSTR path)
265 static char curr[MAX_PATH] = { 0 };
266 char temp[MAX_PATH];
267 LPSTR ptr;
269 if (!*curr)
270 GetCurrentDirectoryA(MAX_PATH, curr);
271 GetTempFileNameA(curr, "set", 0, temp);
272 ptr = strrchr(temp, '\\');
274 lstrcpyA(path, ptr + 1);
277 static void testInstallClass(void)
279 static const WCHAR classKey[] = {'S','y','s','t','e','m','\\',
280 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
281 'C','o','n','t','r','o','l','\\','C','l','a','s','s','\\',
282 '{','6','a','5','5','b','5','a','4','-','3','f','6','5','-',
283 '1','1','d','b','-','b','7','0','4','-',
284 '0','0','1','1','9','5','5','c','2','b','d','b','}',0};
285 static const CHAR classKey_win9x[] =
286 "System\\CurrentControlSet\\Services\\Class\\"
287 "{6a55b5a4-3f65-11db-b704-0011955c2bdb}";
288 static const CHAR bogus_win9x[] =
289 "System\\CurrentControlSet\\Services\\Class\\Bogus";
290 char tmpfile[MAX_PATH];
291 BOOL ret;
292 HKEY hkey;
294 if (!pSetupDiInstallClassA)
296 skip("No SetupDiInstallClassA\n");
297 return;
299 tmpfile[0] = '.';
300 tmpfile[1] = '\\';
301 get_temp_filename(tmpfile + 2);
302 create_inf_file(tmpfile + 2);
304 ret = pSetupDiInstallClassA(NULL, NULL, 0, NULL);
305 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
306 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
307 ret = pSetupDiInstallClassA(NULL, NULL, DI_NOVCP, NULL);
308 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
309 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
310 ret = pSetupDiInstallClassA(NULL, tmpfile + 2, DI_NOVCP, NULL);
311 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
312 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
313 ret = pSetupDiInstallClassA(NULL, tmpfile + 2, 0, NULL);
314 ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND,
315 "Expected ERROR_FILE_NOT_FOUND, got %08x\n", GetLastError());
316 /* The next call will succeed. Information is put into the registry but the
317 * location(s) is/are depending on the Windows version.
319 ret = pSetupDiInstallClassA(NULL, tmpfile, 0, NULL);
320 ok(ret, "SetupDiInstallClassA failed: %08x\n", GetLastError());
321 if (!RegOpenKeyA(HKEY_LOCAL_MACHINE, classKey_win9x, &hkey))
323 /* We are on win9x */
324 RegCloseKey(hkey);
325 ok(!RegDeleteKeyA(HKEY_LOCAL_MACHINE, classKey_win9x),
326 "Couldn't delete win9x classkey\n");
327 ok(!RegDeleteKeyA(HKEY_LOCAL_MACHINE, bogus_win9x),
328 "Couldn't delete win9x bogus services class\n");
330 else
332 /* NT4 and above */
333 ok(!RegDeleteKeyW(HKEY_LOCAL_MACHINE, classKey),
334 "Couldn't delete NT classkey\n");
336 DeleteFile(tmpfile);
339 static void testCreateDeviceInfo(void)
341 BOOL ret;
342 HDEVINFO set;
343 GUID guid = {0x6a55b5a4, 0x3f65, 0x11db, {0xb7,0x04,
344 0x00,0x11,0x95,0x5c,0x2b,0xdb}};
346 if (!pSetupDiCreateDeviceInfoList || !pSetupDiEnumDeviceInfo ||
347 !pSetupDiDestroyDeviceInfoList || !pSetupDiCreateDeviceInfoA)
349 skip("No SetupDiCreateDeviceInfoA\n");
350 return;
352 SetLastError(0xdeadbeef);
353 ret = pSetupDiCreateDeviceInfoA(NULL, NULL, NULL, NULL, NULL, 0, NULL);
354 ok(!ret, "Expected failure\n");
355 ok(GetLastError() == ERROR_INVALID_DEVINST_NAME ||
356 GetLastError() == ERROR_INVALID_PARAMETER /* NT4 */ ||
357 GetLastError() == ERROR_INVALID_HANDLE /* Win9x */,
358 "Unexpected last error, got %08x\n", GetLastError());
360 /* If we are running on win9x we should skip these tests. Win95
361 * fails most tests anyway and win98 pops up the "Add New Hardware
362 * Wizard".
364 if (GetLastError() == ERROR_INVALID_HANDLE)
366 skip("We are on win9x where the tests introduce issues\n");
367 return;
370 SetLastError(0xdeadbeef);
371 ret = pSetupDiCreateDeviceInfoA(NULL, "Root\\LEGACY_BOGUS\\0000", NULL,
372 NULL, NULL, 0, NULL);
373 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
374 "Expected ERROR_INVALID_HANDLEHANDLE, got %08x\n", GetLastError());
375 set = pSetupDiCreateDeviceInfoList(&guid, NULL);
376 ok(set != NULL, "SetupDiCreateDeviceInfoList failed: %08x\n",
377 GetLastError());
378 if (set)
380 SP_DEVINFO_DATA devInfo = { 0 };
381 DWORD i;
383 SetLastError(0xdeadbeef);
384 ret = pSetupDiCreateDeviceInfoA(set, "Root\\LEGACY_BOGUS\\0000", NULL,
385 NULL, NULL, 0, NULL);
386 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
387 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
388 /* Finally, with all three required parameters, this succeeds: */
389 ret = pSetupDiCreateDeviceInfoA(set, "Root\\LEGACY_BOGUS\\0000", &guid,
390 NULL, NULL, 0, NULL);
391 ok(ret, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
392 /* This fails because the device ID already exists.. */
393 SetLastError(0xdeadbeef);
394 ret = pSetupDiCreateDeviceInfoA(set, "Root\\LEGACY_BOGUS\\0000", &guid,
395 NULL, NULL, 0, &devInfo);
396 ok(!ret && GetLastError() == ERROR_DEVINST_ALREADY_EXISTS,
397 "Expected ERROR_DEVINST_ALREADY_EXISTS, got %08x\n", GetLastError());
398 /* whereas this "fails" because cbSize is wrong.. */
399 SetLastError(0xdeadbeef);
400 ret = pSetupDiCreateDeviceInfoA(set, "LEGACY_BOGUS", &guid, NULL, NULL,
401 DICD_GENERATE_ID, &devInfo);
402 ok(!ret && GetLastError() == ERROR_INVALID_USER_BUFFER,
403 "Expected ERROR_INVALID_USER_BUFFER, got %08x\n", GetLastError());
404 devInfo.cbSize = sizeof(devInfo);
405 ret = pSetupDiCreateDeviceInfoA(set, "LEGACY_BOGUS", &guid, NULL, NULL,
406 DICD_GENERATE_ID, &devInfo);
407 /* and this finally succeeds. */
408 ok(ret, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
409 /* There were three devices added, however - the second failure just
410 * resulted in the SP_DEVINFO_DATA not getting copied.
412 SetLastError(0xdeadbeef);
413 i = 0;
414 while (pSetupDiEnumDeviceInfo(set, i, &devInfo))
415 i++;
416 ok(i == 3, "Expected 3 devices, got %d\n", i);
417 ok(GetLastError() == ERROR_NO_MORE_ITEMS,
418 "SetupDiEnumDeviceInfo failed: %08x\n", GetLastError());
419 pSetupDiDestroyDeviceInfoList(set);
423 static void testGetDeviceInstanceId(void)
425 BOOL ret;
426 HDEVINFO set;
427 GUID guid = {0x6a55b5a4, 0x3f65, 0x11db, {0xb7,0x04,
428 0x00,0x11,0x95,0x5c,0x2b,0xdb}};
429 SP_DEVINFO_DATA devInfo = { 0 };
431 if (!pSetupDiCreateDeviceInfoList || !pSetupDiDestroyDeviceInfoList ||
432 !pSetupDiCreateDeviceInfoA || !pSetupDiGetDeviceInstanceIdA)
434 skip("No SetupDiGetDeviceInstanceIdA\n");
435 return;
437 SetLastError(0xdeadbeef);
438 ret = pSetupDiGetDeviceInstanceIdA(NULL, NULL, NULL, 0, NULL);
439 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
440 "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
441 SetLastError(0xdeadbeef);
442 ret = pSetupDiGetDeviceInstanceIdA(NULL, &devInfo, NULL, 0, NULL);
443 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
444 "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
445 set = pSetupDiCreateDeviceInfoList(&guid, NULL);
446 ok(set != NULL, "SetupDiCreateDeviceInfoList failed: %08x\n",
447 GetLastError());
448 if (set)
450 char instanceID[MAX_PATH];
451 DWORD size;
453 SetLastError(0xdeadbeef);
454 ret = pSetupDiGetDeviceInstanceIdA(set, NULL, NULL, 0, NULL);
455 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
456 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
457 SetLastError(0xdeadbeef);
458 ret = pSetupDiGetDeviceInstanceIdA(set, &devInfo, NULL, 0, NULL);
459 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
460 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
461 SetLastError(0xdeadbeef);
462 ret = pSetupDiGetDeviceInstanceIdA(set, &devInfo, NULL, 0, &size);
463 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
464 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
465 devInfo.cbSize = sizeof(devInfo);
466 SetLastError(0xdeadbeef);
467 ret = pSetupDiGetDeviceInstanceIdA(set, &devInfo, NULL, 0, &size);
468 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
469 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
470 ret = pSetupDiCreateDeviceInfoA(set, "Root\\LEGACY_BOGUS\\0000", &guid,
471 NULL, NULL, 0, &devInfo);
472 ok(ret, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
473 SetLastError(0xdeadbeef);
474 ret = pSetupDiGetDeviceInstanceIdA(set, &devInfo, NULL, 0, &size);
475 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
476 "Expected ERROR_INSUFFICIENT_BUFFER, got %08x\n", GetLastError());
477 ret = pSetupDiGetDeviceInstanceIdA(set, &devInfo, instanceID,
478 sizeof(instanceID), NULL);
479 ok(ret, "SetupDiGetDeviceInstanceIdA failed: %08x\n", GetLastError());
480 ok(!lstrcmpA(instanceID, "ROOT\\LEGACY_BOGUS\\0000"),
481 "Unexpected instance ID %s\n", instanceID);
482 ret = pSetupDiCreateDeviceInfoA(set, "LEGACY_BOGUS", &guid,
483 NULL, NULL, DICD_GENERATE_ID, &devInfo);
484 ok(ret, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
485 ret = pSetupDiGetDeviceInstanceIdA(set, &devInfo, instanceID,
486 sizeof(instanceID), NULL);
487 ok(ret, "SetupDiGetDeviceInstanceIdA failed: %08x\n", GetLastError());
488 ok(!lstrcmpA(instanceID, "ROOT\\LEGACY_BOGUS\\0001"),
489 "Unexpected instance ID %s\n", instanceID);
490 pSetupDiDestroyDeviceInfoList(set);
494 static void testRegisterDeviceInfo(void)
496 BOOL ret;
497 GUID guid = {0x6a55b5a4, 0x3f65, 0x11db, {0xb7,0x04,
498 0x00,0x11,0x95,0x5c,0x2b,0xdb}};
499 HDEVINFO set;
501 if (!pSetupDiCreateDeviceInfoList || !pSetupDiDestroyDeviceInfoList ||
502 !pSetupDiRegisterDeviceInfo)
504 skip("No SetupDiRegisterDeviceInfo\n");
505 return;
507 SetLastError(0xdeadbeef);
508 ret = pSetupDiRegisterDeviceInfo(NULL, NULL, 0, NULL, NULL, NULL);
509 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
510 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
511 set = pSetupDiCreateDeviceInfoList(&guid, NULL);
512 ok(set != NULL, "SetupDiCreateDeviceInfoList failed: %d\n", GetLastError());
513 if (set)
515 SP_DEVINFO_DATA devInfo = { 0 };
517 SetLastError(0xdeadbeef);
518 ret = pSetupDiRegisterDeviceInfo(set, NULL, 0, NULL, NULL, NULL);
519 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
520 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
521 SetLastError(0xdeadbeef);
522 ret = pSetupDiRegisterDeviceInfo(set, &devInfo, 0, NULL, NULL, NULL);
523 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
524 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
525 devInfo.cbSize = sizeof(devInfo);
526 SetLastError(0xdeadbeef);
527 ret = pSetupDiRegisterDeviceInfo(set, &devInfo, 0, NULL, NULL, NULL);
528 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
529 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
530 ret = pSetupDiCreateDeviceInfoA(set, "USB\\BOGUS\\0000", &guid,
531 NULL, NULL, 0, &devInfo);
532 ok(ret || GetLastError() == ERROR_DEVINST_ALREADY_EXISTS,
533 "SetupDiCreateDeviceInfoA failed: %d\n", GetLastError());
534 if (ret)
536 /* If it already existed, registering it again will fail */
537 ret = pSetupDiRegisterDeviceInfo(set, &devInfo, 0, NULL, NULL,
538 NULL);
539 ok(ret, "SetupDiCreateDeviceInfoA failed: %d\n", GetLastError());
541 /* FIXME: On Win2K+ systems, this is now persisted to registry in
542 * HKLM\System\CCS\Enum\USB\Bogus\0000. I don't check because the
543 * Win9x location is different.
544 * FIXME: the key also becomes undeletable. How to get rid of it?
546 pSetupDiDestroyDeviceInfoList(set);
550 static void testCreateDeviceInterface(void)
552 BOOL ret;
553 GUID guid = {0x6a55b5a4, 0x3f65, 0x11db, {0xb7,0x04,
554 0x00,0x11,0x95,0x5c,0x2b,0xdb}};
555 HDEVINFO set;
557 if (!pSetupDiCreateDeviceInfoList || !pSetupDiDestroyDeviceInfoList ||
558 !pSetupDiCreateDeviceInfoA || !pSetupDiCreateDeviceInterfaceA ||
559 !pSetupDiEnumDeviceInterfaces)
561 skip("No SetupDiCreateDeviceInterfaceA\n");
562 return;
564 SetLastError(0xdeadbeef);
565 ret = pSetupDiCreateDeviceInterfaceA(NULL, NULL, NULL, NULL, 0, NULL);
566 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
567 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
568 SetLastError(0xdeadbeef);
569 ret = pSetupDiCreateDeviceInterfaceA(NULL, NULL, &guid, NULL, 0, NULL);
570 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
571 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
572 set = pSetupDiCreateDeviceInfoList(&guid, NULL);
573 ok(set != NULL, "SetupDiCreateDeviceInfoList failed: %d\n", GetLastError());
574 if (set)
576 SP_DEVINFO_DATA devInfo = { 0 };
577 SP_DEVICE_INTERFACE_DATA interfaceData = { sizeof(interfaceData),
578 { 0 } };
579 DWORD i;
581 SetLastError(0xdeadbeef);
582 ret = pSetupDiCreateDeviceInterfaceA(set, NULL, NULL, NULL, 0, NULL);
583 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
584 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
585 SetLastError(0xdeadbeef);
586 ret = pSetupDiCreateDeviceInterfaceA(set, &devInfo, NULL, NULL, 0,
587 NULL);
588 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
589 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
590 devInfo.cbSize = sizeof(devInfo);
591 ret = pSetupDiCreateDeviceInfoA(set, "ROOT\\LEGACY_BOGUS\\0000", &guid,
592 NULL, NULL, 0, &devInfo);
593 ok(ret, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
594 SetLastError(0xdeadbeef);
595 ret = pSetupDiCreateDeviceInterfaceA(set, &devInfo, NULL, NULL, 0,
596 NULL);
597 ok(!ret && GetLastError() == ERROR_INVALID_USER_BUFFER,
598 "Expected ERROR_INVALID_USER_BUFFER, got %08x\n", GetLastError());
599 ret = pSetupDiCreateDeviceInterfaceA(set, &devInfo, &guid, NULL, 0,
600 NULL);
601 ok(ret, "SetupDiCreateDeviceInterfaceA failed: %08x\n", GetLastError());
602 /* Creating the same interface a second time succeeds */
603 ret = pSetupDiCreateDeviceInterfaceA(set, &devInfo, &guid, NULL, 0,
604 NULL);
605 ok(ret, "SetupDiCreateDeviceInterfaceA failed: %08x\n", GetLastError());
606 ret = pSetupDiCreateDeviceInterfaceA(set, &devInfo, &guid, "Oogah", 0,
607 NULL);
608 ok(ret, "SetupDiCreateDeviceInterfaceA failed: %08x\n", GetLastError());
609 ret = pSetupDiEnumDeviceInterfaces(set, &devInfo, &guid, 0,
610 &interfaceData);
611 ok(ret, "SetupDiEnumDeviceInterfaces failed: %d\n", GetLastError());
612 i = 0;
613 while (pSetupDiEnumDeviceInterfaces(set, &devInfo, &guid, i,
614 &interfaceData))
615 i++;
616 ok(i == 2, "expected 2 interfaces, got %d\n", i);
617 ok(GetLastError() == ERROR_NO_MORE_ITEMS,
618 "SetupDiEnumDeviceInterfaces failed: %08x\n", GetLastError());
619 pSetupDiDestroyDeviceInfoList(set);
623 static void testGetDeviceInterfaceDetail(void)
625 BOOL ret;
626 GUID guid = {0x6a55b5a4, 0x3f65, 0x11db, {0xb7,0x04,
627 0x00,0x11,0x95,0x5c,0x2b,0xdb}};
628 HDEVINFO set;
630 if (!pSetupDiCreateDeviceInfoList || !pSetupDiDestroyDeviceInfoList ||
631 !pSetupDiCreateDeviceInfoA || !pSetupDiCreateDeviceInterfaceA ||
632 !pSetupDiGetDeviceInterfaceDetailA)
634 skip("No SetupDiGetDeviceInterfaceDetailA\n");
635 return;
637 SetLastError(0xdeadbeef);
638 ret = pSetupDiGetDeviceInterfaceDetailA(NULL, NULL, NULL, 0, NULL, NULL);
639 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
640 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
641 set = pSetupDiCreateDeviceInfoList(&guid, NULL);
642 ok(set != NULL, "SetupDiCreateDeviceInfoList failed: %d\n", GetLastError());
643 if (set)
645 SP_DEVINFO_DATA devInfo = { sizeof(devInfo), { 0 } };
646 SP_DEVICE_INTERFACE_DATA interfaceData = { sizeof(interfaceData),
647 { 0 } };
648 DWORD size = 0;
650 SetLastError(0xdeadbeef);
651 ret = pSetupDiGetDeviceInterfaceDetailA(set, NULL, NULL, 0, NULL,
652 NULL);
653 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
654 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
655 ret = pSetupDiCreateDeviceInfoA(set, "ROOT\\LEGACY_BOGUS\\0000", &guid,
656 NULL, NULL, 0, &devInfo);
657 ok(ret, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
658 SetLastError(0xdeadbeef);
659 ret = pSetupDiCreateDeviceInterfaceA(set, &devInfo, &guid, NULL, 0,
660 &interfaceData);
661 ok(ret, "SetupDiCreateDeviceInterfaceA failed: %08x\n", GetLastError());
662 SetLastError(0xdeadbeef);
663 ret = pSetupDiGetDeviceInterfaceDetailA(set, &interfaceData, NULL,
664 0, NULL, NULL);
665 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
666 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
667 SetLastError(0xdeadbeef);
668 ret = pSetupDiGetDeviceInterfaceDetailA(set, &interfaceData, NULL,
669 100, NULL, NULL);
670 ok(!ret && GetLastError() == ERROR_INVALID_USER_BUFFER,
671 "Expected ERROR_INVALID_USER_BUFFER, got %08x\n", GetLastError());
672 SetLastError(0xdeadbeef);
673 ret = pSetupDiGetDeviceInterfaceDetailA(set, &interfaceData, NULL,
674 0, &size, NULL);
675 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
676 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
677 if (!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER)
679 static const char path[] =
680 "\\\\?\\root#legacy_bogus#0000#{6a55b5a4-3f65-11db-b704-0011955c2bdb}";
681 LPBYTE buf = HeapAlloc(GetProcessHeap(), 0, size);
682 SP_DEVICE_INTERFACE_DETAIL_DATA_A *detail =
683 (SP_DEVICE_INTERFACE_DETAIL_DATA_A *)buf;
684 DWORD expectedsize = offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_W, DevicePath) + sizeof(WCHAR)*(1 + strlen(path));
686 detail->cbSize = 0;
687 SetLastError(0xdeadbeef);
688 ret = pSetupDiGetDeviceInterfaceDetailA(set, &interfaceData, detail,
689 size, &size, NULL);
690 ok(!ret && GetLastError() == ERROR_INVALID_USER_BUFFER,
691 "Expected ERROR_INVALID_USER_BUFFER, got %08x\n", GetLastError());
692 detail->cbSize = size;
693 SetLastError(0xdeadbeef);
694 ret = pSetupDiGetDeviceInterfaceDetailA(set, &interfaceData, detail,
695 size, &size, NULL);
696 ok(!ret && GetLastError() == ERROR_INVALID_USER_BUFFER,
697 "Expected ERROR_INVALID_USER_BUFFER, got %08x\n", GetLastError());
698 detail->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_A);
699 SetLastError(0xdeadbeef);
700 ret = pSetupDiGetDeviceInterfaceDetailA(set, &interfaceData, detail,
701 size, &size, NULL);
702 ok(!ret && GetLastError() == ERROR_INVALID_USER_BUFFER,
703 "Expected ERROR_INVALID_USER_BUFFER, got %08x\n", GetLastError());
704 /* Windows 2000 and up check for the exact size. Win9x returns ERROR_INVALID_PARAMETER
705 * on every call (so doesn't get here) and NT4 doesn't have this function.
707 detail->cbSize = FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_A, DevicePath[1]);
708 ret = pSetupDiGetDeviceInterfaceDetailA(set, &interfaceData, detail,
709 size, &size, NULL);
710 ok(ret, "SetupDiGetDeviceInterfaceDetailA failed: %d\n",
711 GetLastError());
712 ok(!lstrcmpiA(path, detail->DevicePath), "Unexpected path %s\n",
713 detail->DevicePath);
714 /* Check SetupDiGetDeviceInterfaceDetailW */
715 if (pSetupDiGetDeviceInterfaceDetailW)
717 ret = pSetupDiGetDeviceInterfaceDetailW(set, &interfaceData, NULL, 0, &size, NULL);
718 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Expected ERROR_INSUFFICIENT_BUFFER, got error code: %d\n", GetLastError());
719 ok(expectedsize == size, "SetupDiGetDeviceInterfaceDetailW returned wrong reqsize: expected %d, got %d\n", expectedsize, size);
721 else
722 skip("SetupDiGetDeviceInterfaceDetailW is not available\n");
724 HeapFree(GetProcessHeap(), 0, buf);
726 pSetupDiDestroyDeviceInfoList(set);
730 static void testDevRegKey(void)
732 static const WCHAR classKey[] = {'S','y','s','t','e','m','\\',
733 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
734 'C','o','n','t','r','o','l','\\','C','l','a','s','s','\\',
735 '{','6','a','5','5','b','5','a','4','-','3','f','6','5','-',
736 '1','1','d','b','-','b','7','0','4','-',
737 '0','0','1','1','9','5','5','c','2','b','d','b','}',0};
738 BOOL ret;
739 GUID guid = {0x6a55b5a4, 0x3f65, 0x11db, {0xb7,0x04,
740 0x00,0x11,0x95,0x5c,0x2b,0xdb}};
741 HDEVINFO set;
743 if (!pSetupDiCreateDeviceInfoList || !pSetupDiDestroyDeviceInfoList ||
744 !pSetupDiCreateDeviceInfoA || !pSetupDiOpenDevRegKey ||
745 !pSetupDiRegisterDeviceInfo || !pSetupDiCreateDevRegKeyW ||
746 !pSetupDiCallClassInstaller)
748 skip("No SetupDiOpenDevRegKey\n");
749 return;
751 set = pSetupDiCreateDeviceInfoList(&guid, NULL);
752 ok(set != NULL, "SetupDiCreateDeviceInfoList failed: %d\n", GetLastError());
753 if (set)
755 SP_DEVINFO_DATA devInfo = { sizeof(devInfo), { 0 } };
756 HKEY key = INVALID_HANDLE_VALUE;
758 ret = pSetupDiCreateDeviceInfoA(set, "ROOT\\LEGACY_BOGUS\\0000", &guid,
759 NULL, NULL, 0, &devInfo);
760 ok(ret, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
761 SetLastError(0xdeadbeef);
762 key = pSetupDiOpenDevRegKey(NULL, NULL, 0, 0, 0, 0);
763 ok(!key || key == INVALID_HANDLE_VALUE,
764 "Expected INVALID_HANDLE_VALUE or a NULL key (NT4)\n");
765 ok(GetLastError() == ERROR_INVALID_HANDLE,
766 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
767 SetLastError(0xdeadbeef);
768 key = pSetupDiOpenDevRegKey(set, NULL, 0, 0, 0, 0);
769 ok(key == INVALID_HANDLE_VALUE &&
770 GetLastError() == ERROR_INVALID_PARAMETER,
771 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
772 SetLastError(0xdeadbeef);
773 key = pSetupDiOpenDevRegKey(set, &devInfo, 0, 0, 0, 0);
774 ok(key == INVALID_HANDLE_VALUE &&
775 GetLastError() == ERROR_INVALID_FLAGS,
776 "Expected ERROR_INVALID_FLAGS, got %d\n", GetLastError());
777 SetLastError(0xdeadbeef);
778 key = pSetupDiOpenDevRegKey(set, &devInfo, DICS_FLAG_GLOBAL, 0, 0, 0);
779 ok(key == INVALID_HANDLE_VALUE &&
780 GetLastError() == ERROR_INVALID_FLAGS,
781 "Expected ERROR_INVALID_FLAGS, got %d\n", GetLastError());
782 SetLastError(0xdeadbeef);
783 key = pSetupDiOpenDevRegKey(set, &devInfo, DICS_FLAG_GLOBAL, 0,
784 DIREG_BOTH, 0);
785 ok(key == INVALID_HANDLE_VALUE &&
786 GetLastError() == ERROR_INVALID_FLAGS,
787 "Expected ERROR_INVALID_FLAGS, got %d\n", GetLastError());
788 SetLastError(0xdeadbeef);
789 key = pSetupDiOpenDevRegKey(set, &devInfo, DICS_FLAG_GLOBAL, 0,
790 DIREG_DRV, 0);
791 ok(key == INVALID_HANDLE_VALUE &&
792 GetLastError() == ERROR_DEVINFO_NOT_REGISTERED,
793 "Expected ERROR_DEVINFO_NOT_REGISTERED, got %08x\n", GetLastError());
794 SetLastError(0xdeadbeef);
795 ret = pSetupDiRegisterDeviceInfo(set, &devInfo, 0, NULL, NULL, NULL);
796 ok(ret, "SetupDiRegisterDeviceInfo failed: %08x\n", GetLastError());
797 SetLastError(0xdeadbeef);
798 key = pSetupDiOpenDevRegKey(set, &devInfo, DICS_FLAG_GLOBAL, 0,
799 DIREG_DRV, 0);
800 /* The software key isn't created by default */
801 todo_wine
802 ok(key == INVALID_HANDLE_VALUE &&
803 GetLastError() == ERROR_KEY_DOES_NOT_EXIST,
804 "Expected ERROR_KEY_DOES_NOT_EXIST_EXIST, got %08x\n", GetLastError());
805 SetLastError(0xdeadbeef);
806 key = pSetupDiOpenDevRegKey(set, &devInfo, DICS_FLAG_GLOBAL, 0,
807 DIREG_DEV, 0);
808 todo_wine
809 ok(key == INVALID_HANDLE_VALUE &&
810 GetLastError() == ERROR_KEY_DOES_NOT_EXIST,
811 "Expected ERROR_KEY_DOES_NOT_EXIST_EXIST, got %08x\n", GetLastError());
812 SetLastError(0xdeadbeef);
813 key = pSetupDiCreateDevRegKeyW(set, &devInfo, DICS_FLAG_GLOBAL, 0,
814 DIREG_DRV, NULL, NULL);
815 ok(key != INVALID_HANDLE_VALUE, "SetupDiCreateDevRegKey failed: %08x\n",
816 GetLastError());
817 RegCloseKey(key);
818 SetLastError(0xdeadbeef);
819 key = pSetupDiOpenDevRegKey(set, &devInfo, DICS_FLAG_GLOBAL, 0,
820 DIREG_DRV, 0);
821 todo_wine
822 ok(key == INVALID_HANDLE_VALUE &&
823 (GetLastError() == ERROR_INVALID_DATA ||
824 GetLastError() == ERROR_ACCESS_DENIED), /* win2k3 */
825 "Expected ERROR_INVALID_DATA or ERROR_ACCESS_DENIED, got %08x\n", GetLastError());
826 key = pSetupDiOpenDevRegKey(set, &devInfo, DICS_FLAG_GLOBAL, 0,
827 DIREG_DRV, KEY_READ);
828 ok(key != INVALID_HANDLE_VALUE, "SetupDiOpenDevRegKey failed: %08x\n",
829 GetLastError());
830 ret = pSetupDiCallClassInstaller(DIF_REMOVE, set, &devInfo);
831 pSetupDiDestroyDeviceInfoList(set);
833 devinst_RegDeleteTreeW(HKEY_LOCAL_MACHINE, classKey);
836 static void testRegisterAndGetDetail(void)
838 HDEVINFO set;
839 BOOL ret;
840 GUID guid = {0x6a55b5a4, 0x3f65, 0x11db, {0xb7,0x04,
841 0x00,0x11,0x95,0x5c,0x2b,0xdb}};
842 SP_DEVINFO_DATA devInfo = { sizeof(SP_DEVINFO_DATA), { 0 } };
843 SP_DEVICE_INTERFACE_DATA interfaceData = { sizeof(interfaceData), { 0 } };
844 DWORD dwSize = 0;
846 SetLastError(0xdeadbeef);
847 set = pSetupDiGetClassDevsA(&guid, NULL, 0, DIGCF_ALLCLASSES);
848 ok(set != INVALID_HANDLE_VALUE, "SetupDiGetClassDevsA failed: %08x\n",
849 GetLastError());
851 SetLastError(0xdeadbeef);
852 ret = pSetupDiCreateDeviceInfoA(set, "LEGACY_BOGUS", &guid, NULL, 0,
853 DICD_GENERATE_ID, &devInfo);
854 ok(ret, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
855 SetLastError(0xdeadbeef);
856 ret = pSetupDiCreateDeviceInterfaceA(set, &devInfo, &guid, NULL, 0, &interfaceData);
857 ok(ret, "SetupDiCreateDeviceInterfaceA failed: %08x\n", GetLastError());
858 SetLastError(0xdeadbeef);
859 ret = pSetupDiRegisterDeviceInfo(set, &devInfo, 0, NULL, NULL, NULL);
860 ok(ret, "SetupDiRegisterDeviceInfo failed: %08x\n", GetLastError());
862 pSetupDiDestroyDeviceInfoList(set);
864 SetLastError(0xdeadbeef);
865 set = pSetupDiGetClassDevsA(&guid, NULL, 0, DIGCF_DEVICEINTERFACE);
866 ok(set != INVALID_HANDLE_VALUE, "SetupDiGetClassDevsA failed: %08x\n",
867 GetLastError());
869 SetLastError(0xdeadbeef);
870 ret = pSetupDiEnumDeviceInterfaces(set, NULL, &guid, 0, &interfaceData);
871 ok(ret, "SetupDiEnumDeviceInterfaces failed: %08x\n", GetLastError());
872 SetLastError(0xdeadbeef);
873 ret = pSetupDiGetDeviceInterfaceDetailA(set, &interfaceData, NULL, 0, &dwSize, NULL);
874 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
875 "Expected ERROR_INSUFFICIENT_BUFFER, got %08x\n", GetLastError());
876 if (!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER)
878 static const char path[] =
879 "\\\\?\\root#legacy_bogus#0000#{6a55b5a4-3f65-11db-b704-0011955c2bdb}";
880 PSP_DEVICE_INTERFACE_DETAIL_DATA_A detail = NULL;
882 detail = (PSP_DEVICE_INTERFACE_DETAIL_DATA_A)HeapAlloc(GetProcessHeap(), 0, dwSize);
883 if (detail)
885 detail->cbSize = offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA_A, DevicePath) + sizeof(char);
886 SetLastError(0xdeadbeef);
887 ret = pSetupDiGetDeviceInterfaceDetailA(set, &interfaceData,
888 detail, dwSize, &dwSize, NULL);
889 ok(ret, "SetupDiGetDeviceInterfaceDetailA failed: %08x\n", GetLastError());
890 ok(!lstrcmpiA(path, detail->DevicePath), "Unexpected path %s\n",
891 detail->DevicePath);
892 HeapFree(GetProcessHeap(), 0, detail);
896 pSetupDiDestroyDeviceInfoList(set);
899 static void testDeviceRegistryPropertyA()
901 HDEVINFO set;
902 GUID guid = {0x6a55b5a4, 0x3f65, 0x11db, {0xb7,0x04,
903 0x00,0x11,0x95,0x5c,0x2b,0xdb}};
904 SP_DEVINFO_DATA devInfo = { sizeof(SP_DEVINFO_DATA), { 0 } };
905 CHAR devName[] = "LEGACY_BOGUS";
906 CHAR friendlyName[] = "Bogus";
907 CHAR buf[6] = "";
908 DWORD buflen = 6;
909 DWORD size;
910 DWORD regType;
911 BOOL ret;
913 SetLastError(0xdeadbeef);
914 set = pSetupDiGetClassDevsA(&guid, NULL, 0, DIGCF_DEVICEINTERFACE);
915 ok(set != INVALID_HANDLE_VALUE, "SetupDiGetClassDevsA failed: %08x\n",
916 GetLastError());
917 SetLastError(0xdeadbeef);
918 ret = pSetupDiCreateDeviceInfoA(set, devName, &guid, NULL, NULL,
919 DICD_GENERATE_ID, &devInfo);
920 ok(ret, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
921 SetLastError(0xdeadbeef);
922 ret = pSetupDiSetDeviceRegistryPropertyA(NULL, NULL, -1, NULL, 0);
923 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
924 "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
925 SetLastError(0xdeadbeef);
926 ret = pSetupDiSetDeviceRegistryPropertyA(set, NULL, -1, NULL, 0);
927 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
928 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
929 SetLastError(0xdeadbeef);
930 ret = pSetupDiSetDeviceRegistryPropertyA(set, &devInfo, -1, NULL, 0);
931 todo_wine
932 ok(!ret && GetLastError() == ERROR_INVALID_REG_PROPERTY,
933 "Expected ERROR_INVALID_REG_PROPERTY, got %08x\n", GetLastError());
934 /* GetLastError() returns nonsense in win2k3 */
935 ret = pSetupDiSetDeviceRegistryPropertyA(set, &devInfo, SPDRP_FRIENDLYNAME,
936 NULL, 0);
937 todo_wine
938 ok(!ret, "Expected failure, got %d\n", ret);
939 SetLastError(0xdeadbeef);
940 ret = pSetupDiSetDeviceRegistryPropertyA(set, &devInfo, SPDRP_FRIENDLYNAME,
941 (PBYTE)friendlyName, buflen);
942 ok(ret, "SetupDiSetDeviceRegistryPropertyA failed: %08x\n", GetLastError());
943 SetLastError(0xdeadbeef);
944 ret = pSetupDiGetDeviceRegistryPropertyA(NULL, NULL, -1, NULL, NULL, 0, NULL);
945 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
946 "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
947 SetLastError(0xdeadbeef);
948 ret = pSetupDiGetDeviceRegistryPropertyA(set, NULL, -1, NULL, NULL, 0, NULL);
949 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
950 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
951 SetLastError(0xdeadbeef);
952 ret = pSetupDiGetDeviceRegistryPropertyA(set, &devInfo, -1, NULL, NULL, 0, NULL);
953 todo_wine
954 ok(!ret && GetLastError() == ERROR_INVALID_REG_PROPERTY,
955 "Expected ERROR_INVALID_REG_PROPERTY, got %08x\n", GetLastError());
956 /* GetLastError() returns nonsense in win2k3 */
957 ret = pSetupDiGetDeviceRegistryPropertyA(set, &devInfo, SPDRP_FRIENDLYNAME,
958 NULL, NULL, buflen, NULL);
959 ok(!ret, "Expected failure, got %d\n", ret);
960 SetLastError(0xdeadbeef);
961 ret = pSetupDiGetDeviceRegistryPropertyA(set, &devInfo, SPDRP_FRIENDLYNAME,
962 NULL, NULL, 0, &size);
963 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
964 "Expected ERROR_INSUFFICIENT_BUFFER, got %08x\n", GetLastError());
965 ok(buflen == size, "Unexpected size: %d\n", size);
966 SetLastError(0xdeadbeef);
967 ret = pSetupDiGetDeviceRegistryPropertyA(set, &devInfo, SPDRP_FRIENDLYNAME,
968 NULL, (PBYTE)buf, buflen, NULL);
969 ok(ret, "SetupDiGetDeviceRegistryPropertyA failed: %08x\n", GetLastError());
970 ok(!lstrcmpiA(friendlyName, buf), "Unexpected property\n");
971 SetLastError(0xdeadbeef);
972 ret = pSetupDiGetDeviceRegistryPropertyA(set, &devInfo, SPDRP_FRIENDLYNAME,
973 &regType, (PBYTE)buf, buflen, NULL);
974 ok(ret, "SetupDiGetDeviceRegistryPropertyA failed: %08x\n", GetLastError());
975 ok(!lstrcmpiA(friendlyName, buf), "Unexpected value of property\n");
976 ok(regType == REG_SZ, "Unexpected type of property: %d\n", regType);
977 SetLastError(0xdeadbeef);
978 ret = pSetupDiSetDeviceRegistryPropertyA(set, &devInfo, SPDRP_FRIENDLYNAME,
979 NULL, 0);
980 ok(ret, "SetupDiSetDeviceRegistryPropertyA failed: %08x\n", GetLastError());
981 SetLastError(0xdeadbeef);
982 ret = pSetupDiGetDeviceRegistryPropertyA(set, &devInfo, SPDRP_FRIENDLYNAME,
983 NULL, (PBYTE)buf, buflen, &size);
984 todo_wine
985 ok(!ret && GetLastError() == ERROR_INVALID_DATA,
986 "Expected ERROR_INVALID_DATA, got %08x\n", GetLastError());
987 pSetupDiDestroyDeviceInfoList(set);
990 static void testDeviceRegistryPropertyW()
992 HDEVINFO set;
993 GUID guid = {0x6a55b5a4, 0x3f65, 0x11db, {0xb7,0x04,
994 0x00,0x11,0x95,0x5c,0x2b,0xdb}};
995 SP_DEVINFO_DATA devInfo = { sizeof(SP_DEVINFO_DATA), { 0 } };
996 WCHAR devName[] = {'L','E','G','A','C','Y','_','B','O','G','U','S',0};
997 WCHAR friendlyName[] = {'B','o','g','u','s',0};
998 WCHAR buf[6] = {0};
999 DWORD buflen = 6 * sizeof(WCHAR);
1000 DWORD size;
1001 DWORD regType;
1002 BOOL ret;
1004 SetLastError(0xdeadbeef);
1005 set = pSetupDiGetClassDevsW(&guid, NULL, 0, DIGCF_DEVICEINTERFACE);
1006 if (set == INVALID_HANDLE_VALUE && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1008 skip("W-functions are not implemented\n");
1009 return;
1011 ok(set != INVALID_HANDLE_VALUE, "SetupDiGetClassDevsW failed: %08x\n",
1012 GetLastError());
1013 SetLastError(0xdeadbeef);
1014 ret = pSetupDiCreateDeviceInfoW(set, devName, &guid, NULL, NULL,
1015 DICD_GENERATE_ID, &devInfo);
1016 ok(ret, "SetupDiCreateDeviceInfoW failed: %08x\n", GetLastError());
1017 SetLastError(0xdeadbeef);
1018 ret = pSetupDiSetDeviceRegistryPropertyW(NULL, NULL, -1, NULL, 0);
1019 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
1020 "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
1021 SetLastError(0xdeadbeef);
1022 ret = pSetupDiSetDeviceRegistryPropertyW(set, NULL, -1, NULL, 0);
1023 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
1024 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
1025 SetLastError(0xdeadbeef);
1026 ret = pSetupDiSetDeviceRegistryPropertyW(set, &devInfo, -1, NULL, 0);
1027 todo_wine
1028 ok(!ret && GetLastError() == ERROR_INVALID_REG_PROPERTY,
1029 "Expected ERROR_INVALID_REG_PROPERTY, got %08x\n", GetLastError());
1030 /* GetLastError() returns nonsense in win2k3 */
1031 ret = pSetupDiSetDeviceRegistryPropertyW(set, &devInfo, SPDRP_FRIENDLYNAME,
1032 NULL, 0);
1033 todo_wine
1034 ok(!ret, "Expected failure, got %d\n", ret);
1035 SetLastError(0xdeadbeef);
1036 ret = pSetupDiSetDeviceRegistryPropertyW(set, &devInfo, SPDRP_FRIENDLYNAME,
1037 (PBYTE)friendlyName, buflen);
1038 ok(ret, "SetupDiSetDeviceRegistryPropertyW failed: %08x\n", GetLastError());
1039 SetLastError(0xdeadbeef);
1040 ret = pSetupDiGetDeviceRegistryPropertyW(NULL, NULL, -1, NULL, NULL, 0, NULL);
1041 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
1042 "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
1043 SetLastError(0xdeadbeef);
1044 ret = pSetupDiGetDeviceRegistryPropertyW(set, NULL, -1, NULL, NULL, 0, NULL);
1045 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
1046 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
1047 SetLastError(0xdeadbeef);
1048 ret = pSetupDiGetDeviceRegistryPropertyW(set, &devInfo, -1, NULL, NULL, 0, NULL);
1049 todo_wine
1050 ok(!ret && GetLastError() == ERROR_INVALID_REG_PROPERTY,
1051 "Expected ERROR_INVALID_REG_PROPERTY, got %08x\n", GetLastError());
1052 /* GetLastError() returns nonsense in win2k3 */
1053 ret = pSetupDiGetDeviceRegistryPropertyW(set, &devInfo, SPDRP_FRIENDLYNAME,
1054 NULL, NULL, buflen, NULL);
1055 ok(!ret, "Expected failure, got %d\n", ret);
1056 SetLastError(0xdeadbeef);
1057 ret = pSetupDiGetDeviceRegistryPropertyW(set, &devInfo, SPDRP_FRIENDLYNAME,
1058 NULL, NULL, 0, &size);
1059 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
1060 "Expected ERROR_INSUFFICIENT_BUFFER, got %08x\n", GetLastError());
1061 ok(buflen == size, "Unexpected size: %d\n", size);
1062 SetLastError(0xdeadbeef);
1063 ret = pSetupDiGetDeviceRegistryPropertyW(set, &devInfo, SPDRP_FRIENDLYNAME,
1064 NULL, (PBYTE)buf, buflen, NULL);
1065 ok(ret, "SetupDiGetDeviceRegistryPropertyW failed: %08x\n", GetLastError());
1066 ok(!lstrcmpiW(friendlyName, buf), "Unexpected property\n");
1067 SetLastError(0xdeadbeef);
1068 ret = pSetupDiGetDeviceRegistryPropertyW(set, &devInfo, SPDRP_FRIENDLYNAME,
1069 &regType, (PBYTE)buf, buflen, NULL);
1070 ok(ret, "SetupDiGetDeviceRegistryPropertyW failed: %08x\n", GetLastError());
1071 ok(!lstrcmpiW(friendlyName, buf), "Unexpected value of property\n");
1072 ok(regType == REG_SZ, "Unexpected type of property: %d\n", regType);
1073 SetLastError(0xdeadbeef);
1074 ret = pSetupDiSetDeviceRegistryPropertyW(set, &devInfo, SPDRP_FRIENDLYNAME,
1075 NULL, 0);
1076 ok(ret, "SetupDiSetDeviceRegistryPropertyW failed: %08x\n", GetLastError());
1077 SetLastError(0xdeadbeef);
1078 ret = pSetupDiGetDeviceRegistryPropertyW(set, &devInfo, SPDRP_FRIENDLYNAME,
1079 NULL, (PBYTE)buf, buflen, &size);
1080 todo_wine
1081 ok(!ret && GetLastError() == ERROR_INVALID_DATA,
1082 "Expected ERROR_INVALID_DATA, got %08x\n", GetLastError());
1083 pSetupDiDestroyDeviceInfoList(set);
1086 START_TEST(devinst)
1088 init_function_pointers();
1090 if (pSetupDiCreateDeviceInfoListExW && pSetupDiDestroyDeviceInfoList)
1091 test_SetupDiCreateDeviceInfoListEx();
1092 else
1093 skip("SetupDiCreateDeviceInfoListExW and/or SetupDiDestroyDeviceInfoList not available\n");
1095 if (pSetupDiOpenClassRegKeyExA)
1096 test_SetupDiOpenClassRegKeyExA();
1097 else
1098 skip("SetupDiOpenClassRegKeyExA is not available\n");
1099 testInstallClass();
1100 testCreateDeviceInfo();
1101 testGetDeviceInstanceId();
1102 testRegisterDeviceInfo();
1103 testCreateDeviceInterface();
1104 testGetDeviceInterfaceDetail();
1105 testDevRegKey();
1106 testRegisterAndGetDetail();
1107 testDeviceRegistryPropertyA();
1108 testDeviceRegistryPropertyW();