2
0
mirror of https://github.com/boostorg/thread.git synced 2026-01-20 05:02:37 +00:00
Files
thread/test/test_thread.cpp
William E. Kempf 125193dcfa Turned all tests into 'timed_test's.
[SVN r17053]
2003-01-27 22:44:06 +00:00

67 lines
1.3 KiB
C++

#include <boost/thread/thread.hpp>
#include <boost/thread/xtime.hpp>
#include <boost/test/unit_test.hpp>
#define DEFAULT_EXECUTION_MONITOR_TYPE execution_monitor::use_sleep_only
#include "util.inl"
int test_value;
void simple_thread()
{
test_value = 999;
}
void comparison_thread(boost::thread* parent)
{
boost::thread thrd;
BOOST_TEST(thrd != *parent);
BOOST_TEST(thrd == boost::thread());
}
void test_sleep()
{
boost::xtime xt = delay(3);
boost::thread::sleep(xt);
// Insure it's in a range instead of checking actual equality due to time lapse
BOOST_CHECK(in_range(xt));
}
void do_test_creation()
{
test_value = 0;
boost::thread thrd(&simple_thread);
thrd.join();
BOOST_CHECK_EQUAL(test_value, 999);
}
void test_creation()
{
timed_test(&do_test_creation, 1);
}
void do_test_comparison()
{
boost::thread self;
boost::thread thrd(bind(&comparison_thread, &self));
thrd.join();
}
void test_comparison()
{
timed_test(&do_test_comparison, 1);
}
boost::unit_test_framework::test_suite* init_unit_test_suite(int, char*[])
{
boost::unit_test_framework::test_suite* test = BOOST_TEST_SUITE("Boost.Threads: thread test suite");
test->add(BOOST_TEST_CASE(test_sleep));
test->add(BOOST_TEST_CASE(test_creation));
test->add(BOOST_TEST_CASE(test_comparison));
return test;
}