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
diff --git a/src/util/time.hpp b/src/util/time.hpp
index f8bcabc..e239ccd 100644
--- a/src/util/time.hpp
+++ b/src/util/time.hpp
@@ -48,7 +48,7 @@
* 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)
{
diff --git a/tests/unit-tests/util/time.t.cpp b/tests/unit-tests/util/time.t.cpp
index c4ac260..74d893c 100644
--- a/tests/unit-tests/util/time.t.cpp
+++ b/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_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