Improved SkipListSet unit tests
[libcds.git] / test / unit / set / skiplist_dhp.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_ordered_set_hp.h"
32
33 #include <cds/container/skip_list_set_dhp.h>
34
35 namespace {
36     namespace cc = cds::container;
37     typedef cds::gc::DHP gc_type;
38
39     class SkipListSet_DHP : public cds_test::container_ordered_set_hp
40     {
41     protected:
42         typedef cds_test::container_ordered_set_hp base_class;
43
44         void SetUp()
45         {
46             struct set_traits: public cc::skip_list::traits
47             {
48                 typedef cmp compare;
49             };
50             typedef cc::SkipListSet< gc_type, int_item > set_type;
51
52             cds::gc::dhp::GarbageCollector::Construct( 16, set_type::c_nHazardPtrCount );
53             cds::threading::Manager::attachThread();
54         }
55
56         void TearDown()
57         {
58             cds::threading::Manager::detachThread();
59             cds::gc::dhp::GarbageCollector::Destruct();
60         }
61     };
62
63     TEST_F( SkipListSet_DHP, compare )
64     {
65         typedef cc::SkipListSet< gc_type, int_item,
66             typename cc::skip_list::make_traits<
67                 cds::opt::compare< cmp >
68             >::type
69         > set_type;
70
71         set_type s;
72         test( s );
73     }
74
75     TEST_F( SkipListSet_DHP, less )
76     {
77         typedef cc::SkipListSet< gc_type, int_item,
78             typename cc::skip_list::make_traits<
79                 cds::opt::less< base_class::less >
80             >::type
81         > set_type;
82
83         set_type s;
84         test( s );
85     }
86
87     TEST_F( SkipListSet_DHP, cmpmix )
88     {
89         typedef cc::SkipListSet< gc_type, int_item,
90             typename cc::skip_list::make_traits<
91                 cds::opt::less< base_class::less >
92                 ,cds::opt::compare< cmp >
93             >::type
94         > set_type;
95
96         set_type s;
97         test( s );
98     }
99
100     TEST_F( SkipListSet_DHP, item_counting )
101     {
102         struct set_traits: public cc::skip_list::traits
103         {
104             typedef cmp compare;
105             typedef base_class::less less;
106             typedef cds::atomicity::item_counter item_counter;
107         };
108         typedef cc::SkipListSet< gc_type, int_item, set_traits >set_type;
109
110         set_type s;
111         test( s );
112     }
113
114     TEST_F( SkipListSet_DHP, backoff )
115     {
116         struct set_traits: public cc::skip_list::traits
117         {
118             typedef cmp compare;
119             typedef base_class::less less;
120             typedef cds::atomicity::item_counter item_counter;
121             typedef cds::backoff::yield back_off;
122         };
123         typedef cc::SkipListSet< gc_type, int_item, set_traits >set_type;
124
125         set_type s;
126         test( s );
127     }
128
129     TEST_F( SkipListSet_DHP, stat )
130     {
131         struct set_traits: public cc::skip_list::traits
132         {
133             typedef cmp compare;
134             typedef base_class::less less;
135             typedef cds::atomicity::item_counter item_counter;
136             typedef cds::backoff::yield back_off;
137             typedef cc::skip_list::stat<> stat;
138         };
139         typedef cc::SkipListSet< gc_type, int_item, set_traits >set_type;
140
141         set_type s;
142         test( s );
143     }
144
145     TEST_F( SkipListSet_DHP, random_level_generator )
146     {
147         struct set_traits: public cc::skip_list::traits
148         {
149             typedef cmp compare;
150             typedef base_class::less less;
151             typedef cds::atomicity::item_counter item_counter;
152             typedef cc::skip_list::stat<> stat;
153             typedef cc::skip_list::xorshift random_level_generator;
154         };
155         typedef cc::SkipListSet< gc_type, int_item, set_traits >set_type;
156
157         set_type s;
158         test( s );
159     }
160
161 } // namespace