util: enable unit-tests

Start write tests and fix a missing header inclusion.

Change-Id: I4e56323f972b1358dc83a4cb61c25f98cda2a479
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/test/Makefile.am b/test/Makefile.am
index 4d5ca63..2a51c00 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -13,7 +13,7 @@
 
 # Run all 'check' test programs
 check_PROGRAMS = sensor_manager_unittest sensor_pluggable_unittest \
- sensor_host_unittest
+ sensor_host_unittest util_unittest
 TESTS = $(check_PROGRAMS)
 
 # Until libconfig is mocked out or replaced, include it.
@@ -25,3 +25,6 @@
 
 sensor_host_unittest_SOURCES = sensor_host_unittest.cpp
 sensor_host_unittest_LDADD = $(top_builddir)/sensors/host.o
+
+util_unittest_SOURCES = util_unittest.cpp
+util_unittest_LDADD = $(top_builddir)/util.o
diff --git a/test/util_unittest.cpp b/test/util_unittest.cpp
new file mode 100644
index 0000000..8abf1eb
--- /dev/null
+++ b/test/util_unittest.cpp
@@ -0,0 +1,71 @@
+#include "util.hpp"
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+#include <string>
+
+TEST(UtilTest, WriteTypeEmptyString_ReturnsNONE) {
+    // Verify it responds to an empty string.
+
+    EXPECT_EQ(IOInterfaceType::NONE, GetWriteInterfaceType(""));
+}
+
+TEST(UtilTest, WriteTypeNonePath_ReturnsNONE) {
+    // Verify it responds to a path of "None"
+
+    EXPECT_EQ(IOInterfaceType::NONE, GetWriteInterfaceType("None"));
+}
+
+TEST(UtilTest, WriteTypeSysfs_ReturnsSYSFS) {
+    // Verify the sysfs type is determined with an expected path
+
+    std::string path = "/sys/devices/asfdadsf";
+    EXPECT_EQ(IOInterfaceType::SYSFS, GetWriteInterfaceType(path));
+}
+
+TEST(UtilTest, WriteTypeUnknown_ReturnsUNKNOWN) {
+    // Verify it reports unknown by default.
+
+    std::string path = "/xyz/openbmc_project";
+    EXPECT_EQ(IOInterfaceType::UNKNOWN, GetWriteInterfaceType(path));
+}
+
+TEST(UtilTest, ReadTypeEmptyString_ReturnsNONE) {
+    // Verify it responds to an empty string.
+
+    EXPECT_EQ(IOInterfaceType::NONE, GetReadInterfaceType(""));
+}
+
+TEST(UtilTest, ReadTypeNonePath_ReturnsNONE) {
+    // Verify it responds to a path of "None"
+
+    EXPECT_EQ(IOInterfaceType::NONE, GetReadInterfaceType("None"));
+}
+
+TEST(UtilTest, ReadTypeExternalSensors_ReturnsEXTERNAL) {
+    // Verify it responds to a path that represents a host sensor.
+
+    std::string path = "/xyz/openbmc_project/extsensors/temperature/fleeting0";
+    EXPECT_EQ(IOInterfaceType::EXTERNAL, GetReadInterfaceType(path));
+}
+
+TEST(UtilTest, ReadTypeOpenBMCSensor_ReturnsDBUSPASSIVE) {
+    // Verify it responds to a path that represents a dbus sensor.
+
+    std::string path = "/xyz/openbmc_project/sensors/fan_tach/fan1";
+    EXPECT_EQ(IOInterfaceType::DBUSPASSIVE, GetReadInterfaceType(path));
+}
+
+TEST(UtilTest, ReadTypeSysfsPath_ReturnsSYSFS) {
+    // Verify the sysfs type is determined with an expected path
+
+    std::string path = "/sys/devices/asdf/asdf0";
+    EXPECT_EQ(IOInterfaceType::SYSFS, GetReadInterfaceType(path));
+}
+
+TEST(UtilTest, ReadTypeUnknownDefault_ReturnsUNKNOWN) {
+    // Verify it reports unknown by default.
+
+    std::string path = "asdf09as0df9a0fd";
+    EXPECT_EQ(IOInterfaceType::UNKNOWN, GetReadInterfaceType(path));
+}
diff --git a/util.hpp b/util.hpp
index 2c5eccd..d04baaa 100644
--- a/util.hpp
+++ b/util.hpp
@@ -1,5 +1,7 @@
 #pragma once
 
+#include <string>
+
 /* This program assumes sensors use the Sensor.Value interface
  * and for sensor->write() I only implemented sysfs as a type,
  * but -- how would it know whether to use Control.FanSpeed or Control.FanPwm?