Migrated SkipListSet unit test to gtest
[libcds.git] / test / unit / set / test_skiplist_rcu.h
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 #ifndef CDSUNIT_SET_TEST_SKIPLIST_RCU_H
31 #define CDSUNIT_SET_TEST_SKIPLIST_RCU_H
32
33 #include "test_set_rcu.h"
34 #include <cds/container/skip_list_set_rcu.h>
35
36 namespace cc = cds::container;
37
38 template <class RCU>
39 class SkipListSet: public cds_test::container_set_rcu
40 {
41     typedef cds_test::container_set_rcu base_class;
42 public:
43     typedef cds::urcu::gc<RCU> rcu_type;
44
45 protected:
46     void SetUp()
47     {
48         RCU::Construct();
49         cds::threading::Manager::attachThread();
50     }
51
52     void TearDown()
53     {
54         cds::threading::Manager::detachThread();
55         RCU::Destruct();
56     }
57 };
58
59 TYPED_TEST_CASE_P( SkipListSet );
60
61 //TYPED_TEST_P( SkipListSet, compare )
62 TYPED_TEST_P( SkipListSet, compare )
63 {
64     typedef typename TestFixture::rcu_type rcu_type;
65     typedef typename TestFixture::int_item int_item;
66
67     typedef cc::SkipListSet< rcu_type, int_item,
68         typename cc::skip_list::make_traits<
69             cds::opt::compare< typename TestFixture::cmp >
70         >::type
71     > set_type;
72
73     set_type s;
74     this->test( s );
75 }
76
77 TYPED_TEST_P( SkipListSet, less )
78 {
79     typedef typename TestFixture::rcu_type rcu_type;
80     typedef typename TestFixture::int_item int_item;
81
82     typedef cc::SkipListSet< rcu_type, int_item,
83         typename cc::skip_list::make_traits<
84             cds::opt::less< typename TestFixture::less >
85         >::type
86     > set_type;
87
88     set_type s;
89     this->test( s );
90 }
91
92 TYPED_TEST_P( SkipListSet, cmpmix )
93 {
94     typedef typename TestFixture::rcu_type rcu_type;
95     typedef typename TestFixture::int_item int_item;
96
97     typedef cc::SkipListSet< rcu_type, int_item,
98         typename cc::skip_list::make_traits<
99             cds::opt::less< typename TestFixture::less >
100             ,cds::opt::compare< typename TestFixture::cmp >
101         >::type
102     > set_type;
103
104     set_type s;
105     this->test( s );
106 }
107
108 TYPED_TEST_P( SkipListSet, item_counting )
109 {
110     typedef typename TestFixture::rcu_type rcu_type;
111     typedef typename TestFixture::int_item int_item;
112
113     struct set_traits: public cc::skip_list::traits
114     {
115         typedef typename TestFixture::cmp compare;
116         typedef typename TestFixture::less less;
117         typedef cds::atomicity::item_counter item_counter;
118     };
119     typedef cc::SkipListSet< rcu_type, int_item, set_traits >set_type;
120
121     set_type s;
122     this->test( s );
123 }
124
125 TYPED_TEST_P( SkipListSet, backoff )
126 {
127     typedef typename TestFixture::rcu_type rcu_type;
128     typedef typename TestFixture::int_item int_item;
129
130     struct set_traits: public cc::skip_list::traits
131     {
132         typedef typename TestFixture::cmp compare;
133         typedef typename TestFixture::less less;
134         typedef cds::atomicity::item_counter item_counter;
135         typedef cds::backoff::yield back_off;
136     };
137     typedef cc::SkipListSet< rcu_type, int_item, set_traits >set_type;
138
139     set_type s;
140     this->test( s );
141 }
142
143 TYPED_TEST_P( SkipListSet, stat )
144 {
145     typedef typename TestFixture::rcu_type rcu_type;
146     typedef typename TestFixture::int_item int_item;
147
148     struct set_traits: public cc::skip_list::traits
149     {
150         typedef typename TestFixture::cmp compare;
151         typedef typename TestFixture::less less;
152         typedef cds::atomicity::item_counter item_counter;
153         typedef cds::backoff::yield back_off;
154         typedef cc::skip_list::stat<> stat;
155     };
156     typedef cc::SkipListSet< rcu_type, int_item, set_traits >set_type;
157
158     set_type s;
159     this->test( s );
160 }
161
162 TYPED_TEST_P( SkipListSet, random_level_generator )
163 {
164     typedef typename TestFixture::rcu_type rcu_type;
165     typedef typename TestFixture::int_item int_item;
166
167     struct set_traits: public cc::skip_list::traits
168     {
169         typedef typename TestFixture::cmp compare;
170         typedef typename TestFixture::less less;
171         typedef cds::atomicity::item_counter item_counter;
172         typedef cc::skip_list::stat<> stat;
173         typedef cc::skip_list::xorshift random_level_generator;
174         typedef cds::opt::v::rcu_assert_deadlock rcu_check_deadlock;
175     };
176     typedef cc::SkipListSet< rcu_type, int_item, set_traits >set_type;
177
178     set_type s;
179     this->test( s );
180 }
181
182
183 // GCC 5: All this->test names should be written on single line, otherwise a runtime error will be encountered like as
184 // "No this->test named <test_name> can be found in this this->test case"
185 REGISTER_TYPED_TEST_CASE_P( SkipListSet,
186     compare, less, cmpmix, item_counting, backoff, stat, random_level_generator
187 );
188
189
190 #endif // CDSUNIT_SET_TEST_SKIPLIST_RCU_H
191