blob: b121e131cf8e8696eb3ca60af711fa32fce05122 [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 McCarney4e0402c2021-02-05 00:08:33 -060023#include "mock_vpd.hpp"
Shawn McCarneyd58858c2020-11-04 18:28:01 -060024#include "presence_service.hpp"
Bob King23243f82020-07-29 10:38:57 +080025#include "services.hpp"
Shawn McCarney4e0402c2021-02-05 00:08:33 -060026#include "vpd.hpp"
Shawn McCarney81095022020-07-16 14:22:26 -050027
28#include <sdbusplus/bus.hpp>
29
30namespace phosphor::power::regulators
31{
32
33/**
34 * @class MockServices
35 *
36 * Implementation of the Services interface using mock system services.
37 */
38class MockServices : public Services
39{
40 public:
41 // Specify which compiler-generated methods we want
42 MockServices() = default;
43 MockServices(const MockServices&) = delete;
44 MockServices(MockServices&&) = delete;
45 MockServices& operator=(const MockServices&) = delete;
46 MockServices& operator=(MockServices&&) = delete;
47 virtual ~MockServices() = default;
48
49 /** @copydoc Services::getBus() */
50 virtual sdbusplus::bus::bus& getBus() override
51 {
52 return bus;
53 }
54
55 /** @copydoc Services::getErrorLogging() */
56 virtual ErrorLogging& getErrorLogging() override
57 {
58 return errorLogging;
59 }
60
61 /** @copydoc Services::getJournal() */
62 virtual Journal& getJournal() override
63 {
64 return journal;
65 }
66
Shawn McCarneyd58858c2020-11-04 18:28:01 -060067 /** @copydoc Services::getPresenceService() */
68 virtual PresenceService& getPresenceService() override
69 {
70 return presenceService;
71 }
72
Shawn McCarney4e0402c2021-02-05 00:08:33 -060073 /** @copydoc Services::getVPD() */
74 virtual VPD& getVPD() override
75 {
76 return vpd;
77 }
78
Shawn McCarney81095022020-07-16 14:22:26 -050079 /**
80 * Returns the MockErrorLogging object that implements the ErrorLogging
81 * interface.
82 *
83 * This allows test cases to use the object in EXPECT_CALL() statements.
84 *
85 * @return mock error logging object
86 */
Bob King23243f82020-07-29 10:38:57 +080087 virtual MockErrorLogging& getMockErrorLogging()
Shawn McCarney81095022020-07-16 14:22:26 -050088 {
89 return errorLogging;
90 }
91
92 /**
93 * Returns the MockJournal object that implements the Journal interface.
94 *
95 * This allows test cases to use the object in EXPECT_CALL() statements.
96 *
97 * @return mock journal object
98 */
Bob King23243f82020-07-29 10:38:57 +080099 virtual MockJournal& getMockJournal()
Shawn McCarney81095022020-07-16 14:22:26 -0500100 {
101 return journal;
102 }
103
Shawn McCarneyd58858c2020-11-04 18:28:01 -0600104 /**
105 * Returns the MockPresenceService object that implements the
106 * PresenceService interface.
107 *
108 * This allows test cases to use the object in EXPECT_CALL() statements.
109 *
110 * @return mock presence service object
111 */
112 virtual MockPresenceService& getMockPresenceService()
113 {
114 return presenceService;
115 }
116
Shawn McCarney4e0402c2021-02-05 00:08:33 -0600117 /**
118 * Returns the MockVPD object that implements the VPD interface.
119 *
120 * This allows test cases to use the object in EXPECT_CALL() statements.
121 *
122 * @return mock VPD interface object
123 */
124 virtual MockVPD& getMockVPD()
125 {
126 return vpd;
127 }
128
Shawn McCarney81095022020-07-16 14:22:26 -0500129 private:
130 /**
131 * D-Bus bus object.
132 */
133 sdbusplus::bus::bus bus{sdbusplus::bus::new_default()};
134
135 /**
136 * Mock implementation of the ErrorLogging interface.
137 */
138 MockErrorLogging errorLogging{};
139
140 /**
141 * Mock implementation of the Journal interface.
142 */
143 MockJournal journal{};
Shawn McCarneyd58858c2020-11-04 18:28:01 -0600144
145 /**
146 * Mock implementation of the PresenceService interface.
147 */
148 MockPresenceService presenceService{};
Shawn McCarney4e0402c2021-02-05 00:08:33 -0600149
150 /**
151 * Mock implementation of the VPD interface.
152 */
153 MockVPD vpd{};
Shawn McCarney81095022020-07-16 14:22:26 -0500154};
155
156} // namespace phosphor::power::regulators