diff options
author | Vitaly Buka <vitalybuka@google.com> | 2016-02-03 16:37:28 -0800 |
---|---|---|
committer | Vitaly Buka <vitalybuka@google.com> | 2016-02-03 16:49:26 -0800 |
commit | ff46c9361512be430b2aea0e8e11b51c2b9671b5 (patch) | |
tree | 3836a79d53e7ab607d6c0b89ccd6cc8eefe30cb7 /src/commands/cloud_command_proxy_unittest.cc | |
parent | 08be74de678930e6823f9fe7e460c35bb58040f9 (diff) | |
parent | 51c4d0d3184dfb5f2601367f06a46459126f377d (diff) | |
download | libweave-ff46c9361512be430b2aea0e8e11b51c2b9671b5.tar.gz |
Merge remote-tracking branch 'weave/master' into dev_review
* weave/master:
Revert "Make internal googletest optional."
Fix incorrect weave setting file path
Make internal googletest optional.
Make internal libevhtp optional.
Periodicly clean up command queue and remove old processed commands
Changed meaning of some SSID flags
Rename CommandQueue::DelayedRemove into RemoveLater()
Fix memory leak when removing CommandInstance from CommandQueue
Add a unit tests for deleting CloudCommandProxy along with CommandInstance
Add libevent-dev to README.
Make default Makefile target "all".
Replace bleeding-edge libevent with libevhtp.
Remove crypto type "None"
Merge: Add write callback into SaveSettings function
Merge: Add |name| into LoadSettings/SaveSettings
Change-Id: Ia20fbfd59ee3b6287380b6e674b03f038d1b88b3
Diffstat (limited to 'src/commands/cloud_command_proxy_unittest.cc')
-rw-r--r-- | src/commands/cloud_command_proxy_unittest.cc | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/src/commands/cloud_command_proxy_unittest.cc b/src/commands/cloud_command_proxy_unittest.cc index 013769d..0de67fe 100644 --- a/src/commands/cloud_command_proxy_unittest.cc +++ b/src/commands/cloud_command_proxy_unittest.cc @@ -7,6 +7,7 @@ #include <memory> #include <queue> +#include <base/bind.h> #include <gmock/gmock.h> #include <gtest/gtest.h> #include <weave/provider/test/fake_task_runner.h> @@ -16,6 +17,7 @@ #include "src/mock_component_manager.h" using testing::_; +using testing::AnyNumber; using testing::DoAll; using testing::Invoke; using testing::Return; @@ -62,6 +64,27 @@ class TestBackoffEntry : public BackoffEntry { base::Time creation_time_; }; +class CloudCommandProxyWrapper : public CloudCommandProxy { + public: + CloudCommandProxyWrapper(CommandInstance* command_instance, + CloudCommandUpdateInterface* cloud_command_updater, + ComponentManager* component_manager, + std::unique_ptr<BackoffEntry> backoff_entry, + provider::TaskRunner* task_runner, + const base::Closure& destruct_callback) + : CloudCommandProxy{command_instance, cloud_command_updater, + component_manager, std::move(backoff_entry), + task_runner}, + destruct_callback_{destruct_callback} {} + + ~CloudCommandProxyWrapper() { + destruct_callback_.Run(); + } + + private: + base::Closure destruct_callback_; +}; + class CloudCommandProxyTest : public ::testing::Test { protected: void SetUp() override { @@ -100,15 +123,21 @@ class CloudCommandProxyTest : public ::testing::Test { new TestBackoffEntry{&policy, task_runner_.GetClock()}}; // Finally construct the CloudCommandProxy we are going to test here. - std::unique_ptr<CloudCommandProxy> proxy{new CloudCommandProxy{ + std::unique_ptr<CloudCommandProxy> proxy{new CloudCommandProxyWrapper{ command_instance_.get(), &cloud_updater_, &component_manager_, - std::move(backoff), &task_runner_}}; + std::move(backoff), &task_runner_, + base::Bind(&CloudCommandProxyTest::OnProxyDestroyed, + base::Unretained(this))}}; // CloudCommandProxy::CloudCommandProxy() subscribe itself to weave::Command // notifications. When weave::Command is being destroyed it sends // ::OnCommandDestroyed() and CloudCommandProxy deletes itself. proxy.release(); + + EXPECT_CALL(*this, OnProxyDestroyed()).Times(AnyNumber()); } + MOCK_METHOD0(OnProxyDestroyed, void()); + ComponentManager::UpdateID current_state_update_id_{0}; base::CallbackList<void(ComponentManager::UpdateID)> callbacks_; testing::StrictMock<MockCloudCommandUpdateInterface> cloud_updater_; @@ -120,6 +149,14 @@ class CloudCommandProxyTest : public ::testing::Test { } // anonymous namespace +TEST_F(CloudCommandProxyTest, EnsureDestroyed) { + EXPECT_CALL(*this, OnProxyDestroyed()).Times(1); + command_instance_.reset(); + // Verify that CloudCommandProxy has been destroyed already and not at some + // point during the destruction of CloudCommandProxyTest class. + testing::Mock::VerifyAndClearExpectations(this); +} + TEST_F(CloudCommandProxyTest, ImmediateUpdate) { const char expected[] = "{'state':'done'}"; EXPECT_CALL(cloud_updater_, UpdateCommand(kCmdID, MatchJson(expected), _)); |