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

Side by Side Diff: device/bluetooth/test/mock_bluetooth_cbcharacteristic_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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_cbcharacteristic_mac.h" 5 #include "device/bluetooth/test/mock_bluetooth_cbcharacteristic_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/bluetooth_gatt_characteristic.h" 9 #include "device/bluetooth/bluetooth_gatt_characteristic.h"
10 #include "device/bluetooth/test/mock_bluetooth_cbdescriptor_mac.h"
10 11
11 using base::mac::ObjCCast; 12 using base::mac::ObjCCast;
12 using base::scoped_nsobject; 13 using base::scoped_nsobject;
13 14
14 namespace device { 15 namespace device {
15 16
16 namespace { 17 namespace {
17 18
18 CBCharacteristicProperties AddCBCharacteristicProperties( 19 CBCharacteristicProperties AddCBCharacteristicProperties(
19 CBCharacteristicProperties value1, 20 CBCharacteristicProperties value1,
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 return result; 87 return result;
87 } 88 }
88 } // namespace 89 } // namespace
89 } // device 90 } // device
90 91
91 @interface MockCBCharacteristic () { 92 @interface MockCBCharacteristic () {
92 // Owner of this instance. 93 // Owner of this instance.
93 CBService* _service; 94 CBService* _service;
94 scoped_nsobject<CBUUID> _UUID; 95 scoped_nsobject<CBUUID> _UUID;
95 CBCharacteristicProperties _cb_properties; 96 CBCharacteristicProperties _cb_properties;
96 base::scoped_nsobject<NSData> _value; 97 scoped_nsobject<NSMutableArray> _simulatedDescriptors;
98 scoped_nsobject<NSArray> _descriptors;
99 scoped_nsobject<NSData> _value;
97 BOOL _notifying; 100 BOOL _notifying;
98 } 101 }
99 @end 102 @end
100 103
101 @implementation MockCBCharacteristic 104 @implementation MockCBCharacteristic
102 105
103 - (instancetype)initWithService:(CBService*)service 106 - (instancetype)initWithService:(CBService*)service
104 CBUUID:(CBUUID*)uuid 107 CBUUID:(CBUUID*)uuid
105 properties:(int)properties { 108 properties:(int)properties {
106 self = [super init]; 109 self = [super init];
107 if (self) { 110 if (self) {
108 _service = service; 111 _service = service;
109 _UUID.reset([uuid retain]); 112 _UUID.reset([uuid retain]);
110 _cb_properties = 113 _cb_properties =
111 device::GattCharacteristicPropertyToCBCharacteristicProperty( 114 device::GattCharacteristicPropertyToCBCharacteristicProperty(
112 properties); 115 properties);
116 _simulatedDescriptors.reset([[NSMutableArray alloc] init]);
113 } 117 }
114 return self; 118 return self;
115 } 119 }
116 120
117 - (BOOL)isKindOfClass:(Class)aClass { 121 - (BOOL)isKindOfClass:(Class)aClass {
118 if (aClass == [CBCharacteristic class] || 122 if (aClass == [CBCharacteristic class] ||
119 [aClass isSubclassOfClass:[CBCharacteristic class]]) { 123 [aClass isSubclassOfClass:[CBCharacteristic class]]) {
120 return YES; 124 return YES;
121 } 125 }
122 return [super isKindOfClass:aClass]; 126 return [super isKindOfClass:aClass];
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 } 165 }
162 166
163 - (void)simulateGattCharacteristicChangedWithValue:(NSData*)value { 167 - (void)simulateGattCharacteristicChangedWithValue:(NSData*)value {
164 _value.reset([value copy]); 168 _value.reset([value copy]);
165 CBPeripheral* peripheral = _service.peripheral; 169 CBPeripheral* peripheral = _service.peripheral;
166 [peripheral.delegate peripheral:peripheral 170 [peripheral.delegate peripheral:peripheral
167 didUpdateValueForCharacteristic:self.characteristic 171 didUpdateValueForCharacteristic:self.characteristic
168 error:nil]; 172 error:nil];
169 } 173 }
170 174
175 - (void)simulateDescriptorWithUUID:(CBUUID*)uuid {
176 scoped_nsobject<MockCBDescriptor> descriptor_mock([[MockCBDescriptor alloc]
177 initWithCharacteristic:self.characteristic
178 CBUUID:uuid]);
179 [_simulatedDescriptors.get() addObject:descriptor_mock];
180 }
181
182 - (void)discoverDescriptors {
183 _descriptors.reset([_simulatedDescriptors copy]);
184 }
185
171 - (CBUUID*)UUID { 186 - (CBUUID*)UUID {
172 return _UUID.get(); 187 return _UUID.get();
173 } 188 }
174 189
175 - (CBCharacteristic*)characteristic { 190 - (CBCharacteristic*)characteristic {
176 return ObjCCast<CBCharacteristic>(self); 191 return ObjCCast<CBCharacteristic>(self);
177 } 192 }
178 193
179 - (CBService*)service { 194 - (CBService*)service {
180 return _service; 195 return _service;
181 } 196 }
182 197
183 - (CBCharacteristicProperties)properties { 198 - (CBCharacteristicProperties)properties {
184 return _cb_properties; 199 return _cb_properties;
185 } 200 }
186 201
202 - (NSArray*)descriptors {
203 return _descriptors;
204 }
205
187 - (NSData*)value { 206 - (NSData*)value {
188 return _value.get(); 207 return _value.get();
189 } 208 }
190 209
191 - (BOOL)isNotifying { 210 - (BOOL)isNotifying {
192 return _notifying; 211 return _notifying;
193 } 212 }
194 213
195 @end 214 @end
OLDNEW
« no previous file with comments | « device/bluetooth/test/mock_bluetooth_cbcharacteristic_mac.h ('k') | device/bluetooth/test/mock_bluetooth_cbdescriptor_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698