|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r74807 - in branches/release/libs/chrono/test: . io
From: vicente.botet_at_[hidden]
Date: 2011-10-08 11:02:47
Author: viboes
Date: 2011-10-08 11:02:46 EDT (Sat, 08 Oct 2011)
New Revision: 74807
URL: http://svn.boost.org/trac/boost/changeset/74807
Log:
Chrono: Add some io tests
Added:
branches/release/libs/chrono/test/io/
branches/release/libs/chrono/test/io/duration_input.cpp (contents, props changed)
branches/release/libs/chrono/test/io/duration_output.cpp (contents, props changed)
branches/release/libs/chrono/test/io/time_point_input.cpp (contents, props changed)
branches/release/libs/chrono/test/io/time_point_output.cpp (contents, props changed)
Text files modified:
branches/release/libs/chrono/test/Jamfile.v2 | 14 +++++++-------
1 files changed, 7 insertions(+), 7 deletions(-)
Modified: branches/release/libs/chrono/test/Jamfile.v2
==============================================================================
--- branches/release/libs/chrono/test/Jamfile.v2 (original)
+++ branches/release/libs/chrono/test/Jamfile.v2 2011-10-08 11:02:46 EDT (Sat, 08 Oct 2011)
@@ -333,13 +333,13 @@
[ chrono-run ../example/french.cpp ]
;
- #test-suite "io"
- # :
- # [ chrono-run-header io/duration_input.cpp ]
- # [ chrono-run-header io/duration_output.cpp ]
- # [ chrono-run-header io/time_point_input.cpp ]
- # [ chrono-run-header io/time_point_output.cpp ]
- # ;
+ test-suite "io"
+ :
+ [ chrono-run-header io/duration_input.cpp ]
+ [ chrono-run-header io/duration_output.cpp ]
+ [ chrono-run-header io/time_point_input.cpp ]
+ [ chrono-run-header io/time_point_output.cpp ]
+ ;
test-suite "win32"
:
Added: branches/release/libs/chrono/test/io/duration_input.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/chrono/test/io/duration_input.cpp 2011-10-08 11:02:46 EDT (Sat, 08 Oct 2011)
@@ -0,0 +1,71 @@
+// Copyright 2011 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/chrono_io.hpp>
+#include <sstream>
+#include <boost/detail/lightweight_test.hpp>
+
+template<typename D>
+void test_good(const char* str, D res)
+{
+ std::cout << str << std::endl;
+ std::istringstream in(str);
+ D d(0);
+ in >> d;
+ BOOST_TEST(in.good());
+ BOOST_TEST(d == res);
+}
+
+template<typename DFail, typename DGood>
+void test_fail(const char* str, DFail r, DGood res)
+{
+ {
+ std::istringstream in(str);
+ DFail d = DFail::zero();
+ in >> d;
+ BOOST_TEST(in.fail());
+ BOOST_TEST(d == DFail::zero());
+ }
+ {
+ std::istringstream in(str);
+ DGood d = DGood::zero();
+ in >> d;
+ BOOST_TEST(in.good());
+ BOOST_TEST(d == res);
+ }
+}
+
+int main()
+{
+ using namespace boost::chrono;
+ using namespace boost;
+
+ test_good("5000 hours", hours(5000));
+ test_good("5000 minutes", minutes(5000));
+ test_good("5000 seconds", seconds(5000));
+ test_good("1 seconds", seconds(1));
+ //test_good("-1 second", seconds(-1));
+ test_good("5000 milliseconds", milliseconds(5000));
+ test_good("5000 microseconds", microseconds(5000));
+ test_good("5000 nanoseconds", nanoseconds(5000));
+ test_good("5000 deciseconds", duration<boost::int_least64_t, deci> (5000));
+ test_good("5000 [1/30]seconds", duration<boost::int_least64_t, ratio<1, 30> > (5000));
+
+ test_good("1 s", seconds(1));
+ //test_good("-1 s", seconds(-1));
+ test_good("5000 h", hours(5000));
+ test_good("5000 m", minutes(5000));
+ test_good("5000 s", seconds(5000));
+ test_good("5000 ms", milliseconds(5000));
+ test_good("5000 ns", nanoseconds(5000));
+ test_good("5000 ds", duration<boost::int_least64_t, deci> (5000));
+ test_good("5000 [1/30]s", duration<boost::int_least64_t, ratio<1, 30> > (5000));
+
+ test_good("5000 milliseconds", seconds(5));
+ test_good("5 milliseconds", nanoseconds(5000000));
+ test_good("4000 ms", seconds(4));
+ test_fail("3001 ms", seconds(3), milliseconds(3001));
+
+}
+
Added: branches/release/libs/chrono/test/io/duration_output.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/chrono/test/io/duration_output.cpp 2011-10-08 11:02:46 EDT (Sat, 08 Oct 2011)
@@ -0,0 +1,54 @@
+// Copyright 2011 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/chrono_io.hpp>
+#include <sstream>
+#include <boost/detail/lightweight_test.hpp>
+
+template<typename D>
+void test_good_prefix(const char* str, D d)
+{
+ std::ostringstream out;
+ out << d;
+ BOOST_TEST(out.good());
+ BOOST_TEST(out.str() == str);
+}
+
+template<typename D>
+void test_good_symbol(const char* str, D d)
+{
+ std::ostringstream out;
+ out << boost::chrono::duration_short << d;
+ BOOST_TEST(out.good());
+ BOOST_TEST(out.str() == str);
+}
+
+
+int main()
+{
+ using namespace boost::chrono;
+ using namespace boost;
+
+ test_good_prefix("5000 hours", hours(5000));
+ test_good_prefix("5000 minutes", minutes(5000));
+ test_good_prefix("5000 seconds", seconds(5000));
+ test_good_prefix("1 seconds", seconds(1));
+ test_good_prefix("-1 seconds", seconds(-1));
+ test_good_prefix("5000 milliseconds", milliseconds(5000));
+ test_good_prefix("5000 microseconds", microseconds(5000));
+ test_good_prefix("5000 nanoseconds", nanoseconds(5000));
+ test_good_prefix("5000 deciseconds", duration<boost::int_least64_t, deci> (5000));
+ test_good_prefix("5000 [1/30]seconds", duration<boost::int_least64_t, ratio<1, 30> > (5000));
+
+ test_good_symbol("5000 h", hours(5000));
+ test_good_symbol("5000 m", minutes(5000));
+ test_good_symbol("5000 s", seconds(5000));
+ test_good_symbol("5000 ms", milliseconds(5000));
+ test_good_symbol("5000 ns", nanoseconds(5000));
+ test_good_symbol("5000 ds", duration<boost::int_least64_t, deci> (5000));
+ test_good_symbol("5000 [1/30]s", duration<boost::int_least64_t, ratio<1, 30> > (5000));
+
+
+}
+
Added: branches/release/libs/chrono/test/io/time_point_input.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/chrono/test/io/time_point_input.cpp 2011-10-08 11:02:46 EDT (Sat, 08 Oct 2011)
@@ -0,0 +1,113 @@
+// Copyright 2011 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/chrono_io.hpp>
+#include <sstream>
+#include <boost/detail/lightweight_test.hpp>
+#include <boost/chrono/system_clocks.hpp>
+#include <boost/chrono/thread_clock.hpp>
+#include <boost/chrono/process_cpu_clocks.hpp>
+
+template<typename Clock, typename D>
+void test_good(std::string str, D res)
+{
+ std::istringstream in(str+boost::chrono::clock_string<Clock,char>::since());
+ boost::chrono::time_point<Clock,D> tp;
+ in >> tp;
+ BOOST_TEST(in.good());
+ BOOST_TEST((tp == boost::chrono::time_point<Clock,D>(res)));
+}
+
+template<typename Clock, typename D>
+void test_fail(const char* str, D r)
+{
+ std::istringstream in(str+boost::chrono::clock_string<Clock,char>::since());
+ boost::chrono::time_point<Clock,D> tp;
+ in >> tp;
+ BOOST_TEST(in.fail());
+ BOOST_TEST((tp == boost::chrono::time_point<Clock,D>()));
+}
+
+template<typename Clock, typename D>
+void test_fail_no_epoch(const char* str, D r)
+{
+ std::istringstream in(str);
+ boost::chrono::time_point<Clock,D> tp;
+ in >> tp;
+ BOOST_TEST(in.fail());
+ BOOST_TEST((tp == boost::chrono::time_point<Clock,D>()));
+}
+
+template<typename Clock, typename D>
+void test_fail_epoch(const char* str, D r)
+{
+ std::istringstream in(str);
+ boost::chrono::time_point<Clock,D> tp;
+ in >> tp;
+ BOOST_TEST(in.fail());
+ BOOST_TEST((tp == boost::chrono::time_point<Clock,D>()));
+}
+
+template<typename Clock>
+void check_all()
+{
+ using namespace boost::chrono;
+ using namespace boost;
+
+ test_good<Clock>("5000 hours", hours(5000));
+ test_good<Clock>("5000 minutes", minutes(5000));
+ test_good<Clock>("5000 seconds", seconds(5000));
+ test_good<Clock>("1 seconds", seconds(1));
+ //test_good<Clock>("-1 seconds", seconds(-1));
+ test_good<Clock>("5000 milliseconds", milliseconds(5000));
+ test_good<Clock>("5000 microseconds", microseconds(5000));
+ test_good<Clock>("5000 nanoseconds", nanoseconds(5000));
+ test_good<Clock>("5000 deciseconds", duration<boost::int_least64_t, deci> (5000));
+ test_good<Clock>("5000 [1/30]seconds", duration<boost::int_least64_t, ratio<1, 30> > (5000));
+
+ test_good<Clock>("5000 h", hours(5000));
+ test_good<Clock>("5000 m", minutes(5000));
+ test_good<Clock>("5000 s", seconds(5000));
+ test_good<Clock>("5000 ms", milliseconds(5000));
+ test_good<Clock>("5000 ns", nanoseconds(5000));
+ test_good<Clock>("5000 ds", duration<boost::int_least64_t, deci> (5000));
+ test_good<Clock>("5000 [1/30]s", duration<boost::int_least64_t, ratio<1, 30> > (5000));
+
+ test_good<Clock>("5000 milliseconds", seconds(5));
+ test_good<Clock>("5 milliseconds", nanoseconds(5000000));
+ test_good<Clock>("4000 ms", seconds(4));
+ test_fail<Clock>("3001 ms", seconds(3));
+ test_fail_epoch<Clock>("3001 ms", seconds(3));
+ test_fail_epoch<Clock>("3001 ms since", seconds(3));
+
+}
+
+int main()
+{
+ std::cout << "high_resolution_clock=";
+ check_all<boost::chrono::high_resolution_clock>();
+#ifdef BOOST_CHRONO_HAS_CLOCK_STEADY
+ std::cout << "steady_clock=";
+ check_all<boost::chrono::steady_clock>();
+#endif
+ //std::cout << "system_clock=";
+ //check_all<boost::chrono::system_clock>();
+
+#if defined(BOOST_CHRONO_HAS_THREAD_CLOCK)
+ std::cout << "thread_clock=";
+ check_all<boost::chrono::thread_clock>();
+#endif
+
+#if defined(BOOST_CHRONO_HAS_PROCESS_CLOCKS)
+ std::cout << "process_real_cpu_clock=";
+ check_all<boost::chrono::process_real_cpu_clock>();
+ std::cout << "process_user_cpu_clock=";
+ check_all<boost::chrono::process_user_cpu_clock>();
+ std::cout << "process_system_cpu_clock=";
+ check_all<boost::chrono::process_system_cpu_clock>();
+ std::cout << "process_cpu_clock=";
+ check_all<boost::chrono::process_cpu_clock>();
+#endif
+}
+
Added: branches/release/libs/chrono/test/io/time_point_output.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/chrono/test/io/time_point_output.cpp 2011-10-08 11:02:46 EDT (Sat, 08 Oct 2011)
@@ -0,0 +1,86 @@
+// Copyright 2011 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/chrono_io.hpp>
+#include <sstream>
+#include <boost/detail/lightweight_test.hpp>
+#include <boost/chrono/system_clocks.hpp>
+#include <boost/chrono/thread_clock.hpp>
+#include <boost/chrono/process_cpu_clocks.hpp>
+
+template<typename Clock, typename D>
+void test_good_prefix(const char* str, D d)
+{
+ std::ostringstream out;
+ boost::chrono::time_point<Clock,D> tp(d);
+ out << tp;
+ BOOST_TEST(out.good());
+ BOOST_TEST((out.str() == std::string(str)+boost::chrono::clock_string<Clock,char>::since()));
+}
+
+template<typename Clock, typename D>
+void test_good_symbol(const char* str, D d)
+{
+ std::ostringstream out;
+ boost::chrono::time_point<Clock,D> tp(d);
+ out << boost::chrono::duration_short << tp;
+ BOOST_TEST(out.good());
+ BOOST_TEST((out.str() == std::string(str)+boost::chrono::clock_string<Clock,char>::since()));
+}
+
+template<typename Clock>
+void check_all()
+{
+ using namespace boost::chrono;
+ using namespace boost;
+
+ test_good_prefix<Clock>("2 hours", hours(2));
+ test_good_prefix<Clock>("2 minutes", minutes(2));
+ test_good_prefix<Clock>("2 seconds", seconds(2));
+ test_good_prefix<Clock>("1 seconds", seconds(1));
+ //test_good_prefix<Clock>("-1 seconds", seconds(-1));
+ test_good_prefix<Clock>("2 milliseconds", milliseconds(2));
+ test_good_prefix<Clock>("2 microseconds", microseconds(2));
+ test_good_prefix<Clock>("2 nanoseconds", nanoseconds(2));
+ test_good_prefix<Clock>("2 deciseconds", duration<boost::int_least64_t, deci> (2));
+ test_good_prefix<Clock>("2 [1/30]seconds", duration<boost::int_least64_t, ratio<1, 30> > (2));
+
+ test_good_symbol<Clock>("2 h", hours(2));
+ test_good_symbol<Clock>("2 m", minutes(2));
+ test_good_symbol<Clock>("2 s", seconds(2));
+ test_good_symbol<Clock>("2 ms", milliseconds(2));
+ test_good_symbol<Clock>("2 ns", nanoseconds(2));
+ test_good_symbol<Clock>("2 ds", duration<boost::int_least64_t, deci> (2));
+ test_good_symbol<Clock>("2 [1/30]s", duration<boost::int_least64_t, ratio<1, 30> > (2));
+}
+
+int main()
+{
+
+ std::cout << "high_resolution_clock=";
+ check_all<boost::chrono::high_resolution_clock>();
+#ifdef BOOST_CHRONO_HAS_CLOCK_STEADY
+ std::cout << "steady_clock=";
+ check_all<boost::chrono::steady_clock>();
+#endif
+ //std::cout << "system_clock=";
+ //check_all<boost::chrono::system_clock>();
+
+#if defined(BOOST_CHRONO_HAS_THREAD_CLOCK)
+ std::cout << "thread_clock=";
+ check_all<boost::chrono::thread_clock>();
+#endif
+
+#if defined(BOOST_CHRONO_HAS_PROCESS_CLOCKS)
+ std::cout << "process_real_cpu_clock=";
+ check_all<boost::chrono::process_real_cpu_clock>();
+ std::cout << "process_user_cpu_clock=";
+ check_all<boost::chrono::process_user_cpu_clock>();
+ std::cout << "process_system_cpu_clock=";
+ check_all<boost::chrono::process_system_cpu_clock>();
+ std::cout << "process_cpu_clock=";
+ check_all<boost::chrono::process_cpu_clock>();
+#endif
+}
+
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