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