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

Side by Side Diff: device/bluetooth/test/bluetooth_test.cc

Issue 1804093003: Add BluetoothGattCharacteristicTest::StartNotifySession_Reentrant unit test (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 8 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "device/bluetooth/test/bluetooth_test.h" 5 #include "device/bluetooth/test/bluetooth_test.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 BluetoothRemoteGattService::GattErrorCode error_code) { 154 BluetoothRemoteGattService::GattErrorCode error_code) {
155 ++error_callback_count_; 155 ++error_callback_count_;
156 last_gatt_error_code_ = error_code; 156 last_gatt_error_code_ = error_code;
157 157
158 if (expected == Call::EXPECTED) 158 if (expected == Call::EXPECTED)
159 ++actual_error_callback_calls_; 159 ++actual_error_callback_calls_;
160 else 160 else
161 unexpected_error_callback_ = true; 161 unexpected_error_callback_ = true;
162 } 162 }
163 163
164 void BluetoothTestBase::ReentrantStartNotifySessionSuccessCallback(
165 Call expected,
166 BluetoothRemoteGattCharacteristic* characteristic,
167 std::unique_ptr<BluetoothGattNotifySession> notify_session) {
168 ++callback_count_;
169 notify_sessions_.push_back(notify_session.release());
ortuno 2016/04/22 16:23:39 I think std::move(notify_session) would be better
gogerald1 2016/04/27 20:15:32 Done.
170
171 if (expected == Call::EXPECTED)
172 ++actual_success_callback_calls_;
173 else
174 unexpected_success_callback_ = true;
175
176 characteristic->StartNotifySession(GetNotifyCallback(Call::EXPECTED),
177 GetGattErrorCallback(Call::NOT_EXPECTED));
178 }
179
180 void BluetoothTestBase::ReentrantStartNotifySessionErrorCallback(
181 Call expected,
182 BluetoothRemoteGattCharacteristic* characteristic,
183 bool error_in_reentrant,
184 BluetoothGattService::GattErrorCode error_code) {
185 ++error_callback_count_;
186 last_gatt_error_code_ = error_code;
187
188 if (expected == Call::EXPECTED)
189 ++actual_error_callback_calls_;
190 else
191 unexpected_error_callback_ = true;
192
193 if (error_in_reentrant) {
194 SimulateGattCharacteristicSetNotifyWillFailAsynchronouslyOnce(
195 characteristic);
196 characteristic->StartNotifySession(GetNotifyCallback(Call::NOT_EXPECTED),
197 GetGattErrorCallback(Call::EXPECTED));
198 } else {
199 characteristic->StartNotifySession(
200 GetNotifyCallback(Call::EXPECTED),
201 GetGattErrorCallback(Call::NOT_EXPECTED));
202 }
203 }
204
164 base::Closure BluetoothTestBase::GetCallback(Call expected) { 205 base::Closure BluetoothTestBase::GetCallback(Call expected) {
165 if (expected == Call::EXPECTED) 206 if (expected == Call::EXPECTED)
166 ++expected_success_callback_calls_; 207 ++expected_success_callback_calls_;
167 return base::Bind(&BluetoothTestBase::Callback, weak_factory_.GetWeakPtr(), 208 return base::Bind(&BluetoothTestBase::Callback, weak_factory_.GetWeakPtr(),
168 expected); 209 expected);
169 } 210 }
170 211
171 BluetoothAdapter::DiscoverySessionCallback 212 BluetoothAdapter::DiscoverySessionCallback
172 BluetoothTestBase::GetDiscoverySessionCallback(Call expected) { 213 BluetoothTestBase::GetDiscoverySessionCallback(Call expected) {
173 if (expected == Call::EXPECTED) 214 if (expected == Call::EXPECTED)
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 } 258 }
218 259
219 base::Callback<void(BluetoothRemoteGattService::GattErrorCode)> 260 base::Callback<void(BluetoothRemoteGattService::GattErrorCode)>
220 BluetoothTestBase::GetGattErrorCallback(Call expected) { 261 BluetoothTestBase::GetGattErrorCallback(Call expected) {
221 if (expected == Call::EXPECTED) 262 if (expected == Call::EXPECTED)
222 ++expected_error_callback_calls_; 263 ++expected_error_callback_calls_;
223 return base::Bind(&BluetoothTestBase::GattErrorCallback, 264 return base::Bind(&BluetoothTestBase::GattErrorCallback,
224 weak_factory_.GetWeakPtr(), expected); 265 weak_factory_.GetWeakPtr(), expected);
225 } 266 }
226 267
268 BluetoothRemoteGattCharacteristic::NotifySessionCallback
269 BluetoothTestBase::GetReentrantStartNotifySessionSuccessCallback(
270 Call expected,
271 BluetoothRemoteGattCharacteristic* characteristic) {
272 if (expected == Call::EXPECTED)
273 ++expected_success_callback_calls_;
274 return base::Bind(
275 &BluetoothTestBase::ReentrantStartNotifySessionSuccessCallback,
276 weak_factory_.GetWeakPtr(), expected, characteristic);
277 }
278
279 base::Callback<void(BluetoothGattService::GattErrorCode)>
280 BluetoothTestBase::GetReentrantStartNotifySessionErrorCallback(
281 Call expected,
282 BluetoothRemoteGattCharacteristic* characteristic,
283 bool error_in_reentrant) {
284 if (expected == Call::EXPECTED)
285 ++expected_error_callback_calls_;
286 return base::Bind(
287 &BluetoothTestBase::ReentrantStartNotifySessionErrorCallback,
288 weak_factory_.GetWeakPtr(), expected, characteristic, error_in_reentrant);
289 }
290
227 void BluetoothTestBase::ResetEventCounts() { 291 void BluetoothTestBase::ResetEventCounts() {
228 last_connect_error_code_ = BluetoothDevice::ERROR_UNKNOWN; 292 last_connect_error_code_ = BluetoothDevice::ERROR_UNKNOWN;
229 callback_count_ = 0; 293 callback_count_ = 0;
230 error_callback_count_ = 0; 294 error_callback_count_ = 0;
231 gatt_connection_attempts_ = 0; 295 gatt_connection_attempts_ = 0;
232 gatt_disconnection_attempts_ = 0; 296 gatt_disconnection_attempts_ = 0;
233 gatt_discovery_attempts_ = 0; 297 gatt_discovery_attempts_ = 0;
234 gatt_notify_characteristic_attempts_ = 0; 298 gatt_notify_characteristic_attempts_ = 0;
235 gatt_read_characteristic_attempts_ = 0; 299 gatt_read_characteristic_attempts_ = 0;
236 gatt_write_characteristic_attempts_ = 0; 300 gatt_write_characteristic_attempts_ = 0;
237 gatt_read_descriptor_attempts_ = 0; 301 gatt_read_descriptor_attempts_ = 0;
238 gatt_write_descriptor_attempts_ = 0; 302 gatt_write_descriptor_attempts_ = 0;
239 } 303 }
240 304
241 } // namespace device 305 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698