Test cases for VPD-Manager editor functionalities
Implementation of test cases for editor functionalities provided
by VPD-Manager app.
Signed-off-by: Sunny Srivastava <sunnsr25@in.ibm.com>
Change-Id: I6281f2be898f95e37c9575ea12affe57744a0cab
diff --git a/vpd-manager/editor_impl.cpp b/vpd-manager/editor_impl.cpp
index d69d7fa..b9104f0 100644
--- a/vpd-manager/editor_impl.cpp
+++ b/vpd-manager/editor_impl.cpp
@@ -61,7 +61,6 @@
sizeof(ECCOffset) + sizeof(ECCLength));
}
}
-
// imples the record was not found
throw std::runtime_error("Record not found");
}
@@ -82,6 +81,19 @@
std::advance(iteratorToKWdData, thisRecord.kwDataOffset);
std::copy(iteratorToNewdata, end, iteratorToKWdData);
+#ifdef ManagerTest
+ auto startItr = vpdFile.begin();
+ std::advance(iteratorToKWdData, thisRecord.kwDataOffset);
+ auto endItr = startItr;
+ std::advance(endItr, thisRecord.kwdDataLength);
+
+ Binary updatedData(startItr, endItr);
+ if (updatedData == kwdData)
+ {
+ throw std::runtime_error("Data updated successfully");
+ }
+#else
+
// update data in EEPROM as well. As we will not write complete file back
vpdFileStream.seekg(thisRecord.kwDataOffset, std::ios::beg);
iteratorToNewdata = kwdData.cbegin();
@@ -95,6 +107,7 @@
auto kwdDataEnd = itrToKWdData;
std::advance(kwdDataEnd, thisRecord.kwdDataLength);
std::copy(itrToKWdData, kwdDataEnd, thisRecord.kwdUpdatedData.begin());
+#endif
}
void EditorImpl::checkRecordForKwd()
@@ -172,9 +185,11 @@
auto end = itrToRecordECC;
std::advance(end, thisRecord.recECCLength);
+#ifndef ManagerTest
vpdFileStream.seekp(thisRecord.recECCoffset, std::ios::beg);
std::copy(itrToRecordECC, end,
std::ostreambuf_iterator<char>(vpdFileStream));
+#endif
}
auto EditorImpl::getValue(offsets::Offsets offset)
@@ -433,8 +448,11 @@
void EditorImpl::updateKeyword(const Binary& kwdData)
{
+
+#ifndef ManagerTest
vpdFileStream.open(vpdFilePath,
std::ios::in | std::ios::out | std::ios::binary);
+
if (!vpdFileStream)
{
throw std::runtime_error("unable to open vpd file to edit");
@@ -443,6 +461,13 @@
Binary completeVPDFile((std::istreambuf_iterator<char>(vpdFileStream)),
std::istreambuf_iterator<char>());
vpdFile = completeVPDFile;
+#else
+ Binary completeVPDFile = vpdFile;
+#endif
+ if (vpdFile.empty())
+ {
+ throw std::runtime_error("Invalid File");
+ }
auto iterator = vpdFile.cbegin();
std::advance(iterator, IPZ_DATA_START);
@@ -464,14 +489,12 @@
// update the ECC data for the record once data has been updated
updateRecordECC();
-
+#ifndef ManagerTest
// update the cache once data has been updated
updateCache();
-
+#endif
return;
}
-
- throw std::runtime_error("Invalid VPD file type");
}
} // namespace editor
diff --git a/vpd-manager/editor_impl.hpp b/vpd-manager/editor_impl.hpp
index ac8909c..b3d24f7 100644
--- a/vpd-manager/editor_impl.hpp
+++ b/vpd-manager/editor_impl.hpp
@@ -53,6 +53,17 @@
*
* @param[in] path - Path to the vpd file
*/
+ EditorImpl(const std::string& record, const std::string& kwd,
+ Binary&& vpd) :
+ thisRecord(record, kwd),
+ vpdFile(std::move(vpd))
+ {
+ }
+
+ /** @brief Construct EditorImpl class
+ *
+ * @param[in] path - Path to the vpd file
+ */
EditorImpl(const inventory::Path& path, const nlohmann::json& json,
const std::string& record, const std::string& kwd) :
vpdFilePath(path),
@@ -140,20 +151,20 @@
const std::string& property, const std::variant<T>& data);
// path to the VPD file to edit
- const inventory::Path& vpdFilePath;
+ const inventory::Path vpdFilePath;
// stream to perform operation on file
std::fstream vpdFileStream;
// file to store parsed json
- const nlohmann::json& jsonFile;
+ const nlohmann::json jsonFile;
// structure to hold info about record to edit
struct RecInfo
{
Binary kwdUpdatedData; // need access to it in case encoding is needed
- const std::string& recName;
- const std::string& recKWd;
+ const std::string recName;
+ const std::string recKWd;
openpower::vpd::constants::RecordOffset recOffset;
openpower::vpd::constants::ECCOffset recECCoffset;
std::size_t recECCLength;