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
7#include <limits>
8
9#include <boost/lockfree/detail/tagged_ptr.hpp>
10
11#define BOOST_TEST_MAIN
12#ifdef BOOST_LOCKFREE_INCLUDE_TESTS
13#include <boost/test/included/unit_test.hpp>
14#else
15#include <boost/test/unit_test.hpp>
16#endif
17
18BOOST_AUTO_TEST_CASE( tagged_ptr_test )
19{
20 using namespace boost::lockfree::detail;
21 int a(1), b(2);
22
23 typedef tagged_ptr<int>::tag_t tag_t;
24 const tag_t max_tag = (std::numeric_limits<tag_t>::max)();
25
26 {
27 tagged_ptr<int> i (&a, 0);
28 tagged_ptr<int> j (&b, 1);
29
30 i = j;
31
32 BOOST_REQUIRE_EQUAL(i.get_ptr(), &b);
33 BOOST_REQUIRE_EQUAL(i.get_tag(), 1);
34 }
35
36 {
37 tagged_ptr<int> i (&a, 0);
38 tagged_ptr<int> j (i);
39
40 BOOST_REQUIRE_EQUAL(i.get_ptr(), j.get_ptr());
41 BOOST_REQUIRE_EQUAL(i.get_tag(), j.get_tag());
42 }
43
44 {
45 tagged_ptr<int> i (&a, 0);
46 BOOST_REQUIRE_EQUAL(i.get_tag() + 1, i.get_next_tag());
47 }
48
49 {
50 tagged_ptr<int> j (&a, max_tag);
51 BOOST_REQUIRE_EQUAL(j.get_next_tag(), 0);
52 }
53
54 {
55 tagged_ptr<int> j (&a, max_tag - 1);
56 BOOST_REQUIRE_EQUAL(j.get_next_tag(), max_tag);
57 }
58}
59

source code of boost/libs/lockfree/test/tagged_ptr_test.cpp