|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r86491 - branches/release/libs/chrono/test/io
From: vicente.botet_at_[hidden]
Date: 2013-10-27 19:29:52
Author: viboes
Date: 2013-10-27 19:29:52 EDT (Sun, 27 Oct 2013)
New Revision: 86491
URL: http://svn.boost.org/trac/boost/changeset/86491
Log:
Chrono: merge timepoint io improvements.
Text files modified:
branches/release/libs/chrono/test/io/time_point_output.cpp | 120 +++++++++++++++++++++++++++-------------
1 files changed, 81 insertions(+), 39 deletions(-)
Modified: branches/release/libs/chrono/test/io/time_point_output.cpp
==============================================================================
--- branches/release/libs/chrono/test/io/time_point_output.cpp Sun Oct 27 17:19:13 2013 (r86490)
+++ branches/release/libs/chrono/test/io/time_point_output.cpp 2013-10-27 19:29:52 EDT (Sun, 27 Oct 2013) (r86491)
@@ -10,6 +10,7 @@
#include <boost/chrono/process_cpu_clocks.hpp>
#include <locale>
#include <ctime>
+#include <cstdio>
template <typename Clock, typename D>
void test_good_prefix(const char* str, D d)
@@ -148,67 +149,101 @@
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_system_clock("1970-01-01 02:00:00.000000000 +0000", hours(2), duration_style::prefix);
+ test_good_system_clock("1970-01-01 02:00:00.000000000 +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));
+ test_good_prefix_system_clock("1970-01-01 02:00:00.000000000 +0000", hours(2));
+ test_good_prefix_system_clock("1970-01-01 00:02:00.000000000 +0000", minutes(2));
+ test_good_prefix_system_clock("1970-01-01 00:00:02.000000000 +0000", seconds(2));
+ test_good_prefix_system_clock("1970-01-01 00:00:01.000000000 +0000", seconds(1));
+ test_good_prefix_system_clock("1969-12-31 23:59:59.000000000 +0000", seconds(-1));
+ test_good_prefix_system_clock("1970-01-01 00:00:00.000000000 +0000", seconds(0));
+ test_good_prefix_system_clock("1970-01-01 00:00:00.002000000 +0000", milliseconds(2));
+ test_good_prefix_system_clock("1970-01-01 00:00:00.000002000 +0000", microseconds(2));
+ test_good_prefix_system_clock("1970-01-01 00:00:00.000000002 +0000", nanoseconds(2));
+ test_good_prefix_system_clock("1970-01-01 00:00:00.200000000 +0000", duration<boost::int_least64_t, deci> (2));
+ test_good_prefix_system_clock("1970-01-01 00:00:00.066666667 +0000", duration<boost::int_least64_t, ratio<1, 30> > (2));
+
+ test_good_symbol_system_clock("1970-01-01 02:00:00.000000000 +0000", hours(2));
+ test_good_symbol_system_clock("1970-01-01 00:02:00.000000000 +0000", minutes(2));
+ test_good_symbol_system_clock("1970-01-01 00:00:02.000000000 +0000", seconds(2));
+ test_good_symbol_system_clock("1970-01-01 00:00:00.002000000 +0000", milliseconds(2));
+ test_good_symbol_system_clock("1970-01-01 00:00:00.000000002 +0000", nanoseconds(2));
+ test_good_symbol_system_clock("1970-01-01 00:00:00.200000000 +0000", duration<boost::int_least64_t, deci> (2));
+ test_good_symbol_system_clock("1970-01-01 00:00:00.066666667 +0000", duration<boost::int_least64_t, ratio<1, 30> > (2));
test_good_utc_fmt_system_clock("1970-01-01 02:00:00", "%Y-%m-%d %H:%M:%S", hours(2));
test_good_utc_fmt_system_clock("1970-01-01 02", "%Y-%m-%d %H", hours(2));
-
+#if ! defined(BOOST_CHRONO_WINDOWS_API)
test_good_utc_fmt_system_clock ("1970-01-01 02:00:00", "%Y-%m-%d %T", hours(2));
test_good_utc_fmt_system_clock ("1970-01-01 02:00", "%Y-%m-%d %R", hours(2));
test_good_utc_fmt_system_clock ("% 1970-01-01 02:00", "%% %Y-%m-%d %R", hours(2));
test_good_utc_fmt_system_clock ("1970-01-01 02:00 Thursday January", "%Y-%m-%d %R %A %B", hours(2));
-
+#endif
}
+
+#endif
+#if BOOST_CHRONO_INTERNAL_GMTIME
+#elif BOOST_CHRONO_VERSION == 2
void test_gmtime(std::time_t t)
{
std::cout << "t " << t << std::endl;
+ puts(ctime(&t));
std::tm tm;
+ std::memset(&tm, 0, sizeof(std::tm));
if (boost::chrono::detail::internal_gmtime(&t, &tm))
{
- std::cout << "year " << tm.tm_year << std::endl;
- std::cout << "month " << tm.tm_mon << std::endl;
- std::cout << "day " << tm.tm_mday << std::endl;
- std::cout << "hour " << tm.tm_hour << std::endl;
- std::cout << "min " << tm.tm_min << std::endl;
- std::cout << "sec " << tm.tm_sec << std::endl;
+ tm.tm_isdst = -1;
+ (void)mktime(&tm);
+ std::tm tm2;
+ std::memset(&tm2, 0, sizeof(std::tm));
+ if (gmtime_r(&t, &tm2))
+ {
+ tm2.tm_isdst = -1;
+ (void)mktime(&tm2);
+
+ BOOST_TEST_EQ( tm.tm_year , tm2.tm_year );
+ BOOST_TEST_EQ( tm.tm_mon , tm2.tm_mon );
+ BOOST_TEST_EQ( tm.tm_mday , tm2.tm_mday );
+ BOOST_TEST_EQ( tm.tm_hour , tm2.tm_hour);
+ BOOST_TEST_EQ( tm.tm_min , tm2.tm_min );
+ BOOST_TEST_EQ( tm.tm_sec , tm2.tm_sec );
+ BOOST_TEST_EQ( tm.tm_wday , tm2.tm_wday );
+ BOOST_TEST_EQ( tm.tm_yday , tm2.tm_yday );
+ BOOST_TEST_EQ( tm.tm_isdst , tm2.tm_isdst );
+ }
}
+
}
#endif
+
int main()
{
-// test_gmtime( 0 );
-// test_gmtime( -1 );
-// test_gmtime( +1 );
-// test_gmtime( 0 - (3600 * 24) );
-// test_gmtime( -1 - (3600 * 24) );
-// test_gmtime( +1 - (3600 * 24) );
-// test_gmtime( 0 + (3600 * 24) );
-// test_gmtime( -1 + (3600 * 24) );
-// test_gmtime( +1 + (3600 * 24) );
-
+#if BOOST_CHRONO_INTERNAL_GMTIME
+#elif BOOST_CHRONO_VERSION == 2
+ test_gmtime( 0 );
+ test_gmtime( -1 );
+ test_gmtime( +1 );
+ test_gmtime( 0 - (3600 * 24) );
+ test_gmtime( -1 - (3600 * 24) );
+ test_gmtime( +1 - (3600 * 24) );
+ test_gmtime( 0 + (3600 * 24) );
+ test_gmtime( -1 + (3600 * 24) );
+ test_gmtime( +1 + (3600 * 24) );
+ test_gmtime( 0 + 365*(3600 * 24) );
+ test_gmtime( 0 + 10LL*365*(3600 * 24) );
+ test_gmtime( 0 + 15LL*365*(3600 * 24) );
+ test_gmtime( 0 + 17LL*365*(3600 * 24) );
+ test_gmtime( 0 + 18LL*365*(3600 * 24) );
+ test_gmtime( 0 + 19LL*365*(3600 * 24) );
+ test_gmtime( 0 + 19LL*365*(3600 * 24)+ (3600 * 24));
+ test_gmtime( 0 + 19LL*365*(3600 * 24)+ 3*(3600 * 24));
+ test_gmtime( 0 + 19LL*365*(3600 * 24)+ 4*(3600 * 24));
+ test_gmtime( 0 + 20LL*365*(3600 * 24) );
+ test_gmtime( 0 + 40LL*365*(3600 * 24) );
+#endif
std::cout << "high_resolution_clock=" << std::endl;
check_all<boost::chrono::high_resolution_clock> ();
@@ -239,6 +274,13 @@
check_all<boost::chrono::process_cpu_clock> ();
#endif
+#if BOOST_CHRONO_VERSION == 2
+ boost::chrono::system_clock::time_point tp = boost::chrono::system_clock::now();
+ std::cout << tp << std::endl;
+ time_t t = boost::chrono::system_clock::to_time_t(tp);
+ test_gmtime( t );
+#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