OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "device/bluetooth/test/mock_bluetooth_cbcharacteristic_mac.h" |
| 6 |
| 7 #include "base/mac/foundation_util.h" |
| 8 #include "base/mac/scoped_nsobject.h" |
| 9 #include "device/bluetooth/bluetooth_gatt_characteristic.h" |
| 10 |
| 11 using base::mac::ObjCCast; |
| 12 using base::scoped_nsobject; |
| 13 |
| 14 namespace device { |
| 15 |
| 16 namespace { |
| 17 // static |
| 18 CBCharacteristicProperties GattCharacteristicPropertyToCBCharacteristicProperty( |
| 19 BluetoothGattCharacteristic::Properties cb_property) { |
| 20 CBCharacteristicProperties result = 0; |
| 21 if (cb_property & BluetoothGattCharacteristic::PROPERTY_BROADCAST) { |
| 22 result |= CBCharacteristicPropertyBroadcast; |
| 23 } |
| 24 if (cb_property & BluetoothGattCharacteristic::PROPERTY_READ) { |
| 25 result |= CBCharacteristicPropertyRead; |
| 26 } |
| 27 if (cb_property & |
| 28 BluetoothGattCharacteristic::PROPERTY_WRITE_WITHOUT_RESPONSE) { |
| 29 result |= CBCharacteristicPropertyWriteWithoutResponse; |
| 30 } |
| 31 if (cb_property & BluetoothGattCharacteristic::PROPERTY_WRITE) { |
| 32 result |= CBCharacteristicPropertyWrite; |
| 33 } |
| 34 if (cb_property & BluetoothGattCharacteristic::PROPERTY_NOTIFY) { |
| 35 result |= CBCharacteristicPropertyNotify; |
| 36 } |
| 37 if (cb_property & BluetoothGattCharacteristic::PROPERTY_INDICATE) { |
| 38 result |= CBCharacteristicPropertyIndicate; |
| 39 } |
| 40 if (cb_property & |
| 41 BluetoothGattCharacteristic::PROPERTY_AUTHENTICATED_SIGNED_WRITES) { |
| 42 result |= CBCharacteristicPropertyAuthenticatedSignedWrites; |
| 43 } |
| 44 if (cb_property & BluetoothGattCharacteristic::PROPERTY_EXTENDED_PROPERTIES) { |
| 45 result |= CBCharacteristicPropertyExtendedProperties; |
| 46 } |
| 47 if (cb_property & BluetoothGattCharacteristic::PROPERTY_RELIABLE_WRITE) { |
| 48 } |
| 49 if (cb_property & |
| 50 BluetoothGattCharacteristic::PROPERTY_WRITABLE_AUXILIARIES) { |
| 51 } |
| 52 if (cb_property & BluetoothGattCharacteristic::PROPERTY_READ_ENCRYPTED) { |
| 53 result |= CBCharacteristicPropertyRead; |
| 54 } |
| 55 if (cb_property & BluetoothGattCharacteristic::PROPERTY_WRITE_ENCRYPTED) { |
| 56 result |= CBCharacteristicPropertyWrite; |
| 57 } |
| 58 if (cb_property & |
| 59 BluetoothGattCharacteristic::PROPERTY_READ_ENCRYPTED_AUTHENTICATED) { |
| 60 result |= CBCharacteristicPropertyRead; |
| 61 } |
| 62 if (cb_property & |
| 63 BluetoothGattCharacteristic::PROPERTY_WRITE_ENCRYPTED_AUTHENTICATED) { |
| 64 result |= CBCharacteristicPropertyWrite; |
| 65 } |
| 66 return result; |
| 67 } |
| 68 } // namespace |
| 69 } // device |
| 70 |
| 71 @interface MockCBCharacteristic () { |
| 72 scoped_nsobject<CBUUID> _UUID; |
| 73 CBCharacteristicProperties _cb_properties; |
| 74 } |
| 75 @end |
| 76 |
| 77 @implementation MockCBCharacteristic |
| 78 |
| 79 - (instancetype)initWithCBUUID:(CBUUID*)uuid properties:(int)properties { |
| 80 self = [super init]; |
| 81 if (self) { |
| 82 _UUID.reset([uuid retain]); |
| 83 _cb_properties = |
| 84 device::GattCharacteristicPropertyToCBCharacteristicProperty( |
| 85 properties); |
| 86 } |
| 87 return self; |
| 88 } |
| 89 |
| 90 - (BOOL)isKindOfClass:(Class)aClass { |
| 91 if (aClass == [CBCharacteristic class] || |
| 92 [aClass isSubclassOfClass:[CBCharacteristic class]]) { |
| 93 return YES; |
| 94 } |
| 95 return [super isKindOfClass:aClass]; |
| 96 } |
| 97 |
| 98 - (BOOL)isMemberOfClass:(Class)aClass { |
| 99 if (aClass == [CBCharacteristic class] || |
| 100 [aClass isSubclassOfClass:[CBCharacteristic class]]) { |
| 101 return YES; |
| 102 } |
| 103 return [super isKindOfClass:aClass]; |
| 104 } |
| 105 |
| 106 - (CBUUID*)UUID { |
| 107 return _UUID.get(); |
| 108 } |
| 109 |
| 110 - (CBCharacteristic*)characteristic { |
| 111 return ObjCCast<CBCharacteristic>(self); |
| 112 } |
| 113 |
| 114 - (CBCharacteristicProperties)properties { |
| 115 return _cb_properties; |
| 116 } |
| 117 |
| 118 @end |
OLD | NEW |