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; |
| 7 | using namespace pldm::responder::bios; |
| 8 | |
| 9 | class MockBIOSStringTable : public BIOSStringTable |
| 10 | { |
| 11 | public: |
| 12 | MockBIOSStringTable() : BIOSStringTable({}) |
| 13 | { |
| 14 | } |
| 15 | |
| 16 | MOCK_METHOD(uint16_t, findHandle, (const std::string&), (const override)); |
John Wang | 3be7085 | 2020-02-13 15:59:04 +0800 | [diff] [blame] | 17 | |
| 18 | MOCK_METHOD(std::string, findString, (const uint16_t), (const override)); |
John Wang | 29683b5 | 2020-02-27 16:41:44 +0800 | [diff] [blame] | 19 | }; |
| 20 | |
| 21 | void checkHeader(const Table& attrEntry, const Table& attrValueEntry) |
| 22 | { |
| 23 | auto attrHeader = table::attribute::decodeHeader( |
| 24 | reinterpret_cast<const pldm_bios_attr_table_entry*>(attrEntry.data())); |
| 25 | auto attrValueHeader = 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(Table& entry, 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(BIOSAttribute& attribute, BIOSStringTable& stringTable, |
| 50 | Table& expectedAttrEntry, |
| 51 | Table& expectedAttrValueEntry) |
| 52 | { |
| 53 | Table attrEntry, attrValueEntry; |
| 54 | attribute.constructEntry(stringTable, attrEntry, attrValueEntry); |
| 55 | |
| 56 | checkHeader(attrEntry, attrValueEntry); |
| 57 | checkEntry(attrEntry, expectedAttrEntry); |
| 58 | checkEntry(attrValueEntry, expectedAttrValueEntry); |
| 59 | } |