/* The software in this package is distributed under the GNU General Public License version 2 (with a special exception described below). A copy of GNU General Public License (GPL) is included in this distribution, in the file COPYING.GPL. As a special exception, if other files instantiate templates or use macros or inline functions from this file, or you compile this file and link it with other works to produce a work based on this file, this file does not by itself cause the resulting work to be covered by the GNU General Public License. However the source code for this file must still be made available in accordance with section (3) of the GNU General Public License. This exception does not invalidate any other reasons why a work based on this file might be covered by the GNU General Public License. */ /** Pid file handling unit tests @copyright Intra2net AG */ #include #include #include #include #include #define BOOST_TEST_DYN_LINK #include #include #include using namespace std; class TestPidFileFixture { protected: string Filename; public: TestPidFileFixture() { ostringstream out; out << "test_pidfile.run." << getpid(); Filename = out.str(); } ~TestPidFileFixture() { } }; BOOST_FIXTURE_TEST_SUITE(TestPidFile, TestPidFileFixture) BOOST_AUTO_TEST_CASE(WriteFile) { PidFile pidfile(Filename); bool rtn_write = pidfile.write(); BOOST_CHECK_EQUAL(true, rtn_write); } BOOST_AUTO_TEST_CASE(AutoRemoval) { bool rtn_write = false; { PidFile pidfile(Filename); rtn_write = pidfile.write(); } bool exists = I2n::file_exists(Filename); BOOST_CHECK_EQUAL(true, rtn_write); BOOST_CHECK_EQUAL(false, exists); } BOOST_AUTO_TEST_CASE(NoAutoRemoval) { bool rtn_write = false; { PidFile pidfile(Filename, false); rtn_write = pidfile.write(); } bool exists = I2n::file_exists(Filename); I2n::unlink(Filename); BOOST_CHECK_EQUAL(true, rtn_write); BOOST_CHECK_EQUAL(true, exists); } BOOST_AUTO_TEST_CASE(NotRunning) { PidFile pidfile(Filename); bool rtn_check = pidfile.check_already_running(); BOOST_CHECK_EQUAL(false, rtn_check); } BOOST_AUTO_TEST_CASE(IsAlreadyRunning) { PidFile pidfile1(Filename); bool rtn_file1_check = pidfile1.check_already_running(); bool rtn_file1_write = pidfile1.write(); BOOST_CHECK_EQUAL(false, rtn_file1_check); BOOST_CHECK_EQUAL(true, rtn_file1_write); PidFile pidfile2(Filename); pid_t my_pid = 0; bool rtn_file2_check = pidfile2.check_already_running(&my_pid); BOOST_CHECK_EQUAL(true, rtn_file2_check); BOOST_CHECK_EQUAL(getpid(), my_pid); } BOOST_AUTO_TEST_SUITE_END()