diff options
author | Ed Tanous <ed@tanous.net> | 2024-04-07 23:35:51 +0300 |
---|---|---|
committer | Ed Tanous <ed@tanous.net> | 2024-04-11 23:25:04 +0300 |
commit | 6f056f246d9bcfd611102ee712d4a2935504b448 (patch) | |
tree | 4741f732fb0853fd10d89b24c6c94053baa68cbd /test/redfish-core | |
parent | 8d45b9cbd583312fa45aa9e5cb4d41dd0cb17afa (diff) | |
download | bmcweb-6f056f246d9bcfd611102ee712d4a2935504b448.tar.xz |
Fix post code parsing
If we use string_view with std::from_chars, we can use begin() and end()
directly (because they return pointers) and not have to do silly things
like dereference end(), which, while works in practice, is technically
undefined behavior, and some static analyzers complain about it.
Tested: Unit tests pass against both old parsePostCode and new.
Change-Id: Icfdec3b81f4a9c9bed3599571a8bc8779f9bfb98
Signed-off-by: Ed Tanous <ed@tanous.net>
Diffstat (limited to 'test/redfish-core')
-rw-r--r-- | test/redfish-core/lib/log_services_test.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/test/redfish-core/lib/log_services_test.cpp b/test/redfish-core/lib/log_services_test.cpp index 631e3d159f..5dc04c8863 100644 --- a/test/redfish-core/lib/log_services_test.cpp +++ b/test/redfish-core/lib/log_services_test.cpp @@ -63,5 +63,34 @@ TEST(LogServicesBMCJouralTest, LogServicesBMCJouralGetReturnsError) EXPECT_EQ(indexOut, indexIn); } +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 |