Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r74451 - in trunk/libs/chrono/test: . clock stopwatch
From: vicente.botet_at_[hidden]
Date: 2011-09-18 10:12:54


Author: viboes
Date: 2011-09-18 10:12:53 EDT (Sun, 18 Sep 2011)
New Revision: 74451
URL: http://svn.boost.org/trac/boost/changeset/74451

Log:
Adapt test to definition of BOOST_CHRONO_HAS_THREAD_CLOCK+BOOST_CHRONO_HAS_PROCESS_CLOCK
Added:
   trunk/libs/chrono/test/stopwatch/
   trunk/libs/chrono/test/stopwatch/simple_stopwatch_pass.cpp (contents, props changed)
Text files modified:
   trunk/libs/chrono/test/Jamfile.v2 | 5 +++++
   trunk/libs/chrono/test/clock/clock_pass.cpp | 2 ++
   2 files changed, 7 insertions(+), 0 deletions(-)

Modified: trunk/libs/chrono/test/Jamfile.v2
==============================================================================
--- trunk/libs/chrono/test/Jamfile.v2 (original)
+++ trunk/libs/chrono/test/Jamfile.v2 2011-09-18 10:12:53 EDT (Sun, 18 Sep 2011)
@@ -242,6 +242,11 @@
         [ chrono-run2-mt clock/clock_pass.cpp : clock_clock_pass ]
         ;
 
+ test-suite "stopwatch"
+ :
+ [ chrono-run2-mt stopwatch/simple_stopwatch_pass.cpp : simple_stopwatch_pass ]
+ ;
+
     test-suite "io"
         :
         [ chrono-run-mt ../example/io_ex1.cpp ]

Modified: trunk/libs/chrono/test/clock/clock_pass.cpp
==============================================================================
--- trunk/libs/chrono/test/clock/clock_pass.cpp (original)
+++ trunk/libs/chrono/test/clock/clock_pass.cpp 2011-09-18 10:12:53 EDT (Sun, 18 Sep 2011)
@@ -137,6 +137,7 @@
     check_clock_now_throws<boost::chrono::thread_clock>();
 #endif
     
+#if defined(BOOST_CHRONO_HAS_PROCESS_CLOCKS)
     check_clock_invariants<boost::chrono::process_real_cpu_clock>();
     BOOST_CHRONO_STATIC_ASSERT(boost::chrono::process_real_cpu_clock::is_steady, NOTHING, ());
     check_clock_now<boost::chrono::process_real_cpu_clock>();
@@ -160,6 +161,7 @@
     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>();
+#endif
     
     return boost::report_errors();
 }

Added: trunk/libs/chrono/test/stopwatch/simple_stopwatch_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/chrono/test/stopwatch/simple_stopwatch_pass.cpp 2011-09-18 10:12:53 EDT (Sun, 18 Sep 2011)
@@ -0,0 +1,128 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 <iostream>
+#include <boost/type_traits/is_same.hpp>
+#include <boost/chrono/stopwatches/simple_stopwatch.hpp>
+#include <boost/chrono/process_cpu_clocks.hpp>
+#include <boost/chrono/thread_clock.hpp>
+#include <boost/chrono/chrono_io.hpp>
+#include <boost/system/system_error.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+#if !defined(BOOST_NO_STATIC_ASSERT)
+#define NOTHING ""
+#endif
+
+namespace ex
+{
+ template<class Rep, class Period>
+ void sleep_for(const boost::chrono::duration<Rep, Period>& d)
+ {
+ typedef boost::chrono::high_resolution_clock Clock;
+ typename Clock::time_point go =
+ Clock::now() + d;
+ while (Clock::now() < go)
+ {
+ }
+ }
+}
+
+template <typename Clock>
+void check_invariants()
+{
+ typedef boost::chrono::simple_stopwatch<Clock> Stopwatch;
+ BOOST_CHRONO_STATIC_ASSERT((boost::is_same<typename Stopwatch::rep, typename Stopwatch::clock::duration::rep>::value), NOTHING, ());
+ BOOST_CHRONO_STATIC_ASSERT((boost::is_same<typename Stopwatch::period, typename Stopwatch::clock::duration::period>::value), NOTHING, ());
+ BOOST_CHRONO_STATIC_ASSERT((boost::is_same<typename Stopwatch::duration, typename Stopwatch::clock::time_point::duration>::value), NOTHING, ());
+ BOOST_CHRONO_STATIC_ASSERT(Stopwatch::is_steady == Stopwatch::clock::is_steady, NOTHING, ());
+ // to be replaced by has static member bool is_steady
+}
+
+template <typename Clock>
+void check_default_constructor()
+{
+ typedef boost::chrono::simple_stopwatch<Clock> Stopwatch;
+ Stopwatch _;
+}
+
+template <typename Clock>
+void check_constructor_ec()
+{
+ typedef boost::chrono::simple_stopwatch<Clock> Stopwatch;
+ boost::system::error_code ec;
+ Stopwatch _(ec);
+ BOOST_TEST(ec.value()==0);
+}
+
+template <typename Clock>
+void check_constructor_throws()
+{
+ typedef boost::chrono::simple_stopwatch<Clock> Stopwatch;
+ Stopwatch _(boost::throws());
+}
+
+
+template <typename Clock>
+void check_elapsed(bool check=true)
+{
+ typedef boost::chrono::simple_stopwatch<Clock> Stopwatch;
+ Stopwatch sw;
+ ex::sleep_for(boost::chrono::milliseconds(10));
+ typename Stopwatch::duration d=sw.elapsed();
+ //std::cout << d << std::endl;
+ //std::cout << boost::chrono::duration_cast<boost::chrono::milliseconds>(d) << std::endl;
+ if (check)
+ BOOST_TEST(boost::chrono::duration_cast<boost::chrono::milliseconds>(d)>=boost::chrono::milliseconds(10));
+}
+template <typename Clock>
+void check_elapsed2()
+{
+ typedef boost::chrono::simple_stopwatch<Clock> Stopwatch;
+ Stopwatch sw;
+ ex::sleep_for(boost::chrono::milliseconds(10));
+ typename Stopwatch::duration d=sw.elapsed();
+}
+
+
+template <typename Clock>
+void check_all(bool check=true)
+{
+ check_invariants<Clock>();
+ check_default_constructor<Clock>();
+ check_constructor_ec<Clock>();
+ check_constructor_throws<Clock>();
+ check_elapsed<Clock>(check);
+}
+
+int main()
+{
+ check_all<boost::chrono::high_resolution_clock>();
+#ifdef BOOST_CHRONO_HAS_CLOCK_STEADY
+ check_all<boost::chrono::steady_clock>();
+#endif
+ check_all<boost::chrono::system_clock>();
+
+#if defined(BOOST_CHRONO_HAS_THREAD_CLOCK)
+ check_all<boost::chrono::thread_clock>();
+#endif
+
+#if defined(BOOST_CHRONO_HAS_PROCESS_CLOCKS)
+ check_all<boost::chrono::process_real_cpu_clock>();
+ check_all<boost::chrono::process_user_cpu_clock>(false);
+ check_all<boost::chrono::process_system_cpu_clock>(false);
+ check_all<boost::chrono::process_cpu_clock>();
+#endif
+
+ 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