Changelog
[libcds.git] / test / unit / 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-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/split_list_nogc.h>
35
36 #include <mutex>
37
38 namespace {
39     namespace ci = cds::intrusive;
40     typedef cds::gc::nogc gc_type;
41
42     class IntrusiveSplitListLazySet_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::split_list::node< ci::lazy_list::node<gc_type>>>   base_item_type;
49         typedef typename base_class::base_int_item< ci::split_list::node< ci::lazy_list::node<gc_type, std::mutex >>>   base_mutex_item_type;
50         typedef typename base_class::member_int_item< ci::split_list::node< ci::lazy_list::node<gc_type>>> member_item_type;
51         typedef typename base_class::member_int_item< ci::split_list::node< 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( IntrusiveSplitListLazySet_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::SplitListSet< gc_type, bucket_type,
74             ci::split_list::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( IntrusiveSplitListLazySet_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::SplitListSet< gc_type, bucket_type,
95             ci::split_list::make_traits<
96                 ci::opt::hash< hash_int >
97                 , ci::opt::item_counter< cds::atomicity::item_counter >
98             >::type
99         > set_type;
100
101         set_type s( kSize, 2 );
102         test( s );
103     }
104
105     TEST_F( IntrusiveSplitListLazySet_NoGC, base_cmpmix )
106     {
107         struct list_traits : public ci::lazy_list::traits
108         {
109             typedef ci::lazy_list::base_hook< ci::opt::gc<gc_type>> hook;
110             typedef base_class::less<base_item_type> less;
111             typedef cmp<base_item_type> compare;
112             typedef mock_disposer disposer;
113         };
114         typedef ci::LazyList< gc_type, base_item_type, list_traits > bucket_type;
115
116         struct set_traits : public ci::split_list::traits
117         {
118             typedef hash_int hash;
119             typedef simple_item_counter item_counter;
120             typedef ci::split_list::stat<> stat;
121         };
122         typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
123
124         set_type s( kSize, 2 );
125         test( s );
126     }
127
128     TEST_F( IntrusiveSplitListLazySet_NoGC, base_mutex )
129     {
130         struct list_traits : public ci::lazy_list::traits
131         {
132             typedef ci::lazy_list::base_hook< ci::opt::gc<gc_type>, ci::opt::lock_type<std::mutex>> hook;
133             typedef base_class::less<base_mutex_item_type> less;
134             typedef cmp<base_mutex_item_type> compare;
135             typedef mock_disposer disposer;
136         };
137         typedef ci::LazyList< gc_type, base_mutex_item_type, list_traits > bucket_type;
138
139         struct set_traits : public ci::split_list::traits
140         {
141             typedef hash_int hash;
142             typedef simple_item_counter item_counter;
143             typedef cds::backoff::empty back_off;
144         };
145         typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
146
147         set_type s( kSize, 2 );
148         test( s );
149     }
150
151
152     TEST_F( IntrusiveSplitListLazySet_NoGC, member_cmp )
153     {
154         typedef ci::LazyList< gc_type
155             ,member_item_type
156             ,ci::lazy_list::make_traits<
157                 ci::opt::hook< ci::lazy_list::member_hook<
158                     offsetof( member_item_type, hMember ),
159                     ci::opt::gc<gc_type>
160                 > >
161                 ,ci::opt::compare< cmp<member_item_type> >
162                 ,ci::opt::disposer< mock_disposer >
163             >::type
164         >    bucket_type;
165
166         typedef ci::SplitListSet< gc_type, bucket_type,
167             ci::split_list::make_traits<
168                 ci::opt::hash< hash_int >
169             >::type
170         > set_type;
171
172         set_type s( kSize, 2 );
173         test( s );
174     }
175
176     TEST_F( IntrusiveSplitListLazySet_NoGC, member_less )
177     {
178         typedef ci::LazyList< gc_type
179             , member_item_type
180             ,ci::lazy_list::make_traits<
181                 ci::opt::hook< ci::lazy_list::member_hook<
182                     offsetof( member_item_type, hMember ),
183                     ci::opt::gc<gc_type>
184                 > >
185                 ,ci::opt::less< less<member_item_type> >
186                 ,ci::opt::disposer< mock_disposer >
187             >::type
188         > bucket_type;
189
190         typedef ci::SplitListSet< gc_type, bucket_type,
191             ci::split_list::make_traits<
192                 ci::opt::hash< hash_int >
193                 , ci::opt::back_off< cds::backoff::pause >
194             >::type
195         > set_type;
196
197         set_type s( kSize, 2 );
198         test( s );
199     }
200
201     TEST_F( IntrusiveSplitListLazySet_NoGC, member_cmpmix )
202     {
203         struct list_traits : public ci::lazy_list::traits
204         {
205             typedef ci::lazy_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc<gc_type>> hook;
206             typedef base_class::less<member_item_type> less;
207             typedef cmp<member_item_type> compare;
208             typedef mock_disposer disposer;
209         };
210         typedef ci::LazyList< gc_type, member_item_type, list_traits > bucket_type;
211
212         struct set_traits : public ci::split_list::traits
213         {
214             typedef hash_int hash;
215             typedef simple_item_counter item_counter;
216         };
217         typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
218
219         set_type s( kSize, 2 );
220         test( s );
221     }
222
223     TEST_F( IntrusiveSplitListLazySet_NoGC, member_mutex )
224     {
225         struct list_traits : public ci::lazy_list::traits
226         {
227             typedef ci::lazy_list::member_hook< offsetof( member_mutex_item_type, hMember ), ci::opt::gc<gc_type>, ci::opt::lock_type<std::mutex>> hook;
228             typedef base_class::less<member_mutex_item_type> less;
229             typedef cmp<member_mutex_item_type> compare;
230             typedef mock_disposer disposer;
231         };
232         typedef ci::LazyList< gc_type, member_mutex_item_type, list_traits > bucket_type;
233
234         struct set_traits : public ci::split_list::traits
235         {
236             typedef hash_int hash;
237             typedef simple_item_counter item_counter;
238         };
239         typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
240
241         set_type s( kSize, 2 );
242         test( s );
243     }
244
245 } // namespace