blob: 8e3a100d87c8b98978e9699353b4787a123f7135 [file] [log] [blame]
Shawn McCarney81095022020-07-16 14:22:26 -05001/**
2 * Copyright © 2020 IBM Corporation
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#pragma once
17
18#include "error_logging.hpp"
19#include "journal.hpp"
20#include "mock_error_logging.hpp"
21#include "mock_journal.hpp"
Shawn McCarneyd58858c2020-11-04 18:28:01 -060022#include "mock_presence_service.hpp"
Shawn McCarney8279a112021-04-27 16:51:30 -050023#include "mock_sensors.hpp"
Shawn McCarney4e0402c2021-02-05 00:08:33 -060024#include "mock_vpd.hpp"
Shawn McCarneyd58858c2020-11-04 18:28:01 -060025#include "presence_service.hpp"
Shawn McCarney8279a112021-04-27 16:51:30 -050026#include "sensors.hpp"
Bob King23243f82020-07-29 10:38:57 +080027#include "services.hpp"
Shawn McCarney4e0402c2021-02-05 00:08:33 -060028#include "vpd.hpp"
Shawn McCarney81095022020-07-16 14:22:26 -050029
30#include <sdbusplus/bus.hpp>
31
32namespace phosphor::power::regulators
33{
34
35/**
36 * @class MockServices
37 *
38 * Implementation of the Services interface using mock system services.
39 */
40class MockServices : public Services
41{
42 public:
43 // Specify which compiler-generated methods we want
44 MockServices() = default;
45 MockServices(const MockServices&) = delete;
46 MockServices(MockServices&&) = delete;
47 MockServices& operator=(const MockServices&) = delete;
48 MockServices& operator=(MockServices&&) = delete;
49 virtual ~MockServices() = default;
50
51 /** @copydoc Services::getBus() */
52 virtual sdbusplus::bus::bus& getBus() override
53 {
54 return bus;
55 }
56
57 /** @copydoc Services::getErrorLogging() */
58 virtual ErrorLogging& getErrorLogging() override
59 {
60 return errorLogging;
61 }
62
63 /** @copydoc Services::getJournal() */
64 virtual Journal& getJournal() override
65 {
66 return journal;
67 }
68
Shawn McCarneyd58858c2020-11-04 18:28:01 -060069 /** @copydoc Services::getPresenceService() */
70 virtual PresenceService& getPresenceService() override
71 {
72 return presenceService;
73 }
74
Shawn McCarney8279a112021-04-27 16:51:30 -050075 /** @copydoc Services::getSensors() */
76 virtual Sensors& getSensors() override
77 {
78 return sensors;
79 }
80
Shawn McCarney4e0402c2021-02-05 00:08:33 -060081 /** @copydoc Services::getVPD() */
82 virtual VPD& getVPD() override
83 {
84 return vpd;
85 }
86
Shawn McCarney81095022020-07-16 14:22:26 -050087 /**
88 * Returns the MockErrorLogging object that implements the ErrorLogging
89 * interface.
90 *
91 * This allows test cases to use the object in EXPECT_CALL() statements.
92 *
93 * @return mock error logging object
94 */
Bob King23243f82020-07-29 10:38:57 +080095 virtual MockErrorLogging& getMockErrorLogging()
Shawn McCarney81095022020-07-16 14:22:26 -050096 {
97 return errorLogging;
98 }
99
100 /**
101 * Returns the MockJournal object that implements the Journal interface.
102 *
103 * This allows test cases to use the object in EXPECT_CALL() statements.
104 *
105 * @return mock journal object
106 */
Bob King23243f82020-07-29 10:38:57 +0800107 virtual MockJournal& getMockJournal()
Shawn McCarney81095022020-07-16 14:22:26 -0500108 {
109 return journal;
110 }
111
Shawn McCarneyd58858c2020-11-04 18:28:01 -0600112 /**
113 * Returns the MockPresenceService object that implements the
114 * PresenceService interface.
115 *
116 * This allows test cases to use the object in EXPECT_CALL() statements.
117 *
118 * @return mock presence service object
119 */
120 virtual MockPresenceService& getMockPresenceService()
121 {
122 return presenceService;
123 }
124
Shawn McCarney4e0402c2021-02-05 00:08:33 -0600125 /**
Shawn McCarney8279a112021-04-27 16:51:30 -0500126 * Returns the MockSensors object that implements the Sensors interface.
127 *
128 * This allows test cases to use the object in EXPECT_CALL() statements.
129 *
130 * @return mock sensors interface object
131 */
132 virtual MockSensors& getMockSensors()
133 {
134 return sensors;
135 }
136
137 /**
Shawn McCarney4e0402c2021-02-05 00:08:33 -0600138 * Returns the MockVPD object that implements the VPD interface.
139 *
140 * This allows test cases to use the object in EXPECT_CALL() statements.
141 *
142 * @return mock VPD interface object
143 */
144 virtual MockVPD& getMockVPD()
145 {
146 return vpd;
147 }
148
Shawn McCarney81095022020-07-16 14:22:26 -0500149 private:
150 /**
151 * D-Bus bus object.
152 */
153 sdbusplus::bus::bus bus{sdbusplus::bus::new_default()};
154
155 /**
156 * Mock implementation of the ErrorLogging interface.
157 */
158 MockErrorLogging errorLogging{};
159
160 /**
161 * Mock implementation of the Journal interface.
162 */
163 MockJournal journal{};
Shawn McCarneyd58858c2020-11-04 18:28:01 -0600164
165 /**
166 * Mock implementation of the PresenceService interface.
167 */
168 MockPresenceService presenceService{};
Shawn McCarney4e0402c2021-02-05 00:08:33 -0600169
170 /**
Shawn McCarney8279a112021-04-27 16:51:30 -0500171 * Mock implementation of the Sensors interface.
172 */
173 MockSensors sensors{};
174
175 /**
Shawn McCarney4e0402c2021-02-05 00:08:33 -0600176 * Mock implementation of the VPD interface.
177 */
178 MockVPD vpd{};
Shawn McCarney81095022020-07-16 14:22:26 -0500179};
180
181} // namespace phosphor::power::regulators