Fixed -Wshadow warnings
[libcds.git] / test / unit / intrusive-set / intrusive_split_lazy_nogc.cpp
1 /*
2     This file is a part of libcds - Concurrent Data Structures library
3
4     (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2017
5
6     Source code repo: http://github.com/khizmax/libcds/
7     Download: http://sourceforge.net/projects/libcds/files/
8
9     Redistribution and use in source and binary forms, with or without
10     modification, are permitted provided that the following conditions are met:
11
12     * Redistributions of source code must retain the above copyright notice, this
13       list of conditions and the following disclaimer.
14
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.
18
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.
29 */
30
31 #include "test_intrusive_set_nogc.h"
32
33 #include <cds/intrusive/lazy_list_nogc.h>
34 #include <cds/intrusive/split_list_nogc.h>
35 #include <cds/intrusive/free_list.h>
36
37 #include <mutex>
38
39 namespace {
40     namespace ci = cds::intrusive;
41     typedef cds::gc::nogc gc_type;
42
43     class IntrusiveSplitListLazySet_NoGC : public cds_test::intrusive_set_nogc
44     {
45     protected:
46         typedef cds_test::intrusive_set_nogc base_class;
47
48     protected:
49         typedef typename base_class::base_int_item< ci::split_list::node< ci::lazy_list::node<gc_type>>>   base_item_type;
50         typedef typename base_class::base_int_item< ci::split_list::node< ci::lazy_list::node<gc_type, std::mutex >>>   base_mutex_item_type;
51         typedef typename base_class::member_int_item< ci::split_list::node< ci::lazy_list::node<gc_type>>> member_item_type;
52         typedef typename base_class::member_int_item< ci::split_list::node< ci::lazy_list::node<gc_type, std::mutex>>> member_mutex_item_type;
53
54         //void SetUp()
55         //{}
56
57         //void TearDown()
58         //{}
59     };
60
61
62     TEST_F( IntrusiveSplitListLazySet_NoGC, base_cmp )
63     {
64         typedef ci::LazyList< gc_type
65             , base_item_type
66             ,ci::lazy_list::make_traits<
67                 ci::opt::hook< ci::lazy_list::base_hook< ci::opt::gc< gc_type > > >
68                 ,ci::opt::compare< cmp<base_item_type> >
69                 ,ci::opt::disposer< mock_disposer >
70                 ,ci::opt::back_off< cds::backoff::pause >
71             >::type
72         > bucket_type;
73
74         typedef ci::SplitListSet< gc_type, bucket_type,
75             ci::split_list::make_traits<
76                 ci::opt::hash< hash_int >
77             >::type
78         > set_type;
79
80         set_type s( kSize, 2 );
81         test( s );
82     }
83
84     TEST_F( IntrusiveSplitListLazySet_NoGC, base_less )
85     {
86         typedef ci::LazyList< gc_type
87             , base_item_type
88             ,ci::lazy_list::make_traits<
89                 ci::opt::hook< ci::lazy_list::base_hook< ci::opt::gc< gc_type >>>
90                 ,ci::opt::less< less<base_item_type> >
91                 ,ci::opt::disposer< mock_disposer >
92             >::type
93         > bucket_type;
94
95         typedef ci::SplitListSet< gc_type, bucket_type,
96             ci::split_list::make_traits<
97                 ci::opt::hash< hash_int >
98                 , ci::opt::item_counter< cds::atomicity::item_counter >
99             >::type
100         > set_type;
101
102         set_type s( kSize, 2 );
103         test( s );
104     }
105
106     TEST_F( IntrusiveSplitListLazySet_NoGC, base_cmpmix )
107     {
108         struct list_traits : public ci::lazy_list::traits
109         {
110             typedef ci::lazy_list::base_hook< ci::opt::gc<gc_type>> hook;
111             typedef base_class::less<base_item_type> less;
112             typedef cmp<base_item_type> compare;
113             typedef mock_disposer disposer;
114         };
115         typedef ci::LazyList< gc_type, base_item_type, list_traits > bucket_type;
116
117         struct set_traits : public ci::split_list::traits
118         {
119             typedef hash_int hash;
120             typedef simple_item_counter item_counter;
121             typedef ci::split_list::stat<> stat;
122         };
123         typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
124
125         set_type s( kSize, 2 );
126         test( s );
127     }
128
129     TEST_F( IntrusiveSplitListLazySet_NoGC, base_mutex )
130     {
131         struct list_traits : public ci::lazy_list::traits
132         {
133             typedef ci::lazy_list::base_hook< ci::opt::gc<gc_type>, ci::opt::lock_type<std::mutex>> hook;
134             typedef base_class::less<base_mutex_item_type> less;
135             typedef cmp<base_mutex_item_type> compare;
136             typedef mock_disposer disposer;
137         };
138         typedef ci::LazyList< gc_type, base_mutex_item_type, list_traits > bucket_type;
139
140         struct set_traits : public ci::split_list::traits
141         {
142             typedef hash_int hash;
143             typedef simple_item_counter item_counter;
144             typedef cds::backoff::empty back_off;
145         };
146         typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
147
148         set_type s( kSize, 2 );
149         test( s );
150     }
151
152     TEST_F( IntrusiveSplitListLazySet_NoGC, base_static_bucket_table )
153     {
154         struct list_traits: public ci::lazy_list::traits
155         {
156             typedef ci::lazy_list::base_hook< ci::opt::gc<gc_type>> hook;
157             typedef base_class::less<base_item_type> less;
158             typedef cmp<base_item_type> compare;
159             typedef mock_disposer disposer;
160         };
161         typedef ci::LazyList< gc_type, base_item_type, list_traits > bucket_type;
162
163         struct set_traits: public ci::split_list::traits
164         {
165             typedef hash_int hash;
166             typedef simple_item_counter item_counter;
167             typedef ci::split_list::stat<> stat;
168             enum {
169                 dynamic_bucket_table = false
170             };
171         };
172         typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
173
174         set_type s( kSize, 2 );
175         test( s );
176     }
177
178     TEST_F( IntrusiveSplitListLazySet_NoGC, base_static_bucket_table_free_list )
179     {
180         struct list_traits: public ci::lazy_list::traits
181         {
182             typedef ci::lazy_list::base_hook< ci::opt::gc<gc_type>> hook;
183             typedef base_class::less<base_item_type> less;
184             typedef mock_disposer disposer;
185         };
186         typedef ci::LazyList< gc_type, base_item_type, list_traits > bucket_type;
187
188         struct set_traits: public ci::split_list::traits
189         {
190             typedef hash_int hash;
191             typedef simple_item_counter item_counter;
192             typedef ci::split_list::stat<> stat;
193             enum {
194                 dynamic_bucket_table = false
195             };
196             typedef ci::FreeList free_list;
197         };
198         typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
199
200         set_type s( kSize, 2 );
201         test( s );
202     }
203
204     TEST_F( IntrusiveSplitListLazySet_NoGC, base_free_list )
205     {
206         struct list_traits: public ci::lazy_list::traits
207         {
208             typedef ci::lazy_list::base_hook< ci::opt::gc<gc_type>> hook;
209             typedef cmp<base_item_type> compare;
210             typedef mock_disposer disposer;
211         };
212         typedef ci::LazyList< gc_type, base_item_type, list_traits > bucket_type;
213
214         struct set_traits: public ci::split_list::traits
215         {
216             typedef hash_int hash;
217             typedef simple_item_counter item_counter;
218             typedef ci::split_list::stat<> stat;
219             typedef ci::FreeList free_list;
220         };
221         typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
222
223         set_type s( kSize, 2 );
224         test( s );
225     }
226
227     TEST_F( IntrusiveSplitListLazySet_NoGC, member_cmp )
228     {
229         typedef ci::LazyList< gc_type
230             ,member_item_type
231             ,ci::lazy_list::make_traits<
232                 ci::opt::hook< ci::lazy_list::member_hook<
233                     offsetof( member_item_type, hMember ),
234                     ci::opt::gc<gc_type>
235                 > >
236                 ,ci::opt::compare< cmp<member_item_type> >
237                 ,ci::opt::disposer< mock_disposer >
238             >::type
239         >    bucket_type;
240
241         typedef ci::SplitListSet< gc_type, bucket_type,
242             ci::split_list::make_traits<
243                 ci::opt::hash< hash_int >
244             >::type
245         > set_type;
246
247         set_type s( kSize, 2 );
248         test( s );
249     }
250
251     TEST_F( IntrusiveSplitListLazySet_NoGC, member_less )
252     {
253         typedef ci::LazyList< gc_type
254             , member_item_type
255             ,ci::lazy_list::make_traits<
256                 ci::opt::hook< ci::lazy_list::member_hook<
257                     offsetof( member_item_type, hMember ),
258                     ci::opt::gc<gc_type>
259                 > >
260                 ,ci::opt::less< less<member_item_type> >
261                 ,ci::opt::disposer< mock_disposer >
262             >::type
263         > bucket_type;
264
265         typedef ci::SplitListSet< gc_type, bucket_type,
266             ci::split_list::make_traits<
267                 ci::opt::hash< hash_int >
268                 , ci::opt::back_off< cds::backoff::pause >
269             >::type
270         > set_type;
271
272         set_type s( kSize, 2 );
273         test( s );
274     }
275
276     TEST_F( IntrusiveSplitListLazySet_NoGC, member_cmpmix )
277     {
278         struct list_traits : public ci::lazy_list::traits
279         {
280             typedef ci::lazy_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc<gc_type>> hook;
281             typedef base_class::less<member_item_type> less;
282             typedef cmp<member_item_type> compare;
283             typedef mock_disposer disposer;
284         };
285         typedef ci::LazyList< gc_type, member_item_type, list_traits > bucket_type;
286
287         struct set_traits : public ci::split_list::traits
288         {
289             typedef hash_int hash;
290             typedef simple_item_counter item_counter;
291         };
292         typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
293
294         set_type s( kSize, 2 );
295         test( s );
296     }
297
298     TEST_F( IntrusiveSplitListLazySet_NoGC, member_mutex )
299     {
300         struct list_traits : public ci::lazy_list::traits
301         {
302             typedef ci::lazy_list::member_hook< offsetof( member_mutex_item_type, hMember ), ci::opt::gc<gc_type>, ci::opt::lock_type<std::mutex>> hook;
303             typedef base_class::less<member_mutex_item_type> less;
304             typedef cmp<member_mutex_item_type> compare;
305             typedef mock_disposer disposer;
306         };
307         typedef ci::LazyList< gc_type, member_mutex_item_type, list_traits > bucket_type;
308
309         struct set_traits : public ci::split_list::traits
310         {
311             typedef hash_int hash;
312             typedef simple_item_counter item_counter;
313         };
314         typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
315
316         set_type s( kSize, 2 );
317         test( s );
318     }
319
320     TEST_F( IntrusiveSplitListLazySet_NoGC, member_static_bucket_table )
321     {
322         struct list_traits: public ci::lazy_list::traits
323         {
324             typedef ci::lazy_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc<gc_type>> hook;
325             typedef base_class::less<member_item_type> less;
326             typedef cmp<member_item_type> compare;
327             typedef mock_disposer disposer;
328         };
329         typedef ci::LazyList< gc_type, member_item_type, list_traits > bucket_type;
330
331         struct set_traits: public ci::split_list::traits
332         {
333             typedef hash_int hash;
334             typedef simple_item_counter item_counter;
335             enum {
336                 dynamic_bucket_table = false
337             };
338         };
339         typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
340
341         set_type s( kSize, 2 );
342         test( s );
343     }
344
345     TEST_F( IntrusiveSplitListLazySet_NoGC, member_static_bucket_table_free_list )
346     {
347         struct list_traits: public ci::lazy_list::traits
348         {
349             typedef ci::lazy_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc<gc_type>> hook;
350             typedef base_class::less<member_item_type> less;
351             typedef mock_disposer disposer;
352         };
353         typedef ci::LazyList< gc_type, member_item_type, list_traits > bucket_type;
354
355         struct set_traits: public ci::split_list::traits
356         {
357             typedef hash_int hash;
358             typedef simple_item_counter item_counter;
359             enum {
360                 dynamic_bucket_table = false
361             };
362             typedef ci::FreeList free_list;
363         };
364         typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
365
366         set_type s( kSize, 2 );
367         test( s );
368     }
369
370     TEST_F( IntrusiveSplitListLazySet_NoGC, member_free_list )
371     {
372         struct list_traits: public ci::lazy_list::traits
373         {
374             typedef ci::lazy_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc<gc_type>> hook;
375             typedef cmp<member_item_type> compare;
376             typedef mock_disposer disposer;
377         };
378         typedef ci::LazyList< gc_type, member_item_type, list_traits > bucket_type;
379
380         struct set_traits: public ci::split_list::traits
381         {
382             typedef hash_int hash;
383             typedef simple_item_counter item_counter;
384             typedef ci::FreeList free_list;
385         };
386         typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
387
388         set_type s( kSize, 2 );
389         test( s );
390     }
391
392 } // namespace