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