blob: 6d0db3f2fc3ff7d12c30f9cdd2a508670b516c4c [file] [log] [blame]
Junxiao Shi61c5ef32014-01-24 20:59:30 -07001/* -*- 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
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080011namespace nfd {
Junxiao Shi61c5ef32014-01-24 20:59:30 -070012
13BOOST_AUTO_TEST_SUITE(CoreTime)
14
15BOOST_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 Afanasyev920af2f2014-01-25 22:56:11 -080022BOOST_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 Shi61c5ef32014-01-24 20:59:30 -070045BOOST_AUTO_TEST_SUITE_END()
46
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080047} // namespace nfd