testtime_resolution_traits.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. #include "boost/date_time/time_resolution_traits.hpp"
  8. #include "testfrmwk.hpp"
  9. int
  10. main()
  11. {
  12. using namespace boost::date_time;
  13. check("milli traits num digits", milli_res::num_fractional_digits() == 3);
  14. check("milli traits resolution adjust",
  15. milli_res::res_adjust() == 1000);
  16. check("milli tick calculations",
  17. milli_res::to_tick_count(0,0,0,1) == 1);
  18. check("milli tick calculations",
  19. milli_res::to_tick_count(0,0,1,1) == 1001);
  20. check("milli tick calculations",
  21. milli_res::to_tick_count(0,1,0,0) == 60000);
  22. boost::int64_t one_hour_milli = 3600*1000;
  23. check("milli tick calculations",
  24. milli_res::to_tick_count(1,0,0,0) == one_hour_milli);
  25. check("micro traits num digits", micro_res::num_fractional_digits() == 6);
  26. check("micro traits resolution adjust",
  27. micro_res::res_adjust() == 1000000);
  28. check("micro tick calculations",
  29. micro_res::to_tick_count(0,0,0,1) == 1);
  30. check("micro tick calculations",
  31. micro_res::to_tick_count(0,0,1,1) == 1000001);
  32. check("micro tick calculations",
  33. micro_res::to_tick_count(0,1,0,0) == 60000000);
  34. boost::int64_t one_hour_micro = 3600*1000;
  35. one_hour_micro = one_hour_micro*1000; //avoid compiler overflow!
  36. check("micro tick calculations",
  37. micro_res::to_tick_count(1,0,0,0) == one_hour_micro);
  38. check("nano traits num digits", nano_res::num_fractional_digits() == 9);
  39. check("nano traits resolution adjust",
  40. nano_res::res_adjust() == 1000000000);
  41. check("nano tick calculations",
  42. nano_res::to_tick_count(0,0,0,1) == 1);
  43. check("nano tick calculations",
  44. nano_res::to_tick_count(0,0,1,1) == 1000000001);
  45. boost::int64_t one_minute_nano = 60*1000*1000;
  46. one_minute_nano = one_minute_nano*1000;
  47. check("nano tick calculations",
  48. nano_res::to_tick_count(0,1,0,0) == one_minute_nano);
  49. //skip io on VC6 b/c of lack of operator<< for int64
  50. #if (defined(BOOST_MSVC) && (_MSC_VER < 1300))
  51. #else
  52. std::cout << one_hour_micro << std::endl;
  53. #endif
  54. boost::int64_t one_hour_nano = one_hour_micro*1000;
  55. #if (defined(BOOST_MSVC) && (_MSC_VER < 1300))
  56. #else
  57. std::cout << one_hour_nano << std::endl;
  58. #endif
  59. check("nano tick calculations",
  60. nano_res::to_tick_count(1,0,0,0) == one_hour_nano);
  61. return printTestStats();
  62. }