test_thread_move.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright (C) 2007-9 Anthony Williams
  2. //
  3. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. #define BOOST_TEST_MODULE Boost.Threads: thread move test suite
  6. #include <boost/thread/thread_only.hpp>
  7. #include <boost/test/unit_test.hpp>
  8. void do_nothing(boost::thread::id* my_id)
  9. {
  10. *my_id=boost::this_thread::get_id();
  11. }
  12. BOOST_AUTO_TEST_CASE(test_move_on_construction)
  13. {
  14. boost::thread::id the_id;
  15. boost::thread x=boost::thread(do_nothing,&the_id);
  16. boost::thread::id x_id=x.get_id();
  17. x.join();
  18. BOOST_CHECK_EQUAL(the_id,x_id);
  19. }
  20. boost::thread make_thread(boost::thread::id* the_id)
  21. {
  22. return boost::thread(do_nothing,the_id);
  23. }
  24. BOOST_AUTO_TEST_CASE(test_move_from_function_return)
  25. {
  26. boost::thread::id the_id;
  27. boost::thread x=make_thread(&the_id);
  28. boost::thread::id x_id=x.get_id();
  29. x.join();
  30. BOOST_CHECK_EQUAL(the_id,x_id);
  31. }
  32. BOOST_AUTO_TEST_CASE(test_move_assign)
  33. {
  34. boost::thread::id the_id;
  35. boost::thread x(do_nothing,&the_id);
  36. boost::thread y;
  37. y=boost::move(x);
  38. boost::thread::id y_id=y.get_id();
  39. y.join();
  40. BOOST_CHECK_EQUAL(the_id,y_id);
  41. }