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 "presence_service.hpp"
24 #include "services.hpp"
25 
26 #include <sdbusplus/bus.hpp>
27 
28 namespace phosphor::power::regulators
29 {
30 
31 /**
32  * @class MockServices
33  *
34  * Implementation of the Services interface using mock system services.
35  */
36 class 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 
65     /** @copydoc Services::getPresenceService() */
66     virtual PresenceService& getPresenceService() override
67     {
68         return presenceService;
69     }
70 
71     /**
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      */
79     virtual MockErrorLogging& getMockErrorLogging()
80     {
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      */
91     virtual MockJournal& getMockJournal()
92     {
93         return journal;
94     }
95 
96     /**
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 
109   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{};
124 
125     /**
126      * Mock implementation of the PresenceService interface.
127      */
128     MockPresenceService presenceService{};
129 };
130 
131 } // namespace phosphor::power::regulators
132