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