Socket/Protocols/INet: Add MulticastSocketProtocol unit test
g0dil [Wed, 13 Feb 2008 12:52:13 +0000 (12:52 +0000)]
git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@693 270642c3-0616-0410-b53a-bc976706d245

PPI/Mainpage.dox
Socket/Protocols/INet/MulticastSocketProtocol.cc
Socket/Protocols/INet/MulticastSocketProtocol.hh
Socket/Protocols/INet/MulticastSocketProtocol.test.cc [new file with mode: 0644]

index 17aa545..f2f2905 100644 (file)
     <span coords="597,543,717,570">\ref senf::ppi::connector::PassiveOutput</span>
     <span coords="66,432,210,459">\ref senf::ppi::detail::EventBindingBase</span>
     <span coords="378,428,505,455">\ref senf::ppi::connector::InputConnector</span>
-    <span coords="491,124,694,210">\ref senf::ppi::RouteImplementation</span>
+    <span coords="491,124,694,210">\ref senf::ppi::detail::RouteImplementation</span>
     <span coords="283,464,423,491">\ref senf::ppi::connector::OutputConnector</span>
     <span coords="512,428,645,455">\ref senf::ppi::connector::ActiveConnector</span>
     <span coords="85,487,259,527">\ref senf::ppi::detail::EventBinding</span>
index 8c7fb37..ba30fce 100644 (file)
@@ -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();
index 9cb8e19..b1dcf4a 100644 (file)
@@ -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 (file)
index 0000000..6f23b5d
--- /dev/null
@@ -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 <g0dil@berlios.de>
+//
+// 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 <boost/test/auto_unit_test.hpp>
+#include <boost/test/test_tools.hpp>
+
+#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_
+
+\f
+// 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: