test: common: associations

Test software associations in common code.
Write necessary wrappers in example device to use the protected members.

Change-Id: If7c38f12472699672ed8a4c1b3e1c99c398cdba5
Signed-off-by: Alexander Hansen <alexander.hansen@9elements.com>
diff --git a/test/common/exampledevice/example_device.cpp b/test/common/exampledevice/example_device.cpp
index 86606fb..9200bb2 100644
--- a/test/common/exampledevice/example_device.cpp
+++ b/test/common/exampledevice/example_device.cpp
@@ -41,13 +41,45 @@
     SoftwareManager(ctx, "ExampleUpdater" + std::to_string(uniqueSuffix))
 {}
 
+ExampleCodeUpdater::ExampleCodeUpdater(sdbusplus::async::context& ctx,
+                                       const char* swVersion) :
+    ExampleCodeUpdater(ctx)
+{
+    const std::string exampleInvObjPath =
+        "/xyz/openbmc_project/inventory/system/board/ExampleBoard/ExampleDevice";
+    auto exampleDevice = std::make_unique<ExampleDevice>(ctx, &(*this));
+
+    devices.insert({exampleInvObjPath, std::move(exampleDevice)});
+
+    if (swVersion)
+    {
+        auto& device = getDevice();
+        device->softwareCurrent =
+            std::make_unique<ExampleSoftware>(ctx, *device);
+        device->softwareCurrent->setVersion(swVersion);
+    }
+}
+
+std::unique_ptr<ExampleDevice>& ExampleCodeUpdater::getDevice()
+{
+    if (devices.empty())
+    {
+        throw std::invalid_argument(
+            "could not find any device, example CU wrongly initialized");
+    }
+
+    auto& deviceRef = devices.begin()->second;
+
+    return reinterpret_cast<std::unique_ptr<ExampleDevice>&>(deviceRef);
+}
+
 sdbusplus::async::task<bool> ExampleCodeUpdater::initDevice(
     const std::string& /*unused*/, const std::string& /*unused*/,
     SoftwareConfig& /*unused*/)
 {
     auto device = std::make_unique<ExampleDevice>(ctx, this);
 
-    device->softwareCurrent = std::make_unique<Software>(ctx, *device);
+    device->softwareCurrent = std::make_unique<ExampleSoftware>(ctx, *device);
 
     device->softwareCurrent->setVersion("v1.0",
                                         SoftwareVersion::VersionPurpose::Other);
@@ -91,3 +123,7 @@
 
     co_return true;
 }
+
+ExampleSoftware::ExampleSoftware(sdbusplus::async::context& ctx,
+                                 ExampleDevice& parent) : Software(ctx, parent)
+{}