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

Unified Diff: device/bluetooth/bluez/bluetooth_bluez_unittest.cc

Issue 1941923002: bluetooth: Return int8_t and use -128 for unknown tx power. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@my-origin
Patch Set: Moar fixes Created 4 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
Index: device/bluetooth/bluez/bluetooth_bluez_unittest.cc
diff --git a/device/bluetooth/bluez/bluetooth_bluez_unittest.cc b/device/bluetooth/bluez/bluetooth_bluez_unittest.cc
index c2f0fa1bb3b010df85dd0ba7fab1e6bd69a53261..8ec0fa39262fafade2a2058a58a1412f93d666e3 100644
--- a/device/bluetooth/bluez/bluetooth_bluez_unittest.cc
+++ b/device/bluetooth/bluez/bluetooth_bluez_unittest.cc
@@ -2503,8 +2503,43 @@ TEST_F(BluetoothBlueZTest, DeviceInquiryRSSIInvalidated) {
EXPECT_EQ(1, observer.device_changed_count());
EXPECT_EQ(devices[idx], observer.last_device());
- int unknown_power = BluetoothDevice::kUnknownPower;
- EXPECT_EQ(unknown_power, devices[idx]->GetInquiryRSSI());
+ EXPECT_TRUE(devices[idx]->GetInquiryRSSI() == BluetoothDevice::kUnknownRSSI);
+}
+
+TEST_F(BluetoothBlueZTest, DeviceInquiryRSSIOutOfBounds) {
+ // RSSI should be a int8 but luez returns a int16 because DBus doesn't
scheib 2016/05/04 01:18:37 bluez ^
ortuno 2016/05/04 16:44:11 Done.
+ // support int8 even though Bluez uses a int8 internally. This test
+ // makes sure we handle values outside of the int8 range.
+ GetAdapter();
+
+ BluetoothAdapter::DeviceList devices = adapter_->GetDevices();
+ ASSERT_EQ(2U, devices.size());
+
+ int idx = GetDeviceIndexByAddress(
+ devices, bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress);
+ ASSERT_NE(-1, idx);
+
+ bluez::FakeBluetoothDeviceClient::Properties* properties =
+ fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath(
+ bluez::FakeBluetoothDeviceClient::kPairedDevicePath));
+
+ properties->rssi.set_valid(true);
+
+ // Small invalid value
+ properties->rssi.ReplaceValue(-129);
+ EXPECT_TRUE(devices[idx]->GetInquiryRSSI() == BluetoothDevice::kUnknownRSSI);
+
+ // Small valid value
+ properties->rssi.ReplaceValue(-128);
+ EXPECT_EQ(-128, devices[idx]->GetInquiryRSSI());
+
+ // Large valid value. (127 is used for BluetoothDevice::kUnknownRSSI).
+ properties->rssi.ReplaceValue(126);
+ EXPECT_EQ(126, devices[idx]->GetInquiryRSSI());
+
+ // Large invalid value
+ properties->rssi.ReplaceValue(128);
+ EXPECT_TRUE(devices[idx]->GetInquiryRSSI() == BluetoothDevice::kUnknownRSSI);
scheib 2016/05/04 01:18:37 EXPECT_EQ instead of _TRUE. (and elsewhere)
ortuno 2016/05/04 16:44:12 That's what I tried to do the first time but I get
}
TEST_F(BluetoothBlueZTest, DeviceInquiryTxPowerInvalidated) {
@@ -2540,8 +2575,46 @@ TEST_F(BluetoothBlueZTest, DeviceInquiryTxPowerInvalidated) {
EXPECT_EQ(1, observer.device_changed_count());
EXPECT_EQ(devices[idx], observer.last_device());
- int unknown_power = BluetoothDevice::kUnknownPower;
- EXPECT_EQ(unknown_power, devices[idx]->GetInquiryTxPower());
+ EXPECT_TRUE(devices[idx]->GetInquiryTxPower() ==
+ BluetoothDevice::kUnknownTxPower);
+}
+
+TEST_F(BluetoothBlueZTest, DeviceInquiryTxPowerOutOfBounds) {
+ // TxPower should be a int8 but Bluez returns a int16 because DBus doesn't
+ // support int8 even though Bluez uses a int8 internally. This test
+ // makes sure we handle values outside of the int8 range.
+ GetAdapter();
+
+ BluetoothAdapter::DeviceList devices = adapter_->GetDevices();
+ ASSERT_EQ(2U, devices.size());
+
+ int idx = GetDeviceIndexByAddress(
+ devices, bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress);
+ ASSERT_NE(-1, idx);
+
+ bluez::FakeBluetoothDeviceClient::Properties* properties =
+ fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath(
+ bluez::FakeBluetoothDeviceClient::kPairedDevicePath));
+
+ properties->tx_power.set_valid(true);
+
+ // Small invalid value
+ properties->tx_power.ReplaceValue(-129);
+ EXPECT_TRUE(devices[idx]->GetInquiryTxPower() ==
+ BluetoothDevice::kUnknownTxPower);
+
+ // Small valid value
+ properties->tx_power.ReplaceValue(-128);
+ EXPECT_EQ(-128, devices[idx]->GetInquiryTxPower());
+
+ // Large valid value. (127 is used for BluetoothDevice::kUnknownTxPower).
scheib 2016/05/04 01:18:37 What does Bluez use for UnknownTxPower? This patch
ortuno 2016/05/04 16:44:12 In bluez, if a property is not present property.is
+ properties->tx_power.ReplaceValue(126);
+ EXPECT_EQ(126, devices[idx]->GetInquiryTxPower());
+
+ // Large invalid value
+ properties->tx_power.ReplaceValue(128);
+ EXPECT_TRUE(devices[idx]->GetInquiryTxPower() ==
+ BluetoothDevice::kUnknownTxPower);
}
TEST_F(BluetoothBlueZTest, ForgetDevice) {
@@ -4132,14 +4205,14 @@ TEST_F(BluetoothBlueZTest, GetConnectionInfoForDisconnectedDevice) {
bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress);
// Calling GetConnectionInfo for an unconnected device should return a result
- // in which all fields are filled with BluetoothDevice::kUnknownPower.
+ // in which all fields are filled with BluetoothDevice::kUnknownRSSI and
+ // BluetoothDevice::kUnknownTxPower.
BluetoothDevice::ConnectionInfo conn_info(0, 0, 0);
device->GetConnectionInfo(base::Bind(&SaveConnectionInfo, &conn_info));
- int unknown_power = BluetoothDevice::kUnknownPower;
- EXPECT_NE(0, unknown_power);
- EXPECT_EQ(unknown_power, conn_info.rssi);
- EXPECT_EQ(unknown_power, conn_info.transmit_power);
- EXPECT_EQ(unknown_power, conn_info.max_transmit_power);
+
+ EXPECT_TRUE(conn_info.rssi == BluetoothDevice::kUnknownRSSI);
+ EXPECT_TRUE(conn_info.transmit_power == BluetoothDevice::kUnknownTxPower);
+ EXPECT_TRUE(conn_info.max_transmit_power == BluetoothDevice::kUnknownTxPower);
}
TEST_F(BluetoothBlueZTest, GetConnectionInfoForConnectedDevice) {

Powered by Google App Engine
This is Rietveld 408576698