xref: /openbmc/phosphor-psu-code-mgmt/test/mocked_utils.hpp (revision d57bd2f2b15738da1a38e3caaa193a7cc713adca)
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     MockedUtils() = default;
12     MockedUtils(const MockedUtils&) = delete;
13     MockedUtils& operator=(const MockedUtils&) = delete;
14     MockedUtils(MockedUtils&&) = delete;
15     MockedUtils& operator=(MockedUtils&&) = delete;
16 
17     ~MockedUtils() override = default;
18 
19     MOCK_CONST_METHOD1(getPSUInventoryPaths,
20                        std::vector<std::string>(sdbusplus::bus_t& bus));
21 
22     MOCK_CONST_METHOD3(getService,
23                        std::string(sdbusplus::bus_t& bus, const char* path,
24                                    const char* interface));
25 
26     MOCK_CONST_METHOD3(getServices,
27                        std::vector<std::string>(sdbusplus::bus_t& bus,
28                                                 const char* path,
29                                                 const char* interface));
30 
31     MOCK_CONST_METHOD1(getVersionId, std::string(const std::string& version));
32 
33     MOCK_CONST_METHOD1(getVersion,
34                        std::string(const std::string& psuInventoryPath));
35 
36     MOCK_CONST_METHOD1(getModel,
37                        std::string(const std::string& psuInventoryPath));
38 
39     MOCK_CONST_METHOD1(getLatestVersion,
40                        std::string(const std::set<std::string>& versions));
41 
42     MOCK_CONST_METHOD2(isAssociated, bool(const std::string& psuInventoryPath,
43                                           const AssociationList& assocs));
44 
45     MOCK_CONST_METHOD5(getPropertyImpl,
46                        any(sdbusplus::bus_t& bus, const char* service,
47                            const char* path, const char* interface,
48                            const char* propertyName));
49 };
50 
51 static std::unique_ptr<MockedUtils> utils;
getUtils()52 inline const UtilsInterface& getUtils()
53 {
54     if (!utils)
55     {
56         utils = std::make_unique<MockedUtils>();
57     }
58     return *utils;
59 }
60 
freeUtils()61 inline void freeUtils()
62 {
63     utils.reset();
64 }
65 
66 } // namespace utils
67