shill: Replace TestProxyFactory variants with MockProxyFactory.
This CL reduces the number of TestProxyFactory variants in unit tests as
follows:
- Add a ReturnAndReleasePointee Google Mock action, which can be used
with EXPECT_CALL on MockProxyFactory, to mimic how TestProxyFactory
handles the scoped_ptr of mock proxies.
- Use MockProxyFactor with EXPECT_CALL to mimic
TestProxyFactory::Create*Proxy methods.
- Check arguments passed to MockProxyFactory::Create*Proxy() via
EXPECT_CALL.
BUG=chromium:338623
TEST=`FEATURES=test emerge-{x86,amd64,arm}-generic shill`
Change-Id: Ieb0689f76feb105a2d1efaf1e7c52b4bc15fb8d7
Reviewed-on: https://chromium-review.googlesource.com/184033
Reviewed-by: Paul Stewart <pstew@chromium.org>
Tested-by: Ben Chan <benchan@chromium.org>
Commit-Queue: Ben Chan <benchan@chromium.org>
diff --git a/dhcp_config_unittest.cc b/dhcp_config_unittest.cc
index f094531..cd37627 100644
--- a/dhcp_config_unittest.cc
+++ b/dhcp_config_unittest.cc
@@ -9,7 +9,6 @@
#include <base/files/scoped_temp_dir.h>
#include <base/stringprintf.h>
#include <chromeos/dbus/service_constants.h>
-#include <gtest/gtest.h>
#include "shill/dbus_adaptor.h"
#include "shill/dhcp_provider.h"
@@ -19,8 +18,9 @@
#include "shill/mock_glib.h"
#include "shill/mock_log.h"
#include "shill/mock_minijail.h"
+#include "shill/mock_proxy_factory.h"
#include "shill/property_store_unittest.h"
-#include "shill/proxy_factory.h"
+#include "shill/testing.h"
using base::Bind;
using base::FilePath;
@@ -52,7 +52,6 @@
public:
DHCPConfigTest()
: proxy_(new MockDHCPProxy()),
- proxy_factory_(this),
minijail_(new MockMinijail()),
config_(new DHCPConfig(&control_,
dispatcher(),
@@ -86,18 +85,6 @@
bool lease_file_exists);
protected:
- class TestProxyFactory : public ProxyFactory {
- public:
- explicit TestProxyFactory(DHCPConfigTest *test) : test_(test) {}
-
- virtual DHCPProxyInterface *CreateDHCPProxy(const string &/*service*/) {
- return test_->proxy_.release();
- }
-
- private:
- DHCPConfigTest *test_;
- };
-
static const int kPID;
static const unsigned int kTag;
@@ -105,7 +92,7 @@
FilePath pid_file_;
ScopedTempDir temp_dir_;
scoped_ptr<MockDHCPProxy> proxy_;
- TestProxyFactory proxy_factory_;
+ MockProxyFactory proxy_factory_;
MockControl control_;
scoped_ptr<MockMinijail> minijail_;
DHCPConfigRefPtr config_;
@@ -195,6 +182,8 @@
static const char kService[] = ":1.200";
EXPECT_TRUE(proxy_.get());
EXPECT_FALSE(config_->proxy_.get());
+ EXPECT_CALL(proxy_factory_, CreateDHCPProxy(kService))
+ .WillOnce(ReturnAndReleasePointee(&proxy_));
config_->InitProxy(kService);
EXPECT_FALSE(proxy_.get());
EXPECT_TRUE(config_->proxy_.get());