cui/source/dialogs/AdditionsDialog.cxx | 2 +- sc/source/core/data/documen2.cxx | 2 +- sc/source/core/data/queryiter.cxx | 8 ++++---- sd/source/ui/framework/module/SlideSorterModule.cxx | 3 ++- sd/source/ui/unoidl/unomodel.cxx | 3 ++- sfx2/source/view/viewfrm.cxx | 7 ++++--- solenv/gbuild/CppunitTest.mk | 1 + solenv/gbuild/UITest.mk | 1 + svtools/source/control/ctrlbox.cxx | 5 ++++- vcl/inc/salinst.hxx | 4 +--- vcl/inc/skia/utils.hxx | 4 ++-- vcl/source/app/salvtables.cxx | 9 ++++++++- vcl/source/app/settings.cxx | 3 ++- vcl/source/filter/graphicfilter.cxx | 6 ++---- vcl/source/font/fontcache.cxx | 2 +- 15 files changed, 36 insertions(+), 24 deletions(-)
New commits: commit 69e7000ed420faf513002076089aca82bddfbc28 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Wed Jul 17 12:16:59 2024 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Wed Jul 17 15:21:57 2024 +0200 Simplify checking for "running under unit/ui test" In various places, the code checks if we are running as a unit test or a UI test. This code grew organically, and is most re-using environment variables that were designed for narrower purposes. Rather than being clever, just add two new explicit and simple environment variables in the natural place (the command that runs them), and check for those variables in the code. Change-Id: Icce0997914fa0be30a5ac1f29bd870bdb5893a8b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170618 Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> Tested-by: Jenkins diff --git a/cui/source/dialogs/AdditionsDialog.cxx b/cui/source/dialogs/AdditionsDialog.cxx index 3f57676a13ec..01be684d1d86 100644 --- a/cui/source/dialogs/AdditionsDialog.cxx +++ b/cui/source/dialogs/AdditionsDialog.cxx @@ -278,7 +278,7 @@ SearchAndParseThread::SearchAndParseThread(AdditionsDialog* pDialog, const bool { // if we are running a UITest, e.g. UITest_sw_options then // don't attempt to downloading anything - static const bool bUITest = getenv("LIBO_TEST_UNIT"); + static const bool bUITest = getenv("LO_RUNNING_UI_TEST"); m_bUITest = bUITest; } diff --git a/sc/source/core/data/documen2.cxx b/sc/source/core/data/documen2.cxx index 49cdd8d8fb81..1c64bb8f334f 100644 --- a/sc/source/core/data/documen2.cxx +++ b/sc/source/core/data/documen2.cxx @@ -102,7 +102,7 @@ ScSheetLimits ScSheetLimits::CreateDefault() if( SC_MOD()) jumboSheets = SC_MOD()->GetDefaultsOptions().GetInitJumboSheets(); else - assert( getenv("LO_TESTNAME") != nullptr ); // in unittests + assert( getenv("LO_RUNNING_UNIT_TEST") != nullptr ); // in unittests if (jumboSheets) return ScSheetLimits(MAXCOL_JUMBO, MAXROW_JUMBO); else diff --git a/sc/source/core/data/queryiter.cxx b/sc/source/core/data/queryiter.cxx index 72a3cc1dcf3e..11b4bb725ce6 100644 --- a/sc/source/core/data/queryiter.cxx +++ b/sc/source/core/data/queryiter.cxx @@ -1625,25 +1625,25 @@ static bool CanBeUsedForSorterCache(ScDocument& /*rDoc*/, const ScQueryParam& /* && rParam.GetEntry(0).eOp != SC_EQUAL) return false; // For unittests allow inefficient caching, in order for the code to be checked. - static bool inUnitTest = getenv("LO_TESTNAME") != nullptr; + static const bool bRunningUnitTest = getenv("LO_RUNNING_UNIT_TEST"); if(refData == nullptr || refData->Ref1.IsRowRel() || refData->Ref2.IsRowRel()) { // If this is not a range, then a cache is not worth it. If rows are relative, then each // computation will use a different area, so the cache wouldn't be reused. Tab/cols are // not a problem, because formula group computations are done for the same tab/col. - if(!inUnitTest) + if(!bRunningUnitTest) return false; } if(rParam.nRow2 - rParam.nRow1 < 10) { - if(!inUnitTest) + if(!bRunningUnitTest) return false; } if( !cell ) return false; if( !cell->GetCellGroup() || cell->GetCellGroup()->mnLength < 10 ) { - if(!inUnitTest) + if(!bRunningUnitTest) return false; } // Check that all the relevant caches would be valid (may not be the case when mixing diff --git a/sd/source/ui/framework/module/SlideSorterModule.cxx b/sd/source/ui/framework/module/SlideSorterModule.cxx index 6b6987df2968..80e97aeb8022 100644 --- a/sd/source/ui/framework/module/SlideSorterModule.cxx +++ b/sd/source/ui/framework/module/SlideSorterModule.cxx @@ -81,8 +81,9 @@ SlideSorterModule::SlideSorterModule ( UpdateViewTabBar(nullptr); + static const bool bRunningUnitTest = getenv("LO_RUNNING_UNIT_TEST"); if (officecfg::Office::Impress::MultiPaneGUI::SlideSorterBar::Visible::ImpressView::get().value_or(true) - && (!getenv("LO_TESTNAME") || !comphelper::LibreOfficeKit::isActive())) + && (!bRunningUnitTest || !comphelper::LibreOfficeKit::isActive())) AddActiveMainView(FrameworkHelper::msImpressViewURL); if (officecfg::Office::Impress::MultiPaneGUI::SlideSorterBar::Visible::OutlineView::get().value_or(true)) AddActiveMainView(FrameworkHelper::msOutlineViewURL); diff --git a/sd/source/ui/unoidl/unomodel.cxx b/sd/source/ui/unoidl/unomodel.cxx index d30840feb64d..3bc5d96770e9 100644 --- a/sd/source/ui/unoidl/unomodel.cxx +++ b/sd/source/ui/unoidl/unomodel.cxx @@ -2779,7 +2779,8 @@ void SdXImpressDocument::initializeForTiledRendering(const css::uno::Sequence<cs auto xChanges = comphelper::ConfigurationChanges::create(); officecfg::Office::Common::Save::Document::WarnAlienFormat::set(false, xChanges); - if (!getenv("LO_TESTNAME") || !comphelper::LibreOfficeKit::isActive()) + static const bool bRunningUnitTest = getenv("LO_RUNNING_UNIT_TEST"); + if (!bRunningUnitTest || !comphelper::LibreOfficeKit::isActive()) officecfg::Office::Impress::MultiPaneGUI::SlideSorterBar::Visible::ImpressView::set(true,xChanges); xChanges->commit(); diff --git a/sfx2/source/view/viewfrm.cxx b/sfx2/source/view/viewfrm.cxx index b5bd686aa62a..458ab766f0d9 100644 --- a/sfx2/source/view/viewfrm.cxx +++ b/sfx2/source/view/viewfrm.cxx @@ -1458,17 +1458,18 @@ bool SfxApplication::IsHeadlessOrUITest() if (Application::IsHeadlessModeEnabled()) return true; - bool bIsUITest = getenv("LO_TESTNAME") == nullptr; //uitest.uicheck fails when the dialog is open + static const bool bIsUITest = getenv("LO_RUNNING_UI_TEST"); //uitest.uicheck fails when the dialog is open + bool bRet = bIsUITest; for (sal_uInt16 i = 0, nCount = Application::GetCommandLineParamCount(); i < nCount; ++i) { if (Application::GetCommandLineParam(i) == "--nologo") { - bIsUITest = true; + bRet = true; break; } } - return bIsUITest; + return bRet; } bool SfxApplication::IsTipOfTheDayDue() diff --git a/solenv/gbuild/CppunitTest.mk b/solenv/gbuild/CppunitTest.mk index cfca2bbbf570..7ff3caec5f31 100644 --- a/solenv/gbuild/CppunitTest.mk +++ b/solenv/gbuild/CppunitTest.mk @@ -153,6 +153,7 @@ else PYTHONDONTWRITEBYTECODE=1) \ $(if $(filter gdb,$(CPPUNITTRACE)),\ PYTHONWARNINGS=default) \ + LO_RUNNING_UNIT_TEST=1 \ $(ICECREAM_RUN) $(gb_CppunitTest_coredumpctl_run) $(gb_CppunitTest_GDBTRACE) $(gb_CppunitTest_VALGRINDTOOL) $(gb_CppunitTest_RR) \ $(gb_CppunitTest_CPPTESTCOMMAND) \ $(call gb_CppunitTest_get_linktarget_target,$*) \ diff --git a/solenv/gbuild/UITest.mk b/solenv/gbuild/UITest.mk index e49dbed2fe8f..7f0597f15293 100644 --- a/solenv/gbuild/UITest.mk +++ b/solenv/gbuild/UITest.mk @@ -74,6 +74,7 @@ else PYTHONPATH="$(PYPATH)" \ TestUserDir="$(call gb_Helper_make_url,$(dir $(call gb_UITest_get_target,$*)))" \ PYTHONDONTWRITEBYTECODE=0 \ + LO_RUNNING_UI_TEST=1 \ $(if $(ENABLE_WERROR),PYTHONWARNINGS=error) \ $(if $(filter WNT,$(OS)),TZ=) \ $(gb_TEST_ENV_VARS) \ diff --git a/svtools/source/control/ctrlbox.cxx b/svtools/source/control/ctrlbox.cxx index a4b293b7629e..5297fa43f543 100644 --- a/svtools/source/control/ctrlbox.cxx +++ b/svtools/source/control/ctrlbox.cxx @@ -528,7 +528,10 @@ void FontNameBox::Fill( const FontList* pList ) set_active_or_entry_text(aOldText); } -static bool IsRunningUnitTest() { return getenv("LO_TESTNAME") != nullptr; } +static bool IsRunningUnitTest() { + static const bool bRunningUnitTest = getenv("LO_RUNNING_UNIT_TEST"); + return bRunningUnitTest; +} void FontNameBox::EnableWYSIWYG(bool bEnable) { diff --git a/vcl/inc/salinst.hxx b/vcl/inc/salinst.hxx index 45c031db30ae..b356a4514aee 100644 --- a/vcl/inc/salinst.hxx +++ b/vcl/inc/salinst.hxx @@ -211,9 +211,7 @@ public: virtual void BeforeAbort(const OUString& /* rErrorText */, bool /* bDumpCore */) {} - // Note: we 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; } - + static bool IsRunningUnitTest(); static bool IsRunningUITest(); // both must be implemented, if the VCL plugin needs to run via system event loop diff --git a/vcl/inc/skia/utils.hxx b/vcl/inc/skia/utils.hxx index e1bed3dffdd9..99bac8e4c877 100644 --- a/vcl/inc/skia/utils.hxx +++ b/vcl/inc/skia/utils.hxx @@ -143,8 +143,8 @@ inline bool isUnitTestRunning(const char* name = nullptr) { if (name == nullptr) { - static const char* const testname = getenv("LO_TESTNAME"); - if (testname != nullptr) + static const bool bRunningUnitTest = getenv("LO_RUNNING_UNIT_TEST"); + if (bRunningUnitTest) return true; return !vcl::test::activeGraphicsRenderTest().isEmpty(); } diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx index 67ac9f971a63..d80cf3facc00 100644 --- a/vcl/source/app/salvtables.cxx +++ b/vcl/source/app/salvtables.cxx @@ -180,10 +180,17 @@ void SalInstance::DoQuit() std::abort(); } +// static +bool SalInstance::IsRunningUnitTest() +{ + static const bool bRunningUnitTest = getenv("LO_RUNNING_UNIT_TEST"); + return bRunningUnitTest; +} + // static bool SalInstance::IsRunningUITest() { - static const bool bRunningUITest = getenv("LIBO_TEST_UNIT"); + static const bool bRunningUITest = getenv("LO_RUNNING_UI_TEST"); return bRunningUITest; } diff --git a/vcl/source/app/settings.cxx b/vcl/source/app/settings.cxx index 3a9df910c06d..b2b1bcbbedf1 100644 --- a/vcl/source/app/settings.cxx +++ b/vcl/source/app/settings.cxx @@ -2788,7 +2788,8 @@ void MiscSettings::SetEnableATToolSupport( bool bEnable ) mxData->mnEnableATT = bEnable ? TRISTATE_TRUE : TRISTATE_FALSE; - if (getenv("LO_TESTNAME") != nullptr) + static const bool bRunningUnitTest = getenv("LO_RUNNING_UNIT_TEST"); + if (bRunningUnitTest) return; // No registry changing; no SettingsConfigItem modification HKEY hkey; diff --git a/vcl/source/filter/graphicfilter.cxx b/vcl/source/filter/graphicfilter.cxx index 18bd05d107ba..b89d6dfea75f 100644 --- a/vcl/source/filter/graphicfilter.cxx +++ b/vcl/source/filter/graphicfilter.cxx @@ -100,10 +100,8 @@ static bool supportNativeWebp() { // Enable support only for unittests - const char* const testname = getenv("LO_TESTNAME"); - if(testname) - return true; - return false; + static const bool bRunningUnitTest = getenv("LO_RUNNING_UNIT_TEST"); + return bRunningUnitTest; } static std::vector< GraphicFilter* > gaFilterHdlList; diff --git a/vcl/source/font/fontcache.cxx b/vcl/source/font/fontcache.cxx index ce4ba6adf64c..d8c0bf191379 100644 --- a/vcl/source/font/fontcache.cxx +++ b/vcl/source/font/fontcache.cxx @@ -173,7 +173,7 @@ rtl::Reference<LogicalFontInstance> ImplFontCache::GetFontInstance( PhysicalFont } #endif - static const size_t FONTCACHE_MAX = getenv("LO_TESTNAME") ? 1 : 50; + static const size_t FONTCACHE_MAX = getenv("LO_RUNNING_UNIT_TEST") ? 1 : 50; if (maFontInstanceList.size() >= FONTCACHE_MAX) {