X-Git-Url: http://g0dil.de/git?p=senf.git;a=blobdiff_plain;f=senf%2FSocket%2FProtocols%2FINet%2Fnet.test.cc;fp=senf%2FSocket%2FProtocols%2FINet%2Fnet.test.cc;h=aee08d144ca6de93406df5e0bcdc6cb6a04d6737;hp=0000000000000000000000000000000000000000;hb=74febc7a9abc84c4939269b3443d15fc27f4e960;hpb=9de1568365b7ac411b84da000e18516d9c3b3293 diff --git a/senf/Socket/Protocols/INet/net.test.cc b/senf/Socket/Protocols/INet/net.test.cc new file mode 100644 index 0000000..aee08d1 --- /dev/null +++ b/senf/Socket/Protocols/INet/net.test.cc @@ -0,0 +1,124 @@ +// $Id$ +// +// Copyright (C) 2009 +// Fraunhofer Institute for Open Communication Systems (FOKUS) +// +// The contents of this file are subject to the Fraunhofer FOKUS Public License +// Version 1.0 (the "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// http://senf.berlios.de/license.html +// +// The Fraunhofer FOKUS Public License Version 1.0 is based on, +// but modifies the Mozilla Public License Version 1.1. +// See the full license text for the amendments. +// +// Software distributed under the License is distributed on an "AS IS" basis, +// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License +// for the specific language governing rights and limitations under the License. +// +// The Original Code is Fraunhofer FOKUS code. +// +// The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. +// (registered association), Hansastraße 27 c, 80686 Munich, Germany. +// All Rights Reserved. +// +// Contributor(s): +// Stefan Bund + +/** \file + \brief net.test public header */ + +#include "net.test.hh" + +// Custom includes +#include +#include +#include +#include +#include +#include +#include +#include + +//-///////////////////////////////////////////////////////////////////////////////////////////////// +namespace { + int base_pid = 0; + int server_pid = 0; +} + +void senf::test::error(char const * fn, char const * proc) +{ + std::cerr << "\n" << proc << ((*proc)?": ":"") << fn << ": " << strerror(errno) << std::endl; +} + +void senf::test::fail(char const * proc, char const * fn) +{ + error(fn,proc); + _exit(1); +} + +void senf::test::start(void (*fn)()) +{ + if (! base_pid) + base_pid = ::getpid(); + server_pid = ::fork(); + if (server_pid < 0) BOOST_FAIL("fork()"); + if (server_pid == 0) { + signal(SIGCHLD, SIG_IGN); + (*fn)(); + _exit(0); + } + signal(SIGCHLD, SIG_DFL); + sleep(1); +} + +void senf::test::wait() +{ + int status; + if (waitpid(server_pid,&status,0)<0) + BOOST_FAIL("waitpid()"); + BOOST_CHECK_EQUAL( status , 0 ); +} + +void senf::test::stop() +{ + if (server_pid) { + kill(server_pid,9); + wait(); + server_pid = 0; + } +} + +unsigned senf::test::port(unsigned i) +{ + if (! base_pid) + base_pid = ::getpid(); + return 23456u + (((base_pid^(base_pid>>8)^(base_pid>>16)^(base_pid>>24))&0xff)<<2) + i; +} + +std::string senf::test::localhost4str(unsigned i) +{ + return (boost::format("localhost:%d") % port(i)).str(); +} + +std::string senf::test::localhost6str(unsigned i) +{ + return (boost::format("[::1]:%d") % port(i)).str(); +} + + +//-///////////////////////////////////////////////////////////////////////////////////////////////// +//#include "net.test.cci" +//#include "net.test.ct" +//#include "net.test.cti" + + +// 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: