net/addr/ether: Add ToStr conversion
Change-Id: Ic2bd81f4e453a53024dd9288f7b3d1e292ad4574
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/test/net/addr/ether.cpp b/test/net/addr/ether.cpp
index 012e1b0..8005906 100644
--- a/test/net/addr/ether.cpp
+++ b/test/net/addr/ether.cpp
@@ -1,3 +1,5 @@
+#include <fmt/format.h>
+
#include <stdplus/net/addr/ether.hpp>
#include <gtest/gtest.h>
@@ -13,6 +15,20 @@
std::hash<EtherAddr>{}(EtherAddr{});
}
+TEST(ToStr, EthAddr)
+{
+ ToStrHandle<ToStr<EtherAddr>> tsh;
+ EXPECT_EQ("11:22:33:44:55:66",
+ tsh(EtherAddr{0x11, 0x22, 0x33, 0x44, 0x55, 0x66}));
+ EXPECT_EQ("01:02:03:04:05:67",
+ tsh(EtherAddr{0x01, 0x02, 0x03, 0x04, 0x05, 0x67}));
+ EXPECT_EQ("00:00:00:00:00:00",
+ tsh(ether_addr{0x00, 0x00, 0x00, 0x00, 0x00, 0x00}));
+ EXPECT_EQ(
+ "a 01:02:03:04:05:67 b",
+ fmt::format("a {} b", EtherAddr{0x01, 0x02, 0x03, 0x04, 0x05, 0x67}));
+}
+
TEST(FromStr, EtherAddr)
{
EXPECT_THROW(fromStr<EtherAddr>("0x:00:00:00:00:00"),