blob: c93d788d574b7cdab14000a6ffb44868d4f722bd [file] [log] [blame]
John Wang29683b52020-02-27 16:41:44 +08001#include "libpldmresponder/bios_table.hpp"
2
3#include <gmock/gmock.h>
4#include <gtest/gtest.h>
5
6using testing::ElementsAreArray;
John Wang29683b52020-02-27 16:41:44 +08007
Brad Bishop5079ac42021-08-19 18:35:06 -04008class MockBIOSStringTable : public pldm::responder::bios::BIOSStringTable
John Wang29683b52020-02-27 16:41:44 +08009{
10 public:
11 MockBIOSStringTable() : BIOSStringTable({})
George Liu6492f522020-06-16 10:34:05 +080012 {}
John Wang29683b52020-02-27 16:41:44 +080013
14 MOCK_METHOD(uint16_t, findHandle, (const std::string&), (const override));
John Wang3be70852020-02-13 15:59:04 +080015
16 MOCK_METHOD(std::string, findString, (const uint16_t), (const override));
John Wang29683b52020-02-27 16:41:44 +080017};
18
Brad Bishop5079ac42021-08-19 18:35:06 -040019void checkHeader(const pldm::responder::bios::Table& attrEntry,
20 const pldm::responder::bios::Table& attrValueEntry)
John Wang29683b52020-02-27 16:41:44 +080021{
Brad Bishop5079ac42021-08-19 18:35:06 -040022 auto attrHeader = pldm::responder::bios::table::attribute::decodeHeader(
John Wang29683b52020-02-27 16:41:44 +080023 reinterpret_cast<const pldm_bios_attr_table_entry*>(attrEntry.data()));
Brad Bishop5079ac42021-08-19 18:35:06 -040024 auto attrValueHeader =
25 pldm::responder::bios::table::attribute_value::decodeHeader(
26 reinterpret_cast<const pldm_bios_attr_val_table_entry*>(
27 attrValueEntry.data()));
John Wang29683b52020-02-27 16:41:44 +080028
29 EXPECT_EQ(attrHeader.attrHandle, attrValueHeader.attrHandle);
30}
31
Brad Bishop5079ac42021-08-19 18:35:06 -040032void checkEntry(pldm::responder::bios::Table& entry,
33 pldm::responder::bios::Table& expectedEntry)
John Wang29683b52020-02-27 16:41:44 +080034{
35 /** backup the attr handle */
36 auto attr0 = entry[0], eAttr0 = expectedEntry[0];
37 auto attr1 = entry[1], eAttr1 = expectedEntry[1];
38
39 /** attr handle is computed by libpldm, set it to 0 to test */
40 entry[0] = 0, expectedEntry[0] = 0;
41 entry[1] = 0, expectedEntry[1] = 0;
42
43 EXPECT_THAT(entry, ElementsAreArray(expectedEntry));
44
45 /** restore the attr handle */
46 entry[0] = attr0, expectedEntry[0] = eAttr0;
47 entry[1] = attr1, expectedEntry[1] = eAttr1;
48}
49
Brad Bishop5079ac42021-08-19 18:35:06 -040050void checkConstructEntry(pldm::responder::bios::BIOSAttribute& attribute,
51 pldm::responder::bios::BIOSStringTable& stringTable,
52 pldm::responder::bios::Table& expectedAttrEntry,
53 pldm::responder::bios::Table& expectedAttrValueEntry)
John Wang29683b52020-02-27 16:41:44 +080054{
Brad Bishop5079ac42021-08-19 18:35:06 -040055 pldm::responder::bios::Table attrEntry, attrValueEntry;
John Wang29683b52020-02-27 16:41:44 +080056 attribute.constructEntry(stringTable, attrEntry, attrValueEntry);
57
58 checkHeader(attrEntry, attrValueEntry);
59 checkEntry(attrEntry, expectedAttrEntry);
60 checkEntry(attrValueEntry, expectedAttrValueEntry);
61}