Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r66330 - in sandbox/chrono/libs/chrono/test/time_point: . cons
From: vicente.botet_at_[hidden]
Date: 2010-11-01 17:11:13


Author: viboes
Date: 2010-11-01 17:11:08 EDT (Mon, 01 Nov 2010)
New Revision: 66330
URL: http://svn.boost.org/trac/boost/changeset/66330

Log:
Chrono: Refactor tests

Added:
   sandbox/chrono/libs/chrono/test/time_point/arithmetic_pass.cpp (contents, props changed)
   sandbox/chrono/libs/chrono/test/time_point/comparisons_pass.cpp (contents, props changed)
   sandbox/chrono/libs/chrono/test/time_point/cons/implicit_fail.cpp (contents, props changed)
   sandbox/chrono/libs/chrono/test/time_point/cons/non_implicit_convertible_duration_fail.cpp (contents, props changed)
   sandbox/chrono/libs/chrono/test/time_point/constructor_pass.cpp (contents, props changed)
   sandbox/chrono/libs/chrono/test/time_point/default_duration_pass.cpp (contents, props changed)
   sandbox/chrono/libs/chrono/test/time_point/min_max_pass.cpp (contents, props changed)
   sandbox/chrono/libs/chrono/test/time_point/not_duration_fail.cpp (contents, props changed)
   sandbox/chrono/libs/chrono/test/time_point/time_point_cast_int_fail.cpp (contents, props changed)
   sandbox/chrono/libs/chrono/test/time_point/time_point_cast_pass.cpp (contents, props changed)

Added: sandbox/chrono/libs/chrono/test/time_point/arithmetic_pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/libs/chrono/test/time_point/arithmetic_pass.cpp 2010-11-01 17:11:08 EDT (Mon, 01 Nov 2010)
@@ -0,0 +1,52 @@
+// 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.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+int main()
+{
+ {
+ typedef boost::chrono::system_clock Clock;
+ typedef boost::chrono::milliseconds Duration;
+ boost::chrono::time_point<Clock, Duration> t(Duration(3));
+ t += Duration(2);
+ BOOST_TEST(t.time_since_epoch() == Duration(5));
+ }
+ {
+ typedef boost::chrono::system_clock Clock;
+ typedef boost::chrono::milliseconds Duration;
+ boost::chrono::time_point<Clock, Duration> t(Duration(3));
+ t -= Duration(2);
+ BOOST_TEST(t.time_since_epoch() == Duration(1));
+ }
+ {
+ typedef boost::chrono::system_clock Clock;
+ typedef boost::chrono::milliseconds Duration1;
+ typedef boost::chrono::microseconds Duration2;
+ boost::chrono::time_point<Clock, Duration1> t1(Duration1(3));
+ boost::chrono::time_point<Clock, Duration2> t2 = t1 - Duration2(5);
+ BOOST_TEST(t2.time_since_epoch() == Duration2(2995));
+ }
+ {
+ typedef boost::chrono::system_clock Clock;
+ typedef boost::chrono::milliseconds Duration1;
+ typedef boost::chrono::microseconds Duration2;
+ boost::chrono::time_point<Clock, Duration1> t1(Duration1(3));
+ boost::chrono::time_point<Clock, Duration2> t2(Duration2(5));
+ BOOST_TEST((t1 - t2) == Duration2(2995));
+ }
+ {
+ typedef boost::chrono::system_clock Clock;
+ typedef boost::chrono::milliseconds Duration1;
+ typedef boost::chrono::microseconds Duration2;
+ boost::chrono::time_point<Clock, Duration1> t1(Duration1(3));
+ boost::chrono::time_point<Clock, Duration2> t2 = t1 + Duration2(5);
+ BOOST_TEST(t2.time_since_epoch() == Duration2(3005));
+ t2 = Duration2(6) + t1;
+ BOOST_TEST(t2.time_since_epoch() == Duration2(3006));
+ }
+
+ return boost::report_errors();
+}

