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/software/test_software.cpp b/test/common/software/test_software.cpp
new file mode 100644
index 0000000..5eae56d
--- /dev/null
+++ b/test/common/software/test_software.cpp
@@ -0,0 +1,79 @@
+#include "../nopdevice/nopdevice.hpp"
+
+#include <phosphor-logging/lg2.hpp>
+#include <sdbusplus/asio/connection.hpp>
+#include <sdbusplus/asio/object_server.hpp>
+#include <sdbusplus/async.hpp>
+#include <sdbusplus/server.hpp>
+
+#include <memory>
+#include <regex>
+
+#include <gtest/gtest.h>
+
+// NOLINTBEGIN
+sdbusplus::async::task<> endContext(sdbusplus::async::context& ctx)
+// NOLINTEND
+{
+    ctx.request_stop();
+
+    co_return;
+}
+
+TEST(SoftwareTest, TestSoftwareConstructor)
+{
+    sdbusplus::async::context ctx;
+    NopCodeUpdater nopcu(ctx);
+    NopCodeUpdater* cu = &nopcu;
+
+    auto device = std::make_unique<NopDevice>(ctx, cu);
+
+    // the software version is currently unknown
+    assert(device->softwareCurrent == nullptr);
+
+    auto sw = std::make_unique<Software>(ctx, "swid_test_constructor", *device);
+
+    // since that software is not an update, there is no progress
+    assert(sw->optSoftwareActivationProgress == nullptr);
+
+    // test succeeds if we construct without any exception
+    // and can run the context
+
+    ctx.spawn(endContext(ctx));
+    ctx.run();
+}
+
+TEST(SoftwareTest, TestSoftwareId)
+{
+    sdbusplus::async::context ctx;
+    NopCodeUpdater nopcu(ctx);
+    NopCodeUpdater* cu = &nopcu;
+
+    auto device = std::make_unique<NopDevice>(ctx, cu);
+
+    // the software version is currently unknown
+    assert(device->softwareCurrent == nullptr);
+
+    auto sw = std::make_unique<Software>(ctx, "Nop_swid_test_swid", *device);
+
+    // design: Swid = <DeviceX>_<RandomId>
+    assert(sw->swid.starts_with("Nop"));
+}
+
+TEST(SoftwareTest, TestSoftwareObjectPath)
+{
+    sdbusplus::async::context ctx;
+    NopCodeUpdater nopcu(ctx);
+    NopCodeUpdater* cu = &nopcu;
+
+    auto device = std::make_unique<NopDevice>(ctx, cu);
+
+    auto sw = std::make_unique<Software>(ctx, "swid_test_obj_path", *device);
+
+    lg2::debug("{PATH}", "PATH", sw->getObjectPath());
+
+    // assert that the object path is as per the design
+    // design: /xyz/openbmc_project/Software/<SwId>
+    assert(std::string(sw->getObjectPath())
+               .starts_with("/xyz/openbmc_project/software/"));
+}