Replace NULL with nullptr
[libcds.git] / tests / test-hdr / queue / queue_test_header.h
1 //$$CDS-header$$
2
3 #ifndef __UNIT_QUEUE_SIMPLE_H
4 #define __UNIT_QUEUE_SIMPLE_H
5
6 #include "cppunit/cppunit_proxy.h"
7 #include <cds/details/defs.h>
8
9 namespace queue {
10
11     //
12     // Test queue operation in single thread mode
13     //
14     class Queue_TestHeader: public CppUnitMini::TestCase
15     {
16     protected:
17         template <class Queue>
18         void testNoItemCounter()
19         {
20             Queue   q;
21             test_with( q );
22             test_emplace( q );
23         }
24
25         template <class Queue>
26         void test_with( Queue& q )
27         {
28             int     it;
29             int     nPrev;
30
31             for ( size_t i = 0; i < 3; ++i ) {
32                 CPPUNIT_ASSERT( q.empty() );
33 #ifndef _DEBUG
34                 CPPUNIT_ASSERT( q.size() == 0 );
35 #endif
36                 CPPUNIT_ASSERT( q.enqueue( 1 ) );
37                 CPPUNIT_ASSERT( !q.empty() );
38                 CPPUNIT_ASSERT( q.push( 10 ) );
39                 CPPUNIT_ASSERT( !q.empty() );
40 #ifndef _DEBUG
41                 CPPUNIT_ASSERT( q.size() == 0 )     ;   // no queue's item counter!
42 #endif
43
44                 it = -1;
45                 CPPUNIT_ASSERT( q.pop( it ) );
46                 CPPUNIT_ASSERT( it == 1 );
47                 CPPUNIT_ASSERT( !q.empty() );
48                 CPPUNIT_ASSERT( q.dequeue( it ) );
49                 CPPUNIT_ASSERT( it == 10 );
50 #ifndef _DEBUG
51                 CPPUNIT_ASSERT( q.size() == 0 );
52 #endif
53                 CPPUNIT_ASSERT( q.empty() );
54                 it += 2009;
55                 nPrev = it;
56                 CPPUNIT_ASSERT( !q.dequeue( it ) );
57                 CPPUNIT_ASSERT( it == nPrev )       ;   // it must not be changed!
58             }
59         }
60
61         template <class Queue>
62         void test_emplace( Queue& q )
63         {
64 #   ifdef CDS_EMPLACE_SUPPORT
65             int     it;
66             for ( size_t i = 0; i < 3; ++i ) {
67                 CPPUNIT_ASSERT( q.emplace( static_cast<int>( i * 42 )) );
68                 CPPUNIT_ASSERT( !q.empty() );
69                 it = -1;
70                 CPPUNIT_ASSERT( q.pop( it ));
71                 CPPUNIT_ASSERT( it == static_cast<int>( i * 42 ));
72                 CPPUNIT_ASSERT( q.empty() );
73             }
74 #   endif
75         }
76
77         template <class Queue>
78         void testWithItemCounter()
79         {
80             Queue   q;
81             test_ic_with( q );
82             test_emplace_ic( q );
83         }
84
85         template <class Queue>
86         void testFCQueue()
87         {
88             Queue   q;
89             test_ic_with( q );
90         }
91
92         template <class Queue>
93         void test_ic_with( Queue& q )
94         {
95             int     it;
96             int     nPrev;
97
98             for ( size_t i = 0; i < 3; ++i ) {
99                 CPPUNIT_ASSERT( q.empty() );
100                 CPPUNIT_ASSERT( q.size() == 0 );
101                 CPPUNIT_ASSERT( q.enqueue( 1 ) );
102                 CPPUNIT_ASSERT( q.size() == 1 );
103                 CPPUNIT_ASSERT( !q.empty() );
104                 CPPUNIT_ASSERT( q.push( 10 ) );
105                 CPPUNIT_ASSERT( !q.empty() );
106                 CPPUNIT_ASSERT( q.size() == 2 );
107
108                 it = -1;
109                 CPPUNIT_ASSERT( q.pop( it ) );
110                 CPPUNIT_ASSERT( it == 1 );
111                 CPPUNIT_ASSERT( !q.empty() );
112                 CPPUNIT_ASSERT( q.size() == 1 );
113                 CPPUNIT_ASSERT( q.dequeue( it ) );
114                 CPPUNIT_ASSERT( it == 10 );
115                 CPPUNIT_ASSERT( q.size() == 0 );
116                 CPPUNIT_ASSERT( q.empty() );
117                 CPPUNIT_ASSERT( q.size() == 0 );
118                 it += 2009;
119                 nPrev = it;
120                 CPPUNIT_ASSERT( !q.dequeue( it ) );
121                 CPPUNIT_ASSERT( it == nPrev )       ;   // it must not be changed!
122
123                 CPPUNIT_ASSERT( q.empty() );
124                 CPPUNIT_ASSERT( q.size() == 0 );
125             }
126         }
127
128         template <class Queue>
129         void test_emplace_ic( Queue& q )
130         {
131 #   ifdef CDS_EMPLACE_SUPPORT
132             int     it = 0;
133             for ( size_t i = 0; i < 3; ++i ) {
134                 CPPUNIT_ASSERT( q.emplace( (int) i * 10 ) );
135                 CPPUNIT_ASSERT( !q.empty() );
136                 CPPUNIT_ASSERT( q.size() == 1 );
137                 CPPUNIT_ASSERT( q.pop( it ));
138                 CPPUNIT_ASSERT( it == (int) i * 10 );
139                 CPPUNIT_ASSERT( q.empty() );
140                 CPPUNIT_ASSERT( q.size() == 0 );
141             }
142 #   endif
143         }
144
145     public:
146         void MSQueue_HP();
147         void MSQueue_HP_relax();
148         void MSQueue_HP_seqcst();
149         void MSQueue_HP_relax_align();
150         void MSQueue_HP_seqcst_align();
151         void MSQueue_HP_Counted();
152         void MSQueue_HP_Counted_relax();
153         void MSQueue_HP_Counted_seqcst();
154         void MSQueue_HP_Counted_relax_align();
155         void MSQueue_HP_Counted_seqcst_align();
156
157         void MSQueue_HRC();
158         void MSQueue_HRC_relax();
159         void MSQueue_HRC_seqcst();
160         void MSQueue_HRC_relax_align();
161         void MSQueue_HRC_seqcst_align();
162         void MSQueue_HRC_Counted();
163         void MSQueue_HRC_Counted_relax();
164         void MSQueue_HRC_Counted_seqcst();
165         void MSQueue_HRC_Counted_relax_align();
166         void MSQueue_HRC_Counted_seqcst_align();
167
168         void MSQueue_PTB();
169         void MSQueue_PTB_relax();
170         void MSQueue_PTB_seqcst();
171         void MSQueue_PTB_relax_align();
172         void MSQueue_PTB_seqcst_align();
173         void MSQueue_PTB_Counted();
174         void MSQueue_PTB_Counted_relax();
175         void MSQueue_PTB_Counted_seqcst();
176         void MSQueue_PTB_Counted_relax_align();
177         void MSQueue_PTB_Counted_seqcst_align();
178
179         void MoirQueue_HP();
180         void MoirQueue_HP_relax();
181         void MoirQueue_HP_seqcst();
182         void MoirQueue_HP_relax_align();
183         void MoirQueue_HP_seqcst_align();
184         void MoirQueue_HP_Counted();
185         void MoirQueue_HP_Counted_relax();
186         void MoirQueue_HP_Counted_seqcst();
187         void MoirQueue_HP_Counted_relax_align();
188         void MoirQueue_HP_Counted_seqcst_align();
189
190         void MoirQueue_HRC();
191         void MoirQueue_HRC_relax();
192         void MoirQueue_HRC_seqcst();
193         void MoirQueue_HRC_relax_align();
194         void MoirQueue_HRC_seqcst_align();
195         void MoirQueue_HRC_Counted();
196         void MoirQueue_HRC_Counted_relax();
197         void MoirQueue_HRC_Counted_seqcst();
198         void MoirQueue_HRC_Counted_relax_align();
199         void MoirQueue_HRC_Counted_seqcst_align();
200
201         void MoirQueue_PTB();
202         void MoirQueue_PTB_relax();
203         void MoirQueue_PTB_seqcst();
204         void MoirQueue_PTB_relax_align();
205         void MoirQueue_PTB_seqcst_align();
206         void MoirQueue_PTB_Counted();
207         void MoirQueue_PTB_Counted_relax();
208         void MoirQueue_PTB_Counted_seqcst();
209         void MoirQueue_PTB_Counted_relax_align();
210         void MoirQueue_PTB_Counted_seqcst_align();
211
212         void OptimisticQueue_HP();
213         void OptimisticQueue_HP_relax();
214         void OptimisticQueue_HP_seqcst();
215         void OptimisticQueue_HP_relax_align();
216         void OptimisticQueue_HP_seqcst_align();
217         void OptimisticQueue_HP_Counted();
218         void OptimisticQueue_HP_Counted_relax();
219         void OptimisticQueue_HP_Counted_seqcst();
220         void OptimisticQueue_HP_Counted_relax_align();
221         void OptimisticQueue_HP_Counted_seqcst_align();
222
223         void OptimisticQueue_PTB();
224         void OptimisticQueue_PTB_relax();
225         void OptimisticQueue_PTB_seqcst();
226         void OptimisticQueue_PTB_relax_align();
227         void OptimisticQueue_PTB_seqcst_align();
228         void OptimisticQueue_PTB_Counted();
229         void OptimisticQueue_PTB_Counted_relax();
230         void OptimisticQueue_PTB_Counted_seqcst();
231         void OptimisticQueue_PTB_Counted_relax_align();
232         void OptimisticQueue_PTB_Counted_seqcst_align();
233
234         void BasketQueue_HP();
235         void BasketQueue_HP_relax();
236         void BasketQueue_HP_seqcst();
237         void BasketQueue_HP_relax_align();
238         void BasketQueue_HP_seqcst_align();
239         void BasketQueue_HP_Counted();
240         void BasketQueue_HP_Counted_relax();
241         void BasketQueue_HP_Counted_seqcst();
242         void BasketQueue_HP_Counted_relax_align();
243         void BasketQueue_HP_Counted_seqcst_align();
244
245         void BasketQueue_HRC();
246         void BasketQueue_HRC_relax();
247         void BasketQueue_HRC_seqcst();
248         void BasketQueue_HRC_relax_align();
249         void BasketQueue_HRC_seqcst_align();
250         void BasketQueue_HRC_Counted();
251         void BasketQueue_HRC_Counted_relax();
252         void BasketQueue_HRC_Counted_seqcst();
253         void BasketQueue_HRC_Counted_relax_align();
254         void BasketQueue_HRC_Counted_seqcst_align();
255
256         void BasketQueue_PTB();
257         void BasketQueue_PTB_relax();
258         void BasketQueue_PTB_seqcst();
259         void BasketQueue_PTB_relax_align();
260         void BasketQueue_PTB_seqcst_align();
261         void BasketQueue_PTB_Counted();
262         void BasketQueue_PTB_Counted_relax();
263         void BasketQueue_PTB_Counted_seqcst();
264         void BasketQueue_PTB_Counted_relax_align();
265         void BasketQueue_PTB_Counted_seqcst_align();
266
267         void FCQueue_deque();
268         void FCQueue_deque_elimination();
269         void FCQueue_deque_mutex();
270         void FCQueue_deque_stat();
271         void FCQueue_list();
272         void FCQueue_list_elimination();
273         void FCQueue_list_mutex();
274         void FCQueue_list_stat();
275
276         void Vyukov_MPMCCyclicQueue();
277         void Vyukov_MPMCCyclicQueue_Counted();
278
279         void RWQueue_();
280         void RWQueue_Counted();
281
282         CPPUNIT_TEST_SUITE(Queue_TestHeader)
283             CPPUNIT_TEST(MSQueue_HP);
284             CPPUNIT_TEST(MSQueue_HP_relax);
285             CPPUNIT_TEST(MSQueue_HP_seqcst);
286             CPPUNIT_TEST(MSQueue_HP_relax_align);
287             CPPUNIT_TEST(MSQueue_HP_seqcst_align);
288             CPPUNIT_TEST(MSQueue_HP_Counted);
289             CPPUNIT_TEST(MSQueue_HP_Counted_relax);
290             CPPUNIT_TEST(MSQueue_HP_Counted_seqcst);
291             CPPUNIT_TEST(MSQueue_HP_Counted_relax_align);
292             CPPUNIT_TEST(MSQueue_HP_Counted_seqcst_align);
293
294             CPPUNIT_TEST(MSQueue_HRC);
295             CPPUNIT_TEST(MSQueue_HRC_relax);
296             CPPUNIT_TEST(MSQueue_HRC_seqcst);
297             CPPUNIT_TEST(MSQueue_HRC_relax_align);
298             CPPUNIT_TEST(MSQueue_HRC_seqcst_align);
299             CPPUNIT_TEST(MSQueue_HRC_Counted);
300             CPPUNIT_TEST(MSQueue_HRC_Counted_relax);
301             CPPUNIT_TEST(MSQueue_HRC_Counted_seqcst);
302             CPPUNIT_TEST(MSQueue_HRC_Counted_relax_align);
303             CPPUNIT_TEST(MSQueue_HRC_Counted_seqcst_align);
304
305             CPPUNIT_TEST(MSQueue_PTB);
306             CPPUNIT_TEST(MSQueue_PTB_relax);
307             CPPUNIT_TEST(MSQueue_PTB_seqcst);
308             CPPUNIT_TEST(MSQueue_PTB_relax_align);
309             CPPUNIT_TEST(MSQueue_PTB_seqcst_align);
310             CPPUNIT_TEST(MSQueue_PTB_Counted);
311             CPPUNIT_TEST(MSQueue_PTB_Counted_relax);
312             CPPUNIT_TEST(MSQueue_PTB_Counted_seqcst);
313             CPPUNIT_TEST(MSQueue_PTB_Counted_relax_align);
314             CPPUNIT_TEST(MSQueue_PTB_Counted_seqcst_align);
315
316             CPPUNIT_TEST(MoirQueue_HP);
317             CPPUNIT_TEST(MoirQueue_HP_relax);
318             CPPUNIT_TEST(MoirQueue_HP_seqcst);
319             CPPUNIT_TEST(MoirQueue_HP_relax_align);
320             CPPUNIT_TEST(MoirQueue_HP_seqcst_align);
321             CPPUNIT_TEST(MoirQueue_HP_Counted);
322             CPPUNIT_TEST(MoirQueue_HP_Counted_relax);
323             CPPUNIT_TEST(MoirQueue_HP_Counted_seqcst);
324             CPPUNIT_TEST(MoirQueue_HP_Counted_relax_align);
325             CPPUNIT_TEST(MoirQueue_HP_Counted_seqcst_align);
326
327             CPPUNIT_TEST(MoirQueue_HRC);
328             CPPUNIT_TEST(MoirQueue_HRC_relax);
329             CPPUNIT_TEST(MoirQueue_HRC_seqcst);
330             CPPUNIT_TEST(MoirQueue_HRC_relax_align);
331             CPPUNIT_TEST(MoirQueue_HRC_seqcst_align);
332             CPPUNIT_TEST(MoirQueue_HRC_Counted);
333             CPPUNIT_TEST(MoirQueue_HRC_Counted_relax);
334             CPPUNIT_TEST(MoirQueue_HRC_Counted_seqcst);
335             CPPUNIT_TEST(MoirQueue_HRC_Counted_relax_align);
336             CPPUNIT_TEST(MoirQueue_HRC_Counted_seqcst_align);
337
338             CPPUNIT_TEST(MoirQueue_PTB);
339             CPPUNIT_TEST(MoirQueue_PTB_relax);
340             CPPUNIT_TEST(MoirQueue_PTB_seqcst);
341             CPPUNIT_TEST(MoirQueue_PTB_relax_align);
342             CPPUNIT_TEST(MoirQueue_PTB_seqcst_align);
343             CPPUNIT_TEST(MoirQueue_PTB_Counted);
344             CPPUNIT_TEST(MoirQueue_PTB_Counted_relax);
345             CPPUNIT_TEST(MoirQueue_PTB_Counted_seqcst);
346             CPPUNIT_TEST(MoirQueue_PTB_Counted_relax_align);
347             CPPUNIT_TEST(MoirQueue_PTB_Counted_seqcst_align);
348
349             CPPUNIT_TEST(OptimisticQueue_HP);
350             CPPUNIT_TEST(OptimisticQueue_HP_relax);
351             CPPUNIT_TEST(OptimisticQueue_HP_seqcst);
352             CPPUNIT_TEST(OptimisticQueue_HP_relax_align);
353             CPPUNIT_TEST(OptimisticQueue_HP_seqcst_align);
354             CPPUNIT_TEST(OptimisticQueue_HP_Counted);
355             CPPUNIT_TEST(OptimisticQueue_HP_Counted_relax);
356             CPPUNIT_TEST(OptimisticQueue_HP_Counted_seqcst);
357             CPPUNIT_TEST(OptimisticQueue_HP_Counted_relax_align);
358             CPPUNIT_TEST(OptimisticQueue_HP_Counted_seqcst_align);
359
360             CPPUNIT_TEST(OptimisticQueue_PTB);
361             CPPUNIT_TEST(OptimisticQueue_PTB_relax);
362             CPPUNIT_TEST(OptimisticQueue_PTB_seqcst);
363             CPPUNIT_TEST(OptimisticQueue_PTB_relax_align);
364             CPPUNIT_TEST(OptimisticQueue_PTB_seqcst_align);
365             CPPUNIT_TEST(OptimisticQueue_PTB_Counted);
366             CPPUNIT_TEST(OptimisticQueue_PTB_Counted_relax);
367             CPPUNIT_TEST(OptimisticQueue_PTB_Counted_seqcst);
368             CPPUNIT_TEST(OptimisticQueue_PTB_Counted_relax_align);
369             CPPUNIT_TEST(OptimisticQueue_PTB_Counted_seqcst_align);
370
371             CPPUNIT_TEST(BasketQueue_HP);
372             CPPUNIT_TEST(BasketQueue_HP_relax);
373             CPPUNIT_TEST(BasketQueue_HP_seqcst);
374             CPPUNIT_TEST(BasketQueue_HP_relax_align);
375             CPPUNIT_TEST(BasketQueue_HP_seqcst_align);
376             CPPUNIT_TEST(BasketQueue_HP_Counted);
377             CPPUNIT_TEST(BasketQueue_HP_Counted_relax);
378             CPPUNIT_TEST(BasketQueue_HP_Counted_seqcst);
379             CPPUNIT_TEST(BasketQueue_HP_Counted_relax_align);
380             CPPUNIT_TEST(BasketQueue_HP_Counted_seqcst_align);
381
382             CPPUNIT_TEST(BasketQueue_HRC);
383             CPPUNIT_TEST(BasketQueue_HRC_relax);
384             CPPUNIT_TEST(BasketQueue_HRC_seqcst);
385             CPPUNIT_TEST(BasketQueue_HRC_relax_align);
386             CPPUNIT_TEST(BasketQueue_HRC_seqcst_align);
387             CPPUNIT_TEST(BasketQueue_HRC_Counted);
388             CPPUNIT_TEST(BasketQueue_HRC_Counted_relax);
389             CPPUNIT_TEST(BasketQueue_HRC_Counted_seqcst);
390             CPPUNIT_TEST(BasketQueue_HRC_Counted_relax_align);
391             CPPUNIT_TEST(BasketQueue_HRC_Counted_seqcst_align);
392
393             CPPUNIT_TEST(BasketQueue_PTB);
394             CPPUNIT_TEST(BasketQueue_PTB_relax);
395             CPPUNIT_TEST(BasketQueue_PTB_seqcst);
396             CPPUNIT_TEST(BasketQueue_PTB_relax_align);
397             CPPUNIT_TEST(BasketQueue_PTB_seqcst_align);
398             CPPUNIT_TEST(BasketQueue_PTB_Counted);
399             CPPUNIT_TEST(BasketQueue_PTB_Counted_relax);
400             CPPUNIT_TEST(BasketQueue_PTB_Counted_seqcst);
401             CPPUNIT_TEST(BasketQueue_PTB_Counted_relax_align);
402             CPPUNIT_TEST(BasketQueue_PTB_Counted_seqcst_align);
403
404             CPPUNIT_TEST(FCQueue_deque)
405             CPPUNIT_TEST(FCQueue_deque_elimination)
406             CPPUNIT_TEST(FCQueue_deque_mutex)
407             CPPUNIT_TEST(FCQueue_deque_stat)
408             CPPUNIT_TEST(FCQueue_list)
409             CPPUNIT_TEST(FCQueue_list_elimination)
410             CPPUNIT_TEST(FCQueue_list_mutex)
411             CPPUNIT_TEST(FCQueue_list_stat)
412
413             CPPUNIT_TEST(RWQueue_);
414             CPPUNIT_TEST(RWQueue_Counted);
415
416             CPPUNIT_TEST(Vyukov_MPMCCyclicQueue);
417             CPPUNIT_TEST(Vyukov_MPMCCyclicQueue_Counted);
418         CPPUNIT_TEST_SUITE_END();
419
420     };
421 } // namespace queue
422
423 #endif // #ifndef __UNIT_QUEUE_SIMPLE_H