From: Mohamad Al-Jaf mohamadaljaf@gmail.com
--- dlls/windows.devices.usb/tests/usb.c | 56 +++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-)
diff --git a/dlls/windows.devices.usb/tests/usb.c b/dlls/windows.devices.usb/tests/usb.c index 347cfa29c1c..1899c24e95f 100644 --- a/dlls/windows.devices.usb/tests/usb.c +++ b/dlls/windows.devices.usb/tests/usb.c @@ -45,13 +45,40 @@ static void check_interface_( unsigned int line, void *obj, const IID *iid ) IUnknown_Release( unk ); }
+static HRESULT wine_GetDeviceSelectorVidPidOnly( UINT32 vendor, UINT32 product, HSTRING *value ) +{ + static const WCHAR *prefix = L"System.Devices.InterfaceClassGuid:="{DEE824EF-729B-4A0E-9C14-B7117D33A817}"" + L" AND System.Devices.InterfaceEnabled:=System.StructuredQueryType.Boolean#True" + L" AND System.DeviceInterface.WinUsb.UsbVendorId:="; + static const WCHAR *suffix = L" AND System.DeviceInterface.WinUsb.UsbProductId:="; + WCHAR *buffer; + int length; + HRESULT hr; + + if (!value) return E_INVALIDARG; + + length = _snwprintf( NULL, 0, L"%ls%d%ls%d", prefix, (INT32)vendor, suffix, (INT32)product ); + if (length < 0) return E_FAIL; + + buffer = (WCHAR *)malloc( (length + 1) * sizeof(WCHAR) ); + if (!buffer) return E_OUTOFMEMORY; + + _snwprintf( buffer, length + 1, L"%ls%d%ls%d", prefix, (INT32)vendor, suffix, (INT32)product ); + hr = WindowsCreateString( buffer, length, value ); + + free( buffer ); + return hr; +} + static void test_UsbDevicesStatics(void) { static const WCHAR *usbdevice_statics_name = L"Windows.Devices.Usb.UsbDevice"; IUsbDeviceStatics *usbdevice_statics; IActivationFactory *factory; - HSTRING str; + UINT32 vendor, product; + HSTRING str, wine_str; HRESULT hr; + INT32 res; LONG ref;
hr = WindowsCreateString( usbdevice_statics_name, wcslen( usbdevice_statics_name ), &str ); @@ -73,6 +100,33 @@ static void test_UsbDevicesStatics(void) hr = IActivationFactory_QueryInterface( factory, &IID_IUsbDeviceStatics, (void **)&usbdevice_statics ); ok( hr == S_OK, "got hr %#lx.\n", hr );
+ hr = IUsbDeviceStatics_GetDeviceSelectorVidPidOnly( usbdevice_statics, 5, 10, NULL ); + ok( hr == E_INVALIDARG, "got hr %#lx.\n", hr ); + + vendor = 20; + product = 23; + hr = IUsbDeviceStatics_GetDeviceSelectorVidPidOnly( usbdevice_statics, vendor, product, &str ); + ok( hr == S_OK, "got hr %#lx.\n", hr ); + hr = wine_GetDeviceSelectorVidPidOnly( vendor, product, &wine_str ); + ok( hr == S_OK, "got hr %#lx.\n", hr ); + hr = WindowsCompareStringOrdinal( str, wine_str, &res ); + ok( hr == S_OK, "got hr %#lx.\n", hr ); + ok( !res, "got string %s.\n", debugstr_hstring(str) ); + WindowsDeleteString( str ); + WindowsDeleteString( wine_str ); + + vendor = 4294967195; /* Vendor = -101 */ + product = -1294967195; + hr = IUsbDeviceStatics_GetDeviceSelectorVidPidOnly( usbdevice_statics, vendor, product, &str ); + ok( hr == S_OK, "got hr %#lx.\n", hr ); + hr = wine_GetDeviceSelectorVidPidOnly( vendor, product, &wine_str ); + ok( hr == S_OK, "got hr %#lx.\n", hr ); + hr = WindowsCompareStringOrdinal( str, wine_str, &res ); + ok( hr == S_OK, "got hr %#lx.\n", hr ); + ok( !res, "got string %s.\n", debugstr_hstring(str) ); + WindowsDeleteString( str ); + WindowsDeleteString( wine_str ); + ref = IUsbDeviceStatics_Release( usbdevice_statics ); ok( ref == 2, "got ref %ld.\n", ref ); ref = IActivationFactory_Release( factory );