Migrated EllenBinTreeSet unit test to gtest framework
[libcds.git] / test / unit / tree / ellenbintree_set_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_tree_set_hp.h"
32
33 #include <cds/container/ellen_bintree_set_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 EllenBinTreeSet_HP : public cds_test::container_tree_set_hp
41     {
42     protected:
43         typedef cds_test::container_tree_set_hp base_class;
44         typedef int key_type;
45
46         struct generic_traits: public cc::ellen_bintree::traits
47         {
48             typedef base_class::key_extractor key_extractor;
49         };
50
51         void SetUp()
52         {
53             typedef cc::EllenBinTreeSet< gc_type, key_type, int_item > set_type;
54
55             // +1 - for guarded_ptr
56             cds::gc::hp::GarbageCollector::Construct( set_type::c_nHazardPtrCount + 1, 1, 16 );
57             cds::threading::Manager::attachThread();
58         }
59
60         void TearDown()
61         {
62             cds::threading::Manager::detachThread();
63             cds::gc::hp::GarbageCollector::Destruct( true );
64         }
65     };
66
67
68     TEST_F( EllenBinTreeSet_HP, compare )
69     {
70         typedef cc::EllenBinTreeSet< gc_type, key_type, int_item,
71             typename cc::ellen_bintree::make_set_traits<
72                 cc::opt::type_traits< generic_traits >
73                 ,cds::opt::compare< cmp >
74             >::type
75         > set_type;
76
77         set_type s;
78         test( s );
79     }
80
81     TEST_F( EllenBinTreeSet_HP, less )
82     {
83         typedef cc::EllenBinTreeSet< gc_type, key_type, int_item,
84             typename cc::ellen_bintree::make_set_traits<
85                 cc::opt::type_traits< generic_traits >
86                 ,cds::opt::less< base_class::less >
87             >::type
88         > set_type;
89
90         set_type s;
91         test( s );
92     }
93
94     TEST_F( EllenBinTreeSet_HP, cmpmix )
95     {
96         typedef cc::EllenBinTreeSet< gc_type, key_type, int_item,
97             typename cc::ellen_bintree::make_set_traits<
98                 cc::opt::type_traits< generic_traits >
99                 ,cds::opt::less< base_class::less >
100                 ,cds::opt::compare< cmp >
101             >::type
102         > set_type;
103
104         set_type s;
105         test( s );
106     }
107
108     TEST_F( EllenBinTreeSet_HP, update_desc_pool )
109     {
110         struct set_traits: public generic_traits
111         {
112             typedef cmp compare;
113             typedef cds::memory::pool_allocator<cds_test::update_desc, cds_test::pool_accessor> update_desc_allocator;
114         };
115         typedef cc::EllenBinTreeSet< gc_type, key_type, int_item, set_traits > set_type;
116
117         set_type s;
118         test( s );
119     }
120
121     TEST_F( EllenBinTreeSet_HP, update_desc_lazy_pool )
122     {
123         struct set_traits: public generic_traits
124         {
125             typedef cmp compare;
126             typedef cds::memory::pool_allocator< cds_test::update_desc, cds_test::lazy_pool_accessor> update_desc_allocator;
127         };
128         typedef cc::EllenBinTreeSet< gc_type, key_type, int_item, set_traits > set_type;
129
130         set_type s;
131         test( s );
132     }
133
134     TEST_F( EllenBinTreeSet_HP, item_counting )
135     {
136         struct set_traits: public generic_traits
137         {
138             typedef cmp compare;
139             typedef base_class::less less;
140             typedef cds::atomicity::item_counter item_counter;
141             typedef cds::memory::pool_allocator<cds_test::update_desc, cds_test::pool_accessor> update_desc_allocator;
142         };
143         typedef cc::EllenBinTreeSet< gc_type, key_type, int_item, set_traits > set_type;
144
145         set_type s;
146         test( s );
147     }
148
149     TEST_F( EllenBinTreeSet_HP, backoff )
150     {
151         struct set_traits: public generic_traits
152         {
153             typedef cmp compare;
154             typedef base_class::less less;
155             typedef cds::atomicity::item_counter item_counter;
156             typedef cds::backoff::yield back_off;
157             typedef cds::memory::pool_allocator<cds_test::update_desc, cds_test::lazy_pool_accessor> update_desc_allocator;
158         };
159         typedef cc::EllenBinTreeSet< gc_type, key_type, int_item, set_traits > set_type;
160
161         set_type s;
162         test( s );
163     }
164
165     TEST_F( EllenBinTreeSet_HP, stat )
166     {
167         struct set_traits: public generic_traits
168         {
169             typedef base_class::less less;
170             typedef cds::atomicity::item_counter item_counter;
171             typedef cds::backoff::yield back_off;
172             typedef cc::ellen_bintree::stat<> stat;
173             typedef cds::memory::pool_allocator<cds_test::update_desc, cds_test::pool_accessor> update_desc_allocator;
174         };
175         typedef cc::EllenBinTreeSet< gc_type, key_type, int_item, set_traits > set_type;
176
177         set_type s;
178         test( s );
179     }
180
181 } // namespace