sc/qa/unit/uicalc/data/tdf86305.ods |binary sc/qa/unit/uicalc/uicalc.cxx | 52 +++++++++++++++++++++++++++++++----- 2 files changed, 46 insertions(+), 6 deletions(-)
New commits: commit 7a7f72c30e888222ea8fc92327cdb7743f2307aa Author: Xisco Fauli <xiscofa...@libreoffice.org> AuthorDate: Tue Jan 26 11:46:48 2021 +0100 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Tue Jan 26 21:06:55 2021 +0100 tdf#86305: sc_uicalc: Add unittest Change-Id: If681436295be102c0bc97d0641799b0fdc7063ff Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109937 Tested-by: Jenkins Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> diff --git a/sc/qa/unit/uicalc/data/tdf86305.ods b/sc/qa/unit/uicalc/data/tdf86305.ods new file mode 100644 index 000000000000..fac69aa2307c Binary files /dev/null and b/sc/qa/unit/uicalc/data/tdf86305.ods differ diff --git a/sc/qa/unit/uicalc/uicalc.cxx b/sc/qa/unit/uicalc/uicalc.cxx index 0adc4f40f3ab..5e43d0f1d60a 100644 --- a/sc/qa/unit/uicalc/uicalc.cxx +++ b/sc/qa/unit/uicalc/uicalc.cxx @@ -40,6 +40,7 @@ public: ScModelObj* createDoc(const char* pName); void goToCell(const OUString& rCell); + void insertStringToCell(ScModelObj& rModelObj, const OUString& rCell, const std::string& rStr); protected: uno::Reference<lang::XComponent> mxComponent; @@ -86,6 +87,23 @@ void ScUiCalcTest::goToCell(const OUString& rCell) dispatchCommand(mxComponent, ".uno:GoToCell", aArgs); } +void ScUiCalcTest::insertStringToCell(ScModelObj& rModelObj, const OUString& rCell, + 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(); + } + + rModelObj.postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::RETURN); + rModelObj.postKeyEvent(LOK_KEYEVENT_KEYUP, 0, awt::Key::RETURN); + Scheduler::ProcessEventsToIdle(); +} + constexpr OUStringLiteral DATA_DIRECTORY = u"/sc/qa/unit/uicalc/data/"; ScModelObj* ScUiCalcTest::createDoc(const char* pName) @@ -509,7 +527,7 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf132431) // Without the fix in place, it would crash here with // uncaught exception of type std::exception (or derived). // - vector::_M_fill_insert - pDoc->SetString(ScAddress(7, 219, 0), "=SUMIFS($H$2:$DB$198,B$2:B$198,G220)"); + insertStringToCell(*pModelObj, "H220", "=SUMIFS($H$2:$DB$198,B$2:B$198,G220)"); pDoc->GetFormula(7, 219, 0, aFormula); CPPUNIT_ASSERT_EQUAL(OUString("=SUMIFS($H$2:$DB$198,B$2:B$198,G220)"), aFormula); @@ -526,11 +544,9 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf83901) CPPUNIT_ASSERT(pDoc); lcl_AssertCurrentCursorPosition(0, 0); - pDoc->SetString(ScAddress(0, 1, 0), "=ROW(A3)"); + insertStringToCell(*pModelObj, "A2", "=ROW(A3)"); CPPUNIT_ASSERT_EQUAL(3.0, pDoc->GetValue(ScAddress(0, 1, 0))); - dispatchCommand(mxComponent, ".uno:GoDown", {}); - dispatchCommand(mxComponent, ".uno:GoDown", {}); lcl_AssertCurrentCursorPosition(0, 2); dispatchCommand(mxComponent, ".uno:SelectRow", {}); dispatchCommand(mxComponent, ".uno:InsertRowsBefore", {}); @@ -795,8 +811,8 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf71339) ScDocument* pDoc = pModelObj->GetDocument(); CPPUNIT_ASSERT(pDoc); - pDoc->SetString(ScAddress(0, 1, 0), "1"); - pDoc->SetString(ScAddress(0, 2, 0), "1"); + insertStringToCell(*pModelObj, "A2", "1"); + insertStringToCell(*pModelObj, "A3", "1"); goToCell("A1:A3"); @@ -813,6 +829,30 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf71339) CPPUNIT_ASSERT_EQUAL(OUString("=SUM(A1:A3)"), aFormula); } +CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf86305) +{ + ScModelObj* pModelObj = createDoc("tdf86305.ods"); + CPPUNIT_ASSERT(pModelObj); + ScDocument* pDoc = pModelObj->GetDocument(); + CPPUNIT_ASSERT(pDoc); + + OUString aFormula; + pDoc->GetFormula(1, 6, 0, aFormula); + CPPUNIT_ASSERT_EQUAL(OUString("{=IF(SUM(B2:B4) > 0, SUM(B2:B4*D2:D4/C2:C4), 0)}"), aFormula); + CPPUNIT_ASSERT_EQUAL(0.0, pDoc->GetValue(ScAddress(1, 6, 0))); + + insertStringToCell(*pModelObj, "B3", "50"); + CPPUNIT_ASSERT_EQUAL(50.0, pDoc->GetValue(ScAddress(1, 2, 0))); + + pDoc->GetFormula(1, 6, 0, aFormula); + + // Without the fix in place, this test would have failed with + // - Expected: {=IF(SUM(B2:B4) > 0, SUM(B2:B4*D2:D4/C2:C4), 0)} + // - Actual : {=IF(SUM(B2:B4) > 0, SUM(B2:B4*D2:D4/C2:C4), 0.175)} + CPPUNIT_ASSERT_EQUAL(OUString("{=IF(SUM(B2:B4) > 0, SUM(B2:B4*D2:D4/C2:C4), 0)}"), aFormula); + CPPUNIT_ASSERT_EQUAL(0.175, pDoc->GetValue(ScAddress(1, 6, 0))); +} + CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf81351) { ScModelObj* pModelObj = createDoc("tdf81351.ods"); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits