Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r81040 - in trunk: boost/chrono/io libs/chrono/test/io
From: vicente.botet_at_[hidden]
Date: 2012-10-21 13:23:25


Author: viboes
Date: 2012-10-21 13:23:23 EDT (Sun, 21 Oct 2012)
New Revision: 81040
URL: http://svn.boost.org/trac/boost/changeset/81040

Log:
Chrono: ref #7546
Text files modified:
   trunk/boost/chrono/io/time_point_io.hpp | 25 ++++++++---
   trunk/libs/chrono/test/io/time_point_input.cpp | 59 ++++++++++++++++++++++++++
   trunk/libs/chrono/test/io/time_point_output.cpp | 85 ++++++++++++++++++++++++++++++++++++++-
   3 files changed, 157 insertions(+), 12 deletions(-)

Modified: trunk/boost/chrono/io/time_point_io.hpp
==============================================================================
--- trunk/boost/chrono/io/time_point_io.hpp (original)
+++ trunk/boost/chrono/io/time_point_io.hpp 2012-10-21 13:23:23 EDT (Sun, 21 Oct 2012)
@@ -24,6 +24,9 @@
 #include <locale>
 #include <string.h>
 
+#define BOOST_CHRONO_INTERNAL_TIMEGM defined BOOST_WINDOWS && ! defined(__CYGWIN__)
+//#define BOOST_CHRONO_INTERNAL_TIMEGM
+
 namespace boost
 {
   namespace chrono
@@ -332,7 +335,7 @@
 
     namespace detail
     {
-#if defined BOOST_WINDOWS && ! defined(__CYGWIN__)
+#if defined BOOST_CHRONO_INTERNAL_TIMEGM
     int is_leap(int year)
     {
       if(year % 400 == 0)
@@ -412,7 +415,7 @@
 
           timezone tz = get_timezone(os);
           std::locale loc = os.getloc();
- time_t t = system_clock::to_time_t(tp);
+ time_t t = system_clock::to_time_t(time_point_cast<system_clock::duration>(tp));
           std::tm tm;
           if (tz == timezone::local)
           {
@@ -629,12 +632,14 @@
             minutes min = detail::extract_z(i, eof, err, ct);
             if (err & std::ios_base::failbit) goto exit;
             time_t t;
-#if defined BOOST_WINDOWS && ! defined(__CYGWIN__)
+#if defined BOOST_CHRONO_INTERNAL_TIMEGM
             t = detail::internal_timegm(&tm);
 #else
             t = timegm(&tm);
 #endif
- tp = system_clock::from_time_t(t) - min + round<microseconds> (duration<double> (sec));
+ tp = time_point_cast<Duration>(
+ system_clock::from_time_t(t) - min + round<microseconds> (duration<double> (sec))
+ );
           }
           else
           {
@@ -652,7 +657,7 @@
               }
               It i(is);
               It eof;
- minu = extract_z(i, eof, err, ct);
+ minu = detail::extract_z(i, eof, err, ct);
               if (err & std::ios_base::failbit) goto exit;
               if (fz + 2 != pe)
               {
@@ -668,14 +673,20 @@
             tm.tm_isdst = -1;
             time_t t;
             if (tz == timezone::utc || fz != pe)
-#if defined BOOST_WINDOWS && ! defined(__CYGWIN__)
+ {
+#if defined BOOST_CHRONO_INTERNAL_TIMEGM
               t = detail::internal_timegm(&tm);
 #else
               t = timegm(&tm);
 #endif
+ }
             else
+ {
               t = mktime(&tm);
- tp = system_clock::from_time_t(t) - minu;
+ }
+ tp = time_point_cast<Duration>(
+ system_clock::from_time_t(t) - minu
+ );
           }
         }
         BOOST_CATCH (...)

Modified: trunk/libs/chrono/test/io/time_point_input.cpp
==============================================================================
--- trunk/libs/chrono/test/io/time_point_input.cpp (original)
+++ trunk/libs/chrono/test/io/time_point_input.cpp 2012-10-21 13:23:23 EDT (Sun, 21 Oct 2012)
@@ -20,6 +20,20 @@
   BOOST_TEST( (tp == boost::chrono::time_point<Clock, D>(res)));
 }
 
+template <typename D>
+void test_good_system_clock(std::string str, D res)
+{
+ typedef boost::chrono::system_clock Clock;
+
+ std::istringstream in(str + boost::chrono::clock_string<Clock, char>::since());
+ boost::chrono::time_point<Clock, D> tp;
+ in >> tp;
+ BOOST_TEST(in.eof());
+ BOOST_TEST(!in.fail());
+ std::cout << "Expected= " << boost::chrono::time_point<Clock, D>(res) << std::endl;
+ std::cout << "Obtained= " << tp << std::endl;
+ BOOST_TEST( (tp == boost::chrono::time_point<Clock, D>(res)));
+}
 template <typename Clock, typename D>
 void test_fail(const char* str, D)
 {
@@ -91,6 +105,47 @@
 
 }
 
+void check_all_system_clock()
+{
+ using namespace boost::chrono;
+ using namespace boost;
+
+ //test_good_system_clock ("1970-01-01 02:00:00.000000 +0000", hours(2));
+ //test_good_system_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 second", seconds(1));
+// test_good<Clock> ("-1 seconds", seconds(-1));
+// test_good<Clock> ("0 second", seconds(0));
+// test_good<Clock> ("0 seconds", seconds(0));
+// 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));
+//#if BOOST_CHRONO_VERSION==2
+// test_good<Clock>("5000 min", minutes(5000));
+//#else
+// test_good<Clock> ("5000 m", minutes(5000));
+//#endif
+// 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=" << std::endl;
@@ -99,8 +154,8 @@
   std::cout << "steady_clock=" << std::endl;
   check_all<boost::chrono::steady_clock> ();
 #endif
- //std::cout << "system_clock=";
- //check_all<boost::chrono::system_clock>();
+ std::cout << "system_clock=";
+ check_all_system_clock();
 
 #if defined(BOOST_CHRONO_HAS_THREAD_CLOCK)
   std::cout << "thread_clock="<< std::endl;

Modified: trunk/libs/chrono/test/io/time_point_output.cpp
==============================================================================
--- trunk/libs/chrono/test/io/time_point_output.cpp (original)
+++ trunk/libs/chrono/test/io/time_point_output.cpp 2012-10-21 13:23:23 EDT (Sun, 21 Oct 2012)
@@ -16,9 +16,26 @@
   boost::chrono::time_point<Clock, D> tp(d);
   out << tp;
   BOOST_TEST(out.good());
+ //std::cout << "Expected= " << std::string(str) + boost::chrono::clock_string<Clock, char>::since() << std::endl;
+ //std::cout << "Obtained= " << out.str() << std::endl;
   BOOST_TEST( (out.str() == std::string(str) + boost::chrono::clock_string<Clock, char>::since()));
 }
 
+template <typename D>
+void test_good_prefix_system_clock(const char* str, D d)
+{
+ typedef boost::chrono::system_clock Clock;
+
+ std::ostringstream out;
+ boost::chrono::time_point<Clock, D> tp(d);
+ out << tp;
+ BOOST_TEST(out.good());
+
+ std::cout << "Expected= " << str << std::endl;
+ std::cout << "Obtained= " << out.str() << std::endl;
+ BOOST_TEST( (out.str() == std::string(str) ));
+}
+
 template <typename Clock, typename D>
 void test_good_symbol(const char* str, D d)
 {
@@ -33,7 +50,21 @@
   BOOST_TEST( (out.str() == std::string(str) + boost::chrono::clock_string<Clock, char>::since()));
 }
 
-#if BOOST_CHRONO_VERSION==2
+#if BOOST_CHRONO_VERSION>=2
+template <typename D>
+void test_good_symbol_system_clock(const char* str, D d)
+{
+ typedef boost::chrono::system_clock Clock;
+
+ std::ostringstream out;
+ boost::chrono::time_point<Clock, D> tp(d);
+ out << boost::chrono::duration_fmt(boost::chrono::duration_style::symbol) << tp;
+ BOOST_TEST(out.good());
+ std::cout << "Expected= " << str << std::endl;
+ std::cout << "Obtained= " << out.str() << std::endl;
+ BOOST_TEST( (out.str() == std::string(str) ));
+}
+
 template<typename Clock, typename D>
 void test_good(const char* str, D d, boost::chrono::duration_style style)
 {
@@ -43,6 +74,20 @@
   BOOST_TEST(out.good());
   BOOST_TEST((out.str() == std::string(str)+boost::chrono::clock_string<Clock,char>::since()));
 }
+
+template<typename D>
+void test_good_system_clock(const char* str, D d, boost::chrono::duration_style style)
+{
+ typedef boost::chrono::system_clock Clock;
+
+ std::ostringstream out;
+ boost::chrono::time_point<Clock,D> tp(d);
+ out << boost::chrono::duration_fmt(style) << tp;
+ BOOST_TEST(out.good());
+ std::cout << "Expected= " << str << std::endl;
+ std::cout << "Obtained= " << out.str() << std::endl;
+ BOOST_TEST((out.str() == std::string(str) ));
+}
 #endif
 
 template <typename Clock>
@@ -81,6 +126,36 @@
   test_good_symbol<Clock> ("2 [1/30]s", duration<boost::int_least64_t, ratio<1, 30> > (2));
 }
 
