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)); |
| 17 | }; |
| 18 | |
| 19 | void checkHeader(const Table& attrEntry, const Table& attrValueEntry) |
| 20 | { |
| 21 | auto attrHeader = table::attribute::decodeHeader( |
| 22 | reinterpret_cast<const pldm_bios_attr_table_entry*>(attrEntry.data())); |
| 23 | auto attrValueHeader = table::attribute_value::decodeHeader( |
| 24 | reinterpret_cast<const pldm_bios_attr_val_table_entry*>( |
| 25 | attrValueEntry.data())); |
| 26 | |
| 27 | EXPECT_EQ(attrHeader.attrHandle, attrValueHeader.attrHandle); |
| 28 | } |
| 29 | |
| 30 | void checkEntry(Table& entry, Table& expectedEntry) |
| 31 | { |
| 32 | /** backup the attr handle */ |
| 33 | auto attr0 = entry[0], eAttr0 = expectedEntry[0]; |
| 34 | auto attr1 = entry[1], eAttr1 = expectedEntry[1]; |
| 35 | |
| 36 | /** attr handle is computed by libpldm, set it to 0 to test */ |
| 37 | entry[0] = 0, expectedEntry[0] = 0; |
| 38 | entry[1] = 0, expectedEntry[1] = 0; |
| 39 | |
| 40 | EXPECT_THAT(entry, ElementsAreArray(expectedEntry)); |
| 41 | |
| 42 | /** restore the attr handle */ |
| 43 | entry[0] = attr0, expectedEntry[0] = eAttr0; |
| 44 | entry[1] = attr1, expectedEntry[1] = eAttr1; |
| 45 | } |
| 46 | |
| 47 | void checkConstructEntry(BIOSAttribute& attribute, BIOSStringTable& stringTable, |
| 48 | Table& expectedAttrEntry, |
| 49 | Table& expectedAttrValueEntry) |
| 50 | { |
| 51 | Table attrEntry, attrValueEntry; |
| 52 | attribute.constructEntry(stringTable, attrEntry, attrValueEntry); |
| 53 | |
| 54 | checkHeader(attrEntry, attrValueEntry); |
| 55 | checkEntry(attrEntry, expectedAttrEntry); |
| 56 | checkEntry(attrValueEntry, expectedAttrValueEntry); |
| 57 | } |