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