test_chrono.cpp revision 12391:ceeca8b41e4b
1/* 2 tests/test_chrono.cpp -- test conversions to/from std::chrono types 3 4 Copyright (c) 2016 Trent Houliston <trent@houliston.me> and 5 Wenzel Jakob <wenzel.jakob@epfl.ch> 6 7 All rights reserved. Use of this source code is governed by a 8 BSD-style license that can be found in the LICENSE file. 9*/ 10 11#include "pybind11_tests.h" 12#include <pybind11/chrono.h> 13 14TEST_SUBMODULE(chrono, m) { 15 using system_time = std::chrono::system_clock::time_point; 16 using steady_time = std::chrono::steady_clock::time_point; 17 // test_chrono_system_clock 18 // Return the current time off the wall clock 19 m.def("test_chrono1", []() { return std::chrono::system_clock::now(); }); 20 21 // test_chrono_system_clock_roundtrip 22 // Round trip the passed in system clock time 23 m.def("test_chrono2", [](system_time t) { return t; }); 24 25 // test_chrono_duration_roundtrip 26 // Round trip the passed in duration 27 m.def("test_chrono3", [](std::chrono::system_clock::duration d) { return d; }); 28 29 // test_chrono_duration_subtraction_equivalence 30 // Difference between two passed in time_points 31 m.def("test_chrono4", [](system_time a, system_time b) { return a - b; }); 32 33 // test_chrono_steady_clock 34 // Return the current time off the steady_clock 35 m.def("test_chrono5", []() { return std::chrono::steady_clock::now(); }); 36 37 // test_chrono_steady_clock_roundtrip 38 // Round trip a steady clock timepoint 39 m.def("test_chrono6", [](steady_time t) { return t; }); 40 41 // test_floating_point_duration 42 // Roundtrip a duration in microseconds from a float argument 43 m.def("test_chrono7", [](std::chrono::microseconds t) { return t; }); 44 // Float durations (issue #719) 45 m.def("test_chrono_float_diff", [](std::chrono::duration<float> a, std::chrono::duration<float> b) { 46 return a - b; }); 47} 48