+#if BOOST_CHRONO_VERSION==2
+void check_all_system_clock()
+{
+ using namespace boost::chrono;
+ using namespace boost;
+
+ test_good_system_clock("1970-01-01 02:00:00.000000 +0000", hours(2), duration_style::prefix);
+ test_good_system_clock("1970-01-01 02:00:00.000000 +0000", hours(2), duration_style::symbol);
+
+ test_good_prefix_system_clock("1970-01-01 02:00:00.000000 +0000", hours(2));
+ test_good_prefix_system_clock("1970-01-01 00:02:00.000000 +0000", minutes(2));
+ test_good_prefix_system_clock("1970-01-01 00:00:02.000000 +0000", seconds(2));
+ test_good_prefix_system_clock("1970-01-01 00:00:01.000000 +0000", seconds(1));
+ test_good_prefix_system_clock("1969-12-31 23:59:59.000000 +0000", seconds(-1));
+ test_good_prefix_system_clock("1970-01-01 00:00:00.000000 +0000", seconds(0));
+ test_good_prefix_system_clock("1970-01-01 00:00:00.002000 +0000", milliseconds(2));
+ test_good_prefix_system_clock("1970-01-01 00:00:00.000002 +0000", microseconds(2));
+ test_good_prefix_system_clock("1970-01-01 00:00:00.000000 +0000", nanoseconds(2));
+ test_good_prefix_system_clock("1970-01-01 00:00:00.200000 +0000", duration<boost::int_least64_t, deci> (2));
+ test_good_prefix_system_clock("1970-01-01 00:00:00.066667 +0000", duration<boost::int_least64_t, ratio<1, 30> > (2));
+
+ test_good_symbol_system_clock("1970-01-01 02:00:00.000000 +0000", hours(2));
+ test_good_symbol_system_clock("1970-01-01 00:02:00.000000 +0000", minutes(2));
+ test_good_symbol_system_clock("1970-01-01 00:00:02.000000 +0000", seconds(2));
+ test_good_symbol_system_clock("1970-01-01 00:00:00.002000 +0000", milliseconds(2));
+ test_good_symbol_system_clock("1970-01-01 00:00:00.000000 +0000", nanoseconds(2));
+ test_good_symbol_system_clock("1970-01-01 00:00:00.200000 +0000", duration<boost::int_least64_t, deci> (2));
+ test_good_symbol_system_clock("1970-01-01 00:00:00.066667 +0000", duration<boost::int_least64_t, ratio<1, 30> > (2));
+}
+#endif
 int main()
 {
 
@@ -90,8 +165,12 @@
   std::cout << "steady_clock=" << std::endl;
   check_all<boost::chrono::steady_clock> ();
 #endif
- //std::cout << "system_clock=";
- //check_all<boost::chrono::system_clock>();
+ std::cout << "system_clock=" << std::endl;
+#if BOOST_CHRONO_VERSION==2
+ check_all_system_clock();
+#else
+ check_all<boost::chrono::system_clock> ();
+#endif
 
 #if defined(BOOST_CHRONO_HAS_THREAD_CLOCK)
   std::cout << "thread_clock="<< std::endl;


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