sc/qa/unit/tiledrendering/data/validity.xlsx |binary
 sc/qa/unit/tiledrendering/tiledrendering.cxx |   57 ++++++++++++++++++++++++---
 2 files changed, 52 insertions(+), 5 deletions(-)

New commits:
commit 388b4fc1085074da759903a9b1768bded43dd0d3
Author:     Dennis Francis <[email protected]>
AuthorDate: Thu Apr 7 13:14:59 2022 +0530
Commit:     Dennis Francis <[email protected]>
CommitDate: Fri Apr 8 09:16:08 2022 +0200

    lok: unit test for invalid entry save
    
    Unit test related to the fix
    
    lok: avoid validation-dialog yield when saving
    e0175ee821eaff56c4b8e0a1b7afa1cabe0ab593
    
    The test ensures that the document is marked unmodified after save has
    been executed in the middle of entering partial data to a validation
    cell.
    
    Change-Id: Idffd6d647034e128d0d800fe8e29efc333c03db6
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132655
    Tested-by: Jenkins
    Reviewed-by: Dennis Francis <[email protected]>

diff --git a/sc/qa/unit/tiledrendering/data/validity.xlsx 
b/sc/qa/unit/tiledrendering/data/validity.xlsx
new file mode 100644
index 000000000000..54a92acd5979
Binary files /dev/null and b/sc/qa/unit/tiledrendering/data/validity.xlsx differ
diff --git a/sc/qa/unit/tiledrendering/tiledrendering.cxx 
b/sc/qa/unit/tiledrendering/tiledrendering.cxx
index 249cd2420e4a..7ce8ad47105b 100644
--- a/sc/qa/unit/tiledrendering/tiledrendering.cxx
+++ b/sc/qa/unit/tiledrendering/tiledrendering.cxx
@@ -124,6 +124,7 @@ public:
     void testSheetViewDataCrash();
     void testTextBoxInsert();
     void testCommentCellCopyPaste();
+    void testInvalidEntrySave();
 
     CPPUNIT_TEST_SUITE(ScTiledRenderingTest);
     CPPUNIT_TEST(testRowColumnHeaders);
@@ -180,6 +181,7 @@ public:
     CPPUNIT_TEST(testSheetViewDataCrash);
     CPPUNIT_TEST(testTextBoxInsert);
     CPPUNIT_TEST(testCommentCellCopyPaste);
+    CPPUNIT_TEST(testInvalidEntrySave);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -2569,18 +2571,25 @@ void ScTiledRenderingTest::testSortAscendingDescending()
     CPPUNIT_ASSERT_EQUAL(OString("rows"), aView.m_sInvalidateSheetGeometry);
 }
 
-void lcl_typeCharsInCell(const std::string& aStr, SCCOL nCol, SCROW nRow, 
ScTabViewShell* pView, ScModelObj* pModelObj)
+void lcl_typeCharsInCell(const std::string& aStr, SCCOL nCol, SCROW nRow, 
ScTabViewShell* pView,
+    ScModelObj* pModelObj, bool bInEdit = false, bool bCommit = true)
 {
-    pView->SetCursor(nCol, nRow);
+    if (!bInEdit)
+        pView->SetCursor(nCol, nRow);
+
     for (const char& cChar : aStr)
     {
         pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, cChar, 0);
         pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, cChar, 0);
         Scheduler::ProcessEventsToIdle();
     }
-    pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::RETURN);
-    pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, awt::Key::RETURN);
-    Scheduler::ProcessEventsToIdle();
+
+    if (bCommit)
+    {
+        pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::RETURN);
+        pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, awt::Key::RETURN);
+        Scheduler::ProcessEventsToIdle();
+    }
 }
 
 void ScTiledRenderingTest::testAutoInputStringBlock()
@@ -2914,6 +2923,44 @@ void ScTiledRenderingTest::testCommentCellCopyPaste()
     comphelper::LibreOfficeKit::setTiledAnnotations(true);
 }
 
+void ScTiledRenderingTest::testInvalidEntrySave()
+{
+    // Load a document
+    comphelper::LibreOfficeKit::setActive();
+
+    ScModelObj* pModelObj = createDoc("validity.xlsx");
+    const ScDocument* pDoc = pModelObj->GetDocument();
+    ViewCallback aView;
+    int nView = SfxLokHelper::getView();
+
+    SfxLokHelper::setView(nView);
+
+    ScDocShell* pDocSh = dynamic_cast< ScDocShell* >( 
pModelObj->GetEmbeddedObject() );
+    ScTabViewShell* pTabViewShell = 
dynamic_cast<ScTabViewShell*>(SfxViewShell::Current());
+    CPPUNIT_ASSERT(pTabViewShell);
+
+    // Type partial date "7/8" of "7/8/2013" that
+    // the validation cell at A8 can accept
+    lcl_typeCharsInCell("7/8", 0, 7, pTabViewShell, pModelObj,
+        false /* bInEdit */, false /* bCommit */); // Type "7/8" in A8
+
+    uno::Sequence<beans::PropertyValue> aArgs;
+    comphelper::dispatchCommand(".uno:Save", aArgs);
+    Scheduler::ProcessEventsToIdle();
+
+    CPPUNIT_ASSERT_MESSAGE("Should not be marked modified after save", 
!pDocSh->IsModified());
+
+    // Complete the date in A8 by appending "/2013" and commit.
+    lcl_typeCharsInCell("/2013", 0, 7, pTabViewShell, pModelObj,
+        true /* bInEdit */, true /* bCommit */);
+
+    // This would hang if the date entered "7/8/2013" is not acceptable.
+    Scheduler::ProcessEventsToIdle();
+
+    // Ensure that the correct date is recorded in the document.
+    CPPUNIT_ASSERT_EQUAL(double(41463), pDoc->GetValue(ScAddress(0, 7, 0)));
+}
+
 }
 
 CPPUNIT_TEST_SUITE_REGISTRATION(ScTiledRenderingTest);

Reply via email to