2012-02-27 03:34:51 +04:00
|
|
|
#include "Timer.h"
|
|
|
|
|
|
|
|
#define BOOST_TEST_MODULE TimerTest
|
|
|
|
#include <boost/test/unit_test.hpp>
|
|
|
|
|
|
|
|
#include <string>
|
2012-02-28 07:34:40 +04:00
|
|
|
#include <unistd.h>
|
2012-02-27 03:34:51 +04:00
|
|
|
|
2012-07-01 00:39:10 +04:00
|
|
|
using namespace MosesTuning;
|
|
|
|
|
2013-05-29 21:16:15 +04:00
|
|
|
BOOST_AUTO_TEST_CASE(timer_basic_test)
|
|
|
|
{
|
2012-02-27 03:34:51 +04:00
|
|
|
Timer timer;
|
2012-02-28 07:34:40 +04:00
|
|
|
const int sleep_time_microsec = 40; // ad-hoc microseconds to pass unit tests.
|
|
|
|
|
2012-02-27 03:34:51 +04:00
|
|
|
timer.start();
|
|
|
|
BOOST_REQUIRE(timer.is_running());
|
2012-02-28 07:34:40 +04:00
|
|
|
BOOST_REQUIRE(usleep(sleep_time_microsec) == 0);
|
|
|
|
BOOST_CHECK(timer.get_elapsed_wall_time() > 0.0);
|
|
|
|
BOOST_CHECK(timer.get_elapsed_wall_time_microseconds() > 0);
|
2012-02-27 03:34:51 +04:00
|
|
|
|
|
|
|
timer.restart();
|
|
|
|
BOOST_REQUIRE(timer.is_running());
|
2012-02-28 07:34:40 +04:00
|
|
|
BOOST_REQUIRE(usleep(sleep_time_microsec) == 0);
|
|
|
|
BOOST_CHECK(timer.get_elapsed_wall_time() > 0.0);
|
|
|
|
BOOST_CHECK(timer.get_elapsed_wall_time_microseconds() > 0);
|
2012-02-27 03:34:51 +04:00
|
|
|
|
|
|
|
const std::string s = timer.ToString();
|
2012-02-28 07:34:40 +04:00
|
|
|
BOOST_CHECK(!s.empty());
|
2012-02-27 03:34:51 +04:00
|
|
|
}
|