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 UDPServer.test unit tests */
26 //#include "UDPServer.test.hh"
27 //#include "UDPServer.test.ih"
30 #include "UDPServer.hh"
32 #include "../../Utils/auto_unit_test.hh"
33 #include <boost/test/test_tools.hpp>
36 ///////////////////////////////cc.p////////////////////////////////////////
42 senf::scheduler::terminate();
49 void read(senf::ConnectedUDPv4ClientSocketHandle socket, int ev)
56 senf::ClockService::clock_type delay(unsigned ms)
58 return senf::ClockService::now() + senf::ClockService::milliseconds(ms);
63 BOOST_AUTO_UNIT_TEST(udpServer)
65 senf::console::UDPServer server (senf::INet4SocketAddress("127.0.0.1:23232"));
66 senf::ConnectedUDPv4ClientSocketHandle socket (senf::INet4SocketAddress("127.0.0.1:23232"));
67 senf::scheduler::TimerEvent timer ("udpServer test timer", &timeout);
68 senf::scheduler::FdEvent fdev ("udpServer test fd", boost::bind(&read, socket, _1),
69 socket, senf::scheduler::FdEvent::EV_READ);
75 timer.timeout(delay(300));
76 senf::scheduler::process();
77 BOOST_CHECK_EQUAL( nread, 1 );
78 BOOST_CHECK_EQUAL( flags, senf::scheduler::FdEvent::EV_READ );
79 BOOST_CHECK_EQUAL( data, "sys/ \n" );
81 // Check exception handling
86 timer.timeout(delay(300));
87 senf::scheduler::process();
88 BOOST_CHECK_EQUAL( nread, 1 );
89 BOOST_CHECK_EQUAL( flags, senf::scheduler::FdEvent::EV_READ );
90 BOOST_CHECK_EQUAL( data, "invalid command\n" "at <unknown>:1:4\n" );
96 socket.write("cd sys");
97 timer.timeout(delay(300));
98 senf::scheduler::process();
99 BOOST_CHECK_EQUAL( nread, 1 );
100 BOOST_CHECK_EQUAL( flags, senf::scheduler::FdEvent::EV_READ );
101 BOOST_CHECK_EQUAL( data, std::string(1, '\0') );
103 // Check that we go back to the root dir for every packet
108 timer.timeout(delay(300));
109 senf::scheduler::process();
110 BOOST_CHECK_EQUAL( nread, 1 );
111 BOOST_CHECK_EQUAL( flags, senf::scheduler::FdEvent::EV_READ );
112 BOOST_CHECK_EQUAL( data, "sys/ \n" );
115 ///////////////////////////////cc.e////////////////////////////////////////
122 // comment-column: 40
123 // c-file-style: "senf"
124 // indent-tabs-mode: nil
125 // ispell-local-dictionary: "american"
126 // compile-command: "scons -u test"