sc/qa/unit/ucalc_copypaste.cxx | 57 +++++++++++++++++++++++++++++++++++++++ sc/source/core/data/documen3.cxx | 2 - 2 files changed, 58 insertions(+), 1 deletion(-)
New commits: commit fd0779f6a0fd04263155d293320546ce7cbae84b Author: scito <i...@scito.ch> AuthorDate: Fri May 21 11:06:20 2021 +0200 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Fri May 21 12:32:47 2021 +0200 tdf#71058 cut paste transposed: use correct clipdoc ScDocument: :UpdateTranspose() operated on the wrong clipdoc Change-Id: I10fb010c7b6a1d523a1af92d67fc127957f9d17f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115901 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> diff --git a/sc/qa/unit/ucalc_copypaste.cxx b/sc/qa/unit/ucalc_copypaste.cxx index 40536a573d90..0bbd326eb128 100644 --- a/sc/qa/unit/ucalc_copypaste.cxx +++ b/sc/qa/unit/ucalc_copypaste.cxx @@ -114,6 +114,7 @@ public: void testCopyPasteFormulas(); void testCopyPasteFormulasExternalDoc(); void testCopyPasteReferencesExternalDoc(); // tdf#106456 + void testTdf71058(); CPPUNIT_TEST_SUITE(TestCopyPaste); @@ -188,6 +189,8 @@ public: CPPUNIT_TEST(testCopyPasteFormulasExternalDoc); CPPUNIT_TEST(testCopyPasteReferencesExternalDoc); + CPPUNIT_TEST(testTdf71058); + CPPUNIT_TEST_SUITE_END(); private: @@ -6817,6 +6820,60 @@ void TestCopyPaste::testCopyPasteReferencesExternalDoc() xExtDocSh->DoClose(); } +void TestCopyPaste::testTdf71058() +{ + const SCTAB nTab = 0; + m_pDoc->InsertTab(nTab, "Test"); + + m_pDoc->SetString(2, 2, nTab, "=C4"); // C3 + m_pDoc->SetString(3, 2, nTab, "=D4"); // D3 + m_pDoc->SetValue(2, 3, nTab, 1.0); // C4 + m_pDoc->SetValue(3, 3, nTab, 2.0); // D4 + + // Cut C4:C5 to the clip document. + ScDocument aClipDoc(SCDOCMODE_CLIP); + ScRange aSrcRange(2, 3, nTab, 3, 3, nTab); + cutToClip(*m_xDocShell, aSrcRange, &aClipDoc, false); + + // To E6:E7 + ScRange aDestRange(4, 5, nTab, 4, 6, nTab); + ScMarkData aDestMark(m_pDoc->GetSheetLimits()); + + // Transpose + ScDocument* pOrigClipDoc = &aClipDoc; + ScDocumentUniquePtr pTransClip(new ScDocument(SCDOCMODE_CLIP)); + aClipDoc.TransposeClip(pTransClip.get(), InsertDeleteFlags::ALL, false, true); + aDestMark.SetMarkArea(aDestRange); + // Paste + m_pDoc->CopyFromClip(aDestRange, aDestMark, InsertDeleteFlags::ALL, nullptr, pTransClip.get(), + true, false, true, false); + m_pDoc->UpdateTranspose(aDestRange.aStart, pOrigClipDoc, aDestMark, nullptr); + pTransClip.reset(); + + // Check precondition + CPPUNIT_ASSERT_EQUAL(1.0, m_pDoc->GetValue(4, 5, nTab)); + CPPUNIT_ASSERT_EQUAL(2.0, m_pDoc->GetValue(4, 6, nTab)); + + // Check results + // Without the fix in place, this would have failed with + // - Expected: =E6 + // - Actual : =C4 + ASSERT_FORMULA_EQUAL(*m_pDoc, ScAddress(2, 2, nTab), "E6", "Wrong formula"); + // Without the fix in place, this would have failed with + // - Expected: 1 + // - Actual : 0 + CPPUNIT_ASSERT_EQUAL(1.0, m_pDoc->GetValue(2, 2, nTab)); + + // Without the fix in place, this would have failed with + // - Expected: =E7 + // - Actual : =D4 + ASSERT_FORMULA_EQUAL(*m_pDoc, ScAddress(3, 2, nTab), "E7", "Wrong formula"); + // Without the fix in place, this would have failed with + // - Expected: 2 + // - Actual : 0 + CPPUNIT_ASSERT_EQUAL(2.0, m_pDoc->GetValue(3, 2, nTab)); +} + CPPUNIT_TEST_SUITE_REGISTRATION(TestCopyPaste); CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sc/source/core/data/documen3.cxx b/sc/source/core/data/documen3.cxx index 8de06d151d78..5db63b6e7815 100644 --- a/sc/source/core/data/documen3.cxx +++ b/sc/source/core/data/documen3.cxx @@ -1112,7 +1112,7 @@ void ScDocument::UpdateTranspose( const ScAddress& rDestPos, ScDocument* pClipDo OSL_ENSURE(pClipDoc->bIsClip, "UpdateTranspose: No Clip"); ScRange aSource; - ScClipParam& rClipParam = GetClipParam(); + ScClipParam& rClipParam = pClipDoc->GetClipParam(); if (!rClipParam.maRanges.empty()) aSource = rClipParam.maRanges.front(); ScAddress aDest = rDestPos; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits