Lei YU | ebd3d09 | 2020-09-27 18:11:48 +0800 | [diff] [blame^] | 1 | #include "sdbus_wrapper.hpp" |
| 2 | |
| 3 | #include <sdbusplus/test/sdbus_mock.hpp> |
| 4 | |
| 5 | #include <memory> |
| 6 | |
| 7 | // To support ipmid_get_sd_bus_connection, we have to make the sdbusMock global |
| 8 | static std::unique_ptr<sdbusplus::SdBusMock> sdbusMock; |
| 9 | static std::unique_ptr<sdbusplus::bus::bus> mockedBus; |
| 10 | |
| 11 | sdbusplus::bus::bus& getBus() |
| 12 | { |
| 13 | if (!sdbusMock) |
| 14 | { |
| 15 | sdbusMock = std::make_unique<sdbusplus::SdBusMock>(); |
| 16 | } |
| 17 | mockedBus = std::make_unique<sdbusplus::bus::bus>( |
| 18 | sdbusplus::get_mocked_new(sdbusMock.get())); |
| 19 | return *mockedBus.get(); |
| 20 | } |
| 21 | |
| 22 | void clearMockedBus() |
| 23 | { |
| 24 | sdbusMock.reset(); |
| 25 | mockedBus.reset(); |
| 26 | } |