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: |
George Liu | 66a54ad | 2024-08-23 13:53:39 +0800 | [diff] [blame] | 11 | MockedUtils() = default; |
| 12 | MockedUtils(const MockedUtils&) = delete; |
| 13 | MockedUtils& operator=(const MockedUtils&) = delete; |
| 14 | MockedUtils(MockedUtils&&) = delete; |
| 15 | MockedUtils& operator=(MockedUtils&&) = delete; |
| 16 | |
George Liu | 047d994 | 2024-08-23 13:44:31 +0800 | [diff] [blame] | 17 | ~MockedUtils() override = default; |
Lei YU | f77189f | 2019-08-07 14:26:30 +0800 | [diff] [blame] | 18 | |
Shawn McCarney | d57bd2f | 2024-12-02 18:40:28 -0600 | [diff] [blame] | 19 | MOCK_CONST_METHOD1(getPSUInventoryPaths, |
Patrick Williams | 374fae5 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 20 | std::vector<std::string>(sdbusplus::bus_t& bus)); |
Lei YU | f77189f | 2019-08-07 14:26:30 +0800 | [diff] [blame] | 21 | |
| 22 | MOCK_CONST_METHOD3(getService, |
Patrick Williams | 374fae5 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 23 | std::string(sdbusplus::bus_t& bus, const char* path, |
Lei YU | f77189f | 2019-08-07 14:26:30 +0800 | [diff] [blame] | 24 | const char* interface)); |
| 25 | |
Lei YU | d0bbfa9 | 2019-09-11 16:10:54 +0800 | [diff] [blame] | 26 | MOCK_CONST_METHOD3(getServices, |
Patrick Williams | 374fae5 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 27 | std::vector<std::string>(sdbusplus::bus_t& bus, |
Lei YU | d0bbfa9 | 2019-09-11 16:10:54 +0800 | [diff] [blame] | 28 | const char* path, |
| 29 | const char* interface)); |
| 30 | |
Lei YU | f77189f | 2019-08-07 14:26:30 +0800 | [diff] [blame] | 31 | MOCK_CONST_METHOD1(getVersionId, std::string(const std::string& version)); |
| 32 | |
Lei YU | 5f3584d | 2019-08-27 16:28:53 +0800 | [diff] [blame] | 33 | MOCK_CONST_METHOD1(getVersion, |
| 34 | std::string(const std::string& psuInventoryPath)); |
| 35 | |
Shawn McCarney | 783406e | 2024-11-17 21:49:37 -0600 | [diff] [blame] | 36 | MOCK_CONST_METHOD1(getModel, |
| 37 | std::string(const std::string& psuInventoryPath)); |
| 38 | |
Lei YU | 6520748 | 2019-10-11 16:39:36 +0800 | [diff] [blame] | 39 | MOCK_CONST_METHOD1(getLatestVersion, |
| 40 | std::string(const std::set<std::string>& versions)); |
| 41 | |
Lei YU | 4b9ac39 | 2019-10-12 11:02:26 +0800 | [diff] [blame] | 42 | MOCK_CONST_METHOD2(isAssociated, bool(const std::string& psuInventoryPath, |
| 43 | const AssociationList& assocs)); |
| 44 | |
Lei YU | f77189f | 2019-08-07 14:26:30 +0800 | [diff] [blame] | 45 | MOCK_CONST_METHOD5(getPropertyImpl, |
Patrick Williams | 374fae5 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 46 | any(sdbusplus::bus_t& bus, const char* service, |
Lei YU | f77189f | 2019-08-07 14:26:30 +0800 | [diff] [blame] | 47 | const char* path, const char* interface, |
| 48 | const char* propertyName)); |
| 49 | }; |
| 50 | |
Lei YU | c09155b | 2019-10-11 17:30:48 +0800 | [diff] [blame] | 51 | static std::unique_ptr<MockedUtils> utils; |
Lei YU | ff83c2a | 2019-09-12 13:55:18 +0800 | [diff] [blame] | 52 | inline const UtilsInterface& getUtils() |
Lei YU | f77189f | 2019-08-07 14:26:30 +0800 | [diff] [blame] | 53 | { |
Lei YU | c09155b | 2019-10-11 17:30:48 +0800 | [diff] [blame] | 54 | if (!utils) |
| 55 | { |
| 56 | utils = std::make_unique<MockedUtils>(); |
| 57 | } |
| 58 | return *utils; |
| 59 | } |
| 60 | |
| 61 | inline void freeUtils() |
| 62 | { |
| 63 | utils.reset(); |
Lei YU | f77189f | 2019-08-07 14:26:30 +0800 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | } // namespace utils |