summaryrefslogtreecommitdiff
path: root/Tests
diff options
context:
space:
mode:
authorbrapru <brapru@pm.me>2021-07-24 20:15:14 -0400
committerAndreas Kling <kling@serenityos.org>2021-07-25 17:57:08 +0200
commit7e40c174601e5ab9f71bb06e6c70cd6d68d4502f (patch)
treea5fc62a95e7f2208f47f9c5e5dae1b6f24c9f07a /Tests
parent8313d357499b3ac473120252143037e6e633bf60 (diff)
downloadserenity-7e40c174601e5ab9f71bb06e6c70cd6d68d4502f.zip
AK: Create MACAddress from string
Previously there was no way to create a MACAddress by passing a direct address as a string. This will allow programs like the arp utility to create a MACAddress instance by user-passed addresses.
Diffstat (limited to 'Tests')
-rw-r--r--Tests/AK/TestMACAddress.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/Tests/AK/TestMACAddress.cpp b/Tests/AK/TestMACAddress.cpp
index f91ae043a2..258f1ac0e0 100644
--- a/Tests/AK/TestMACAddress.cpp
+++ b/Tests/AK/TestMACAddress.cpp
@@ -82,3 +82,43 @@ TEST_CASE(should_string_format)
MACAddress sut(1, 2, 3, 4, 5, 6);
EXPECT_EQ("01:02:03:04:05:06", sut.to_string());
}
+
+TEST_CASE(should_make_mac_address_from_string_numbers)
+{
+ const auto sut = MACAddress::from_string("01:02:03:04:05:06");
+
+ EXPECT(sut.has_value());
+ EXPECT_EQ(1, sut.value()[0]);
+ EXPECT_EQ(2, sut.value()[1]);
+ EXPECT_EQ(3, sut.value()[2]);
+ EXPECT_EQ(4, sut.value()[3]);
+ EXPECT_EQ(5, sut.value()[4]);
+ EXPECT_EQ(6, sut.value()[5]);
+}
+
+TEST_CASE(should_make_mac_address_from_string_letters)
+{
+ const auto sut = MACAddress::from_string("de:ad:be:ee:ee:ef");
+
+ EXPECT(sut.has_value());
+ EXPECT_EQ(u8 { 0xDE }, sut.value()[0]);
+ EXPECT_EQ(u8 { 0xAD }, sut.value()[1]);
+ EXPECT_EQ(u8 { 0xBE }, sut.value()[2]);
+ EXPECT_EQ(u8 { 0xEE }, sut.value()[3]);
+ EXPECT_EQ(u8 { 0xEE }, sut.value()[4]);
+ EXPECT_EQ(u8 { 0xEF }, sut.value()[5]);
+}
+
+TEST_CASE(should_make_empty_optional_from_bad_string)
+{
+ const auto sut = MACAddress::from_string("bad string");
+
+ EXPECT(!sut.has_value());
+}
+
+TEST_CASE(should_make_empty_optional_from_out_of_range_values)
+{
+ const auto sut = MACAddress::from_string("de:ad:be:ee:ee:fz");
+
+ EXPECT(!sut.has_value());
+}