shill: Create and register a Cellular device for each ModemManager.Modem.
BUG=chromium-os:17818
TEST=unit tests
Change-Id: Ic35adf35c8021f4c9689e72ddd03776948d036c1
Reviewed-on: http://gerrit.chromium.org/gerrit/4711
Reviewed-by: Darin Petkov <petkov@chromium.org>
Tested-by: Darin Petkov <petkov@chromium.org>
diff --git a/modem_manager_unittest.cc b/modem_manager_unittest.cc
index 3ad94ee..aa4961a 100644
--- a/modem_manager_unittest.cc
+++ b/modem_manager_unittest.cc
@@ -4,11 +4,14 @@
#include <base/stl_util-inl.h>
#include <gtest/gtest.h>
+#include <mm/mm-modem.h>
#include "shill/manager.h"
#include "shill/mock_control.h"
+#include "shill/mock_dbus_properties_proxy.h"
#include "shill/mock_glib.h"
#include "shill/mock_modem_manager_proxy.h"
+#include "shill/modem.h"
#include "shill/modem_manager.h"
#include "shill/proxy_factory.h"
@@ -31,27 +34,25 @@
&dispatcher_,
&manager_,
&glib_),
- proxy_factory_(&proxy_) {
+ proxy_factory_(&proxy_, &dbus_properties_proxy_) {
ProxyFactory::set_factory(&proxy_factory_);
}
- virtual void TearDown() {
- modem_manager_.watcher_id_ = 0;
- ModemManagerProxyInterface *proxy = modem_manager_.proxy_.release();
- EXPECT_TRUE(proxy == NULL || proxy == &proxy_);
- ProxyFactory::set_factory(NULL);
- }
+ virtual void TearDown();
protected:
class TestProxyFactory : public ProxyFactory {
public:
- TestProxyFactory(ModemManagerProxyInterface *proxy) : proxy_(proxy) {}
+ TestProxyFactory(ModemManagerProxyInterface *proxy,
+ DBusPropertiesProxyInterface *dbus_properties_proxy)
+ : proxy_(proxy),
+ dbus_properties_proxy_(dbus_properties_proxy) {}
virtual DBusPropertiesProxyInterface *CreateDBusPropertiesProxy(
Modem *modem,
const string &path,
const string &service) {
- return NULL;
+ return dbus_properties_proxy_;
}
virtual ModemManagerProxyInterface *CreateModemManagerProxy(
@@ -63,6 +64,7 @@
private:
ModemManagerProxyInterface *proxy_;
+ DBusPropertiesProxyInterface *dbus_properties_proxy_;
};
static const char kService[];
@@ -70,12 +72,15 @@
static const char kOwner[];
static const char kModemPath[];
+ void ReleaseDBusPropertiesProxy();
+
MockGLib glib_;
MockControl control_interface_;
EventDispatcher dispatcher_;
Manager manager_;
ModemManager modem_manager_;
MockModemManagerProxy proxy_;
+ MockDBusPropertiesProxy dbus_properties_proxy_;
TestProxyFactory proxy_factory_;
};
@@ -84,6 +89,26 @@
const char ModemManagerTest::kOwner[] = ":1.17";
const char ModemManagerTest::kModemPath[] = "/org/chromium/ModemManager/Gobi/0";
+void ModemManagerTest::TearDown() {
+ modem_manager_.watcher_id_ = 0;
+ ModemManagerProxyInterface *proxy = modem_manager_.proxy_.release();
+ EXPECT_TRUE(proxy == NULL || proxy == &proxy_);
+ ReleaseDBusPropertiesProxy();
+ ProxyFactory::set_factory(NULL);
+}
+
+void ModemManagerTest::ReleaseDBusPropertiesProxy() {
+ if (modem_manager_.modems_.empty()) {
+ return;
+ }
+ EXPECT_EQ(1, modem_manager_.modems_.size());
+ ModemManager::Modems::iterator iter = modem_manager_.modems_.begin();
+ DBusPropertiesProxyInterface *dbus_properties_proxy =
+ iter->second->dbus_properties_proxy_.release();
+ EXPECT_TRUE(dbus_properties_proxy == NULL ||
+ dbus_properties_proxy == &dbus_properties_proxy_);
+}
+
TEST_F(ModemManagerTest, Start) {
const int kWatcher = 123;
EXPECT_CALL(glib_, BusWatchName(G_BUS_TYPE_SYSTEM,
@@ -113,6 +138,8 @@
EXPECT_EQ("", modem_manager_.owner_);
EXPECT_CALL(proxy_, EnumerateDevices())
.WillOnce(Return(vector<DBus::Path>(1, kModemPath)));
+ EXPECT_CALL(dbus_properties_proxy_, GetAll(MM_MODEM_INTERFACE))
+ .WillOnce(Return(DBusPropertiesMap()));
modem_manager_.Connect(kOwner);
EXPECT_EQ(kOwner, modem_manager_.owner_);
EXPECT_EQ(1, modem_manager_.modems_.size());
@@ -141,9 +168,13 @@
TEST_F(ModemManagerTest, AddRemoveModem) {
modem_manager_.owner_ = kOwner;
+ EXPECT_CALL(dbus_properties_proxy_, GetAll(MM_MODEM_INTERFACE))
+ .WillOnce(Return(DBusPropertiesMap()));
modem_manager_.AddModem(kModemPath);
EXPECT_EQ(1, modem_manager_.modems_.size());
EXPECT_TRUE(ContainsKey(modem_manager_.modems_, kModemPath));
+
+ ReleaseDBusPropertiesProxy();
modem_manager_.RemoveModem(kModemPath);
EXPECT_EQ(0, modem_manager_.modems_.size());
}