John Wang | 29683b5 | 2020-02-27 16:41:44 +0800 | [diff] [blame] | 1 | #include "libpldmresponder/bios_table.hpp" |
| 2 | |
| 3 | #include <gmock/gmock.h> |
| 4 | #include <gtest/gtest.h> |
| 5 | |
| 6 | using testing::ElementsAreArray; |
John Wang | 29683b5 | 2020-02-27 16:41:44 +0800 | [diff] [blame] | 7 | |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 8 | class MockBIOSStringTable : public pldm::responder::bios::BIOSStringTable |
John Wang | 29683b5 | 2020-02-27 16:41:44 +0800 | [diff] [blame] | 9 | { |
| 10 | public: |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame^] | 11 | MockBIOSStringTable() : BIOSStringTable({}) {} |
John Wang | 29683b5 | 2020-02-27 16:41:44 +0800 | [diff] [blame] | 12 | |
| 13 | MOCK_METHOD(uint16_t, findHandle, (const std::string&), (const override)); |
John Wang | 3be7085 | 2020-02-13 15:59:04 +0800 | [diff] [blame] | 14 | |
| 15 | MOCK_METHOD(std::string, findString, (const uint16_t), (const override)); |
John Wang | 29683b5 | 2020-02-27 16:41:44 +0800 | [diff] [blame] | 16 | }; |
| 17 | |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 18 | void checkHeader(const pldm::responder::bios::Table& attrEntry, |
| 19 | const pldm::responder::bios::Table& attrValueEntry) |
John Wang | 29683b5 | 2020-02-27 16:41:44 +0800 | [diff] [blame] | 20 | { |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 21 | auto attrHeader = pldm::responder::bios::table::attribute::decodeHeader( |
John Wang | 29683b5 | 2020-02-27 16:41:44 +0800 | [diff] [blame] | 22 | reinterpret_cast<const pldm_bios_attr_table_entry*>(attrEntry.data())); |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 23 | auto attrValueHeader = |
| 24 | pldm::responder::bios::table::attribute_value::decodeHeader( |
| 25 | reinterpret_cast<const pldm_bios_attr_val_table_entry*>( |
| 26 | attrValueEntry.data())); |
John Wang | 29683b5 | 2020-02-27 16:41:44 +0800 | [diff] [blame] | 27 | |
| 28 | EXPECT_EQ(attrHeader.attrHandle, attrValueHeader.attrHandle); |
| 29 | } |
| 30 | |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 31 | void checkEntry(pldm::responder::bios::Table& entry, |
| 32 | pldm::responder::bios::Table& expectedEntry) |
John Wang | 29683b5 | 2020-02-27 16:41:44 +0800 | [diff] [blame] | 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 | |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 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) |
John Wang | 29683b5 | 2020-02-27 16:41:44 +0800 | [diff] [blame] | 53 | { |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 54 | pldm::responder::bios::Table attrEntry, attrValueEntry; |
John Wang | 29683b5 | 2020-02-27 16:41:44 +0800 | [diff] [blame] | 55 | attribute.constructEntry(stringTable, attrEntry, attrValueEntry); |
| 56 | |
| 57 | checkHeader(attrEntry, attrValueEntry); |
| 58 | checkEntry(attrEntry, expectedAttrEntry); |
| 59 | checkEntry(attrValueEntry, expectedAttrValueEntry); |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame^] | 60 | } |