test_chrono.cpp 1.8 KB

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