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