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

Side by Side Diff: device/bluetooth/test/bluetooth_test_mac.mm

Issue 2638653002: Bluetooth: macOS: DidModifyServices can happens while scanning (Closed)
Patch Set: Removing useless modification Created 3 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_mac.h" 5 #include "device/bluetooth/test/bluetooth_test_mac.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/mac/foundation_util.h" 9 #include "base/mac/foundation_util.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 NSError* error = BluetoothDeviceMac::GetNSErrorFromGattErrorCode(error_code); 370 NSError* error = BluetoothDeviceMac::GetNSErrorFromGattErrorCode(error_code);
371 [characteristic_mock simulateWriteWithError:error]; 371 [characteristic_mock simulateWriteWithError:error];
372 } 372 }
373 373
374 void BluetoothTestMac::SimulateGattDescriptor( 374 void BluetoothTestMac::SimulateGattDescriptor(
375 BluetoothRemoteGattCharacteristic* characteristic, 375 BluetoothRemoteGattCharacteristic* characteristic,
376 const std::string& uuid) { 376 const std::string& uuid) {
377 MockCBCharacteristic* characteristic_mock = 377 MockCBCharacteristic* characteristic_mock =
378 GetCBMockCharacteristic(characteristic); 378 GetCBMockCharacteristic(characteristic);
379 CBUUID* cb_uuid = [CBUUID UUIDWithString:@(uuid.c_str())]; 379 CBUUID* cb_uuid = [CBUUID UUIDWithString:@(uuid.c_str())];
380 [characteristic_mock simulateDescriptorWithUUID:cb_uuid]; 380 [characteristic_mock addDescriptorWithUUID:cb_uuid];
381 MockCBPeripheral* peripheral_mock = GetMockCBPeripheral(characteristic); 381 MockCBPeripheral* peripheral_mock = GetMockCBPeripheral(characteristic);
382 [peripheral_mock didModifyServices:@[]]; 382 [peripheral_mock didModifyServices:@[]];
383 // After -[MockCBPeripheral didModifyServices:], BluetoothLowEnergyDeviceMac 383 // After -[MockCBPeripheral didModifyServices:], BluetoothLowEnergyDeviceMac
384 // is expected to call -[CBPeripheral discoverServices:] 384 // is expected to call -[CBPeripheral discoverServices:]
385 [peripheral_mock mockDidDiscoverEvents]; 385 [peripheral_mock mockDidDiscoverEvents];
386 } 386 }
387 387
388 void BluetoothTestMac::SimulateGattNotifySessionStarted( 388 void BluetoothTestMac::SimulateGattNotifySessionStarted(
389 BluetoothRemoteGattCharacteristic* characteristic) { 389 BluetoothRemoteGattCharacteristic* characteristic) {
390 MockCBCharacteristic* characteristic_mock = 390 MockCBCharacteristic* characteristic_mock =
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 case NotifyValueState::NONE: 456 case NotifyValueState::NONE:
457 EXPECT_FALSE(last_notify_value_); 457 EXPECT_FALSE(last_notify_value_);
458 break; 458 break;
459 case NotifyValueState::NOTIFY: 459 case NotifyValueState::NOTIFY:
460 case NotifyValueState::INDICATE: 460 case NotifyValueState::INDICATE:
461 EXPECT_TRUE(last_notify_value_); 461 EXPECT_TRUE(last_notify_value_);
462 break; 462 break;
463 } 463 }
464 } 464 }
465 465
466 void BluetoothTestMac::SimulateDidDiscoverServices( 466 void BluetoothTestMac::SimulateDidDiscoverServices(BluetoothDevice* device) {
467 BluetoothDevice* device,
468 const std::vector<std::string>& uuids) {
469 AddServicesToDevice(device, uuids);
470 [GetMockCBPeripheral(device) mockDidDiscoverServices]; 467 [GetMockCBPeripheral(device) mockDidDiscoverServices];
471 } 468 }
472 469
470 void BluetoothTestMac::SimulateDidDiscoverCharacteristics(
471 BluetoothRemoteGattService* service) {
472 BluetoothRemoteGattServiceMac* mac_gatt_service =
473 static_cast<BluetoothRemoteGattServiceMac*>(service);
474 CBService* cb_service = mac_gatt_service->GetService();
475 [GetMockCBPeripheral(service)
476 mockDidDiscoverCharacteristicsForService:cb_service];
477 }
478
479 void BluetoothTestMac::SimulateDidDiscoverDescriptors(
480 BluetoothRemoteGattCharacteristic* characteristic) {
481 BluetoothRemoteGattCharacteristicMac* mac_gatt_characteristic =
482 static_cast<BluetoothRemoteGattCharacteristicMac*>(characteristic);
483 CBCharacteristic* cb_characteristic =
484 mac_gatt_characteristic->GetCBCharacteristic();
485 [GetMockCBPeripheral(characteristic)
486 mockDidDiscoverDescriptorsForCharacteristic:cb_characteristic];
487 }
488
489 void BluetoothTest::AddServicesToDevice(BluetoothDevice* device,
490 const std::vector<std::string>& uuids) {
491 scoped_nsobject<NSMutableArray> services([[NSMutableArray alloc] init]);
492 for (auto uuid : uuids) {
493 CBUUID* cb_service_uuid = [CBUUID UUIDWithString:@(uuid.c_str())];
494 [services addObject:cb_service_uuid];
495 }
496 [GetMockCBPeripheral(device) addServices:services];
497 }
498
499 void BluetoothTestMac::AddCharacteristicToService(
500 BluetoothRemoteGattService* service,
501 const std::string& characteristic_uuid,
502 int properties) {
503 BluetoothRemoteGattServiceMac* mac_gatt_service =
504 static_cast<BluetoothRemoteGattServiceMac*>(service);
505 CBService* cb_service = mac_gatt_service->GetService();
506 MockCBService* service_mock = ObjCCast<MockCBService>(cb_service);
507 CBUUID* cb_uuid = [CBUUID UUIDWithString:@(characteristic_uuid.c_str())];
508 [service_mock addCharacteristicWithUUID:cb_uuid properties:properties];
509 }
510
511 void BluetoothTestMac::AddDescriptorToCharacteristic(
512 BluetoothRemoteGattCharacteristic* characteristic,
513 const std::string& uuid) {
514 BluetoothRemoteGattCharacteristicMac* mac_gatt_characteristic =
515 static_cast<BluetoothRemoteGattCharacteristicMac*>(characteristic);
516 CBCharacteristic* cb_characteristic =
517 mac_gatt_characteristic->GetCBCharacteristic();
518 MockCBCharacteristic* characteristic_mock =
519 ObjCCast<MockCBCharacteristic>(cb_characteristic);
520 CBUUID* cb_uuid = [CBUUID UUIDWithString:@(uuid.c_str())];
521 [characteristic_mock addDescriptorWithUUID:cb_uuid];
522 }
523
473 void BluetoothTestMac::OnFakeBluetoothDeviceConnectGattCalled() { 524 void BluetoothTestMac::OnFakeBluetoothDeviceConnectGattCalled() {
474 gatt_connection_attempts_++; 525 gatt_connection_attempts_++;
475 } 526 }
476 527
477 void BluetoothTestMac::OnFakeBluetoothGattDisconnect() { 528 void BluetoothTestMac::OnFakeBluetoothGattDisconnect() {
478 gatt_disconnection_attempts_++; 529 gatt_disconnection_attempts_++;
479 } 530 }
480 531
481 void BluetoothTestMac::OnFakeBluetoothServiceDiscovery() { 532 void BluetoothTestMac::OnFakeBluetoothServiceDiscovery() {
482 gatt_discovery_attempts_++; 533 gatt_discovery_attempts_++;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 MockCBCharacteristic* BluetoothTest::GetCBMockCharacteristic( 594 MockCBCharacteristic* BluetoothTest::GetCBMockCharacteristic(
544 BluetoothRemoteGattCharacteristic* characteristic) const { 595 BluetoothRemoteGattCharacteristic* characteristic) const {
545 device::BluetoothRemoteGattCharacteristicMac* mac_gatt_characteristic = 596 device::BluetoothRemoteGattCharacteristicMac* mac_gatt_characteristic =
546 static_cast<device::BluetoothRemoteGattCharacteristicMac*>( 597 static_cast<device::BluetoothRemoteGattCharacteristicMac*>(
547 characteristic); 598 characteristic);
548 CBCharacteristic* cb_characteristic = 599 CBCharacteristic* cb_characteristic =
549 mac_gatt_characteristic->GetCBCharacteristic(); 600 mac_gatt_characteristic->GetCBCharacteristic();
550 return ObjCCast<MockCBCharacteristic>(cb_characteristic); 601 return ObjCCast<MockCBCharacteristic>(cb_characteristic);
551 } 602 }
552 603
553 void BluetoothTest::AddServicesToDevice(BluetoothDevice* device,
554 const std::vector<std::string>& uuids) {
555 scoped_nsobject<NSMutableArray> services([[NSMutableArray alloc] init]);
556 for (auto uuid : uuids) {
557 CBUUID* cb_service_uuid = [CBUUID UUIDWithString:@(uuid.c_str())];
558 [services addObject:cb_service_uuid];
559 }
560 [GetMockCBPeripheral(device) addServices:services];
561 }
562
563 // Utility function for generating new (CBUUID, address) pairs where CBUUID 604 // Utility function for generating new (CBUUID, address) pairs where CBUUID
564 // hashes to address. For use when adding a new device address to the testing 605 // hashes to address. For use when adding a new device address to the testing
565 // suite because CoreBluetooth peripherals have CBUUIDs in place of addresses, 606 // suite because CoreBluetooth peripherals have CBUUIDs in place of addresses,
566 // and we construct fake addresses for them by hashing the CBUUID. By changing 607 // and we construct fake addresses for them by hashing the CBUUID. By changing
567 // |target| the user can generate sequentially numbered test addresses. 608 // |target| the user can generate sequentially numbered test addresses.
568 // 609 //
569 // std::string BluetoothTestMac::FindCBUUIDForHashTarget() { 610 // std::string BluetoothTestMac::FindCBUUIDForHashTarget() {
570 // // The desired first 6 digits of the hash. For example 0100000, 020000, 611 // // The desired first 6 digits of the hash. For example 0100000, 020000,
571 // // 030000, ... 612 // // 030000, ...
572 // const std::string target = "010000"; 613 // const std::string target = "010000";
(...skipping 16 matching lines...) Expand all
589 // crypto::SHA256HashString(input_str, raw, sizeof(raw)); 630 // crypto::SHA256HashString(input_str, raw, sizeof(raw));
590 // if (base::HexEncode(raw, sizeof(raw)) == target) { 631 // if (base::HexEncode(raw, sizeof(raw)) == target) {
591 // return input_str; 632 // return input_str;
592 // } 633 // }
593 // ++input[0]; 634 // ++input[0];
594 // } 635 // }
595 // return ""; 636 // return "";
596 // } 637 // }
597 638
598 } // namespace device 639 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698