6b7f84aa3138b34f6e13b03154aea0ec02bd1ea3
[senf.git] / Socket / Protocols / INet / INet4Address.test.cc
1 // $Id$
2 //
3 // Copyright (C) 2007 
4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
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 INet4Address.test unit tests */
25
26 //#include "INet4Address.test.hh"
27 //#include "INet4Address.test.ih"
28
29 // Custom includes
30 #include <arpa/inet.h>
31 #include <sstream>
32 #include "INet4Address.hh"
33
34 #include <boost/test/auto_unit_test.hpp>
35 #include <boost/test/test_tools.hpp>
36
37 #define prefix_
38 ///////////////////////////////cc.p////////////////////////////////////////
39
40 BOOST_AUTO_UNIT_TEST(inet4Address)
41 {
42     senf::INet4Address addr (senf::INet4Address::from_string("127.0.0.1"));
43     BOOST_CHECK_EQUAL( addr, senf::INet4Address::Loopback );
44     BOOST_CHECK( addr != senf::INet4Address::Broadcast );
45
46     addr = senf::INet4Address::from_string("localhost");
47     BOOST_CHECK_EQUAL( addr, senf::INet4Address::Loopback );
48     BOOST_CHECK( addr.loopback() );
49
50     char data[] = { 128, 129, 130, 131 };
51     addr = senf::INet4Address::from_data(data);
52     BOOST_CHECK_EQUAL( addr, senf::INet4Address::from_string("128.129.130.131") );
53     BOOST_CHECK_EQUAL( addr.inaddr(), htonl(0x80818283u) );
54     BOOST_CHECK_EQUAL( addr.address(), 0x80818283u );
55
56     BOOST_CHECK( ! addr.loopback() );
57     BOOST_CHECK( ! addr.local() );
58     BOOST_CHECK( senf::INet4Address::from_string("192.168.1.2").local() );
59     BOOST_CHECK( ! addr.multicast() );
60     BOOST_CHECK( senf::INet4Address::from_string("224.1.2.3").multicast() );
61     BOOST_CHECK( ! addr.broadcast() );
62     BOOST_CHECK( senf::INet4Address::from_string("255.255.255.255").broadcast() );
63     BOOST_CHECK( addr );
64     BOOST_CHECK( ! senf::INet4Address() );
65
66     std::stringstream str;
67     str << addr;
68     BOOST_CHECK_EQUAL( str.str(), "128.129.130.131" );
69 }
70
71 ///////////////////////////////cc.e////////////////////////////////////////
72 #undef prefix_
73
74 \f
75 // Local Variables:
76 // mode: c++
77 // fill-column: 100
78 // comment-column: 40
79 // c-file-style: "senf"
80 // indent-tabs-mode: nil
81 // ispell-local-dictionary: "american"
82 // compile-command: "scons -u test"
83 // End: