Migrated intrusive EllenBinTree unit test to gtest
[libcds.git] / test / unit / tree / intrusive_ellenbintree_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_tree_hp.h"
32
33 #include <cds/intrusive/ellen_bintree_hp.h>
34
35 namespace {
36     namespace ci = cds::intrusive;
37     typedef cds::gc::HP gc_type;
38
39     class IntrusiveEllenBinTree_HP : public cds_test::intrusive_tree_hp
40     {
41     protected:
42         typedef cds_test::intrusive_tree_hp base_class;
43
44     protected:
45         typedef base_class::key_type key_type;
46
47         typedef typename base_class::base_int_item< ci::ellen_bintree::node<gc_type>> base_item_type;
48         typedef ci::ellen_bintree::internal_node< key_type, base_item_type >          internal_base_node;
49         typedef ci::ellen_bintree::update_desc< base_item_type, internal_base_node >  update_base_desc;
50
51         typedef typename base_class::member_int_item< ci::ellen_bintree::node<gc_type>>  member_item_type;
52         typedef ci::ellen_bintree::internal_node< key_type, member_item_type >           internal_member_node;
53         typedef ci::ellen_bintree::update_desc< member_item_type, internal_member_node > update_member_desc;
54
55         void SetUp()
56         {
57             struct list_traits : public ci::ellen_bintree::traits
58             {
59                 typedef ci::ellen_bintree::base_hook< ci::opt::gc<gc_type>> hook;
60             };
61             typedef ci::EllenBinTree< gc_type, key_type, base_item_type >   set_type;
62
63             // +1 - for guarded_ptr
64             cds::gc::hp::GarbageCollector::Construct( set_type::c_nHazardPtrCount + 1, 1, 16 );
65             cds::threading::Manager::attachThread();
66         }
67
68         void TearDown()
69         {
70             cds::threading::Manager::detachThread();
71             cds::gc::hp::GarbageCollector::Destruct( true );
72         }
73
74         struct generic_traits: public ci::ellen_bintree::traits
75         {
76             typedef base_class::key_extractor key_extractor;
77             typedef mock_disposer disposer;
78         };
79     };
80
81
82     TEST_F( IntrusiveEllenBinTree_HP, base_cmp )
83     {
84         typedef ci::EllenBinTree< gc_type, key_type, base_item_type,
85             ci::ellen_bintree::make_traits< 
86                 ci::opt::type_traits< generic_traits >
87                 ,ci::opt::hook< ci::ellen_bintree::base_hook< ci::opt::gc< gc_type >>>
88                 ,ci::opt::compare< cmp<base_item_type>>
89             >::type
90         > tree_type;
91
92         tree_type t;
93         test( t );
94     }
95
96     TEST_F( IntrusiveEllenBinTree_HP, base_less )
97     {
98         typedef ci::EllenBinTree< gc_type, key_type, base_item_type,
99             ci::ellen_bintree::make_traits< 
100                 ci::opt::type_traits< generic_traits >
101                 ,ci::opt::hook< ci::ellen_bintree::base_hook< ci::opt::gc< gc_type >>>
102                 ,ci::opt::less< less<base_item_type>>
103             >::type
104         > tree_type;
105
106         tree_type t;
107         test( t );
108     }
109
110     TEST_F( IntrusiveEllenBinTree_HP, base_item_counter )
111     {
112         typedef ci::EllenBinTree< gc_type, key_type, base_item_type,
113             ci::ellen_bintree::make_traits< 
114                 ci::opt::type_traits< generic_traits >
115                 ,ci::opt::hook< ci::ellen_bintree::base_hook< ci::opt::gc< gc_type >>>
116                 ,ci::opt::compare< cmp<base_item_type>>
117                 ,ci::opt::item_counter< simple_item_counter >
118             >::type
119         > tree_type;
120
121         tree_type t;
122         test( t );
123     }
124
125     TEST_F( IntrusiveEllenBinTree_HP, base_backoff )
126     {
127         struct tree_traits: public generic_traits
128         {
129             typedef ci::ellen_bintree::base_hook< ci::opt::gc< gc_type >> hook;
130             typedef cmp<base_item_type> compare;
131             typedef base_class::less<base_item_type> less;
132             typedef cds::atomicity::item_counter item_counter;
133             typedef cds::backoff::yield back_off;
134         };
135
136         typedef ci::EllenBinTree< gc_type, key_type, base_item_type, tree_traits > tree_type;
137
138         tree_type t;
139         test( t );
140     }
141
142     TEST_F( IntrusiveEllenBinTree_HP, base_seq_cst )
143     {
144         struct tree_traits: public generic_traits
145         {
146             typedef ci::ellen_bintree::base_hook< ci::opt::gc< gc_type >> hook;
147             typedef cmp<base_item_type> compare;
148             typedef base_class::less<base_item_type> less;
149             typedef cds::atomicity::item_counter item_counter;
150             typedef cds::backoff::pause back_off;
151             typedef ci::opt::v::sequential_consistent memory_model;
152         };
153
154         typedef ci::EllenBinTree< gc_type, key_type, base_item_type, tree_traits > tree_type;
155
156         tree_type t;
157         test( t );
158     }
159
160
161 } // namespace