2 The software in this package is distributed under the GNU General
3 Public License version 2 (with a special exception described below).
5 A copy of GNU General Public License (GPL) is included in this distribution,
6 in the file COPYING.GPL.
8 As a special exception, if other files instantiate templates or use macros
9 or inline functions from this file, or you compile this file and link it
10 with other works to produce a work based on this file, this file
11 does not by itself cause the resulting work to be covered
12 by the GNU General Public License.
14 However the source code for this file must still be made available
15 in accordance with section (3) of the GNU General Public License.
17 This exception does not invalidate any other reasons why a work based
18 on this file might be covered by the GNU General Public License.
21 Pid file handling unit tests
23 @copyright Intra2net AG
33 #define BOOST_TEST_DYN_LINK
34 #include <boost/test/unit_test.hpp>
36 #include <pidfile.hpp>
37 #include <filefunc.hxx>
41 class TestPidFileFixture
50 out << "test_pidfile.run." << getpid();
60 BOOST_FIXTURE_TEST_SUITE(TestPidFile, TestPidFileFixture)
62 BOOST_AUTO_TEST_CASE(WriteFile)
64 PidFile pidfile(Filename);
65 bool rtn_write = pidfile.write();
67 BOOST_CHECK_EQUAL(true, rtn_write);
70 BOOST_AUTO_TEST_CASE(AutoRemoval)
72 bool rtn_write = false;
74 PidFile pidfile(Filename);
75 rtn_write = pidfile.write();
77 bool exists = I2n::file_exists(Filename);
79 BOOST_CHECK_EQUAL(true, rtn_write);
80 BOOST_CHECK_EQUAL(false, exists);
83 BOOST_AUTO_TEST_CASE(NoAutoRemoval)
85 bool rtn_write = false;
87 PidFile pidfile(Filename, false);
88 rtn_write = pidfile.write();
90 bool exists = I2n::file_exists(Filename);
91 I2n::unlink(Filename);
93 BOOST_CHECK_EQUAL(true, rtn_write);
94 BOOST_CHECK_EQUAL(true, exists);
97 BOOST_AUTO_TEST_CASE(NotRunning)
99 PidFile pidfile(Filename);
100 bool rtn_check = pidfile.check_already_running();
102 BOOST_CHECK_EQUAL(false, rtn_check);
105 BOOST_AUTO_TEST_CASE(IsAlreadyRunning)
107 PidFile pidfile1(Filename);
108 bool rtn_file1_check = pidfile1.check_already_running();
109 bool rtn_file1_write = pidfile1.write();
111 BOOST_CHECK_EQUAL(false, rtn_file1_check);
112 BOOST_CHECK_EQUAL(true, rtn_file1_write);
114 PidFile pidfile2(Filename);
116 bool rtn_file2_check = pidfile2.check_already_running(&my_pid);
118 BOOST_CHECK_EQUAL(true, rtn_file2_check);
119 BOOST_CHECK_EQUAL(getpid(), my_pid);
122 BOOST_AUTO_TEST_SUITE_END()