1 /* Copyright (c) 2002,2003 CrystalClear Software, Inc.
2  * Use, modification and distribution is subject to the
3  * Boost Software License, Version 1.0. (See accompanying
4  * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
5  * Author: Jeff Garland
6  */
7 
8 #include "boost/date_time/time_resolution_traits.hpp"
9 #include "testfrmwk.hpp"
10 
11 
12 int
main()13 main()
14 {
15   using namespace boost::date_time;
16   check("milli traits num digits",  milli_res::num_fractional_digits() == 3);
17   check("milli traits resolution adjust",
18         milli_res::res_adjust() == 1000);
19   check("milli tick calculations",
20         milli_res::to_tick_count(0,0,0,1) == 1);
21   check("milli tick calculations",
22         milli_res::to_tick_count(0,0,1,1) == 1001);
23   check("milli tick calculations",
24         milli_res::to_tick_count(0,1,0,0) == 60000);
25   boost::int64_t one_hour_milli = 3600*1000;
26   check("milli tick calculations",
27         milli_res::to_tick_count(1,0,0,0) == one_hour_milli);
28 
29   check("micro traits num digits",  micro_res::num_fractional_digits() == 6);
30   check("micro traits resolution adjust",
31         micro_res::res_adjust() == 1000000);
32   check("micro tick calculations",
33         micro_res::to_tick_count(0,0,0,1) == 1);
34   check("micro tick calculations",
35         micro_res::to_tick_count(0,0,1,1) == 1000001);
36   check("micro tick calculations",
37         micro_res::to_tick_count(0,1,0,0) == 60000000);
38   boost::int64_t one_hour_micro = 3600*1000;
39   one_hour_micro = one_hour_micro*1000; //avoid compiler overflow!
40   check("micro tick calculations",
41         micro_res::to_tick_count(1,0,0,0) == one_hour_micro);
42 
43   check("nano traits num digits",  nano_res::num_fractional_digits() == 9);
44   check("nano traits resolution adjust",
45         nano_res::res_adjust() == 1000000000);
46   check("nano tick calculations",
47         nano_res::to_tick_count(0,0,0,1) == 1);
48   check("nano tick calculations",
49         nano_res::to_tick_count(0,0,1,1) == 1000000001);
50   boost::int64_t one_minute_nano = 60*1000*1000;
51   one_minute_nano = one_minute_nano*1000;
52   check("nano tick calculations",
53         nano_res::to_tick_count(0,1,0,0) == one_minute_nano);
54 
55   //skip io on VC6 b/c of lack of operator<< for int64
56 #if (defined(BOOST_MSVC) && (_MSC_VER < 1300))
57 #else
58   std::cout << one_hour_micro << std::endl;
59 #endif
60   boost::int64_t one_hour_nano = one_hour_micro*1000;
61 #if (defined(BOOST_MSVC) && (_MSC_VER < 1300))
62 #else
63   std::cout << one_hour_nano << std::endl;
64 #endif
65   check("nano tick calculations",
66         nano_res::to_tick_count(1,0,0,0) == one_hour_nano);
67 
68 
69   return printTestStats();
70 
71 }
72 
73