|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r75665 - in branches/release: boost/chrono/detail/no_warning boost/chrono/io_v1 libs/chrono/test/io
From: vicente.botet_at_[hidden]
Date: 2011-11-25 19:11:13
Author: viboes
Date: 2011-11-25 19:11:12 EST (Fri, 25 Nov 2011)
New Revision: 75665
URL: http://svn.boost.org/trac/boost/changeset/75665
Log:
Chrono: Fix #6092,#6093,#6113
Added:
branches/release/boost/chrono/detail/no_warning/
branches/release/boost/chrono/detail/no_warning/signed_unsigned_cmp.hpp (contents, props changed)
Text files modified:
branches/release/boost/chrono/io_v1/chrono_io.hpp | 229 ++++++++++++++++++++++++++++++---------
branches/release/libs/chrono/test/io/duration_input.cpp | 55 +++++++--
branches/release/libs/chrono/test/io/duration_output.cpp | 50 ++++++++
branches/release/libs/chrono/test/io/time_point_input.cpp | 137 ++++++++++++-----------
branches/release/libs/chrono/test/io/time_point_output.cpp | 103 +++++++++++------
5 files changed, 402 insertions(+), 172 deletions(-)
Added: branches/release/boost/chrono/detail/no_warning/signed_unsigned_cmp.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/chrono/detail/no_warning/signed_unsigned_cmp.hpp 2011-11-25 19:11:12 EST (Fri, 25 Nov 2011)
@@ -0,0 +1,44 @@
+// is_evenly_divisible_by.hpp --------------------------------------------------------------//
+
+// Copyright 2009-2010 Vicente J. Botet Escriba
+
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+
+#ifndef BOOST_CHRONO_DETAIL_NO_WARNING_SIGNED_UNSIGNED_CMP_HPP
+#define BOOST_CHRONO_DETAIL_NO_WARNING_SIGNED_UNSIGNED_CMP_HPP
+
+//
+// We simply cannot include this header on gcc without getting copious warnings of the kind:
+//
+//../../../boost/chrono/detail/no_warning/signed_unsigned_cmp.hpp:37: warning: comparison between signed and unsigned integer expressions
+//
+// And yet there is no other reasonable implementation, so we declare this a system header
+// to suppress these warnings.
+//
+
+#if defined(__GNUC__) && (__GNUC__ >= 4)
+#pragma GCC system_header
+#endif
+
+namespace boost {
+namespace chrono {
+namespace detail {
+
+ template <class T, class U>
+ bool lt(T t, U u)
+ {
+ return t < u;
+ }
+
+ template <class T, class U>
+ bool gt(T t, U u)
+ {
+ return t > u;
+ }
+
+} // namespace detail
+} // namespace detail
+} // namespace chrono
+
+#endif // BOOST_CHRONO_DETAIL_IS_EVENLY_DIVISIBLE_BY_HPP
Modified: branches/release/boost/chrono/io_v1/chrono_io.hpp
==============================================================================
--- branches/release/boost/chrono/io_v1/chrono_io.hpp (original)
+++ branches/release/boost/chrono/io_v1/chrono_io.hpp 2011-11-25 19:11:12 EST (Fri, 25 Nov 2011)
@@ -24,6 +24,8 @@
#include <boost/mpl/if.hpp>
#include <boost/math/common_factor_rt.hpp>
#include <boost/chrono/detail/scan_keyword.hpp>
+#include <boost/utility/enable_if.hpp>
+#include <boost/chrono/detail/no_warning/signed_unsigned_cmp.hpp>
namespace boost
{
@@ -87,10 +89,35 @@
{return long_name(typename Period::type());}
template <class Period>
- string_type name() const {
- if (use_short_) return short_name<Period>();
- else return long_name<Period>();
+ string_type plural() const
+ {return long_name(typename Period::type());}
+
+ template <class Period>
+ string_type singular() const
+ {
+ return string_type(long_name(typename Period::type()), 0, long_name(typename Period::type()).size()-1);
+ }
+
+ template <class Period>
+ string_type name() const
+ {
+ if (use_short_) return short_name<Period>();
+ else {
+ return long_name<Period>();
+ }
+ }
+ template <class Period, class D>
+ string_type name(D v) const
+ {
+ if (use_short_) return short_name<Period>();
+ else
+ {
+ if (v==-1 || v==1)
+ return singular<Period>();
+ else
+ return plural<Period>();
}
+ }
bool is_short_name() const {return use_short_;}
bool is_long_name() const {return !use_short_;}
@@ -181,7 +208,7 @@
if (!std::has_facet<Facet>(loc))
os.imbue(std::locale(loc, new Facet));
const Facet& f = std::use_facet<Facet>(os.getloc());
- return os << d.count() << ' ' << f.template name<Period>();
+ return os << d.count() << ' ' << f.template name<Period>(d.count());
}
namespace chrono_detail {
@@ -207,123 +234,189 @@
>::type type;
};
+template <typename intermediate_type>
+typename enable_if<is_integral<intermediate_type>, bool>::type
+reduce(intermediate_type& r, unsigned long long& den, std::ios_base::iostate& err)
+{
+ typedef typename common_type<intermediate_type, unsigned long long>::type common_type_t;
+
+ // Reduce r * num / den
+ common_type_t t = math::gcd<common_type_t>(common_type_t(r), common_type_t(den));
+ r /= t;
+ den /= t;
+ if (den != 1)
+ {
+ // Conversion to Period is integral and not exact
+ err |= std::ios_base::failbit;
+ return false;
+ }
+ return true;
+}
+template <typename intermediate_type>
+typename disable_if<is_integral<intermediate_type>, bool>::type
+reduce(intermediate_type& , unsigned long long& , std::ios_base::iostate& )
+{
+ return true;
+}
+
}
template <class CharT, class Traits, class Rep, class Period>
std::basic_istream<CharT, Traits>&
operator>>(std::basic_istream<CharT, Traits>& is, duration<Rep, Period>& d)
{
+ std::cerr << __FILE__ << "[" << __LINE__ << "]"<< std::endl;
typedef duration_punct<CharT> Facet;
std::locale loc = is.getloc();
- if (!std::has_facet<Facet>(loc))
+ std::cerr << __FILE__ << "[" << __LINE__ << "]"<< std::endl;
+ if (!std::has_facet<Facet>(loc)) {
+ std::cerr << __FILE__ << "[" << __LINE__ << "]"<< std::endl;
is.imbue(std::locale(loc, new Facet));
+ }
+ std::cerr << __FILE__ << "[" << __LINE__ << "]"<< std::endl;
loc = is.getloc();
const Facet& f = std::use_facet<Facet>(loc);
typedef typename chrono_detail::duration_io_intermediate<Rep>::type intermediate_type;
intermediate_type r;
+ std::ios_base::iostate err = std::ios_base::goodbit;
// read value into r
+ std::cerr << __FILE__ << "[" << __LINE__ << "]"<< std::endl;
is >> r;
+ std::cerr << __FILE__ << "[" << __LINE__ << "]"<< std::endl;
if (is.good())
{
+ std::cerr << __FILE__ << "[" << __LINE__ << "]"<< std::endl;
// now determine unit
typedef std::istreambuf_iterator<CharT, Traits> in_iterator;
in_iterator i(is);
in_iterator e;
+ std::cerr << __FILE__ << "[" << __LINE__ << "]"<< std::endl;
if (i != e && *i == ' ') // mandatory ' ' after value
{
+ std::cerr << __FILE__ << "[" << __LINE__ << "]"<< std::endl;
++i;
if (i != e)
{
+ std::cerr << __FILE__ << "[" << __LINE__ << "]"<< std::endl;
// unit is num / den (yet to be determined)
unsigned long long num = 0;
unsigned long long den = 0;
if (*i == '[')
{
+ std::cerr << __FILE__ << "[" << __LINE__ << "]"<< std::endl;
// parse [N/D]s or [N/D]seconds format
++i;
CharT x;
is >> num >> x >> den;
if (!is.good() || (x != '/'))
{
+ std::cerr << __FILE__ << "[" << __LINE__ << "]"<< std::endl;
is.setstate(is.failbit);
return is;
}
i = in_iterator(is);
if (*i != ']')
{
+ std::cerr << __FILE__ << "[" << __LINE__ << "]"<< std::endl;
is.setstate(is.failbit);
return is;
}
++i;
const std::basic_string<CharT> units[] =
{
- f.template long_name<ratio<1> >(),
+ f.template singular<ratio<1> >(),
+ f.template plural<ratio<1> >(),
f.template short_name<ratio<1> >()
};
- std::ios_base::iostate err = std::ios_base::goodbit;
+ std::cerr << __FILE__ << "[" << __LINE__ << "]"<< std::endl;
const std::basic_string<CharT>* k = chrono_detail::scan_keyword(i, e,
units, units + sizeof(units)/sizeof(units[0]),
//~ std::use_facet<std::ctype<CharT> >(loc),
err);
- switch ((k - units) / 2)
+ std::cerr << __FILE__ << "[" << __LINE__ << "]"<< std::endl;
+ is.setstate(err);
+ switch ((k - units) / 3)
{
case 0:
+ std::cerr << __FILE__ << "[" << __LINE__ << "]"<< std::endl;
break;
default:
is.setstate(err);
+ std::cerr << __FILE__ << "[" << __LINE__ << "]"<< std::endl;
return is;
}
}
else
{
+ std::cerr << __FILE__ << "[" << __LINE__ << "]"<< std::endl;
// parse SI name, short or long
const std::basic_string<CharT> units[] =
{
- f.template long_name<atto>(),
+ f.template singular<atto>(),
+ f.template plural<atto>(),
f.template short_name<atto>(),
- f.template long_name<femto>(),
+ f.template singular<femto>(),
+ f.template plural<femto>(),
f.template short_name<femto>(),
- f.template long_name<pico>(),
+ f.template singular<pico>(),
+ f.template plural<pico>(),
f.template short_name<pico>(),
- f.template long_name<nano>(),
+ f.template singular<nano>(),
+ f.template plural<nano>(),
f.template short_name<nano>(),
- f.template long_name<micro>(),
+ f.template singular<micro>(),
+ f.template plural<micro>(),
f.template short_name<micro>(),
- f.template long_name<milli>(),
+ f.template singular<milli>(),
+ f.template plural<milli>(),
f.template short_name<milli>(),
- f.template long_name<centi>(),
+ f.template singular<centi>(),
+ f.template plural<centi>(),
f.template short_name<centi>(),
- f.template long_name<deci>(),
+ f.template singular<deci>(),
+ f.template plural<deci>(),
f.template short_name<deci>(),
- f.template long_name<deca>(),
+ f.template singular<deca>(),
+ f.template plural<deca>(),
f.template short_name<deca>(),
- f.template long_name<hecto>(),
+ f.template singular<hecto>(),
+ f.template plural<hecto>(),
f.template short_name<hecto>(),
- f.template long_name<kilo>(),
+ f.template singular<kilo>(),
+ f.template plural<kilo>(),
f.template short_name<kilo>(),
- f.template long_name<mega>(),
+ f.template singular<mega>(),
+ f.template plural<mega>(),
f.template short_name<mega>(),
- f.template long_name<giga>(),
+ f.template singular<giga>(),
+ f.template plural<giga>(),
f.template short_name<giga>(),
- f.template long_name<tera>(),
+ f.template singular<tera>(),
+ f.template plural<tera>(),
f.template short_name<tera>(),
- f.template long_name<peta>(),
+ f.template singular<peta>(),
+ f.template plural<peta>(),
f.template short_name<peta>(),
- f.template long_name<exa>(),
+ f.template singular<exa>(),
+ f.template plural<exa>(),
f.template short_name<exa>(),
- f.template long_name<ratio<1> >(),
+ f.template singular<ratio<1> >(),
+ f.template plural<ratio<1> >(),
f.template short_name<ratio<1> >(),
- f.template long_name<ratio<60> >(),
+ f.template singular<ratio<60> >(),
+ f.template plural<ratio<60> >(),
f.template short_name<ratio<60> >(),
- f.template long_name<ratio<3600> >(),
+ f.template singular<ratio<3600> >(),
+ f.template plural<ratio<3600> >(),
f.template short_name<ratio<3600> >()
};
- std::ios_base::iostate err = std::ios_base::goodbit;
+ std::cerr << __FILE__ << "[" << __LINE__ << "]"<< std::endl;
const std::basic_string<CharT>* k = chrono_detail::scan_keyword(i, e,
units, units + sizeof(units)/sizeof(units[0]),
//~ std::use_facet<std::ctype<CharT> >(loc),
err);
- switch ((k - units) / 2)
+ std::cerr << __FILE__ << "[" << __LINE__ << "]"<< std::endl;
+ switch ((k - units) / 3)
{
case 0:
num = 1ULL;
@@ -402,10 +495,12 @@
den = 1;
break;
default:
- is.setstate(err);
+ std::cerr << __FILE__ << "[" << __LINE__ << "]"<< std::endl;
+ is.setstate(err|is.failbit);
return is;
}
}
+ std::cerr << __FILE__ << "[" << __LINE__ << "]"<< std::endl;
// unit is num/den
// r should be multiplied by (num/den) / Period
// Reduce (num/den) / Period to lowest terms
@@ -418,58 +513,81 @@
if (num > (std::numeric_limits<unsigned long long>::max)() / d2 ||
den > (std::numeric_limits<unsigned long long>::max)() / n2)
{
+ std::cerr << __FILE__ << "[" << __LINE__ << "]"<< std::endl;
// (num/den) / Period overflows
- is.setstate(is.failbit);
+ is.setstate(err|is.failbit);
return is;
}
num *= d2;
den *= n2;
- // num / den is now factor to multiply by r
+
typedef typename common_type<intermediate_type, unsigned long long>::type common_type_t;
- if (is_integral<intermediate_type>::value)
+
+ std::cerr << __FILE__ << "[" << __LINE__ << "]"<< std::endl;
+ // num / den is now factor to multiply by r
+ if (!chrono_detail::reduce(r, den, err))
{
- // Reduce r * num / den
- common_type_t t = math::gcd<common_type_t>(r, den);
- r /= t;
- den /= t;
- if (den != 1)
- {
- // Conversion to Period is integral and not exact
- is.setstate(is.failbit);
- return is;
- }
+ std::cerr << __FILE__ << "[" << __LINE__ << "]"<< std::endl;
+ is.setstate(err|is.failbit);
+ return is;
}
- if (r > ((duration_values<common_type_t>::max)() / num))
+
+ //if (r > ((duration_values<common_type_t>::max)() / num))
+ std::cerr << __FILE__ << "[" << __LINE__ << "]"<< std::endl;
+ if (chrono::detail::gt(r,((duration_values<common_type_t>::max)() / num)))
{
// Conversion to Period overflowed
- is.setstate(is.failbit);
+ std::cerr << __FILE__ << "[" << __LINE__ << "]"<< std::endl;
+ is.setstate(err|is.failbit);
return is;
}
+ std::cerr << __FILE__ << "[" << __LINE__ << "]"<< std::endl;
common_type_t t = r * num;
t /= den;
- if ((duration_values<Rep>::max)() < t)
+ std::cerr << __FILE__ << "[" << __LINE__ << "]"<< std::endl;
+
+ if (t > 0)
{
+ std::cerr << __FILE__ << "[" << __LINE__ << "]"<< std::endl;
+ Rep pt = t;
+ if ( (duration_values<Rep>::max)() < pt)
+ {
+ std::cerr << __FILE__ << "[" << __LINE__ << "]"<< std::endl;
// Conversion to Period overflowed
- is.setstate(is.failbit);
+ is.setstate(err|is.failbit);
return is;
+ }
}
+ std::cerr << __FILE__ << "[" << __LINE__ << "]"<< std::endl;
// Success! Store it.
r = Rep(t);
d = duration<Rep, Period>(r);
+ is.setstate(err);
+ std::cerr << __FILE__ << "[" << __LINE__ << "]"<< std::endl;
+ return is;
}
- else
+ else {
+ std::cerr << __FILE__ << "[" << __LINE__ << "]"<< std::endl;
is.setstate(is.failbit | is.eofbit);
+ return is;
+ }
}
else
{
+ std::cerr << __FILE__ << "[" << __LINE__ << "]"<< std::endl;
if (i == e)
- is.setstate(is.eofbit);
- is.setstate(is.failbit);
+ is.setstate(is.failbit|is.eofbit);
+ else
+ is.setstate(is.failbit);
+ std::cerr << __FILE__ << "[" << __LINE__ << "]"<< std::endl;
+ return is;
}
}
- else
- is.setstate(is.failbit);
- return is;
+ else {
+ std::cerr << __FILE__ << "[" << __LINE__ << "]"<< std::endl;
+ //is.setstate(is.failbit);
+ return is;
+ }
}
@@ -499,10 +617,11 @@
&units, &units + 1,
//~ std::use_facet<std::ctype<CharT> >(is.getloc()),
err) - &units;
+ is.setstate(err);
if (k == 1)
{
+ is.setstate(err | is.failbit);
// failed to read epoch string
- is.setstate(err);
return is;
}
tp = time_point<Clock, Duration>(d);
@@ -515,4 +634,4 @@
}
-#endif // BOOST_CHRONO_IO_V1_CHRONO_IO_HPP
+#endif // BOOST_CHRONO_CHRONO_IO_HPP
Modified: branches/release/libs/chrono/test/io/duration_input.cpp
==============================================================================
--- branches/release/libs/chrono/test/io/duration_input.cpp (original)
+++ branches/release/libs/chrono/test/io/duration_input.cpp 2011-11-25 19:11:12 EST (Fri, 25 Nov 2011)
@@ -1,24 +1,27 @@
-// Copyright 2011 Vicente J. Botet Escriba
// Distributed under the Boost Software License, Version 1.0.
+// Copyright 2011 Vicente J. Botet Escriba
// See http://www.boost.org/LICENSE_1_0.txt
#include <boost/chrono/chrono_io.hpp>
+//#include <boost/chrono/io/duration_units.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(in.eof());
+ BOOST_TEST(!in.fail());
BOOST_TEST(d == res);
+ std::cout << str << " " << res << " " << d << std::endl;
}
-template<typename DFail, typename DGood>
-void test_fail(const char* str, DFail r, DGood res)
+template<typename DFail>
+void test_fail(const char* str, DFail res)
{
{
std::istringstream in(str);
@@ -26,46 +29,70 @@
in >> d;
BOOST_TEST(in.fail());
BOOST_TEST(d == DFail::zero());
+ std::cout << str << " " << res << " " << d << std::endl;
}
+}
+
+template<typename D>
+void test_not_eof(const char* str, D res)
+{
{
std::istringstream in(str);
- DGood d = DGood::zero();
+ D d = D::zero();
in >> d;
- BOOST_TEST(in.good());
+ BOOST_TEST(!in.eof());
BOOST_TEST(d == res);
+ std::cout << str << " " << res << " " << d << std::endl;
}
}
-
int main()
{
using namespace boost::chrono;
using namespace boost;
+ test_good("5000", 5000);
+
test_good("5000 hours", hours(5000));
test_good("5000 minutes", minutes(5000));
test_good("5000 seconds", seconds(5000));
+ test_fail("1.0 second", seconds(1));
+
+ test_good("1.0 second", duration<float,ratio<1> >(1));
+ test_good("1 second", seconds(1));
+ test_not_eof("1 second ", seconds(1));
+ test_not_eof("1 seconde", seconds(1));
test_good("1 seconds", seconds(1));
- //test_good("-1 second", seconds(-1));
+ test_good("0 seconds", seconds(0));
+ test_good("-1 seconds", 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 [1/30]second", duration<boost::int_least64_t, ratio<1, 30> > (5000));
test_good("5000 h", hours(5000));
+#if defined BOOST_CHRONO_DONT_PROVIDE_DEPRECATED_IO_V1
+ test_good("5000 min", minutes(5000));
+#else
test_good("5000 m", minutes(5000));
+#endif
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_not_eof("5000 [1/30]ss", duration<boost::int_least64_t, ratio<1, 30> > (5000));
test_good("5000 milliseconds", seconds(5));
+ test_good("5000 millisecond", seconds(5));
test_good("5 milliseconds", nanoseconds(5000000));
test_good("4000 ms", seconds(4));
- test_fail("3001 ms", seconds(3), milliseconds(3001));
+ test_fail("3001 ms", seconds(3));
+ test_fail("3001 ", milliseconds(3001));
+ test_fail("one ms", milliseconds(1));
+ test_fail("5000 millisecon", seconds(5));
+ test_not_eof("3001 ms ", milliseconds(3001));
+
+ return boost::report_errors();
}
Modified: branches/release/libs/chrono/test/io/duration_output.cpp
==============================================================================
--- branches/release/libs/chrono/test/io/duration_output.cpp (original)
+++ branches/release/libs/chrono/test/io/duration_output.cpp 2011-11-25 19:11:12 EST (Fri, 25 Nov 2011)
@@ -12,6 +12,7 @@
std::ostringstream out;
out << d;
BOOST_TEST(out.good());
+
BOOST_TEST(out.str() == str);
}
@@ -19,11 +20,42 @@
void test_good_symbol(const char* str, D d)
{
std::ostringstream out;
- out << boost::chrono::duration_short << d;
+#if defined BOOST_CHRONO_DONT_PROVIDE_DEPRECATED_IO_V1
+ out << boost::chrono::duration_fmt(boost::chrono::duration_style::symbol) << d;
+#else
+ out << boost::chrono::duration_short << d;
+#endif
+ BOOST_TEST(out.good());
+ BOOST_TEST(out.str() == str);
+}
+#if defined BOOST_CHRONO_DONT_PROVIDE_DEPRECATED_IO_V1
+
+template<typename D>
+void test_good(const char* str, D d, boost::chrono::duration_style::type style)
+{
+ std::ostringstream out;
+
+ out << boost::chrono::duration_fmt(style) << d;
BOOST_TEST(out.good());
BOOST_TEST(out.str() == str);
}
+template<typename D>
+void test_state_saver(const char* str, const char* str2, D d, boost::chrono::duration_style::type style)
+{
+ std::ostringstream out;
+ {
+ boost::chrono::duration_style_io_saver ios(out);
+ out << boost::chrono::duration_fmt(style) << d;
+ BOOST_TEST(out.good());
+ BOOST_TEST(out.str() == str);
+ }
+ out << " " << d;
+ BOOST_TEST(out.good());
+ BOOST_TEST(out.str() == str2);
+}
+
+#endif
int main()
{
@@ -33,8 +65,9 @@
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("0 seconds", seconds(0));
+ test_good_prefix("1 second", seconds(1));
+ test_good_prefix("-1 second", seconds(-1));
test_good_prefix("5000 milliseconds", milliseconds(5000));
test_good_prefix("5000 microseconds", microseconds(5000));
test_good_prefix("5000 nanoseconds", nanoseconds(5000));
@@ -42,13 +75,24 @@
test_good_prefix("5000 [1/30]seconds", duration<boost::int_least64_t, ratio<1, 30> > (5000));
test_good_symbol("5000 h", hours(5000));
+#if defined BOOST_CHRONO_DONT_PROVIDE_DEPRECATED_IO_V1
+ test_good_symbol("5000 min", minutes(5000));
+#else
test_good_symbol("5000 m", minutes(5000));
+#endif
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));
+#if defined BOOST_CHRONO_DONT_PROVIDE_DEPRECATED_IO_V1
+ test_good("5000 hours", hours(5000), duration_style::prefix);
+ test_good("5000 h", hours(5000), duration_style::symbol);
+ test_state_saver("5000 h", "5000 h 5000 hours", hours(5000), duration_style::symbol);
+#endif
+
+ return boost::report_errors();
}
Modified: branches/release/libs/chrono/test/io/time_point_input.cpp
==============================================================================
--- branches/release/libs/chrono/test/io/time_point_input.cpp (original)
+++ branches/release/libs/chrono/test/io/time_point_input.cpp 2011-11-25 19:11:12 EST (Fri, 25 Nov 2011)
@@ -9,105 +9,116 @@
#include <boost/chrono/thread_clock.hpp>
#include <boost/chrono/process_cpu_clocks.hpp>
-template<typename Clock, typename D>
+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;
+ 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)));
+ BOOST_TEST(in.eof());
+ BOOST_TEST(!in.fail());
+ BOOST_TEST( (tp == boost::chrono::time_point<Clock, D>(res)));
}
-template<typename Clock, typename D>
-void test_fail(const char* str, D r)
+template <typename Clock, typename D>
+void test_fail(const char* str, D)
{
- 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>()));
+ 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)
+template <typename Clock, typename D>
+void test_fail_no_epoch(const char* str, D )
{
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>()));
+ 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)
+template <typename Clock, typename D>
+void test_fail_epoch(const char* str, D)
{
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>()));
+ 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>
+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));
+ 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 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 defined BOOST_CHRONO_DONT_PROVIDE_DEPRECATED_IO_V1
+ 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=";
- check_all<boost::chrono::high_resolution_clock>();
+ std::cout << "high_resolution_clock=" << std::endl;
+ check_all<boost::chrono::high_resolution_clock> ();
#ifdef BOOST_CHRONO_HAS_CLOCK_STEADY
- std::cout << "steady_clock=";
- check_all<boost::chrono::steady_clock>();
+ std::cout << "steady_clock=" << std::endl;
+ 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=";
+ std::cout << "thread_clock="<< std::endl;
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>();
+ std::cout << "process_real_cpu_clock=" << std::endl;
+ check_all<boost::chrono::process_real_cpu_clock> ();
+ std::cout << "process_user_cpu_clock=" << std::endl;
+ check_all<boost::chrono::process_user_cpu_clock> ();
+ std::cout << "process_system_cpu_clock=" << std::endl;
+ check_all<boost::chrono::process_system_cpu_clock> ();
+ std::cout << "process_cpu_clock=" << std::endl;
+ check_all<boost::chrono::process_cpu_clock> ();
#endif
+
+ return boost::report_errors();
+
}
Modified: branches/release/libs/chrono/test/io/time_point_output.cpp
==============================================================================
--- branches/release/libs/chrono/test/io/time_point_output.cpp (original)
+++ branches/release/libs/chrono/test/io/time_point_output.cpp 2011-11-25 19:11:12 EST (Fri, 25 Nov 2011)
@@ -9,78 +9,107 @@
#include <boost/chrono/thread_clock.hpp>
#include <boost/chrono/process_cpu_clocks.hpp>
-template<typename Clock, typename D>
+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);
+ 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()));
+ BOOST_TEST( (out.str() == std::string(str) + boost::chrono::clock_string<Clock, char>::since()));
}
-template<typename Clock, typename D>
+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);
+ boost::chrono::time_point<Clock, D> tp(d);
+#if defined BOOST_CHRONO_DONT_PROVIDE_DEPRECATED_IO_V1
+ out << boost::chrono::duration_fmt(boost::chrono::duration_style::symbol) << tp;
+#else
out << boost::chrono::duration_short << tp;
+#endif
+ BOOST_TEST(out.good());
+ BOOST_TEST( (out.str() == std::string(str) + boost::chrono::clock_string<Clock, char>::since()));
+}
+
+#if defined BOOST_CHRONO_DONT_PROVIDE_DEPRECATED_IO_V1
+template<typename Clock, typename D>
+void test_good(const char* str, D d, boost::chrono::duration_style::type style)
+{
+ std::ostringstream out;
+ boost::chrono::time_point<Clock,D> tp(d);
+ out << boost::chrono::duration_fmt(style) << tp;
BOOST_TEST(out.good());
BOOST_TEST((out.str() == std::string(str)+boost::chrono::clock_string<Clock,char>::since()));
}
+#endif
-template<typename Clock>
+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));
+#if defined BOOST_CHRONO_DONT_PROVIDE_DEPRECATED_IO_V1
+ test_good<Clock>("2 hours", hours(2), duration_style::prefix);
+ test_good<Clock>("2 h", hours(2), duration_style::symbol);
+#endif
+
+ 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 second", seconds(1));
+ test_good_prefix<Clock> ("-1 second", seconds(-1));
+ test_good_prefix<Clock> ("0 seconds", seconds(0));
+ 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));
+#if defined BOOST_CHRONO_DONT_PROVIDE_DEPRECATED_IO_V1
+ test_good_symbol<Clock>("2 min", minutes(2));
+#else
+ test_good_symbol<Clock> ("2 m", minutes(2));
+#endif
+ 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>();
+ std::cout << "high_resolution_clock=" << std::endl;
+ check_all<boost::chrono::high_resolution_clock> ();
#ifdef BOOST_CHRONO_HAS_CLOCK_STEADY
- std::cout << "steady_clock=";
- check_all<boost::chrono::steady_clock>();
+ std::cout << "steady_clock=" << std::endl;
+ 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=";
+ std::cout << "thread_clock="<< std::endl;
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>();
+ std::cout << "process_real_cpu_clock=" << std::endl;
+ check_all<boost::chrono::process_real_cpu_clock> ();
+ std::cout << "process_user_cpu_clock=" << std::endl;
+ check_all<boost::chrono::process_user_cpu_clock> ();
+ std::cout << "process_system_cpu_clock=" << std::endl;
+ check_all<boost::chrono::process_system_cpu_clock> ();
+ std::cout << "process_cpu_clock=" << std::endl;
+ check_all<boost::chrono::process_cpu_clock> ();
#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