1
// Distributed under the Boost Software License, Version 1.0.
2
// Copyright 2011 Vicente J. Botet Escriba
3
// See http://www.boost.org/LICENSE_1_0.txt
5
#include <boost/chrono/chrono_io.hpp>
6
//#include <boost/chrono/io/duration_units.hpp>
8
#include <boost/detail/lightweight_test.hpp>
12
void test_good(const char* str, D res)
14
std::istringstream in(str);
18
BOOST_TEST(!in.fail());
20
std::cout << str << " " << res << " " << d << std::endl;
23
template<typename DFail>
24
void test_fail(const char* str, DFail res)
27
std::istringstream in(str);
28
DFail d = DFail::zero();
30
BOOST_TEST(in.fail());
31
BOOST_TEST(d == DFail::zero());
32
std::cout << str << " " << res << " " << d << std::endl;
37
void test_not_eof(const char* str, D res)
40
std::istringstream in(str);
43
BOOST_TEST(!in.eof());
45
std::cout << str << " " << res << " " << d << std::endl;
50
using namespace boost::chrono;
51
using namespace boost;
53
test_good("5000", 5000);
55
test_good("5000 hours", hours(5000));
56
test_good("5000 minutes", minutes(5000));
57
test_good("5000 seconds", seconds(5000));
58
test_fail("1.0 second", seconds(1));
60
test_good("1.0 second", duration<float,ratio<1> >(1));
61
test_good("1 second", seconds(1));
62
test_not_eof("1 second ", seconds(1));
63
test_not_eof("1 seconde", seconds(1));
64
test_good("1 seconds", seconds(1));
65
test_good("0 seconds", seconds(0));
66
test_good("-1 seconds", seconds(-1));
67
test_good("5000 milliseconds", milliseconds(5000));
68
test_good("5000 microseconds", microseconds(5000));
69
test_good("5000 nanoseconds", nanoseconds(5000));
70
test_good("5000 deciseconds", duration<boost::int_least64_t, deci> (5000));
71
test_good("5000 [1/30]seconds", duration<boost::int_least64_t, ratio<1, 30> > (5000));
72
test_good("5000 [1/30]second", duration<boost::int_least64_t, ratio<1, 30> > (5000));
73
test_good("5000 h", hours(5000));
74
#if defined BOOST_CHRONO_DONT_PROVIDE_DEPRECATED_IO_V1
75
test_good("5000 min", minutes(5000));
77
test_good("5000 m", minutes(5000));
79
test_good("5000 s", seconds(5000));
80
test_good("5000 ms", milliseconds(5000));
81
test_good("5000 ns", nanoseconds(5000));
82
test_good("5000 ds", duration<boost::int_least64_t, deci> (5000));
83
test_good("5000 [1/30]s", duration<boost::int_least64_t, ratio<1, 30> > (5000));
84
test_not_eof("5000 [1/30]ss", duration<boost::int_least64_t, ratio<1, 30> > (5000));
85
test_good("5000 milliseconds", seconds(5));
86
test_good("5000 millisecond", seconds(5));
87
test_good("5 milliseconds", nanoseconds(5000000));
88
test_good("4000 ms", seconds(4));
89
test_fail("3001 ms", seconds(3));
90
test_fail("3001 ", milliseconds(3001));
91
test_fail("one ms", milliseconds(1));
92
test_fail("5000 millisecon", seconds(5));
93
test_not_eof("3001 ms ", milliseconds(3001));
95
return boost::report_errors();