include/test/lokcallback.hxx                   |    4 +++-
 sw/qa/extras/tiledrendering/tiledrendering.cxx |   12 +++---------
 test/Library_test.mk                           |    1 +
 test/source/lokcallback.cxx                    |   19 ++++++++++++++++++-
 4 files changed, 25 insertions(+), 11 deletions(-)

New commits:
commit 371390840b7b9ff84f72d9f886bed8110f30f038
Author:     Luboš Luňák <[email protected]>
AuthorDate: Wed Oct 20 11:32:17 2021 +0200
Commit:     Luboš Luňák <[email protected]>
CommitDate: Fri Oct 22 15:54:59 2021 +0200

    properly flush LOK invalidations in tests
    
    This should be done always before doing something with a flag
    related to the invalidations. Use an idle timer for simplicity,
    tests already usually process to idle.
    
    Change-Id: I979900da28061cc690ecbcce023dbb769239f205
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124027
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Luboš Luňák <[email protected]>

diff --git a/include/test/lokcallback.hxx b/include/test/lokcallback.hxx
index f7a619f68cb3..f7372bc7ec80 100644
--- a/include/test/lokcallback.hxx
+++ b/include/test/lokcallback.hxx
@@ -13,6 +13,7 @@
 #include <test/testdllapi.hxx>
 #include <LibreOfficeKit/LibreOfficeKitTypes.h>
 #include <sfx2/lokcallback.hxx>
+#include <vcl/idle.hxx>
 
 /**
 A helper to convert SfxLokCallbackInterface to a LIbreOfficeKitCallback for 
tests.
@@ -21,7 +22,7 @@ It reimplements the specialized callbacks and converts them 
to the generic type/
 callback.
 */
 
-class OOO_DLLPUBLIC_TEST TestLokCallbackWrapper : public 
SfxLokCallbackInterface
+class OOO_DLLPUBLIC_TEST TestLokCallbackWrapper final : public 
SfxLokCallbackInterface, public Idle
 {
 public:
     TestLokCallbackWrapper(LibreOfficeKitCallback callback, void* data);
@@ -30,6 +31,7 @@ public:
                                                       int nViewId) override;
     virtual void libreOfficeKitViewInvalidateTilesCallback(const 
tools::Rectangle* pRect,
                                                            int nPart) override;
+    virtual void Invoke() override;
 
 private:
     void callCallback(int nType, const char* pPayload);
diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx 
b/sw/qa/extras/tiledrendering/tiledrendering.cxx
index 475e64fb3393..e78c91d7370d 100644
--- a/sw/qa/extras/tiledrendering/tiledrendering.cxx
+++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx
@@ -441,7 +441,7 @@ void SwTiledRenderingTest::testRegisterCallback()
     
pWrtShell->GetSfxViewShell()->setLibreOfficeKitViewCallback(&m_callbackWrapper);
     // Insert a character at the beginning of the document.
     pWrtShell->Insert("x");
-    pWrtShell->GetSfxViewShell()->flushPendingLOKInvalidateTiles();
+    Scheduler::ProcessEventsToIdle();
 
     // Check that the top left 256x256px tile would be invalidated.
     CPPUNIT_ASSERT(!m_aInvalidation.IsEmpty());
@@ -859,11 +859,6 @@ public:
         mpViewShell->setLibreOfficeKitViewCallback(nullptr);
     }
 
-    void flushPendingLOKInvalidateTiles()
-    {
-        mpViewShell->flushPendingLOKInvalidateTiles();
-    }
-
     static void callback(int nType, const char* pPayload, void* pData)
     {
         static_cast<ViewCallback*>(pData)->callbackImpl(nType, pPayload);
@@ -1040,13 +1035,12 @@ void SwTiledRenderingTest::testMissingInvalidation()
     pWrtShell->SelWrd();
 
     // Now delete the selected word and make sure both views are invalidated.
+    Scheduler::ProcessEventsToIdle();
     aView1.m_bTilesInvalidated = false;
     aView2.m_bTilesInvalidated = false;
     pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::DELETE);
     pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, awt::Key::DELETE);
     Scheduler::ProcessEventsToIdle();
-    aView1.flushPendingLOKInvalidateTiles();
-    aView2.flushPendingLOKInvalidateTiles();
     CPPUNIT_ASSERT(aView1.m_bTilesInvalidated);
     CPPUNIT_ASSERT(aView2.m_bTilesInvalidated);
 }
@@ -1256,6 +1250,7 @@ void SwTiledRenderingTest::testUndoInvalidations()
     CPPUNIT_ASSERT_EQUAL(OUString("Aaa bbb.c"), 
pShellCursor->GetPoint()->nNode.GetNode().GetTextNode()->GetText());
 
     // Undo and assert that both views are invalidated.
+    Scheduler::ProcessEventsToIdle();
     aView1.m_bTilesInvalidated = false;
     aView2.m_bTilesInvalidated = false;
     comphelper::dispatchCommand(".uno:Undo", {});
@@ -1723,7 +1718,6 @@ void SwTiledRenderingTest::testCommentEndTextEdit()
     pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_RETURN);
     pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_RETURN);
     Scheduler::ProcessEventsToIdle();
-    aView1.flushPendingLOKInvalidateTiles();
     CPPUNIT_ASSERT(aView1.m_bTilesInvalidated);
 }
 
diff --git a/test/Library_test.mk b/test/Library_test.mk
index 8b1fd214490d..bee378ff34f5 100644
--- a/test/Library_test.mk
+++ b/test/Library_test.mk
@@ -33,6 +33,7 @@ $(eval $(call gb_Library_use_libraries,test,\
     cppuhelper \
        i18nlangtag \
     sal \
+    sfx \
     svt \
     test-setupvcl \
        tl \
diff --git a/test/source/lokcallback.cxx b/test/source/lokcallback.cxx
index 389219192a50..13d381f0b46a 100644
--- a/test/source/lokcallback.cxx
+++ b/test/source/lokcallback.cxx
@@ -13,16 +13,23 @@
 #include <rtl/strbuf.hxx>
 #include <tools/gen.hxx>
 #include <comphelper/lok.hxx>
+#include <sfx2/viewsh.hxx>
 
 TestLokCallbackWrapper::TestLokCallbackWrapper(LibreOfficeKitCallback 
callback, void* data)
-    : m_callback(callback)
+    : Idle("TestLokCallbackWrapper flush timer")
+    , m_callback(callback)
     , m_data(data)
 {
+    // Flushing timer needs to run with the lowest priority, so that all 
pending tasks
+    // such as invalidations are processed before it.
+    SetPriority(TaskPriority::LOWEST);
 }
 
 inline void TestLokCallbackWrapper::callCallback(int nType, const char* 
pPayload)
 {
     m_callback(nType, pPayload, m_data);
+    if (!IsActive())
+        Start();
 }
 
 void TestLokCallbackWrapper::libreOfficeKitViewCallback(int nType, const char* 
pPayload)
@@ -52,4 +59,14 @@ void 
TestLokCallbackWrapper::libreOfficeKitViewInvalidateTilesCallback(
     callCallback(LOK_CALLBACK_INVALIDATE_TILES, 
buf.makeStringAndClear().getStr());
 }
 
+void TestLokCallbackWrapper::Invoke()
+{
+    // Timer timeout, flush any possibly pending data.
+    for (SfxViewShell* viewShell = SfxViewShell::GetFirst(false); viewShell != 
nullptr;
+         viewShell = SfxViewShell::GetNext(*viewShell, false))
+    {
+        viewShell->flushPendingLOKInvalidateTiles();
+    }
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Reply via email to