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" |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 8 | #include "utils/transform.hpp" |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 9 | |
| 10 | #include <gmock/gmock.h> |
| 11 | |
| 12 | class TriggerFactoryMock : public interfaces::TriggerFactory |
| 13 | { |
| 14 | public: |
| 15 | TriggerFactoryMock() |
| 16 | { |
| 17 | using namespace testing; |
| 18 | |
Szymon Dompke | e28aa53 | 2021-10-27 12:33:12 +0200 | [diff] [blame] | 19 | ON_CALL(*this, make(A<const std::string&>(), _, _, _, _, _, _, _)) |
| 20 | .WillByDefault(WithArgs<0>(Invoke([](const std::string& id) { |
Patrick Williams | c7935fa | 2023-10-20 11:19:30 -0500 | [diff] [blame] | 21 | return std::make_unique<NiceMock<TriggerMock>>(id); |
| 22 | }))); |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 23 | } |
| 24 | |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 25 | MOCK_METHOD(std::unique_ptr<interfaces::Trigger>, make, |
Szymon Dompke | e28aa53 | 2021-10-27 12:33:12 +0200 | [diff] [blame] | 26 | (const std::string& id, const std::string& name, |
Szymon Dompke | 2001301 | 2021-07-23 09:54:20 +0200 | [diff] [blame] | 27 | const std::vector<std::string>& triggerActions, |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 28 | const std::vector<std::string>& reportIds, |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 29 | interfaces::TriggerManager& triggerManager, |
| 30 | interfaces::JsonStorage& triggerStorage, |
| 31 | const LabeledTriggerThresholdParams& labeledThresholdParams, |
| 32 | const std::vector<LabeledSensorInfo>& labeledSensorsInfo), |
| 33 | (const, override)); |
| 34 | |
| 35 | MOCK_METHOD(std::vector<LabeledSensorInfo>, getLabeledSensorsInfo, |
| 36 | (boost::asio::yield_context&, const SensorsInfo&), |
| 37 | (const, override)); |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 38 | |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 39 | MOCK_METHOD(std::vector<LabeledSensorInfo>, getLabeledSensorsInfo, |
| 40 | (const SensorsInfo&), (const, override)); |
| 41 | |
| 42 | MOCK_METHOD(void, updateThresholds, |
| 43 | (std::vector<std::shared_ptr<interfaces::Threshold>> & |
| 44 | currentThresholds, |
Szymon Dompke | b7b7e1b | 2022-05-19 10:15:48 +0200 | [diff] [blame] | 45 | const std::string& triggerId, |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 46 | const std::vector<TriggerAction>& triggerActions, |
| 47 | const std::shared_ptr<std::vector<std::string>>& reportIds, |
| 48 | const Sensors& sensors, |
| 49 | const LabeledTriggerThresholdParams& newParams), |
| 50 | (const, override)); |
| 51 | |
| 52 | MOCK_METHOD(void, updateSensors, |
| 53 | (Sensors & currentSensors, |
| 54 | const std::vector<LabeledSensorInfo>& senorParams), |
| 55 | (const, override)); |
| 56 | |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 57 | auto& expectMake( |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 58 | std::optional<TriggerParams> paramsOpt, |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 59 | const testing::Matcher<interfaces::TriggerManager&>& tm, |
| 60 | const testing::Matcher<interfaces::JsonStorage&>& triggerStorage) |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 61 | { |
Wludzik, Jozef | 1477fe6 | 2021-01-02 11:56:10 +0100 | [diff] [blame] | 62 | using namespace testing; |
| 63 | |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 64 | if (paramsOpt) |
| 65 | { |
| 66 | const TriggerParams& params = *paramsOpt; |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 67 | |
| 68 | const auto sensorInfos = |
| 69 | utils::fromLabeledSensorsInfo(params.sensors()); |
| 70 | |
| 71 | ON_CALL(*this, getLabeledSensorsInfo(_, sensorInfos)) |
| 72 | .WillByDefault(Return(params.sensors())); |
| 73 | |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 74 | return EXPECT_CALL( |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 75 | *this, make(params.id(), params.name(), |
Patrick Williams | c7935fa | 2023-10-20 11:19:30 -0500 | [diff] [blame] | 76 | utils::transform(params.triggerActions(), |
| 77 | [](const auto& action) { |
Patrick Williams | 3a1c297 | 2023-05-10 07:51:04 -0500 | [diff] [blame] | 78 | return actionToString(action); |
Patrick Williams | c7935fa | 2023-10-20 11:19:30 -0500 | [diff] [blame] | 79 | }), |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 80 | params.reportIds(), tm, triggerStorage, |
Szymon Dompke | 2001301 | 2021-07-23 09:54:20 +0200 | [diff] [blame] | 81 | params.thresholdParams(), params.sensors())); |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 82 | } |
| 83 | else |
| 84 | { |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 85 | const std::vector<LabeledSensorInfo> dummy = { |
| 86 | {"service99", |
| 87 | "/xyz/openbmc_project/sensors/temperature/BMC_Temp99", |
| 88 | "metadata99"}}; |
| 89 | |
| 90 | ON_CALL(*this, getLabeledSensorsInfo(_, _)) |
| 91 | .WillByDefault(Return(dummy)); |
| 92 | |
Szymon Dompke | 2001301 | 2021-07-23 09:54:20 +0200 | [diff] [blame] | 93 | return EXPECT_CALL(*this, |
Szymon Dompke | e28aa53 | 2021-10-27 12:33:12 +0200 | [diff] [blame] | 94 | make(_, _, _, _, tm, triggerStorage, _, dummy)); |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 95 | } |
| 96 | } |
| 97 | }; |