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