Blame external/pybind11/tests/test_chrono.cpp

Packit 534379
/*
Packit 534379
    tests/test_chrono.cpp -- test conversions to/from std::chrono types
Packit 534379
Packit 534379
    Copyright (c) 2016 Trent Houliston <trent@houliston.me> and
Packit 534379
                       Wenzel Jakob <wenzel.jakob@epfl.ch>
Packit 534379
Packit 534379
    All rights reserved. Use of this source code is governed by a
Packit 534379
    BSD-style license that can be found in the LICENSE file.
Packit 534379
*/
Packit 534379
Packit 534379
#include "pybind11_tests.h"
Packit 534379
#include <pybind11/chrono.h>
Packit 534379
Packit 534379
TEST_SUBMODULE(chrono, m) {
Packit 534379
    using system_time = std::chrono::system_clock::time_point;
Packit 534379
    using steady_time = std::chrono::steady_clock::time_point;
Packit 534379
Packit 534379
    using timespan = std::chrono::duration<int64_t, std::nano>;
Packit 534379
    using timestamp = std::chrono::time_point<std::chrono::system_clock, timespan>;
Packit 534379
Packit 534379
    // test_chrono_system_clock
Packit 534379
    // Return the current time off the wall clock
Packit 534379
    m.def("test_chrono1", []() { return std::chrono::system_clock::now(); });
Packit 534379
Packit 534379
    // test_chrono_system_clock_roundtrip
Packit 534379
    // Round trip the passed in system clock time
Packit 534379
    m.def("test_chrono2", [](system_time t) { return t; });
Packit 534379
Packit 534379
    // test_chrono_duration_roundtrip
Packit 534379
    // Round trip the passed in duration
Packit 534379
    m.def("test_chrono3", [](std::chrono::system_clock::duration d) { return d; });
Packit 534379
Packit 534379
    // test_chrono_duration_subtraction_equivalence
Packit 534379
    // Difference between two passed in time_points
Packit 534379
    m.def("test_chrono4", [](system_time a, system_time b) { return a - b; });
Packit 534379
Packit 534379
    // test_chrono_steady_clock
Packit 534379
    // Return the current time off the steady_clock
Packit 534379
    m.def("test_chrono5", []() { return std::chrono::steady_clock::now(); });
Packit 534379
Packit 534379
    // test_chrono_steady_clock_roundtrip
Packit 534379
    // Round trip a steady clock timepoint
Packit 534379
    m.def("test_chrono6", [](steady_time t) { return t; });
Packit 534379
Packit 534379
    // test_floating_point_duration
Packit 534379
    // Roundtrip a duration in microseconds from a float argument
Packit 534379
    m.def("test_chrono7", [](std::chrono::microseconds t) { return t; });
Packit 534379
    // Float durations (issue #719)
Packit 534379
    m.def("test_chrono_float_diff", [](std::chrono::duration<float> a, std::chrono::duration<float> b) {
Packit 534379
        return a - b; });
Packit 534379
Packit 534379
    m.def("test_nano_timepoint", [](timestamp start, timespan delta) -> timestamp {
Packit 534379
        return start + delta;
Packit 534379
    });
Packit 534379
}