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 | 4e0402c | 2021-02-05 00:08:33 -0600 | [diff] [blame] | 23 | #include "mock_vpd.hpp" |
Shawn McCarney | d58858c | 2020-11-04 18:28:01 -0600 | [diff] [blame] | 24 | #include "presence_service.hpp" |
Bob King | 23243f8 | 2020-07-29 10:38:57 +0800 | [diff] [blame] | 25 | #include "services.hpp" |
Shawn McCarney | 4e0402c | 2021-02-05 00:08:33 -0600 | [diff] [blame] | 26 | #include "vpd.hpp" |
Shawn McCarney | 8109502 | 2020-07-16 14:22:26 -0500 | [diff] [blame] | 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 | |
Shawn McCarney | d58858c | 2020-11-04 18:28:01 -0600 | [diff] [blame] | 67 | /** @copydoc Services::getPresenceService() */ |
| 68 | virtual PresenceService& getPresenceService() override |
| 69 | { |
| 70 | return presenceService; |
| 71 | } |
| 72 | |
Shawn McCarney | 4e0402c | 2021-02-05 00:08:33 -0600 | [diff] [blame] | 73 | /** @copydoc Services::getVPD() */ |
| 74 | virtual VPD& getVPD() override |
| 75 | { |
| 76 | return vpd; |
| 77 | } |
| 78 | |
Shawn McCarney | 8109502 | 2020-07-16 14:22:26 -0500 | [diff] [blame] | 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 | */ |
Bob King | 23243f8 | 2020-07-29 10:38:57 +0800 | [diff] [blame] | 87 | virtual MockErrorLogging& getMockErrorLogging() |
Shawn McCarney | 8109502 | 2020-07-16 14:22:26 -0500 | [diff] [blame] | 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 | */ |
Bob King | 23243f8 | 2020-07-29 10:38:57 +0800 | [diff] [blame] | 99 | virtual MockJournal& getMockJournal() |
Shawn McCarney | 8109502 | 2020-07-16 14:22:26 -0500 | [diff] [blame] | 100 | { |
| 101 | return journal; |
| 102 | } |
| 103 | |
Shawn McCarney | d58858c | 2020-11-04 18:28:01 -0600 | [diff] [blame] | 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 | |
Shawn McCarney | 4e0402c | 2021-02-05 00:08:33 -0600 | [diff] [blame] | 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 | |
Shawn McCarney | 8109502 | 2020-07-16 14:22:26 -0500 | [diff] [blame] | 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{}; |
Shawn McCarney | d58858c | 2020-11-04 18:28:01 -0600 | [diff] [blame] | 144 | |
| 145 | /** |
| 146 | * Mock implementation of the PresenceService interface. |
| 147 | */ |
| 148 | MockPresenceService presenceService{}; |
Shawn McCarney | 4e0402c | 2021-02-05 00:08:33 -0600 | [diff] [blame] | 149 | |
| 150 | /** |
| 151 | * Mock implementation of the VPD interface. |
| 152 | */ |
| 153 | MockVPD vpd{}; |
Shawn McCarney | 8109502 | 2020-07-16 14:22:26 -0500 | [diff] [blame] | 154 | }; |
| 155 | |
| 156 | } // namespace phosphor::power::regulators |