diff options
Diffstat (limited to 'src/boost/libs/chrono/test/duration')
23 files changed, 1364 insertions, 0 deletions
diff --git a/src/boost/libs/chrono/test/duration/arithmetic_pass.cpp b/src/boost/libs/chrono/test/duration/arithmetic_pass.cpp new file mode 100644 index 00000000..521ca644 --- /dev/null +++ b/src/boost/libs/chrono/test/duration/arithmetic_pass.cpp @@ -0,0 +1,350 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +#include <boost/chrono/duration.hpp> + +#include <boost/detail/lightweight_test.hpp> +#ifdef BOOST_NO_CXX11_CONSTEXPR +#define BOOST_CONSTEXPR_ASSERT(C) BOOST_TEST(C) +#else +#include <boost/static_assert.hpp> +#define BOOST_CONSTEXPR_ASSERT(C) BOOST_STATIC_ASSERT(C) +#endif + +int main() +{ + // Default construct + { + //BOOST_CONSTEXPR + boost::chrono::minutes m; + //BOOST_CONSTEXPR_ASSERT(m.count() == 0); + (void)m; + } + + // UNARY PLUS + { + boost::chrono::minutes m(3); + boost::chrono::minutes m2 = +m; + BOOST_TEST(m.count() == m2.count()); + } + { + BOOST_CONSTEXPR boost::chrono::minutes m(3); + BOOST_CONSTEXPR boost::chrono::minutes m2(+m); + BOOST_CONSTEXPR_ASSERT(m.count() == m2.count()); + } + + // UNARY MINUS + { + boost::chrono::minutes m(3); + boost::chrono::minutes m2 = -m; + BOOST_TEST(m2.count() == -m.count()); + } + { + BOOST_CONSTEXPR boost::chrono::minutes m(3); + BOOST_CONSTEXPR boost::chrono::minutes m2 = -m; + BOOST_CONSTEXPR_ASSERT(m2.count() == -m.count()); + } + // PRE INCREMENT + { + boost::chrono::hours h(3); + boost::chrono::hours& href = ++h; + BOOST_TEST(&href == &h); + BOOST_TEST(h.count() == 4); + } + // POST INCREMENT + { + boost::chrono::hours h(3); + boost::chrono::hours h2 = h++; + BOOST_TEST(h.count() == 4); + BOOST_TEST(h2.count() == 3); + } + // PRE DECREMENT + { + boost::chrono::hours h(3); + boost::chrono::hours& href = --h; + BOOST_TEST(&href == &h); + BOOST_TEST(h.count() == 2); + } + // POST DECREMENT + { + boost::chrono::hours h(3); + boost::chrono::hours h2 = h--; + BOOST_TEST(h.count() == 2); + BOOST_TEST(h2.count() == 3); + } + // PLUS ASSIGN + { + boost::chrono::seconds s(3); + s += boost::chrono::seconds(2); + BOOST_TEST(s.count() == 5); + s += boost::chrono::minutes(2); + BOOST_TEST(s.count() == 125); + } + // MINUS ASSIGN + { + boost::chrono::seconds s(3); + s -= boost::chrono::seconds(2); + BOOST_TEST(s.count() == 1); + s -= boost::chrono::minutes(2); + BOOST_TEST(s.count() == -119); + } + // TIMES ASSIGN + { + boost::chrono::nanoseconds ns(3); + ns *= 5; + BOOST_TEST(ns.count() == 15); + } + // DIVIDE ASSIGN + { + boost::chrono::nanoseconds ns(15); + ns /= 5; + BOOST_TEST(ns.count() == 3); + } + // MODULUS ASSIGN duration + { + boost::chrono::microseconds us(11); + boost::chrono::microseconds us2(3); + us %= us2; + BOOST_TEST(us.count() == 2); + us %= boost::chrono::milliseconds(3); + BOOST_TEST(us.count() == 2); + } + // MODULUS ASSIGN Rep + { + boost::chrono::microseconds us(11); + us %= 3; + BOOST_TEST(us.count() == 2); + } + // PLUS + { + boost::chrono::seconds s1(3); + boost::chrono::seconds s2(5); + boost::chrono::seconds r = s1 + s2; + BOOST_TEST(r.count() == 8); + } + { + BOOST_CONSTEXPR boost::chrono::seconds s1(3); + BOOST_CONSTEXPR boost::chrono::seconds s2(5); + BOOST_CONSTEXPR boost::chrono::seconds r = s1 + s2; + BOOST_CONSTEXPR_ASSERT(r.count() == 8); + } + { + boost::chrono::seconds s1(3); + boost::chrono::microseconds s2(5); + boost::chrono::microseconds r = s1 + s2; + BOOST_TEST(r.count() == 3000005); + } + { + BOOST_CONSTEXPR boost::chrono::seconds s1(3); + BOOST_CONSTEXPR boost::chrono::microseconds s2(5); + BOOST_CONSTEXPR boost::chrono::microseconds r = s1 + s2; + BOOST_CONSTEXPR_ASSERT(r.count() == 3000005); + } + { + boost::chrono::duration<int, boost::ratio<2, 3> > s1(3); + boost::chrono::duration<int, boost::ratio<3, 5> > s2(5); + boost::chrono::duration<int, boost::ratio<1, 15> > r = s1 + s2; + BOOST_TEST(r.count() == 75); + } + { + BOOST_CONSTEXPR boost::chrono::duration<int, boost::ratio<2, 3> > s1(3); + BOOST_CONSTEXPR boost::chrono::duration<int, boost::ratio<3, 5> > s2(5); + BOOST_CONSTEXPR boost::chrono::duration<int, boost::ratio<1, 15> > r = s1 + s2; + BOOST_CONSTEXPR_ASSERT(r.count() == 75); + } + { + boost::chrono::duration<int, boost::ratio<2, 3> > s1(3); + boost::chrono::duration<double, boost::ratio<3, 5> > s2(5); + boost::chrono::duration<double, boost::ratio<1, 15> > r = s1 + s2; + BOOST_TEST(r.count() == 75); + } + { + BOOST_CONSTEXPR boost::chrono::duration<int, boost::ratio<2, 3> > s1(3); + BOOST_CONSTEXPR boost::chrono::duration<double, boost::ratio<3, 5> > s2(5); + BOOST_CONSTEXPR boost::chrono::duration<double, boost::ratio<1, 15> > r = s1 + s2; + BOOST_CONSTEXPR_ASSERT(r.count() == 75); + } + + // MINUS + { + boost::chrono::seconds s1(3); + boost::chrono::seconds s2(5); + boost::chrono::seconds r = s1 - s2; + BOOST_TEST(r.count() == -2); + } + { + BOOST_CONSTEXPR boost::chrono::seconds s1(3); + BOOST_CONSTEXPR boost::chrono::seconds s2(5); + BOOST_CONSTEXPR boost::chrono::seconds r = s1 - s2; + BOOST_CONSTEXPR_ASSERT(r.count() == -2); + } + { + boost::chrono::seconds s1(3); + boost::chrono::microseconds s2(5); + boost::chrono::microseconds r = s1 - s2; + BOOST_TEST(r.count() == 2999995); + } + { + BOOST_CONSTEXPR boost::chrono::seconds s1(3); + BOOST_CONSTEXPR boost::chrono::microseconds s2(5); + BOOST_CONSTEXPR boost::chrono::microseconds r = s1 - s2; + BOOST_CONSTEXPR_ASSERT(r.count() == 2999995); + } + { + boost::chrono::duration<int, boost::ratio<2, 3> > s1(3); + boost::chrono::duration<int, boost::ratio<3, 5> > s2(5); + boost::chrono::duration<int, boost::ratio<1, 15> > r = s1 - s2; + BOOST_TEST(r.count() == -15); + } + { + BOOST_CONSTEXPR boost::chrono::duration<int, boost::ratio<2, 3> > s1(3); + BOOST_CONSTEXPR boost::chrono::duration<int, boost::ratio<3, 5> > s2(5); + BOOST_CONSTEXPR boost::chrono::duration<int, boost::ratio<1, 15> > r = s1 - s2; + BOOST_CONSTEXPR_ASSERT(r.count() == -15); + } + { + boost::chrono::duration<int, boost::ratio<2, 3> > s1(3); + boost::chrono::duration<double, boost::ratio<3, 5> > s2(5); + boost::chrono::duration<double, boost::ratio<1, 15> > r = s1 - s2; + BOOST_TEST(r.count() == -15); + } + { + BOOST_CONSTEXPR boost::chrono::duration<int, boost::ratio<2, 3> > s1(3); + BOOST_CONSTEXPR boost::chrono::duration<double, boost::ratio<3, 5> > s2(5); + BOOST_CONSTEXPR boost::chrono::duration<double, boost::ratio<1, 15> > r = s1 - s2; + BOOST_CONSTEXPR_ASSERT(r.count() == -15); + } + + // TIMES rep + { + boost::chrono::nanoseconds ns(3); + boost::chrono::nanoseconds ns2 = ns * 5; + BOOST_TEST(ns2.count() == 15); + boost::chrono::nanoseconds ns3 = 6 * ns2; + BOOST_TEST(ns3.count() == 90); + } + { + BOOST_CONSTEXPR boost::chrono::nanoseconds ns(3); + BOOST_CONSTEXPR boost::chrono::nanoseconds ns2 = ns * 5; + BOOST_CONSTEXPR_ASSERT(ns2.count() == 15); + BOOST_CONSTEXPR boost::chrono::nanoseconds ns3 = 6 * ns2; + BOOST_CONSTEXPR_ASSERT(ns3.count() == 90); + } + + // DIVIDE duration + { + boost::chrono::nanoseconds ns1(15); + boost::chrono::nanoseconds ns2(5); + BOOST_TEST(ns1 / ns2 == 3); + } + { + BOOST_CONSTEXPR boost::chrono::nanoseconds ns1(15); + BOOST_CONSTEXPR boost::chrono::nanoseconds ns2(5); + BOOST_CONSTEXPR_ASSERT(ns1 / ns2 == 3); + } + { + boost::chrono::microseconds us1(15); + boost::chrono::nanoseconds ns2(5); + BOOST_TEST(us1 / ns2 == 3000); + } + { + BOOST_CONSTEXPR boost::chrono::microseconds us1(15); + BOOST_CONSTEXPR boost::chrono::nanoseconds ns2(5); + BOOST_CONSTEXPR_ASSERT(us1 / ns2 == 3000); + } + { + boost::chrono::duration<int, boost::ratio<2, 3> > s1(30); + boost::chrono::duration<int, boost::ratio<3, 5> > s2(5); + BOOST_TEST(s1 / s2 == 6); + } + { + BOOST_CONSTEXPR boost::chrono::duration<int, boost::ratio<2, 3> > s1(30); + BOOST_CONSTEXPR boost::chrono::duration<int, boost::ratio<3, 5> > s2(5); + BOOST_CONSTEXPR_ASSERT(s1 / s2 == 6); + } + { + boost::chrono::duration<int, boost::ratio<2, 3> > s1(30); + boost::chrono::duration<double, boost::ratio<3, 5> > s2(5); + //BOOST_TEST(s1 / s2 == 20. / 3); + BOOST_TEST(3 * s1 == 20 * s2); + } + { + BOOST_CONSTEXPR boost::chrono::duration<int, boost::ratio<2, 3> > s1(30); + BOOST_CONSTEXPR boost::chrono::duration<double, boost::ratio<3, 5> > s2(5); + //BOOST_CONSTEXPR_ASSERT(s1 / s2 == 20. / 3); + BOOST_TEST(3 * s1 == 20 * s2); + } + // DIVIDE rep + { + boost::chrono::nanoseconds ns(15); + boost::chrono::nanoseconds ns2 = ns / 5; + BOOST_TEST(ns2.count() == 3); + } + { + BOOST_CONSTEXPR boost::chrono::nanoseconds ns(15); + BOOST_CONSTEXPR boost::chrono::nanoseconds ns2 = ns / 5; + BOOST_CONSTEXPR_ASSERT(ns2.count() == 3); + } + + // MODULUS duration + + { + boost::chrono::nanoseconds ns1(15); + boost::chrono::nanoseconds ns2(6); + boost::chrono::nanoseconds r = ns1 % ns2; + BOOST_TEST(r.count() == 3); + } + { + BOOST_CONSTEXPR boost::chrono::nanoseconds ns1(15); + BOOST_CONSTEXPR boost::chrono::nanoseconds ns2(6); + BOOST_CONSTEXPR boost::chrono::nanoseconds r = ns1 % ns2; + BOOST_CONSTEXPR_ASSERT(r.count() == 3); + } + { + boost::chrono::microseconds us1(15); + boost::chrono::nanoseconds ns2(28); + boost::chrono::nanoseconds r = us1 % ns2; + BOOST_TEST(r.count() == 20); + } + { + BOOST_CONSTEXPR boost::chrono::microseconds us1(15); + BOOST_CONSTEXPR boost::chrono::nanoseconds ns2(28); + BOOST_CONSTEXPR boost::chrono::nanoseconds r = us1 % ns2; + BOOST_CONSTEXPR_ASSERT(r.count() == 20); + } + { + boost::chrono::duration<int, boost::ratio<3, 5> > s1(6); + boost::chrono::duration<int, boost::ratio<2, 3> > s2(3); + boost::chrono::duration<int, boost::ratio<1, 15> > r = s1 % s2; + BOOST_TEST(r.count() == 24); + } + { + BOOST_CONSTEXPR boost::chrono::duration<int, boost::ratio<3, 5> > s1(6); + BOOST_CONSTEXPR boost::chrono::duration<int, boost::ratio<2, 3> > s2(3); + BOOST_CONSTEXPR boost::chrono::duration<int, boost::ratio<1, 15> > r = s1 % s2; + BOOST_CONSTEXPR_ASSERT(r.count() == 24); + } + // MODULUS rep + { + boost::chrono::nanoseconds ns(15); + boost::chrono::nanoseconds ns2 = ns % 6; + BOOST_TEST(ns2.count() == 3); + } + { + BOOST_CONSTEXPR boost::chrono::nanoseconds ns(15); + BOOST_CONSTEXPR boost::chrono::nanoseconds ns2 = ns % 6; + BOOST_CONSTEXPR_ASSERT(ns2.count() == 3); + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/chrono/test/duration/comparisons_pass.cpp b/src/boost/libs/chrono/test/duration/comparisons_pass.cpp new file mode 100644 index 00000000..79deaaa1 --- /dev/null +++ b/src/boost/libs/chrono/test/duration/comparisons_pass.cpp @@ -0,0 +1,222 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +#include <boost/chrono/duration.hpp> +#include <boost/detail/lightweight_test.hpp> +#ifdef BOOST_NO_CXX11_CONSTEXPR +#define BOOST_CONSTEXPR_ASSERT(C) BOOST_TEST(C) +#else +#include <boost/static_assert.hpp> +#define BOOST_CONSTEXPR_ASSERT(C) BOOST_STATIC_ASSERT(C) +#endif + +int main() +{ + { + boost::chrono::seconds s1(3); + boost::chrono::seconds s2(3); + BOOST_TEST(s1 == s2); + BOOST_TEST(! (s1 != s2)); + } + { + BOOST_CONSTEXPR boost::chrono::seconds s1(3); + BOOST_CONSTEXPR boost::chrono::seconds s2(3); + BOOST_CONSTEXPR_ASSERT(s1 == s2); + BOOST_CONSTEXPR_ASSERT(!(s1 != s2)); + } + { + boost::chrono::seconds s1(3); + boost::chrono::seconds s2(4); + BOOST_TEST(! (s1 == s2)); + BOOST_TEST(s1 != s2); + } + { + BOOST_CONSTEXPR boost::chrono::seconds s1(3); + BOOST_CONSTEXPR boost::chrono::seconds s2(4); + BOOST_CONSTEXPR_ASSERT(! (s1 == s2)); + BOOST_CONSTEXPR_ASSERT(s1 != s2); + } + { + boost::chrono::milliseconds s1(3); + boost::chrono::microseconds s2(3000); + BOOST_TEST(s1 == s2); + BOOST_TEST(! (s1 != s2)); + } + { + BOOST_CONSTEXPR boost::chrono::milliseconds s1(3); + BOOST_CONSTEXPR boost::chrono::microseconds s2(3000); + BOOST_CONSTEXPR_ASSERT(s1 == s2); + BOOST_CONSTEXPR_ASSERT(! (s1 != s2)); + } + { + boost::chrono::milliseconds s1(3); + boost::chrono::microseconds s2(4000); + BOOST_TEST(! (s1 == s2)); + BOOST_TEST(s1 != s2); + } + { + BOOST_CONSTEXPR boost::chrono::milliseconds s1(3); + BOOST_CONSTEXPR boost::chrono::microseconds s2(4000); + BOOST_CONSTEXPR_ASSERT(! (s1 == s2)); + BOOST_CONSTEXPR_ASSERT(s1 != s2); + } + { + boost::chrono::duration<int, boost::ratio<2, 3> > s1(9); + boost::chrono::duration<int, boost::ratio<3, 5> > s2(10); + BOOST_TEST(s1 == s2); + BOOST_TEST(! (s1 != s2)); + } + { + BOOST_CONSTEXPR boost::chrono::duration<int, boost::ratio<2, 3> > s1(9); + BOOST_CONSTEXPR boost::chrono::duration<int, boost::ratio<3, 5> > s2(10); + BOOST_CONSTEXPR_ASSERT(s1 == s2); + BOOST_CONSTEXPR_ASSERT(! (s1 != s2)); + } + { + boost::chrono::duration<int, boost::ratio<2, 3> > s1(10); + boost::chrono::duration<int, boost::ratio<3, 5> > s2(9); + BOOST_TEST(! (s1 == s2)); + BOOST_TEST(s1 != s2); + } + { + BOOST_CONSTEXPR boost::chrono::duration<int, boost::ratio<2, 3> > s1(10); + BOOST_CONSTEXPR boost::chrono::duration<int, boost::ratio<3, 5> > s2(9); + BOOST_CONSTEXPR_ASSERT(! (s1 == s2)); + BOOST_CONSTEXPR_ASSERT(s1 != s2); + } + { + boost::chrono::duration<int, boost::ratio<2, 3> > s1(9); + boost::chrono::duration<double, boost::ratio<3, 5> > s2(10); + BOOST_TEST(s1 == s2); + BOOST_TEST(! (s1 != s2)); + } + { + BOOST_CONSTEXPR boost::chrono::duration<int, boost::ratio<2, 3> > s1(9); + BOOST_CONSTEXPR boost::chrono::duration<double, boost::ratio<3, 5> > s2(10); + BOOST_CONSTEXPR_ASSERT(s1 == s2); + BOOST_CONSTEXPR_ASSERT(! (s1 != s2)); + } + { + boost::chrono::seconds s1(3); + boost::chrono::seconds s2(3); + BOOST_TEST(! (s1 < s2)); + BOOST_TEST(! (s1 > s2)); + BOOST_TEST( (s1 <= s2)); + BOOST_TEST( (s1 >= s2)); + } + { + BOOST_CONSTEXPR boost::chrono::seconds s1(3); + BOOST_CONSTEXPR boost::chrono::seconds s2(3); + BOOST_CONSTEXPR_ASSERT(! (s1 < s2)); + BOOST_CONSTEXPR_ASSERT(! (s1 > s2)); + BOOST_CONSTEXPR_ASSERT( (s1 <= s2)); + BOOST_CONSTEXPR_ASSERT( (s1 >= s2)); + } + { + boost::chrono::seconds s1(3); + boost::chrono::seconds s2(4); + BOOST_TEST( (s1 < s2)); + BOOST_TEST(! (s1 > s2)); + BOOST_TEST( (s1 <= s2)); + BOOST_TEST(! (s1 >= s2)); + } + { + BOOST_CONSTEXPR boost::chrono::seconds s1(3); + BOOST_CONSTEXPR boost::chrono::seconds s2(4); + BOOST_CONSTEXPR_ASSERT( (s1 < s2)); + BOOST_CONSTEXPR_ASSERT(! (s1 > s2)); + BOOST_CONSTEXPR_ASSERT( (s1 <= s2)); + BOOST_CONSTEXPR_ASSERT(! (s1 >= s2)); + } + { + boost::chrono::milliseconds s1(3); + boost::chrono::microseconds s2(3000); + BOOST_TEST(! (s1 < s2)); + BOOST_TEST(! (s1 > s2)); + BOOST_TEST( (s1 <= s2)); + BOOST_TEST( (s1 >= s2)); + } + { + BOOST_CONSTEXPR boost::chrono::milliseconds s1(3); + BOOST_CONSTEXPR boost::chrono::microseconds s2(3000); + BOOST_CONSTEXPR_ASSERT(! (s1 < s2)); + BOOST_CONSTEXPR_ASSERT(! (s1 > s2)); + BOOST_CONSTEXPR_ASSERT( (s1 <= s2)); + BOOST_CONSTEXPR_ASSERT( (s1 >= s2)); + } + { + boost::chrono::milliseconds s1(3); + boost::chrono::microseconds s2(4000); + BOOST_TEST( (s1 < s2)); + BOOST_TEST(! (s1 > s2)); + BOOST_TEST( (s1 <= s2)); + BOOST_TEST(! (s1 >= s2)); + } + { + BOOST_CONSTEXPR boost::chrono::milliseconds s1(3); + BOOST_CONSTEXPR boost::chrono::microseconds s2(4000); + BOOST_CONSTEXPR_ASSERT( (s1 < s2)); + BOOST_CONSTEXPR_ASSERT(! (s1 > s2)); + BOOST_CONSTEXPR_ASSERT( (s1 <= s2)); + BOOST_CONSTEXPR_ASSERT(! (s1 >= s2)); + } + { + boost::chrono::duration<int, boost::ratio<2, 3> > s1(9); + boost::chrono::duration<int, boost::ratio<3, 5> > s2(10); + BOOST_TEST(! (s1 < s2)); + BOOST_TEST(! (s1 > s2)); + BOOST_TEST( (s1 <= s2)); + BOOST_TEST( (s1 >= s2)); + } + { + BOOST_CONSTEXPR boost::chrono::duration<int, boost::ratio<2, 3> > s1(9); + BOOST_CONSTEXPR boost::chrono::duration<int, boost::ratio<3, 5> > s2(10); + BOOST_CONSTEXPR_ASSERT(! (s1 < s2)); + BOOST_CONSTEXPR_ASSERT(! (s1 > s2)); + BOOST_CONSTEXPR_ASSERT( (s1 <= s2)); + BOOST_CONSTEXPR_ASSERT( (s1 >= s2)); + } + { + boost::chrono::duration<int, boost::ratio<2, 3> > s1(10); + boost::chrono::duration<int, boost::ratio<3, 5> > s2(9); + BOOST_TEST(! (s1 < s2)); + BOOST_TEST( (s1 > s2)); + BOOST_TEST(! (s1 <= s2)); + BOOST_TEST( (s1 >= s2)); + } + { + BOOST_CONSTEXPR boost::chrono::duration<int, boost::ratio<2, 3> > s1(10); + BOOST_CONSTEXPR boost::chrono::duration<int, boost::ratio<3, 5> > s2(9); + BOOST_CONSTEXPR_ASSERT(! (s1 < s2)); + BOOST_CONSTEXPR_ASSERT( (s1 > s2)); + BOOST_CONSTEXPR_ASSERT(! (s1 <= s2)); + BOOST_CONSTEXPR_ASSERT( (s1 >= s2)); + } + { + boost::chrono::duration<int, boost::ratio<2, 3> > s1(9); + boost::chrono::duration<double, boost::ratio<3, 5> > s2(10); + BOOST_TEST(! (s1 < s2)); + BOOST_TEST(! (s1 > s2)); + BOOST_TEST( (s1 <= s2)); + BOOST_TEST( (s1 >= s2)); + } + { + BOOST_CONSTEXPR boost::chrono::duration<int, boost::ratio<2, 3> > s1(9); + BOOST_CONSTEXPR boost::chrono::duration<double, boost::ratio<3, 5> > s2(10); + BOOST_CONSTEXPR_ASSERT(! (s1 < s2)); + BOOST_CONSTEXPR_ASSERT(! (s1 > s2)); + BOOST_CONSTEXPR_ASSERT( (s1 <= s2)); + BOOST_CONSTEXPR_ASSERT( (s1 >= s2)); + } + return boost::report_errors(); +} diff --git a/src/boost/libs/chrono/test/duration/cons/convert_float_to_int_fail.cpp b/src/boost/libs/chrono/test/duration/cons/convert_float_to_int_fail.cpp new file mode 100644 index 00000000..f3024010 --- /dev/null +++ b/src/boost/libs/chrono/test/duration/cons/convert_float_to_int_fail.cpp @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +// conversions from floating point to integral durations disallowed + +#include <boost/chrono/duration.hpp> + +void test() +{ + boost::chrono::duration<double> d; + boost::chrono::duration<int> i = d; +} diff --git a/src/boost/libs/chrono/test/duration/cons/convert_inexact_fail.cpp b/src/boost/libs/chrono/test/duration/cons/convert_inexact_fail.cpp new file mode 100644 index 00000000..a912daa0 --- /dev/null +++ b/src/boost/libs/chrono/test/duration/cons/convert_inexact_fail.cpp @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +// inexact conversions disallowed for integral reps + +#include <boost/chrono/duration.hpp> + +void test() +{ + boost::chrono::microseconds us(1); + boost::chrono::milliseconds ms = us; +} diff --git a/src/boost/libs/chrono/test/duration/cons/implicit_constructot_fail.cpp b/src/boost/libs/chrono/test/duration/cons/implicit_constructot_fail.cpp new file mode 100644 index 00000000..72ea507b --- /dev/null +++ b/src/boost/libs/chrono/test/duration/cons/implicit_constructot_fail.cpp @@ -0,0 +1,23 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +// test for explicit + +#include <boost/chrono/duration.hpp> + +#include "../../rep.h" + +void test() +{ + boost::chrono::duration<int> d = 1; +} diff --git a/src/boost/libs/chrono/test/duration/cons/non_implicit_convertible_rep_fail.cpp b/src/boost/libs/chrono/test/duration/cons/non_implicit_convertible_rep_fail.cpp new file mode 100644 index 00000000..0be0a589 --- /dev/null +++ b/src/boost/libs/chrono/test/duration/cons/non_implicit_convertible_rep_fail.cpp @@ -0,0 +1,23 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +// Rep2 shall be implicitly convertible to rep + +#include <boost/chrono/duration.hpp> + +#include "../../rep.h" + +void test() +{ + boost::chrono::duration<Rep> d(1); +} diff --git a/src/boost/libs/chrono/test/duration/cons/treat_as_floating_point_Rep2_true_fail.cpp b/src/boost/libs/chrono/test/duration/cons/treat_as_floating_point_Rep2_true_fail.cpp new file mode 100644 index 00000000..47c8b2e0 --- /dev/null +++ b/src/boost/libs/chrono/test/duration/cons/treat_as_floating_point_Rep2_true_fail.cpp @@ -0,0 +1,21 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +// treat_as_floating_point<Rep2>::value must be false + +#include <boost/chrono/duration.hpp> + +void test() +{ + boost::chrono::duration<int> d(1.); +} diff --git a/src/boost/libs/chrono/test/duration/constructor_pass.cpp b/src/boost/libs/chrono/test/duration/constructor_pass.cpp new file mode 100644 index 00000000..54b76b70 --- /dev/null +++ b/src/boost/libs/chrono/test/duration/constructor_pass.cpp @@ -0,0 +1,134 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + + +#include <boost/chrono/duration.hpp> +#include <boost/detail/lightweight_test.hpp> + + +#include "../rep.h" +#include <iostream> + +#ifdef BOOST_NO_CXX11_CONSTEXPR +#define BOOST_CONSTEXPR_ASSERT(C) BOOST_TEST(C) +#else +#include <boost/static_assert.hpp> +#define BOOST_CONSTEXPR_ASSERT(C) BOOST_STATIC_ASSERT(C) +#endif + +template <class D> +void +check_default() +{ + { + D d; + BOOST_TEST(d.count() == typename D::rep()); + } +} +template <class D> +void +check_constexpr() +{ + BOOST_CONSTEXPR D d(0); + BOOST_CONSTEXPR_ASSERT(d.count() == typename D::rep()); +} + +template <class D, class R> +void +check_from_rep(R r) +{ + { + D d(r); + BOOST_TEST(d.count() == r); + } +} + +int main() +{ + // exact conversions allowed for integral reps + { + boost::chrono::milliseconds ms(1); + boost::chrono::microseconds us = ms; + BOOST_TEST(us.count() == 1000); + { + BOOST_CONSTEXPR boost::chrono::milliseconds ms(1); + BOOST_CONSTEXPR boost::chrono::microseconds us = ms; + BOOST_CONSTEXPR_ASSERT(us.count() == 1000); + } + } + // inexact conversions allowed for floating point reps + { + boost::chrono::duration<double, boost::micro> us(1); + boost::chrono::duration<double, boost::milli> ms = us; + BOOST_TEST(ms.count() == 1./1000); + { + BOOST_CONSTEXPR boost::chrono::duration<double, boost::micro> us(1); + BOOST_CONSTEXPR boost::chrono::duration<double, boost::milli> ms = us; + BOOST_CONSTEXPR_ASSERT(ms.count() == 1./1000); + } + } + // Convert int to float + { + boost::chrono::duration<int> i(3); + boost::chrono::duration<double> d = i; + BOOST_TEST(d.count() == 3); + { + BOOST_CONSTEXPR boost::chrono::duration<int> i(3); + BOOST_CONSTEXPR boost::chrono::duration<double> d = i; + BOOST_CONSTEXPR_ASSERT(d.count() == 3); + } + } + // default constructor + { + check_default<boost::chrono::duration<Rep> >(); + } + { + check_constexpr<boost::chrono::duration<int> >(); + } + // constructor from rep + { + check_from_rep<boost::chrono::duration<int> >(5); + { + BOOST_CONSTEXPR boost::chrono::duration<int> d(5); + BOOST_CONSTEXPR_ASSERT(d.count() == 5); + } + check_from_rep<boost::chrono::duration<int, boost::ratio<3, 2> > >(5); + { + BOOST_CONSTEXPR boost::chrono::duration<int, boost::ratio<3, 2> > d(5); + BOOST_CONSTEXPR_ASSERT(d.count() == 5); + } + check_from_rep<boost::chrono::duration<Rep, boost::ratio<3, 2> > >(Rep(3)); + { + BOOST_CONSTEXPR boost::chrono::duration<Rep, boost::ratio<3, 2> > d(Rep(3)); + BOOST_CONSTEXPR_ASSERT(d.count() == Rep(3)); + } + check_from_rep<boost::chrono::duration<double, boost::ratio<2, 3> > >(5.5); + { + BOOST_CONSTEXPR boost::chrono::duration<double, boost::ratio<3, 2> > d(5.5); + BOOST_CONSTEXPR_ASSERT(d.count() == 5.5); + } + + + } + // constructor from other rep + { + boost::chrono::duration<double> d(5); + BOOST_TEST(d.count() == 5); + { + BOOST_CONSTEXPR boost::chrono::duration<double> d(5); + BOOST_CONSTEXPR_ASSERT(d.count() == 5); + } + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/chrono/test/duration/default_ratio_pass.cpp b/src/boost/libs/chrono/test/duration/default_ratio_pass.cpp new file mode 100644 index 00000000..1d8ad3a2 --- /dev/null +++ b/src/boost/libs/chrono/test/duration/default_ratio_pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +// duration +// Test default template arg: + +// template <class Rep, class Period = ratio<1>> +// class duration; + +#include <boost/chrono/duration.hpp> +#include <boost/type_traits.hpp> +#if !defined(BOOST_NO_CXX11_STATIC_ASSERT) +#define NOTHING "" +#endif + +BOOST_CHRONO_STATIC_ASSERT((boost::is_same< + boost::chrono::duration<int, boost::ratio<1> >, + boost::chrono::duration<int> +>::value), NOTHING, ()); diff --git a/src/boost/libs/chrono/test/duration/duration_cast_int_fail.cpp b/src/boost/libs/chrono/test/duration/duration_cast_int_fail.cpp new file mode 100644 index 00000000..77b03b74 --- /dev/null +++ b/src/boost/libs/chrono/test/duration/duration_cast_int_fail.cpp @@ -0,0 +1,21 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +// ToDuration must be an instantiation of duration. + +#include <boost/chrono/duration.hpp> + +void test() +{ + boost::chrono::duration_cast<int>(boost::chrono::milliseconds(3)); +} diff --git a/src/boost/libs/chrono/test/duration/duration_cast_pass.cpp b/src/boost/libs/chrono/test/duration/duration_cast_pass.cpp new file mode 100644 index 00000000..0364faa3 --- /dev/null +++ b/src/boost/libs/chrono/test/duration/duration_cast_pass.cpp @@ -0,0 +1,59 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +#include <boost/chrono/duration.hpp> +#include <boost/type_traits.hpp> +#include <boost/detail/lightweight_test.hpp> +#if !defined(BOOST_NO_CXX11_STATIC_ASSERT) +#define NOTHING "" +#endif + +#ifdef BOOST_NO_CXX11_CONSTEXPR +#define BOOST_CONSTEXPR_ASSERT(C) BOOST_TEST(C) +#else +#include <boost/static_assert.hpp> +#define BOOST_CONSTEXPR_ASSERT(C) BOOST_STATIC_ASSERT(C) +#endif + + +template <class ToDuration, class FromDuration> +void +test(const FromDuration& f, const ToDuration& d) +{ +//~ #if defined(BOOST_NO_CXX11_DECLTYPE) + //~ typedef BOOST_TYPEOF_TPL(boost::chrono::duration_cast<ToDuration>(f)) R; +//~ #else + //~ typedef decltype(boost::chrono::duration_cast<ToDuration>(f)) R; +//~ #endif + //~ BOOST_CHRONO_STATIC_ASSERT((boost::is_same<R, ToDuration>::value), NOTHING, (R, ToDuration)); + BOOST_TEST(boost::chrono::duration_cast<ToDuration>(f) == d); +} + +int main() +{ + test(boost::chrono::milliseconds(7265000), boost::chrono::hours(2)); + test(boost::chrono::milliseconds(7265000), boost::chrono::minutes(121)); + test(boost::chrono::milliseconds(7265000), boost::chrono::seconds(7265)); + test(boost::chrono::milliseconds(7265000), boost::chrono::milliseconds(7265000)); + test(boost::chrono::milliseconds(7265000), boost::chrono::microseconds(7265000000LL)); + test(boost::chrono::milliseconds(7265000), boost::chrono::nanoseconds(7265000000000LL)); + test(boost::chrono::milliseconds(7265000), + boost::chrono::duration<double, boost::ratio<3600> >(7265./3600)); + test(boost::chrono::duration<int, boost::ratio<2, 3> >(9), + boost::chrono::duration<int, boost::ratio<3, 5> >(10)); + { + BOOST_CONSTEXPR boost::chrono::hours h = boost::chrono::duration_cast<boost::chrono::hours>(boost::chrono::milliseconds(7265000)); + BOOST_CONSTEXPR_ASSERT(h.count() == 2); + } + return boost::report_errors(); +} diff --git a/src/boost/libs/chrono/test/duration/duration_duration_fail.cpp b/src/boost/libs/chrono/test/duration/duration_duration_fail.cpp new file mode 100644 index 00000000..19e6928e --- /dev/null +++ b/src/boost/libs/chrono/test/duration/duration_duration_fail.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +// duration +// If a program instantiates duration with a duration type for the template +// argument Rep a diagnostic is required. + +#include <boost/chrono/duration.hpp> + +void test() +{ + typedef boost::chrono::duration<boost::chrono::milliseconds> D; + D d; +} diff --git a/src/boost/libs/chrono/test/duration/duration_values_pass.cpp b/src/boost/libs/chrono/test/duration/duration_values_pass.cpp new file mode 100644 index 00000000..9d6b84b1 --- /dev/null +++ b/src/boost/libs/chrono/test/duration/duration_values_pass.cpp @@ -0,0 +1,76 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +#include <boost/chrono/duration.hpp> +#include <boost/detail/lightweight_test.hpp> + +#include "../rep.h" +#if defined BOOST_NO_CXX11_NUMERIC_LIMITS || defined BOOST_NO_CXX11_CONSTEXPR +#define BOOST_CONSTEXPR_ASSERT(C) BOOST_TEST(C) +#else +#include <boost/static_assert.hpp> +#define BOOST_CONSTEXPR_ASSERT(C) BOOST_STATIC_ASSERT(C) +#endif + +template <class D> +void check_max() +{ + typedef typename D::rep Rep; + Rep max_rep = (boost::chrono::duration_values<Rep>::max)(); + BOOST_TEST((D::max)().count() == max_rep); + { + typedef typename D::rep Rep; + BOOST_CHRONO_LIB_CONSTEXPR Rep max_rep = (boost::chrono::duration_values<Rep>::max)(); + BOOST_CONSTEXPR_ASSERT((D::max)().count() == max_rep); + } +} + +template <class D> +void check_min() +{ + typedef typename D::rep Rep; + Rep min_rep = (boost::chrono::duration_values<Rep>::min)(); + BOOST_TEST((D::min)().count() == min_rep); + { + typedef typename D::rep Rep; + BOOST_CHRONO_LIB_CONSTEXPR Rep min_rep = (boost::chrono::duration_values<Rep>::min)(); + BOOST_CONSTEXPR_ASSERT((D::min)().count() == min_rep); + + } +} + +template <class D> +void check_zero() +{ + typedef typename D::rep Rep; + Rep zero_rep = boost::chrono::duration_values<Rep>::zero(); + BOOST_TEST(D::zero().count() == zero_rep); + { + typedef typename D::rep Rep; + BOOST_CONSTEXPR Rep zero_rep = boost::chrono::duration_values<Rep>::zero(); + BOOST_CONSTEXPR_ASSERT(D::zero().count() == zero_rep); + + } +} + + +int main() +{ + check_max<boost::chrono::duration<int> >(); + check_max<boost::chrono::duration<Rep> >(); + check_min<boost::chrono::duration<int> >(); + check_min<boost::chrono::duration<Rep> >(); + check_zero<boost::chrono::duration<int> >(); + check_zero<boost::chrono::duration<Rep> >(); + return boost::report_errors(); +} diff --git a/src/boost/libs/chrono/test/duration/nonmember/divide_rep2_fail.cpp b/src/boost/libs/chrono/test/duration/nonmember/divide_rep2_fail.cpp new file mode 100644 index 00000000..649f17ea --- /dev/null +++ b/src/boost/libs/chrono/test/duration/nonmember/divide_rep2_fail.cpp @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +#include <boost/chrono/duration.hpp> + +#include "../../rep.h" + +void test() +{ + boost::chrono::duration<Rep> d(Rep(15)); + d = d / 5; +} diff --git a/src/boost/libs/chrono/test/duration/nonmember/modulus_rep2_fail.cpp b/src/boost/libs/chrono/test/duration/nonmember/modulus_rep2_fail.cpp new file mode 100644 index 00000000..b5b8c7e4 --- /dev/null +++ b/src/boost/libs/chrono/test/duration/nonmember/modulus_rep2_fail.cpp @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +#include <boost/chrono/duration.hpp> + +#include "../../rep.h" + +void test() +{ + boost::chrono::duration<Rep> d(Rep(15)); + d = d % 5; +} diff --git a/src/boost/libs/chrono/test/duration/nonmember/times_rep2_lhs_fail.cpp b/src/boost/libs/chrono/test/duration/nonmember/times_rep2_lhs_fail.cpp new file mode 100644 index 00000000..84c6a405 --- /dev/null +++ b/src/boost/libs/chrono/test/duration/nonmember/times_rep2_lhs_fail.cpp @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +#include <boost/chrono/duration.hpp> + +#include "../../rep.h" + +void test() +{ + boost::chrono::duration<Rep> d; + d = 5 * d; +} diff --git a/src/boost/libs/chrono/test/duration/nonmember/times_rep2_rhs_fail.cpp b/src/boost/libs/chrono/test/duration/nonmember/times_rep2_rhs_fail.cpp new file mode 100644 index 00000000..0172b999 --- /dev/null +++ b/src/boost/libs/chrono/test/duration/nonmember/times_rep2_rhs_fail.cpp @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +#include <boost/chrono/duration.hpp> + +#include "../../rep.h" + +void test() +{ + boost::chrono::duration<Rep> d; + d = d * 5; +} diff --git a/src/boost/libs/chrono/test/duration/positive_num_fail.cpp b/src/boost/libs/chrono/test/duration/positive_num_fail.cpp new file mode 100644 index 00000000..fbd25f67 --- /dev/null +++ b/src/boost/libs/chrono/test/duration/positive_num_fail.cpp @@ -0,0 +1,23 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +// duration +// Period::num must be positive, diagnostic required. + +#include <boost/chrono/duration.hpp> + +void test() +{ + typedef boost::chrono::duration<int, boost::ratio<5, -1> > D; + D d; +} diff --git a/src/boost/libs/chrono/test/duration/ratio_alias_pass.cpp b/src/boost/libs/chrono/test/duration/ratio_alias_pass.cpp new file mode 100644 index 00000000..a949032a --- /dev/null +++ b/src/boost/libs/chrono/test/duration/ratio_alias_pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +// duration +// Period shall be a specialization of ratio, diagnostic required. + +#include <boost/chrono/duration.hpp> + +void test() +{ + typedef boost::chrono::duration<int, + boost::ratio_add< + boost::ratio<1,2>, + boost::ratio<1,3> + > + > D; + D d; + (void)d; +} diff --git a/src/boost/libs/chrono/test/duration/ratio_fail.cpp b/src/boost/libs/chrono/test/duration/ratio_fail.cpp new file mode 100644 index 00000000..5ea4b60b --- /dev/null +++ b/src/boost/libs/chrono/test/duration/ratio_fail.cpp @@ -0,0 +1,23 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +// duration +// Period shall be a specialization of ratio, diagnostic required. + +#include <boost/chrono/duration.hpp> + +void test() +{ + typedef boost::chrono::duration<int, int > D; + D d; +} diff --git a/src/boost/libs/chrono/test/duration/rounding_pass.cpp b/src/boost/libs/chrono/test/duration/rounding_pass.cpp new file mode 100644 index 00000000..06a32a1b --- /dev/null +++ b/src/boost/libs/chrono/test/duration/rounding_pass.cpp @@ -0,0 +1,105 @@ +// Copyright 2013 Krzysztof Czainski +// Copyright 2013 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +/* + * @file chrono_rounding.cpp + * + * @since 2013-11-22 + * @author Krzysztof Czainski <1czajnik@gmail.com> + */ + +#include <boost/cstdint.hpp> +#include <boost/chrono/ceil.hpp> +#include <boost/chrono/floor.hpp> +#include <boost/chrono/round.hpp> + +#include <boost/chrono/chrono_io.hpp> +#include <boost/detail/lightweight_test.hpp> + +using namespace boost::chrono; + +void test_floor() +{ + BOOST_TEST_EQ( seconds(-2), floor<seconds>( milliseconds(-2000) ) ); + BOOST_TEST_EQ( seconds(-2), floor<seconds>( milliseconds(-1999) ) ); + BOOST_TEST_EQ( seconds(-2), floor<seconds>( milliseconds(-1001) ) ); + BOOST_TEST_EQ( seconds(-1), floor<seconds>( milliseconds(-1000) ) ); + BOOST_TEST_EQ( seconds(-1), floor<seconds>( milliseconds(-999) ) ); + BOOST_TEST_EQ( seconds(-1), floor<seconds>( milliseconds(-1) ) ); + BOOST_TEST_EQ( seconds(0), floor<seconds>( milliseconds(0) ) ); + BOOST_TEST_EQ( seconds(0), floor<seconds>( milliseconds(1) ) ); + BOOST_TEST_EQ( seconds(0), floor<seconds>( milliseconds(999) ) ); + BOOST_TEST_EQ( seconds(1), floor<seconds>( milliseconds(1000) ) ); + BOOST_TEST_EQ( seconds(1), floor<seconds>( milliseconds(1001) ) ); + BOOST_TEST_EQ( seconds(1), floor<seconds>( milliseconds(1999) ) ); + BOOST_TEST_EQ( seconds(2), floor<seconds>( milliseconds(2000) ) ); + + { + // check that int32 isn't overflowed in intermediate calculations: + typedef duration<boost::int32_t> sec32; + typedef duration< boost::int32_t, boost::ratio<999,1000> > sec32_m1ms; + BOOST_TEST_EQ( sec32(-999000000), floor<sec32>( sec32_m1ms(-1000000000) ) ); + BOOST_TEST_EQ( sec32( 999000000), floor<sec32>( sec32_m1ms( 1000000000) ) ); + } +} + +void test_ceil() +{ + BOOST_TEST_EQ( seconds(-2), ceil<seconds>( milliseconds(-2000) ) ); + BOOST_TEST_EQ( seconds(-1), ceil<seconds>( milliseconds(-1999) ) ); + BOOST_TEST_EQ( seconds(-1), ceil<seconds>( milliseconds(-1001) ) ); + BOOST_TEST_EQ( seconds(-1), ceil<seconds>( milliseconds(-1000) ) ); + BOOST_TEST_EQ( seconds(0), ceil<seconds>( milliseconds(-999) ) ); + BOOST_TEST_EQ( seconds(0), ceil<seconds>( milliseconds(-1) ) ); + BOOST_TEST_EQ( seconds(0), ceil<seconds>( milliseconds(0) ) ); + BOOST_TEST_EQ( seconds(1), ceil<seconds>( milliseconds(1) ) ); + BOOST_TEST_EQ( seconds(1), ceil<seconds>( milliseconds(999) ) ); + BOOST_TEST_EQ( seconds(1), ceil<seconds>( milliseconds(1000) ) ); + BOOST_TEST_EQ( seconds(2), ceil<seconds>( milliseconds(1001) ) ); + BOOST_TEST_EQ( seconds(2), ceil<seconds>( milliseconds(1999) ) ); + BOOST_TEST_EQ( seconds(2), ceil<seconds>( milliseconds(2000) ) ); + { + // check that int32 isn't overflowed in intermediate calculations: + typedef duration<boost::int32_t> sec32; + typedef duration< boost::int32_t, boost::ratio<999,1000> > sec32_m1ms; + BOOST_TEST_EQ( sec32(-999000000), ceil<sec32>( sec32_m1ms(-1000000000) ) ); + BOOST_TEST_EQ( sec32( 999000000), ceil<sec32>( sec32_m1ms( 1000000000) ) ); + } +} + +void test_round() +{ + // to even on tie + BOOST_TEST_EQ( seconds(-2), round<seconds>( milliseconds(-2000) ) ); + BOOST_TEST_EQ( seconds(-2), round<seconds>( milliseconds(-1500) ) ); + BOOST_TEST_EQ( seconds(-1), round<seconds>( milliseconds(-1499) ) ); + BOOST_TEST_EQ( seconds(-1), round<seconds>( milliseconds(-1000) ) ); + BOOST_TEST_EQ( seconds(0), round<seconds>( milliseconds(-500) ) ); + BOOST_TEST_EQ( seconds(0), round<seconds>( milliseconds(-499) ) ); + BOOST_TEST_EQ( seconds(0), round<seconds>( milliseconds(0) ) ); + BOOST_TEST_EQ( seconds(0), round<seconds>( milliseconds(499) ) ); + BOOST_TEST_EQ( seconds(0), round<seconds>( milliseconds(500) ) ); + BOOST_TEST_EQ( seconds(1), round<seconds>( milliseconds(1000) ) ); + BOOST_TEST_EQ( seconds(1), round<seconds>( milliseconds(1499) ) ); + BOOST_TEST_EQ( seconds(2), round<seconds>( milliseconds(1500) ) ); + BOOST_TEST_EQ( seconds(2), round<seconds>( milliseconds(2000) ) ); + { + // check that int32 isn't overflowed in intermediate calculations: + typedef duration<boost::int32_t> sec32; + typedef duration< boost::int32_t, boost::ratio<999,1000> > sec32_m1ms; + BOOST_TEST_EQ( sec32(-999000000), round<sec32>( sec32_m1ms(-1000000000) ) ); + BOOST_TEST_EQ( sec32( 999000000), round<sec32>( sec32_m1ms( 1000000000) ) ); + } +} + +int main() +{ + test_floor(); + test_ceil(); + test_round(); + return boost::report_errors(); + +} diff --git a/src/boost/libs/chrono/test/duration/typedefs_pass.cpp b/src/boost/libs/chrono/test/duration/typedefs_pass.cpp new file mode 100644 index 00000000..2f9d2ef3 --- /dev/null +++ b/src/boost/libs/chrono/test/duration/typedefs_pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + + +#include <boost/chrono/duration.hpp> +#include <boost/type_traits.hpp> +#include <limits> + +#if !defined(BOOST_NO_CXX11_STATIC_ASSERT) +#define NOTHING "" +#endif + +template <typename D, int ExpectedDigits, typename ExpectedPeriod> +void check_duration() +{ + typedef typename D::rep Rep; + typedef typename D::period Period; + BOOST_CHRONO_STATIC_ASSERT(boost::is_signed<Rep>::value, NOTHING, ()); + BOOST_CHRONO_STATIC_ASSERT(boost::is_integral<Rep>::value, NOTHING, ()); + BOOST_CHRONO_STATIC_ASSERT(std::numeric_limits<Rep>::digits >= ExpectedDigits, NOTHING, ()); + BOOST_CHRONO_STATIC_ASSERT((boost::is_same<Period, ExpectedPeriod >::value), NOTHING, ()); +} + +void test() +{ + check_duration<boost::chrono::hours, 22, boost::ratio<3600> >(); + check_duration<boost::chrono::minutes, 28, boost::ratio<60> >(); + check_duration<boost::chrono::seconds, 34, boost::ratio<1> >(); + check_duration<boost::chrono::milliseconds, 44, boost::milli >(); + check_duration<boost::chrono::microseconds, 54, boost::micro >(); + check_duration<boost::chrono::nanoseconds, 63, boost::nano >(); +} diff --git a/src/boost/libs/chrono/test/duration/types_pass.cpp b/src/boost/libs/chrono/test/duration/types_pass.cpp new file mode 100644 index 00000000..568ce0e2 --- /dev/null +++ b/src/boost/libs/chrono/test/duration/types_pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +// duration +// Test nested types + +// typedef Rep rep; +// typedef Period period; + +#include <boost/chrono/duration.hpp> +#include <boost/type_traits.hpp> +#if !defined(BOOST_NO_CXX11_STATIC_ASSERT) +#define NOTHING "" +#endif + +typedef boost::chrono::duration<long, boost::ratio<3, 2> > D; +BOOST_CHRONO_STATIC_ASSERT((boost::is_same<D::rep, long>::value), NOTHING, ()); +BOOST_CHRONO_STATIC_ASSERT((boost::is_same<D::period, boost::ratio<3, 2> >::value), NOTHING, ()); |