blob: d09f3ab243de81afe2a7108dfa3dcdc0e884fbdd [file] [log] [blame]
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
/**
* Copyright (c) 2013-2014, Regents of the University of California.
* All rights reserved.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
* See AUTHORS.md for complete list of ndn-cxx authors and contributors.
*
* This file licensed under New BSD License. See COPYING for detailed information about
* ndn-cxx library copyright, permissions, and redistribution restrictions.
*/
#include "util/time.hpp"
#include "boost-test.hpp"
namespace ndn {
BOOST_AUTO_TEST_SUITE(UtilTestTime)
BOOST_AUTO_TEST_CASE(SystemClock)
{
time::system_clock::TimePoint value = time::system_clock::now();
time::system_clock::TimePoint referenceTime =
time::fromUnixTimestamp(time::milliseconds(1390966967032LL));
BOOST_CHECK_GT(value, referenceTime);
BOOST_CHECK_EQUAL(time::toIsoString(referenceTime), "20140129T034247.032000");
BOOST_CHECK_EQUAL(time::toString(referenceTime), "2014-01-29 03:42:47");
BOOST_CHECK_EQUAL(time::toString(referenceTime), "2014-01-29 03:42:47");
// Unfortunately, not all systems has lv_LV locale installed :(
// BOOST_CHECK_EQUAL(time::toString(referenceTime, "%Y. gada %d. %B",
// std::locale("lv_LV.UTF-8")),
// "2014. gada 29. Janvāris");
BOOST_CHECK_EQUAL(time::toString(referenceTime, "%Y -- %d -- %B",
std::locale("C")),
"2014 -- 29 -- January");
BOOST_CHECK_EQUAL(time::fromIsoString("20140129T034247.032000"), referenceTime);
BOOST_CHECK_EQUAL(time::fromIsoString("20140129T034247.032000Z"), referenceTime);
BOOST_CHECK_EQUAL(time::fromString("2014-01-29 03:42:47"),
time::fromUnixTimestamp(time::seconds(1390966967)));
// Unfortunately, not all systems has lv_LV locale installed :(
// BOOST_CHECK_EQUAL(time::fromString("2014. gada 29. Janvāris", "%Y. gada %d. %B",
// std::locale("lv_LV.UTF-8")),
// time::fromUnixTimestamp(time::seconds(1390953600)));
BOOST_CHECK_EQUAL(time::fromString("2014 -- 29 -- January", "%Y -- %d -- %B",
std::locale("C")),
time::fromUnixTimestamp(time::seconds(1390953600)));
}
BOOST_AUTO_TEST_CASE(SteadyClock)
{
time::steady_clock::TimePoint oldValue = time::steady_clock::now();
usleep(100);
time::steady_clock::TimePoint newValue = time::steady_clock::now();
BOOST_CHECK_GT(newValue, oldValue);
}
BOOST_AUTO_TEST_SUITE_END()
} // namespace ndn