summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorWilliam A. Kennington III <wak@google.com>2019-02-01 21:43:11 -0800
committerWilliam A. Kennington III <wak@google.com>2019-02-14 12:10:12 -0800
commita14879e1f4d5ea2caa1cfccf02727974501d577f (patch)
treec7d34c5890a23bdb6c2cfc23e4e881adbc572447 /test
parenta00b1c3f74d329c1ca65826e430efa9105a72465 (diff)
downloadphosphor-networkd-a14879e1f4d5ea2caa1cfccf02727974501d577f.tar.gz
phosphor-networkd-a14879e1f4d5ea2caa1cfccf02727974501d577f.zip
util: Add a MacAddr population function
This one is pretty trivial since there is only one size of mac address, but we want to be sure we validate the buffer. Tested: Built and runs through unit tests. Works when integrated into neighbor parsing code. Change-Id: Iaf58fc398b51a3bcbbf70968cbe353beeb7b9f54 Signed-off-by: William A. Kennington III <wak@google.com>
Diffstat (limited to 'test')
-rw-r--r--test/test_util.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/test/test_util.cpp b/test/test_util.cpp
index 0e58081..4e39821 100644
--- a/test/test_util.cpp
+++ b/test/test_util.cpp
@@ -31,6 +31,19 @@ TEST_F(TestUtil, ToHex)
EXPECT_EQ('4', mac_address::internal::toHex(std::byte(4)));
}
+TEST_F(TestUtil, MacFromBuf)
+{
+ std::string tooSmall(1, 'a');
+ std::string tooLarge(24, 'a');
+ std::string buf{'\x00', '\xde', '\xad', '\x00', '\xbe', '\xef'};
+
+ MacAddr mac = mac_address::fromBuf(buf);
+ EXPECT_EQ(0, memcmp(buf.data(), mac.data(), buf.size()));
+
+ EXPECT_THROW(mac_address::fromBuf(tooSmall), std::runtime_error);
+ EXPECT_THROW(mac_address::fromBuf(tooLarge), std::runtime_error);
+}
+
TEST_F(TestUtil, MacToString)
{
MacAddr mac1{
OpenPOWER on IntegriCloud