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/mock_modem_info.h"
18
19 namespace shill {
20
MockModemInfo()21 MockModemInfo::MockModemInfo() :
22 ModemInfo(nullptr, nullptr, nullptr, nullptr),
23 mock_pending_activation_store_(nullptr) {}
24
MockModemInfo(ControlInterface * control,EventDispatcher * dispatcher,Metrics * metrics,Manager * manager)25 MockModemInfo::MockModemInfo(ControlInterface* control,
26 EventDispatcher* dispatcher,
27 Metrics* metrics,
28 Manager* manager)
29 : ModemInfo(control, dispatcher, metrics, manager),
30 mock_pending_activation_store_(nullptr) {
31 SetMockMembers();
32 }
33
~MockModemInfo()34 MockModemInfo::~MockModemInfo() {}
35
SetMockMembers()36 void MockModemInfo::SetMockMembers() {
37 // These are always replaced by mocks.
38 // Assumes ownership.
39 set_pending_activation_store(new MockPendingActivationStore());
40 mock_pending_activation_store_ =
41 static_cast<MockPendingActivationStore*>(pending_activation_store());
42 // These are replaced by mocks only if current unset in ModemInfo.
43 if (control_interface() == nullptr) {
44 mock_control_.reset(new MockControl());
45 set_control_interface(mock_control_.get());
46 }
47 if (dispatcher() == nullptr) {
48 mock_dispatcher_.reset(new MockEventDispatcher());
49 set_event_dispatcher(mock_dispatcher_.get());
50 }
51 if (metrics() == nullptr) {
52 mock_metrics_.reset(new MockMetrics(dispatcher()));
53 set_metrics(mock_metrics_.get());
54 }
55 if (manager() == nullptr) {
56 mock_manager_.reset(new MockManager(control_interface(), dispatcher(),
57 metrics()));
58 set_manager(mock_manager_.get());
59 }
60 }
61
62 } // namespace shill
63