| 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 | 10 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 if (cb_property & | 62 if (cb_property & |
| 63 BluetoothGattCharacteristic::PROPERTY_WRITE_ENCRYPTED_AUTHENTICATED) { | 63 BluetoothGattCharacteristic::PROPERTY_WRITE_ENCRYPTED_AUTHENTICATED) { |
| 64 result |= CBCharacteristicPropertyWrite; | 64 result |= CBCharacteristicPropertyWrite; |
| 65 } | 65 } |
| 66 return result; | 66 return result; |
| 67 } | 67 } |
| 68 } // namespace | 68 } // namespace |
| 69 } // device | 69 } // device |
| 70 | 70 |
| 71 @interface MockCBCharacteristic () { | 71 @interface MockCBCharacteristic () { |
| 72 // Owner of this instance. |
| 73 CBService* _service; |
| 72 scoped_nsobject<CBUUID> _UUID; | 74 scoped_nsobject<CBUUID> _UUID; |
| 73 CBCharacteristicProperties _cb_properties; | 75 CBCharacteristicProperties _cb_properties; |
| 76 base::scoped_nsobject<NSData> _value; |
| 74 } | 77 } |
| 75 @end | 78 @end |
| 76 | 79 |
| 77 @implementation MockCBCharacteristic | 80 @implementation MockCBCharacteristic |
| 78 | 81 |
| 79 - (instancetype)initWithCBUUID:(CBUUID*)uuid properties:(int)properties { | 82 - (instancetype)initWithService:(CBService*)service |
| 83 CBUUID:(CBUUID*)uuid |
| 84 properties:(int)properties { |
| 80 self = [super init]; | 85 self = [super init]; |
| 81 if (self) { | 86 if (self) { |
| 87 _service = service; |
| 82 _UUID.reset([uuid retain]); | 88 _UUID.reset([uuid retain]); |
| 83 _cb_properties = | 89 _cb_properties = |
| 84 device::GattCharacteristicPropertyToCBCharacteristicProperty( | 90 device::GattCharacteristicPropertyToCBCharacteristicProperty( |
| 85 properties); | 91 properties); |
| 86 } | 92 } |
| 87 return self; | 93 return self; |
| 88 } | 94 } |
| 89 | 95 |
| 90 - (BOOL)isKindOfClass:(Class)aClass { | 96 - (BOOL)isKindOfClass:(Class)aClass { |
| 91 if (aClass == [CBCharacteristic class] || | 97 if (aClass == [CBCharacteristic class] || |
| 92 [aClass isSubclassOfClass:[CBCharacteristic class]]) { | 98 [aClass isSubclassOfClass:[CBCharacteristic class]]) { |
| 93 return YES; | 99 return YES; |
| 94 } | 100 } |
| 95 return [super isKindOfClass:aClass]; | 101 return [super isKindOfClass:aClass]; |
| 96 } | 102 } |
| 97 | 103 |
| 98 - (BOOL)isMemberOfClass:(Class)aClass { | 104 - (BOOL)isMemberOfClass:(Class)aClass { |
| 99 if (aClass == [CBCharacteristic class] || | 105 if (aClass == [CBCharacteristic class] || |
| 100 [aClass isSubclassOfClass:[CBCharacteristic class]]) { | 106 [aClass isSubclassOfClass:[CBCharacteristic class]]) { |
| 101 return YES; | 107 return YES; |
| 102 } | 108 } |
| 103 return [super isKindOfClass:aClass]; | 109 return [super isKindOfClass:aClass]; |
| 104 } | 110 } |
| 105 | 111 |
| 112 - (void)simulateReadWithValue:(NSData*)value error:(NSError*)error { |
| 113 _value.reset([value copy]); |
| 114 CBPeripheral* peripheral = _service.peripheral; |
| 115 [peripheral.delegate peripheral:peripheral |
| 116 didUpdateValueForCharacteristic:self.characteristic |
| 117 error:error]; |
| 118 } |
| 119 |
| 106 - (CBUUID*)UUID { | 120 - (CBUUID*)UUID { |
| 107 return _UUID.get(); | 121 return _UUID.get(); |
| 108 } | 122 } |
| 109 | 123 |
| 110 - (CBCharacteristic*)characteristic { | 124 - (CBCharacteristic*)characteristic { |
| 111 return ObjCCast<CBCharacteristic>(self); | 125 return ObjCCast<CBCharacteristic>(self); |
| 112 } | 126 } |
| 113 | 127 |
| 128 - (CBService*)service { |
| 129 return _service; |
| 130 } |
| 131 |
| 114 - (CBCharacteristicProperties)properties { | 132 - (CBCharacteristicProperties)properties { |
| 115 return _cb_properties; | 133 return _cb_properties; |
| 116 } | 134 } |
| 117 | 135 |
| 136 - (NSData*)value { |
| 137 return _value.get(); |
| 138 } |
| 139 |
| 118 @end | 140 @end |
| OLD | NEW |