// SFINAE test
template <typename T>
class has_set_array_size {
- typedef char small;
- class big{char dummy[2];};
+ typedef char select_small;
+ class select_big {
+ char dummy[2];
+ };
- template <typename C, void (C::*) (size_t)> class SFINAE {};
+ template <typename C, void (C::*) (size_t)> class selector
+ {};
- template <typename C> static small test( SFINAE<C, &C::set_array> * ) ;
- template <typename C> static big test(...);
+ template <typename C> static select_small test( selector<C, &C::set_array>* ) ;
+ template <typename C> static select_big test(...);
public:
static constexpr bool value = sizeof(test<T>(0)) == sizeof(char) ;
: value(new_value),
nNo(0),
nWriterNo(0)
- {
- };
- heavy_value(const heavy_value &other)
- : value(other.value),
- nNo(other.nNo),
- nWriterNo(other.nWriterNo)
+ {};
+
+ heavy_value( heavy_value const& other)
+ : value(other.value)
+ , nNo(other.nNo)
+ , nWriterNo(other.nWriterNo)
{
for(size_t i = 0; i < buffer_size; ++i)
pop_buff[i] = static_cast<int>(std::sqrt(other.pop_buff[i]*rand()));
}
- void set_array(size_t new_size) {
+
+ void set_array(size_t new_size)
+ {
set_array_size(new_size);
}
- static void set_array_size(size_t new_size){
+
+ static void set_array_size(size_t new_size)
+ {
if (buffer_size == new_size) return;
buffer_size = new_size;
pop_buff.resize(buffer_size, rand());
}
};
+
template<int DefaultSize>
std::vector<int> heavy_value< DefaultSize >::pop_buff(DefaultSize, rand());
template<int DefaultSize>
typedef typename Queue::value_type value_type;
value_type it;
- const size_t nSize = 100;
+ const int nSize = 100;
ASSERT_TRUE( q.empty());
ASSERT_EQ( q.size(), 0u );
// enqueue/dequeue
- for ( size_t i = 0; i < nSize; ++i ) {
- ASSERT_TRUE( q.enqueue( static_cast<value_type>(i)));
+ for ( int i = 0; i < nSize; ++i ) {
+ ASSERT_TRUE( q.enqueue( value_type(i)));
ASSERT_EQ( q.size(), i + 1 );
}
ASSERT_FALSE( q.empty());
ASSERT_EQ( q.size(), nSize );
- for ( size_t i = 0; i < nSize; ++i ) {
- it = -1;
+ for ( int i = 0; i < nSize; ++i ) {
+ it = value_type( -1 );
ASSERT_TRUE( q.dequeue( it ));
- ASSERT_EQ( it, static_cast<value_type>( i ));
+ ASSERT_EQ( it, value_type( i ));
ASSERT_EQ( q.size(), nSize - i - 1 );
}
ASSERT_TRUE( q.empty());
ASSERT_EQ( q.size(), 0u );
// push/pop
- for ( size_t i = 0; i < nSize; ++i ) {
- ASSERT_TRUE( q.push( static_cast<value_type>(i)));
+ for ( int i = 0; i < nSize; ++i ) {
+ ASSERT_TRUE( q.push( value_type(i)));
ASSERT_EQ( q.size(), i + 1 );
}
ASSERT_FALSE( q.empty());
ASSERT_EQ( q.size(), nSize );
- for ( size_t i = 0; i < nSize; ++i ) {
- it = -1;
+ for ( int i = 0; i < nSize; ++i ) {
+ it = value_type( -1 );
ASSERT_TRUE( q.pop( it ));
- ASSERT_EQ( it, static_cast<value_type>( i ));
+ ASSERT_EQ( it, value_type( i ));
ASSERT_EQ( q.size(), nSize - i - 1 );
}
ASSERT_TRUE( q.empty());
ASSERT_EQ( q.size(), 0u );
// clear
- for ( size_t i = 0; i < nSize; ++i ) {
- ASSERT_TRUE( q.push( static_cast<value_type>( i )));
+ for ( int i = 0; i < nSize; ++i ) {
+ ASSERT_TRUE( q.push( value_type( i )));
}
ASSERT_FALSE( q.empty());
ASSERT_EQ( q.size(), nSize );
ASSERT_EQ( q.size(), 0u );
// pop from empty queue
- it = nSize * 2;
+ it = value_type( nSize * 2 );
ASSERT_FALSE( q.pop( it ));
ASSERT_EQ( it, static_cast<value_type>( nSize * 2 ));
ASSERT_TRUE( q.empty());
ASSERT_TRUE( q.empty());
ASSERT_EQ( q.size(), 0u );
}
+
+ template <class Queue>
+ void test_heavy( Queue& q )
+ {
+ typedef typename Queue::value_type value_type;
+ value_type it;
+
+ const int nSize = 100;
+
+ ASSERT_TRUE( q.empty() );
+ ASSERT_EQ( q.size(), 0u );
+
+ // enqueue/dequeue
+ for ( int i = 0; i < nSize; ++i ) {
+ ASSERT_TRUE( q.enqueue( value_type( i )));
+ ASSERT_EQ( q.size(), i + 1 );
+ }
+ ASSERT_FALSE( q.empty() );
+ ASSERT_EQ( q.size(), nSize );
+
+ for ( int i = 0; i < nSize; ++i ) {
+ it.value = -1;
+ ASSERT_TRUE( q.dequeue( it ) );
+ ASSERT_EQ( it.value, i );
+ ASSERT_EQ( q.size(), nSize - i - 1 );
+ }
+ ASSERT_TRUE( q.empty() );
+ ASSERT_EQ( q.size(), 0u );
+
+ // push/pop
+ for ( int i = 0; i < nSize; ++i ) {
+ ASSERT_TRUE( q.push( value_type( i )));
+ ASSERT_EQ( q.size(), i + 1 );
+ }
+ ASSERT_FALSE( q.empty() );
+ ASSERT_EQ( q.size(), nSize );
+
+ for ( int i = 0; i < nSize; ++i ) {
+ it.value = -1;
+ ASSERT_TRUE( q.pop( it ) );
+ ASSERT_EQ( it.value, i );
+ ASSERT_EQ( q.size(), nSize - i - 1 );
+ }
+ ASSERT_TRUE( q.empty() );
+ ASSERT_EQ( q.size(), 0u );
+
+ // clear
+ for ( int i = 0; i < nSize; ++i ) {
+ ASSERT_TRUE( q.push( value_type( i )));
+ }
+ ASSERT_FALSE( q.empty() );
+ ASSERT_EQ( q.size(), nSize );
+
+ q.clear();
+ ASSERT_TRUE( q.empty() );
+ ASSERT_EQ( q.size(), 0u );
+
+ // pop from empty queue
+ it = value_type( nSize * 2 );
+ ASSERT_FALSE( q.pop( it ) );
+ ASSERT_EQ( it.value, nSize * 2 );
+ ASSERT_TRUE( q.empty() );
+ ASSERT_EQ( q.size(), 0u );
+
+ ASSERT_FALSE( q.dequeue( it ) );
+ ASSERT_EQ( it.value, nSize * 2 );
+ ASSERT_TRUE( q.empty() );
+ ASSERT_EQ( q.size(), 0u );
+ }
+
};
TEST_F( FCQueue, std_deque )
typedef cds::container::FCQueue<ValueType> queue_type;
queue_type q;
- test( q );
+ test_heavy( q );
}
TEST_F( FCQueue, std_empty_wait_strategy_heavy_value )
> queue_type;
queue_type q;
- test( q );
+ test_heavy( q );
}
TEST_F( FCQueue, std_single_mutex_single_condvar_heavy_value )
> queue_type;
queue_type q;
- test( q );
+ test_heavy( q );
}
TEST_F( FCQueue, std_single_mutex_multi_condvar_heavy_value )
> queue_type;
queue_type q;
- test( q );
+ test_heavy( q );
}
TEST_F( FCQueue, std_multi_mutex_multi_condvar_heavy_value )
> queue_type;
queue_type q;
- test( q );
+ test_heavy( q );
}
TEST_F( FCQueue, std_single_mutex_single_condvar )