blob: 9fb6d9abdde566e255aea0a1abbda17babf34b96 [file] [log] [blame]
Matt Spinler14d671f2019-09-25 13:11:22 -05001#include "extensions/openpower-pels/generic.hpp"
2#include "pel_utils.hpp"
3
4#include <gtest/gtest.h>
5
6using namespace openpower::pels;
7
8TEST(GenericSectionTest, UnflattenFlattenTest)
9{
10 // Use the private header data
11 auto data = pelDataFactory(TestPelType::privateHeaderSimple);
12
13 Stream stream(*data);
14 Generic section(stream);
15
16 EXPECT_EQ(section.header().id, 0x5048);
17 EXPECT_EQ(section.header().size, data->size());
18 EXPECT_EQ(section.header().version, 0x01);
19 EXPECT_EQ(section.header().subType, 0x02);
20 EXPECT_EQ(section.header().componentID, 0x0304);
21
22 const auto& sectionData = section.data();
23
24 // The data itself starts after the header
25 EXPECT_EQ(sectionData.size(), data->size() - 8);
26
27 for (size_t i = 0; i < sectionData.size(); i++)
28 {
29 EXPECT_EQ(sectionData[i], (*data)[i + 8]);
30 }
31
32 // Now flatten
33 std::vector<uint8_t> newData;
34 Stream newStream(newData);
35 section.flatten(newStream);
36
37 EXPECT_EQ(*data, newData);
38}
39
40TEST(GenericSectionTest, BadDataTest)
41{
42 // Use the private header data to start with
43 auto data = pelDataFactory(TestPelType::privateHeaderSimple);
44 data->resize(4);
45
46 Stream stream(*data);
47 Generic section(stream);
48 ASSERT_FALSE(section.valid());
49}