From: Vibhav Pant vibhavp@gmail.com
--- .../tests/bluetooth.c | 131 ++++++++++++++++-- 1 file changed, 123 insertions(+), 8 deletions(-)
diff --git a/dlls/windows.devices.bluetooth/tests/bluetooth.c b/dlls/windows.devices.bluetooth/tests/bluetooth.c index 5b78e1e176d..0db9ca0ad25 100644 --- a/dlls/windows.devices.bluetooth/tests/bluetooth.c +++ b/dlls/windows.devices.bluetooth/tests/bluetooth.c @@ -201,21 +201,94 @@ static void check_bluetoothledevice_async( int line, IAsyncOperation_BluetoothLE } }
+static void await_bluetoothadapter( int line, IAsyncOperation_BluetoothAdapter *async ) +{ + IAsyncOperationCompletedHandler_IInspectable *handler; + HANDLE event; + HRESULT hr; + DWORD ret; + + event = CreateEventW( NULL, FALSE, FALSE, NULL ); + ok_(__FILE__, line)( !!event, "CreateEventW failed, error %lu\n", GetLastError() ); + + handler = inspectable_async_handler_create( event, &IID_IAsyncOperationCompletedHandler_BluetoothAdapter ); + ok_( __FILE__, line )( !!handler, "inspectable_async_handler_create failed\n" ); + hr = IAsyncOperation_BluetoothAdapter_put_Completed( async, (IAsyncOperationCompletedHandler_BluetoothAdapter *)handler ); + ok_(__FILE__, line)( hr == S_OK, "put_Completed returned %#lx\n", hr ); + IAsyncOperationCompletedHandler_IInspectable_Release( handler ); + + ret = WaitForSingleObject( event, 5000 ); + ok_(__FILE__, line)( !ret, "WaitForSingleObject returned %#lx\n", ret ); + ret = CloseHandle( event ); + ok_(__FILE__, line)( ret, "CloseHandle failed, error %lu\n", GetLastError() ); +} + +static void check_bluetoothadapter_async( int line, IAsyncOperation_BluetoothAdapter *async, + UINT32 expect_id, AsyncStatus expect_status, + HRESULT expect_hr, IBluetoothAdapter **result ) +{ + AsyncStatus async_status; + IAsyncInfo *async_info; + HRESULT hr, async_hr; + UINT32 async_id; + + hr = IAsyncOperation_BluetoothAdapter_QueryInterface( async, &IID_IAsyncInfo, (void **)&async_info ); + ok_(__FILE__, line)( hr == S_OK, "QueryInterface returned %#lx\n", hr ); + + async_id = 0xdeadbeef; + hr = IAsyncInfo_get_Id( async_info, &async_id ); + if (expect_status < 4) ok_(__FILE__, line)( hr == S_OK, "get_Id returned %#lx\n", hr ); + else ok_(__FILE__, line)( hr == E_ILLEGAL_METHOD_CALL, "get_Id returned %#lx\n", hr ); + ok_(__FILE__, line)( async_id == expect_id, "got id %u\n", async_id ); + + async_status = 0xdeadbeef; + hr = IAsyncInfo_get_Status( async_info, &async_status ); + if (expect_status < 4) ok_(__FILE__, line)( hr == S_OK, "get_Status returned %#lx\n", hr ); + else ok_(__FILE__, line)( hr == E_ILLEGAL_METHOD_CALL, "get_Status returned %#lx\n", hr ); + ok_(__FILE__, line)( async_status == expect_status, "got status %u\n", async_status ); + + async_hr = 0xdeadbeef; + hr = IAsyncInfo_get_ErrorCode( async_info, &async_hr ); + if (expect_status < 4) ok_(__FILE__, line)( hr == S_OK, "get_ErrorCode returned %#lx\n", hr ); + else ok_(__FILE__, line)( hr == E_ILLEGAL_METHOD_CALL, "get_ErrorCode returned %#lx\n", hr ); + if (expect_status < 4) todo_wine_if( FAILED(expect_hr)) + ok_(__FILE__, line)( async_hr == expect_hr, "got error %#lx\n", async_hr ); + else ok_(__FILE__, line)( async_hr == E_ILLEGAL_METHOD_CALL, "got error %#lx\n", async_hr ); + + IAsyncInfo_Release( async_info ); + + hr = IAsyncOperation_BluetoothAdapter_GetResults( async, result ); + switch (expect_status) + { + case Completed: + case Error: + todo_wine_if( FAILED(expect_hr)) + ok_(__FILE__, line)( hr == expect_hr, "GetResults returned %#lx\n", hr ); + break; + case Canceled: + case Started: + default: + ok_(__FILE__, line)( hr == E_ILLEGAL_METHOD_CALL, "GetResults returned %#lx\n", hr ); + break; + } +} + static void test_BluetoothAdapterStatics(void) { static const WCHAR *default_res = L"System.Devices.InterfaceClassGuid:="{92383B0E-F90E-4AC9-8D44-8C2D0D0EBDA2}" " L"AND System.Devices.InterfaceEnabled:=System.StructuredQueryType.Boolean#True"; static const WCHAR *bluetoothadapter_statics_name = L"Windows.Devices.Bluetooth.BluetoothAdapter"; + IAsyncOperation_BluetoothAdapter *adapter_async = NULL; IBluetoothAdapterStatics *bluetoothadapter_statics; + IBluetoothAdapter *adapter = NULL; IActivationFactory *factory; HSTRING str, default_str; + boolean value = FALSE; + UINT64 address = 0; HRESULT hr; INT32 res; - LONG ref; - - hr = WindowsCreateString( bluetoothadapter_statics_name, wcslen( bluetoothadapter_statics_name ), &str ); - ok( hr == S_OK, "got hr %#lx.\n", hr );
+ WindowsCreateString( bluetoothadapter_statics_name, wcslen( bluetoothadapter_statics_name ), &str ); hr = RoGetActivationFactory( str, &IID_IActivationFactory, (void **)&factory ); WindowsDeleteString( str ); ok( hr == S_OK || broken( hr == REGDB_E_CLASSNOTREG ), "got hr %#lx.\n", hr ); @@ -244,10 +317,52 @@ static void test_BluetoothAdapterStatics(void)
WindowsDeleteString( str ); WindowsDeleteString( default_str ); - ref = IBluetoothAdapterStatics_Release( bluetoothadapter_statics ); - ok( ref == 2, "got ref %ld.\n", ref ); - ref = IActivationFactory_Release( factory ); - ok( ref == 1, "got ref %ld.\n", ref ); + + hr = IBluetoothAdapterStatics_GetDefaultAsync( bluetoothadapter_statics, &adapter_async ); + todo_wine ok( hr == S_OK, "got hr %#lx.\n", hr ); + if (FAILED( hr )) + { + skip( "GetDefaultAsync failed.\n" ); + goto done; + } + + await_bluetoothadapter( __LINE__, adapter_async ); + check_bluetoothadapter_async( __LINE__, adapter_async, 1, Completed, S_OK, &adapter ); + IAsyncOperation_BluetoothAdapter_Release( adapter_async ); + if (!adapter) + { + skip( "No Bluetooth adapter found.\n" ); + goto done; + } + + str = NULL; + hr = IBluetoothAdapter_get_DeviceId( adapter, &str ); + todo_wine ok( hr == S_OK, "got hr %#lx.\n", hr ); + todo_wine ok( !WindowsIsStringEmpty( str ), "got str %s.\n", debugstr_hstring( str ) ); + WindowsDeleteString( str ); + + hr = IBluetoothAdapter_get_BluetoothAddress( adapter, &address ); + todo_wine ok( hr == S_OK, "got hr %#lx.\n", hr ); + + hr = IBluetoothAdapter_get_IsLowEnergySupported( adapter, &value ); + todo_wine ok( hr == S_OK, "got hr %#lx.\n", hr ); + + hr = IBluetoothAdapter_get_IsClassicSupported( adapter, &value ); + todo_wine ok( hr == S_OK, "got hr %#lx.\n", hr ); + + hr = IBluetoothAdapter_get_IsPeripheralRoleSupported( adapter, &value ); + todo_wine ok( hr == S_OK, "got hr %#lx.\n", hr ); + + hr = IBluetoothAdapter_get_IsCentralRoleSupported( adapter, &value ); + todo_wine ok( hr == S_OK, "got hr %#lx.\n", hr ); + + hr = IBluetoothAdapter_get_IsAdvertisementOffloadSupported( adapter, &value ); + todo_wine ok( hr == S_OK, "got hr %#lx.\n", hr ); + + IBluetoothAdapter_Release( adapter ); +done: + IBluetoothAdapterStatics_Release( bluetoothadapter_statics ); + IActivationFactory_Release( factory ); }
static void test_BluetoothDeviceStatics( void )