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