1 | // Copyright (C) 2001-2003 |
---|
2 | // William E. Kempf |
---|
3 | // |
---|
4 | // Permission to use, copy, modify, distribute and sell this software |
---|
5 | // and its documentation for any purpose is hereby granted without fee, |
---|
6 | // provided that the above copyright notice appear in all copies and |
---|
7 | // that both that copyright notice and this permission notice appear |
---|
8 | // in supporting documentation. William E. Kempf makes no representations |
---|
9 | // about the suitability of this software for any purpose. |
---|
10 | // It is provided "as is" without express or implied warranty. |
---|
11 | |
---|
12 | #include <boost/thread/detail/config.hpp> |
---|
13 | |
---|
14 | #include <boost/thread/xtime.hpp> |
---|
15 | |
---|
16 | #include <boost/test/unit_test.hpp> |
---|
17 | |
---|
18 | void test_xtime_cmp() |
---|
19 | { |
---|
20 | boost::xtime xt1, xt2, cur; |
---|
21 | BOOST_CHECK_EQUAL( |
---|
22 | boost::xtime_get(&cur, boost::TIME_UTC), |
---|
23 | static_cast<int>(boost::TIME_UTC)); |
---|
24 | |
---|
25 | xt1 = xt2 = cur; |
---|
26 | xt1.nsec -= 1; |
---|
27 | xt2.nsec += 1; |
---|
28 | |
---|
29 | BOOST_CHECK(boost::xtime_cmp(xt1, cur) < 0); |
---|
30 | BOOST_CHECK(boost::xtime_cmp(xt2, cur) > 0); |
---|
31 | BOOST_CHECK(boost::xtime_cmp(cur, cur) == 0); |
---|
32 | |
---|
33 | xt1 = xt2 = cur; |
---|
34 | xt1.sec -= 1; |
---|
35 | xt2.sec += 1; |
---|
36 | |
---|
37 | BOOST_CHECK(boost::xtime_cmp(xt1, cur) < 0); |
---|
38 | BOOST_CHECK(boost::xtime_cmp(xt2, cur) > 0); |
---|
39 | BOOST_CHECK(boost::xtime_cmp(cur, cur) == 0); |
---|
40 | } |
---|
41 | |
---|
42 | void test_xtime_get() |
---|
43 | { |
---|
44 | boost::xtime orig, cur, old; |
---|
45 | BOOST_CHECK_EQUAL( |
---|
46 | boost::xtime_get(&orig, |
---|
47 | boost::TIME_UTC), static_cast<int>(boost::TIME_UTC)); |
---|
48 | old = orig; |
---|
49 | |
---|
50 | for (int x=0; x < 100; ++x) |
---|
51 | { |
---|
52 | BOOST_CHECK_EQUAL( |
---|
53 | boost::xtime_get(&cur, boost::TIME_UTC), |
---|
54 | static_cast<int>(boost::TIME_UTC)); |
---|
55 | BOOST_CHECK(boost::xtime_cmp(cur, orig) >= 0); |
---|
56 | BOOST_CHECK(boost::xtime_cmp(cur, old) >= 0); |
---|
57 | old = cur; |
---|
58 | } |
---|
59 | } |
---|
60 | |
---|
61 | boost::unit_test_framework::test_suite* init_unit_test_suite(int, char*[]) |
---|
62 | { |
---|
63 | boost::unit_test_framework::test_suite* test = |
---|
64 | BOOST_TEST_SUITE("Boost.Threads: xtime test suite"); |
---|
65 | |
---|
66 | test->add(BOOST_TEST_CASE(&test_xtime_cmp)); |
---|
67 | test->add(BOOST_TEST_CASE(&test_xtime_get)); |
---|
68 | |
---|
69 | return test; |
---|
70 | } |
---|