// Copyright 2011 Vicente J. Botet Escriba // Distributed under the Boost Software License, Version 1.0. // See http://www.boost.org/LICENSE_1_0.txt #include #include #include #include #include #include template void test_good(std::string str, D res) { std::istringstream in(str + boost::chrono::clock_string::since()); boost::chrono::time_point tp; in >> tp; BOOST_TEST(in.eof()); BOOST_TEST(!in.fail()); BOOST_TEST( (tp == boost::chrono::time_point(res))); } template void test_fail(const char* str, D) { std::istringstream in(str + boost::chrono::clock_string::since()); boost::chrono::time_point tp; in >> tp; BOOST_TEST(in.fail()); BOOST_TEST( (tp == boost::chrono::time_point())); } template void test_fail_no_epoch(const char* str, D ) { std::istringstream in(str); boost::chrono::time_point tp; in >> tp; BOOST_TEST(in.fail()); BOOST_TEST( (tp == boost::chrono::time_point())); } template void test_fail_epoch(const char* str, D) { std::istringstream in(str); boost::chrono::time_point tp; in >> tp; BOOST_TEST(in.fail()); BOOST_TEST( (tp == boost::chrono::time_point())); } template void check_all() { using namespace boost::chrono; using namespace boost; test_good ("5000 hours", hours(5000)); test_good ("5000 minutes", minutes(5000)); test_good ("5000 seconds", seconds(5000)); test_good ("1 seconds", seconds(1)); test_good ("1 second", seconds(1)); test_good ("-1 seconds", seconds(-1)); test_good ("0 second", seconds(0)); test_good ("0 seconds", seconds(0)); test_good ("5000 milliseconds", milliseconds(5000)); test_good ("5000 microseconds", microseconds(5000)); test_good ("5000 nanoseconds", nanoseconds(5000)); test_good ("5000 deciseconds", duration (5000)); test_good ("5000 [1/30]seconds", duration > (5000)); test_good ("5000 h", hours(5000)); #if BOOST_CHRONO_VERSION==2 test_good("5000 min", minutes(5000)); #else test_good ("5000 m", minutes(5000)); #endif test_good ("5000 s", seconds(5000)); test_good ("5000 ms", milliseconds(5000)); test_good ("5000 ns", nanoseconds(5000)); test_good ("5000 ds", duration (5000)); test_good ("5000 [1/30]s", duration > (5000)); test_good ("5000 milliseconds", seconds(5)); test_good ("5 milliseconds", nanoseconds(5000000)); test_good ("4000 ms", seconds(4)); test_fail ("3001 ms", seconds(3)); test_fail_epoch ("3001 ms", seconds(3)); test_fail_epoch ("3001 ms since", seconds(3)); } int main() { std::cout << "high_resolution_clock=" << std::endl; check_all (); #ifdef BOOST_CHRONO_HAS_CLOCK_STEADY std::cout << "steady_clock=" << std::endl; check_all (); #endif //std::cout << "system_clock="; //check_all(); #if defined(BOOST_CHRONO_HAS_THREAD_CLOCK) std::cout << "thread_clock="<< std::endl; check_all(); #endif #if defined(BOOST_CHRONO_HAS_PROCESS_CLOCKS) std::cout << "process_real_cpu_clock=" << std::endl; check_all (); std::cout << "process_user_cpu_clock=" << std::endl; check_all (); std::cout << "process_system_cpu_clock=" << std::endl; check_all (); std::cout << "process_cpu_clock=" << std::endl; check_all (); #endif return boost::report_errors(); }