You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.8 KiB

  1. /*
  2. tests/test_chrono.cpp -- test conversions to/from std::chrono types
  3. Copyright (c) 2016 Trent Houliston <trent@houliston.me> and
  4. Wenzel Jakob <wenzel.jakob@epfl.ch>
  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 "constructor_stats.h"
  10. #include <pybind11/chrono.h>
  11. // Return the current time off the wall clock
  12. std::chrono::system_clock::time_point test_chrono1() {
  13. return std::chrono::system_clock::now();
  14. }
  15. // Round trip the passed in system clock time
  16. std::chrono::system_clock::time_point test_chrono2(std::chrono::system_clock::time_point t) {
  17. return t;
  18. }
  19. // Round trip the passed in duration
  20. std::chrono::system_clock::duration test_chrono3(std::chrono::system_clock::duration d) {
  21. return d;
  22. }
  23. // Difference between two passed in time_points
  24. std::chrono::system_clock::duration test_chrono4(std::chrono::system_clock::time_point a, std::chrono::system_clock::time_point b) {
  25. return a - b;
  26. }
  27. // Return the current time off the steady_clock
  28. std::chrono::steady_clock::time_point test_chrono5() {
  29. return std::chrono::steady_clock::now();
  30. }
  31. // Round trip a steady clock timepoint
  32. std::chrono::steady_clock::time_point test_chrono6(std::chrono::steady_clock::time_point t) {
  33. return t;
  34. }
  35. // Roundtrip a duration in microseconds from a float argument
  36. std::chrono::microseconds test_chrono7(std::chrono::microseconds t) {
  37. return t;
  38. }
  39. test_initializer chrono([] (py::module &m) {
  40. m.def("test_chrono1", &test_chrono1);
  41. m.def("test_chrono2", &test_chrono2);
  42. m.def("test_chrono3", &test_chrono3);
  43. m.def("test_chrono4", &test_chrono4);
  44. m.def("test_chrono5", &test_chrono5);
  45. m.def("test_chrono6", &test_chrono6);
  46. m.def("test_chrono7", &test_chrono7);
  47. });