bios: Implement BIOSStringAttribute
Implement BIOSStringAttribute, most of the code is copied from
bios/bios_parser.cpp.
Implement SetAttrValueOnDbus and constructEntry for string attribute
Signed-off-by: John Wang <wangzqbj@inspur.com>
Change-Id: Ic7c6b35d32738d698d7649f97cb7843606b8a2ba
diff --git a/test/mocked_bios.hpp b/test/mocked_bios.hpp
new file mode 100644
index 0000000..eb95c33
--- /dev/null
+++ b/test/mocked_bios.hpp
@@ -0,0 +1,57 @@
+#include "libpldmresponder/bios_table.hpp"
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+using testing::ElementsAreArray;
+using namespace pldm::responder::bios;
+
+class MockBIOSStringTable : public BIOSStringTable
+{
+ public:
+ MockBIOSStringTable() : BIOSStringTable({})
+ {
+ }
+
+ MOCK_METHOD(uint16_t, findHandle, (const std::string&), (const override));
+};
+
+void checkHeader(const Table& attrEntry, const Table& attrValueEntry)
+{
+ auto attrHeader = table::attribute::decodeHeader(
+ reinterpret_cast<const pldm_bios_attr_table_entry*>(attrEntry.data()));
+ auto attrValueHeader = table::attribute_value::decodeHeader(
+ reinterpret_cast<const pldm_bios_attr_val_table_entry*>(
+ attrValueEntry.data()));
+
+ EXPECT_EQ(attrHeader.attrHandle, attrValueHeader.attrHandle);
+}
+
+void checkEntry(Table& entry, Table& expectedEntry)
+{
+ /** backup the attr handle */
+ auto attr0 = entry[0], eAttr0 = expectedEntry[0];
+ auto attr1 = entry[1], eAttr1 = expectedEntry[1];
+
+ /** attr handle is computed by libpldm, set it to 0 to test */
+ entry[0] = 0, expectedEntry[0] = 0;
+ entry[1] = 0, expectedEntry[1] = 0;
+
+ EXPECT_THAT(entry, ElementsAreArray(expectedEntry));
+
+ /** restore the attr handle */
+ entry[0] = attr0, expectedEntry[0] = eAttr0;
+ entry[1] = attr1, expectedEntry[1] = eAttr1;
+}
+
+void checkConstructEntry(BIOSAttribute& attribute, BIOSStringTable& stringTable,
+ Table& expectedAttrEntry,
+ Table& expectedAttrValueEntry)
+{
+ Table attrEntry, attrValueEntry;
+ attribute.constructEntry(stringTable, attrEntry, attrValueEntry);
+
+ checkHeader(attrEntry, attrValueEntry);
+ checkEntry(attrEntry, expectedAttrEntry);
+ checkEntry(attrValueEntry, expectedAttrValueEntry);
+}
\ No newline at end of file