blob: 022620d1fbbf8aec8d4ec5c3d6d7f6d30fac41f1 [file] [log] [blame]
Matt Spinler6852d722019-09-30 15:35:53 -05001#include "extensions/openpower-pels/ascii_string.hpp"
2#include "extensions/openpower-pels/registry.hpp"
3
4#include <gtest/gtest.h>
5
6using namespace openpower::pels;
7
8TEST(AsciiStringTest, AsciiStringTest)
9{
10 // Build the ASCII string from a message registry entry
11 message::Entry entry;
12 entry.src.type = 0xBD;
13 entry.src.reasonCode = 0xABCD;
14 entry.subsystem = 0x37;
15
16 src::AsciiString as{entry};
17
18 auto data = as.get();
19
20 EXPECT_EQ(data, "BD37ABCD ");
21
22 // Now flatten it
23 std::vector<uint8_t> flattenedData;
24 Stream stream{flattenedData};
25
26 as.flatten(stream);
27
28 for (size_t i = 0; i < 32; i++)
29 {
30 EXPECT_EQ(data[i], flattenedData[i]);
31 }
32}
33
34// A 0x11 power SRC doesn't have the subsystem in it
35TEST(AsciiStringTest, PowerErrorTest)
36{
37 message::Entry entry;
38 entry.src.type = 0x11;
39 entry.src.reasonCode = 0xABCD;
40 entry.subsystem = 0x37;
41
42 src::AsciiString as{entry};
43 auto data = as.get();
44
45 EXPECT_EQ(data, "1100ABCD ");
46}
47
48TEST(AsciiStringTest, UnflattenTest)
49{
50 std::vector<uint8_t> rawData{'B', 'D', '5', '6', '1', '2', 'A', 'B'};
51
52 for (int i = 8; i < 32; i++)
53 {
54 rawData.push_back(' ');
55 }
56
57 Stream stream{rawData};
58 src::AsciiString as{stream};
59
60 auto data = as.get();
61
62 EXPECT_EQ(data, "BD5612AB ");
63}
64
65TEST(AsciiStringTest, UnderflowTest)
66{
67 std::vector<uint8_t> rawData{'B', 'D', '5', '6'};
68 Stream stream{rawData};
69
70 EXPECT_THROW(src::AsciiString as{stream}, std::out_of_range);
71}