ae431d1af501edbc3a669b28e6701b1b7d0b5667
[senf.git] / senf / Socket / Protocols / Raw / EUI64.test.cc
1 // $Id$
2 //
3 // Copyright (C) 2009
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.de>
7 //
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.
12 //
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.
17 //
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.
22
23 /** \file
24     \brief EUI64.test unit tests */
25
26 //#include "EUI64.test.hh"
27 //#include "EUI64.test.ih"
28
29 // Custom includes
30 #include "EUI64.hh"
31 #include <senf/Socket/Protocols/AddressExceptions.hh>
32
33 #include <senf/Utils/auto_unit_test.hh>
34 #include <boost/test/test_tools.hpp>
35
36 #define prefix_
37 ///////////////////////////////cc.p////////////////////////////////////////
38
39 SENF_AUTO_UNIT_TEST(eui64)
40 {
41     senf::EUI64 eui;
42     BOOST_CHECK( !eui );
43     BOOST_CHECK( !eui.isMACCompatible() );
44
45     eui = senf::EUI64::from_mac(senf::MACAddress(0x102030405060ull));
46     boost::uint8_t data[] = { 0x10u, 0x20u, 0x30u, 0xffu, 0xfeu, 0x40u, 0x50u, 0x60u };
47     BOOST_CHECK_EQUAL_COLLECTIONS( eui.begin(), eui.end(), data, data+sizeof(data)/sizeof(data[0]) );
48     BOOST_CHECK( eui );
49     BOOST_CHECK( eui.isMACCompatible() );
50     BOOST_CHECK( ! eui.local() );
51     BOOST_CHECK( ! eui.group() );
52     BOOST_CHECK_EQUAL( eui.uint64(), 0x102030fffe405060ull );
53
54     BOOST_CHECK_EQUAL( eui, senf::EUI64::from_data(data) );
55     BOOST_CHECK_EQUAL( eui, senf::EUI64::from_string("10:20:30:ff-FE:40:50:60") );
56
57     BOOST_CHECK_THROW( senf::EUI64::from_string("123:20:30:40:50:60:70:80"),
58                        senf::AddressSyntaxException );
59     BOOST_CHECK_THROW( senf::EUI64::from_string("12:20:30:40:50:60:70"),
60                        senf::AddressSyntaxException );
61     BOOST_CHECK_THROW( senf::EUI64::from_string("12:20:30:40:50:60:70:8g"),
62                        senf::AddressSyntaxException );
63     BOOST_CHECK_THROW( senf::EUI64::from_string("12:20:30:40:50:60:70:80:90"),
64                        senf::AddressSyntaxException );
65
66     BOOST_CHECK_EQUAL( senf::EUI64::None, senf::EUI64(0) );
67     BOOST_CHECK(! senf::EUI64::None );
68
69     {
70         std::stringstream ss;
71         ss << std::uppercase << eui;
72         BOOST_CHECK_EQUAL( ss.str(), "10:20:30:FF-FE:40:50:60" );
73         eui = senf::EUI64();
74         BOOST_CHECK( !eui );
75         ss >> eui;
76         BOOST_CHECK_EQUAL( eui, senf::EUI64(0x102030fffe405060ull) );
77
78         BOOST_CHECK( (ss >> eui).fail() );
79     }
80
81     {
82         std::stringstream ss;
83         ss << "01:02:03:04-05:06:07:108";
84         BOOST_CHECK( (ss >> eui).fail() );
85     }
86 }
87
88 ///////////////////////////////cc.e////////////////////////////////////////
89 #undef prefix_
90
91 \f
92 // Local Variables:
93 // mode: c++
94 // fill-column: 100
95 // comment-column: 40
96 // c-file-style: "senf"
97 // indent-tabs-mode: nil
98 // ispell-local-dictionary: "american"
99 // compile-command: "scons -u test"
100 // End: