Remove CDS_EMPLACE_SUPPORT macro and unused code
[libcds.git] / tests / test-hdr / stack / hdr_treiber_stack.h
1 //$$CDS-header$$
2
3 #include "cppunit/cppunit_proxy.h"
4
5 namespace stack {
6
7     class TestStack: public CppUnitMini::TestCase
8     {
9         template <class Stack>
10         void test()
11         {
12             Stack s;
13             test_with( s );
14         }
15
16         template <class Stack>
17         void test_elimination()
18         {
19             Stack s(2);
20             test_with( s );
21         }
22
23         template <class Stack>
24         void test_with( Stack& stack)
25         {
26             typedef typename Stack::value_type  value_type;
27             value_type v;
28
29             CPPUNIT_ASSERT( stack.empty() );
30
31             CPPUNIT_ASSERT( stack.push(1));
32             CPPUNIT_ASSERT( !stack.empty() );
33             CPPUNIT_ASSERT( stack.push(2));
34             CPPUNIT_ASSERT( !stack.empty() );
35             CPPUNIT_ASSERT( stack.push(3));
36             CPPUNIT_ASSERT( !stack.empty() );
37
38             CPPUNIT_ASSERT( stack.pop(v) );
39             CPPUNIT_ASSERT( v == 3 );
40             CPPUNIT_ASSERT( !stack.empty() );
41             CPPUNIT_ASSERT( stack.pop(v) );
42             CPPUNIT_ASSERT( v == 2 );
43             CPPUNIT_ASSERT( !stack.empty() );
44             CPPUNIT_ASSERT( stack.pop(v) );
45             CPPUNIT_ASSERT( v == 1 );
46             CPPUNIT_ASSERT( stack.empty() );
47             v = 1000;
48             CPPUNIT_ASSERT( !stack.pop(v) );
49             CPPUNIT_ASSERT( v == 1000 );
50             CPPUNIT_ASSERT( stack.empty() );
51
52             CPPUNIT_ASSERT( stack.push(10));
53             CPPUNIT_ASSERT( stack.push(20));
54             CPPUNIT_ASSERT( stack.push(30));
55             CPPUNIT_ASSERT( !stack.empty());
56
57             CPPUNIT_ASSERT( stack.emplace(100));
58             CPPUNIT_ASSERT( stack.pop(v));
59             CPPUNIT_ASSERT( v == 100 );
60
61             stack.clear();
62             CPPUNIT_ASSERT( stack.empty() );
63
64             Stack::gc::scan();
65         }
66
67         void Treiber_HP();
68         void Treiber_HRC();
69         void Treiber_PTB();
70         void Treiber_HP_yield();
71         void Treiber_HRC_yield();
72         void Treiber_PTB_yield();
73         void Treiber_HP_pause_alloc();
74         void Treiber_HRC_pause_alloc();
75         void Treiber_PTB_pause_alloc();
76
77         void Treiber_HP_relaxed();
78         void Treiber_HRC_relaxed();
79         void Treiber_PTB_relaxed();
80         void Treiber_HP_yield_relaxed();
81         void Treiber_HRC_yield_relaxed();
82         void Treiber_PTB_yield_relaxed();
83         void Treiber_HP_pause_alloc_relaxed();
84         void Treiber_HRC_pause_alloc_relaxed();
85         void Treiber_PTB_pause_alloc_relaxed();
86
87         void Elimination_HP();
88         void Elimination_HP_dyn();
89         void Elimination_HP_stat();
90         void Elimination_HRC();
91         void Elimination_HRC_dyn();
92         void Elimination_HRC_stat();
93         void Elimination_PTB();
94         void Elimination_PTB_dyn();
95         void Elimination_PTB_stat();
96         void Elimination_HP_yield();
97         void Elimination_HRC_yield();
98         void Elimination_PTB_yield();
99         void Elimination_HP_pause_alloc();
100         void Elimination_HRC_pause_alloc();
101         void Elimination_PTB_pause_alloc();
102
103         void Elimination_HP_relaxed();
104         void Elimination_HRC_relaxed();
105         void Elimination_PTB_relaxed();
106         void Elimination_HP_yield_relaxed();
107         void Elimination_HRC_yield_relaxed();
108         void Elimination_PTB_yield_relaxed();
109         void Elimination_HP_pause_alloc_relaxed();
110         void Elimination_HRC_pause_alloc_relaxed();
111         void Elimination_PTB_pause_alloc_relaxed();
112
113         CPPUNIT_TEST_SUITE(TestStack);
114             CPPUNIT_TEST(Treiber_HP)
115             CPPUNIT_TEST(Treiber_HP_relaxed)
116             CPPUNIT_TEST(Treiber_HRC)
117             CPPUNIT_TEST(Treiber_HRC_relaxed)
118             CPPUNIT_TEST(Treiber_PTB)
119             CPPUNIT_TEST(Treiber_PTB_relaxed)
120             CPPUNIT_TEST(Treiber_HP_yield)
121             CPPUNIT_TEST(Treiber_HP_yield_relaxed)
122             CPPUNIT_TEST(Treiber_HRC_yield)
123             CPPUNIT_TEST(Treiber_HRC_yield_relaxed)
124             CPPUNIT_TEST(Treiber_PTB_yield)
125             CPPUNIT_TEST(Treiber_PTB_yield_relaxed)
126             CPPUNIT_TEST(Treiber_HP_pause_alloc)
127             CPPUNIT_TEST(Treiber_HP_pause_alloc_relaxed)
128             CPPUNIT_TEST(Treiber_HRC_pause_alloc)
129             CPPUNIT_TEST(Treiber_HRC_pause_alloc_relaxed)
130             CPPUNIT_TEST(Treiber_PTB_pause_alloc)
131             CPPUNIT_TEST(Treiber_PTB_pause_alloc_relaxed)
132
133             CPPUNIT_TEST(Elimination_HP)
134             CPPUNIT_TEST(Elimination_HP_dyn)
135             CPPUNIT_TEST(Elimination_HP_stat)
136             CPPUNIT_TEST(Elimination_HP_relaxed)
137             CPPUNIT_TEST(Elimination_HRC)
138             CPPUNIT_TEST(Elimination_HRC_dyn)
139             CPPUNIT_TEST(Elimination_HRC_stat)
140             CPPUNIT_TEST(Elimination_HRC_relaxed)
141             CPPUNIT_TEST(Elimination_PTB)
142             CPPUNIT_TEST(Elimination_PTB_dyn)
143             CPPUNIT_TEST(Elimination_PTB_stat)
144             CPPUNIT_TEST(Elimination_PTB_relaxed)
145             CPPUNIT_TEST(Elimination_HP_yield)
146             CPPUNIT_TEST(Elimination_HP_yield_relaxed)
147             CPPUNIT_TEST(Elimination_HRC_yield)
148             CPPUNIT_TEST(Elimination_HRC_yield_relaxed)
149             CPPUNIT_TEST(Elimination_PTB_yield)
150             CPPUNIT_TEST(Elimination_PTB_yield_relaxed)
151             CPPUNIT_TEST(Elimination_HP_pause_alloc)
152             CPPUNIT_TEST(Elimination_HP_pause_alloc_relaxed)
153             CPPUNIT_TEST(Elimination_HRC_pause_alloc)
154             CPPUNIT_TEST(Elimination_HRC_pause_alloc_relaxed)
155             CPPUNIT_TEST(Elimination_PTB_pause_alloc)
156             CPPUNIT_TEST(Elimination_PTB_pause_alloc_relaxed)
157         CPPUNIT_TEST_SUITE_END();
158     };
159 }   // namespace stack
160