blob: beb6eb88c3249445e2b88532a51d40d5f38e2cd2 [file] [log] [blame]
Paul Stewart8c116a92012-05-02 18:30:03 -07001// 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 Prabhu27526f12013-03-25 19:42:18 -07007#include <mobile_provider.h>
8
Paul Stewart8c116a92012-05-02 18:30:03 -07009namespace shill {
10
Prathmesh Prabhu27526f12013-03-25 19:42:18 -070011MockModemInfo::MockModemInfo() :
12 ModemInfo(NULL, NULL, NULL, NULL, NULL),
Arman Uguray41cc6342013-03-29 16:34:39 -070013 mock_pending_activation_store_(NULL),
Prathmesh Prabhu27526f12013-03-25 19:42:18 -070014 mock_cellular_operator_info_(NULL) {}
15
16MockModemInfo::MockModemInfo(ControlInterface *control,
17 EventDispatcher *dispatcher,
18 Metrics *metrics,
19 Manager *manager,
20 GLib *glib) :
21 ModemInfo(control, dispatcher, metrics, manager, glib),
Arman Uguray41cc6342013-03-29 16:34:39 -070022 mock_pending_activation_store_(NULL),
Prathmesh Prabhu27526f12013-03-25 19:42:18 -070023 mock_cellular_operator_info_(NULL) {
24 SetMockMembers();
25}
Paul Stewart8c116a92012-05-02 18:30:03 -070026
27MockModemInfo::~MockModemInfo() {}
28
Prathmesh Prabhu27526f12013-03-25 19:42:18 -070029void MockModemInfo::SetMockMembers() {
30 // These are always replaced by mocks.
31 // Assumes ownership.
Arman Uguray41cc6342013-03-29 16:34:39 -070032 set_pending_activation_store(new MockPendingActivationStore());
33 mock_pending_activation_store_ =
34 static_cast<MockPendingActivationStore*>(pending_activation_store());
Prathmesh Prabhu27526f12013-03-25 19:42:18 -070035 // 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
64void 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 Stewart8c116a92012-05-02 18:30:03 -070072} // namespace shill