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

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

Issue 2339253002: bluetooth: mac: add connected LE devices to chooser (Closed)
Patch Set: Nit for the tests Created 4 years, 1 month 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
« no previous file with comments | « device/bluetooth/test/mock_bluetooth_central_manager_mac.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #import "device/bluetooth/test/mock_bluetooth_central_manager_mac.h" 5 #import "device/bluetooth/test/mock_bluetooth_central_manager_mac.h"
6 6
7 #import "base/mac/scoped_nsobject.h"
7 #import "device/bluetooth/test/bluetooth_test_mac.h" 8 #import "device/bluetooth/test/bluetooth_test_mac.h"
8 #import "device/bluetooth/test/mock_bluetooth_cbperipheral_mac.h" 9 #import "device/bluetooth/test/mock_bluetooth_cbperipheral_mac.h"
9 10
10 @implementation MockCentralManager 11 using base::scoped_nsobject;
12
13 @implementation MockCentralManager {
14 scoped_nsobject<NSMutableDictionary> _connectedMockPeripheralPerServiceUUID;
15 scoped_nsobject<NSMutableArray> _retrieveConnectedPeripheralServiceUUIDs;
16 }
11 17
12 @synthesize scanForPeripheralsCallCount = _scanForPeripheralsCallCount; 18 @synthesize scanForPeripheralsCallCount = _scanForPeripheralsCallCount;
13 @synthesize stopScanCallCount = _stopScanCallCount; 19 @synthesize stopScanCallCount = _stopScanCallCount;
14 @synthesize delegate = _delegate; 20 @synthesize delegate = _delegate;
15 @synthesize state = _state; 21 @synthesize state = _state;
16 @synthesize bluetoothTestMac = _bluetoothTestMac; 22 @synthesize bluetoothTestMac = _bluetoothTestMac;
17 23
24 - (instancetype)init {
25 self = [super init];
26 if (self) {
27 _connectedMockPeripheralPerServiceUUID.reset(
28 [[NSMutableDictionary alloc] init]);
29 _retrieveConnectedPeripheralServiceUUIDs.reset(
30 [[NSMutableArray alloc] init]);
31 }
32 return self;
33 }
34
18 - (BOOL)isKindOfClass:(Class)aClass { 35 - (BOOL)isKindOfClass:(Class)aClass {
19 if (aClass == [CBCentralManager class] || 36 if (aClass == [CBCentralManager class] ||
20 [aClass isSubclassOfClass:[CBCentralManager class]]) { 37 [aClass isSubclassOfClass:[CBCentralManager class]]) {
21 return YES; 38 return YES;
22 } 39 }
23 return [super isKindOfClass:aClass]; 40 return [super isKindOfClass:aClass];
24 } 41 }
25 42
26 - (BOOL)isMemberOfClass:(Class)aClass { 43 - (BOOL)isMemberOfClass:(Class)aClass {
27 if (aClass == [CBCentralManager class] || 44 if (aClass == [CBCentralManager class] ||
(...skipping 18 matching lines...) Expand all
46 _bluetoothTestMac->OnFakeBluetoothDeviceConnectGattCalled(); 63 _bluetoothTestMac->OnFakeBluetoothDeviceConnectGattCalled();
47 } 64 }
48 } 65 }
49 66
50 - (void)cancelPeripheralConnection:(CBPeripheral*)peripheral { 67 - (void)cancelPeripheralConnection:(CBPeripheral*)peripheral {
51 if (_bluetoothTestMac) { 68 if (_bluetoothTestMac) {
52 _bluetoothTestMac->OnFakeBluetoothGattDisconnect(); 69 _bluetoothTestMac->OnFakeBluetoothGattDisconnect();
53 } 70 }
54 } 71 }
55 72
73 - (NSArray*)retrieveConnectedPeripheralServiceUUIDs {
74 return [[_retrieveConnectedPeripheralServiceUUIDs.get() copy] autorelease];
75 }
76
77 - (NSArray*)retrieveConnectedPeripheralsWithServices:(NSArray*)services {
78 [_retrieveConnectedPeripheralServiceUUIDs.get()
79 addObjectsFromArray:[services copy]];
80 NSMutableArray* connectedPeripherals = [[NSMutableArray alloc] init];
81 for (CBUUID* uuid in services) {
82 NSSet* peripheralSet =
83 [_connectedMockPeripheralPerServiceUUID.get() objectForKey:uuid];
84 [connectedPeripherals addObjectsFromArray:peripheralSet.allObjects];
85 }
86 return connectedPeripherals;
87 }
88
89 - (void)setConnectedMockPeripheral:(CBPeripheral*)peripheral
90 withServiceUUIDs:(NSSet*)serviceUUIDs {
91 for (CBUUID* uuid in serviceUUIDs) {
92 NSMutableSet* peripheralSet =
93 [_connectedMockPeripheralPerServiceUUID.get() objectForKey:uuid];
94 if (!peripheralSet) {
95 peripheralSet = [NSMutableSet set];
96 [_connectedMockPeripheralPerServiceUUID.get() setObject:peripheralSet
97 forKey:uuid];
98 }
99 [peripheralSet addObject:peripheral];
100 }
101 }
102
103 - (void)resetRetrieveConnectedPeripheralServiceUUIDs {
104 [_retrieveConnectedPeripheralServiceUUIDs removeAllObjects];
105 }
106
56 @end 107 @end
OLDNEW
« no previous file with comments | « device/bluetooth/test/mock_bluetooth_central_manager_mac.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698