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.h" | 5 #include "device/bluetooth/test/bluetooth_test.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "device/bluetooth/bluetooth_adapter.h" | 10 #include "device/bluetooth/bluetooth_adapter.h" |
11 | 11 |
12 namespace device { | 12 namespace device { |
13 | 13 |
14 const std::string BluetoothTestBase::kTestAdapterName = "FakeBluetoothAdapter"; | 14 const std::string BluetoothTestBase::kTestAdapterName = "FakeBluetoothAdapter"; |
15 const std::string BluetoothTestBase::kTestAdapterAddress = "A1:B2:C3:D4:E5:F6"; | 15 const std::string BluetoothTestBase::kTestAdapterAddress = "A1:B2:C3:D4:E5:F6"; |
16 | 16 |
17 const std::string BluetoothTestBase::kTestDeviceName = "FakeBluetoothDevice"; | 17 const std::string BluetoothTestBase::kTestDeviceName = "FakeBluetoothDevice"; |
18 const std::string BluetoothTestBase::kTestDeviceNameEmpty = ""; | 18 const std::string BluetoothTestBase::kTestDeviceNameEmpty = ""; |
19 | 19 |
20 const std::string BluetoothTestBase::kTestDeviceAddress1 = "01:00:00:90:1E:BE"; | 20 const std::string BluetoothTestBase::kTestDeviceAddress1 = "01:00:00:90:1E:BE"; |
21 const std::string BluetoothTestBase::kTestDeviceAddress2 = "02:00:00:8B:74:63"; | 21 const std::string BluetoothTestBase::kTestDeviceAddress2 = "02:00:00:8B:74:63"; |
22 | 22 |
23 const std::string BluetoothTestBase::kTestUUIDGenericAccess = "1800"; | 23 const std::string BluetoothTestBase::kTestUUIDGenericAccess = "1800"; |
24 const std::string BluetoothTestBase::kTestUUIDGenericAttribute = "1801"; | 24 const std::string BluetoothTestBase::kTestUUIDGenericAttribute = "1801"; |
25 const std::string BluetoothTestBase::kTestUUIDImmediateAlert = "1802"; | 25 const std::string BluetoothTestBase::kTestUUIDImmediateAlert = "1802"; |
26 const std::string BluetoothTestBase::kTestUUIDLinkLoss = "1803"; | 26 const std::string BluetoothTestBase::kTestUUIDLinkLoss = "1803"; |
27 | 27 |
28 BluetoothTestBase::BluetoothTestBase() { | 28 BluetoothTestBase::BluetoothTestBase() : weak_factory_(this) {} |
| 29 |
| 30 BluetoothTestBase::~BluetoothTestBase() { |
29 } | 31 } |
30 | 32 |
31 BluetoothTestBase::~BluetoothTestBase() { | 33 void BluetoothTestBase::DeleteDevice(BluetoothDevice* device) { |
| 34 adapter_->DeleteDeviceForTesting(device->GetAddress()); |
32 } | 35 } |
33 | 36 |
34 void BluetoothTestBase::Callback() { | 37 void BluetoothTestBase::Callback() { |
35 ++callback_count_; | 38 ++callback_count_; |
36 } | 39 } |
37 | 40 |
38 void BluetoothTestBase::DiscoverySessionCallback( | 41 void BluetoothTestBase::DiscoverySessionCallback( |
39 scoped_ptr<BluetoothDiscoverySession> discovery_session) { | 42 scoped_ptr<BluetoothDiscoverySession> discovery_session) { |
40 ++callback_count_; | 43 ++callback_count_; |
41 discovery_sessions_.push_back(discovery_session.release()); | 44 discovery_sessions_.push_back(discovery_session.release()); |
42 } | 45 } |
43 | 46 |
| 47 void BluetoothTestBase::GattConnectionCallback( |
| 48 scoped_ptr<BluetoothGattConnection> connection) { |
| 49 ++callback_count_; |
| 50 gatt_connections_.push_back(connection.release()); |
| 51 } |
| 52 |
44 void BluetoothTestBase::ErrorCallback() { | 53 void BluetoothTestBase::ErrorCallback() { |
45 ++error_callback_count_; | 54 ++error_callback_count_; |
46 } | 55 } |
47 | 56 |
| 57 void BluetoothTestBase::ConnectErrorCallback( |
| 58 enum BluetoothDevice::ConnectErrorCode error_code) { |
| 59 ++error_callback_count_; |
| 60 last_connect_error_code_ = error_code; |
| 61 } |
| 62 |
48 base::Closure BluetoothTestBase::GetCallback() { | 63 base::Closure BluetoothTestBase::GetCallback() { |
49 return base::Bind(&BluetoothTestBase::Callback, base::Unretained(this)); | 64 return base::Bind(&BluetoothTestBase::Callback, weak_factory_.GetWeakPtr()); |
50 } | 65 } |
51 | 66 |
52 BluetoothAdapter::DiscoverySessionCallback | 67 BluetoothAdapter::DiscoverySessionCallback |
53 BluetoothTestBase::GetDiscoverySessionCallback() { | 68 BluetoothTestBase::GetDiscoverySessionCallback() { |
54 return base::Bind(&BluetoothTestBase::DiscoverySessionCallback, | 69 return base::Bind(&BluetoothTestBase::DiscoverySessionCallback, |
55 base::Unretained(this)); | 70 weak_factory_.GetWeakPtr()); |
| 71 } |
| 72 |
| 73 BluetoothDevice::GattConnectionCallback |
| 74 BluetoothTestBase::GetGattConnectionCallback() { |
| 75 return base::Bind(&BluetoothTestBase::GattConnectionCallback, |
| 76 weak_factory_.GetWeakPtr()); |
56 } | 77 } |
57 | 78 |
58 BluetoothAdapter::ErrorCallback BluetoothTestBase::GetErrorCallback() { | 79 BluetoothAdapter::ErrorCallback BluetoothTestBase::GetErrorCallback() { |
59 return base::Bind(&BluetoothTestBase::ErrorCallback, base::Unretained(this)); | 80 return base::Bind(&BluetoothTestBase::ErrorCallback, |
| 81 weak_factory_.GetWeakPtr()); |
| 82 } |
| 83 |
| 84 BluetoothDevice::ConnectErrorCallback |
| 85 BluetoothTestBase::GetConnectErrorCallback() { |
| 86 return base::Bind(&BluetoothTestBase::ConnectErrorCallback, |
| 87 weak_factory_.GetWeakPtr()); |
60 } | 88 } |
61 | 89 |
62 } // namespace device | 90 } // namespace device |
OLD | NEW |