test: common: software config

Tests for the common configuration all updaters receive from EM.

Change-Id: Ic242b5fbaa88a1b10ec9b9e97e084e1e85e7e9e0
Signed-off-by: Alexander Hansen <alexander.hansen@9elements.com>
diff --git a/test/common/software/meson.build b/test/common/software/meson.build
index 7d0a077..e67ee78 100644
--- a/test/common/software/meson.build
+++ b/test/common/software/meson.build
@@ -1,5 +1,5 @@
 
-testcases = ['software_get_random_softwareid']
+testcases = ['software_get_random_softwareid', 'software_config']
 
 foreach t : testcases
     test(
diff --git a/test/common/software/software_config.cpp b/test/common/software/software_config.cpp
new file mode 100644
index 0000000..39fb560
--- /dev/null
+++ b/test/common/software/software_config.cpp
@@ -0,0 +1,57 @@
+
+#include "common/include/software_config.hpp"
+
+#include <fcntl.h>
+#include <inttypes.h>
+#include <unistd.h>
+
+#include <phosphor-logging/lg2.hpp>
+
+#include <gtest/gtest.h>
+
+using namespace phosphor::software;
+using namespace phosphor::software::config;
+
+constexpr uint32_t vendorIANA = 0x0324;
+
+constexpr const char* compatibleHardware =
+    "com.ExampleCorp.Hardware.ExamplePlatform.ExampleDevice";
+constexpr const char* exampleConfigName = "ExampleConfigName";
+constexpr const char* exampleConfigType = "ExampleConfigType";
+
+const std::string objPath =
+    "/xyz/openbmc_project/inventory/system/board/ExampleBoard/ExampleDevice";
+
+TEST(SoftwareConfig, ConfigCreate)
+{
+    SoftwareConfig config(objPath, vendorIANA, compatibleHardware,
+                          exampleConfigType, exampleConfigName);
+
+    ASSERT_EQ(config.configName, exampleConfigName);
+    ASSERT_EQ(config.configType, exampleConfigType);
+}
+
+TEST(SoftwareConfig, FailureCompatibleNoDot)
+{
+    try
+    {
+        SoftwareConfig config(objPath, vendorIANA, "comexamplesamplecorp",
+                              exampleConfigType, exampleConfigName);
+        ASSERT_FALSE(true);
+    }
+    catch (std::exception& /*unused*/)
+    {}
+}
+
+TEST(SoftwareConfig, FailureCompatibleInvalidChar)
+{
+    try
+    {
+        SoftwareConfig config(objPath, vendorIANA,
+                              std::string(compatibleHardware) + "#",
+                              exampleConfigType, exampleConfigName);
+        ASSERT_FALSE(true);
+    }
+    catch (std::exception& /*unused*/)
+    {}
+}