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 #ifndef DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_MAC_H_ | 5 #ifndef DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_MAC_H_ |
6 #define DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_MAC_H_ | 6 #define DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_MAC_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/test/test_simple_task_runner.h" | 10 #include "base/test/test_simple_task_runner.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 const std::vector<uint8_t>& value) override; | 84 const std::vector<uint8_t>& value) override; |
85 void SimulateGattCharacteristicRemoved( | 85 void SimulateGattCharacteristicRemoved( |
86 BluetoothRemoteGattService* service, | 86 BluetoothRemoteGattService* service, |
87 BluetoothRemoteGattCharacteristic* characteristic) override; | 87 BluetoothRemoteGattCharacteristic* characteristic) override; |
88 void ExpectedChangeNotifyValueAttempts(int attempts) override; | 88 void ExpectedChangeNotifyValueAttempts(int attempts) override; |
89 void ExpectedNotifyValue(NotifyValueState expected_value_state) override; | 89 void ExpectedNotifyValue(NotifyValueState expected_value_state) override; |
90 | 90 |
91 // macOS is the only platform for which we need to discover each set of | 91 // macOS is the only platform for which we need to discover each set of |
92 // attributes individually so we need a method to simulate discovering each | 92 // attributes individually so we need a method to simulate discovering each |
93 // set of attributes. | 93 // set of attributes. |
94 void SimulateDidDiscoverServices(BluetoothDevice* device, | 94 // Simulates service discovery for a device. |
95 const std::vector<std::string>& uuids); | 95 void SimulateDidDiscoverServices(BluetoothDevice* device); |
| 96 // Simulates characteristic discovery for a service. |
| 97 void SimulateDidDiscoverCharacteristics(BluetoothRemoteGattService* service); |
| 98 // Simulates descriptor discovery for a characteristic. |
| 99 void SimulateDidDiscoverDescriptors( |
| 100 BluetoothRemoteGattCharacteristic* characteristic); |
| 101 // Adds services in MockCBPeripheral. |
| 102 void AddServicesToDevice(BluetoothDevice* device, |
| 103 const std::vector<std::string>& uuids); |
| 104 // Adds a characteristic in MockCBService. |
| 105 void AddCharacteristicToService(BluetoothRemoteGattService* service, |
| 106 const std::string& characteristic_uuid, |
| 107 int properties); |
| 108 // Adds a descriptor in MockCBCharacteristic. |
| 109 void AddDescriptorToCharacteristic( |
| 110 BluetoothRemoteGattCharacteristic* characteristic, |
| 111 const std::string& uuid); |
96 | 112 |
97 // Callback for the bluetooth central manager mock. | 113 // Callback for the bluetooth central manager mock. |
98 void OnFakeBluetoothDeviceConnectGattCalled(); | 114 void OnFakeBluetoothDeviceConnectGattCalled(); |
99 void OnFakeBluetoothGattDisconnect(); | 115 void OnFakeBluetoothGattDisconnect(); |
100 | 116 |
101 // Callback for the bluetooth peripheral mock. | 117 // Callback for the bluetooth peripheral mock. |
102 void OnFakeBluetoothServiceDiscovery(); | 118 void OnFakeBluetoothServiceDiscovery(); |
103 void OnFakeBluetoothCharacteristicDiscovery(); | 119 void OnFakeBluetoothCharacteristicDiscovery(); |
104 void OnFakeBluetoothCharacteristicReadValue(); | 120 void OnFakeBluetoothCharacteristicReadValue(); |
105 void OnFakeBluetoothCharacteristicWriteValue(std::vector<uint8_t> value); | 121 void OnFakeBluetoothCharacteristicWriteValue(std::vector<uint8_t> value); |
(...skipping 11 matching lines...) Expand all Loading... |
117 MockCBPeripheral* GetMockCBPeripheral(BluetoothDevice* device) const; | 133 MockCBPeripheral* GetMockCBPeripheral(BluetoothDevice* device) const; |
118 // Returns MockCBPeripheral from BluetoothRemoteGattService. | 134 // Returns MockCBPeripheral from BluetoothRemoteGattService. |
119 MockCBPeripheral* GetMockCBPeripheral( | 135 MockCBPeripheral* GetMockCBPeripheral( |
120 BluetoothRemoteGattService* service) const; | 136 BluetoothRemoteGattService* service) const; |
121 // Returns MockCBPeripheral from BluetoothRemoteGattCharacteristic. | 137 // Returns MockCBPeripheral from BluetoothRemoteGattCharacteristic. |
122 MockCBPeripheral* GetMockCBPeripheral( | 138 MockCBPeripheral* GetMockCBPeripheral( |
123 BluetoothRemoteGattCharacteristic* characteristic) const; | 139 BluetoothRemoteGattCharacteristic* characteristic) const; |
124 // Returns MockCBCharacteristic from BluetoothRemoteGattCharacteristic. | 140 // Returns MockCBCharacteristic from BluetoothRemoteGattCharacteristic. |
125 MockCBCharacteristic* GetCBMockCharacteristic( | 141 MockCBCharacteristic* GetCBMockCharacteristic( |
126 BluetoothRemoteGattCharacteristic* characteristic) const; | 142 BluetoothRemoteGattCharacteristic* characteristic) const; |
127 // Adds services in MockCBPeripheral. | |
128 void AddServicesToDevice(BluetoothDevice* device, | |
129 const std::vector<std::string>& uuids); | |
130 | 143 |
131 // Utility function for finding CBUUIDs with relatively nice SHA256 hashes. | 144 // Utility function for finding CBUUIDs with relatively nice SHA256 hashes. |
132 std::string FindCBUUIDForHashTarget(); | 145 std::string FindCBUUIDForHashTarget(); |
133 | 146 |
134 BluetoothAdapterMac* adapter_mac_ = nullptr; | 147 BluetoothAdapterMac* adapter_mac_ = nullptr; |
135 std::unique_ptr<ScopedMockCentralManager> mock_central_manager_; | 148 std::unique_ptr<ScopedMockCentralManager> mock_central_manager_; |
136 | 149 |
137 // Value set by -[CBPeripheral setNotifyValue:forCharacteristic:] call. | 150 // Value set by -[CBPeripheral setNotifyValue:forCharacteristic:] call. |
138 bool last_notify_value_ = false; | 151 bool last_notify_value_ = false; |
139 int gatt_characteristic_discovery_attempts_ = 0; | 152 int gatt_characteristic_discovery_attempts_ = 0; |
140 }; | 153 }; |
141 | 154 |
142 // Defines common test fixture name. Use TEST_F(BluetoothTest, YourTestName). | 155 // Defines common test fixture name. Use TEST_F(BluetoothTest, YourTestName). |
143 typedef BluetoothTestMac BluetoothTest; | 156 typedef BluetoothTestMac BluetoothTest; |
144 | 157 |
145 } // namespace device | 158 } // namespace device |
146 | 159 |
147 #endif // DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_MAC_H_ | 160 #endif // DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_MAC_H_ |
OLD | NEW |