Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame^] | 1 | #pragma once |
| 2 | |
| 3 | #include "interfaces/trigger_factory.hpp" |
| 4 | #include "mocks/trigger_mock.hpp" |
| 5 | #include "params/trigger_params.hpp" |
| 6 | |
| 7 | #include <gmock/gmock.h> |
| 8 | |
| 9 | class TriggerFactoryMock : public interfaces::TriggerFactory |
| 10 | { |
| 11 | public: |
| 12 | TriggerFactoryMock() |
| 13 | { |
| 14 | using namespace testing; |
| 15 | |
| 16 | ON_CALL(*this, make(_, _, _, _, _, _, _, _, _)) |
| 17 | .WillByDefault(WithArgs<0>(Invoke([](const std::string& name) { |
| 18 | return std::make_unique<NiceMock<TriggerMock>>(name); |
| 19 | }))); |
| 20 | } |
| 21 | |
| 22 | MOCK_METHOD(std::unique_ptr<interfaces::Trigger>, make, |
| 23 | (const std::string& name, bool isDiscrete, bool logToJournal, |
| 24 | bool logToRedfish, bool updateReport, |
| 25 | (const std::vector<std::pair<sdbusplus::message::object_path, |
| 26 | std::string>>& sensors), |
| 27 | const std::vector<std::string>& reportNames, |
| 28 | const TriggerThresholdParams& thresholds, |
| 29 | interfaces::TriggerManager& triggerManager), |
| 30 | (const, override)); |
| 31 | |
| 32 | auto& expectMake( |
| 33 | std::optional<std::reference_wrapper<const TriggerParams>> paramsOpt, |
| 34 | const testing::Matcher<interfaces::TriggerManager&>& tm) |
| 35 | { |
| 36 | if (paramsOpt) |
| 37 | { |
| 38 | const TriggerParams& params = *paramsOpt; |
| 39 | return EXPECT_CALL( |
| 40 | *this, make(params.name(), params.isDiscrete(), |
| 41 | params.logToJournal(), params.logToRedfish(), |
| 42 | params.updateReport(), params.sensors(), |
| 43 | params.reportNames(), params.thresholds(), tm)); |
| 44 | } |
| 45 | else |
| 46 | { |
| 47 | using testing::_; |
| 48 | return EXPECT_CALL(*this, make(_, _, _, _, _, _, _, _, tm)); |
| 49 | } |
| 50 | } |
| 51 | }; |