Commit 5806cecb authored by juncai's avatar juncai Committed by Commit bot

Use test UUIDs for device bluetooth unit tests

This is a follow-up CL for:
https://codereview.chromium.org/2785383002/diff/80001/device/bluetooth/bluetooth_remote_gatt_service_unittest.cc

This CL added some test characteristic and descriptor UUIDs to
bluetooth_test.h and updated device bluetooth unit tests to use them.

BUG=None

Review-Url: https://codereview.chromium.org/2798193002
Cr-Commit-Position: refs/heads/master@{#462946}
parent b726dba1
...@@ -1276,10 +1276,9 @@ TEST_F(BluetoothTest, BluetoothGattConnection_DisconnectGatt_Cleanup) { ...@@ -1276,10 +1276,9 @@ TEST_F(BluetoothTest, BluetoothGattConnection_DisconnectGatt_Cleanup) {
EXPECT_TRUE(device->IsConnected()); EXPECT_TRUE(device->IsConnected());
// Discover services // Discover services
std::vector<std::string> services; SimulateGattServicesDiscovered(
services.push_back("00000000-0000-1000-8000-00805f9b34fb"); device,
services.push_back("00000001-0000-1000-8000-00805f9b34fb"); std::vector<std::string>({kTestUUIDGenericAccess, kTestUUIDHeartRate}));
SimulateGattServicesDiscovered(device, services);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_TRUE(device->IsGattServicesDiscoveryComplete()); EXPECT_TRUE(device->IsGattServicesDiscoveryComplete());
EXPECT_EQ(2u, device->GetGattServices().size()); EXPECT_EQ(2u, device->GetGattServices().size());
...@@ -1301,9 +1300,8 @@ TEST_F(BluetoothTest, BluetoothGattConnection_DisconnectGatt_Cleanup) { ...@@ -1301,9 +1300,8 @@ TEST_F(BluetoothTest, BluetoothGattConnection_DisconnectGatt_Cleanup) {
EXPECT_TRUE(device->IsConnected()); EXPECT_TRUE(device->IsConnected());
// Verify that service discovery can be done again // Verify that service discovery can be done again
std::vector<std::string> services2; SimulateGattServicesDiscovered(
services2.push_back("00000002-0000-1000-8000-00805f9b34fb"); device, std::vector<std::string>({kTestUUIDGenericAttribute}));
SimulateGattServicesDiscovered(device, services2);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_TRUE(device->IsGattServicesDiscoveryComplete()); EXPECT_TRUE(device->IsGattServicesDiscoveryComplete());
EXPECT_EQ(1u, device->GetGattServices().size()); EXPECT_EQ(1u, device->GetGattServices().size());
...@@ -1361,10 +1359,9 @@ TEST_F(BluetoothTest, GattServices_ObserversCalls) { ...@@ -1361,10 +1359,9 @@ TEST_F(BluetoothTest, GattServices_ObserversCalls) {
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_EQ(1, gatt_discovery_attempts_); EXPECT_EQ(1, gatt_discovery_attempts_);
std::vector<std::string> services; SimulateGattServicesDiscovered(
services.push_back("00000000-0000-1000-8000-00805f9b34fb"); device,
services.push_back("00000001-0000-1000-8000-00805f9b34fb"); std::vector<std::string>({kTestUUIDGenericAccess, kTestUUIDHeartRate}));
SimulateGattServicesDiscovered(device, services);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_EQ(1, observer.gatt_services_discovered_count()); EXPECT_EQ(1, observer.gatt_services_discovered_count());
...@@ -1396,10 +1393,9 @@ TEST_F(BluetoothTest, GattServicesDiscovered_AfterDeleted) { ...@@ -1396,10 +1393,9 @@ TEST_F(BluetoothTest, GattServicesDiscovered_AfterDeleted) {
RememberDeviceForSubsequentAction(device); RememberDeviceForSubsequentAction(device);
DeleteDevice(device); DeleteDevice(device);
std::vector<std::string> services; SimulateGattServicesDiscovered(
services.push_back("00000000-0000-1000-8000-00805f9b34fb"); nullptr /* use remembered device */,
services.push_back("00000001-0000-1000-8000-00805f9b34fb"); std::vector<std::string>({kTestUUIDGenericAccess, kTestUUIDHeartRate}));
SimulateGattServicesDiscovered(nullptr /* use remembered device */, services);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
} }
#endif // defined(OS_ANDROID) #endif // defined(OS_ANDROID)
...@@ -1454,10 +1450,9 @@ TEST_F(BluetoothTest, GattServicesDiscovered_AfterDisconnection) { ...@@ -1454,10 +1450,9 @@ TEST_F(BluetoothTest, GattServicesDiscovered_AfterDisconnection) {
SimulateGattDisconnection(device); SimulateGattDisconnection(device);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
std::vector<std::string> services; SimulateGattServicesDiscovered(
services.push_back("00000000-0000-1000-8000-00805f9b34fb"); device,
services.push_back("00000001-0000-1000-8000-00805f9b34fb"); std::vector<std::string>({kTestUUIDGenericAccess, kTestUUIDHeartRate}));
SimulateGattServicesDiscovered(device, services);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_FALSE(device->IsGattServicesDiscoveryComplete()); EXPECT_FALSE(device->IsGattServicesDiscoveryComplete());
...@@ -1509,12 +1504,11 @@ TEST_F(BluetoothTest, GetGattServices_and_GetGattService) { ...@@ -1509,12 +1504,11 @@ TEST_F(BluetoothTest, GetGattServices_and_GetGattService) {
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_EQ(1, gatt_discovery_attempts_); EXPECT_EQ(1, gatt_discovery_attempts_);
std::vector<std::string> services;
services.push_back("00000000-0000-1000-8000-00805f9b34fb");
// 2 duplicate UUIDs creating 2 instances. // 2 duplicate UUIDs creating 2 instances.
services.push_back("00000001-0000-1000-8000-00805f9b34fb"); SimulateGattServicesDiscovered(
services.push_back("00000001-0000-1000-8000-00805f9b34fb"); device,
SimulateGattServicesDiscovered(device, services); std::vector<std::string>(
{kTestUUIDGenericAccess, kTestUUIDHeartRate, kTestUUIDHeartRate}));
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_EQ(3u, device->GetGattServices().size()); EXPECT_EQ(3u, device->GetGattServices().size());
......
...@@ -38,15 +38,13 @@ class BluetoothRemoteGattCharacteristicTest : public BluetoothTest { ...@@ -38,15 +38,13 @@ class BluetoothRemoteGattCharacteristicTest : public BluetoothTest {
SimulateGattConnection(device_); SimulateGattConnection(device_);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
std::vector<std::string> services; SimulateGattServicesDiscovered(
std::string uuid("00000000-0000-1000-8000-00805f9b34fb"); device_, std::vector<std::string>({kTestUUIDGenericAccess}));
services.push_back(uuid);
SimulateGattServicesDiscovered(device_, services);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
ASSERT_EQ(1u, device_->GetGattServices().size()); ASSERT_EQ(1u, device_->GetGattServices().size());
service_ = device_->GetGattServices()[0]; service_ = device_->GetGattServices()[0];
SimulateGattCharacteristic(service_, uuid, properties); SimulateGattCharacteristic(service_, kTestUUIDDeviceName, properties);
SimulateGattCharacteristic(service_, uuid, properties); SimulateGattCharacteristic(service_, kTestUUIDDeviceName, properties);
ASSERT_EQ(2u, service_->GetCharacteristics().size()); ASSERT_EQ(2u, service_->GetCharacteristics().size());
characteristic1_ = service_->GetCharacteristics()[0]; characteristic1_ = service_->GetCharacteristics()[0];
characteristic2_ = service_->GetCharacteristics()[1]; characteristic2_ = service_->GetCharacteristics()[1];
...@@ -159,24 +157,23 @@ TEST_F(BluetoothRemoteGattCharacteristicTest, GetIdentifier) { ...@@ -159,24 +157,23 @@ TEST_F(BluetoothRemoteGattCharacteristicTest, GetIdentifier) {
// 3 services (all with same UUID). // 3 services (all with same UUID).
// 1 on the first device (to test characteristic instances across devices). // 1 on the first device (to test characteristic instances across devices).
// 2 on the second device (to test same device, multiple service instances). // 2 on the second device (to test same device, multiple service instances).
std::vector<std::string> services; SimulateGattServicesDiscovered(
std::string uuid = "00000000-0000-1000-8000-00805f9b34fb"; device1, std::vector<std::string>({kTestUUIDGenericAccess}));
services.push_back(uuid);
SimulateGattServicesDiscovered(device1, services);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
services.push_back(uuid); SimulateGattServicesDiscovered(
SimulateGattServicesDiscovered(device2, services); device2, std::vector<std::string>(
{kTestUUIDGenericAccess, kTestUUIDGenericAccess}));
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
BluetoothRemoteGattService* service1 = device1->GetGattServices()[0]; BluetoothRemoteGattService* service1 = device1->GetGattServices()[0];
BluetoothRemoteGattService* service2 = device2->GetGattServices()[0]; BluetoothRemoteGattService* service2 = device2->GetGattServices()[0];
BluetoothRemoteGattService* service3 = device2->GetGattServices()[1]; BluetoothRemoteGattService* service3 = device2->GetGattServices()[1];
// 6 characteristics (same UUID), 2 on each service. // 6 characteristics (same UUID), 2 on each service.
SimulateGattCharacteristic(service1, uuid, /* properties */ 0); SimulateGattCharacteristic(service1, kTestUUIDDeviceName, /* properties */ 0);
SimulateGattCharacteristic(service1, uuid, /* properties */ 0); SimulateGattCharacteristic(service1, kTestUUIDDeviceName, /* properties */ 0);
SimulateGattCharacteristic(service2, uuid, /* properties */ 0); SimulateGattCharacteristic(service2, kTestUUIDDeviceName, /* properties */ 0);
SimulateGattCharacteristic(service2, uuid, /* properties */ 0); SimulateGattCharacteristic(service2, kTestUUIDDeviceName, /* properties */ 0);
SimulateGattCharacteristic(service3, uuid, /* properties */ 0); SimulateGattCharacteristic(service3, kTestUUIDDeviceName, /* properties */ 0);
SimulateGattCharacteristic(service3, uuid, /* properties */ 0); SimulateGattCharacteristic(service3, kTestUUIDDeviceName, /* properties */ 0);
BluetoothRemoteGattCharacteristic* char1 = service1->GetCharacteristics()[0]; BluetoothRemoteGattCharacteristic* char1 = service1->GetCharacteristics()[0];
BluetoothRemoteGattCharacteristic* char2 = service1->GetCharacteristics()[1]; BluetoothRemoteGattCharacteristic* char2 = service1->GetCharacteristics()[1];
BluetoothRemoteGattCharacteristic* char3 = service2->GetCharacteristics()[0]; BluetoothRemoteGattCharacteristic* char3 = service2->GetCharacteristics()[0];
...@@ -220,20 +217,17 @@ TEST_F(BluetoothRemoteGattCharacteristicTest, GetUUID) { ...@@ -220,20 +217,17 @@ TEST_F(BluetoothRemoteGattCharacteristicTest, GetUUID) {
GetConnectErrorCallback(Call::NOT_EXPECTED)); GetConnectErrorCallback(Call::NOT_EXPECTED));
SimulateGattConnection(device); SimulateGattConnection(device);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
std::vector<std::string> services; SimulateGattServicesDiscovered(
services.push_back("00000000-0000-1000-8000-00805f9b34fb"); device, std::vector<std::string>({kTestUUIDGenericAccess}));
SimulateGattServicesDiscovered(device, services);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
BluetoothRemoteGattService* service = device->GetGattServices()[0]; BluetoothRemoteGattService* service = device->GetGattServices()[0];
// Create 3 characteristics. Two of them are duplicates. // Create 3 characteristics. Two of them are duplicates.
std::string uuid_str1("11111111-0000-1000-8000-00805f9b34fb"); BluetoothUUID uuid1(kTestUUIDDeviceName);
std::string uuid_str2("22222222-0000-1000-8000-00805f9b34fb"); BluetoothUUID uuid2(kTestUUIDAppearance);
BluetoothUUID uuid1(uuid_str1); SimulateGattCharacteristic(service, kTestUUIDDeviceName, /* properties */ 0);
BluetoothUUID uuid2(uuid_str2); SimulateGattCharacteristic(service, kTestUUIDAppearance, /* properties */ 0);
SimulateGattCharacteristic(service, uuid_str1, /* properties */ 0); SimulateGattCharacteristic(service, kTestUUIDAppearance, /* properties */ 0);
SimulateGattCharacteristic(service, uuid_str2, /* properties */ 0);
SimulateGattCharacteristic(service, uuid_str2, /* properties */ 0);
BluetoothRemoteGattCharacteristic* char1 = service->GetCharacteristics()[0]; BluetoothRemoteGattCharacteristic* char1 = service->GetCharacteristics()[0];
BluetoothRemoteGattCharacteristic* char2 = service->GetCharacteristics()[1]; BluetoothRemoteGattCharacteristic* char2 = service->GetCharacteristics()[1];
BluetoothRemoteGattCharacteristic* char3 = service->GetCharacteristics()[2]; BluetoothRemoteGattCharacteristic* char3 = service->GetCharacteristics()[2];
...@@ -264,16 +258,14 @@ TEST_F(BluetoothRemoteGattCharacteristicTest, GetProperties) { ...@@ -264,16 +258,14 @@ TEST_F(BluetoothRemoteGattCharacteristicTest, GetProperties) {
GetConnectErrorCallback(Call::NOT_EXPECTED)); GetConnectErrorCallback(Call::NOT_EXPECTED));
SimulateGattConnection(device); SimulateGattConnection(device);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
std::vector<std::string> services; SimulateGattServicesDiscovered(
std::string uuid("00000000-0000-1000-8000-00805f9b34fb"); device, std::vector<std::string>({kTestUUIDGenericAccess}));
services.push_back(uuid);
SimulateGattServicesDiscovered(device, services);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
BluetoothRemoteGattService* service = device->GetGattServices()[0]; BluetoothRemoteGattService* service = device->GetGattServices()[0];
// Create two characteristics with different properties: // Create two characteristics with different properties:
SimulateGattCharacteristic(service, uuid, /* properties */ 0); SimulateGattCharacteristic(service, kTestUUIDDeviceName, /* properties */ 0);
SimulateGattCharacteristic(service, uuid, /* properties */ 7); SimulateGattCharacteristic(service, kTestUUIDDeviceName, /* properties */ 7);
// Read the properties. Because ordering is unknown swap as necessary. // Read the properties. Because ordering is unknown swap as necessary.
int properties1 = service->GetCharacteristics()[0]->GetProperties(); int properties1 = service->GetCharacteristics()[0]->GetProperties();
...@@ -2208,10 +2200,10 @@ TEST_F(BluetoothRemoteGattCharacteristicTest, ...@@ -2208,10 +2200,10 @@ TEST_F(BluetoothRemoteGattCharacteristicTest,
ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate());
// Add several Descriptors: // Add several Descriptors:
BluetoothUUID uuid1("11111111-0000-1000-8000-00805f9b34fb"); BluetoothUUID uuid1(kTestUUIDCharacteristicUserDescription);
BluetoothUUID uuid2("22222222-0000-1000-8000-00805f9b34fb"); BluetoothUUID uuid2(kTestUUIDClientCharacteristicConfiguration);
BluetoothUUID uuid3("33333333-0000-1000-8000-00805f9b34fb"); BluetoothUUID uuid3(kTestUUIDServerCharacteristicConfiguration);
BluetoothUUID uuid4("44444444-0000-1000-8000-00805f9b34fb"); BluetoothUUID uuid4(kTestUUIDCharacteristicPresentationFormat);
SimulateGattDescriptor(characteristic1_, uuid1.canonical_value()); SimulateGattDescriptor(characteristic1_, uuid1.canonical_value());
SimulateGattDescriptor(characteristic1_, uuid2.canonical_value()); SimulateGattDescriptor(characteristic1_, uuid2.canonical_value());
SimulateGattDescriptor(characteristic2_, uuid3.canonical_value()); SimulateGattDescriptor(characteristic2_, uuid3.canonical_value());
...@@ -2253,9 +2245,9 @@ TEST_F(BluetoothRemoteGattCharacteristicTest, GetDescriptorsByUUID) { ...@@ -2253,9 +2245,9 @@ TEST_F(BluetoothRemoteGattCharacteristicTest, GetDescriptorsByUUID) {
ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate());
// Add several Descriptors: // Add several Descriptors:
BluetoothUUID id1("11111111-0000-1000-8000-00805f9b34fb"); BluetoothUUID id1(kTestUUIDCharacteristicUserDescription);
BluetoothUUID id2("22222222-0000-1000-8000-00805f9b34fb"); BluetoothUUID id2(kTestUUIDClientCharacteristicConfiguration);
BluetoothUUID id3("33333333-0000-1000-8000-00805f9b34fb"); BluetoothUUID id3(kTestUUIDServerCharacteristicConfiguration);
SimulateGattDescriptor(characteristic1_, id1.canonical_value()); SimulateGattDescriptor(characteristic1_, id1.canonical_value());
SimulateGattDescriptor(characteristic1_, id2.canonical_value()); SimulateGattDescriptor(characteristic1_, id2.canonical_value());
SimulateGattDescriptor(characteristic2_, id3.canonical_value()); SimulateGattDescriptor(characteristic2_, id3.canonical_value());
......
...@@ -28,20 +28,18 @@ class BluetoothRemoteGattDescriptorTest : public BluetoothTest { ...@@ -28,20 +28,18 @@ class BluetoothRemoteGattDescriptorTest : public BluetoothTest {
GetConnectErrorCallback(Call::NOT_EXPECTED)); GetConnectErrorCallback(Call::NOT_EXPECTED));
SimulateGattConnection(device_); SimulateGattConnection(device_);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
std::vector<std::string> services; SimulateGattServicesDiscovered(
std::string uuid("00000000-0000-1000-8000-00805f9b34fb"); device_, std::vector<std::string>({kTestUUIDGenericAccess}));
services.push_back(uuid);
SimulateGattServicesDiscovered(device_, services);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
ASSERT_EQ(1u, device_->GetGattServices().size()); ASSERT_EQ(1u, device_->GetGattServices().size());
service_ = device_->GetGattServices()[0]; service_ = device_->GetGattServices()[0];
SimulateGattCharacteristic(service_, uuid, 0); SimulateGattCharacteristic(service_, kTestUUIDDeviceName, 0);
ASSERT_EQ(1u, service_->GetCharacteristics().size()); ASSERT_EQ(1u, service_->GetCharacteristics().size());
characteristic_ = service_->GetCharacteristics()[0]; characteristic_ = service_->GetCharacteristics()[0];
SimulateGattDescriptor(characteristic_, SimulateGattDescriptor(characteristic_,
"00000001-0000-1000-8000-00805f9b34fb"); kTestUUIDCharacteristicUserDescription);
SimulateGattDescriptor(characteristic_, SimulateGattDescriptor(characteristic_,
"00000002-0000-1000-8000-00805f9b34fb"); kTestUUIDClientCharacteristicConfiguration);
ASSERT_EQ(2u, characteristic_->GetDescriptors().size()); ASSERT_EQ(2u, characteristic_->GetDescriptors().size());
descriptor1_ = characteristic_->GetDescriptors()[0]; descriptor1_ = characteristic_->GetDescriptors()[0];
descriptor2_ = characteristic_->GetDescriptors()[1]; descriptor2_ = characteristic_->GetDescriptors()[1];
...@@ -78,24 +76,23 @@ TEST_F(BluetoothRemoteGattDescriptorTest, GetIdentifier) { ...@@ -78,24 +76,23 @@ TEST_F(BluetoothRemoteGattDescriptorTest, GetIdentifier) {
// 3 services (all with same UUID). // 3 services (all with same UUID).
// 1 on the first device (to test characteristic instances across devices). // 1 on the first device (to test characteristic instances across devices).
// 2 on the second device (to test same device, multiple service instances). // 2 on the second device (to test same device, multiple service instances).
std::vector<std::string> services; SimulateGattServicesDiscovered(
std::string uuid = "00000000-0000-1000-8000-00805f9b34fb"; device1, std::vector<std::string>({kTestUUIDGenericAccess}));
services.push_back(uuid);
SimulateGattServicesDiscovered(device1, services);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
services.push_back(uuid); SimulateGattServicesDiscovered(
SimulateGattServicesDiscovered(device2, services); device2, std::vector<std::string>(
{kTestUUIDGenericAccess, kTestUUIDGenericAccess}));
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
BluetoothRemoteGattService* service1 = device1->GetGattServices()[0]; BluetoothRemoteGattService* service1 = device1->GetGattServices()[0];
BluetoothRemoteGattService* service2 = device2->GetGattServices()[0]; BluetoothRemoteGattService* service2 = device2->GetGattServices()[0];
BluetoothRemoteGattService* service3 = device2->GetGattServices()[1]; BluetoothRemoteGattService* service3 = device2->GetGattServices()[1];
// 6 characteristics (same UUID), 2 on each service. // 6 characteristics (same UUID), 2 on each service.
SimulateGattCharacteristic(service1, uuid, /* properties */ 0); SimulateGattCharacteristic(service1, kTestUUIDDeviceName, /* properties */ 0);
SimulateGattCharacteristic(service1, uuid, /* properties */ 0); SimulateGattCharacteristic(service1, kTestUUIDDeviceName, /* properties */ 0);
SimulateGattCharacteristic(service2, uuid, /* properties */ 0); SimulateGattCharacteristic(service2, kTestUUIDDeviceName, /* properties */ 0);
SimulateGattCharacteristic(service2, uuid, /* properties */ 0); SimulateGattCharacteristic(service2, kTestUUIDDeviceName, /* properties */ 0);
SimulateGattCharacteristic(service3, uuid, /* properties */ 0); SimulateGattCharacteristic(service3, kTestUUIDDeviceName, /* properties */ 0);
SimulateGattCharacteristic(service3, uuid, /* properties */ 0); SimulateGattCharacteristic(service3, kTestUUIDDeviceName, /* properties */ 0);
BluetoothRemoteGattCharacteristic* char1 = service1->GetCharacteristics()[0]; BluetoothRemoteGattCharacteristic* char1 = service1->GetCharacteristics()[0];
BluetoothRemoteGattCharacteristic* char2 = service1->GetCharacteristics()[1]; BluetoothRemoteGattCharacteristic* char2 = service1->GetCharacteristics()[1];
BluetoothRemoteGattCharacteristic* char3 = service2->GetCharacteristics()[0]; BluetoothRemoteGattCharacteristic* char3 = service2->GetCharacteristics()[0];
...@@ -105,12 +102,12 @@ TEST_F(BluetoothRemoteGattDescriptorTest, GetIdentifier) { ...@@ -105,12 +102,12 @@ TEST_F(BluetoothRemoteGattDescriptorTest, GetIdentifier) {
// 6 descriptors (same UUID), 1 on each characteristic // 6 descriptors (same UUID), 1 on each characteristic
// TODO(576900) Test multiple descriptors with same UUID on one // TODO(576900) Test multiple descriptors with same UUID on one
// characteristic. // characteristic.
SimulateGattDescriptor(char1, uuid); SimulateGattDescriptor(char1, kTestUUIDCharacteristicUserDescription);
SimulateGattDescriptor(char2, uuid); SimulateGattDescriptor(char2, kTestUUIDCharacteristicUserDescription);
SimulateGattDescriptor(char3, uuid); SimulateGattDescriptor(char3, kTestUUIDCharacteristicUserDescription);
SimulateGattDescriptor(char4, uuid); SimulateGattDescriptor(char4, kTestUUIDCharacteristicUserDescription);
SimulateGattDescriptor(char5, uuid); SimulateGattDescriptor(char5, kTestUUIDCharacteristicUserDescription);
SimulateGattDescriptor(char6, uuid); SimulateGattDescriptor(char6, kTestUUIDCharacteristicUserDescription);
BluetoothRemoteGattDescriptor* desc1 = char1->GetDescriptors()[0]; BluetoothRemoteGattDescriptor* desc1 = char1->GetDescriptors()[0];
BluetoothRemoteGattDescriptor* desc2 = char2->GetDescriptors()[0]; BluetoothRemoteGattDescriptor* desc2 = char2->GetDescriptors()[0];
BluetoothRemoteGattDescriptor* desc3 = char3->GetDescriptors()[0]; BluetoothRemoteGattDescriptor* desc3 = char3->GetDescriptors()[0];
...@@ -153,26 +150,25 @@ TEST_F(BluetoothRemoteGattDescriptorTest, GetUUID) { ...@@ -153,26 +150,25 @@ TEST_F(BluetoothRemoteGattDescriptorTest, GetUUID) {
device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED),
GetConnectErrorCallback(Call::NOT_EXPECTED)); GetConnectErrorCallback(Call::NOT_EXPECTED));
SimulateGattConnection(device); SimulateGattConnection(device);
std::vector<std::string> services; SimulateGattServicesDiscovered(
services.push_back("00000000-0000-1000-8000-00805f9b34fb"); device, std::vector<std::string>({kTestUUIDGenericAccess}));
SimulateGattServicesDiscovered(device, services);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
ASSERT_EQ(1u, device->GetGattServices().size()); ASSERT_EQ(1u, device->GetGattServices().size());
BluetoothRemoteGattService* service = device->GetGattServices()[0]; BluetoothRemoteGattService* service = device->GetGattServices()[0];
SimulateGattCharacteristic(service, "00000000-0000-1000-8000-00805f9b34fb", SimulateGattCharacteristic(service, kTestUUIDDeviceName,
/* properties */ 0); /* properties */ 0);
ASSERT_EQ(1u, service->GetCharacteristics().size()); ASSERT_EQ(1u, service->GetCharacteristics().size());
BluetoothRemoteGattCharacteristic* characteristic = BluetoothRemoteGattCharacteristic* characteristic =
service->GetCharacteristics()[0]; service->GetCharacteristics()[0];
// Create 2 descriptors. // Create 2 descriptors.
std::string uuid_str1("11111111-0000-1000-8000-00805f9b34fb"); BluetoothUUID uuid1(kTestUUIDCharacteristicUserDescription);
std::string uuid_str2("22222222-0000-1000-8000-00805f9b34fb"); BluetoothUUID uuid2(kTestUUIDClientCharacteristicConfiguration);
BluetoothUUID uuid1(uuid_str1); SimulateGattDescriptor(characteristic,
BluetoothUUID uuid2(uuid_str2); kTestUUIDCharacteristicUserDescription);
SimulateGattDescriptor(characteristic, uuid_str1); SimulateGattDescriptor(characteristic,
SimulateGattDescriptor(characteristic, uuid_str2); kTestUUIDClientCharacteristicConfiguration);
ASSERT_EQ(2u, characteristic->GetDescriptors().size()); ASSERT_EQ(2u, characteristic->GetDescriptors().size());
BluetoothRemoteGattDescriptor* descriptor1 = BluetoothRemoteGattDescriptor* descriptor1 =
characteristic->GetDescriptors()[0]; characteristic->GetDescriptors()[0];
......
...@@ -43,12 +43,12 @@ TEST_F(BluetoothRemoteGattServiceTest, GetIdentifier) { ...@@ -43,12 +43,12 @@ TEST_F(BluetoothRemoteGattServiceTest, GetIdentifier) {
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
// 2 duplicate UUIDs creating 2 service instances on each device. // 2 duplicate UUIDs creating 2 service instances on each device.
std::vector<std::string> services; SimulateGattServicesDiscovered(
std::string uuid = "00000000-0000-1000-8000-00805f9b34fb"; device1, std::vector<std::string>(
services.push_back(uuid); {kTestUUIDGenericAccess, kTestUUIDGenericAccess}));
services.push_back(uuid); SimulateGattServicesDiscovered(
SimulateGattServicesDiscovered(device1, services); device2, std::vector<std::string>(
SimulateGattServicesDiscovered(device2, services); {kTestUUIDGenericAccess, kTestUUIDGenericAccess}));
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
BluetoothRemoteGattService* service1 = device1->GetGattServices()[0]; BluetoothRemoteGattService* service1 = device1->GetGattServices()[0];
BluetoothRemoteGattService* service2 = device1->GetGattServices()[1]; BluetoothRemoteGattService* service2 = device1->GetGattServices()[1];
...@@ -82,7 +82,7 @@ TEST_F(BluetoothRemoteGattServiceTest, GetUUID) { ...@@ -82,7 +82,7 @@ TEST_F(BluetoothRemoteGattServiceTest, GetUUID) {
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
// Create multiple instances with the same UUID. // Create multiple instances with the same UUID.
BluetoothUUID uuid("00000000-0000-1000-8000-00805f9b34fb"); BluetoothUUID uuid(kTestUUIDGenericAccess);
std::vector<std::string> services; std::vector<std::string> services;
services.push_back(uuid.canonical_value()); services.push_back(uuid.canonical_value());
services.push_back(uuid.canonical_value()); services.push_back(uuid.canonical_value());
...@@ -110,9 +110,8 @@ TEST_F(BluetoothRemoteGattServiceTest, GetCharacteristics_FindNone) { ...@@ -110,9 +110,8 @@ TEST_F(BluetoothRemoteGattServiceTest, GetCharacteristics_FindNone) {
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
// Simulate a service, with no Characteristics: // Simulate a service, with no Characteristics:
std::vector<std::string> services; SimulateGattServicesDiscovered(
services.push_back("00000000-0000-1000-8000-00805f9b34fb"); device, std::vector<std::string>({kTestUUIDGenericAccess}));
SimulateGattServicesDiscovered(device, services);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
BluetoothRemoteGattService* service = device->GetGattServices()[0]; BluetoothRemoteGattService* service = device->GetGattServices()[0];
...@@ -136,19 +135,18 @@ TEST_F(BluetoothRemoteGattServiceTest, ...@@ -136,19 +135,18 @@ TEST_F(BluetoothRemoteGattServiceTest,
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
// Simulate a service, with several Characteristics: // Simulate a service, with several Characteristics:
std::vector<std::string> services; SimulateGattServicesDiscovered(
services.push_back("00000000-0000-1000-8000-00805f9b34fb"); device, std::vector<std::string>({kTestUUIDGenericAccess}));
SimulateGattServicesDiscovered(device, services);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
BluetoothRemoteGattService* service = device->GetGattServices()[0]; BluetoothRemoteGattService* service = device->GetGattServices()[0];
std::string characteristic_uuid1 = "11111111-0000-1000-8000-00805f9b34fb"; SimulateGattCharacteristic(service, kTestUUIDDeviceName, /* properties */ 0);
std::string characteristic_uuid2 = "22222222-0000-1000-8000-00805f9b34fb"; SimulateGattCharacteristic(service, kTestUUIDAppearance,
std::string characteristic_uuid3 = characteristic_uuid2; // Duplicate UUID. /* properties */ 0);
std::string characteristic_uuid4 = "33333333-0000-1000-8000-00805f9b34fb"; // Duplicate UUID.
SimulateGattCharacteristic(service, characteristic_uuid1, /* properties */ 0); SimulateGattCharacteristic(service, kTestUUIDAppearance,
SimulateGattCharacteristic(service, characteristic_uuid2, /* properties */ 0); /* properties */ 0);
SimulateGattCharacteristic(service, characteristic_uuid3, /* properties */ 0); SimulateGattCharacteristic(service, kTestUUIDReconnectionAddress,
SimulateGattCharacteristic(service, characteristic_uuid4, /* properties */ 0); /* properties */ 0);
// Verify that GetCharacteristic can retrieve characteristics again by ID, // Verify that GetCharacteristic can retrieve characteristics again by ID,
// and that the same Characteristics come back. // and that the same Characteristics come back.
...@@ -188,38 +186,36 @@ TEST_F(BluetoothRemoteGattServiceTest, GetCharacteristicsByUUID) { ...@@ -188,38 +186,36 @@ TEST_F(BluetoothRemoteGattServiceTest, GetCharacteristicsByUUID) {
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
// Simulate two primary GATT services. // Simulate two primary GATT services.
std::vector<std::string> services; SimulateGattServicesDiscovered(
services.push_back("00000000-0000-1000-8000-00805f9b34fb"); device,
services.push_back("01010101-0101-1000-8000-00805f9b34fb"); std::vector<std::string>({kTestUUIDGenericAccess, kTestUUIDHeartRate}));
SimulateGattServicesDiscovered(device, services);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
BluetoothRemoteGattService* service1 = device->GetGattServices()[0]; BluetoothRemoteGattService* service1 = device->GetGattServices()[0];
BluetoothRemoteGattService* service2 = device->GetGattServices()[1]; BluetoothRemoteGattService* service2 = device->GetGattServices()[1];
std::string characteristic_uuid1 = "11111111-0000-1000-8000-00805f9b34fb"; SimulateGattCharacteristic(service1, kTestUUIDDeviceName,
std::string characteristic_uuid2 = "22222222-0000-1000-8000-00805f9b34fb";
SimulateGattCharacteristic(service1, characteristic_uuid1,
/* properties */ 0); /* properties */ 0);
// 2 duplicate UUIDs creating 2 instances. // 2 duplicate UUIDs creating 2 instances.
SimulateGattCharacteristic(service2, characteristic_uuid2, SimulateGattCharacteristic(service2, kTestUUIDHeartRateMeasurement,
/* properties */ 0); /* properties */ 0);
SimulateGattCharacteristic(service2, characteristic_uuid2, SimulateGattCharacteristic(service2, kTestUUIDHeartRateMeasurement,
/* properties */ 0); /* properties */ 0);
{ {
std::vector<BluetoothRemoteGattCharacteristic*> characteristics = std::vector<BluetoothRemoteGattCharacteristic*> characteristics =
service1->GetCharacteristicsByUUID(BluetoothUUID(characteristic_uuid1)); service1->GetCharacteristicsByUUID(BluetoothUUID(kTestUUIDDeviceName));
EXPECT_EQ(1u, characteristics.size()); EXPECT_EQ(1u, characteristics.size());
EXPECT_EQ(characteristic_uuid1, EXPECT_EQ(kTestUUIDDeviceName,
characteristics[0]->GetUUID().canonical_value()); characteristics[0]->GetUUID().canonical_value());
} }
{ {
std::vector<BluetoothRemoteGattCharacteristic*> characteristics = std::vector<BluetoothRemoteGattCharacteristic*> characteristics =
service2->GetCharacteristicsByUUID(BluetoothUUID(characteristic_uuid2)); service2->GetCharacteristicsByUUID(
BluetoothUUID(kTestUUIDHeartRateMeasurement));
EXPECT_EQ(2u, characteristics.size()); EXPECT_EQ(2u, characteristics.size());
EXPECT_EQ(characteristic_uuid2, EXPECT_EQ(kTestUUIDHeartRateMeasurement,
characteristics[0]->GetUUID().canonical_value()); characteristics[0]->GetUUID().canonical_value());
EXPECT_EQ(characteristic_uuid2, EXPECT_EQ(kTestUUIDHeartRateMeasurement,
characteristics[1]->GetUUID().canonical_value()); characteristics[1]->GetUUID().canonical_value());
EXPECT_NE(characteristics[0]->GetIdentifier(), EXPECT_NE(characteristics[0]->GetIdentifier(),
characteristics[1]->GetIdentifier()); characteristics[1]->GetIdentifier());
...@@ -253,19 +249,18 @@ TEST_F(BluetoothRemoteGattServiceTest, GattCharacteristics_ObserversCalls) { ...@@ -253,19 +249,18 @@ TEST_F(BluetoothRemoteGattServiceTest, GattCharacteristics_ObserversCalls) {
TestBluetoothAdapterObserver observer(adapter_); TestBluetoothAdapterObserver observer(adapter_);
// Simulate a service, with several Characteristics: // Simulate a service, with several Characteristics:
std::vector<std::string> services; SimulateGattServicesDiscovered(
services.push_back("00000000-0000-1000-8000-00805f9b34fb"); device, std::vector<std::string>({kTestUUIDGenericAccess}));
SimulateGattServicesDiscovered(device, services);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
BluetoothRemoteGattService* service = device->GetGattServices()[0]; BluetoothRemoteGattService* service = device->GetGattServices()[0];
std::string characteristic_uuid1 = "11111111-0000-1000-8000-00805f9b34fb"; SimulateGattCharacteristic(service, kTestUUIDDeviceName, /* properties */ 0);
std::string characteristic_uuid2 = "22222222-0000-1000-8000-00805f9b34fb"; SimulateGattCharacteristic(service, kTestUUIDAppearance,
std::string characteristic_uuid3 = characteristic_uuid2; // Duplicate UUID. /* properties */ 0);
std::string characteristic_uuid4 = "33333333-0000-1000-8000-00805f9b34fb"; // Duplicate UUID.
SimulateGattCharacteristic(service, characteristic_uuid1, /* properties */ 0); SimulateGattCharacteristic(service, kTestUUIDAppearance,
SimulateGattCharacteristic(service, characteristic_uuid2, /* properties */ 0); /* properties */ 0);
SimulateGattCharacteristic(service, characteristic_uuid3, /* properties */ 0); SimulateGattCharacteristic(service, kTestUUIDReconnectionAddress,
SimulateGattCharacteristic(service, characteristic_uuid4, /* properties */ 0); /* properties */ 0);
#if !defined(OS_WIN) #if !defined(OS_WIN)
// TODO(620895) GattCharacteristicAdded has to be implemented for Windows. // TODO(620895) GattCharacteristicAdded has to be implemented for Windows.
EXPECT_EQ(4, observer.gatt_characteristic_added_count()); EXPECT_EQ(4, observer.gatt_characteristic_added_count());
...@@ -326,10 +321,9 @@ TEST_F(BluetoothRemoteGattServiceTest, SimulateGattServiceRemove) { ...@@ -326,10 +321,9 @@ TEST_F(BluetoothRemoteGattServiceTest, SimulateGattServiceRemove) {
TestBluetoothAdapterObserver observer(adapter_); TestBluetoothAdapterObserver observer(adapter_);
// Simulate two primary GATT services. // Simulate two primary GATT services.
std::vector<std::string> services; SimulateGattServicesDiscovered(
services.push_back("00000000-0000-1000-8000-00805f9b34fb"); device,
services.push_back("01010101-0101-1000-8000-00805f9b34fb"); std::vector<std::string>({kTestUUIDGenericAccess, kTestUUIDHeartRate}));
SimulateGattServicesDiscovered(device, services);
EXPECT_EQ(2u, device->GetGattServices().size()); EXPECT_EQ(2u, device->GetGattServices().size());
// Simulate remove of a primary service. // Simulate remove of a primary service.
......
...@@ -25,6 +25,7 @@ const std::string BluetoothTestBase::kTestDeviceAddress1 = "01:00:00:90:1E:BE"; ...@@ -25,6 +25,7 @@ const std::string BluetoothTestBase::kTestDeviceAddress1 = "01:00:00:90:1E:BE";
const std::string BluetoothTestBase::kTestDeviceAddress2 = "02:00:00:8B:74:63"; const std::string BluetoothTestBase::kTestDeviceAddress2 = "02:00:00:8B:74:63";
const std::string BluetoothTestBase::kTestDeviceAddress3 = "03:00:00:17:C0:57"; const std::string BluetoothTestBase::kTestDeviceAddress3 = "03:00:00:17:C0:57";
// Service UUIDs
const std::string BluetoothTestBase::kTestUUIDGenericAccess = const std::string BluetoothTestBase::kTestUUIDGenericAccess =
"00001800-0000-1000-8000-00805f9b34fb"; "00001800-0000-1000-8000-00805f9b34fb";
const std::string BluetoothTestBase::kTestUUIDGenericAttribute = const std::string BluetoothTestBase::kTestUUIDGenericAttribute =
...@@ -35,6 +36,26 @@ const std::string BluetoothTestBase::kTestUUIDLinkLoss = ...@@ -35,6 +36,26 @@ const std::string BluetoothTestBase::kTestUUIDLinkLoss =
"00001803-0000-1000-8000-00805f9b34fb"; "00001803-0000-1000-8000-00805f9b34fb";
const std::string BluetoothTestBase::kTestUUIDHeartRate = const std::string BluetoothTestBase::kTestUUIDHeartRate =
"0000180d-0000-1000-8000-00805f9b34fb"; "0000180d-0000-1000-8000-00805f9b34fb";
// Characteristic UUIDs
const std::string BluetoothTestBase::kTestUUIDDeviceName =
"00002a00-0000-1000-8000-00805f9b34fb";
const std::string BluetoothTestBase::kTestUUIDAppearance =
"00002a01-0000-1000-8000-00805f9b34fb";
const std::string BluetoothTestBase::kTestUUIDReconnectionAddress =
"00002a03-0000-1000-8000-00805f9b34fb";
const std::string BluetoothTestBase::kTestUUIDHeartRateMeasurement =
"00002a37-0000-1000-8000-00805f9b34fb";
// Descriptor UUIDs
const std::string BluetoothTestBase::kTestUUIDCharacteristicUserDescription =
"00002901-0000-1000-8000-00805f9b34fb";
const std::string
BluetoothTestBase::kTestUUIDClientCharacteristicConfiguration =
"00002902-0000-1000-8000-00805f9b34fb";
const std::string
BluetoothTestBase::kTestUUIDServerCharacteristicConfiguration =
"00002903-0000-1000-8000-00805f9b34fb";
const std::string BluetoothTestBase::kTestUUIDCharacteristicPresentationFormat =
"00002904-0000-1000-8000-00805f9b34fb";
BluetoothTestBase::BluetoothTestBase() : weak_factory_(this) {} BluetoothTestBase::BluetoothTestBase() : weak_factory_(this) {}
......
...@@ -87,11 +87,24 @@ class BluetoothTestBase : public testing::Test { ...@@ -87,11 +87,24 @@ class BluetoothTestBase : public testing::Test {
LOWER = -20, LOWER = -20,
}; };
// Services
static const std::string kTestUUIDGenericAccess; static const std::string kTestUUIDGenericAccess;
static const std::string kTestUUIDGenericAttribute; static const std::string kTestUUIDGenericAttribute;
static const std::string kTestUUIDImmediateAlert; static const std::string kTestUUIDImmediateAlert;
static const std::string kTestUUIDLinkLoss; static const std::string kTestUUIDLinkLoss;
static const std::string kTestUUIDHeartRate; static const std::string kTestUUIDHeartRate;
// Characteristics
// The following three characteristics are for kTestUUIDGenericAccess.
static const std::string kTestUUIDDeviceName;
static const std::string kTestUUIDAppearance;
static const std::string kTestUUIDReconnectionAddress;
// This characteristic is for kTestUUIDHeartRate.
static const std::string kTestUUIDHeartRateMeasurement;
// Descriptors
static const std::string kTestUUIDCharacteristicUserDescription;
static const std::string kTestUUIDClientCharacteristicConfiguration;
static const std::string kTestUUIDServerCharacteristicConfiguration;
static const std::string kTestUUIDCharacteristicPresentationFormat;
BluetoothTestBase(); BluetoothTestBase();
~BluetoothTestBase() override; ~BluetoothTestBase() override;
......
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