diff options
author | Eike Rathke <erack@redhat.com> | 2019-12-18 20:00:07 +0100 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2019-12-18 22:40:28 +0100 |
commit | 28ea93627ea4ea1a3003d3d1620125ea84ea31b3 (patch) | |
tree | 733f5403c37a74a0ae01cd77840631f89350ad73 /sc | |
parent | 3e88fc6b0eef06e1e12fcfe765e3092c6c06ce5c (diff) |
Unit test insert with shared formula group shift, tdf#129396
Change-Id: I99ab71f6fba4eb9f83fe8c262a6549a236ccf1ec
Reviewed-on: https://gerrit.libreoffice.org/85422
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Jenkins
Diffstat (limited to 'sc')
-rw-r--r-- | sc/qa/unit/ucalc.hxx | 2 | ||||
-rw-r--r-- | sc/qa/unit/ucalc_sharedformula.cxx | 66 |
2 files changed, 68 insertions, 0 deletions
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: */ |