Commit 318d6767 authored by Matt Swartwout's avatar Matt Swartwout Committed by Commit Bot

Enable MockGattClientManager to have > 1 observer

Bug: None
Test: Unit tests that add/remove more than 1 observer now pass.
Change-Id: I097eaa3bea90501e9325b969963e2e02caf62878
Reviewed-on: https://chromium-review.googlesource.com/1119627Reviewed-by: default avatarStephen Lanham <slan@chromium.org>
Commit-Queue: Matt Swartwout <mwswartwout@google.com>
Cr-Commit-Position: refs/heads/master@{#571940}
parent cf889ee1
...@@ -64,6 +64,7 @@ cast_source_set("test_support") { ...@@ -64,6 +64,7 @@ cast_source_set("test_support") {
] ]
deps = [ deps = [
":le", ":le",
"//base",
"//chromecast/public", "//chromecast/public",
"//testing/gmock", "//testing/gmock",
] ]
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef CHROMECAST_DEVICE_BLUETOOTH_LE_MOCK_GATT_CLIENT_MANAGER_H_ #ifndef CHROMECAST_DEVICE_BLUETOOTH_LE_MOCK_GATT_CLIENT_MANAGER_H_
#define CHROMECAST_DEVICE_BLUETOOTH_LE_MOCK_GATT_CLIENT_MANAGER_H_ #define CHROMECAST_DEVICE_BLUETOOTH_LE_MOCK_GATT_CLIENT_MANAGER_H_
#include "base/containers/flat_set.h"
#include "chromecast/device/bluetooth/le/gatt_client_manager.h" #include "chromecast/device/bluetooth/le/gatt_client_manager.h"
#include "chromecast/device/bluetooth/le/mock_remote_device.h" #include "chromecast/device/bluetooth/le/mock_remote_device.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
...@@ -18,12 +19,12 @@ class MockGattClientManager : public GattClientManager { ...@@ -18,12 +19,12 @@ class MockGattClientManager : public GattClientManager {
~MockGattClientManager(); ~MockGattClientManager();
void AddObserver(Observer* o) override { void AddObserver(Observer* o) override {
DCHECK(o && !observer_); DCHECK(o && !observers_.count(o));
observer_ = o; observers_.insert(o);
} }
void RemoveObserver(Observer* o) override { void RemoveObserver(Observer* o) override {
DCHECK(o && o == observer_); DCHECK(o && observers_.count(o));
observer_ = nullptr; observers_.erase(o);
} }
MOCK_METHOD1( MOCK_METHOD1(
...@@ -42,7 +43,7 @@ class MockGattClientManager : public GattClientManager { ...@@ -42,7 +43,7 @@ class MockGattClientManager : public GattClientManager {
MOCK_METHOD1(NotifyConnect, void(const bluetooth_v2_shlib::Addr& addr)); MOCK_METHOD1(NotifyConnect, void(const bluetooth_v2_shlib::Addr& addr));
MOCK_METHOD0(task_runner, scoped_refptr<base::SingleThreadTaskRunner>()); MOCK_METHOD0(task_runner, scoped_refptr<base::SingleThreadTaskRunner>());
Observer* observer_ = nullptr; base::flat_set<Observer*> observers_;
}; };
} // namespace bluetooth } // namespace bluetooth
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment