Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r74650 - in trunk/libs/chrono/test: . stopwatch
From: vicente.botet_at_[hidden]
Date: 2011-10-02 11:12:30


Author: viboes
Date: 2011-10-02 11:12:29 EDT (Sun, 02 Oct 2011)
New Revision: 74650
URL: http://svn.boost.org/trac/boost/changeset/74650

Log:
Chrono: Added basic and accumulator set reporter tests
Added:
   trunk/libs/chrono/test/stopwatch/basic_stopwatch_reporter_laps_accumulator_set_pass.cpp (contents, props changed)
   trunk/libs/chrono/test/stopwatch/basic_stopwatch_reporter_pass.cpp (contents, props changed)
Text files modified:
   trunk/libs/chrono/test/Jamfile.v2 | 6 +++++-
   1 files changed, 5 insertions(+), 1 deletions(-)

Modified: trunk/libs/chrono/test/Jamfile.v2
==============================================================================
--- trunk/libs/chrono/test/Jamfile.v2 (original)
+++ trunk/libs/chrono/test/Jamfile.v2 2011-10-02 11:12:29 EDT (Sun, 02 Oct 2011)
@@ -248,6 +248,7 @@
         [ chrono-run2 stopwatch/basic_stopwatch_last_lap_pass.cpp : basic_stopwatch_last_lap_pass ]
         [ chrono-run2 stopwatch/basic_stopwatch_laps_accumulator_set_pass.cpp : basic_stopwatch_laps_accumulator_set_pass ]
         [ chrono-run2 stopwatch/basic_stopwatch_laps_container_pass.cpp : basic_stopwatch_laps_container_pass ]
+
         [ chrono-run2 stopwatch/suspendable_stopwatch_pass.cpp : suspendable_stopwatch_pass ]
         ;
 
@@ -258,7 +259,10 @@
 
     test-suite "stopclock"
         :
- [ chrono-run2-mt stopwatch/simple_stopwatch_reporter_pass.cpp : simple_stopwatch_reporter_pass ]
+ [ chrono-run2 stopwatch/simple_stopwatch_reporter_pass.cpp : simple_stopwatch_reporter_pass ]
+ [ chrono-run2 stopwatch/basic_stopwatch_reporter_pass.cpp : basic_stopwatch_reporter_pass ]
+ [ chrono-run2 stopwatch/basic_stopwatch_reporter_laps_accumulator_set_pass.cpp : basic_stopwatch_reporter_laps_accumulator_set_pass ]
+
         ;
     test-suite "stopclock_ex"
         :

Added: trunk/libs/chrono/test/stopwatch/basic_stopwatch_reporter_laps_accumulator_set_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/chrono/test/stopwatch/basic_stopwatch_reporter_laps_accumulator_set_pass.cpp 2011-10-02 11:12:29 EDT (Sun, 02 Oct 2011)
@@ -0,0 +1,263 @@
+//===----------------------------------------------------------------------===//
+//
+// 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/basic_stopwatch.hpp>
+#include <libs/chrono/test/cycle_count.hpp>
+#include <boost/chrono/stopwatches/reporters/stopwatch_reporter.hpp>
+#include <boost/chrono/stopwatches/reporters/system_default_formatter.hpp>
+#include <boost/chrono/stopwatches/reporters/basic_stopwatch_default_formatter.hpp>
+#include <boost/chrono/stopwatches/collectors/laps_accumulator_set.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
+
+using namespace boost::chrono;
+
+
+template <typename Stopwatch>
+void check_invariants()
+{
+ 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, ());
+}
+
+template <typename Stopwatch>
+void check_default_constructor()
+{
+ Stopwatch sw;
+ BOOST_TEST(sw.is_running());
+}
+
+template <typename Stopwatch>
+void check_dont_start_constructor()
+{
+ Stopwatch sw(boost::chrono::dont_start);
+ BOOST_TEST(!sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ typename Stopwatch::duration d=sw.elapsed();
+ BOOST_TEST(d == Stopwatch::duration::zero());
+}
+
+template <typename Stopwatch>
+void check_constructor_ec()
+{
+ boost::system::error_code ec;
+ Stopwatch sw(ec);
+ BOOST_TEST(sw.is_running());
+ BOOST_TEST(ec.value()==0);
+}
+
+template <typename Stopwatch>
+void check_constructor_throws()
+{
+ Stopwatch sw(boost::throws());
+ BOOST_TEST(sw.is_running());
+}
+
+template <typename Stopwatch>
+void check_elapsed()
+{
+ Stopwatch sw;
+ BOOST_TEST(sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ typename Stopwatch::duration d=sw.elapsed();
+ BOOST_TEST(sw.is_running());
+ BOOST_TEST(d >= boost::chrono::milliseconds(100));
+}
+
+template <typename Stopwatch>
+void check_start_start()
+{
+ Stopwatch sw;
+ BOOST_TEST(sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ sw.start();
+ BOOST_TEST(sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ typename Stopwatch::duration d=sw.elapsed();
+ BOOST_TEST(sw.is_running());
+ BOOST_TEST(d >= boost::chrono::milliseconds(100));
+ BOOST_TEST(d < boost::chrono::milliseconds(200));
+}
+
+template <typename Stopwatch>
+void check_dont_start_start()
+{
+ Stopwatch sw(boost::chrono::dont_start);
+ BOOST_TEST(!sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ sw.start();
+ BOOST_TEST(sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ typename Stopwatch::duration d=sw.elapsed();
+ BOOST_TEST(sw.is_running());
+ BOOST_TEST(d >= boost::chrono::milliseconds(100));
+ BOOST_TEST(d < boost::chrono::milliseconds(200));
+}
+
+template <typename Stopwatch>
+void check_dont_start_start_stop()
+{
+ Stopwatch sw(boost::chrono::dont_start);
+ BOOST_TEST(!sw.is_running());
+ sw.start();
+ BOOST_TEST(sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ sw.stop();
+ BOOST_TEST(!sw.is_running());
+ typename Stopwatch::duration d=sw.elapsed();
+ BOOST_TEST(!sw.is_running());
+ BOOST_TEST(d >= boost::chrono::milliseconds(0));
+}
+
+template <typename Stopwatch>
+void check_dont_start_scoped_run()
+{
+ Stopwatch sw(boost::chrono::dont_start);
+ BOOST_TEST(!sw.is_running());
+ {
+ typename Stopwatch::scoped_run _(sw);
+ BOOST_TEST(sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ }
+ BOOST_TEST(!sw.is_running());
+ typename Stopwatch::duration d=sw.elapsed();
+ BOOST_TEST(!sw.is_running());
+ BOOST_TEST(d >= boost::chrono::milliseconds(0));
+}
+
+template <typename Stopwatch>
+void check_stop()
+{
+ Stopwatch sw;
+ BOOST_TEST(sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ sw.stop();
+ BOOST_TEST(!sw.is_running());
+ typename Stopwatch::duration d=sw.elapsed();
+ BOOST_TEST(!sw.is_running());
+ BOOST_TEST(d == boost::chrono::milliseconds(0));
+}
+
+template <typename Stopwatch>
+void check_stop_stop()
+{
+ Stopwatch sw;
+ BOOST_TEST(sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ sw.stop();
+ BOOST_TEST(!sw.is_running());
+ typename Stopwatch::duration d=sw.elapsed();
+ BOOST_TEST(!sw.is_running());
+ BOOST_TEST(d == boost::chrono::milliseconds(0));
+ sw.stop();
+ BOOST_TEST(!sw.is_running());
+ d=sw.elapsed();
+ BOOST_TEST(!sw.is_running());
+ BOOST_TEST(d == boost::chrono::milliseconds(0));
+}
+
+
+
+struct file_line {
+ file_line(const char* file, std::size_t line)
+ : fmt("%1%[%2%] Elapsed time:")
+ {
+ fmt % file % line;
+ }
+ ~file_line()
+ {
+ std::cout << fmt;
+ }
+ boost::format fmt;
+
+};
+
+template <typename Reporter>
+void check_file_line2()
+{
+ Reporter _("%1%\n");
+ file_line fl(__FILE__, __LINE__);
+ ex::sleep_for<typename Reporter::clock>(milliseconds(100));
+
+}
+template <typename Reporter>
+void check_file_line()
+{
+ Reporter rp("%1%[%2%] Elapsed time: %3%\n");
+ rp.format() % __FILE__ % __LINE__;
+
+ ex::sleep_for<typename Reporter::clock>(milliseconds(100));
+
+}
+
+template <typename Reporter>
+void check_report()
+{
+ Reporter sw;
+ ex::sleep_for<typename Reporter::clock>(milliseconds(100));
+ sw.report();
+}
+
+
+
+
+template <typename Clock>
+void check_all()
+{
+ typedef stopwatch_reporter<basic_stopwatch<Clock, boost::chrono::laps_accumulator_set<typename Clock::duration> > > Reporter;
+ typedef stopwatch_reporter<basic_stopwatch<Clock>, elapsed_formatter > ReporterE;
+
+ check_invariants<Reporter>();
+ check_default_constructor<Reporter>();
+ check_constructor_ec<Reporter>();
+ check_constructor_throws<Reporter>();
+ check_elapsed<Reporter>();
+
+ check_report<Reporter>();
+ check_file_line<ReporterE>();
+
+ check_start_start<Reporter>();
+ check_dont_start_constructor<Reporter>();
+ check_dont_start_start<Reporter>();
+ check_dont_start_start_stop<Reporter>();
+ check_dont_start_scoped_run<Reporter>();
+ check_stop<Reporter>();
+ check_stop_stop<Reporter>();
+
+}
+
+
+
+int main()
+{
+ typedef basic_stopwatch<high_resolution_clock > Stopwatch;
+ typedef stopwatch_reporter_default_formatter<Stopwatch>::type Formatter;
+ typedef stopwatch_reporter<Stopwatch> Reporter;
+ static Formatter fmtr;
+
+ Reporter _(fmtr);
+
+ check_all<ex::cycle_count<1500> >();
+
+ return 1+boost::report_errors();
+}

Added: trunk/libs/chrono/test/stopwatch/basic_stopwatch_reporter_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/chrono/test/stopwatch/basic_stopwatch_reporter_pass.cpp 2011-10-02 11:12:29 EDT (Sun, 02 Oct 2011)
@@ -0,0 +1,260 @@
+//===----------------------------------------------------------------------===//
+//
+// 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/basic_stopwatch.hpp>
+#include <libs/chrono/test/cycle_count.hpp>
+#include <boost/chrono/stopwatches/reporters/stopwatch_reporter.hpp>
+#include <boost/chrono/stopwatches/reporters/system_default_formatter.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
+
+using namespace boost::chrono;
+
+
+template <typename Stopwatch>
+void check_invariants()
+{
+ 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, ());
+}
+
+template <typename Stopwatch>
+void check_default_constructor()
+{
+ Stopwatch sw;
+ BOOST_TEST(sw.is_running());
+}
+
+template <typename Stopwatch>
+void check_dont_start_constructor()
+{
+ Stopwatch sw(boost::chrono::dont_start);
+ BOOST_TEST(!sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ typename Stopwatch::duration d=sw.elapsed();
+ BOOST_TEST(d == Stopwatch::duration::zero());
+}
+
+template <typename Stopwatch>
+void check_constructor_ec()
+{
+ boost::system::error_code ec;
+ Stopwatch sw(ec);
+ BOOST_TEST(sw.is_running());
+ BOOST_TEST(ec.value()==0);
+}
+
+template <typename Stopwatch>
+void check_constructor_throws()
+{
+ Stopwatch sw(boost::throws());
+ BOOST_TEST(sw.is_running());
+}
+
+template <typename Stopwatch>
+void check_elapsed()
+{
+ Stopwatch sw;
+ BOOST_TEST(sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ typename Stopwatch::duration d=sw.elapsed();
+ BOOST_TEST(sw.is_running());
+ BOOST_TEST(d >= boost::chrono::milliseconds(100));
+}
+
+template <typename Stopwatch>
+void check_start_start()
+{
+ Stopwatch sw;
+ BOOST_TEST(sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ sw.start();
+ BOOST_TEST(sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ typename Stopwatch::duration d=sw.elapsed();
+ BOOST_TEST(sw.is_running());
+ BOOST_TEST(d >= boost::chrono::milliseconds(100));
+ BOOST_TEST(d < boost::chrono::milliseconds(200));
+}
+
+template <typename Stopwatch>
+void check_dont_start_start()
+{
+ Stopwatch sw(boost::chrono::dont_start);
+ BOOST_TEST(!sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ sw.start();
+ BOOST_TEST(sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ typename Stopwatch::duration d=sw.elapsed();
+ BOOST_TEST(sw.is_running());
+ BOOST_TEST(d >= boost::chrono::milliseconds(100));
+ BOOST_TEST(d < boost::chrono::milliseconds(200));
+}
+
+template <typename Stopwatch>
+void check_dont_start_start_stop()
+{
+ Stopwatch sw(boost::chrono::dont_start);
+ BOOST_TEST(!sw.is_running());
+ sw.start();
+ BOOST_TEST(sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ sw.stop();
+ BOOST_TEST(!sw.is_running());
+ typename Stopwatch::duration d=sw.elapsed();
+ BOOST_TEST(!sw.is_running());
+ BOOST_TEST(d >= boost::chrono::milliseconds(0));
+}
+
+template <typename Stopwatch>
+void check_dont_start_scoped_run()
+{
+ Stopwatch sw(boost::chrono::dont_start);
+ BOOST_TEST(!sw.is_running());
+ {
+ typename Stopwatch::scoped_run _(sw);
+ BOOST_TEST(sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ }
+ BOOST_TEST(!sw.is_running());
+ typename Stopwatch::duration d=sw.elapsed();
+ BOOST_TEST(!sw.is_running());
+ BOOST_TEST(d >= boost::chrono::milliseconds(0));
+}
+
+template <typename Stopwatch>
+void check_stop()
+{
+ Stopwatch sw;
+ BOOST_TEST(sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ sw.stop();
+ BOOST_TEST(!sw.is_running());
+ typename Stopwatch::duration d=sw.elapsed();
+ BOOST_TEST(!sw.is_running());
+ BOOST_TEST(d == boost::chrono::milliseconds(0));
+}
+
+template <typename Stopwatch>
+void check_stop_stop()
+{
+ Stopwatch sw;
+ BOOST_TEST(sw.is_running());
+ ex::sleep_for<typename Stopwatch::clock>(boost::chrono::milliseconds(100));
+ sw.stop();
+ BOOST_TEST(!sw.is_running());
+ typename Stopwatch::duration d=sw.elapsed();
+ BOOST_TEST(!sw.is_running());
+ BOOST_TEST(d == boost::chrono::milliseconds(0));
+ sw.stop();
+ BOOST_TEST(!sw.is_running());
+ d=sw.elapsed();
+ BOOST_TEST(!sw.is_running());
+ BOOST_TEST(d == boost::chrono::milliseconds(0));
+}
+
+
+
+struct file_line {
+ file_line(const char* file, std::size_t line)
+ : fmt("%1%[%2%] Elapsed time:")
+ {
+ fmt % file % line;
+ }
+ ~file_line()
+ {
+ std::cout << fmt;
+ }
+ boost::format fmt;
+
+};
+
+template <typename Reporter>
+void check_file_line2()
+{
+ Reporter _("%1%\n");
+ file_line fl(__FILE__, __LINE__);
+ ex::sleep_for<typename Reporter::clock>(milliseconds(100));
+
+}
+template <typename Reporter>
+void check_file_line()
+{
+ Reporter rp("%1%[%2%] Elapsed time: %3%\n");
+ rp.format() % __FILE__ % __LINE__;
+
+ ex::sleep_for<typename Reporter::clock>(milliseconds(100));
+
+}
+
+template <typename Reporter>
+void check_report()
+{
+ Reporter sw;
+ ex::sleep_for<typename Reporter::clock>(milliseconds(100));
+ sw.report();
+}
+
+
+
+
+template <typename Clock>
+void check_all()
+{
+ typedef stopwatch_reporter<basic_stopwatch<Clock> > Reporter;
+ typedef stopwatch_reporter<basic_stopwatch<Clock>, elapsed_formatter > ReporterE;
+
+ check_invariants<Reporter>();
+ check_default_constructor<Reporter>();
+ check_constructor_ec<Reporter>();
+ check_constructor_throws<Reporter>();
+ check_elapsed<Reporter>();
+
+ check_report<Reporter>();
+ check_file_line<ReporterE>();
+
+ check_start_start<Reporter>();
+ check_dont_start_constructor<Reporter>();
+ check_dont_start_start<Reporter>();
+ check_dont_start_start_stop<Reporter>();
+ check_dont_start_scoped_run<Reporter>();
+ check_stop<Reporter>();
+ check_stop_stop<Reporter>();
+
+
+}
+
+int main()
+{
+ typedef basic_stopwatch<high_resolution_clock > Stopwatch;
+ typedef stopwatch_reporter_default_formatter<Stopwatch>::type Formatter;
+ typedef stopwatch_reporter<Stopwatch> Reporter;
+ static Formatter fmtr;
+
+ Reporter _(fmtr);
+
+ check_all<ex::cycle_count<1500> >();
+
+ 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