Browse Source

util: fix clang 3.4 time::abs compilation error

This commit also adds a test case for time::abs function template.

refs #3698

Change-Id: I32c3d15362d5515841a95ce6d9804be11df632b5
pull/6/head
Junxiao Shi 9 years ago
parent
commit
5537d13e56
  1. 2
      src/util/time.hpp
  2. 15
      tests/unit-tests/util/time.t.cpp

2
src/util/time.hpp

@ -48,7 +48,7 @@ using boost::chrono::duration_cast;
* unless std::numeric_limits<Rep>::is_signed is true.
*/
template<typename Rep, typename Period,
typename = typename std::enable_if<duration<Rep, Period>::min() < duration<Rep, Period>::zero()>::type>
typename = typename std::enable_if<std::numeric_limits<Rep>::is_signed>::type>
constexpr duration<Rep, Period>
abs(duration<Rep, Period> d)
{

15
tests/unit-tests/util/time.t.cpp

@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2013-2015 Regents of the University of California.
* Copyright (c) 2013-2016 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@ -26,7 +26,8 @@
namespace ndn {
namespace tests {
BOOST_AUTO_TEST_SUITE(UtilTime)
BOOST_AUTO_TEST_SUITE(Util)
BOOST_AUTO_TEST_SUITE(TestTime)
BOOST_AUTO_TEST_CASE(SystemClock)
{
@ -73,7 +74,15 @@ BOOST_AUTO_TEST_CASE(SteadyClock)
BOOST_CHECK_GT(newValue, oldValue);
}
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(Abs)
{
BOOST_CHECK_EQUAL(time::abs(time::nanoseconds(24422)), time::nanoseconds(24422));
BOOST_CHECK_EQUAL(time::abs(time::microseconds(0)), time::microseconds(0));
BOOST_CHECK_EQUAL(time::abs(time::milliseconds(-15583)), time::milliseconds(15583));
}
BOOST_AUTO_TEST_SUITE_END() // TestTime
BOOST_AUTO_TEST_SUITE_END() // Util
} // namespace tests
} // namespace ndn

Loading…
Cancel
Save