| Index: device/bluetooth/bluetooth_gatt_service_unittest.cc
|
| diff --git a/device/bluetooth/bluetooth_gatt_service_unittest.cc b/device/bluetooth/bluetooth_gatt_service_unittest.cc
|
| index ed01bf8b5647bd14638f3748a4f7371191f2fe42..3413cbc7ef1f2e12da1907f93dea373401f287f2 100644
|
| --- a/device/bluetooth/bluetooth_gatt_service_unittest.cc
|
| +++ b/device/bluetooth/bluetooth_gatt_service_unittest.cc
|
| @@ -12,16 +12,22 @@
|
| #include "device/bluetooth/test/bluetooth_test_android.h"
|
| #elif defined(OS_MACOSX)
|
| #include "device/bluetooth/test/bluetooth_test_mac.h"
|
| +#elif defined(OS_WIN)
|
| +#include "device/bluetooth/test/bluetooth_test_win.h"
|
| #endif
|
|
|
| namespace device {
|
|
|
| -#if defined(OS_ANDROID) || defined(OS_MACOSX)
|
| +#if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
|
| class BluetoothGattServiceTest : public BluetoothTest {};
|
| #endif
|
|
|
| -#if defined(OS_ANDROID)
|
| +#if defined(OS_ANDROID) || defined(OS_WIN)
|
| TEST_F(BluetoothGattServiceTest, GetIdentifier) {
|
| + if (!PlatformSupportsLowEnergy()) {
|
| + LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
|
| + return;
|
| + }
|
| InitWithFakeAdapter();
|
| StartLowEnergyDiscoverySession();
|
| // 2 devices to verify unique IDs across them.
|
| @@ -56,10 +62,14 @@ TEST_F(BluetoothGattServiceTest, GetIdentifier) {
|
|
|
| EXPECT_NE(service3->GetIdentifier(), service4->GetIdentifier());
|
| }
|
| -#endif // defined(OS_ANDROID)
|
| +#endif // defined(OS_ANDROID) || defined(OS_WIN)
|
|
|
| -#if defined(OS_ANDROID)
|
| +#if defined(OS_ANDROID) || defined(OS_WIN)
|
| TEST_F(BluetoothGattServiceTest, GetUUID) {
|
| + if (!PlatformSupportsLowEnergy()) {
|
| + LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
|
| + return;
|
| + }
|
| InitWithFakeAdapter();
|
| StartLowEnergyDiscoverySession();
|
| BluetoothDevice* device = DiscoverLowEnergyDevice(3);
|
| @@ -78,10 +88,14 @@ TEST_F(BluetoothGattServiceTest, GetUUID) {
|
| EXPECT_EQ(uuid, device->GetGattServices()[0]->GetUUID());
|
| EXPECT_EQ(uuid, device->GetGattServices()[1]->GetUUID());
|
| }
|
| -#endif // defined(OS_ANDROID)
|
| +#endif // defined(OS_ANDROID) || defined(OS_WIN)
|
|
|
| -#if defined(OS_ANDROID)
|
| +#if defined(OS_ANDROID) || defined(OS_WIN)
|
| TEST_F(BluetoothGattServiceTest, GetCharacteristics_FindNone) {
|
| + if (!PlatformSupportsLowEnergy()) {
|
| + LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
|
| + return;
|
| + }
|
| InitWithFakeAdapter();
|
| StartLowEnergyDiscoverySession();
|
| BluetoothDevice* device = DiscoverLowEnergyDevice(3);
|
| @@ -97,10 +111,14 @@ TEST_F(BluetoothGattServiceTest, GetCharacteristics_FindNone) {
|
|
|
| EXPECT_EQ(0u, service->GetCharacteristics().size());
|
| }
|
| -#endif // defined(OS_ANDROID)
|
| +#endif // defined(OS_ANDROID) || defined(OS_WIN)
|
|
|
| -#if defined(OS_ANDROID)
|
| +#if defined(OS_ANDROID) || defined(OS_WIN)
|
| TEST_F(BluetoothGattServiceTest, GetCharacteristics_and_GetCharacteristic) {
|
| + if (!PlatformSupportsLowEnergy()) {
|
| + LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
|
| + return;
|
| + }
|
| InitWithFakeAdapter();
|
| StartLowEnergyDiscoverySession();
|
| BluetoothDevice* device = DiscoverLowEnergyDevice(3);
|
| @@ -145,6 +163,150 @@ TEST_F(BluetoothGattServiceTest, GetCharacteristics_and_GetCharacteristic) {
|
| EXPECT_EQ(service->GetCharacteristic(char_id1),
|
| service->GetCharacteristic(char_id1));
|
| }
|
| -#endif // defined(OS_ANDROID)
|
| +#endif // defined(OS_ANDROID) || defined(OS_WIN)
|
| +
|
| +#if defined(OS_WIN)
|
| +TEST_F(BluetoothGattServiceTest, GetCharacteristic_CharacteristicRemoved) {
|
| + if (!PlatformSupportsLowEnergy()) {
|
| + LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
|
| + return;
|
| + }
|
| + InitWithFakeAdapter();
|
| + StartLowEnergyDiscoverySession();
|
| + BluetoothDevice* device = DiscoverLowEnergyDevice(3);
|
| + device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED),
|
| + GetConnectErrorCallback(Call::NOT_EXPECTED));
|
| + SimulateGattConnection(device);
|
| +
|
| + // Simulate a service, with several Characteristics:
|
| + std::vector<std::string> services;
|
| + services.push_back("00000000-0000-1000-8000-00805f9b34fb");
|
| + SimulateGattServicesDiscovered(device, services);
|
| + BluetoothGattService* service = device->GetGattServices()[0];
|
| + std::string characteristic_uuid1 = "11111111-0000-1000-8000-00805f9b34fb";
|
| + std::string characteristic_uuid2 = "22222222-0000-1000-8000-00805f9b34fb";
|
| + std::string characteristic_uuid3 = characteristic_uuid2; // Duplicate UUID.
|
| + std::string characteristic_uuid4 = "33333333-0000-1000-8000-00805f9b34fb";
|
| + SimulateGattCharacteristic(service, characteristic_uuid1, /* properties */ 0);
|
| + SimulateGattCharacteristic(service, characteristic_uuid2, /* properties */ 0);
|
| + SimulateGattCharacteristic(service, characteristic_uuid3, /* properties */ 0);
|
| + SimulateGattCharacteristic(service, characteristic_uuid4, /* properties */ 0);
|
| +
|
| + // Simulate remove of characteristics one by one.
|
| + EXPECT_EQ(4u, service->GetCharacteristics().size());
|
| + std::string removed_char = service->GetCharacteristics()[0]->GetIdentifier();
|
| + SimulateGattCharacteristicRemove(service,
|
| + service->GetCharacteristic(removed_char));
|
| + EXPECT_FALSE(service->GetCharacteristic(removed_char));
|
| + EXPECT_EQ(3u, service->GetCharacteristics().size());
|
| + removed_char = service->GetCharacteristics()[0]->GetIdentifier();
|
| + SimulateGattCharacteristicRemove(service,
|
| + service->GetCharacteristic(removed_char));
|
| + EXPECT_FALSE(service->GetCharacteristic(removed_char));
|
| + EXPECT_EQ(2u, service->GetCharacteristics().size());
|
| + removed_char = service->GetCharacteristics()[0]->GetIdentifier();
|
| + SimulateGattCharacteristicRemove(service,
|
| + service->GetCharacteristic(removed_char));
|
| + EXPECT_FALSE(service->GetCharacteristic(removed_char));
|
| + EXPECT_EQ(1u, service->GetCharacteristics().size());
|
| + removed_char = service->GetCharacteristics()[0]->GetIdentifier();
|
| + SimulateGattCharacteristicRemove(service,
|
| + service->GetCharacteristic(removed_char));
|
| + EXPECT_FALSE(service->GetCharacteristic(removed_char));
|
| + EXPECT_EQ(0u, service->GetCharacteristics().size());
|
| +}
|
| +#endif // defined(OS_WIN)
|
| +
|
| +#if defined(OS_WIN)
|
| +TEST_F(BluetoothGattServiceTest, GetIncludedServices) {
|
| + if (!PlatformSupportsLowEnergy()) {
|
| + LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
|
| + return;
|
| + }
|
| + InitWithFakeAdapter();
|
| + StartLowEnergyDiscoverySession();
|
| + BluetoothDevice* device = DiscoverLowEnergyDevice(3);
|
| + device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED),
|
| + GetConnectErrorCallback(Call::NOT_EXPECTED));
|
| + SimulateGattConnection(device);
|
| +
|
| + // Simulate a service, with several included services:
|
| + std::vector<std::string> services;
|
| + services.push_back("00000000-0000-1000-8000-00805f9b34fb");
|
| + SimulateGattServicesDiscovered(device, services);
|
| + BluetoothGattService* service = device->GetGattServices()[0];
|
| + std::vector<std::string> included_service_uuids;
|
| + included_service_uuids.push_back("11111111-0000-1000-8000-00805f9b34fb");
|
| + included_service_uuids.push_back("22222222-0000-1000-8000-00805f9b34fb");
|
| + included_service_uuids.push_back(
|
| + "22222222-0000-1000-8000-00805f9b34fb"); // Duplicate UUID.
|
| + included_service_uuids.push_back("33333333-0000-1000-8000-00805f9b34fb");
|
| + SimulateIncludedGattServicesDiscovered(service, included_service_uuids);
|
| +
|
| + // Verify that GetIncludedServices can retrieve included services.
|
| + EXPECT_EQ(4u, service->GetIncludedServices().size());
|
| + std::vector<BluetoothGattService*> f_included_services =
|
| + service->GetIncludedServices();
|
| + for (auto i_s : f_included_services) {
|
| + EXPECT_FALSE(i_s->IsPrimary());
|
| + }
|
| + std::vector<std::string> f_included_service_uuids;
|
| + f_included_service_uuids.push_back(f_included_services[0]->GetUUID().value());
|
| + f_included_service_uuids.push_back(f_included_services[1]->GetUUID().value());
|
| + f_included_service_uuids.push_back(f_included_services[2]->GetUUID().value());
|
| + f_included_service_uuids.push_back(f_included_services[3]->GetUUID().value());
|
| + std::sort(f_included_service_uuids.begin(), f_included_service_uuids.end());
|
| + std::sort(included_service_uuids.begin(), included_service_uuids.end());
|
| + for (std::size_t i = 0; i < 4; i++) {
|
| + EXPECT_EQ(f_included_service_uuids[i], included_service_uuids[i]);
|
| + }
|
| +}
|
| +#endif // defined(OS_WIN)
|
| +
|
| +#if defined(OS_WIN)
|
| +TEST_F(BluetoothGattServiceTest, SimulateGattServiceRemove) {
|
| + if (!PlatformSupportsLowEnergy()) {
|
| + LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
|
| + return;
|
| + }
|
| + InitWithFakeAdapter();
|
| + StartLowEnergyDiscoverySession();
|
| + BluetoothDevice* device = DiscoverLowEnergyDevice(3);
|
| + device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED),
|
| + GetConnectErrorCallback(Call::NOT_EXPECTED));
|
| + SimulateGattConnection(device);
|
| +
|
| + // Simulate two primary GATT services, with several included services:
|
| + std::vector<std::string> services;
|
| + services.push_back("00000000-0000-1000-8000-00805f9b34fb");
|
| + services.push_back("01010101-0101-1000-8000-00805f9b34fb");
|
| + SimulateGattServicesDiscovered(device, services);
|
| + EXPECT_EQ(2u, device->GetGattServices().size());
|
| + BluetoothGattService* service1 = device->GetGattServices()[0];
|
| + BluetoothGattService* service2 = device->GetGattServices()[1];
|
| + std::vector<std::string> included_service_uuids;
|
| + included_service_uuids.push_back("11111111-0000-1000-8000-00805f9b34fb");
|
| + included_service_uuids.push_back("22222222-0000-1000-8000-00805f9b34fb");
|
| + included_service_uuids.push_back(
|
| + "22222222-0000-1000-8000-00805f9b34fb"); // Duplicate UUID.
|
| + included_service_uuids.push_back("33333333-0000-1000-8000-00805f9b34fb");
|
| + SimulateIncludedGattServicesDiscovered(service1, included_service_uuids);
|
| + SimulateIncludedGattServicesDiscovered(service2, included_service_uuids);
|
| + EXPECT_EQ(4u, service1->GetIncludedServices().size());
|
| + EXPECT_EQ(4u, service2->GetIncludedServices().size());
|
| +
|
| + // Simulate remove of an included service.
|
| + SimulateGattServiceRemoved(service1->GetIncludedServices()[0]);
|
| + EXPECT_EQ(3u, service1->GetIncludedServices().size());
|
| + SimulateGattServiceRemoved(service2->GetIncludedServices()[0]);
|
| + EXPECT_EQ(3u, service2->GetIncludedServices().size());
|
| +
|
| + // Simulate remove of a primary service.
|
| + std::string removed_service = service1->GetIdentifier();
|
| + SimulateGattServiceRemoved(device->GetGattService(removed_service));
|
| + EXPECT_EQ(1u, device->GetGattServices().size());
|
| + EXPECT_FALSE(device->GetGattService(removed_service));
|
| +}
|
| +#endif // defined(OS_WIN)
|
|
|
| } // namespace device
|
|
|