blob: 037d65316b1a28d3cb4238c30a330271a6495208 [file] [log] [blame]
Junxiao Shi77dcadd2014-10-05 14:40:54 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2013-2014 Regents of the University of California.
4 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6 *
7 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20 */
21
22#include "util/ethernet.hpp"
23
24#include "boost-test.hpp"
25
26namespace ndn {
27namespace util {
28
29BOOST_AUTO_TEST_SUITE(UtilTestEthernet)
30
31BOOST_AUTO_TEST_CASE(Checks)
32{
33 BOOST_CHECK(ethernet::Address().isNull());
34 BOOST_CHECK(ethernet::getBroadcastAddress().isBroadcast());
35 BOOST_CHECK(ethernet::getDefaultMulticastAddress().isMulticast());
36}
37
38BOOST_AUTO_TEST_CASE(ToString)
39{
40 BOOST_CHECK_EQUAL(ethernet::Address().toString('-'),
41 "00-00-00-00-00-00");
42 BOOST_CHECK_EQUAL(ethernet::getBroadcastAddress().toString(),
43 "ff:ff:ff:ff:ff:ff");
44 BOOST_CHECK_EQUAL(ethernet::Address(0x01, 0x23, 0x45, 0x67, 0x89, 0xAB).toString('-'),
45 "01-23-45-67-89-ab");
46 BOOST_CHECK_EQUAL(ethernet::Address(0x01, 0x23, 0x45, 0x67, 0x89, 0xAB).toString(),
47 "01:23:45:67:89:ab");
48}
49
50BOOST_AUTO_TEST_CASE(FromString)
51{
52 BOOST_CHECK_EQUAL(ethernet::Address::fromString("0:0:0:0:0:0"),
53 ethernet::Address());
54 BOOST_CHECK_EQUAL(ethernet::Address::fromString("ff-ff-ff-ff-ff-ff"),
55 ethernet::getBroadcastAddress());
56 BOOST_CHECK_EQUAL(ethernet::Address::fromString("de:ad:be:ef:1:2"),
57 ethernet::Address(0xde, 0xad, 0xbe, 0xef, 0x01, 0x02));
58 BOOST_CHECK_EQUAL(ethernet::Address::fromString("DE:AD:BE:EF:1:2"),
59 ethernet::Address(0xde, 0xad, 0xbe, 0xef, 0x01, 0x02));
60
61 // malformed inputs
62 BOOST_CHECK_EQUAL(ethernet::Address::fromString("01.23.45.67.89.ab"),
63 ethernet::Address());
64 BOOST_CHECK_EQUAL(ethernet::Address::fromString("01:23:45 :67:89:ab"),
65 ethernet::Address());
66 BOOST_CHECK_EQUAL(ethernet::Address::fromString("01:23:45:67:89::1"),
67 ethernet::Address());
68 BOOST_CHECK_EQUAL(ethernet::Address::fromString("01-23-45-67-89"),
69 ethernet::Address());
70 BOOST_CHECK_EQUAL(ethernet::Address::fromString("01:23:45:67:89:ab:cd"),
71 ethernet::Address());
72 BOOST_CHECK_EQUAL(ethernet::Address::fromString("01:23:45:67-89-ab"),
73 ethernet::Address());
74 BOOST_CHECK_EQUAL(ethernet::Address::fromString("qw-er-ty-12-34-56"),
75 ethernet::Address());
76 BOOST_CHECK_EQUAL(ethernet::Address::fromString("this-is-not-an-ethernet-address"),
77 ethernet::Address());
78 BOOST_CHECK_EQUAL(ethernet::Address::fromString("foobar"),
79 ethernet::Address());
80 BOOST_CHECK_EQUAL(ethernet::Address::fromString(""),
81 ethernet::Address());
82}
83
84BOOST_AUTO_TEST_SUITE_END()
85
86} // namespace util
87} // namespace ndn