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" |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 6 | #include "trigger.hpp" |
| 7 | #include "utils/conversion_trigger.hpp" |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 8 | |
| 9 | #include <gmock/gmock.h> |
| 10 | |
| 11 | class TriggerFactoryMock : public interfaces::TriggerFactory |
| 12 | { |
| 13 | public: |
| 14 | TriggerFactoryMock() |
| 15 | { |
| 16 | using namespace testing; |
| 17 | |
Szymon Dompke | e28aa53 | 2021-10-27 12:33:12 +0200 | [diff] [blame] | 18 | ON_CALL(*this, make(A<const std::string&>(), _, _, _, _, _, _, _)) |
| 19 | .WillByDefault(WithArgs<0>(Invoke([](const std::string& id) { |
| 20 | return std::make_unique<NiceMock<TriggerMock>>(id); |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 21 | }))); |
| 22 | } |
| 23 | |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 24 | MOCK_METHOD(std::unique_ptr<interfaces::Trigger>, make, |
Szymon Dompke | e28aa53 | 2021-10-27 12:33:12 +0200 | [diff] [blame] | 25 | (const std::string& id, const std::string& name, |
Szymon Dompke | 2001301 | 2021-07-23 09:54:20 +0200 | [diff] [blame] | 26 | const std::vector<std::string>& triggerActions, |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 27 | const std::vector<std::string>& reportNames, |
| 28 | interfaces::TriggerManager& triggerManager, |
| 29 | interfaces::JsonStorage& triggerStorage, |
| 30 | const LabeledTriggerThresholdParams& labeledThresholdParams, |
| 31 | const std::vector<LabeledSensorInfo>& labeledSensorsInfo), |
| 32 | (const, override)); |
| 33 | |
| 34 | MOCK_METHOD(std::vector<LabeledSensorInfo>, getLabeledSensorsInfo, |
| 35 | (boost::asio::yield_context&, const SensorsInfo&), |
| 36 | (const, override)); |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 37 | |
| 38 | auto& expectMake( |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 39 | std::optional<TriggerParams> paramsOpt, |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 40 | const testing::Matcher<interfaces::TriggerManager&>& tm, |
| 41 | const testing::Matcher<interfaces::JsonStorage&>& triggerStorage) |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 42 | { |
Wludzik, Jozef | 1477fe6 | 2021-01-02 11:56:10 +0100 | [diff] [blame] | 43 | using namespace testing; |
| 44 | |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 45 | if (paramsOpt) |
| 46 | { |
| 47 | const TriggerParams& params = *paramsOpt; |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 48 | |
| 49 | const auto sensorInfos = |
| 50 | utils::fromLabeledSensorsInfo(params.sensors()); |
| 51 | |
| 52 | ON_CALL(*this, getLabeledSensorsInfo(_, sensorInfos)) |
| 53 | .WillByDefault(Return(params.sensors())); |
| 54 | |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 55 | return EXPECT_CALL( |
Szymon Dompke | e28aa53 | 2021-10-27 12:33:12 +0200 | [diff] [blame] | 56 | *this, make(params.id(), params.name(), params.triggerActions(), |
Szymon Dompke | 2001301 | 2021-07-23 09:54:20 +0200 | [diff] [blame] | 57 | params.reportNames(), tm, triggerStorage, |
| 58 | params.thresholdParams(), params.sensors())); |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 59 | } |
| 60 | else |
| 61 | { |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 62 | const std::vector<LabeledSensorInfo> dummy = { |
| 63 | {"service99", |
| 64 | "/xyz/openbmc_project/sensors/temperature/BMC_Temp99", |
| 65 | "metadata99"}}; |
| 66 | |
| 67 | ON_CALL(*this, getLabeledSensorsInfo(_, _)) |
| 68 | .WillByDefault(Return(dummy)); |
| 69 | |
Szymon Dompke | 2001301 | 2021-07-23 09:54:20 +0200 | [diff] [blame] | 70 | return EXPECT_CALL(*this, |
Szymon Dompke | e28aa53 | 2021-10-27 12:33:12 +0200 | [diff] [blame] | 71 | make(_, _, _, _, tm, triggerStorage, _, dummy)); |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 72 | } |
| 73 | } |
| 74 | }; |