1 #include "libpldmresponder/bios_table.hpp"
2 
3 #include <gmock/gmock.h>
4 #include <gtest/gtest.h>
5 
6 using testing::ElementsAreArray;
7 using namespace pldm::responder::bios;
8 
9 class MockBIOSStringTable : public BIOSStringTable
10 {
11   public:
12     MockBIOSStringTable() : BIOSStringTable({})
13     {}
14 
15     MOCK_METHOD(uint16_t, findHandle, (const std::string&), (const override));
16 
17     MOCK_METHOD(std::string, findString, (const uint16_t), (const override));
18 };
19 
20 void checkHeader(const Table& attrEntry, const Table& attrValueEntry)
21 {
22     auto attrHeader = table::attribute::decodeHeader(
23         reinterpret_cast<const pldm_bios_attr_table_entry*>(attrEntry.data()));
24     auto attrValueHeader = 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(Table& entry, Table& expectedEntry)
32 {
33     /** backup the attr handle */
34     auto attr0 = entry[0], eAttr0 = expectedEntry[0];
35     auto attr1 = entry[1], eAttr1 = expectedEntry[1];
36 
37     /** attr handle is computed by libpldm, set it to 0 to test */
38     entry[0] = 0, expectedEntry[0] = 0;
39     entry[1] = 0, expectedEntry[1] = 0;
40 
41     EXPECT_THAT(entry, ElementsAreArray(expectedEntry));
42 
43     /** restore the attr handle */
44     entry[0] = attr0, expectedEntry[0] = eAttr0;
45     entry[1] = attr1, expectedEntry[1] = eAttr1;
46 }
47 
48 void checkConstructEntry(BIOSAttribute& attribute, BIOSStringTable& stringTable,
49                          Table& expectedAttrEntry,
50                          Table& expectedAttrValueEntry)
51 {
52     Table attrEntry, attrValueEntry;
53     attribute.constructEntry(stringTable, attrEntry, attrValueEntry);
54 
55     checkHeader(attrEntry, attrValueEntry);
56     checkEntry(attrEntry, expectedAttrEntry);
57     checkEntry(attrValueEntry, expectedAttrValueEntry);
58 }