Merge pull request #63 from mgalimullin/cmake-update
[libcds.git] / test / unit / intrusive-set / intrusive_michael_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-2016
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/michael_set_nogc.h>
35
36 #include <mutex>
37
38 namespace {
39     namespace ci = cds::intrusive;
40     typedef cds::gc::nogc gc_type;
41
42     class IntrusiveMichaelLazySet_NoGC : public cds_test::intrusive_set_nogc
43     {
44     protected:
45         typedef cds_test::intrusive_set_nogc base_class;
46
47     protected:
48         typedef typename base_class::base_int_item< ci::lazy_list::node<gc_type>>   base_item_type;
49         typedef typename base_class::base_int_item< ci::lazy_list::node<gc_type, std::mutex>>   base_mutex_item_type;
50         typedef typename base_class::member_int_item< ci::lazy_list::node<gc_type>> member_item_type;
51         typedef typename base_class::member_int_item< ci::lazy_list::node<gc_type, std::mutex>> member_mutex_item_type;
52
53         //void SetUp()
54         //{}
55
56         //void TearDown()
57         //{}
58     };
59
60
61     TEST_F( IntrusiveMichaelLazySet_NoGC, base_cmp )
62     {
63         typedef ci::LazyList< gc_type
64             , base_item_type
65             ,ci::lazy_list::make_traits<
66                 ci::opt::hook< ci::lazy_list::base_hook< ci::opt::gc< gc_type > > >
67                 ,ci::opt::compare< cmp<base_item_type> >
68                 ,ci::opt::disposer< mock_disposer >
69                 ,ci::opt::back_off< cds::backoff::pause >
70             >::type
71         > bucket_type;
72
73         typedef ci::MichaelHashSet< gc_type, bucket_type,
74             ci::michael_set::make_traits<
75                 ci::opt::hash< hash_int >
76             >::type
77         > set_type;
78
79         set_type s( kSize, 2 );
80         test( s );
81     }
82
83     TEST_F( IntrusiveMichaelLazySet_NoGC, base_less )
84     {
85         typedef ci::LazyList< gc_type
86             , base_item_type
87             ,ci::lazy_list::make_traits<
88                 ci::opt::hook< ci::lazy_list::base_hook< ci::opt::gc< gc_type >>>
89                 ,ci::opt::less< less<base_item_type> >
90                 ,ci::opt::disposer< mock_disposer >
91             >::type
92         > bucket_type;
93
94         typedef ci::MichaelHashSet< gc_type, bucket_type,
95             ci::michael_set::make_traits<
96                 ci::opt::hash< hash_int >
97             >::type
98         > set_type;
99
100         set_type s( kSize, 2 );
101         test( s );
102     }
103
104     TEST_F( IntrusiveMichaelLazySet_NoGC, base_cmpmix )
105     {
106         struct list_traits : public ci::lazy_list::traits
107         {
108             typedef ci::lazy_list::base_hook< ci::opt::gc<gc_type>> hook;
109             typedef base_class::less<base_item_type> less;
110             typedef cmp<base_item_type> compare;
111             typedef mock_disposer disposer;
112         };
113         typedef ci::LazyList< gc_type, base_item_type, list_traits > bucket_type;
114
115         struct set_traits : public ci::michael_set::traits
116         {
117             typedef hash_int hash;
118             typedef simple_item_counter item_counter;
119         };
120         typedef ci::MichaelHashSet< gc_type, bucket_type, set_traits > set_type;
121
122         set_type s( kSize, 2 );
123         test( s );
124     }
125
126     TEST_F( IntrusiveMichaelLazySet_NoGC, base_mutex )
127     {
128         struct list_traits : public ci::lazy_list::traits
129         {
130             typedef ci::lazy_list::base_hook< ci::opt::gc<gc_type>, ci::opt::lock_type<std::mutex>> hook;
131             typedef base_class::less<base_mutex_item_type> less;
132             typedef cmp<base_mutex_item_type> compare;
133             typedef mock_disposer disposer;
134         };
135         typedef ci::LazyList< gc_type, base_mutex_item_type, list_traits > bucket_type;
136
137         struct set_traits : public ci::michael_set::traits
138         {
139             typedef hash_int hash;
140             typedef simple_item_counter item_counter;
141         };
142         typedef ci::MichaelHashSet< gc_type, bucket_type, set_traits > set_type;
143
144         set_type s( kSize, 2 );
145         test( s );
146     }
147
148     TEST_F( IntrusiveMichaelLazySet_NoGC, base_stat )
149     {
150         struct list_traits: public ci::lazy_list::traits
151         {
152             typedef ci::lazy_list::base_hook< ci::opt::gc<gc_type>> hook;
153             typedef base_class::less<base_item_type> less;
154             typedef mock_disposer disposer;
155             typedef ci::lazy_list::stat<> stat;
156         };
157         typedef ci::LazyList< gc_type, base_item_type, list_traits > bucket_type;
158
159         struct set_traits: public ci::michael_set::traits
160         {
161             typedef hash_int hash;
162             typedef simple_item_counter item_counter;
163         };
164         typedef ci::MichaelHashSet< gc_type, bucket_type, set_traits > set_type;
165
166         set_type s( kSize, 2 );
167         test( s );
168     }
169
170     TEST_F( IntrusiveMichaelLazySet_NoGC, base_wrapped_stat )
171     {
172         struct list_traits: public ci::lazy_list::traits
173         {
174             typedef ci::lazy_list::base_hook< ci::opt::gc<gc_type>> hook;
175             typedef base_class::less<base_item_type> less;
176             typedef mock_disposer disposer;
177             typedef ci::lazy_list::wrapped_stat<> stat;
178         };
179         typedef ci::LazyList< gc_type, base_item_type, list_traits > bucket_type;
180
181         struct set_traits: public ci::michael_set::traits
182         {
183             typedef hash_int hash;
184             typedef simple_item_counter item_counter;
185         };
186         typedef ci::MichaelHashSet< gc_type, bucket_type, set_traits > set_type;
187
188         set_type s( kSize, 2 );
189         test( s );
190     }
191
192     TEST_F( IntrusiveMichaelLazySet_NoGC, member_cmp )
193     {
194         typedef ci::LazyList< gc_type
195             ,member_item_type
196             ,ci::lazy_list::make_traits<
197                 ci::opt::hook< ci::lazy_list::member_hook<
198                     offsetof( member_item_type, hMember ),
199                     ci::opt::gc<gc_type>
200                 > >
201                 ,ci::opt::compare< cmp<member_item_type> >
202                 ,ci::opt::disposer< mock_disposer >
203             >::type
204         >    bucket_type;
205
206         typedef ci::MichaelHashSet< gc_type, bucket_type,
207             ci::michael_set::make_traits<
208                 ci::opt::hash< hash_int >
209             >::type
210         > set_type;
211
212         set_type s( kSize, 2 );
213         test( s );
214     }
215
216     TEST_F( IntrusiveMichaelLazySet_NoGC, member_less )
217     {
218         typedef ci::LazyList< gc_type
219             , member_item_type
220             ,ci::lazy_list::make_traits<
221                 ci::opt::hook< ci::lazy_list::member_hook<
222                     offsetof( member_item_type, hMember ),
223                     ci::opt::gc<gc_type>
224                 > >
225                 ,ci::opt::less< less<member_item_type> >
226                 ,ci::opt::disposer< mock_disposer >
227             >::type
228         > bucket_type;
229
230         typedef ci::MichaelHashSet< gc_type, bucket_type,
231             ci::michael_set::make_traits<
232                 ci::opt::hash< hash_int >
233             >::type
234         > set_type;
235
236         set_type s( kSize, 2 );
237         test( s );
238     }
239
240     TEST_F( IntrusiveMichaelLazySet_NoGC, member_cmpmix )
241     {
242         struct list_traits : public ci::lazy_list::traits
243         {
244             typedef ci::lazy_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc<gc_type>> hook;
245             typedef base_class::less<member_item_type> less;
246             typedef cmp<member_item_type> compare;
247             typedef mock_disposer disposer;
248         };
249         typedef ci::LazyList< gc_type, member_item_type, list_traits > bucket_type;
250
251         struct set_traits : public ci::michael_set::traits
252         {
253             typedef hash_int hash;
254             typedef simple_item_counter item_counter;
255         };
256         typedef ci::MichaelHashSet< gc_type, bucket_type, set_traits > set_type;
257
258         set_type s( kSize, 2 );
259         test( s );
260     }
261
262     TEST_F( IntrusiveMichaelLazySet_NoGC, member_mutex )
263     {
264         struct list_traits : public ci::lazy_list::traits
265         {
266             typedef ci::lazy_list::member_hook< offsetof( member_mutex_item_type, hMember ), ci::opt::gc<gc_type>, ci::opt::lock_type<std::mutex>> hook;
267             typedef base_class::less<member_mutex_item_type> less;
268             typedef cmp<member_mutex_item_type> compare;
269             typedef mock_disposer disposer;
270         };
271         typedef ci::LazyList< gc_type, member_mutex_item_type, list_traits > bucket_type;
272
273         struct set_traits : public ci::michael_set::traits
274         {
275             typedef hash_int hash;
276             typedef simple_item_counter item_counter;
277         };
278         typedef ci::MichaelHashSet< gc_type, bucket_type, set_traits > set_type;
279
280         set_type s( kSize, 2 );
281         test( s );
282     }
283
284     TEST_F( IntrusiveMichaelLazySet_NoGC, member_stat )
285     {
286         struct list_traits: public ci::lazy_list::traits
287         {
288             typedef ci::lazy_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc<gc_type>> hook;
289             typedef cmp<member_item_type> compare;
290             typedef mock_disposer disposer;
291             typedef ci::lazy_list::stat<> stat;
292         };
293         typedef ci::LazyList< gc_type, member_item_type, list_traits > bucket_type;
294
295         struct set_traits: public ci::michael_set::traits
296         {
297             typedef hash_int hash;
298             typedef simple_item_counter item_counter;
299         };
300         typedef ci::MichaelHashSet< gc_type, bucket_type, set_traits > set_type;
301
302         set_type s( kSize, 2 );
303         test( s );
304     }
305
306     TEST_F( IntrusiveMichaelLazySet_NoGC, member_wrapped_stat )
307     {
308         struct list_traits: public ci::lazy_list::traits
309         {
310             typedef ci::lazy_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc<gc_type>> hook;
311             typedef cmp<member_item_type> compare;
312             typedef mock_disposer disposer;
313             typedef ci::lazy_list::wrapped_stat<> stat;
314         };
315         typedef ci::LazyList< gc_type, member_item_type, list_traits > bucket_type;
316
317         struct set_traits: public ci::michael_set::traits
318         {
319             typedef hash_int hash;
320             typedef simple_item_counter item_counter;
321         };
322         typedef ci::MichaelHashSet< gc_type, bucket_type, set_traits > set_type;
323
324         set_type s( kSize, 2 );
325         test( s );
326     }
327
328 } // namespace