[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.4' - sc/qa

Dennis Francis (via logerrit) logerrit at kemper.freedesktop.org
Tue Jun 1 08:19:47 UTC 2021


 sc/qa/unit/tiledrendering/tiledrendering.cxx |  130 +++++++++++++++++++++++++++
 1 file changed, 130 insertions(+)

New commits:
commit 42b08e239983063e559af8bd249213bba79eee48
Author:     Dennis Francis <dennis.francis at collabora.com>
AuthorDate: Thu May 27 14:02:28 2021 +0530
Commit:     Dennis Francis <dennis.francis at collabora.com>
CommitDate: Tue Jun 1 10:19:13 2021 +0200

    unit test: lok: text selection message test
    
    Change-Id: Ie551461e323a2705c5b0b159dd50e8a1eef7d364
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116429
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Luboš Luňák <l.lunak at collabora.com>
    Reviewed-by: Dennis Francis <dennis.francis at collabora.com>

diff --git a/sc/qa/unit/tiledrendering/tiledrendering.cxx b/sc/qa/unit/tiledrendering/tiledrendering.cxx
index ecf054abb41b..fc3d675ba79a 100644
--- a/sc/qa/unit/tiledrendering/tiledrendering.cxx
+++ b/sc/qa/unit/tiledrendering/tiledrendering.cxx
@@ -120,6 +120,7 @@ public:
     void testAutoInputExactMatch();
     void testMoveShapeHandle();
     void testEditCursorBounds();
+    void testTextSelectionBounds();
 
 
     CPPUNIT_TEST_SUITE(ScTiledRenderingTest);
@@ -173,6 +174,7 @@ public:
     CPPUNIT_TEST(testAutoInputExactMatch);
     CPPUNIT_TEST(testMoveShapeHandle);
     CPPUNIT_TEST(testEditCursorBounds);
+    CPPUNIT_TEST(testTextSelectionBounds);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -482,6 +484,78 @@ struct EditCursorMessage final {
     }
 };
 
+struct TextSelectionMessage
+{
+    std::vector<tools::Rectangle> m_aRelRects;
+    Point m_aRefPoint;
+
+    void clear() {
+        m_aRefPoint.setX(0);
+        m_aRefPoint.setY(0);
+        m_aRelRects.clear();
+    }
+
+    bool empty() {
+        return m_aRelRects.empty();
+    }
+
+    void parseMessage(const char* pMessage)
+    {
+        clear();
+        if (!pMessage)
+            return;
+
+        std::string aStr(pMessage);
+        if (aStr.find(",") == std::string::npos)
+            return;
+
+        size_t nRefDelimStart = aStr.find("::");
+        std::string aRectListString = (nRefDelimStart == std::string::npos) ? aStr : aStr.substr(0, nRefDelimStart);
+        std::string aRefPointString = (nRefDelimStart == std::string::npos) ?
+            std::string("0, 0") :
+            aStr.substr(nRefDelimStart + 2, aStr.length() - 2 - nRefDelimStart);
+        uno::Sequence<OUString> aSeq = comphelper::string::convertCommaSeparated(OUString::createFromAscii(aRefPointString.c_str()));
+        CPPUNIT_ASSERT(aSeq.getLength() == 2);
+        m_aRefPoint.setX(aSeq[0].toInt32());
+        m_aRefPoint.setY(aSeq[1].toInt32());
+
+        size_t nStart = 0;
+        size_t nEnd = aRectListString.find(";");
+        if (nEnd == std::string::npos)
+            nEnd = aRectListString.length();
+        do
+        {
+            std::string aRectString = aRectListString.substr(nStart, nEnd - nStart);
+            {
+                aSeq = comphelper::string::convertCommaSeparated(OUString::createFromAscii(aRectString.c_str()));
+                CPPUNIT_ASSERT(aSeq.getLength() == 4);
+                tools::Rectangle aRect;
+                aRect.setX(aSeq[0].toInt32());
+                aRect.setY(aSeq[1].toInt32());
+                aRect.setWidth(aSeq[2].toInt32());
+                aRect.setHeight(aSeq[3].toInt32());
+
+                m_aRelRects.push_back(aRect);
+            }
+
+            nStart = nEnd + 1;
+            nEnd = aRectListString.find(";", nStart);
+        }
+        while(nEnd != std::string::npos);
+    }
+
+    tools::Rectangle getBounds(size_t nIndex)
+    {
+        if (nIndex >= m_aRelRects.size())
+            return tools::Rectangle();
+
+        tools::Rectangle aBounds = m_aRelRects[nIndex];
+        aBounds.Move(m_aRefPoint.X(), m_aRefPoint.Y());
+        return aBounds;
+    }
+
+};
+
 /// A view callback tracks callbacks invoked on one specific view.
 class ViewCallback final
 {
@@ -502,6 +576,7 @@ public:
     OString m_sCellFormula;
     boost::property_tree::ptree m_aCommentCallbackResult;
     EditCursorMessage m_aInvalidateCursorResult;
+    TextSelectionMessage m_aTextSelectionResult;
     OString m_sInvalidateHeader;
     OString m_sInvalidateSheetGeometry;
     OString m_ShapeSelection;
@@ -633,6 +708,11 @@ public:
         {
             m_aInvalidateCursorResult.parseMessage(pPayload);
         }
+        break;
+        case LOK_CALLBACK_TEXT_SELECTION:
+        {
+            m_aTextSelectionResult.parseMessage(pPayload);
+        }
         }
     }
 };
