[Libreoffice-commits] core.git: postprocess/qa sal/cppunittester vcl/osx vcl/unx vcl/win

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Wed Sep 1 18:43:13 UTC 2021


 postprocess/qa/services.cxx            |    4 ----
 sal/cppunittester/cppunittester.cxx    |   25 ++++++++++++-------------
 vcl/osx/service_entry.cxx              |    9 +++++----
 vcl/unx/generic/dtrans/X11_service.cxx |    9 +++++----
 vcl/unx/gtk3/gtkinst.cxx               |    9 +++++----
 vcl/win/dtrans/WinClipboard.cxx        |    6 +++---
 6 files changed, 30 insertions(+), 32 deletions(-)

New commits:
commit e25ba7dc57229d1cb9794abd1ca23c0d87ebecb3
Author:     Noel Grandin <noel at peralex.com>
AuthorDate: Wed Sep 1 10:58:18 2021 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Wed Sep 1 20:42:40 2021 +0200

    use a dummy clipboard when running unit tests
    
    so the multiple unit tests don't stomp on each other.
    
    This fixes a couple of things in my earlier attempt
    (*) actually set the env variable on Windows
    (*) don't use a global variable to test the env var, because that
    variable might be initialised BEFORE the env var is actually set
    
    Change-Id: Id43a1dd2fbd324691e0b6578c9026b8a523012e8
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121436
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/postprocess/qa/services.cxx b/postprocess/qa/services.cxx
index 5ff9f63f522b..2912356d40ea 100644
--- a/postprocess/qa/services.cxx
+++ b/postprocess/qa/services.cxx
@@ -350,11 +350,7 @@ void Test::createInstance(
     } else if (name == "com.sun.star.datatransfer.clipboard.SystemClipboard") {
         // SystemClipboard is a wrapper returning either a platform-specific or
         // the generic VCLGenericClipboard:
-#if defined(_WIN32)
-        expImpl = "com.sun.star.datatransfer.clipboard.ClipboardW32";
-#else
         expImpl = "com.sun.star.datatransfer.VCLGenericClipboard";
-#endif
 #if !defined(_WIN32)
     } else if (name == "com.sun.star.comp.datatransfer.dnd.OleDragSource_V1"
                || name == "com.sun.star.datatransfer.dnd.XdndSupport")
diff --git a/sal/cppunittester/cppunittester.cxx b/sal/cppunittester/cppunittester.cxx
index f5f34c802c83..9e4c6e2c048b 100644
--- a/sal/cppunittester/cppunittester.cxx
+++ b/sal/cppunittester/cppunittester.cxx
@@ -34,6 +34,7 @@
 #include <sys/resource.h>
 #endif
 
+#include <stdlib.h>
 #include <cstdlib>
 #include <iostream>
 #include <string>
@@ -47,6 +48,7 @@
 #include <rtl/process.h>
 #include <rtl/string.h>
 #include <rtl/string.hxx>
+#include <rtl/strbuf.hxx>
 #include <rtl/textcvt.h>
 #include <rtl/ustring.hxx>
 #include <sal/main.h>
@@ -121,8 +123,6 @@ private:
     sal_uInt32 m_nStartTime;
 };
 
-#ifdef UNX
-#include <stdlib.h>
 // Setup an env variable so that temp file (or other) can
 // have a useful value to identify the source
 class EyecatcherListener
@@ -134,26 +134,26 @@ public:
     EyecatcherListener& operator=(const EyecatcherListener&) = delete;
     void startTest( CppUnit::Test* test) override
     {
-        std::unique_ptr<char[]> tn(new char [ test->getName().length() + 2 ]);
-        strcpy(tn.get(), test->getName().c_str());
-        int len = strlen(tn.get());
-        for(int i = 0; i < len; i++)
+        rtl::OStringBuffer tn(test->getName());
+        for(int i = 0; i < tn.getLength(); i++)
         {
             if(!rtl::isAsciiAlphanumeric(static_cast<unsigned char>(tn[i])))
             {
                 tn[i] = '_';
             }
         }
-        tn[len] = '_';
-        tn[len + 1] = 0;
-        setenv("LO_TESTNAME", tn.get(), true);
+        tn.append('_');
+#ifdef WIN32
+        _putenv_s("LO_TESTNAME", tn.getStr());
+#else
+        setenv("LO_TESTNAME", tn.getStr(), true);
+#endif
     }
 
     void endTest( CppUnit::Test* /* test */ ) override
     {
     }
 };
