all unit tests: replaced BOOST_AUTO_UNIT_TEST with new SENF_AUTO_UNIT_TEST macro
[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
32 #include <senf/Utils/auto_unit_test.hh>
33 #include <boost/test/test_tools.hpp>
34
35 #define prefix_
36 ///////////////////////////////cc.p////////////////////////////////////////
37
38 SENF_AUTO_UNIT_TEST(eui64)
39 {
40     senf::EUI64 eui;
41     BOOST_CHECK( !eui );
42     BOOST_CHECK( !eui.isMACCompatible() );
43
44     eui = senf::EUI64::from_mac(senf::MACAddress(0x102030405060ull));
45     boost::uint8_t data[] = { 0x10u, 0x20u, 0x30u, 0xffu, 0xfeu, 0x40u, 0x50u, 0x60u };
46     BOOST_CHECK_EQUAL_COLLECTIONS( eui.begin(), eui.end(), data, data+sizeof(data)/sizeof(data[0]) );
47     BOOST_CHECK( eui );
48     BOOST_CHECK( eui.isMACCompatible() );
49     BOOST_CHECK( ! eui.local() );
50     BOOST_CHECK( ! eui.group() );
51     BOOST_CHECK_EQUAL( eui.uint64(), 0x102030fffe405060ull );
52
53     BOOST_CHECK_EQUAL( eui, senf::EUI64::from_data(data) );
54     BOOST_CHECK_EQUAL( eui, senf::EUI64::from_string("10:20:30:ff-FE:40:50:60") );
55
56     BOOST_CHECK_THROW( senf::EUI64::from_string("123:20:30:40:50:60:70:80"), 
57                        senf::AddressSyntaxException );
58     BOOST_CHECK_THROW( senf::EUI64::from_string("12:20:30:40:50:60:70"), 
59                        senf::AddressSyntaxException );
60     BOOST_CHECK_THROW( senf::EUI64::from_string("12:20:30:40:50:60:70:8g"), 
61                        senf::AddressSyntaxException );
62     BOOST_CHECK_THROW( senf::EUI64::from_string("12:20:30:40:50:60:70:80:90"), 
63                        senf::AddressSyntaxException );
64     
65     BOOST_CHECK_EQUAL( senf::EUI64::None, senf::EUI64(0) );
66     BOOST_CHECK(! senf::EUI64::None );
67     
68     {
69         std::stringstream ss;
70         ss << std::uppercase << eui;
71         BOOST_CHECK_EQUAL( ss.str(), "10:20:30:FF-FE:40:50:60" );
72         eui = senf::EUI64();
73         BOOST_CHECK( !eui );
74         ss >> eui;
75         BOOST_CHECK_EQUAL( eui, senf::EUI64(0x102030fffe405060ull) );
76         
77         BOOST_CHECK( (ss >> eui).fail() );
78     }
79
80     {
81         std::stringstream ss;
82         ss << "01:02:03:04-05:06:07:108";
83         BOOST_CHECK( (ss >> eui).fail() );
84     }
85 }
86
87 ///////////////////////////////cc.e////////////////////////////////////////
88 #undef prefix_
89
90 \f
91 // Local Variables:
92 // mode: c++
93 // fill-column: 100
94 // comment-column: 40
95 // c-file-style: "senf"
96 // indent-tabs-mode: nil
97 // ispell-local-dictionary: "american"
98 // compile-command: "scons -u test"
99 // End: