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

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

Issue 2641133003: Bluetooth: macOS: Adding counter for service discovery callbacks. (Closed)
Patch Set: Adding BluetoothTestMac::SimulateDidDiscoverServices() Created 3 years, 9 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 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 static_cast<BluetoothRemoteGattServiceMac*>(service); 460 static_cast<BluetoothRemoteGattServiceMac*>(service);
461 CBService* cb_service = mac_gatt_service->GetService(); 461 CBService* cb_service = mac_gatt_service->GetService();
462 MockCBService* service_mock = ObjCCast<MockCBService>(cb_service); 462 MockCBService* service_mock = ObjCCast<MockCBService>(cb_service);
463 BluetoothRemoteGattCharacteristicMac* characteristic_mac = 463 BluetoothRemoteGattCharacteristicMac* characteristic_mac =
464 static_cast<BluetoothRemoteGattCharacteristicMac*>(characteristic); 464 static_cast<BluetoothRemoteGattCharacteristicMac*>(characteristic);
465 CBCharacteristic* cb_characteristic = 465 CBCharacteristic* cb_characteristic =
466 characteristic_mac->GetCBCharacteristic(); 466 characteristic_mac->GetCBCharacteristic();
467 MockCBCharacteristic* characteristic_mock = 467 MockCBCharacteristic* characteristic_mock =
468 ObjCCast<MockCBCharacteristic>(cb_characteristic); 468 ObjCCast<MockCBCharacteristic>(cb_characteristic);
469 [service_mock removeCharacteristicMock:characteristic_mock]; 469 [service_mock removeCharacteristicMock:characteristic_mock];
470 [peripheral_mock didModifyServices:@[]];
470 [peripheral_mock mockDidDiscoverEvents]; 471 [peripheral_mock mockDidDiscoverEvents];
471 } 472 }
472 473
473 void BluetoothTestMac::ExpectedChangeNotifyValueAttempts(int attempts) { 474 void BluetoothTestMac::ExpectedChangeNotifyValueAttempts(int attempts) {
474 EXPECT_EQ(attempts, gatt_notify_characteristic_attempts_); 475 EXPECT_EQ(attempts, gatt_notify_characteristic_attempts_);
475 } 476 }
476 477
477 void BluetoothTestMac::ExpectedNotifyValue( 478 void BluetoothTestMac::ExpectedNotifyValue(
478 NotifyValueState expected_value_state) { 479 NotifyValueState expected_value_state) {
479 switch (expected_value_state) { 480 switch (expected_value_state) {
480 case NotifyValueState::NONE: 481 case NotifyValueState::NONE:
481 EXPECT_FALSE(last_notify_value_); 482 EXPECT_FALSE(last_notify_value_);
482 break; 483 break;
483 case NotifyValueState::NOTIFY: 484 case NotifyValueState::NOTIFY:
484 case NotifyValueState::INDICATE: 485 case NotifyValueState::INDICATE:
485 EXPECT_TRUE(last_notify_value_); 486 EXPECT_TRUE(last_notify_value_);
486 break; 487 break;
487 } 488 }
488 } 489 }
489 490
491 void BluetoothTestMac::SimulateDidDiscoverServices(
ortuno 2017/03/06 09:49:55 Seems like we are repeating a lot of code from Sim
jlebel 2017/03/06 22:13:20 crrev.com/2738563002
492 BluetoothDevice* device,
493 const std::vector<std::string>& uuids) {
494 BluetoothLowEnergyDeviceMac* device_mac =
495 static_cast<BluetoothLowEnergyDeviceMac*>(device);
496 CBPeripheral* peripheral = device_mac->GetPeripheral();
497 MockCBPeripheral* peripheral_mock = ObjCCast<MockCBPeripheral>(peripheral);
498 scoped_nsobject<NSMutableArray> services([[NSMutableArray alloc] init]);
499 for (auto uuid : uuids) {
500 CBUUID* cb_service_uuid = [CBUUID UUIDWithString:@(uuid.c_str())];
501 [services addObject:cb_service_uuid];
502 }
503 [peripheral_mock addServices:services];
504 [peripheral_mock mockDidDiscoverServices];
505 }
506
490 void BluetoothTestMac::OnFakeBluetoothDeviceConnectGattCalled() { 507 void BluetoothTestMac::OnFakeBluetoothDeviceConnectGattCalled() {
491 gatt_connection_attempts_++; 508 gatt_connection_attempts_++;
492 } 509 }
493 510
494 void BluetoothTestMac::OnFakeBluetoothGattDisconnect() { 511 void BluetoothTestMac::OnFakeBluetoothGattDisconnect() {
495 gatt_disconnection_attempts_++; 512 gatt_disconnection_attempts_++;
496 } 513 }
497 514
498 void BluetoothTestMac::OnFakeBluetoothServiceDiscovery() { 515 void BluetoothTestMac::OnFakeBluetoothServiceDiscovery() {
499 gatt_discovery_attempts_++; 516 gatt_discovery_attempts_++;
500 } 517 }
501 518
519 void BluetoothTestMac::OnFakeBluetoothCharacteristicDiscovery() {
520 gatt_characteristic_discovery_attempts_++;
521 }
522
502 void BluetoothTest::OnFakeBluetoothCharacteristicReadValue() { 523 void BluetoothTest::OnFakeBluetoothCharacteristicReadValue() {
503 gatt_read_characteristic_attempts_++; 524 gatt_read_characteristic_attempts_++;
504 } 525 }
505 526
506 void BluetoothTest::OnFakeBluetoothCharacteristicWriteValue( 527 void BluetoothTest::OnFakeBluetoothCharacteristicWriteValue(
507 std::vector<uint8_t> value) { 528 std::vector<uint8_t> value) {
508 last_write_value_ = value; 529 last_write_value_ = value;
509 gatt_write_characteristic_attempts_++; 530 gatt_write_characteristic_attempts_++;
510 } 531 }
511 532
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 // crypto::SHA256HashString(input_str, raw, sizeof(raw)); 603 // crypto::SHA256HashString(input_str, raw, sizeof(raw));
583 // if (base::HexEncode(raw, sizeof(raw)) == target) { 604 // if (base::HexEncode(raw, sizeof(raw)) == target) {
584 // return input_str; 605 // return input_str;
585 // } 606 // }
586 // ++input[0]; 607 // ++input[0];
587 // } 608 // }
588 // return ""; 609 // return "";
589 // } 610 // }
590 611
591 } // namespace device 612 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698