unit-test: Introduce unit tests to phosphor-objmgr
Move a function to make more testable and add a test case for it
Testing: Verified 100% test coverage in processing.cpp
Change-Id: I0a888009cfeb57bbc8ad295681bea00b79f2a23d
Signed-off-by: Andrew Geissler <geissonator@yahoo.com>
diff --git a/src/test/Makefile.am.include b/src/test/Makefile.am.include
new file mode 100644
index 0000000..a698753
--- /dev/null
+++ b/src/test/Makefile.am.include
@@ -0,0 +1,4 @@
+src_test_well_known_SOURCES = %reldir%/well_known.cpp src/processing.cpp
+
+check_PROGRAMS += \
+ %reldir%/well_known
diff --git a/src/test/well_known.cpp b/src/test/well_known.cpp
new file mode 100644
index 0000000..c9f119c
--- /dev/null
+++ b/src/test/well_known.cpp
@@ -0,0 +1,37 @@
+#include "src/processing.hpp"
+
+#include <gtest/gtest.h>
+
+// Verify if name does not start with a : that it is returned
+TEST(WellKnownName, NameNotStartColon)
+{
+ boost::container::flat_map<std::string, std::string> owners;
+ const std::string request = "test";
+ std::string well_known;
+
+ EXPECT_TRUE(getWellKnown(owners, request, well_known));
+ EXPECT_EQ(well_known, request);
+}
+
+// Verify if name is not found, false is returned
+TEST(WellKnownName, NameNotFound)
+{
+ boost::container::flat_map<std::string, std::string> owners;
+ const std::string request = ":test";
+ std::string well_known;
+
+ EXPECT_FALSE(getWellKnown(owners, request, well_known));
+ EXPECT_TRUE(well_known.empty());
+}
+
+// Verify if name is found, true is returned and name is correct
+TEST(WellKnownName, NameFound)
+{
+ boost::container::flat_map<std::string, std::string> owners;
+ const std::string request = ":1.25";
+ std::string well_known;
+
+ owners[request] = "test";
+ EXPECT_TRUE(getWellKnown(owners, request, well_known));
+ EXPECT_EQ(well_known, "test");
+}