diff options
author | Noel Grandin <noel@peralex.com> | 2021-09-01 10:58:18 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-09-01 20:42:40 +0200 |
commit | e25ba7dc57229d1cb9794abd1ca23c0d87ebecb3 (patch) | |
tree | 8c95e0c81e003410526cb4ad8357eab3a2db0f44 /sal/cppunittester/cppunittester.cxx | |
parent | 86576cef2c77c8dc78e374aadaadf018610ed6f4 (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>
Diffstat (limited to 'sal/cppunittester/cppunittester.cxx')
-rw-r--r-- | sal/cppunittester/cppunittester.cxx | 25 |
1 files changed, 12 insertions, 13 deletions
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; |