4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at
9 // http://senf.berlios.de/license.html
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on,
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
15 // Software distributed under the License is distributed on an "AS IS" basis,
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
17 // for the specific language governing rights and limitations under the License.
19 // The Original Code is Fraunhofer FOKUS code.
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V.
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
26 // Stefan Bund <g0dil@berlios.de>
29 \brief UDPSocketHandle unit tests */
31 //#include "UDPSocketHandle.test.hh"
32 //#include "UDPSocketHandle.test.ih"
35 #include <sys/types.h>
36 #include <sys/ioctl.h>
39 #include <sys/socket.h>
40 #include <netinet/in.h>
42 #include "UDPSocketHandle.hh"
43 #include "net.test.hh"
45 #include <senf/Utils/auto_unit_test.hh>
46 #include <boost/test/test_tools.hpp>
49 //-/////////////////////////////////////////////////////////////////////////////////////////////////
51 using namespace senf::test;
57 int sock = socket(PF_INET,SOCK_DGRAM,0);
58 if (sock<0) fail("server_v4","socket()");
59 struct sockaddr_in sin;
60 ::memset(&sin,0,sizeof(sin));
61 sin.sin_family = AF_INET;
62 sin.sin_port = htons(port(0));
63 sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
64 if (bind(sock,(struct sockaddr *)&sin,sizeof(sin))<0) fail("server_v4","bind()");
66 sin.sin_port = htons(port(1));
69 int n = read(sock,buffer,1024);
70 if (n == 4 && strncmp(buffer,"QUIT",4) == 0)
72 sendto(sock,buffer,n,0,(struct sockaddr *)&sin,sizeof(sin));
75 if (close(sock) < 0) fail("server_v4","close()");
80 // int sock = socket(PF_INET6,SOCK_DGRAM,0);
81 // if (sock<0) fail("server_v6","socket()");
82 // struct sockaddr_in6 sin;
83 // ::memset(&sin,0,sizeof(sin));
84 // sin.sin6_family = AF_INET6;
85 // sin.sin6_port = htons(port(0));
86 // sin.sin6_addr = in6addr_loopback;
87 // if (bind(sock,(struct sockaddr *)&sin,sizeof(sin))<0) fail("server_v6","bind()");
89 // sin.sin6_port = htons(port(1));
92 // int n = read(sock,buffer,1024);
93 // if (n == 4 && strncmp(buffer,"QUIT",4) == 0)
95 // sendto(sock,buffer,n,0,(struct sockaddr *)&sin,sizeof(sin));
98 // if (close(sock) < 0) fail("server_v6","close()");
103 SENF_AUTO_UNIT_TEST(udpv4ClientSocketHandle)
108 senf::UDPv4ClientSocketHandle sock;
109 SENF_CHECK_NO_THROW( sock.bind(senf::INet4SocketAddress(localhost4str(1))) );
110 BOOST_CHECK( sock.local() == senf::INet4SocketAddress(localhost4str(1)) );
111 SENF_CHECK_NO_THROW( sock.protocol().rcvbuf(2048) );
112 BOOST_CHECK_EQUAL( sock.protocol().rcvbuf(), 2048u );
113 SENF_CHECK_NO_THROW( sock.protocol().sndbuf(2048) );
114 BOOST_CHECK_EQUAL( sock.protocol().sndbuf(), 2048u );
115 SENF_CHECK_NO_THROW( sock.writeto(senf::INet4SocketAddress(localhost4str(0)),
116 std::string("TEST-WRITE")) );
117 BOOST_CHECK_EQUAL( sock.read(), "TEST-WRITE" );
118 SENF_CHECK_NO_THROW( sock.protocol().timestamp() );
119 sock.writeto(senf::INet4SocketAddress(localhost4str(0)), std::string("QUIT"));
133 //-/////////////////////////////////////////////////////////////////////////////////////////////////
140 // c-file-style: "senf"
141 // indent-tabs-mode: nil
142 // ispell-local-dictionary: "american"
143 // compile-command: "scons -u test"
144 // comment-column: 40