sc/qa/unit/uicalc/uicalc.cxx |   51 ++++++++++++++++++++++++++++++++-----------
 1 file changed, 39 insertions(+), 12 deletions(-)

New commits:
commit eea8182795324d5f0df9c12f4debda6d532502bb
Author:     Xisco Fauli <xiscofa...@libreoffice.org>
AuthorDate: Fri Mar 11 15:25:27 2022 +0100
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Fri Mar 11 22:31:58 2022 +0100

    tdf#56036: sc_uicalc: Add unittest
    
    Change-Id: I48f5e0550e4ff7a57bd8a8eae057429b620c7508
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131379
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/sc/qa/unit/uicalc/uicalc.cxx b/sc/qa/unit/uicalc/uicalc.cxx
index 56f70c19bc48..3248dc1ac732 100644
--- a/sc/qa/unit/uicalc/uicalc.cxx
+++ b/sc/qa/unit/uicalc/uicalc.cxx
@@ -50,6 +50,7 @@ public:
     ScModelObj* saveAndReload(css::uno::Reference<css::lang::XComponent>& 
xComponent,
                               const OUString& rFilter);
     void goToCell(const OUString& rCell);
+    void insertString(ScModelObj& rModelObj, const std::string& rStr);
     void insertStringToCell(ScModelObj& rModelObj, const OUString& rCell, 
const std::string& rStr,
                             bool bUseReturn = true);
     void insertArrayToCell(ScModelObj& rModelObj, const OUString& rCell, const 
std::string& rStr);
@@ -106,17 +107,22 @@ void ScUiCalcTest::goToCell(const OUString& rCell)
     dispatchCommand(mxComponent, ".uno:GoToCell", aArgs);
 }
 
-void ScUiCalcTest::insertStringToCell(ScModelObj& rModelObj, const OUString& 
rCell,
-                                      const std::string& rStr, bool bUseReturn)
+void ScUiCalcTest::insertString(ScModelObj& rModelObj, const std::string& rStr)
 {
-    goToCell(rCell);
-
     for (const char c : rStr)
     {
         rModelObj.postKeyEvent(LOK_KEYEVENT_KEYINPUT, c, 0);
         rModelObj.postKeyEvent(LOK_KEYEVENT_KEYUP, c, 0);
         Scheduler::ProcessEventsToIdle();
     }
+}
+
+void ScUiCalcTest::insertStringToCell(ScModelObj& rModelObj, const OUString& 
rCell,
+                                      const std::string& rStr, bool bUseReturn)
+{
+    goToCell(rCell);
+
+    insertString(rModelObj, rStr);
 
     if (bUseReturn)
     {
@@ -458,6 +464,33 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf144308)
     xGlobalSheetSettings->setDoAutoComplete(bOldValue);
 }
 
+CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf56036)
+{
+    mxComponent = loadFromDesktop("private:factory/scalc");
+    ScModelObj* pModelObj = dynamic_cast<ScModelObj*>(mxComponent.get());
+    CPPUNIT_ASSERT(pModelObj);
+    ScDocument* pDoc = pModelObj->GetDocument();
+    CPPUNIT_ASSERT(pDoc);
+
+    insertStringToCell(*pModelObj, "A1", "=SUM( 1 + 2 ", /*bUseReturn*/ false);
+
+    // Insert Newline
+    pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_MOD1 | 
awt::Key::RETURN);
+    pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_MOD1 | 
awt::Key::RETURN);
+    Scheduler::ProcessEventsToIdle();
+
+    insertString(*pModelObj, "+ 3)");
+
+    pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::RETURN);
+    pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, awt::Key::RETURN);
+    Scheduler::ProcessEventsToIdle();
+
+    // Without the fix in place, this test would have failed with
+    // - Expected: 6
+    // - Actual  : Err:501
+    CPPUNIT_ASSERT_EQUAL(OUString("6"), pDoc->GetString(ScAddress(0, 0, 0)));
+}
+
 CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf119162)
 {
     mxComponent = loadFromDesktop("private:factory/scalc");
@@ -584,11 +617,7 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf138432)
     dispatchCommand(mxComponent, ".uno:Copy", {});
     Scheduler::ProcessEventsToIdle();
 
-    goToCell("A2");
-
-    pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, '=', 0);
-    pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, '=', 0);
-    Scheduler::ProcessEventsToIdle();
+    insertStringToCell(*pModelObj, "A2", "=", /*bUseReturn*/ false);
 
     dispatchCommand(mxComponent, ".uno:Paste", {});
     Scheduler::ProcessEventsToIdle();
@@ -1489,9 +1518,7 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf119793)
     CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1381), 
xShape->getPosition().Y);
 
     // Type into the shape
-    pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 'x', 0);
-    pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 'x', 0);
-    Scheduler::ProcessEventsToIdle();
+    insertString(*pModelObj, "x");
     pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_ESCAPE);
     pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_ESCAPE);
     Scheduler::ProcessEventsToIdle();

Reply via email to