Browse Source

Added cppunit test for boost threading issue

Signed-off-by: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 14 years ago
parent
commit
e4f27879d7
1 changed files with 63 additions and 0 deletions
  1. 63 0
      rtl/eclrtl/eclrtl.cpp

+ 63 - 0
rtl/eclrtl/eclrtl.cpp

@@ -5685,3 +5685,66 @@ static void testPackedSigned()
 void ensureRtlLoaded()
 {
 }
+
+#ifdef _USE_CPPUNIT
+#include <cppunit/extensions/HelperMacros.h>
+#define ASSERT(a) { if (!(a)) CPPUNIT_ASSERT(a); }
+
+class EclRtlTests : public CppUnit::TestFixture
+{
+    CPPUNIT_TEST_SUITE( EclRtlTests );
+        CPPUNIT_TEST(RegexTest);
+        CPPUNIT_TEST(MultiRegexTest);
+    CPPUNIT_TEST_SUITE_END();
+
+protected:
+    void RegexTest()
+    {
+        rtlCompiledStrRegex r;
+        size32_t outlen;
+        char * out = NULL;
+        r.setPattern("([A-Z]+)[ ]?'(S) ", true);
+        r->replace(outlen, out, 7, "ABC'S  ", 5, "$1$2 ");
+        ASSERT(outlen==6);
+        ASSERT(out != NULL);
+        ASSERT(memcmp(out, "ABCS  ", outlen)==0);
+        rtlFree(out);
+    }
+
+    void MultiRegexTest()
+    {
+        class RegexTestThread : public Thread
+        {
+            virtual int run()
+            {
+                for (int i = 0; i < 100000; i++)
+                {
+                    rtlCompiledStrRegex r;
+                    size32_t outlen;
+                    char * out = NULL;
+                    r.setPattern("([A-Z]+)[ ]?'(S) ", true);
+                    r->replace(outlen, out, 7, "ABC'S  ", 5, "$1$2 ");
+                    ASSERT(outlen==6);
+                    ASSERT(out != NULL);
+                    ASSERT(memcmp(out, "ABCS  ", outlen)==0);
+                    rtlFree(out);
+                }
+                return 0;
+            }
+        };
+        RegexTestThread t1;
+        RegexTestThread t2;
+        RegexTestThread t3;
+        t1.start();
+        t2.start();
+        t3.start();
+        t1.join();
+        t2.join();
+        t3.join();
+    }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION( EclRtlTests );
+CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( EclRtlTests, "EclRtlTests" );
+
+#endif