test_chrono.cpp revision 11986:c12e4625ab56
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 12#include "pybind11_tests.h" 13#include "constructor_stats.h" 14#include <pybind11/chrono.h> 15 16// Return the current time off the wall clock 17std::chrono::system_clock::time_point test_chrono1() { 18 return std::chrono::system_clock::now(); 19} 20 21// Round trip the passed in system clock time 22std::chrono::system_clock::time_point test_chrono2(std::chrono::system_clock::time_point t) { 23 return t; 24} 25 26// Round trip the passed in duration 27std::chrono::system_clock::duration test_chrono3(std::chrono::system_clock::duration d) { 28 return d; 29} 30 31// Difference between two passed in time_points 32std::chrono::system_clock::duration test_chrono4(std::chrono::system_clock::time_point a, std::chrono::system_clock::time_point b) { 33 return a - b; 34} 35 36// Return the current time off the steady_clock 37std::chrono::steady_clock::time_point test_chrono5() { 38 return std::chrono::steady_clock::now(); 39} 40 41// Round trip a steady clock timepoint 42std::chrono::steady_clock::time_point test_chrono6(std::chrono::steady_clock::time_point t) { 43 return t; 44} 45 46// Roundtrip a duration in microseconds from a float argument 47std::chrono::microseconds test_chrono7(std::chrono::microseconds t) { 48 return t; 49} 50 51test_initializer chrono([] (py::module &m) { 52 m.def("test_chrono1", &test_chrono1); 53 m.def("test_chrono2", &test_chrono2); 54 m.def("test_chrono3", &test_chrono3); 55 m.def("test_chrono4", &test_chrono4); 56 m.def("test_chrono5", &test_chrono5); 57 m.def("test_chrono6", &test_chrono6); 58 m.def("test_chrono7", &test_chrono7); 59}); 60