1 /**
2  * Copyright © 2019 IBM Corporation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #include "extensions/openpower-pels/generic.hpp"
17 #include "pel_utils.hpp"
18 
19 #include <gtest/gtest.h>
20 
21 using namespace openpower::pels;
22 
23 TEST(GenericSectionTest, UnflattenFlattenTest)
24 {
25     // Use the private header data
26     auto data = pelDataFactory(TestPELType::privateHeaderSection);
27 
28     Stream stream(data);
29     Generic section(stream);
30 
31     EXPECT_EQ(section.header().id, 0x5048);
32     EXPECT_EQ(section.header().size, data.size());
33     EXPECT_EQ(section.header().version, 0x01);
34     EXPECT_EQ(section.header().subType, 0x02);
35     EXPECT_EQ(section.header().componentID, 0x0304);
36 
37     const auto& sectionData = section.data();
38 
39     // The data itself starts after the header
40     EXPECT_EQ(sectionData.size(), data.size() - 8);
41 
42     for (size_t i = 0; i < sectionData.size(); i++)
43     {
44         EXPECT_EQ(sectionData[i], (data)[i + 8]);
45     }
46 
47     // Now flatten
48     std::vector<uint8_t> newData;
49     Stream newStream(newData);
50     section.flatten(newStream);
51 
52     EXPECT_EQ(data, newData);
53 }
54 
55 TEST(GenericSectionTest, BadDataTest)
56 {
57     // Use the private header data to start with
58     auto data = pelDataFactory(TestPELType::privateHeaderSection);
59     data.resize(4);
60 
61     Stream stream(data);
62     Generic section(stream);
63     ASSERT_FALSE(section.valid());
64 }
65