diff options
author | Luboš Luňák <l.lunak@collabora.com> | 2021-10-20 11:32:17 +0200 |
---|---|---|
committer | Luboš Luňák <l.lunak@collabora.com> | 2021-10-22 15:54:02 +0200 |
commit | 62f47c26ad096cf088b545f10e14f9d81e2f2cc1 (patch) | |
tree | 3e3e70e924b4075adb9b351042f658e132d1c4bc | |
parent | 9037e42ab3c3793341b583b181617185aefcbde5 (diff) |
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/+/124003
Tested-by: Jenkins
Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
-rw-r--r-- | include/test/lokcallback.hxx | 4 | ||||
-rw-r--r-- | sw/qa/extras/tiledrendering/tiledrendering.cxx | 12 | ||||
-rw-r--r-- | test/Library_test.mk | 1 | ||||
-rw-r--r-- | test/source/lokcallback.cxx | 19 |
4 files changed, 25 insertions, 11 deletions
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 2bc101923b41..7dab608c6323 100644 --- a/sw/qa/extras/tiledrendering/tiledrendering.cxx +++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx @@ -444,7 +444,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()); @@ -863,11 +863,6 @@ namespace { mpViewShell->setLibreOfficeKitViewCallback(nullptr); } - void flushPendingLOKInvalidateTiles() - { - mpViewShell->flushPendingLOKInvalidateTiles(); - } - static void callback(int nType, const char* pPayload, void* pData) { static_cast<ViewCallback*>(pData)->callbackImpl(nType, pPayload); @@ -1044,13 +1039,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); } @@ -1262,6 +1256,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", {}); @@ -1739,7 +1734,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: */ |