blob: 0f726e1dd47dbe6314c86de435c17439daeaa6e2 [file] [log] [blame]
Davide Pesavento56fb5972014-03-12 06:18:37 +01001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (C) 2014 Named Data Networking Project
4 * See COPYING for copyright and distribution information.
5 */
6
7#include "face/ethernet.hpp"
8#include "tests/test-common.hpp"
9
10namespace nfd {
11namespace tests {
12
13BOOST_FIXTURE_TEST_SUITE(FaceEthernetAddress, BaseFixture)
14
15BOOST_AUTO_TEST_CASE(Checks)
16{
17 BOOST_CHECK(ethernet::Address().isNull());
18 BOOST_CHECK(ethernet::getBroadcastAddress().isBroadcast());
19 BOOST_CHECK(ethernet::getDefaultMulticastAddress().isMulticast());
20}
21
22BOOST_AUTO_TEST_CASE(ToString)
23{
24 BOOST_CHECK_EQUAL(ethernet::Address().toString(),
25 "00-00-00-00-00-00");
26 BOOST_CHECK_EQUAL(ethernet::getBroadcastAddress().toString(':'),
27 "ff:ff:ff:ff:ff:ff");
28 BOOST_CHECK_EQUAL(ethernet::Address(0x01, 0x23, 0x45, 0x67, 0x89, 0xAB).toString(),
29 "01-23-45-67-89-ab");
30 BOOST_CHECK_EQUAL(ethernet::Address(0x01, 0x23, 0x45, 0x67, 0x89, 0xAB).toString(':'),
31 "01:23:45:67:89:ab");
32}
33
34BOOST_AUTO_TEST_CASE(FromString)
35{
36 BOOST_CHECK_EQUAL(ethernet::Address::fromString("0:0:0:0:0:0"),
37 ethernet::Address());
38 BOOST_CHECK_EQUAL(ethernet::Address::fromString("ff-ff-ff-ff-ff-ff"),
39 ethernet::getBroadcastAddress());
40 BOOST_CHECK_EQUAL(ethernet::Address::fromString("de:ad:be:ef:1:2"),
41 ethernet::Address(0xde, 0xad, 0xbe, 0xef, 0x01, 0x02));
42
43 // malformed inputs
44 BOOST_CHECK_EQUAL(ethernet::Address::fromString("01.23.45.67.89.ab"),
45 ethernet::Address());
46 BOOST_CHECK_EQUAL(ethernet::Address::fromString("01:23:45 :67:89:ab"),
47 ethernet::Address());
48 BOOST_CHECK_EQUAL(ethernet::Address::fromString("01:23:45:67:89::1"),
49 ethernet::Address());
50 BOOST_CHECK_EQUAL(ethernet::Address::fromString("01-23-45-67-89"),
51 ethernet::Address());
52 BOOST_CHECK_EQUAL(ethernet::Address::fromString("01:23:45:67:89:ab:cd"),
53 ethernet::Address());
54 BOOST_CHECK_EQUAL(ethernet::Address::fromString("qw-er-ty-12-34-56"),
55 ethernet::Address());
56 BOOST_CHECK_EQUAL(ethernet::Address::fromString("this-is-not-an-ethernet-address"),
57 ethernet::Address());
58 BOOST_CHECK_EQUAL(ethernet::Address::fromString("foobar"),
59 ethernet::Address());
60 BOOST_CHECK_EQUAL(ethernet::Address::fromString(""),
61 ethernet::Address());
62}
63
64BOOST_AUTO_TEST_SUITE_END()
65
66} // namespace tests
67} // namespace nfd