summaryrefslogtreecommitdiffstats
path: root/test/openpower-pels/ascii_string_test.cpp
blob: 96ee4ad5582263e6742f3baa23d04516157f4240 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/**
 * Copyright © 2019 IBM Corporation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include "extensions/openpower-pels/ascii_string.hpp"
#include "extensions/openpower-pels/registry.hpp"

#include <gtest/gtest.h>

using namespace openpower::pels;

TEST(AsciiStringTest, AsciiStringTest)
{
    // Build the ASCII string from a message registry entry
    message::Entry entry;
    entry.src.type = 0xBD;
    entry.src.reasonCode = 0xABCD;
    entry.subsystem = 0x37;

    src::AsciiString as{entry};

    auto data = as.get();

    EXPECT_EQ(data, "BD37ABCD                        ");

    // Now flatten it
    std::vector<uint8_t> flattenedData;
    Stream stream{flattenedData};

    as.flatten(stream);

    for (size_t i = 0; i < 32; i++)
    {
        EXPECT_EQ(data[i], flattenedData[i]);
    }
}

// A 0x11 power SRC doesn't have the subsystem in it
TEST(AsciiStringTest, PowerErrorTest)
{
    message::Entry entry;
    entry.src.type = 0x11;
    entry.src.reasonCode = 0xABCD;
    entry.subsystem = 0x37;

    src::AsciiString as{entry};
    auto data = as.get();

    EXPECT_EQ(data, "1100ABCD                        ");
}

TEST(AsciiStringTest, UnflattenTest)
{
    std::vector<uint8_t> rawData{'B', 'D', '5', '6', '1', '2', 'A', 'B'};

    for (int i = 8; i < 32; i++)
    {
        rawData.push_back(' ');
    }

    Stream stream{rawData};
    src::AsciiString as{stream};

    auto data = as.get();

    EXPECT_EQ(data, "BD5612AB                        ");
}

TEST(AsciiStringTest, UnderflowTest)
{
    std::vector<uint8_t> rawData{'B', 'D', '5', '6'};
    Stream stream{rawData};

    EXPECT_THROW(src::AsciiString as{stream}, std::out_of_range);
}
OpenPOWER on IntegriCloud