Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Alexander Afanasyev | 1e0a077 | 2014-01-28 20:07:07 -0800 | [diff] [blame] | 2 | /** |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame^] | 3 | * Copyright (c) 2013-2015 Regents of the University of California. |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 6 | * |
Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 7 | * ndn-cxx library is free software: you can redistribute it and/or modify it under the |
| 8 | * terms of the GNU Lesser General Public License as published by the Free Software |
| 9 | * Foundation, either version 3 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 13 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received copies of the GNU General Public License and GNU Lesser |
| 16 | * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
| 17 | * <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
Alexander Afanasyev | 1e0a077 | 2014-01-28 20:07:07 -0800 | [diff] [blame] | 20 | */ |
| 21 | |
Alexander Afanasyev | 09c613f | 2014-01-29 00:23:58 -0800 | [diff] [blame] | 22 | #include "util/time.hpp" |
Alexander Afanasyev | 1e0a077 | 2014-01-28 20:07:07 -0800 | [diff] [blame] | 23 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 24 | #include "boost-test.hpp" |
| 25 | |
Alexander Afanasyev | 0abb2da | 2014-01-30 18:07:57 -0800 | [diff] [blame] | 26 | namespace ndn { |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame^] | 27 | namespace tests { |
Alexander Afanasyev | 0abb2da | 2014-01-30 18:07:57 -0800 | [diff] [blame] | 28 | |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame^] | 29 | BOOST_AUTO_TEST_SUITE(UtilTime) |
Alexander Afanasyev | 1e0a077 | 2014-01-28 20:07:07 -0800 | [diff] [blame] | 30 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 31 | BOOST_AUTO_TEST_CASE(SystemClock) |
Alexander Afanasyev | 1e0a077 | 2014-01-28 20:07:07 -0800 | [diff] [blame] | 32 | { |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 33 | time::system_clock::TimePoint value = time::system_clock::now(); |
| 34 | time::system_clock::TimePoint referenceTime = |
Alexander Afanasyev | 0bb9aae | 2014-04-21 18:08:18 -0700 | [diff] [blame] | 35 | time::fromUnixTimestamp(time::milliseconds(1390966967032LL)); |
Alexander Afanasyev | 1e0a077 | 2014-01-28 20:07:07 -0800 | [diff] [blame] | 36 | |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 37 | BOOST_CHECK_GT(value, referenceTime); |
Alexander Afanasyev | 1e0a077 | 2014-01-28 20:07:07 -0800 | [diff] [blame] | 38 | |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 39 | BOOST_CHECK_EQUAL(time::toIsoString(referenceTime), "20140129T034247.032000"); |
Alexander Afanasyev | 53af7a1 | 2014-04-10 23:35:28 -0700 | [diff] [blame] | 40 | BOOST_CHECK_EQUAL(time::toString(referenceTime), "2014-01-29 03:42:47"); |
| 41 | BOOST_CHECK_EQUAL(time::toString(referenceTime), "2014-01-29 03:42:47"); |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 42 | |
Alexander Afanasyev | 53af7a1 | 2014-04-10 23:35:28 -0700 | [diff] [blame] | 43 | // Unfortunately, not all systems has lv_LV locale installed :( |
| 44 | // BOOST_CHECK_EQUAL(time::toString(referenceTime, "%Y. gada %d. %B", |
| 45 | // std::locale("lv_LV.UTF-8")), |
| 46 | // "2014. gada 29. Janvāris"); |
| 47 | |
| 48 | BOOST_CHECK_EQUAL(time::toString(referenceTime, "%Y -- %d -- %B", |
| 49 | std::locale("C")), |
| 50 | "2014 -- 29 -- January"); |
| 51 | |
| 52 | BOOST_CHECK_EQUAL(time::fromIsoString("20140129T034247.032000"), referenceTime); |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 53 | BOOST_CHECK_EQUAL(time::fromIsoString("20140129T034247.032000Z"), referenceTime); |
Alexander Afanasyev | 53af7a1 | 2014-04-10 23:35:28 -0700 | [diff] [blame] | 54 | BOOST_CHECK_EQUAL(time::fromString("2014-01-29 03:42:47"), |
| 55 | time::fromUnixTimestamp(time::seconds(1390966967))); |
| 56 | |
| 57 | // Unfortunately, not all systems has lv_LV locale installed :( |
| 58 | // BOOST_CHECK_EQUAL(time::fromString("2014. gada 29. Janvāris", "%Y. gada %d. %B", |
| 59 | // std::locale("lv_LV.UTF-8")), |
| 60 | // time::fromUnixTimestamp(time::seconds(1390953600))); |
| 61 | |
| 62 | BOOST_CHECK_EQUAL(time::fromString("2014 -- 29 -- January", "%Y -- %d -- %B", |
| 63 | std::locale("C")), |
| 64 | time::fromUnixTimestamp(time::seconds(1390953600))); |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 65 | } |
| 66 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 67 | BOOST_AUTO_TEST_CASE(SteadyClock) |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 68 | { |
| 69 | time::steady_clock::TimePoint oldValue = time::steady_clock::now(); |
| 70 | usleep(100); |
| 71 | time::steady_clock::TimePoint newValue = time::steady_clock::now(); |
| 72 | |
| 73 | BOOST_CHECK_GT(newValue, oldValue); |
Alexander Afanasyev | 1e0a077 | 2014-01-28 20:07:07 -0800 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | BOOST_AUTO_TEST_SUITE_END() |
Alexander Afanasyev | 0abb2da | 2014-01-30 18:07:57 -0800 | [diff] [blame] | 77 | |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame^] | 78 | } // namespace tests |
Alexander Afanasyev | 0abb2da | 2014-01-30 18:07:57 -0800 | [diff] [blame] | 79 | } // namespace ndn |