Add TriggerManager and Trigger objects
Implemented initial version of Trigger and TriggerManager DBus
interfaces. Now DBus user is able to add new Trigger and delete it.
There is no support for other functionality added.
Tested:
- Built using yocto dependencies with success
- Unit tests passed
- Verified manually if Trigger and TriggerManager works as
expected
Change-Id: Ie68463526ecccc3be67cc7bfaaf9a9aa7326dee6
Signed-off-by: Wludzik, Jozef <jozef.wludzik@intel.com>
diff --git a/tests/src/mocks/report_mock.hpp b/tests/src/mocks/report_mock.hpp
index 2f6ffac..f3eafba 100644
--- a/tests/src/mocks/report_mock.hpp
+++ b/tests/src/mocks/report_mock.hpp
@@ -7,17 +7,12 @@
class ReportMock : public interfaces::Report
{
public:
- ReportMock(std::string reportName)
+ ReportMock(std::string name)
{
using namespace testing;
- ON_CALL(*this, getName).WillByDefault([reportName] {
- return reportName;
- });
- ON_CALL(*this, getPath).WillByDefault([reportName] {
- return "/" + reportName;
- });
-
+ ON_CALL(*this, getName).WillByDefault([name] { return name; });
+ ON_CALL(*this, getPath).WillByDefault([name] { return "/" + name; });
EXPECT_CALL(*this, Die).Times(AnyNumber());
}
diff --git a/tests/src/mocks/trigger_factory_mock.hpp b/tests/src/mocks/trigger_factory_mock.hpp
new file mode 100644
index 0000000..b714a44
--- /dev/null
+++ b/tests/src/mocks/trigger_factory_mock.hpp
@@ -0,0 +1,51 @@
+#pragma once
+
+#include "interfaces/trigger_factory.hpp"
+#include "mocks/trigger_mock.hpp"
+#include "params/trigger_params.hpp"
+
+#include <gmock/gmock.h>
+
+class TriggerFactoryMock : public interfaces::TriggerFactory
+{
+ public:
+ TriggerFactoryMock()
+ {
+ using namespace testing;
+
+ ON_CALL(*this, make(_, _, _, _, _, _, _, _, _))
+ .WillByDefault(WithArgs<0>(Invoke([](const std::string& name) {
+ return std::make_unique<NiceMock<TriggerMock>>(name);
+ })));
+ }
+
+ MOCK_METHOD(std::unique_ptr<interfaces::Trigger>, make,
+ (const std::string& name, bool isDiscrete, bool logToJournal,
+ bool logToRedfish, bool updateReport,
+ (const std::vector<std::pair<sdbusplus::message::object_path,
+ std::string>>& sensors),
+ const std::vector<std::string>& reportNames,
+ const TriggerThresholdParams& thresholds,
+ interfaces::TriggerManager& triggerManager),
+ (const, override));
+
+ auto& expectMake(
+ std::optional<std::reference_wrapper<const TriggerParams>> paramsOpt,
+ const testing::Matcher<interfaces::TriggerManager&>& tm)
+ {
+ if (paramsOpt)
+ {
+ const TriggerParams& params = *paramsOpt;
+ return EXPECT_CALL(
+ *this, make(params.name(), params.isDiscrete(),
+ params.logToJournal(), params.logToRedfish(),
+ params.updateReport(), params.sensors(),
+ params.reportNames(), params.thresholds(), tm));
+ }
+ else
+ {
+ using testing::_;
+ return EXPECT_CALL(*this, make(_, _, _, _, _, _, _, _, tm));
+ }
+ }
+};
diff --git a/tests/src/mocks/trigger_manager_mock.hpp b/tests/src/mocks/trigger_manager_mock.hpp
new file mode 100644
index 0000000..9377d2a
--- /dev/null
+++ b/tests/src/mocks/trigger_manager_mock.hpp
@@ -0,0 +1,12 @@
+#pragma once
+
+#include "interfaces/trigger_manager.hpp"
+
+#include <gmock/gmock.h>
+
+class TriggerManagerMock : public interfaces::TriggerManager
+{
+ public:
+ MOCK_METHOD(void, removeTrigger, (const interfaces::Trigger* trigger),
+ (override));
+};
diff --git a/tests/src/mocks/trigger_mock.hpp b/tests/src/mocks/trigger_mock.hpp
new file mode 100644
index 0000000..d8eddd2
--- /dev/null
+++ b/tests/src/mocks/trigger_mock.hpp
@@ -0,0 +1,27 @@
+#pragma once
+
+#include "interfaces/trigger.hpp"
+
+#include <gmock/gmock.h>
+
+class TriggerMock : public interfaces::Trigger
+{
+ public:
+ TriggerMock(std::string name)
+ {
+ using namespace testing;
+
+ ON_CALL(*this, getName).WillByDefault([name] { return name; });
+ ON_CALL(*this, getPath).WillByDefault([name] { return "/" + name; });
+ EXPECT_CALL(*this, Die).Times(AnyNumber());
+ }
+
+ virtual ~TriggerMock()
+ {
+ Die();
+ }
+
+ MOCK_METHOD(std::string, getName, (), (const, override));
+ MOCK_METHOD(std::string, getPath, (), (const, override));
+ MOCK_METHOD(void, Die, ());
+};