pldm: Move the updateDbusProperty method to the common utils
The updateDbusProperty method defined in libpldmresponder/bios_parse.cpp
and need to moved pldm/utils.hpp.
Add the updateDbusProperty method to Mock test class and remove the
setDbusProperty method in Mock test class.
Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: Ib1c339af41df7f625d6976c192a3b72ce06b04a2
diff --git a/test/libpldmresponder_platform_test.cpp b/test/libpldmresponder_platform_test.cpp
index d1241c2..2e99f5a 100644
--- a/test/libpldmresponder_platform_test.cpp
+++ b/test/libpldmresponder_platform_test.cpp
@@ -1,13 +1,12 @@
#include "libpldmresponder/pdr.hpp"
#include "libpldmresponder/pdr_utils.hpp"
#include "libpldmresponder/platform.hpp"
+#include "mocked_utils.hpp"
+#include "utils.hpp"
#include <iostream>
-#include <gmock/gmock-matchers.h>
-#include <gmock/gmock.h>
-#include <gtest/gtest.h>
-
+using namespace pldm::utils;
using namespace pldm::responder;
using namespace pldm::responder::platform;
using namespace pldm::responder::pdr;
@@ -175,26 +174,6 @@
pldm_pdr_destroy(pdrRepo);
}
-namespace pldm
-{
-
-namespace responder
-{
-
-class MockdBusHandler
-{
- public:
- MOCK_CONST_METHOD4(setDbusProperty,
- int(const std::string&, const std::string&,
- const std::string&,
- const std::variant<std::string>&));
-};
-} // namespace responder
-} // namespace pldm
-
-using ::testing::_;
-using ::testing::Return;
-
TEST(setStateEffecterStatesHandler, testGoodRequest)
{
auto inPDRRepo = pldm_pdr_init();
@@ -213,16 +192,16 @@
std::vector<set_effecter_state_field> stateField;
stateField.push_back({PLDM_REQUEST_SET, 1});
stateField.push_back({PLDM_REQUEST_SET, 1});
-
- auto bootProgressInf = "xyz.openbmc_project.State.OperatingSystem.Status";
- auto bootProgressProp = "OperatingSystemState";
- std::string objPath = "/foo/bar";
- std::variant<std::string> value{"xyz.openbmc_project.State.OperatingSystem."
- "Status.OSStatus.Standby"};
+ std::string value = "xyz.openbmc_project.State.OperatingSystem."
+ "Status.OSStatus.Standby";
+ PropertyValue propertyValue = value;
MockdBusHandler handlerObj;
- EXPECT_CALL(handlerObj, setDbusProperty(objPath, bootProgressProp,
- bootProgressInf, value))
+ DBusMapping dbusMapping{"/foo/bar",
+ "xyz.openbmc_project.State.OperatingSystem.Status",
+ "OperatingSystemState", "string"};
+
+ EXPECT_CALL(handlerObj, setDbusProperty(dbusMapping, propertyValue))
.Times(2);
auto rc = handler.setStateEffecterStatesHandler<MockdBusHandler>(
handlerObj, 0x1, stateField);
diff --git a/test/mocked_utils.hpp b/test/mocked_utils.hpp
new file mode 100644
index 0000000..39ac8bb
--- /dev/null
+++ b/test/mocked_utils.hpp
@@ -0,0 +1,35 @@
+#pragma once
+
+#include "utils.hpp"
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+namespace pldm
+{
+namespace utils
+{
+
+/** @brief helper function for parameter matching
+ * @param[in] lhs - left-hand side value
+ * @param[in] rhs - right-hand side value
+ * @return true if it matches
+ */
+inline bool operator==(const DBusMapping& lhs, const DBusMapping& rhs)
+{
+ return lhs.objectPath == rhs.objectPath && lhs.interface == rhs.interface &&
+ lhs.propertyName == rhs.propertyName &&
+ lhs.propertyType == rhs.propertyType;
+}
+
+} // namespace utils
+} // namespace pldm
+
+using namespace pldm::utils;
+
+class MockdBusHandler : public DBusHandler
+{
+ public:
+ MOCK_METHOD(void, setDbusProperty,
+ (const DBusMapping&, const PropertyValue&), (const override));
+};