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

Side by Side Diff: device/bluetooth/test/bluetooth_test.h

Issue 1422463012: bluetooth: android: Implement StartNotifySession. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed ortuno Created 5 years, 1 month 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 #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 "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/memory/weak_ptr.h" 9 #include "base/memory/weak_ptr.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "device/bluetooth/bluetooth_adapter.h" 11 #include "device/bluetooth/bluetooth_adapter.h"
12 #include "device/bluetooth/bluetooth_device.h" 12 #include "device/bluetooth/bluetooth_device.h"
13 #include "device/bluetooth/bluetooth_discovery_session.h" 13 #include "device/bluetooth/bluetooth_discovery_session.h"
14 #include "device/bluetooth/bluetooth_gatt_characteristic.h" 14 #include "device/bluetooth/bluetooth_gatt_characteristic.h"
15 #include "device/bluetooth/bluetooth_gatt_connection.h" 15 #include "device/bluetooth/bluetooth_gatt_connection.h"
16 #include "device/bluetooth/bluetooth_gatt_notify_session.h"
16 #include "device/bluetooth/bluetooth_gatt_service.h" 17 #include "device/bluetooth/bluetooth_gatt_service.h"
17 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
18 19
19 namespace device { 20 namespace device {
20 21
21 class BluetoothAdapter; 22 class BluetoothAdapter;
22 class BluetoothDevice; 23 class BluetoothDevice;
23 24
24 // A test fixture for Bluetooth that abstracts platform specifics for creating 25 // A test fixture for Bluetooth that abstracts platform specifics for creating
25 // and controlling fake low level objects. 26 // and controlling fake low level objects.
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 const std::vector<std::string>& uuids) {} 95 const std::vector<std::string>& uuids) {}
95 96
96 // Simulates failure to discover services. 97 // Simulates failure to discover services.
97 virtual void SimulateGattServicesDiscoveryError(BluetoothDevice* device) {} 98 virtual void SimulateGattServicesDiscoveryError(BluetoothDevice* device) {}
98 99
99 // Simulates a Characteristic on a service. 100 // Simulates a Characteristic on a service.
100 virtual void SimulateGattCharacteristic(BluetoothGattService* service, 101 virtual void SimulateGattCharacteristic(BluetoothGattService* service,
101 const std::string& uuid, 102 const std::string& uuid,
102 int properties) {} 103 int properties) {}
103 104
105 // Simulates a Characteristic Set Notify success.
106 virtual void SimulateGattNotifySessionStarted(
107 BluetoothGattCharacteristic* characteristic) {}
108
109 // Simulates a Characteristic Set Notify operation failing synchronously once
110 // for an unknown reason.
111 virtual void SimulateGattCharacteristicSetNotifyWillFailSynchronouslyOnce(
112 BluetoothGattCharacteristic* characteristic) {}
113
104 // Simulates a Characteristic Read operation succeeding, returning |value|. 114 // Simulates a Characteristic Read operation succeeding, returning |value|.
105 virtual void SimulateGattCharacteristicRead( 115 virtual void SimulateGattCharacteristicRead(
106 BluetoothGattCharacteristic* characteristic, 116 BluetoothGattCharacteristic* characteristic,
107 const std::vector<uint8>& value) {} 117 const std::vector<uint8>& value) {}
108 118
109 // Simulates a Characteristic Read operation failing with a GattErrorCode. 119 // Simulates a Characteristic Read operation failing with a GattErrorCode.
110 virtual void SimulateGattCharacteristicReadError( 120 virtual void SimulateGattCharacteristicReadError(
111 BluetoothGattCharacteristic* characteristic, 121 BluetoothGattCharacteristic* characteristic,
112 BluetoothGattService::GattErrorCode) {} 122 BluetoothGattService::GattErrorCode) {}
113 123
(...skipping 16 matching lines...) Expand all
130 virtual void SimulateGattCharacteristicWriteWillFailSynchronouslyOnce( 140 virtual void SimulateGattCharacteristicWriteWillFailSynchronouslyOnce(
131 BluetoothGattCharacteristic* characteristic) {} 141 BluetoothGattCharacteristic* characteristic) {}
132 142
133 // Remove the device from the adapter and delete it. 143 // Remove the device from the adapter and delete it.
134 virtual void DeleteDevice(BluetoothDevice* device); 144 virtual void DeleteDevice(BluetoothDevice* device);
135 145
136 // Callbacks that increment |callback_count_|, |error_callback_count_|: 146 // Callbacks that increment |callback_count_|, |error_callback_count_|:
137 void Callback(); 147 void Callback();
138 void DiscoverySessionCallback(scoped_ptr<BluetoothDiscoverySession>); 148 void DiscoverySessionCallback(scoped_ptr<BluetoothDiscoverySession>);
139 void GattConnectionCallback(scoped_ptr<BluetoothGattConnection>); 149 void GattConnectionCallback(scoped_ptr<BluetoothGattConnection>);
150 void NotifyCallback(scoped_ptr<BluetoothGattNotifySession>);
140 void ReadValueCallback(const std::vector<uint8>& value); 151 void ReadValueCallback(const std::vector<uint8>& value);
141 void ErrorCallback(); 152 void ErrorCallback();
142 void ConnectErrorCallback(enum BluetoothDevice::ConnectErrorCode); 153 void ConnectErrorCallback(enum BluetoothDevice::ConnectErrorCode);
143 void GattErrorCallback(BluetoothGattService::GattErrorCode); 154 void GattErrorCallback(BluetoothGattService::GattErrorCode);
144 155
145 // Accessors to get callbacks bound to this fixture: 156 // Accessors to get callbacks bound to this fixture:
146 base::Closure GetCallback(); 157 base::Closure GetCallback();
147 BluetoothAdapter::DiscoverySessionCallback GetDiscoverySessionCallback(); 158 BluetoothAdapter::DiscoverySessionCallback GetDiscoverySessionCallback();
148 BluetoothDevice::GattConnectionCallback GetGattConnectionCallback(); 159 BluetoothDevice::GattConnectionCallback GetGattConnectionCallback();
160 BluetoothGattCharacteristic::NotifySessionCallback GetNotifyCallback();
149 BluetoothGattCharacteristic::ValueCallback GetReadValueCallback(); 161 BluetoothGattCharacteristic::ValueCallback GetReadValueCallback();
150 BluetoothAdapter::ErrorCallback GetErrorCallback(); 162 BluetoothAdapter::ErrorCallback GetErrorCallback();
151 BluetoothDevice::ConnectErrorCallback GetConnectErrorCallback(); 163 BluetoothDevice::ConnectErrorCallback GetConnectErrorCallback();
152 base::Callback<void(BluetoothGattService::GattErrorCode)> 164 base::Callback<void(BluetoothGattService::GattErrorCode)>
153 GetGattErrorCallback(); 165 GetGattErrorCallback();
154 166
155 // Reset all event count members to 0. 167 // Reset all event count members to 0.
156 void ResetEventCounts(); 168 void ResetEventCounts();
157 169
158 // A Message loop is required by some implementations that will PostTasks and 170 // A Message loop is required by some implementations that will PostTasks and
159 // by base::RunLoop().RunUntilIdle() use in this fixuture. 171 // by base::RunLoop().RunUntilIdle() use in this fixuture.
160 base::MessageLoop message_loop_; 172 base::MessageLoop message_loop_;
161 173
162 scoped_refptr<BluetoothAdapter> adapter_; 174 scoped_refptr<BluetoothAdapter> adapter_;
163 ScopedVector<BluetoothDiscoverySession> discovery_sessions_; 175 ScopedVector<BluetoothDiscoverySession> discovery_sessions_;
164 ScopedVector<BluetoothGattConnection> gatt_connections_; 176 ScopedVector<BluetoothGattConnection> gatt_connections_;
165 enum BluetoothDevice::ConnectErrorCode last_connect_error_code_ = 177 enum BluetoothDevice::ConnectErrorCode last_connect_error_code_ =
166 BluetoothDevice::ERROR_UNKNOWN; 178 BluetoothDevice::ERROR_UNKNOWN;
179 ScopedVector<BluetoothGattNotifySession> notify_sessions_;
167 std::vector<uint8> last_read_value_; 180 std::vector<uint8> last_read_value_;
168 std::vector<uint8> last_write_value_; 181 std::vector<uint8> last_write_value_;
169 BluetoothGattService::GattErrorCode last_gatt_error_code_; 182 BluetoothGattService::GattErrorCode last_gatt_error_code_;
170 int callback_count_ = 0; 183 int callback_count_ = 0;
171 int error_callback_count_ = 0; 184 int error_callback_count_ = 0;
172 int gatt_connection_attempts_ = 0; 185 int gatt_connection_attempts_ = 0;
173 int gatt_disconnection_attempts_ = 0; 186 int gatt_disconnection_attempts_ = 0;
174 int gatt_discovery_attempts_ = 0; 187 int gatt_discovery_attempts_ = 0;
188 int gatt_notify_characteristic_attempts_ = 0;
175 int gatt_read_characteristic_attempts_ = 0; 189 int gatt_read_characteristic_attempts_ = 0;
176 int gatt_write_characteristic_attempts_ = 0; 190 int gatt_write_characteristic_attempts_ = 0;
177 base::WeakPtrFactory<BluetoothTestBase> weak_factory_; 191 base::WeakPtrFactory<BluetoothTestBase> weak_factory_;
178 }; 192 };
179 193
180 } // namespace device 194 } // namespace device
181 195
182 #endif // DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_H_ 196 #endif // DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698