blob: 47454e3fac5b6cebecf6710fa4ced6a535fc89cf [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 =
Alexander Afanasyev0bb9aae2014-04-21 18:08:18 -070018 time::fromUnixTimestamp(time::milliseconds(1390966967032LL));
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");
Alexander Afanasyev53af7a12014-04-10 23:35:28 -070023 BOOST_CHECK_EQUAL(time::toString(referenceTime), "2014-01-29 03:42:47");
24 BOOST_CHECK_EQUAL(time::toString(referenceTime), "2014-01-29 03:42:47");
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070025
Alexander Afanasyev53af7a12014-04-10 23:35:28 -070026 // Unfortunately, not all systems has lv_LV locale installed :(
27 // BOOST_CHECK_EQUAL(time::toString(referenceTime, "%Y. gada %d. %B",
28 // std::locale("lv_LV.UTF-8")),
29 // "2014. gada 29. Janvāris");
30
31 BOOST_CHECK_EQUAL(time::toString(referenceTime, "%Y -- %d -- %B",
32 std::locale("C")),
33 "2014 -- 29 -- January");
34
35 BOOST_CHECK_EQUAL(time::fromIsoString("20140129T034247.032000"), referenceTime);
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070036 BOOST_CHECK_EQUAL(time::fromIsoString("20140129T034247.032000Z"), referenceTime);
Alexander Afanasyev53af7a12014-04-10 23:35:28 -070037 BOOST_CHECK_EQUAL(time::fromString("2014-01-29 03:42:47"),
38 time::fromUnixTimestamp(time::seconds(1390966967)));
39
40 // Unfortunately, not all systems has lv_LV locale installed :(
41 // BOOST_CHECK_EQUAL(time::fromString("2014. gada 29. Janvāris", "%Y. gada %d. %B",
42 // std::locale("lv_LV.UTF-8")),
43 // time::fromUnixTimestamp(time::seconds(1390953600)));
44
45 BOOST_CHECK_EQUAL(time::fromString("2014 -- 29 -- January", "%Y -- %d -- %B",
46 std::locale("C")),
47 time::fromUnixTimestamp(time::seconds(1390953600)));
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070048}
49
Alexander Afanasyevd1b5c412014-03-27 15:03:51 -070050BOOST_AUTO_TEST_CASE(SteadyClock)
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070051{
52 time::steady_clock::TimePoint oldValue = time::steady_clock::now();
53 usleep(100);
54 time::steady_clock::TimePoint newValue = time::steady_clock::now();
55
56 BOOST_CHECK_GT(newValue, oldValue);
Alexander Afanasyev1e0a0772014-01-28 20:07:07 -080057}
58
59BOOST_AUTO_TEST_SUITE_END()
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -080060
61} // namespace ndn