Alexander Afanasyev | 1e0a077 | 2014-01-28 20:07:07 -0800 | [diff] [blame] | 1 | /** |
| 2 | * Copyright (C) 2013 Regents of the University of California. |
| 3 | * See COPYING for copyright and distribution information. |
| 4 | */ |
| 5 | |
Alexander Afanasyev | 09c613f | 2014-01-29 00:23:58 -0800 | [diff] [blame] | 6 | #include "util/time.hpp" |
Alexander Afanasyev | 1e0a077 | 2014-01-28 20:07:07 -0800 | [diff] [blame] | 7 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 8 | #include "boost-test.hpp" |
| 9 | |
Alexander Afanasyev | 0abb2da | 2014-01-30 18:07:57 -0800 | [diff] [blame] | 10 | namespace ndn { |
| 11 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 12 | BOOST_AUTO_TEST_SUITE(UtilTestTime) |
Alexander Afanasyev | 1e0a077 | 2014-01-28 20:07:07 -0800 | [diff] [blame] | 13 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 14 | BOOST_AUTO_TEST_CASE(SystemClock) |
Alexander Afanasyev | 1e0a077 | 2014-01-28 20:07:07 -0800 | [diff] [blame] | 15 | { |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 16 | time::system_clock::TimePoint value = time::system_clock::now(); |
| 17 | time::system_clock::TimePoint referenceTime = |
Alexander Afanasyev | 0bb9aae | 2014-04-21 18:08:18 -0700 | [diff] [blame] | 18 | time::fromUnixTimestamp(time::milliseconds(1390966967032LL)); |
Alexander Afanasyev | 1e0a077 | 2014-01-28 20:07:07 -0800 | [diff] [blame] | 19 | |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 20 | BOOST_CHECK_GT(value, referenceTime); |
Alexander Afanasyev | 1e0a077 | 2014-01-28 20:07:07 -0800 | [diff] [blame] | 21 | |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 22 | BOOST_CHECK_EQUAL(time::toIsoString(referenceTime), "20140129T034247.032000"); |
Alexander Afanasyev | 53af7a1 | 2014-04-10 23:35:28 -0700 | [diff] [blame] | 23 | 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 Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 25 | |
Alexander Afanasyev | 53af7a1 | 2014-04-10 23:35:28 -0700 | [diff] [blame] | 26 | // 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 Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 36 | BOOST_CHECK_EQUAL(time::fromIsoString("20140129T034247.032000Z"), referenceTime); |
Alexander Afanasyev | 53af7a1 | 2014-04-10 23:35:28 -0700 | [diff] [blame] | 37 | 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 Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 48 | } |
| 49 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 50 | BOOST_AUTO_TEST_CASE(SteadyClock) |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 51 | { |
| 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 Afanasyev | 1e0a077 | 2014-01-28 20:07:07 -0800 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | BOOST_AUTO_TEST_SUITE_END() |
Alexander Afanasyev | 0abb2da | 2014-01-30 18:07:57 -0800 | [diff] [blame] | 60 | |
| 61 | } // namespace ndn |