2 This file is a part of libcds - Concurrent Data Structures library
4 (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016
6 Source code repo: http://github.com/khizmax/libcds/
7 Download: http://sourceforge.net/projects/libcds/files/
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions are met:
12 * Redistributions of source code must retain the above copyright notice, this
13 list of conditions and the following disclaimer.
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.
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.
31 #ifndef CDSTEST_HDR_FCQUEUE_H
32 #define CDSTEST_HDR_FCQUEUE_H
34 #include "cppunit/cppunit_proxy.h"
35 #include <cds/details/defs.h>
40 // Test queue operation in single thread mode
42 class HdrFCQueue: public CppUnitMini::TestCase
45 template <class Queue>
46 void testNoItemCounter()
53 template <class Queue>
54 void test_with( Queue& q )
59 for ( size_t i = 0; i < 3; ++i ) {
60 CPPUNIT_ASSERT( q.empty() );
62 CPPUNIT_ASSERT( q.size() == 0 );
64 CPPUNIT_ASSERT( q.enqueue( 1 ) );
65 CPPUNIT_ASSERT( !q.empty() );
66 CPPUNIT_ASSERT( q.push( 10 ) );
67 CPPUNIT_ASSERT( !q.empty() );
69 CPPUNIT_ASSERT( q.size() == 0 ) ; // no queue's item counter!
73 CPPUNIT_ASSERT( q.pop( it ) );
74 CPPUNIT_ASSERT( it == 1 );
75 CPPUNIT_ASSERT( !q.empty() );
76 CPPUNIT_ASSERT( q.dequeue( it ) );
77 CPPUNIT_ASSERT( it == 10 );
79 CPPUNIT_ASSERT( q.size() == 0 );
81 CPPUNIT_ASSERT( q.empty() );
84 CPPUNIT_ASSERT( !q.dequeue( it ) );
85 CPPUNIT_ASSERT( it == nPrev ) ; // it must not be changed!
89 template <class Queue>
90 void test_emplace( Queue& q )
93 for ( size_t i = 0; i < 3; ++i ) {
94 CPPUNIT_ASSERT( q.emplace( static_cast<int>( i * 42 )) );
95 CPPUNIT_ASSERT( !q.empty() );
97 CPPUNIT_ASSERT( q.pop( it ));
98 CPPUNIT_ASSERT( it == static_cast<int>( i * 42 ));
99 CPPUNIT_ASSERT( q.empty() );
103 template <class Queue>
104 void testWithItemCounter()
108 test_emplace_ic( q );
111 template <class Queue>
118 template <class Queue>
119 void test_ic_with( Queue& q )
124 for ( size_t i = 0; i < 3; ++i ) {
125 CPPUNIT_ASSERT( q.empty() );
126 CPPUNIT_ASSERT( q.size() == 0 );
127 CPPUNIT_ASSERT( q.enqueue( 1 ) );
128 CPPUNIT_ASSERT( q.size() == 1 );
129 CPPUNIT_ASSERT( !q.empty() );
130 CPPUNIT_ASSERT( q.push( 10 ) );
131 CPPUNIT_ASSERT( !q.empty() );
132 CPPUNIT_ASSERT( q.size() == 2 );
135 CPPUNIT_ASSERT( q.pop( it ) );
136 CPPUNIT_ASSERT( it == 1 );
137 CPPUNIT_ASSERT( !q.empty() );
138 CPPUNIT_ASSERT( q.size() == 1 );
139 CPPUNIT_ASSERT( q.dequeue( it ) );
140 CPPUNIT_ASSERT( it == 10 );
141 CPPUNIT_ASSERT( q.size() == 0 );
142 CPPUNIT_ASSERT( q.empty() );
143 CPPUNIT_ASSERT( q.size() == 0 );
146 CPPUNIT_ASSERT( !q.dequeue( it ) );
147 CPPUNIT_ASSERT( it == nPrev ) ; // it must not be changed!
149 CPPUNIT_ASSERT( q.empty() );
150 CPPUNIT_ASSERT( q.size() == 0 );
154 template <class Queue>
155 void test_emplace_ic( Queue& q )
158 for ( size_t i = 0; i < 3; ++i ) {
159 CPPUNIT_ASSERT( q.emplace( (int) i * 10 ) );
160 CPPUNIT_ASSERT( !q.empty() );
161 CPPUNIT_ASSERT( q.size() == 1 );
162 CPPUNIT_ASSERT( q.pop( it ));
163 CPPUNIT_ASSERT( it == (int) i * 10 );
164 CPPUNIT_ASSERT( q.empty() );
165 CPPUNIT_ASSERT( q.size() == 0 );
170 void FCQueue_deque();
171 void FCQueue_deque_elimination();
172 void FCQueue_deque_mutex();
173 void FCQueue_deque_stat();
175 void FCQueue_list_elimination();
176 void FCQueue_list_mutex();
177 void FCQueue_list_stat();
179 CPPUNIT_TEST_SUITE(HdrFCQueue)
180 CPPUNIT_TEST(FCQueue_deque)
181 CPPUNIT_TEST(FCQueue_deque_elimination)
182 CPPUNIT_TEST(FCQueue_deque_mutex)
183 CPPUNIT_TEST(FCQueue_deque_stat)
184 CPPUNIT_TEST(FCQueue_list)
185 CPPUNIT_TEST(FCQueue_list_elimination)
186 CPPUNIT_TEST(FCQueue_list_mutex)
187 CPPUNIT_TEST(FCQueue_list_stat)
188 CPPUNIT_TEST_SUITE_END();
193 #endif // #ifndef CDSTEST_HDR_FCQUEUE_H