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

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

Issue 2595373003: Bluetooth: mac: Working on macOS descriptor implementation. (Closed)
Patch Set: Fixes Created 3 years, 11 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
« no previous file with comments | « device/bluetooth/test/mock_bluetooth_cbperipheral_mac.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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_cbservice_mac.h" 11 #include "device/bluetooth/test/mock_bluetooth_cbservice_mac.h"
11 12
12 using base::mac::ObjCCast; 13 using base::mac::ObjCCast;
13 using base::scoped_nsobject; 14 using base::scoped_nsobject;
14 15
15 @interface MockCBPeripheral () { 16 @interface MockCBPeripheral () {
16 scoped_nsobject<NSUUID> _identifier; 17 scoped_nsobject<NSUUID> _identifier;
17 scoped_nsobject<NSString> _name; 18 scoped_nsobject<NSString> _name;
18 id<CBPeripheralDelegate> _delegate; 19 id<CBPeripheralDelegate> _delegate;
19 scoped_nsobject<NSMutableArray> _services; 20 scoped_nsobject<NSMutableArray> _services;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 if (_bluetoothTestMac) { 83 if (_bluetoothTestMac) {
83 _bluetoothTestMac->OnFakeBluetoothServiceDiscovery(); 84 _bluetoothTestMac->OnFakeBluetoothServiceDiscovery();
84 } 85 }
85 [_delegate peripheral:self.peripheral didDiscoverServices:nil]; 86 [_delegate peripheral:self.peripheral didDiscoverServices:nil];
86 } 87 }
87 88
88 - (void)discoverCharacteristics:(NSArray*)characteristics 89 - (void)discoverCharacteristics:(NSArray*)characteristics
89 forService:(CBService*)service { 90 forService:(CBService*)service {
90 } 91 }
91 92
93 - (void)discoverDescriptorsForCharacteristic:(CBCharacteristic*)characteristic {
94 MockCBCharacteristic* mock_characteristic =
95 ObjCCast<MockCBCharacteristic>(characteristic);
96 [mock_characteristic discoverDescriptors];
97 }
98
92 - (void)readValueForCharacteristic:(CBCharacteristic*)characteristic { 99 - (void)readValueForCharacteristic:(CBCharacteristic*)characteristic {
93 DCHECK(_bluetoothTestMac); 100 DCHECK(_bluetoothTestMac);
94 _bluetoothTestMac->OnFakeBluetoothCharacteristicReadValue(); 101 _bluetoothTestMac->OnFakeBluetoothCharacteristicReadValue();
95 } 102 }
96 103
97 - (void)writeValue:(NSData*)data 104 - (void)writeValue:(NSData*)data
98 forCharacteristic:(CBCharacteristic*)characteristic 105 forCharacteristic:(CBCharacteristic*)characteristic
99 type:(CBCharacteristicWriteType)type { 106 type:(CBCharacteristicWriteType)type {
100 DCHECK(_bluetoothTestMac); 107 DCHECK(_bluetoothTestMac);
101 const uint8_t* buffer = static_cast<const uint8_t*>(data.bytes); 108 const uint8_t* buffer = static_cast<const uint8_t*>(data.bytes);
(...skipping 23 matching lines...) Expand all
125 } 132 }
126 133
127 - (void)removeService:(CBService*)service { 134 - (void)removeService:(CBService*)service {
128 base::scoped_nsobject<CBService> serviceToRemove(service, 135 base::scoped_nsobject<CBService> serviceToRemove(service,
129 base::scoped_policy::RETAIN); 136 base::scoped_policy::RETAIN);
130 DCHECK(serviceToRemove); 137 DCHECK(serviceToRemove);
131 [_services.get() removeObject:serviceToRemove]; 138 [_services.get() removeObject:serviceToRemove];
132 [self didModifyServices:@[ serviceToRemove ]]; 139 [self didModifyServices:@[ serviceToRemove ]];
133 } 140 }
134 141
135
136 - (void)didModifyServices:(NSArray*)invalidatedServices {
137 DCHECK(
138 [_delegate respondsToSelector:@selector(peripheral:didModifyServices:)]);
139 [_delegate peripheral:self.peripheral didModifyServices:invalidatedServices];
140 }
141
142 - (void)mockDidDiscoverEvents { 142 - (void)mockDidDiscoverEvents {
143 [_delegate peripheral:self.peripheral didDiscoverServices:nil]; 143 [_delegate peripheral:self.peripheral didDiscoverServices:nil];
144 // BluetoothLowEnergyDeviceMac is expected to call 144 // BluetoothLowEnergyDeviceMac is expected to call
145 // -[CBPeripheral discoverCharacteristics:forService:] for each services, 145 // -[CBPeripheral discoverCharacteristics:forService:] for each services,
146 // so -[<CBPeripheralDelegate peripheral:didDiscoverCharacteristicsForService: 146 // so -[<CBPeripheralDelegate peripheral:didDiscoverCharacteristicsForService:
147 // error:] needs to be called for all services. 147 // error:] needs to be called for all services.
148 for (CBService* service in _services.get()) { 148 for (CBService* service in _services.get()) {
149 [_delegate peripheral:self.peripheral 149 [_delegate peripheral:self.peripheral
150 didDiscoverCharacteristicsForService:service 150 didDiscoverCharacteristicsForService:service
151 error:nil]; 151 error:nil];
152 for (CBCharacteristic* characteristic in service.characteristics) {
153 // After discovering services, BluetoothLowEnergyDeviceMac is expected to
154 // discover characteristics for all services.
155 [_delegate peripheral:self.peripheral
156 didDiscoverDescriptorsForCharacteristic:characteristic
157 error:nil];
158 }
152 } 159 }
153 } 160 }
154 161
162 - (void)didModifyServices:(NSArray*)invalidatedServices {
163 DCHECK(
164 [_delegate respondsToSelector:@selector(peripheral:didModifyServices:)]);
165 [_delegate peripheral:self.peripheral didModifyServices:invalidatedServices];
166 }
167
168 - (void)didDiscoverDescriptorsWithCharacteristic:
169 (MockCBCharacteristic*)characteristic_mock {
170 [_delegate peripheral:self.peripheral
171 didDiscoverDescriptorsForCharacteristic:characteristic_mock.characteristic
172 error:nil];
173 }
174
155 - (NSUUID*)identifier { 175 - (NSUUID*)identifier {
156 return _identifier.get(); 176 return _identifier.get();
157 } 177 }
158 178
159 - (NSString*)name { 179 - (NSString*)name {
160 return _name.get(); 180 return _name.get();
161 } 181 }
162 182
163 - (NSArray*)services { 183 - (NSArray*)services {
164 return _services.get(); 184 return _services.get();
165 } 185 }
166 186
167 - (CBPeripheral*)peripheral { 187 - (CBPeripheral*)peripheral {
168 return ObjCCast<CBPeripheral>(self); 188 return ObjCCast<CBPeripheral>(self);
169 } 189 }
170 190
171 - (void)setNotifyValue:(BOOL)notification 191 - (void)setNotifyValue:(BOOL)notification
172 forCharacteristic:(CBCharacteristic*)characteristic { 192 forCharacteristic:(CBCharacteristic*)characteristic {
173 _bluetoothTestMac->OnFakeBluetoothGattSetCharacteristicNotification(); 193 _bluetoothTestMac->OnFakeBluetoothGattSetCharacteristicNotification();
174 } 194 }
175 195
176 @end 196 @end
OLDNEW
« no previous file with comments | « device/bluetooth/test/mock_bluetooth_cbperipheral_mac.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698