#include <sys/types.h>
#include <sys/wait.h>
#include <iostream>
+#include <fstream>
#include <boost/filesystem/operations.hpp>
#include "Daemon.hh"
#include "../Utils/Exception.hh"
{
void configure() {
std::cout << "Running configure()" << std::endl;
- pidFile("testDaemon.pid");
+ pidFile("invalid.pid");
+ consoleLog("invalid.log");
+ senf::Daemon::configure();
}
void init() {
}
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////////////////////////////////////////