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/thread.hpp> |
---|
15 | #include <boost/thread/xtime.hpp> |
---|
16 | |
---|
17 | #include <boost/test/unit_test.hpp> |
---|
18 | |
---|
19 | #define DEFAULT_EXECUTION_MONITOR_TYPE execution_monitor::use_sleep_only |
---|
20 | #include <libs/thread/test/util.inl> |
---|
21 | |
---|
22 | int test_value; |
---|
23 | |
---|
24 | void simple_thread() |
---|
25 | { |
---|
26 | test_value = 999; |
---|
27 | } |
---|
28 | |
---|
29 | void comparison_thread(boost::thread* parent) |
---|
30 | { |
---|
31 | boost::thread thrd; |
---|
32 | BOOST_CHECK(thrd != *parent); |
---|
33 | boost::thread thrd2; |
---|
34 | BOOST_CHECK(thrd == thrd2); |
---|
35 | } |
---|
36 | |
---|
37 | void test_sleep() |
---|
38 | { |
---|
39 | boost::xtime xt = delay(3); |
---|
40 | boost::thread::sleep(xt); |
---|
41 | |
---|
42 | // Ensure it's in a range instead of checking actual equality due to time |
---|
43 | // lapse |
---|
44 | BOOST_CHECK(in_range(xt, 2)); |
---|
45 | } |
---|
46 | |
---|
47 | void do_test_creation() |
---|
48 | { |
---|
49 | test_value = 0; |
---|
50 | boost::thread thrd(&simple_thread); |
---|
51 | thrd.join(); |
---|
52 | BOOST_CHECK_EQUAL(test_value, 999); |
---|
53 | } |
---|
54 | |
---|
55 | void test_creation() |
---|
56 | { |
---|
57 | timed_test(&do_test_creation, 1); |
---|
58 | } |
---|
59 | |
---|
60 | void do_test_comparison() |
---|
61 | { |
---|
62 | boost::thread self; |
---|
63 | boost::thread thrd(bind(&comparison_thread, &self)); |
---|
64 | thrd.join(); |
---|
65 | } |
---|
66 | |
---|
67 | void test_comparison() |
---|
68 | { |
---|
69 | timed_test(&do_test_comparison, 1); |
---|
70 | } |
---|
71 | |
---|
72 | boost::unit_test_framework::test_suite* init_unit_test_suite(int, char*[]) |
---|
73 | { |
---|
74 | boost::unit_test_framework::test_suite* test = |
---|
75 | BOOST_TEST_SUITE("Boost.Threads: thread test suite"); |
---|
76 | |
---|
77 | test->add(BOOST_TEST_CASE(test_sleep)); |
---|
78 | test->add(BOOST_TEST_CASE(test_creation)); |
---|
79 | test->add(BOOST_TEST_CASE(test_comparison)); |
---|
80 | |
---|
81 | return test; |
---|
82 | } |
---|