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

Unified Diff: device/bluetooth/bluetooth_local_gatt_characteristic_unittest.cc

Issue 1973703002: Implement //device/bt changes for notifications. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@notifications_dbus
Patch Set: Created 4 years, 7 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/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 dc9f9e8d99b6ccff0ae4765ac475c4c111a47c04..e7f4fcc8f29de3d5a50cdb6f69c1ff13ef07c321 100644
--- a/device/bluetooth/bluetooth_local_gatt_characteristic_unittest.cc
+++ b/device/bluetooth/bluetooth_local_gatt_characteristic_unittest.cc
@@ -27,14 +27,27 @@ class BluetoothLocalGattCharacteristicTest : public BluetoothGattServerTest {
device::BluetoothLocalGattCharacteristic::PROPERTY_RELIABLE_WRITE,
device::BluetoothLocalGattCharacteristic::Permissions(),
service_.get());
+ notify_characteristic_ = BluetoothLocalGattCharacteristic::Create(
+ BluetoothUUID(kTestUUIDGenericAttribute),
+ device::BluetoothLocalGattCharacteristic::PROPERTY_NOTIFY,
+ device::BluetoothLocalGattCharacteristic::Permissions(),
+ service_.get());
+ indicate_characteristic_ = BluetoothLocalGattCharacteristic::Create(
+ BluetoothUUID(kTestUUIDGenericAttribute),
+ device::BluetoothLocalGattCharacteristic::PROPERTY_INDICATE,
+ device::BluetoothLocalGattCharacteristic::Permissions(),
+ service_.get());
EXPECT_LT(0u, read_characteristic_->GetIdentifier().size());
EXPECT_LT(0u, write_characteristic_->GetIdentifier().size());
+ EXPECT_LT(0u, notify_characteristic_->GetIdentifier().size());
CompleteGattSetup();
}
protected:
base::WeakPtr<BluetoothLocalGattCharacteristic> read_characteristic_;
base::WeakPtr<BluetoothLocalGattCharacteristic> write_characteristic_;
+ base::WeakPtr<BluetoothLocalGattCharacteristic> notify_characteristic_;
+ base::WeakPtr<BluetoothLocalGattCharacteristic> indicate_characteristic_;
};
#if defined(OS_CHROMEOS) || defined(OS_LINUX)
@@ -108,4 +121,91 @@ TEST_F(BluetoothLocalGattCharacteristicTest,
}
#endif // defined(OS_CHROMEOS) || defined(OS_LINUX)
+#if defined(OS_CHROMEOS) || defined(OS_LINUX)
+TEST_F(BluetoothLocalGattCharacteristicTest, StartAndStopNotifications) {
+ EXPECT_FALSE(SimulateLocalGattCharacteristicNotificationsRequest(
+ service_.get(), read_characteristic_.get(), true));
+ EXPECT_FALSE(delegate_->NotificationStatusForCharacteristic(
+ read_characteristic_.get()));
+
+ EXPECT_FALSE(SimulateLocalGattCharacteristicNotificationsRequest(
+ service_.get(), write_characteristic_.get(), true));
+ EXPECT_FALSE(delegate_->NotificationStatusForCharacteristic(
+ write_characteristic_.get()));
+
+ EXPECT_TRUE(SimulateLocalGattCharacteristicNotificationsRequest(
+ service_.get(), notify_characteristic_.get(), true));
+ EXPECT_TRUE(delegate_->NotificationStatusForCharacteristic(
+ notify_characteristic_.get()));
+
+ EXPECT_TRUE(SimulateLocalGattCharacteristicNotificationsRequest(
+ service_.get(), notify_characteristic_.get(), false));
+ EXPECT_FALSE(delegate_->NotificationStatusForCharacteristic(
+ notify_characteristic_.get()));
+}
+#endif // defined(OS_CHROMEOS) || defined(OS_LINUX)
+
+#if defined(OS_CHROMEOS) || defined(OS_LINUX)
+TEST_F(BluetoothLocalGattCharacteristicTest, SendNotifications) {
+ const uint64_t kNotifyValue = 0x7331ul;
+ EXPECT_EQ(BluetoothLocalGattCharacteristic::NOTIFICATION_SUCCESS,
+ notify_characteristic_->NotifyValueChanged(GetValue(kNotifyValue),
+ false));
+ EXPECT_EQ(kNotifyValue, GetInteger(LastNotifactionValueForCharacteristic(
+ notify_characteristic_.get())));
+
+ const uint64_t kIndicateValue = 0x1337ul;
+ EXPECT_EQ(BluetoothLocalGattCharacteristic::NOTIFICATION_SUCCESS,
+ indicate_characteristic_->NotifyValueChanged(
+ GetValue(kIndicateValue), true));
+ EXPECT_EQ(kIndicateValue, GetInteger(LastNotifactionValueForCharacteristic(
+ indicate_characteristic_.get())));
+}
+#endif // defined(OS_CHROMEOS) || defined(OS_LINUX)
+
+#if defined(OS_CHROMEOS) || defined(OS_LINUX)
+TEST_F(BluetoothLocalGattCharacteristicTest, SendNotificationsWrongProperties) {
+ const uint64_t kNewValue = 0x3334ul;
+ EXPECT_EQ(
+ BluetoothLocalGattCharacteristic::NOTIFY_PROPERTY_NOT_SET,
+ read_characteristic_->NotifyValueChanged(GetValue(kNewValue), false));
+ EXPECT_NE(kNewValue, GetInteger(LastNotifactionValueForCharacteristic(
+ read_characteristic_.get())));
+
+ EXPECT_EQ(
+ BluetoothLocalGattCharacteristic::NOTIFY_PROPERTY_NOT_SET,
+ write_characteristic_->NotifyValueChanged(GetValue(kNewValue), false));
+ EXPECT_NE(kNewValue, GetInteger(LastNotifactionValueForCharacteristic(
+ write_characteristic_.get())));
+
+ const uint64_t kNotifyValue = 0x7331ul;
+ EXPECT_EQ(
+ BluetoothLocalGattCharacteristic::INDICATE_PROPERTY_NOT_SET,
+ notify_characteristic_->NotifyValueChanged(GetValue(kNotifyValue), true));
+ EXPECT_NE(kNotifyValue, GetInteger(LastNotifactionValueForCharacteristic(
+ notify_characteristic_.get())));
+
+ const uint64_t kIndicateValue = 0x1337ul;
+ EXPECT_EQ(BluetoothLocalGattCharacteristic::NOTIFY_PROPERTY_NOT_SET,
+ indicate_characteristic_->NotifyValueChanged(
+ GetValue(kIndicateValue), false));
+ EXPECT_NE(kIndicateValue, GetInteger(LastNotifactionValueForCharacteristic(
+ indicate_characteristic_.get())));
+}
+#endif // defined(OS_CHROMEOS) || defined(OS_LINUX)
+
+#if defined(OS_CHROMEOS) || defined(OS_LINUX)
+TEST_F(BluetoothLocalGattCharacteristicTest,
+ SendNotificationsServiceNotRegistered) {
+ service_->Unregister(GetCallback(Call::EXPECTED),
+ GetGattErrorCallback(Call::NOT_EXPECTED));
+ const uint64_t kNotifyValue = 0x7331ul;
+ EXPECT_EQ(BluetoothLocalGattCharacteristic::SERVICE_NOT_REGISTERED,
+ notify_characteristic_->NotifyValueChanged(GetValue(kNotifyValue),
+ false));
+ EXPECT_NE(kNotifyValue, GetInteger(LastNotifactionValueForCharacteristic(
+ notify_characteristic_.get())));
+}
+#endif // defined(OS_CHROMEOS) || defined(OS_LINUX)
+
} // namespace device
« no previous file with comments | « device/bluetooth/bluetooth_local_gatt_characteristic.h ('k') | device/bluetooth/bluetooth_local_gatt_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698