Updated copyright
[libcds.git] / test / unit / intrusive-list / intrusive_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-2017
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_list_nogc.h"
32 #include <cds/intrusive/michael_list_nogc.h>
33
34 namespace {
35     namespace ci = cds::intrusive;
36     typedef cds::gc::nogc gc_type;
37
38     class IntrusiveMichaelList_NOGC : public cds_test::intrusive_list_nogc
39     {
40     public:
41         typedef cds_test::intrusive_list_nogc::base_item< ci::michael_list::node< gc_type>> base_item;
42         typedef cds_test::intrusive_list_nogc::member_item< ci::michael_list::node< gc_type>> member_item;
43     };
44
45     TEST_F( IntrusiveMichaelList_NOGC, base_hook )
46     {
47         typedef ci::MichaelList< gc_type, base_item,
48             typename ci::michael_list::make_traits<
49                 ci::opt::hook< ci::michael_list::base_hook< cds::opt::gc< gc_type >>>
50                 ,ci::opt::disposer< mock_disposer >
51                 ,cds::opt::less< less< base_item >>
52             >::type
53        > list_type;
54
55        list_type l;
56        test_common( l );
57        test_ordered_iterator( l );
58     }
59
60     TEST_F( IntrusiveMichaelList_NOGC, base_hook_cmp )
61     {
62         typedef ci::MichaelList< gc_type, base_item,
63             typename ci::michael_list::make_traits<
64                 ci::opt::hook< ci::michael_list::base_hook< cds::opt::gc< gc_type >>>
65                 , ci::opt::disposer< mock_disposer >
66                 , cds::opt::compare< cmp< base_item >>
67             >::type
68         > list_type;
69
70         list_type l;
71         test_common( l );
72         test_ordered_iterator( l );
73     }
74
75     TEST_F( IntrusiveMichaelList_NOGC, base_hook_item_counting )
76     {
77         struct traits : public ci::michael_list::traits {
78             typedef ci::michael_list::base_hook< cds::opt::gc< gc_type >> hook;
79             typedef mock_disposer disposer;
80             typedef cmp< base_item > compare;
81             typedef intrusive_list_nogc::less< base_item > less;
82             typedef cds::atomicity::item_counter item_counter;
83         };
84         typedef ci::MichaelList< gc_type, base_item, traits > list_type;
85
86         list_type l;
87         test_common( l );
88         test_ordered_iterator( l );
89     }
90
91     TEST_F( IntrusiveMichaelList_NOGC, base_hook_backoff )
92     {
93         struct traits : public ci::michael_list::traits {
94             typedef ci::michael_list::base_hook< cds::opt::gc< gc_type >> hook;
95             typedef mock_disposer disposer;
96             typedef cmp< base_item > compare;
97             typedef intrusive_list_nogc::less< base_item > less;
98             typedef cds::atomicity::item_counter item_counter;
99             typedef cds::backoff::pause back_off;
100         };
101         typedef ci::MichaelList< gc_type, base_item, traits > list_type;
102
103         list_type l;
104         test_common( l );
105         test_ordered_iterator( l );
106     }
107
108     TEST_F( IntrusiveMichaelList_NOGC, base_hook_seqcst )
109     {
110         struct traits : public ci::michael_list::traits {
111             typedef ci::michael_list::base_hook< cds::opt::gc< gc_type >> hook;
112             typedef mock_disposer disposer;
113             typedef cmp< base_item > compare;
114             typedef intrusive_list_nogc::less< base_item > less;
115             typedef cds::atomicity::item_counter item_counter;
116             typedef cds::opt::v::sequential_consistent memory_model;
117         };
118         typedef ci::MichaelList< gc_type, base_item, traits > list_type;
119
120         list_type l;
121         test_common( l );
122         test_ordered_iterator( l );
123     }
124
125     TEST_F( IntrusiveMichaelList_NOGC, member_hook )
126     {
127         typedef ci::MichaelList< gc_type, member_item,
128             typename ci::michael_list::make_traits<
129                 ci::opt::hook< ci::michael_list::member_hook< offsetof( member_item, hMember ), cds::opt::gc< gc_type >>>
130                 ,ci::opt::disposer< mock_disposer >
131                 ,cds::opt::less< less< member_item >>
132             >::type
133        > list_type;
134
135        list_type l;
136        test_common( l );
137        test_ordered_iterator( l );
138     }
139
140     TEST_F( IntrusiveMichaelList_NOGC, member_hook_cmp )
141     {
142         typedef ci::MichaelList< gc_type, member_item,
143             typename ci::michael_list::make_traits<
144                 ci::opt::hook< ci::michael_list::member_hook< offsetof( member_item, hMember ), cds::opt::gc< gc_type >>>
145                 ,ci::opt::disposer< mock_disposer >
146                 ,cds::opt::compare< cmp< member_item >>
147             >::type
148         > list_type;
149
150         list_type l;
151         test_common( l );
152         test_ordered_iterator( l );
153     }
154
155     TEST_F( IntrusiveMichaelList_NOGC, member_hook_item_counting )
156     {
157         struct traits : public ci::michael_list::traits {
158             typedef ci::michael_list::member_hook< offsetof( member_item, hMember ), cds::opt::gc< gc_type >> hook;
159             typedef mock_disposer disposer;
160             typedef cmp< member_item > compare;
161             typedef intrusive_list_nogc::less< member_item > less;
162             typedef cds::atomicity::item_counter item_counter;
163         };
164         typedef ci::MichaelList< gc_type, member_item, traits > list_type;
165
166         list_type l;
167         test_common( l );
168         test_ordered_iterator( l );
169     }
170
171     TEST_F( IntrusiveMichaelList_NOGC, member_hook_seqcst )
172     {
173         struct traits : public ci::michael_list::traits {
174             typedef ci::michael_list::member_hook< offsetof( member_item, hMember ), cds::opt::gc< gc_type >> hook;
175             typedef mock_disposer disposer;
176             typedef cmp< member_item > compare;
177             typedef intrusive_list_nogc::less< member_item > less;
178             typedef cds::atomicity::item_counter item_counter;
179             typedef cds::opt::v::sequential_consistent memory_model;
180         };
181         typedef ci::MichaelList< gc_type, member_item, traits > list_type;
182
183         list_type l;
184         test_common( l );
185         test_ordered_iterator( l );
186     }
187
188     TEST_F( IntrusiveMichaelList_NOGC, member_hook_back_off )
189     {
190         struct traits : public ci::michael_list::traits {
191             typedef ci::michael_list::member_hook< offsetof( member_item, hMember ), cds::opt::gc< gc_type >> hook;
192             typedef mock_disposer disposer;
193             typedef cmp< member_item > compare;
194             typedef intrusive_list_nogc::less< member_item > less;
195             typedef cds::atomicity::item_counter item_counter;
196             typedef cds::backoff::empty back_off;
197         };
198         typedef ci::MichaelList< gc_type, member_item, traits > list_type;
199
200         list_type l;
201         test_common( l );
202         test_ordered_iterator( l );
203     }
204
205 } // namespace