Migrated intrusive FeldmanHashSet unit test to gtest framework
[libcds.git] / test / unit / set / intrusive_split_michael_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/michael_list_dhp.h>
34 #include <cds/intrusive/split_list.h>
35
36 namespace {
37     namespace ci = cds::intrusive;
38     typedef cds::gc::DHP gc_type;
39
40     class IntrusiveSplitListSet_DHP : public cds_test::intrusive_set_hp
41     {
42     protected:
43         typedef cds_test::intrusive_set_hp base_class;
44
45     protected:
46         typedef typename base_class::base_int_item< ci::split_list::node< ci::michael_list::node<gc_type>>>   base_item_type;
47         typedef typename base_class::member_int_item< ci::split_list::node< ci::michael_list::node<gc_type>>> member_item_type;
48
49         void SetUp()
50         {
51             struct list_traits : public ci::michael_list::traits
52             {
53                 typedef ci::michael_list::base_hook< ci::opt::gc<gc_type>> hook;
54             };
55             typedef ci::MichaelList< gc_type, base_item_type, list_traits > list_type;
56             typedef ci::SplitListSet< gc_type, list_type >   set_type;
57
58             cds::gc::dhp::GarbageCollector::Construct( 16, set_type::c_nHazardPtrCount );
59             cds::threading::Manager::attachThread();
60         }
61
62         void TearDown()
63         {
64             cds::threading::Manager::detachThread();
65             cds::gc::dhp::GarbageCollector::Destruct();
66         }
67     };
68
69
70     TEST_F( IntrusiveSplitListSet_DHP, base_cmp )
71     {
72         typedef ci::MichaelList< gc_type
73             , base_item_type
74             ,ci::michael_list::make_traits<
75                 ci::opt::hook< ci::michael_list::base_hook< ci::opt::gc< gc_type > > >
76                 ,ci::opt::compare< cmp<base_item_type> >
77                 ,ci::opt::disposer< mock_disposer >
78             >::type
79         > bucket_type;
80
81         typedef ci::SplitListSet< gc_type, bucket_type,
82             ci::split_list::make_traits<
83                 ci::opt::hash< hash_int >
84             >::type
85         > set_type;
86
87         set_type s( kSize, 2 );
88         test( s );
89     }
90
91     TEST_F( IntrusiveSplitListSet_DHP, base_less )
92     {
93         typedef ci::MichaelList< gc_type
94             , base_item_type
95             ,ci::michael_list::make_traits<
96                 ci::opt::hook< ci::michael_list::base_hook< ci::opt::gc< gc_type >>>
97                 ,ci::opt::less< less<base_item_type> >
98                 ,ci::opt::disposer< mock_disposer >
99             >::type
100         > bucket_type;
101
102         typedef ci::SplitListSet< gc_type, bucket_type,
103             ci::split_list::make_traits<
104                 ci::opt::hash< hash_int >
105                 ,ci::opt::item_counter< cds::atomicity::item_counter >
106             >::type
107         > set_type;
108
109         set_type s( kSize, 2 );
110         test( s );
111     }
112
113     TEST_F( IntrusiveSplitListSet_DHP, base_cmpmix )
114     {
115         struct list_traits : public ci::michael_list::traits
116         {
117             typedef ci::michael_list::base_hook< ci::opt::gc<gc_type>> hook;
118             typedef base_class::less<base_item_type> less;
119             typedef cmp<base_item_type> compare;
120             typedef mock_disposer disposer;
121         };
122         typedef ci::MichaelList< gc_type, base_item_type, list_traits > bucket_type;
123
124         struct set_traits : public ci::split_list::traits
125         {
126             typedef hash_int hash;
127             typedef simple_item_counter item_counter;
128             typedef ci::split_list::stat<> stat;
129         };
130         typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
131
132         set_type s( kSize, 2 );
133         test( s );
134     }
135
136
137     TEST_F( IntrusiveSplitListSet_DHP, member_cmp )
138     {
139         typedef ci::MichaelList< gc_type
140             ,member_item_type
141             ,ci::michael_list::make_traits<
142                 ci::opt::hook< ci::michael_list::member_hook<
143                     offsetof( member_item_type, hMember ),
144                     ci::opt::gc<gc_type>
145                 > >
146                 ,ci::opt::compare< cmp<member_item_type> >
147                 ,ci::opt::disposer< mock_disposer >
148             >::type
149         >    bucket_type;
150
151         typedef ci::SplitListSet< gc_type, bucket_type,
152             ci::split_list::make_traits<
153                 ci::opt::hash< hash_int >
154             >::type
155         > set_type;
156
157         set_type s( kSize, 2 );
158         test( s );
159     }
160
161     TEST_F( IntrusiveSplitListSet_DHP, member_less )
162     {
163         typedef ci::MichaelList< gc_type
164             , member_item_type
165             ,ci::michael_list::make_traits<
166                 ci::opt::hook< ci::michael_list::member_hook<
167                     offsetof( member_item_type, hMember ),
168                     ci::opt::gc<gc_type>
169                 > >
170                 ,ci::opt::less< less<member_item_type> >
171                 ,ci::opt::disposer< mock_disposer >
172             >::type
173         > bucket_type;
174
175         typedef ci::SplitListSet< gc_type, bucket_type,
176             ci::split_list::make_traits<
177                 ci::opt::hash< hash_int >
178                 ,ci::opt::back_off< cds::backoff::pause >
179             >::type
180         > set_type;
181
182         set_type s( kSize, 2 );
183         test( s );
184     }
185
186     TEST_F( IntrusiveSplitListSet_DHP, member_cmpmix )
187     {
188         struct list_traits : public ci::michael_list::traits
189         {
190             typedef ci::michael_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc<gc_type>> hook;
191             typedef base_class::less<member_item_type> less;
192             typedef cmp<member_item_type> compare;
193             typedef mock_disposer disposer;
194         };
195         typedef ci::MichaelList< gc_type, member_item_type, list_traits > bucket_type;
196
197         struct set_traits : public ci::split_list::traits
198         {
199             typedef hash_int hash;
200             typedef simple_item_counter item_counter;
201         };
202         typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
203
204         set_type s( kSize, 2 );
205         test( s );
206     }
207
208 } // namespace