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_sensors.hpp" 24 #include "mock_vpd.hpp" 25 #include "presence_service.hpp" 26 #include "sensors.hpp" 27 #include "services.hpp" 28 #include "vpd.hpp" 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_t& 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 69 /** @copydoc Services::getPresenceService() */ 70 virtual PresenceService& getPresenceService() override 71 { 72 return presenceService; 73 } 74 75 /** @copydoc Services::getSensors() */ 76 virtual Sensors& getSensors() override 77 { 78 return sensors; 79 } 80 81 /** @copydoc Services::getVPD() */ 82 virtual VPD& getVPD() override 83 { 84 return vpd; 85 } 86 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 */ 95 virtual MockErrorLogging& getMockErrorLogging() 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 */ 107 virtual MockJournal& getMockJournal() 108 { 109 return journal; 110 } 111 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 125 /** 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 /** 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 149 private: 150 /** 151 * D-Bus bus object. 152 */ 153 sdbusplus::bus_t 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{}; 164 165 /** 166 * Mock implementation of the PresenceService interface. 167 */ 168 MockPresenceService presenceService{}; 169 170 /** 171 * Mock implementation of the Sensors interface. 172 */ 173 MockSensors sensors{}; 174 175 /** 176 * Mock implementation of the VPD interface. 177 */ 178 MockVPD vpd{}; 179 }; 180 181 } // namespace phosphor::power::regulators 182