arithmetic_pass.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is dual licensed under the MIT and the University of Illinois Open
  6. // Source Licenses. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. // Adaptation to Boost of the libcxx
  10. // Copyright 2010 Vicente J. Botet Escriba
  11. // Distributed under the Boost Software License, Version 1.0.
  12. // See http://www.boost.org/LICENSE_1_0.txt
  13. #include <boost/chrono/chrono.hpp>
  14. #include <boost/detail/lightweight_test.hpp>
  15. #ifdef BOOST_NO_CXX11_CONSTEXPR
  16. #define BOOST_CONSTEXPR_ASSERT(C) BOOST_TEST(C)
  17. #else
  18. #include <boost/static_assert.hpp>
  19. #define BOOST_CONSTEXPR_ASSERT(C) BOOST_STATIC_ASSERT(C)
  20. #endif
  21. int main()
  22. {
  23. {
  24. typedef boost::chrono::system_clock Clock;
  25. typedef boost::chrono::milliseconds Duration;
  26. boost::chrono::time_point<Clock, Duration> t(Duration(3));
  27. t += Duration(2);
  28. BOOST_TEST(t.time_since_epoch() == Duration(5));
  29. }
  30. {
  31. typedef boost::chrono::system_clock Clock;
  32. typedef boost::chrono::milliseconds Duration;
  33. boost::chrono::time_point<Clock, Duration> t(Duration(3));
  34. t -= Duration(2);
  35. BOOST_TEST(t.time_since_epoch() == Duration(1));
  36. }
  37. {
  38. typedef boost::chrono::system_clock Clock;
  39. typedef boost::chrono::milliseconds Duration1;
  40. typedef boost::chrono::microseconds Duration2;
  41. boost::chrono::time_point<Clock, Duration1> t1(Duration1(3));
  42. boost::chrono::time_point<Clock, Duration2> t2 = t1 - Duration2(5);
  43. BOOST_TEST(t2.time_since_epoch() == Duration2(2995));
  44. }
  45. {
  46. typedef boost::chrono::system_clock Clock;
  47. typedef boost::chrono::milliseconds Duration1;
  48. typedef boost::chrono::microseconds Duration2;
  49. BOOST_CONSTEXPR boost::chrono::time_point<Clock, Duration1> t1(Duration1(3));
  50. BOOST_CONSTEXPR boost::chrono::time_point<Clock, Duration2> t2 = t1 - Duration2(5);
  51. BOOST_CONSTEXPR_ASSERT(t2.time_since_epoch() == Duration2(2995));
  52. }
  53. {
  54. typedef boost::chrono::system_clock Clock;
  55. typedef boost::chrono::milliseconds Duration1;
  56. typedef boost::chrono::microseconds Duration2;
  57. boost::chrono::time_point<Clock, Duration1> t1(Duration1(3));
  58. boost::chrono::time_point<Clock, Duration2> t2(Duration2(5));
  59. BOOST_TEST( (t1 - t2) == Duration2(2995));
  60. }
  61. {
  62. typedef boost::chrono::system_clock Clock;
  63. typedef boost::chrono::milliseconds Duration1;
  64. typedef boost::chrono::microseconds Duration2;
  65. BOOST_CONSTEXPR boost::chrono::time_point<Clock, Duration1> t1(Duration1(3));
  66. BOOST_CONSTEXPR boost::chrono::time_point<Clock, Duration2> t2(Duration2(5));
  67. BOOST_CONSTEXPR_ASSERT( (t1 - t2) == Duration2(2995));
  68. }
  69. {
  70. typedef boost::chrono::system_clock Clock;
  71. typedef boost::chrono::milliseconds Duration1;
  72. typedef boost::chrono::microseconds Duration2;
  73. boost::chrono::time_point<Clock, Duration1> t1(Duration1(3));
  74. boost::chrono::time_point<Clock, Duration2> t2 = t1 + Duration2(5);
  75. BOOST_TEST(t2.time_since_epoch() == Duration2(3005));
  76. t2 = Duration2(6) + t1;
  77. BOOST_TEST(t2.time_since_epoch() == Duration2(3006));
  78. }
  79. {
  80. typedef boost::chrono::system_clock Clock;
  81. typedef boost::chrono::milliseconds Duration1;
  82. typedef boost::chrono::microseconds Duration2;
  83. BOOST_CONSTEXPR boost::chrono::time_point<Clock, Duration1> t1(Duration1(3));
  84. BOOST_CONSTEXPR boost::chrono::time_point<Clock, Duration2> t2 = t1 + Duration2(5);
  85. BOOST_CONSTEXPR_ASSERT(t2.time_since_epoch() == Duration2(3005));
  86. BOOST_CONSTEXPR boost::chrono::time_point<Clock, Duration2> t3 = Duration2(6) + t1;
  87. BOOST_CONSTEXPR_ASSERT(t3.time_since_epoch() == Duration2(3006));
  88. }
  89. #ifdef BOOST_CHRONO_EXTENSIONS
  90. {
  91. typedef boost::chrono::system_clock Clock;
  92. typedef boost::chrono::milliseconds Duration;
  93. boost::chrono::time_point<Clock, Duration> t(Duration(3));
  94. t += 2;
  95. BOOST_TEST(t.time_since_epoch() == Duration(5));
  96. }
  97. {
  98. typedef boost::chrono::system_clock Clock;
  99. typedef boost::chrono::milliseconds Duration;
  100. boost::chrono::time_point<Clock, Duration> t(Duration(3));
  101. t++;
  102. BOOST_TEST(t.time_since_epoch() == Duration(4));
  103. }
  104. {
  105. typedef boost::chrono::system_clock Clock;
  106. typedef boost::chrono::milliseconds Duration;
  107. boost::chrono::time_point<Clock, Duration> t(Duration(3));
  108. ++t;
  109. BOOST_TEST(t.time_since_epoch() == Duration(4));
  110. }
  111. {
  112. typedef boost::chrono::system_clock Clock;
  113. typedef boost::chrono::milliseconds Duration;
  114. boost::chrono::time_point<Clock, Duration> t(Duration(3));
  115. t -= 2;
  116. BOOST_TEST(t.time_since_epoch() == Duration(1));
  117. }
  118. #if 0
  119. {
  120. typedef boost::chrono::system_clock Clock;
  121. typedef boost::chrono::milliseconds Duration1;
  122. typedef boost::chrono::microseconds Duration2;
  123. boost::chrono::time_point<Clock, Duration1> t1(Duration1(3));
  124. boost::chrono::time_point<Clock, Duration2> t2 = t1 - Duration2(5);
  125. BOOST_TEST(t2.time_since_epoch() == Duration2(2995));
  126. }
  127. {
  128. typedef boost::chrono::system_clock Clock;
  129. typedef boost::chrono::milliseconds Duration1;
  130. typedef boost::chrono::microseconds Duration2;
  131. boost::chrono::time_point<Clock, Duration1> t1(Duration1(3));
  132. boost::chrono::time_point<Clock, Duration2> t2(Duration2(5));
  133. BOOST_TEST((t1 - t2) == Duration2(2995));
  134. }
  135. {
  136. typedef boost::chrono::system_clock Clock;
  137. typedef boost::chrono::milliseconds Duration1;
  138. typedef boost::chrono::microseconds Duration2;
  139. boost::chrono::time_point<Clock, Duration1> t1(Duration1(3));
  140. boost::chrono::time_point<Clock, Duration2> t2 = t1 + Duration2(5);
  141. BOOST_TEST(t2.time_since_epoch() == Duration2(3005));
  142. t2 = Duration2(6) + t1;
  143. BOOST_TEST(t2.time_since_epoch() == Duration2(3006));
  144. }
  145. #endif
  146. #endif
  147. return boost::report_errors();
  148. }