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" | |
11 | 10 |
12 using base::mac::ObjCCast; | 11 using base::mac::ObjCCast; |
13 using base::scoped_nsobject; | 12 using base::scoped_nsobject; |
14 | 13 |
15 @interface MockCBService () { | 14 @interface MockCBService () { |
16 // Owner of this instance. | |
17 CBPeripheral* _peripheral; | |
18 scoped_nsobject<CBUUID> _UUID; | 15 scoped_nsobject<CBUUID> _UUID; |
19 BOOL _primary; | 16 BOOL _primary; |
20 scoped_nsobject<NSMutableArray> _characteristics; | |
21 } | 17 } |
22 | 18 |
23 @end | 19 @end |
24 | 20 |
25 @implementation MockCBService | 21 @implementation MockCBService |
26 | 22 |
27 @synthesize isPrimary = _primary; | 23 @synthesize isPrimary = _primary; |
28 | 24 |
29 - (instancetype)initWithPeripheral:(CBPeripheral*)peripheral | 25 - (instancetype)initWithCBUUID:(CBUUID*)uuid primary:(BOOL)isPrimary { |
30 CBUUID:(CBUUID*)uuid | |
31 primary:(BOOL)isPrimary { | |
32 self = [super init]; | 26 self = [super init]; |
33 if (self) { | 27 if (self) { |
34 _UUID.reset([uuid retain]); | 28 _UUID.reset([uuid retain]); |
35 _primary = isPrimary; | 29 _primary = isPrimary; |
36 _peripheral = peripheral; | |
37 _characteristics.reset([[NSMutableArray alloc] init]); | |
38 } | 30 } |
39 return self; | 31 return self; |
40 } | 32 } |
41 | 33 |
42 - (BOOL)isKindOfClass:(Class)aClass { | 34 - (BOOL)isKindOfClass:(Class)aClass { |
43 if (aClass == [CBService class] || | 35 if (aClass == [CBService class] || |
44 [aClass isSubclassOfClass:[CBService class]]) { | 36 [aClass isSubclassOfClass:[CBService class]]) { |
45 return YES; | 37 return YES; |
46 } | 38 } |
47 return [super isKindOfClass:aClass]; | 39 return [super isKindOfClass:aClass]; |
48 } | 40 } |
49 | 41 |
50 - (BOOL)isMemberOfClass:(Class)aClass { | 42 - (BOOL)isMemberOfClass:(Class)aClass { |
51 if (aClass == [CBService class] || | 43 if (aClass == [CBService class] || |
52 [aClass isSubclassOfClass:[CBService class]]) { | 44 [aClass isSubclassOfClass:[CBService class]]) { |
53 return YES; | 45 return YES; |
54 } | 46 } |
55 return [super isKindOfClass:aClass]; | 47 return [super isKindOfClass:aClass]; |
56 } | 48 } |
57 | 49 |
58 - (CBPeripheral*)peripheral { | |
59 return _peripheral; | |
60 } | |
61 | |
62 - (CBUUID*)UUID { | 50 - (CBUUID*)UUID { |
63 return _UUID.get(); | 51 return _UUID.get(); |
64 } | 52 } |
65 | 53 |
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 | |
73 - (void)removeCharacteristicMock:(MockCBCharacteristic*)characteristic_mock { | |
74 [_characteristics.get() removeObject:characteristic_mock]; | |
75 } | |
76 | |
77 - (CBService*)service { | 54 - (CBService*)service { |
78 return ObjCCast<CBService>(self); | 55 return ObjCCast<CBService>(self); |
79 } | 56 } |
80 | 57 |
81 - (NSArray*)characteristics { | |
82 return _characteristics.get(); | |
83 } | |
84 | |
85 @end | 58 @end |
OLD | NEW |