2 This file is a part of libcds - Concurrent Data Structures library
4 (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016
6 Source code repo: http://github.com/khizmax/libcds/
7 Download: http://sourceforge.net/projects/libcds/files/
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions are met:
12 * Redistributions of source code must retain the above copyright notice, this
13 list of conditions and the following disclaimer.
15 * Redistributions in binary form must reproduce the above copyright notice,
16 this list of conditions and the following disclaimer in the documentation
17 and/or other materials provided with the distribution.
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include "cppunit/cppunit_proxy.h"
32 #include <cds/intrusive/fcstack.h>
34 #include <boost/intrusive/list.hpp>
38 class TestIntrusiveFCStack: public CppUnitMini::TestCase
41 template <typename Hook>
42 struct base_hook_item: public Hook
52 template <typename Hook>
53 struct member_hook_item
67 void operator ()( T * p )
73 template <class Stack>
80 template <class Stack>
81 void test_with( Stack& stack )
83 typedef typename Stack::value_type value_type;
85 CPPUNIT_ASSERT( stack.empty() );
87 value_type v1, v2, v3;
91 CPPUNIT_ASSERT( stack.push(v1));
92 CPPUNIT_ASSERT( !stack.empty() );
93 CPPUNIT_ASSERT( stack.push(v2));
94 CPPUNIT_ASSERT( !stack.empty() );
95 CPPUNIT_ASSERT( stack.push(v3));
96 CPPUNIT_ASSERT( !stack.empty() );
100 CPPUNIT_ASSERT( pv != nullptr );
101 CPPUNIT_ASSERT( pv->nVal == 3 );
102 CPPUNIT_ASSERT( !stack.empty() );
104 CPPUNIT_ASSERT( pv != nullptr );
105 CPPUNIT_ASSERT( pv->nVal == 2 );
106 CPPUNIT_ASSERT( !stack.empty() );
108 CPPUNIT_ASSERT( pv != nullptr );
109 CPPUNIT_ASSERT( pv->nVal == 1 );
110 CPPUNIT_ASSERT( stack.empty() );
112 CPPUNIT_ASSERT( pv == nullptr );
114 CPPUNIT_ASSERT( v1.nDisposeCount == 0 );
115 CPPUNIT_ASSERT( v2.nDisposeCount == 0 );
116 CPPUNIT_ASSERT( v3.nDisposeCount == 0 );
123 CPPUNIT_ASSERT( stack.empty() );
125 if ( !std::is_same<typename Stack::disposer, cds::intrusive::opt::v::empty_disposer>::value ) {
126 CPPUNIT_ASSERT( v1.nDisposeCount == 1 );
127 CPPUNIT_ASSERT( v2.nDisposeCount == 1 );
128 CPPUNIT_ASSERT( v3.nDisposeCount == 1 );
132 void FCStack_slist();
133 void FCStack_slist_mutex();
134 void FCStack_slist_elimination();
135 void FCStack_slist_elimination_stat();
136 void FCStack_slist_member();
137 void FCStack_slist_member_elimination();
138 void FCStack_slist_member_elimination_stat();
140 void FCStack_list_mutex();
141 void FCStack_list_elimination();
142 void FCStack_list_elimination_stat();
143 void FCStack_list_member();
144 void FCStack_list_member_elimination();
145 void FCStack_list_member_elimination_stat();
147 CPPUNIT_TEST_SUITE(TestIntrusiveFCStack)
148 CPPUNIT_TEST(FCStack_slist)
149 CPPUNIT_TEST(FCStack_slist_mutex)
150 CPPUNIT_TEST(FCStack_slist_elimination)
151 CPPUNIT_TEST(FCStack_slist_elimination_stat)
152 CPPUNIT_TEST(FCStack_slist_member)
153 CPPUNIT_TEST(FCStack_slist_member_elimination)
154 CPPUNIT_TEST(FCStack_slist_member_elimination_stat)
155 CPPUNIT_TEST(FCStack_list)
156 CPPUNIT_TEST(FCStack_list_mutex)
157 CPPUNIT_TEST(FCStack_list_elimination)
158 CPPUNIT_TEST(FCStack_list_elimination_stat)
159 CPPUNIT_TEST(FCStack_list_member)
160 CPPUNIT_TEST(FCStack_list_member_elimination)
161 CPPUNIT_TEST(FCStack_list_member_elimination_stat)
162 CPPUNIT_TEST_SUITE_END()
165 void TestIntrusiveFCStack::FCStack_slist()
167 typedef base_hook_item< boost::intrusive::slist_base_hook<> > value_type;
168 typedef cds::intrusive::FCStack< value_type, boost::intrusive::slist< value_type > > stack_type;
172 void TestIntrusiveFCStack::FCStack_slist_mutex()
174 typedef base_hook_item< boost::intrusive::slist_base_hook<> > value_type;
175 struct stack_traits : public cds::intrusive::fcstack::traits
177 typedef std::mutex lock_type;
179 typedef cds::intrusive::FCStack< value_type, boost::intrusive::slist< value_type >, stack_traits > stack_type;
183 void TestIntrusiveFCStack::FCStack_slist_elimination()
185 typedef base_hook_item< boost::intrusive::slist_base_hook<> > value_type;
186 struct stack_traits : public
187 cds::intrusive::fcstack::make_traits <
188 cds::opt::enable_elimination < true >
191 typedef cds::intrusive::FCStack< value_type, boost::intrusive::slist< value_type >, stack_traits > stack_type;
195 void TestIntrusiveFCStack::FCStack_slist_elimination_stat()
197 typedef base_hook_item< boost::intrusive::slist_base_hook<> > value_type;
198 typedef cds::intrusive::FCStack< value_type, boost::intrusive::slist< value_type >,
199 cds::intrusive::fcstack::make_traits<
200 cds::opt::enable_elimination< true >
201 ,cds::opt::stat< cds::intrusive::fcstack::stat<> >
207 void TestIntrusiveFCStack::FCStack_slist_member()
209 typedef member_hook_item< boost::intrusive::slist_member_hook<> > value_type;
210 typedef boost::intrusive::member_hook<value_type, boost::intrusive::slist_member_hook<>, &value_type::hMember> member_option;
212 typedef cds::intrusive::FCStack< value_type, boost::intrusive::slist< value_type, member_option > > stack_type;
216 void TestIntrusiveFCStack::FCStack_slist_member_elimination()
218 typedef member_hook_item< boost::intrusive::slist_member_hook<> > value_type;
219 typedef boost::intrusive::member_hook<value_type, boost::intrusive::slist_member_hook<>, &value_type::hMember> member_option;
221 typedef cds::intrusive::FCStack< value_type, boost::intrusive::slist< value_type, member_option >,
222 cds::intrusive::fcstack::make_traits<
223 cds::opt::enable_elimination< true >
229 void TestIntrusiveFCStack::FCStack_slist_member_elimination_stat()
231 typedef member_hook_item< boost::intrusive::slist_member_hook<> > value_type;
232 typedef boost::intrusive::member_hook<value_type, boost::intrusive::slist_member_hook<>, &value_type::hMember> member_option;
234 typedef cds::intrusive::FCStack< value_type, boost::intrusive::slist< value_type, member_option >,
235 cds::intrusive::fcstack::make_traits<
236 cds::opt::enable_elimination< true >
237 ,cds::opt::stat< cds::intrusive::fcstack::stat<> >
243 void TestIntrusiveFCStack::FCStack_list()
245 typedef base_hook_item< boost::intrusive::list_base_hook<> > value_type;
246 typedef cds::intrusive::FCStack< value_type, boost::intrusive::list< value_type > > stack_type;
250 void TestIntrusiveFCStack::FCStack_list_mutex()
252 typedef base_hook_item< boost::intrusive::list_base_hook<> > value_type;
253 typedef cds::intrusive::FCStack< value_type, boost::intrusive::list< value_type >,
254 cds::intrusive::fcstack::make_traits<
255 cds::opt::lock_type< std::mutex >
262 void TestIntrusiveFCStack::FCStack_list_elimination()
264 typedef base_hook_item< boost::intrusive::list_base_hook<> > value_type;
265 typedef cds::intrusive::FCStack< value_type, boost::intrusive::list< value_type >,
266 cds::intrusive::fcstack::make_traits<
267 cds::opt::enable_elimination< true >
273 void TestIntrusiveFCStack::FCStack_list_elimination_stat()
275 typedef base_hook_item< boost::intrusive::list_base_hook<> > value_type;
276 typedef cds::intrusive::FCStack< value_type, boost::intrusive::list< value_type >,
277 cds::intrusive::fcstack::make_traits<
278 cds::opt::enable_elimination< true >
279 ,cds::opt::stat< cds::intrusive::fcstack::stat<> >
285 void TestIntrusiveFCStack::FCStack_list_member()
287 typedef member_hook_item< boost::intrusive::list_member_hook<> > value_type;
288 typedef boost::intrusive::member_hook<value_type, boost::intrusive::list_member_hook<>, &value_type::hMember> member_option;
290 typedef cds::intrusive::FCStack< value_type, boost::intrusive::list< value_type, member_option > > stack_type;
294 void TestIntrusiveFCStack::FCStack_list_member_elimination()
296 typedef member_hook_item< boost::intrusive::list_member_hook<> > value_type;
297 typedef boost::intrusive::member_hook<value_type, boost::intrusive::list_member_hook<>, &value_type::hMember> member_option;
299 typedef cds::intrusive::FCStack< value_type, boost::intrusive::list< value_type, member_option >,
300 cds::intrusive::fcstack::make_traits<
301 cds::opt::enable_elimination< true >
307 void TestIntrusiveFCStack::FCStack_list_member_elimination_stat()
309 typedef member_hook_item< boost::intrusive::list_member_hook<> > value_type;
310 typedef boost::intrusive::member_hook<value_type, boost::intrusive::list_member_hook<>, &value_type::hMember> member_option;
312 typedef cds::intrusive::FCStack< value_type, boost::intrusive::list< value_type, member_option >,
313 cds::intrusive::fcstack::make_traits<
314 cds::opt::enable_elimination< true >
315 ,cds::opt::stat< cds::intrusive::fcstack::stat<> >
321 CPPUNIT_TEST_SUITE_REGISTRATION(stack::TestIntrusiveFCStack);