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 17 #include "extensions/openpower-pels/section_header.hpp" 18 19 #include <gtest/gtest.h> 20 21 using namespace openpower::pels; 22 23 TEST(SectionHeaderTest, SizeTest) 24 { 25 EXPECT_EQ(SectionHeader::flattenedSize(), 8); 26 } 27 28 TEST(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 43 TEST(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 } 56