X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Scheduler%2FDaemon.test.cc;h=aceed1c34d4b19ca3fbda2c23a4885c4b54d9082;hb=e2ac92bd4334159ffa54e29cad2eeba5846df1f6;hp=418ea9f59a7f3afb001a6bf51de2c41dc85a8943;hpb=17e24d84603667395e9ffa786a9cdbb722bf9c1f;p=senf.git diff --git a/Scheduler/Daemon.test.cc b/Scheduler/Daemon.test.cc index 418ea9f..aceed1c 100644 --- a/Scheduler/Daemon.test.cc +++ b/Scheduler/Daemon.test.cc @@ -31,10 +31,12 @@ #include #include #include +#include +#include #include "Daemon.hh" #include "../Utils/Exception.hh" -#include +#include "../Utils/auto_unit_test.hh" #include #define prefix_ @@ -52,11 +54,20 @@ namespace { class MyDaemon : public senf::Daemon { - void configure() { std::cout << "Running configure()" << std::endl; } - void init() { std::cout << "Running init()" << std::endl; } + void configure() { + std::cout << "Running configure()" << std::endl; + pidFile("invalid.pid"); + consoleLog("invalid.log"); + senf::Daemon::configure(); + } + + void init() { + std::cout << "Running init()" << std::endl; + } + void run() { - delay(2000); std::cout << "Running run()" << std::endl; + delay(1500); } }; @@ -75,15 +86,30 @@ namespace { } int status; if (::waitpid(pid, &status, 0) < 0) senf::throwErrno("::waitpid()"); - return WIFEXITED(status) ? WEXITSTATUS(status) : -1; + return WIFEXITED(status) ? WEXITSTATUS(status) : -1; } } BOOST_AUTO_UNIT_TEST(testDaemon) { - char const * args[] = { "run", 0 }; - BOOST_CHECK_EQUAL( run(1,args), 0 ); + char const * args[] = { "run", + "--console-log=testDaemon.log,none", + "--pid-file=testDaemon.pid" }; + BOOST_CHECK_EQUAL( run(sizeof(args)/sizeof(*args),args), 0 ); + + BOOST_CHECK( ! boost::filesystem::exists("invalid.log") ); + BOOST_CHECK( ! boost::filesystem::exists("invalid.pid") ); + BOOST_CHECK( boost::filesystem::exists("testDaemon.pid") ); + delay(1000); + BOOST_CHECK( ! boost::filesystem::exists("testDaemon.pid") ); + BOOST_REQUIRE( boost::filesystem::exists("testDaemon.log") ); + + std::ifstream log ("testDaemon.log"); + std::stringstream data; + data << log.rdbuf(); + BOOST_CHECK_EQUAL( data.str(), "Running init()\nRunning run()\n" ); + BOOST_CHECK_NO_THROW( boost::filesystem::remove("testDaemon.log") ); } ///////////////////////////////cc.e////////////////////////////////////////