Add testcases for NamesValues

Change-Id: I61c52f2a196a32dbd4d03a2ccafa2b94414f7555
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
diff --git a/.gitignore b/.gitignore
index bcbfb29..b90d129 100644
--- a/.gitignore
+++ b/.gitignore
@@ -27,3 +27,4 @@
 stamp-h1
 witherspoon-pseq-monitor
 xyz/openbmc_project/Power/Fault/
+test-driver
diff --git a/Makefile.am b/Makefile.am
index 1e01319..ae6014f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -33,4 +33,4 @@
 	@mkdir -p `dirname $@`
 	$(SDBUSPLUSPLUS) -r $(srcdir) error exception-cpp xyz.openbmc_project.Power.Fault > $@
 
-SUBDIRS = . power-sequencer
+SUBDIRS = . power-sequencer test
diff --git a/configure.ac b/configure.ac
index cb986cc..edc2a1e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -38,6 +38,29 @@
 # Checks for library functions.
 LT_INIT # Required for systemd linking
 
+# Check/set gtest specific functions.
+AX_PTHREAD([GTEST_CPPFLAGS="-DGTEST_HAS_PTHREAD=1"],[GTEST_CPPFLAGS="-DGTEST_HAS_PTHREAD=0"])
+AC_SUBST(GTEST_CPPFLAGS)
+
+# Test cases require SDK so only build if we're told to (and SDK is available)
+AC_ARG_ENABLE([oe-sdk],
+    AS_HELP_STRING([--enable-oe-sdk], [Link testcases absolutely against OE SDK so they can be ran within it.])
+)
+AC_ARG_VAR(OECORE_TARGET_SYSROOT,
+    [Path to the OE SDK SYSROOT])
+AS_IF([test "x$enable_oe_sdk" == "xyes"],
+    AS_IF([test "x$OECORE_TARGET_SYSROOT" == "x"],
+          AC_MSG_ERROR([OECORE_TARGET_SYSROOT must be set with --enable-oe-sdk])
+    )
+    AC_MSG_NOTICE([Enabling OE-SDK at $OECORE_TARGET_SYSROOT])
+    [
+        testcase_flags="-Wl,-rpath,\${OECORE_TARGET_SYSROOT}/lib"
+        testcase_flags="${testcase_flags} -Wl,-rpath,\${OECORE_TARGET_SYSROOT}/usr/lib"
+        testcase_flags="${testcase_flags} -Wl,-dynamic-linker,`find \${OECORE_TARGET_SYSROOT}/lib/ld-*.so | sort -r -n | head -n1`"
+    ]
+    AC_SUBST([OESDK_TESTCASE_FLAGS], [$testcase_flags])
+)
+
 AC_ARG_ENABLE([turn-off-ucd90160-access],
     AS_HELP_STRING([--enable-turn-off-ucd90160-access], [Turn off UCD90160 hardware access])
 )
@@ -51,5 +74,5 @@
 )
 
 # Create configured output
-AC_CONFIG_FILES([Makefile power-sequencer/Makefile])
+AC_CONFIG_FILES([Makefile power-sequencer/Makefile test/Makefile])
 AC_OUTPUT
diff --git a/test/Makefile.am b/test/Makefile.am
new file mode 100644
index 0000000..138d637
--- /dev/null
+++ b/test/Makefile.am
@@ -0,0 +1,12 @@
+AM_CPPFLAGS = -I$(top_srcdir)
+
+# Run all 'check' test programs
+TESTS = $(check_PROGRAMS)
+
+check_PROGRAMS = nvtest
+nvtest_CPPFLAGS = -Igtest $(GTEST_CPPFLAGS) $(AM_CPPFLAGS)
+
+nvtest_CXXFLAGS = $(PTHREAD_CFLAGS)
+nvtest_LDFLAGS = -lgtest_main -lgtest $(PTHREAD_LIBS) $(OESDK_TESTCASE_FLAGS)
+
+nvtest_SOURCES = nvtest.cpp
diff --git a/test/nvtest.cpp b/test/nvtest.cpp
new file mode 100644
index 0000000..2abdae9
--- /dev/null
+++ b/test/nvtest.cpp
@@ -0,0 +1,35 @@
+/**
+ * Copyright © 2017 IBM Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <gtest/gtest.h>
+#include "names_values.hpp"
+
+TEST(NamesValuesTest, TestValues)
+{
+    witherspoon::power::util::NamesValues nv;
+
+    std::string expected;
+    EXPECT_EQ(nv.get(), expected); //empty
+
+    nv.add("name1", 0);
+    nv.add("name2", 0xC0FFEE);
+    nv.add("name3", 0x12345678abcdef12);
+    nv.add("name4", 0x0000000001);
+
+    expected = "name1=0x0|name2=0xc0ffee|name3=0x12345678abcdef12|name4=0x1";
+
+    EXPECT_EQ(nv.get(), expected);
+}
+