dev/null                          |binary
 sc/qa/uitest/textCase/textCase.py |   14 --------
 sc/qa/unit/uicalc/uicalc.cxx      |   65 +++++++++++++++++++++++++++++++-------
 3 files changed, 54 insertions(+), 25 deletions(-)

New commits:
commit b9a04e8a2352d2e6290299fb6416f0bdc0c90756
Author:     Xisco Fauli <xiscofa...@libreoffice.org>
AuthorDate: Wed Nov 10 17:11:43 2021 +0100
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Wed Nov 10 20:39:55 2021 +0100

    tdf#119162: sc: move UItest to CppUnittest
    
    Change-Id: I2e5467e92a4ebbaf2d028dd733d2f4a75eb03bb0
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125003
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/sc/qa/uitest/data/tdf119162.xls b/sc/qa/uitest/data/tdf119162.xls
deleted file mode 100644
index 42765fbe9000..000000000000
Binary files a/sc/qa/uitest/data/tdf119162.xls and /dev/null differ
diff --git a/sc/qa/uitest/textCase/textCase.py 
b/sc/qa/uitest/textCase/textCase.py
index 7dbb6d2a41d5..b2235a5f7ce0 100644
--- a/sc/qa/uitest/textCase/textCase.py
+++ b/sc/qa/uitest/textCase/textCase.py
@@ -123,18 +123,4 @@ class textCase(UITestCase):
             self.assertEqual(get_cell_by_position(document, 0, 0, 
4).getString(), "")
             self.assertEqual(get_cell_by_position(document, 0, 0, 
3).getString(), "Free suite")
 
-    def test_tdf119162_Cycle_Case(self):
-        #Bug 119162 - Format > Text > Cycle Case on attached example file 
hangs Calc reproducibly
-        with self.ui_test.load_file(get_url_for_data_file("tdf119162.xls")) as 
calc_doc:
-            xCalcDoc = self.xUITest.getTopFocusWindow()
-            gridwin = xCalcDoc.getChild("grid_window")
-            #1.Open the attached .xls file
-            #2. Select column A
-            gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "A1"}))
-            #3. Select [Format] > [Text] > [Cycle Case]
-            self.xUITest.executeCommand(".uno:ChangeCaseRotateCase")
-            self.xUITest.executeCommand(".uno:ChangeCaseToLower")
-            #Actual Results:Freezes LibreOffice
-            self.assertEqual(get_cell_by_position(calc_doc, 0, 0, 
0).getString(), "test\n")
-
 # vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/sc/qa/unit/uicalc/uicalc.cxx b/sc/qa/unit/uicalc/uicalc.cxx
index ef3b8dd24959..ea44aaa3cd40 100644
--- a/sc/qa/unit/uicalc/uicalc.cxx
+++ b/sc/qa/unit/uicalc/uicalc.cxx
@@ -49,7 +49,8 @@ public:
                               const OUString& rFilter);
     void goToCell(const OUString& rCell);
     void insertStringToCell(ScModelObj& rModelObj, const OUString& rCell, 
const std::string& rStr,
-                            bool bIsArray = false);
+                            bool bUseReturn = true);
+    void insertArrayToCell(ScModelObj& rModelObj, const OUString& rCell, const 
std::string& rStr);
     void insertNewSheet(ScDocument& rDoc);
 
 protected:
@@ -98,7 +99,7 @@ void ScUiCalcTest::goToCell(const OUString& rCell)
 }
 
 void ScUiCalcTest::insertStringToCell(ScModelObj& rModelObj, const OUString& 
rCell,
-                                      const std::string& rStr, bool bIsArray)
+                                      const std::string& rStr, bool bUseReturn)
 {
     goToCell(rCell);
 
@@ -109,13 +110,7 @@ void ScUiCalcTest::insertStringToCell(ScModelObj& 
rModelObj, const OUString& rCe
         Scheduler::ProcessEventsToIdle();
     }
 
-    if (bIsArray)
-    {
-        rModelObj.postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_MOD1 | KEY_SHIFT 
| awt::Key::RETURN);
-        rModelObj.postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_MOD1 | KEY_SHIFT | 
awt::Key::RETURN);
-        Scheduler::ProcessEventsToIdle();
-    }
-    else
+    if (bUseReturn)
     {
         rModelObj.postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::RETURN);
         rModelObj.postKeyEvent(LOK_KEYEVENT_KEYUP, 0, awt::Key::RETURN);
