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