Lei YU | f77189f | 2019-08-07 14:26:30 +0800 | [diff] [blame] | 1 | #include "utils.hpp" |
| 2 | |
| 3 | #include <gmock/gmock.h> |
| 4 | |
| 5 | namespace utils |
| 6 | { |
| 7 | |
| 8 | class MockedUtils : public UtilsInterface |
| 9 | { |
| 10 | public: |
| 11 | virtual ~MockedUtils() = default; |
| 12 | |
| 13 | MOCK_CONST_METHOD1(getPSUInventoryPath, |
Patrick Williams | 374fae5 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 14 | std::vector<std::string>(sdbusplus::bus_t& bus)); |
Lei YU | f77189f | 2019-08-07 14:26:30 +0800 | [diff] [blame] | 15 | |
| 16 | MOCK_CONST_METHOD3(getService, |
Patrick Williams | 374fae5 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 17 | std::string(sdbusplus::bus_t& bus, const char* path, |
Lei YU | f77189f | 2019-08-07 14:26:30 +0800 | [diff] [blame] | 18 | const char* interface)); |
| 19 | |
Lei YU | d0bbfa9 | 2019-09-11 16:10:54 +0800 | [diff] [blame] | 20 | MOCK_CONST_METHOD3(getServices, |
Patrick Williams | 374fae5 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 21 | std::vector<std::string>(sdbusplus::bus_t& bus, |
Lei YU | d0bbfa9 | 2019-09-11 16:10:54 +0800 | [diff] [blame] | 22 | const char* path, |
| 23 | const char* interface)); |
| 24 | |
Lei YU | f77189f | 2019-08-07 14:26:30 +0800 | [diff] [blame] | 25 | MOCK_CONST_METHOD1(getVersionId, std::string(const std::string& version)); |
| 26 | |
Lei YU | 5f3584d | 2019-08-27 16:28:53 +0800 | [diff] [blame] | 27 | MOCK_CONST_METHOD1(getVersion, |
| 28 | std::string(const std::string& psuInventoryPath)); |
| 29 | |
Lei YU | 6520748 | 2019-10-11 16:39:36 +0800 | [diff] [blame] | 30 | MOCK_CONST_METHOD1(getLatestVersion, |
| 31 | std::string(const std::set<std::string>& versions)); |
| 32 | |
Lei YU | 4b9ac39 | 2019-10-12 11:02:26 +0800 | [diff] [blame] | 33 | MOCK_CONST_METHOD2(isAssociated, bool(const std::string& psuInventoryPath, |
| 34 | const AssociationList& assocs)); |
| 35 | |
Lei YU | f77189f | 2019-08-07 14:26:30 +0800 | [diff] [blame] | 36 | MOCK_CONST_METHOD5(getPropertyImpl, |
Patrick Williams | 374fae5 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 37 | any(sdbusplus::bus_t& bus, const char* service, |
Lei YU | f77189f | 2019-08-07 14:26:30 +0800 | [diff] [blame] | 38 | const char* path, const char* interface, |
| 39 | const char* propertyName)); |
| 40 | }; |
| 41 | |
Lei YU | c09155b | 2019-10-11 17:30:48 +0800 | [diff] [blame] | 42 | static std::unique_ptr<MockedUtils> utils; |
Lei YU | ff83c2a | 2019-09-12 13:55:18 +0800 | [diff] [blame] | 43 | inline const UtilsInterface& getUtils() |
Lei YU | f77189f | 2019-08-07 14:26:30 +0800 | [diff] [blame] | 44 | { |
Lei YU | c09155b | 2019-10-11 17:30:48 +0800 | [diff] [blame] | 45 | if (!utils) |
| 46 | { |
| 47 | utils = std::make_unique<MockedUtils>(); |
| 48 | } |
| 49 | return *utils; |
| 50 | } |
| 51 | |
| 52 | inline void freeUtils() |
| 53 | { |
| 54 | utils.reset(); |
Lei YU | f77189f | 2019-08-07 14:26:30 +0800 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | } // namespace utils |