fw update: tests for common code
Tests for the common code introduced in another commit.
These tests should check that the common code behaves as outlined in the
design [1]
References:
[1] https://github.com/openbmc/docs/blob/master/designs/code-update.md
Tested: unit tests pass
Change-Id: I8f12839afd47ef3403a80439af54fedcc00f10be
Signed-off-by: Alexander Hansen <alexander.hansen@9elements.com>
diff --git a/test/common/test_device_config.cpp b/test/common/test_device_config.cpp
new file mode 100644
index 0000000..a4f0422
--- /dev/null
+++ b/test/common/test_device_config.cpp
@@ -0,0 +1,47 @@
+
+#include "common/include/device_config.hpp"
+
+#include <fcntl.h>
+#include <inttypes.h>
+#include <unistd.h>
+
+#include <phosphor-logging/lg2.hpp>
+
+#include <cassert>
+#include <cstdlib>
+#include <cstring>
+
+#include <gtest/gtest.h>
+
+TEST(DeviceConfig, success)
+{
+ DeviceConfig config(0x0324, "com.example.SampleCorp", "ConfigType",
+ "SampleComponent");
+
+ ASSERT_EQ(config.vendorIANA, 0x0324);
+ ASSERT_EQ(config.compatibleHardware, "com.example.SampleCorp");
+}
+
+TEST(DeviceConfig, failureCompatibleNoDot)
+{
+ try
+ {
+ DeviceConfig config(0x0324, "comexamplesamplecorp", "ConfigType",
+ "SampleComponent");
+ ASSERT_FALSE(true);
+ }
+ catch (std::exception& /*unused*/)
+ {}
+}
+
+TEST(DeviceConfig, failureCompatibleInvalidChar)
+{
+ try
+ {
+ DeviceConfig config(0x0324, "com-examplesamplecorp#", "ConfigType",
+ "SampleComponent");
+ ASSERT_FALSE(true);
+ }
+ catch (std::exception& /*unused*/)
+ {}
+}