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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 } | 87 } |
88 } // namespace | 88 } // namespace |
89 } // device | 89 } // device |
90 | 90 |
91 @interface MockCBCharacteristic () { | 91 @interface MockCBCharacteristic () { |
92 // Owner of this instance. | 92 // Owner of this instance. |
93 CBService* _service; | 93 CBService* _service; |
94 scoped_nsobject<CBUUID> _UUID; | 94 scoped_nsobject<CBUUID> _UUID; |
95 CBCharacteristicProperties _cb_properties; | 95 CBCharacteristicProperties _cb_properties; |
96 base::scoped_nsobject<NSData> _value; | 96 base::scoped_nsobject<NSData> _value; |
| 97 BOOL _notifying; |
97 } | 98 } |
98 @end | 99 @end |
99 | 100 |
100 @implementation MockCBCharacteristic | 101 @implementation MockCBCharacteristic |
101 | 102 |
102 - (instancetype)initWithService:(CBService*)service | 103 - (instancetype)initWithService:(CBService*)service |
103 CBUUID:(CBUUID*)uuid | 104 CBUUID:(CBUUID*)uuid |
104 properties:(int)properties { | 105 properties:(int)properties { |
105 self = [super init]; | 106 self = [super init]; |
106 if (self) { | 107 if (self) { |
(...skipping 30 matching lines...) Expand all Loading... |
137 error:error]; | 138 error:error]; |
138 } | 139 } |
139 | 140 |
140 - (void)simulateWriteWithError:(NSError*)error { | 141 - (void)simulateWriteWithError:(NSError*)error { |
141 CBPeripheral* peripheral = _service.peripheral; | 142 CBPeripheral* peripheral = _service.peripheral; |
142 [peripheral.delegate peripheral:peripheral | 143 [peripheral.delegate peripheral:peripheral |
143 didWriteValueForCharacteristic:self.characteristic | 144 didWriteValueForCharacteristic:self.characteristic |
144 error:error]; | 145 error:error]; |
145 } | 146 } |
146 | 147 |
| 148 - (void)simulateGattNotifySessionStarted { |
| 149 _notifying = YES; |
| 150 CBPeripheral* peripheral = _service.peripheral; |
| 151 [peripheral.delegate peripheral:peripheral |
| 152 didUpdateNotificationStateForCharacteristic:self.characteristic |
| 153 error:nil]; |
| 154 } |
| 155 |
| 156 - (void)simulateGattNotifySessionFailedWithError:(NSError*)error { |
| 157 CBPeripheral* peripheral = _service.peripheral; |
| 158 [peripheral.delegate peripheral:peripheral |
| 159 didUpdateNotificationStateForCharacteristic:self.characteristic |
| 160 error:error]; |
| 161 } |
| 162 |
| 163 - (void)simulateGattCharacteristicChangedWithValue:(NSData*)value { |
| 164 _value.reset([value copy]); |
| 165 CBPeripheral* peripheral = _service.peripheral; |
| 166 [peripheral.delegate peripheral:peripheral |
| 167 didUpdateValueForCharacteristic:self.characteristic |
| 168 error:nil]; |
| 169 } |
| 170 |
147 - (CBUUID*)UUID { | 171 - (CBUUID*)UUID { |
148 return _UUID.get(); | 172 return _UUID.get(); |
149 } | 173 } |
150 | 174 |
151 - (CBCharacteristic*)characteristic { | 175 - (CBCharacteristic*)characteristic { |
152 return ObjCCast<CBCharacteristic>(self); | 176 return ObjCCast<CBCharacteristic>(self); |
153 } | 177 } |
154 | 178 |
155 - (CBService*)service { | 179 - (CBService*)service { |
156 return _service; | 180 return _service; |
157 } | 181 } |
158 | 182 |
159 - (CBCharacteristicProperties)properties { | 183 - (CBCharacteristicProperties)properties { |
160 return _cb_properties; | 184 return _cb_properties; |
161 } | 185 } |
162 | 186 |
163 - (NSData*)value { | 187 - (NSData*)value { |
164 return _value.get(); | 188 return _value.get(); |
165 } | 189 } |
166 | 190 |
| 191 - (BOOL)isNotifying { |
| 192 return _notifying; |
| 193 } |
| 194 |
167 @end | 195 @end |
OLD | NEW |