dbus: add unit-tests for dbusutil: getSensorPath

Signed-off-by: Patrick Venture <venture@google.com>
Change-Id: Iabb2df7a725da1b70cb6a907d19c451e7bba609d
diff --git a/dbus/dbusutil.cpp b/dbus/dbusutil.cpp
index 1596628..7545eed 100644
--- a/dbus/dbusutil.cpp
+++ b/dbus/dbusutil.cpp
@@ -1,8 +1,11 @@
 #include "util.hpp"
 
 #include <cmath>
+#include <cstdint>
 #include <iostream>
+#include <map>
 #include <set>
+#include <string>
 #include <variant>
 
 using Property = std::string;
diff --git a/test/Makefile.am b/test/Makefile.am
index 73c52a9..7cb8014 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -25,7 +25,7 @@
  sensor_host_unittest util_unittest pid_zone_unittest \
  pid_thermalcontroller_unittest pid_fancontroller_unittest \
  pid_stepwisecontroller_unittest \
- dbus_passive_unittest dbus_active_unittest \
+ dbus_passive_unittest dbus_active_unittest dbus_util_unittest \
  sensors_json_unittest pid_json_unittest json_parse_unittest
 TESTS = $(check_PROGRAMS)
 
@@ -68,6 +68,9 @@
 dbus_active_unittest_SOURCES = dbus_active_unittest.cpp
 dbus_active_unittest_LDADD = $(top_builddir)/dbus/dbusactiveread.o
 
+dbus_util_unittest_SOURCES = dbus_util_unittest.cpp
+dbus_util_unittest_LDADD = $(top_builddir)/dbus/dbusutil.o
+
 sensors_json_unittest_SOURCES = sensors_json_unittest.cpp
 sensors_json_unittest_LDADD = $(top_builddir)/sensors/buildjson.o
 
diff --git a/test/dbus_util_unittest.cpp b/test/dbus_util_unittest.cpp
new file mode 100644
index 0000000..b02e1d6
--- /dev/null
+++ b/test/dbus_util_unittest.cpp
@@ -0,0 +1,40 @@
+#include "dbus/dbusutil.hpp"
+
+#include <string>
+#include <tuple>
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+namespace pid_control
+{
+namespace
+{
+
+using ::testing::StrEq;
+
+class GetSensorPathTest :
+    public ::testing::TestWithParam<
+        std::tuple<std::string, std::string, std::string>>
+{};
+
+TEST_P(GetSensorPathTest, ReturnsExpectedValue)
+{
+    // type, id, output
+    const auto& params = GetParam();
+    EXPECT_THAT(getSensorPath(std::get<0>(params), std::get<1>(params)),
+                StrEq(std::get<2>(params)));
+}
+
+INSTANTIATE_TEST_CASE_P(
+    GetSensorPathTests, GetSensorPathTest,
+    ::testing::Values(
+        std::make_tuple("fan", "0", "/xyz/openbmc_project/sensors/fan_tach/0"),
+        std::make_tuple("as", "we", "/xyz/openbmc_project/sensors/unknown/we"),
+        std::make_tuple("margin", "9",
+                        "/xyz/openbmc_project/sensors/temperature/9"),
+        std::make_tuple("temp", "123",
+                        "/xyz/openbmc_project/sensors/temperature/123")));
+
+} // namespace
+} // namespace pid_control