Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r66332 - in sandbox/chrono/libs/chrono/test: . clock traits
From: vicente.botet_at_[hidden]
Date: 2010-11-01 17:31:14


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

Log:
Chrono: Refactor tests

Added:
   sandbox/chrono/libs/chrono/test/clock/clock_pass.cpp (contents, props changed)
   sandbox/chrono/libs/chrono/test/traits/duration_values_pass.cpp (contents, props changed)
   sandbox/chrono/libs/chrono/test/traits/treat_as_floating_point_pass.cpp (contents, props changed)
Text files modified:
   sandbox/chrono/libs/chrono/test/Jamfile.v2 | 81 +++++++++++++++++----------------------
   1 files changed, 36 insertions(+), 45 deletions(-)

Modified: sandbox/chrono/libs/chrono/test/Jamfile.v2
==============================================================================
--- sandbox/chrono/libs/chrono/test/Jamfile.v2 (original)
+++ sandbox/chrono/libs/chrono/test/Jamfile.v2 2010-11-01 17:31:12 EDT (Mon, 01 Nov 2010)
@@ -191,12 +191,10 @@
 
     test-suite "traits"
         :
- [ chrono-compile traits/specializations/duration.pass.cpp ]
- [ chrono-compile traits/specializations/time_point.pass.cpp ]
- [ chrono-compile traits/is_fp/treat_as_floating_point.pass.cpp ]
- [ chrono-run traits/duration_values/max.pass.cpp ]
- [ chrono-run traits/duration_values/zero.pass.cpp ]
- [ chrono-run traits/duration_values/min.pass.cpp ]
+ [ chrono-compile traits/common_type_duration_pass.cpp ]
+ [ chrono-compile traits/common_type_time_point_pass.cpp ]
+ [ chrono-compile traits/treat_as_floating_point_pass.cpp ]
+ [ chrono-run2 traits/duration_values_pass.cpp : traits_duration_values_pass ]
         ;
 
     test-suite "duration"
@@ -235,56 +233,49 @@
 
     test-suite "time_point"
         :
- [ chrono-compile2 time_point/default_duration.pass.cpp : time_point.default_duration.pass ]
- [ compile-fail time_point/duration.fail.cpp : : time_point.duration.fail ]
+ [ chrono-compile2 time_point/default_duration_pass.cpp : time_point.default_duration_pass ]
+ [ compile-fail time_point/not_duration_fail.cpp : : time_point_not_duration_fail ]
 
- [ chrono-run2 time_point/arithmetic/op_plus_ass.pass.cpp : time_point.op_plus_ass.pass ]
- [ chrono-run2 time_point/arithmetic/op_minus_ass.pass.cpp : time_point.op_minus_ass.pass ]
+ [ chrono-run2 time_point/arithmetic_pass.cpp : time_point_arithmetic_pass ]
 
- [ chrono-run2 time_point/cast/time_point_cast.pass.cpp : time_point.time_point_cast.pass ]
- [ compile-fail time_point/cast/toduration.fail.cpp : : time_point.toduration.fail ]
+ [ chrono-run2 time_point/time_point_cast_pass.cpp : time_point_time_point_cast_pass ]
+ [ compile-fail time_point/time_point_cast_int_fail.cpp : : time_point_time_point_cast_int_fail ]
 
- [ compile-fail time_point/comparisons/op_equal.fail.cpp : : time_point.op_equal.fail ]
- [ chrono-run2 time_point/comparisons/op_equal.pass.cpp : time_point.op_equal.pass ]
- [ compile-fail time_point/comparisons/op_less.fail.cpp : : time_point.op_less.fail ]
- [ chrono-run2 time_point/comparisons/op_less.pass.cpp : time_point.op_less.pass ]
-
- [ compile-fail time_point/cons/convert.fail.cpp : : time_point.convert.fail ]
- [ chrono-run2 time_point/cons/convert.pass.cpp : time_point.convert.pass ]
- [ chrono-run2 time_point/cons/default.pass.cpp : time_point.default.pass ]
- [ compile-fail time_point/cons/duration.fail.cpp : : time_point.cons.duration.fail ]
- [ chrono-run2 time_point/cons/duration.pass.cpp : time_point.duration.pass ]
-
- [ chrono-run2 time_point/nonmember/op_plus.pass.cpp : time_point.op_plus.pass ]
- [ chrono-run2 time_point/nonmember/op_minus_time_point.pass.cpp : time_point.op_minus_time_point.pass ]
- [ chrono-run2 time_point/nonmember/op_minus_duration.pass.cpp : time_point.op_minus_duration.pass ]
+ [ chrono-run2 time_point/comparisons_pass.cpp : time_point_comparisons_pass ]
+ [ compile-fail time_point/comparisons/equal_fail.cpp : : time_point_equal_fail ]
+ [ compile-fail time_point/comparisons/less_fail.cpp : : time_point_less_fail ]
 
- [ chrono-run2 time_point/special/max.pass.cpp : time_point.max.pass ]
- [ chrono-run2 time_point/special/min.pass.cpp : time_point.min.pass ]
+ [ chrono-run2 time_point/constructor_pass.cpp : time_point_constructor_pass ]
+ [ compile-fail time_point/cons/implicit_fail.cpp : : time_point_implicit_fail ]
+ [ compile-fail time_point/cons/non_implicit_convertible_duration_fail.cpp : : time_point_non_implicit_convertible_duration_fail ]
+
+ [ chrono-run2 time_point/min_max_pass.cpp : time_point_min_max_pass ]
         ;
 
     test-suite "clock"
         :
- [ chrono-compile2 clock/hires/consistency.pass.cpp : clock.hires.consistency.pass ]
- [ chrono-run2 clock/hires/now.pass.cpp : clock.hires.now.pass ]
-
- [ chrono-compile2 clock/monotonic/consistency.pass.cpp : clock.monotonic.consistency.pass ]
- [ chrono-run2 clock/monotonic/now.pass.cpp : clock.monotonic.now.pass ]
-
- [ chrono-compile2 clock/system/consistency.pass.cpp : clock.system.consistency.pass ]
- [ chrono-run2 clock/system/now.pass.cpp : clock.system.now.pass ]
- [ chrono-run2 clock/system/from_time_t.pass.cpp : clock.system.from_time_t.pass ]
- [ chrono-run2 clock/system/rep_signed.pass.cpp : clock.system.rep_signed.pass ]
- [ chrono-run2 clock/system/to_time_t.pass.cpp : clock.system.to_time_t.pass ]
+
+ [ chrono-run2 clock/clock_pass.cpp : clock_clock_pass_ ]
+ #[ chrono-compile2 clock/hires/consistency.pass.cpp : clock.hires.consistency.pass ]
+ #[ chrono-run2 clock/hires/now.pass.cpp : clock.hires.now.pass ]
+
+ #[ chrono-compile2 clock/monotonic/consistency.pass.cpp : clock.monotonic.consistency.pass ]
+ #[ chrono-run2 clock/monotonic/now.pass.cpp : clock.monotonic.now.pass ]
+
+ #[ chrono-compile2 clock/system/consistency.pass.cpp : clock.system.consistency.pass ]
+ #[ chrono-run2 clock/system/now.pass.cpp : clock.system.now.pass ]
+ #[ chrono-run2 clock/system/from_time_t.pass.cpp : clock.system.from_time_t.pass ]
+ #[ chrono-run2 clock/system/rep_signed.pass.cpp : clock.system.rep_signed.pass ]
+ #[ chrono-run2 clock/system/to_time_t.pass.cpp : clock.system.to_time_t.pass ]
 
- [ chrono-compile2 clock/process/consistency.pass.cpp : clock.process.consistency.pass ]
- [ chrono-run2 clock/process/now.pass.cpp : clock.process.now.pass ]
+ #[ chrono-compile2 clock/process/consistency.pass.cpp : clock.process.consistency.pass ]
+ #[ chrono-run2 clock/process/now.pass.cpp : clock.process.now.pass ]
 
- [ chrono-compile2 clock/thread/consistency.pass.cpp : clock.thread.consistency.pass ]
- [ chrono-run2 clock/thread/now.pass.cpp : clock.thread.now.pass ]
+ #[ chrono-compile2 clock/thread/consistency.pass.cpp : clock.thread.consistency.pass ]
+ #[ chrono-run2 clock/thread/now.pass.cpp : clock.thread.now.pass ]
 
- [ chrono-compile2 clock/errored/consistency.pass.cpp : clock.errored.consistency.pass ]
- [ chrono-run2 clock/errored/now.pass.cpp : clock.errored.now.pass ]
+ #[ chrono-compile2 clock/errored/consistency.pass.cpp : clock.errored.consistency.pass ]
+ #[ chrono-run2 clock/errored/now.pass.cpp : clock.errored.now.pass ]
 
         ;
 

Added: sandbox/chrono/libs/chrono/test/clock/clock_pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/libs/chrono/test/clock/clock_pass.cpp 2010-11-01 17:31:12 EDT (Mon, 01 Nov 2010)
@@ -0,0 +1,156 @@
+// 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/type_traits/is_same.hpp>
+#include <boost/chrono.hpp>
+#include <boost/chrono/process_cpu_clocks.hpp>
+#include <boost/chrono/thread_clock.hpp>
+#include <boost/system/system_error.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+#if !defined(BOOST_NO_STATIC_ASSERT)
+#define NOTHING ""
+#endif
+
+template <typename Clock>
+void check_clock_invariants()
+{
+ BOOST_CHRONO_STATIC_ASSERT((boost::is_same<typename Clock::rep, typename Clock::duration::rep>::value), NOTHING, ());
+ BOOST_CHRONO_STATIC_ASSERT((boost::is_same<typename Clock::period, typename Clock::duration::period>::value), NOTHING, ());
+ BOOST_CHRONO_STATIC_ASSERT((boost::is_same<typename Clock::duration, typename Clock::time_point::duration>::value), NOTHING, ());
+ BOOST_CHRONO_STATIC_ASSERT(Clock::is_monotonic || !Clock::is_monotonic, NOTHING, ());
+ // to be replaced by has static member bool is_monotonic
+}
+
+template <typename Clock>
+void check_clock_now()
+{
+ typename Clock::time_point t1 = Clock::now();
+}
+
+template <typename Clock>
+void check_clock_now_ec()
+{
+ boost::system::error_code ec;
+ typename Clock::time_point t1 = Clock::now(ec);
+ BOOST_TEST(ec.value()==0);
+}
+
+template <typename Clock>
+void check_clock_now_throws()
+{
+ typename Clock::time_point t1 = Clock::now(boost::throws());
+}
+
+template <typename Clock>
+void check_clock_now_err(int err)
+{
+ Clock::set_errno(err);
+ try {
+ typename Clock::time_point t1 = Clock::now();
+ } catch (boost::system::system_error& ex) {
+ BOOST_TEST(ex.code().value()==err);
+// BOOST_TEST(ex.code().category() == BOOST_CHRONO_SYSTEM_CATEGORY);
+// BOOST_TEST(std::string(ex.what()) == std::string("errored_clock"));
+ }
+ Clock::set_errno(0);
+}
+
+template <typename Clock>
+void check_clock_now_ec_err(int err)
+{
+ Clock::set_errno(err);
+ boost::system::error_code ec;
+ typename Clock::time_point t1 = Clock::now(ec);
+ BOOST_TEST(ec.value()==err);
+// BOOST_TEST(ec.category() == BOOST_CHRONO_SYSTEM_CATEGORY);
+ Clock::set_errno(0);
+}
+
+template <typename Clock>
+void check_clock_now_throws_err(int err)
+{
+ Clock::set_errno(err);
+ try {
+ typename Clock::time_point t1 = Clock::now(boost::throws());
+ BOOST_TEST(0&&"exception not thown");
+ } catch (boost::system::system_error& ex) {
+ BOOST_TEST(ex.code().value()==err);
+// BOOST_TEST(ex.code().category() == BOOST_CHRONO_SYSTEM_CATEGORY);
+// BOOST_TEST(std::string(ex.what()) == std::string("errored_clock"));
+ }
+ Clock::set_errno(0);
+}
+
+int main()
+{
+ check_clock_invariants<boost::chrono::high_resolution_clock>();
+ check_clock_now<boost::chrono::high_resolution_clock>();
+ check_clock_now_ec<boost::chrono::high_resolution_clock>();
+ check_clock_now_throws<boost::chrono::high_resolution_clock>();
+
+#ifdef BOOST_CHRONO_HAS_CLOCK_MONOTONIC
+ check_clock_invariants<boost::chrono::monotonic_clock>();
+ BOOST_CHRONO_STATIC_ASSERT(boost::chrono::monotonic_clock::is_monotonic, NOTHING, ());
+ check_clock_now<boost::chrono::monotonic_clock>();
+ check_clock_now_ec<boost::chrono::monotonic_clock>();
+ check_clock_now_throws<boost::chrono::monotonic_clock>();
+#endif
+
+ check_clock_invariants<boost::chrono::system_clock>();
+ BOOST_CHRONO_STATIC_ASSERT(!boost::chrono::system_clock::is_monotonic, NOTHING, ());
+ check_clock_now<boost::chrono::system_clock>();
+ check_clock_now_ec<boost::chrono::system_clock>();
+ check_clock_now_throws<boost::chrono::system_clock>();
+ {
+ typedef boost::chrono::system_clock C;
+ C::time_point t1 = C::from_time_t(C::to_time_t(C::now()));
+ (void)t1;
+ }
+ {
+ typedef boost::chrono::system_clock C;
+ std::time_t t1 = C::to_time_t(C::now());
+ (void)t1;
+
+ }
+ {
+ BOOST_TEST((boost::chrono::system_clock::duration::min)() <
+ boost::chrono::system_clock::duration::zero());
+
+ }
+
+#if defined(BOOST_CHRONO_HAS_THREAD_CLOCK)
+ check_clock_invariants<boost::chrono::thread_clock>();
+ BOOST_CHRONO_STATIC_ASSERT(boost::chrono::thread_clock>::is_monotonic, NOTHING, ());
+ check_clock_now<boost::chrono::thread_clock>();
+ check_clock_now_ec<boost::chrono::thread_clock>();
+ check_clock_now_throws<boost::chrono::thread_clock>();
+#endif
+
+ check_clock_invariants<boost::chrono::process_real_cpu_clock>();
+ BOOST_CHRONO_STATIC_ASSERT(boost::chrono::process_real_cpu_clock::is_monotonic, NOTHING, ());
+ check_clock_now<boost::chrono::process_real_cpu_clock>();
+ check_clock_now_ec<boost::chrono::process_real_cpu_clock>();
+ check_clock_now_throws<boost::chrono::process_real_cpu_clock>();
+
+ check_clock_invariants<boost::chrono::process_user_cpu_clock>();
+ BOOST_CHRONO_STATIC_ASSERT(boost::chrono::process_user_cpu_clock::is_monotonic, NOTHING, ());
+ check_clock_now<boost::chrono::process_user_cpu_clock>();
+ check_clock_now_ec<boost::chrono::process_user_cpu_clock>();
+ check_clock_now_throws<boost::chrono::process_user_cpu_clock>();
+
+ check_clock_invariants<boost::chrono::process_system_cpu_clock>();
+ BOOST_CHRONO_STATIC_ASSERT(boost::chrono::process_system_cpu_clock::is_monotonic, NOTHING, ());
+ check_clock_now<boost::chrono::process_system_cpu_clock>();
+ check_clock_now_ec<boost::chrono::process_system_cpu_clock>();
+ check_clock_now_throws<boost::chrono::process_system_cpu_clock>();
+
+ check_clock_invariants<boost::chrono::process_cpu_clock>();
+ BOOST_CHRONO_STATIC_ASSERT(boost::chrono::process_cpu_clock::is_monotonic, NOTHING, ());
+ check_clock_now<boost::chrono::process_cpu_clock>();
+ check_clock_now_ec<boost::chrono::process_cpu_clock>();
+ check_clock_now_throws<boost::chrono::process_cpu_clock>();
+
+ return boost::report_errors();
+}
\ No newline at end of file

Added: sandbox/chrono/libs/chrono/test/traits/duration_values_pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/libs/chrono/test/traits/duration_values_pass.cpp 2010-11-01 17:31:12 EDT (Mon, 01 Nov 2010)
@@ -0,0 +1,32 @@
+// 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 <limits>
+#include <boost/detail/lightweight_test.hpp>
+
+#include <libs/chrono/test/rep.h>
+
+int main()
+{
+ BOOST_TEST((boost::chrono::duration_values<int>::min)() ==
+ (std::numeric_limits<int>::min)());
+ BOOST_TEST((boost::chrono::duration_values<double>::min)() ==
+ -(std::numeric_limits<double>::max)());
+ BOOST_TEST((boost::chrono::duration_values<Rep>::min)() ==
+ (std::numeric_limits<Rep>::min)());
+
+ BOOST_TEST((boost::chrono::duration_values<int>::max)() ==
+ (std::numeric_limits<int>::max)());
+ BOOST_TEST((boost::chrono::duration_values<double>::max)() ==
+ (std::numeric_limits<double>::max)());
+ BOOST_TEST((boost::chrono::duration_values<Rep>::max)() ==
+ (std::numeric_limits<Rep>::max)());
+
+ BOOST_TEST(boost::chrono::duration_values<int>::zero() == 0);
+ BOOST_TEST(boost::chrono::duration_values<Rep>::zero() == 0);
+
+ return boost::report_errors();
+}

Added: sandbox/chrono/libs/chrono/test/traits/treat_as_floating_point_pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/libs/chrono/test/traits/treat_as_floating_point_pass.cpp 2010-11-01 17:31:12 EDT (Mon, 01 Nov 2010)
@@ -0,0 +1,32 @@
+// 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
+
+template <class T>
+void
+test()
+{
+ BOOST_CHRONO_STATIC_ASSERT((boost::is_base_of<boost::is_floating_point<T>,
+ boost::chrono::treat_as_floating_point<T> >::value), NOTHING, ());
+}
+
+struct A {};
+
+void testall()
+{
+ test<int>();
+ test<unsigned>();
+ test<char>();
+ test<bool>();
+ test<float>();
+ test<double>();
+ test<long double>();
+ test<A>();
+}


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