4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 \brief MACAddress.test unit tests */
26 //#include "MACAddress.test.hh"
27 //#include "MACAddress.test.ih"
31 #include <boost/lexical_cast.hpp>
32 #include "MACAddress.hh"
34 #include "../../../Utils/auto_unit_test.hh"
35 #include <boost/test/test_tools.hpp>
38 ///////////////////////////////cc.p////////////////////////////////////////
40 BOOST_AUTO_UNIT_TEST(macAddress)
42 std::string test ("A1-b2-C3:d4:E5:f6");
43 senf::MACAddress mac (senf::MACAddress::from_string(test));
45 BOOST_CHECK_EQUAL( mac[0], 0xA1u );
46 BOOST_CHECK_EQUAL( mac[1], 0xB2u );
47 BOOST_CHECK_EQUAL( mac[2], 0xC3u );
48 BOOST_CHECK_EQUAL( mac[3], 0xD4u );
49 BOOST_CHECK_EQUAL( mac[4], 0xE5u );
50 BOOST_CHECK_EQUAL( mac[5], 0xF6u );
52 std::stringstream str;
54 BOOST_CHECK_EQUAL( str.str(), "a1:b2:c3:d4:e5:f6" );
55 BOOST_CHECK_EQUAL (mac.toString(), "a1:b2:c3:d4:e5:f6");
57 BOOST_CHECK( ! mac.local() );
58 BOOST_CHECK( mac.multicast() );
59 BOOST_CHECK( ! mac.broadcast() );
61 BOOST_CHECK_EQUAL( mac.oui(), 0xa1b2c3u );
62 BOOST_CHECK_EQUAL( mac.nic(), 0xd4e5f6u );
63 BOOST_CHECK_EQUAL( mac.eui64(), 0xa1b2c3fffed4e5f6llu );
65 senf::MACAddress mac2;
66 BOOST_CHECK( ! mac2 );
67 mac2 = senf::MACAddress::from_string("ff:ff:ff:ff:ff:ff");
68 BOOST_CHECK( mac2.broadcast() );
69 BOOST_CHECK_EQUAL( mac2, senf::MACAddress::Broadcast );
70 char data[] = { 0x01,0x02,0x03,0x04,0x05,0x06 };
71 mac2 = senf::MACAddress::from_data(data);
72 BOOST_CHECK_EQUAL( boost::lexical_cast<std::string>(mac2), "01:02:03:04:05:06" );
73 BOOST_CHECK( mac != mac2 );
75 BOOST_CHECK( mac == mac2 );
76 BOOST_CHECK_EQUAL( boost::lexical_cast<std::string>(mac2), "a1:b2:c3:d4:e5:f6" );
78 BOOST_CHECK_THROW( senf::MACAddress::from_string("1:2:3:4:5:6"),
79 senf::AddressSyntaxException );
80 BOOST_CHECK_THROW( senf::MACAddress::from_string("01:02:03:04:05"),
81 senf::AddressSyntaxException );
82 BOOST_CHECK_THROW( senf::MACAddress::from_string("01:02:03:04:05:z6"),
83 senf::AddressSyntaxException );
85 BOOST_CHECK_EQUAL( mac, senf::MACAddress::from_eui64(0xa1b2c3fffed4e5f6llu) );
86 BOOST_CHECK_THROW( senf::MACAddress::from_eui64(0u), senf::AddressSyntaxException );
88 BOOST_CHECK_EQUAL( senf::MACAddress(0x1a2b3c4d5e6fULL).uint64(), 0x1a2b3c4d5e6fULL);
91 ///////////////////////////////cc.e////////////////////////////////////////
99 // c-file-style: "senf"
100 // indent-tabs-mode: nil
101 // ispell-local-dictionary: "american"
102 // compile-command: "scons -u test"