| OLD | NEW |
| 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 #include "device/bluetooth/test/mock_bluetooth_cbdescriptor_mac.h" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 return result; | 87 return result; |
| 88 } | 88 } |
| 89 } // namespace | 89 } // namespace |
| 90 } // device | 90 } // device |
| 91 | 91 |
| 92 @interface MockCBCharacteristic () { | 92 @interface MockCBCharacteristic () { |
| 93 // Owner of this instance. | 93 // Owner of this instance. |
| 94 CBService* _service; | 94 CBService* _service; |
| 95 scoped_nsobject<CBUUID> _UUID; | 95 scoped_nsobject<CBUUID> _UUID; |
| 96 CBCharacteristicProperties _cb_properties; | 96 CBCharacteristicProperties _cb_properties; |
| 97 scoped_nsobject<NSMutableArray> _simulatedDescriptors; | 97 scoped_nsobject<NSMutableArray> _descriptors; |
| 98 scoped_nsobject<NSArray> _descriptors; | |
| 99 scoped_nsobject<NSObject> _value; | 98 scoped_nsobject<NSObject> _value; |
| 100 BOOL _notifying; | 99 BOOL _notifying; |
| 101 } | 100 } |
| 102 @end | 101 @end |
| 103 | 102 |
| 104 @implementation MockCBCharacteristic | 103 @implementation MockCBCharacteristic |
| 105 | 104 |
| 106 - (instancetype)initWithService:(CBService*)service | 105 - (instancetype)initWithService:(CBService*)service |
| 107 CBUUID:(CBUUID*)uuid | 106 CBUUID:(CBUUID*)uuid |
| 108 properties:(int)properties { | 107 properties:(int)properties { |
| 109 self = [super init]; | 108 self = [super init]; |
| 110 if (self) { | 109 if (self) { |
| 111 _service = service; | 110 _service = service; |
| 112 _UUID.reset([uuid retain]); | 111 _UUID.reset([uuid retain]); |
| 113 _cb_properties = | 112 _cb_properties = |
| 114 device::GattCharacteristicPropertyToCBCharacteristicProperty( | 113 device::GattCharacteristicPropertyToCBCharacteristicProperty( |
| 115 properties); | 114 properties); |
| 116 _simulatedDescriptors.reset([[NSMutableArray alloc] init]); | 115 _descriptors.reset([[NSMutableArray alloc] init]); |
| 117 } | 116 } |
| 118 return self; | 117 return self; |
| 119 } | 118 } |
| 120 | 119 |
| 121 - (BOOL)isKindOfClass:(Class)aClass { | 120 - (BOOL)isKindOfClass:(Class)aClass { |
| 122 if (aClass == [CBCharacteristic class] || | 121 if (aClass == [CBCharacteristic class] || |
| 123 [aClass isSubclassOfClass:[CBCharacteristic class]]) { | 122 [aClass isSubclassOfClass:[CBCharacteristic class]]) { |
| 124 return YES; | 123 return YES; |
| 125 } | 124 } |
| 126 return [super isKindOfClass:aClass]; | 125 return [super isKindOfClass:aClass]; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 } | 181 } |
| 183 | 182 |
| 184 - (void)simulateGattCharacteristicChangedWithValue:(NSData*)value { | 183 - (void)simulateGattCharacteristicChangedWithValue:(NSData*)value { |
| 185 _value.reset([value copy]); | 184 _value.reset([value copy]); |
| 186 CBPeripheral* peripheral = _service.peripheral; | 185 CBPeripheral* peripheral = _service.peripheral; |
| 187 [peripheral.delegate peripheral:peripheral | 186 [peripheral.delegate peripheral:peripheral |
| 188 didUpdateValueForCharacteristic:self.characteristic | 187 didUpdateValueForCharacteristic:self.characteristic |
| 189 error:nil]; | 188 error:nil]; |
| 190 } | 189 } |
| 191 | 190 |
| 192 - (void)simulateDescriptorWithUUID:(CBUUID*)uuid { | 191 - (void)addDescriptorWithUUID:(CBUUID*)uuid { |
| 193 scoped_nsobject<MockCBDescriptor> descriptor_mock([[MockCBDescriptor alloc] | 192 scoped_nsobject<MockCBDescriptor> descriptor_mock([[MockCBDescriptor alloc] |
| 194 initWithCharacteristic:self.characteristic | 193 initWithCharacteristic:self.characteristic |
| 195 CBUUID:uuid]); | 194 CBUUID:uuid]); |
| 196 [_simulatedDescriptors.get() addObject:descriptor_mock]; | 195 [_descriptors.get() addObject:descriptor_mock]; |
| 197 } | |
| 198 | |
| 199 - (void)discoverDescriptors { | |
| 200 _descriptors.reset([_simulatedDescriptors copy]); | |
| 201 } | 196 } |
| 202 | 197 |
| 203 - (CBUUID*)UUID { | 198 - (CBUUID*)UUID { |
| 204 return _UUID.get(); | 199 return _UUID.get(); |
| 205 } | 200 } |
| 206 | 201 |
| 207 - (CBCharacteristic*)characteristic { | 202 - (CBCharacteristic*)characteristic { |
| 208 return ObjCCast<CBCharacteristic>(self); | 203 return ObjCCast<CBCharacteristic>(self); |
| 209 } | 204 } |
| 210 | 205 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 222 | 217 |
| 223 - (id)value { | 218 - (id)value { |
| 224 return _value.get(); | 219 return _value.get(); |
| 225 } | 220 } |
| 226 | 221 |
| 227 - (BOOL)isNotifying { | 222 - (BOOL)isNotifying { |
| 228 return _notifying; | 223 return _notifying; |
| 229 } | 224 } |
| 230 | 225 |
| 231 @end | 226 @end |
| OLD | NEW |