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

Side by Side Diff: device/bluetooth/bluetooth_local_gatt_characteristic_unittest.cc

Issue 2039773005: Add support in Chrome to send notifications to a specific device. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
(...skipping 28 matching lines...) Expand all
39 BluetoothUUID(kTestUUIDGenericAttribute), 39 BluetoothUUID(kTestUUIDGenericAttribute),
40 device::BluetoothLocalGattCharacteristic::PROPERTY_INDICATE, 40 device::BluetoothLocalGattCharacteristic::PROPERTY_INDICATE,
41 device::BluetoothLocalGattCharacteristic::Permissions(), 41 device::BluetoothLocalGattCharacteristic::Permissions(),
42 service_.get()); 42 service_.get());
43 EXPECT_LT(0u, read_characteristic_->GetIdentifier().size()); 43 EXPECT_LT(0u, read_characteristic_->GetIdentifier().size());
44 EXPECT_LT(0u, write_characteristic_->GetIdentifier().size()); 44 EXPECT_LT(0u, write_characteristic_->GetIdentifier().size());
45 EXPECT_LT(0u, notify_characteristic_->GetIdentifier().size()); 45 EXPECT_LT(0u, notify_characteristic_->GetIdentifier().size());
46 CompleteGattSetup(); 46 CompleteGattSetup();
47 } 47 }
48 48
49 void CheckNotification(
50 const BluetoothDevice* expected_device,
51 uint64_t expected_value,
52 bool expected_indicate_flag,
53 const BluetoothTestBase::NotificationType& actual_notification) {
54 if (expected_device) {
55 EXPECT_EQ(expected_device->GetIdentifier(),
56 std::get<0>(actual_notification));
xiyuan 2016/06/06 21:49:29 nit: #include <tuple> ?
rkc 2016/06/09 21:08:27 Done.
57 }
58 EXPECT_EQ(GetValue(expected_value), std::get<1>(actual_notification));
59 EXPECT_EQ(expected_indicate_flag, std::get<2>(actual_notification));
60 }
61
49 protected: 62 protected:
50 base::WeakPtr<BluetoothLocalGattCharacteristic> read_characteristic_; 63 base::WeakPtr<BluetoothLocalGattCharacteristic> read_characteristic_;
51 base::WeakPtr<BluetoothLocalGattCharacteristic> write_characteristic_; 64 base::WeakPtr<BluetoothLocalGattCharacteristic> write_characteristic_;
52 base::WeakPtr<BluetoothLocalGattCharacteristic> notify_characteristic_; 65 base::WeakPtr<BluetoothLocalGattCharacteristic> notify_characteristic_;
53 base::WeakPtr<BluetoothLocalGattCharacteristic> indicate_characteristic_; 66 base::WeakPtr<BluetoothLocalGattCharacteristic> indicate_characteristic_;
54 BluetoothDevice* device_; 67 BluetoothDevice* device_;
55 }; 68 };
56 69
57 #if defined(OS_CHROMEOS) || defined(OS_LINUX) 70 #if defined(OS_CHROMEOS) || defined(OS_LINUX)
58 TEST_F(BluetoothLocalGattCharacteristicTest, ReadLocalCharacteristicValue) { 71 TEST_F(BluetoothLocalGattCharacteristicTest, ReadLocalCharacteristicValue) {
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 163
151 EXPECT_TRUE(SimulateLocalGattCharacteristicNotificationsRequest( 164 EXPECT_TRUE(SimulateLocalGattCharacteristicNotificationsRequest(
152 notify_characteristic_.get(), false)); 165 notify_characteristic_.get(), false));
153 EXPECT_FALSE(delegate_->NotificationStatusForCharacteristic( 166 EXPECT_FALSE(delegate_->NotificationStatusForCharacteristic(
154 notify_characteristic_.get())); 167 notify_characteristic_.get()));
155 } 168 }
156 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX) 169 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX)
157 170
158 #if defined(OS_CHROMEOS) || defined(OS_LINUX) 171 #if defined(OS_CHROMEOS) || defined(OS_LINUX)
159 TEST_F(BluetoothLocalGattCharacteristicTest, SendNotifications) { 172 TEST_F(BluetoothLocalGattCharacteristicTest, SendNotifications) {
173 BluetoothDevice* device = SimulateLowEnergyDevice(1);
174 const uint64_t kNotifyValue = 0x7331ul;
175 EXPECT_EQ(BluetoothLocalGattCharacteristic::NOTIFICATION_SUCCESS,
176 notify_characteristic_->NotifyValueChanged(
177 device, GetValue(kNotifyValue), false));
178 CheckNotification(
179 device, kNotifyValue, false,
180 LastNotifactionValueForCharacteristic(notify_characteristic_.get()));
181
182 const uint64_t kIndicateValue = 0x1337ul;
183 EXPECT_EQ(BluetoothLocalGattCharacteristic::NOTIFICATION_SUCCESS,
184 indicate_characteristic_->NotifyValueChanged(
185 device, GetValue(kIndicateValue), true));
186 CheckNotification(
187 device, kIndicateValue, true,
188 LastNotifactionValueForCharacteristic(indicate_characteristic_.get()));
189 }
190 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX)
191
192 #if defined(OS_CHROMEOS) || defined(OS_LINUX)
193 TEST_F(BluetoothLocalGattCharacteristicTest, SendNotificationsToNullDevice) {
160 const uint64_t kNotifyValue = 0x7331ul; 194 const uint64_t kNotifyValue = 0x7331ul;
161 EXPECT_EQ(BluetoothLocalGattCharacteristic::NOTIFICATION_SUCCESS, 195 EXPECT_EQ(BluetoothLocalGattCharacteristic::NOTIFICATION_SUCCESS,
162 notify_characteristic_->NotifyValueChanged( 196 notify_characteristic_->NotifyValueChanged(
163 nullptr, GetValue(kNotifyValue), false)); 197 nullptr, GetValue(kNotifyValue), false));
164 EXPECT_EQ(kNotifyValue, GetInteger(LastNotifactionValueForCharacteristic( 198 CheckNotification(
165 notify_characteristic_.get()))); 199 nullptr, kNotifyValue, false,
200 LastNotifactionValueForCharacteristic(notify_characteristic_.get()));
166 201
167 const uint64_t kIndicateValue = 0x1337ul; 202 const uint64_t kIndicateValue = 0x1337ul;
168 EXPECT_EQ(BluetoothLocalGattCharacteristic::NOTIFICATION_SUCCESS, 203 EXPECT_EQ(BluetoothLocalGattCharacteristic::NOTIFICATION_SUCCESS,
169 indicate_characteristic_->NotifyValueChanged( 204 indicate_characteristic_->NotifyValueChanged(
170 nullptr, GetValue(kIndicateValue), true)); 205 nullptr, GetValue(kIndicateValue), true));
171 EXPECT_EQ(kIndicateValue, GetInteger(LastNotifactionValueForCharacteristic( 206 CheckNotification(
172 indicate_characteristic_.get()))); 207 nullptr, kIndicateValue, true,
208 LastNotifactionValueForCharacteristic(indicate_characteristic_.get()));
173 } 209 }
174 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX) 210 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX)
175 211
176 #if defined(OS_CHROMEOS) || defined(OS_LINUX) 212 #if defined(OS_CHROMEOS) || defined(OS_LINUX)
177 TEST_F(BluetoothLocalGattCharacteristicTest, SendNotificationsWrongProperties) { 213 TEST_F(BluetoothLocalGattCharacteristicTest, SendNotificationsWrongProperties) {
214 BluetoothDevice* device = SimulateLowEnergyDevice(1);
178 const uint64_t kNewValue = 0x3334ul; 215 const uint64_t kNewValue = 0x3334ul;
179 EXPECT_EQ(BluetoothLocalGattCharacteristic::NOTIFY_PROPERTY_NOT_SET, 216 EXPECT_EQ(BluetoothLocalGattCharacteristic::NOTIFY_PROPERTY_NOT_SET,
180 read_characteristic_->NotifyValueChanged( 217 read_characteristic_->NotifyValueChanged(
181 nullptr, GetValue(kNewValue), false)); 218 device, GetValue(kNewValue), false));
182 EXPECT_NE(kNewValue, GetInteger(LastNotifactionValueForCharacteristic( 219 EXPECT_NE(kNewValue,
183 read_characteristic_.get()))); 220 GetInteger(std::get<1>(LastNotifactionValueForCharacteristic(
221 read_characteristic_.get()))));
184 222
185 EXPECT_EQ(BluetoothLocalGattCharacteristic::NOTIFY_PROPERTY_NOT_SET, 223 EXPECT_EQ(BluetoothLocalGattCharacteristic::NOTIFY_PROPERTY_NOT_SET,
186 write_characteristic_->NotifyValueChanged( 224 write_characteristic_->NotifyValueChanged(
187 nullptr, GetValue(kNewValue), false)); 225 device, GetValue(kNewValue), false));
188 EXPECT_NE(kNewValue, GetInteger(LastNotifactionValueForCharacteristic( 226 EXPECT_NE(kNewValue,
189 write_characteristic_.get()))); 227 GetInteger(std::get<1>(LastNotifactionValueForCharacteristic(
228 write_characteristic_.get()))));
190 229
191 const uint64_t kNotifyValue = 0x7331ul; 230 const uint64_t kNotifyValue = 0x7331ul;
192 EXPECT_EQ(BluetoothLocalGattCharacteristic::INDICATE_PROPERTY_NOT_SET, 231 EXPECT_EQ(BluetoothLocalGattCharacteristic::INDICATE_PROPERTY_NOT_SET,
193 notify_characteristic_->NotifyValueChanged( 232 notify_characteristic_->NotifyValueChanged(
194 nullptr, GetValue(kNotifyValue), true)); 233 device, GetValue(kNotifyValue), true));
195 EXPECT_NE(kNotifyValue, GetInteger(LastNotifactionValueForCharacteristic( 234 EXPECT_NE(kNotifyValue,
196 notify_characteristic_.get()))); 235 GetInteger(std::get<1>(LastNotifactionValueForCharacteristic(
236 notify_characteristic_.get()))));
197 237
198 const uint64_t kIndicateValue = 0x1337ul; 238 const uint64_t kIndicateValue = 0x1337ul;
199 EXPECT_EQ(BluetoothLocalGattCharacteristic::NOTIFY_PROPERTY_NOT_SET, 239 EXPECT_EQ(BluetoothLocalGattCharacteristic::NOTIFY_PROPERTY_NOT_SET,
200 indicate_characteristic_->NotifyValueChanged( 240 indicate_characteristic_->NotifyValueChanged(
201 nullptr, GetValue(kIndicateValue), false)); 241 device, GetValue(kIndicateValue), false));
202 EXPECT_NE(kIndicateValue, GetInteger(LastNotifactionValueForCharacteristic( 242 EXPECT_NE(kIndicateValue,
203 indicate_characteristic_.get()))); 243 GetInteger(std::get<1>(LastNotifactionValueForCharacteristic(
244 indicate_characteristic_.get()))));
204 } 245 }
205 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX) 246 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX)
206 247
207 #if defined(OS_CHROMEOS) || defined(OS_LINUX) 248 #if defined(OS_CHROMEOS) || defined(OS_LINUX)
208 TEST_F(BluetoothLocalGattCharacteristicTest, 249 TEST_F(BluetoothLocalGattCharacteristicTest,
209 SendNotificationsServiceNotRegistered) { 250 SendNotificationsServiceNotRegistered) {
251 BluetoothDevice* device = SimulateLowEnergyDevice(1);
210 service_->Unregister(GetCallback(Call::EXPECTED), 252 service_->Unregister(GetCallback(Call::EXPECTED),
211 GetGattErrorCallback(Call::NOT_EXPECTED)); 253 GetGattErrorCallback(Call::NOT_EXPECTED));
212 const uint64_t kNotifyValue = 0x7331ul; 254 const uint64_t kNotifyValue = 0x7331ul;
213 EXPECT_EQ(BluetoothLocalGattCharacteristic::SERVICE_NOT_REGISTERED, 255 EXPECT_EQ(BluetoothLocalGattCharacteristic::SERVICE_NOT_REGISTERED,
214 notify_characteristic_->NotifyValueChanged( 256 notify_characteristic_->NotifyValueChanged(
215 nullptr, GetValue(kNotifyValue), false)); 257 device, GetValue(kNotifyValue), false));
216 EXPECT_NE(kNotifyValue, GetInteger(LastNotifactionValueForCharacteristic( 258 EXPECT_NE(kNotifyValue,
217 notify_characteristic_.get()))); 259 GetInteger(std::get<1>(LastNotifactionValueForCharacteristic(
260 notify_characteristic_.get()))));
218 } 261 }
219 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX) 262 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX)
220 263
221 } // namespace device 264 } // namespace device
OLDNEW
« no previous file with comments | « no previous file | device/bluetooth/bluez/bluetooth_adapter_bluez.h » ('j') | device/bluetooth/test/bluetooth_test.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698