Index: device/bluetooth/bluetooth_local_gatt_characteristic_unittest.cc |
diff --git a/device/bluetooth/bluetooth_local_gatt_characteristic_unittest.cc b/device/bluetooth/bluetooth_local_gatt_characteristic_unittest.cc |
index 6cebf6021d935bc32331191ca3465524278de3e2..2134e68821f129c2e2f30b96a9b0819a1fbbe7b2 100644 |
--- a/device/bluetooth/bluetooth_local_gatt_characteristic_unittest.cc |
+++ b/device/bluetooth/bluetooth_local_gatt_characteristic_unittest.cc |
@@ -46,6 +46,19 @@ class BluetoothLocalGattCharacteristicTest : public BluetoothGattServerTest { |
CompleteGattSetup(); |
} |
+ void CheckNotification( |
+ const BluetoothDevice* expected_device, |
+ uint64_t expected_value, |
+ bool expected_indicate_flag, |
+ const BluetoothTestBase::NotificationType& actual_notification) { |
+ if (expected_device) { |
+ EXPECT_EQ(expected_device->GetIdentifier(), |
+ std::get<0>(actual_notification)); |
xiyuan
2016/06/06 21:49:29
nit: #include <tuple> ?
rkc
2016/06/09 21:08:27
Done.
|
+ } |
+ EXPECT_EQ(GetValue(expected_value), std::get<1>(actual_notification)); |
+ EXPECT_EQ(expected_indicate_flag, std::get<2>(actual_notification)); |
+ } |
+ |
protected: |
base::WeakPtr<BluetoothLocalGattCharacteristic> read_characteristic_; |
base::WeakPtr<BluetoothLocalGattCharacteristic> write_characteristic_; |
@@ -157,64 +170,94 @@ TEST_F(BluetoothLocalGattCharacteristicTest, StartAndStopNotifications) { |
#if defined(OS_CHROMEOS) || defined(OS_LINUX) |
TEST_F(BluetoothLocalGattCharacteristicTest, SendNotifications) { |
+ BluetoothDevice* device = SimulateLowEnergyDevice(1); |
+ const uint64_t kNotifyValue = 0x7331ul; |
+ EXPECT_EQ(BluetoothLocalGattCharacteristic::NOTIFICATION_SUCCESS, |
+ notify_characteristic_->NotifyValueChanged( |
+ device, GetValue(kNotifyValue), false)); |
+ CheckNotification( |
+ device, kNotifyValue, false, |
+ LastNotifactionValueForCharacteristic(notify_characteristic_.get())); |
+ |
+ const uint64_t kIndicateValue = 0x1337ul; |
+ EXPECT_EQ(BluetoothLocalGattCharacteristic::NOTIFICATION_SUCCESS, |
+ indicate_characteristic_->NotifyValueChanged( |
+ device, GetValue(kIndicateValue), true)); |
+ CheckNotification( |
+ device, kIndicateValue, true, |
+ LastNotifactionValueForCharacteristic(indicate_characteristic_.get())); |
+} |
+#endif // defined(OS_CHROMEOS) || defined(OS_LINUX) |
+ |
+#if defined(OS_CHROMEOS) || defined(OS_LINUX) |
+TEST_F(BluetoothLocalGattCharacteristicTest, SendNotificationsToNullDevice) { |
const uint64_t kNotifyValue = 0x7331ul; |
EXPECT_EQ(BluetoothLocalGattCharacteristic::NOTIFICATION_SUCCESS, |
notify_characteristic_->NotifyValueChanged( |
nullptr, GetValue(kNotifyValue), false)); |
- EXPECT_EQ(kNotifyValue, GetInteger(LastNotifactionValueForCharacteristic( |
- notify_characteristic_.get()))); |
+ CheckNotification( |
+ nullptr, kNotifyValue, false, |
+ LastNotifactionValueForCharacteristic(notify_characteristic_.get())); |
const uint64_t kIndicateValue = 0x1337ul; |
EXPECT_EQ(BluetoothLocalGattCharacteristic::NOTIFICATION_SUCCESS, |
indicate_characteristic_->NotifyValueChanged( |
nullptr, GetValue(kIndicateValue), true)); |
- EXPECT_EQ(kIndicateValue, GetInteger(LastNotifactionValueForCharacteristic( |
- indicate_characteristic_.get()))); |
+ CheckNotification( |
+ nullptr, kIndicateValue, true, |
+ LastNotifactionValueForCharacteristic(indicate_characteristic_.get())); |
} |
#endif // defined(OS_CHROMEOS) || defined(OS_LINUX) |
#if defined(OS_CHROMEOS) || defined(OS_LINUX) |
TEST_F(BluetoothLocalGattCharacteristicTest, SendNotificationsWrongProperties) { |
+ BluetoothDevice* device = SimulateLowEnergyDevice(1); |
const uint64_t kNewValue = 0x3334ul; |
EXPECT_EQ(BluetoothLocalGattCharacteristic::NOTIFY_PROPERTY_NOT_SET, |
read_characteristic_->NotifyValueChanged( |
- nullptr, GetValue(kNewValue), false)); |
- EXPECT_NE(kNewValue, GetInteger(LastNotifactionValueForCharacteristic( |
- read_characteristic_.get()))); |
+ device, GetValue(kNewValue), false)); |
+ EXPECT_NE(kNewValue, |
+ GetInteger(std::get<1>(LastNotifactionValueForCharacteristic( |
+ read_characteristic_.get())))); |
EXPECT_EQ(BluetoothLocalGattCharacteristic::NOTIFY_PROPERTY_NOT_SET, |
write_characteristic_->NotifyValueChanged( |
- nullptr, GetValue(kNewValue), false)); |
- EXPECT_NE(kNewValue, GetInteger(LastNotifactionValueForCharacteristic( |
- write_characteristic_.get()))); |
+ device, GetValue(kNewValue), false)); |
+ EXPECT_NE(kNewValue, |
+ GetInteger(std::get<1>(LastNotifactionValueForCharacteristic( |
+ write_characteristic_.get())))); |
const uint64_t kNotifyValue = 0x7331ul; |
EXPECT_EQ(BluetoothLocalGattCharacteristic::INDICATE_PROPERTY_NOT_SET, |
notify_characteristic_->NotifyValueChanged( |
- nullptr, GetValue(kNotifyValue), true)); |
- EXPECT_NE(kNotifyValue, GetInteger(LastNotifactionValueForCharacteristic( |
- notify_characteristic_.get()))); |
+ device, GetValue(kNotifyValue), true)); |
+ EXPECT_NE(kNotifyValue, |
+ GetInteger(std::get<1>(LastNotifactionValueForCharacteristic( |
+ notify_characteristic_.get())))); |
const uint64_t kIndicateValue = 0x1337ul; |
EXPECT_EQ(BluetoothLocalGattCharacteristic::NOTIFY_PROPERTY_NOT_SET, |
indicate_characteristic_->NotifyValueChanged( |
- nullptr, GetValue(kIndicateValue), false)); |
- EXPECT_NE(kIndicateValue, GetInteger(LastNotifactionValueForCharacteristic( |
- indicate_characteristic_.get()))); |
+ device, GetValue(kIndicateValue), false)); |
+ EXPECT_NE(kIndicateValue, |
+ GetInteger(std::get<1>(LastNotifactionValueForCharacteristic( |
+ indicate_characteristic_.get())))); |
} |
#endif // defined(OS_CHROMEOS) || defined(OS_LINUX) |
#if defined(OS_CHROMEOS) || defined(OS_LINUX) |
TEST_F(BluetoothLocalGattCharacteristicTest, |
SendNotificationsServiceNotRegistered) { |
+ BluetoothDevice* device = SimulateLowEnergyDevice(1); |
service_->Unregister(GetCallback(Call::EXPECTED), |
GetGattErrorCallback(Call::NOT_EXPECTED)); |
const uint64_t kNotifyValue = 0x7331ul; |
EXPECT_EQ(BluetoothLocalGattCharacteristic::SERVICE_NOT_REGISTERED, |
notify_characteristic_->NotifyValueChanged( |
- nullptr, GetValue(kNotifyValue), false)); |
- EXPECT_NE(kNotifyValue, GetInteger(LastNotifactionValueForCharacteristic( |
- notify_characteristic_.get()))); |
+ device, GetValue(kNotifyValue), false)); |
+ EXPECT_NE(kNotifyValue, |
+ GetInteger(std::get<1>(LastNotifactionValueForCharacteristic( |
+ notify_characteristic_.get())))); |
} |
#endif // defined(OS_CHROMEOS) || defined(OS_LINUX) |