blob: 885d243919d4ebcbf17cab6b2fcbbcf0f6dc4c5b [file] [log] [blame]
Thieu Le3426c8f2012-01-11 17:35:11 -08001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Darin Petkov887f2982011-07-14 16:10:17 -07002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Eric Shienbrood3e20a232012-02-16 11:35:56 -05005#include <base/stl_util.h>
Darin Petkov887f2982011-07-14 16:10:17 -07006#include <gtest/gtest.h>
Darin Petkov137884a2011-10-26 18:52:47 +02007#include <mobile_provider.h>
Darin Petkov887f2982011-07-14 16:10:17 -07008
9#include "shill/manager.h"
10#include "shill/mock_control.h"
11#include "shill/mock_glib.h"
Chris Masone2ae797d2011-08-23 20:41:00 -070012#include "shill/mock_manager.h"
Thieu Le3426c8f2012-01-11 17:35:11 -080013#include "shill/mock_metrics.h"
Darin Petkov887f2982011-07-14 16:10:17 -070014#include "shill/modem_info.h"
15#include "shill/modem_manager.h"
16
17using testing::_;
18using testing::Return;
19using testing::Test;
20
21namespace shill {
22
23class ModemInfoTest : public Test {
24 public:
25 ModemInfoTest()
Thieu Le3426c8f2012-01-11 17:35:11 -080026 : manager_(&control_interface_, &dispatcher_, &metrics_, &glib_),
27 modem_info_(&control_interface_, &dispatcher_, &metrics_, &manager_,
28 &glib_) {}
Darin Petkov887f2982011-07-14 16:10:17 -070029
30 protected:
Darin Petkov137884a2011-10-26 18:52:47 +020031 static const char kTestMobileProviderDBPath[];
32
Darin Petkov887f2982011-07-14 16:10:17 -070033 MockGLib glib_;
34 MockControl control_interface_;
35 EventDispatcher dispatcher_;
Thieu Le3426c8f2012-01-11 17:35:11 -080036 MockMetrics metrics_;
Chris Masone2ae797d2011-08-23 20:41:00 -070037 MockManager manager_;
Darin Petkov887f2982011-07-14 16:10:17 -070038 ModemInfo modem_info_;
39};
40
Darin Petkov137884a2011-10-26 18:52:47 +020041const char ModemInfoTest::kTestMobileProviderDBPath[] =
42 "provider_db_unittest.bfd";
43
Darin Petkov887f2982011-07-14 16:10:17 -070044TEST_F(ModemInfoTest, StartStop) {
David Rochberg7cb06f62012-03-05 11:23:44 -050045 const int kWatcher = 123;
Darin Petkov887f2982011-07-14 16:10:17 -070046 EXPECT_EQ(0, modem_info_.modem_managers_.size());
47 EXPECT_CALL(glib_, BusWatchName(_, _, _, _, _, _, _))
David Rochberg7cb06f62012-03-05 11:23:44 -050048 .WillOnce(Return(kWatcher))
49 .WillOnce(Return(kWatcher + 1))
50 .WillOnce(Return(kWatcher + 2));
Darin Petkov137884a2011-10-26 18:52:47 +020051 modem_info_.provider_db_path_ = kTestMobileProviderDBPath;
Darin Petkov887f2982011-07-14 16:10:17 -070052 modem_info_.Start();
David Rochberg7cb06f62012-03-05 11:23:44 -050053 EXPECT_EQ(3, modem_info_.modem_managers_.size());
Darin Petkov137884a2011-10-26 18:52:47 +020054 EXPECT_TRUE(modem_info_.provider_db_);
55 EXPECT_TRUE(mobile_provider_lookup_by_name(modem_info_.provider_db_, "AT&T"));
56 EXPECT_FALSE(mobile_provider_lookup_by_name(modem_info_.provider_db_, "xyz"));
Darin Petkov887f2982011-07-14 16:10:17 -070057
David Rochberg7cb06f62012-03-05 11:23:44 -050058 EXPECT_CALL(glib_, BusUnwatchName(kWatcher)).Times(1);
59 EXPECT_CALL(glib_, BusUnwatchName(kWatcher + 1)).Times(1);
60 EXPECT_CALL(glib_, BusUnwatchName(kWatcher + 2)).Times(1);
Darin Petkov887f2982011-07-14 16:10:17 -070061 modem_info_.Stop();
62 EXPECT_EQ(0, modem_info_.modem_managers_.size());
Darin Petkov137884a2011-10-26 18:52:47 +020063 EXPECT_FALSE(modem_info_.provider_db_);
Darin Petkov887f2982011-07-14 16:10:17 -070064}
65
66TEST_F(ModemInfoTest, RegisterModemManager) {
67 const int kWatcher = 123;
68 static const char kService[] = "some.dbus.service";
69 EXPECT_CALL(glib_, BusWatchName(_, _, _, _, _, _, _))
70 .WillOnce(Return(kWatcher));
Darin Petkov137884a2011-10-26 18:52:47 +020071 // Passes ownership of the database.
72 modem_info_.provider_db_ = mobile_provider_open_db(kTestMobileProviderDBPath);
73 EXPECT_TRUE(modem_info_.provider_db_);
David Rochberg7cb06f62012-03-05 11:23:44 -050074 modem_info_.RegisterModemManager<ModemManagerClassic>(
75 kService,
76 "/dbus/service/path");
Darin Petkov887f2982011-07-14 16:10:17 -070077 ASSERT_EQ(1, modem_info_.modem_managers_.size());
78 ModemManager *manager = modem_info_.modem_managers_[0];
79 EXPECT_EQ(kService, manager->service_);
80 EXPECT_EQ(kWatcher, manager->watcher_id_);
Darin Petkov137884a2011-10-26 18:52:47 +020081 EXPECT_EQ(modem_info_.provider_db_, manager->provider_db_);
Darin Petkov887f2982011-07-14 16:10:17 -070082 manager->watcher_id_ = 0;
83}
84
85} // namespace shill