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_version.cpp b/test/common/software/test_software_version.cpp
new file mode 100644
index 0000000..0fc216f
--- /dev/null
+++ b/test/common/software/test_software_version.cpp
@@ -0,0 +1,77 @@
+#include "../nopdevice/nopdevice.hpp"
+
+#include <fcntl.h>
+#include <inttypes.h>
+#include <unistd.h>
+
+#include <phosphor-logging/lg2.hpp>
+#include <sdbusplus/async/context.hpp>
+#include <xyz/openbmc_project/Software/Update/client.hpp>
+#include <xyz/openbmc_project/Software/Version/client.hpp>
+
+#include <cassert>
+#include <cstdlib>
+#include <cstring>
+
+#include <gtest/gtest.h>
+
+// NOLINTBEGIN
+sdbusplus::async::task<> testSoftwareVersion(sdbusplus::async::context& ctx)
+// NOLINTEND
+{
+    NopCodeUpdater nopcu(ctx);
+    NopCodeUpdater* cu = &nopcu;
+
+    const std::string service = nopcu.setupBusName();
+
+    auto device = std::make_unique<NopDevice>(ctx, cu);
+
+    device->softwareCurrent =
+        std::make_unique<Software>(ctx, "swid_sw_version", *device);
+
+    std::string objPathCurrentSoftware =
+        device->softwareCurrent->getObjectPath();
+
+    auto clientVersion =
+        sdbusplus::client::xyz::openbmc_project::software::Version<>(ctx)
+            .service(service)
+            .path(objPathCurrentSoftware);
+
+    // the version is unavailable at this point
+    try
+    {
+        co_await clientVersion.version();
+        assert(false);
+    }
+    catch (std::exception& e)
+    {
+        lg2::debug(e.what());
+    }
+
+    // now the version is available
+    {
+        device->softwareCurrent->setVersion("v12.6");
+
+        assert((co_await clientVersion.version()) == "v12.6");
+    }
+
+    // we cannot set the version twice
+    {
+        device->softwareCurrent->setVersion("v20");
+
+        assert((co_await clientVersion.version()) == "v12.6");
+    }
+
+    ctx.request_stop();
+
+    co_return;
+}
+
+TEST(SoftwareUpdate, TestSoftwareUpdate)
+{
+    sdbusplus::async::context ctx;
+
+    ctx.spawn(testSoftwareVersion(ctx));
+
+    ctx.run();
+}