blob: 7c293cfb22bcc958d197d93bd64cd7c7298c25de [file] [log] [blame]
Lei YUf77189f2019-08-07 14:26:30 +08001#include "utils.hpp"
2
3#include <gmock/gmock.h>
4
5namespace utils
6{
7
8class MockedUtils : public UtilsInterface
9{
10 public:
George Liu66a54ad2024-08-23 13:53:39 +080011 MockedUtils() = default;
12 MockedUtils(const MockedUtils&) = delete;
13 MockedUtils& operator=(const MockedUtils&) = delete;
14 MockedUtils(MockedUtils&&) = delete;
15 MockedUtils& operator=(MockedUtils&&) = delete;
16
George Liu047d9942024-08-23 13:44:31 +080017 ~MockedUtils() override = default;
Lei YUf77189f2019-08-07 14:26:30 +080018
Shawn McCarneyd57bd2f2024-12-02 18:40:28 -060019 MOCK_CONST_METHOD1(getPSUInventoryPaths,
Patrick Williams374fae52022-07-22 19:26:55 -050020 std::vector<std::string>(sdbusplus::bus_t& bus));
Lei YUf77189f2019-08-07 14:26:30 +080021
22 MOCK_CONST_METHOD3(getService,
Patrick Williams374fae52022-07-22 19:26:55 -050023 std::string(sdbusplus::bus_t& bus, const char* path,
Lei YUf77189f2019-08-07 14:26:30 +080024 const char* interface));
25
Lei YUd0bbfa92019-09-11 16:10:54 +080026 MOCK_CONST_METHOD3(getServices,
Patrick Williams374fae52022-07-22 19:26:55 -050027 std::vector<std::string>(sdbusplus::bus_t& bus,
Lei YUd0bbfa92019-09-11 16:10:54 +080028 const char* path,
29 const char* interface));
30
Lei YUf77189f2019-08-07 14:26:30 +080031 MOCK_CONST_METHOD1(getVersionId, std::string(const std::string& version));
32
Lei YU5f3584d2019-08-27 16:28:53 +080033 MOCK_CONST_METHOD1(getVersion,
34 std::string(const std::string& psuInventoryPath));
35
Shawn McCarney783406e2024-11-17 21:49:37 -060036 MOCK_CONST_METHOD1(getModel,
37 std::string(const std::string& psuInventoryPath));
38
Lei YU65207482019-10-11 16:39:36 +080039 MOCK_CONST_METHOD1(getLatestVersion,
40 std::string(const std::set<std::string>& versions));
41
Lei YU4b9ac392019-10-12 11:02:26 +080042 MOCK_CONST_METHOD2(isAssociated, bool(const std::string& psuInventoryPath,
43 const AssociationList& assocs));
44
Lei YUf77189f2019-08-07 14:26:30 +080045 MOCK_CONST_METHOD5(getPropertyImpl,
Patrick Williams374fae52022-07-22 19:26:55 -050046 any(sdbusplus::bus_t& bus, const char* service,
Lei YUf77189f2019-08-07 14:26:30 +080047 const char* path, const char* interface,
48 const char* propertyName));
49};
50
Lei YUc09155b2019-10-11 17:30:48 +080051static std::unique_ptr<MockedUtils> utils;
Lei YUff83c2a2019-09-12 13:55:18 +080052inline const UtilsInterface& getUtils()
Lei YUf77189f2019-08-07 14:26:30 +080053{
Lei YUc09155b2019-10-11 17:30:48 +080054 if (!utils)
55 {
56 utils = std::make_unique<MockedUtils>();
57 }
58 return *utils;
59}
60
61inline void freeUtils()
62{
63 utils.reset();
Lei YUf77189f2019-08-07 14:26:30 +080064}
65
66} // namespace utils