• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright (C) 2012 The Android Open Source Project
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 #include "shill/cellular/modem_info.h"
18 
19 #include <base/stl_util.h>
20 #include <gtest/gtest.h>
21 
22 #include "shill/cellular/mock_dbus_objectmanager_proxy.h"
23 #include "shill/cellular/mock_modem_manager_proxy.h"
24 #include "shill/cellular/modem_manager.h"
25 #include "shill/manager.h"
26 #include "shill/mock_control.h"
27 #include "shill/mock_manager.h"
28 #include "shill/mock_metrics.h"
29 #include "shill/test_event_dispatcher.h"
30 
31 using testing::_;
32 using testing::Return;
33 using testing::Test;
34 
35 namespace shill {
36 
37 class ModemInfoTest : public Test {
38  public:
ModemInfoTest()39   ModemInfoTest()
40       : metrics_(&dispatcher_),
41         manager_(&control_interface_, &dispatcher_, &metrics_),
42         modem_info_(&control_interface_, &dispatcher_, &metrics_, &manager_) {}
43 
44  protected:
45   MockControl control_interface_;
46   EventDispatcherForTest dispatcher_;
47   MockMetrics metrics_;
48   MockManager manager_;
49   ModemInfo modem_info_;
50 };
51 
TEST_F(ModemInfoTest,StartStop)52 TEST_F(ModemInfoTest, StartStop) {
53   EXPECT_EQ(0, modem_info_.modem_managers_.size());
54   EXPECT_CALL(control_interface_,
55               CreateModemManagerProxy(_, _, "org.chromium.ModemManager", _, _))
56       .WillOnce(Return(new MockModemManagerProxy()));
57   EXPECT_CALL(control_interface_,
58               CreateDBusObjectManagerProxy(
59                   _, "org.freedesktop.ModemManager1", _, _))
60       .WillOnce(Return(new MockDBusObjectManagerProxy()));
61   modem_info_.Start();
62   EXPECT_EQ(2, modem_info_.modem_managers_.size());
63   modem_info_.Stop();
64   EXPECT_EQ(0, modem_info_.modem_managers_.size());
65 }
66 
TEST_F(ModemInfoTest,RegisterModemManager)67 TEST_F(ModemInfoTest, RegisterModemManager) {
68   static const char kService[] = "some.dbus.service";
69   EXPECT_CALL(control_interface_,
70               CreateModemManagerProxy(_, _, kService, _, _))
71       .WillOnce(Return(new MockModemManagerProxy()));
72   modem_info_.RegisterModemManager(
73       new ModemManagerClassic(&control_interface_,
74                               kService,
75                               "/dbus/service/path",
76                               &modem_info_));
77   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(&modem_info_, manager->modem_info_);
81 }
82 
83 }  // namespace shill
84