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

Side by Side Diff: device/bluetooth/test/test_bluetooth_adapter_observer.cc

Issue 1898643002: Refactor device::BluetoothGattXXX classes to split into remote/local. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
« no previous file with comments | « device/bluetooth/test/test_bluetooth_adapter_observer.h ('k') | device/device_tests.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/test_bluetooth_adapter_observer.h" 5 #include "device/bluetooth/test/test_bluetooth_adapter_observer.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "device/bluetooth/bluetooth_gatt_characteristic.h" 11 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h"
12 #include "device/bluetooth/bluetooth_gatt_descriptor.h" 12 #include "device/bluetooth/bluetooth_remote_gatt_descriptor.h"
13 #include "device/bluetooth/bluetooth_gatt_service.h" 13 #include "device/bluetooth/bluetooth_remote_gatt_service.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 15
16 namespace device { 16 namespace device {
17 17
18 TestBluetoothAdapterObserver::TestBluetoothAdapterObserver( 18 TestBluetoothAdapterObserver::TestBluetoothAdapterObserver(
19 scoped_refptr<BluetoothAdapter> adapter) 19 scoped_refptr<BluetoothAdapter> adapter)
20 : adapter_(adapter) { 20 : adapter_(adapter) {
21 Reset(); 21 Reset();
22 adapter_->AddObserver(this); 22 adapter_->AddObserver(this);
23 } 23 }
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 ++device_removed_count_; 153 ++device_removed_count_;
154 // Can't save device, it may be freed 154 // Can't save device, it may be freed
155 last_device_address_ = device->GetAddress(); 155 last_device_address_ = device->GetAddress();
156 156
157 QuitMessageLoop(); 157 QuitMessageLoop();
158 } 158 }
159 159
160 void TestBluetoothAdapterObserver::GattServiceAdded( 160 void TestBluetoothAdapterObserver::GattServiceAdded(
161 BluetoothAdapter* adapter, 161 BluetoothAdapter* adapter,
162 BluetoothDevice* device, 162 BluetoothDevice* device,
163 BluetoothGattService* service) { 163 BluetoothRemoteGattService* service) {
164 ASSERT_EQ(adapter_.get(), adapter); 164 ASSERT_EQ(adapter_.get(), adapter);
165 ASSERT_EQ(service->GetDevice(), device); 165 ASSERT_EQ(service->GetDevice(), device);
166 166
167 ++gatt_service_added_count_; 167 ++gatt_service_added_count_;
168 last_gatt_service_id_ = service->GetIdentifier(); 168 last_gatt_service_id_ = service->GetIdentifier();
169 last_gatt_service_uuid_ = service->GetUUID(); 169 last_gatt_service_uuid_ = service->GetUUID();
170 170
171 EXPECT_FALSE(service->IsLocal());
172 EXPECT_TRUE(service->IsPrimary()); 171 EXPECT_TRUE(service->IsPrimary());
173 172
174 EXPECT_EQ(device->GetGattService(last_gatt_service_id_), service); 173 EXPECT_EQ(device->GetGattService(last_gatt_service_id_), service);
175 174
176 QuitMessageLoop(); 175 QuitMessageLoop();
177 } 176 }
178 177
179 void TestBluetoothAdapterObserver::GattServiceRemoved( 178 void TestBluetoothAdapterObserver::GattServiceRemoved(
180 BluetoothAdapter* adapter, 179 BluetoothAdapter* adapter,
181 BluetoothDevice* device, 180 BluetoothDevice* device,
182 BluetoothGattService* service) { 181 BluetoothRemoteGattService* service) {
183 ASSERT_EQ(adapter_.get(), adapter); 182 ASSERT_EQ(adapter_.get(), adapter);
184 ASSERT_EQ(service->GetDevice(), device); 183 ASSERT_EQ(service->GetDevice(), device);
185 184
186 ++gatt_service_removed_count_; 185 ++gatt_service_removed_count_;
187 last_gatt_service_id_ = service->GetIdentifier(); 186 last_gatt_service_id_ = service->GetIdentifier();
188 last_gatt_service_uuid_ = service->GetUUID(); 187 last_gatt_service_uuid_ = service->GetUUID();
189 188
190 EXPECT_FALSE(service->IsLocal());
191 EXPECT_TRUE(service->IsPrimary()); 189 EXPECT_TRUE(service->IsPrimary());
192 190
193 // The device should return NULL for this service. 191 // The device should return NULL for this service.
194 EXPECT_FALSE(device->GetGattService(last_gatt_service_id_)); 192 EXPECT_FALSE(device->GetGattService(last_gatt_service_id_));
195 193
196 QuitMessageLoop(); 194 QuitMessageLoop();
197 } 195 }
198 196
199 void TestBluetoothAdapterObserver::GattServicesDiscovered( 197 void TestBluetoothAdapterObserver::GattServicesDiscovered(
200 BluetoothAdapter* adapter, 198 BluetoothAdapter* adapter,
201 BluetoothDevice* device) { 199 BluetoothDevice* device) {
202 ASSERT_EQ(adapter_.get(), adapter); 200 ASSERT_EQ(adapter_.get(), adapter);
203 201
204 ++gatt_services_discovered_count_; 202 ++gatt_services_discovered_count_;
205 last_device_ = device; 203 last_device_ = device;
206 last_device_address_ = device->GetAddress(); 204 last_device_address_ = device->GetAddress();
207 205
208 QuitMessageLoop(); 206 QuitMessageLoop();
209 } 207 }
210 208
211 void TestBluetoothAdapterObserver::GattDiscoveryCompleteForService( 209 void TestBluetoothAdapterObserver::GattDiscoveryCompleteForService(
212 BluetoothAdapter* adapter, 210 BluetoothAdapter* adapter,
213 BluetoothGattService* service) { 211 BluetoothRemoteGattService* service) {
214 ASSERT_EQ(adapter_.get(), adapter); 212 ASSERT_EQ(adapter_.get(), adapter);
215 ++gatt_discovery_complete_count_; 213 ++gatt_discovery_complete_count_;
216 214
217 QuitMessageLoop(); 215 QuitMessageLoop();
218 } 216 }
219 217
220 void TestBluetoothAdapterObserver::GattServiceChanged( 218 void TestBluetoothAdapterObserver::GattServiceChanged(
221 BluetoothAdapter* adapter, 219 BluetoothAdapter* adapter,
222 BluetoothGattService* service) { 220 BluetoothRemoteGattService* service) {
223 ASSERT_EQ(adapter_.get(), adapter); 221 ASSERT_EQ(adapter_.get(), adapter);
224 ++gatt_service_changed_count_; 222 ++gatt_service_changed_count_;
225 223
226 QuitMessageLoop(); 224 QuitMessageLoop();
227 } 225 }
228 226
229 void TestBluetoothAdapterObserver::GattCharacteristicAdded( 227 void TestBluetoothAdapterObserver::GattCharacteristicAdded(
230 BluetoothAdapter* adapter, 228 BluetoothAdapter* adapter,
231 BluetoothGattCharacteristic* characteristic) { 229 BluetoothRemoteGattCharacteristic* characteristic) {
232 ASSERT_EQ(adapter_.get(), adapter); 230 ASSERT_EQ(adapter_.get(), adapter);
233 231
234 ++gatt_characteristic_added_count_; 232 ++gatt_characteristic_added_count_;
235 last_gatt_characteristic_id_ = characteristic->GetIdentifier(); 233 last_gatt_characteristic_id_ = characteristic->GetIdentifier();
236 last_gatt_characteristic_uuid_ = characteristic->GetUUID(); 234 last_gatt_characteristic_uuid_ = characteristic->GetUUID();
237 235
238 ASSERT_TRUE(characteristic->GetService()); 236 ASSERT_TRUE(characteristic->GetService());
239 EXPECT_EQ(characteristic->GetService()->GetCharacteristic( 237 EXPECT_EQ(characteristic->GetService()->GetCharacteristic(
240 last_gatt_characteristic_id_), 238 last_gatt_characteristic_id_),
241 characteristic); 239 characteristic);
242 240
243 QuitMessageLoop(); 241 QuitMessageLoop();
244 } 242 }
245 243
246 void TestBluetoothAdapterObserver::GattCharacteristicRemoved( 244 void TestBluetoothAdapterObserver::GattCharacteristicRemoved(
247 BluetoothAdapter* adapter, 245 BluetoothAdapter* adapter,
248 BluetoothGattCharacteristic* characteristic) { 246 BluetoothRemoteGattCharacteristic* characteristic) {
249 ASSERT_EQ(adapter_.get(), adapter); 247 ASSERT_EQ(adapter_.get(), adapter);
250 248
251 ++gatt_characteristic_removed_count_; 249 ++gatt_characteristic_removed_count_;
252 last_gatt_characteristic_id_ = characteristic->GetIdentifier(); 250 last_gatt_characteristic_id_ = characteristic->GetIdentifier();
253 last_gatt_characteristic_uuid_ = characteristic->GetUUID(); 251 last_gatt_characteristic_uuid_ = characteristic->GetUUID();
254 252
255 // The service should return NULL for this characteristic. 253 // The service should return NULL for this characteristic.
256 ASSERT_TRUE(characteristic->GetService()); 254 ASSERT_TRUE(characteristic->GetService());
257 EXPECT_FALSE(characteristic->GetService()->GetCharacteristic( 255 EXPECT_FALSE(characteristic->GetService()->GetCharacteristic(
258 last_gatt_characteristic_id_)); 256 last_gatt_characteristic_id_));
259 257
260 QuitMessageLoop(); 258 QuitMessageLoop();
261 } 259 }
262 260
263 void TestBluetoothAdapterObserver::GattDescriptorAdded( 261 void TestBluetoothAdapterObserver::GattDescriptorAdded(
264 BluetoothAdapter* adapter, 262 BluetoothAdapter* adapter,
265 BluetoothGattDescriptor* descriptor) { 263 BluetoothRemoteGattDescriptor* descriptor) {
266 ASSERT_EQ(adapter_.get(), adapter); 264 ASSERT_EQ(adapter_.get(), adapter);
267 265
268 ++gatt_descriptor_added_count_; 266 ++gatt_descriptor_added_count_;
269 last_gatt_descriptor_id_ = descriptor->GetIdentifier(); 267 last_gatt_descriptor_id_ = descriptor->GetIdentifier();
270 last_gatt_descriptor_uuid_ = descriptor->GetUUID(); 268 last_gatt_descriptor_uuid_ = descriptor->GetUUID();
271 269
272 ASSERT_TRUE(descriptor->GetCharacteristic()); 270 ASSERT_TRUE(descriptor->GetCharacteristic());
273 EXPECT_EQ( 271 EXPECT_EQ(
274 descriptor->GetCharacteristic()->GetDescriptor(last_gatt_descriptor_id_), 272 descriptor->GetCharacteristic()->GetDescriptor(last_gatt_descriptor_id_),
275 descriptor); 273 descriptor);
276 274
277 QuitMessageLoop(); 275 QuitMessageLoop();
278 } 276 }
279 277
280 void TestBluetoothAdapterObserver::GattDescriptorRemoved( 278 void TestBluetoothAdapterObserver::GattDescriptorRemoved(
281 BluetoothAdapter* adapter, 279 BluetoothAdapter* adapter,
282 BluetoothGattDescriptor* descriptor) { 280 BluetoothRemoteGattDescriptor* descriptor) {
283 ASSERT_EQ(adapter_.get(), adapter); 281 ASSERT_EQ(adapter_.get(), adapter);
284 282
285 ++gatt_descriptor_removed_count_; 283 ++gatt_descriptor_removed_count_;
286 last_gatt_descriptor_id_ = descriptor->GetIdentifier(); 284 last_gatt_descriptor_id_ = descriptor->GetIdentifier();
287 last_gatt_descriptor_uuid_ = descriptor->GetUUID(); 285 last_gatt_descriptor_uuid_ = descriptor->GetUUID();
288 286
289 // The characteristic should return NULL for this descriptor.. 287 // The characteristic should return NULL for this descriptor..
290 ASSERT_TRUE(descriptor->GetCharacteristic()); 288 ASSERT_TRUE(descriptor->GetCharacteristic());
291 EXPECT_FALSE( 289 EXPECT_FALSE(
292 descriptor->GetCharacteristic()->GetDescriptor(last_gatt_descriptor_id_)); 290 descriptor->GetCharacteristic()->GetDescriptor(last_gatt_descriptor_id_));
293 291
294 QuitMessageLoop(); 292 QuitMessageLoop();
295 } 293 }
296 294
297 void TestBluetoothAdapterObserver::GattCharacteristicValueChanged( 295 void TestBluetoothAdapterObserver::GattCharacteristicValueChanged(
298 BluetoothAdapter* adapter, 296 BluetoothAdapter* adapter,
299 BluetoothGattCharacteristic* characteristic, 297 BluetoothRemoteGattCharacteristic* characteristic,
300 const std::vector<uint8_t>& value) { 298 const std::vector<uint8_t>& value) {
301 ASSERT_EQ(adapter_.get(), adapter); 299 ASSERT_EQ(adapter_.get(), adapter);
302 300
303 ++gatt_characteristic_value_changed_count_; 301 ++gatt_characteristic_value_changed_count_;
304 last_gatt_characteristic_id_ = characteristic->GetIdentifier(); 302 last_gatt_characteristic_id_ = characteristic->GetIdentifier();
305 last_gatt_characteristic_uuid_ = characteristic->GetUUID(); 303 last_gatt_characteristic_uuid_ = characteristic->GetUUID();
306 last_changed_characteristic_value_ = value; 304 last_changed_characteristic_value_ = value;
307 305
308 ASSERT_TRUE(characteristic->GetService()); 306 ASSERT_TRUE(characteristic->GetService());
309 EXPECT_EQ(characteristic->GetService()->GetCharacteristic( 307 EXPECT_EQ(characteristic->GetService()->GetCharacteristic(
310 last_gatt_characteristic_id_), 308 last_gatt_characteristic_id_),
311 characteristic); 309 characteristic);
312 310
313 QuitMessageLoop(); 311 QuitMessageLoop();
314 } 312 }
315 313
316 void TestBluetoothAdapterObserver::GattDescriptorValueChanged( 314 void TestBluetoothAdapterObserver::GattDescriptorValueChanged(
317 BluetoothAdapter* adapter, 315 BluetoothAdapter* adapter,
318 BluetoothGattDescriptor* descriptor, 316 BluetoothRemoteGattDescriptor* descriptor,
319 const std::vector<uint8_t>& value) { 317 const std::vector<uint8_t>& value) {
320 ASSERT_EQ(adapter_.get(), adapter); 318 ASSERT_EQ(adapter_.get(), adapter);
321 319
322 ++gatt_descriptor_value_changed_count_; 320 ++gatt_descriptor_value_changed_count_;
323 last_gatt_descriptor_id_ = descriptor->GetIdentifier(); 321 last_gatt_descriptor_id_ = descriptor->GetIdentifier();
324 last_gatt_descriptor_uuid_ = descriptor->GetUUID(); 322 last_gatt_descriptor_uuid_ = descriptor->GetUUID();
325 last_changed_descriptor_value_ = value; 323 last_changed_descriptor_value_ = value;
326 324
327 ASSERT_TRUE(descriptor->GetCharacteristic()); 325 ASSERT_TRUE(descriptor->GetCharacteristic());
328 EXPECT_EQ( 326 EXPECT_EQ(
329 descriptor->GetCharacteristic()->GetDescriptor(last_gatt_descriptor_id_), 327 descriptor->GetCharacteristic()->GetDescriptor(last_gatt_descriptor_id_),
330 descriptor); 328 descriptor);
331 329
332 QuitMessageLoop(); 330 QuitMessageLoop();
333 } 331 }
334 332
335 void TestBluetoothAdapterObserver::QuitMessageLoop() { 333 void TestBluetoothAdapterObserver::QuitMessageLoop() {
336 if (base::MessageLoop::current() && 334 if (base::MessageLoop::current() &&
337 base::MessageLoop::current()->is_running()) 335 base::MessageLoop::current()->is_running())
338 base::MessageLoop::current()->QuitWhenIdle(); 336 base::MessageLoop::current()->QuitWhenIdle();
339 } 337 }
340 338
341 } // namespace device 339 } // namespace device
OLDNEW
« no previous file with comments | « device/bluetooth/test/test_bluetooth_adapter_observer.h ('k') | device/device_tests.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698