ToStringChrono.tests.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #define CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER
  2. #include "catch.hpp"
  3. #include <chrono>
  4. #include <cstdint>
  5. TEST_CASE("Stringifying std::chrono::duration helpers", "[toString][chrono]") {
  6. // No literals because we still support c++11
  7. auto hour = std::chrono::hours(1);
  8. auto minute = std::chrono::minutes(1);
  9. auto seconds = std::chrono::seconds(60);
  10. auto micro = std::chrono::microseconds(1);
  11. auto milli = std::chrono::milliseconds(1);
  12. auto nano = std::chrono::nanoseconds(1);
  13. REQUIRE(minute == seconds);
  14. REQUIRE(hour != seconds);
  15. REQUIRE(micro != milli);
  16. REQUIRE(nano != micro);
  17. }
  18. TEST_CASE("Stringifying std::chrono::duration with weird ratios", "[toString][chrono]") {
  19. std::chrono::duration<int64_t, std::ratio<30>> half_minute(1);
  20. std::chrono::duration<int64_t, std::ratio<1, 1000000000000>> pico_second(1);
  21. std::chrono::duration<int64_t, std::ratio<1, 1000000000000000>> femto_second(1);
  22. std::chrono::duration<int64_t, std::ratio<1, 1000000000000000000>> atto_second(1);
  23. REQUIRE(half_minute != femto_second);
  24. REQUIRE(pico_second != atto_second);
  25. }
  26. TEST_CASE("Stringifying std::chrono::time_point<system_clock>", "[toString][chrono]") {
  27. auto now = std::chrono::system_clock::now();
  28. auto later = now + std::chrono::minutes(2);
  29. REQUIRE(now != later);
  30. }
  31. TEST_CASE("Stringifying std::chrono::time_point<Clock>", "[toString][chrono][!nonportable]") {
  32. auto now = std::chrono::high_resolution_clock::now();
  33. auto later = now + std::chrono::minutes(2);
  34. REQUIRE(now != later);
  35. auto now2 = std::chrono::steady_clock::now();
  36. auto later2 = now2 + std::chrono::minutes(2);
  37. REQUIRE(now2 != later2);
  38. }