Socket: Moved PacketSocketHandle and related stuff into 'Raw' subdir
[senf.git] / Socket / Protocols / Raw / MACAddress.test.cc
1 // Copyright (C) 2007 
2 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
3 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
4 //     Stefan Bund <g0dil@berlios.de>
5 //
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.
10 //
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.
15 //
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.
20
21 /** \file
22     \brief MACAddress.test unit tests */
23
24 //#include "MACAddress.test.hh"
25 //#include "MACAddress.test.ih"
26
27 // Custom includes
28 #include <sstream>
29 #include <boost/lexical_cast.hpp>
30 #include "MACAddress.hh"
31
32 #include <boost/test/auto_unit_test.hpp>
33 #include <boost/test/test_tools.hpp>
34
35 #define prefix_
36 ///////////////////////////////cc.p////////////////////////////////////////
37
38 BOOST_AUTO_UNIT_TEST(macAddress)
39 {
40     senf::MACAddress mac (senf::MACAddress::from_string("A1-b2-C3:d4:E5:f6"));
41     std::stringstream str;
42     str << mac;
43     BOOST_CHECK_EQUAL( str.str(), "a1:b2:c3:d4:e5:f6" );
44
45     BOOST_CHECK( ! mac.local() );
46     BOOST_CHECK( mac.group() );
47     BOOST_CHECK( ! mac.broadcast() );
48     BOOST_CHECK( mac );
49     BOOST_CHECK_EQUAL( mac.oui(), 0xa1b2c3u );
50     BOOST_CHECK_EQUAL( mac.nic(), 0xd4e5f6u );
51     BOOST_CHECK_EQUAL( mac.eui64(), 0xa1b2c3fffed4e5f6llu );
52
53     senf::MACAddress mac2;
54     BOOST_CHECK( ! mac2 );
55     mac2 = senf::MACAddress::from_string("ff:ff:ff:ff:ff:ff");
56     BOOST_CHECK( mac2.broadcast() );
57     char data[] = { 0x01,0x02,0x03,0x04,0x05,0x06 };
58     mac2 = senf::MACAddress::from_data(data);
59     BOOST_CHECK_EQUAL( boost::lexical_cast<std::string>(mac2), "01:02:03:04:05:06" );
60     BOOST_CHECK( mac != mac2 );
61     mac2 = mac;
62     BOOST_CHECK( mac == mac2 );
63     BOOST_CHECK_EQUAL( boost::lexical_cast<std::string>(mac2), "a1:b2:c3:d4:e5:f6" );
64
65     BOOST_CHECK_THROW( senf::MACAddress::from_string("1:2:3:4:5:6"), 
66                        senf::MACAddress::SyntaxException );
67     BOOST_CHECK_THROW( senf::MACAddress::from_string("01:02:03:04:05"), 
68                        senf::MACAddress::SyntaxException );
69     BOOST_CHECK_THROW( senf::MACAddress::from_string("01:02:03:04:05:z6"), 
70                        senf::MACAddress::SyntaxException );
71
72     BOOST_CHECK_EQUAL( mac, senf::MACAddress::from_eui64(0xa1b2c3fffed4e5f6llu) );
73     BOOST_CHECK_THROW( senf::MACAddress::from_eui64(0u), senf::MACAddress::SyntaxException );
74 }
75
76 ///////////////////////////////cc.e////////////////////////////////////////
77 #undef prefix_
78
79 \f
80 // Local Variables:
81 // mode: c++
82 // fill-column: 100
83 // comment-column: 40
84 // c-file-style: "senf"
85 // indent-tabs-mode: nil
86 // ispell-local-dictionary: "american"
87 // compile-command: "scons -u test"
88 // End: