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

Side by Side Diff: device/bluetooth/test/bluetooth_test_mac.mm

Issue 2339253002: bluetooth: mac: add connected LE devices to chooser (Closed)
Patch Set: Implementing RetrieveGattConnectedDevicesWithDiscoveryFilter() with tests Created 4 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 #include "device/bluetooth/test/bluetooth_test_mac.h" 5 #include "device/bluetooth/test/bluetooth_test_mac.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/mac/foundation_util.h" 9 #include "base/mac/foundation_util.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/sys_string_conversions.h"
11 #include "build/build_config.h" 12 #include "build/build_config.h"
12 #include "device/bluetooth/bluetooth_adapter_mac.h" 13 #include "device/bluetooth/bluetooth_adapter_mac.h"
13 #include "device/bluetooth/bluetooth_device_mac.h" 14 #include "device/bluetooth/bluetooth_device_mac.h"
14 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_mac.h" 15 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_mac.h"
15 #include "device/bluetooth/bluetooth_remote_gatt_service_mac.h" 16 #include "device/bluetooth/bluetooth_remote_gatt_service_mac.h"
16 #include "device/bluetooth/test/mock_bluetooth_cbcharacteristic_mac.h" 17 #include "device/bluetooth/test/mock_bluetooth_cbcharacteristic_mac.h"
17 #include "device/bluetooth/test/mock_bluetooth_cbperipheral_mac.h" 18 #include "device/bluetooth/test/mock_bluetooth_cbperipheral_mac.h"
18 #include "device/bluetooth/test/mock_bluetooth_cbservice_mac.h" 19 #include "device/bluetooth/test/mock_bluetooth_cbservice_mac.h"
19 #include "device/bluetooth/test/mock_bluetooth_central_manager_mac.h" 20 #include "device/bluetooth/test/mock_bluetooth_central_manager_mac.h"
20 #include "device/bluetooth/test/test_bluetooth_adapter_observer.h" 21 #include "device/bluetooth/test/test_bluetooth_adapter_observer.h"
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 138
138 if (BluetoothAdapterMac::IsLowEnergyAvailable()) { 139 if (BluetoothAdapterMac::IsLowEnergyAvailable()) {
139 mock_central_manager_.reset( 140 mock_central_manager_.reset(
140 new ScopedMockCentralManager([[MockCentralManager alloc] init])); 141 new ScopedMockCentralManager([[MockCentralManager alloc] init]));
141 mock_central_manager_->get().bluetoothTestMac = this; 142 mock_central_manager_->get().bluetoothTestMac = this;
142 [mock_central_manager_->get() setState:CBCentralManagerStatePoweredOn]; 143 [mock_central_manager_->get() setState:CBCentralManagerStatePoweredOn];
143 adapter_mac_->SetCentralManagerForTesting((id)mock_central_manager_->get()); 144 adapter_mac_->SetCentralManagerForTesting((id)mock_central_manager_->get());
144 } 145 }
145 } 146 }
146 147
148 void BluetoothTestMac::SimulateConnectedLowEnergyDevice(
149 int device_ordinal,
150 const BluetoothDevice::UUIDSet& service_uuids) {
151 const char* identifier = NULL;
152 NSString* name;
153 switch (device_ordinal) {
154 case 1:
155 identifier = kTestPeripheralUUID1.c_str();
156 break;
157 case 2:
158 identifier = kTestPeripheralUUID2.c_str();
159 break;
160 default:
161 NOTREACHED() << "SimulateLowEnergyDevice not implemented for "
162 << device_ordinal;
163 }
164 name = @(kTestDeviceName.c_str());
165 scoped_nsobject<MockCBPeripheral> mock_peripheral([[MockCBPeripheral alloc]
166 initWithUTF8StringIdentifier:identifier
167 name:name]);
168 mock_peripheral.get().bluetoothTestMac = this;
169 scoped_nsobject<NSMutableSet> cbUUIDs([[NSMutableSet alloc] init]);
170 for (auto iterator = service_uuids.begin(); iterator != service_uuids.end();
171 ++iterator) {
172 NSString* uuidString =
173 base::SysUTF8ToNSString(iterator->canonical_value().c_str());
174 [cbUUIDs.get() addObject:[CBUUID UUIDWithString:uuidString]];
175 }
176 [mock_central_manager_->get()
177 setConnectedMockPeripheral:mock_peripheral.get().peripheral
178 withServiceUUIDs:cbUUIDs.get()];
179 }
180
147 BluetoothDevice* BluetoothTestMac::SimulateLowEnergyDevice(int device_ordinal) { 181 BluetoothDevice* BluetoothTestMac::SimulateLowEnergyDevice(int device_ordinal) {
148 TestBluetoothAdapterObserver observer(adapter_); 182 TestBluetoothAdapterObserver observer(adapter_);
149 CBCentralManager* central_manager = adapter_mac_->low_energy_central_manager_; 183 CBCentralManager* central_manager = adapter_mac_->low_energy_central_manager_;
150 BluetoothLowEnergyCentralManagerDelegate* central_manager_delegate = 184 BluetoothLowEnergyCentralManagerDelegate* central_manager_delegate =
151 adapter_mac_->low_energy_central_manager_delegate_; 185 adapter_mac_->low_energy_central_manager_delegate_;
152 186
153 const char* identifier; 187 const char* identifier;
154 NSString* name; 188 NSString* name;
155 NSArray* uuids; 189 NSArray* uuids;
156 NSNumber* rssi; 190 NSNumber* rssi;
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 // crypto::SHA256HashString(input_str, raw, sizeof(raw)); 522 // crypto::SHA256HashString(input_str, raw, sizeof(raw));
489 // if (base::HexEncode(raw, sizeof(raw)) == target) { 523 // if (base::HexEncode(raw, sizeof(raw)) == target) {
490 // return input_str; 524 // return input_str;
491 // } 525 // }
492 // ++input[0]; 526 // ++input[0];
493 // } 527 // }
494 // return ""; 528 // return "";
495 // } 529 // }
496 530
497 } // namespace device 531 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698