From 04b91dfbf973404cf69a78d18e2f42906c51152d Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 11 Jun 2013 11:41:38 -0700 Subject: gras: added test for timer stuff --- tests/CMakeLists.txt | 1 + tests/chrono_time_test.cpp | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 tests/chrono_time_test.cpp (limited to 'tests') diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 797f858..761239e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -14,6 +14,7 @@ if (NOT Boost_FOUND) endif() set(test_sources + chrono_time_test.cpp block_props_test.cpp serialize_tags_test.cpp ) diff --git a/tests/chrono_time_test.cpp b/tests/chrono_time_test.cpp new file mode 100644 index 0000000..80c80ab --- /dev/null +++ b/tests/chrono_time_test.cpp @@ -0,0 +1,23 @@ +// Copyright (C) by Josh Blum. See LICENSE.txt for licensing information. + +#include +#include + +#include +#include //sleep + +BOOST_AUTO_TEST_CASE(test_chrono_time) +{ + gras::time_ticks_t t0 = gras::time_now(); + boost::this_thread::sleep(boost::posix_time::seconds(1)); + gras::time_ticks_t t1 = gras::time_now(); + + std::cout << "t0 " << t0 << std::endl; + std::cout << "t1 " << t1 << std::endl; + BOOST_CHECK(t1 > t0); + + const double delta_time = double(t1-t0)/gras::time_tps(); + std::cout << "delta_time " << delta_time << std::endl; + //this check allows +/- 0.5 seconds -- so it should always pass + BOOST_CHECK(delta_time < 1.5 and delta_time > 0.5); +} -- cgit