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

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

Issue 1898643002: Refactor device::BluetoothGattXXX classes to split into remote/local. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 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 "device/bluetooth/test/bluetooth_test_win.h" 5 #include "device/bluetooth/test/bluetooth_test_win.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/strings/sys_string_conversions.h" 10 #include "base/strings/sys_string_conversions.h"
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 197
198 for (auto uuid : uuids) { 198 for (auto uuid : uuids) {
199 fake_bt_le_wrapper_->SimulateGattService( 199 fake_bt_le_wrapper_->SimulateGattService(
200 simulated_device, nullptr, CanonicalStringToBTH_LE_UUID(uuid)); 200 simulated_device, nullptr, CanonicalStringToBTH_LE_UUID(uuid));
201 } 201 }
202 202
203 FinishPendingTasks(); 203 FinishPendingTasks();
204 } 204 }
205 205
206 void BluetoothTestWin::SimulateGattServiceRemoved( 206 void BluetoothTestWin::SimulateGattServiceRemoved(
207 BluetoothGattService* service) { 207 BluetoothRemoteGattService* service) {
208 std::string device_address = service->GetDevice()->GetAddress(); 208 std::string device_address = service->GetDevice()->GetAddress();
209 win::BLEDevice* target_device = 209 win::BLEDevice* target_device =
210 fake_bt_le_wrapper_->GetSimulatedBLEDevice(device_address); 210 fake_bt_le_wrapper_->GetSimulatedBLEDevice(device_address);
211 CHECK(target_device); 211 CHECK(target_device);
212 212
213 BluetoothRemoteGattServiceWin* win_service = 213 BluetoothRemoteGattServiceWin* win_service =
214 static_cast<BluetoothRemoteGattServiceWin*>(service); 214 static_cast<BluetoothRemoteGattServiceWin*>(service);
215 std::string service_att_handle = 215 std::string service_att_handle =
216 std::to_string(win_service->GetAttributeHandle()); 216 std::to_string(win_service->GetAttributeHandle());
217 fake_bt_le_wrapper_->SimulateGattServiceRemoved(target_device, nullptr, 217 fake_bt_le_wrapper_->SimulateGattServiceRemoved(target_device, nullptr,
218 service_att_handle); 218 service_att_handle);
219 219
220 ForceRefreshDevice(); 220 ForceRefreshDevice();
221 } 221 }
222 222
223 void BluetoothTestWin::SimulateGattCharacteristic(BluetoothGattService* service, 223 void BluetoothTestWin::SimulateGattCharacteristic(
224 const std::string& uuid, 224 BluetoothRemoteGattService* service,
225 int properties) { 225 const std::string& uuid,
226 int properties) {
226 std::string device_address = service->GetDevice()->GetAddress(); 227 std::string device_address = service->GetDevice()->GetAddress();
227 win::BLEDevice* target_device = 228 win::BLEDevice* target_device =
228 fake_bt_le_wrapper_->GetSimulatedBLEDevice(device_address); 229 fake_bt_le_wrapper_->GetSimulatedBLEDevice(device_address);
229 CHECK(target_device); 230 CHECK(target_device);
230 win::GattService* target_service = 231 win::GattService* target_service =
231 GetSimulatedService(target_device, service); 232 GetSimulatedService(target_device, service);
232 CHECK(target_service); 233 CHECK(target_service);
233 234
234 BTH_LE_GATT_CHARACTERISTIC win_characteristic_info; 235 BTH_LE_GATT_CHARACTERISTIC win_characteristic_info;
235 win_characteristic_info.CharacteristicUuid = 236 win_characteristic_info.CharacteristicUuid =
236 CanonicalStringToBTH_LE_UUID(uuid); 237 CanonicalStringToBTH_LE_UUID(uuid);
237 win_characteristic_info.IsBroadcastable = FALSE; 238 win_characteristic_info.IsBroadcastable = FALSE;
238 win_characteristic_info.IsReadable = FALSE; 239 win_characteristic_info.IsReadable = FALSE;
239 win_characteristic_info.IsWritableWithoutResponse = FALSE; 240 win_characteristic_info.IsWritableWithoutResponse = FALSE;
240 win_characteristic_info.IsWritable = FALSE; 241 win_characteristic_info.IsWritable = FALSE;
241 win_characteristic_info.IsNotifiable = FALSE; 242 win_characteristic_info.IsNotifiable = FALSE;
242 win_characteristic_info.IsIndicatable = FALSE; 243 win_characteristic_info.IsIndicatable = FALSE;
243 win_characteristic_info.IsSignedWritable = FALSE; 244 win_characteristic_info.IsSignedWritable = FALSE;
244 win_characteristic_info.HasExtendedProperties = FALSE; 245 win_characteristic_info.HasExtendedProperties = FALSE;
245 if (properties & BluetoothGattCharacteristic::PROPERTY_BROADCAST) 246 if (properties & BluetoothRemoteGattCharacteristic::PROPERTY_BROADCAST)
246 win_characteristic_info.IsBroadcastable = TRUE; 247 win_characteristic_info.IsBroadcastable = TRUE;
247 if (properties & BluetoothGattCharacteristic::PROPERTY_READ) 248 if (properties & BluetoothRemoteGattCharacteristic::PROPERTY_READ)
248 win_characteristic_info.IsReadable = TRUE; 249 win_characteristic_info.IsReadable = TRUE;
249 if (properties & BluetoothGattCharacteristic::PROPERTY_WRITE_WITHOUT_RESPONSE) 250 if (properties &
251 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE_WITHOUT_RESPONSE)
250 win_characteristic_info.IsWritableWithoutResponse = TRUE; 252 win_characteristic_info.IsWritableWithoutResponse = TRUE;
251 if (properties & BluetoothGattCharacteristic::PROPERTY_WRITE) 253 if (properties & BluetoothRemoteGattCharacteristic::PROPERTY_WRITE)
252 win_characteristic_info.IsWritable = TRUE; 254 win_characteristic_info.IsWritable = TRUE;
253 if (properties & BluetoothGattCharacteristic::PROPERTY_NOTIFY) 255 if (properties & BluetoothRemoteGattCharacteristic::PROPERTY_NOTIFY)
254 win_characteristic_info.IsNotifiable = TRUE; 256 win_characteristic_info.IsNotifiable = TRUE;
255 if (properties & BluetoothGattCharacteristic::PROPERTY_INDICATE) 257 if (properties & BluetoothRemoteGattCharacteristic::PROPERTY_INDICATE)
256 win_characteristic_info.IsIndicatable = TRUE; 258 win_characteristic_info.IsIndicatable = TRUE;
257 if (properties & 259 if (properties &
258 BluetoothGattCharacteristic::PROPERTY_AUTHENTICATED_SIGNED_WRITES) { 260 BluetoothRemoteGattCharacteristic::PROPERTY_AUTHENTICATED_SIGNED_WRITES) {
259 win_characteristic_info.IsSignedWritable = TRUE; 261 win_characteristic_info.IsSignedWritable = TRUE;
260 } 262 }
261 if (properties & BluetoothGattCharacteristic::PROPERTY_EXTENDED_PROPERTIES) 263 if (properties &
264 BluetoothRemoteGattCharacteristic::PROPERTY_EXTENDED_PROPERTIES)
262 win_characteristic_info.HasExtendedProperties = TRUE; 265 win_characteristic_info.HasExtendedProperties = TRUE;
263 266
264 fake_bt_le_wrapper_->SimulateGattCharacterisc(device_address, target_service, 267 fake_bt_le_wrapper_->SimulateGattCharacterisc(device_address, target_service,
265 win_characteristic_info); 268 win_characteristic_info);
266 269
267 ForceRefreshDevice(); 270 ForceRefreshDevice();
268 } 271 }
269 272
270 void BluetoothTestWin::SimulateGattCharacteristicRemoved( 273 void BluetoothTestWin::SimulateGattCharacteristicRemoved(
271 BluetoothGattService* service, 274 BluetoothRemoteGattService* service,
272 BluetoothGattCharacteristic* characteristic) { 275 BluetoothRemoteGattCharacteristic* characteristic) {
273 CHECK(service); 276 CHECK(service);
274 CHECK(characteristic); 277 CHECK(characteristic);
275 278
276 std::string device_address = service->GetDevice()->GetAddress(); 279 std::string device_address = service->GetDevice()->GetAddress();
277 win::GattService* target_service = GetSimulatedService( 280 win::GattService* target_service = GetSimulatedService(
278 fake_bt_le_wrapper_->GetSimulatedBLEDevice(device_address), service); 281 fake_bt_le_wrapper_->GetSimulatedBLEDevice(device_address), service);
279 CHECK(target_service); 282 CHECK(target_service);
280 283
281 std::string characteristic_att_handle = std::to_string( 284 std::string characteristic_att_handle = std::to_string(
282 static_cast<BluetoothRemoteGattCharacteristicWin*>(characteristic) 285 static_cast<BluetoothRemoteGattCharacteristicWin*>(characteristic)
283 ->GetAttributeHandle()); 286 ->GetAttributeHandle());
284 fake_bt_le_wrapper_->SimulateGattCharacteriscRemove( 287 fake_bt_le_wrapper_->SimulateGattCharacteriscRemove(
285 target_service, characteristic_att_handle); 288 target_service, characteristic_att_handle);
286 289
287 ForceRefreshDevice(); 290 ForceRefreshDevice();
288 } 291 }
289 292
290 void BluetoothTestWin::RememberCharacteristicForSubsequentAction( 293 void BluetoothTestWin::RememberCharacteristicForSubsequentAction(
291 BluetoothGattCharacteristic* characteristic) { 294 BluetoothRemoteGattCharacteristic* characteristic) {
292 CHECK(characteristic); 295 CHECK(characteristic);
293 BluetoothRemoteGattCharacteristicWin* win_characteristic = 296 BluetoothRemoteGattCharacteristicWin* win_characteristic =
294 static_cast<BluetoothRemoteGattCharacteristicWin*>(characteristic); 297 static_cast<BluetoothRemoteGattCharacteristicWin*>(characteristic);
295 298
296 std::string device_address = 299 std::string device_address =
297 win_characteristic->GetService()->GetDevice()->GetAddress(); 300 win_characteristic->GetService()->GetDevice()->GetAddress();
298 win::BLEDevice* target_device = 301 win::BLEDevice* target_device =
299 fake_bt_le_wrapper_->GetSimulatedBLEDevice(device_address); 302 fake_bt_le_wrapper_->GetSimulatedBLEDevice(device_address);
300 CHECK(target_device); 303 CHECK(target_device);
301 win::GattService* target_service = 304 win::GattService* target_service =
302 GetSimulatedService(target_device, win_characteristic->GetService()); 305 GetSimulatedService(target_device, win_characteristic->GetService());
303 CHECK(target_service); 306 CHECK(target_service);
304 fake_bt_le_wrapper_->RememberCharacteristicForSubsequentAction( 307 fake_bt_le_wrapper_->RememberCharacteristicForSubsequentAction(
305 target_service, std::to_string(win_characteristic->GetAttributeHandle())); 308 target_service, std::to_string(win_characteristic->GetAttributeHandle()));
306 } 309 }
307 310
308 void BluetoothTestWin::SimulateGattCharacteristicRead( 311 void BluetoothTestWin::SimulateGattCharacteristicRead(
309 BluetoothGattCharacteristic* characteristic, 312 BluetoothRemoteGattCharacteristic* characteristic,
310 const std::vector<uint8_t>& value) { 313 const std::vector<uint8_t>& value) {
311 win::GattCharacteristic* target_simulated_characteristic = nullptr; 314 win::GattCharacteristic* target_simulated_characteristic = nullptr;
312 if (characteristic) { 315 if (characteristic) {
313 target_simulated_characteristic = 316 target_simulated_characteristic =
314 GetSimulatedCharacteristic(characteristic); 317 GetSimulatedCharacteristic(characteristic);
315 } 318 }
316 319
317 fake_bt_le_wrapper_->SimulateGattCharacteristicValue( 320 fake_bt_le_wrapper_->SimulateGattCharacteristicValue(
318 target_simulated_characteristic, value); 321 target_simulated_characteristic, value);
319 322
320 RunPendingTasksUntilCallback(); 323 RunPendingTasksUntilCallback();
321 } 324 }
322 325
323 void BluetoothTestWin::SimulateGattCharacteristicReadError( 326 void BluetoothTestWin::SimulateGattCharacteristicReadError(
324 BluetoothGattCharacteristic* characteristic, 327 BluetoothRemoteGattCharacteristic* characteristic,
325 BluetoothGattService::GattErrorCode error_code) { 328 BluetoothRemoteGattService::GattErrorCode error_code) {
326 win::GattCharacteristic* target_characteristic = 329 win::GattCharacteristic* target_characteristic =
327 GetSimulatedCharacteristic(characteristic); 330 GetSimulatedCharacteristic(characteristic);
328 CHECK(target_characteristic); 331 CHECK(target_characteristic);
329 HRESULT hr = HRESULT_FROM_WIN32(ERROR_SEM_TIMEOUT); 332 HRESULT hr = HRESULT_FROM_WIN32(ERROR_SEM_TIMEOUT);
330 if (error_code == BluetoothGattService::GATT_ERROR_INVALID_LENGTH) 333 if (error_code == BluetoothRemoteGattService::GATT_ERROR_INVALID_LENGTH)
331 hr = E_BLUETOOTH_ATT_INVALID_ATTRIBUTE_VALUE_LENGTH; 334 hr = E_BLUETOOTH_ATT_INVALID_ATTRIBUTE_VALUE_LENGTH;
332 fake_bt_le_wrapper_->SimulateGattCharacteristicReadError( 335 fake_bt_le_wrapper_->SimulateGattCharacteristicReadError(
333 target_characteristic, hr); 336 target_characteristic, hr);
334 337
335 FinishPendingTasks(); 338 FinishPendingTasks();
336 } 339 }
337 340
338 void BluetoothTestWin::SimulateGattCharacteristicWrite( 341 void BluetoothTestWin::SimulateGattCharacteristicWrite(
339 BluetoothGattCharacteristic* characteristic) { 342 BluetoothRemoteGattCharacteristic* characteristic) {
340 RunPendingTasksUntilCallback(); 343 RunPendingTasksUntilCallback();
341 } 344 }
342 345
343 void BluetoothTestWin::SimulateGattCharacteristicWriteError( 346 void BluetoothTestWin::SimulateGattCharacteristicWriteError(
344 BluetoothGattCharacteristic* characteristic, 347 BluetoothRemoteGattCharacteristic* characteristic,
345 BluetoothGattService::GattErrorCode error_code) { 348 BluetoothRemoteGattService::GattErrorCode error_code) {
346 win::GattCharacteristic* target_characteristic = 349 win::GattCharacteristic* target_characteristic =
347 GetSimulatedCharacteristic(characteristic); 350 GetSimulatedCharacteristic(characteristic);
348 CHECK(target_characteristic); 351 CHECK(target_characteristic);
349 HRESULT hr = HRESULT_FROM_WIN32(ERROR_SEM_TIMEOUT); 352 HRESULT hr = HRESULT_FROM_WIN32(ERROR_SEM_TIMEOUT);
350 if (error_code == BluetoothGattService::GATT_ERROR_INVALID_LENGTH) 353 if (error_code == BluetoothRemoteGattService::GATT_ERROR_INVALID_LENGTH)
351 hr = E_BLUETOOTH_ATT_INVALID_ATTRIBUTE_VALUE_LENGTH; 354 hr = E_BLUETOOTH_ATT_INVALID_ATTRIBUTE_VALUE_LENGTH;
352 fake_bt_le_wrapper_->SimulateGattCharacteristicWriteError( 355 fake_bt_le_wrapper_->SimulateGattCharacteristicWriteError(
353 target_characteristic, hr); 356 target_characteristic, hr);
354 357
355 FinishPendingTasks(); 358 FinishPendingTasks();
356 } 359 }
357 360
358 void BluetoothTestWin::DeleteDevice(BluetoothDevice* device) { 361 void BluetoothTestWin::DeleteDevice(BluetoothDevice* device) {
359 CHECK(device); 362 CHECK(device);
360 fake_bt_le_wrapper_->RemoveSimulatedBLEDevice(device->GetAddress()); 363 fake_bt_le_wrapper_->RemoveSimulatedBLEDevice(device->GetAddress());
361 FinishPendingTasks(); 364 FinishPendingTasks();
362 } 365 }
363 366
364 void BluetoothTestWin::SimulateGattDescriptor( 367 void BluetoothTestWin::SimulateGattDescriptor(
365 BluetoothGattCharacteristic* characteristic, 368 BluetoothRemoteGattCharacteristic* characteristic,
366 const std::string& uuid) { 369 const std::string& uuid) {
367 win::GattCharacteristic* target_characteristic = 370 win::GattCharacteristic* target_characteristic =
368 GetSimulatedCharacteristic(characteristic); 371 GetSimulatedCharacteristic(characteristic);
369 CHECK(target_characteristic); 372 CHECK(target_characteristic);
370 fake_bt_le_wrapper_->SimulateGattDescriptor( 373 fake_bt_le_wrapper_->SimulateGattDescriptor(
371 characteristic->GetService()->GetDevice()->GetAddress(), 374 characteristic->GetService()->GetDevice()->GetAddress(),
372 target_characteristic, CanonicalStringToBTH_LE_UUID(uuid)); 375 target_characteristic, CanonicalStringToBTH_LE_UUID(uuid));
373 ForceRefreshDevice(); 376 ForceRefreshDevice();
374 } 377 }
375 378
376 void BluetoothTestWin::SimulateGattNotifySessionStarted( 379 void BluetoothTestWin::SimulateGattNotifySessionStarted(
377 BluetoothGattCharacteristic* characteristic) { 380 BluetoothRemoteGattCharacteristic* characteristic) {
378 FinishPendingTasks(); 381 FinishPendingTasks();
379 } 382 }
380 383
381 void BluetoothTestWin::SimulateGattCharacteristicChanged( 384 void BluetoothTestWin::SimulateGattCharacteristicChanged(
382 BluetoothGattCharacteristic* characteristic, 385 BluetoothRemoteGattCharacteristic* characteristic,
383 const std::vector<uint8_t>& value) { 386 const std::vector<uint8_t>& value) {
384 win::GattCharacteristic* target_simulated_characteristic = nullptr; 387 win::GattCharacteristic* target_simulated_characteristic = nullptr;
385 if (characteristic) { 388 if (characteristic) {
386 target_simulated_characteristic = 389 target_simulated_characteristic =
387 GetSimulatedCharacteristic(characteristic); 390 GetSimulatedCharacteristic(characteristic);
388 } 391 }
389 392
390 fake_bt_le_wrapper_->SimulateGattCharacteristicValue( 393 fake_bt_le_wrapper_->SimulateGattCharacteristicValue(
391 target_simulated_characteristic, value); 394 target_simulated_characteristic, value);
392 fake_bt_le_wrapper_->SimulateCharacteristicValueChangeNotification( 395 fake_bt_le_wrapper_->SimulateCharacteristicValueChangeNotification(
(...skipping 19 matching lines...) Expand all
412 } 415 }
413 416
414 void BluetoothTestWin::OnWriteGattDescriptorValue( 417 void BluetoothTestWin::OnWriteGattDescriptorValue(
415 const std::vector<uint8_t>& value) { 418 const std::vector<uint8_t>& value) {
416 gatt_write_descriptor_attempts_++; 419 gatt_write_descriptor_attempts_++;
417 last_write_value_.assign(value.begin(), value.end()); 420 last_write_value_.assign(value.begin(), value.end());
418 } 421 }
419 422
420 win::GattService* BluetoothTestWin::GetSimulatedService( 423 win::GattService* BluetoothTestWin::GetSimulatedService(
421 win::BLEDevice* device, 424 win::BLEDevice* device,
422 BluetoothGattService* service) { 425 BluetoothRemoteGattService* service) {
423 CHECK(device); 426 CHECK(device);
424 CHECK(service); 427 CHECK(service);
425 428
426 std::vector<std::string> chain_of_att_handles; 429 std::vector<std::string> chain_of_att_handles;
427 BluetoothRemoteGattServiceWin* win_service = 430 BluetoothRemoteGattServiceWin* win_service =
428 static_cast<BluetoothRemoteGattServiceWin*>(service); 431 static_cast<BluetoothRemoteGattServiceWin*>(service);
429 chain_of_att_handles.insert( 432 chain_of_att_handles.insert(
430 chain_of_att_handles.begin(), 433 chain_of_att_handles.begin(),
431 std::to_string(win_service->GetAttributeHandle())); 434 std::to_string(win_service->GetAttributeHandle()));
432 win::GattService* simulated_service = 435 win::GattService* simulated_service =
433 fake_bt_le_wrapper_->GetSimulatedGattService(device, 436 fake_bt_le_wrapper_->GetSimulatedGattService(device,
434 chain_of_att_handles); 437 chain_of_att_handles);
435 CHECK(simulated_service); 438 CHECK(simulated_service);
436 return simulated_service; 439 return simulated_service;
437 } 440 }
438 441
439 win::GattCharacteristic* BluetoothTestWin::GetSimulatedCharacteristic( 442 win::GattCharacteristic* BluetoothTestWin::GetSimulatedCharacteristic(
440 BluetoothGattCharacteristic* characteristic) { 443 BluetoothRemoteGattCharacteristic* characteristic) {
441 CHECK(characteristic); 444 CHECK(characteristic);
442 BluetoothRemoteGattCharacteristicWin* win_characteristic = 445 BluetoothRemoteGattCharacteristicWin* win_characteristic =
443 static_cast<BluetoothRemoteGattCharacteristicWin*>(characteristic); 446 static_cast<BluetoothRemoteGattCharacteristicWin*>(characteristic);
444 447
445 std::string device_address = 448 std::string device_address =
446 win_characteristic->GetService()->GetDevice()->GetAddress(); 449 win_characteristic->GetService()->GetDevice()->GetAddress();
447 win::BLEDevice* target_device = 450 win::BLEDevice* target_device =
448 fake_bt_le_wrapper_->GetSimulatedBLEDevice(device_address); 451 fake_bt_le_wrapper_->GetSimulatedBLEDevice(device_address);
449 if (target_device == nullptr) 452 if (target_device == nullptr)
450 return nullptr; 453 return nullptr;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 void BluetoothTestWin::ForceRefreshDevice() { 487 void BluetoothTestWin::ForceRefreshDevice() {
485 adapter_win_->force_update_device_for_test_ = true; 488 adapter_win_->force_update_device_for_test_ = true;
486 FinishPendingTasks(); 489 FinishPendingTasks();
487 } 490 }
488 491
489 void BluetoothTestWin::FinishPendingTasks() { 492 void BluetoothTestWin::FinishPendingTasks() {
490 bluetooth_task_runner_->RunPendingTasks(); 493 bluetooth_task_runner_->RunPendingTasks();
491 base::RunLoop().RunUntilIdle(); 494 base::RunLoop().RunUntilIdle();
492 } 495 }
493 } 496 }
OLDNEW
« no previous file with comments | « device/bluetooth/test/bluetooth_test_win.h ('k') | device/bluetooth/test/mock_bluetooth_device.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698