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/meson.build b/test/common/software/meson.build
index 62c97de..a5ed0bf 100644
--- a/test/common/software/meson.build
+++ b/test/common/software/meson.build
@@ -3,6 +3,7 @@
     'software_get_random_softwareid',
     'software_config',
     'software_association',
+    'software_version',
 ]
 
 foreach t : testcases
diff --git a/test/common/software/software_association.cpp b/test/common/software/software_association.cpp
index c8da550..98fe3a9 100644
--- a/test/common/software/software_association.cpp
+++ b/test/common/software/software_association.cpp
@@ -22,7 +22,8 @@
 {
   protected:
     SoftwareAssocTest() :
-        exampleUpdater(ctx, "swVersion"), device(exampleUpdater.getDevice()),
+        exampleUpdater(ctx, true, "swVersion"),
+        device(exampleUpdater.getDevice()),
         objPathCurrentSoftware(
             reinterpret_cast<ExampleSoftware*>(device->softwareCurrent.get())
                 ->objectPath),
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();
+}