3 #include "cppunit/cppunit_proxy.h"
4 #include <cds/intrusive/fcstack.h>
6 #include <boost/intrusive/list.hpp>
10 class TestIntrusiveFCStack: public CppUnitMini::TestCase
13 template <typename Hook>
14 struct base_hook_item: public Hook
24 template <typename Hook>
25 struct member_hook_item
39 void operator ()( T * p )
45 template <class Stack>
52 template <class Stack>
53 void test_with( Stack& stack )
55 typedef typename Stack::value_type value_type;
57 CPPUNIT_ASSERT( stack.empty() );
59 value_type v1, v2, v3;
63 CPPUNIT_ASSERT( stack.push(v1));
64 CPPUNIT_ASSERT( !stack.empty() );
65 CPPUNIT_ASSERT( stack.push(v2));
66 CPPUNIT_ASSERT( !stack.empty() );
67 CPPUNIT_ASSERT( stack.push(v3));
68 CPPUNIT_ASSERT( !stack.empty() );
72 CPPUNIT_ASSERT( pv != nullptr );
73 CPPUNIT_ASSERT( pv->nVal == 3 );
74 CPPUNIT_ASSERT( !stack.empty() );
76 CPPUNIT_ASSERT( pv != nullptr );
77 CPPUNIT_ASSERT( pv->nVal == 2 );
78 CPPUNIT_ASSERT( !stack.empty() );
80 CPPUNIT_ASSERT( pv != nullptr );
81 CPPUNIT_ASSERT( pv->nVal == 1 );
82 CPPUNIT_ASSERT( stack.empty() );
84 CPPUNIT_ASSERT( pv == nullptr );
86 CPPUNIT_ASSERT( v1.nDisposeCount == 0 );
87 CPPUNIT_ASSERT( v2.nDisposeCount == 0 );
88 CPPUNIT_ASSERT( v3.nDisposeCount == 0 );
95 CPPUNIT_ASSERT( stack.empty() );
97 if ( !std::is_same<typename Stack::disposer, cds::intrusive::opt::v::empty_disposer>::value ) {
98 CPPUNIT_ASSERT( v1.nDisposeCount == 1 );
99 CPPUNIT_ASSERT( v2.nDisposeCount == 1 );
100 CPPUNIT_ASSERT( v3.nDisposeCount == 1 );
104 void FCStack_slist();
105 void FCStack_slist_mutex();
106 void FCStack_slist_elimination();
107 void FCStack_slist_elimination_stat();
108 void FCStack_slist_member();
109 void FCStack_slist_member_elimination();
110 void FCStack_slist_member_elimination_stat();
112 void FCStack_list_mutex();
113 void FCStack_list_elimination();
114 void FCStack_list_elimination_stat();
115 void FCStack_list_member();
116 void FCStack_list_member_elimination();
117 void FCStack_list_member_elimination_stat();
119 CPPUNIT_TEST_SUITE(TestIntrusiveFCStack)
120 CPPUNIT_TEST(FCStack_slist)
121 CPPUNIT_TEST(FCStack_slist_mutex)
122 CPPUNIT_TEST(FCStack_slist_elimination)
123 CPPUNIT_TEST(FCStack_slist_elimination_stat)
124 CPPUNIT_TEST(FCStack_slist_member)
125 CPPUNIT_TEST(FCStack_slist_member_elimination)
126 CPPUNIT_TEST(FCStack_slist_member_elimination_stat)
127 CPPUNIT_TEST(FCStack_list)
128 CPPUNIT_TEST(FCStack_list_mutex)
129 CPPUNIT_TEST(FCStack_list_elimination)
130 CPPUNIT_TEST(FCStack_list_elimination_stat)
131 CPPUNIT_TEST(FCStack_list_member)
132 CPPUNIT_TEST(FCStack_list_member_elimination)
133 CPPUNIT_TEST(FCStack_list_member_elimination_stat)
134 CPPUNIT_TEST_SUITE_END()
137 void TestIntrusiveFCStack::FCStack_slist()
139 typedef base_hook_item< boost::intrusive::slist_base_hook<> > value_type;
140 typedef cds::intrusive::FCStack< value_type, boost::intrusive::slist< value_type > > stack_type;
144 void TestIntrusiveFCStack::FCStack_slist_mutex()
146 typedef base_hook_item< boost::intrusive::slist_base_hook<> > value_type;
147 typedef cds::intrusive::FCStack< value_type, boost::intrusive::slist< value_type >,
148 cds::intrusive::fcstack::make_traits<
149 cds::opt::lock_type< std::mutex >
155 void TestIntrusiveFCStack::FCStack_slist_elimination()
157 typedef base_hook_item< boost::intrusive::slist_base_hook<> > value_type;
158 typedef cds::intrusive::FCStack< value_type, boost::intrusive::slist< value_type >,
159 cds::intrusive::fcstack::make_traits<
160 cds::opt::enable_elimination< true >
166 void TestIntrusiveFCStack::FCStack_slist_elimination_stat()
168 typedef base_hook_item< boost::intrusive::slist_base_hook<> > value_type;
169 typedef cds::intrusive::FCStack< value_type, boost::intrusive::slist< value_type >,
170 cds::intrusive::fcstack::make_traits<
171 cds::opt::enable_elimination< true >
172 ,cds::opt::stat< cds::intrusive::fcstack::stat<> >
178 void TestIntrusiveFCStack::FCStack_slist_member()
180 typedef member_hook_item< boost::intrusive::slist_member_hook<> > value_type;
181 typedef boost::intrusive::member_hook<value_type, boost::intrusive::slist_member_hook<>, &value_type::hMember> member_option;
183 typedef cds::intrusive::FCStack< value_type, boost::intrusive::slist< value_type, member_option > > stack_type;
187 void TestIntrusiveFCStack::FCStack_slist_member_elimination()
189 typedef member_hook_item< boost::intrusive::slist_member_hook<> > value_type;
190 typedef boost::intrusive::member_hook<value_type, boost::intrusive::slist_member_hook<>, &value_type::hMember> member_option;
192 typedef cds::intrusive::FCStack< value_type, boost::intrusive::slist< value_type, member_option >,
193 cds::intrusive::fcstack::make_traits<
194 cds::opt::enable_elimination< true >
200 void TestIntrusiveFCStack::FCStack_slist_member_elimination_stat()
202 typedef member_hook_item< boost::intrusive::slist_member_hook<> > value_type;
203 typedef boost::intrusive::member_hook<value_type, boost::intrusive::slist_member_hook<>, &value_type::hMember> member_option;
205 typedef cds::intrusive::FCStack< value_type, boost::intrusive::slist< value_type, member_option >,
206 cds::intrusive::fcstack::make_traits<
207 cds::opt::enable_elimination< true >
208 ,cds::opt::stat< cds::intrusive::fcstack::stat<> >
214 void TestIntrusiveFCStack::FCStack_list()
216 typedef base_hook_item< boost::intrusive::list_base_hook<> > value_type;
217 typedef cds::intrusive::FCStack< value_type, boost::intrusive::list< value_type > > stack_type;
221 void TestIntrusiveFCStack::FCStack_list_mutex()
223 typedef base_hook_item< boost::intrusive::list_base_hook<> > value_type;
224 typedef cds::intrusive::FCStack< value_type, boost::intrusive::list< value_type >,
225 cds::intrusive::fcstack::make_traits<
226 cds::opt::lock_type< std::mutex >
233 void TestIntrusiveFCStack::FCStack_list_elimination()
235 typedef base_hook_item< boost::intrusive::list_base_hook<> > value_type;
236 typedef cds::intrusive::FCStack< value_type, boost::intrusive::list< value_type >,
237 cds::intrusive::fcstack::make_traits<
238 cds::opt::enable_elimination< true >
244 void TestIntrusiveFCStack::FCStack_list_elimination_stat()
246 typedef base_hook_item< boost::intrusive::list_base_hook<> > value_type;
247 typedef cds::intrusive::FCStack< value_type, boost::intrusive::list< value_type >,
248 cds::intrusive::fcstack::make_traits<
249 cds::opt::enable_elimination< true >
250 ,cds::opt::stat< cds::intrusive::fcstack::stat<> >
256 void TestIntrusiveFCStack::FCStack_list_member()
258 typedef member_hook_item< boost::intrusive::list_member_hook<> > value_type;
259 typedef boost::intrusive::member_hook<value_type, boost::intrusive::list_member_hook<>, &value_type::hMember> member_option;
261 typedef cds::intrusive::FCStack< value_type, boost::intrusive::list< value_type, member_option > > stack_type;
265 void TestIntrusiveFCStack::FCStack_list_member_elimination()
267 typedef member_hook_item< boost::intrusive::list_member_hook<> > value_type;
268 typedef boost::intrusive::member_hook<value_type, boost::intrusive::list_member_hook<>, &value_type::hMember> member_option;
270 typedef cds::intrusive::FCStack< value_type, boost::intrusive::list< value_type, member_option >,
271 cds::intrusive::fcstack::make_traits<
272 cds::opt::enable_elimination< true >
278 void TestIntrusiveFCStack::FCStack_list_member_elimination_stat()
280 typedef member_hook_item< boost::intrusive::list_member_hook<> > value_type;
281 typedef boost::intrusive::member_hook<value_type, boost::intrusive::list_member_hook<>, &value_type::hMember> member_option;
283 typedef cds::intrusive::FCStack< value_type, boost::intrusive::list< value_type, member_option >,
284 cds::intrusive::fcstack::make_traits<
285 cds::opt::enable_elimination< true >
286 ,cds::opt::stat< cds::intrusive::fcstack::stat<> >
292 CPPUNIT_TEST_SUITE_REGISTRATION(stack::TestIntrusiveFCStack);