dea7b881d2236ea6a297e8dbd60f60e37bc2062f
[senf.git] / Socket / INetAddressing.test.cc
1 // $Id$
2 //
3 // Copyright (C) 2006 
4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 //     Stefan Bund <stefan.bund@fokus.fraunhofer.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 // Unit tests
24
25 //#include "INetAddressing.test.hh"
26 //#include "INetAddressing.test.ih"
27
28 // Custom includes
29 #include "INetAddressing.hh"
30
31 #include <boost/test/auto_unit_test.hpp>
32 #include <boost/test/test_tools.hpp>
33
34 #define prefix_
35 ///////////////////////////////cc.p////////////////////////////////////////
36
37 BOOST_AUTO_UNIT_TEST(inet4Address)
38 {
39     using satcom::lib::INet4Address;
40     using satcom::lib::InvalidINetAddressException;
41
42     {
43         INet4Address addr;
44     
45         addr = "127.0.0.1:12345";
46     }
47     
48     {
49         INet4Address addr1("127.0.0.1:12345");
50         INet4Address addr2(std::string("127.0.0.1:12345"));
51         INet4Address addr3("127.0.0.1",12345);
52     }
53
54     BOOST_CHECK_EQUAL( INet4Address("127.0.0.1:12345"), INet4Address("127.0.0.1",12345) );
55
56     BOOST_CHECK_THROW( INet4Address("127.0.0.1"), InvalidINetAddressException );
57     BOOST_CHECK_THROW( INet4Address("foo@bar:12345"), InvalidINetAddressException );
58     BOOST_CHECK_THROW( INet4Address("127.0.0.1:1234a"), InvalidINetAddressException );
59     BOOST_CHECK_THROW( INet4Address("foo@bar",12345), InvalidINetAddressException );
60
61     BOOST_CHECK_EQUAL( INet4Address("127.0.0.1:12345").host(), "127.0.0.1" );
62     BOOST_CHECK_EQUAL( INet4Address("127.0.0.1:12345").port(), 12345u );
63     BOOST_CHECK_EQUAL( INet4Address("127.0.0.1:12345").str(), "127.0.0.1:12345" );
64
65     {
66         INet4Address addr("127.0.0.1:12345");
67         BOOST_CHECK_EQUAL( reinterpret_cast< ::sockaddr_in * >(addr.sockaddr_p())->sin_port,
68                            htons(12345) );
69         BOOST_CHECK_EQUAL( reinterpret_cast< ::sockaddr_in * >(addr.sockaddr_p())->sin_addr.s_addr,
70                            htonl(INADDR_LOOPBACK) );
71
72         std::stringstream s;
73         s << addr;
74         BOOST_CHECK_EQUAL( s.str(), "127.0.0.1:12345" );
75     }
76 }
77
78 BOOST_AUTO_UNIT_TEST(inet6Address)
79 {
80 }
81
82 ///////////////////////////////cc.e////////////////////////////////////////
83 #undef prefix_
84
85 \f
86 // Local Variables:
87 // mode: c++
88 // c-file-style: "satcom"
89 // End: