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

Unified Diff: device/bluetooth/test/mock_bluetooth_central_manager_mac.mm

Issue 2339253002: bluetooth: mac: add connected LE devices to chooser (Closed)
Patch Set: Implementing RetrieveGattConnectedDevicesWithDiscoveryFilter() with tests Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: device/bluetooth/test/mock_bluetooth_central_manager_mac.mm
diff --git a/device/bluetooth/test/mock_bluetooth_central_manager_mac.mm b/device/bluetooth/test/mock_bluetooth_central_manager_mac.mm
index fbb0dff41e75d315a5044a6e61dde508fe7382fd..703c6f3ec1783c5f24e4fefdb3269215929a7985 100644
--- a/device/bluetooth/test/mock_bluetooth_central_manager_mac.mm
+++ b/device/bluetooth/test/mock_bluetooth_central_manager_mac.mm
@@ -4,10 +4,15 @@
#import "device/bluetooth/test/mock_bluetooth_central_manager_mac.h"
+#import "base/mac/scoped_nsobject.h"
#import "device/bluetooth/test/bluetooth_test_mac.h"
#import "device/bluetooth/test/mock_bluetooth_cbperipheral_mac.h"
-@implementation MockCentralManager
+using base::scoped_nsobject;
+
+@implementation MockCentralManager {
+ scoped_nsobject<NSMutableDictionary> _connectedMockPeripheralPerServiceUUID;
+}
@synthesize scanForPeripheralsCallCount = _scanForPeripheralsCallCount;
@synthesize stopScanCallCount = _stopScanCallCount;
@@ -15,6 +20,15 @@
@synthesize state = _state;
@synthesize bluetoothTestMac = _bluetoothTestMac;
+- (instancetype)init {
+ self = [super init];
+ if (self) {
+ _connectedMockPeripheralPerServiceUUID.reset(
+ [[NSMutableDictionary alloc] init]);
+ }
+ return self;
+}
+
- (BOOL)isKindOfClass:(Class)aClass {
if (aClass == [CBCentralManager class] ||
[aClass isSubclassOfClass:[CBCentralManager class]]) {
@@ -53,4 +67,28 @@
}
}
+- (NSArray*)retrieveConnectedPeripheralsWithServices:(NSArray*)services {
ortuno 2016/10/31 04:30:51 Save the services used in this function. That way
jlebel 2016/11/07 01:43:18 Done.
+ NSMutableArray* connectedPeripherals = [[NSMutableArray alloc] init];
+ for (CBUUID* uuid in services) {
+ NSSet* peripheralSet =
+ [_connectedMockPeripheralPerServiceUUID.get() objectForKey:uuid];
+ [connectedPeripherals addObjectsFromArray:peripheralSet.allObjects];
+ }
+ return connectedPeripherals;
+}
+
+- (void)setConnectedMockPeripheral:(CBPeripheral*)peripheral
+ withServiceUUIDs:(NSSet*)serviceUUIDs {
+ for (CBUUID* uuid in serviceUUIDs) {
+ NSMutableSet* peripheralSet =
+ [_connectedMockPeripheralPerServiceUUID.get() objectForKey:uuid];
+ if (!peripheralSet) {
+ peripheralSet = [NSMutableSet set];
+ [_connectedMockPeripheralPerServiceUUID.get() setObject:peripheralSet
+ forKey:uuid];
+ }
+ [peripheralSet addObject:peripheral];
+ }
+}
+
@end

Powered by Google App Engine
This is Rietveld 408576698