util: enhance MAC address parsing
Current ether_aton does not support the MAC string without colons.
Add extra conversion when string length equal to 12.
Test log:
1/7 config_parser OK 0.01s
2/7 neighbor OK 0.01s
3/7 netlink OK 0.01s
4/7 util OK 0.01s
5/7 network_manager OK 0.01s
6/7 ethernet_interface OK 0.01s
7/7 vlan_interface OK 0.01s
Ok: 7
Expected Fail: 0
Fail: 0
Unexpected Pass: 0
Skipped: 0
Timeout: 0
Signed-off-by: Potin Lai <potin.lai@quantatw.com>
Change-Id: Id2125af85f1c3d75424ff6ea0980c1460614f14e
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
diff --git a/test/test_util.cpp b/test/test_util.cpp
index d335adc..fc895cf 100644
--- a/test/test_util.cpp
+++ b/test/test_util.cpp
@@ -269,6 +269,9 @@
EXPECT_THROW(fromString("0x:00:00:00:00:00"), std::invalid_argument);
EXPECT_THROW(fromString("00:00:00:00:00"), std::invalid_argument);
EXPECT_THROW(fromString(""), std::invalid_argument);
+ EXPECT_THROW(fromString("123456789XYZ"), std::invalid_argument);
+ EXPECT_THROW(fromString("123456789AB"), std::invalid_argument);
+ EXPECT_THROW(fromString("123456789ABCD"), std::invalid_argument);
}
TEST(MacFromString, Valid)
@@ -281,6 +284,12 @@
EXPECT_TRUE(
stdplus::raw::equal(ether_addr{0x00, 0x01, 0x02, 0x03, 0x04, 0x05},
fromString("0:1:2:3:4:5")));
+ EXPECT_TRUE(
+ stdplus::raw::equal(ether_addr{0x01, 0x23, 0x45, 0x67, 0x89, 0xab},
+ fromString("0123456789AB")));
+ EXPECT_TRUE(
+ stdplus::raw::equal(ether_addr{0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa},
+ fromString("FFEEDDccbbaa")));
}
TEST(MacToString, Valid)