summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noel@peralex.com>2021-09-01 10:58:18 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2021-09-01 20:42:40 +0200
commite25ba7dc57229d1cb9794abd1ca23c0d87ebecb3 (patch)
tree8c95e0c81e003410526cb4ad8357eab3a2db0f44
parent86576cef2c77c8dc78e374aadaadf018610ed6f4 (diff)
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@collabora.co.uk>
-rw-r--r--postprocess/qa/services.cxx4
-rw-r--r--sal/cppunittester/cppunittester.cxx25
-rw-r--r--vcl/osx/service_entry.cxx9
-rw-r--r--vcl/unx/generic/dtrans/X11_service.cxx9
-rw-r--r--vcl/unx/gtk3/gtkinst.cxx9
-rw-r--r--vcl/win/dtrans/WinClipboard.cxx6
6 files changed, 30 insertions, 32 deletions
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;