switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / Socket / Protocols / Raw / LLAddressing.test.cc
1 // $Id$
2 //
3 // Copyright (C) 2006
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 //
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at 
9 // http://senf.berlios.de/license.html
10 //
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on, 
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
14 //
15 // Software distributed under the License is distributed on an "AS IS" basis, 
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
17 // for the specific language governing rights and limitations under the License.
18 //
19 // The Original Code is Fraunhofer FOKUS code.
20 //
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. 
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
24 //
25 // Contributor(s):
26 //   Stefan Bund <g0dil@berlios.de>
27
28 /** \file
29     \brief LLAddressing unit tests */
30
31 //#include "LLAddressing.test.hh"
32 //#include "LLAddressing.test.ih"
33
34 // Custom includes
35 #include "LLAddressing.hh"
36 #include <senf/Utils/String.hh>
37 #include <senf/Socket/Protocols/AddressExceptions.hh>
38
39 #include <senf/Utils/auto_unit_test.hh>
40 #include <boost/test/test_tools.hpp>
41
42 #define prefix_
43 //-/////////////////////////////////////////////////////////////////////////////////////////////////
44
45 SENF_AUTO_UNIT_TEST(llAddress)
46 {
47     using senf::LLSocketAddress;
48
49     {
50         LLSocketAddress addr;
51
52         BOOST_CHECK( ! addr );
53         BOOST_CHECK_EQUAL( addr.protocol(), 0u );
54         BOOST_CHECK_EQUAL( addr.interface(), "" );
55         BOOST_CHECK_EQUAL( addr.arptype(), 0u );
56         BOOST_CHECK_EQUAL( addr.pkttype(), LLSocketAddress::Undefined );
57         BOOST_CHECK( ! addr.address() );
58
59         senf::MACAddress mac (senf::MACAddress::from_string("05-10-1A-2f-25-30"));
60         addr.address( mac);
61         BOOST_CHECK( addr );
62         BOOST_CHECK_EQUAL( addr, LLSocketAddress(mac));
63         BOOST_CHECK_EQUAL( addr, LLSocketAddress(addr));
64         BOOST_CHECK_EQUAL( addr.address(), mac );
65         addr.interface("lo");
66         BOOST_CHECK_EQUAL( addr.interface(), "lo" );
67         addr.protocol(123);
68         BOOST_CHECK_EQUAL( addr.protocol(), 123u );
69     }
70
71     {
72         LLSocketAddress addr (
73             senf::MACAddress::from_string("11-12-13-14-15-16"), "lo");
74
75         BOOST_CHECK_EQUAL( addr.protocol(), 0u );
76         BOOST_CHECK_EQUAL( addr.interface(), "lo" );
77         BOOST_CHECK_EQUAL( addr.arptype(), 0u );
78         BOOST_CHECK_EQUAL( addr.pkttype(), LLSocketAddress::Undefined );
79         BOOST_CHECK_EQUAL( senf::str(addr.address()), "11:12:13:14:15:16" );
80     }
81
82     {
83         LLSocketAddress addr (123, "lo");
84
85         BOOST_CHECK_EQUAL( addr.protocol(), 123u );
86         BOOST_CHECK_EQUAL( addr.interface(), "lo" );
87         BOOST_CHECK_EQUAL( addr.arptype(), 0u );
88         BOOST_CHECK_EQUAL( addr.pkttype(), LLSocketAddress::Undefined );
89         BOOST_CHECK( ! addr.address() );
90     }
91
92     {
93         BOOST_CHECK_THROW( LLSocketAddress addr("SENF_TEST_INVALID_INTERFACENAME"),
94                 senf::UnknownInterfaceException );
95
96         LLSocketAddress addr ("lo");
97
98         BOOST_CHECK_EQUAL( addr.protocol(), 0u );
99         BOOST_CHECK_EQUAL( addr.interface(), "lo" );
100         BOOST_CHECK_EQUAL( addr.arptype(), 0u );
101         BOOST_CHECK_EQUAL( addr.pkttype(), LLSocketAddress::Undefined );
102         BOOST_CHECK( ! addr.address() );
103
104         BOOST_CHECK_EQUAL( LLSocketAddress("").interface(), "" );
105     }
106 }
107
108 //-/////////////////////////////////////////////////////////////////////////////////////////////////
109 #undef prefix_
110
111 \f
112 // Local Variables:
113 // mode: c++
114 // fill-column: 100
115 // c-file-style: "senf"
116 // indent-tabs-mode: nil
117 // ispell-local-dictionary: "american"
118 // compile-command: "scons -u test"
119 // comment-column: 40
120 // End: