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_cbservice_mac.h" | 5 #include "device/bluetooth/test/mock_bluetooth_cbservice_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/test/bluetooth_test.h" | 9 #include "device/bluetooth/test/bluetooth_test.h" |
10 #include "device/bluetooth/test/mock_bluetooth_cbcharacteristic_mac.h" | |
10 | 11 |
11 using base::mac::ObjCCast; | 12 using base::mac::ObjCCast; |
12 using base::scoped_nsobject; | 13 using base::scoped_nsobject; |
13 | 14 |
14 @interface MockCBService () { | 15 @interface MockCBService () { |
16 // Owner of this instance. | |
17 CBPeripheral* _peripheral; | |
msarda
2016/06/14 09:15:05
Consider using a WeakNSObject for this.
jlebel
2016/06/15 16:16:37
WeakNSObject is defined in base/ios/weak_nsobject.
| |
15 scoped_nsobject<CBUUID> _UUID; | 18 scoped_nsobject<CBUUID> _UUID; |
16 BOOL _primary; | 19 BOOL _primary; |
20 scoped_nsobject<NSMutableArray> _characteristics; | |
17 } | 21 } |
18 | 22 |
19 @end | 23 @end |
20 | 24 |
21 @implementation MockCBService | 25 @implementation MockCBService |
22 | 26 |
23 @synthesize isPrimary = _primary; | 27 @synthesize isPrimary = _primary; |
24 | 28 |
25 - (instancetype)initWithCBUUID:(CBUUID*)uuid primary:(BOOL)isPrimary { | 29 - (instancetype)initWithPeripheral:(CBPeripheral*)peripheral |
30 CBUUID:(CBUUID*)uuid | |
31 primary:(BOOL)isPrimary { | |
26 self = [super init]; | 32 self = [super init]; |
27 if (self) { | 33 if (self) { |
28 _UUID.reset([uuid retain]); | 34 _UUID.reset([uuid retain]); |
29 _primary = isPrimary; | 35 _primary = isPrimary; |
36 _peripheral = peripheral; | |
37 _characteristics.reset([[NSMutableArray alloc] init]); | |
30 } | 38 } |
31 return self; | 39 return self; |
32 } | 40 } |
33 | 41 |
34 - (BOOL)isKindOfClass:(Class)aClass { | 42 - (BOOL)isKindOfClass:(Class)aClass { |
35 if (aClass == [CBService class] || | 43 if (aClass == [CBService class] || |
36 [aClass isSubclassOfClass:[CBService class]]) { | 44 [aClass isSubclassOfClass:[CBService class]]) { |
37 return YES; | 45 return YES; |
38 } | 46 } |
39 return [super isKindOfClass:aClass]; | 47 return [super isKindOfClass:aClass]; |
40 } | 48 } |
41 | 49 |
42 - (BOOL)isMemberOfClass:(Class)aClass { | 50 - (BOOL)isMemberOfClass:(Class)aClass { |
43 if (aClass == [CBService class] || | 51 if (aClass == [CBService class] || |
44 [aClass isSubclassOfClass:[CBService class]]) { | 52 [aClass isSubclassOfClass:[CBService class]]) { |
45 return YES; | 53 return YES; |
46 } | 54 } |
47 return [super isKindOfClass:aClass]; | 55 return [super isKindOfClass:aClass]; |
48 } | 56 } |
49 | 57 |
58 - (CBPeripheral*)peripheral { | |
59 return _peripheral; | |
60 } | |
61 | |
50 - (CBUUID*)UUID { | 62 - (CBUUID*)UUID { |
51 return _UUID.get(); | 63 return _UUID.get(); |
52 } | 64 } |
53 | 65 |
66 - (void)addCharacteristicWithUUID:(CBUUID*)cb_uuid properties:(int)properties { | |
67 scoped_nsobject<MockCBCharacteristic> characteristic_mock( | |
68 [[MockCBCharacteristic alloc] initWithCBUUID:cb_uuid | |
69 properties:properties]); | |
70 [_characteristics.get() addObject:characteristic_mock]; | |
71 } | |
72 | |
54 - (CBService*)service { | 73 - (CBService*)service { |
55 return ObjCCast<CBService>(self); | 74 return ObjCCast<CBService>(self); |
56 } | 75 } |
57 | 76 |
77 - (NSArray*)characteristics { | |
78 return _characteristics.get(); | |
79 } | |
80 | |
58 @end | 81 @end |
OLD | NEW |