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/mtms.hpp" 17 18 #include <gtest/gtest.h> 19 20 using namespace openpower::pels; 21 22 TEST(MTMSTest, SizeTest) 23 { 24 EXPECT_EQ(MTMS::flattenedSize(), 20); 25 } 26 27 TEST(MTMSTest, ConstructorTest) 28 { 29 { 30 std::string tm{"TTTT-MMM"}; 31 std::string sn{"123456789ABC"}; 32 33 MTMS mtms{tm, sn}; 34 35 std::array<uint8_t, 8> t{'T', 'T', 'T', 'T', '-', 'M', 'M', 'M'}; 36 EXPECT_EQ(t, mtms.machineTypeAndModelRaw()); 37 EXPECT_EQ("TTTT-MMM", mtms.machineTypeAndModel()); 38 39 std::array<uint8_t, 12> s{'1', '2', '3', '4', '5', '6', 40 '7', '8', '9', 'A', 'B', 'C'}; 41 EXPECT_EQ(s, mtms.machineSerialNumberRaw()); 42 EXPECT_EQ("123456789ABC", mtms.machineSerialNumber()); 43 } 44 45 { 46 // too long- truncate it 47 std::string tm{"TTTT-MMME"}; 48 std::string sn{"123456789ABCE"}; 49 50 MTMS mtms{tm, sn}; 51 52 std::array<uint8_t, 8> t{'T', 'T', 'T', 'T', '-', 'M', 'M', 'M'}; 53 EXPECT_EQ(t, mtms.machineTypeAndModelRaw()); 54 55 std::array<uint8_t, 12> s{'1', '2', '3', '4', '5', '6', 56 '7', '8', '9', 'A', 'B', 'C'}; 57 EXPECT_EQ(s, mtms.machineSerialNumberRaw()); 58 } 59 60 { 61 // short 62 std::string tm{"TTTT"}; 63 std::string sn{"1234"}; 64 65 MTMS mtms{tm, sn}; 66 67 std::array<uint8_t, 8> t{'T', 'T', 'T', 'T', 0, 0, 0, 0}; 68 EXPECT_EQ(t, mtms.machineTypeAndModelRaw()); 69 EXPECT_EQ("TTTT", mtms.machineTypeAndModel()); 70 71 std::array<uint8_t, 12> s{'1', '2', '3', '4', 0, 0, 0, 0, 0, 0, 0, 0}; 72 EXPECT_EQ(s, mtms.machineSerialNumberRaw()); 73 EXPECT_EQ("1234", mtms.machineSerialNumber()); 74 } 75 76 { 77 // Stream constructor 78 std::vector<uint8_t> data{'T', 'T', 'T', 'T', '-', 'M', 'M', 79 'M', '1', '2', '3', '4', '5', '6', 80 '7', '8', '9', 'A', 'B', 'C'}; 81 Stream stream{data}; 82 83 MTMS mtms{stream}; 84 85 EXPECT_EQ("TTTT-MMM", mtms.machineTypeAndModel()); 86 87 EXPECT_EQ("123456789ABC", mtms.machineSerialNumber()); 88 } 89 } 90 91 TEST(MTMSTest, OperatorExtractTest) 92 { 93 std::string tm{"TTTT-MMM"}; 94 std::string sn{"123456789ABC"}; 95 96 MTMS mtms{tm, sn}; 97 98 // Check that we can extract the same data 99 std::vector<uint8_t> data; 100 Stream stream{data}; 101 stream << mtms; 102 103 std::vector<uint8_t> expected{'T', 'T', 'T', 'T', '-', 'M', 'M', 104 'M', '1', '2', '3', '4', '5', '6', 105 '7', '8', '9', 'A', 'B', 'C'}; 106 EXPECT_EQ(expected, data); 107 } 108 109 TEST(MTMSTest, OperatorInsertTest) 110 { 111 std::vector<uint8_t> data{'T', 'T', 'T', 'T', '-', 'M', 'M', 'M', '1', '2', 112 '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C'}; 113 Stream stream{data}; 114 115 // Check that when we insert data it is what's expected 116 MTMS mtms; 117 stream >> mtms; 118 119 EXPECT_EQ("TTTT-MMM", mtms.machineTypeAndModel()); 120 121 EXPECT_EQ("123456789ABC", mtms.machineSerialNumber()); 122 } 123