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