summaryrefslogtreecommitdiff
path: root/test/redfish-core/lib/systems_logservices_postcode.cpp
blob: d41ccffa7d5b43800d5aac469019347b3c6ca989 (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
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright OpenBMC Authors

#include "systems_logservices_postcodes.hpp"

#include <cstdint>

#include <gtest/gtest.h>

namespace redfish
{
namespace
{

TEST(LogServicesPostCodeParse, PostCodeParse)
{
    uint64_t currentValue = 0;
    uint16_t index = 0;
    EXPECT_TRUE(parsePostCode("B1-2", currentValue, index));
    EXPECT_EQ(currentValue, 2);
    EXPECT_EQ(index, 1);
    EXPECT_TRUE(parsePostCode("B200-300", currentValue, index));
    EXPECT_EQ(currentValue, 300);
    EXPECT_EQ(index, 200);

    EXPECT_FALSE(parsePostCode("", currentValue, index));
    EXPECT_FALSE(parsePostCode("B", currentValue, index));
    EXPECT_FALSE(parsePostCode("B1", currentValue, index));
    EXPECT_FALSE(parsePostCode("B1-", currentValue, index));
    EXPECT_FALSE(parsePostCode("B1A-2", currentValue, index));
    EXPECT_FALSE(parsePostCode("B1A-2", currentValue, index));
    EXPECT_FALSE(parsePostCode("B1A-2z", currentValue, index));
    // Uint16_t max + 1
    EXPECT_FALSE(parsePostCode("B65536-1", currentValue, index));

    // Uint64_t max + 1
    EXPECT_FALSE(parsePostCode("B1-18446744073709551616", currentValue, index));

    // Negative numbers
    EXPECT_FALSE(parsePostCode("B-1-2", currentValue, index));
    EXPECT_FALSE(parsePostCode("B-1--2", currentValue, index));
}

} // namespace
} // namespace redfish