include: Use the hard-float calling convention for Windows APIs on ARM
[wine.git] / dlls / setupapi / tests / devinst.c
blob4df00b1855fd70ff30a6f1901a0f5b60603a2281
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 <stdarg.h>
22 #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 static BOOL is_wow64;
36 /* function pointers */
37 static HDEVINFO (WINAPI *pSetupDiCreateDeviceInfoList)(GUID*,HWND);
38 static HDEVINFO (WINAPI *pSetupDiCreateDeviceInfoListExW)(GUID*,HWND,PCWSTR,PVOID);
39 static BOOL (WINAPI *pSetupDiCreateDeviceInterfaceA)(HDEVINFO, PSP_DEVINFO_DATA, const GUID *, PCSTR, DWORD, PSP_DEVICE_INTERFACE_DATA);
40 static BOOL (WINAPI *pSetupDiCallClassInstaller)(DI_FUNCTION, HDEVINFO, PSP_DEVINFO_DATA);
41 static BOOL (WINAPI *pSetupDiDestroyDeviceInfoList)(HDEVINFO);
42 static BOOL (WINAPI *pSetupDiEnumDeviceInfo)(HDEVINFO, DWORD, PSP_DEVINFO_DATA);
43 static BOOL (WINAPI *pSetupDiEnumDeviceInterfaces)(HDEVINFO, PSP_DEVINFO_DATA, const GUID *, DWORD, PSP_DEVICE_INTERFACE_DATA);
44 static BOOL (WINAPI *pSetupDiGetINFClassA)(PCSTR, LPGUID, PSTR, DWORD, PDWORD);
45 static BOOL (WINAPI *pSetupDiInstallClassA)(HWND, PCSTR, DWORD, HSPFILEQ);
46 static HKEY (WINAPI *pSetupDiOpenClassRegKeyExA)(GUID*,REGSAM,DWORD,PCSTR,PVOID);
47 static HKEY (WINAPI *pSetupDiOpenDevRegKey)(HDEVINFO, PSP_DEVINFO_DATA, DWORD, DWORD, DWORD, REGSAM);
48 static HKEY (WINAPI *pSetupDiCreateDevRegKeyW)(HDEVINFO, PSP_DEVINFO_DATA, DWORD, DWORD, DWORD, HINF, PCWSTR);
49 static BOOL (WINAPI *pSetupDiCreateDeviceInfoA)(HDEVINFO, PCSTR, GUID *, PCSTR, HWND, DWORD, PSP_DEVINFO_DATA);
50 static BOOL (WINAPI *pSetupDiCreateDeviceInfoW)(HDEVINFO, PCWSTR, GUID *, PCWSTR, HWND, DWORD, PSP_DEVINFO_DATA);
51 static BOOL (WINAPI *pSetupDiGetDeviceInstanceIdA)(HDEVINFO, PSP_DEVINFO_DATA, PSTR, DWORD, PDWORD);
52 static BOOL (WINAPI *pSetupDiGetDeviceInterfaceDetailA)(HDEVINFO, PSP_DEVICE_INTERFACE_DATA, PSP_DEVICE_INTERFACE_DETAIL_DATA_A, DWORD, PDWORD, PSP_DEVINFO_DATA);
53 static BOOL (WINAPI *pSetupDiGetDeviceInterfaceDetailW)(HDEVINFO, PSP_DEVICE_INTERFACE_DATA, PSP_DEVICE_INTERFACE_DETAIL_DATA_W, DWORD, PDWORD, PSP_DEVINFO_DATA);
54 static BOOL (WINAPI *pSetupDiRegisterDeviceInfo)(HDEVINFO, PSP_DEVINFO_DATA, DWORD, PSP_DETSIG_CMPPROC, PVOID, PSP_DEVINFO_DATA);
55 static HDEVINFO (WINAPI *pSetupDiGetClassDevsA)(const GUID *, LPCSTR, HWND, DWORD);
56 static HDEVINFO (WINAPI *pSetupDiGetClassDevsW)(const GUID *, LPCWSTR, HWND, DWORD);
57 static BOOL (WINAPI *pSetupDiSetDeviceRegistryPropertyA)(HDEVINFO, PSP_DEVINFO_DATA, DWORD, const BYTE *, DWORD);
58 static BOOL (WINAPI *pSetupDiSetDeviceRegistryPropertyW)(HDEVINFO, PSP_DEVINFO_DATA, DWORD, const BYTE *, DWORD);
59 static BOOL (WINAPI *pSetupDiGetDeviceRegistryPropertyA)(HDEVINFO, PSP_DEVINFO_DATA, DWORD, PDWORD, PBYTE, DWORD, PDWORD);
60 static BOOL (WINAPI *pSetupDiGetDeviceRegistryPropertyW)(HDEVINFO, PSP_DEVINFO_DATA, DWORD, PDWORD, PBYTE, DWORD, PDWORD);
61 static BOOL (WINAPI *pSetupDiRemoveDevice)(HDEVINFO, PSP_DEVINFO_DATA);
62 static BOOL (WINAPI *pSetupDiRemoveDeviceInterface)(HDEVINFO, PSP_DEVICE_INTERFACE_DATA);
63 static BOOL (WINAPI *pIsWow64Process)(HANDLE, PBOOL);
65 /* This is a unique guid for testing purposes */
66 static GUID guid = {0x6a55b5a4, 0x3f65, 0x11db, {0xb7,0x04,0x00,0x11,0x95,0x5c,0x2b,0xdb}};
68 static void init_function_pointers(void)
70 HMODULE hSetupAPI = GetModuleHandleA("setupapi.dll");
71 HMODULE hKernel32 = GetModuleHandleA("kernel32.dll");
73 pSetupDiCreateDeviceInfoA = (void *)GetProcAddress(hSetupAPI, "SetupDiCreateDeviceInfoA");
74 pSetupDiCreateDeviceInfoW = (void *)GetProcAddress(hSetupAPI, "SetupDiCreateDeviceInfoW");
75 pSetupDiCreateDeviceInfoList = (void *)GetProcAddress(hSetupAPI, "SetupDiCreateDeviceInfoList");
76 pSetupDiCreateDeviceInfoListExW = (void *)GetProcAddress(hSetupAPI, "SetupDiCreateDeviceInfoListExW");
77 pSetupDiCreateDeviceInterfaceA = (void *)GetProcAddress(hSetupAPI, "SetupDiCreateDeviceInterfaceA");
78 pSetupDiDestroyDeviceInfoList = (void *)GetProcAddress(hSetupAPI, "SetupDiDestroyDeviceInfoList");
79 pSetupDiCallClassInstaller = (void *)GetProcAddress(hSetupAPI, "SetupDiCallClassInstaller");
80 pSetupDiEnumDeviceInfo = (void *)GetProcAddress(hSetupAPI, "SetupDiEnumDeviceInfo");
81 pSetupDiEnumDeviceInterfaces = (void *)GetProcAddress(hSetupAPI, "SetupDiEnumDeviceInterfaces");
82 pSetupDiGetDeviceInstanceIdA = (void *)GetProcAddress(hSetupAPI, "SetupDiGetDeviceInstanceIdA");
83 pSetupDiGetDeviceInterfaceDetailA = (void *)GetProcAddress(hSetupAPI, "SetupDiGetDeviceInterfaceDetailA");
84 pSetupDiGetDeviceInterfaceDetailW = (void *)GetProcAddress(hSetupAPI, "SetupDiGetDeviceInterfaceDetailW");
85 pSetupDiInstallClassA = (void *)GetProcAddress(hSetupAPI, "SetupDiInstallClassA");
86 pSetupDiOpenClassRegKeyExA = (void *)GetProcAddress(hSetupAPI, "SetupDiOpenClassRegKeyExA");
87 pSetupDiOpenDevRegKey = (void *)GetProcAddress(hSetupAPI, "SetupDiOpenDevRegKey");
88 pSetupDiCreateDevRegKeyW = (void *)GetProcAddress(hSetupAPI, "SetupDiCreateDevRegKeyW");
89 pSetupDiRegisterDeviceInfo = (void *)GetProcAddress(hSetupAPI, "SetupDiRegisterDeviceInfo");
90 pSetupDiGetClassDevsA = (void *)GetProcAddress(hSetupAPI, "SetupDiGetClassDevsA");
91 pSetupDiGetClassDevsW = (void *)GetProcAddress(hSetupAPI, "SetupDiGetClassDevsW");
92 pSetupDiGetINFClassA = (void *)GetProcAddress(hSetupAPI, "SetupDiGetINFClassA");
93 pSetupDiSetDeviceRegistryPropertyA = (void *)GetProcAddress(hSetupAPI, "SetupDiSetDeviceRegistryPropertyA");
94 pSetupDiSetDeviceRegistryPropertyW = (void *)GetProcAddress(hSetupAPI, "SetupDiSetDeviceRegistryPropertyW");
95 pSetupDiGetDeviceRegistryPropertyA = (void *)GetProcAddress(hSetupAPI, "SetupDiGetDeviceRegistryPropertyA");
96 pSetupDiGetDeviceRegistryPropertyW = (void *)GetProcAddress(hSetupAPI, "SetupDiGetDeviceRegistryPropertyW");
97 pSetupDiRemoveDeviceInterface = (void *)GetProcAddress(hSetupAPI, "SetupDiRemoveDeviceInterface");
98 pSetupDiRemoveDevice = (void *)GetProcAddress(hSetupAPI, "SetupDiRemoveDevice");
99 pIsWow64Process = (void *)GetProcAddress(hKernel32, "IsWow64Process");
102 static LSTATUS devinst_RegDeleteTreeW(HKEY hKey, LPCWSTR lpszSubKey)
104 LONG ret;
105 DWORD dwMaxSubkeyLen, dwMaxValueLen;
106 DWORD dwMaxLen, dwSize;
107 WCHAR szNameBuf[MAX_PATH], *lpszName = szNameBuf;
108 HKEY hSubKey = hKey;
110 if(lpszSubKey)
112 ret = RegOpenKeyExW(hKey, lpszSubKey, 0, KEY_READ, &hSubKey);
113 if (ret) return ret;
116 /* Get highest length for keys, values */
117 ret = RegQueryInfoKeyW(hSubKey, NULL, NULL, NULL, NULL,
118 &dwMaxSubkeyLen, NULL, NULL, &dwMaxValueLen, NULL, NULL, NULL);
119 if (ret) goto cleanup;
121 dwMaxSubkeyLen++;
122 dwMaxValueLen++;
123 dwMaxLen = max(dwMaxSubkeyLen, dwMaxValueLen);
124 if (dwMaxLen > sizeof(szNameBuf)/sizeof(WCHAR))
126 /* Name too big: alloc a buffer for it */
127 if (!(lpszName = HeapAlloc( GetProcessHeap(), 0, dwMaxLen*sizeof(WCHAR))))
129 ret = ERROR_NOT_ENOUGH_MEMORY;
130 goto cleanup;
135 /* Recursively delete all the subkeys */
136 while (TRUE)
138 dwSize = dwMaxLen;
139 if (RegEnumKeyExW(hSubKey, 0, lpszName, &dwSize, NULL,
140 NULL, NULL, NULL)) break;
142 ret = devinst_RegDeleteTreeW(hSubKey, lpszName);
143 if (ret) goto cleanup;
146 if (lpszSubKey)
147 ret = RegDeleteKeyW(hKey, lpszSubKey);
148 else
149 while (TRUE)
151 dwSize = dwMaxLen;
152 if (RegEnumValueW(hKey, 0, lpszName, &dwSize,
153 NULL, NULL, NULL, NULL)) break;
155 ret = RegDeleteValueW(hKey, lpszName);
156 if (ret) goto cleanup;
159 cleanup:
160 /* Free buffer if allocated */
161 if (lpszName != szNameBuf)
162 HeapFree( GetProcessHeap(), 0, lpszName);
163 if(lpszSubKey)
164 RegCloseKey(hSubKey);
165 return ret;
168 static void test_SetupDiCreateDeviceInfoListEx(void)
170 HDEVINFO devlist;
171 BOOL ret;
172 DWORD error;
173 static CHAR notnull[] = "NotNull";
174 static const WCHAR machine[] = { 'd','u','m','m','y',0 };
175 static const WCHAR empty[] = { 0 };
177 SetLastError(0xdeadbeef);
178 /* create empty DeviceInfoList, but set Reserved to a value, which is not NULL */
179 devlist = pSetupDiCreateDeviceInfoListExW(NULL, NULL, NULL, notnull);
181 error = GetLastError();
182 if (error == ERROR_CALL_NOT_IMPLEMENTED)
184 win_skip("SetupDiCreateDeviceInfoListExW is not implemented\n");
185 return;
187 ok(devlist == INVALID_HANDLE_VALUE, "SetupDiCreateDeviceInfoListExW failed : %p %d (expected %p)\n", devlist, error, INVALID_HANDLE_VALUE);
188 ok(error == ERROR_INVALID_PARAMETER, "GetLastError returned wrong value : %d, (expected %d)\n", error, ERROR_INVALID_PARAMETER);
190 SetLastError(0xdeadbeef);
191 /* create empty DeviceInfoList, but set MachineName to something */
192 devlist = pSetupDiCreateDeviceInfoListExW(NULL, NULL, machine, NULL);
194 error = GetLastError();
195 if (error == ERROR_CALL_NOT_IMPLEMENTED)
197 /* win10 reports ERROR_CALL_NOT_IMPLEMENTED at first here */
198 win_skip("SetupDiCreateDeviceInfoListExW is not implemented\n");
199 return;
201 ok(devlist == INVALID_HANDLE_VALUE, "SetupDiCreateDeviceInfoListExW failed : %p %d (expected %p)\n", devlist, error, INVALID_HANDLE_VALUE);
202 ok(error == ERROR_INVALID_MACHINENAME || error == ERROR_MACHINE_UNAVAILABLE, "GetLastError returned wrong value : %d, (expected %d or %d)\n", error, ERROR_INVALID_MACHINENAME, ERROR_MACHINE_UNAVAILABLE);
204 /* create empty DeviceInfoList */
205 devlist = pSetupDiCreateDeviceInfoListExW(NULL, NULL, NULL, NULL);
206 ok(devlist && devlist != INVALID_HANDLE_VALUE, "SetupDiCreateDeviceInfoListExW failed : %p %d (expected != %p)\n", devlist, error, INVALID_HANDLE_VALUE);
208 /* destroy DeviceInfoList */
209 ret = pSetupDiDestroyDeviceInfoList(devlist);
210 ok(ret, "SetupDiDestroyDeviceInfoList failed : %d\n", error);
212 /* create empty DeviceInfoList with empty machine name */
213 devlist = pSetupDiCreateDeviceInfoListExW(NULL, NULL, empty, NULL);
214 ok(devlist && devlist != INVALID_HANDLE_VALUE, "SetupDiCreateDeviceInfoListExW failed : %p %d (expected != %p)\n", devlist, error, INVALID_HANDLE_VALUE);
216 /* destroy DeviceInfoList */
217 ret = pSetupDiDestroyDeviceInfoList(devlist);
218 ok(ret, "SetupDiDestroyDeviceInfoList failed : %d\n", error);
221 static void test_SetupDiOpenClassRegKeyExA(void)
223 static const CHAR guidString[] = "{6a55b5a4-3f65-11db-b704-0011955c2bdb}";
224 HKEY hkey;
226 /* Check return value for nonexistent key */
227 hkey = pSetupDiOpenClassRegKeyExA(&guid, KEY_ALL_ACCESS,
228 DIOCR_INSTALLER, NULL, NULL);
229 ok(hkey == INVALID_HANDLE_VALUE,
230 "returned %p (expected INVALID_HANDLE_VALUE)\n", hkey);
232 /* Test it for a key that exists */
233 hkey = SetupDiOpenClassRegKey(NULL, KEY_ALL_ACCESS);
234 if (hkey != INVALID_HANDLE_VALUE)
236 HKEY classKey;
237 if (RegCreateKeyA(hkey, guidString, &classKey) == ERROR_SUCCESS)
239 RegCloseKey(classKey);
240 SetLastError(0xdeadbeef);
241 classKey = pSetupDiOpenClassRegKeyExA(&guid, KEY_ALL_ACCESS,
242 DIOCR_INSTALLER, NULL, NULL);
243 ok(classKey != INVALID_HANDLE_VALUE,
244 "opening class registry key failed with error %d\n",
245 GetLastError());
246 if (classKey != INVALID_HANDLE_VALUE)
247 RegCloseKey(classKey);
248 RegDeleteKeyA(hkey, guidString);
250 else
251 trace("failed to create registry key for test\n");
253 RegCloseKey(hkey);
255 else
256 trace("failed to open classes key %u\n", GetLastError());
259 static void create_inf_file(LPCSTR filename)
261 DWORD dwNumberOfBytesWritten;
262 HANDLE hf = CreateFileA(filename, GENERIC_WRITE, 0, NULL,
263 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
265 static const char data[] =
266 "[Version]\n"
267 "Signature=\"$Chicago$\"\n"
268 "Class=Bogus\n"
269 "ClassGUID={6a55b5a4-3f65-11db-b704-0011955c2bdb}\n"
270 "[ClassInstall32]\n"
271 "AddReg=BogusClass.NT.AddReg\n"
272 "[BogusClass.NT.AddReg]\n"
273 "HKR,,,,\"Wine test devices\"\n";
275 WriteFile(hf, data, sizeof(data) - 1, &dwNumberOfBytesWritten, NULL);
276 CloseHandle(hf);
279 static void get_temp_filename(LPSTR path)
281 static char curr[MAX_PATH] = { 0 };
282 char temp[MAX_PATH];
283 LPSTR ptr;
285 if (!*curr)
286 GetCurrentDirectoryA(MAX_PATH, curr);
287 GetTempFileNameA(curr, "set", 0, temp);
288 ptr = strrchr(temp, '\\');
290 lstrcpyA(path, ptr + 1);
293 static void testInstallClass(void)
295 static const WCHAR classKey[] = {'S','y','s','t','e','m','\\',
296 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
297 'C','o','n','t','r','o','l','\\','C','l','a','s','s','\\',
298 '{','6','a','5','5','b','5','a','4','-','3','f','6','5','-',
299 '1','1','d','b','-','b','7','0','4','-',
300 '0','0','1','1','9','5','5','c','2','b','d','b','}',0};
301 char tmpfile[MAX_PATH];
302 BOOL ret;
304 tmpfile[0] = '.';
305 tmpfile[1] = '\\';
306 get_temp_filename(tmpfile + 2);
307 create_inf_file(tmpfile + 2);
309 ret = pSetupDiInstallClassA(NULL, NULL, 0, NULL);
310 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
311 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
312 ret = pSetupDiInstallClassA(NULL, NULL, DI_NOVCP, NULL);
313 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
314 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
315 ret = pSetupDiInstallClassA(NULL, tmpfile + 2, DI_NOVCP, NULL);
316 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
317 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
318 ret = pSetupDiInstallClassA(NULL, tmpfile + 2, 0, NULL);
319 ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND,
320 "Expected ERROR_FILE_NOT_FOUND, got %08x\n", GetLastError());
321 /* The next call will succeed. Information is put into the registry but the
322 * location(s) is/are depending on the Windows version.
324 ret = pSetupDiInstallClassA(NULL, tmpfile, 0, NULL);
325 ok(ret, "SetupDiInstallClassA failed: %08x\n", GetLastError());
327 ok(!RegDeleteKeyW(HKEY_LOCAL_MACHINE, classKey),
328 "Couldn't delete classkey\n");
330 DeleteFileA(tmpfile);
333 static void testCreateDeviceInfo(void)
335 BOOL ret;
336 HDEVINFO set;
338 SetLastError(0xdeadbeef);
339 ret = pSetupDiCreateDeviceInfoA(NULL, NULL, NULL, NULL, NULL, 0, NULL);
340 ok(!ret, "Expected failure\n");
341 ok(GetLastError() == ERROR_INVALID_DEVINST_NAME ||
342 GetLastError() == ERROR_INVALID_PARAMETER /* NT4 */,
343 "Unexpected last error, got %08x\n", GetLastError());
345 SetLastError(0xdeadbeef);
346 ret = pSetupDiCreateDeviceInfoA(NULL, "Root\\LEGACY_BOGUS\\0000", NULL,
347 NULL, NULL, 0, NULL);
348 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
349 "Expected ERROR_INVALID_HANDLEHANDLE, got %08x\n", GetLastError());
350 set = pSetupDiCreateDeviceInfoList(&guid, NULL);
351 ok(set != NULL, "SetupDiCreateDeviceInfoList failed: %08x\n",
352 GetLastError());
353 if (set)
355 SP_DEVINFO_DATA devInfo = { 0 };
356 DWORD i;
357 static GUID deadbeef =
358 {0xdeadbeef, 0xdead, 0xbeef, {0xde,0xad,0xbe,0xef,0xde,0xad,0xbe,0xef}};
360 /* No GUID given */
361 SetLastError(0xdeadbeef);
362 ret = pSetupDiCreateDeviceInfoA(set, "Root\\LEGACY_BOGUS\\0000", NULL,
363 NULL, NULL, 0, NULL);
364 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
365 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
367 /* We can't add device information to the set with a different GUID */
368 SetLastError(0xdeadbeef);
369 ret = pSetupDiCreateDeviceInfoA(set, "Root\\LEGACY_BOGUS\\0000",
370 &deadbeef, NULL, NULL, 0, NULL);
371 ok(!ret && GetLastError() == ERROR_CLASS_MISMATCH,
372 "Expected ERROR_CLASS_MISMATCH, got %08x\n", GetLastError());
374 /* Finally, with all three required parameters, this succeeds: */
375 ret = pSetupDiCreateDeviceInfoA(set, "Root\\LEGACY_BOGUS\\0000", &guid,
376 NULL, NULL, 0, NULL);
377 ok(ret, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
378 /* This fails because the device ID already exists.. */
379 SetLastError(0xdeadbeef);
380 ret = pSetupDiCreateDeviceInfoA(set, "Root\\LEGACY_BOGUS\\0000", &guid,
381 NULL, NULL, 0, &devInfo);
382 ok(!ret && GetLastError() == ERROR_DEVINST_ALREADY_EXISTS,
383 "Expected ERROR_DEVINST_ALREADY_EXISTS, got %08x\n", GetLastError());
384 /* whereas this "fails" because cbSize is wrong.. */
385 SetLastError(0xdeadbeef);
386 ret = pSetupDiCreateDeviceInfoA(set, "LEGACY_BOGUS", &guid, NULL, NULL,
387 DICD_GENERATE_ID, &devInfo);
388 ok(!ret && GetLastError() == ERROR_INVALID_USER_BUFFER,
389 "Expected ERROR_INVALID_USER_BUFFER, got %08x\n", GetLastError());
390 /* and this finally succeeds. */
391 devInfo.cbSize = sizeof(devInfo);
392 ret = pSetupDiCreateDeviceInfoA(set, "LEGACY_BOGUS", &guid, NULL, NULL,
393 DICD_GENERATE_ID, &devInfo);
394 ok(ret, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
395 /* There were three devices added, however - the second failure just
396 * resulted in the SP_DEVINFO_DATA not getting copied.
398 SetLastError(0xdeadbeef);
399 i = 0;
400 while (pSetupDiEnumDeviceInfo(set, i, &devInfo))
401 i++;
402 ok(i == 3, "Expected 3 devices, got %d\n", i);
403 ok(GetLastError() == ERROR_NO_MORE_ITEMS,
404 "SetupDiEnumDeviceInfo failed: %08x\n", GetLastError());
406 ret = pSetupDiRemoveDevice(set, &devInfo);
407 todo_wine ok(ret, "got %u\n", GetLastError());
408 pSetupDiDestroyDeviceInfoList(set);
412 static void testGetDeviceInstanceId(void)
414 BOOL ret;
415 HDEVINFO set;
416 SP_DEVINFO_DATA devInfo = { 0 };
418 SetLastError(0xdeadbeef);
419 ret = pSetupDiGetDeviceInstanceIdA(NULL, NULL, NULL, 0, NULL);
420 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
421 "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
422 SetLastError(0xdeadbeef);
423 ret = pSetupDiGetDeviceInstanceIdA(NULL, &devInfo, NULL, 0, NULL);
424 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
425 "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
426 set = pSetupDiCreateDeviceInfoList(&guid, NULL);
427 ok(set != NULL, "SetupDiCreateDeviceInfoList failed: %08x\n",
428 GetLastError());
429 if (set)
431 char instanceID[MAX_PATH];
432 DWORD size;
434 SetLastError(0xdeadbeef);
435 ret = pSetupDiGetDeviceInstanceIdA(set, NULL, NULL, 0, NULL);
436 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
437 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
438 SetLastError(0xdeadbeef);
439 ret = pSetupDiGetDeviceInstanceIdA(set, &devInfo, NULL, 0, NULL);
440 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
441 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
442 SetLastError(0xdeadbeef);
443 ret = pSetupDiGetDeviceInstanceIdA(set, &devInfo, NULL, 0, &size);
444 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
445 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
446 devInfo.cbSize = sizeof(devInfo);
447 SetLastError(0xdeadbeef);
448 ret = pSetupDiGetDeviceInstanceIdA(set, &devInfo, NULL, 0, &size);
449 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
450 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
451 ret = pSetupDiCreateDeviceInfoA(set, "Root\\LEGACY_BOGUS\\0000", &guid,
452 NULL, NULL, 0, &devInfo);
453 ok(ret, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
454 SetLastError(0xdeadbeef);
455 ret = pSetupDiGetDeviceInstanceIdA(set, &devInfo, NULL, 0, &size);
456 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
457 "Expected ERROR_INSUFFICIENT_BUFFER, got %08x\n", GetLastError());
458 ret = pSetupDiGetDeviceInstanceIdA(set, &devInfo, instanceID,
459 sizeof(instanceID), NULL);
460 ok(ret, "SetupDiGetDeviceInstanceIdA failed: %08x\n", GetLastError());
461 ok(!lstrcmpA(instanceID, "ROOT\\LEGACY_BOGUS\\0000"),
462 "Unexpected instance ID %s\n", instanceID);
463 ret = pSetupDiCreateDeviceInfoA(set, "LEGACY_BOGUS", &guid,
464 NULL, NULL, DICD_GENERATE_ID, &devInfo);
465 ok(ret, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
466 ret = pSetupDiGetDeviceInstanceIdA(set, &devInfo, instanceID,
467 sizeof(instanceID), NULL);
468 ok(ret, "SetupDiGetDeviceInstanceIdA failed: %08x\n", GetLastError());
469 /* NT4 returns 'Root' and W2K and above 'ROOT' */
470 ok(!lstrcmpiA(instanceID, "ROOT\\LEGACY_BOGUS\\0001"),
471 "Unexpected instance ID %s\n", instanceID);
473 ret = pSetupDiRemoveDevice(set, &devInfo);
474 todo_wine ok(ret, "got %u\n", GetLastError());
475 pSetupDiDestroyDeviceInfoList(set);
479 static void testRegisterDeviceInfo(void)
481 static const WCHAR bogus[] = {'S','y','s','t','e','m','\\',
482 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
483 'E','n','u','m','\\','U','S','B','\\','B','O','G','U','S',0};
484 BOOL ret;
485 HDEVINFO set;
487 SetLastError(0xdeadbeef);
488 ret = pSetupDiRegisterDeviceInfo(NULL, NULL, 0, NULL, NULL, NULL);
489 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
490 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
491 set = pSetupDiCreateDeviceInfoList(&guid, NULL);
492 ok(set != NULL, "SetupDiCreateDeviceInfoList failed: %d\n", GetLastError());
493 if (set)
495 SP_DEVINFO_DATA devInfo = { 0 };
497 SetLastError(0xdeadbeef);
498 ret = pSetupDiRegisterDeviceInfo(set, NULL, 0, NULL, NULL, NULL);
499 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
500 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
501 SetLastError(0xdeadbeef);
502 ret = pSetupDiRegisterDeviceInfo(set, &devInfo, 0, NULL, NULL, NULL);
503 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
504 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
505 devInfo.cbSize = sizeof(devInfo);
506 SetLastError(0xdeadbeef);
507 ret = pSetupDiRegisterDeviceInfo(set, &devInfo, 0, NULL, NULL, NULL);
508 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
509 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
511 ret = pSetupDiCreateDeviceInfoA(set, "USB\\BOGUS\\0000", &guid,
512 NULL, NULL, 0, &devInfo);
513 ok(ret, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
515 ret = pSetupDiRegisterDeviceInfo(set, &devInfo, 0, NULL, NULL, NULL);
516 ok(ret, "SetupDiRegisterDeviceInfo failed: %d\n", GetLastError());
518 ret = pSetupDiRemoveDevice(set, &devInfo);
519 todo_wine ok(ret, "got %u\n", GetLastError());
520 pSetupDiDestroyDeviceInfoList(set);
522 /* remove once Wine is fixed */
523 devinst_RegDeleteTreeW(HKEY_LOCAL_MACHINE, bogus);
527 static void testCreateDeviceInterface(void)
529 BOOL ret;
530 HDEVINFO set;
532 if (!pSetupDiCreateDeviceInterfaceA || !pSetupDiEnumDeviceInterfaces)
534 win_skip("SetupDiCreateDeviceInterfaceA and/or SetupDiEnumDeviceInterfaces are not available\n");
535 return;
537 SetLastError(0xdeadbeef);
538 ret = pSetupDiCreateDeviceInterfaceA(NULL, NULL, NULL, NULL, 0, NULL);
539 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
540 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
541 SetLastError(0xdeadbeef);
542 ret = pSetupDiCreateDeviceInterfaceA(NULL, NULL, &guid, NULL, 0, NULL);
543 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
544 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
545 set = pSetupDiCreateDeviceInfoList(&guid, NULL);
546 ok(set != NULL, "SetupDiCreateDeviceInfoList failed: %d\n", GetLastError());
547 if (set)
549 SP_DEVINFO_DATA devInfo = { 0 };
550 SP_DEVICE_INTERFACE_DATA interfaceData = { sizeof(interfaceData),
551 { 0 } };
552 DWORD i;
554 SetLastError(0xdeadbeef);
555 ret = pSetupDiCreateDeviceInterfaceA(set, NULL, NULL, NULL, 0, NULL);
556 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
557 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
558 SetLastError(0xdeadbeef);
559 ret = pSetupDiCreateDeviceInterfaceA(set, &devInfo, NULL, NULL, 0,
560 NULL);
561 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
562 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
563 devInfo.cbSize = sizeof(devInfo);
564 ret = pSetupDiCreateDeviceInfoA(set, "ROOT\\LEGACY_BOGUS\\0000", &guid,
565 NULL, NULL, 0, &devInfo);
566 ok(ret, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
567 SetLastError(0xdeadbeef);
568 ret = pSetupDiCreateDeviceInterfaceA(set, &devInfo, NULL, NULL, 0,
569 NULL);
570 ok(!ret && GetLastError() == ERROR_INVALID_USER_BUFFER,
571 "Expected ERROR_INVALID_USER_BUFFER, got %08x\n", GetLastError());
572 ret = pSetupDiCreateDeviceInterfaceA(set, &devInfo, &guid, NULL, 0,
573 NULL);
574 ok(ret, "SetupDiCreateDeviceInterfaceA failed: %08x\n", GetLastError());
575 /* Creating the same interface a second time succeeds */
576 ret = pSetupDiCreateDeviceInterfaceA(set, &devInfo, &guid, NULL, 0,
577 NULL);
578 ok(ret, "SetupDiCreateDeviceInterfaceA failed: %08x\n", GetLastError());
579 ret = pSetupDiCreateDeviceInterfaceA(set, &devInfo, &guid, "Oogah", 0,
580 NULL);
581 ok(ret, "SetupDiCreateDeviceInterfaceA failed: %08x\n", GetLastError());
582 ret = pSetupDiEnumDeviceInterfaces(set, &devInfo, &guid, 0,
583 &interfaceData);
584 ok(ret, "SetupDiEnumDeviceInterfaces failed: %d\n", GetLastError());
585 i = 0;
586 while (pSetupDiEnumDeviceInterfaces(set, &devInfo, &guid, i,
587 &interfaceData))
588 i++;
589 ok(i == 2, "expected 2 interfaces, got %d\n", i);
590 ok(GetLastError() == ERROR_NO_MORE_ITEMS,
591 "SetupDiEnumDeviceInterfaces failed: %08x\n", GetLastError());
593 for (i = 0; i < 2; i++)
595 ret = pSetupDiEnumDeviceInterfaces(set, &devInfo, &guid, i, &interfaceData);
596 ok(ret, "SetupDiEnumDeviceInterfaces failed: %08x\n", GetLastError());
598 ret = pSetupDiRemoveDeviceInterface(set, &interfaceData);
599 todo_wine ok(ret, "SetupDiRemoveDeviceInterface failed: %08x\n", GetLastError());
602 ret = pSetupDiRemoveDevice(set, &devInfo);
603 todo_wine ok(ret, "got %u\n", GetLastError());
605 ret = pSetupDiDestroyDeviceInfoList(set);
606 ok(ret, "SetupDiDestroyDeviceInfoList failed: %08x\n", GetLastError());
610 static void testGetDeviceInterfaceDetail(void)
612 static const WCHAR bogus[] = {'S','y','s','t','e','m','\\',
613 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
614 'E','n','u','m','\\','R','o','o','t','\\',
615 'L','E','G','A','C','Y','_','B','O','G','U','S',0};
616 static const WCHAR devclass[] = {'S','y','s','t','e','m','\\',
617 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
618 'C','o','n','t','r','o','l','\\','D','e','v','i','c','e','C','l','a','s','s','e','s','\\',
619 '{','6','a','5','5','b','5','a','4','-','3','f','6','5','-',
620 '1','1','d','b','-','b','7','0','4','-',
621 '0','0','1','1','9','5','5','c','2','b','d','b','}',0};
622 BOOL ret;
623 HDEVINFO set;
625 if (!pSetupDiCreateDeviceInterfaceA || !pSetupDiGetDeviceInterfaceDetailA)
627 win_skip("SetupDiCreateDeviceInterfaceA and/or SetupDiGetDeviceInterfaceDetailA are not available\n");
628 return;
630 SetLastError(0xdeadbeef);
631 ret = pSetupDiGetDeviceInterfaceDetailA(NULL, NULL, NULL, 0, NULL, NULL);
632 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
633 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
634 set = pSetupDiCreateDeviceInfoList(&guid, NULL);
635 ok(set != NULL, "SetupDiCreateDeviceInfoList failed: %d\n", GetLastError());
636 if (set)
638 SP_DEVINFO_DATA devInfo = { sizeof(devInfo), { 0 } };
639 SP_DEVICE_INTERFACE_DATA interfaceData = { sizeof(interfaceData),
640 { 0 } };
641 DWORD size = 0;
643 SetLastError(0xdeadbeef);
644 ret = pSetupDiGetDeviceInterfaceDetailA(set, NULL, NULL, 0, NULL,
645 NULL);
646 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
647 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
648 ret = pSetupDiCreateDeviceInfoA(set, "ROOT\\LEGACY_BOGUS\\0000", &guid,
649 NULL, NULL, 0, &devInfo);
650 ok(ret, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
651 SetLastError(0xdeadbeef);
652 ret = pSetupDiCreateDeviceInterfaceA(set, &devInfo, &guid, NULL, 0,
653 &interfaceData);
654 ok(ret, "SetupDiCreateDeviceInterfaceA failed: %08x\n", GetLastError());
655 SetLastError(0xdeadbeef);
656 ret = pSetupDiGetDeviceInterfaceDetailA(set, &interfaceData, NULL,
657 0, NULL, NULL);
658 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
659 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
660 SetLastError(0xdeadbeef);
661 ret = pSetupDiGetDeviceInterfaceDetailA(set, &interfaceData, NULL,
662 100, NULL, NULL);
663 ok(!ret && GetLastError() == ERROR_INVALID_USER_BUFFER,
664 "Expected ERROR_INVALID_USER_BUFFER, got %08x\n", GetLastError());
665 SetLastError(0xdeadbeef);
666 ret = pSetupDiGetDeviceInterfaceDetailA(set, &interfaceData, NULL,
667 0, &size, NULL);
668 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
669 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
670 if (!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER)
672 static const char path[] =
673 "\\\\?\\root#legacy_bogus#0000#{6a55b5a4-3f65-11db-b704-0011955c2bdb}";
674 static const char path_w2k[] =
675 "\\\\?\\root#legacy_bogus#0000#{6a55b5a4-3f65-11db-b704-0011955c2bdb}\\";
676 LPBYTE buf = HeapAlloc(GetProcessHeap(), 0, size);
677 SP_DEVICE_INTERFACE_DETAIL_DATA_A *detail =
678 (SP_DEVICE_INTERFACE_DETAIL_DATA_A *)buf;
679 DWORD expectedsize = FIELD_OFFSET(SP_DEVICE_INTERFACE_DETAIL_DATA_W, DevicePath) + sizeof(WCHAR)*(1 + strlen(path));
681 detail->cbSize = 0;
682 SetLastError(0xdeadbeef);
683 ret = pSetupDiGetDeviceInterfaceDetailA(set, &interfaceData, detail,
684 size, &size, NULL);
685 ok(!ret && GetLastError() == ERROR_INVALID_USER_BUFFER,
686 "Expected ERROR_INVALID_USER_BUFFER, got %08x\n", GetLastError());
687 detail->cbSize = size;
688 SetLastError(0xdeadbeef);
689 ret = pSetupDiGetDeviceInterfaceDetailA(set, &interfaceData, detail,
690 size, &size, NULL);
691 ok(!ret && GetLastError() == ERROR_INVALID_USER_BUFFER,
692 "Expected ERROR_INVALID_USER_BUFFER, got %08x\n", GetLastError());
693 detail->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_A);
694 SetLastError(0xdeadbeef);
695 ret = pSetupDiGetDeviceInterfaceDetailA(set, &interfaceData, detail,
696 size, &size, NULL);
697 ok(ret, "SetupDiGetDeviceInterfaceDetailA failed: %d\n",
698 GetLastError());
699 ok(!lstrcmpiA(path, detail->DevicePath) ||
700 !lstrcmpiA(path_w2k, detail->DevicePath), "Unexpected path %s\n",
701 detail->DevicePath);
702 /* Check SetupDiGetDeviceInterfaceDetailW */
703 ret = pSetupDiGetDeviceInterfaceDetailW(set, &interfaceData, NULL, 0, &size, NULL);
704 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
705 "Expected ERROR_INSUFFICIENT_BUFFER, got error code: %d\n", GetLastError());
706 ok(expectedsize == size ||
707 (expectedsize + sizeof(WCHAR)) == size /* W2K adds a backslash */,
708 "SetupDiGetDeviceInterfaceDetailW returned wrong reqsize, got %d\n",
709 size);
711 HeapFree(GetProcessHeap(), 0, buf);
714 ret = pSetupDiEnumDeviceInterfaces(set, &devInfo, &guid, 0, &interfaceData);
715 ok(ret, "SetupDiEnumDeviceInterfaces failed: %08x\n", GetLastError());
717 ret = pSetupDiRemoveDeviceInterface(set, &interfaceData);
718 todo_wine ok(ret, "SetupDiRemoveDeviceInterface failed: %08x\n", GetLastError());
720 ret = pSetupDiRemoveDevice(set, &devInfo);
721 todo_wine ok(ret, "got %u\n", GetLastError());
722 pSetupDiDestroyDeviceInfoList(set);
724 /* remove once Wine is fixed */
725 devinst_RegDeleteTreeW(HKEY_LOCAL_MACHINE, bogus);
726 devinst_RegDeleteTreeW(HKEY_LOCAL_MACHINE, devclass);
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 static const WCHAR bogus[] = {'S','y','s','t','e','m','\\',
739 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
740 'E','n','u','m','\\','R','o','o','t','\\',
741 'L','E','G','A','C','Y','_','B','O','G','U','S',0};
742 BOOL ret;
743 HDEVINFO set;
744 HKEY key = NULL;
746 SetLastError(0xdeadbeef);
747 key = pSetupDiCreateDevRegKeyW(NULL, NULL, 0, 0, 0, NULL, NULL);
748 ok(key == INVALID_HANDLE_VALUE,
749 "Expected INVALID_HANDLE_VALUE, got %p\n", key);
750 ok(GetLastError() == ERROR_INVALID_HANDLE,
751 "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
753 set = pSetupDiCreateDeviceInfoList(&guid, NULL);
754 ok(set != NULL, "SetupDiCreateDeviceInfoList failed: %d\n", GetLastError());
755 if (set)
757 SP_DEVINFO_DATA devInfo = { sizeof(devInfo), { 0 } };
758 LONG res;
760 /* The device info key shouldn't be there */
761 res = RegOpenKeyW(HKEY_LOCAL_MACHINE, bogus, &key);
762 ok(res != ERROR_SUCCESS, "Expected key to not exist\n");
763 RegCloseKey(key);
764 /* Create the device information */
765 ret = pSetupDiCreateDeviceInfoA(set, "ROOT\\LEGACY_BOGUS\\0000", &guid,
766 NULL, NULL, 0, &devInfo);
767 ok(ret, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
768 /* The device info key should have been created */
769 ok(!RegOpenKeyW(HKEY_LOCAL_MACHINE, bogus, &key),
770 "Expected registry key to exist\n");
771 RegCloseKey(key);
772 SetLastError(0xdeadbeef);
773 key = pSetupDiOpenDevRegKey(NULL, NULL, 0, 0, 0, 0);
774 ok(!key || key == INVALID_HANDLE_VALUE,
775 "Expected INVALID_HANDLE_VALUE or a NULL key (NT4)\n");
776 ok(GetLastError() == ERROR_INVALID_HANDLE,
777 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
778 SetLastError(0xdeadbeef);
779 key = pSetupDiOpenDevRegKey(set, NULL, 0, 0, 0, 0);
780 ok(key == INVALID_HANDLE_VALUE &&
781 GetLastError() == ERROR_INVALID_PARAMETER,
782 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
783 SetLastError(0xdeadbeef);
784 key = pSetupDiOpenDevRegKey(set, &devInfo, 0, 0, 0, 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, 0, 0);
790 ok(key == INVALID_HANDLE_VALUE &&
791 GetLastError() == ERROR_INVALID_FLAGS,
792 "Expected ERROR_INVALID_FLAGS, got %d\n", GetLastError());
793 SetLastError(0xdeadbeef);
794 key = pSetupDiOpenDevRegKey(set, &devInfo, DICS_FLAG_GLOBAL, 0,
795 DIREG_BOTH, 0);
796 ok(key == INVALID_HANDLE_VALUE &&
797 GetLastError() == ERROR_INVALID_FLAGS,
798 "Expected ERROR_INVALID_FLAGS, got %d\n", GetLastError());
799 SetLastError(0xdeadbeef);
800 key = pSetupDiOpenDevRegKey(set, &devInfo, DICS_FLAG_GLOBAL, 0,
801 DIREG_DRV, 0);
802 ok(key == INVALID_HANDLE_VALUE &&
803 GetLastError() == ERROR_DEVINFO_NOT_REGISTERED,
804 "Expected ERROR_DEVINFO_NOT_REGISTERED, got %08x\n", GetLastError());
805 SetLastError(0xdeadbeef);
806 ret = pSetupDiRegisterDeviceInfo(set, &devInfo, 0, NULL, NULL, NULL);
807 ok(ret, "SetupDiRegisterDeviceInfo failed: %08x\n", GetLastError());
808 SetLastError(0xdeadbeef);
809 key = pSetupDiOpenDevRegKey(set, &devInfo, DICS_FLAG_GLOBAL, 0,
810 DIREG_DRV, 0);
811 /* The software key isn't created by default */
812 ok(key == INVALID_HANDLE_VALUE &&
813 GetLastError() == ERROR_KEY_DOES_NOT_EXIST,
814 "Expected ERROR_KEY_DOES_NOT_EXIST, got %08x\n", GetLastError());
815 SetLastError(0xdeadbeef);
816 key = pSetupDiOpenDevRegKey(set, &devInfo, DICS_FLAG_GLOBAL, 0,
817 DIREG_DEV, 0);
818 todo_wine
819 ok(key == INVALID_HANDLE_VALUE &&
820 GetLastError() == ERROR_KEY_DOES_NOT_EXIST,
821 "Expected ERROR_KEY_DOES_NOT_EXIST, got %08x\n", GetLastError());
822 SetLastError(0xdeadbeef);
823 /* The class key shouldn't be there */
824 res = RegOpenKeyW(HKEY_LOCAL_MACHINE, classKey, &key);
825 todo_wine
826 ok(res != ERROR_SUCCESS, "Expected key to not exist\n");
827 RegCloseKey(key);
828 /* Create the device reg key */
829 key = pSetupDiCreateDevRegKeyW(set, &devInfo, DICS_FLAG_GLOBAL, 0,
830 DIREG_DRV, NULL, NULL);
831 /* Vista and higher don't actually create the key */
832 ok(key != INVALID_HANDLE_VALUE || GetLastError() == ERROR_KEY_DOES_NOT_EXIST,
833 "SetupDiCreateDevRegKey failed: %08x\n", GetLastError());
834 if (key != INVALID_HANDLE_VALUE)
836 RegCloseKey(key);
837 /* The class key should have been created */
838 ok(!RegOpenKeyW(HKEY_LOCAL_MACHINE, classKey, &key),
839 "Expected registry key to exist\n");
840 RegCloseKey(key);
841 SetLastError(0xdeadbeef);
842 key = pSetupDiOpenDevRegKey(set, &devInfo, DICS_FLAG_GLOBAL, 0,
843 DIREG_DRV, 0);
844 todo_wine
845 ok(key == INVALID_HANDLE_VALUE &&
846 (GetLastError() == ERROR_INVALID_DATA ||
847 GetLastError() == ERROR_ACCESS_DENIED), /* win2k3 */
848 "Expected ERROR_INVALID_DATA or ERROR_ACCESS_DENIED, got %08x\n", GetLastError());
849 key = pSetupDiOpenDevRegKey(set, &devInfo, DICS_FLAG_GLOBAL, 0,
850 DIREG_DRV, KEY_READ);
851 ok(key != INVALID_HANDLE_VALUE, "SetupDiOpenDevRegKey failed: %08x\n",
852 GetLastError());
853 RegCloseKey(key);
856 ret = pSetupDiRemoveDevice(set, &devInfo);
857 todo_wine ok(ret, "got %u\n", GetLastError());
858 pSetupDiDestroyDeviceInfoList(set);
860 /* remove once Wine is fixed */
861 devinst_RegDeleteTreeW(HKEY_LOCAL_MACHINE, bogus);
862 devinst_RegDeleteTreeW(HKEY_LOCAL_MACHINE, classKey);
866 static void testRegisterAndGetDetail(void)
868 static const WCHAR classKey[] = {'S','y','s','t','e','m','\\',
869 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
870 'C','o','n','t','r','o','l','\\','C','l','a','s','s','\\',
871 '{','6','a','5','5','b','5','a','4','-','3','f','6','5','-',
872 '1','1','d','b','-','b','7','0','4','-',
873 '0','0','1','1','9','5','5','c','2','b','d','b','}',0};
874 static const WCHAR bogus[] = {'S','y','s','t','e','m','\\',
875 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
876 'E','n','u','m','\\','R','o','o','t','\\',
877 'L','E','G','A','C','Y','_','B','O','G','U','S',0};
878 HDEVINFO set, set2;
879 BOOL ret;
880 SP_DEVINFO_DATA devInfo = { sizeof(SP_DEVINFO_DATA), { 0 } };
881 SP_DEVICE_INTERFACE_DATA interfaceData = { sizeof(interfaceData), { 0 } };
882 SP_DEVICE_INTERFACE_DATA interfaceData2 = { sizeof(interfaceData2), { 0 } };
883 DWORD dwSize = 0;
884 HKEY key;
885 LONG res;
887 if (!pSetupDiCreateDeviceInterfaceA || !pSetupDiEnumDeviceInterfaces ||
888 !pSetupDiGetDeviceInterfaceDetailA)
890 win_skip("Needed functions are not available\n");
891 return;
894 SetLastError(0xdeadbeef);
895 set = pSetupDiGetClassDevsA(&guid, NULL, 0, DIGCF_ALLCLASSES);
896 ok(set != INVALID_HANDLE_VALUE, "SetupDiGetClassDevsA failed: %08x\n",
897 GetLastError());
899 res = RegOpenKeyW(HKEY_LOCAL_MACHINE, bogus, &key);
900 ok(res != ERROR_SUCCESS, "Expected key to not exist\n");
901 RegCloseKey(key);
903 SetLastError(0xdeadbeef);
904 ret = pSetupDiCreateDeviceInfoA(set, "LEGACY_BOGUS", &guid, NULL, 0,
905 DICD_GENERATE_ID, &devInfo);
906 ok(ret, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
907 SetLastError(0xdeadbeef);
908 ret = pSetupDiCreateDeviceInterfaceA(set, &devInfo, &guid, NULL, 0, &interfaceData);
909 ok(ret, "SetupDiCreateDeviceInterfaceA failed: %08x\n", GetLastError());
910 SetLastError(0xdeadbeef);
911 ret = pSetupDiRegisterDeviceInfo(set, &devInfo, 0, NULL, NULL, NULL);
912 ok(ret, "SetupDiRegisterDeviceInfo failed: %08x\n", GetLastError());
914 SetLastError(0xdeadbeef);
915 set2 = pSetupDiGetClassDevsA(&guid, NULL, 0, DIGCF_DEVICEINTERFACE);
916 ok(set2 != INVALID_HANDLE_VALUE, "SetupDiGetClassDevsA failed: %08x\n",
917 GetLastError());
919 SetLastError(0xdeadbeef);
920 ret = pSetupDiEnumDeviceInterfaces(set2, NULL, &guid, 0, &interfaceData2);
921 ok(ret, "SetupDiEnumDeviceInterfaces failed: %08x\n", GetLastError());
922 SetLastError(0xdeadbeef);
923 ret = pSetupDiGetDeviceInterfaceDetailA(set2, &interfaceData2, NULL, 0, &dwSize, NULL);
924 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
925 "Expected ERROR_INSUFFICIENT_BUFFER, got %08x\n", GetLastError());
926 if (!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER)
928 static const char path[] =
929 "\\\\?\\root#legacy_bogus#0000#{6a55b5a4-3f65-11db-b704-0011955c2bdb}";
930 static const char path_w10[] =
931 "\\\\?\\root#legacy_bogus#0001#{6a55b5a4-3f65-11db-b704-0011955c2bdb}";
932 static const char path_w2k[] =
933 "\\\\?\\root#legacy_bogus#0000#{6a55b5a4-3f65-11db-b704-0011955c2bdb}\\";
934 PSP_DEVICE_INTERFACE_DETAIL_DATA_A detail = NULL;
936 detail = HeapAlloc(GetProcessHeap(), 0, dwSize);
937 if (detail)
939 detail->cbSize = sizeof(*detail);
940 SetLastError(0xdeadbeef);
941 ret = pSetupDiGetDeviceInterfaceDetailA(set2, &interfaceData2,
942 detail, dwSize, &dwSize, NULL);
943 ok(ret, "SetupDiGetDeviceInterfaceDetailA failed: %08x\n", GetLastError());
944 ok(!lstrcmpiA(path, detail->DevicePath) ||
945 !lstrcmpiA(path_w10, detail->DevicePath) ||
946 !lstrcmpiA(path_w2k, detail->DevicePath),
947 "Unexpected path %s\n", detail->DevicePath);
948 HeapFree(GetProcessHeap(), 0, detail);
952 ret = pSetupDiRemoveDeviceInterface(set, &interfaceData);
953 todo_wine ok(ret, "SetupDiRemoveDeviceInterface failed: %08x\n", GetLastError());
955 ret = pSetupDiRemoveDevice(set, &devInfo);
956 todo_wine ok(ret, "got %u\n", GetLastError());
958 pSetupDiDestroyDeviceInfoList(set);
959 pSetupDiDestroyDeviceInfoList(set2);
961 /* remove once Wine is fixed */
962 devinst_RegDeleteTreeW(HKEY_LOCAL_MACHINE, bogus);
963 devinst_RegDeleteTreeW(HKEY_LOCAL_MACHINE, classKey);
966 static void testDeviceRegistryPropertyA(void)
968 HDEVINFO set;
969 SP_DEVINFO_DATA devInfo = { sizeof(SP_DEVINFO_DATA), { 0 } };
970 CHAR devName[] = "LEGACY_BOGUS";
971 CHAR friendlyName[] = "Bogus";
972 CHAR buf[6] = "";
973 DWORD buflen = 6;
974 DWORD size;
975 DWORD regType;
976 BOOL ret;
977 LONG res;
978 HKEY key;
979 static const CHAR bogus[] =
980 "System\\CurrentControlSet\\Enum\\Root\\LEGACY_BOGUS";
982 SetLastError(0xdeadbeef);
983 set = pSetupDiGetClassDevsA(&guid, NULL, 0, DIGCF_DEVICEINTERFACE);
984 ok(set != INVALID_HANDLE_VALUE, "SetupDiGetClassDevsA failed: %08x\n",
985 GetLastError());
986 SetLastError(0xdeadbeef);
987 ret = pSetupDiCreateDeviceInfoA(set, devName, &guid, NULL, NULL,
988 DICD_GENERATE_ID, &devInfo);
989 ok(ret, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError());
990 SetLastError(0xdeadbeef);
991 ret = pSetupDiSetDeviceRegistryPropertyA(NULL, NULL, -1, NULL, 0);
992 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
993 "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
994 SetLastError(0xdeadbeef);
995 ret = pSetupDiSetDeviceRegistryPropertyA(set, NULL, -1, NULL, 0);
996 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
997 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
998 SetLastError(0xdeadbeef);
999 ret = pSetupDiSetDeviceRegistryPropertyA(set, &devInfo, -1, NULL, 0);
1000 todo_wine
1001 ok(!ret && GetLastError() == ERROR_INVALID_REG_PROPERTY,
1002 "Expected ERROR_INVALID_REG_PROPERTY, got %08x\n", GetLastError());
1003 /* GetLastError() returns nonsense in win2k3 */
1004 ret = pSetupDiSetDeviceRegistryPropertyA(set, &devInfo, SPDRP_FRIENDLYNAME,
1005 NULL, 0);
1006 todo_wine
1007 ok(!ret, "Expected failure, got %d\n", ret);
1008 SetLastError(0xdeadbeef);
1009 ret = pSetupDiSetDeviceRegistryPropertyA(set, &devInfo, SPDRP_FRIENDLYNAME,
1010 (PBYTE)friendlyName, buflen);
1011 ok(ret, "SetupDiSetDeviceRegistryPropertyA failed: %08x\n", GetLastError());
1012 SetLastError(0xdeadbeef);
1013 ret = pSetupDiGetDeviceRegistryPropertyA(NULL, NULL, -1, NULL, NULL, 0, NULL);
1014 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
1015 "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
1016 SetLastError(0xdeadbeef);
1017 ret = pSetupDiGetDeviceRegistryPropertyA(set, NULL, -1, NULL, NULL, 0, NULL);
1018 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
1019 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
1020 SetLastError(0xdeadbeef);
1021 ret = pSetupDiGetDeviceRegistryPropertyA(set, &devInfo, -1, NULL, NULL, 0, NULL);
1022 todo_wine
1023 ok(!ret && GetLastError() == ERROR_INVALID_REG_PROPERTY,
1024 "Expected ERROR_INVALID_REG_PROPERTY, got %08x\n", GetLastError());
1025 /* GetLastError() returns nonsense in win2k3 */
1026 ret = pSetupDiGetDeviceRegistryPropertyA(set, &devInfo, SPDRP_FRIENDLYNAME,
1027 NULL, NULL, buflen, NULL);
1028 ok(!ret, "Expected failure, got %d\n", ret);
1029 SetLastError(0xdeadbeef);
1030 ret = pSetupDiGetDeviceRegistryPropertyA(set, &devInfo, SPDRP_FRIENDLYNAME,
1031 NULL, NULL, 0, &size);
1032 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
1033 "Expected ERROR_INSUFFICIENT_BUFFER, got %08x\n", GetLastError());
1034 ok(buflen == size, "Unexpected size: %d\n", size);
1035 SetLastError(0xdeadbeef);
1036 ret = pSetupDiGetDeviceRegistryPropertyA(set, &devInfo, SPDRP_FRIENDLYNAME,
1037 NULL, (PBYTE)buf, buflen, NULL);
1038 ok(ret, "SetupDiGetDeviceRegistryPropertyA failed: %08x\n", GetLastError());
1039 ok(!lstrcmpiA(friendlyName, buf), "Unexpected property\n");
1040 SetLastError(0xdeadbeef);
1041 ret = pSetupDiGetDeviceRegistryPropertyA(set, &devInfo, SPDRP_FRIENDLYNAME,
1042 &regType, (PBYTE)buf, buflen, NULL);
1043 ok(ret, "SetupDiGetDeviceRegistryPropertyA failed: %08x\n", GetLastError());
1044 ok(!lstrcmpiA(friendlyName, buf), "Unexpected value of property\n");
1045 ok(regType == REG_SZ, "Unexpected type of property: %d\n", regType);
1046 SetLastError(0xdeadbeef);
1047 ret = pSetupDiSetDeviceRegistryPropertyA(set, &devInfo, SPDRP_FRIENDLYNAME,
1048 NULL, 0);
1049 ok(ret, "SetupDiSetDeviceRegistryPropertyA failed: %08x\n", GetLastError());
1050 SetLastError(0xdeadbeef);
1051 ret = pSetupDiGetDeviceRegistryPropertyA(set, &devInfo, SPDRP_FRIENDLYNAME,
1052 NULL, (PBYTE)buf, buflen, &size);
1053 todo_wine
1054 ok(!ret && GetLastError() == ERROR_INVALID_DATA,
1055 "Expected ERROR_INVALID_DATA, got %08x\n", GetLastError());
1056 ret = pSetupDiGetDeviceRegistryPropertyA(set, &devInfo, SPDRP_HARDWAREID,
1057 NULL, NULL, 0, &size);
1058 ok(!ret && GetLastError() == ERROR_INVALID_DATA,
1059 "Expected ERROR_INVALID_DATA, got %08x\n", GetLastError());
1060 pSetupDiDestroyDeviceInfoList(set);
1062 res = RegOpenKeyA(HKEY_LOCAL_MACHINE, bogus, &key);
1063 if(!is_wow64)
1064 todo_wine ok(res == ERROR_FILE_NOT_FOUND, "Expected key to not exist\n");
1065 /* FIXME: Remove when Wine is fixed */
1066 if (res == ERROR_SUCCESS)
1068 /* Wine doesn't delete the information currently */
1069 RegDeleteKeyA(HKEY_LOCAL_MACHINE, bogus);
1073 static void testDeviceRegistryPropertyW(void)
1075 HDEVINFO set;
1076 SP_DEVINFO_DATA devInfo = { sizeof(SP_DEVINFO_DATA), { 0 } };
1077 WCHAR devName[] = {'L','E','G','A','C','Y','_','B','O','G','U','S',0};
1078 WCHAR friendlyName[] = {'B','o','g','u','s',0};
1079 WCHAR buf[6] = {0};
1080 DWORD buflen = 6 * sizeof(WCHAR);
1081 DWORD size;
1082 DWORD regType;
1083 BOOL ret;
1084 LONG res;
1085 HKEY key;
1086 static const WCHAR bogus[] = {'S','y','s','t','e','m','\\',
1087 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
1088 'E','n','u','m','\\','R','o','o','t','\\',
1089 'L','E','G','A','C','Y','_','B','O','G','U','S',0};
1091 SetLastError(0xdeadbeef);
1092 set = pSetupDiGetClassDevsW(&guid, NULL, 0, DIGCF_DEVICEINTERFACE);
1093 ok(set != INVALID_HANDLE_VALUE, "SetupDiGetClassDevsW failed: %08x\n",
1094 GetLastError());
1095 SetLastError(0xdeadbeef);
1096 ret = pSetupDiCreateDeviceInfoW(set, devName, &guid, NULL, NULL,
1097 DICD_GENERATE_ID, &devInfo);
1098 ok(ret, "SetupDiCreateDeviceInfoW failed: %08x\n", GetLastError());
1099 SetLastError(0xdeadbeef);
1100 ret = pSetupDiSetDeviceRegistryPropertyW(NULL, NULL, -1, NULL, 0);
1101 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
1102 "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
1103 SetLastError(0xdeadbeef);
1104 ret = pSetupDiSetDeviceRegistryPropertyW(set, NULL, -1, NULL, 0);
1105 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
1106 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
1107 SetLastError(0xdeadbeef);
1108 ret = pSetupDiSetDeviceRegistryPropertyW(set, &devInfo, -1, NULL, 0);
1109 todo_wine
1110 ok(!ret && GetLastError() == ERROR_INVALID_REG_PROPERTY,
1111 "Expected ERROR_INVALID_REG_PROPERTY, got %08x\n", GetLastError());
1112 /* GetLastError() returns nonsense in win2k3 */
1113 ret = pSetupDiSetDeviceRegistryPropertyW(set, &devInfo, SPDRP_FRIENDLYNAME,
1114 NULL, 0);
1115 todo_wine
1116 ok(!ret, "Expected failure, got %d\n", ret);
1117 SetLastError(0xdeadbeef);
1118 ret = pSetupDiSetDeviceRegistryPropertyW(set, &devInfo, SPDRP_FRIENDLYNAME,
1119 (PBYTE)friendlyName, buflen);
1120 ok(ret, "SetupDiSetDeviceRegistryPropertyW failed: %08x\n", GetLastError());
1121 SetLastError(0xdeadbeef);
1122 ret = pSetupDiGetDeviceRegistryPropertyW(NULL, NULL, -1, NULL, NULL, 0, NULL);
1123 ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
1124 "Expected ERROR_INVALID_HANDLE, got %08x\n", GetLastError());
1125 SetLastError(0xdeadbeef);
1126 ret = pSetupDiGetDeviceRegistryPropertyW(set, NULL, -1, NULL, NULL, 0, NULL);
1127 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
1128 "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
1129 SetLastError(0xdeadbeef);
1130 ret = pSetupDiGetDeviceRegistryPropertyW(set, &devInfo, -1, NULL, NULL, 0, NULL);
1131 todo_wine
1132 ok(!ret && GetLastError() == ERROR_INVALID_REG_PROPERTY,
1133 "Expected ERROR_INVALID_REG_PROPERTY, got %08x\n", GetLastError());
1134 /* GetLastError() returns nonsense in win2k3 */
1135 ret = pSetupDiGetDeviceRegistryPropertyW(set, &devInfo, SPDRP_FRIENDLYNAME,
1136 NULL, NULL, buflen, NULL);
1137 ok(!ret, "Expected failure, got %d\n", ret);
1138 SetLastError(0xdeadbeef);
1139 ret = pSetupDiGetDeviceRegistryPropertyW(set, &devInfo, SPDRP_FRIENDLYNAME,
1140 NULL, NULL, 0, &size);
1141 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
1142 "Expected ERROR_INSUFFICIENT_BUFFER, got %08x\n", GetLastError());
1143 ok(buflen == size, "Unexpected size: %d\n", size);
1144 SetLastError(0xdeadbeef);
1145 ret = pSetupDiGetDeviceRegistryPropertyW(set, &devInfo, SPDRP_FRIENDLYNAME,
1146 NULL, (PBYTE)buf, buflen, NULL);
1147 ok(ret, "SetupDiGetDeviceRegistryPropertyW failed: %08x\n", GetLastError());
1148 ok(!lstrcmpiW(friendlyName, buf), "Unexpected property\n");
1149 SetLastError(0xdeadbeef);
1150 ret = pSetupDiGetDeviceRegistryPropertyW(set, &devInfo, SPDRP_FRIENDLYNAME,
1151 &regType, (PBYTE)buf, buflen, NULL);
1152 ok(ret, "SetupDiGetDeviceRegistryPropertyW failed: %08x\n", GetLastError());
1153 ok(!lstrcmpiW(friendlyName, buf), "Unexpected value of property\n");
1154 ok(regType == REG_SZ, "Unexpected type of property: %d\n", regType);
1155 SetLastError(0xdeadbeef);
1156 ret = pSetupDiSetDeviceRegistryPropertyW(set, &devInfo, SPDRP_FRIENDLYNAME,
1157 NULL, 0);
1158 ok(ret, "SetupDiSetDeviceRegistryPropertyW failed: %08x\n", GetLastError());
1159 SetLastError(0xdeadbeef);
1160 ret = pSetupDiGetDeviceRegistryPropertyW(set, &devInfo, SPDRP_FRIENDLYNAME,
1161 NULL, (PBYTE)buf, buflen, &size);
1162 todo_wine
1163 ok(!ret && GetLastError() == ERROR_INVALID_DATA,
1164 "Expected ERROR_INVALID_DATA, got %08x\n", GetLastError());
1165 ret = pSetupDiGetDeviceRegistryPropertyW(set, &devInfo, SPDRP_HARDWAREID,
1166 NULL, NULL, 0, &size);
1167 ok(!ret && GetLastError() == ERROR_INVALID_DATA,
1168 "Expected ERROR_INVALID_DATA, got %08x\n", GetLastError());
1169 pSetupDiDestroyDeviceInfoList(set);
1171 res = RegOpenKeyW(HKEY_LOCAL_MACHINE, bogus, &key);
1172 if(!is_wow64)
1173 todo_wine ok(res == ERROR_FILE_NOT_FOUND, "Expected key to not exist\n");
1174 /* FIXME: Remove when Wine is fixed */
1175 if (res == ERROR_SUCCESS)
1177 /* Wine doesn't delete the information currently */
1178 RegDeleteKeyW(HKEY_LOCAL_MACHINE, bogus);
1182 static void testSetupDiGetINFClassA(void)
1184 static const char inffile[] = "winetest.inf";
1185 static const char content[] = "[Version]\r\n\r\n";
1186 static const char* signatures[] = {"\"$CHICAGO$\"", "\"$Windows NT$\""};
1188 char cn[MAX_PATH];
1189 char filename[MAX_PATH];
1190 DWORD count;
1191 BOOL retval;
1192 GUID guid;
1193 HANDLE h;
1194 int i;
1196 if(!pSetupDiGetINFClassA)
1198 win_skip("SetupDiGetINFClassA not present\n");
1199 return;
1202 count = GetTempPathA(MAX_PATH, filename);
1203 if(!count)
1205 win_skip("GetTempPathA failed\n");
1206 return;
1209 strcat(filename, inffile);
1210 DeleteFileA(filename);
1212 /* not existing file */
1213 SetLastError(0xdeadbeef);
1214 retval = SetupDiGetINFClassA(filename, &guid, cn, MAX_PATH, &count);
1215 ok(!retval, "expected SetupDiGetINFClassA to fail!\n");
1216 if (ERROR_CALL_NOT_IMPLEMENTED == GetLastError())
1218 skip("SetupDiGetINFClassA is not implemented\n");
1219 return;
1221 ok(ERROR_FILE_NOT_FOUND == GetLastError(),
1222 "expected error ERROR_FILE_NOT_FOUND, got %u\n", GetLastError());
1224 /* missing file wins against other invalid parameter */
1225 SetLastError(0xdeadbeef);
1226 retval = SetupDiGetINFClassA(filename, NULL, cn, MAX_PATH, &count);
1227 ok(!retval, "expected SetupDiGetINFClassA to fail!\n");
1228 ok(ERROR_FILE_NOT_FOUND == GetLastError(),
1229 "expected error ERROR_FILE_NOT_FOUND, got %u\n", GetLastError());
1231 SetLastError(0xdeadbeef);
1232 retval = SetupDiGetINFClassA(filename, &guid, NULL, MAX_PATH, &count);
1233 ok(!retval, "expected SetupDiGetINFClassA to fail!\n");
1234 ok(ERROR_FILE_NOT_FOUND == GetLastError(),
1235 "expected error ERROR_FILE_NOT_FOUND, got %u\n", GetLastError());
1237 SetLastError(0xdeadbeef);
1238 retval = SetupDiGetINFClassA(filename, &guid, cn, 0, &count);
1239 ok(!retval, "expected SetupDiGetINFClassA to fail!\n");
1240 ok(ERROR_FILE_NOT_FOUND == GetLastError(),
1241 "expected error ERROR_FILE_NOT_FOUND, got %u\n", GetLastError());
1243 SetLastError(0xdeadbeef);
1244 retval = SetupDiGetINFClassA(filename, &guid, cn, MAX_PATH, NULL);
1245 ok(!retval, "expected SetupDiGetINFClassA to fail!\n");
1246 ok(ERROR_FILE_NOT_FOUND == GetLastError(),
1247 "expected error ERROR_FILE_NOT_FOUND, got %u\n", GetLastError());
1249 /* test file content */
1250 h = CreateFileA(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
1251 FILE_ATTRIBUTE_NORMAL, NULL);
1252 if(h == INVALID_HANDLE_VALUE)
1254 win_skip("failed to create file %s (error %u)\n", filename, GetLastError());
1255 return;
1257 CloseHandle( h);
1259 retval = SetupDiGetINFClassA(filename, &guid, cn, MAX_PATH, &count);
1260 ok(!retval, "expected SetupDiGetINFClassA to fail!\n");
1262 for(i=0; i < sizeof(signatures)/sizeof(char*); i++)
1264 trace("testing signature %s\n", signatures[i]);
1265 h = CreateFileA(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
1266 FILE_ATTRIBUTE_NORMAL, NULL);
1267 if(h == INVALID_HANDLE_VALUE)
1269 win_skip("failed to create file %s (error %u)\n", filename, GetLastError());
1270 return;
1272 WriteFile( h, content, sizeof(content), &count, NULL);
1273 CloseHandle( h);
1275 retval = SetupDiGetINFClassA(filename, &guid, cn, MAX_PATH, &count);
1276 ok(!retval, "expected SetupDiGetINFClassA to fail!\n");
1278 WritePrivateProfileStringA("Version", "Signature", signatures[i], filename);
1280 retval = SetupDiGetINFClassA(filename, &guid, cn, MAX_PATH, &count);
1281 ok(!retval, "expected SetupDiGetINFClassA to fail!\n");
1283 WritePrivateProfileStringA("Version", "Class", "WINE", filename);
1285 count = 0xdeadbeef;
1286 retval = SetupDiGetINFClassA(filename, &guid, cn, MAX_PATH, &count);
1287 ok(retval, "expected SetupDiGetINFClassA to succeed! error %u\n", GetLastError());
1288 ok(count == 5, "expected count==5, got %u\n", count);
1290 count = 0xdeadbeef;
1291 retval = SetupDiGetINFClassA(filename, &guid, cn, 5, &count);
1292 ok(retval, "expected SetupDiGetINFClassA to succeed! error %u\n", GetLastError());
1293 ok(count == 5, "expected count==5, got %u\n", count);
1295 count = 0xdeadbeef;
1296 SetLastError(0xdeadbeef);
1297 retval = SetupDiGetINFClassA(filename, &guid, cn, 4, &count);
1298 ok(!retval, "expected SetupDiGetINFClassA to fail!\n");
1299 ok(ERROR_INSUFFICIENT_BUFFER == GetLastError(),
1300 "expected error ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
1301 ok(count == 5, "expected count==5, got %u\n", count);
1303 /* invalid parameter */
1304 SetLastError(0xdeadbeef);
1305 retval = SetupDiGetINFClassA(NULL, &guid, cn, MAX_PATH, &count);
1306 ok(!retval, "expected SetupDiGetINFClassA to fail!\n");
1307 ok(ERROR_INVALID_PARAMETER == GetLastError(),
1308 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1310 SetLastError(0xdeadbeef);
1311 retval = SetupDiGetINFClassA(filename, NULL, cn, MAX_PATH, &count);
1312 ok(!retval, "expected SetupDiGetINFClassA to fail!\n");
1313 ok(ERROR_INVALID_PARAMETER == GetLastError(),
1314 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1316 SetLastError(0xdeadbeef);
1317 retval = SetupDiGetINFClassA(filename, &guid, NULL, MAX_PATH, &count);
1318 ok(!retval, "expected SetupDiGetINFClassA to fail!\n");
1319 ok(ERROR_INVALID_PARAMETER == GetLastError(),
1320 "expected error ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1322 SetLastError(0xdeadbeef);
1323 retval = SetupDiGetINFClassA(filename, &guid, cn, 0, &count);
1324 ok(!retval, "expected SetupDiGetINFClassA to fail!\n");
1325 ok(ERROR_INSUFFICIENT_BUFFER == GetLastError() ||
1326 ERROR_INVALID_PARAMETER == GetLastError(),
1327 "expected error ERROR_INSUFFICIENT_BUFFER or ERROR_INVALID_PARAMETER, "
1328 "got %u\n", GetLastError());
1330 DeleteFileA(filename);
1332 WritePrivateProfileStringA("Version", "Signature", signatures[i], filename);
1333 WritePrivateProfileStringA("Version", "ClassGUID", "WINE", filename);
1335 SetLastError(0xdeadbeef);
1336 retval = SetupDiGetINFClassA(filename, &guid, cn, MAX_PATH, &count);
1337 ok(!retval, "expected SetupDiGetINFClassA to fail!\n");
1338 ok(RPC_S_INVALID_STRING_UUID == GetLastError() ||
1339 ERROR_INVALID_PARAMETER == GetLastError(),
1340 "expected error RPC_S_INVALID_STRING_UUID or ERROR_INVALID_PARAMETER, "
1341 "got %u\n", GetLastError());
1343 /* network adapter guid */
1344 WritePrivateProfileStringA("Version", "ClassGUID",
1345 "{4d36e972-e325-11ce-bfc1-08002be10318}", filename);
1347 /* this test succeeds only if the guid is known to the system */
1348 count = 0xdeadbeef;
1349 retval = SetupDiGetINFClassA(filename, &guid, cn, MAX_PATH, &count);
1350 ok(retval, "expected SetupDiGetINFClassA to succeed! error %u\n", GetLastError());
1351 todo_wine
1352 ok(count == 4, "expected count==4, got %u(%s)\n", count, cn);
1354 DeleteFileA(filename);
1358 START_TEST(devinst)
1360 HKEY hkey;
1362 init_function_pointers();
1364 if ((hkey = SetupDiOpenClassRegKey(NULL, KEY_ALL_ACCESS)) == INVALID_HANDLE_VALUE)
1366 skip("needs admin rights\n");
1367 return;
1369 RegCloseKey(hkey);
1371 if (pIsWow64Process)
1372 pIsWow64Process(GetCurrentProcess(), &is_wow64);
1374 if (pSetupDiCreateDeviceInfoListExW)
1375 test_SetupDiCreateDeviceInfoListEx();
1376 else
1377 win_skip("SetupDiCreateDeviceInfoListExW is not available\n");
1379 if (pSetupDiOpenClassRegKeyExA)
1380 test_SetupDiOpenClassRegKeyExA();
1381 else
1382 win_skip("SetupDiOpenClassRegKeyExA is not available\n");
1384 testInstallClass();
1385 testCreateDeviceInfo();
1386 testGetDeviceInstanceId();
1387 testRegisterDeviceInfo();
1388 testCreateDeviceInterface();
1389 testGetDeviceInterfaceDetail();
1390 testDevRegKey();
1391 testRegisterAndGetDetail();
1392 testDeviceRegistryPropertyA();
1393 testDeviceRegistryPropertyW();
1394 testSetupDiGetINFClassA();