@@ -2688,6 +2768,56 @@ void ScTiledRenderingTest::testEditCursorBounds()
     SfxViewShell::Current()->registerLibreOfficeKitViewCallback(nullptr, nullptr);
 }
 
+void ScTiledRenderingTest::testTextSelectionBounds()
+{
+    comphelper::LibreOfficeKit::setActive();
+    comphelper::LibreOfficeKit::setCompatFlag(
+        comphelper::LibreOfficeKit::Compat::scPrintTwipsMsgs);
+    ScModelObj* pModelObj = createDoc("empty.ods");
+    ScDocument* pDoc = pModelObj->GetDocument();
+
+    ViewCallback aView;
+    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView);
+    ScTabViewShell* pView = dynamic_cast<ScTabViewShell*>(SfxViewShell::Current());
+    CPPUNIT_ASSERT(pView);
+    comphelper::LibreOfficeKit::setViewIdForVisCursorInvalidation(true);
+
+    // ~170% zoom.
+    pModelObj->setClientZoom(256, 256, 2222, 2222);
+    pModelObj->setClientVisibleArea(tools::Rectangle(7725, 379832, 16240, 6449));
+    Scheduler::ProcessEventsToIdle();
+
+    constexpr SCCOL nCol = 5;
+    constexpr SCROW nRow = 2048;
+    pDoc->SetValue(ScAddress(nCol, nRow, 0), 123);
+
+    aView.m_bOwnCursorInvalidated = false;
+    // Obtain the cell bounds via cursor.
+    pView->SetCursor(nCol, nRow);
+    Scheduler::ProcessEventsToIdle();
+
+    CPPUNIT_ASSERT(aView.m_bOwnCursorInvalidated);
+    CPPUNIT_ASSERT(!aView.m_aCellCursorBounds.IsEmpty());
+    tools::Rectangle aCellBounds(aView.m_aCellCursorBounds);
+
+    aView.m_aTextSelectionResult.clear();
+    // Enter edit mode in the same cell and select all text.
+    pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::F2);
+    pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, awt::Key::F2);
+    Scheduler::ProcessEventsToIdle();
+
+    // CTRL + A
+    pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_MOD1 | awt::Key::A);
+    pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_MOD1 | awt::Key::A);
+    Scheduler::ProcessEventsToIdle();
+
+    CPPUNIT_ASSERT(!aView.m_aTextSelectionResult.empty());
+    CPPUNIT_ASSERT_MESSAGE("Text selections must be in cell bounds!",
+        !aCellBounds.Intersection(aView.m_aTextSelectionResult.getBounds(0)).IsEmpty());
+
+    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(nullptr, nullptr);
+}
+
 }
 
 CPPUNIT_TEST_SUITE_REGISTRATION(ScTiledRenderingTest);


More information about the Libreoffice-commits mailing list