Test cases for VPD-Manager read functionalities

Implementation of test cases for read functionalities provided
by VPD-Manager app.

Signed-off-by: Sunny Srivastava <sunnsr25@in.ibm.com>
Change-Id: I83ad6757934a4c28ae26eb11f0b1f380e2c82aa8
diff --git a/vpd-manager/reader_impl.cpp b/vpd-manager/reader_impl.cpp
index f1b5c6b..4da02be 100644
--- a/vpd-manager/reader_impl.cpp
+++ b/vpd-manager/reader_impl.cpp
@@ -11,6 +11,10 @@
 #include <vector>
 #include <xyz/openbmc_project/Common/error.hpp>
 
+#ifdef ManagerTest
+#include "reader_test.hpp"
+#endif
+
 namespace openpower
 {
 namespace vpd
@@ -23,6 +27,7 @@
 using namespace phosphor::logging;
 using namespace openpower::vpd::inventory;
 using namespace openpower::vpd::constants;
+using namespace openpower::vpd::utils::interface;
 
 using InvalidArgument =
     sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument;
@@ -46,13 +51,14 @@
     const LocationCode& locationCode, const NodeNumber& nodeNumber,
     const LocationCodeMap& frusLocationCode) const
 {
+    // unused at this moment. Hence to avoid warnings
+    (void)nodeNumber;
     if (!isValidLocationCode(locationCode))
     {
         // argument is not valid
         elog<InvalidArgument>(Argument::ARGUMENT_NAME("LOCATIONCODE"),
                               Argument::ARGUMENT_VALUE(locationCode.c_str()));
     }
-
     auto iterator = frusLocationCode.find(locationCode);
     if (iterator == frusLocationCode.end())
     {
@@ -64,8 +70,12 @@
                               Argument::ARGUMENT_VALUE(locationCode.c_str()));
     }
 
-    std::string expandedLocationCode =
-        readBusProperty(iterator->second, LOCATION_CODE_INF, "LocationCode");
+    std::string expandedLocationCode{};
+#ifndef ManagerTest
+    utility utilObj;
+#endif
+    expandedLocationCode = utilObj.readBusProperty(
+        iterator->second, LOCATION_CODE_INF, "LocationCode");
     return expandedLocationCode;
 }
 
@@ -74,6 +84,9 @@
                                   const NodeNumber& nodeNumber,
                                   const LocationCodeMap& frusLocationCode) const
 {
+    // unused at this moment, to avoid compilation warning
+    (void)nodeNumber;
+
     // TODO:Implementation related to node number
     if (!isValidLocationCode(locationCode))
     {
@@ -116,8 +129,12 @@
                               Argument::ARGUMENT_VALUE(locationCode.c_str()));
     }
 
-    std::string fc =
-        readBusProperty(SYSTEM_OBJECT, "com.ibm.ipzvpd.VCEN", "FC");
+    std::string fc{};
+#ifndef ManagerTest
+    utility utilObj;
+#endif
+
+    fc = utilObj.readBusProperty(SYSTEM_OBJECT, "com.ibm.ipzvpd.VCEN", "FC");
 
     // get the first part of expanded location code to check for FC or TM
     std::string firstKeyword = locationCode.substr(1, 4);
@@ -169,9 +186,11 @@
     }
     else
     {
+        std::string tm{};
         // read TM kwd value
-        std::string tm =
-            readBusProperty(SYSTEM_OBJECT, "com.ibm.ipzvpd.VSYS", "TM");
+        tm =
+            utilObj.readBusProperty(SYSTEM_OBJECT, "com.ibm.ipzvpd.VSYS", "TM");
+        ;
 
         // check if the substr matches to TM kwd
         if (tm.substr(0, 4) ==
diff --git a/vpd-manager/reader_impl.hpp b/vpd-manager/reader_impl.hpp
index dab8b8e..4de3c9b 100644
--- a/vpd-manager/reader_impl.hpp
+++ b/vpd-manager/reader_impl.hpp
@@ -1,6 +1,7 @@
 #pragma once
 
 #include "types.hpp"
+#include "utilInterface.hpp"
 
 namespace openpower
 {
@@ -11,6 +12,7 @@
 namespace reader
 {
 
+using IUtil = openpower::vpd::utils::interface::UtilityInterface;
 /** @class ReaderImpl
  *  @brief Implements functionalities related to reading of VPD related data
  *  from the system.
@@ -19,12 +21,18 @@
 {
   public:
     ReaderImpl() = default;
-    ReaderImpl(const ReaderImpl&) = delete;
+    ReaderImpl(const ReaderImpl&) = default;
     ReaderImpl& operator=(const ReaderImpl&) = delete;
-    ReaderImpl(ReaderImpl&&) = delete;
+    ReaderImpl(ReaderImpl&&) = default;
     ReaderImpl& operator=(ReaderImpl&&) = delete;
     ~ReaderImpl() = default;
 
+#ifdef ManagerTest
+    explicit ReaderImpl(IUtil& obj) : utilObj(obj)
+    {
+    }
+#endif
+
     /** @brief An API to expand a given unexpanded location code.
      *  @param[in] locationCode - unexpanded location code.
      *  @param[in] nodeNumber - node on which we are looking for location code.
@@ -72,6 +80,9 @@
     std::tuple<inventory::LocationCode, inventory::NodeNumber>
         getCollapsedLocationCode(
             const inventory::LocationCode& locationCode) const;
+#ifdef ManagerTest
+    IUtil& utilObj;
+#endif
 
 }; // class ReaderImpl