Removed trailing spaces
[libcds.git] / test / unit / intrusive-list / intrusive_iterable_hp.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_iterable_list_hp.h"
32 #include <cds/intrusive/iterable_list_hp.h>
33
34 namespace {
35     namespace ci = cds::intrusive;
36     typedef cds::gc::HP gc_type;
37
38     class IntrusiveIterableList_HP : public cds_test::intrusive_iterable_list_hp
39     {
40     protected:
41         void SetUp()
42         {
43             typedef ci::IterableList< gc_type, item_type > list_type;
44
45             // +1 - for guarded_ptr
46             // +3 - for iterator test
47             cds::gc::hp::GarbageCollector::Construct( list_type::c_nHazardPtrCount + 3, 1, 16 );
48             cds::threading::Manager::attachThread();
49         }
50
51         void TearDown()
52         {
53             cds::threading::Manager::detachThread();
54             cds::gc::hp::GarbageCollector::Destruct( true );
55         }
56     };
57
58     TEST_F( IntrusiveIterableList_HP, less )
59     {
60         typedef ci::IterableList< gc_type, item_type,
61             typename ci::iterable_list::make_traits<
62                 ci::opt::disposer< mock_disposer >
63                 ,cds::opt::less< less< item_type >>
64                 ,cds::opt::item_counter< cds::atomicity::item_counter >
65
66             >::type
67        > list_type;
68
69        list_type l;
70        test_common( l );
71        test_ordered_iterator( l );
72        test_hp( l );
73     }
74
75     TEST_F( IntrusiveIterableList_HP, compare )
76     {
77         typedef ci::IterableList< gc_type, item_type,
78             typename ci::iterable_list::make_traits<
79                 ci::opt::disposer< mock_disposer >
80                 , cds::opt::compare< cmp< item_type >>
81                 , cds::opt::item_counter< cds::atomicity::item_counter >
82             >::type
83         > list_type;
84
85         list_type l;
86         test_common( l );
87         test_ordered_iterator( l );
88         test_hp( l );
89     }
90
91     TEST_F( IntrusiveIterableList_HP, item_counting )
92     {
93         struct traits : public ci::iterable_list::traits {
94             typedef mock_disposer disposer;
95             typedef cmp< item_type > compare;
96             typedef intrusive_iterable_list::less< item_type > less;
97             typedef cds::atomicity::item_counter item_counter;
98         };
99         typedef ci::IterableList< gc_type, item_type, traits > list_type;
100
101         list_type l;
102         test_common( l );
103         test_ordered_iterator( l );
104         test_hp( l );
105     }
106
107     TEST_F( IntrusiveIterableList_HP, backoff )
108     {
109         struct traits : public ci::iterable_list::traits {
110             typedef mock_disposer disposer;
111             typedef cmp< item_type > compare;
112             typedef intrusive_iterable_list::less< item_type > less;
113             typedef cds::atomicity::item_counter item_counter;
114             typedef cds::backoff::pause back_off;
115         };
116         typedef ci::IterableList< gc_type, item_type, traits > list_type;
117
118         list_type l;
119         test_common( l );
120         test_ordered_iterator( l );
121         test_hp( l );
122     }
123
124     TEST_F( IntrusiveIterableList_HP, seqcst )
125     {
126         struct traits : public ci::iterable_list::traits {
127             typedef mock_disposer disposer;
128             typedef intrusive_iterable_list::less< item_type > less;
129             typedef cds::atomicity::item_counter item_counter;
130             typedef cds::opt::v::sequential_consistent memory_model;
131         };
132         typedef ci::IterableList< gc_type, item_type, traits > list_type;
133
134         list_type l;
135         test_common( l );
136         test_ordered_iterator( l );
137         test_hp( l );
138     }
139
140     TEST_F( IntrusiveIterableList_HP, stat )
141     {
142         struct traits: public ci::iterable_list::traits {
143             typedef mock_disposer disposer;
144             typedef intrusive_iterable_list::less< item_type > less;
145             typedef cds::atomicity::item_counter item_counter;
146             typedef cds::intrusive::iterable_list::stat<> stat;
147         };
148         typedef ci::IterableList< gc_type, item_type, traits > list_type;
149
150         list_type l;
151         test_common( l );
152         test_ordered_iterator( l );
153         test_hp( l );
154     }
155
156     TEST_F( IntrusiveIterableList_HP, wrapped_stat )
157     {
158         struct traits: public ci::iterable_list::traits {
159             typedef mock_disposer disposer;
160             typedef intrusive_iterable_list::less< item_type > less;
161             typedef cds::atomicity::item_counter item_counter;
162             typedef cds::intrusive::iterable_list::wrapped_stat<> stat;
163         };
164         typedef ci::IterableList< gc_type, item_type, traits > list_type;
165
166         traits::stat::stat_type st;
167
168         list_type l( st );
169         test_common( l );
170         test_ordered_iterator( l );
171         test_hp( l );
172     }
173
174     TEST_F( IntrusiveIterableList_HP, derived )
175     {
176         class list_type: public ci::IterableList< gc_type, item_type,
177             typename ci::iterable_list::make_traits<
178                 ci::opt::disposer< mock_disposer >
179                 ,cds::opt::less< less< item_type >>
180                 ,cds::opt::item_counter< cds::atomicity::item_counter >
181
182             >::type
183         >
184         {};
185
186        list_type l;
187        test_common( l );
188        test_ordered_iterator( l );
189        test_hp( l );
190     }
191
192 } // namespace