Added: sandbox/chrono/libs/chrono/test/time_point/comparisons_pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/libs/chrono/test/time_point/comparisons_pass.cpp 2010-11-01 17:11:08 EDT (Mon, 01 Nov 2010)
@@ -0,0 +1,74 @@
+// 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.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+int main()
+{
+ typedef boost::chrono::system_clock Clock;
+ typedef boost::chrono::milliseconds Duration1;
+ typedef boost::chrono::microseconds Duration2;
+ typedef boost::chrono::time_point<Clock, Duration1> T1;
+ typedef boost::chrono::time_point<Clock, Duration2> T2;
+
+ {
+ T1 t1(Duration1(3));
+ T1 t2(Duration1(3));
+ BOOST_TEST( (t1 == t2));
+ BOOST_TEST(!(t1 != t2));
+ }
+ {
+ T1 t1(Duration1(3));
+ T1 t2(Duration1(4));
+ BOOST_TEST(!(t1 == t2));
+ BOOST_TEST( (t1 != t2));
+ }
+ {
+ T1 t1(Duration1(3));
+ T2 t2(Duration2(3000));
+ BOOST_TEST( (t1 == t2));
+ BOOST_TEST(!(t1 != t2));
+ }
+ {
+ T1 t1(Duration1(3));
+ T2 t2(Duration2(3001));
+ BOOST_TEST(!(t1 == t2));
+ BOOST_TEST( (t1 != t2));
+ }
+ {
+ T1 t1(Duration1(3));
+ T1 t2(Duration1(3));
+ BOOST_TEST(!(t1 < t2));
+ BOOST_TEST(!(t1 > t2));
+ BOOST_TEST( (t1 <= t2));
+ BOOST_TEST( (t1 >= t2));
+ }
+ {
+ T1 t1(Duration1(3));
+ T1 t2(Duration1(4));
+ BOOST_TEST( (t1 < t2));
+ BOOST_TEST(!(t1 > t2));
+ BOOST_TEST( (t1 <= t2));
+ BOOST_TEST(!(t1 >= t2));
+ }
+ {
+ T1 t1(Duration1(3));
+ T2 t2(Duration2(3000));
+ BOOST_TEST(!(t1 < t2));
+ BOOST_TEST(!(t1 > t2));
+ BOOST_TEST( (t1 <= t2));
+ BOOST_TEST( (t1 >= t2));
+ }
+ {
+ T1 t1(Duration1(3));
+ T2 t2(Duration2(3001));
+ BOOST_TEST( (t1 < t2));
+ BOOST_TEST(!(t1 > t2));
+ BOOST_TEST( (t1 <= t2));
+ BOOST_TEST(!(t1 >= t2));
+ }
+
+ return boost::report_errors();
+}

Added: sandbox/chrono/libs/chrono/test/time_point/cons/implicit_fail.cpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/libs/chrono/test/time_point/cons/implicit_fail.cpp 2010-11-01 17:11:08 EDT (Mon, 01 Nov 2010)
@@ -0,0 +1,14 @@
+// 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.hpp>
+
+void test()
+{
+ typedef boost::chrono::system_clock Clock;
+ typedef boost::chrono::milliseconds Duration;
+ boost::chrono::time_point<Clock, Duration> t = Duration(3);
+}

Added: sandbox/chrono/libs/chrono/test/time_point/cons/non_implicit_convertible_duration_fail.cpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/libs/chrono/test/time_point/cons/non_implicit_convertible_duration_fail.cpp 2010-11-01 17:11:08 EDT (Mon, 01 Nov 2010)
@@ -0,0 +1,18 @@
+// Copyright 2010 Vicente J. Botet Escriba
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+
+// Duration2 shall be implicitly convertible to duration.
+
+#include <boost/chrono.hpp>
+
+void test()
+{
+ typedef boost::chrono::system_clock Clock;
+ typedef boost::chrono::milliseconds Duration1;
+ typedef boost::chrono::microseconds Duration2;
+ {
+ boost::chrono::time_point<Clock, Duration2> t2(Duration2(3));
+ boost::chrono::time_point<Clock, Duration1> t1 = t2;
+ }
+}

Added: sandbox/chrono/libs/chrono/test/time_point/constructor_pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/libs/chrono/test/time_point/constructor_pass.cpp 2010-11-01 17:11:08 EDT (Mon, 01 Nov 2010)
@@ -0,0 +1,40 @@
+// 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.hpp>
+#include <boost/detail/lightweight_test.hpp>
+#include <libs/chrono/test/rep.h>
+
+int main()
+{
+ {
+ typedef boost::chrono::system_clock Clock;
+ typedef boost::chrono::microseconds Duration1;
+ typedef boost::chrono::milliseconds Duration2;
+ boost::chrono::time_point<Clock, Duration2> t2(Duration2(3));
+ boost::chrono::time_point<Clock, Duration1> t1 = t2;
+ BOOST_TEST(t1.time_since_epoch() == Duration1(3000));
+ }
+ {
+ typedef boost::chrono::system_clock Clock;
+ typedef boost::chrono::duration<Rep, boost::milli> Duration;
+ boost::chrono::time_point<Clock, Duration> t;
+ BOOST_TEST(t.time_since_epoch() == Duration::zero());
+ }
+ {
+ typedef boost::chrono::system_clock Clock;
+ typedef boost::chrono::milliseconds Duration;
+ boost::chrono::time_point<Clock, Duration> t(Duration(3));
+ BOOST_TEST(t.time_since_epoch() == Duration(3));
+ }
+ {
+ typedef boost::chrono::system_clock Clock;
+ typedef boost::chrono::milliseconds Duration;
+ boost::chrono::time_point<Clock, Duration> t(boost::chrono::seconds(3));
+ BOOST_TEST(t.time_since_epoch() == Duration(3000));
+ }
+
+
+ return boost::report_errors();
+}

