blob: 6741306332286212ab76d3d9d6e81fb4e2188837 [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({})
George Liu6492f522020-06-16 10:34:05 +080013 {}
John Wang29683b52020-02-27 16:41:44 +080014
15 MOCK_METHOD(uint16_t, findHandle, (const std::string&), (const override));
John Wang3be70852020-02-13 15:59:04 +080016
17 MOCK_METHOD(std::string, findString, (const uint16_t), (const override));
John Wang29683b52020-02-27 16:41:44 +080018};
19
20void checkHeader(const Table& attrEntry, const Table& attrValueEntry)
21{
22 auto attrHeader = table::attribute::decodeHeader(
23 reinterpret_cast<const pldm_bios_attr_table_entry*>(attrEntry.data()));
24 auto attrValueHeader = table::attribute_value::decodeHeader(
25 reinterpret_cast<const pldm_bios_attr_val_table_entry*>(
26 attrValueEntry.data()));
27
28 EXPECT_EQ(attrHeader.attrHandle, attrValueHeader.attrHandle);
29}
30
31void checkEntry(Table& entry, Table& expectedEntry)
32{
33 /** backup the attr handle */
34 auto attr0 = entry[0], eAttr0 = expectedEntry[0];
35 auto attr1 = entry[1], eAttr1 = expectedEntry[1];
36
37 /** attr handle is computed by libpldm, set it to 0 to test */
38 entry[0] = 0, expectedEntry[0] = 0;
39 entry[1] = 0, expectedEntry[1] = 0;
40
41 EXPECT_THAT(entry, ElementsAreArray(expectedEntry));
42
43 /** restore the attr handle */
44 entry[0] = attr0, expectedEntry[0] = eAttr0;
45 entry[1] = attr1, expectedEntry[1] = eAttr1;
46}
47
48void checkConstructEntry(BIOSAttribute& attribute, BIOSStringTable& stringTable,
49 Table& expectedAttrEntry,
50 Table& expectedAttrValueEntry)
51{
52 Table attrEntry, attrValueEntry;
53 attribute.constructEntry(stringTable, attrEntry, attrValueEntry);
54
55 checkHeader(attrEntry, attrValueEntry);
56 checkEntry(attrEntry, expectedAttrEntry);
57 checkEntry(attrValueEntry, expectedAttrValueEntry);
58}