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