OLD | NEW |
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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 | 126 |
127 if (BluetoothAdapterMac::IsLowEnergyAvailable()) { | 127 if (BluetoothAdapterMac::IsLowEnergyAvailable()) { |
128 mock_central_manager_.reset( | 128 mock_central_manager_.reset( |
129 new ScopedMockCentralManager([[MockCentralManager alloc] init])); | 129 new ScopedMockCentralManager([[MockCentralManager alloc] init])); |
130 mock_central_manager_->get().bluetoothTestMac = this; | 130 mock_central_manager_->get().bluetoothTestMac = this; |
131 [mock_central_manager_->get() setState:CBCentralManagerStatePoweredOn]; | 131 [mock_central_manager_->get() setState:CBCentralManagerStatePoweredOn]; |
132 adapter_mac_->SetCentralManagerForTesting((id)mock_central_manager_->get()); | 132 adapter_mac_->SetCentralManagerForTesting((id)mock_central_manager_->get()); |
133 } | 133 } |
134 } | 134 } |
135 | 135 |
| 136 void BluetoothTestMac::ResetEventCounts() { |
| 137 BluetoothTestBase::ResetEventCounts(); |
| 138 last_notify_value = false; |
| 139 gatt_notify_characteristic_attempts_ = 0; |
| 140 } |
| 141 |
136 BluetoothDevice* BluetoothTestMac::SimulateLowEnergyDevice(int device_ordinal) { | 142 BluetoothDevice* BluetoothTestMac::SimulateLowEnergyDevice(int device_ordinal) { |
137 TestBluetoothAdapterObserver observer(adapter_); | 143 TestBluetoothAdapterObserver observer(adapter_); |
138 CBCentralManager* central_manager = adapter_mac_->low_energy_central_manager_; | 144 CBCentralManager* central_manager = adapter_mac_->low_energy_central_manager_; |
139 BluetoothLowEnergyCentralManagerDelegate* central_manager_delegate = | 145 BluetoothLowEnergyCentralManagerDelegate* central_manager_delegate = |
140 adapter_mac_->low_energy_central_manager_delegate_; | 146 adapter_mac_->low_energy_central_manager_delegate_; |
141 | 147 |
142 const char* identifier; | 148 const char* identifier; |
143 NSString* name; | 149 NSString* name; |
144 NSArray* uuids; | 150 NSArray* uuids; |
145 NSNumber* rssi; | 151 NSNumber* rssi; |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 BluetoothRemoteGattCharacteristicMac* characteristic_mac = | 464 BluetoothRemoteGattCharacteristicMac* characteristic_mac = |
459 static_cast<BluetoothRemoteGattCharacteristicMac*>(characteristic); | 465 static_cast<BluetoothRemoteGattCharacteristicMac*>(characteristic); |
460 CBCharacteristic* cb_characteristic = | 466 CBCharacteristic* cb_characteristic = |
461 characteristic_mac->GetCBCharacteristic(); | 467 characteristic_mac->GetCBCharacteristic(); |
462 MockCBCharacteristic* characteristic_mock = | 468 MockCBCharacteristic* characteristic_mock = |
463 ObjCCast<MockCBCharacteristic>(cb_characteristic); | 469 ObjCCast<MockCBCharacteristic>(cb_characteristic); |
464 [service_mock removeCharacteristicMock:characteristic_mock]; | 470 [service_mock removeCharacteristicMock:characteristic_mock]; |
465 [peripheral_mock mockDidDiscoverEvents]; | 471 [peripheral_mock mockDidDiscoverEvents]; |
466 } | 472 } |
467 | 473 |
| 474 void BluetoothTestMac::ExpectedChangeNotifyValueAttempts(int attempts) { |
| 475 EXPECT_EQ(attempts, gatt_notify_characteristic_attempts_); |
| 476 } |
| 477 |
| 478 void BluetoothTestMac::ExpectedNotifyValue( |
| 479 NotifyValueState expected_value_state) { |
| 480 switch (expected_value_state) { |
| 481 case NotifyValueState::NONE: |
| 482 EXPECT_FALSE(last_notify_value); |
| 483 break; |
| 484 case NotifyValueState::NOTIFY: |
| 485 case NotifyValueState::INDICATE: |
| 486 EXPECT_TRUE(last_notify_value); |
| 487 break; |
| 488 } |
| 489 } |
| 490 |
468 void BluetoothTestMac::OnFakeBluetoothDeviceConnectGattCalled() { | 491 void BluetoothTestMac::OnFakeBluetoothDeviceConnectGattCalled() { |
469 gatt_connection_attempts_++; | 492 gatt_connection_attempts_++; |
470 } | 493 } |
471 | 494 |
472 void BluetoothTestMac::OnFakeBluetoothGattDisconnect() { | 495 void BluetoothTestMac::OnFakeBluetoothGattDisconnect() { |
473 gatt_disconnection_attempts_++; | 496 gatt_disconnection_attempts_++; |
474 } | 497 } |
475 | 498 |
476 void BluetoothTestMac::OnFakeBluetoothServiceDiscovery() { | 499 void BluetoothTestMac::OnFakeBluetoothServiceDiscovery() { |
477 gatt_discovery_attempts_++; | 500 gatt_discovery_attempts_++; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
560 // crypto::SHA256HashString(input_str, raw, sizeof(raw)); | 583 // crypto::SHA256HashString(input_str, raw, sizeof(raw)); |
561 // if (base::HexEncode(raw, sizeof(raw)) == target) { | 584 // if (base::HexEncode(raw, sizeof(raw)) == target) { |
562 // return input_str; | 585 // return input_str; |
563 // } | 586 // } |
564 // ++input[0]; | 587 // ++input[0]; |
565 // } | 588 // } |
566 // return ""; | 589 // return ""; |
567 // } | 590 // } |
568 | 591 |
569 } // namespace device | 592 } // namespace device |
OLD | NEW |