Ticket #7546: 7546.patch

File 7546.patch, 10.7 KB (added by viboes, 10 years ago)

This patch fixes the compile issue and refactor the tests.

  • boost/chrono/io/time_point_io.hpp

     
    2424#include <locale>
    2525#include <string.h>
    2626
     27#define  BOOST_CHRONO_INTERNAL_TIMEGM defined BOOST_WINDOWS && ! defined(__CYGWIN__)
     28//#define  BOOST_CHRONO_INTERNAL_TIMEGM
     29
    2730namespace boost
    2831{
    2932  namespace chrono
     
    332335
    333336    namespace detail
    334337    {
    335 #if defined BOOST_WINDOWS && ! defined(__CYGWIN__)
     338#if defined BOOST_CHRONO_INTERNAL_TIMEGM
    336339    int is_leap(int year)
    337340    {
    338341      if(year % 400 == 0)
     
    412415
    413416          timezone tz = get_timezone(os);
    414417          std::locale loc = os.getloc();
    415           time_t t = system_clock::to_time_t(tp);
     418          time_t t = system_clock::to_time_t(time_point_cast<system_clock::duration>(tp));
    416419          std::tm tm;
    417420          if (tz == timezone::local)
    418421          {
     
    629632            minutes min = detail::extract_z(i, eof, err, ct);
    630633            if (err & std::ios_base::failbit) goto exit;
    631634            time_t t;
    632 #if defined BOOST_WINDOWS && ! defined(__CYGWIN__)
     635#if defined BOOST_CHRONO_INTERNAL_TIMEGM
    633636            t = detail::internal_timegm(&tm);
    634637#else
    635638            t = timegm(&tm);
    636639#endif
    637             tp = system_clock::from_time_t(t) - min + round<microseconds> (duration<double> (sec));
     640            tp = time_point_cast<Duration>(
     641                system_clock::from_time_t(t) - min + round<microseconds> (duration<double> (sec))
     642                );
    638643          }
    639644          else
    640645          {
     
    652657              }
    653658              It i(is);
    654659              It eof;
    655               minu = extract_z(i, eof, err, ct);
     660              minu = detail::extract_z(i, eof, err, ct);
    656661              if (err & std::ios_base::failbit) goto exit;
    657662              if (fz + 2 != pe)
    658663              {
     
    668673            tm.tm_isdst = -1;
    669674            time_t t;
    670675            if (tz == timezone::utc || fz != pe)
    671 #if defined BOOST_WINDOWS && ! defined(__CYGWIN__)
     676            {
     677#if defined BOOST_CHRONO_INTERNAL_TIMEGM
    672678              t = detail::internal_timegm(&tm);
    673679#else
    674680              t = timegm(&tm);
    675681#endif
     682            }
    676683            else
     684            {
    677685              t = mktime(&tm);
    678             tp = system_clock::from_time_t(t) - minu;
     686            }
     687            tp = time_point_cast<Duration>(
     688                system_clock::from_time_t(t) - minu
     689                );
    679690          }
    680691        }
    681692        BOOST_CATCH (...)
  • libs/chrono/test/io/time_point_input.cpp

     
    2020  BOOST_TEST( (tp == boost::chrono::time_point<Clock, D>(res)));
    2121}
    2222
     23template <typename D>
     24void test_good_system_clock(std::string str, D res)
     25{
     26  typedef boost::chrono::system_clock Clock;
     27
     28  std::istringstream in(str + boost::chrono::clock_string<Clock, char>::since());
     29  boost::chrono::time_point<Clock, D> tp;
     30  in >> tp;
     31  BOOST_TEST(in.eof());
     32  BOOST_TEST(!in.fail());
     33  std::cout << "Expected= " << boost::chrono::time_point<Clock, D>(res) << std::endl;
     34  std::cout << "Obtained= " << tp << std::endl;
     35  BOOST_TEST( (tp == boost::chrono::time_point<Clock, D>(res)));
     36}
    2337template <typename Clock, typename D>
    2438void test_fail(const char* str, D)
    2539{
     
    91105
    92106}
    93107
     108void check_all_system_clock()
     109{
     110  using namespace boost::chrono;
     111  using namespace boost;
     112
     113  //test_good_system_clock ("1970-01-01 02:00:00.000000 +0000", hours(2));
     114  //test_good_system_clock ("5000 hours", hours(5000));
     115//  test_good<Clock> ("5000 minutes", minutes(5000));
     116//  test_good<Clock> ("5000 seconds", seconds(5000));
     117//  test_good<Clock> ("1 seconds", seconds(1));
     118//  test_good<Clock> ("1 second", seconds(1));
     119//  test_good<Clock> ("-1 seconds", seconds(-1));
     120//  test_good<Clock> ("0 second", seconds(0));
     121//  test_good<Clock> ("0 seconds", seconds(0));
     122//  test_good<Clock> ("5000 milliseconds", milliseconds(5000));
     123//  test_good<Clock> ("5000 microseconds", microseconds(5000));
     124//  test_good<Clock> ("5000 nanoseconds", nanoseconds(5000));
     125//  test_good<Clock> ("5000 deciseconds", duration<boost::int_least64_t, deci> (5000));
     126//  test_good<Clock> ("5000 [1/30]seconds", duration<boost::int_least64_t, ratio<1, 30> > (5000));
     127//
     128//  test_good<Clock> ("5000 h", hours(5000));
     129//#if BOOST_CHRONO_VERSION==2
     130//  test_good<Clock>("5000 min", minutes(5000));
     131//#else
     132//  test_good<Clock> ("5000 m", minutes(5000));
     133//#endif
     134//  test_good<Clock> ("5000 s", seconds(5000));
     135//  test_good<Clock> ("5000 ms", milliseconds(5000));
     136//  test_good<Clock> ("5000 ns", nanoseconds(5000));
     137//  test_good<Clock> ("5000 ds", duration<boost::int_least64_t, deci> (5000));
     138//  test_good<Clock> ("5000 [1/30]s", duration<boost::int_least64_t, ratio<1, 30> > (5000));
     139//
     140//  test_good<Clock> ("5000 milliseconds", seconds(5));
     141//  test_good<Clock> ("5 milliseconds", nanoseconds(5000000));
     142//  test_good<Clock> ("4000 ms", seconds(4));
     143//  test_fail<Clock> ("3001 ms", seconds(3));
     144//  test_fail_epoch<Clock> ("3001 ms", seconds(3));
     145//  test_fail_epoch<Clock> ("3001 ms since", seconds(3));
     146
     147}
     148
    94149int main()
    95150{
    96151  std::cout << "high_resolution_clock=" << std::endl;
     
    99154  std::cout << "steady_clock=" << std::endl;
    100155  check_all<boost::chrono::steady_clock> ();
    101156#endif
    102   //std::cout << "system_clock=";
    103   //check_all<boost::chrono::system_clock>();
     157  std::cout << "system_clock=";
     158  check_all_system_clock();
    104159
    105160#if defined(BOOST_CHRONO_HAS_THREAD_CLOCK)
    106161  std::cout << "thread_clock="<< std::endl;
  • libs/chrono/test/io/time_point_output.cpp

     
    1616  boost::chrono::time_point<Clock, D> tp(d);
    1717  out << tp;
    1818  BOOST_TEST(out.good());
     19  //std::cout << "Expected= " << std::string(str) + boost::chrono::clock_string<Clock, char>::since() << std::endl;
     20  //std::cout << "Obtained= " << out.str() << std::endl;
    1921  BOOST_TEST( (out.str() == std::string(str) + boost::chrono::clock_string<Clock, char>::since()));
    2022}
    2123
     24template <typename D>
     25void test_good_prefix_system_clock(const char* str, D d)
     26{
     27  typedef boost::chrono::system_clock Clock;
     28
     29  std::ostringstream out;
     30  boost::chrono::time_point<Clock, D> tp(d);
     31  out << tp;
     32  BOOST_TEST(out.good());
     33
     34  std::cout << "Expected= " << str << std::endl;
     35  std::cout << "Obtained= " << out.str() << std::endl;
     36  BOOST_TEST( (out.str() == std::string(str) ));
     37}
     38
    2239template <typename Clock, typename D>
    2340void test_good_symbol(const char* str, D d)
    2441{
     
    3350  BOOST_TEST( (out.str() == std::string(str) + boost::chrono::clock_string<Clock, char>::since()));
    3451}
    3552
    36 #if BOOST_CHRONO_VERSION==2
     53#if BOOST_CHRONO_VERSION>=2
     54template <typename D>
     55void test_good_symbol_system_clock(const char* str, D d)
     56{
     57  typedef boost::chrono::system_clock Clock;
     58
     59  std::ostringstream out;
     60  boost::chrono::time_point<Clock, D> tp(d);
     61  out << boost::chrono::duration_fmt(boost::chrono::duration_style::symbol) << tp;
     62  BOOST_TEST(out.good());
     63  std::cout << "Expected= " << str << std::endl;
     64  std::cout << "Obtained= " << out.str() << std::endl;
     65  BOOST_TEST( (out.str() == std::string(str) ));
     66}
     67
    3768template<typename Clock, typename D>
    3869void test_good(const char* str, D d, boost::chrono::duration_style style)
    3970{
     
    4374  BOOST_TEST(out.good());
    4475  BOOST_TEST((out.str() == std::string(str)+boost::chrono::clock_string<Clock,char>::since()));
    4576}
     77
     78template<typename D>
     79void test_good_system_clock(const char* str, D d, boost::chrono::duration_style style)
     80{
     81  typedef boost::chrono::system_clock Clock;
     82
     83  std::ostringstream out;
     84  boost::chrono::time_point<Clock,D> tp(d);
     85  out << boost::chrono::duration_fmt(style) << tp;
     86  BOOST_TEST(out.good());
     87  std::cout << "Expected= " << str << std::endl;
     88  std::cout << "Obtained= " << out.str() << std::endl;
     89  BOOST_TEST((out.str() == std::string(str) ));
     90}
    4691#endif
    4792
    4893template <typename Clock>
     
    81126  test_good_symbol<Clock> ("2 [1/30]s", duration<boost::int_least64_t, ratio<1, 30> > (2));
    82127}
    83128
     129#if BOOST_CHRONO_VERSION==2
     130void check_all_system_clock()
     131{
     132  using namespace boost::chrono;
     133  using namespace boost;
     134
     135  test_good_system_clock("1970-01-01 02:00:00.000000 +0000", hours(2), duration_style::prefix);
     136  test_good_system_clock("1970-01-01 02:00:00.000000 +0000", hours(2), duration_style::symbol);
     137
     138  test_good_prefix_system_clock("1970-01-01 02:00:00.000000 +0000", hours(2));
     139  test_good_prefix_system_clock("1970-01-01 00:02:00.000000 +0000", minutes(2));
     140  test_good_prefix_system_clock("1970-01-01 00:00:02.000000 +0000", seconds(2));
     141  test_good_prefix_system_clock("1970-01-01 00:00:01.000000 +0000", seconds(1));
     142  test_good_prefix_system_clock("1969-12-31 23:59:59.000000 +0000", seconds(-1));
     143  test_good_prefix_system_clock("1970-01-01 00:00:00.000000 +0000", seconds(0));
     144  test_good_prefix_system_clock("1970-01-01 00:00:00.002000 +0000", milliseconds(2));
     145  test_good_prefix_system_clock("1970-01-01 00:00:00.000002 +0000", microseconds(2));
     146  test_good_prefix_system_clock("1970-01-01 00:00:00.000000 +0000", nanoseconds(2));
     147  test_good_prefix_system_clock("1970-01-01 00:00:00.200000 +0000", duration<boost::int_least64_t, deci> (2));
     148  test_good_prefix_system_clock("1970-01-01 00:00:00.066667 +0000", duration<boost::int_least64_t, ratio<1, 30> > (2));
     149
     150  test_good_symbol_system_clock("1970-01-01 02:00:00.000000 +0000", hours(2));
     151  test_good_symbol_system_clock("1970-01-01 00:02:00.000000 +0000", minutes(2));
     152  test_good_symbol_system_clock("1970-01-01 00:00:02.000000 +0000", seconds(2));
     153  test_good_symbol_system_clock("1970-01-01 00:00:00.002000 +0000", milliseconds(2));
     154  test_good_symbol_system_clock("1970-01-01 00:00:00.000000 +0000", nanoseconds(2));
     155  test_good_symbol_system_clock("1970-01-01 00:00:00.200000 +0000", duration<boost::int_least64_t, deci> (2));
     156  test_good_symbol_system_clock("1970-01-01 00:00:00.066667 +0000", duration<boost::int_least64_t, ratio<1, 30> > (2));
     157}
     158#endif
    84159int main()
    85160{
    86161
     
    90165  std::cout << "steady_clock=" << std::endl;
    91166  check_all<boost::chrono::steady_clock> ();
    92167#endif
    93   //std::cout << "system_clock=";
    94   //check_all<boost::chrono::system_clock>();
     168  std::cout << "system_clock=" << std::endl;
     169#if BOOST_CHRONO_VERSION==2
     170  check_all_system_clock();
     171#else
     172  check_all<boost::chrono::system_clock> ();
     173#endif
    95174
    96175#if defined(BOOST_CHRONO_HAS_THREAD_CLOCK)
    97176  std::cout << "thread_clock="<< std::endl;