Paul Stewart | 8c116a9 | 2012-05-02 18:30:03 -0700 | [diff] [blame] | 1 | // Copyright (c) 2012 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 "shill/mock_modem_info.h" |
| 6 | |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 7 | #include <mobile_provider.h> |
| 8 | |
Paul Stewart | 8c116a9 | 2012-05-02 18:30:03 -0700 | [diff] [blame] | 9 | namespace shill { |
| 10 | |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 11 | MockModemInfo::MockModemInfo() : |
| 12 | ModemInfo(NULL, NULL, NULL, NULL, NULL), |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 13 | mock_pending_activation_store_(NULL), |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 14 | mock_cellular_operator_info_(NULL) {} |
| 15 | |
| 16 | MockModemInfo::MockModemInfo(ControlInterface *control, |
| 17 | EventDispatcher *dispatcher, |
| 18 | Metrics *metrics, |
| 19 | Manager *manager, |
| 20 | GLib *glib) : |
| 21 | ModemInfo(control, dispatcher, metrics, manager, glib), |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 22 | mock_pending_activation_store_(NULL), |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 23 | mock_cellular_operator_info_(NULL) { |
| 24 | SetMockMembers(); |
| 25 | } |
Paul Stewart | 8c116a9 | 2012-05-02 18:30:03 -0700 | [diff] [blame] | 26 | |
| 27 | MockModemInfo::~MockModemInfo() {} |
| 28 | |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 29 | void MockModemInfo::SetMockMembers() { |
| 30 | // These are always replaced by mocks. |
| 31 | // Assumes ownership. |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 32 | set_pending_activation_store(new MockPendingActivationStore()); |
| 33 | mock_pending_activation_store_ = |
| 34 | static_cast<MockPendingActivationStore*>(pending_activation_store()); |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 35 | // Assumes ownership. |
| 36 | set_cellular_operator_info(new MockCellularOperatorInfo()); |
| 37 | mock_cellular_operator_info_ = |
| 38 | static_cast<MockCellularOperatorInfo*>(cellular_operator_info()); |
| 39 | |
| 40 | // These are replaced by mocks only if current unset in ModemInfo. |
| 41 | if(control_interface() == NULL) { |
| 42 | mock_control_.reset(new MockControl()); |
| 43 | set_control_interface(mock_control_.get()); |
| 44 | } |
| 45 | if(dispatcher() == NULL) { |
| 46 | mock_dispatcher_.reset(new MockEventDispatcher()); |
| 47 | set_event_dispatcher(mock_dispatcher_.get()); |
| 48 | } |
| 49 | if(metrics() == NULL) { |
| 50 | mock_metrics_.reset(new MockMetrics(dispatcher())); |
| 51 | set_metrics(mock_metrics_.get()); |
| 52 | } |
| 53 | if(glib() == NULL) { |
| 54 | mock_glib_.reset(new MockGLib()); |
| 55 | set_glib(mock_glib_.get()); |
| 56 | } |
| 57 | if(manager() == NULL) { |
| 58 | mock_manager_.reset(new MockManager(control_interface(), dispatcher(), |
| 59 | metrics(), glib())); |
| 60 | set_manager(mock_manager_.get()); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | void MockModemInfo::SetProviderDB(const char *provider_db_path) { |
| 65 | mobile_provider_db *provider_db = |
| 66 | mobile_provider_open_db(provider_db_path); |
| 67 | ASSERT_TRUE(provider_db); |
| 68 | // Assumes ownership. |
| 69 | set_mobile_provider_db(provider_db); |
| 70 | } |
| 71 | |
Paul Stewart | 8c116a9 | 2012-05-02 18:30:03 -0700 | [diff] [blame] | 72 | } // namespace shill |