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_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" |
(...skipping 23 matching lines...) Expand all Loading... | |
34 MockCentralManager* get() { return mock_central_manager_.get(); }; | 34 MockCentralManager* get() { return mock_central_manager_.get(); }; |
35 | 35 |
36 private: | 36 private: |
37 scoped_nsobject<MockCentralManager> mock_central_manager_; | 37 scoped_nsobject<MockCentralManager> mock_central_manager_; |
38 | 38 |
39 DISALLOW_COPY_AND_ASSIGN(ScopedMockCentralManager); | 39 DISALLOW_COPY_AND_ASSIGN(ScopedMockCentralManager); |
40 }; | 40 }; |
41 | 41 |
42 namespace { | 42 namespace { |
43 | 43 |
44 NSDictionary* CreateAdvertisementData(NSString* name, NSArray* uuids) { | 44 scoped_nsobject<NSDictionary> CreateAdvertisementData(NSString* name, |
45 NSArray* uuids) { | |
45 NSMutableDictionary* advertisement_data = | 46 NSMutableDictionary* advertisement_data = |
46 [NSMutableDictionary dictionaryWithDictionary:@{ | 47 [NSMutableDictionary dictionaryWithDictionary:@{ |
47 CBAdvertisementDataLocalNameKey : name, | 48 CBAdvertisementDataLocalNameKey : name, |
48 CBAdvertisementDataServiceDataKey : @{}, | 49 CBAdvertisementDataServiceDataKey : @{}, |
49 CBAdvertisementDataIsConnectable : @(YES), | 50 CBAdvertisementDataIsConnectable : @(YES), |
50 }]; | 51 }]; |
51 if (uuids) { | 52 if (uuids) { |
52 [advertisement_data setObject:uuids | 53 [advertisement_data setObject:uuids |
53 forKey:CBAdvertisementDataServiceUUIDsKey]; | 54 forKey:CBAdvertisementDataServiceUUIDsKey]; |
54 } | 55 } |
55 return [advertisement_data retain]; | 56 return scoped_nsobject<NSDictionary>([advertisement_data retain]); |
Reilly Grant (use Gerrit)
2016/06/01 01:05:15
I believe this retain was and still is unnecessary
ccameron
2016/06/01 01:59:31
Yeah, I suspected. Removed.
Eugene But (OOO till 7-30)
2016/06/01 05:12:06
Wait... this retain is still necessary (and actual
Reilly Grant (use Gerrit)
2016/06/01 15:34:42
I only pretend to understand Objective-C memory ma
Eugene But (OOO till 7-30)
2016/06/01 15:58:35
In Objective-C the method prefix tell if you are r
jlebel
2016/06/02 23:07:34
And "create" when we are using functions. That's t
ccameron
2016/06/02 23:11:18
I've added a base::scoped_policy::RETAIN here.
| |
56 } | 57 } |
57 | 58 |
58 } // namespace | 59 } // namespace |
59 | 60 |
60 // UUID1 hashes to kTestDeviceAddress1, and UUID2 to kTestDeviceAddress2. | 61 // UUID1 hashes to kTestDeviceAddress1, and UUID2 to kTestDeviceAddress2. |
61 const std::string BluetoothTestMac::kTestPeripheralUUID1 = | 62 const std::string BluetoothTestMac::kTestPeripheralUUID1 = |
62 "34045B00-0000-0000-0000-000000000000"; | 63 "34045B00-0000-0000-0000-000000000000"; |
63 const std::string BluetoothTestMac::kTestPeripheralUUID2 = | 64 const std::string BluetoothTestMac::kTestPeripheralUUID2 = |
64 "EC1B8F00-0000-0000-0000-000000000000"; | 65 "EC1B8F00-0000-0000-0000-000000000000"; |
65 | 66 |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
222 error:nil]; | 223 error:nil]; |
223 } | 224 } |
224 | 225 |
225 void BluetoothTestMac::SimulateGattServicesDiscovered( | 226 void BluetoothTestMac::SimulateGattServicesDiscovered( |
226 BluetoothDevice* device, | 227 BluetoothDevice* device, |
227 const std::vector<std::string>& uuids) { | 228 const std::vector<std::string>& uuids) { |
228 BluetoothLowEnergyDeviceMac* device_mac = | 229 BluetoothLowEnergyDeviceMac* device_mac = |
229 static_cast<BluetoothLowEnergyDeviceMac*>(device); | 230 static_cast<BluetoothLowEnergyDeviceMac*>(device); |
230 CBPeripheral* peripheral = device_mac->GetPeripheral(); | 231 CBPeripheral* peripheral = device_mac->GetPeripheral(); |
231 MockCBPeripheral* peripheral_mock = ObjCCast<MockCBPeripheral>(peripheral); | 232 MockCBPeripheral* peripheral_mock = ObjCCast<MockCBPeripheral>(peripheral); |
232 scoped_nsobject<NSMutableArray> services = [[NSMutableArray alloc] init]; | 233 scoped_nsobject<NSMutableArray> services([[NSMutableArray alloc] init]); |
233 for (auto uuid : uuids) { | 234 for (auto uuid : uuids) { |
234 CBUUID* cb_service_uuid = [CBUUID UUIDWithString:@(uuid.c_str())]; | 235 CBUUID* cb_service_uuid = [CBUUID UUIDWithString:@(uuid.c_str())]; |
235 [services addObject:cb_service_uuid]; | 236 [services addObject:cb_service_uuid]; |
236 } | 237 } |
237 [peripheral_mock removeAllServices]; | 238 [peripheral_mock removeAllServices]; |
238 [peripheral_mock addServices:services]; | 239 [peripheral_mock addServices:services]; |
239 [peripheral_mock didDiscoverWithError:nil]; | 240 [peripheral_mock didDiscoverWithError:nil]; |
240 } | 241 } |
241 | 242 |
242 void BluetoothTestMac::SimulateGattServiceRemoved( | 243 void BluetoothTestMac::SimulateGattServiceRemoved( |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
295 // crypto::SHA256HashString(input_str, raw, sizeof(raw)); | 296 // crypto::SHA256HashString(input_str, raw, sizeof(raw)); |
296 // if (base::HexEncode(raw, sizeof(raw)) == target) { | 297 // if (base::HexEncode(raw, sizeof(raw)) == target) { |
297 // return input_str; | 298 // return input_str; |
298 // } | 299 // } |
299 // ++input[0]; | 300 // ++input[0]; |
300 // } | 301 // } |
301 // return ""; | 302 // return ""; |
302 // } | 303 // } |
303 | 304 |
304 } // namespace device | 305 } // namespace device |
OLD | NEW |