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

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

Issue 1979163002: Add DBus plumbing and tests for sending devices with ATT read/writes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@devices
Patch Set: gyp fix 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 // We will need this device to use with simulating read/write attribute
20 // value events.
21 device_ = SimulateLowEnergyDevice(1);
19 read_characteristic_ = BluetoothLocalGattCharacteristic::Create( 22 read_characteristic_ = BluetoothLocalGattCharacteristic::Create(
20 BluetoothUUID(kTestUUIDGenericAttribute), 23 BluetoothUUID(kTestUUIDGenericAttribute),
21 device::BluetoothLocalGattCharacteristic:: 24 device::BluetoothLocalGattCharacteristic::
22 PROPERTY_READ_ENCRYPTED_AUTHENTICATED, 25 PROPERTY_READ_ENCRYPTED_AUTHENTICATED,
23 device::BluetoothLocalGattCharacteristic::Permissions(), 26 device::BluetoothLocalGattCharacteristic::Permissions(),
24 service_.get()); 27 service_.get());
25 write_characteristic_ = BluetoothLocalGattCharacteristic::Create( 28 write_characteristic_ = BluetoothLocalGattCharacteristic::Create(
26 BluetoothUUID(kTestUUIDGenericAttribute), 29 BluetoothUUID(kTestUUIDGenericAttribute),
27 device::BluetoothLocalGattCharacteristic::PROPERTY_RELIABLE_WRITE, 30 device::BluetoothLocalGattCharacteristic::PROPERTY_RELIABLE_WRITE,
28 device::BluetoothLocalGattCharacteristic::Permissions(), 31 device::BluetoothLocalGattCharacteristic::Permissions(),
(...skipping 12 matching lines...) Expand all
41 EXPECT_LT(0u, write_characteristic_->GetIdentifier().size()); 44 EXPECT_LT(0u, write_characteristic_->GetIdentifier().size());
42 EXPECT_LT(0u, notify_characteristic_->GetIdentifier().size()); 45 EXPECT_LT(0u, notify_characteristic_->GetIdentifier().size());
43 CompleteGattSetup(); 46 CompleteGattSetup();
44 } 47 }
45 48
46 protected: 49 protected:
47 base::WeakPtr<BluetoothLocalGattCharacteristic> read_characteristic_; 50 base::WeakPtr<BluetoothLocalGattCharacteristic> read_characteristic_;
48 base::WeakPtr<BluetoothLocalGattCharacteristic> write_characteristic_; 51 base::WeakPtr<BluetoothLocalGattCharacteristic> write_characteristic_;
49 base::WeakPtr<BluetoothLocalGattCharacteristic> notify_characteristic_; 52 base::WeakPtr<BluetoothLocalGattCharacteristic> notify_characteristic_;
50 base::WeakPtr<BluetoothLocalGattCharacteristic> indicate_characteristic_; 53 base::WeakPtr<BluetoothLocalGattCharacteristic> indicate_characteristic_;
54 BluetoothDevice* device_;
51 }; 55 };
52 56
53 #if defined(OS_CHROMEOS) || defined(OS_LINUX) 57 #if defined(OS_CHROMEOS) || defined(OS_LINUX)
54 TEST_F(BluetoothLocalGattCharacteristicTest, ReadLocalCharacteristicValue) { 58 TEST_F(BluetoothLocalGattCharacteristicTest, ReadLocalCharacteristicValue) {
55 delegate_->value_to_write_ = 0x1337; 59 delegate_->value_to_write_ = 0x1337;
56 SimulateLocalGattCharacteristicValueReadRequest( 60 SimulateLocalGattCharacteristicValueReadRequest(
57 read_characteristic_.get(), GetReadValueCallback(Call::EXPECTED), 61 device_, read_characteristic_.get(), GetReadValueCallback(Call::EXPECTED),
58 GetCallback(Call::NOT_EXPECTED)); 62 GetCallback(Call::NOT_EXPECTED));
59 63
60 EXPECT_EQ(delegate_->value_to_write_, GetInteger(last_read_value_)); 64 EXPECT_EQ(delegate_->value_to_write_, GetInteger(last_read_value_));
65 EXPECT_EQ(device_->GetIdentifier(), delegate_->last_seen_device_);
61 } 66 }
62 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX) 67 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX)
63 68
64 #if defined(OS_CHROMEOS) || defined(OS_LINUX) 69 #if defined(OS_CHROMEOS) || defined(OS_LINUX)
65 TEST_F(BluetoothLocalGattCharacteristicTest, WriteLocalCharacteristicValue) { 70 TEST_F(BluetoothLocalGattCharacteristicTest, WriteLocalCharacteristicValue) {
66 const uint64_t kValueToWrite = 0x7331ul; 71 const uint64_t kValueToWrite = 0x7331ul;
67 SimulateLocalGattCharacteristicValueWriteRequest( 72 SimulateLocalGattCharacteristicValueWriteRequest(
68 write_characteristic_.get(), GetValue(kValueToWrite), 73 device_, write_characteristic_.get(), GetValue(kValueToWrite),
69 GetCallback(Call::EXPECTED), GetCallback(Call::NOT_EXPECTED)); 74 GetCallback(Call::EXPECTED), GetCallback(Call::NOT_EXPECTED));
70 75
71 EXPECT_EQ(kValueToWrite, delegate_->last_written_value_); 76 EXPECT_EQ(kValueToWrite, delegate_->last_written_value_);
77 EXPECT_EQ(device_->GetIdentifier(), delegate_->last_seen_device_);
72 } 78 }
73 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX) 79 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX)
74 80
75 #if defined(OS_CHROMEOS) || defined(OS_LINUX) 81 #if defined(OS_CHROMEOS) || defined(OS_LINUX)
76 TEST_F(BluetoothLocalGattCharacteristicTest, ReadLocalCharacteristicValueFail) { 82 TEST_F(BluetoothLocalGattCharacteristicTest, ReadLocalCharacteristicValueFail) {
77 delegate_->value_to_write_ = 0x1337; 83 delegate_->value_to_write_ = 0x1337;
78 delegate_->should_fail_ = true; 84 delegate_->should_fail_ = true;
79 SimulateLocalGattCharacteristicValueReadRequest( 85 SimulateLocalGattCharacteristicValueReadRequest(
80 read_characteristic_.get(), GetReadValueCallback(Call::NOT_EXPECTED), 86 device_, read_characteristic_.get(),
81 GetCallback(Call::EXPECTED)); 87 GetReadValueCallback(Call::NOT_EXPECTED), GetCallback(Call::EXPECTED));
82 88
83 EXPECT_NE(delegate_->value_to_write_, GetInteger(last_read_value_)); 89 EXPECT_NE(delegate_->value_to_write_, GetInteger(last_read_value_));
90 EXPECT_NE(device_->GetIdentifier(), delegate_->last_seen_device_);
84 } 91 }
85 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX) 92 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX)
86 93
87 #if defined(OS_CHROMEOS) || defined(OS_LINUX) 94 #if defined(OS_CHROMEOS) || defined(OS_LINUX)
88 TEST_F(BluetoothLocalGattCharacteristicTest, 95 TEST_F(BluetoothLocalGattCharacteristicTest,
89 ReadLocalCharacteristicValueWrongPermission) { 96 ReadLocalCharacteristicValueWrongPermission) {
90 delegate_->value_to_write_ = 0x1337; 97 delegate_->value_to_write_ = 0x1337;
91 SimulateLocalGattCharacteristicValueReadRequest( 98 SimulateLocalGattCharacteristicValueReadRequest(
92 write_characteristic_.get(), GetReadValueCallback(Call::NOT_EXPECTED), 99 device_, write_characteristic_.get(),
93 GetCallback(Call::EXPECTED)); 100 GetReadValueCallback(Call::NOT_EXPECTED), GetCallback(Call::EXPECTED));
94 101
95 EXPECT_NE(delegate_->value_to_write_, GetInteger(last_read_value_)); 102 EXPECT_NE(delegate_->value_to_write_, GetInteger(last_read_value_));
103 EXPECT_NE(device_->GetIdentifier(), delegate_->last_seen_device_);
96 } 104 }
97 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX) 105 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX)
98 106
99 #if defined(OS_CHROMEOS) || defined(OS_LINUX) 107 #if defined(OS_CHROMEOS) || defined(OS_LINUX)
100 TEST_F(BluetoothLocalGattCharacteristicTest, 108 TEST_F(BluetoothLocalGattCharacteristicTest,
101 WriteLocalCharacteristicValueFail) { 109 WriteLocalCharacteristicValueFail) {
102 const uint64_t kValueToWrite = 0x7331ul; 110 const uint64_t kValueToWrite = 0x7331ul;
103 delegate_->should_fail_ = true; 111 delegate_->should_fail_ = true;
104 SimulateLocalGattCharacteristicValueWriteRequest( 112 SimulateLocalGattCharacteristicValueWriteRequest(
105 write_characteristic_.get(), GetValue(kValueToWrite), 113 device_, write_characteristic_.get(), GetValue(kValueToWrite),
106 GetCallback(Call::NOT_EXPECTED), GetCallback(Call::EXPECTED)); 114 GetCallback(Call::NOT_EXPECTED), GetCallback(Call::EXPECTED));
107 115
108 EXPECT_NE(kValueToWrite, delegate_->last_written_value_); 116 EXPECT_NE(kValueToWrite, delegate_->last_written_value_);
117 EXPECT_NE(device_->GetIdentifier(), delegate_->last_seen_device_);
109 } 118 }
110 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX) 119 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX)
111 120
112 #if defined(OS_CHROMEOS) || defined(OS_LINUX) 121 #if defined(OS_CHROMEOS) || defined(OS_LINUX)
113 TEST_F(BluetoothLocalGattCharacteristicTest, 122 TEST_F(BluetoothLocalGattCharacteristicTest,
114 WriteLocalCharacteristicValueWrongPermission) { 123 WriteLocalCharacteristicValueWrongPermission) {
115 const uint64_t kValueToWrite = 0x7331ul; 124 const uint64_t kValueToWrite = 0x7331ul;
116 SimulateLocalGattCharacteristicValueWriteRequest( 125 SimulateLocalGattCharacteristicValueWriteRequest(
117 read_characteristic_.get(), GetValue(kValueToWrite), 126 device_, read_characteristic_.get(), GetValue(kValueToWrite),
118 GetCallback(Call::NOT_EXPECTED), GetCallback(Call::EXPECTED)); 127 GetCallback(Call::NOT_EXPECTED), GetCallback(Call::EXPECTED));
119 128
120 EXPECT_NE(kValueToWrite, delegate_->last_written_value_); 129 EXPECT_NE(kValueToWrite, delegate_->last_written_value_);
130 EXPECT_NE(device_->GetIdentifier(), delegate_->last_seen_device_);
121 } 131 }
122 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX) 132 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX)
123 133
124 #if defined(OS_CHROMEOS) || defined(OS_LINUX) 134 #if defined(OS_CHROMEOS) || defined(OS_LINUX)
125 TEST_F(BluetoothLocalGattCharacteristicTest, StartAndStopNotifications) { 135 TEST_F(BluetoothLocalGattCharacteristicTest, StartAndStopNotifications) {
126 EXPECT_FALSE(SimulateLocalGattCharacteristicNotificationsRequest( 136 EXPECT_FALSE(SimulateLocalGattCharacteristicNotificationsRequest(
127 read_characteristic_.get(), true)); 137 read_characteristic_.get(), true));
128 EXPECT_FALSE(delegate_->NotificationStatusForCharacteristic( 138 EXPECT_FALSE(delegate_->NotificationStatusForCharacteristic(
129 read_characteristic_.get())); 139 read_characteristic_.get()));
130 140
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 const uint64_t kNotifyValue = 0x7331ul; 212 const uint64_t kNotifyValue = 0x7331ul;
203 EXPECT_EQ(BluetoothLocalGattCharacteristic::SERVICE_NOT_REGISTERED, 213 EXPECT_EQ(BluetoothLocalGattCharacteristic::SERVICE_NOT_REGISTERED,
204 notify_characteristic_->NotifyValueChanged( 214 notify_characteristic_->NotifyValueChanged(
205 nullptr, GetValue(kNotifyValue), false)); 215 nullptr, GetValue(kNotifyValue), false));
206 EXPECT_NE(kNotifyValue, GetInteger(LastNotifactionValueForCharacteristic( 216 EXPECT_NE(kNotifyValue, GetInteger(LastNotifactionValueForCharacteristic(
207 notify_characteristic_.get()))); 217 notify_characteristic_.get())));
208 } 218 }
209 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX) 219 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX)
210 220
211 } // namespace device 221 } // namespace device
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth.gyp ('k') | device/bluetooth/bluetooth_local_gatt_descriptor_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698