Shawn McCarney | 8109502 | 2020-07-16 14:22:26 -0500 | [diff] [blame] | 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" |
Shawn McCarney | d58858c | 2020-11-04 18:28:01 -0600 | [diff] [blame] | 22 | #include "mock_presence_service.hpp" |
Shawn McCarney | 8279a11 | 2021-04-27 16:51:30 -0500 | [diff] [blame] | 23 | #include "mock_sensors.hpp" |
Shawn McCarney | 4e0402c | 2021-02-05 00:08:33 -0600 | [diff] [blame] | 24 | #include "mock_vpd.hpp" |
Shawn McCarney | d58858c | 2020-11-04 18:28:01 -0600 | [diff] [blame] | 25 | #include "presence_service.hpp" |
Shawn McCarney | 8279a11 | 2021-04-27 16:51:30 -0500 | [diff] [blame] | 26 | #include "sensors.hpp" |
Bob King | 23243f8 | 2020-07-29 10:38:57 +0800 | [diff] [blame] | 27 | #include "services.hpp" |
Shawn McCarney | 4e0402c | 2021-02-05 00:08:33 -0600 | [diff] [blame] | 28 | #include "vpd.hpp" |
Shawn McCarney | 8109502 | 2020-07-16 14:22:26 -0500 | [diff] [blame] | 29 | |
| 30 | #include <sdbusplus/bus.hpp> |
| 31 | |
| 32 | namespace phosphor::power::regulators |
| 33 | { |
| 34 | |
| 35 | /** |
| 36 | * @class MockServices |
| 37 | * |
| 38 | * Implementation of the Services interface using mock system services. |
| 39 | */ |
| 40 | class MockServices : public Services |
| 41 | { |
| 42 | public: |
| 43 | // Specify which compiler-generated methods we want |
| 44 | MockServices() = default; |
| 45 | MockServices(const MockServices&) = delete; |
| 46 | MockServices(MockServices&&) = delete; |
| 47 | MockServices& operator=(const MockServices&) = delete; |
| 48 | MockServices& operator=(MockServices&&) = delete; |
| 49 | virtual ~MockServices() = default; |
| 50 | |
| 51 | /** @copydoc Services::getBus() */ |
| 52 | virtual sdbusplus::bus::bus& getBus() override |
| 53 | { |
| 54 | return bus; |
| 55 | } |
| 56 | |
| 57 | /** @copydoc Services::getErrorLogging() */ |
| 58 | virtual ErrorLogging& getErrorLogging() override |
| 59 | { |
| 60 | return errorLogging; |
| 61 | } |
| 62 | |
| 63 | /** @copydoc Services::getJournal() */ |
| 64 | virtual Journal& getJournal() override |
| 65 | { |
| 66 | return journal; |
| 67 | } |
| 68 | |
Shawn McCarney | d58858c | 2020-11-04 18:28:01 -0600 | [diff] [blame] | 69 | /** @copydoc Services::getPresenceService() */ |
| 70 | virtual PresenceService& getPresenceService() override |
| 71 | { |
| 72 | return presenceService; |
| 73 | } |
| 74 | |
Shawn McCarney | 8279a11 | 2021-04-27 16:51:30 -0500 | [diff] [blame] | 75 | /** @copydoc Services::getSensors() */ |
| 76 | virtual Sensors& getSensors() override |
| 77 | { |
| 78 | return sensors; |
| 79 | } |
| 80 | |
Shawn McCarney | 4e0402c | 2021-02-05 00:08:33 -0600 | [diff] [blame] | 81 | /** @copydoc Services::getVPD() */ |
| 82 | virtual VPD& getVPD() override |
| 83 | { |
| 84 | return vpd; |
| 85 | } |
| 86 | |
Shawn McCarney | 8109502 | 2020-07-16 14:22:26 -0500 | [diff] [blame] | 87 | /** |
| 88 | * Returns the MockErrorLogging object that implements the ErrorLogging |
| 89 | * interface. |
| 90 | * |
| 91 | * This allows test cases to use the object in EXPECT_CALL() statements. |
| 92 | * |
| 93 | * @return mock error logging object |
| 94 | */ |
Bob King | 23243f8 | 2020-07-29 10:38:57 +0800 | [diff] [blame] | 95 | virtual MockErrorLogging& getMockErrorLogging() |
Shawn McCarney | 8109502 | 2020-07-16 14:22:26 -0500 | [diff] [blame] | 96 | { |
| 97 | return errorLogging; |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Returns the MockJournal object that implements the Journal interface. |
| 102 | * |
| 103 | * This allows test cases to use the object in EXPECT_CALL() statements. |
| 104 | * |
| 105 | * @return mock journal object |
| 106 | */ |
Bob King | 23243f8 | 2020-07-29 10:38:57 +0800 | [diff] [blame] | 107 | virtual MockJournal& getMockJournal() |
Shawn McCarney | 8109502 | 2020-07-16 14:22:26 -0500 | [diff] [blame] | 108 | { |
| 109 | return journal; |
| 110 | } |
| 111 | |
Shawn McCarney | d58858c | 2020-11-04 18:28:01 -0600 | [diff] [blame] | 112 | /** |
| 113 | * Returns the MockPresenceService object that implements the |
| 114 | * PresenceService interface. |
| 115 | * |
| 116 | * This allows test cases to use the object in EXPECT_CALL() statements. |
| 117 | * |
| 118 | * @return mock presence service object |
| 119 | */ |
| 120 | virtual MockPresenceService& getMockPresenceService() |
| 121 | { |
| 122 | return presenceService; |
| 123 | } |
| 124 | |
Shawn McCarney | 4e0402c | 2021-02-05 00:08:33 -0600 | [diff] [blame] | 125 | /** |
Shawn McCarney | 8279a11 | 2021-04-27 16:51:30 -0500 | [diff] [blame] | 126 | * Returns the MockSensors object that implements the Sensors interface. |
| 127 | * |
| 128 | * This allows test cases to use the object in EXPECT_CALL() statements. |
| 129 | * |
| 130 | * @return mock sensors interface object |
| 131 | */ |
| 132 | virtual MockSensors& getMockSensors() |
| 133 | { |
| 134 | return sensors; |
| 135 | } |
| 136 | |
| 137 | /** |
Shawn McCarney | 4e0402c | 2021-02-05 00:08:33 -0600 | [diff] [blame] | 138 | * Returns the MockVPD object that implements the VPD interface. |
| 139 | * |
| 140 | * This allows test cases to use the object in EXPECT_CALL() statements. |
| 141 | * |
| 142 | * @return mock VPD interface object |
| 143 | */ |
| 144 | virtual MockVPD& getMockVPD() |
| 145 | { |
| 146 | return vpd; |
| 147 | } |
| 148 | |
Shawn McCarney | 8109502 | 2020-07-16 14:22:26 -0500 | [diff] [blame] | 149 | private: |
| 150 | /** |
| 151 | * D-Bus bus object. |
| 152 | */ |
| 153 | sdbusplus::bus::bus bus{sdbusplus::bus::new_default()}; |
| 154 | |
| 155 | /** |
| 156 | * Mock implementation of the ErrorLogging interface. |
| 157 | */ |
| 158 | MockErrorLogging errorLogging{}; |
| 159 | |
| 160 | /** |
| 161 | * Mock implementation of the Journal interface. |
| 162 | */ |
| 163 | MockJournal journal{}; |
Shawn McCarney | d58858c | 2020-11-04 18:28:01 -0600 | [diff] [blame] | 164 | |
| 165 | /** |
| 166 | * Mock implementation of the PresenceService interface. |
| 167 | */ |
| 168 | MockPresenceService presenceService{}; |
Shawn McCarney | 4e0402c | 2021-02-05 00:08:33 -0600 | [diff] [blame] | 169 | |
| 170 | /** |
Shawn McCarney | 8279a11 | 2021-04-27 16:51:30 -0500 | [diff] [blame] | 171 | * Mock implementation of the Sensors interface. |
| 172 | */ |
| 173 | MockSensors sensors{}; |
| 174 | |
| 175 | /** |
Shawn McCarney | 4e0402c | 2021-02-05 00:08:33 -0600 | [diff] [blame] | 176 | * Mock implementation of the VPD interface. |
| 177 | */ |
| 178 | MockVPD vpd{}; |
Shawn McCarney | 8109502 | 2020-07-16 14:22:26 -0500 | [diff] [blame] | 179 | }; |
| 180 | |
| 181 | } // namespace phosphor::power::regulators |