Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(363)

Unified Diff: device/bluetooth/bluetooth_device_unittest.cc

Issue 2785383002: Update unit tests for BluetoothDevice::GetPrimaryServicesByUUID() etc. (Closed)
Patch Set: added TODO Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « device/bluetooth/bluetooth_device.cc ('k') | device/bluetooth/bluetooth_remote_gatt_service.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/bluetooth/bluetooth_device_unittest.cc
diff --git a/device/bluetooth/bluetooth_device_unittest.cc b/device/bluetooth/bluetooth_device_unittest.cc
index ab478fc7386df4a49d9bf91a0645488354e48239..0d5f19a9dfba740dcb4c1816375513da24c2c3e2 100644
--- a/device/bluetooth/bluetooth_device_unittest.cc
+++ b/device/bluetooth/bluetooth_device_unittest.cc
@@ -46,9 +46,13 @@ int8_t ToInt8(BluetoothTest::TestTxPower tx_power) {
using UUIDSet = BluetoothDevice::UUIDSet;
using ServiceDataMap = BluetoothDevice::ServiceDataMap;
-class BluetoothGetServiceOrCharacteristicTest : public BluetoothTest {
+class BluetoothGetServiceTest : public BluetoothTest {
public:
- // Creates |device_|, |services_|.
+ BluetoothGetServiceTest()
+ : unique_service_uuid_(kTestUUIDGenericAccess),
+ duplicate_service_uuid_(kTestUUIDHeartRate) {}
+
+ // Creates |device_|.
void FakeServiceBoilerplate() {
InitWithFakeAdapter();
StartLowEnergyDiscoverySession();
@@ -62,21 +66,36 @@ class BluetoothGetServiceOrCharacteristicTest : public BluetoothTest {
TestBluetoothAdapterObserver observer(adapter_);
SimulateGattConnection(device_);
base::RunLoop().RunUntilIdle();
+#if defined(OS_WIN)
+ // TODO(crbug.com/507419): Check connection once CreateGattConnection is
+ // implemented on Windows.
+ EXPECT_FALSE(device_->IsConnected());
+#else
EXPECT_TRUE(device_->IsConnected());
+#endif // defined(OS_WIN)
// Discover services.
- services_.push_back("00000000-0000-1000-8000-00805f9b34fb");
+ std::vector<std::string> service_uuids;
+ service_uuids.push_back(unique_service_uuid_.canonical_value());
// 2 duplicate UUIDs creating 2 instances.
- services_.push_back("00000001-0000-1000-8000-00805f9b34fb");
- services_.push_back("00000001-0000-1000-8000-00805f9b34fb");
- SimulateGattServicesDiscovered(device_, services_);
+ service_uuids.push_back(duplicate_service_uuid_.canonical_value());
ortuno 2017/04/05 22:50:00 Out of curiosity why did you end up using push_bac
juncai 2017/04/05 22:55:15 From what I see, other places in this file use pus
+ service_uuids.push_back(duplicate_service_uuid_.canonical_value());
+ SimulateGattServicesDiscovered(device_, service_uuids);
base::RunLoop().RunUntilIdle();
+#if defined(OS_WIN)
+ // TODO(crbug.com/507419): Check connection once CreateGattConnection is
+ // implemented on Windows.
+ EXPECT_FALSE(device_->IsGattServicesDiscoveryComplete());
+#else
EXPECT_TRUE(device_->IsGattServicesDiscoveryComplete());
+#endif // defined(OS_WIN)
}
protected:
+ BluetoothUUID unique_service_uuid_;
+ BluetoothUUID duplicate_service_uuid_;
+
BluetoothDevice* device_ = nullptr;
- std::vector<std::string> services_;
};
TEST(BluetoothDeviceTest, CanonicalizeAddressFormat_AcceptsAllValidFormats) {
@@ -1516,8 +1535,8 @@ TEST_F(BluetoothTest, GetDeviceTransportType) {
}
#endif // defined(OS_CHROMEOS) || defined(OS_LINUX)
-#if defined(OS_ANDROID) || defined(OS_MACOSX)
-TEST_F(BluetoothGetServiceOrCharacteristicTest, GetPrimaryServices) {
+#if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
+TEST_F(BluetoothGetServiceTest, GetPrimaryServices) {
if (!PlatformSupportsLowEnergy()) {
LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
return;
@@ -1527,96 +1546,35 @@ TEST_F(BluetoothGetServiceOrCharacteristicTest, GetPrimaryServices) {
EXPECT_EQ(3u, device_->GetPrimaryServices().size());
}
-TEST_F(BluetoothGetServiceOrCharacteristicTest, GetPrimaryServicesByUUID) {
+TEST_F(BluetoothGetServiceTest, GetPrimaryServicesByUUID) {
if (!PlatformSupportsLowEnergy()) {
LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
return;
}
ASSERT_NO_FATAL_FAILURE(FakeServiceBoilerplate());
- EXPECT_EQ(
- 1u,
- device_->GetPrimaryServicesByUUID(BluetoothUUID(services_[0])).size());
- EXPECT_EQ(
- 2u,
- device_->GetPrimaryServicesByUUID(BluetoothUUID(services_[1])).size());
- std::string service_uuid_not_exist_in_setup =
- "00000002-0000-1000-8000-00805f9b34fb";
- EXPECT_TRUE(device_
- ->GetPrimaryServicesByUUID(
- BluetoothUUID(service_uuid_not_exist_in_setup))
- .empty());
-}
-
-TEST_F(BluetoothGetServiceOrCharacteristicTest, GetCharacteristicsByUUID) {
- if (!PlatformSupportsLowEnergy()) {
- LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
- return;
+ {
+ std::vector<BluetoothRemoteGattService*> services =
+ device_->GetPrimaryServicesByUUID(unique_service_uuid_);
+ EXPECT_EQ(1u, services.size());
+ EXPECT_EQ(unique_service_uuid_, services[0]->GetUUID());
}
- ASSERT_NO_FATAL_FAILURE(FakeServiceBoilerplate());
- std::vector<BluetoothRemoteGattService*> primary_services =
- device_->GetPrimaryServices();
- std::string service_instance_id0 = primary_services[0]->GetIdentifier();
- std::string service_instance_id1 = primary_services[1]->GetIdentifier();
- std::string service_instance_id2 = primary_services[2]->GetIdentifier();
-
- std::string characteristic_uuid0 = "00000002-0000-1000-8000-00805f9b34fb";
- std::string characteristic_uuid1 = "00000003-0000-1000-8000-00805f9b34fb";
- SimulateGattCharacteristic(primary_services[0], characteristic_uuid0,
- 0 /* properties */);
- SimulateGattCharacteristic(primary_services[1], characteristic_uuid1,
- 0 /* properties */);
- SimulateGattCharacteristic(primary_services[2], characteristic_uuid1,
- 0 /* properties */);
-
- EXPECT_EQ(1u,
- device_
- ->GetCharacteristicsByUUID(service_instance_id0,
- BluetoothUUID(characteristic_uuid0))
- .size());
- EXPECT_EQ(1u,
- device_
- ->GetCharacteristicsByUUID(service_instance_id1,
- BluetoothUUID(characteristic_uuid1))
- .size());
- EXPECT_EQ(1u,
- device_
- ->GetCharacteristicsByUUID(service_instance_id2,
- BluetoothUUID(characteristic_uuid1))
- .size());
-
- std::string service_instance_id_not_exist_in_setup =
- "non-existent platform specific service instance id";
- EXPECT_TRUE(
- device_
- ->GetCharacteristicsByUUID(service_instance_id_not_exist_in_setup,
- BluetoothUUID(characteristic_uuid0))
- .empty());
- EXPECT_TRUE(
- device_
- ->GetCharacteristicsByUUID(service_instance_id_not_exist_in_setup,
- BluetoothUUID(characteristic_uuid1))
- .empty());
-
- std::string characteristic_uuid_not_exist_in_setup =
- "00000005-0000-1000-8000-00805f9b34fb";
- EXPECT_TRUE(device_
- ->GetCharacteristicsByUUID(
- service_instance_id0,
- BluetoothUUID(characteristic_uuid_not_exist_in_setup))
- .empty());
- EXPECT_TRUE(device_
- ->GetCharacteristicsByUUID(
- service_instance_id1,
- BluetoothUUID(characteristic_uuid_not_exist_in_setup))
- .empty());
- EXPECT_TRUE(device_
- ->GetCharacteristicsByUUID(
- service_instance_id2,
- BluetoothUUID(characteristic_uuid_not_exist_in_setup))
- .empty());
+ {
+ std::vector<BluetoothRemoteGattService*> services =
+ device_->GetPrimaryServicesByUUID(duplicate_service_uuid_);
+ EXPECT_EQ(2u, services.size());
+ EXPECT_EQ(duplicate_service_uuid_, services[0]->GetUUID());
+ EXPECT_EQ(duplicate_service_uuid_, services[1]->GetUUID());
+
+ EXPECT_TRUE(device_
+ ->GetPrimaryServicesByUUID(BluetoothUUID(
+ BluetoothTestBase::kTestUUIDGenericAttribute))
+ .empty());
+
+ EXPECT_NE(services[0]->GetIdentifier(), services[1]->GetIdentifier());
+ }
}
-#endif // defined(OS_ANDROID) || defined(OS_MACOSX)
+#endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
} // namespace device
« no previous file with comments | « device/bluetooth/bluetooth_device.cc ('k') | device/bluetooth/bluetooth_remote_gatt_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698