From: khizmax Date: Mon, 16 Jan 2017 19:28:42 +0000 (+0300) Subject: Fixed FCQueue tests X-Git-Tag: v2.3.0~203 X-Git-Url: http://plrg.eecs.uci.edu/git/?p=libcds.git;a=commitdiff_plain;h=4b7d4444f2d72fdb37261ec7e0e012aee4d987bb Fixed FCQueue tests --- diff --git a/test/include/cds_test/fc_hevy_value.h b/test/include/cds_test/fc_hevy_value.h index ba3fc266..96db4440 100644 --- a/test/include/cds_test/fc_hevy_value.h +++ b/test/include/cds_test/fc_hevy_value.h @@ -16,13 +16,16 @@ namespace fc_test { // SFINAE test template class has_set_array_size { - typedef char small; - class big{char dummy[2];}; + typedef char select_small; + class select_big { + char dummy[2]; + }; - template class SFINAE {}; + template class selector + {}; - template static small test( SFINAE * ) ; - template static big test(...); + template static select_small test( selector* ) ; + template static select_big test(...); public: static constexpr bool value = sizeof(test(0)) == sizeof(char) ; @@ -43,25 +46,30 @@ namespace fc_test { : 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(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 std::vector heavy_value< DefaultSize >::pop_buff(DefaultSize, rand()); template diff --git a/test/unit/queue/fcqueue.cpp b/test/unit/queue/fcqueue.cpp index 3a553ab2..f6fccd0b 100644 --- a/test/unit/queue/fcqueue.cpp +++ b/test/unit/queue/fcqueue.cpp @@ -45,48 +45,48 @@ namespace { 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(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( 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(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( 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( i ))); + for ( int i = 0; i < nSize; ++i ) { + ASSERT_TRUE( q.push( value_type( i ))); } ASSERT_FALSE( q.empty()); ASSERT_EQ( q.size(), nSize ); @@ -96,7 +96,7 @@ namespace { 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( nSize * 2 )); ASSERT_TRUE( q.empty()); @@ -137,6 +137,76 @@ namespace { ASSERT_TRUE( q.empty()); ASSERT_EQ( q.size(), 0u ); } + + template + 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 ) @@ -173,7 +243,7 @@ namespace { typedef cds::container::FCQueue queue_type; queue_type q; - test( q ); + test_heavy( q ); } TEST_F( FCQueue, std_empty_wait_strategy_heavy_value ) @@ -186,7 +256,7 @@ namespace { > queue_type; queue_type q; - test( q ); + test_heavy( q ); } TEST_F( FCQueue, std_single_mutex_single_condvar_heavy_value ) @@ -199,7 +269,7 @@ namespace { > queue_type; queue_type q; - test( q ); + test_heavy( q ); } TEST_F( FCQueue, std_single_mutex_multi_condvar_heavy_value ) @@ -212,7 +282,7 @@ namespace { > queue_type; queue_type q; - test( q ); + test_heavy( q ); } TEST_F( FCQueue, std_multi_mutex_multi_condvar_heavy_value ) @@ -225,7 +295,7 @@ namespace { > queue_type; queue_type q; - test( q ); + test_heavy( q ); } TEST_F( FCQueue, std_single_mutex_single_condvar )