blob: 568fad98d03687f11bc2aa7ed6c611f0573774a2 [file] [log] [blame]
John Wang29683b52020-02-27 16:41:44 +08001#include "libpldmresponder/bios_table.hpp"
2
3#include <gmock/gmock.h>
4#include <gtest/gtest.h>
5
6using testing::ElementsAreArray;
7using namespace pldm::responder::bios;
8
9class MockBIOSStringTable : public BIOSStringTable
10{
11 public:
12 MockBIOSStringTable() : BIOSStringTable({})
13 {
14 }
15
16 MOCK_METHOD(uint16_t, findHandle, (const std::string&), (const override));
John Wang3be70852020-02-13 15:59:04 +080017
18 MOCK_METHOD(std::string, findString, (const uint16_t), (const override));
John Wang29683b52020-02-27 16:41:44 +080019};
20
21void 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
32void 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
49void 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}