From: dw6 Date: Wed, 19 Sep 2007 16:00:00 +0000 (+0000) Subject: removed some errors, added basic unit tests X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=4225a17d92c3692e6d3f96a8dd5cb432cd402e61;p=senf.git removed some errors, added basic unit tests git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@448 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/Socket/Protocols/UN/UNAddress.cc b/Socket/Protocols/UN/UNAddress.cc index 870f2b9..70aab9a 100644 --- a/Socket/Protocols/UN/UNAddress.cc +++ b/Socket/Protocols/UN/UNAddress.cc @@ -36,9 +36,8 @@ prefix_ senf::UNAddress::UNAddress() } 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:: } prefix_ std::string senf::UNAddress::pathString() + const { 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(); return os; diff --git a/Socket/Protocols/UN/UNAddress.hh b/Socket/Protocols/UN/UNAddress.hh index 67a7061..e5cb5f2 100644 --- a/Socket/Protocols/UN/UNAddress.hh +++ b/Socket/Protocols/UN/UNAddress.hh @@ -48,16 +48,17 @@ namespace senf { 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 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 */ struct AddressException : public std::exception {}; 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//////////////////////////////////////// diff --git a/Socket/Protocols/UN/UNAddress.test.cc b/Socket/Protocols/UN/UNAddress.test.cc new file mode 100644 index 0000000..d6ade16 --- /dev/null +++ b/Socket/Protocols/UN/UNAddress.test.cc @@ -0,0 +1,59 @@ +// $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 +#include +#include + +#include +#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: diff --git a/Socket/Protocols/UN/UNAddressing.cc b/Socket/Protocols/UN/UNAddressing.cc index abc278f..ce957e4 100644 --- a/Socket/Protocols/UN/UNAddressing.cc +++ b/Socket/Protocols/UN/UNAddressing.cc @@ -55,6 +55,7 @@ prefix_ senf::UNSocketAddress::UNSocketAddress(boost::filesystem::path p) return senf::UNSocketAddress::UNSocketAddress(p); } prefix_ std::string senf::UNSocketAddress::path() + const { return std::string(sockAddr.sun_path); } @@ -80,7 +81,6 @@ prefix_ sockaddr const * senf::UNSocketAddress::sockaddr_p() } prefix_ unsigned senf::UNSocketAddress::sockaddr_len() - const { return sizeof(sockAddr); } diff --git a/Socket/Protocols/UN/UNAddressing.hh b/Socket/Protocols/UN/UNAddressing.hh index 25b02d9..f30cfdd 100644 --- a/Socket/Protocols/UN/UNAddressing.hh +++ b/Socket/Protocols/UN/UNAddressing.hh @@ -42,7 +42,7 @@ namespace senf { /** \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. \implementation This implementation is based on sockaddr_un. @@ -59,14 +59,13 @@ namespace senf { ///< Construct an address constant from given path 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 std::string path(); ///< Return path as string - static sockaddr_un sockaddr(); - - struct sockaddr * sockaddr_p(); + std::string path() const ; ///< Return path as string + struct sockaddr_un sockaddr(); + struct sockaddr * sockaddr_p() ; struct sockaddr const * sockaddr_p() const; - unsigned sockaddr_len() const; + unsigned sockaddr_len(); private: - static struct sockaddr_un sockAddr; + struct sockaddr_un sockAddr; }; /** \brief Write path os diff --git a/Socket/Protocols/UN/UNAddressing.o b/Socket/Protocols/UN/UNAddressing.o new file mode 100644 index 0000000..417b79b Binary files /dev/null and b/Socket/Protocols/UN/UNAddressing.o differ diff --git a/Socket/Protocols/UN/UNAddressing.test.cc b/Socket/Protocols/UN/UNAddressing.test.cc new file mode 100644 index 0000000..b3b76e8 --- /dev/null +++ b/Socket/Protocols/UN/UNAddressing.test.cc @@ -0,0 +1,61 @@ +// $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 +#include + +#include +#include + +#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: diff --git a/Socket/Protocols/UN/UNAddressing.test.cc~ b/Socket/Protocols/UN/UNAddressing.test.cc~ new file mode 100644 index 0000000..7f224cf --- /dev/null +++ b/Socket/Protocols/UN/UNAddressing.test.cc~ @@ -0,0 +1,61 @@ +// $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 +#include + +#include +#include + +#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: diff --git a/Socket/Protocols/UN/UNDatagramSocketHandle.hh b/Socket/Protocols/UN/UNDatagramSocketHandle.hh index 458a958..0956525 100644 --- a/Socket/Protocols/UN/UNDatagramSocketHandle.hh +++ b/Socket/Protocols/UN/UNDatagramSocketHandle.hh @@ -110,7 +110,7 @@ namespace senf { typedef MakeSocketPolicy< UNDatagramSocket_Policy, UNAddressingPolicy - >::policy UDPv6Socket_Policy; + >::policy UNDatagramSocket_Policy; } ///////////////////////////////hh.e//////////////////////////////////////// //#include "UNDatagramSocketHandle.cci" diff --git a/Socket/Protocols/UN/UNDatagramSocketHandle.test.cc b/Socket/Protocols/UN/UNDatagramSocketHandle.test.cc new file mode 100644 index 0000000..d648574 --- /dev/null +++ b/Socket/Protocols/UN/UNDatagramSocketHandle.test.cc @@ -0,0 +1,56 @@ +// $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 +#include + +#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: diff --git a/Socket/Protocols/UN/UNProtocol.cc b/Socket/Protocols/UN/UNProtocol.cc index d3afe3f..d04192d 100644 --- a/Socket/Protocols/UN/UNProtocol.cc +++ b/Socket/Protocols/UN/UNProtocol.cc @@ -33,14 +33,14 @@ prefix_ void senf::UNProtocol::connect(UNSocketAddress const & address) 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); } prefix_ void senf::UNProtocol::bind(UNSocketAddress const & address) 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); } diff --git a/Socket/Protocols/UN/UNProtocol.test.cc b/Socket/Protocols/UN/UNProtocol.test.cc new file mode 100644 index 0000000..5ab47b6 --- /dev/null +++ b/Socket/Protocols/UN/UNProtocol.test.cc @@ -0,0 +1,54 @@ +// $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 +#include + +#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: diff --git a/Socket/Protocols/UN/main.test.cc b/Socket/Protocols/UN/main.test.cc new file mode 100644 index 0000000..91e601d --- /dev/null +++ b/Socket/Protocols/UN/main.test.cc @@ -0,0 +1,49 @@ +// $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 +// +// 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 +#include + +#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: