| 1 |
|
| 2 |
// Copyright Catch2 Authors |
| 3 |
// Distributed under the Boost Software License, Version 1.0. |
| 4 |
// (See accompanying file LICENSE.txt or copy at |
| 5 |
// https://www.boost.org/LICENSE_1_0.txt) |
| 6 |
|
| 7 |
// SPDX-License-Identifier: BSL-1.0 |
| 8 |
|
| 9 |
#include <catch2/catch_test_macros.hpp> |
| 10 |
|
| 11 |
#include <chrono> |
| 12 |
#include <cstdint> |
| 13 |
|
| 14 |
TEST_CASE("Stringifying std::chrono::duration helpers", "[toString][chrono]") { |
| 15 |
// No literals because we still support c++11 |
| 16 |
auto hour = std::chrono::hours(1); |
| 17 |
auto minute = std::chrono::minutes(1); |
| 18 |
auto seconds = std::chrono::seconds(60); |
| 19 |
auto micro = std::chrono::microseconds(1); |
| 20 |
auto milli = std::chrono::milliseconds(1); |
| 21 |
auto nano = std::chrono::nanoseconds(1); |
| 22 |
REQUIRE(minute == seconds); |
| 23 |
REQUIRE(hour != seconds); |
| 24 |
REQUIRE(micro != milli); |
| 25 |
REQUIRE(nano != micro); |
| 26 |
} |
| 27 |
|
| 28 |
TEST_CASE("Stringifying std::chrono::duration with weird ratios", "[toString][chrono]") { |
| 29 |
std::chrono::duration<int64_t, std::ratio<30>> half_minute(1); |
| 30 |
std::chrono::duration<int64_t, std::ratio<1, 1000000000000>> pico_second(1); |
| 31 |
std::chrono::duration<int64_t, std::ratio<1, 1000000000000000>> femto_second(1); |
| 32 |
std::chrono::duration<int64_t, std::ratio<1, 1000000000000000000>> atto_second(1); |
| 33 |
REQUIRE(half_minute != femto_second); |
| 34 |
REQUIRE(pico_second != atto_second); |
| 35 |
} |
| 36 |
|
| 37 |
TEST_CASE("Stringifying std::chrono::time_point<system_clock>", "[toString][chrono]") { |
| 38 |
auto now = std::chrono::system_clock::now(); |
| 39 |
auto later = now + std::chrono::minutes(2); |
| 40 |
REQUIRE(now != later); |
| 41 |
} |
| 42 |
|
| 43 |
TEST_CASE("Stringifying std::chrono::time_point<Clock>", "[toString][chrono][!nonportable]") { |
| 44 |
auto now = std::chrono::high_resolution_clock::now(); |
| 45 |
auto later = now + std::chrono::minutes(2); |
| 46 |
REQUIRE(now != later); |
| 47 |
|
| 48 |
auto now2 = std::chrono::steady_clock::now(); |
| 49 |
auto later2 = now2 + std::chrono::minutes(2); |
| 50 |
REQUIRE(now2 != later2); |
| 51 |
} |
| 52 |
|
| 53 |
TEST_CASE( "system_clock timepoint with non-default duration", "[toString][chrono]" ) { |
| 54 |
std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> |
| 55 |
tp1, tp2; |
| 56 |
CHECK( tp1 == tp2 ); |
| 57 |
} |