Fixed FCQueue tests
authorkhizmax <libcds.dev@gmail.com>
Mon, 16 Jan 2017 19:28:42 +0000 (22:28 +0300)
committerkhizmax <libcds.dev@gmail.com>
Mon, 16 Jan 2017 19:28:42 +0000 (22:28 +0300)
test/include/cds_test/fc_hevy_value.h
test/unit/queue/fcqueue.cpp

index ba3fc26..96db444 100644 (file)
@@ -16,13 +16,16 @@ namespace fc_test {
     // 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) ;
@@ -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<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>
index 3a553ab..f6fccd0 100644 (file)
@@ -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<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 );
@@ -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<value_type>( nSize * 2 ));
             ASSERT_TRUE( q.empty());
@@ -137,6 +137,76 @@ namespace {
             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 )
@@ -173,7 +243,7 @@ namespace {
         typedef cds::container::FCQueue<ValueType> 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 )