[Libreoffice-commits] core.git: sal/cppunittester unotools/source

Norbert Thiebaud nthiebaud at gmail.com
Sun Mar 30 19:06:28 PDT 2014


 sal/cppunittester/cppunittester.cxx    |   37 +++++++++++++++++++++++++++++++++
 unotools/source/ucbhelper/tempfile.cxx |   14 ++++++++++--
 2 files changed, 49 insertions(+), 2 deletions(-)

New commits:
commit c176cb8907530a795cb0e38de8193df931f891fb
Author: Norbert Thiebaud <nthiebaud at gmail.com>
Date:   Sun Mar 30 20:20:23 2014 -0500

    decorate tempfile name's to help identify leaks' author
    
    unottols TempFile class check in debug bod for
    and env variable LO_TESTNAME.. if present it use that as the root
    for the tempfile filename.
    
    cppunitteset framework is augmented so that it export such
    LO_TESNAME using the cppunit testName(), after replacement of
    non-alphnum characters by _
    
    Change-Id: Iebb9545d3bd789083afbeaf4c64eab086b56049a

diff --git a/sal/cppunittester/cppunittester.cxx b/sal/cppunittester/cppunittester.cxx
index 1faae71..0f4d58a 100644
--- a/sal/cppunittester/cppunittester.cxx
+++ b/sal/cppunittester/cppunittester.cxx
@@ -95,6 +95,39 @@ private:
     sal_uInt32 m_nStartTime;
 };
 
+#ifdef UNX
+#include <stdlib.h>
+// Setup an env variable so that temp file (or other) can
+// have a usefull value to identify the source
+class EyecatcherListener
+    : public CppUnit::TestListener
+    , private boost::noncopyable
+{
+public:
+    void startTest( CppUnit::Test* test) SAL_OVERRIDE
+    {
+        char* tn = new char [ test->getName().length() + 2 ];
+        strcpy(tn, test->getName().c_str());
+        int len = strlen(tn);
+        for(int i = 0; i < len; i++)
+        {
+            if(!isalnum(tn[i]))
+            {
+                tn[i] = '_';
+            }
+            tn[len] = '_';
+            tn[len + 1] = 0;
+        }
+        setenv("LO_TESTNAME", tn, true);
+        delete[] tn;
+    }
+
+    void endTest( CppUnit::Test* /* test */ ) SAL_OVERRIDE
+    {
+    }
+};
+#endif
+
 //Allow the whole uniting testing framework to be run inside a "Protector"
 //which knows about uno exceptions, so it can print the content of the
 //exception before falling over and dying
@@ -144,6 +177,10 @@ public:
         result.addListener(&timer);
 #endif
 
+#ifdef UNX
+        EyecatcherListener eye;
+        result.addListener(&eye);
+#endif
         for (size_t i = 0; i < protectors.size(); ++i)
             result.pushProtector(protectors[i]);
 
diff --git a/unotools/source/ucbhelper/tempfile.cxx b/unotools/source/ucbhelper/tempfile.cxx
index 17dafaa..9585639 100644
--- a/unotools/source/ucbhelper/tempfile.cxx
+++ b/unotools/source/ucbhelper/tempfile.cxx
@@ -184,8 +184,18 @@ void CreateTempName_Impl( OUString& rName, bool bKeep, bool bDir = true )
     // 36 ** 6 == 2176782336
     unsigned const nRadix = 36;
     unsigned long const nMax = (nRadix*nRadix*nRadix*nRadix*nRadix*nRadix);
-    OUString aName = rName + "lu";
-
+    OUString aName;
+    OUString aEyeCatcher = "lu";
+#ifdef DBG_UTIL
+#ifdef UNX
+    const char* eye = getenv("LO_TESTNAME");
+    if(eye)
+    {
+        aEyeCatcher = OUString(eye, strlen(eye), RTL_TEXTENCODING_ASCII_US);
+    }
+#endif
+#endif
+    aName = rName + aEyeCatcher;
     rName = "";
     static unsigned long u = Time::GetSystemTicks() % nMax;
     for ( unsigned long nSeed = u; ++u != nSeed; )


More information about the Libreoffice-commits mailing list