blob: 2290374212bd6a6e8da323fb57dc615b54994549 [file] [log] [blame]
Matt Spinlerb6664332019-09-10 15:24:10 -05001#include "extensions/openpower-pels/mtms.hpp"
2
3#include <gtest/gtest.h>
4
5using namespace openpower::pels;
6
7TEST(MTMSTest, SizeTest)
8{
9 EXPECT_EQ(MTMS::flattenedSize(), 20);
10}
11
12TEST(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 Spinler4b59f7a2019-10-08 13:55:17 -050021 EXPECT_EQ(t, mtms.machineTypeAndModelRaw());
22 EXPECT_EQ("TTTT-MMM", mtms.machineTypeAndModel());
Matt Spinlerb6664332019-09-10 15:24:10 -050023
24 std::array<uint8_t, 12> s{'1', '2', '3', '4', '5', '6',
25 '7', '8', '9', 'A', 'B', 'C'};
Matt Spinler4b59f7a2019-10-08 13:55:17 -050026 EXPECT_EQ(s, mtms.machineSerialNumberRaw());
27 EXPECT_EQ("123456789ABC", mtms.machineSerialNumber());
Matt Spinlerb6664332019-09-10 15:24:10 -050028 }
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 Spinler4b59f7a2019-10-08 13:55:17 -050038 EXPECT_EQ(t, mtms.machineTypeAndModelRaw());
Matt Spinlerb6664332019-09-10 15:24:10 -050039
40 std::array<uint8_t, 12> s{'1', '2', '3', '4', '5', '6',
41 '7', '8', '9', 'A', 'B', 'C'};
Matt Spinler4b59f7a2019-10-08 13:55:17 -050042 EXPECT_EQ(s, mtms.machineSerialNumberRaw());
Matt Spinlerb6664332019-09-10 15:24:10 -050043 }
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 Spinler4b59f7a2019-10-08 13:55:17 -050053 EXPECT_EQ(t, mtms.machineTypeAndModelRaw());
54 EXPECT_EQ("TTTT", mtms.machineTypeAndModel());
Matt Spinlerb6664332019-09-10 15:24:10 -050055
56 std::array<uint8_t, 12> s{'1', '2', '3', '4', 0, 0, 0, 0, 0, 0, 0, 0};
Matt Spinler4b59f7a2019-10-08 13:55:17 -050057 EXPECT_EQ(s, mtms.machineSerialNumberRaw());
58 EXPECT_EQ("1234", mtms.machineSerialNumber());
Matt Spinlerb6664332019-09-10 15:24:10 -050059 }
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 Spinler4b59f7a2019-10-08 13:55:17 -050070 EXPECT_EQ("TTTT-MMM", mtms.machineTypeAndModel());
Matt Spinlerb6664332019-09-10 15:24:10 -050071
Matt Spinler4b59f7a2019-10-08 13:55:17 -050072 EXPECT_EQ("123456789ABC", mtms.machineSerialNumber());
Matt Spinlerb6664332019-09-10 15:24:10 -050073 }
74}
75
76TEST(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
94TEST(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 Spinler4b59f7a2019-10-08 13:55:17 -0500104 EXPECT_EQ("TTTT-MMM", mtms.machineTypeAndModel());
Matt Spinlerb6664332019-09-10 15:24:10 -0500105
Matt Spinler4b59f7a2019-10-08 13:55:17 -0500106 EXPECT_EQ("123456789ABC", mtms.machineSerialNumber());
Matt Spinlerb6664332019-09-10 15:24:10 -0500107}