Migrate from cppunit to Boost.test
[libt2n] / test / test_fixtures.hxx
CommitLineData
307b5e74
TJ
1/*
2Copyright (C) 2010 by Intra2net AG - Thomas Jarosch
3
4The software in this package is distributed under the GNU General
5Public License version 2 (with a special exception described below).
6
7A copy of GNU General Public License (GPL) is included in this distribution,
8in the file COPYING.GPL.
9
10As a special exception, if other files instantiate templates or use macros
11or inline functions from this file, or you compile this file and link it
12with other works to produce a work based on this file, this file
13does not by itself cause the resulting work to be covered
14by the GNU General Public License.
15
16However the source code for this file must still be made available
17in accordance with section (3) of the GNU General Public License.
18
19This exception does not invalidate any other reasons why a work based
20on this file might be covered by the GNU General Public License.
21*/
22#ifndef __LIBT2N_TEST_FIXTURES
23#define __LIBT2N_TEST_FIXTURES
24
25#include <sys/wait.h>
26#include <sys/types.h>
27#include <signal.h>
28
29class KillChildOnShutdownFixture
30{
31protected:
32 pid_t child_pid;
33
34public:
35 KillChildOnShutdownFixture()
36 : child_pid(0)
37 {
38 // Work around Boost.test reporting killed childs as "fatal error".
39 // Can be ignored with boost 1.40.0+, need to check after upgrade
40 signal(SIGCHLD, SIG_IGN);
41 }
42
43 ~KillChildOnShutdownFixture()
44 {
45 // make sure the server-child is dead before the next test runs
46 if (child_pid)
47 {
48 // std::cout << "Killing child with pid: " << child_pid << std::endl;
49 kill(child_pid, SIGKILL);
50
51 int status = 0;
52 waitpid(child_pid, &status, 0);
53 }
54 }
55};
56
57#endif