Socket/Protocols/INet: Updated INet4SocketAddress to use INet4Address
[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     BOOST_CHECK( addr != senf::INet4Address::Broadcast );
43
44     addr = senf::INet4Address::from_string("localhost");
45     BOOST_CHECK_EQUAL( addr, senf::INet4Address::Loopback );
46     BOOST_CHECK( addr.loopback() );
47
48     char data[] = { 128, 129, 130, 131 };
49     addr = senf::INet4Address::from_data(data);
50     BOOST_CHECK_EQUAL( addr, senf::INet4Address::from_string("128.129.130.131") );
51     BOOST_CHECK_EQUAL( addr.inaddr(), htonl(0x80818283u) );
52     BOOST_CHECK_EQUAL( addr.address(), 0x80818283u );
53
54     BOOST_CHECK( ! addr.loopback() );
55     BOOST_CHECK( ! addr.local() );
56     BOOST_CHECK( senf::INet4Address::from_string("192.168.1.2").local() );
57     BOOST_CHECK( ! addr.multicast() );
58     BOOST_CHECK( senf::INet4Address::from_string("224.1.2.3").multicast() );
59     BOOST_CHECK( ! addr.broadcast() );
60     BOOST_CHECK( senf::INet4Address::from_string("255.255.255.255").broadcast() );
61     BOOST_CHECK( addr );
62     BOOST_CHECK( ! senf::INet4Address() );
63
64     std::stringstream str;
65     str << addr;
66     BOOST_CHECK_EQUAL( str.str(), "128.129.130.131" );
67 }
68
69 ///////////////////////////////cc.e////////////////////////////////////////
70 #undef prefix_
71
72 \f
73 // Local Variables:
74 // mode: c++
75 // fill-column: 100
76 // comment-column: 40
77 // c-file-style: "senf"
78 // indent-tabs-mode: nil
79 // ispell-local-dictionary: "american"
80 // compile-command: "scons -u test"
81 // End: