00001 #include "Timer.h"
00002
00003 #define BOOST_TEST_MODULE TimerTest
00004 #include <boost/test/unit_test.hpp>
00005
00006 #include <string>
00007 #include <unistd.h>
00008
00009 using namespace MosesTuning;
00010
00011 BOOST_AUTO_TEST_CASE(timer_basic_test)
00012 {
00013 Timer timer;
00014
00015
00016
00017
00018
00019
00020 #if defined(WIN32)
00021
00022
00023 const int sleep_time_microsec = 1000;
00024 #else
00025
00026 const int sleep_time_microsec = 40;
00027 #endif
00028
00029 timer.start();
00030 BOOST_REQUIRE(timer.is_running());
00031 BOOST_REQUIRE(usleep(sleep_time_microsec) == 0);
00032 BOOST_CHECK(timer.get_elapsed_wall_time() > 0.0);
00033 BOOST_CHECK(timer.get_elapsed_wall_time_microseconds() > 0);
00034
00035 timer.restart();
00036 BOOST_REQUIRE(timer.is_running());
00037 BOOST_REQUIRE(usleep(sleep_time_microsec) == 0);
00038 BOOST_CHECK(timer.get_elapsed_wall_time() > 0.0);
00039 BOOST_CHECK(timer.get_elapsed_wall_time_microseconds() > 0);
00040
00041 const std::string s = timer.ToString();
00042 BOOST_CHECK(!s.empty());
00043 }