File: testtime_resolution_traits.cpp

package info (click to toggle)
boost 1.34.1-14
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 116,412 kB
  • ctags: 259,566
  • sloc: cpp: 642,395; xml: 56,450; python: 17,612; ansic: 14,520; sh: 2,265; yacc: 858; perl: 481; makefile: 478; lex: 94; sql: 74; csh: 6
file content (72 lines) | stat: -rw-r--r-- 2,608 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* Copyright (c) 2002,2003 CrystalClear Software, Inc.
 * Use, modification and distribution is subject to the 
 * Boost Software License, Version 1.0. (See accompanying
 * file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
 * Author: Jeff Garland 
 */

#include "boost/date_time/time_resolution_traits.hpp"
#include "boost/date_time/testfrmwk.hpp"


int
main() 
{
  using namespace boost::date_time;
  check("milli traits num digits",  milli_res::num_fractional_digits() == 3);
  check("milli traits resolution adjust",  
        milli_res::res_adjust() == 1000);
  check("milli tick calculations",  
        milli_res::to_tick_count(0,0,0,1) == 1);
  check("milli tick calculations",  
        milli_res::to_tick_count(0,0,1,1) == 1001);
  check("milli tick calculations",  
        milli_res::to_tick_count(0,1,0,0) == 60000);
  boost::int64_t one_hour_milli = 3600*1000;
  check("milli tick calculations",  
        milli_res::to_tick_count(1,0,0,0) == one_hour_milli);
  
  check("micro traits num digits",  micro_res::num_fractional_digits() == 6);
  check("micro traits resolution adjust",  
        micro_res::res_adjust() == 1000000);
  check("micro tick calculations",  
        micro_res::to_tick_count(0,0,0,1) == 1);
  check("micro tick calculations",  
        micro_res::to_tick_count(0,0,1,1) == 1000001);
  check("micro tick calculations",  
        micro_res::to_tick_count(0,1,0,0) == 60000000);
  boost::int64_t one_hour_micro = 3600*1000;
  one_hour_micro = one_hour_micro*1000; //avoid compiler overflow!
  check("micro tick calculations",  
        micro_res::to_tick_count(1,0,0,0) == one_hour_micro);

  check("nano traits num digits",  nano_res::num_fractional_digits() == 9);
  check("nano traits resolution adjust",  
        nano_res::res_adjust() == 1000000000);
  check("nano tick calculations",  
        nano_res::to_tick_count(0,0,0,1) == 1);
  check("nano tick calculations",  
        nano_res::to_tick_count(0,0,1,1) == 1000000001);
  boost::int64_t one_minute_nano = 60*1000*1000;
  one_minute_nano = one_minute_nano*1000;
  check("nano tick calculations",  
        nano_res::to_tick_count(0,1,0,0) == one_minute_nano);

  //skip io on VC6 b/c of lack of operator<< for int64
#if (defined(BOOST_MSVC) && (_MSC_VER < 1300))
#else
  std::cout << one_hour_micro << std::endl;
#endif
  boost::int64_t one_hour_nano = one_hour_micro*1000;
#if (defined(BOOST_MSVC) && (_MSC_VER < 1300))
#else
  std::cout << one_hour_nano << std::endl;
#endif
  check("nano tick calculations",  
        nano_res::to_tick_count(1,0,0,0) == one_hour_nano);


  return printTestStats();

}