4498172a535c39f645d93418f05c78de5a8ff8e2
[libcds.git] / test / unit / intrusive-set / intrusive_michael_iterable_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_michael_iterable_hp.h"
32
33 #include <cds/intrusive/iterable_list_hp.h>
34 #include <cds/intrusive/michael_set.h>
35
36 namespace {
37     namespace ci = cds::intrusive;
38     typedef cds::gc::HP gc_type;
39
40     class IntrusiveMichaelIterableSet_HP : public cds_test::intrusive_set_hp
41     {
42     protected:
43         typedef cds_test::intrusive_set_hp base_class;
44
45     protected:
46         void SetUp()
47         {
48             struct list_traits : public ci::iterable_list::traits
49             {};
50             typedef ci::IterableList< gc_type, item_type, list_traits > list_type;
51             typedef ci::MichaelHashSet< gc_type, list_type >   set_type;
52
53             // +3 - for iterators
54             cds::gc::hp::GarbageCollector::Construct( set_type::c_nHazardPtrCount + 3, 1, 16 );
55             cds::threading::Manager::attachThread();
56         }
57
58         void TearDown()
59         {
60             cds::threading::Manager::detachThread();
61             cds::gc::hp::GarbageCollector::Destruct( true );
62         }
63     };
64
65
66     TEST_F( IntrusiveMichaelIterableSet_HP, cmp )
67     {
68         typedef ci::IterableList< gc_type
69             , item_type
70             ,ci::iterable_list::make_traits<
71                 ci::opt::compare< cmp<item_type> >
72                 ,ci::opt::disposer< mock_disposer >
73             >::type
74         > bucket_type;
75
76         typedef ci::MichaelHashSet< gc_type, bucket_type,
77             ci::michael_set::make_traits<
78                 ci::opt::hash< hash_int >
79             >::type
80         > set_type;
81
82         set_type s( kSize, 2 );
83         test( s );
84     }
85
86     TEST_F( IntrusiveMichaelIterableSet_HP, less )
87     {
88         typedef ci::IterableList< gc_type
89             , item_type
90             ,ci::iterable_list::make_traits<
91                 ci::opt::less< less<item_type> >
92                 ,ci::opt::disposer< mock_disposer >
93             >::type
94         > bucket_type;
95
96         typedef ci::MichaelHashSet< gc_type, bucket_type,
97             ci::michael_set::make_traits<
98                 ci::opt::hash< hash_int >
99             >::type
100         > set_type;
101
102         set_type s( kSize, 2 );
103         test( s );
104     }
105
106     TEST_F( IntrusiveMichaelIterableSet_HP, cmpmix )
107     {
108         struct list_traits : public ci::iterable_list::traits
109         {
110             typedef base_class::less<item_type> less;
111             typedef cmp<item_type> compare;
112             typedef mock_disposer disposer;
113         };
114         typedef ci::IterableList< gc_type, item_type, list_traits > bucket_type;
115
116         struct set_traits : public ci::michael_set::traits
117         {
118             typedef hash_int hash;
119             typedef simple_item_counter item_counter;
120         };
121         typedef ci::MichaelHashSet< gc_type, bucket_type, set_traits > set_type;
122
123         set_type s( kSize, 2 );
124         test( s );
125     }
126
127 } // namespace