include/test/idletask.hxx | 34 ++++++++++++++++++++ sc/qa/unit/subsequent_filters_test2.cxx | 3 + sw/qa/extras/uiwriter/uiwriter7.cxx | 54 ++------------------------------ test/Library_test.mk | 1 test/source/idletask.cxx | 50 +++++++++++++++++++++++++++++ 5 files changed, 91 insertions(+), 51 deletions(-)
New commits: commit 41b426d4384b1ecd316f450a1231eeef3d85240c Author: Caolán McNamara <[email protected]> AuthorDate: Sun Oct 8 14:33:38 2023 +0100 Commit: Miklos Vajna <[email protected]> CommitDate: Tue Oct 10 14:35:36 2023 +0200 make testCondFormatFormulaListenerXLSX reliable Change-Id: Ibd8c9b7831af73967229c578b9dcf7217d800610 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157687 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Miklos Vajna <[email protected]> diff --git a/include/test/idletask.hxx b/include/test/idletask.hxx new file mode 100644 index 000000000000..168f9052974a --- /dev/null +++ b/include/test/idletask.hxx @@ -0,0 +1,34 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#pragma once + +#include <sal/config.h> +#include <test/testdllapi.hxx> +#include <vcl/idle.hxx> + +//IdleTask class to add a low priority Idle task +class OOO_DLLPUBLIC_TEST IdleTask +{ +public: + bool GetFlag() const; + IdleTask(); + + // Launch an Idle at TaskPriority::LOWEST and wait until it completes. Can + // be used to wait until pending Idles at higher TaskPriority::DEFAULT_IDLE + // have completed. + static void waitUntilIdleDispatched(); + +private: + DECL_LINK(FlipFlag, Timer*, void); + bool flag; + Idle maIdle{ "testtool IdleTask" }; +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/unit/subsequent_filters_test2.cxx b/sc/qa/unit/subsequent_filters_test2.cxx index 3c76b14b67b1..dc2c76ef2fb3 100644 --- a/sc/qa/unit/subsequent_filters_test2.cxx +++ b/sc/qa/unit/subsequent_filters_test2.cxx @@ -64,6 +64,7 @@ #include <unotools/syslocaleoptions.hxx> #include "helper/qahelper.hxx" #include <officecfg/Office/Common.hxx> +#include <test/idletask.hxx> using namespace ::com::sun::star; using namespace ::com::sun::star::uno; @@ -2141,7 +2142,7 @@ void ScFiltersTest2::testCondFormatFormulaListenerXLSX() pDoc->SetDocVisible(true); pDoc->SetValue(0, 0, 0, 2.0); - Scheduler::ProcessEventsToIdle(); + IdleTask::waitUntilIdleDispatched(); CPPUNIT_ASSERT(aListener.mbCalled); } diff --git a/sw/qa/extras/uiwriter/uiwriter7.cxx b/sw/qa/extras/uiwriter/uiwriter7.cxx index 8c14e7184f44..697a9defa63c 100644 --- a/sw/qa/extras/uiwriter/uiwriter7.cxx +++ b/sw/qa/extras/uiwriter/uiwriter7.cxx @@ -71,6 +71,7 @@ #include <unotxdoc.hxx> #include <rootfrm.hxx> #include <officecfg/Office/Writer.hxx> +#include <test/idletask.hxx> namespace { @@ -2246,55 +2247,11 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testDde) #endif } -namespace -{ -//IdleTask class to add a low priority Idle task -class IdleTask -{ -public: - bool GetFlag() const; - IdleTask(); - DECL_LINK(FlipFlag, Timer*, void); - -private: - bool flag; - Idle maIdle{ "sw uiwriter IdleTask" }; -}; -} - -//constructor of IdleTask Class -IdleTask::IdleTask() - : flag(false) -{ - //setting the Priority of Idle task to LOW, LOWEST - maIdle.SetPriority(TaskPriority::LOWEST); - //set idle for callback - maIdle.SetInvokeHandler(LINK(this, IdleTask, FlipFlag)); - //starting the idle - maIdle.Start(); -} - -//GetFlag() of IdleTask Class -bool IdleTask::GetFlag() const -{ - //returning the status of current flag - return flag; -} - -//Callback function of IdleTask Class -IMPL_LINK(IdleTask, FlipFlag, Timer*, , void) -{ - //setting the flag to make sure that low priority idle task has been dispatched - flag = true; -} - CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testDocModState) { //creating a new writer document via the XDesktop(to have more shells etc.) createSwDoc(); SwDoc* pDoc = getSwDoc(); - //creating instance of IdleTask Class - IdleTask idleTask; //checking the state of the document via IDocumentState IDocumentState& rState(pDoc->getIDocumentState()); //the state should not be modified @@ -2302,12 +2259,9 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testDocModState) //checking the state of the document via SfxObjectShell SwDocShell* pShell(pDoc->GetDocShell()); CPPUNIT_ASSERT(!(pShell->IsModified())); - //looping around yield until low priority idle task is dispatched and flag is flipped - while (!idleTask.GetFlag()) - { - //dispatching all the events via VCL main-loop - Application::Yield(); - } + + IdleTask::waitUntilIdleDispatched(); + //again checking for the state via IDocumentState CPPUNIT_ASSERT(!(rState.IsModified())); //again checking for the state via SfxObjectShell diff --git a/test/Library_test.mk b/test/Library_test.mk index 268a68744eaf..951ddf6edab2 100644 --- a/test/Library_test.mk +++ b/test/Library_test.mk @@ -50,6 +50,7 @@ $(eval $(call gb_Library_add_exception_objects,test,\ test/source/callgrind \ test/source/xmltesttools \ test/source/htmltesttools \ + test/source/idletask \ test/source/screenshot_test \ test/source/unoapi_property_testers \ test/source/lokcallback \ diff --git a/test/source/idletask.cxx b/test/source/idletask.cxx new file mode 100644 index 000000000000..904d98eb1e24 --- /dev/null +++ b/test/source/idletask.cxx @@ -0,0 +1,50 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <test/idletask.hxx> +#include <vcl/svapp.hxx> + +//constructor of IdleTask Class +IdleTask::IdleTask() + : flag(false) +{ + //setting the Priority of Idle task to LOW, LOWEST + maIdle.SetPriority(TaskPriority::LOWEST); + //set idle for callback + maIdle.SetInvokeHandler(LINK(this, IdleTask, FlipFlag)); + //starting the idle + maIdle.Start(); +} + +//GetFlag() of IdleTask Class +bool IdleTask::GetFlag() const +{ + //returning the status of current flag + return flag; +} + +//Callback function of IdleTask Class +IMPL_LINK(IdleTask, FlipFlag, Timer*, , void) +{ + //setting the flag to make sure that low priority idle task has been dispatched + flag = true; +} + +void IdleTask::waitUntilIdleDispatched() +{ + //creating instance of IdleTask Class + IdleTask idleTask; + while (!idleTask.GetFlag()) + { + //dispatching all the events via VCL main-loop + Application::Yield(); + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
