1 // SPDX-License-Identifier: Apache-2.0
2 // SPDX-FileCopyrightText: Copyright OpenBMC Authors
3
4 #include "systems_logservices_postcodes.hpp"
5
6 #include <cstdint>
7
8 #include <gtest/gtest.h>
9
10 namespace redfish
11 {
12 namespace
13 {
14
TEST(LogServicesPostCodeParse,PostCodeParse)15 TEST(LogServicesPostCodeParse, PostCodeParse)
16 {
17 uint64_t currentValue = 0;
18 uint16_t index = 0;
19 EXPECT_TRUE(parsePostCode("B1-2", currentValue, index));
20 EXPECT_EQ(currentValue, 2);
21 EXPECT_EQ(index, 1);
22 EXPECT_TRUE(parsePostCode("B200-300", currentValue, index));
23 EXPECT_EQ(currentValue, 300);
24 EXPECT_EQ(index, 200);
25
26 EXPECT_FALSE(parsePostCode("", currentValue, index));
27 EXPECT_FALSE(parsePostCode("B", currentValue, index));
28 EXPECT_FALSE(parsePostCode("B1", currentValue, index));
29 EXPECT_FALSE(parsePostCode("B1-", currentValue, index));
30 EXPECT_FALSE(parsePostCode("B1A-2", currentValue, index));
31 EXPECT_FALSE(parsePostCode("B1A-2", currentValue, index));
32 EXPECT_FALSE(parsePostCode("B1A-2z", currentValue, index));
33 // Uint16_t max + 1
34 EXPECT_FALSE(parsePostCode("B65536-1", currentValue, index));
35
36 // Uint64_t max + 1
37 EXPECT_FALSE(parsePostCode("B1-18446744073709551616", currentValue, index));
38
39 // Negative numbers
40 EXPECT_FALSE(parsePostCode("B-1-2", currentValue, index));
41 EXPECT_FALSE(parsePostCode("B-1--2", currentValue, index));
42 }
43
44 } // namespace
45 } // namespace redfish
46