-#endif
 
 class LogFailuresAsTheyHappen : public CppUnit::TestListener
 {
@@ -298,14 +298,13 @@ public:
             TimingListener timer;
             result.addListener(&timer);
 
-#ifdef UNX
             EyecatcherListener eye;
             result.addListener(&eye);
+#ifdef UNX
             // set this to track down files created before first test method
-            std::string lib(testlib.substr(testlib.rfind('/')+1));
+            std::string lib = testlib.substr(testlib.rfind('/')+1);
             setenv("LO_TESTNAME", lib.c_str(), true);
 #endif
-
             const char* pVal = getenv("CPPUNIT_TEST_NAME");
 
             CppUnit::TestRunner runner;
diff --git a/vcl/osx/service_entry.cxx b/vcl/osx/service_entry.cxx
index 22b28a2c4a1a..73fd2aa9c958 100644
--- a/vcl/osx/service_entry.cxx
+++ b/vcl/osx/service_entry.cxx
@@ -36,11 +36,12 @@ using namespace ::com::sun::star::datatransfer::clipboard;
 
 // We run unit tests in parallel, which is a problem when touching a shared resource
 // the system clipboard, so rather use the dummy GenericClipboard.
-const bool bRunningUnitTest = getenv("LO_TESTNAME");
+// Note, cannot make this a global variable, because it might be initialised BEFORE the putenv() call in cppunittester.
+static bool IsRunningUnitTest() { return getenv("LO_TESTNAME") != nullptr; }
 
 uno::Reference< XInterface > AquaSalInstance::CreateClipboard( const Sequence< Any >& i_rArguments )
 {
-    if ( Application::IsHeadlessModeEnabled() || bRunningUnitTest )
+    if ( Application::IsHeadlessModeEnabled() || IsRunningUnitTest() )
         return SalInstance::CreateClipboard( i_rArguments );
 
     SalData* pSalData = GetSalData();
@@ -51,7 +52,7 @@ uno::Reference< XInterface > AquaSalInstance::CreateClipboard( const Sequence< A
 
 uno::Reference<XInterface> AquaSalInstance::CreateDragSource()
 {
-    if ( Application::IsHeadlessModeEnabled() || bRunningUnitTest )
+    if ( Application::IsHeadlessModeEnabled() || IsRunningUnitTest() )
         return SalInstance::CreateDragSource();
 
     return uno::Reference<XInterface>(static_cast< XInitialization* >(new DragSource()), UNO_QUERY);
@@ -59,7 +60,7 @@ uno::Reference<XInterface> AquaSalInstance::CreateDragSource()
 
 uno::Reference<XInterface> AquaSalInstance::CreateDropTarget()
 {
-    if ( Application::IsHeadlessModeEnabled() || bRunningUnitTest )
+    if ( Application::IsHeadlessModeEnabled() || IsRunningUnitTest() )
         return SalInstance::CreateDropTarget();
 
     return uno::Reference<XInterface>(static_cast< XInitialization* >(new DropTarget()), UNO_QUERY);
diff --git a/vcl/unx/generic/dtrans/X11_service.cxx b/vcl/unx/generic/dtrans/X11_service.cxx
index 3d8ef3382a46..c05773dbad80 100644
--- a/vcl/unx/generic/dtrans/X11_service.cxx
+++ b/vcl/unx/generic/dtrans/X11_service.cxx
@@ -46,11 +46,12 @@ Sequence< OUString > x11::Xdnd_dropTarget_getSupportedServiceNames()
 
 // We run unit tests in parallel, which is a problem when touching a shared resource
 // the system clipboard, so rather use the dummy GenericClipboard.
-const bool bRunningUnitTest = getenv("LO_TESTNAME");
+// Note, cannot make this a global variable, because it might be initialised BEFORE the putenv() call in cppunittester.
+static bool IsRunningUnitTest() { return getenv("LO_TESTNAME") != nullptr; }
 
 css::uno::Reference< XInterface > X11SalInstance::CreateClipboard( const Sequence< Any >& arguments )
 {
-    if ( bRunningUnitTest )
+    if ( IsRunningUnitTest() )
         return SalInstance::CreateClipboard( arguments );
 
     SelectionManager& rManager = SelectionManager::get();
@@ -80,7 +81,7 @@ css::uno::Reference< XInterface > X11SalInstance::CreateClipboard( const Sequenc
 
 css::uno::Reference< XInterface > X11SalInstance::CreateDragSource()
 {
-    if ( bRunningUnitTest )
+    if ( IsRunningUnitTest() )
         return SalInstance::CreateDragSource();
 
     return css::uno::Reference < XInterface >( static_cast<OWeakObject *>(new SelectionManagerHolder()) );
@@ -88,7 +89,7 @@ css::uno::Reference< XInterface > X11SalInstance::CreateDragSource()
 
 css::uno::Reference< XInterface > X11SalInstance::CreateDropTarget()
 {
-    if ( bRunningUnitTest )
+    if ( IsRunningUnitTest() )
         return SalInstance::CreateDropTarget();
 
     return css::uno::Reference < XInterface >( static_cast<OWeakObject *>(new DropTarget()) );
diff --git a/vcl/unx/gtk3/gtkinst.cxx b/vcl/unx/gtk3/gtkinst.cxx
index 8cb71eae9554..1790537725cf 100644
--- a/vcl/unx/gtk3/gtkinst.cxx
+++ b/vcl/unx/gtk3/gtkinst.cxx
@@ -1571,11 +1571,12 @@ void VclGtkClipboard::removeClipboardListener( const Reference< datatransfer::cl
 
 // We run unit tests in parallel, which is a problem when touching a shared resource
 // the system clipboard, so rather use the dummy GenericClipboard.
-const bool bRunningUnitTest = getenv("LO_TESTNAME");
+// Note, cannot make this a global variable, because it might be initialised BEFORE the putenv() call in cppunittester.
+static bool IsRunningUnitTest() { return getenv("LO_TESTNAME") != nullptr; }
 
 Reference< XInterface > GtkInstance::CreateClipboard(const Sequence< Any >& arguments)
 {
-    if ( bRunningUnitTest )
+    if ( IsRunningUnitTest() )
         return SalInstance::CreateClipboard( arguments );
 
     OUString sel;
@@ -1743,7 +1744,7 @@ void GtkInstDropTarget::setDefaultActions(sal_Int8 nDefaultActions)
 
 Reference< XInterface > GtkInstance::CreateDropTarget()
 {
-    if ( bRunningUnitTest )
+    if ( IsRunningUnitTest() )
         return SalInstance::CreateDropTarget();
 
     return Reference<XInterface>(static_cast<cppu::OWeakObject*>(new GtkInstDropTarget));
@@ -1815,7 +1816,7 @@ css::uno::Sequence<OUString> SAL_CALL GtkInstDragSource::getSupportedServiceName
 
 Reference< XInterface > GtkInstance::CreateDragSource()
 {
-    if ( bRunningUnitTest )
+    if ( IsRunningUnitTest() )
         return SalInstance::CreateDragSource();
 
     return Reference< XInterface >( static_cast<cppu::OWeakObject *>(new GtkInstDragSource()) );
diff --git a/vcl/win/dtrans/WinClipboard.cxx b/vcl/win/dtrans/WinClipboard.cxx
index a2ecb7427d44..39094d9e5e0f 100644
--- a/vcl/win/dtrans/WinClipboard.cxx
+++ b/vcl/win/dtrans/WinClipboard.cxx
@@ -328,13 +328,13 @@ uno::Sequence<OUString> SAL_CALL CWinClipboard::getSupportedServiceNames()
 }
 
 // We run unit tests in parallel, which is a problem when touching a shared resource
-// the system clipboard, so rather use the dummy GenericClipboard.
-const bool bRunningUnitTest = getenv("LO_TESTNAME");
-
 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
 dtrans_CWinClipboard_get_implementation(css::uno::XComponentContext* context,
                                         css::uno::Sequence<css::uno::Any> const& args)
 {
+    // the system clipboard, so rather use the dummy GenericClipboard.
+    static const bool bRunningUnitTest = getenv("LO_TESTNAME");
+
     if (bRunningUnitTest)
     {
         SolarMutexGuard aGuard;


More information about the Libreoffice-commits mailing list