blob: eb95c3302b89df42476e107eb823bd2b5e81a875 [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));
17};
18
19void 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
30void 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
47void 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}