Commit 9092f83f authored by Jan Wilken Doerrie's avatar Jan Wilken Doerrie Committed by Commit Bot

[Bluetooth][WinRT] Implement BluetoothDevice::IsPaired()

This change implements BluetoothDevice::IsPaired() by querying the
underlying device information. Furthermore, a test is added, which is
currently only enabled for Windows.

Bug: 821766
Change-Id: Idaed73fe544f115c1a0fc2157f477b009f4c26a6
Reviewed-on: https://chromium-review.googlesource.com/1172971Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Reviewed-by: default avatarGiovanni Ortuño Urquidi <ortuno@chromium.org>
Commit-Queue: Jan Wilken Dörrie <jdoerrie@chromium.org>
Cr-Commit-Position: refs/heads/master@{#582853}
parent 1c4e3fce
...@@ -298,6 +298,8 @@ test("device_unittests") { ...@@ -298,6 +298,8 @@ test("device_unittests") {
"bluetooth/test/fake_bluetooth_le_device_winrt.h", "bluetooth/test/fake_bluetooth_le_device_winrt.h",
"bluetooth/test/fake_bluetooth_le_manufacturer_data_winrt.cc", "bluetooth/test/fake_bluetooth_le_manufacturer_data_winrt.cc",
"bluetooth/test/fake_bluetooth_le_manufacturer_data_winrt.h", "bluetooth/test/fake_bluetooth_le_manufacturer_data_winrt.h",
"bluetooth/test/fake_device_information_pairing_winrt.cc",
"bluetooth/test/fake_device_information_pairing_winrt.h",
"bluetooth/test/fake_device_information_winrt.cc", "bluetooth/test/fake_device_information_winrt.cc",
"bluetooth/test/fake_device_information_winrt.h", "bluetooth/test/fake_device_information_winrt.h",
"bluetooth/test/fake_gatt_characteristic_winrt.cc", "bluetooth/test/fake_gatt_characteristic_winrt.cc",
......
...@@ -94,6 +94,32 @@ TEST(BluetoothDeviceTest, CanonicalizeAddressFormat_RejectsInvalidFormats) { ...@@ -94,6 +94,32 @@ TEST(BluetoothDeviceTest, CanonicalizeAddressFormat_RejectsInvalidFormats) {
} }
} }
#if defined(OS_WIN)
TEST_P(BluetoothTestWinrtOnly, DeviceIsPaired) {
if (!PlatformSupportsLowEnergy()) {
LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
return;
}
InitWithFakeAdapter();
StartLowEnergyDiscoverySession();
BluetoothDevice* device = SimulateLowEnergyDevice(1);
// By default a device should not be paired.
EXPECT_FALSE(device->IsPaired());
// Connect to the device and simulate a paired state.
device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED),
GetConnectErrorCallback(Call::NOT_EXPECTED));
SimulateGattConnection(device);
base::RunLoop().RunUntilIdle();
SimulateDevicePaired(device, true);
EXPECT_TRUE(device->IsPaired());
SimulateDevicePaired(device, false);
EXPECT_FALSE(device->IsPaired());
}
#endif
// Verifies basic device properties, e.g. GetAddress, GetName, ... // Verifies basic device properties, e.g. GetAddress, GetName, ...
#if defined(OS_WIN) #if defined(OS_WIN)
TEST_P(BluetoothTestWinrt, LowEnergyDeviceProperties) { TEST_P(BluetoothTestWinrt, LowEnergyDeviceProperties) {
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "device/bluetooth/bluetooth_device_winrt.h" #include "device/bluetooth/bluetooth_device_winrt.h"
#include <windows.devices.enumeration.h>
#include <windows.foundation.h> #include <windows.foundation.h>
#include <utility> #include <utility>
...@@ -35,8 +36,12 @@ using ABI::Windows::Devices::Bluetooth::GenericAttributeProfile:: ...@@ -35,8 +36,12 @@ using ABI::Windows::Devices::Bluetooth::GenericAttributeProfile::
using ABI::Windows::Devices::Bluetooth::GenericAttributeProfile:: using ABI::Windows::Devices::Bluetooth::GenericAttributeProfile::
IGattDeviceServicesResult; IGattDeviceServicesResult;
using ABI::Windows::Devices::Bluetooth::IBluetoothLEDevice; using ABI::Windows::Devices::Bluetooth::IBluetoothLEDevice;
using ABI::Windows::Devices::Bluetooth::IBluetoothLEDevice2;
using ABI::Windows::Devices::Bluetooth::IBluetoothLEDevice3; using ABI::Windows::Devices::Bluetooth::IBluetoothLEDevice3;
using ABI::Windows::Devices::Bluetooth::IBluetoothLEDeviceStatics; using ABI::Windows::Devices::Bluetooth::IBluetoothLEDeviceStatics;
using ABI::Windows::Devices::Enumeration::IDeviceInformation;
using ABI::Windows::Devices::Enumeration::IDeviceInformation2;
using ABI::Windows::Devices::Enumeration::IDeviceInformationPairing;
using ABI::Windows::Foundation::IAsyncOperation; using ABI::Windows::Foundation::IAsyncOperation;
using ABI::Windows::Foundation::IClosable; using ABI::Windows::Foundation::IClosable;
using Microsoft::WRL::ComPtr; using Microsoft::WRL::ComPtr;
...@@ -147,8 +152,54 @@ base::Optional<std::string> BluetoothDeviceWinrt::GetName() const { ...@@ -147,8 +152,54 @@ base::Optional<std::string> BluetoothDeviceWinrt::GetName() const {
} }
bool BluetoothDeviceWinrt::IsPaired() const { bool BluetoothDeviceWinrt::IsPaired() const {
NOTIMPLEMENTED(); if (!ble_device_) {
return false; VLOG(2) << "No BLE device instance present.";
return false;
}
ComPtr<IBluetoothLEDevice2> ble_device_2;
HRESULT hr = ble_device_.As(&ble_device_2);
if (FAILED(hr)) {
VLOG(2) << "Obtaining IBluetoothLEDevice2 failed: "
<< logging::SystemErrorCodeToString(hr);
return false;
}
ComPtr<IDeviceInformation> device_information;
hr = ble_device_2->get_DeviceInformation(&device_information);
if (FAILED(hr)) {
VLOG(2) << "Getting Device Information failed: "
<< logging::SystemErrorCodeToString(hr);
return false;
}
ComPtr<IDeviceInformation2> device_information_2;
hr = device_information.As(&device_information_2);
if (FAILED(hr)) {
VLOG(2) << "Obtaining IDeviceInformation2 failed: "
<< logging::SystemErrorCodeToString(hr);
return false;
}
ComPtr<IDeviceInformationPairing> pairing;
hr = device_information_2->get_Pairing(&pairing);
if (FAILED(hr)) {
VLOG(2) << "DeviceInformation::get_Pairing() failed: "
<< logging::SystemErrorCodeToString(hr);
return false;
}
boolean is_paired;
hr = pairing->get_IsPaired(&is_paired);
if (FAILED(hr)) {
VLOG(2) << "DeviceInformationPairing::get_IsPaired() failed: "
<< logging::SystemErrorCodeToString(hr);
return false;
}
VLOG(2) << "BluetoothDeviceWinrt::IsPaired(): "
<< (is_paired ? "True" : "False");
return is_paired;
} }
bool BluetoothDeviceWinrt::IsConnected() const { bool BluetoothDeviceWinrt::IsConnected() const {
......
...@@ -248,6 +248,9 @@ class BluetoothTestBase : public testing::Test { ...@@ -248,6 +248,9 @@ class BluetoothTestBase : public testing::Test {
// name kTestDeviceName, no advertised UUIDs and address kTestDeviceAddress3. // name kTestDeviceName, no advertised UUIDs and address kTestDeviceAddress3.
virtual BluetoothDevice* SimulateClassicDevice(); virtual BluetoothDevice* SimulateClassicDevice();
// Simulates a change in |device|'s pairing state.
virtual void SimulateDevicePaired(BluetoothDevice* device, bool is_paired) {}
// Remembers |device|'s platform specific object to be used in a // Remembers |device|'s platform specific object to be used in a
// subsequent call to methods such as SimulateGattServicesDiscovered that // subsequent call to methods such as SimulateGattServicesDiscovered that
// accept a nullptr value to select this remembered characteristic. This // accept a nullptr value to select this remembered characteristic. This
......
...@@ -674,6 +674,14 @@ BluetoothDevice* BluetoothTestWinrt::SimulateLowEnergyDevice( ...@@ -674,6 +674,14 @@ BluetoothDevice* BluetoothTestWinrt::SimulateLowEnergyDevice(
return adapter_->GetDevice(data.address); return adapter_->GetDevice(data.address);
} }
void BluetoothTestWinrt::SimulateDevicePaired(BluetoothDevice* device,
bool is_paired) {
auto* const ble_device =
static_cast<TestBluetoothDeviceWinrt*>(device)->ble_device();
DCHECK(ble_device);
ble_device->SimulateDevicePaired(is_paired);
}
void BluetoothTestWinrt::SimulateGattConnection(BluetoothDevice* device) { void BluetoothTestWinrt::SimulateGattConnection(BluetoothDevice* device) {
if (!GetParam() || !PlatformSupportsLowEnergy()) if (!GetParam() || !PlatformSupportsLowEnergy())
return BluetoothTestWin::SimulateGattConnection(device); return BluetoothTestWin::SimulateGattConnection(device);
......
...@@ -122,6 +122,7 @@ class BluetoothTestWinrt : public BluetoothTestWin, ...@@ -122,6 +122,7 @@ class BluetoothTestWinrt : public BluetoothTestWin,
void InitWithoutDefaultAdapter() override; void InitWithoutDefaultAdapter() override;
void InitWithFakeAdapter() override; void InitWithFakeAdapter() override;
BluetoothDevice* SimulateLowEnergyDevice(int device_ordinal) override; BluetoothDevice* SimulateLowEnergyDevice(int device_ordinal) override;
void SimulateDevicePaired(BluetoothDevice* device, bool is_paired) override;
void SimulateGattConnection(BluetoothDevice* device) override; void SimulateGattConnection(BluetoothDevice* device) override;
void SimulateGattConnectionError( void SimulateGattConnectionError(
BluetoothDevice* device, BluetoothDevice* device,
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "base/win/async_operation.h" #include "base/win/async_operation.h"
#include "device/bluetooth/bluetooth_remote_gatt_service_winrt.h" #include "device/bluetooth/bluetooth_remote_gatt_service_winrt.h"
#include "device/bluetooth/test/bluetooth_test_win.h" #include "device/bluetooth/test/bluetooth_test_win.h"
#include "device/bluetooth/test/fake_device_information_pairing_winrt.h"
#include "device/bluetooth/test/fake_gatt_characteristic_winrt.h" #include "device/bluetooth/test/fake_gatt_characteristic_winrt.h"
#include "device/bluetooth/test/fake_gatt_device_service_winrt.h" #include "device/bluetooth/test/fake_gatt_device_service_winrt.h"
#include "device/bluetooth/test/fake_gatt_device_services_result_winrt.h" #include "device/bluetooth/test/fake_gatt_device_services_result_winrt.h"
...@@ -23,6 +24,7 @@ namespace device { ...@@ -23,6 +24,7 @@ namespace device {
namespace { namespace {
using ABI::Windows::Devices::Bluetooth::BluetoothAddressType;
using ABI::Windows::Devices::Bluetooth::BluetoothCacheMode; using ABI::Windows::Devices::Bluetooth::BluetoothCacheMode;
using ABI::Windows::Devices::Bluetooth::BluetoothConnectionStatus; using ABI::Windows::Devices::Bluetooth::BluetoothConnectionStatus;
using ABI::Windows::Devices::Bluetooth::BluetoothConnectionStatus_Connected; using ABI::Windows::Devices::Bluetooth::BluetoothConnectionStatus_Connected;
...@@ -44,8 +46,10 @@ using ABI::Windows::Devices::Bluetooth::GenericAttributeProfile:: ...@@ -44,8 +46,10 @@ using ABI::Windows::Devices::Bluetooth::GenericAttributeProfile::
GattDeviceServicesResult; GattDeviceServicesResult;
using ABI::Windows::Devices::Bluetooth::GenericAttributeProfile:: using ABI::Windows::Devices::Bluetooth::GenericAttributeProfile::
IGattDeviceService; IGattDeviceService;
using ABI::Windows::Devices::Bluetooth::IBluetoothLEAppearance;
using ABI::Windows::Devices::Enumeration::DeviceAccessStatus; using ABI::Windows::Devices::Enumeration::DeviceAccessStatus;
using ABI::Windows::Devices::Enumeration::IDeviceAccessInformation; using ABI::Windows::Devices::Enumeration::IDeviceAccessInformation;
using ABI::Windows::Devices::Enumeration::IDeviceInformation;
using ABI::Windows::Foundation::Collections::IVectorView; using ABI::Windows::Foundation::Collections::IVectorView;
using ABI::Windows::Foundation::IAsyncOperation; using ABI::Windows::Foundation::IAsyncOperation;
using ABI::Windows::Foundation::ITypedEventHandler; using ABI::Windows::Foundation::ITypedEventHandler;
...@@ -125,6 +129,21 @@ HRESULT FakeBluetoothLEDeviceWinrt::remove_ConnectionStatusChanged( ...@@ -125,6 +129,21 @@ HRESULT FakeBluetoothLEDeviceWinrt::remove_ConnectionStatusChanged(
return S_OK; return S_OK;
} }
HRESULT FakeBluetoothLEDeviceWinrt::get_DeviceInformation(
IDeviceInformation** value) {
return device_information_.CopyTo(value);
}
HRESULT FakeBluetoothLEDeviceWinrt::get_Appearance(
IBluetoothLEAppearance** value) {
return E_NOTIMPL;
}
HRESULT FakeBluetoothLEDeviceWinrt::get_BluetoothAddressType(
BluetoothAddressType* value) {
return E_NOTIMPL;
}
HRESULT FakeBluetoothLEDeviceWinrt::get_DeviceAccessInformation( HRESULT FakeBluetoothLEDeviceWinrt::get_DeviceAccessInformation(
IDeviceAccessInformation** value) { IDeviceAccessInformation** value) {
return E_NOTIMPL; return E_NOTIMPL;
...@@ -168,6 +187,11 @@ HRESULT FakeBluetoothLEDeviceWinrt::Close() { ...@@ -168,6 +187,11 @@ HRESULT FakeBluetoothLEDeviceWinrt::Close() {
return S_OK; return S_OK;
} }
void FakeBluetoothLEDeviceWinrt::SimulateDevicePaired(bool is_paired) {
device_information_ = Make<FakeDeviceInformationWinrt>(
Make<FakeDeviceInformationPairingWinrt>(is_paired));
}
void FakeBluetoothLEDeviceWinrt::SimulateGattConnection() { void FakeBluetoothLEDeviceWinrt::SimulateGattConnection() {
status_ = BluetoothConnectionStatus_Connected; status_ = BluetoothConnectionStatus_Connected;
connection_status_changed_handler_->Invoke(this, nullptr); connection_status_changed_handler_->Invoke(this, nullptr);
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <windows.devices.bluetooth.h> #include <windows.devices.bluetooth.h>
#include <windows.foundation.h> #include <windows.foundation.h>
#include <wrl/client.h>
#include <wrl/implements.h> #include <wrl/implements.h>
#include <stdint.h> #include <stdint.h>
...@@ -17,6 +18,7 @@ ...@@ -17,6 +18,7 @@
#include "base/callback.h" #include "base/callback.h"
#include "base/macros.h" #include "base/macros.h"
#include "device/bluetooth/bluetooth_device.h" #include "device/bluetooth/bluetooth_device.h"
#include "device/bluetooth/test/fake_device_information_winrt.h"
namespace device { namespace device {
...@@ -28,6 +30,7 @@ class FakeBluetoothLEDeviceWinrt ...@@ -28,6 +30,7 @@ class FakeBluetoothLEDeviceWinrt
Microsoft::WRL::RuntimeClassFlags< Microsoft::WRL::RuntimeClassFlags<
Microsoft::WRL::WinRt | Microsoft::WRL::InhibitRoOriginateError>, Microsoft::WRL::WinRt | Microsoft::WRL::InhibitRoOriginateError>,
ABI::Windows::Devices::Bluetooth::IBluetoothLEDevice, ABI::Windows::Devices::Bluetooth::IBluetoothLEDevice,
ABI::Windows::Devices::Bluetooth::IBluetoothLEDevice2,
ABI::Windows::Devices::Bluetooth::IBluetoothLEDevice3, ABI::Windows::Devices::Bluetooth::IBluetoothLEDevice3,
ABI::Windows::Foundation::IClosable> { ABI::Windows::Foundation::IClosable> {
public: public:
...@@ -70,6 +73,15 @@ class FakeBluetoothLEDeviceWinrt ...@@ -70,6 +73,15 @@ class FakeBluetoothLEDeviceWinrt
IFACEMETHODIMP remove_ConnectionStatusChanged( IFACEMETHODIMP remove_ConnectionStatusChanged(
EventRegistrationToken token) override; EventRegistrationToken token) override;
// IBluetoothLEDevice2:
IFACEMETHODIMP get_DeviceInformation(
ABI::Windows::Devices::Enumeration::IDeviceInformation** value) override;
IFACEMETHODIMP get_Appearance(
ABI::Windows::Devices::Bluetooth::IBluetoothLEAppearance** value)
override;
IFACEMETHODIMP get_BluetoothAddressType(
ABI::Windows::Devices::Bluetooth::BluetoothAddressType* value) override;
// IBluetoothLEDevice3: // IBluetoothLEDevice3:
IFACEMETHODIMP get_DeviceAccessInformation( IFACEMETHODIMP get_DeviceAccessInformation(
ABI::Windows::Devices::Enumeration::IDeviceAccessInformation** value) ABI::Windows::Devices::Enumeration::IDeviceAccessInformation** value)
...@@ -102,6 +114,7 @@ class FakeBluetoothLEDeviceWinrt ...@@ -102,6 +114,7 @@ class FakeBluetoothLEDeviceWinrt
// IClosable: // IClosable:
IFACEMETHODIMP Close() override; IFACEMETHODIMP Close() override;
void SimulateDevicePaired(bool is_paired);
void SimulateGattConnection(); void SimulateGattConnection();
void SimulateGattConnectionError( void SimulateGattConnectionError(
BluetoothDevice::ConnectErrorCode error_code); BluetoothDevice::ConnectErrorCode error_code);
...@@ -127,6 +140,9 @@ class FakeBluetoothLEDeviceWinrt ...@@ -127,6 +140,9 @@ class FakeBluetoothLEDeviceWinrt
IInspectable*>> IInspectable*>>
connection_status_changed_handler_; connection_status_changed_handler_;
Microsoft::WRL::ComPtr<ABI::Windows::Devices::Enumeration::IDeviceInformation>
device_information_ = Microsoft::WRL::Make<FakeDeviceInformationWinrt>();
Microsoft::WRL::ComPtr<ABI::Windows::Foundation::ITypedEventHandler< Microsoft::WRL::ComPtr<ABI::Windows::Foundation::ITypedEventHandler<
ABI::Windows::Devices::Bluetooth::BluetoothLEDevice*, ABI::Windows::Devices::Bluetooth::BluetoothLEDevice*,
IInspectable*>> IInspectable*>>
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "device/bluetooth/test/fake_device_information_pairing_winrt.h"
namespace device {
namespace {
using ABI::Windows::Devices::Enumeration::DevicePairingProtectionLevel;
using ABI::Windows::Devices::Enumeration::DevicePairingResult;
using ABI::Windows::Foundation::IAsyncOperation;
} // namespace
FakeDeviceInformationPairingWinrt::FakeDeviceInformationPairingWinrt(
bool is_paired)
: is_paired_(is_paired) {}
FakeDeviceInformationPairingWinrt::~FakeDeviceInformationPairingWinrt() =
default;
HRESULT FakeDeviceInformationPairingWinrt::get_IsPaired(boolean* value) {
*value = is_paired_;
return S_OK;
}
HRESULT FakeDeviceInformationPairingWinrt::get_CanPair(boolean* value) {
return E_NOTIMPL;
}
HRESULT FakeDeviceInformationPairingWinrt::PairAsync(
IAsyncOperation<DevicePairingResult*>** result) {
return E_NOTIMPL;
}
HRESULT FakeDeviceInformationPairingWinrt::PairWithProtectionLevelAsync(
DevicePairingProtectionLevel min_protection_level,
IAsyncOperation<DevicePairingResult*>** result) {
return E_NOTIMPL;
}
} // namespace device
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef DEVICE_BLUETOOTH_TEST_FAKE_DEVICE_INFORMATION_PAIRING_WINRT_H_
#define DEVICE_BLUETOOTH_TEST_FAKE_DEVICE_INFORMATION_PAIRING_WINRT_H_
#include <windows.devices.enumeration.h>
#include <wrl/client.h>
#include <wrl/implements.h>
#include "base/macros.h"
namespace device {
class FakeDeviceInformationPairingWinrt
: public Microsoft::WRL::RuntimeClass<
Microsoft::WRL::RuntimeClassFlags<
Microsoft::WRL::WinRt | Microsoft::WRL::InhibitRoOriginateError>,
ABI::Windows::Devices::Enumeration::IDeviceInformationPairing> {
public:
explicit FakeDeviceInformationPairingWinrt(bool is_paired);
~FakeDeviceInformationPairingWinrt() override;
// IDeviceInformationPairing:
IFACEMETHODIMP get_IsPaired(boolean* value) override;
IFACEMETHODIMP get_CanPair(boolean* value) override;
IFACEMETHODIMP PairAsync(
ABI::Windows::Foundation::IAsyncOperation<
ABI::Windows::Devices::Enumeration::DevicePairingResult*>** result)
override;
IFACEMETHODIMP PairWithProtectionLevelAsync(
ABI::Windows::Devices::Enumeration::DevicePairingProtectionLevel
min_protection_level,
ABI::Windows::Foundation::IAsyncOperation<
ABI::Windows::Devices::Enumeration::DevicePairingResult*>** result)
override;
private:
bool is_paired_ = false;
DISALLOW_COPY_AND_ASSIGN(FakeDeviceInformationPairingWinrt);
};
} // namespace device
#endif // DEVICE_BLUETOOTH_TEST_FAKE_DEVICE_INFORMATION_PAIRING_WINRT_H_
...@@ -20,8 +20,10 @@ namespace { ...@@ -20,8 +20,10 @@ namespace {
using ABI::Windows::Devices::Enumeration::DeviceClass; using ABI::Windows::Devices::Enumeration::DeviceClass;
using ABI::Windows::Devices::Enumeration::DeviceInformation; using ABI::Windows::Devices::Enumeration::DeviceInformation;
using ABI::Windows::Devices::Enumeration::DeviceInformationCollection; using ABI::Windows::Devices::Enumeration::DeviceInformationCollection;
using ABI::Windows::Devices::Enumeration::DeviceInformationKind;
using ABI::Windows::Devices::Enumeration::DeviceThumbnail; using ABI::Windows::Devices::Enumeration::DeviceThumbnail;
using ABI::Windows::Devices::Enumeration::IDeviceInformation; using ABI::Windows::Devices::Enumeration::IDeviceInformation;
using ABI::Windows::Devices::Enumeration::IDeviceInformationPairing;
using ABI::Windows::Devices::Enumeration::IDeviceInformationUpdate; using ABI::Windows::Devices::Enumeration::IDeviceInformationUpdate;
using ABI::Windows::Devices::Enumeration::IDeviceWatcher; using ABI::Windows::Devices::Enumeration::IDeviceWatcher;
using ABI::Windows::Devices::Enumeration::IEnclosureLocation; using ABI::Windows::Devices::Enumeration::IEnclosureLocation;
...@@ -33,9 +35,18 @@ using Microsoft::WRL::Make; ...@@ -33,9 +35,18 @@ using Microsoft::WRL::Make;
} // namespace } // namespace
FakeDeviceInformationWinrt::FakeDeviceInformationWinrt() = default;
FakeDeviceInformationWinrt::FakeDeviceInformationWinrt(const char* name)
: name_(name) {}
FakeDeviceInformationWinrt::FakeDeviceInformationWinrt(std::string name) FakeDeviceInformationWinrt::FakeDeviceInformationWinrt(std::string name)
: name_(std::move(name)) {} : name_(std::move(name)) {}
FakeDeviceInformationWinrt::FakeDeviceInformationWinrt(
ComPtr<IDeviceInformationPairing> pairing)
: pairing_(std::move(pairing)) {}
FakeDeviceInformationWinrt::~FakeDeviceInformationWinrt() = default; FakeDeviceInformationWinrt::~FakeDeviceInformationWinrt() = default;
HRESULT FakeDeviceInformationWinrt::get_Id(HSTRING* value) { HRESULT FakeDeviceInformationWinrt::get_Id(HSTRING* value) {
...@@ -80,6 +91,15 @@ HRESULT FakeDeviceInformationWinrt::GetGlyphThumbnailAsync( ...@@ -80,6 +91,15 @@ HRESULT FakeDeviceInformationWinrt::GetGlyphThumbnailAsync(
return E_NOTIMPL; return E_NOTIMPL;
} }
HRESULT FakeDeviceInformationWinrt::get_Kind(DeviceInformationKind* value) {
return E_NOTIMPL;
}
HRESULT FakeDeviceInformationWinrt::get_Pairing(
IDeviceInformationPairing** value) {
return pairing_.CopyTo(value);
}
FakeDeviceInformationStaticsWinrt::FakeDeviceInformationStaticsWinrt( FakeDeviceInformationStaticsWinrt::FakeDeviceInformationStaticsWinrt(
ComPtr<IDeviceInformation> device_information) ComPtr<IDeviceInformation> device_information)
: device_information_(std::move(device_information)) {} : device_information_(std::move(device_information)) {}
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include <string> #include <string>
#include "base/macros.h" #include "base/macros.h"
#include "device/bluetooth/test/fake_device_information_pairing_winrt.h"
namespace device { namespace device {
...@@ -19,9 +20,18 @@ class FakeDeviceInformationWinrt ...@@ -19,9 +20,18 @@ class FakeDeviceInformationWinrt
: public Microsoft::WRL::RuntimeClass< : public Microsoft::WRL::RuntimeClass<
Microsoft::WRL::RuntimeClassFlags< Microsoft::WRL::RuntimeClassFlags<
Microsoft::WRL::WinRt | Microsoft::WRL::InhibitRoOriginateError>, Microsoft::WRL::WinRt | Microsoft::WRL::InhibitRoOriginateError>,
ABI::Windows::Devices::Enumeration::IDeviceInformation> { ABI::Windows::Devices::Enumeration::IDeviceInformation,
ABI::Windows::Devices::Enumeration::IDeviceInformation2> {
public: public:
FakeDeviceInformationWinrt();
// Explicit const char* constructor is required to break ambiguity for C
// string arguments.
explicit FakeDeviceInformationWinrt(const char* name);
explicit FakeDeviceInformationWinrt(std::string name); explicit FakeDeviceInformationWinrt(std::string name);
explicit FakeDeviceInformationWinrt(
Microsoft::WRL::ComPtr<
ABI::Windows::Devices::Enumeration::IDeviceInformationPairing>
pairing);
~FakeDeviceInformationWinrt() override; ~FakeDeviceInformationWinrt() override;
// IDeviceInformation: // IDeviceInformation:
...@@ -46,8 +56,19 @@ class FakeDeviceInformationWinrt ...@@ -46,8 +56,19 @@ class FakeDeviceInformationWinrt
ABI::Windows::Devices::Enumeration::DeviceThumbnail*>** async_op) ABI::Windows::Devices::Enumeration::DeviceThumbnail*>** async_op)
override; override;
// IDeviceInformation2:
IFACEMETHODIMP get_Kind(
ABI::Windows::Devices::Enumeration::DeviceInformationKind* value)
override;
IFACEMETHODIMP get_Pairing(
ABI::Windows::Devices::Enumeration::IDeviceInformationPairing** value)
override;
private: private:
std::string name_; std::string name_;
Microsoft::WRL::ComPtr<
ABI::Windows::Devices::Enumeration::IDeviceInformationPairing>
pairing_ = Microsoft::WRL::Make<FakeDeviceInformationPairingWinrt>(false);
DISALLOW_COPY_AND_ASSIGN(FakeDeviceInformationWinrt); DISALLOW_COPY_AND_ASSIGN(FakeDeviceInformationWinrt);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment