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