blob: 2db2131461ca83b6bd18863f2ca5605e36fb628f [file] [log] [blame]
Alexander Afanasyev1e0a0772014-01-28 20:07:07 -08001/**
2 * Copyright (C) 2013 Regents of the University of California.
3 * See COPYING for copyright and distribution information.
4 */
5
Alexander Afanasyev09c613f2014-01-29 00:23:58 -08006#include "util/time.hpp"
Alexander Afanasyev1e0a0772014-01-28 20:07:07 -08007
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -07008#include "boost-test.hpp"
9
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -080010namespace ndn {
11
Alexander Afanasyevd1b5c412014-03-27 15:03:51 -070012BOOST_AUTO_TEST_SUITE(UtilTestTime)
Alexander Afanasyev1e0a0772014-01-28 20:07:07 -080013
Alexander Afanasyevd1b5c412014-03-27 15:03:51 -070014BOOST_AUTO_TEST_CASE(SystemClock)
Alexander Afanasyev1e0a0772014-01-28 20:07:07 -080015{
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070016 time::system_clock::TimePoint value = time::system_clock::now();
17 time::system_clock::TimePoint referenceTime =
18 time::fromUnixTimestamp(time::milliseconds(1390966967032));
Alexander Afanasyev1e0a0772014-01-28 20:07:07 -080019
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070020 BOOST_CHECK_GT(value, referenceTime);
Alexander Afanasyev1e0a0772014-01-28 20:07:07 -080021
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070022 BOOST_CHECK_EQUAL(time::toIsoString(referenceTime), "20140129T034247.032000");
23 BOOST_CHECK_EQUAL(time::fromIsoString("20140129T034247.032000"), referenceTime);
24
25 BOOST_CHECK_EQUAL(time::fromIsoString("20140129T034247.032000Z"), referenceTime);
26}
27
Alexander Afanasyevd1b5c412014-03-27 15:03:51 -070028BOOST_AUTO_TEST_CASE(SteadyClock)
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070029{
30 time::steady_clock::TimePoint oldValue = time::steady_clock::now();
31 usleep(100);
32 time::steady_clock::TimePoint newValue = time::steady_clock::now();
33
34 BOOST_CHECK_GT(newValue, oldValue);
Alexander Afanasyev1e0a0772014-01-28 20:07:07 -080035}
36
37BOOST_AUTO_TEST_SUITE_END()
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -080038
39} // namespace ndn