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

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

Issue 1973343005: Remove service, add device, in BluetoothLocalGattService::Delegate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
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
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 base::WeakPtr<BluetoothLocalGattCharacteristic> read_characteristic_; 47 base::WeakPtr<BluetoothLocalGattCharacteristic> read_characteristic_;
48 base::WeakPtr<BluetoothLocalGattCharacteristic> write_characteristic_; 48 base::WeakPtr<BluetoothLocalGattCharacteristic> write_characteristic_;
49 base::WeakPtr<BluetoothLocalGattCharacteristic> notify_characteristic_; 49 base::WeakPtr<BluetoothLocalGattCharacteristic> notify_characteristic_;
50 base::WeakPtr<BluetoothLocalGattCharacteristic> indicate_characteristic_; 50 base::WeakPtr<BluetoothLocalGattCharacteristic> indicate_characteristic_;
51 }; 51 };
52 52
53 #if defined(OS_CHROMEOS) || defined(OS_LINUX) 53 #if defined(OS_CHROMEOS) || defined(OS_LINUX)
54 TEST_F(BluetoothLocalGattCharacteristicTest, ReadLocalCharacteristicValue) { 54 TEST_F(BluetoothLocalGattCharacteristicTest, ReadLocalCharacteristicValue) {
55 delegate_->value_to_write_ = 0x1337; 55 delegate_->value_to_write_ = 0x1337;
56 SimulateLocalGattCharacteristicValueReadRequest( 56 SimulateLocalGattCharacteristicValueReadRequest(
57 service_.get(), read_characteristic_.get(), 57 read_characteristic_.get(), GetReadValueCallback(Call::EXPECTED),
58 GetReadValueCallback(Call::EXPECTED), GetCallback(Call::NOT_EXPECTED)); 58 GetCallback(Call::NOT_EXPECTED));
59 59
60 EXPECT_EQ(delegate_->value_to_write_, GetInteger(last_read_value_)); 60 EXPECT_EQ(delegate_->value_to_write_, GetInteger(last_read_value_));
61 } 61 }
62 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX) 62 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX)
63 63
64 #if defined(OS_CHROMEOS) || defined(OS_LINUX) 64 #if defined(OS_CHROMEOS) || defined(OS_LINUX)
65 TEST_F(BluetoothLocalGattCharacteristicTest, WriteLocalCharacteristicValue) { 65 TEST_F(BluetoothLocalGattCharacteristicTest, WriteLocalCharacteristicValue) {
66 const uint64_t kValueToWrite = 0x7331ul; 66 const uint64_t kValueToWrite = 0x7331ul;
67 SimulateLocalGattCharacteristicValueWriteRequest( 67 SimulateLocalGattCharacteristicValueWriteRequest(
68 service_.get(), write_characteristic_.get(), GetValue(kValueToWrite), 68 write_characteristic_.get(), GetValue(kValueToWrite),
69 GetCallback(Call::EXPECTED), GetCallback(Call::NOT_EXPECTED)); 69 GetCallback(Call::EXPECTED), GetCallback(Call::NOT_EXPECTED));
70 70
71 EXPECT_EQ(kValueToWrite, delegate_->last_written_value_); 71 EXPECT_EQ(kValueToWrite, delegate_->last_written_value_);
72 } 72 }
73 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX) 73 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX)
74 74
75 #if defined(OS_CHROMEOS) || defined(OS_LINUX) 75 #if defined(OS_CHROMEOS) || defined(OS_LINUX)
76 TEST_F(BluetoothLocalGattCharacteristicTest, ReadLocalCharacteristicValueFail) { 76 TEST_F(BluetoothLocalGattCharacteristicTest, ReadLocalCharacteristicValueFail) {
77 delegate_->value_to_write_ = 0x1337; 77 delegate_->value_to_write_ = 0x1337;
78 delegate_->should_fail_ = true; 78 delegate_->should_fail_ = true;
79 SimulateLocalGattCharacteristicValueReadRequest( 79 SimulateLocalGattCharacteristicValueReadRequest(
80 service_.get(), read_characteristic_.get(), 80 read_characteristic_.get(), GetReadValueCallback(Call::NOT_EXPECTED),
81 GetReadValueCallback(Call::NOT_EXPECTED), GetCallback(Call::EXPECTED)); 81 GetCallback(Call::EXPECTED));
82 82
83 EXPECT_NE(delegate_->value_to_write_, GetInteger(last_read_value_)); 83 EXPECT_NE(delegate_->value_to_write_, GetInteger(last_read_value_));
84 } 84 }
85 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX) 85 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX)
86 86
87 #if defined(OS_CHROMEOS) || defined(OS_LINUX) 87 #if defined(OS_CHROMEOS) || defined(OS_LINUX)
88 TEST_F(BluetoothLocalGattCharacteristicTest, 88 TEST_F(BluetoothLocalGattCharacteristicTest,
89 ReadLocalCharacteristicValueWrongPermission) { 89 ReadLocalCharacteristicValueWrongPermission) {
90 delegate_->value_to_write_ = 0x1337; 90 delegate_->value_to_write_ = 0x1337;
91 SimulateLocalGattCharacteristicValueReadRequest( 91 SimulateLocalGattCharacteristicValueReadRequest(
92 service_.get(), write_characteristic_.get(), 92 write_characteristic_.get(), GetReadValueCallback(Call::NOT_EXPECTED),
93 GetReadValueCallback(Call::NOT_EXPECTED), GetCallback(Call::EXPECTED)); 93 GetCallback(Call::EXPECTED));
94 94
95 EXPECT_NE(delegate_->value_to_write_, GetInteger(last_read_value_)); 95 EXPECT_NE(delegate_->value_to_write_, GetInteger(last_read_value_));
96 } 96 }
97 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX) 97 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX)
98 98
99 #if defined(OS_CHROMEOS) || defined(OS_LINUX) 99 #if defined(OS_CHROMEOS) || defined(OS_LINUX)
100 TEST_F(BluetoothLocalGattCharacteristicTest, 100 TEST_F(BluetoothLocalGattCharacteristicTest,
101 WriteLocalCharacteristicValueFail) { 101 WriteLocalCharacteristicValueFail) {
102 const uint64_t kValueToWrite = 0x7331ul; 102 const uint64_t kValueToWrite = 0x7331ul;
103 delegate_->should_fail_ = true; 103 delegate_->should_fail_ = true;
104 SimulateLocalGattCharacteristicValueWriteRequest( 104 SimulateLocalGattCharacteristicValueWriteRequest(
105 service_.get(), write_characteristic_.get(), GetValue(kValueToWrite), 105 write_characteristic_.get(), GetValue(kValueToWrite),
106 GetCallback(Call::NOT_EXPECTED), GetCallback(Call::EXPECTED)); 106 GetCallback(Call::NOT_EXPECTED), GetCallback(Call::EXPECTED));
107 107
108 EXPECT_NE(kValueToWrite, delegate_->last_written_value_); 108 EXPECT_NE(kValueToWrite, delegate_->last_written_value_);
109 } 109 }
110 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX) 110 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX)
111 111
112 #if defined(OS_CHROMEOS) || defined(OS_LINUX) 112 #if defined(OS_CHROMEOS) || defined(OS_LINUX)
113 TEST_F(BluetoothLocalGattCharacteristicTest, 113 TEST_F(BluetoothLocalGattCharacteristicTest,
114 WriteLocalCharacteristicValueWrongPermission) { 114 WriteLocalCharacteristicValueWrongPermission) {
115 const uint64_t kValueToWrite = 0x7331ul; 115 const uint64_t kValueToWrite = 0x7331ul;
116 SimulateLocalGattCharacteristicValueWriteRequest( 116 SimulateLocalGattCharacteristicValueWriteRequest(
117 service_.get(), read_characteristic_.get(), GetValue(kValueToWrite), 117 read_characteristic_.get(), GetValue(kValueToWrite),
118 GetCallback(Call::NOT_EXPECTED), GetCallback(Call::EXPECTED)); 118 GetCallback(Call::NOT_EXPECTED), GetCallback(Call::EXPECTED));
119 119
120 EXPECT_NE(kValueToWrite, delegate_->last_written_value_); 120 EXPECT_NE(kValueToWrite, delegate_->last_written_value_);
121 } 121 }
122 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX) 122 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX)
123 123
124 #if defined(OS_CHROMEOS) || defined(OS_LINUX) 124 #if defined(OS_CHROMEOS) || defined(OS_LINUX)
125 TEST_F(BluetoothLocalGattCharacteristicTest, StartAndStopNotifications) { 125 TEST_F(BluetoothLocalGattCharacteristicTest, StartAndStopNotifications) {
126 EXPECT_FALSE(SimulateLocalGattCharacteristicNotificationsRequest( 126 EXPECT_FALSE(SimulateLocalGattCharacteristicNotificationsRequest(
127 service_.get(), read_characteristic_.get(), true)); 127 read_characteristic_.get(), true));
128 EXPECT_FALSE(delegate_->NotificationStatusForCharacteristic( 128 EXPECT_FALSE(delegate_->NotificationStatusForCharacteristic(
129 read_characteristic_.get())); 129 read_characteristic_.get()));
130 130
131 EXPECT_FALSE(SimulateLocalGattCharacteristicNotificationsRequest( 131 EXPECT_FALSE(SimulateLocalGattCharacteristicNotificationsRequest(
132 service_.get(), write_characteristic_.get(), true)); 132 write_characteristic_.get(), true));
133 EXPECT_FALSE(delegate_->NotificationStatusForCharacteristic( 133 EXPECT_FALSE(delegate_->NotificationStatusForCharacteristic(
134 write_characteristic_.get())); 134 write_characteristic_.get()));
135 135
136 EXPECT_TRUE(SimulateLocalGattCharacteristicNotificationsRequest( 136 EXPECT_TRUE(SimulateLocalGattCharacteristicNotificationsRequest(
137 service_.get(), notify_characteristic_.get(), true)); 137 notify_characteristic_.get(), true));
138 EXPECT_TRUE(delegate_->NotificationStatusForCharacteristic( 138 EXPECT_TRUE(delegate_->NotificationStatusForCharacteristic(
139 notify_characteristic_.get())); 139 notify_characteristic_.get()));
140 140
141 EXPECT_TRUE(SimulateLocalGattCharacteristicNotificationsRequest( 141 EXPECT_TRUE(SimulateLocalGattCharacteristicNotificationsRequest(
142 service_.get(), notify_characteristic_.get(), false)); 142 notify_characteristic_.get(), false));
143 EXPECT_FALSE(delegate_->NotificationStatusForCharacteristic( 143 EXPECT_FALSE(delegate_->NotificationStatusForCharacteristic(
144 notify_characteristic_.get())); 144 notify_characteristic_.get()));
145 } 145 }
146 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX) 146 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX)
147 147
148 #if defined(OS_CHROMEOS) || defined(OS_LINUX) 148 #if defined(OS_CHROMEOS) || defined(OS_LINUX)
149 TEST_F(BluetoothLocalGattCharacteristicTest, SendNotifications) { 149 TEST_F(BluetoothLocalGattCharacteristicTest, SendNotifications) {
150 const uint64_t kNotifyValue = 0x7331ul; 150 const uint64_t kNotifyValue = 0x7331ul;
151 EXPECT_EQ(BluetoothLocalGattCharacteristic::NOTIFICATION_SUCCESS, 151 EXPECT_EQ(BluetoothLocalGattCharacteristic::NOTIFICATION_SUCCESS,
152 notify_characteristic_->NotifyValueChanged(GetValue(kNotifyValue), 152 notify_characteristic_->NotifyValueChanged(
153 false)); 153 nullptr, GetValue(kNotifyValue), false));
154 EXPECT_EQ(kNotifyValue, GetInteger(LastNotifactionValueForCharacteristic( 154 EXPECT_EQ(kNotifyValue, GetInteger(LastNotifactionValueForCharacteristic(
155 notify_characteristic_.get()))); 155 notify_characteristic_.get())));
156 156
157 const uint64_t kIndicateValue = 0x1337ul; 157 const uint64_t kIndicateValue = 0x1337ul;
158 EXPECT_EQ(BluetoothLocalGattCharacteristic::NOTIFICATION_SUCCESS, 158 EXPECT_EQ(BluetoothLocalGattCharacteristic::NOTIFICATION_SUCCESS,
159 indicate_characteristic_->NotifyValueChanged( 159 indicate_characteristic_->NotifyValueChanged(
160 GetValue(kIndicateValue), true)); 160 nullptr, GetValue(kIndicateValue), true));
161 EXPECT_EQ(kIndicateValue, GetInteger(LastNotifactionValueForCharacteristic( 161 EXPECT_EQ(kIndicateValue, GetInteger(LastNotifactionValueForCharacteristic(
162 indicate_characteristic_.get()))); 162 indicate_characteristic_.get())));
163 } 163 }
164 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX) 164 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX)
165 165
166 #if defined(OS_CHROMEOS) || defined(OS_LINUX) 166 #if defined(OS_CHROMEOS) || defined(OS_LINUX)
167 TEST_F(BluetoothLocalGattCharacteristicTest, SendNotificationsWrongProperties) { 167 TEST_F(BluetoothLocalGattCharacteristicTest, SendNotificationsWrongProperties) {
168 const uint64_t kNewValue = 0x3334ul; 168 const uint64_t kNewValue = 0x3334ul;
169 EXPECT_EQ( 169 EXPECT_EQ(BluetoothLocalGattCharacteristic::NOTIFY_PROPERTY_NOT_SET,
170 BluetoothLocalGattCharacteristic::NOTIFY_PROPERTY_NOT_SET, 170 read_characteristic_->NotifyValueChanged(
171 read_characteristic_->NotifyValueChanged(GetValue(kNewValue), false)); 171 nullptr, GetValue(kNewValue), false));
172 EXPECT_NE(kNewValue, GetInteger(LastNotifactionValueForCharacteristic( 172 EXPECT_NE(kNewValue, GetInteger(LastNotifactionValueForCharacteristic(
173 read_characteristic_.get()))); 173 read_characteristic_.get())));
174 174
175 EXPECT_EQ( 175 EXPECT_EQ(BluetoothLocalGattCharacteristic::NOTIFY_PROPERTY_NOT_SET,
176 BluetoothLocalGattCharacteristic::NOTIFY_PROPERTY_NOT_SET, 176 write_characteristic_->NotifyValueChanged(
177 write_characteristic_->NotifyValueChanged(GetValue(kNewValue), false)); 177 nullptr, GetValue(kNewValue), false));
178 EXPECT_NE(kNewValue, GetInteger(LastNotifactionValueForCharacteristic( 178 EXPECT_NE(kNewValue, GetInteger(LastNotifactionValueForCharacteristic(
179 write_characteristic_.get()))); 179 write_characteristic_.get())));
180 180
181 const uint64_t kNotifyValue = 0x7331ul; 181 const uint64_t kNotifyValue = 0x7331ul;
182 EXPECT_EQ( 182 EXPECT_EQ(BluetoothLocalGattCharacteristic::INDICATE_PROPERTY_NOT_SET,
183 BluetoothLocalGattCharacteristic::INDICATE_PROPERTY_NOT_SET, 183 notify_characteristic_->NotifyValueChanged(
184 notify_characteristic_->NotifyValueChanged(GetValue(kNotifyValue), true)); 184 nullptr, GetValue(kNotifyValue), true));
185 EXPECT_NE(kNotifyValue, GetInteger(LastNotifactionValueForCharacteristic( 185 EXPECT_NE(kNotifyValue, GetInteger(LastNotifactionValueForCharacteristic(
186 notify_characteristic_.get()))); 186 notify_characteristic_.get())));
187 187
188 const uint64_t kIndicateValue = 0x1337ul; 188 const uint64_t kIndicateValue = 0x1337ul;
189 EXPECT_EQ(BluetoothLocalGattCharacteristic::NOTIFY_PROPERTY_NOT_SET, 189 EXPECT_EQ(BluetoothLocalGattCharacteristic::NOTIFY_PROPERTY_NOT_SET,
190 indicate_characteristic_->NotifyValueChanged( 190 indicate_characteristic_->NotifyValueChanged(
191 GetValue(kIndicateValue), false)); 191 nullptr, GetValue(kIndicateValue), false));
192 EXPECT_NE(kIndicateValue, GetInteger(LastNotifactionValueForCharacteristic( 192 EXPECT_NE(kIndicateValue, GetInteger(LastNotifactionValueForCharacteristic(
193 indicate_characteristic_.get()))); 193 indicate_characteristic_.get())));
194 } 194 }
195 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX) 195 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX)
196 196
197 #if defined(OS_CHROMEOS) || defined(OS_LINUX) 197 #if defined(OS_CHROMEOS) || defined(OS_LINUX)
198 TEST_F(BluetoothLocalGattCharacteristicTest, 198 TEST_F(BluetoothLocalGattCharacteristicTest,
199 SendNotificationsServiceNotRegistered) { 199 SendNotificationsServiceNotRegistered) {
200 service_->Unregister(GetCallback(Call::EXPECTED), 200 service_->Unregister(GetCallback(Call::EXPECTED),
201 GetGattErrorCallback(Call::NOT_EXPECTED)); 201 GetGattErrorCallback(Call::NOT_EXPECTED));
202 const uint64_t kNotifyValue = 0x7331ul; 202 const uint64_t kNotifyValue = 0x7331ul;
203 EXPECT_EQ(BluetoothLocalGattCharacteristic::SERVICE_NOT_REGISTERED, 203 EXPECT_EQ(BluetoothLocalGattCharacteristic::SERVICE_NOT_REGISTERED,
204 notify_characteristic_->NotifyValueChanged(GetValue(kNotifyValue), 204 notify_characteristic_->NotifyValueChanged(
205 false)); 205 nullptr, GetValue(kNotifyValue), false));
206 EXPECT_NE(kNotifyValue, GetInteger(LastNotifactionValueForCharacteristic( 206 EXPECT_NE(kNotifyValue, GetInteger(LastNotifactionValueForCharacteristic(
207 notify_characteristic_.get()))); 207 notify_characteristic_.get())));
208 } 208 }
209 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX) 209 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX)
210 210
211 } // namespace device 211 } // namespace device
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_local_gatt_characteristic.h ('k') | device/bluetooth/bluetooth_local_gatt_descriptor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698