Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/setupapi/tests/devinst.c | 156 ++++++++++++++++++++++++++++++++++ 1 file changed, 156 insertions(+)
diff --git a/dlls/setupapi/tests/devinst.c b/dlls/setupapi/tests/devinst.c index 728c4a3627d..38d0bb162c9 100644 --- a/dlls/setupapi/tests/devinst.c +++ b/dlls/setupapi/tests/devinst.c @@ -37,6 +37,7 @@ /* This is a unique guid for testing purposes */ static GUID guid = {0x6a55b5a4, 0x3f65, 0x11db, {0xb7,0x04,0x00,0x11,0x95,0x5c,0x2b,0xdb}}; static GUID guid2 = {0x6a55b5a5, 0x3f65, 0x11db, {0xb7,0x04,0x00,0x11,0x95,0x5c,0x2b,0xdb}}; +static GUID iface_guid = {0xdeadbeef, 0x3f65, 0x11db, {0xb7,0x04,0x00,0x11,0x95,0x5c,0x2b,0xdb}};
BOOL (WINAPI *pSetupDiSetDevicePropertyW)(HDEVINFO, PSP_DEVINFO_DATA, const DEVPROPKEY *, DEVPROPTYPE, const BYTE *, DWORD, DWORD); BOOL (WINAPI *pSetupDiGetDevicePropertyW)(HDEVINFO, PSP_DEVINFO_DATA, const DEVPROPKEY *, DEVPROPTYPE *, BYTE *, DWORD, DWORD *, DWORD); @@ -2699,6 +2700,160 @@ static void test_call_class_installer(void) ok(ret, "Failed to delete file, error %u.\n", GetLastError()); }
+static void check_all_devices_enumerated_(int line, HDEVINFO set) +{ + SP_DEVINFO_DATA device = {sizeof(device)}; + BOOL ret, found_dev1 = 0, found_dev2 = 0, found_dev3 = 0; + char id[50]; + DWORD i; + + for (i = 0; SetupDiEnumDeviceInfo(set, i, &device); ++i) + { + ret = SetupDiGetDeviceInstanceIdA(set, &device, id, sizeof(id), NULL); + if (!ret) continue; + + if (!strcasecmp(id, "Root\LEGACY_BOGUS\foo")) + { + found_dev1 = 1; + ok_(__FILE__, line)(IsEqualGUID(&device.ClassGuid, &guid), + "Got unexpected class %s.\n", wine_dbgstr_guid(&device.ClassGuid)); + } + else if (!strcasecmp(id, "Root\LEGACY_BOGUS\qux")) + { + found_dev2 = 1; + ok_(__FILE__, line)(IsEqualGUID(&device.ClassGuid, &guid), + "Got unexpected class %s.\n", wine_dbgstr_guid(&device.ClassGuid)); + } + else if (!strcasecmp(id, "Root\LEGACY_BOGUS\bar")) + { + found_dev3 = 1; + ok_(__FILE__, line)(IsEqualGUID(&device.ClassGuid, &guid2), + "Got unexpected class %s.\n", wine_dbgstr_guid(&device.ClassGuid)); + } + } + ok_(__FILE__, line)(found_dev1, "Expected device 1 to be enumerated.\n"); + ok_(__FILE__, line)(found_dev2, "Expected device 2 to be enumerated.\n"); + ok_(__FILE__, line)(found_dev3, "Expected device 2 to be enumerated.\n"); +} +#define check_all_devices_enumerated(a) check_all_devices_enumerated_(__LINE__,a) + +static void test_get_class_devs(void) +{ + SP_DEVICE_INTERFACE_DATA iface = {sizeof(iface)}; + SP_DEVINFO_DATA device = {sizeof(device)}; + HDEVINFO set; + BOOL ret; + + set = SetupDiCreateDeviceInfoList(NULL, NULL); + ok(set != INVALID_HANDLE_VALUE, "Failed to create device list, error %#x.\n", GetLastError()); + + ret = SetupDiCreateDeviceInfoA(set, "Root\LEGACY_BOGUS\foo", &guid, NULL, NULL, 0, &device); + ok(ret, "Failed to create device, error %#x.\n", GetLastError()); + ret = SetupDiCreateDeviceInterfaceA(set, &device, &iface_guid, NULL, 0, &iface); + ok(ret, "Failed to create interface, error %#x.\n", GetLastError()); + ret = SetupDiRegisterDeviceInfo(set, &device, 0, NULL, NULL, NULL); + ok(ret, "Failed to register device, error %#x.\n", GetLastError()); + + ret = SetupDiCreateDeviceInfoA(set, "Root\LEGACY_BOGUS\qux", &guid, NULL, NULL, 0, &device); + ok(ret, "Failed to create device, error %#x.\n", GetLastError()); + ret = SetupDiRegisterDeviceInfo(set, &device, 0, NULL, NULL, NULL); + ok(ret, "Failed to register device, error %#x.\n", GetLastError()); + + ret = SetupDiCreateDeviceInfoA(set, "Root\LEGACY_BOGUS\bar", &guid2, NULL, NULL, 0, &device); + ok(ret, "Failed to create device, error %#x.\n", GetLastError()); + ret = SetupDiRegisterDeviceInfo(set, &device, 0, NULL, NULL, NULL); + ok(ret, "Failed to register device, error %#x.\n", GetLastError()); + + ret = SetupDiDestroyDeviceInfoList(set); + ok(ret, "Failed to destroy device list, error %#x.\n", GetLastError()); + + SetLastError(0xdeadbeef); + set = SetupDiGetClassDevsA(NULL, NULL, NULL, 0); + ok(set == INVALID_HANDLE_VALUE, "Expected failure.\n"); + ok(GetLastError() == ERROR_INVALID_PARAMETER, "Got unexpected error %#x.\n", GetLastError()); + + set = SetupDiGetClassDevsA(NULL, NULL, NULL, DIGCF_ALLCLASSES); + ok(set != INVALID_HANDLE_VALUE, "Failed to create device list, error %#x.\n", GetLastError()); + check_all_devices_enumerated(set); + check_device_iface(set, NULL, &iface_guid, 0, 0, NULL); + ret = SetupDiDestroyDeviceInfoList(set); + ok(ret, "Failed to destroy device list, error %#x.\n", GetLastError()); + + set = SetupDiGetClassDevsA(&guid, NULL, NULL, 0); + ok(set != INVALID_HANDLE_VALUE, "Failed to create device list, error %#x.\n", GetLastError()); + check_device_info(set, 0, &guid, "ROOT\LEGACY_BOGUS\FOO"); + check_device_info(set, 1, &guid, "ROOT\LEGACY_BOGUS\QUX"); + check_device_info(set, 2, NULL, NULL); + check_device_iface(set, NULL, &iface_guid, 0, 0, NULL); + ret = SetupDiDestroyDeviceInfoList(set); + ok(ret, "Failed to destroy device list, error %#x.\n", GetLastError()); + + set = SetupDiGetClassDevsA(&guid, NULL, NULL, DIGCF_ALLCLASSES); + ok(set != INVALID_HANDLE_VALUE, "Failed to create device list, error %#x.\n", GetLastError()); + check_all_devices_enumerated(set); + check_device_iface(set, NULL, &iface_guid, 0, 0, NULL); + ret = SetupDiDestroyDeviceInfoList(set); + ok(ret, "Failed to destroy device list, error %#x.\n", GetLastError()); + + SetLastError(0xdeadbeef); + set = SetupDiGetClassDevsA(NULL, "ROOT", NULL, 0); + ok(set == INVALID_HANDLE_VALUE, "Expected failure.\n"); + ok(GetLastError() == ERROR_INVALID_PARAMETER, "Got unexpected error %#x.\n", GetLastError()); + + set = SetupDiGetClassDevsA(NULL, "ROOT", NULL, DIGCF_ALLCLASSES); + ok(set != INVALID_HANDLE_VALUE, "Failed to create device list, error %#x.\n", GetLastError()); + check_all_devices_enumerated(set); + check_device_iface(set, NULL, &iface_guid, 0, 0, NULL); + ret = SetupDiDestroyDeviceInfoList(set); + ok(ret, "Failed to destroy device list, error %#x.\n", GetLastError()); + + set = SetupDiGetClassDevsA(NULL, "ROOT\LEGACY_BOGUS", NULL, DIGCF_ALLCLASSES); + ok(set != INVALID_HANDLE_VALUE, "Failed to create device list, error %#x.\n", GetLastError()); +todo_wine { + check_device_info(set, 0, &guid2, "ROOT\LEGACY_BOGUS\BAR"); + check_device_info(set, 1, &guid, "ROOT\LEGACY_BOGUS\FOO"); + check_device_info(set, 2, &guid, "ROOT\LEGACY_BOGUS\QUX"); +} + check_device_info(set, 3, NULL, NULL); + check_device_iface(set, NULL, &iface_guid, 0, 0, NULL); + ret = SetupDiDestroyDeviceInfoList(set); + ok(ret, "Failed to destroy device list, error %#x.\n", GetLastError()); + + set = SetupDiGetClassDevsA(&guid, "ROOT\LEGACY_BOGUS", NULL, 0); + ok(set != INVALID_HANDLE_VALUE, "Failed to create device list, error %#x.\n", GetLastError()); +todo_wine { + check_device_info(set, 0, &guid, "ROOT\LEGACY_BOGUS\FOO"); + check_device_info(set, 1, &guid, "ROOT\LEGACY_BOGUS\QUX"); +} + check_device_info(set, 2, NULL, NULL); + check_device_iface(set, NULL, &iface_guid, 0, 0, NULL); + ret = SetupDiDestroyDeviceInfoList(set); + ok(ret, "Failed to destroy device list, error %#x.\n", GetLastError()); + + set = SetupDiGetClassDevsA(&guid, "ROOT\LEGACY_BOGUS", NULL, DIGCF_ALLCLASSES); + ok(set != INVALID_HANDLE_VALUE, "Failed to create device list, error %#x.\n", GetLastError()); +todo_wine { + check_device_info(set, 0, &guid2, "ROOT\LEGACY_BOGUS\BAR"); + check_device_info(set, 1, &guid, "ROOT\LEGACY_BOGUS\FOO"); + check_device_info(set, 2, &guid, "ROOT\LEGACY_BOGUS\QUX"); +} + check_device_info(set, 3, NULL, NULL); + check_device_iface(set, NULL, &iface_guid, 0, 0, NULL); + ret = SetupDiDestroyDeviceInfoList(set); + ok(ret, "Failed to destroy device list, error %#x.\n", GetLastError()); + + set = SetupDiGetClassDevsA(&guid, NULL, NULL, 0); + SetupDiEnumDeviceInfo(set, 0, &device); + SetupDiRemoveDevice(set, &device); + SetupDiEnumDeviceInfo(set, 1, &device); + SetupDiRemoveDevice(set, &device); + SetupDiDestroyDeviceInfoList(set); + set = SetupDiGetClassDevsA(&guid2, NULL, NULL, 0); + SetupDiEnumDeviceInfo(set, 0, &device); + SetupDiRemoveDevice(set, &device); + SetupDiDestroyDeviceInfoList(set); +} + START_TEST(devinst) { static BOOL (WINAPI *pIsWow64Process)(HANDLE, BOOL *); @@ -2736,4 +2891,5 @@ START_TEST(devinst) test_device_install_params(); test_driver_list(); test_call_class_installer(); + test_get_class_devs(); }