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/mock_bluetooth_cbperipheral_mac.h" | 5 #include "device/bluetooth/test/mock_bluetooth_cbperipheral_mac.h" |
6 | 6 |
7 #include "base/mac/foundation_util.h" | 7 #include "base/mac/foundation_util.h" |
8 #include "base/mac/scoped_nsobject.h" | 8 #include "base/mac/scoped_nsobject.h" |
9 #include "device/bluetooth/test/bluetooth_test_mac.h" | 9 #include "device/bluetooth/test/bluetooth_test_mac.h" |
10 #include "device/bluetooth/test/mock_bluetooth_cbcharacteristic_mac.h" | 10 #include "device/bluetooth/test/mock_bluetooth_cbcharacteristic_mac.h" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 } | 87 } |
88 | 88 |
89 - (void)discoverCharacteristics:(NSArray*)characteristics | 89 - (void)discoverCharacteristics:(NSArray*)characteristics |
90 forService:(CBService*)service { | 90 forService:(CBService*)service { |
91 if (_bluetoothTestMac) { | 91 if (_bluetoothTestMac) { |
92 _bluetoothTestMac->OnFakeBluetoothCharacteristicDiscovery(); | 92 _bluetoothTestMac->OnFakeBluetoothCharacteristicDiscovery(); |
93 } | 93 } |
94 } | 94 } |
95 | 95 |
96 - (void)discoverDescriptorsForCharacteristic:(CBCharacteristic*)characteristic { | 96 - (void)discoverDescriptorsForCharacteristic:(CBCharacteristic*)characteristic { |
97 MockCBCharacteristic* mock_characteristic = | |
98 ObjCCast<MockCBCharacteristic>(characteristic); | |
99 [mock_characteristic discoverDescriptors]; | |
100 } | 97 } |
101 | 98 |
102 - (void)readValueForCharacteristic:(CBCharacteristic*)characteristic { | 99 - (void)readValueForCharacteristic:(CBCharacteristic*)characteristic { |
103 DCHECK(_bluetoothTestMac); | 100 DCHECK(_bluetoothTestMac); |
104 _bluetoothTestMac->OnFakeBluetoothCharacteristicReadValue(); | 101 _bluetoothTestMac->OnFakeBluetoothCharacteristicReadValue(); |
105 } | 102 } |
106 | 103 |
107 - (void)writeValue:(NSData*)data | 104 - (void)writeValue:(NSData*)data |
108 forCharacteristic:(CBCharacteristic*)characteristic | 105 forCharacteristic:(CBCharacteristic*)characteristic |
109 type:(CBCharacteristicWriteType)type { | 106 type:(CBCharacteristicWriteType)type { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 base::scoped_policy::RETAIN); | 148 base::scoped_policy::RETAIN); |
152 DCHECK(serviceToRemove); | 149 DCHECK(serviceToRemove); |
153 [_services.get() removeObject:serviceToRemove]; | 150 [_services.get() removeObject:serviceToRemove]; |
154 [self didModifyServices:@[ serviceToRemove ]]; | 151 [self didModifyServices:@[ serviceToRemove ]]; |
155 } | 152 } |
156 | 153 |
157 - (void)mockDidDiscoverServices { | 154 - (void)mockDidDiscoverServices { |
158 [_delegate peripheral:self.peripheral didDiscoverServices:nil]; | 155 [_delegate peripheral:self.peripheral didDiscoverServices:nil]; |
159 } | 156 } |
160 | 157 |
| 158 - (void)mockDidDiscoverCharacteristicsForService:(CBService*)service { |
| 159 [_delegate peripheral:self.peripheral |
| 160 didDiscoverCharacteristicsForService:service |
| 161 error:nil]; |
| 162 } |
| 163 |
| 164 - (void)mockDidDiscoverDescriptorsForCharacteristic: |
| 165 (CBCharacteristic*)characteristic { |
| 166 [_delegate peripheral:self.peripheral |
| 167 didDiscoverDescriptorsForCharacteristic:characteristic |
| 168 error:nil]; |
| 169 } |
| 170 |
161 - (void)mockDidDiscoverEvents { | 171 - (void)mockDidDiscoverEvents { |
162 [self mockDidDiscoverServices]; | 172 [self mockDidDiscoverServices]; |
163 // BluetoothLowEnergyDeviceMac is expected to call | 173 // BluetoothLowEnergyDeviceMac is expected to call |
164 // -[CBPeripheral discoverCharacteristics:forService:] for each services, | 174 // -[CBPeripheral discoverCharacteristics:forService:] for each services, |
165 // so -[<CBPeripheralDelegate peripheral:didDiscoverCharacteristicsForService: | 175 // so -[<CBPeripheralDelegate peripheral:didDiscoverCharacteristicsForService: |
166 // error:] needs to be called for all services. | 176 // error:] needs to be called for all services. |
167 for (CBService* service in _services.get()) { | 177 for (CBService* service in _services.get()) { |
168 [_delegate peripheral:self.peripheral | 178 [self mockDidDiscoverCharacteristicsForService:service]; |
169 didDiscoverCharacteristicsForService:service | |
170 error:nil]; | |
171 for (CBCharacteristic* characteristic in service.characteristics) { | 179 for (CBCharacteristic* characteristic in service.characteristics) { |
172 // After discovering services, BluetoothLowEnergyDeviceMac is expected to | 180 // After discovering services, BluetoothLowEnergyDeviceMac is expected to |
173 // discover characteristics for all services. | 181 // discover characteristics for all services. |
174 [_delegate peripheral:self.peripheral | 182 [_delegate peripheral:self.peripheral |
175 didDiscoverDescriptorsForCharacteristic:characteristic | 183 didDiscoverDescriptorsForCharacteristic:characteristic |
176 error:nil]; | 184 error:nil]; |
177 } | 185 } |
178 } | 186 } |
179 } | 187 } |
180 | 188 |
(...skipping 26 matching lines...) Expand all Loading... |
207 return ObjCCast<CBPeripheral>(self); | 215 return ObjCCast<CBPeripheral>(self); |
208 } | 216 } |
209 | 217 |
210 - (void)setNotifyValue:(BOOL)notification | 218 - (void)setNotifyValue:(BOOL)notification |
211 forCharacteristic:(CBCharacteristic*)characteristic { | 219 forCharacteristic:(CBCharacteristic*)characteristic { |
212 _bluetoothTestMac->OnFakeBluetoothGattSetCharacteristicNotification( | 220 _bluetoothTestMac->OnFakeBluetoothGattSetCharacteristicNotification( |
213 notification == YES); | 221 notification == YES); |
214 } | 222 } |
215 | 223 |
216 @end | 224 @end |
OLD | NEW |