From: g0dil Date: Wed, 13 Feb 2008 12:52:13 +0000 (+0000) Subject: Socket/Protocols/INet: Add MulticastSocketProtocol unit test X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=6ba573a99f93543ee32292f79865751b3e9b89a4;p=senf.git Socket/Protocols/INet: Add MulticastSocketProtocol unit test git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@693 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/PPI/Mainpage.dox b/PPI/Mainpage.dox index 17aa545..f2f2905 100644 --- a/PPI/Mainpage.dox +++ b/PPI/Mainpage.dox @@ -475,7 +475,7 @@ \ref senf::ppi::connector::PassiveOutput \ref senf::ppi::detail::EventBindingBase \ref senf::ppi::connector::InputConnector - \ref senf::ppi::RouteImplementation + \ref senf::ppi::detail::RouteImplementation \ref senf::ppi::connector::OutputConnector \ref senf::ppi::connector::ActiveConnector \ref senf::ppi::detail::EventBinding diff --git a/Socket/Protocols/INet/MulticastSocketProtocol.cc b/Socket/Protocols/INet/MulticastSocketProtocol.cc index 8c7fb37..ba30fce 100644 --- a/Socket/Protocols/INet/MulticastSocketProtocol.cc +++ b/Socket/Protocols/INet/MulticastSocketProtocol.cc @@ -39,6 +39,7 @@ // senf::MulticastSocketProtocol prefix_ void senf::MulticastSocketProtocol::broadcastEnabled(bool v) + const { int ivalue (v); if (::setsockopt(fd(), SOL_SOCKET, SO_BROADCAST, &ivalue, sizeof(ivalue)) < 0) @@ -46,6 +47,7 @@ prefix_ void senf::MulticastSocketProtocol::broadcastEnabled(bool v) } prefix_ bool senf::MulticastSocketProtocol::broadcastEnabled() + const { int value (0); ::socklen_t len (sizeof(value)); @@ -57,7 +59,7 @@ prefix_ bool senf::MulticastSocketProtocol::broadcastEnabled() prefix_ bool senf::MulticastSocketProtocol::mcLoop() const { - int value; + int value (0); socklen_t len (sizeof(value)); if (::getsockopt(fd(),SOL_IP,IP_MULTICAST_LOOP,&value,&len) < 0) throw SystemException(); @@ -89,7 +91,7 @@ prefix_ void senf::MulticastSocketProtocol::mcIface(std::string const & iface) prefix_ unsigned senf::MulticastSocketProtocol::mcTTL() const { - int value; + int value (0); socklen_t len (sizeof(value)); if (::getsockopt(fd(),SOL_IP,IP_MULTICAST_TTL,&value,&len) < 0) throw SystemException(); diff --git a/Socket/Protocols/INet/MulticastSocketProtocol.hh b/Socket/Protocols/INet/MulticastSocketProtocol.hh index 9cb8e19..b1dcf4a 100644 --- a/Socket/Protocols/INet/MulticastSocketProtocol.hh +++ b/Socket/Protocols/INet/MulticastSocketProtocol.hh @@ -45,14 +45,14 @@ namespace senf { : public virtual SocketProtocol { public: - void broadcastEnabled(bool v); ///< Enable broadcast send/receive + void broadcastEnabled(bool v) const; ///< Enable broadcast send/receive /**< If this option is enabled, broadcast UDP messages will be received on the socket and the socket will be allowed to send out broadcast UDP messages \param[in] v \c true to enable broadcast send/receive, \c false to disable */ - bool broadcastEnabled(); ///< Get broadcast send/receive state + bool broadcastEnabled() const; ///< Get broadcast send/receive state /**< \returns Current state of the broadcastEnabled() option. */ diff --git a/Socket/Protocols/INet/MulticastSocketProtocol.test.cc b/Socket/Protocols/INet/MulticastSocketProtocol.test.cc new file mode 100644 index 0000000..6f23b5d --- /dev/null +++ b/Socket/Protocols/INet/MulticastSocketProtocol.test.cc @@ -0,0 +1,72 @@ +// $Id$ +// +// Copyright (C) 2008 +// Fraunhofer Institute for Open Communication Systems (FOKUS) +// Competence Center NETwork research (NET), St. Augustin, GERMANY +// Stefan Bund +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the +// Free Software Foundation, Inc., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +/** \file + \brief MulticastSocketProtocol.test unit tests */ + +//#include "MulticastSocketProtocol.test.hh" +//#include "MulticastSocketProtocol.test.ih" + +// Custom includes +#include "UDPSocketHandle.hh" + +#include +#include + +#define prefix_ +///////////////////////////////cc.p//////////////////////////////////////// + +BOOST_AUTO_UNIT_TEST(multicastSocketProtocol) +{ + senf::UDPv4ClientSocketHandle sock; + + sock.protocol().broadcastEnabled(false); + BOOST_CHECK( ! sock.protocol().broadcastEnabled() ); + sock.protocol().broadcastEnabled(true); + BOOST_CHECK( sock.protocol().broadcastEnabled() ); + + sock.protocol().mcTTL(4u); + BOOST_CHECK_EQUAL( sock.protocol().mcTTL(), 4u ); + sock.protocol().mcTTL(1u); + BOOST_CHECK_EQUAL( sock.protocol().mcTTL(), 1u ); + + sock.protocol().mcLoop(false); + BOOST_CHECK( ! sock.protocol().mcLoop() ); + sock.protocol().mcLoop(true); + BOOST_CHECK( sock.protocol().mcLoop() ); + + sock.protocol().mcIface("lo"); +} + +///////////////////////////////cc.e//////////////////////////////////////// +#undef prefix_ + + +// Local Variables: +// mode: c++ +// fill-column: 100 +// comment-column: 40 +// c-file-style: "senf" +// indent-tabs-mode: nil +// ispell-local-dictionary: "american" +// compile-command: "scons -u test" +// End: