blob: b8ff7328d322ecf7f9ca5eb326f1eea8e2aafb9a [file] [log] [blame]
Matt Spinler97f7abc2019-11-06 09:40:23 -06001/**
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 */
Matt Spinler1b5c72b2019-07-10 10:32:06 -050016
17#include "extensions/openpower-pels/section_header.hpp"
18
19#include <gtest/gtest.h>
20
21using namespace openpower::pels;
22
23TEST(SectionHeaderTest, SizeTest)
24{
25 EXPECT_EQ(SectionHeader::flattenedSize(), 8);
26}
27
28TEST(SectionHeaderTest, UnflattenTest)
29{
30 std::vector<uint8_t> data{0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88};
31 Stream reader{data};
32 SectionHeader header;
33
34 reader >> header;
35
36 EXPECT_EQ(header.id, 0x1122);
37 EXPECT_EQ(header.size, 0x3344);
38 EXPECT_EQ(header.version, 0x55);
39 EXPECT_EQ(header.subType, 0x66);
40 EXPECT_EQ(header.componentID, 0x7788);
41}
42
43TEST(SectionHeaderTest, FlattenTest)
44{
45 SectionHeader header{0xAABB, 0xCCDD, 0xEE, 0xFF, 0xA0A0};
46
47 std::vector<uint8_t> data;
48 Stream writer{data};
49
50 writer << header;
51
52 std::vector<uint8_t> expected{0xAA, 0xBB, 0xCC, 0xDD,
53 0xEE, 0xFF, 0xA0, 0xA0};
54 EXPECT_EQ(data, expected);
55}