blob: 1ef7192aace02038db976a6e088dbb7fb3b2ba42 [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"
23#include "presence_service.hpp"
Bob King23243f82020-07-29 10:38:57 +080024#include "services.hpp"
Shawn McCarney81095022020-07-16 14:22:26 -050025
26#include <sdbusplus/bus.hpp>
27
28namespace phosphor::power::regulators
29{
30
31/**
32 * @class MockServices
33 *
34 * Implementation of the Services interface using mock system services.
35 */
36class MockServices : public Services
37{
38 public:
39 // Specify which compiler-generated methods we want
40 MockServices() = default;
41 MockServices(const MockServices&) = delete;
42 MockServices(MockServices&&) = delete;
43 MockServices& operator=(const MockServices&) = delete;
44 MockServices& operator=(MockServices&&) = delete;
45 virtual ~MockServices() = default;
46
47 /** @copydoc Services::getBus() */
48 virtual sdbusplus::bus::bus& getBus() override
49 {
50 return bus;
51 }
52
53 /** @copydoc Services::getErrorLogging() */
54 virtual ErrorLogging& getErrorLogging() override
55 {
56 return errorLogging;
57 }
58
59 /** @copydoc Services::getJournal() */
60 virtual Journal& getJournal() override
61 {
62 return journal;
63 }
64
Shawn McCarneyd58858c2020-11-04 18:28:01 -060065 /** @copydoc Services::getPresenceService() */
66 virtual PresenceService& getPresenceService() override
67 {
68 return presenceService;
69 }
70
Shawn McCarney81095022020-07-16 14:22:26 -050071 /**
72 * Returns the MockErrorLogging object that implements the ErrorLogging
73 * interface.
74 *
75 * This allows test cases to use the object in EXPECT_CALL() statements.
76 *
77 * @return mock error logging object
78 */
Bob King23243f82020-07-29 10:38:57 +080079 virtual MockErrorLogging& getMockErrorLogging()
Shawn McCarney81095022020-07-16 14:22:26 -050080 {
81 return errorLogging;
82 }
83
84 /**
85 * Returns the MockJournal object that implements the Journal interface.
86 *
87 * This allows test cases to use the object in EXPECT_CALL() statements.
88 *
89 * @return mock journal object
90 */
Bob King23243f82020-07-29 10:38:57 +080091 virtual MockJournal& getMockJournal()
Shawn McCarney81095022020-07-16 14:22:26 -050092 {
93 return journal;
94 }
95
Shawn McCarneyd58858c2020-11-04 18:28:01 -060096 /**
97 * Returns the MockPresenceService object that implements the
98 * PresenceService interface.
99 *
100 * This allows test cases to use the object in EXPECT_CALL() statements.
101 *
102 * @return mock presence service object
103 */
104 virtual MockPresenceService& getMockPresenceService()
105 {
106 return presenceService;
107 }
108
Shawn McCarney81095022020-07-16 14:22:26 -0500109 private:
110 /**
111 * D-Bus bus object.
112 */
113 sdbusplus::bus::bus bus{sdbusplus::bus::new_default()};
114
115 /**
116 * Mock implementation of the ErrorLogging interface.
117 */
118 MockErrorLogging errorLogging{};
119
120 /**
121 * Mock implementation of the Journal interface.
122 */
123 MockJournal journal{};
Shawn McCarneyd58858c2020-11-04 18:28:01 -0600124
125 /**
126 * Mock implementation of the PresenceService interface.
127 */
128 MockPresenceService presenceService{};
Shawn McCarney81095022020-07-16 14:22:26 -0500129};
130
131} // namespace phosphor::power::regulators