summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorWilliam A. Kennington III <wak@google.com>2019-01-30 17:15:43 -0800
committerRatan Gupta <ratagupt@linux.vnet.ibm.com>2019-02-14 05:25:29 +0000
commitd27410f19fe3277930d19938882d6382331e0377 (patch)
tree2b9b53954b7c04952ef9fb684e4f23bdfba13149 /test
parent0d7ce48e8d36e381e35550450c8bd0903a859e71 (diff)
downloadphosphor-networkd-d27410f19fe3277930d19938882d6382331e0377.tar.gz
phosphor-networkd-d27410f19fe3277930d19938882d6382331e0377.zip
util: Add a function for converting MAC addresses
We need to be able to convert a mac addresses from byte form into our typical human readable string form. Tested: Unit tests pass. Change-Id: I6e68cfefd4d5962e1125c1b5229e61fce475729a Signed-off-by: William A. Kennington III <wak@google.com>
Diffstat (limited to 'test')
-rw-r--r--test/test_util.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/test/test_util.cpp b/test/test_util.cpp
index 6c647ed..f536bd7 100644
--- a/test/test_util.cpp
+++ b/test/test_util.cpp
@@ -2,6 +2,7 @@
#include <netinet/in.h>
+#include <cstddef>
#include <xyz/openbmc_project/Common/error.hpp>
#include <gtest/gtest.h>
@@ -22,6 +23,27 @@ class TestUtil : public testing::Test
}
};
+TEST_F(TestUtil, ToHex)
+{
+ EXPECT_EQ('E', mac_address::internal::toHex(std::byte(0xfe)));
+ EXPECT_EQ('A', mac_address::internal::toHex(std::byte(10)));
+ EXPECT_EQ('4', mac_address::internal::toHex(std::byte(4)));
+}
+
+TEST_F(TestUtil, MacToString)
+{
+ MacAddr mac1{
+ std::byte(0x00), std::byte(0xDE), std::byte(0xAD),
+ std::byte(0x00), std::byte(0xBE), std::byte(0xEF),
+ };
+ EXPECT_EQ("00:DE:AD:00:BE:EF", mac_address::toString(mac1));
+ MacAddr mac2{
+ std::byte(0x70), std::byte(0xFF), std::byte(0x84),
+ std::byte(0x09), std::byte(0x35), std::byte(0x09),
+ };
+ EXPECT_EQ("70:FF:84:09:35:09", mac_address::toString(mac2));
+}
+
TEST_F(TestUtil, IpValidation)
{
std::string ipaddress = "0.0.0.0";
OpenPOWER on IntegriCloud