2 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
3 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
4 // Stefan Bund <g0dil@berlios.de>
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the
18 // Free Software Foundation, Inc.,
19 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 \brief MACAddress.test unit tests */
24 //#include "MACAddress.test.hh"
25 //#include "MACAddress.test.ih"
29 #include <boost/lexical_cast.hpp>
30 #include "MACAddress.hh"
32 #include "../../../Utils/auto_unit_test.hh"
33 #include <boost/test/test_tools.hpp>
36 ///////////////////////////////cc.p////////////////////////////////////////
38 BOOST_AUTO_UNIT_TEST(macAddress)
40 senf::MACAddress mac (senf::MACAddress::from_string("A1-b2-C3:d4:E5:f6"));
42 BOOST_CHECK_EQUAL( mac[0], 0xA1u );
43 BOOST_CHECK_EQUAL( mac[1], 0xB2u );
44 BOOST_CHECK_EQUAL( mac[2], 0xC3u );
45 BOOST_CHECK_EQUAL( mac[3], 0xD4u );
46 BOOST_CHECK_EQUAL( mac[4], 0xE5u );
47 BOOST_CHECK_EQUAL( mac[5], 0xF6u );
49 std::stringstream str;
51 BOOST_CHECK_EQUAL( str.str(), "a1:b2:c3:d4:e5:f6" );
53 BOOST_CHECK( ! mac.local() );
54 BOOST_CHECK( mac.multicast() );
55 BOOST_CHECK( ! mac.broadcast() );
57 BOOST_CHECK_EQUAL( mac.oui(), 0xa1b2c3u );
58 BOOST_CHECK_EQUAL( mac.nic(), 0xd4e5f6u );
59 BOOST_CHECK_EQUAL( mac.eui64(), 0xa1b2c3fffed4e5f6llu );
61 senf::MACAddress mac2;
62 BOOST_CHECK( ! mac2 );
63 mac2 = senf::MACAddress::from_string("ff:ff:ff:ff:ff:ff");
64 BOOST_CHECK( mac2.broadcast() );
65 BOOST_CHECK_EQUAL( mac2, senf::MACAddress::Broadcast );
66 char data[] = { 0x01,0x02,0x03,0x04,0x05,0x06 };
67 mac2 = senf::MACAddress::from_data(data);
68 BOOST_CHECK_EQUAL( boost::lexical_cast<std::string>(mac2), "01:02:03:04:05:06" );
69 BOOST_CHECK( mac != mac2 );
71 BOOST_CHECK( mac == mac2 );
72 BOOST_CHECK_EQUAL( boost::lexical_cast<std::string>(mac2), "a1:b2:c3:d4:e5:f6" );
74 BOOST_CHECK_THROW( senf::MACAddress::from_string("1:2:3:4:5:6"),
75 senf::MACAddress::SyntaxException );
76 BOOST_CHECK_THROW( senf::MACAddress::from_string("01:02:03:04:05"),
77 senf::MACAddress::SyntaxException );
78 BOOST_CHECK_THROW( senf::MACAddress::from_string("01:02:03:04:05:z6"),
79 senf::MACAddress::SyntaxException );
81 BOOST_CHECK_EQUAL( mac, senf::MACAddress::from_eui64(0xa1b2c3fffed4e5f6llu) );
82 BOOST_CHECK_THROW( senf::MACAddress::from_eui64(0u), senf::MACAddress::SyntaxException );
85 ///////////////////////////////cc.e////////////////////////////////////////
93 // c-file-style: "senf"
94 // indent-tabs-mode: nil
95 // ispell-local-dictionary: "american"
96 // compile-command: "scons -u test"