include/test/idletask.hxx               |   34 ++++++++++++++++++++
 sc/qa/unit/subsequent_filters_test3.cxx |    5 +-
 sw/qa/extras/uiwriter/uiwriter7.cxx     |   54 ++------------------------------
 test/Library_test.mk                    |    1 
 test/source/idletask.cxx                |   50 +++++++++++++++++++++++++++++
 5 files changed, 92 insertions(+), 52 deletions(-)

New commits:
commit 9a02f4ed071f15908624fb1cafcf6dbb72b00a1b
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Sun Oct 8 14:33:38 2023 +0100
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Sun Oct 8 19:12:46 2023 +0200

    make testCondFormatFormulaListenerXLSX reliable
    
    Change-Id: Ibd8c9b7831af73967229c578b9dcf7217d800610
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157686
    Tested-by: Jenkins
    Tested-by: Caolán McNamara <caolan.mcnam...@collabora.com>
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

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_test3.cxx 
b/sc/qa/unit/subsequent_filters_test3.cxx
index cd9acf90bece..7980e8083559 100644
--- a/sc/qa/unit/subsequent_filters_test3.cxx
+++ b/sc/qa/unit/subsequent_filters_test3.cxx
@@ -50,6 +50,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;
@@ -420,7 +421,7 @@ CPPUNIT_TEST_FIXTURE(ScFiltersTest3, 
testCondFormatFormulaListenerXLSX)
     pDoc->SetDocVisible(true);
     pDoc->SetValue(0, 0, 0, 2.0);
 
-    Scheduler::ProcessEventsToIdle();
+    IdleTask::waitUntilIdleDispatched();
 
     CPPUNIT_ASSERT(aListener.mbCalled);
 }
@@ -442,7 +443,7 @@ CPPUNIT_TEST_FIXTURE(ScFiltersTest3, testTdf131471)
     pDoc->SetDocVisible(true);
     pDoc->SetValue(0, 0, 0, 1.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 f29e75e8c65e..871ce984ba75 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
 {
@@ -2271,55 +2272,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
@@ -2327,12 +2284,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: */

Reply via email to