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