Junxiao Shi | 61c5ef3 | 2014-01-24 20:59:30 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2014 Named Data Networking Project |
| 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
| 7 | #include "core/time.hpp" |
| 8 | |
| 9 | #include <boost/test/unit_test.hpp> |
| 10 | |
| 11 | namespace ndn { |
| 12 | |
| 13 | BOOST_AUTO_TEST_SUITE(CoreTime) |
| 14 | |
| 15 | BOOST_AUTO_TEST_CASE(Now) |
| 16 | { |
| 17 | time::Point p1 = time::now(); |
| 18 | time::Point p2 = time::now(); |
| 19 | BOOST_CHECK_LE(p1, p2); |
| 20 | } |
| 21 | |
Alexander Afanasyev | 920af2f | 2014-01-25 22:56:11 -0800 | [diff] [blame] | 22 | BOOST_AUTO_TEST_CASE(Operations) |
| 23 | { |
| 24 | // helpers |
| 25 | BOOST_CHECK_GT(time::seconds(1), time::milliseconds(1)); |
| 26 | BOOST_CHECK_GT(time::milliseconds(1), time::microseconds(1)); |
| 27 | BOOST_CHECK_GT(time::microseconds(1), time::nanoseconds(1)); |
| 28 | |
| 29 | // duration operations + helpers |
| 30 | BOOST_CHECK_EQUAL(time::seconds(8) + time::microseconds(101), time::nanoseconds(8000101000)); |
| 31 | BOOST_CHECK_EQUAL(time::seconds(7) - time::milliseconds(234), time::microseconds(6766000)); |
| 32 | |
| 33 | // point operations |
| 34 | time::Point p1 = time::now(); |
| 35 | time::Point p2 = p1 + time::milliseconds(10000); |
| 36 | time::Point p3 = p2 - time::microseconds(5000000); |
| 37 | BOOST_CHECK_LE(p1, p2); |
| 38 | BOOST_CHECK_LE(p1, p3); |
| 39 | BOOST_CHECK_LE(p3, p2); |
| 40 | |
| 41 | BOOST_CHECK_EQUAL(p2 - p1, time::seconds(10)); |
| 42 | BOOST_CHECK_EQUAL(p3 - p1, time::seconds(5)); |
| 43 | } |
| 44 | |
Junxiao Shi | 61c5ef3 | 2014-01-24 20:59:30 -0700 | [diff] [blame] | 45 | BOOST_AUTO_TEST_SUITE_END() |
| 46 | |
| 47 | } // namespace ndn |