186202f62487c553919f5dc0798da2d4f58be8dd
[senf.git] / Socket / Protocols / INet / INet4Address.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 INet4Address.test unit tests */
23
24 //#include "INet4Address.test.hh"
25 //#include "INet4Address.test.ih"
26
27 // Custom includes
28 #include <arpa/inet.h>
29 #include <sstream>
30 #include "INet4Address.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(inet4Address)
39 {
40     senf::INet4Address addr (senf::INet4Address::from_string("127.0.0.1"));
41     BOOST_CHECK_EQUAL( addr, senf::INet4Address::Loopback );
42
43     addr = senf::INet4Address::from_string("localhost");
44     BOOST_CHECK_EQUAL( addr, senf::INet4Address::Loopback );
45     BOOST_CHECK( addr.loopback() );
46
47     char data[] = { 128, 129, 130, 131 };
48     addr = senf::INet4Address::from_data(data);
49     BOOST_CHECK_EQUAL( addr, senf::INet4Address::from_string("128.129.130.131") );
50     BOOST_CHECK_EQUAL( addr.inaddr(), htonl(0x80818283u) );
51     BOOST_CHECK_EQUAL( addr.address(), 0x80818283u );
52
53     BOOST_CHECK( ! addr.loopback() );
54     BOOST_CHECK( ! addr.local() );
55     BOOST_CHECK( senf::INet4Address::from_string("192.168.1.2").local() );
56     BOOST_CHECK( ! addr.multicast() );
57     BOOST_CHECK( senf::INet4Address::from_string("224.1.2.3").multicast() );
58     BOOST_CHECK( ! addr.broadcast() );
59     BOOST_CHECK( senf::INet4Address::from_string("255.255.255.255").broadcast() );
60     BOOST_CHECK( addr );
61     BOOST_CHECK( ! senf::INet4Address() );
62
63     std::stringstream str;
64     str << addr;
65     BOOST_CHECK_EQUAL( str.str(), "128.129.130.131" );
66 }
67
68 ///////////////////////////////cc.e////////////////////////////////////////
69 #undef prefix_
70
71 \f
72 // Local Variables:
73 // mode: c++
74 // fill-column: 100
75 // comment-column: 40
76 // c-file-style: "senf"
77 // indent-tabs-mode: nil
78 // ispell-local-dictionary: "american"
79 // compile-command: "scons -u test"
80 // End: