~ubuntu-branches/debian/sid/boost1.49/sid

« back to all changes in this revision

Viewing changes to libs/chrono/test/io/duration_input.cpp

  • Committer: Package Import Robot
  • Author(s): Steve M. Robbins
  • Date: 2012-02-26 00:31:44 UTC
  • Revision ID: package-import@ubuntu.com-20120226003144-eaytp12cbf6ubpms
Tags: upstream-1.49.0
ImportĀ upstreamĀ versionĀ 1.49.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
4
 
 
5
#include <boost/chrono/chrono_io.hpp>
 
6
//#include <boost/chrono/io/duration_units.hpp>
 
7
#include <sstream>
 
8
#include <boost/detail/lightweight_test.hpp>
 
9
 
 
10
 
 
11
template<typename D>
 
12
void test_good(const char* str, D res)
 
13
{
 
14
  std::istringstream in(str);
 
15
  D d(0);
 
16
  in >> d;
 
17
  BOOST_TEST(in.eof());
 
18
  BOOST_TEST(!in.fail());
 
19
  BOOST_TEST(d == res);
 
20
  std::cout << str << " " << res << " " << d << std::endl;
 
21
}
 
22
 
 
23
template<typename DFail>
 
24
void test_fail(const char* str, DFail res)
 
25
{
 
26
  {
 
27
    std::istringstream in(str);
 
28
    DFail d = DFail::zero();
 
29
    in >> d;
 
30
    BOOST_TEST(in.fail());
 
31
    BOOST_TEST(d == DFail::zero());
 
32
    std::cout << str << " " << res << " " << d << std::endl;
 
33
  }
 
34
}
 
35
 
 
36
template<typename D>
 
37
void test_not_eof(const char* str, D res)
 
38
{
 
39
  {
 
40
    std::istringstream in(str);
 
41
    D d = D::zero();
 
42
    in >> d;
 
43
    BOOST_TEST(!in.eof());
 
44
    BOOST_TEST(d == res);
 
45
    std::cout << str << " " << res << " " << d << std::endl;
 
46
  }
 
47
}
 
48
int main()
 
49
{
 
50
  using namespace boost::chrono;
 
51
  using namespace boost;
 
52
 
 
53
  test_good("5000", 5000);
 
54
 
 
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));
 
59
 
 
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));
 
76
#else
 
77
  test_good("5000 m", minutes(5000));
 
78
#endif
 
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));
 
94
 
 
95
  return boost::report_errors();
 
96
 
 
97
}
 
98