test: common: software version

Test Software Version DBus API.

Change-Id: I287b7e7957199463ec80bda8f71bf881bc0e5cb8
Signed-off-by: Alexander Hansen <alexander.hansen@9elements.com>
diff --git a/test/common/software/software_version.cpp b/test/common/software/software_version.cpp
new file mode 100644
index 0000000..a81cc21
--- /dev/null
+++ b/test/common/software/software_version.cpp
@@ -0,0 +1,75 @@
+#include "../exampledevice/example_device.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 <gtest/gtest.h>
+
+PHOSPHOR_LOG2_USING;
+
+using namespace phosphor::software;
+using namespace phosphor::software::example_device;
+
+sdbusplus::async::task<> testSoftwareVersion(sdbusplus::async::context& ctx)
+{
+    ExampleCodeUpdater exampleUpdater(ctx, true, nullptr);
+
+    auto& device = exampleUpdater.getDevice();
+
+    device->softwareCurrent = std::make_unique<ExampleSoftware>(ctx, *device);
+
+    std::string objPathCurrentSoftware =
+        reinterpret_cast<ExampleSoftware*>(device->softwareCurrent.get())
+            ->objectPath;
+
+    auto busName = exampleUpdater.getBusName();
+
+    auto clientVersion =
+        sdbusplus::client::xyz::openbmc_project::software::Version<>(ctx)
+            .service(busName)
+            .path(objPathCurrentSoftware);
+
+    // the version is unavailable at this point
+    try
+    {
+        co_await clientVersion.version();
+        EXPECT_TRUE(false);
+    }
+    catch (std::exception& e)
+    {
+        debug(e.what());
+    }
+
+    // now the version is available
+    {
+        device->softwareCurrent->setVersion("v12.6");
+
+        EXPECT_EQ((co_await clientVersion.version()), "v12.6");
+    }
+
+    // we can set the version twice
+    {
+        device->softwareCurrent->setVersion("v20");
+
+        EXPECT_EQ((co_await clientVersion.version()), "v20");
+    }
+
+    ctx.request_stop();
+
+    co_return;
+}
+
+TEST(SoftwareUpdate, TestSoftwareUpdate)
+{
+    sdbusplus::async::context ctx;
+
+    ctx.spawn(testSoftwareVersion(ctx));
+
+    ctx.run();
+}