4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
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.
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.
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.
24 \brief UDPSocketHandle unit tests */
26 //#include "UDPSocketHandle.test.hh"
27 //#include "UDPSocketHandle.test.ih"
30 #include <sys/types.h>
31 #include <sys/ioctl.h>
34 #include <sys/socket.h>
35 #include <netinet/in.h>
37 #include "UDPSocketHandle.hh"
38 #include "net.test.hh"
40 #include <senf/Utils/auto_unit_test.hh>
41 #include <boost/test/test_tools.hpp>
44 ///////////////////////////////cc.p////////////////////////////////////////
46 ///////////////////////////////////////////////////////////////////////////
52 int sock = socket(PF_INET,SOCK_DGRAM,0);
53 if (sock<0) fail("server_v4","socket()");
54 struct sockaddr_in sin;
55 ::memset(&sin,0,sizeof(sin));
56 sin.sin_family = AF_INET;
57 sin.sin_port = htons(port(0));
58 sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
59 if (bind(sock,(struct sockaddr *)&sin,sizeof(sin))<0) fail("server_v4","bind()");
61 sin.sin_port = htons(port(1));
64 int n = read(sock,buffer,1024);
65 if (n == 4 && strncmp(buffer,"QUIT",4) == 0)
67 sendto(sock,buffer,n,0,(struct sockaddr *)&sin,sizeof(sin));
70 if (close(sock) < 0) fail("server_v4","close()");
75 int sock = socket(PF_INET6,SOCK_DGRAM,0);
76 if (sock<0) fail("server_v6","socket()");
77 struct sockaddr_in6 sin;
78 ::memset(&sin,0,sizeof(sin));
79 sin.sin6_family = AF_INET6;
80 sin.sin6_port = htons(port(0));
81 sin.sin6_addr = in6addr_loopback;
82 if (bind(sock,(struct sockaddr *)&sin,sizeof(sin))<0) fail("server_v6","bind()");
84 sin.sin6_port = htons(port(1));
87 int n = read(sock,buffer,1024);
88 if (n == 4 && strncmp(buffer,"QUIT",4) == 0)
90 sendto(sock,buffer,n,0,(struct sockaddr *)&sin,sizeof(sin));
93 if (close(sock) < 0) fail("server_v6","close()");
98 SENF_AUTO_UNIT_TEST(udpv4ClientSocketHandle)
103 senf::UDPv4ClientSocketHandle sock;
104 SENF_CHECK_NO_THROW( sock.bind(senf::INet4SocketAddress(localhost4str(1))) );
105 BOOST_CHECK( sock.local() == senf::INet4SocketAddress(localhost4str(1)) );
106 SENF_CHECK_NO_THROW( sock.protocol().rcvbuf(2048) );
107 BOOST_CHECK_EQUAL( sock.protocol().rcvbuf(), 2048u );
108 SENF_CHECK_NO_THROW( sock.protocol().sndbuf(2048) );
109 BOOST_CHECK_EQUAL( sock.protocol().sndbuf(), 2048u );
110 SENF_CHECK_NO_THROW( sock.writeto(senf::INet4SocketAddress(localhost4str(0)),
111 std::string("TEST-WRITE")) );
112 BOOST_CHECK_EQUAL( sock.read(), "TEST-WRITE" );
113 SENF_CHECK_NO_THROW( sock.protocol().timestamp() );
114 sock.writeto(senf::INet4SocketAddress(localhost4str(0)), std::string("QUIT"));
128 ///////////////////////////////cc.e////////////////////////////////////////
135 // c-file-style: "senf"
136 // indent-tabs-mode: nil
137 // ispell-local-dictionary: "american"
138 // compile-command: "scons -u test"
139 // comment-column: 40