1 #include "extensions/openpower-pels/pce_identity.hpp" 2 3 #include <gtest/gtest.h> 4 5 using namespace openpower::pels; 6 using namespace openpower::pels::src; 7 8 TEST(PCEIdentityTest, TestConstructor) 9 { 10 std::vector<uint8_t> data{ 11 'P', 'E', 0x24, 0x00, // type, size, flags 12 'T', 'T', 'T', 'T', '-', 'M', 'M', 'M', // MTM 13 '1', '2', '3', '4', '5', '6', '7', // SN 14 '8', '9', 'A', 'B', 'C', 'P', 'C', 'E', // Name + null padded 15 'N', 'A', 'M', 'E', '1', '2', 0x00, 0x00, 0x00}; 16 17 Stream stream{data}; 18 19 PCEIdentity pce{stream}; 20 21 EXPECT_EQ(pce.flattenedSize(), data.size()); 22 EXPECT_EQ(pce.enclosureName(), "PCENAME12"); 23 EXPECT_EQ(pce.mtms().machineTypeAndModel(), "TTTT-MMM"); 24 EXPECT_EQ(pce.mtms().machineSerialNumber(), "123456789ABC"); 25 26 // Flatten it 27 std::vector<uint8_t> newData; 28 Stream newStream{newData}; 29 pce.flatten(newStream); 30 31 EXPECT_EQ(data, newData); 32 } 33 34 TEST(PCEIdentityTest, TestBadData) 35 { 36 std::vector<uint8_t> data{ 37 'P', 'E', 0x20, 0x00, 'T', 'T', 'T', 'T', '-', 38 }; 39 40 Stream stream{data}; 41 EXPECT_THROW(PCEIdentity pce{stream}, std::out_of_range); 42 } 43