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

Side by Side Diff: device/bluetooth/bluetooth_adapter_mac_unittest.mm

Issue 2906883004: bluetooth: macOS: Removing useless |.get()| (Closed)
Patch Set: Created 3 years, 6 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/bluetooth_adapter_mac.h" 5 #include "device/bluetooth/bluetooth_adapter_mac.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 return adapter_->GetDevice(address); 62 return adapter_->GetDevice(address);
63 } 63 }
64 64
65 CBPeripheral* CreateMockPeripheral(const char* identifier) { 65 CBPeripheral* CreateMockPeripheral(const char* identifier) {
66 if (!BluetoothAdapterMac::IsLowEnergyAvailable()) { 66 if (!BluetoothAdapterMac::IsLowEnergyAvailable()) {
67 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 67 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
68 return nil; 68 return nil;
69 } 69 }
70 base::scoped_nsobject<MockCBPeripheral> mock_peripheral( 70 base::scoped_nsobject<MockCBPeripheral> mock_peripheral(
71 [[MockCBPeripheral alloc] initWithUTF8StringIdentifier:identifier]); 71 [[MockCBPeripheral alloc] initWithUTF8StringIdentifier:identifier]);
72 return [mock_peripheral.get().peripheral retain]; 72 return [[mock_peripheral peripheral] retain];
73 } 73 }
74 74
75 NSDictionary* AdvertisementData() { 75 NSDictionary* AdvertisementData() {
76 NSDictionary* advertisement_data = @{ 76 NSDictionary* advertisement_data = @{
77 CBAdvertisementDataIsConnectable : @(YES), 77 CBAdvertisementDataIsConnectable : @(YES),
78 CBAdvertisementDataServiceDataKey : [NSDictionary dictionary], 78 CBAdvertisementDataServiceDataKey : [NSDictionary dictionary],
79 }; 79 };
80 return [advertisement_data retain]; 80 return [advertisement_data retain];
81 } 81 }
82 82
(...skipping 10 matching lines...) Expand all
93 } 93 }
94 94
95 bool SetMockCentralManager(CBCentralManagerState desired_state) { 95 bool SetMockCentralManager(CBCentralManagerState desired_state) {
96 if (!BluetoothAdapterMac::IsLowEnergyAvailable()) { 96 if (!BluetoothAdapterMac::IsLowEnergyAvailable()) {
97 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 97 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
98 return false; 98 return false;
99 } 99 }
100 mock_central_manager_.reset([[MockCentralManager alloc] init]); 100 mock_central_manager_.reset([[MockCentralManager alloc] init]);
101 [mock_central_manager_ setState:desired_state]; 101 [mock_central_manager_ setState:desired_state];
102 CBCentralManager* centralManager = 102 CBCentralManager* centralManager =
103 (CBCentralManager*)mock_central_manager_.get(); 103 (CBCentralManager*)(mock_central_manager_.get());
ortuno 2017/05/26 16:33:02 Do we have an issue to get rid of c-style casting?
jlebel 2017/05/26 16:51:14 No, but I'm working on that one right now. I didn'
104 adapter_mac_->SetCentralManagerForTesting(centralManager); 104 adapter_mac_->SetCentralManagerForTesting(centralManager);
105 return true; 105 return true;
106 } 106 }
107 107
108 void AddDiscoverySession(BluetoothDiscoveryFilter* discovery_filter) { 108 void AddDiscoverySession(BluetoothDiscoveryFilter* discovery_filter) {
109 adapter_mac_->AddDiscoverySession( 109 adapter_mac_->AddDiscoverySession(
110 discovery_filter, 110 discovery_filter,
111 base::Bind(&BluetoothAdapterMacTest::Callback, base::Unretained(this)), 111 base::Bind(&BluetoothAdapterMacTest::Callback, base::Unretained(this)),
112 base::Bind(&BluetoothAdapterMacTest::DiscoveryErrorCallback, 112 base::Bind(&BluetoothAdapterMacTest::DiscoveryErrorCallback,
113 base::Unretained(this))); 113 base::Unretained(this)));
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 227
228 // Check that stopScan was not called. 228 // Check that stopScan was not called.
229 EXPECT_EQ(0, [mock_central_manager_ stopScanCallCount]); 229 EXPECT_EQ(0, [mock_central_manager_ stopScanCallCount]);
230 } 230 }
231 231
232 TEST_F(BluetoothAdapterMacTest, CheckGetPeripheralHashAddress) { 232 TEST_F(BluetoothAdapterMacTest, CheckGetPeripheralHashAddress) {
233 if (!SetMockCentralManager(CBCentralManagerStatePoweredOn)) 233 if (!SetMockCentralManager(CBCentralManagerStatePoweredOn))
234 return; 234 return;
235 base::scoped_nsobject<CBPeripheral> mock_peripheral( 235 base::scoped_nsobject<CBPeripheral> mock_peripheral(
236 CreateMockPeripheral(kTestNSUUID)); 236 CreateMockPeripheral(kTestNSUUID));
237 if (mock_peripheral.get() == nil) 237 if (!mock_peripheral)
238 return; 238 return;
239 EXPECT_EQ(kTestHashAddress, GetHashAddress(mock_peripheral)); 239 EXPECT_EQ(kTestHashAddress, GetHashAddress(mock_peripheral));
240 } 240 }
241 241
242 TEST_F(BluetoothAdapterMacTest, LowEnergyDeviceUpdatedNewDevice) { 242 TEST_F(BluetoothAdapterMacTest, LowEnergyDeviceUpdatedNewDevice) {
243 if (!SetMockCentralManager(CBCentralManagerStatePoweredOn)) 243 if (!SetMockCentralManager(CBCentralManagerStatePoweredOn))
244 return; 244 return;
245 base::scoped_nsobject<CBPeripheral> mock_peripheral( 245 base::scoped_nsobject<CBPeripheral> mock_peripheral(
246 CreateMockPeripheral(kTestNSUUID)); 246 CreateMockPeripheral(kTestNSUUID));
247 if (mock_peripheral.get() == nil) 247 if (!mock_peripheral)
248 return; 248 return;
249 base::scoped_nsobject<NSDictionary> advertisement_data(AdvertisementData()); 249 base::scoped_nsobject<NSDictionary> advertisement_data(AdvertisementData());
250 250
251 EXPECT_EQ(0, NumDevices()); 251 EXPECT_EQ(0, NumDevices());
252 EXPECT_FALSE(DevicePresent(mock_peripheral)); 252 EXPECT_FALSE(DevicePresent(mock_peripheral));
253 LowEnergyDeviceUpdated(mock_peripheral, advertisement_data, kTestRssi); 253 LowEnergyDeviceUpdated(mock_peripheral, advertisement_data, kTestRssi);
254 EXPECT_EQ(1, NumDevices()); 254 EXPECT_EQ(1, NumDevices());
255 EXPECT_TRUE(DevicePresent(mock_peripheral)); 255 EXPECT_TRUE(DevicePresent(mock_peripheral));
256 } 256 }
257 257
258 } // namespace device 258 } // namespace device
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_adapter_mac.mm ('k') | device/bluetooth/bluetooth_low_energy_device_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698