Skip to content
Snippets Groups Projects
Commit 11acd2bf authored by dw6's avatar dw6
Browse files

removed some errors, added basic unit tests

parent a1ecefaf
No related branches found
No related tags found
No related merge requests found
Showing with 362 additions and 17 deletions
...@@ -36,9 +36,8 @@ prefix_ senf::UNAddress::UNAddress() ...@@ -36,9 +36,8 @@ prefix_ senf::UNAddress::UNAddress()
} }
prefix_ senf::UNAddress::UNAddress(boost::filesystem::path p) prefix_ senf::UNAddress::UNAddress(boost::filesystem::path p)
//:path(p)
{ {
path = p;
} }
...@@ -52,12 +51,18 @@ prefix_ senf::UNAddress::UNAddress senf::UNAddress::fromPath(boost::filesystem:: ...@@ -52,12 +51,18 @@ prefix_ senf::UNAddress::UNAddress senf::UNAddress::fromPath(boost::filesystem::
} }
prefix_ std::string senf::UNAddress::pathString() prefix_ std::string senf::UNAddress::pathString()
const
{ {
return path.string(); return path.string();
} }
prefix_ senf::UNAddress::UNAddress senf::UNAddress::clone()
{
senf::UNAddress::UNAddress local_addr = senf::UNAddress::UNAddress(pathString());
return local_addr;
}
prefix_ const std::ostream & senf::operator<<(std::ostream & os, UNAddress const & addr) prefix_ std::ostream & senf::operator<<(std::ostream & os, UNAddress const & addr)
{ {
os << addr.pathString(); os << addr.pathString();
return os; return os;
......
...@@ -48,16 +48,17 @@ namespace senf { ...@@ -48,16 +48,17 @@ namespace senf {
explicit UNAddress(boost::filesystem::path);///< Construct an address constant from given path explicit UNAddress(boost::filesystem::path);///< Construct an address constant from given path
static UNAddress fromString(std::string & s); ///< Convert string to address by interpreting the string as path static UNAddress fromString(std::string & s); ///< Convert string to address by interpreting the string as path
static UNAddress fromPath(boost::filesystem::path & p);///< Convert path to address static UNAddress fromPath(boost::filesystem::path & p);///< Convert path to address
static std::string pathString(); ///< Return the path of the address as string UNAddress clone(); ///< Clone object
std::string pathString() const; ///< Return the path of the address as string
/** \brief Base-class for UNAddress exceptions */ /** \brief Base-class for UNAddress exceptions */
struct AddressException : public std::exception {}; struct AddressException : public std::exception {};
private: private:
static boost::filesystem::path path; boost::filesystem::path path;
}; };
const std::ostream & operator<<(std::ostream & os, UNAddress const & addr);
std::ostream & operator<<(std::ostream & os, UNAddress const & addr);
} }
///////////////////////////////hh.e//////////////////////////////////////// ///////////////////////////////hh.e////////////////////////////////////////
......
// $Id$
//
// Copyright (C) 2007
//
// 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 UNAddress.test unit tests */
//#include "UNAddress.test.hh"
//#include "UNAddress.test.ih"
// Custom includes
#include "UNAddress.hh"
#include <boost/filesystem/path.hpp>
#include <boost/test/auto_unit_test.hpp>
#include <boost/test/test_tools.hpp>
#include <iostream>
#define prefix_
///////////////////////////////cc.p////////////////////////////////////////
BOOST_AUTO_UNIT_TEST(unAddress)
{
// das koennt sicher mehr sein...
std::string testS = "/tmp/senfTestSocket";
boost::filesystem::path testp = boost::filesystem::path(testS);
senf::UNAddress addr1 = senf::UNAddress::fromString(testS);
senf::UNAddress addr2 = senf::UNAddress::fromPath(testp);
BOOST_CHECK( testS == addr1.pathString());
BOOST_CHECK( testS == addr2.pathString());
}
///////////////////////////////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:
...@@ -55,6 +55,7 @@ prefix_ senf::UNSocketAddress::UNSocketAddress(boost::filesystem::path p) ...@@ -55,6 +55,7 @@ prefix_ senf::UNSocketAddress::UNSocketAddress(boost::filesystem::path p)
return senf::UNSocketAddress::UNSocketAddress(p); return senf::UNSocketAddress::UNSocketAddress(p);
} }
prefix_ std::string senf::UNSocketAddress::path() prefix_ std::string senf::UNSocketAddress::path()
const
{ {
return std::string(sockAddr.sun_path); return std::string(sockAddr.sun_path);
} }
...@@ -80,7 +81,6 @@ prefix_ sockaddr const * senf::UNSocketAddress::sockaddr_p() ...@@ -80,7 +81,6 @@ prefix_ sockaddr const * senf::UNSocketAddress::sockaddr_p()
} }
prefix_ unsigned senf::UNSocketAddress::sockaddr_len() prefix_ unsigned senf::UNSocketAddress::sockaddr_len()
const
{ {
return sizeof(sockAddr); return sizeof(sockAddr);
} }
......
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
namespace senf { namespace senf {
/** \brief Unix domain socket address /** \brief Unix domain socket address
UNSocketAddress wraps the standard sockaddr_in datatype. It provides simple accessor methods UNSocketAddress wraps the standard sockaddr_un datatype. It provides simple accessor methods
to access the path. to access the path.
\implementation This implementation is based on sockaddr_un. \implementation This implementation is based on sockaddr_un.
...@@ -59,14 +59,13 @@ namespace senf { ...@@ -59,14 +59,13 @@ namespace senf {
///< Construct an address constant from given path ///< Construct an address constant from given path
static UNSocketAddress from_string(std::string const s); ///< Create UNSocketAddress from string static UNSocketAddress from_string(std::string const s); ///< Create UNSocketAddress from string
static UNSocketAddress from_path(boost::filesystem::path const p); ///< Create UNSocketAddress from path static UNSocketAddress from_path(boost::filesystem::path const p); ///< Create UNSocketAddress from path
static std::string path(); ///< Return path as string std::string path() const ; ///< Return path as string
static sockaddr_un sockaddr(); struct sockaddr_un sockaddr();
struct sockaddr * sockaddr_p() ;
struct sockaddr * sockaddr_p();
struct sockaddr const * sockaddr_p() const; struct sockaddr const * sockaddr_p() const;
unsigned sockaddr_len() const; unsigned sockaddr_len();
private: private:
static struct sockaddr_un sockAddr; struct sockaddr_un sockAddr;
}; };
/** \brief Write path os /** \brief Write path os
......
File added
// $Id$
//
// Copyright (C) 2007
//
// 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 UNAddressing.test unit tests */
//#include "UNAddressing.test.hh"
//#include "UNAddressing.test.ih"
// Custom includes
#include "UNAddressing.hh"
#include <boost/test/auto_unit_test.hpp>
#include <boost/test/test_tools.hpp>
#include <sys/socket.h>
#include <sys/un.h>
#define prefix_
///////////////////////////////cc.p////////////////////////////////////////
BOOST_AUTO_UNIT_TEST(unSocketAddress)
{
std::string testS = "/tmp/senfTestSocket";
senf::UNSocketAddress addr (testS) ;
int mySock = socket(AF_UNIX, SOCK_DGRAM, 0);
if (bind(mySock, addr.sockaddr_p(), addr.sockaddr_len())) {
std::cout << "Error while binding name to unix socket" << std::endl;
}
}
///////////////////////////////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:
// $Id$
//
// Copyright (C) 2007
//
// 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 UNAddressing.test unit tests */
//#include "UNAddressing.test.hh"
//#include "UNAddressing.test.ih"
// Custom includes
#include "UNAddressing.hh"
#include <boost/test/auto_unit_test.hpp>
#include <boost/test/test_tools.hpp>
#include <sys/socket.h>
#include <sys/un.h>
#define prefix_
///////////////////////////////cc.p////////////////////////////////////////
BOOST_AUTO_UNIT_TEST(unSocketAddress)
{
std::string testS = "/tmp/senfTestSocket";
senf::UNSocketAddress addr (testS) ;
mySock = socket(AF_UNIX, SOCK_DGRAM, 0);
if (bind(mySock, addr.sockaddr_p(), addr.sockaddr_len())) {
std::cout << "Error while binding name to unix socket" std::endl;
}
}
///////////////////////////////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:
...@@ -110,7 +110,7 @@ namespace senf { ...@@ -110,7 +110,7 @@ namespace senf {
typedef MakeSocketPolicy< typedef MakeSocketPolicy<
UNDatagramSocket_Policy, UNDatagramSocket_Policy,
UNAddressingPolicy UNAddressingPolicy
>::policy UDPv6Socket_Policy; >::policy UNDatagramSocket_Policy;
} }
///////////////////////////////hh.e//////////////////////////////////////// ///////////////////////////////hh.e////////////////////////////////////////
//#include "UNDatagramSocketHandle.cci" //#include "UNDatagramSocketHandle.cci"
......
// $Id$
//
// Copyright (C) 2007
//
// 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 UNDatagramSocketHandle.test unit tests */
//#include "UNDatagramSocketHandle.test.hh"
//#include "UNDatagramSocketHandle.test.ih"
// Custom includes
#include "UNDatagramSocketHandle.hh"
#include <boost/test/auto_unit_test.hpp>
#include <boost/test/test_tools.hpp>
#define prefix_
///////////////////////////////cc.p////////////////////////////////////////
BOOST_AUTO_UNIT_TEST(unDatagramSocketHandle)
{
std::string testS = "/tmp/senfTestSocket";
senf::UNSocketAddress addr (testS) ;
//senf::UNDatagramSocketHandle init_client(addr);
senf::UNDatagramClientSocketHandle inputSocket(senf::UNSocketAddress(tests));
}
///////////////////////////////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:
...@@ -33,14 +33,14 @@ ...@@ -33,14 +33,14 @@
prefix_ void senf::UNProtocol::connect(UNSocketAddress const & address) prefix_ void senf::UNProtocol::connect(UNSocketAddress const & address)
const const
{ {
if(::connect(body().fd(), address.sockaddr_p(), sizeof(address.sockaddr())) < 0) if(::connect(body().fd(), address.sockaddr_p(), sizeof(sockaddr_un)) < 0)
throw SystemException(errno); throw SystemException(errno);
} }
prefix_ void senf::UNProtocol::bind(UNSocketAddress const & address) prefix_ void senf::UNProtocol::bind(UNSocketAddress const & address)
const const
{ {
if(::bind(body().fd(), address.sockaddr_p(), sizeof(address.sockaddr())) < 0) if(::bind(body().fd(), address.sockaddr_p(), sizeof(sockaddr_un)) < 0)
throw SystemException(errno); throw SystemException(errno);
} }
......
// $Id$
//
// Copyright (C) 2007
//
// 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 UNProtocol.test unit tests */
//#include "UNProtocol.test.hh"
//#include "UNProtocol.test.ih"
// Custom includes
#include "UNProtocol.hh"
#include <boost/test/auto_unit_test.hpp>
#include <boost/test/test_tools.hpp>
#define prefix_
///////////////////////////////cc.p////////////////////////////////////////
BOOST_AUTO_UNIT_TEST(unProtocol)
{
std::string testS = "/tmp/senfTestSocket";
//zZ leer
}
///////////////////////////////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:
// $Id: main.test.cc 296 2007-07-10 20:39:34Z g0dil $
//
// Copyright (C) 2006
// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
// Stefan Bund <stefan.bund@fokus.fraunhofer.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.
// Definition of non-inline non-template functions
//#include "test.hh"
//#include "test.ih"
// Custom includes
#define BOOST_AUTO_TEST_MAIN
#include <boost/test/auto_unit_test.hpp>
#include <boost/test/test_tools.hpp>
#define prefix_
///////////////////////////////cc.p////////////////////////////////////////
///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_
// Local Variables:
// mode: c++
// fill-column: 100
// c-file-style: "senf"
// indent-tabs-mode: nil
// ispell-local-dictionary: "american"
// compile-command: "scons -u test"
// comment-column: 40
// End:
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment