1 #include "libpldmresponder/bios_table.hpp"
2 
3 #include <gmock/gmock.h>
4 #include <gtest/gtest.h>
5 
6 using testing::ElementsAreArray;
7 
8 class MockBIOSStringTable : public pldm::responder::bios::BIOSStringTable
9 {
10   public:
11     MockBIOSStringTable() : BIOSStringTable({}) {}
12 
13     MOCK_METHOD(uint16_t, findHandle, (const std::string&), (const override));
14 
15     MOCK_METHOD(std::string, findString, (const uint16_t), (const override));
16 };
17 
18 void checkHeader(const pldm::responder::bios::Table& attrEntry,
19                  const pldm::responder::bios::Table& attrValueEntry)
20 {
21     auto attrHeader = pldm::responder::bios::table::attribute::decodeHeader(
22         reinterpret_cast<const pldm_bios_attr_table_entry*>(attrEntry.data()));
23     auto attrValueHeader =
24         pldm::responder::bios::table::attribute_value::decodeHeader(
25             reinterpret_cast<const pldm_bios_attr_val_table_entry*>(
26                 attrValueEntry.data()));
27 
28     EXPECT_EQ(attrHeader.attrHandle, attrValueHeader.attrHandle);
29 }
30 
31 void checkEntry(pldm::responder::bios::Table& entry,
32                 pldm::responder::bios::Table& expectedEntry)
33 {
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 
49 void checkConstructEntry(pldm::responder::bios::BIOSAttribute& attribute,
50                          pldm::responder::bios::BIOSStringTable& stringTable,
51                          pldm::responder::bios::Table& expectedAttrEntry,
52                          pldm::responder::bios::Table& expectedAttrValueEntry)
53 {
54     pldm::responder::bios::Table attrEntry, attrValueEntry;
55     attribute.constructEntry(stringTable, attrEntry, attrValueEntry);
56 
57     checkHeader(attrEntry, attrValueEntry);
58     checkEntry(attrEntry, expectedAttrEntry);
59     checkEntry(attrValueEntry, expectedAttrValueEntry);
60 }
61