added unit tests fcqueue with heavyvalue
authorMarsel Galimullin <mfgalimullin@yandex.ru>
Sat, 27 Aug 2016 23:16:55 +0000 (02:16 +0300)
committerMarsel Galimullin <mfgalimullin@yandex.ru>
Mon, 5 Dec 2016 20:01:04 +0000 (23:01 +0300)
.gitignore
test/unit/queue/fcqueue.cpp

index 93cba78..757121b 100644 (file)
@@ -25,3 +25,5 @@
 /build/Makefile
 /build/build.sh
 /build/sample
+/.cproject
+/.settings/
index 432fb6c..03e7e50 100644 (file)
 #include <cds/container/fcqueue.h>
 
 #include <list>
+#include <math.h>
+#include <vector>
 
 namespace {
 
+       template<int DefaultSize = 10000>
+       struct HeavyValue {
+               static std::vector<int> pop_buff;
+               int value;
+               size_t buffer_size;
+
+               explicit HeavyValue(int new_value = 0, size_t new_bufer_size = DefaultSize)
+               : value(new_value),
+                 buffer_size(new_bufer_size)
+
+               {
+                       if( buffer_size != pop_buff.size() ){
+                               pop_buff.resize(buffer_size);
+                       }
+               };
+               HeavyValue(const HeavyValue &other)
+                       : value(other.value),
+                         buffer_size(other.buffer_size)
+               {
+                       working(other);
+               }
+               void operator=(const int& new_value)
+               {
+                       value = new_value;
+               }
+               bool operator==(const int new_value) const
+               {
+                       return value == new_value;
+               }
+               void working(const HeavyValue &other) {
+                       for (size_t i = 0; i < buffer_size; ++i)
+                               pop_buff[i] =  static_cast<int>(std::sqrt(other.pop_buff[i]));
+               }
+       };
+
+       template<int DefaultSize>
+       std::vector<int> HeavyValue< DefaultSize >::pop_buff = {};
+
     class FCQueue: public ::testing::Test
     {
     protected:
@@ -166,6 +206,67 @@ namespace {
         test( q );
     }
 
+       TEST_F( FCQueue, std_deque_heavy_value )
+       {
+               typedef HeavyValue<> ValueType;
+               typedef cds::container::FCQueue<ValueType> queue_type;
+
+               queue_type q;
+               test( q );
+       }
+
+    TEST_F( FCQueue, std_empty_wait_strategy_heavy_value )
+    {
+       typedef HeavyValue<> ValueType;
+        typedef cds::container::FCQueue<ValueType, std::queue< ValueType, std::deque<ValueType>>,
+            cds::container::fcqueue::make_traits<
+                cds::opt::wait_strategy< cds::algo::flat_combining::wait_strategy::empty >
+            >::type
+        > queue_type;
+
+        queue_type q;
+        test( q );
+    }
+
+    TEST_F( FCQueue, std_single_mutex_single_condvar_heavy_value )
+    {
+       typedef HeavyValue<> ValueType;
+        typedef cds::container::FCQueue<ValueType, std::queue< ValueType, std::deque<ValueType>>,
+            cds::container::fcqueue::make_traits<
+                cds::opt::wait_strategy< cds::algo::flat_combining::wait_strategy::single_mutex_single_condvar<> >
+            >::type
+        > queue_type;
+
+        queue_type q;
+        test( q );
+    }
+
+    TEST_F( FCQueue, std_single_mutex_multi_condvar_heavy_value )
+    {
+       typedef HeavyValue<> ValueType;
+        typedef cds::container::FCQueue<ValueType, std::queue< ValueType, std::deque<ValueType>>,
+            cds::container::fcqueue::make_traits<
+                cds::opt::wait_strategy< cds::algo::flat_combining::wait_strategy::single_mutex_multi_condvar<> >
+            >::type
+        > queue_type;
+
+        queue_type q;
+        test( q );
+    }
+
+    TEST_F( FCQueue, std_multi_mutex_multi_condvar_heavy_value )
+    {
+       typedef HeavyValue<> ValueType;
+        typedef cds::container::FCQueue<ValueType, std::queue< ValueType, std::deque<ValueType>>,
+            cds::container::fcqueue::make_traits<
+                cds::opt::wait_strategy< cds::algo::flat_combining::wait_strategy::multi_mutex_multi_condvar<> >
+            >::type
+        > queue_type;
+
+        queue_type q;
+        test( q );
+    }
+
     TEST_F( FCQueue, std_single_mutex_single_condvar )
     {
         typedef cds::container::FCQueue<int, std::queue< int, std::deque<int>>,