Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(163)

Side by Side Diff: device/bluetooth/test/mock_bluetooth_cbcharacteristic_mac.mm

Issue 2052513002: Read characteristic implementation on macOS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@characteristicscan_servicescan_cleanup
Patch Set: Addressing msarda's comment Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 BluetoothGattCharacteristic::PROPERTY_WRITE_ENCRYPTED_AUTHENTICATED) { 82 BluetoothGattCharacteristic::PROPERTY_WRITE_ENCRYPTED_AUTHENTICATED) {
83 result = 83 result =
84 AddCBCharacteristicProperties(result, CBCharacteristicPropertyWrite); 84 AddCBCharacteristicProperties(result, CBCharacteristicPropertyWrite);
85 } 85 }
86 return result; 86 return result;
87 } 87 }
88 } // namespace 88 } // namespace
89 } // device 89 } // device
90 90
91 @interface MockCBCharacteristic () { 91 @interface MockCBCharacteristic () {
92 // Owner of this instance.
93 CBService* _service;
92 scoped_nsobject<CBUUID> _UUID; 94 scoped_nsobject<CBUUID> _UUID;
93 CBCharacteristicProperties _cb_properties; 95 CBCharacteristicProperties _cb_properties;
96 base::scoped_nsobject<NSData> _value;
94 } 97 }
95 @end 98 @end
96 99
97 @implementation MockCBCharacteristic 100 @implementation MockCBCharacteristic
98 101
99 - (instancetype)initWithCBUUID:(CBUUID*)uuid properties:(int)properties { 102 - (instancetype)initWithService:(CBService*)service
103 CBUUID:(CBUUID*)uuid
104 properties:(int)properties {
100 self = [super init]; 105 self = [super init];
101 if (self) { 106 if (self) {
107 _service = service;
102 _UUID.reset([uuid retain]); 108 _UUID.reset([uuid retain]);
103 _cb_properties = 109 _cb_properties =
104 device::GattCharacteristicPropertyToCBCharacteristicProperty( 110 device::GattCharacteristicPropertyToCBCharacteristicProperty(
105 properties); 111 properties);
106 } 112 }
107 return self; 113 return self;
108 } 114 }
109 115
110 - (BOOL)isKindOfClass:(Class)aClass { 116 - (BOOL)isKindOfClass:(Class)aClass {
111 if (aClass == [CBCharacteristic class] || 117 if (aClass == [CBCharacteristic class] ||
112 [aClass isSubclassOfClass:[CBCharacteristic class]]) { 118 [aClass isSubclassOfClass:[CBCharacteristic class]]) {
113 return YES; 119 return YES;
114 } 120 }
115 return [super isKindOfClass:aClass]; 121 return [super isKindOfClass:aClass];
116 } 122 }
117 123
118 - (BOOL)isMemberOfClass:(Class)aClass { 124 - (BOOL)isMemberOfClass:(Class)aClass {
119 if (aClass == [CBCharacteristic class] || 125 if (aClass == [CBCharacteristic class] ||
120 [aClass isSubclassOfClass:[CBCharacteristic class]]) { 126 [aClass isSubclassOfClass:[CBCharacteristic class]]) {
121 return YES; 127 return YES;
122 } 128 }
123 return [super isKindOfClass:aClass]; 129 return [super isKindOfClass:aClass];
124 } 130 }
125 131
132 - (void)simulateReadWithValue:(NSData*)value error:(NSError*)error {
133 _value.reset([value copy]);
134 CBPeripheral* peripheral = _service.peripheral;
135 [peripheral.delegate peripheral:peripheral
136 didUpdateValueForCharacteristic:self.characteristic
137 error:error];
138 }
139
126 - (CBUUID*)UUID { 140 - (CBUUID*)UUID {
127 return _UUID.get(); 141 return _UUID.get();
128 } 142 }
129 143
130 - (CBCharacteristic*)characteristic { 144 - (CBCharacteristic*)characteristic {
131 return ObjCCast<CBCharacteristic>(self); 145 return ObjCCast<CBCharacteristic>(self);
132 } 146 }
133 147
148 - (CBService*)service {
149 return _service;
150 }
151
134 - (CBCharacteristicProperties)properties { 152 - (CBCharacteristicProperties)properties {
135 return _cb_properties; 153 return _cb_properties;
136 } 154 }
137 155
156 - (NSData*)value {
157 return _value.get();
158 }
159
138 @end 160 @end
OLDNEW
« no previous file with comments | « device/bluetooth/test/mock_bluetooth_cbcharacteristic_mac.h ('k') | device/bluetooth/test/mock_bluetooth_cbperipheral_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698