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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/memory/weak_ptr.h" 5 #include "base/memory/weak_ptr.h"
6 #include "device/bluetooth/bluetooth_local_gatt_characteristic.h" 6 #include "device/bluetooth/bluetooth_local_gatt_characteristic.h"
7 #include "device/bluetooth/test/bluetooth_gatt_server_test.h" 7 #include "device/bluetooth/test/bluetooth_gatt_server_test.h"
8 #include "device/bluetooth/test/bluetooth_test.h" 8 #include "device/bluetooth/test/bluetooth_test.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
11 namespace device { 11 namespace device {
12 12
13 class BluetoothLocalGattCharacteristicTest : public BluetoothGattServerTest { 13 class BluetoothLocalGattCharacteristicTest : public BluetoothGattServerTest {
14 public: 14 public:
15 void SetUp() override { 15 void SetUp() override {
16 BluetoothGattServerTest::SetUp(); 16 BluetoothGattServerTest::SetUp();
17 17
18 StartGattSetup(); 18 StartGattSetup();
19 read_characteristic_ = BluetoothLocalGattCharacteristic::Create( 19 read_characteristic_ = BluetoothLocalGattCharacteristic::Create(
20 BluetoothUUID(kTestUUIDGenericAttribute), 20 BluetoothUUID(kTestUUIDGenericAttribute),
21 device::BluetoothLocalGattCharacteristic:: 21 device::BluetoothLocalGattCharacteristic::
22 PROPERTY_READ_ENCRYPTED_AUTHENTICATED, 22 PROPERTY_READ_ENCRYPTED_AUTHENTICATED,
23 device::BluetoothLocalGattCharacteristic::Permissions(), 23 device::BluetoothLocalGattCharacteristic::Permissions(),
24 service_.get()); 24 service_.get());
25 write_characteristic_ = BluetoothLocalGattCharacteristic::Create( 25 write_characteristic_ = BluetoothLocalGattCharacteristic::Create(
26 BluetoothUUID(kTestUUIDGenericAttribute), 26 BluetoothUUID(kTestUUIDGenericAttribute),
27 device::BluetoothLocalGattCharacteristic::PROPERTY_RELIABLE_WRITE, 27 device::BluetoothLocalGattCharacteristic::PROPERTY_RELIABLE_WRITE,
28 device::BluetoothLocalGattCharacteristic::Permissions(), 28 device::BluetoothLocalGattCharacteristic::Permissions(),
29 service_.get()); 29 service_.get());
30 notify_characteristic_ = BluetoothLocalGattCharacteristic::Create(
31 BluetoothUUID(kTestUUIDGenericAttribute),
32 device::BluetoothLocalGattCharacteristic::PROPERTY_NOTIFY,
33 device::BluetoothLocalGattCharacteristic::Permissions(),
34 service_.get());
35 indicate_characteristic_ = BluetoothLocalGattCharacteristic::Create(
36 BluetoothUUID(kTestUUIDGenericAttribute),
37 device::BluetoothLocalGattCharacteristic::PROPERTY_INDICATE,
38 device::BluetoothLocalGattCharacteristic::Permissions(),
39 service_.get());
30 EXPECT_LT(0u, read_characteristic_->GetIdentifier().size()); 40 EXPECT_LT(0u, read_characteristic_->GetIdentifier().size());
31 EXPECT_LT(0u, write_characteristic_->GetIdentifier().size()); 41 EXPECT_LT(0u, write_characteristic_->GetIdentifier().size());
42 EXPECT_LT(0u, notify_characteristic_->GetIdentifier().size());
32 CompleteGattSetup(); 43 CompleteGattSetup();
33 } 44 }
34 45
35 protected: 46 protected:
36 base::WeakPtr<BluetoothLocalGattCharacteristic> read_characteristic_; 47 base::WeakPtr<BluetoothLocalGattCharacteristic> read_characteristic_;
37 base::WeakPtr<BluetoothLocalGattCharacteristic> write_characteristic_; 48 base::WeakPtr<BluetoothLocalGattCharacteristic> write_characteristic_;
49 base::WeakPtr<BluetoothLocalGattCharacteristic> notify_characteristic_;
50 base::WeakPtr<BluetoothLocalGattCharacteristic> indicate_characteristic_;
38 }; 51 };
39 52
40 #if defined(OS_CHROMEOS) || defined(OS_LINUX) 53 #if defined(OS_CHROMEOS) || defined(OS_LINUX)
41 TEST_F(BluetoothLocalGattCharacteristicTest, ReadLocalCharacteristicValue) { 54 TEST_F(BluetoothLocalGattCharacteristicTest, ReadLocalCharacteristicValue) {
42 delegate_->value_to_write_ = 0x1337; 55 delegate_->value_to_write_ = 0x1337;
43 SimulateLocalGattCharacteristicValueReadRequest( 56 SimulateLocalGattCharacteristicValueReadRequest(
44 service_.get(), read_characteristic_.get(), 57 service_.get(), read_characteristic_.get(),
45 GetReadValueCallback(Call::EXPECTED), GetCallback(Call::NOT_EXPECTED)); 58 GetReadValueCallback(Call::EXPECTED), GetCallback(Call::NOT_EXPECTED));
46 59
47 EXPECT_EQ(delegate_->value_to_write_, GetInteger(last_read_value_)); 60 EXPECT_EQ(delegate_->value_to_write_, GetInteger(last_read_value_));
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 WriteLocalCharacteristicValueWrongPermission) { 114 WriteLocalCharacteristicValueWrongPermission) {
102 const uint64_t kValueToWrite = 0x7331ul; 115 const uint64_t kValueToWrite = 0x7331ul;
103 SimulateLocalGattCharacteristicValueWriteRequest( 116 SimulateLocalGattCharacteristicValueWriteRequest(
104 service_.get(), read_characteristic_.get(), GetValue(kValueToWrite), 117 service_.get(), read_characteristic_.get(), GetValue(kValueToWrite),
105 GetCallback(Call::NOT_EXPECTED), GetCallback(Call::EXPECTED)); 118 GetCallback(Call::NOT_EXPECTED), GetCallback(Call::EXPECTED));
106 119
107 EXPECT_NE(kValueToWrite, delegate_->last_written_value_); 120 EXPECT_NE(kValueToWrite, delegate_->last_written_value_);
108 } 121 }
109 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX) 122 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX)
110 123
124 #if defined(OS_CHROMEOS) || defined(OS_LINUX)
125 TEST_F(BluetoothLocalGattCharacteristicTest, StartAndStopNotifications) {
126 EXPECT_FALSE(SimulateLocalGattCharacteristicNotificationsRequest(
127 service_.get(), read_characteristic_.get(), true));
128 EXPECT_FALSE(delegate_->NotificationStatusForCharacteristic(
129 read_characteristic_.get()));
130
131 EXPECT_FALSE(SimulateLocalGattCharacteristicNotificationsRequest(
132 service_.get(), write_characteristic_.get(), true));
133 EXPECT_FALSE(delegate_->NotificationStatusForCharacteristic(
134 write_characteristic_.get()));
135
136 EXPECT_TRUE(SimulateLocalGattCharacteristicNotificationsRequest(
137 service_.get(), notify_characteristic_.get(), true));
138 EXPECT_TRUE(delegate_->NotificationStatusForCharacteristic(
139 notify_characteristic_.get()));
140
141 EXPECT_TRUE(SimulateLocalGattCharacteristicNotificationsRequest(
142 service_.get(), notify_characteristic_.get(), false));
143 EXPECT_FALSE(delegate_->NotificationStatusForCharacteristic(
144 notify_characteristic_.get()));
145 }
146 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX)
147
148 #if defined(OS_CHROMEOS) || defined(OS_LINUX)
149 TEST_F(BluetoothLocalGattCharacteristicTest, SendNotifications) {
150 const uint64_t kNotifyValue = 0x7331ul;
151 EXPECT_EQ(BluetoothLocalGattCharacteristic::NOTIFICATION_SUCCESS,
152 notify_characteristic_->NotifyValueChanged(GetValue(kNotifyValue),
153 false));
154 EXPECT_EQ(kNotifyValue, GetInteger(LastNotifactionValueForCharacteristic(
155 notify_characteristic_.get())));
156
157 const uint64_t kIndicateValue = 0x1337ul;
158 EXPECT_EQ(BluetoothLocalGattCharacteristic::NOTIFICATION_SUCCESS,
159 indicate_characteristic_->NotifyValueChanged(
160 GetValue(kIndicateValue), true));
161 EXPECT_EQ(kIndicateValue, GetInteger(LastNotifactionValueForCharacteristic(
162 indicate_characteristic_.get())));
163 }
164 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX)
165
166 #if defined(OS_CHROMEOS) || defined(OS_LINUX)
167 TEST_F(BluetoothLocalGattCharacteristicTest, SendNotificationsWrongProperties) {
168 const uint64_t kNewValue = 0x3334ul;
169 EXPECT_EQ(
170 BluetoothLocalGattCharacteristic::NOTIFY_PROPERTY_NOT_SET,
171 read_characteristic_->NotifyValueChanged(GetValue(kNewValue), false));
172 EXPECT_NE(kNewValue, GetInteger(LastNotifactionValueForCharacteristic(
173 read_characteristic_.get())));
174
175 EXPECT_EQ(
176 BluetoothLocalGattCharacteristic::NOTIFY_PROPERTY_NOT_SET,
177 write_characteristic_->NotifyValueChanged(GetValue(kNewValue), false));
178 EXPECT_NE(kNewValue, GetInteger(LastNotifactionValueForCharacteristic(
179 write_characteristic_.get())));
180
181 const uint64_t kNotifyValue = 0x7331ul;
182 EXPECT_EQ(
183 BluetoothLocalGattCharacteristic::INDICATE_PROPERTY_NOT_SET,
184 notify_characteristic_->NotifyValueChanged(GetValue(kNotifyValue), true));
185 EXPECT_NE(kNotifyValue, GetInteger(LastNotifactionValueForCharacteristic(
186 notify_characteristic_.get())));
187
188 const uint64_t kIndicateValue = 0x1337ul;
189 EXPECT_EQ(BluetoothLocalGattCharacteristic::NOTIFY_PROPERTY_NOT_SET,
190 indicate_characteristic_->NotifyValueChanged(
191 GetValue(kIndicateValue), false));
192 EXPECT_NE(kIndicateValue, GetInteger(LastNotifactionValueForCharacteristic(
193 indicate_characteristic_.get())));
194 }
195 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX)
196
197 #if defined(OS_CHROMEOS) || defined(OS_LINUX)
198 TEST_F(BluetoothLocalGattCharacteristicTest,
199 SendNotificationsServiceNotRegistered) {
200 service_->Unregister(GetCallback(Call::EXPECTED),
201 GetGattErrorCallback(Call::NOT_EXPECTED));
202 const uint64_t kNotifyValue = 0x7331ul;
203 EXPECT_EQ(BluetoothLocalGattCharacteristic::SERVICE_NOT_REGISTERED,
204 notify_characteristic_->NotifyValueChanged(GetValue(kNotifyValue),
205 false));
206 EXPECT_NE(kNotifyValue, GetInteger(LastNotifactionValueForCharacteristic(
207 notify_characteristic_.get())));
208 }
209 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX)
210
111 } // namespace device 211 } // namespace device
OLDNEW
« 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