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