tagged_ptr_test.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright (C) 2011 Tim Blechmann
  2. //
  3. // Distributed under the Boost Software License, Version 1.0. (See
  4. // accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. #include <limits>
  7. #include <boost/lockfree/detail/tagged_ptr.hpp>
  8. #define BOOST_TEST_MAIN
  9. #ifdef BOOST_LOCKFREE_INCLUDE_TESTS
  10. #include <boost/test/included/unit_test.hpp>
  11. #else
  12. #include <boost/test/unit_test.hpp>
  13. #endif
  14. BOOST_AUTO_TEST_CASE( tagged_ptr_test )
  15. {
  16. using namespace boost::lockfree::detail;
  17. int a(1), b(2);
  18. typedef tagged_ptr<int>::tag_t tag_t;
  19. const tag_t max_tag = (std::numeric_limits<tag_t>::max)();
  20. {
  21. tagged_ptr<int> i (&a, 0);
  22. tagged_ptr<int> j (&b, 1);
  23. i = j;
  24. BOOST_REQUIRE_EQUAL(i.get_ptr(), &b);
  25. BOOST_REQUIRE_EQUAL(i.get_tag(), 1);
  26. }
  27. {
  28. tagged_ptr<int> i (&a, 0);
  29. tagged_ptr<int> j (i);
  30. BOOST_REQUIRE_EQUAL(i.get_ptr(), j.get_ptr());
  31. BOOST_REQUIRE_EQUAL(i.get_tag(), j.get_tag());
  32. }
  33. {
  34. tagged_ptr<int> i (&a, 0);
  35. BOOST_REQUIRE_EQUAL(i.get_tag() + 1, i.get_next_tag());
  36. }
  37. {
  38. tagged_ptr<int> j (&a, max_tag);
  39. BOOST_REQUIRE_EQUAL(j.get_next_tag(), 0);
  40. }
  41. {
  42. tagged_ptr<int> j (&a, max_tag - 1);
  43. BOOST_REQUIRE_EQUAL(j.get_next_tag(), max_tag);
  44. }
  45. }