blob: 075768c24e079b707e2400b5652563bbfb020107 [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"
Bob King23243f82020-07-29 10:38:57 +080022#include "services.hpp"
Shawn McCarney81095022020-07-16 14:22:26 -050023
24#include <sdbusplus/bus.hpp>
25
26namespace phosphor::power::regulators
27{
28
29/**
30 * @class MockServices
31 *
32 * Implementation of the Services interface using mock system services.
33 */
34class MockServices : public Services
35{
36 public:
37 // Specify which compiler-generated methods we want
38 MockServices() = default;
39 MockServices(const MockServices&) = delete;
40 MockServices(MockServices&&) = delete;
41 MockServices& operator=(const MockServices&) = delete;
42 MockServices& operator=(MockServices&&) = delete;
43 virtual ~MockServices() = default;
44
45 /** @copydoc Services::getBus() */
46 virtual sdbusplus::bus::bus& getBus() override
47 {
48 return bus;
49 }
50
51 /** @copydoc Services::getErrorLogging() */
52 virtual ErrorLogging& getErrorLogging() override
53 {
54 return errorLogging;
55 }
56
57 /** @copydoc Services::getJournal() */
58 virtual Journal& getJournal() override
59 {
60 return journal;
61 }
62
63 /**
64 * Returns the MockErrorLogging object that implements the ErrorLogging
65 * interface.
66 *
67 * This allows test cases to use the object in EXPECT_CALL() statements.
68 *
69 * @return mock error logging object
70 */
Bob King23243f82020-07-29 10:38:57 +080071 virtual MockErrorLogging& getMockErrorLogging()
Shawn McCarney81095022020-07-16 14:22:26 -050072 {
73 return errorLogging;
74 }
75
76 /**
77 * Returns the MockJournal object that implements the Journal interface.
78 *
79 * This allows test cases to use the object in EXPECT_CALL() statements.
80 *
81 * @return mock journal object
82 */
Bob King23243f82020-07-29 10:38:57 +080083 virtual MockJournal& getMockJournal()
Shawn McCarney81095022020-07-16 14:22:26 -050084 {
85 return journal;
86 }
87
88 private:
89 /**
90 * D-Bus bus object.
91 */
92 sdbusplus::bus::bus bus{sdbusplus::bus::new_default()};
93
94 /**
95 * Mock implementation of the ErrorLogging interface.
96 */
97 MockErrorLogging errorLogging{};
98
99 /**
100 * Mock implementation of the Journal interface.
101 */
102 MockJournal journal{};
103};
104
105} // namespace phosphor::power::regulators