sc/qa/unit/ucalc.hxx | 2 + sc/qa/unit/ucalc_sharedformula.cxx | 66 +++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+)
New commits: commit 28ea93627ea4ea1a3003d3d1620125ea84ea31b3 Author: Eike Rathke <er...@redhat.com> AuthorDate: Wed Dec 18 20:00:07 2019 +0100 Commit: Eike Rathke <er...@redhat.com> CommitDate: Wed Dec 18 22:40:28 2019 +0100 Unit test insert with shared formula group shift, tdf#129396 Change-Id: I99ab71f6fba4eb9f83fe8c262a6549a236ccf1ec Reviewed-on: https://gerrit.libreoffice.org/85422 Reviewed-by: Eike Rathke <er...@redhat.com> Tested-by: Jenkins diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx index 777dc4a51389..521a81130971 100644 --- a/sc/qa/unit/ucalc.hxx +++ b/sc/qa/unit/ucalc.hxx @@ -414,6 +414,7 @@ public: void testSharedFormulaCutCopyMoveIntoRef(); void testSharedFormulaCutCopyMoveWithRef(); void testSharedFormulaCutCopyMoveWithinRun(); + void testSharedFormulaInsertShift(); void testFormulaPosition(); void testFormulaWizardSubformula(); @@ -771,6 +772,7 @@ public: CPPUNIT_TEST(testSharedFormulaCutCopyMoveIntoRef); CPPUNIT_TEST(testSharedFormulaCutCopyMoveWithRef); CPPUNIT_TEST(testSharedFormulaCutCopyMoveWithinRun); + CPPUNIT_TEST(testSharedFormulaInsertShift); CPPUNIT_TEST(testFormulaPosition); CPPUNIT_TEST(testFormulaWizardSubformula); CPPUNIT_TEST(testMixData); diff --git a/sc/qa/unit/ucalc_sharedformula.cxx b/sc/qa/unit/ucalc_sharedformula.cxx index 0c3f06d46602..f076b57f8a64 100644 --- a/sc/qa/unit/ucalc_sharedformula.cxx +++ b/sc/qa/unit/ucalc_sharedformula.cxx @@ -2688,4 +2688,70 @@ void Test::testSharedFormulaCutCopyMoveWithinRun() m_pDoc->DeleteTab(0); } +// tdf#129396 +void Test::testSharedFormulaInsertShift() +{ + sc::AutoCalcSwitch aACSwitch(*m_pDoc, true); // turn on auto calc. + + m_pDoc->InsertTab(0, "Test"); + + // Data in A1:C2 + const std::vector<std::vector<const char*>> aData = { + { "1", "2", "=SUM(A1:B1)" }, + { "4", "8", "=SUM(A2:B2)" } + }; + const ScAddress aOrgPos(0,0,0); + insertRangeData( m_pDoc, aOrgPos, aData); + + { + // Check that C1:C2 is a formula group. + const ScAddress aFormulaPos(2,0,0); + const ScFormulaCell* pFC = m_pDoc->GetFormulaCell( aFormulaPos); + CPPUNIT_ASSERT(pFC); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Shared formula top row.", aFormulaPos.Row(), pFC->GetSharedTopRow()); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Shared formula length.", static_cast<SCROW>(2), pFC->GetSharedLength()); + } + + { + // Check results in C1:C2 + ScAddress aPos( aOrgPos); + aPos.SetCol(2); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "C1", 3.0, m_pDoc->GetValue(aPos)); + aPos.IncRow(); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "C2", 12.0, m_pDoc->GetValue(aPos)); + } + + const bool bSuccess = m_pDoc->InsertCol( 0, 0, 1, 0, 2, 1); + CPPUNIT_ASSERT_MESSAGE( "InsertCol", bSuccess); + + { + // Check that D1:D2 is a formula group. + const ScAddress aFormulaPos(3,0,0); + const ScFormulaCell* pFC = m_pDoc->GetFormulaCell( aFormulaPos); + CPPUNIT_ASSERT(pFC); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Shared formula top row.", aFormulaPos.Row(), pFC->GetSharedTopRow()); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Shared formula length.", static_cast<SCROW>(2), pFC->GetSharedLength()); + } + + { + // Modify values in B1:B2 + ScAddress aPos( aOrgPos); + aPos.SetCol(1); + m_pDoc->SetValue(aPos, 16.0); + aPos.IncRow(); + m_pDoc->SetValue(aPos, 32.0); + } + + { + // Check results in D1:D2 + ScAddress aPos( aOrgPos); + aPos.SetCol(3); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "D1", 17.0, m_pDoc->GetValue(aPos)); + aPos.IncRow(); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "D2", 36.0, m_pDoc->GetValue(aPos)); + } + + m_pDoc->DeleteTab(0); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits