sw/CppunitTest_sw_tiledrendering2.mk             |   67 ++++++++
 sw/Module_sw.mk                                  |    1 
 sw/qa/extras/tiledrendering/tiledrendering.cxx   |   64 --------
 sw/qa/extras/tiledrendering2/tiledrendering2.cxx |  182 +++++++++++++++++++++++
 4 files changed, 250 insertions(+), 64 deletions(-)

New commits:
commit 7d1e5fdf4b0a9ab41e496dd2c4ff4f0653cf982f
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Mon Feb 19 09:40:04 2024 +0100
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Mon Feb 19 11:30:33 2024 +0100

    CppunitTest_sw_tiledrendering2: extract one test from the old, large suite
    
    Not a split, to avoid too many conflicts while cherry-picking, but at
    least create a new suite where next tests can be added without too much
    build time after source code edits.
    
    Change-Id: I0fb95e91ca9289aad25f72b0faa5f8eca3c6c06a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163582
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Tested-by: Jenkins

diff --git a/sw/CppunitTest_sw_tiledrendering2.mk 
b/sw/CppunitTest_sw_tiledrendering2.mk
new file mode 100644
index 000000000000..88d624e0761f
--- /dev/null
+++ b/sw/CppunitTest_sw_tiledrendering2.mk
@@ -0,0 +1,67 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#*************************************************************************
+#
+# 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/.
+#
+#*************************************************************************
+
+$(eval $(call gb_CppunitTest_CppunitTest,sw_tiledrendering2))
+
+$(eval $(call gb_CppunitTest_use_common_precompiled_header,sw_tiledrendering2))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,sw_tiledrendering2, \
+    sw/qa/extras/tiledrendering2/tiledrendering2 \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,sw_tiledrendering2, \
+    comphelper \
+    cppu \
+    cppuhelper \
+    editeng \
+    docmodel \
+    sal \
+    sfx \
+    subsequenttest \
+    svl \
+    svt \
+    svxcore \
+    sw \
+    swqahelper \
+    test \
+    unotest \
+    vcl \
+    tl \
+    utl \
+))
+
+$(eval $(call gb_CppunitTest_use_externals,sw_tiledrendering2,\
+    boost_headers \
+    libxml2 \
+))
+
+$(eval $(call gb_CppunitTest_set_include,sw_tiledrendering2,\
+    -I$(SRCDIR)/sw/inc \
+    -I$(SRCDIR)/sw/source/core/inc \
+    -I$(SRCDIR)/sw/source/uibase/inc \
+    -I$(SRCDIR)/sw/qa/inc \
+    $$(INCLUDE) \
+))
+
+$(eval $(call gb_CppunitTest_use_api,sw_tiledrendering2,\
+    udkapi \
+    offapi \
+    oovbaapi \
+))
+
+$(eval $(call gb_CppunitTest_use_ure,sw_tiledrendering2))
+$(eval $(call gb_CppunitTest_use_vcl,sw_tiledrendering2))
+
+$(eval $(call gb_CppunitTest_use_rdb,sw_tiledrendering2,services))
+
+$(eval $(call gb_CppunitTest_use_configuration,sw_tiledrendering2))
+
+# vim: set noet sw=4 ts=4:
diff --git a/sw/Module_sw.mk b/sw/Module_sw.mk
index 7d5679e52f3c..4b57a5393ce7 100644
--- a/sw/Module_sw.mk
+++ b/sw/Module_sw.mk
@@ -174,6 +174,7 @@ ifneq ($(DISABLE_GUI),TRUE)
 ifeq ($(OS),LINUX)
 $(eval $(call gb_Module_add_slowcheck_targets,sw,\
     CppunitTest_sw_tiledrendering \
+    CppunitTest_sw_tiledrendering2 \
 ))
 endif
 endif
diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx 
b/sw/qa/extras/tiledrendering/tiledrendering.cxx
index 4a707de2e6e6..8dccfeb9271a 100644
--- a/sw/qa/extras/tiledrendering/tiledrendering.cxx
+++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx
@@ -22,7 +22,6 @@
 #include <com/sun/star/text/XTextField.hpp>
 #include <com/sun/star/text/AuthorDisplayFormat.hpp>
 #include <com/sun/star/datatransfer/XTransferable2.hpp>
-#include <com/sun/star/util/URLTransformer.hpp>
 
 #include <test/helper/transferable.hxx>
 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
@@ -55,7 +54,6 @@
 #include <comphelper/processfactory.hxx>
 #include <comphelper/propertyvalue.hxx>
 #include <test/lokcallback.hxx>
-#include <sfx2/msgpool.hxx>
 
 #include <drawdoc.hxx>
 #include <ndtxt.hxx>
@@ -66,7 +64,6 @@
 #include <redline.hxx>
 #include <IDocumentDrawModelAccess.hxx>
 #include <IDocumentRedlineAccess.hxx>
-#include <IDocumentLayoutAccess.hxx>
 #include <flddat.hxx>
 #include <basesh.hxx>
 #include <unotxdoc.hxx>
@@ -780,7 +777,6 @@ namespace {
         boost::property_tree::ptree m_aRedlineTableModified;
         /// Post-it / annotation payload.
         boost::property_tree::ptree m_aComment;
-        std::vector<OString> m_aStateChanges;
         TestLokCallbackWrapper m_callbackWrapper;
 
         ViewCallback(SfxViewShell* pViewShell = nullptr, 
std::function<void(ViewCallback&)> const & rBeforeInstallFunc = {})
@@ -944,11 +940,6 @@ namespace {
                         m_aComment = m_aComment.get_child("comment");
                     }
                     break;
-                case LOK_CALLBACK_STATE_CHANGED:
-                    {
-                        m_aStateChanges.push_back(pPayload);
-                        break;
-                    }
             }
         }
     };
@@ -4174,61 +4165,6 @@ CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, 
testSwitchingChartToDarkMode)
     CPPUNIT_ASSERT(nBlackPixels > nWhitePixels);
 }
 
-CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, testStatusBarPageNumber)
-{
-    // Given a document with 2 pages, first view on page 1, second view on 
page 2:
-    SwXTextDocument* pXTextDocument = createDoc();
-    int nView1 = SfxLokHelper::getView();
-    SwWrtShell* pWrtShell1 = pXTextDocument->GetDocShell()->GetWrtShell();
-    pWrtShell1->InsertPageBreak();
-    SwRootFrame* pLayout = 
pWrtShell1->getIDocumentLayoutAccess().GetCurrentLayout();
-    SwFrame* pPage1 = pLayout->GetLower();
-    CPPUNIT_ASSERT(pPage1);
-    SwFrame* pPage2 = pPage1->GetNext();
-    CPPUNIT_ASSERT(pPage2);
-    SfxLokHelper::createView();
-    int nView2 = SfxLokHelper::getView();
-    
pXTextDocument->initializeForTiledRendering(uno::Sequence<beans::PropertyValue>());
-    SfxLokHelper::setView(nView1);
-    ViewCallback aView1;
-    pWrtShell1->SttEndDoc(/*bStt=*/true);
-    pWrtShell1->Insert("start");
-    pWrtShell1->GetView().SetVisArea(pPage1->getFrameArea().SVRect());
-    SfxLokHelper::setView(nView2);
-    ViewCallback aView2;
-    SwWrtShell* pWrtShell2 = pXTextDocument->GetDocShell()->GetWrtShell();
-    pWrtShell2->SttEndDoc(/*bStt=*/false);
-    pWrtShell2->Insert("end");
-    pWrtShell2->GetView().SetVisArea(pPage2->getFrameArea().SVRect());
-    {
-        // Listen to StatePageNumber changes in view 2:
-        SfxViewFrame& rFrame = pWrtShell2->GetView().GetViewFrame();
-        SfxSlotPool& rSlotPool = SfxSlotPool::GetSlotPool(&rFrame);
-        uno::Reference<util::XURLTransformer> 
xParser(util::URLTransformer::create(m_xContext));
-        util::URL aCommandURL;
-        aCommandURL.Complete = ".uno:StatePageNumber";
-        xParser->parseStrict(aCommandURL);
-        const SfxSlot* pSlot = rSlotPool.GetUnoSlot(aCommandURL.Path);
-        rFrame.GetBindings().GetDispatch(pSlot, aCommandURL, false);
-    }
-    aView2.m_aStateChanges.clear();
-
-    // When deleting a character in view 2 and processing jobs with view 1 set 
to active:
-    pWrtShell2->DelLeft();
-    SfxLokHelper::setView(nView1);
-    pWrtShell2->GetView().GetViewFrame().GetBindings().GetTimer().Invoke();
-    // Once more to hit the pImpl->bMsgDirty = false case in 
SfxBindings::NextJob_Impl().
-    pWrtShell2->GetView().GetViewFrame().GetBindings().GetTimer().Invoke();
-
-    // Then make sure the page number in view 2 is correct:
-    CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), 
aView2.m_aStateChanges.size());
-    // Without the accompanying fix in place, this test would have failed with:
-    // - Expected: .uno:StatePageNumber=Page 2 of 2
-    // - Actual  : .uno:StatePageNumber=Page 1 of 2
-    // i.e. view 2 got the page number of view 1.
-    CPPUNIT_ASSERT_EQUAL(".uno:StatePageNumber=Page 2 of 2"_ostr, 
aView2.m_aStateChanges[0]);
-}
-
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/qa/extras/tiledrendering2/tiledrendering2.cxx 
b/sw/qa/extras/tiledrendering2/tiledrendering2.cxx
new file mode 100644
index 000000000000..4c1217198f52
--- /dev/null
+++ b/sw/qa/extras/tiledrendering2/tiledrendering2.cxx
@@ -0,0 +1,182 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * 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 <swmodeltestbase.hxx>
+
+#include <string>
+
+#include <com/sun/star/util/URLTransformer.hpp>
+
+#include <LibreOfficeKit/LibreOfficeKitEnums.h>
+#include <comphelper/lok.hxx>
+#include <sfx2/viewsh.hxx>
+#include <sfx2/bindings.hxx>
+#include <sfx2/viewfrm.hxx>
+#include <sfx2/lokhelper.hxx>
+#include <test/lokcallback.hxx>
+#include <sfx2/msgpool.hxx>
+
+#include <wrtsh.hxx>
+#include <view.hxx>
+#include <IDocumentLayoutAccess.hxx>
+#include <unotxdoc.hxx>
+#include <docsh.hxx>
+#include <rootfrm.hxx>
+#include <swmodule.hxx>
+#include <swdll.hxx>
+
+namespace
+{
+/// Writer tests with comphelper::LibreOfficeKit::isActive() enabled, part 2.
+class SwTiledRenderingTest : public SwModelTestBase
+{
+public:
+    SwTiledRenderingTest();
+    virtual void setUp() override;
+    virtual void tearDown() override;
+
+protected:
+    SwXTextDocument* createDoc();
+};
+
+SwTiledRenderingTest::SwTiledRenderingTest()
+    : SwModelTestBase("/sw/qa/extras/tiledrendering2/data/")
+{
+}
+
+void SwTiledRenderingTest::setUp()
+{
+    SwModelTestBase::setUp();
+    SwGlobals::ensure();
+    SW_MOD()->ClearRedlineAuthors();
+    comphelper::LibreOfficeKit::setActive(true);
+}
+
+void SwTiledRenderingTest::tearDown()
+{
+    if (mxComponent.is())
+    {
+        mxComponent->dispose();
+        mxComponent.clear();
+    }
+    comphelper::LibreOfficeKit::setActive(false);
+    test::BootstrapFixture::tearDown();
+}
+
+SwXTextDocument* SwTiledRenderingTest::createDoc()
+{
+    createSwDoc();
+    auto pTextDocument = dynamic_cast<SwXTextDocument*>(mxComponent.get());
+    CPPUNIT_ASSERT(pTextDocument);
+    
pTextDocument->initializeForTiledRendering(uno::Sequence<beans::PropertyValue>());
+    return pTextDocument;
+}
+
+/// A view callback tracks callbacks invoked on one specific view.
+class ViewCallback final
+{
+    SfxViewShell* mpViewShell;
+    int mnView;
+
+public:
+    std::vector<OString> m_aStateChanges;
+    TestLokCallbackWrapper m_callbackWrapper;
+
+    ViewCallback()
+        : m_callbackWrapper(&callback, this)
+    {
+        mpViewShell = SfxViewShell::Current();
+        mpViewShell->setLibreOfficeKitViewCallback(&m_callbackWrapper);
+        mnView = SfxLokHelper::getView();
+        m_callbackWrapper.setLOKViewId(mnView);
+    }
+
+    ~ViewCallback()
+    {
+        SfxLokHelper::setView(mnView);
+        mpViewShell->setLibreOfficeKitViewCallback(nullptr);
+    }
+
+    static void callback(int nType, const char* pPayload, void* pData)
+    {
+        static_cast<ViewCallback*>(pData)->callbackImpl(nType, pPayload);
+    }
+
+    void callbackImpl(int nType, const char* pPayload)
+    {
+        switch (nType)
+        {
+            case LOK_CALLBACK_STATE_CHANGED:
+            {
+                m_aStateChanges.push_back(pPayload);
+                break;
+            }
+        }
+    }
+};
+
+CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, testStatusBarPageNumber)
+{
+    // Given a document with 2 pages, first view on page 1, second view on 
page 2:
+    SwXTextDocument* pXTextDocument = createDoc();
+    int nView1 = SfxLokHelper::getView();
+    SwWrtShell* pWrtShell1 = pXTextDocument->GetDocShell()->GetWrtShell();
+    pWrtShell1->InsertPageBreak();
+    SwRootFrame* pLayout = 
pWrtShell1->getIDocumentLayoutAccess().GetCurrentLayout();
+    SwFrame* pPage1 = pLayout->GetLower();
+    CPPUNIT_ASSERT(pPage1);
+    SwFrame* pPage2 = pPage1->GetNext();
+    CPPUNIT_ASSERT(pPage2);
+    SfxLokHelper::createView();
+    int nView2 = SfxLokHelper::getView();
+    
pXTextDocument->initializeForTiledRendering(uno::Sequence<beans::PropertyValue>());
+    SfxLokHelper::setView(nView1);
+    ViewCallback aView1;
+    pWrtShell1->SttEndDoc(/*bStt=*/true);
+    pWrtShell1->Insert("start");
+    pWrtShell1->GetView().SetVisArea(pPage1->getFrameArea().SVRect());
+    SfxLokHelper::setView(nView2);
+    ViewCallback aView2;
+    SwWrtShell* pWrtShell2 = pXTextDocument->GetDocShell()->GetWrtShell();
+    pWrtShell2->SttEndDoc(/*bStt=*/false);
+    pWrtShell2->Insert("end");
+    pWrtShell2->GetView().SetVisArea(pPage2->getFrameArea().SVRect());
+    {
+        // Listen to StatePageNumber changes in view 2:
+        SfxViewFrame& rFrame = pWrtShell2->GetView().GetViewFrame();
+        SfxSlotPool& rSlotPool = SfxSlotPool::GetSlotPool(&rFrame);
+        uno::Reference<util::XURLTransformer> 
xParser(util::URLTransformer::create(m_xContext));
+        util::URL aCommandURL;
+        aCommandURL.Complete = ".uno:StatePageNumber";
+        xParser->parseStrict(aCommandURL);
+        const SfxSlot* pSlot = rSlotPool.GetUnoSlot(aCommandURL.Path);
+        rFrame.GetBindings().GetDispatch(pSlot, aCommandURL, false);
+    }
+    aView2.m_aStateChanges.clear();
+
+    // When deleting a character in view 2 and processing jobs with view 1 set 
to active:
+    pWrtShell2->DelLeft();
+    SfxLokHelper::setView(nView1);
+    pWrtShell2->GetView().GetViewFrame().GetBindings().GetTimer().Invoke();
+    // Once more to hit the pImpl->bMsgDirty = false case in 
SfxBindings::NextJob_Impl().
+    pWrtShell2->GetView().GetViewFrame().GetBindings().GetTimer().Invoke();
+
+    // Then make sure the page number in view 2 is correct:
+    CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), 
aView2.m_aStateChanges.size());
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Expected: .uno:StatePageNumber=Page 2 of 2
+    // - Actual  : .uno:StatePageNumber=Page 1 of 2
+    // i.e. view 2 got the page number of view 1.
+    CPPUNIT_ASSERT_EQUAL(".uno:StatePageNumber=Page 2 of 2"_ostr, 
aView2.m_aStateChanges[0]);
+}
+}
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Reply via email to