diff options
author | Dennis Francis <dennis.francis@collabora.com> | 2022-04-07 13:14:59 +0530 |
---|---|---|
committer | Christian Lohmaier <lohmaier+LibreOffice@googlemail.com> | 2022-04-12 20:28:44 +0200 |
commit | 31167c542b6b9b6482dffee1a253a388ff3c0e2c (patch) | |
tree | d5daf50e500d49d1fc574fe91f8a5e1aaf7679db | |
parent | c45ab05455486323763851d6c3b6a168ae1abba6 (diff) |
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.
Conflicts:
sc/qa/unit/tiledrendering/tiledrendering.cxx
Change-Id: Idffd6d647034e128d0d800fe8e29efc333c03db6
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132657
Tested-by: Jenkins
Reviewed-by: Christian Lohmaier <lohmaier+LibreOffice@googlemail.com>
-rw-r--r-- | sc/qa/unit/tiledrendering/data/validity.xlsx | bin | 0 -> 5702 bytes | |||
-rw-r--r-- | sc/qa/unit/tiledrendering/tiledrendering.cxx | 57 |
2 files changed, 52 insertions, 5 deletions
diff --git a/sc/qa/unit/tiledrendering/data/validity.xlsx b/sc/qa/unit/tiledrendering/data/validity.xlsx Binary files differnew file mode 100644 index 000000000000..54a92acd5979 --- /dev/null +++ b/sc/qa/unit/tiledrendering/data/validity.xlsx diff --git a/sc/qa/unit/tiledrendering/tiledrendering.cxx b/sc/qa/unit/tiledrendering/tiledrendering.cxx index 6c6cd5990c3c..dbad2535fb1d 100644 --- a/sc/qa/unit/tiledrendering/tiledrendering.cxx +++ b/sc/qa/unit/tiledrendering/tiledrendering.cxx @@ -122,6 +122,7 @@ public: void testTextSelectionBounds(); void testSheetViewDataCrash(); void testTextBoxInsert(); + void testInvalidEntrySave(); CPPUNIT_TEST_SUITE(ScTiledRenderingTest); CPPUNIT_TEST(testRowColumnHeaders); @@ -177,6 +178,7 @@ public: CPPUNIT_TEST(testTextSelectionBounds); CPPUNIT_TEST(testSheetViewDataCrash); CPPUNIT_TEST(testTextBoxInsert); + CPPUNIT_TEST(testInvalidEntrySave); CPPUNIT_TEST_SUITE_END(); private: @@ -2643,18 +2645,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() @@ -2897,6 +2906,44 @@ void ScTiledRenderingTest::testTextBoxInsert() Scheduler::ProcessEventsToIdle(); } +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); |