3 #ifndef __CDSUNIT_HDR_FCQUEUE_H
4 #define __CDSUNIT_HDR_FCQUEUE_H
6 #include "cppunit/cppunit_proxy.h"
7 #include <cds/details/defs.h>
12 // Test queue operation in single thread mode
14 class HdrFCQueue: public CppUnitMini::TestCase
17 template <class Queue>
18 void testNoItemCounter()
25 template <class Queue>
26 void test_with( Queue& q )
31 for ( size_t i = 0; i < 3; ++i ) {
32 CPPUNIT_ASSERT( q.empty() );
34 CPPUNIT_ASSERT( q.size() == 0 );
36 CPPUNIT_ASSERT( q.enqueue( 1 ) );
37 CPPUNIT_ASSERT( !q.empty() );
38 CPPUNIT_ASSERT( q.push( 10 ) );
39 CPPUNIT_ASSERT( !q.empty() );
41 CPPUNIT_ASSERT( q.size() == 0 ) ; // no queue's item counter!
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 );
51 CPPUNIT_ASSERT( q.size() == 0 );
53 CPPUNIT_ASSERT( q.empty() );
56 CPPUNIT_ASSERT( !q.dequeue( it ) );
57 CPPUNIT_ASSERT( it == nPrev ) ; // it must not be changed!
61 template <class Queue>
62 void test_emplace( Queue& q )
65 for ( size_t i = 0; i < 3; ++i ) {
66 CPPUNIT_ASSERT( q.emplace( static_cast<int>( i * 42 )) );
67 CPPUNIT_ASSERT( !q.empty() );
69 CPPUNIT_ASSERT( q.pop( it ));
70 CPPUNIT_ASSERT( it == static_cast<int>( i * 42 ));
71 CPPUNIT_ASSERT( q.empty() );
75 template <class Queue>
76 void testWithItemCounter()
83 template <class Queue>
90 template <class Queue>
91 void test_ic_with( Queue& q )
96 for ( size_t i = 0; i < 3; ++i ) {
97 CPPUNIT_ASSERT( q.empty() );
98 CPPUNIT_ASSERT( q.size() == 0 );
99 CPPUNIT_ASSERT( q.enqueue( 1 ) );
100 CPPUNIT_ASSERT( q.size() == 1 );
101 CPPUNIT_ASSERT( !q.empty() );
102 CPPUNIT_ASSERT( q.push( 10 ) );
103 CPPUNIT_ASSERT( !q.empty() );
104 CPPUNIT_ASSERT( q.size() == 2 );
107 CPPUNIT_ASSERT( q.pop( it ) );
108 CPPUNIT_ASSERT( it == 1 );
109 CPPUNIT_ASSERT( !q.empty() );
110 CPPUNIT_ASSERT( q.size() == 1 );
111 CPPUNIT_ASSERT( q.dequeue( it ) );
112 CPPUNIT_ASSERT( it == 10 );
113 CPPUNIT_ASSERT( q.size() == 0 );
114 CPPUNIT_ASSERT( q.empty() );
115 CPPUNIT_ASSERT( q.size() == 0 );
118 CPPUNIT_ASSERT( !q.dequeue( it ) );
119 CPPUNIT_ASSERT( it == nPrev ) ; // it must not be changed!
121 CPPUNIT_ASSERT( q.empty() );
122 CPPUNIT_ASSERT( q.size() == 0 );
126 template <class Queue>
127 void test_emplace_ic( Queue& q )
130 for ( size_t i = 0; i < 3; ++i ) {
131 CPPUNIT_ASSERT( q.emplace( (int) i * 10 ) );
132 CPPUNIT_ASSERT( !q.empty() );
133 CPPUNIT_ASSERT( q.size() == 1 );
134 CPPUNIT_ASSERT( q.pop( it ));
135 CPPUNIT_ASSERT( it == (int) i * 10 );
136 CPPUNIT_ASSERT( q.empty() );
137 CPPUNIT_ASSERT( q.size() == 0 );
142 void FCQueue_deque();
143 void FCQueue_deque_elimination();
144 void FCQueue_deque_mutex();
145 void FCQueue_deque_stat();
147 void FCQueue_list_elimination();
148 void FCQueue_list_mutex();
149 void FCQueue_list_stat();
151 CPPUNIT_TEST_SUITE(HdrFCQueue)
152 CPPUNIT_TEST(FCQueue_deque)
153 CPPUNIT_TEST(FCQueue_deque_elimination)
154 CPPUNIT_TEST(FCQueue_deque_mutex)
155 CPPUNIT_TEST(FCQueue_deque_stat)
156 CPPUNIT_TEST(FCQueue_list)
157 CPPUNIT_TEST(FCQueue_list_elimination)
158 CPPUNIT_TEST(FCQueue_list_mutex)
159 CPPUNIT_TEST(FCQueue_list_stat)
160 CPPUNIT_TEST_SUITE_END();
165 #endif // #ifndef __CDSUNIT_HDR_FCQUEUE_H