phosphor-rsyslog-conf: add unit tests

Add tests pertaining to remote logging config file.

Change-Id: Idaeac09b5abe91af30dc0eb32664e8af556ecda2
Signed-off-by: Deepak Kodihalli <dkodihal@in.ibm.com>
diff --git a/test/Makefile.am b/test/Makefile.am
index 0db1650..30e5472 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -7,7 +7,8 @@
 	serialization_test_path \
 	serialization_test_properties \
 	remote_logging_test_address \
-	remote_logging_test_port
+	remote_logging_test_port \
+	remote_logging_test_config
 
 test_cppflags = \
 	-Igtest \
@@ -78,3 +79,11 @@
 remote_logging_test_port_LDFLAGS = \
 	$(test_ldflags) \
 	-lstdc++fs
+
+remote_logging_test_config_CPPFLAGS = $(test_cppflags)
+remote_logging_test_config_CXXFLAGS = $(test_cxxflags)
+remote_logging_test_config_SOURCES = remote_logging_test_config.cpp
+remote_logging_test_config_LDADD = $(remote_logging_test_ldadd)
+remote_logging_test_config_LDFLAGS = \
+	$(test_ldflags) \
+	-lstdc++fs
diff --git a/test/remote_logging_test_config.cpp b/test/remote_logging_test_config.cpp
new file mode 100644
index 0000000..8c3a98a
--- /dev/null
+++ b/test/remote_logging_test_config.cpp
@@ -0,0 +1,58 @@
+#include "remote_logging_tests.hpp"
+#include <fstream>
+
+namespace phosphor
+{
+namespace logging
+{
+namespace test
+{
+
+std::string getConfig(const char* filePath)
+{
+    std::fstream stream(filePath, std::fstream::in);
+    std::string line;
+    getline(stream, line);
+    return line;
+}
+
+TEST_F(TestRemoteLogging, testOnlyAddress)
+{
+    config->address("1.1.1.1");
+    EXPECT_EQ(getConfig(configFilePath.c_str()), "#*.* @@remote-host:port");
+}
+
+TEST_F(TestRemoteLogging, testOnlyPort)
+{
+    config->port(100);
+    EXPECT_EQ(getConfig(configFilePath.c_str()), "#*.* @@remote-host:port");
+}
+
+TEST_F(TestRemoteLogging, testGoodConfig)
+{
+    config->address("1.1.1.1");
+    config->port(100);
+    EXPECT_EQ(getConfig(configFilePath.c_str()), "*.* @@1.1.1.1:100");
+}
+
+TEST_F(TestRemoteLogging, testClearAddress)
+{
+    config->address("1.1.1.1");
+    config->port(100);
+    EXPECT_EQ(getConfig(configFilePath.c_str()), "*.* @@1.1.1.1:100");
+    config->address("");
+    EXPECT_EQ(getConfig(configFilePath.c_str()), "#*.* @@remote-host:port");
+}
+
+TEST_F(TestRemoteLogging, testClearPort)
+{
+    config->address("1.1.1.1");
+    config->port(100);
+    EXPECT_EQ(getConfig(configFilePath.c_str()), "*.* @@1.1.1.1:100");
+    config->port(0);
+    EXPECT_EQ(getConfig(configFilePath.c_str()), "#*.* @@remote-host:port");
+}
+
+}// namespace test
+}// namespace logging
+}// namespace phosphor