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_H_ | 5 #ifndef DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_H_ |
6 #define DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_H_ | 6 #define DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_H_ |
7 | 7 |
| 8 #include <stdint.h> |
| 9 |
8 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
9 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
10 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
11 #include "device/bluetooth/bluetooth_adapter.h" | 13 #include "device/bluetooth/bluetooth_adapter.h" |
12 #include "device/bluetooth/bluetooth_device.h" | 14 #include "device/bluetooth/bluetooth_device.h" |
13 #include "device/bluetooth/bluetooth_discovery_session.h" | 15 #include "device/bluetooth/bluetooth_discovery_session.h" |
14 #include "device/bluetooth/bluetooth_gatt_characteristic.h" | 16 #include "device/bluetooth/bluetooth_gatt_characteristic.h" |
15 #include "device/bluetooth/bluetooth_gatt_connection.h" | 17 #include "device/bluetooth/bluetooth_gatt_connection.h" |
16 #include "device/bluetooth/bluetooth_gatt_notify_session.h" | 18 #include "device/bluetooth/bluetooth_gatt_notify_session.h" |
17 #include "device/bluetooth/bluetooth_gatt_service.h" | 19 #include "device/bluetooth/bluetooth_gatt_service.h" |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 // Simulates a Characteristic Set Notify operation failing synchronously once | 135 // Simulates a Characteristic Set Notify operation failing synchronously once |
134 // for an unknown reason. | 136 // for an unknown reason. |
135 virtual void SimulateGattCharacteristicSetNotifyWillFailSynchronouslyOnce( | 137 virtual void SimulateGattCharacteristicSetNotifyWillFailSynchronouslyOnce( |
136 BluetoothGattCharacteristic* characteristic) {} | 138 BluetoothGattCharacteristic* characteristic) {} |
137 | 139 |
138 // Simulates a Characteristic Read operation succeeding, returning |value|. | 140 // Simulates a Characteristic Read operation succeeding, returning |value|. |
139 // If |characteristic| is null, acts upon the characteristic provided to | 141 // If |characteristic| is null, acts upon the characteristic provided to |
140 // RememberCharacteristicForSubsequentAction. | 142 // RememberCharacteristicForSubsequentAction. |
141 virtual void SimulateGattCharacteristicRead( | 143 virtual void SimulateGattCharacteristicRead( |
142 BluetoothGattCharacteristic* characteristic, | 144 BluetoothGattCharacteristic* characteristic, |
143 const std::vector<uint8>& value) {} | 145 const std::vector<uint8_t>& value) {} |
144 | 146 |
145 // Simulates a Characteristic Read operation failing with a GattErrorCode. | 147 // Simulates a Characteristic Read operation failing with a GattErrorCode. |
146 virtual void SimulateGattCharacteristicReadError( | 148 virtual void SimulateGattCharacteristicReadError( |
147 BluetoothGattCharacteristic* characteristic, | 149 BluetoothGattCharacteristic* characteristic, |
148 BluetoothGattService::GattErrorCode) {} | 150 BluetoothGattService::GattErrorCode) {} |
149 | 151 |
150 // Simulates a Characteristic Read operation failing synchronously once for an | 152 // Simulates a Characteristic Read operation failing synchronously once for an |
151 // unknown reason. | 153 // unknown reason. |
152 virtual void SimulateGattCharacteristicReadWillFailSynchronouslyOnce( | 154 virtual void SimulateGattCharacteristicReadWillFailSynchronouslyOnce( |
153 BluetoothGattCharacteristic* characteristic) {} | 155 BluetoothGattCharacteristic* characteristic) {} |
(...skipping 17 matching lines...) Expand all Loading... |
171 // Removes the device from the adapter and deletes it. | 173 // Removes the device from the adapter and deletes it. |
172 virtual void DeleteDevice(BluetoothDevice* device); | 174 virtual void DeleteDevice(BluetoothDevice* device); |
173 | 175 |
174 // Callbacks that increment |callback_count_|, |error_callback_count_|: | 176 // Callbacks that increment |callback_count_|, |error_callback_count_|: |
175 void Callback(Call expected); | 177 void Callback(Call expected); |
176 void DiscoverySessionCallback(Call expected, | 178 void DiscoverySessionCallback(Call expected, |
177 scoped_ptr<BluetoothDiscoverySession>); | 179 scoped_ptr<BluetoothDiscoverySession>); |
178 void GattConnectionCallback(Call expected, | 180 void GattConnectionCallback(Call expected, |
179 scoped_ptr<BluetoothGattConnection>); | 181 scoped_ptr<BluetoothGattConnection>); |
180 void NotifyCallback(Call expected, scoped_ptr<BluetoothGattNotifySession>); | 182 void NotifyCallback(Call expected, scoped_ptr<BluetoothGattNotifySession>); |
181 void ReadValueCallback(Call expected, const std::vector<uint8>& value); | 183 void ReadValueCallback(Call expected, const std::vector<uint8_t>& value); |
182 void ErrorCallback(Call expected); | 184 void ErrorCallback(Call expected); |
183 void ConnectErrorCallback(Call expected, | 185 void ConnectErrorCallback(Call expected, |
184 enum BluetoothDevice::ConnectErrorCode); | 186 enum BluetoothDevice::ConnectErrorCode); |
185 void GattErrorCallback(Call expected, BluetoothGattService::GattErrorCode); | 187 void GattErrorCallback(Call expected, BluetoothGattService::GattErrorCode); |
186 | 188 |
187 // Accessors to get callbacks bound to this fixture: | 189 // Accessors to get callbacks bound to this fixture: |
188 base::Closure GetCallback(Call expected); | 190 base::Closure GetCallback(Call expected); |
189 BluetoothAdapter::DiscoverySessionCallback GetDiscoverySessionCallback( | 191 BluetoothAdapter::DiscoverySessionCallback GetDiscoverySessionCallback( |
190 Call expected); | 192 Call expected); |
191 BluetoothDevice::GattConnectionCallback GetGattConnectionCallback( | 193 BluetoothDevice::GattConnectionCallback GetGattConnectionCallback( |
(...skipping 13 matching lines...) Expand all Loading... |
205 // A Message loop is required by some implementations that will PostTasks and | 207 // A Message loop is required by some implementations that will PostTasks and |
206 // by base::RunLoop().RunUntilIdle() use in this fixture. | 208 // by base::RunLoop().RunUntilIdle() use in this fixture. |
207 base::MessageLoop message_loop_; | 209 base::MessageLoop message_loop_; |
208 | 210 |
209 scoped_refptr<BluetoothAdapter> adapter_; | 211 scoped_refptr<BluetoothAdapter> adapter_; |
210 ScopedVector<BluetoothDiscoverySession> discovery_sessions_; | 212 ScopedVector<BluetoothDiscoverySession> discovery_sessions_; |
211 ScopedVector<BluetoothGattConnection> gatt_connections_; | 213 ScopedVector<BluetoothGattConnection> gatt_connections_; |
212 enum BluetoothDevice::ConnectErrorCode last_connect_error_code_ = | 214 enum BluetoothDevice::ConnectErrorCode last_connect_error_code_ = |
213 BluetoothDevice::ERROR_UNKNOWN; | 215 BluetoothDevice::ERROR_UNKNOWN; |
214 ScopedVector<BluetoothGattNotifySession> notify_sessions_; | 216 ScopedVector<BluetoothGattNotifySession> notify_sessions_; |
215 std::vector<uint8> last_read_value_; | 217 std::vector<uint8_t> last_read_value_; |
216 std::vector<uint8> last_write_value_; | 218 std::vector<uint8_t> last_write_value_; |
217 BluetoothGattService::GattErrorCode last_gatt_error_code_; | 219 BluetoothGattService::GattErrorCode last_gatt_error_code_; |
218 | 220 |
219 int callback_count_ = 0; | 221 int callback_count_ = 0; |
220 int error_callback_count_ = 0; | 222 int error_callback_count_ = 0; |
221 int gatt_connection_attempts_ = 0; | 223 int gatt_connection_attempts_ = 0; |
222 int gatt_disconnection_attempts_ = 0; | 224 int gatt_disconnection_attempts_ = 0; |
223 int gatt_discovery_attempts_ = 0; | 225 int gatt_discovery_attempts_ = 0; |
224 int gatt_notify_characteristic_attempts_ = 0; | 226 int gatt_notify_characteristic_attempts_ = 0; |
225 int gatt_read_characteristic_attempts_ = 0; | 227 int gatt_read_characteristic_attempts_ = 0; |
226 int gatt_write_characteristic_attempts_ = 0; | 228 int gatt_write_characteristic_attempts_ = 0; |
227 | 229 |
228 // The following values are used to make sure the correct callbacks | 230 // The following values are used to make sure the correct callbacks |
229 // have been called. They are not reset when calling ResetEventCounts(). | 231 // have been called. They are not reset when calling ResetEventCounts(). |
230 int expected_success_callback_calls_ = 0; | 232 int expected_success_callback_calls_ = 0; |
231 int expected_error_callback_calls_ = 0; | 233 int expected_error_callback_calls_ = 0; |
232 int actual_success_callback_calls_ = 0; | 234 int actual_success_callback_calls_ = 0; |
233 int actual_error_callback_calls_ = 0; | 235 int actual_error_callback_calls_ = 0; |
234 bool unexpected_success_callback_ = false; | 236 bool unexpected_success_callback_ = false; |
235 bool unexpected_error_callback_ = false; | 237 bool unexpected_error_callback_ = false; |
236 | 238 |
237 base::WeakPtrFactory<BluetoothTestBase> weak_factory_; | 239 base::WeakPtrFactory<BluetoothTestBase> weak_factory_; |
238 }; | 240 }; |
239 | 241 |
240 } // namespace device | 242 } // namespace device |
241 | 243 |
242 #endif // DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_H_ | 244 #endif // DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_H_ |
OLD | NEW |