Docfix
[libcds.git] / tests / cppunit / cppunit_mini.h
index 81e85017d457e2af027df9460a54657b8c01dac5..a3232162abc779e12d2352ab8c65df8cdcc7720b 100644 (file)
@@ -21,8 +21,8 @@
 
 /* $Id$ */
 
-#ifndef _CPPUNITMPFR_H_
-#define _CPPUNITMPFR_H_
+#ifndef CDS_CPPUNIT_MPFR_H_
+#define CDS_CPPUNIT_MPFR_H_
 
 #include <string.h>
 #include <sstream>
@@ -30,6 +30,8 @@
 #include <vector>
 #include <string>
 #include <map>
+#include <random>
+
 #include <assert.h>
 
 #include <boost/lexical_cast.hpp>
@@ -81,6 +83,10 @@ namespace CppUnitMini
       unsigned int getUInt( const char * pszParamName, unsigned int nDefVal = 0 ) const { return get( pszParamName, nDefVal ) ; }
       long getLong( const char * pszParamName, long nDefVal = 0 ) const { return get( pszParamName, nDefVal ) ; }
       unsigned long getULong( const char * pszParamName, unsigned long nDefVal = 0 ) const { return get( pszParamName, nDefVal ) ; }
+      size_t getSizeT( const char * pszParamName, size_t nDefVal = 0 ) const
+      {
+          return static_cast<size_t>( getULong( pszParamName, static_cast<unsigned long>(nDefVal)));
+      }
 
       bool getBool( const char * pszParamName, bool bDefVal = false ) const
       {
@@ -96,8 +102,7 @@ namespace CppUnitMini
               std::cerr << "bad_lexical_cast encountered while getting parameter "
                   << strParamName << "=" << it->second
                   << ": " << ex.what()
-                  << std::endl
-;
+                  << std::endl;
           }
           return bDefVal;
       }
@@ -131,7 +136,10 @@ namespace CppUnitMini
 
   class TestCase : public TestFixture {
   public:
-    TestCase() { registerTestCase(this); }
+    TestCase()
+    {
+        registerTestCase(this);
+    }
 
     void setUp() { m_failed = false; }
     static int run(Reporter *in_reporter = 0, const char *in_testName = "", bool invert = false);
@@ -154,6 +162,7 @@ namespace CppUnitMini
         m_reporter->error(in_macroName, in_macro, in_file, in_line);
       }
     }
+    virtual char const * test_name() const = 0;
 
     static void message(const char *msg) {
       if (m_reporter) {
@@ -176,25 +185,8 @@ namespace CppUnitMini
       }
     }
 
-    bool shouldRunThis(const char *in_desiredTest, const char *in_className, const char *in_functionName,
-                       bool invert, bool explicit_test, bool &do_progress) {
-      if ((in_desiredTest) && (in_desiredTest[0] != '\0')) {
-        do_progress = false;
-        const char *ptr = strstr(in_desiredTest, "::");
-        if (ptr) {
-            bool match = (strncmp(in_desiredTest, in_className, strlen(in_className)) == 0 && in_desiredTest[strlen(in_className)] == ':' )
-                      && (strncmp(ptr + 2, in_functionName, strlen(ptr + 2)) == 0);
-          // Invert shall not make explicit test run:
-          return invert ? (match ? !match : !explicit_test)
-                        : match;
-        }
-        bool match = (strcmp(in_desiredTest, in_className) == 0);
-        do_progress = match;
-        return !explicit_test && (match == !invert);
-      }
-      do_progress = true;
-      return !explicit_test;
-    }
+    bool shouldRunThis( const char *in_desiredTest, const char *in_className, const char *in_functionName,
+                        bool invert, bool explicit_test, bool &do_progress );
 
     void tearDown() {
       print_gc_state();
@@ -205,7 +197,15 @@ namespace CppUnitMini
 
     static void print_gc_state();
 
-    static std::vector<std::string> const &    getTestStrings();
+    static std::vector<std::string> const&  getTestStrings();
+
+    template <typename RandomIt>
+    static void shuffle( RandomIt first, RandomIt last )
+    {
+        std::shuffle( first, last, m_RandomGen );
+    }
+
+    static void print_test_list();
 
   protected:
     static std::vector<std::string>  m_arrStrings ;   // array of test strings
@@ -213,7 +213,12 @@ namespace CppUnitMini
   public:
       static bool m_bPrintGCState   ;   // print GC state after each test
       static Config m_Cfg;
-      static std::string    m_strTestDataDir;
+      static std::string m_strTestDataDir;
+      static bool m_bExactMatch;
+
+      // random shuffle support
+      static std::random_device m_RandomDevice;
+      static std::mt19937       m_RandomGen;
 
   protected:
     static int m_numErrors;
@@ -241,16 +246,12 @@ namespace CppUnitMini
 
 #define CPPUNIT_TEST_SUITE_(X, cfgBranchName) \
     typedef CppUnitMini::TestCase Base; \
+    virtual char const * test_name() const { return #X; } \
     virtual void myRun(const char *in_name, bool invert = false) { \
     const char *className = #X; CPPUNIT_MINI_HIDE_UNUSED_VARIABLE(className) \
     bool ignoring = false; CPPUNIT_MINI_HIDE_UNUSED_VARIABLE(ignoring) \
     setUpParams( m_Cfg.get( cfgBranchName ));
 
-#define CPPUNIT_TEST_SUITE_PART(X, func) \
-    void X::func(const char *in_name, bool invert /*= false*/) { \
-    const char *className = #X; CPPUNIT_MINI_HIDE_UNUSED_VARIABLE(className) \
-    bool ignoring = false; CPPUNIT_MINI_HIDE_UNUSED_VARIABLE(ignoring)
-
 #define CPPUNIT_TEST_SUITE(X) CPPUNIT_TEST_SUITE_(X, #X)
 
 #if defined CPPUNIT_MINI_USE_EXCEPTIONS
@@ -266,7 +267,7 @@ namespace CppUnitMini
           X(); \
         } \
         catch(...) { \
-          Base::error("Test Failed: An Exception was thrown.", #X, __FILE__, __LINE__); \
+          Base::error("Test Failed: An exception was thrown.", #X, __FILE__, __LINE__); \
         } \
       } \
       tearDown(); \
@@ -290,6 +291,8 @@ namespace CppUnitMini
 #define CPPUNIT_TEST(X) CPPUNIT_TEST_BASE(X, false)
 #define CPPUNIT_EXPLICIT_TEST(X) CPPUNIT_TEST_BASE(X, true)
 
+#define CDSUNIT_DECLARE_TEST(X) void X();
+
 #define CPPUNIT_IGNORE \
   ignoring = true
 
@@ -299,8 +302,8 @@ namespace CppUnitMini
 #define CPPUNIT_TEST_SUITE_END() endTestCase(); }
 #define CPPUNIT_TEST_SUITE_END_PART() }
 
-#define CPPUNIT_TEST_SUITE_REGISTRATION(X) static X local
 #define CPPUNIT_TEST_SUITE_REGISTRATION_(X, NAME) static X NAME
+#define CPPUNIT_TEST_SUITE_REGISTRATION(X) CPPUNIT_TEST_SUITE_REGISTRATION_(X, local)
 
 #define CPPUNIT_CHECK(X) \
   if (!(X)) { \
@@ -382,4 +385,4 @@ namespace CppUnitMini
         error( "CPPUNIT_ASSERT_MSG", st.str().c_str(), __FILE__, __LINE__ )     ;   \
     }
 
-#endif
+#endif // #ifndef CDS_CPPUNIT_MPFR_H_