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