blob: b9c09290f78444c7307a61cfbe6c5d845d421d63 [file] [log] [blame]
Matt Spinler97f7abc2019-11-06 09:40:23 -06001/**
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 */
Matt Spinlerb6664332019-09-10 15:24:10 -050016#include "extensions/openpower-pels/mtms.hpp"
17
18#include <gtest/gtest.h>
19
20using namespace openpower::pels;
21
22TEST(MTMSTest, SizeTest)
23{
24 EXPECT_EQ(MTMS::flattenedSize(), 20);
25}
26
27TEST(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'};
Matt Spinler4b59f7a2019-10-08 13:55:17 -050036 EXPECT_EQ(t, mtms.machineTypeAndModelRaw());
37 EXPECT_EQ("TTTT-MMM", mtms.machineTypeAndModel());
Matt Spinlerb6664332019-09-10 15:24:10 -050038
39 std::array<uint8_t, 12> s{'1', '2', '3', '4', '5', '6',
40 '7', '8', '9', 'A', 'B', 'C'};
Matt Spinler4b59f7a2019-10-08 13:55:17 -050041 EXPECT_EQ(s, mtms.machineSerialNumberRaw());
42 EXPECT_EQ("123456789ABC", mtms.machineSerialNumber());
Matt Spinlerb6664332019-09-10 15:24:10 -050043 }
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'};
Matt Spinler4b59f7a2019-10-08 13:55:17 -050053 EXPECT_EQ(t, mtms.machineTypeAndModelRaw());
Matt Spinlerb6664332019-09-10 15:24:10 -050054
55 std::array<uint8_t, 12> s{'1', '2', '3', '4', '5', '6',
56 '7', '8', '9', 'A', 'B', 'C'};
Matt Spinler4b59f7a2019-10-08 13:55:17 -050057 EXPECT_EQ(s, mtms.machineSerialNumberRaw());
Matt Spinlerb6664332019-09-10 15:24:10 -050058 }
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};
Matt Spinler4b59f7a2019-10-08 13:55:17 -050068 EXPECT_EQ(t, mtms.machineTypeAndModelRaw());
69 EXPECT_EQ("TTTT", mtms.machineTypeAndModel());
Matt Spinlerb6664332019-09-10 15:24:10 -050070
71 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 -050072 EXPECT_EQ(s, mtms.machineSerialNumberRaw());
73 EXPECT_EQ("1234", mtms.machineSerialNumber());
Matt Spinlerb6664332019-09-10 15:24:10 -050074 }
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
Matt Spinler4b59f7a2019-10-08 13:55:17 -050085 EXPECT_EQ("TTTT-MMM", mtms.machineTypeAndModel());
Matt Spinlerb6664332019-09-10 15:24:10 -050086
Matt Spinler4b59f7a2019-10-08 13:55:17 -050087 EXPECT_EQ("123456789ABC", mtms.machineSerialNumber());
Matt Spinlerb6664332019-09-10 15:24:10 -050088 }
89}
90
91TEST(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
109TEST(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
Matt Spinler4b59f7a2019-10-08 13:55:17 -0500119 EXPECT_EQ("TTTT-MMM", mtms.machineTypeAndModel());
Matt Spinlerb6664332019-09-10 15:24:10 -0500120
Matt Spinler4b59f7a2019-10-08 13:55:17 -0500121 EXPECT_EQ("123456789ABC", mtms.machineSerialNumber());
Matt Spinlerb6664332019-09-10 15:24:10 -0500122}