blob: 8a01cb3a549504e9d1da24685a7ae09d5579014e [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:
Patrick Williams6da4f912023-05-10 07:50:53 -050011 MockBIOSStringTable() : BIOSStringTable({}) {}
John Wang29683b52020-02-27 16:41:44 +080012
13 MOCK_METHOD(uint16_t, findHandle, (const std::string&), (const override));
John Wang3be70852020-02-13 15:59:04 +080014
15 MOCK_METHOD(std::string, findString, (const uint16_t), (const override));
John Wang29683b52020-02-27 16:41:44 +080016};
17
Brad Bishop5079ac42021-08-19 18:35:06 -040018void checkHeader(const pldm::responder::bios::Table& attrEntry,
19 const pldm::responder::bios::Table& attrValueEntry)
John Wang29683b52020-02-27 16:41:44 +080020{
Brad Bishop5079ac42021-08-19 18:35:06 -040021 auto attrHeader = pldm::responder::bios::table::attribute::decodeHeader(
John Wang29683b52020-02-27 16:41:44 +080022 reinterpret_cast<const pldm_bios_attr_table_entry*>(attrEntry.data()));
Brad Bishop5079ac42021-08-19 18:35:06 -040023 auto attrValueHeader =
24 pldm::responder::bios::table::attribute_value::decodeHeader(
25 reinterpret_cast<const pldm_bios_attr_val_table_entry*>(
26 attrValueEntry.data()));
John Wang29683b52020-02-27 16:41:44 +080027
28 EXPECT_EQ(attrHeader.attrHandle, attrValueHeader.attrHandle);
29}
30
Brad Bishop5079ac42021-08-19 18:35:06 -040031void checkEntry(pldm::responder::bios::Table& entry,
32 pldm::responder::bios::Table& expectedEntry)
John Wang29683b52020-02-27 16:41:44 +080033{
34 /** backup the attr handle */
35 auto attr0 = entry[0], eAttr0 = expectedEntry[0];
36 auto attr1 = entry[1], eAttr1 = expectedEntry[1];
37
38 /** attr handle is computed by libpldm, set it to 0 to test */
39 entry[0] = 0, expectedEntry[0] = 0;
40 entry[1] = 0, expectedEntry[1] = 0;
41
42 EXPECT_THAT(entry, ElementsAreArray(expectedEntry));
43
44 /** restore the attr handle */
45 entry[0] = attr0, expectedEntry[0] = eAttr0;
46 entry[1] = attr1, expectedEntry[1] = eAttr1;
47}
48
Brad Bishop5079ac42021-08-19 18:35:06 -040049void checkConstructEntry(pldm::responder::bios::BIOSAttribute& attribute,
50 pldm::responder::bios::BIOSStringTable& stringTable,
51 pldm::responder::bios::Table& expectedAttrEntry,
52 pldm::responder::bios::Table& expectedAttrValueEntry)
John Wang29683b52020-02-27 16:41:44 +080053{
Brad Bishop5079ac42021-08-19 18:35:06 -040054 pldm::responder::bios::Table attrEntry, attrValueEntry;
John Wang29683b52020-02-27 16:41:44 +080055 attribute.constructEntry(stringTable, attrEntry, attrValueEntry);
56
57 checkHeader(attrEntry, attrValueEntry);
58 checkEntry(attrEntry, expectedAttrEntry);
59 checkEntry(attrValueEntry, expectedAttrValueEntry);
Patrick Williams6da4f912023-05-10 07:50:53 -050060}