Added: sandbox/chrono/libs/chrono/test/time_point/default_duration_pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/libs/chrono/test/time_point/default_duration_pass.cpp 2010-11-01 17:11:08 EDT (Mon, 01 Nov 2010)
@@ -0,0 +1,15 @@
+// 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.hpp>
+#include <boost/type_traits.hpp>
+#if !defined(BOOST_NO_STATIC_ASSERT)
+#define NOTHING ""
+#endif
+
+void test()
+{
+ BOOST_CHRONO_STATIC_ASSERT((boost::is_same<boost::chrono::system_clock::duration,
+ boost::chrono::time_point<boost::chrono::system_clock>::duration>::value), NOTHING, ());
+}

Added: sandbox/chrono/libs/chrono/test/time_point/min_max_pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/libs/chrono/test/time_point/min_max_pass.cpp 2010-11-01 17:11:08 EDT (Mon, 01 Nov 2010)
@@ -0,0 +1,18 @@
+// 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.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+int main()
+{
+ typedef boost::chrono::system_clock Clock;
+ typedef boost::chrono::milliseconds Duration;
+ typedef boost::chrono::time_point<Clock, Duration> TP;
+
+ BOOST_TEST((TP::min)() == TP((Duration::min)()));
+ BOOST_TEST((TP::max)() == TP((Duration::max)()));
+
+ return boost::report_errors();
+}

Added: sandbox/chrono/libs/chrono/test/time_point/not_duration_fail.cpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/libs/chrono/test/time_point/not_duration_fail.cpp 2010-11-01 17:11:08 EDT (Mon, 01 Nov 2010)
@@ -0,0 +1,13 @@
+// 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 shall be an instance of duration.
+
+#include <boost/chrono.hpp>
+
+void test()
+{
+ typedef boost::chrono::time_point<boost::chrono::system_clock, int> T;
+ T t;
+}

Added: sandbox/chrono/libs/chrono/test/time_point/time_point_cast_int_fail.cpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/libs/chrono/test/time_point/time_point_cast_int_fail.cpp 2010-11-01 17:11:08 EDT (Mon, 01 Nov 2010)
@@ -0,0 +1,15 @@
+// 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 shall be an instantiation of duration.
+
+#include <boost/chrono.hpp>
+
+void test()
+{
+ typedef boost::chrono::system_clock Clock;
+ typedef boost::chrono::time_point<Clock, boost::chrono::milliseconds> FromTimePoint;
+ typedef boost::chrono::time_point<Clock, boost::chrono::minutes> ToTimePoint;
+ boost::chrono::time_point_cast<ToTimePoint>(FromTimePoint(boost::chrono::milliseconds(3)));
+}

Added: sandbox/chrono/libs/chrono/test/time_point/time_point_cast_pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/libs/chrono/test/time_point/time_point_cast_pass.cpp 2010-11-01 17:11:08 EDT (Mon, 01 Nov 2010)
@@ -0,0 +1,45 @@
+// 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.hpp>
+#include <boost/type_traits.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+#if !defined(BOOST_NO_STATIC_ASSERT)
+#define NOTHING ""
+#endif
+
+template <class FromDuration, class ToDuration>
+void
+test(const FromDuration& df, const ToDuration& d)
+{
+ typedef boost::chrono::system_clock Clock;
+ typedef boost::chrono::time_point<Clock, FromDuration> FromTimePoint;
+ typedef boost::chrono::time_point<Clock, ToDuration> ToTimePoint;
+ FromTimePoint f(df);
+ ToTimePoint t(d);
+#if defined(BOOST_NO_DECLTYPE)
+ typedef BOOST_TYPEOF_TPL(boost::chrono::time_point_cast<ToDuration>(f)) R;
+#else
+ typedef decltype(boost::chrono::time_point_cast<ToDuration>(f)) R;
+#endif
+ BOOST_CHRONO_STATIC_ASSERT((boost::is_same<R, ToTimePoint>::value), NOTHING, ());
+ BOOST_TEST(boost::chrono::time_point_cast<ToDuration>(f) == t);
+}
+
+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));
+
+ return boost::report_errors();
+}


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk