Split stress-queue test
[libcds.git] / test / include / cds_test / fixture.h
index aa9fcffe358916ce09be49dc240eb3c49c0015b2..6705770e5e4ca7039bee24d9f07cedf4cac5d2be 100644 (file)
@@ -1,7 +1,7 @@
 /*
     This file is a part of libcds - Concurrent Data Structures library
 
-    (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016
+    (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2017
 
     Source code repo: http://github.com/khizmax/libcds/
     Download: http://sourceforge.net/projects/libcds/files/
 #include <algorithm>
 #include <random>
 
+// earlier version of gtest do not support 4th parameter in INSTANTIATE_TEST_CASE_P macro
+//TODO: how to known gtest version?..
+//#define CDSTEST_GTEST_INSTANTIATE_TEST_CASE_P_HAS_4TH_ARG
+
 namespace cds_test {
 
     class fixture : public ::testing::Test
@@ -44,10 +48,17 @@ namespace cds_test {
         static void shuffle( RandomIt first, RandomIt last )
         {
             static std::random_device random_dev;
-            static std::mt19937       random_gen( random_dev() );
+            static std::mt19937       random_gen( random_dev());
 
             std::shuffle( first, last, random_gen );
         }
+
+        static inline unsigned int rand( unsigned int nMax )
+        {
+            double rnd = double( std::rand()) / double( RAND_MAX );
+            unsigned int n = (unsigned int)(rnd * nMax);
+            return n < nMax ? n : (n - 1);
+        }
     };
 
 } // namespace cds_test