@@ -123,6 +118,16 @@ void ScUiCalcTest::insertStringToCell(ScModelObj& 
rModelObj, const OUString& rCe
     }
 }
 
+void ScUiCalcTest::insertArrayToCell(ScModelObj& rModelObj, const OUString& 
rCell,
+                                     const std::string& rStr)
+{
+    insertStringToCell(rModelObj, rCell, rStr, false);
+
+    rModelObj.postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_MOD1 | KEY_SHIFT | 
awt::Key::RETURN);
+    rModelObj.postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_MOD1 | KEY_SHIFT | 
awt::Key::RETURN);
+    Scheduler::ProcessEventsToIdle();
+}
+
 void ScUiCalcTest::insertNewSheet(ScDocument& rDoc)
 {
     sal_Int32 nTabs = static_cast<sal_Int32>(rDoc.GetTableCount());
@@ -166,6 +171,44 @@ ScModelObj* 
ScUiCalcTest::saveAndReload(css::uno::Reference<css::lang::XComponen
     return pModelObj;
 }
 
+CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf119162)
+{
+    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", "Test", /*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();
+
+    pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::RETURN);
+    pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, awt::Key::RETURN);
+    Scheduler::ProcessEventsToIdle();
+
+    CPPUNIT_ASSERT_EQUAL(OUString(u"Test" + OUStringChar(u'\xA')),
+                         pDoc->GetString(ScAddress(0, 0, 0)));
+
+    goToCell("A1");
+
+    // Without the fix in place, this test would have hung here
+    dispatchCommand(mxComponent, ".uno:ChangeCaseRotateCase", {});
+    Scheduler::ProcessEventsToIdle();
+
+    CPPUNIT_ASSERT_EQUAL(OUString(u"Test" + OUStringChar(u'\xA')),
+                         pDoc->GetString(ScAddress(0, 0, 0)));
+
+    dispatchCommand(mxComponent, ".uno:ChangeCaseToLower", {});
+    Scheduler::ProcessEventsToIdle();
+
+    CPPUNIT_ASSERT_EQUAL(OUString(u"test" + OUStringChar(u'\xA')),
+                         pDoc->GetString(ScAddress(0, 0, 0)));
+}
+
 CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf119155)
 {
     ScModelObj* pModelObj = createDoc("tdf119155.xlsx");
@@ -257,7 +300,7 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf145085)
     ScDocument* pDoc = pModelObj->GetDocument();
     CPPUNIT_ASSERT(pDoc);
 
-    insertStringToCell(*pModelObj, "A1", "=HYPERLINK(\"a\";\"b\")", true);
+    insertArrayToCell(*pModelObj, "A1", "=HYPERLINK(\"a\";\"b\")");
 
     CPPUNIT_ASSERT_EQUAL(OUString("b"), pDoc->GetString(ScAddress(0, 0, 0)));
 
@@ -738,7 +781,7 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf131442)
     ScDocument* pDoc = pModelObj->GetDocument();
     CPPUNIT_ASSERT(pDoc);
 
-    insertStringToCell(*pModelObj, "A1:A5", "={6;4;2;5;3}", true);
+    insertArrayToCell(*pModelObj, "A1:A5", "={6;4;2;5;3}");
 
     CPPUNIT_ASSERT_EQUAL(OUString("6"), pDoc->GetString(ScAddress(0, 0, 0)));
     CPPUNIT_ASSERT_EQUAL(OUString("4"), pDoc->GetString(ScAddress(0, 1, 0)));

Reply via email to