Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include <base/stl_util-inl.h> |
| 6 | #include <gtest/gtest.h> |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 7 | #include <mobile_provider.h> |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 8 | |
| 9 | #include "shill/manager.h" |
| 10 | #include "shill/mock_control.h" |
| 11 | #include "shill/mock_glib.h" |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 12 | #include "shill/mock_manager.h" |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 13 | #include "shill/modem_info.h" |
| 14 | #include "shill/modem_manager.h" |
| 15 | |
| 16 | using testing::_; |
| 17 | using testing::Return; |
| 18 | using testing::Test; |
| 19 | |
| 20 | namespace shill { |
| 21 | |
| 22 | class ModemInfoTest : public Test { |
| 23 | public: |
| 24 | ModemInfoTest() |
| 25 | : manager_(&control_interface_, &dispatcher_, &glib_), |
| 26 | modem_info_(&control_interface_, &dispatcher_, &manager_, &glib_) {} |
| 27 | |
| 28 | protected: |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 29 | static const char kTestMobileProviderDBPath[]; |
| 30 | |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 31 | MockGLib glib_; |
| 32 | MockControl control_interface_; |
| 33 | EventDispatcher dispatcher_; |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 34 | MockManager manager_; |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 35 | ModemInfo modem_info_; |
| 36 | }; |
| 37 | |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 38 | const char ModemInfoTest::kTestMobileProviderDBPath[] = |
| 39 | "provider_db_unittest.bfd"; |
| 40 | |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 41 | TEST_F(ModemInfoTest, StartStop) { |
| 42 | const int kWatcher1 = 123; |
| 43 | const int kWatcher2 = 456; |
| 44 | EXPECT_EQ(0, modem_info_.modem_managers_.size()); |
| 45 | EXPECT_CALL(glib_, BusWatchName(_, _, _, _, _, _, _)) |
| 46 | .WillOnce(Return(kWatcher1)) |
| 47 | .WillOnce(Return(kWatcher2)); |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 48 | modem_info_.provider_db_path_ = kTestMobileProviderDBPath; |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 49 | modem_info_.Start(); |
| 50 | EXPECT_EQ(2, modem_info_.modem_managers_.size()); |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 51 | EXPECT_TRUE(modem_info_.provider_db_); |
| 52 | EXPECT_TRUE(mobile_provider_lookup_by_name(modem_info_.provider_db_, "AT&T")); |
| 53 | EXPECT_FALSE(mobile_provider_lookup_by_name(modem_info_.provider_db_, "xyz")); |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 54 | |
| 55 | EXPECT_CALL(glib_, BusUnwatchName(kWatcher1)).Times(1); |
| 56 | EXPECT_CALL(glib_, BusUnwatchName(kWatcher2)).Times(1); |
| 57 | modem_info_.Stop(); |
| 58 | EXPECT_EQ(0, modem_info_.modem_managers_.size()); |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 59 | EXPECT_FALSE(modem_info_.provider_db_); |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | TEST_F(ModemInfoTest, RegisterModemManager) { |
| 63 | const int kWatcher = 123; |
| 64 | static const char kService[] = "some.dbus.service"; |
| 65 | EXPECT_CALL(glib_, BusWatchName(_, _, _, _, _, _, _)) |
| 66 | .WillOnce(Return(kWatcher)); |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 67 | // Passes ownership of the database. |
| 68 | modem_info_.provider_db_ = mobile_provider_open_db(kTestMobileProviderDBPath); |
| 69 | EXPECT_TRUE(modem_info_.provider_db_); |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 70 | modem_info_.RegisterModemManager(kService, "/dbus/service/path"); |
| 71 | ASSERT_EQ(1, modem_info_.modem_managers_.size()); |
| 72 | ModemManager *manager = modem_info_.modem_managers_[0]; |
| 73 | EXPECT_EQ(kService, manager->service_); |
| 74 | EXPECT_EQ(kWatcher, manager->watcher_id_); |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 75 | EXPECT_EQ(modem_info_.provider_db_, manager->provider_db_); |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 76 | manager->watcher_id_ = 0; |
| 77 | } |
| 78 | |
| 79 | } // namespace shill |