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