Migrated instrusive::SplitListSet unit test to gtest framework
[libcds.git] / test / unit / set / intrusive_split_lazy_dhp.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_hp.h"
32
33 #include <cds/intrusive/lazy_list_dhp.h>
34 #include <cds/intrusive/split_list.h>
35
36 #include <mutex>
37
38 namespace {
39     namespace ci = cds::intrusive;
40     typedef cds::gc::DHP gc_type;
41
42     class IntrusiveSplitListLazySet_DHP : public cds_test::intrusive_set_hp
43     {
44     protected:
45         typedef cds_test::intrusive_set_hp 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             struct list_traits : public ci::lazy_list::traits
56             {
57                 typedef ci::lazy_list::base_hook< ci::opt::gc<gc_type>> hook;
58             };
59             typedef ci::LazyList< gc_type, base_item_type, list_traits > list_type;
60             typedef ci::SplitListSet< gc_type, list_type >   set_type;
61
62             cds::gc::dhp::GarbageCollector::Construct( 16, set_type::c_nHazardPtrCount );
63             cds::threading::Manager::attachThread();
64         }
65
66         void TearDown()
67         {
68             cds::threading::Manager::detachThread();
69             cds::gc::dhp::GarbageCollector::Destruct();
70         }
71     };
72
73
74     TEST_F( IntrusiveSplitListLazySet_DHP, base_cmp )
75     {
76         typedef ci::LazyList< gc_type
77             , base_item_type
78             ,ci::lazy_list::make_traits<
79                 ci::opt::hook< ci::lazy_list::base_hook< ci::opt::gc< gc_type > > >
80                 ,ci::opt::compare< cmp<base_item_type> >
81                 ,ci::opt::disposer< mock_disposer >
82                 ,ci::opt::back_off< cds::backoff::pause >
83             >::type
84         > bucket_type;
85
86         typedef ci::SplitListSet< gc_type, bucket_type,
87             ci::split_list::make_traits<
88                 ci::opt::hash< hash_int >
89             >::type
90         > set_type;
91
92         set_type s( kSize, 2 );
93         test( s );
94     }
95
96     TEST_F( IntrusiveSplitListLazySet_DHP, base_less )
97     {
98         typedef ci::LazyList< gc_type
99             , base_item_type
100             ,ci::lazy_list::make_traits<
101                 ci::opt::hook< ci::lazy_list::base_hook< ci::opt::gc< gc_type >>>
102                 ,ci::opt::less< less<base_item_type> >
103                 ,ci::opt::disposer< mock_disposer >
104             >::type
105         > bucket_type;
106
107         typedef ci::SplitListSet< gc_type, bucket_type,
108             ci::split_list::make_traits<
109                 ci::opt::hash< hash_int >
110                 , ci::opt::item_counter< cds::atomicity::item_counter >
111             >::type
112         > set_type;
113
114         set_type s( kSize, 2 );
115         test( s );
116     }
117
118     TEST_F( IntrusiveSplitListLazySet_DHP, base_cmpmix )
119     {
120         struct list_traits : public ci::lazy_list::traits
121         {
122             typedef ci::lazy_list::base_hook< ci::opt::gc<gc_type>> hook;
123             typedef base_class::less<base_item_type> less;
124             typedef cmp<base_item_type> compare;
125             typedef mock_disposer disposer;
126         };
127         typedef ci::LazyList< gc_type, base_item_type, list_traits > bucket_type;
128
129         struct set_traits : public ci::split_list::traits
130         {
131             typedef hash_int hash;
132             typedef simple_item_counter item_counter;
133             typedef ci::split_list::stat<> stat;
134         };
135         typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
136
137         set_type s( kSize, 2 );
138         test( s );
139     }
140
141     TEST_F( IntrusiveSplitListLazySet_DHP, base_mutex )
142     {
143         struct list_traits : public ci::lazy_list::traits
144         {
145             typedef ci::lazy_list::base_hook< ci::opt::gc<gc_type>, ci::opt::lock_type<std::mutex>> hook;
146             typedef base_class::less<base_mutex_item_type> less;
147             typedef cmp<base_mutex_item_type> compare;
148             typedef mock_disposer disposer;
149         };
150         typedef ci::LazyList< gc_type, base_mutex_item_type, list_traits > bucket_type;
151
152         struct set_traits : public ci::split_list::traits
153         {
154             typedef hash_int hash;
155             typedef simple_item_counter item_counter;
156             typedef cds::backoff::empty back_off;
157         };
158         typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
159
160         set_type s( kSize, 2 );
161         test( s );
162     }
163
164
165     TEST_F( IntrusiveSplitListLazySet_DHP, member_cmp )
166     {
167         typedef ci::LazyList< gc_type
168             ,member_item_type
169             ,ci::lazy_list::make_traits<
170                 ci::opt::hook< ci::lazy_list::member_hook<
171                     offsetof( member_item_type, hMember ),
172                     ci::opt::gc<gc_type>
173                 > >
174                 ,ci::opt::compare< cmp<member_item_type> >
175                 ,ci::opt::disposer< mock_disposer >
176             >::type
177         >    bucket_type;
178
179         typedef ci::SplitListSet< gc_type, bucket_type,
180             ci::split_list::make_traits<
181                 ci::opt::hash< hash_int >
182             >::type
183         > set_type;
184
185         set_type s( kSize, 2 );
186         test( s );
187     }
188
189     TEST_F( IntrusiveSplitListLazySet_DHP, member_less )
190     {
191         typedef ci::LazyList< gc_type
192             , member_item_type
193             ,ci::lazy_list::make_traits<
194                 ci::opt::hook< ci::lazy_list::member_hook<
195                     offsetof( member_item_type, hMember ),
196                     ci::opt::gc<gc_type>
197                 > >
198                 ,ci::opt::less< less<member_item_type> >
199                 ,ci::opt::disposer< mock_disposer >
200             >::type
201         > bucket_type;
202
203         typedef ci::SplitListSet< gc_type, bucket_type,
204             ci::split_list::make_traits<
205                 ci::opt::hash< hash_int >
206                 , ci::opt::back_off< cds::backoff::pause >
207             >::type
208         > set_type;
209
210         set_type s( kSize, 2 );
211         test( s );
212     }
213
214     TEST_F( IntrusiveSplitListLazySet_DHP, member_cmpmix )
215     {
216         struct list_traits : public ci::lazy_list::traits
217         {
218             typedef ci::lazy_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc<gc_type>> hook;
219             typedef base_class::less<member_item_type> less;
220             typedef cmp<member_item_type> compare;
221             typedef mock_disposer disposer;
222         };
223         typedef ci::LazyList< gc_type, member_item_type, list_traits > bucket_type;
224
225         struct set_traits : public ci::split_list::traits
226         {
227             typedef hash_int hash;
228             typedef simple_item_counter item_counter;
229         };
230         typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
231
232         set_type s( kSize, 2 );
233         test( s );
234     }
235
236     TEST_F( IntrusiveSplitListLazySet_DHP, member_mutex )
237     {
238         struct list_traits : public ci::lazy_list::traits
239         {
240             typedef ci::lazy_list::member_hook< offsetof( member_mutex_item_type, hMember ), ci::opt::gc<gc_type>, ci::opt::lock_type<std::mutex>> hook;
241             typedef base_class::less<member_mutex_item_type> less;
242             typedef cmp<member_mutex_item_type> compare;
243             typedef mock_disposer disposer;
244         };
245         typedef ci::LazyList< gc_type, member_mutex_item_type, list_traits > bucket_type;
246
247         struct set_traits : public ci::split_list::traits
248         {
249             typedef hash_int hash;
250             typedef simple_item_counter item_counter;
251         };
252         typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
253
254         set_type s( kSize, 2 );
255         test( s );
256     }
257
258 } // namespace