Fix documentation build under maverick (doxygen 1.7.1)
[senf.git] / senf / Socket / Protocols / INet / net.test.hh
1 // $Id$
2 //
3 // Copyright (C) 2009
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.de>
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
23 /** \file
24     \brief net.test public header */
25
26 #ifndef HH_SENF_senf_Socket_Protocols_INet_net_test_
27 #define HH_SENF_senf_Socket_Protocols_INet_net_test_ 1
28
29 // Custom includes
30 #include <boost/format.hpp>
31 #include <boost/test/test_tools.hpp>
32
33 //#include "net.test.mpp"
34 //-/////////////////////////////////////////////////////////////////////////////////////////////////
35
36 namespace {
37
38     void error(char const * fn, char const * proc="")
39     {
40         std::cerr << "\n" << proc << ((*proc)?": ":"") << fn << ": " << strerror(errno) << std::endl;
41     }
42
43     void fail(char const * proc, char const * fn)
44     {
45         error(fn,proc);
46         _exit(1);
47     }
48
49     int base_pid = 0;
50     int server_pid = 0;
51
52     void start(void (*fn)())
53     {
54         if (! base_pid)
55             base_pid = ::getpid();
56         server_pid = ::fork();
57         if (server_pid < 0) BOOST_FAIL("fork()");
58         if (server_pid == 0) {
59             signal(SIGCHLD, SIG_IGN);
60             (*fn)();
61             _exit(0);
62         }
63         signal(SIGCHLD, SIG_DFL);
64         sleep(1);
65     }
66
67     void wait()
68     {
69         int status;
70         if (waitpid(server_pid,&status,0)<0)
71             BOOST_FAIL("waitpid()");
72         BOOST_CHECK_EQUAL( status , 0 );
73     }
74
75     void stop()
76     {
77         if (server_pid) {
78             kill(server_pid,9);
79             wait();
80             server_pid = 0;
81         }
82     }
83
84     unsigned port(unsigned i)
85     {
86         if (! base_pid)
87             base_pid = ::getpid();
88         return 23456u + (((base_pid^(base_pid>>8)^(base_pid>>16)^(base_pid>>24))&0xff)<<2) + i;
89     }
90
91     std::string localhost4str(unsigned i)
92     {
93         return (boost::format("localhost:%d") % port(i)).str();
94     }
95
96     std::string localhost6str(unsigned i)
97     {
98         return (boost::format("[::1]:%d") % port(i)).str();
99     }
100
101 }
102
103 //-/////////////////////////////////////////////////////////////////////////////////////////////////
104 //#include "net.test.cci"
105 //#include "net.test.ct"
106 //#include "net.test.cti"
107 #endif
108
109 \f
110 // Local Variables:
111 // mode: c++
112 // fill-column: 100
113 // comment-column: 40
114 // c-file-style: "senf"
115 // indent-tabs-mode: nil
116 // ispell-local-dictionary: "american"
117 // compile-command: "scons -u test"
118 // End: