1 /**
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"
22 #include "mock_presence_service.hpp"
23 #include "mock_vpd.hpp"
24 #include "presence_service.hpp"
25 #include "services.hpp"
26 #include "vpd.hpp"
27 
28 #include <sdbusplus/bus.hpp>
29 
30 namespace phosphor::power::regulators
31 {
32 
33 /**
34  * @class MockServices
35  *
36  * Implementation of the Services interface using mock system services.
37  */
38 class 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 
67     /** @copydoc Services::getPresenceService() */
68     virtual PresenceService& getPresenceService() override
69     {
70         return presenceService;
71     }
72 
73     /** @copydoc Services::getVPD() */
74     virtual VPD& getVPD() override
75     {
76         return vpd;
77     }
78 
79     /**
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      */
87     virtual MockErrorLogging& getMockErrorLogging()
88     {
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      */
99     virtual MockJournal& getMockJournal()
100     {
101         return journal;
102     }
103 
104     /**
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 
117     /**
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 
129   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{};
144 
145     /**
146      * Mock implementation of the PresenceService interface.
147      */
148     MockPresenceService presenceService{};
149 
150     /**
151      * Mock implementation of the VPD interface.
152      */
153     MockVPD vpd{};
154 };
155 
156 } // namespace phosphor::power::regulators
157