DRDE/AusRegEPPTK/session/TimerTest.cpp

38 lines
815 B
C++
Raw Normal View History

2013-12-31 19:36:07 +00:00
#include "session/Timer.hpp"
#include <string>
#include <ctime>
using namespace std;
#include "common/Test.hpp"
int main(int argc, char* argv[])
{
const std::string bad_time = "123";
2014-01-18 20:35:18 +00:00
const std::string good_time = "20140101.010101";
const std::string good_time_string = "Mon Jan 1 01:01:01 2014\n";
2013-12-31 19:36:07 +00:00
std::string timeString;
time_t time;
try
{
Timer::setTime(bad_time);
ASSERT_EQ(1, 2);
}
catch (ParameterSyntaxException& pse)
{
// pass
}
Timer::setTime(good_time);
time = static_cast<time_t>(Timer::now() / 1000);
timeString = ctime(&time);
ASSERT_EQ(timeString, good_time_string);
// revert to wall clock.
Timer::setTime("");
time = static_cast<time_t>(Timer::now() / 1000);
timeString = ctime(&time);
ASSERT_NEQ(timeString, good_time_string);
}