[Libreoffice-commits] core.git: sc/CppunitTest_sc_ucalc_copypaste.mk sc/Module_sc.mk sc/qa
Xisco Fauli (via logerrit)
logerrit at kemper.freedesktop.org
Mon May 17 11:50:04 UTC 2021
sc/CppunitTest_sc_ucalc_copypaste.mk | 14
sc/Module_sc.mk | 1
sc/qa/unit/helper/qahelper.cxx | 16
sc/qa/unit/helper/qahelper.hxx | 2
sc/qa/unit/ucalc.cxx | 7019 -----------------------------------
sc/qa/unit/ucalc.hxx | 157
sc/qa/unit/ucalc_copypaste.cxx | 6928 ++++++++++++++++++++++++++++++++++
7 files changed, 7139 insertions(+), 6998 deletions(-)
New commits:
commit a78770c1935cabaafbb1d0bec258095b8899d25d
Author: Xisco Fauli <xiscofauli at libreoffice.org>
AuthorDate: Mon May 17 12:14:50 2021 +0200
Commit: Xisco Fauli <xiscofauli at libreoffice.org>
CommitDate: Mon May 17 13:49:23 2021 +0200
sc_ucalc: move copypaste tests to their own module
in order to split sc_ucalc monster into smaller
modules
While at it, fix the clang-format issues in
sc/qa/unit/ucalc_copypaste.cxx
Change-Id: Ifd3af351f4b880da29e1f48c4852ac65fcd3276e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115696
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli at libreoffice.org>
diff --git a/sc/CppunitTest_sc_ucalc_copypaste.mk b/sc/CppunitTest_sc_ucalc_copypaste.mk
new file mode 100644
index 000000000000..933b020081ad
--- /dev/null
+++ b/sc/CppunitTest_sc_ucalc_copypaste.mk
@@ -0,0 +1,14 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#*************************************************************************
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+#*************************************************************************
+
+$(eval $(call sc_ucalc_test,_copypaste))
+
+# vim: set noet sw=4 ts=4:
diff --git a/sc/Module_sc.mk b/sc/Module_sc.mk
index 9cc25d6052ea..94880fb19a72 100644
--- a/sc/Module_sc.mk
+++ b/sc/Module_sc.mk
@@ -41,6 +41,7 @@ $(eval $(call gb_Module_add_check_targets,sc,\
$(if $(and $(filter $(COM),MSC),$(MERGELIBS)),, \
CppunitTest_sc_ucalc) \
CppunitTest_sc_ucalc_condformat \
+ CppunitTest_sc_ucalc_copypaste \
CppunitTest_sc_ucalc_pivottable \
CppunitTest_sc_ucalc_sharedformula \
CppunitTest_sc_ucalc_sort \
diff --git a/sc/qa/unit/helper/qahelper.cxx b/sc/qa/unit/helper/qahelper.cxx
index ec8119d7a3f5..46196f9c28f4 100644
--- a/sc/qa/unit/helper/qahelper.cxx
+++ b/sc/qa/unit/helper/qahelper.cxx
@@ -979,6 +979,22 @@ void pasteOneCellFromClip(ScDocument* pDestDoc, const ScRange& rDestRange, ScDoc
rDestRange.aEnd.Col(), rDestRange.aEnd.Row());
}
+ScDocShell* findLoadedDocShellByName(std::u16string_view rName)
+{
+ ScDocShell* pShell = static_cast<ScDocShell*>(SfxObjectShell::GetFirst(checkSfxObjectShell<ScDocShell>, false));
+ while (pShell)
+ {
+ SfxMedium* pMedium = pShell->GetMedium();
+ if (pMedium)
+ {
+ OUString aName = pMedium->GetName();
+ if (aName == rName)
+ return pShell;
+ }
+ pShell = static_cast<ScDocShell*>(SfxObjectShell::GetNext(*pShell, checkSfxObjectShell<ScDocShell>, false));
+ }
+ return nullptr;
+}
bool insertRangeNames(
ScDocument* pDoc, ScRangeName* pNames, const RangeNameDef* p, const RangeNameDef* pEnd)
diff --git a/sc/qa/unit/helper/qahelper.hxx b/sc/qa/unit/helper/qahelper.hxx
index c7e3c0790e16..4d9986dd7373 100644
--- a/sc/qa/unit/helper/qahelper.hxx
+++ b/sc/qa/unit/helper/qahelper.hxx
@@ -252,7 +252,7 @@ SCQAHELPER_DLLPUBLIC ScUndoPaste* createUndoPaste(ScDocShell& rDocSh, const ScRa
SCQAHELPER_DLLPUBLIC void pasteOneCellFromClip(ScDocument* pDestDoc, const ScRange& rDestRange,
ScDocument* pClipDoc,
InsertDeleteFlags eFlags = InsertDeleteFlags::ALL);
-
+SCQAHELPER_DLLPUBLIC ScDocShell* findLoadedDocShellByName(std::u16string_view rName);
SCQAHELPER_DLLPUBLIC ScRange insertRangeData(ScDocument* pDoc, const ScAddress& rPos,
const std::vector<std::vector<const char*>>& rData);
SCQAHELPER_DLLPUBLIC bool insertRangeNames(ScDocument* pDoc, ScRangeName* pNames, const RangeNameDef* p,
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index 340d2112e898..5b34c2a073fb 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -18,7 +18,6 @@
#include <svl/gridprinter.hxx>
#include <scdll.hxx>
-#include <formulacell.hxx>
#include <simpleformulacalc.hxx>
#include <formulaopt.hxx>
#include <stringutil.hxx>
@@ -137,20 +136,6 @@ void Test::tearDown()
BootstrapFixture::tearDown();
}
-static ScMF lcl_getMergeFlagOfCell(const ScDocument& rDoc, SCCOL nCol, SCROW nRow, SCTAB nTab)
-{
- const SfxPoolItem& rPoolItem = rDoc.GetPattern(nCol, nRow, nTab)->GetItem(ATTR_MERGE_FLAG);
- const ScMergeFlagAttr& rMergeFlag = static_cast<const ScMergeFlagAttr&>(rPoolItem);
- return rMergeFlag.GetValue();
-}
-
-static ScAddress lcl_getMergeSizeOfCell(const ScDocument& rDoc, SCCOL nCol, SCROW nRow, SCTAB nTab)
-{
- const SfxPoolItem& rPoolItem = rDoc.GetPattern(nCol, nRow, nTab)->GetItem(ATTR_MERGE);
- const ScMergeAttr& rMerge = static_cast<const ScMergeAttr&>(rPoolItem);
- return ScAddress(rMerge.GetColMerge(), rMerge.GetRowMerge(), nTab);
-}
-
void Test::testCollator()
{
CollatorWrapper* p = ScGlobal::GetCollator();
@@ -3456,6733 +3441,237 @@ void Test::testTdf98642()
m_pDoc->DeleteTab(0);
}
-void Test::testCopyPaste()
+void Test::testMergedCells()
{
+ //test merge and unmerge
+ //TODO: an undo/redo test for this would be a good idea
m_pDoc->InsertTab(0, "Sheet1");
- m_pDoc->InsertTab(1, "Sheet2");
-
- // We need a drawing layer in order to create caption objects.
- m_pDoc->InitDrawLayer(m_xDocShell.get());
-
- //test copy&paste + ScUndoPaste
- //copy local and global range names in formulas
- //string cells and value cells
- m_pDoc->SetValue(0, 0, 0, 1);
- m_pDoc->SetValue(3, 0, 0, 0);
- m_pDoc->SetValue(3, 1, 0, 1);
- m_pDoc->SetValue(3, 2, 0, 2);
- m_pDoc->SetValue(3, 3, 0, 3);
- m_pDoc->SetString(2, 0, 0, "test");
- ScAddress aAdr (0, 0, 0);
-
- //create some range names, local and global
- ScRangeData* pLocal1 = new ScRangeData( *m_pDoc, "local1", aAdr);
- ScRangeData* pLocal2 = new ScRangeData( *m_pDoc, "local2", aAdr);
- ScRangeData* pLocal3 = new ScRangeData( *m_pDoc, "local3", "$Sheet1.$A$1");
- ScRangeData* pLocal4 = new ScRangeData( *m_pDoc, "local4", "Sheet1.$A$1");
- ScRangeData* pLocal5 = new ScRangeData( *m_pDoc, "local5", "$A$1"); // implicit relative sheet reference
- ScRangeData* pGlobal = new ScRangeData( *m_pDoc, "global", aAdr);
- const OUString aGlobal2Symbol("$Sheet1.$A$1:$A$23");
- ScRangeData* pGlobal2 = new ScRangeData( *m_pDoc, "global2", aGlobal2Symbol);
- std::unique_ptr<ScRangeName> pGlobalRangeName(new ScRangeName());
- pGlobalRangeName->insert(pGlobal);
- pGlobalRangeName->insert(pGlobal2);
- std::unique_ptr<ScRangeName> pLocalRangeName1(new ScRangeName());
- pLocalRangeName1->insert(pLocal1);
- pLocalRangeName1->insert(pLocal2);
- pLocalRangeName1->insert(pLocal3);
- pLocalRangeName1->insert(pLocal4);
- pLocalRangeName1->insert(pLocal5);
- m_pDoc->SetRangeName(std::move(pGlobalRangeName));
- m_pDoc->SetRangeName(0, std::move(pLocalRangeName1));
-
- // Add formula to B1.
- OUString aFormulaString("=local1+global+SUM($C$1:$D$4)+local3+local4+local5");
- m_pDoc->SetString(1, 0, 0, aFormulaString);
-
- double fValue = m_pDoc->GetValue(ScAddress(1,0,0));
- ASSERT_DOUBLES_EQUAL_MESSAGE("formula should return 11", fValue, 11);
-
- // add notes to A1:C1
- ScAddress aAdrA1 (0, 0, 0); // empty cell content
- ScPostIt* pNoteA1 = m_pDoc->GetOrCreateNote(aAdrA1);
- pNoteA1->SetText(aAdrA1, "Hello world in A1");
- ScAddress aAdrB1 (1, 0, 0); // formula cell content
- ScPostIt* pNoteB1 = m_pDoc->GetOrCreateNote(aAdrB1);
- pNoteB1->SetText(aAdrB1, "Hello world in B1");
- ScAddress aAdrC1 (2, 0, 0); // string cell content
- ScPostIt* pNoteC1 = m_pDoc->GetOrCreateNote(aAdrC1);
- pNoteC1->SetText(aAdrC1, "Hello world in C1");
-
- //copy Sheet1.A1:C1 to Sheet2.A2:C2
- ScRange aRange(0,0,0,2,0,0);
- ScDocument aClipDoc(SCDOCMODE_CLIP);
- copyToClip(m_pDoc, aRange, &aClipDoc);
-
- aRange = ScRange(0,1,1,2,1,1);//target: Sheet2.A2:C2
- ScDocumentUniquePtr pUndoDoc(new ScDocument(SCDOCMODE_UNDO));
- pUndoDoc->InitUndo(*m_pDoc, 1, 1, true, true);
- std::unique_ptr<ScUndoPaste> pUndo(createUndoPaste(*m_xDocShell, aRange, std::move(pUndoDoc)));
+ m_pDoc->DoMerge(0, 1, 1, 3, 3, false);
+ SCCOL nEndCol = 1;
+ SCROW nEndRow = 1;
+ m_pDoc->ExtendMerge( 1, 1, nEndCol, nEndRow, 0);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("did not merge cells", SCCOL(3), nEndCol);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("did not merge cells", SCROW(3), nEndRow);
+ ScRange aRange(0,2,0,MAXCOL,2,0);
ScMarkData aMark(m_pDoc->GetSheetLimits());
aMark.SetMarkArea(aRange);
- m_pDoc->CopyFromClip(aRange, aMark, InsertDeleteFlags::ALL, nullptr, &aClipDoc);
-
- //check values after copying
- OUString aString;
- m_pDoc->GetFormula(1,1,1, aString);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("formula string was not copied correctly", aString, aFormulaString);
- // Only the global range points to Sheet1.A1, all copied sheet-local ranges
- // to Sheet2.A1 that is empty, hence the result is 1, not 2.
- fValue = m_pDoc->GetValue(ScAddress(1,1,1));
- ASSERT_DOUBLES_EQUAL_MESSAGE("copied formula should return 1", 1.0, fValue);
- fValue = m_pDoc->GetValue(ScAddress(0,1,1));
- ASSERT_DOUBLES_EQUAL_MESSAGE("copied value should be 1", 1.0, fValue);
-
- ScRange aSheet2A1(0,0,1,0,0,1);
-
- //check local range name after copying
- pLocal1 = m_pDoc->GetRangeName(1)->findByUpperName(OUString("LOCAL1"));
- CPPUNIT_ASSERT_MESSAGE("local range name 1 should be copied", pLocal1);
- ScRange aRangeLocal1;
- bool bIsValidRef1 = pLocal1->IsValidReference(aRangeLocal1);
- CPPUNIT_ASSERT_MESSAGE("local range name 1 should be valid", bIsValidRef1);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("local range 1 should now point to Sheet2.A1", aSheet2A1, aRangeLocal1);
-
- pLocal2 = m_pDoc->GetRangeName(1)->findByUpperName(OUString("LOCAL2"));
- CPPUNIT_ASSERT_MESSAGE("local2 should not be copied", !pLocal2);
-
- pLocal3 = m_pDoc->GetRangeName(1)->findByUpperName(OUString("LOCAL3"));
- CPPUNIT_ASSERT_MESSAGE("local range name 3 should be copied", pLocal3);
- ScRange aRangeLocal3;
- bool bIsValidRef3 = pLocal3->IsValidReference(aRangeLocal3);
- CPPUNIT_ASSERT_MESSAGE("local range name 3 should be valid", bIsValidRef3);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("local range 3 should now point to Sheet2.A1", aSheet2A1, aRangeLocal3);
-
- pLocal4 = m_pDoc->GetRangeName(1)->findByUpperName(OUString("LOCAL4"));
- CPPUNIT_ASSERT_MESSAGE("local range name 4 should be copied", pLocal4);
- ScRange aRangeLocal4;
- bool bIsValidRef4 = pLocal4->IsValidReference(aRangeLocal4);
- CPPUNIT_ASSERT_MESSAGE("local range name 4 should be valid", bIsValidRef4);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("local range 4 should now point to Sheet2.A1", aSheet2A1, aRangeLocal4);
-
- pLocal5 = m_pDoc->GetRangeName(1)->findByUpperName(OUString("LOCAL5"));
- CPPUNIT_ASSERT_MESSAGE("local range name 5 should be copied", pLocal5);
- ScRange aRangeLocal5;
- bool bIsValidRef5 = pLocal5->IsValidReference(aRangeLocal5);
- CPPUNIT_ASSERT_MESSAGE("local range name 5 should be valid", bIsValidRef5);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("local range 5 should now point to Sheet2.A1", aSheet2A1, aRangeLocal5);
-
- // check notes after copying
- CPPUNIT_ASSERT_MESSAGE("There should be a note on Sheet2.A2", m_pDoc->HasNote(ScAddress(0, 1, 1)));
- CPPUNIT_ASSERT_MESSAGE("There should be a note on Sheet2.B2", m_pDoc->HasNote(ScAddress(1, 1, 1)));
- CPPUNIT_ASSERT_MESSAGE("There should be a note on Sheet2.C2", m_pDoc->HasNote(ScAddress(2, 1, 1)));
- CPPUNIT_ASSERT_EQUAL_MESSAGE("Note content on Sheet1.A1 not copied to Sheet2.A2, empty cell content",
- m_pDoc->GetNote(ScAddress(0, 0, 0))->GetText(), m_pDoc->GetNote(ScAddress(0, 1, 1))->GetText());
- CPPUNIT_ASSERT_EQUAL_MESSAGE("Note content on Sheet1.B1 not copied to Sheet2.B2, formula cell content",
- m_pDoc->GetNote(ScAddress(1, 0, 0))->GetText(), m_pDoc->GetNote(ScAddress(1, 1, 1))->GetText());
- CPPUNIT_ASSERT_EQUAL_MESSAGE("Note content on Sheet1.C1 not copied to Sheet2.C2, string cell content",
- m_pDoc->GetNote(ScAddress(2, 0, 0))->GetText(), m_pDoc->GetNote(ScAddress(2, 1, 1))->GetText());
-
- //check undo and redo
- pUndo->Undo();
- fValue = m_pDoc->GetValue(ScAddress(1,1,1));
- ASSERT_DOUBLES_EQUAL_MESSAGE("after undo formula should return nothing", fValue, 0);
- aString = m_pDoc->GetString(2, 1, 1);
- CPPUNIT_ASSERT_MESSAGE("after undo, string should be removed", aString.isEmpty());
- CPPUNIT_ASSERT_MESSAGE("after undo, note on A2 should be removed", !m_pDoc->HasNote(ScAddress(0, 1, 1)));
- CPPUNIT_ASSERT_MESSAGE("after undo, note on B2 should be removed", !m_pDoc->HasNote(ScAddress(1, 1, 1)));
- CPPUNIT_ASSERT_MESSAGE("after undo, note on C2 should be removed", !m_pDoc->HasNote(ScAddress(2, 1, 1)));
-
- pUndo->Redo();
- fValue = m_pDoc->GetValue(ScAddress(1,1,1));
- ASSERT_DOUBLES_EQUAL_MESSAGE("formula should return 1 after redo", 1.0, fValue);
- aString = m_pDoc->GetString(2, 1, 1);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("Cell Sheet2.C2 should contain: test", OUString("test"), aString);
- m_pDoc->GetFormula(1,1,1, aString);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("Formula should be correct again", aFormulaString, aString);
-
- CPPUNIT_ASSERT_MESSAGE("After Redo, there should be a note on Sheet2.A2", m_pDoc->HasNote(ScAddress(0, 1, 1)));
- CPPUNIT_ASSERT_MESSAGE("After Redo, there should be a note on Sheet2.B2", m_pDoc->HasNote(ScAddress(1, 1, 1)));
- CPPUNIT_ASSERT_MESSAGE("After Redo, there should be a note on Sheet2.C2", m_pDoc->HasNote(ScAddress(2, 1, 1)));
- CPPUNIT_ASSERT_EQUAL_MESSAGE("After Redo, note again on Sheet2.A2, empty cell content",
- m_pDoc->GetNote(ScAddress(0, 0, 0))->GetText(), m_pDoc->GetNote(ScAddress(0, 1, 1))->GetText());
- CPPUNIT_ASSERT_EQUAL_MESSAGE("After Redo, note again on Sheet2.B2, formula cell content",
- m_pDoc->GetNote(ScAddress(1, 0, 0))->GetText(), m_pDoc->GetNote(ScAddress(1, 1, 1))->GetText());
- CPPUNIT_ASSERT_EQUAL_MESSAGE("After Redo, note again on Sheet2.C2, string cell content",
- m_pDoc->GetNote(ScAddress(2, 0, 0))->GetText(), m_pDoc->GetNote(ScAddress(2, 1, 1))->GetText());
-
-
- // Copy Sheet1.A11:A13 to Sheet1.A7:A9, both within global2 range.
- aRange = ScRange(0,10,0,0,12,0);
- ScDocument aClipDoc2(SCDOCMODE_CLIP);
- copyToClip(m_pDoc, aRange, &aClipDoc2);
-
- aRange = ScRange(0,6,0,0,8,0);
- aMark.SetMarkArea(aRange);
- m_pDoc->CopyFromClip(aRange, aMark, InsertDeleteFlags::ALL, nullptr, &aClipDoc2);
-
- // The global2 range must not have changed.
- pGlobal2 = m_pDoc->GetRangeName()->findByUpperName("GLOBAL2");
- CPPUNIT_ASSERT_MESSAGE("GLOBAL2 name not found", pGlobal2);
- OUString aSymbol;
- pGlobal2->GetSymbol(aSymbol);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("GLOBAL2 named range changed", aGlobal2Symbol, aSymbol);
-
-
- m_pDoc->DeleteTab(1);
+ m_xDocShell->GetDocFunc().InsertCells(aRange, &aMark, INS_INSROWS_BEFORE, true, true);
+ m_pDoc->ExtendMerge(1, 1, nEndCol, nEndRow, 0);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("did not increase merge area", SCCOL(3), nEndCol);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("did not increase merge area", SCROW(4), nEndRow);
m_pDoc->DeleteTab(0);
}
-void Test::testCopyPasteAsLink()
+void Test::testRenameTable()
{
- sc::AutoCalcSwitch aACSwitch(*m_pDoc, true); // Turn on auto calc.
+ //test set rename table
+ //TODO: set name1 and name2 and do an undo to check if name 1 is set now
+ //TODO: also check if new name for table is same as another table
m_pDoc->InsertTab(0, "Sheet1");
m_pDoc->InsertTab(1, "Sheet2");
- m_pDoc->SetValue(ScAddress(0,0,0), 1); // A1
- m_pDoc->SetValue(ScAddress(0,1,0), 2); // A2
- m_pDoc->SetValue(ScAddress(0,2,0), 3); // A3
+ //test case 1 , rename table2 to sheet 1, it should return error
+ OUString nameToSet = "Sheet1";
+ ScDocFunc& rDocFunc = m_xDocShell->GetDocFunc();
+ CPPUNIT_ASSERT_MESSAGE("name same as another table is being set", !rDocFunc.RenameTable(1,nameToSet,false,true) );
- ScRange aRange(0,0,0,0,2,0); // Copy A1:A3 to clip.
- ScDocument aClipDoc(SCDOCMODE_CLIP);
- copyToClip(m_pDoc, aRange, &aClipDoc);
+ //test case 2 , simple rename to check name
+ nameToSet = "test1";
+ m_xDocShell->GetDocFunc().RenameTable(0,nameToSet,false,true);
+ OUString nameJustSet;
+ m_pDoc->GetName(0,nameJustSet);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("table not renamed", nameToSet, nameJustSet);
- aRange = ScRange(1,1,1,1,3,1); // Paste to B2:B4 on Sheet2.
- ScMarkData aMark(m_pDoc->GetSheetLimits());
- aMark.SetMarkArea(aRange);
- // Paste range as link.
- m_pDoc->CopyFromClip(aRange, aMark, InsertDeleteFlags::CONTENTS, nullptr, &aClipDoc, true, true);
+ //test case 3 , rename again
+ OUString anOldName;
+ m_pDoc->GetName(0,anOldName);
- // Check pasted content to make sure they reference the correct cells.
- ScFormulaCell* pFC = m_pDoc->GetFormulaCell(ScAddress(1,1,1));
- CPPUNIT_ASSERT_MESSAGE("This should be a formula cell.", pFC);
- CPPUNIT_ASSERT_EQUAL(1.0, pFC->GetValue());
+ nameToSet = "test2";
+ rDocFunc.RenameTable(0,nameToSet,false,true);
+ m_pDoc->GetName(0,nameJustSet);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("table not renamed", nameToSet, nameJustSet);
- pFC = m_pDoc->GetFormulaCell(ScAddress(1,2,1));
- CPPUNIT_ASSERT_MESSAGE("This should be a formula cell.", pFC);
- CPPUNIT_ASSERT_EQUAL(2.0, pFC->GetValue());
+ //test case 4 , check if undo works
+ SfxUndoAction* pUndo = new ScUndoRenameTab(m_xDocShell.get(),0,anOldName,nameToSet);
+ pUndo->Undo();
+ m_pDoc->GetName(0,nameJustSet);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("the correct name is not set after undo", nameJustSet, anOldName);
- pFC = m_pDoc->GetFormulaCell(ScAddress(1,3,1));
- CPPUNIT_ASSERT_MESSAGE("This should be a formula cell.", pFC);
- CPPUNIT_ASSERT_EQUAL(3.0, pFC->GetValue());
+ pUndo->Redo();
+ m_pDoc->GetName(0,nameJustSet);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("the correct color is not set after redo", nameJustSet, nameToSet);
+ delete pUndo;
- m_pDoc->DeleteTab(1);
m_pDoc->DeleteTab(0);
+ m_pDoc->DeleteTab(1);
}
-void Test::testCopyPasteTranspose()
+void Test::testSetBackgroundColor()
{
- m_pDoc->InsertTab(0, "Sheet1");
-
- // We need a drawing layer in order to create caption objects.
- m_pDoc->InitDrawLayer(m_xDocShell.get());
-
- m_pDoc->SetValue(0, 0, 0, 1);
- m_pDoc->SetString(1, 0, 0, "=A1+1");
- m_pDoc->SetString(2, 0, 0, "test");
-
- // add notes to A1:C1
- ScAddress aAdrA1 (0, 0, 0); // numerical cell content
- ScPostIt* pNoteA1 = m_pDoc->GetOrCreateNote(aAdrA1);
- pNoteA1->SetText(aAdrA1, "Hello world in A1");
- ScAddress aAdrB1 (1, 0, 0); // formula cell content
- ScPostIt* pNoteB1 = m_pDoc->GetOrCreateNote(aAdrB1);
- pNoteB1->SetText(aAdrB1, "Hello world in B1");
- ScAddress aAdrC1 (2, 0, 0); // string cell content
- ScPostIt* pNoteC1 = m_pDoc->GetOrCreateNote(aAdrC1);
- pNoteC1->SetText(aAdrC1, "Hello world in C1");
-
- // transpose clipboard, paste and check on Sheet2
- m_pDoc->InsertTab(1, "Sheet2");
+ //test set background color
+ //TODO: set color1 and set color2 and do an undo to check if color1 is set now.
- ScRange aSrcRange(0,0,0,2,0,0);
- ScDocument aNewClipDoc(SCDOCMODE_CLIP);
- copyToClip(m_pDoc, aSrcRange, &aNewClipDoc);
+ m_pDoc->InsertTab(0, "Sheet1");
+ Color aColor;
- ScDocumentUniquePtr pTransClip(new ScDocument(SCDOCMODE_CLIP));
- aNewClipDoc.TransposeClip(pTransClip.get(), InsertDeleteFlags::ALL, false, false);
+ //test yellow
+ aColor=COL_YELLOW;
+ m_xDocShell->GetDocFunc().SetTabBgColor(0,aColor,false, true);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("the correct color is not set",
+ aColor, m_pDoc->GetTabBgColor(0));
- ScRange aDestRange(3,1,1,3,3,1);//target: Sheet2.D2:D4
- ScMarkData aMark(m_pDoc->GetSheetLimits());
- aMark.SetMarkArea(aDestRange);
- m_pDoc->CopyFromClip(aDestRange, aMark, InsertDeleteFlags::ALL, nullptr, pTransClip.get());
- pTransClip.reset();
-
- //check cell content after transposed copy/paste
- OUString aString = m_pDoc->GetString(3, 3, 1);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("Cell Sheet2.D4 should contain: test", OUString("test"), aString);
- double fValue = m_pDoc->GetValue(ScAddress(3,1,1));
- ASSERT_DOUBLES_EQUAL_MESSAGE("transposed copied cell should return 1", 1, fValue);
- fValue = m_pDoc->GetValue(ScAddress(3,2,1));
- ASSERT_DOUBLES_EQUAL_MESSAGE("transposed copied formula should return 2", 2, fValue);
- m_pDoc->GetFormula(3, 2, 1, aString);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("transposed formula should point on Sheet2.D2", OUString("=D2+1"), aString);
-
- // check notes after transposed copy/paste
- CPPUNIT_ASSERT_MESSAGE("There should be a note on Sheet2.D2", m_pDoc->HasNote(ScAddress(3, 1, 1)));
- CPPUNIT_ASSERT_MESSAGE("There should be a note on Sheet2.D3", m_pDoc->HasNote(ScAddress(3, 2, 1)));
- CPPUNIT_ASSERT_MESSAGE("There should be a note on Sheet2.D4", m_pDoc->HasNote(ScAddress(3, 3, 1)));
- CPPUNIT_ASSERT_EQUAL_MESSAGE("Content of cell note on Sheet2.D2",
- m_pDoc->GetNote(ScAddress(0, 0, 0))->GetText(),
- m_pDoc->GetNote(ScAddress(3, 1, 1))->GetText());
- CPPUNIT_ASSERT_EQUAL_MESSAGE("Content of cell note on Sheet2.D3",
- m_pDoc->GetNote(ScAddress(1, 0, 0))->GetText(),
- m_pDoc->GetNote(ScAddress(3, 2, 1))->GetText());
- CPPUNIT_ASSERT_EQUAL_MESSAGE("Content of cell note on Sheet2.D4",
- m_pDoc->GetNote(ScAddress(2, 0, 0))->GetText(),
- m_pDoc->GetNote(ScAddress(3, 3, 1))->GetText());
+ Color aOldTabBgColor=m_pDoc->GetTabBgColor(0);
+ aColor = COL_BLUE;
+ m_xDocShell->GetDocFunc().SetTabBgColor(0,aColor,false, true);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("the correct color is not set the second time",
+ aColor, m_pDoc->GetTabBgColor(0));
- m_pDoc->DeleteTab(1);
+ //now check for undo
+ SfxUndoAction* pUndo = new ScUndoTabColor(m_xDocShell.get(), 0, aOldTabBgColor, aColor);
+ pUndo->Undo();
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("the correct color is not set after undo", aOldTabBgColor, m_pDoc->GetTabBgColor(0));
+ pUndo->Redo();
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("the correct color is not set after undo", aColor, m_pDoc->GetTabBgColor(0));
+ delete pUndo;
m_pDoc->DeleteTab(0);
}
-void Test::testCopyPasteSpecialMergedCellsTranspose()
+void Test::testUpdateReference()
{
- const SCTAB srcSheet = 0;
- const SCTAB destSheet = 1;
-
- sc::AutoCalcSwitch aACSwitch(*m_pDoc, true); // Turn on auto calc.
-
- m_pDoc->InsertTab(srcSheet, "Sheet1");
- m_pDoc->InsertTab(destSheet, "Sheet2");
-
- m_pDoc->SetValue(0, 0, srcSheet, 1); // A1
- m_pDoc->SetValue(0, 1, srcSheet, 2); // A2
- m_pDoc->SetValue(0, 2, srcSheet, 3); // A3
- m_pDoc->SetValue(0, 3, srcSheet, 4); // A4
-
- m_pDoc->DoMerge(srcSheet, 0, 1, 1, 1, false); // Merge A2 and B2
- m_pDoc->DoMerge(srcSheet, 0, 2, 1, 2, false); // Merge A3 and B3
-
- // Test precondition
- CPPUNIT_ASSERT_EQUAL(ScAddress(0, 0, srcSheet),
- lcl_getMergeSizeOfCell(*m_pDoc, 0, 0, srcSheet));
- CPPUNIT_ASSERT_EQUAL(ScMF::NONE, lcl_getMergeFlagOfCell(*m_pDoc, 1, 0, srcSheet));
- CPPUNIT_ASSERT_EQUAL(ScAddress(2, 1, srcSheet),
- lcl_getMergeSizeOfCell(*m_pDoc, 0, 1, srcSheet));
- CPPUNIT_ASSERT_EQUAL(ScAddress(0, 0, srcSheet),
- lcl_getMergeSizeOfCell(*m_pDoc, 1, 1, srcSheet));
- CPPUNIT_ASSERT_EQUAL(ScMF::Hor, lcl_getMergeFlagOfCell(*m_pDoc, 1, 1, srcSheet));
- CPPUNIT_ASSERT_EQUAL(ScAddress(2, 1, srcSheet),
- lcl_getMergeSizeOfCell(*m_pDoc, 0, 2, srcSheet));
- CPPUNIT_ASSERT_EQUAL(ScAddress(0, 0, srcSheet),
- lcl_getMergeSizeOfCell(*m_pDoc, 1, 2, srcSheet));
- CPPUNIT_ASSERT_EQUAL(ScMF::Hor, lcl_getMergeFlagOfCell(*m_pDoc, 1, 2, srcSheet));
- CPPUNIT_ASSERT_EQUAL(ScAddress(0, 0, srcSheet),
- lcl_getMergeSizeOfCell(*m_pDoc, 0, 3, srcSheet));
- CPPUNIT_ASSERT_EQUAL(ScMF::NONE, lcl_getMergeFlagOfCell(*m_pDoc, 1, 3, srcSheet));
-
- ScRange aSrcRange(0, 0, srcSheet, 1, 3, srcSheet); // Copy A1:B4 to clip.
- ScDocument aClipDoc(SCDOCMODE_CLIP);
- copyToClip(m_pDoc, aSrcRange, &aClipDoc);
-
- // transpose
- ScDocumentUniquePtr pTransClip(new ScDocument(SCDOCMODE_CLIP));
- aClipDoc.TransposeClip(pTransClip.get(), InsertDeleteFlags::ALL, true, false);
-
- ScRange aDestRange(1, 1, destSheet, 4, 2, destSheet); // Paste to B2:E3 on Sheet2.
- ScMarkData aMark(m_pDoc->GetSheetLimits());
- aMark.SetMarkArea(aDestRange);
- m_pDoc->CopyFromClip(aDestRange, aMark, InsertDeleteFlags::ALL, nullptr, pTransClip.get(), true,
- false);
- pTransClip.reset();
-
- // Check transpose of merged cells
- CPPUNIT_ASSERT_EQUAL(ScAddress(0, 0, destSheet),
- lcl_getMergeSizeOfCell(*m_pDoc, 1, 1, destSheet));
- CPPUNIT_ASSERT_EQUAL(ScMF::NONE, lcl_getMergeFlagOfCell(*m_pDoc, 1, 2, destSheet));
- CPPUNIT_ASSERT_EQUAL(ScAddress(1, 2, destSheet),
- lcl_getMergeSizeOfCell(*m_pDoc, 2, 1, destSheet));
- CPPUNIT_ASSERT_EQUAL(2.0, m_pDoc->GetValue(2, 1, destSheet));
- CPPUNIT_ASSERT_EQUAL(ScAddress(1, 2, destSheet),
- lcl_getMergeSizeOfCell(*m_pDoc, 3, 1, destSheet));
- CPPUNIT_ASSERT_EQUAL(3.0, m_pDoc->GetValue(3, 1, destSheet));
- CPPUNIT_ASSERT_EQUAL(ScAddress(0, 0, destSheet),
- lcl_getMergeSizeOfCell(*m_pDoc, 4, 1, destSheet));
- CPPUNIT_ASSERT_EQUAL(ScMF::NONE, lcl_getMergeFlagOfCell(*m_pDoc, 4, 2, destSheet));
-
- m_pDoc->DeleteTab(destSheet);
- m_pDoc->DeleteTab(srcSheet);
-}
+ //test that formulas are correctly updated during sheet delete
+ //TODO: add tests for relative references, updating of named ranges, ...
+ m_pDoc->InsertTab(0, "Sheet1");
+ m_pDoc->InsertTab(1, "Sheet2");
+ m_pDoc->InsertTab(2, "Sheet3");
+ m_pDoc->InsertTab(3, "Sheet4");
-void Test::testCopyPasteSpecialMergedCellsFilteredTranspose()
-{
- const SCTAB srcSheet = 0;
- const SCTAB destSheet = 1;
+ m_pDoc->SetValue(0,0,2, 1);
+ m_pDoc->SetValue(1,0,2, 2);
+ m_pDoc->SetValue(1,1,3, 4);
+ m_pDoc->SetString(2,0,2, "=A1+B1");
+ m_pDoc->SetString(2,1,2, "=Sheet4.B2+A1");
- sc::AutoCalcSwitch aACSwitch(*m_pDoc, true); // Turn on auto calc.
+ double aValue;
+ m_pDoc->GetValue(2,0,2, aValue);
+ ASSERT_DOUBLES_EQUAL_MESSAGE("formula does not return correct result", aValue, 3);
+ m_pDoc->GetValue(2,1,2, aValue);
+ ASSERT_DOUBLES_EQUAL_MESSAGE("formula does not return correct result", aValue, 5);
- m_pDoc->InsertTab(srcSheet, "Sheet1");
- m_pDoc->InsertTab(destSheet, "Sheet2");
+ //test deleting both sheets: one is not directly before the sheet, the other one is
+ m_pDoc->DeleteTab(0);
+ m_pDoc->GetValue(2,0,1, aValue);
+ ASSERT_DOUBLES_EQUAL_MESSAGE("after deleting first sheet formula does not return correct result", aValue, 3);
+ m_pDoc->GetValue(2,1,1, aValue);
+ ASSERT_DOUBLES_EQUAL_MESSAGE("after deleting first sheet formula does not return correct result", aValue, 5);
- m_pDoc->SetValue(0, 0, srcSheet, 1); // A1
- m_pDoc->SetValue(0, 1, srcSheet, 2); // A2
- m_pDoc->SetValue(0, 2, srcSheet, 3); // A3
- m_pDoc->SetValue(0, 3, srcSheet, 4); // A4
+ m_pDoc->DeleteTab(0);
+ m_pDoc->GetValue(2,0,0, aValue);
+ ASSERT_DOUBLES_EQUAL_MESSAGE("after deleting second sheet formula does not return correct result", aValue, 3);
+ m_pDoc->GetValue(2,1,0, aValue);
+ ASSERT_DOUBLES_EQUAL_MESSAGE("after deleting second sheet formula does not return correct result", aValue, 5);
- m_pDoc->DoMerge(srcSheet, 0, 1, 1, 1, false); // Merge A2 and B2
- m_pDoc->DoMerge(srcSheet, 0, 2, 1, 2, false); // Merge A3 and B3
+ //test adding two sheets
+ m_pDoc->InsertTab(0, "Sheet2");
+ m_pDoc->GetValue(2,0,1, aValue);
+ ASSERT_DOUBLES_EQUAL_MESSAGE("after inserting first sheet formula does not return correct result", aValue, 3);
+ m_pDoc->GetValue(2,1,1, aValue);
+ ASSERT_DOUBLES_EQUAL_MESSAGE("after inserting first sheet formula does not return correct result", aValue, 5);
- // Filter row 1
- ScDBData* pDBData = new ScDBData("TRANSPOSE_TEST_DATA", srcSheet, 0, 0, 0, 3);
- m_pDoc->SetAnonymousDBData(0, std::unique_ptr<ScDBData>(pDBData));
+ m_pDoc->InsertTab(0, "Sheet1");
+ m_pDoc->GetValue(2,0,2, aValue);
+ ASSERT_DOUBLES_EQUAL_MESSAGE("after inserting second sheet formula does not return correct result", aValue, 3);
+ m_pDoc->GetValue(2,1,2, aValue);
+ ASSERT_DOUBLES_EQUAL_MESSAGE("after inserting second sheet formula does not return correct result", aValue, 5);
- pDBData->SetAutoFilter(true);
- ScRange aRange;
- pDBData->GetArea(aRange);
- m_pDoc->ApplyFlagsTab(aRange.aStart.Col(), aRange.aStart.Row(), aRange.aEnd.Col(),
- aRange.aStart.Row(), aRange.aStart.Tab(), ScMF::Auto);
+ //test new DeleteTabs/InsertTabs methods
+ m_pDoc->DeleteTabs(0, 2);
+ m_pDoc->GetValue(2, 0, 0, aValue);
+ ASSERT_DOUBLES_EQUAL_MESSAGE("after deleting sheets formula does not return correct result", aValue, 3);
+ m_pDoc->GetValue(2, 1, 0, aValue);
+ ASSERT_DOUBLES_EQUAL_MESSAGE("after deleting sheets formula does not return correct result", aValue, 5);
- //create the query param
- ScQueryParam aParam;
- pDBData->GetQueryParam(aParam);
- ScQueryEntry& rEntry = aParam.GetEntry(0);
- rEntry.bDoQuery = true;
- rEntry.nField = 0;
- rEntry.eOp = SC_NOT_EQUAL;
- rEntry.GetQueryItem().mfVal = 2; // value of row A2 -> filtering row 1
- // add queryParam to database range.
- pDBData->SetQueryParam(aParam);
+ std::vector<OUString> aSheets;
+ aSheets.emplace_back("Sheet1");
+ aSheets.emplace_back("Sheet2");
+ m_pDoc->InsertTabs(0, aSheets, true);
+ m_pDoc->GetValue(2, 0, 2, aValue);
+ OUString aFormula;
+ m_pDoc->GetFormula(2,0,2, aFormula);
- // perform the query.
- m_pDoc->Query(srcSheet, aParam, true);
-
- // Test precondition
- CPPUNIT_ASSERT_EQUAL(ScAddress(0, 0, srcSheet),
- lcl_getMergeSizeOfCell(*m_pDoc, 0, 0, srcSheet));
- CPPUNIT_ASSERT_EQUAL(ScMF::NONE, lcl_getMergeFlagOfCell(*m_pDoc, 1, 0, srcSheet));
- CPPUNIT_ASSERT_EQUAL(ScAddress(2, 1, srcSheet),
- lcl_getMergeSizeOfCell(*m_pDoc, 0, 1, srcSheet));
- CPPUNIT_ASSERT_EQUAL(ScAddress(0, 0, srcSheet),
- lcl_getMergeSizeOfCell(*m_pDoc, 1, 1, srcSheet));
- CPPUNIT_ASSERT_EQUAL(ScMF::Hor, lcl_getMergeFlagOfCell(*m_pDoc, 1, 1, srcSheet));
- CPPUNIT_ASSERT_EQUAL(ScAddress(2, 1, srcSheet),
- lcl_getMergeSizeOfCell(*m_pDoc, 0, 2, srcSheet));
- CPPUNIT_ASSERT_EQUAL(ScAddress(0, 0, srcSheet),
- lcl_getMergeSizeOfCell(*m_pDoc, 1, 2, srcSheet));
- CPPUNIT_ASSERT_EQUAL(ScMF::Hor, lcl_getMergeFlagOfCell(*m_pDoc, 1, 2, srcSheet));
- CPPUNIT_ASSERT_EQUAL(ScAddress(0, 0, srcSheet),
- lcl_getMergeSizeOfCell(*m_pDoc, 0, 3, srcSheet));
- CPPUNIT_ASSERT_EQUAL(ScMF::NONE, lcl_getMergeFlagOfCell(*m_pDoc, 1, 3, srcSheet));
-
- ScRange aSrcRange(0, 0, srcSheet, 1, 3, srcSheet); // Copy A1:B4 to clip.
- ScDocument aClipDoc(SCDOCMODE_CLIP);
- copyToClip(m_pDoc, aSrcRange, &aClipDoc);
+ ASSERT_DOUBLES_EQUAL_MESSAGE("after inserting sheets formula does not return correct result", aValue, 3);
+ m_pDoc->GetValue(2, 1, 2, aValue);
+ ASSERT_DOUBLES_EQUAL_MESSAGE("after inserting sheets formula does not return correct result", aValue, 5);
- // transpose
- ScDocumentUniquePtr pTransClip(new ScDocument(SCDOCMODE_CLIP));
- aClipDoc.TransposeClip(pTransClip.get(), InsertDeleteFlags::ALL, true, false);
+ m_pDoc->DeleteTab(3);
+ m_pDoc->DeleteTab(2);
+ m_pDoc->DeleteTab(1);
+ m_pDoc->DeleteTab(0);
- ScRange aDestRange(1, 1, destSheet, 3, 2, destSheet); // Paste to B2:D3 on Sheet2.
- ScMarkData aMark(m_pDoc->GetSheetLimits());
- aMark.SetMarkArea(aDestRange);
- m_pDoc->CopyFromClip(aDestRange, aMark, InsertDeleteFlags::ALL, nullptr, pTransClip.get(), true,
- false);
- pTransClip.reset();
-
- // Check transpose of merged cells
- CPPUNIT_ASSERT_EQUAL(ScAddress(0, 0, destSheet),
- lcl_getMergeSizeOfCell(*m_pDoc, 1, 1, destSheet));
- CPPUNIT_ASSERT_EQUAL(ScMF::NONE, lcl_getMergeFlagOfCell(*m_pDoc, 1, 2, destSheet));
- CPPUNIT_ASSERT_EQUAL(ScAddress(1, 2, destSheet),
- lcl_getMergeSizeOfCell(*m_pDoc, 2, 1, destSheet));
- CPPUNIT_ASSERT_EQUAL(3.0, m_pDoc->GetValue(2, 1, destSheet));
- CPPUNIT_ASSERT_EQUAL(ScAddress(0, 0, destSheet),
- lcl_getMergeSizeOfCell(*m_pDoc, 3, 1, destSheet));
- CPPUNIT_ASSERT_EQUAL(ScMF::NONE, lcl_getMergeFlagOfCell(*m_pDoc, 3, 2, destSheet));
-
- m_pDoc->DeleteTab(destSheet);
- m_pDoc->DeleteTab(srcSheet);
+ // Test positional update and invalidation of lookup cache for insertion
+ // and deletion within entire column reference.
+ m_pDoc->InsertTab(0, "Sheet1");
+ m_pDoc->InsertTab(1, "Sheet2");
+ m_pDoc->SetString(0,1,0, "s1");
+ m_pDoc->SetString(0,0,1, "=MATCH(\"s1\";Sheet1.A:A;0)");
+ m_pDoc->GetValue(0,0,1, aValue);
+ ASSERT_DOUBLES_EQUAL_MESSAGE("unexpected MATCH result", 2, aValue);
+ m_pDoc->InsertRow(0,0,MAXCOL,0,0,1); // insert 1 row before row 1 in Sheet1
+ m_pDoc->GetValue(0,0,1, aValue);
+ ASSERT_DOUBLES_EQUAL_MESSAGE("unexpected MATCH result", 3, aValue);
+ m_pDoc->DeleteRow(0,0,MAXCOL,0,0,1); // delete row 1 in Sheet1
+ m_pDoc->GetValue(0,0,1, aValue);
+ ASSERT_DOUBLES_EQUAL_MESSAGE("unexpected MATCH result", 2, aValue);
+ m_pDoc->DeleteTab(1);
+ m_pDoc->DeleteTab(0);
}
-// InsertDeleteFlags::CONTENTS
-void Test::testCopyPasteSpecialAsLinkTranspose()
+void Test::testSearchCells()
{
- const SCTAB srcSheet = 0;
- const SCTAB destSheet = 1;
-
- sc::AutoCalcSwitch aACSwitch(*m_pDoc, true); // Turn on auto calc.
-
- m_pDoc->InsertTab(srcSheet, "Sheet1");
- m_pDoc->InsertTab(destSheet, "Sheet2");
-
- m_pDoc->SetValue(0, 0, srcSheet, 1); // A1
- m_pDoc->SetValue(0, 1, srcSheet, 2); // A2
- m_pDoc->SetValue(0, 3, srcSheet, 4); // A4
+ m_pDoc->InsertTab(0, "Test");
- ScRange aSrcRange(0, 0, srcSheet, 0, 3, srcSheet); // Copy A1:A4 to clip.
- ScDocument aClipDoc(SCDOCMODE_CLIP);
- copyToClip(m_pDoc, aSrcRange, &aClipDoc);
+ m_pDoc->SetString(ScAddress(0,0,0), "A");
+ m_pDoc->SetString(ScAddress(0,1,0), "B");
+ m_pDoc->SetString(ScAddress(0,2,0), "A");
+ // Leave A4 blank.
+ m_pDoc->SetString(ScAddress(0,4,0), "A");
+ m_pDoc->SetString(ScAddress(0,5,0), "B");
+ m_pDoc->SetString(ScAddress(0,6,0), "C");
- // transpose
- ScDocumentUniquePtr pTransClip(new ScDocument(SCDOCMODE_CLIP));
- aClipDoc.TransposeClip(pTransClip.get(), InsertDeleteFlags::CONTENTS, true, false);
+ SvxSearchItem aItem(SID_SEARCH_ITEM);
+ aItem.SetSearchString("A");
+ aItem.SetCommand(SvxSearchCmd::FIND_ALL);
+ ScMarkData aMarkData(m_pDoc->GetSheetLimits());
+ aMarkData.SelectOneTable(0);
+ SCCOL nCol = 0;
+ SCROW nRow = 0;
+ SCTAB nTab = 0;
+ ScRangeList aMatchedRanges;
+ OUString aUndoStr;
+ bool bSuccess = m_pDoc->SearchAndReplace(aItem, nCol, nRow, nTab, aMarkData, aMatchedRanges, aUndoStr);
- ScRange aDestRange(1, 1, destSheet, 4, 1, destSheet); // Paste to B2:E2 on Sheet2.
- ScMarkData aMark(m_pDoc->GetSheetLimits());
- aMark.SetMarkArea(aDestRange);
- m_pDoc->CopyFromClip(aDestRange, aMark, InsertDeleteFlags::CONTENTS, nullptr, pTransClip.get(),
- true, false);
- pTransClip.reset();
+ CPPUNIT_ASSERT_MESSAGE("Search And Replace should succeed", bSuccess);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("There should be exactly 3 matching cells.", size_t(3), aMatchedRanges.size());
+ ScAddress aHit(0,0,0);
+ CPPUNIT_ASSERT_MESSAGE("A1 should be inside the matched range.", aMatchedRanges.In(aHit));
+ aHit.SetRow(2);
+ CPPUNIT_ASSERT_MESSAGE("A3 should be inside the matched range.", aMatchedRanges.In(aHit));
+ aHit.SetRow(4);
+ CPPUNIT_ASSERT_MESSAGE("A5 should be inside the matched range.", aMatchedRanges.In(aHit));
- OUString aString;
- // Check pasted content to make sure they reference the correct cells.
- ScFormulaCell* pFC = m_pDoc->GetFormulaCell(ScAddress(1, 1, destSheet));
- CPPUNIT_ASSERT_MESSAGE("This should be a formula cell B2.", pFC);
- m_pDoc->GetFormula(1, 1, destSheet, aString);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("Formula cell B2", OUString("=$Sheet1.$A$1"), aString);
- CPPUNIT_ASSERT_EQUAL(1.0, pFC->GetValue());
-
- pFC = m_pDoc->GetFormulaCell(ScAddress(2, 1, destSheet));
- CPPUNIT_ASSERT_MESSAGE("This should be a formula cell.", pFC);
- m_pDoc->GetFormula(2, 1, destSheet, aString);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("Formula cell C2", OUString("=$Sheet1.$A$2"), aString);
- CPPUNIT_ASSERT_EQUAL(2.0, pFC->GetValue());
-
- pFC = m_pDoc->GetFormulaCell(ScAddress(3, 1, destSheet));
- CPPUNIT_ASSERT_MESSAGE("This should be no formula cell D2.", !pFC);
-
- pFC = m_pDoc->GetFormulaCell(ScAddress(4, 1, destSheet));
- CPPUNIT_ASSERT_MESSAGE("This should be a formula cell.", pFC);
- m_pDoc->GetFormula(4, 1, destSheet, aString);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("Formula cell E2", OUString("=$Sheet1.$A$4"), aString);
- CPPUNIT_ASSERT_EQUAL(4.0, pFC->GetValue());
-
- m_pDoc->DeleteTab(destSheet);
- m_pDoc->DeleteTab(srcSheet);
+ m_pDoc->DeleteTab(0);
}
-// InsertDeleteFlags::CONTENTS
-void Test::testCopyPasteSpecialAsLinkFilteredTranspose()
+void Test::testFormulaPosition()
{
- const SCTAB srcSheet = 0;
- const SCTAB destSheet = 1;
-
- sc::AutoCalcSwitch aACSwitch(*m_pDoc, true); // Turn on auto calc.
-
- m_pDoc->InsertTab(srcSheet, "Sheet1");
- m_pDoc->InsertTab(destSheet, "Sheet2");
+ m_pDoc->InsertTab(0, "Test");
- m_pDoc->SetValue(0, 0, srcSheet, 1); // A1
- m_pDoc->SetValue(0, 1, srcSheet, 2); // A2
- m_pDoc->SetValue(0, 3, srcSheet, 4); // A4
-
- // Filter row 1
- ScDBData* pDBData = new ScDBData("TRANSPOSE_TEST_DATA", srcSheet, 0, 0, 0, 3);
- m_pDoc->SetAnonymousDBData(0, std::unique_ptr<ScDBData>(pDBData));
-
- pDBData->SetAutoFilter(true);
- ScRange aRange;
- pDBData->GetArea(aRange);
- m_pDoc->ApplyFlagsTab(aRange.aStart.Col(), aRange.aStart.Row(), aRange.aEnd.Col(),
- aRange.aStart.Row(), aRange.aStart.Tab(), ScMF::Auto);
-
- //create the query param
- ScQueryParam aParam;
- pDBData->GetQueryParam(aParam);
- ScQueryEntry& rEntry = aParam.GetEntry(0);
- rEntry.bDoQuery = true;
- rEntry.nField = 0;
- rEntry.eOp = SC_NOT_EQUAL;
- rEntry.GetQueryItem().mfVal = 2; // value of row A2 -> filtering row 1
- // add queryParam to database range.
- pDBData->SetQueryParam(aParam);
-
- // perform the query.
- m_pDoc->Query(srcSheet, aParam, true);
-
- // Check precondition for test: row 1 is hidden/filtered
- SCROW nRow1, nRow2;
- SCROW nFilteredRow1, nFilteredRow2;
- bool bHidden = m_pDoc->RowHidden(SCROW(1), srcSheet, &nRow1, &nRow2);
- CPPUNIT_ASSERT_MESSAGE("row 1 should be hidden", bHidden);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("row 1 should be hidden", SCROW(1), nRow1);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("row 1 should be hidden", SCROW(1), nRow2);
- bool bFiltered = m_pDoc->RowFiltered(SCROW(1), srcSheet, &nFilteredRow1, &nFilteredRow2);
- CPPUNIT_ASSERT_MESSAGE("row 1 should be filtered", bFiltered);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("row 1 should be filtered", SCROW(1), nFilteredRow1);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("row 1 should be filtered", SCROW(1), nFilteredRow2);
-
- // Copy A1:A4 to clip.
- ScRange aSrcRange(0, 0, srcSheet, 0, 3, srcSheet);
- ScDocument aClipDoc(SCDOCMODE_CLIP);
- copyToClip(m_pDoc, aSrcRange, &aClipDoc);
-
- // transpose
- ScDocumentUniquePtr pTransClip(new ScDocument(SCDOCMODE_CLIP));
- aClipDoc.TransposeClip(pTransClip.get(), InsertDeleteFlags::CONTENTS, true, false);
-
- ScRange aDestRange(1, 1, destSheet, 3, 1, destSheet); // Paste to B2:D2 on Sheet2.
- ScMarkData aMark(m_pDoc->GetSheetLimits());
- aMark.SetMarkArea(aDestRange);
- m_pDoc->CopyFromClip(aDestRange, aMark, InsertDeleteFlags::CONTENTS, nullptr, pTransClip.get(),
- true, false, false);
- pTransClip.reset();
-
- OUString aString;
- // Check pasted content to make sure they reference the correct cells.
- ScFormulaCell* pFC = m_pDoc->GetFormulaCell(ScAddress(1, 1, destSheet));
- CPPUNIT_ASSERT_MESSAGE("This should be a formula cell B2.", pFC);
- m_pDoc->GetFormula(1, 1, destSheet, aString);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("Formula cell B2", OUString("=$Sheet1.$A$1"), aString);
- CPPUNIT_ASSERT_EQUAL(1.0, pFC->GetValue());
-
- pFC = m_pDoc->GetFormulaCell(ScAddress(2, 1, destSheet));
- CPPUNIT_ASSERT_MESSAGE("This should be no formula cell C2.", !pFC);
-
- pFC = m_pDoc->GetFormulaCell(ScAddress(3, 1, destSheet));
- CPPUNIT_ASSERT_MESSAGE("This should be a formula cell.", pFC);
- m_pDoc->GetFormula(3, 1, destSheet, aString);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("Formula cell D2", OUString("=$Sheet1.$A$4"), aString);
- CPPUNIT_ASSERT_EQUAL(4.0, pFC->GetValue());
-
- m_pDoc->DeleteTab(destSheet);
- m_pDoc->DeleteTab(srcSheet);
-}
-
-// tdf#141683
-// InsertDeleteFlags::CONTENTS
-void Test::testCopyPasteSpecialMultiRangeRowAsLinkTranspose()
-{
- const SCTAB srcSheet = 0;
- const SCTAB destSheet = 1;
-
- sc::AutoCalcSwitch aACSwitch(*m_pDoc, true); // Turn on auto calc.
-
- m_pDoc->InsertTab(srcSheet, "Sheet1");
- m_pDoc->InsertTab(destSheet, "Sheet2");
-
- m_pDoc->SetValue(0, 0, srcSheet, 1); // A1
- m_pDoc->SetValue(1, 0, srcSheet, 2); // B1
- m_pDoc->SetValue(3, 0, srcSheet, 4); // D1
-
- m_pDoc->SetValue(0, 2, srcSheet, 11); // A3
- m_pDoc->SetValue(1, 2, srcSheet, 12); // B3
- m_pDoc->SetValue(3, 2, srcSheet, 14); // D3
-
- ScMarkData aSrcMark(m_pDoc->GetSheetLimits());
- aSrcMark.SelectOneTable(0);
- ScClipParam aClipParam;
- aClipParam.meDirection = ScClipParam::Row;
- aClipParam.maRanges.push_back(ScRange(0, 0, srcSheet, 3, 0, srcSheet)); // A1:D1
- aClipParam.maRanges.push_back(ScRange(0, 2, srcSheet, 3, 2, srcSheet)); // A3:D3
-
- ScDocument aClipDoc(SCDOCMODE_CLIP);
- m_pDoc->CopyToClip(aClipParam, &aClipDoc, &aSrcMark, false, false);
-
- // transpose
- ScDocumentUniquePtr pTransClip(new ScDocument(SCDOCMODE_CLIP));
- aClipDoc.TransposeClip(pTransClip.get(), InsertDeleteFlags::CONTENTS, true, false);
-
- ScRange aDestRange(1, 1, destSheet, 2, 4, destSheet); // Paste to B2:C5 on Sheet2.
- ScMarkData aMark(m_pDoc->GetSheetLimits());
- aMark.SetMarkArea(aDestRange);
- m_pDoc->CopyMultiRangeFromClip(ScAddress(1, 1, destSheet), aMark, InsertDeleteFlags::CONTENTS,
- pTransClip.get(), true, false /* false fixes tdf#141683 */,
- false, false);
- pTransClip.reset();
-
- OUString aString;
- // Check pasted content to make sure they reference the correct cells.
- ScFormulaCell* pFC = m_pDoc->GetFormulaCell(ScAddress(1, 1, destSheet));
- CPPUNIT_ASSERT_MESSAGE("This should be a formula cell B2.", pFC);
- m_pDoc->GetFormula(1, 1, destSheet, aString);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("Formula cell B2", OUString("=$Sheet1.$A$1"), aString);
- CPPUNIT_ASSERT_EQUAL(1.0, pFC->GetValue());
-
- pFC = m_pDoc->GetFormulaCell(ScAddress(1, 2, destSheet));
- CPPUNIT_ASSERT_MESSAGE("This should be a formula cell B3.", pFC);
- m_pDoc->GetFormula(1, 2, destSheet, aString);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("Formula cell B3", OUString("=$Sheet1.$B$1"), aString);
- CPPUNIT_ASSERT_EQUAL(2.0, pFC->GetValue());
-
- pFC = m_pDoc->GetFormulaCell(ScAddress(1, 3, destSheet));
- CPPUNIT_ASSERT_MESSAGE("This should be no formula cell B4.", !pFC);
-
- pFC = m_pDoc->GetFormulaCell(ScAddress(1, 4, destSheet));
- CPPUNIT_ASSERT_MESSAGE("This should be a formula cell.", pFC);
- m_pDoc->GetFormula(1, 4, destSheet, aString);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("Formula cell B5", OUString("=$Sheet1.$D$1"), aString);
- CPPUNIT_ASSERT_EQUAL(4.0, pFC->GetValue());
-
- pFC = m_pDoc->GetFormulaCell(ScAddress(2, 1, destSheet));
- CPPUNIT_ASSERT_MESSAGE("This should be a formula cell C2.", pFC);
- m_pDoc->GetFormula(2, 1, destSheet, aString);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("Formula cell C2", OUString("=$Sheet1.$A$3"), aString);
- CPPUNIT_ASSERT_EQUAL(11.0, pFC->GetValue());
-
- pFC = m_pDoc->GetFormulaCell(ScAddress(2, 2, destSheet));
- CPPUNIT_ASSERT_MESSAGE("This should be a formula cell C3.", pFC);
- m_pDoc->GetFormula(2, 2, destSheet, aString);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("Formula cell C3", OUString("=$Sheet1.$B$3"), aString);
- CPPUNIT_ASSERT_EQUAL(12.0, pFC->GetValue());
-
- pFC = m_pDoc->GetFormulaCell(ScAddress(2, 3, destSheet));
- CPPUNIT_ASSERT_MESSAGE("This should be no formula cell C4.", !pFC);
-
- pFC = m_pDoc->GetFormulaCell(ScAddress(2, 4, destSheet));
- CPPUNIT_ASSERT_MESSAGE("This should be a formula cell.", pFC);
- m_pDoc->GetFormula(2, 4, destSheet, aString);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("Formula cell C5", OUString("=$Sheet1.$D$3"), aString);
- CPPUNIT_ASSERT_EQUAL(14.0, pFC->GetValue());
-
- m_pDoc->DeleteTab(destSheet);
- m_pDoc->DeleteTab(srcSheet);
-}
-
-// tdf#141683
-// InsertDeleteFlags::CONTENTS
-void Test::testCopyPasteSpecialMultiRangeRowAsLinkFilteredTranspose()
-{
- const SCTAB srcSheet = 0;
- const SCTAB destSheet = 1;
-
- sc::AutoCalcSwitch aACSwitch(*m_pDoc, true); // Turn on auto calc.
-
- m_pDoc->InsertTab(srcSheet, "Sheet1");
- m_pDoc->InsertTab(destSheet, "Sheet2");
-
- m_pDoc->SetValue(0, 0, srcSheet, 1); // A1
- m_pDoc->SetValue(1, 0, srcSheet, 2); // B1
- m_pDoc->SetValue(3, 0, srcSheet, 4); // D1
-
- m_pDoc->SetValue(0, 1, srcSheet, -1); // A2, filtered and selected
- m_pDoc->SetValue(1, 1, srcSheet, -2); // B2, filtered and selected
- m_pDoc->SetValue(3, 1, srcSheet, -4); // D2, filtered and selected
-
- m_pDoc->SetValue(0, 2, srcSheet, 11); // A3
- m_pDoc->SetValue(1, 2, srcSheet, 12); // B3
- m_pDoc->SetValue(3, 2, srcSheet, 14); // D3
-
- m_pDoc->SetValue(0, 3, srcSheet, -11); // A4, filtered and not selected
- m_pDoc->SetValue(1, 3, srcSheet, -12); // B4, filtered and not selected
- m_pDoc->SetValue(3, 3, srcSheet, -14); // D4, filtered and not selected
-
- m_pDoc->SetValue(0, 5, srcSheet, 111); // A6
- m_pDoc->SetValue(1, 5, srcSheet, 112); // B6
- m_pDoc->SetValue(3, 5, srcSheet, 114); // D6
-
- // Filter row 1
- ScDBData* pDBData = new ScDBData("TRANSPOSE_TEST_DATA", srcSheet, 0, 0, 3, 3);
- m_pDoc->SetAnonymousDBData(0, std::unique_ptr<ScDBData>(pDBData));
-
- pDBData->SetAutoFilter(true);
- ScRange aRange;
- pDBData->GetArea(aRange);
- m_pDoc->ApplyFlagsTab(aRange.aStart.Col(), aRange.aStart.Row(), aRange.aEnd.Col(),
- aRange.aStart.Row(), aRange.aStart.Tab(), ScMF::Auto);
-
- //create the query param
- ScQueryParam aParam;
- pDBData->GetQueryParam(aParam);
- ScQueryEntry& rEntry = aParam.GetEntry(0);
- rEntry.bDoQuery = true;
- rEntry.nField = 0;
- rEntry.eOp = SC_GREATER_EQUAL;
- rEntry.GetQueryItem().mfVal = 0; // filtering negative values -> filtering row 1 and 2
- // add queryParam to database range.
- pDBData->SetQueryParam(aParam);
-
- // perform the query.
- m_pDoc->Query(srcSheet, aParam, true);
-
- ScMarkData aSrcMark(m_pDoc->GetSheetLimits());
- aSrcMark.SelectOneTable(0);
- ScClipParam aClipParam;
- aClipParam.meDirection = ScClipParam::Row;
- aClipParam.maRanges.push_back(ScRange(0, 0, srcSheet, 3, 2, srcSheet)); // A1:C3
- aClipParam.maRanges.push_back(ScRange(0, 5, srcSheet, 3, 5, srcSheet)); // A6:C6
-
- ScDocument aClipDoc(SCDOCMODE_CLIP);
- m_pDoc->CopyToClip(aClipParam, &aClipDoc, &aSrcMark, false, false);
-
- printRange(m_pDoc, aClipParam.getWholeRange(), "Src range");
- // transpose
- ScDocumentUniquePtr pTransClip(new ScDocument(SCDOCMODE_CLIP));
- aClipDoc.TransposeClip(pTransClip.get(), InsertDeleteFlags::CONTENTS, true, false);
-
- printRange(&aClipDoc, ScRange(0, 0, 0, 4, 5, 0), "Base doc (&aNewClipDoc)");
- printRange(pTransClip.get(), ScRange(0, 0, 0, 3, 3, 0),
- "Transposed filtered clipdoc (pTransClip.get())");
- ScRange aDestRange(1, 1, destSheet, 3, 4, destSheet); // Paste to B2:D5 on Sheet2.
- ScMarkData aMark(m_pDoc->GetSheetLimits());
- aMark.SetMarkArea(aDestRange);
- m_pDoc->CopyMultiRangeFromClip(ScAddress(1, 1, destSheet), aMark, InsertDeleteFlags::CONTENTS,
- pTransClip.get(), true, false /* false fixes tdf#141683 */,
- false, false);
- pTransClip.reset();
- printRange(m_pDoc, aDestRange, "Transposed dest sheet");
-
- OUString aString;
- // Check pasted content to make sure they reference the correct cells.
- ScFormulaCell* pFC = m_pDoc->GetFormulaCell(ScAddress(1, 1, destSheet));
- CPPUNIT_ASSERT_MESSAGE("This should be a formula cell B2.", pFC);
- m_pDoc->GetFormula(1, 1, destSheet, aString);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("Formula cell B2", OUString("=$Sheet1.$A$1"), aString);
- CPPUNIT_ASSERT_EQUAL(1.0, pFC->GetValue());
-
- pFC = m_pDoc->GetFormulaCell(ScAddress(1, 2, destSheet));
- CPPUNIT_ASSERT_MESSAGE("This should be a formula cell B3.", pFC);
- m_pDoc->GetFormula(1, 2, destSheet, aString);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("Formula cell B3", OUString("=$Sheet1.$B$1"), aString);
- CPPUNIT_ASSERT_EQUAL(2.0, pFC->GetValue());
-
- pFC = m_pDoc->GetFormulaCell(ScAddress(1, 3, destSheet));
- CPPUNIT_ASSERT_MESSAGE("This should be no formula cell B4.", !pFC);
-
- pFC = m_pDoc->GetFormulaCell(ScAddress(1, 4, destSheet));
- CPPUNIT_ASSERT_MESSAGE("This should be a formula cell.", pFC);
- m_pDoc->GetFormula(1, 4, destSheet, aString);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("Formula cell B5", OUString("=$Sheet1.$D$1"), aString);
- CPPUNIT_ASSERT_EQUAL(4.0, pFC->GetValue());
-
- pFC = m_pDoc->GetFormulaCell(ScAddress(2, 1, destSheet));
- CPPUNIT_ASSERT_MESSAGE("This should be a formula cell C2.", pFC);
- m_pDoc->GetFormula(2, 1, destSheet, aString);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("Formula cell C2", OUString("=$Sheet1.$A$3"), aString);
- CPPUNIT_ASSERT_EQUAL(11.0, pFC->GetValue());
-
- pFC = m_pDoc->GetFormulaCell(ScAddress(2, 2, destSheet));
- CPPUNIT_ASSERT_MESSAGE("This should be a formula cell C3.", pFC);
- m_pDoc->GetFormula(2, 2, destSheet, aString);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("Formula cell C3", OUString("=$Sheet1.$B$3"), aString);
- CPPUNIT_ASSERT_EQUAL(12.0, pFC->GetValue());
-
- pFC = m_pDoc->GetFormulaCell(ScAddress(2, 3, destSheet));
- CPPUNIT_ASSERT_MESSAGE("This should be no formula cell C4.", !pFC);
-
- pFC = m_pDoc->GetFormulaCell(ScAddress(2, 4, destSheet));
- CPPUNIT_ASSERT_MESSAGE("This should be a formula cell.", pFC);
- m_pDoc->GetFormula(2, 4, destSheet, aString);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("Formula cell C5", OUString("=$Sheet1.$D$3"), aString);
- CPPUNIT_ASSERT_EQUAL(14.0, pFC->GetValue());
-
- pFC = m_pDoc->GetFormulaCell(ScAddress(3, 1, destSheet));
- CPPUNIT_ASSERT_MESSAGE("This should be a formula cell D2.", pFC);
- m_pDoc->GetFormula(3, 1, destSheet, aString);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("Formula cell D2", OUString("=$Sheet1.$A$6"), aString);
- CPPUNIT_ASSERT_EQUAL(111.0, pFC->GetValue());
-
- pFC = m_pDoc->GetFormulaCell(ScAddress(3, 2, destSheet));
- CPPUNIT_ASSERT_MESSAGE("This should be a formula cell D3.", pFC);
- m_pDoc->GetFormula(3, 2, destSheet, aString);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("Formula cell D3", OUString("=$Sheet1.$B$6"), aString);
- CPPUNIT_ASSERT_EQUAL(112.0, pFC->GetValue());
-
- pFC = m_pDoc->GetFormulaCell(ScAddress(3, 3, destSheet));
- CPPUNIT_ASSERT_MESSAGE("This should be no formula cell D4.", !pFC);
-
- pFC = m_pDoc->GetFormulaCell(ScAddress(3, 4, destSheet));
- CPPUNIT_ASSERT_MESSAGE("This should be a formula cell.", pFC);
- m_pDoc->GetFormula(3, 4, destSheet, aString);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("Formula cell D5", OUString("=$Sheet1.$D$6"), aString);
- CPPUNIT_ASSERT_EQUAL(114.0, pFC->GetValue());
-
- m_pDoc->DeleteTab(destSheet);
- m_pDoc->DeleteTab(srcSheet);
-}
-
-// tdf#141683
-// InsertDeleteFlags::CONTENTS
-void Test::testCopyPasteSpecialMultiRangeColAsLinkTranspose()
-{
- const SCTAB srcSheet = 0;
- const SCTAB destSheet = 1;
-
- sc::AutoCalcSwitch aACSwitch(*m_pDoc, true); // Turn on auto calc.
-
- m_pDoc->InsertTab(srcSheet, "Sheet1");
- m_pDoc->InsertTab(destSheet, "Sheet2");
-
- m_pDoc->SetValue(0, 0, srcSheet, 1); // A1
- m_pDoc->SetValue(0, 1, srcSheet, 2); // A2
- m_pDoc->SetValue(0, 3, srcSheet, 4); // A4
-
- m_pDoc->SetValue(2, 0, srcSheet, 11); // C1
- m_pDoc->SetValue(2, 1, srcSheet, 12); // C2
- m_pDoc->SetValue(2, 3, srcSheet, 14); // C4
-
- ScMarkData aSrcMark(m_pDoc->GetSheetLimits());
- aSrcMark.SelectOneTable(0);
- ScClipParam aClipParam;
- aClipParam.meDirection = ScClipParam::Column;
- aClipParam.maRanges.push_back(ScRange(0, 0, srcSheet, 0, 3, srcSheet)); // A1:A4
- aClipParam.maRanges.push_back(ScRange(2, 0, srcSheet, 2, 3, srcSheet)); // C1:C4
-
- ScDocument aClipDoc(SCDOCMODE_CLIP);
- m_pDoc->CopyToClip(aClipParam, &aClipDoc, &aSrcMark, false, false);
-
- // transpose
- ScDocumentUniquePtr pTransClip(new ScDocument(SCDOCMODE_CLIP));
- aClipDoc.TransposeClip(pTransClip.get(), InsertDeleteFlags::CONTENTS, true, false);
-
- ScRange aDestRange(1, 1, destSheet, 4, 2, destSheet); // Paste to B2:E3 on Sheet2.
- ScMarkData aMark(m_pDoc->GetSheetLimits());
- aMark.SetMarkArea(aDestRange);
- m_pDoc->CopyMultiRangeFromClip(ScAddress(1, 1, destSheet), aMark, InsertDeleteFlags::CONTENTS,
- pTransClip.get(), true, false /* false fixes tdf#141683 */,
- false, false);
- pTransClip.reset();
-
- OUString aString;
- // Check pasted content to make sure they reference the correct cells.
- ScFormulaCell* pFC = m_pDoc->GetFormulaCell(ScAddress(1, 1, destSheet));
- CPPUNIT_ASSERT_MESSAGE("This should be a formula cell B2.", pFC);
- m_pDoc->GetFormula(1, 1, destSheet, aString);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("Formula cell B2", OUString("=$Sheet1.$A$1"), aString);
- CPPUNIT_ASSERT_EQUAL(1.0, pFC->GetValue());
-
- pFC = m_pDoc->GetFormulaCell(ScAddress(2, 1, destSheet));
- CPPUNIT_ASSERT_MESSAGE("This should be a formula cell C2.", pFC);
- m_pDoc->GetFormula(2, 1, destSheet, aString);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("Formula cell C2", OUString("=$Sheet1.$A$2"), aString);
- CPPUNIT_ASSERT_EQUAL(2.0, pFC->GetValue());
-
- pFC = m_pDoc->GetFormulaCell(ScAddress(3, 1, destSheet));
- CPPUNIT_ASSERT_MESSAGE("This should be no formula cell D2.", !pFC);
-
- pFC = m_pDoc->GetFormulaCell(ScAddress(4, 1, destSheet));
- CPPUNIT_ASSERT_MESSAGE("This should be a formula cell.", pFC);
- m_pDoc->GetFormula(4, 1, destSheet, aString);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("Formula cell E2", OUString("=$Sheet1.$A$4"), aString);
- CPPUNIT_ASSERT_EQUAL(4.0, pFC->GetValue());
-
- pFC = m_pDoc->GetFormulaCell(ScAddress(1, 2, destSheet));
- CPPUNIT_ASSERT_MESSAGE("This should be a formula cell B3.", pFC);
- m_pDoc->GetFormula(1, 2, destSheet, aString);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("Formula cell B3", OUString("=$Sheet1.$C$1"), aString);
- CPPUNIT_ASSERT_EQUAL(11.0, pFC->GetValue());
-
- pFC = m_pDoc->GetFormulaCell(ScAddress(2, 2, destSheet));
- CPPUNIT_ASSERT_MESSAGE("This should be a formula cell C3.", pFC);
- m_pDoc->GetFormula(2, 2, destSheet, aString);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("Formula cell C3", OUString("=$Sheet1.$C$2"), aString);
- CPPUNIT_ASSERT_EQUAL(12.0, pFC->GetValue());
-
- pFC = m_pDoc->GetFormulaCell(ScAddress(3, 2, destSheet));
- CPPUNIT_ASSERT_MESSAGE("This should be no formula cell D3.", !pFC);
-
- pFC = m_pDoc->GetFormulaCell(ScAddress(4, 2, destSheet));
- CPPUNIT_ASSERT_MESSAGE("This should be a formula cell.", pFC);
- m_pDoc->GetFormula(4, 2, destSheet, aString);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("Formula cell E3", OUString("=$Sheet1.$C$4"), aString);
- CPPUNIT_ASSERT_EQUAL(14.0, pFC->GetValue());
-
- m_pDoc->DeleteTab(destSheet);
- m_pDoc->DeleteTab(srcSheet);
-}
-
-// tdf#141683
-// InsertDeleteFlags::CONTENTS
-void Test::testCopyPasteSpecialMultiRangeColAsLinkFilteredTranspose()
-{
- const SCTAB srcSheet = 0;
- const SCTAB destSheet = 1;
-
- sc::AutoCalcSwitch aACSwitch(*m_pDoc, true); // Turn on auto calc.
-
- m_pDoc->InsertTab(srcSheet, "Sheet1");
- m_pDoc->InsertTab(destSheet, "Sheet2");
-
- m_pDoc->SetValue(0, 0, srcSheet, 1); // A1
- m_pDoc->SetValue(0, 1, srcSheet, 2); // A2
- m_pDoc->SetValue(0, 3, srcSheet, 4); // A4
-
- m_pDoc->SetValue(2, 0, srcSheet, 11); // C1
- m_pDoc->SetValue(2, 1, srcSheet, 12); // C2
- m_pDoc->SetValue(2, 3, srcSheet, 14); // C4
-
- // Filter row 1
- ScDBData* pDBData = new ScDBData("TRANSPOSE_TEST_DATA", srcSheet, 0, 0, 0, 3);
- m_pDoc->SetAnonymousDBData(0, std::unique_ptr<ScDBData>(pDBData));
-
- pDBData->SetAutoFilter(true);
- ScRange aRange;
- pDBData->GetArea(aRange);
- m_pDoc->ApplyFlagsTab(aRange.aStart.Col(), aRange.aStart.Row(), aRange.aEnd.Col(),
- aRange.aStart.Row(), aRange.aStart.Tab(), ScMF::Auto);
-
- //create the query param
- ScQueryParam aParam;
- pDBData->GetQueryParam(aParam);
- ScQueryEntry& rEntry = aParam.GetEntry(0);
- rEntry.bDoQuery = true;
- rEntry.nField = 0;
- rEntry.eOp = SC_NOT_EQUAL;
- rEntry.GetQueryItem().mfVal = 2; // value of row A2 -> filtering row 1
- // add queryParam to database range.
- pDBData->SetQueryParam(aParam);
-
- // perform the query.
- m_pDoc->Query(srcSheet, aParam, true);
-
- ScMarkData aSrcMark(m_pDoc->GetSheetLimits());
- aSrcMark.SelectOneTable(0);
- ScClipParam aClipParam;
- aClipParam.meDirection = ScClipParam::Column;
- aClipParam.maRanges.push_back(ScRange(0, 0, srcSheet, 0, 3, srcSheet)); // A1:A4
- aClipParam.maRanges.push_back(ScRange(2, 0, srcSheet, 2, 3, srcSheet)); // C1:C4
-
- ScDocument aClipDoc(SCDOCMODE_CLIP);
- m_pDoc->CopyToClip(aClipParam, &aClipDoc, &aSrcMark, false, false);
-
- // transpose
- ScDocumentUniquePtr pTransClip(new ScDocument(SCDOCMODE_CLIP));
- aClipDoc.TransposeClip(pTransClip.get(), InsertDeleteFlags::CONTENTS, true, false);
-
- ScRange aDestRange(1, 1, destSheet, 4, 2, destSheet); // Paste to B2:E3 on Sheet2.
- ScMarkData aMark(m_pDoc->GetSheetLimits());
- aMark.SetMarkArea(aDestRange);
- m_pDoc->CopyMultiRangeFromClip(ScAddress(1, 1, destSheet), aMark, InsertDeleteFlags::CONTENTS,
- pTransClip.get(), true, false /* false fixes tdf#141683 */,
- false, false);
- pTransClip.reset();
-
- OUString aString;
- // Check pasted content to make sure they reference the correct cells.
- ScFormulaCell* pFC = m_pDoc->GetFormulaCell(ScAddress(1, 1, destSheet));
- CPPUNIT_ASSERT_MESSAGE("This should be a formula cell B2.", pFC);
- m_pDoc->GetFormula(1, 1, destSheet, aString);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("Formula cell B2", OUString("=$Sheet1.$A$1"), aString);
- CPPUNIT_ASSERT_EQUAL(1.0, pFC->GetValue());
-
- pFC = m_pDoc->GetFormulaCell(ScAddress(2, 1, destSheet));
- CPPUNIT_ASSERT_MESSAGE("This should be no formula cell C2.", !pFC);
-
- pFC = m_pDoc->GetFormulaCell(ScAddress(3, 1, destSheet));
- CPPUNIT_ASSERT_MESSAGE("This should be a formula cell.", pFC);
- m_pDoc->GetFormula(3, 1, destSheet, aString);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("Formula cell D2", OUString("=$Sheet1.$A$4"), aString);
- CPPUNIT_ASSERT_EQUAL(4.0, pFC->GetValue());
-
- pFC = m_pDoc->GetFormulaCell(ScAddress(1, 2, destSheet));
- CPPUNIT_ASSERT_MESSAGE("This should be a formula cell B3.", pFC);
- m_pDoc->GetFormula(1, 2, destSheet, aString);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("Formula cell B3", OUString("=$Sheet1.$C$1"), aString);
- CPPUNIT_ASSERT_EQUAL(11.0, pFC->GetValue());
-
- pFC = m_pDoc->GetFormulaCell(ScAddress(2, 2, destSheet));
- CPPUNIT_ASSERT_MESSAGE("This should be no formula cell C3.", !pFC);
-
- pFC = m_pDoc->GetFormulaCell(ScAddress(3, 2, destSheet));
- CPPUNIT_ASSERT_MESSAGE("This should be a formula cell.", pFC);
- m_pDoc->GetFormula(3, 2, destSheet, aString);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("Formula cell D3", OUString("=$Sheet1.$C$4"), aString);
- CPPUNIT_ASSERT_EQUAL(14.0, pFC->GetValue());
-
- m_pDoc->DeleteTab(destSheet);
- m_pDoc->DeleteTab(srcSheet);
-}
-
-// InsertDeleteFlags::ALL
-void Test::testCopyPasteSpecialAllAsLinkTranspose()
-{
- const SCTAB srcSheet = 0;
- const SCTAB destSheet = 1;
-
- sc::AutoCalcSwitch aACSwitch(*m_pDoc, true); // Turn on auto calc.
-
- m_pDoc->InsertTab(srcSheet, "Sheet1");
- m_pDoc->InsertTab(destSheet, "Sheet2");
-
- m_pDoc->SetValue(0, 0, srcSheet, 1); // A1
- m_pDoc->SetValue(0, 1, srcSheet, 2); // A2
- m_pDoc->SetValue(0, 3, srcSheet, 4); // A4
-
- ScRange aSrcRange(0, 0, srcSheet, 0, 3, srcSheet); // Copy A1:A4 to clip.
- ScDocument aClipDoc(SCDOCMODE_CLIP);
- copyToClip(m_pDoc, aSrcRange, &aClipDoc);
-
- // transpose
- ScDocumentUniquePtr pTransClip(new ScDocument(SCDOCMODE_CLIP));
- aClipDoc.TransposeClip(pTransClip.get(), InsertDeleteFlags::ALL, true, false);
-
- ScRange aDestRange(1, 1, destSheet, 4, 1, destSheet); // Paste to B2:E2 on Sheet2.
- ScMarkData aMark(m_pDoc->GetSheetLimits());
- aMark.SetMarkArea(aDestRange);
- m_pDoc->CopyFromClip(aDestRange, aMark, InsertDeleteFlags::ALL, nullptr, pTransClip.get(), true,
- false);
- pTransClip.reset();
-
- OUString aString;
- // Check pasted content to make sure they reference the correct cells.
- ScFormulaCell* pFC = m_pDoc->GetFormulaCell(ScAddress(1, 1, destSheet));
- CPPUNIT_ASSERT_MESSAGE("This should be a formula cell B2.", pFC);
- m_pDoc->GetFormula(1, 1, destSheet, aString);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("Formula cell B2", OUString("=$Sheet1.$A$1"), aString);
- CPPUNIT_ASSERT_EQUAL(1.0, pFC->GetValue());
-
- pFC = m_pDoc->GetFormulaCell(ScAddress(2, 1, destSheet));
- CPPUNIT_ASSERT_MESSAGE("This should be a formula cell.", pFC);
- m_pDoc->GetFormula(2, 1, destSheet, aString);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("Formula cell C2", OUString("=$Sheet1.$A$2"), aString);
- CPPUNIT_ASSERT_EQUAL(2.0, pFC->GetValue());
-
- pFC = m_pDoc->GetFormulaCell(ScAddress(3, 1, destSheet));
- CPPUNIT_ASSERT_MESSAGE("This should be a formula cell.", pFC);
- m_pDoc->GetFormula(3, 1, destSheet, aString);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("Formula cell D2", OUString("=$Sheet1.$A$3"), aString);
- CPPUNIT_ASSERT_EQUAL(0.0, pFC->GetValue());
-
- pFC = m_pDoc->GetFormulaCell(ScAddress(4, 1, destSheet));
- CPPUNIT_ASSERT_MESSAGE("This should be a formula cell.", pFC);
- m_pDoc->GetFormula(4, 1, destSheet, aString);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("Formula cell E2", OUString("=$Sheet1.$A$4"), aString);
- CPPUNIT_ASSERT_EQUAL(4.0, pFC->GetValue());
-
- m_pDoc->DeleteTab(destSheet);
- m_pDoc->DeleteTab(srcSheet);
-}
-
-// InsertDeleteFlags::ALL
-void Test::testCopyPasteSpecialAllAsLinkFilteredTranspose()
-{
- const SCTAB srcSheet = 0;
- const SCTAB destSheet = 1;
-
- sc::AutoCalcSwitch aACSwitch(*m_pDoc, true); // Turn on auto calc.
-
- m_pDoc->InsertTab(srcSheet, "Sheet1");
- m_pDoc->InsertTab(destSheet, "Sheet2");
-
- m_pDoc->SetValue(0, 0, srcSheet, 1); // A1
- m_pDoc->SetValue(0, 1, srcSheet, 2); // A2
- m_pDoc->SetValue(0, 3, srcSheet, 4); // A4
-
- // Filter row 1
- ScDBData* pDBData = new ScDBData("TRANSPOSE_TEST_DATA", srcSheet, 0, 0, 0, 3);
- m_pDoc->SetAnonymousDBData(0, std::unique_ptr<ScDBData>(pDBData));
-
- pDBData->SetAutoFilter(true);
- ScRange aRange;
- pDBData->GetArea(aRange);
- m_pDoc->ApplyFlagsTab(aRange.aStart.Col(), aRange.aStart.Row(), aRange.aEnd.Col(),
- aRange.aStart.Row(), aRange.aStart.Tab(), ScMF::Auto);
-
- //create the query param
- ScQueryParam aParam;
- pDBData->GetQueryParam(aParam);
- ScQueryEntry& rEntry = aParam.GetEntry(0);
- rEntry.bDoQuery = true;
- rEntry.nField = 0;
- rEntry.eOp = SC_NOT_EQUAL;
- rEntry.GetQueryItem().mfVal = 2; // value of row A2 -> filtering row 1
- // add queryParam to database range.
- pDBData->SetQueryParam(aParam);
-
- // perform the query.
- m_pDoc->Query(srcSheet, aParam, true);
-
- // Check precondition for test: row 1 is hidden/filtered
- SCROW nRow1, nRow2;
- SCROW nFilteredRow1, nFilteredRow2;
- bool bHidden = m_pDoc->RowHidden(SCROW(1), srcSheet, &nRow1, &nRow2);
- CPPUNIT_ASSERT_MESSAGE("row 1 should be hidden", bHidden);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("row 1 should be hidden", SCROW(1), nRow1);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("row 1 should be hidden", SCROW(1), nRow2);
- bool bFiltered = m_pDoc->RowFiltered(SCROW(1), srcSheet, &nFilteredRow1, &nFilteredRow2);
- CPPUNIT_ASSERT_MESSAGE("row 1 should be filtered", bFiltered);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("row 1 should be filtered", SCROW(1), nFilteredRow1);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("row 1 should be filtered", SCROW(1), nFilteredRow2);
-
- // Copy A1:A4 to clip.
- ScRange aSrcRange(0, 0, srcSheet, 0, 3, srcSheet);
- ScDocument aClipDoc(SCDOCMODE_CLIP);
- copyToClip(m_pDoc, aSrcRange, &aClipDoc);
-
- // transpose
- ScDocumentUniquePtr pTransClip(new ScDocument(SCDOCMODE_CLIP));
- aClipDoc.TransposeClip(pTransClip.get(), InsertDeleteFlags::ALL, true, false);
-
- ScRange aDestRange(1, 1, destSheet, 3, 1, destSheet); // Paste to B2:D2 on Sheet2.
- ScMarkData aMark(m_pDoc->GetSheetLimits());
- aMark.SetMarkArea(aDestRange);
- m_pDoc->CopyFromClip(aDestRange, aMark, InsertDeleteFlags::ALL, nullptr, pTransClip.get(), true,
- false, false);
- pTransClip.reset();
-
- OUString aString;
- // Check pasted content to make sure they reference the correct cells.
- ScFormulaCell* pFC = m_pDoc->GetFormulaCell(ScAddress(1, 1, destSheet));
- CPPUNIT_ASSERT_MESSAGE("This should be a formula cell B2.", pFC);
- m_pDoc->GetFormula(1, 1, destSheet, aString);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("Formula cell B2", OUString("=$Sheet1.$A$1"), aString);
- CPPUNIT_ASSERT_EQUAL(1.0, pFC->GetValue());
-
- pFC = m_pDoc->GetFormulaCell(ScAddress(2, 1, destSheet));
- CPPUNIT_ASSERT_MESSAGE("This should be a formula cell.", pFC);
- m_pDoc->GetFormula(2, 1, destSheet, aString);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("Formula cell C2", OUString("=$Sheet1.$A$3"), aString);
- CPPUNIT_ASSERT_EQUAL(0.0, pFC->GetValue());
-
- pFC = m_pDoc->GetFormulaCell(ScAddress(3, 1, destSheet));
- CPPUNIT_ASSERT_MESSAGE("This should be a formula cell.", pFC);
- m_pDoc->GetFormula(3, 1, destSheet, aString);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("Formula cell D2", OUString("=$Sheet1.$A$4"), aString);
- CPPUNIT_ASSERT_EQUAL(4.0, pFC->GetValue());
-
- m_pDoc->DeleteTab(destSheet);
- m_pDoc->DeleteTab(srcSheet);
-}
-
-// This method is used to create the different copy/paste special test cases.
-// Principle: Creation of test cases is parameterized, whereas checking uses a minimum of logic
-void Test::executeCopyPasteSpecial(bool bApplyFilter, bool bIncludedFiltered, bool bAsLink,
- bool bTranspose, bool bMultiRangeSelection, bool bSkipEmpty,
- ScClipParam::Direction eDirection = ScClipParam::Column,
- bool bCalcAll = false,
- InsertDeleteFlags aFlags
- = InsertDeleteFlags::CONTENTS | InsertDeleteFlags::ATTRIB)
-{
- ScFormulaOptions aOldOptions, aNewOptions;
- aOldOptions = SC_MOD()->GetFormulaOptions();
- aNewOptions.SetFormulaSepArg(";");
- m_xDocShell->SetFormulaOptions(aNewOptions);
-
- const SCTAB srcSheet = 0;
- m_pDoc->InsertTab(srcSheet, "SrcSheet");
-
- // We need a drawing layer in order to create caption objects.
- m_pDoc->InitDrawLayer(m_xDocShell.get());
- ScFieldEditEngine& rEditEngine = m_pDoc->GetEditEngine();
-
- /*
- | A | B | C | D | E | F |
-
- 1r | 1 B*| =A1+10 *| a | R1 *| =A1+A3+60 | =SUMIF(A1:A4;"<4") |
- 2r | 2 B*| =A2+20 b | b *| R2 *| | *| <- filtered row
- 3r | 3 B*| =D3+30 b*| c *| 5 *| B*| |
- 4 | 4 | =A2+40 b*| d *| R4 *| =A1+A3+70 *| =B$1+$A$3+80 *|
- (5r | 6 | q | r bB*| s bB| t | u |) optional, for row range
- (6 | -1 | -2 | -3 | -4 | -5 | -6 |) optional, for row range
- (7r | -11 | -12 | -13 | -14 | -15 | -16 |) optional, for row range
- (8 | -21 | -22 | -23 | -24 | -25 | -26 |) optional, for row range
-
- \______________/ \________________________________________/
- col range 1 col range 2
-
- * means note attached
- B means background
- b means border
- r means row selected for row range in multi range selection
-
- The following test scenarios can be created:
-
- * Filtered row
- * Transpose
- * All cell types: numbers, strings, formulas, rich text, empty cell
- * Notes at different position
- * Formula references to rows before and after filtered row
- * Double reference (e.g. A1:A3)
- * Relative and absolute references
- * absolute references are not changed by transposing
- * Formatting patterns (e.g. cell backgrounds and borders)
- * Multi range selection with direction column and row
-
- */
- SCCOL nSrcCols = 6;
- SCROW nSrcRows = 4;
- // Add additional row for MultiRange test cases
- if (bMultiRangeSelection)
- {
- nSrcRows = eDirection == ScClipParam::Row ? nSrcRows + 2 : nSrcRows;
- nSrcCols = eDirection == ScClipParam::Column ? nSrcCols + 1 : nSrcCols;
- }
-
- // col A
- m_pDoc->SetValue(0, 0, srcSheet, 1);
- m_pDoc->SetValue(0, 1, srcSheet, 2);
- m_pDoc->SetValue(0, 2, srcSheet, 3);
- m_pDoc->SetValue(0, 3, srcSheet, 4);
- // col B
- m_pDoc->SetString(1, 0, srcSheet, "=A1+10");
- m_pDoc->SetString(1, 1, srcSheet, "=A2+20");
- m_pDoc->SetString(1, 2, srcSheet, "=D3+30");
- m_pDoc->SetString(1, 3, srcSheet, "=A2+40");
- // col C
- m_pDoc->SetString(2, 0, srcSheet, "a");
- m_pDoc->SetString(2, 1, srcSheet, "b");
- m_pDoc->SetString(2, 2, srcSheet, "c");
- m_pDoc->SetString(2, 3, srcSheet, "d");
- // col D
- rEditEngine.SetTextCurrentDefaults("R1");
- m_pDoc->SetEditText(ScAddress(3, 0, srcSheet), rEditEngine.CreateTextObject());
- rEditEngine.SetTextCurrentDefaults("R2");
- m_pDoc->SetEditText(ScAddress(3, 1, srcSheet), rEditEngine.CreateTextObject());
- m_pDoc->SetValue(3, 2, srcSheet, 5);
- rEditEngine.SetTextCurrentDefaults("R4");
- m_pDoc->SetEditText(ScAddress(3, 3, srcSheet), rEditEngine.CreateTextObject());
- // col E
- m_pDoc->SetValue(4, 0, srcSheet, 9);
- m_pDoc->SetString(4, 0, srcSheet, "=A1+A3+60");
- m_pDoc->SetEmptyCell(ScAddress(4, 1, srcSheet));
- m_pDoc->SetEmptyCell(ScAddress(4, 2, srcSheet));
- m_pDoc->SetString(4, 3, srcSheet, "=A1+A3+70");
- // col F
- m_pDoc->SetValue(5, 0, srcSheet, 9);
- m_pDoc->SetString(5, 0, srcSheet, "=SUMIF(A1:A4;\"<4\")");
- m_pDoc->SetEmptyCell(ScAddress(5, 1, srcSheet));
- m_pDoc->SetEmptyCell(ScAddress(5, 2, srcSheet));
- m_pDoc->SetString(5, 3, srcSheet, "=B$1+$A$3+80");
-
- const SfxPoolItem* pItem = nullptr;
-
- // row 4, additional row for MultiRange test case, otherwise not selected
- m_pDoc->SetValue(0, 4, srcSheet, 6);
- m_pDoc->SetString(1, 4, srcSheet, "q");
- m_pDoc->SetString(2, 4, srcSheet, "r");
- m_pDoc->SetString(3, 4, srcSheet, "s");
- m_pDoc->SetString(4, 4, srcSheet, "t");
- m_pDoc->SetString(5, 4, srcSheet, "u");
-
- // row 5, not selected
- m_pDoc->SetValue(0, 5, srcSheet, -1);
- m_pDoc->SetValue(1, 5, srcSheet, -2);
- m_pDoc->SetValue(2, 5, srcSheet, -3);
- m_pDoc->SetValue(3, 5, srcSheet, -4);
- m_pDoc->SetValue(4, 5, srcSheet, -5);
- m_pDoc->SetValue(5, 5, srcSheet, -6);
-
- // row 6, additional row for MultiRange test case, otherwise not selected
- m_pDoc->SetValue(0, 6, srcSheet, -11);
- m_pDoc->SetValue(1, 6, srcSheet, -12);
- m_pDoc->SetValue(2, 6, srcSheet, -13);
- m_pDoc->SetValue(3, 6, srcSheet, -14);
- m_pDoc->SetValue(4, 6, srcSheet, -15);
- m_pDoc->SetValue(5, 6, srcSheet, -16);
-
- // row 7, additional row for MultiRange test case, otherwise not selected
- m_pDoc->SetValue(0, 7, srcSheet, -21);
- m_pDoc->SetValue(1, 7, srcSheet, -22);
- m_pDoc->SetValue(2, 7, srcSheet, -23);
- m_pDoc->SetValue(3, 7, srcSheet, -24);
- m_pDoc->SetValue(4, 7, srcSheet, -25);
- m_pDoc->SetValue(5, 7, srcSheet, -26);
-
- // Col G, not selected
- m_pDoc->SetValue(6, 0, srcSheet, 111);
- m_pDoc->SetValue(6, 1, srcSheet, 112);
- m_pDoc->SetValue(6, 2, srcSheet, 113);
- m_pDoc->SetValue(6, 3, srcSheet, 114);
- m_pDoc->SetValue(6, 4, srcSheet, 115);
- m_pDoc->SetValue(6, 5, srcSheet, 116);
-
- // Col H, additional col for MultiRange test case, otherwise not selected
- m_pDoc->SetValue(7, 0, srcSheet, 121);
- m_pDoc->SetValue(7, 1, srcSheet, 122);
- m_pDoc->SetValue(7, 2, srcSheet, 123);
- m_pDoc->SetValue(7, 3, srcSheet, 124);
- m_pDoc->SetValue(7, 4, srcSheet, 125);
- m_pDoc->SetValue(7, 5, srcSheet, 126);
-
- // Col J, not selected
- m_pDoc->SetValue(8, 0, srcSheet, 131);
- m_pDoc->SetValue(8, 1, srcSheet, 132);
- m_pDoc->SetValue(8, 2, srcSheet, 133);
- m_pDoc->SetValue(8, 3, srcSheet, 134);
- m_pDoc->SetValue(8, 4, srcSheet, 135);
- m_pDoc->SetValue(8, 5, srcSheet, 136);
-
- // add patterns
- ScPatternAttr aCellBlueColor(m_pDoc->GetPool());
- aCellBlueColor.GetItemSet().Put(SvxBrushItem(COL_BLUE, ATTR_BACKGROUND));
- m_pDoc->ApplyPatternAreaTab(0, 0, 0, 2, srcSheet, aCellBlueColor);
-
- // Check pattern precondition
- m_pDoc->GetPattern(ScAddress(0, 0, srcSheet))->GetItemSet().HasItem(ATTR_BACKGROUND, &pItem);
- CPPUNIT_ASSERT_MESSAGE("SrcSheet.A1 has a pattern", pItem);
- CPPUNIT_ASSERT_EQUAL(COL_BLUE, static_cast<const SvxBrushItem*>(pItem)->GetColor());
- m_pDoc->GetPattern(ScAddress(0, 1, srcSheet))->GetItemSet().HasItem(ATTR_BACKGROUND, &pItem);
- CPPUNIT_ASSERT_MESSAGE("SrcSheet.A2 has a pattern", pItem);
- CPPUNIT_ASSERT_EQUAL(COL_BLUE, static_cast<const SvxBrushItem*>(pItem)->GetColor());
- m_pDoc->GetPattern(ScAddress(0, 3, srcSheet))->GetItemSet().HasItem(ATTR_BACKGROUND, &pItem);
- CPPUNIT_ASSERT_MESSAGE("SrcSheet.A4 has no pattern", !pItem);
-
- // row 2 on empty cell
- ScPatternAttr aCellGreenColor(m_pDoc->GetPool());
- aCellGreenColor.GetItemSet().Put(SvxBrushItem(COL_GREEN, ATTR_BACKGROUND));
- m_pDoc->ApplyPatternAreaTab(4, 2, 4, 2, srcSheet, aCellGreenColor);
-
- // row 4 for multi range row selection
- ScPatternAttr aCellRedColor(m_pDoc->GetPool());
- aCellRedColor.GetItemSet().Put(SvxBrushItem(COL_RED, ATTR_BACKGROUND));
- m_pDoc->ApplyPatternAreaTab(2, 4, 3, 4, srcSheet, aCellRedColor);
-
- // add borders
- ::editeng::SvxBorderLine aLine(nullptr, 50, SvxBorderLineStyle::SOLID);
- SvxBoxItem aBorderItem(ATTR_BORDER);
- aBorderItem.SetLine(&aLine, SvxBoxItemLine::LEFT);
- aBorderItem.SetLine(&aLine, SvxBoxItemLine::RIGHT);
- m_pDoc->ApplyAttr(1, 1, srcSheet, aBorderItem);
- m_pDoc->ApplyAttr(1, 2, srcSheet, aBorderItem);
- m_pDoc->ApplyAttr(1, 3, srcSheet, aBorderItem);
- // Check border precondition
- pItem = m_pDoc->GetAttr(ScAddress(1, 0, srcSheet), ATTR_BORDER);
- CPPUNIT_ASSERT_MESSAGE("SrcSheet.B1 has a border", pItem);
- CPPUNIT_ASSERT(!static_cast<const SvxBoxItem*>(pItem)->GetLeft());
- CPPUNIT_ASSERT(!static_cast<const SvxBoxItem*>(pItem)->GetRight());
- CPPUNIT_ASSERT(!static_cast<const SvxBoxItem*>(pItem)->GetTop());
- CPPUNIT_ASSERT(!static_cast<const SvxBoxItem*>(pItem)->GetBottom());
- pItem = m_pDoc->GetAttr(ScAddress(1, 1, srcSheet), ATTR_BORDER);
- CPPUNIT_ASSERT_MESSAGE("SrcSheet.B2 has a border", pItem);
- CPPUNIT_ASSERT(static_cast<const SvxBoxItem*>(pItem)->GetLeft());
- CPPUNIT_ASSERT(static_cast<const SvxBoxItem*>(pItem)->GetRight());
- CPPUNIT_ASSERT(!static_cast<const SvxBoxItem*>(pItem)->GetTop());
- CPPUNIT_ASSERT(!static_cast<const SvxBoxItem*>(pItem)->GetBottom());
- // Check border precondition 2
- m_pDoc->GetPattern(ScAddress(1, 1, srcSheet))->GetItemSet().HasItem(ATTR_BORDER, &pItem);
- CPPUNIT_ASSERT_MESSAGE("SrcSheet.B2 has a border", pItem);
- CPPUNIT_ASSERT(static_cast<const SvxBoxItem*>(pItem)->GetLeft());
- CPPUNIT_ASSERT(static_cast<const SvxBoxItem*>(pItem)->GetRight());
- CPPUNIT_ASSERT(!static_cast<const SvxBoxItem*>(pItem)->GetTop());
- CPPUNIT_ASSERT(!static_cast<const SvxBoxItem*>(pItem)->GetBottom());
- // row 4 for multi range row selection
- ::editeng::SvxBorderLine aDoubleLine(nullptr, 50, SvxBorderLineStyle::DOUBLE);
- SvxBoxItem aDoubleBorderItem(ATTR_BORDER);
- aDoubleBorderItem.SetLine(&aDoubleLine, SvxBoxItemLine::TOP);
- aDoubleBorderItem.SetLine(&aDoubleLine, SvxBoxItemLine::BOTTOM);
- m_pDoc->ApplyAttr(2, 4, srcSheet, aDoubleBorderItem);
- m_pDoc->ApplyAttr(3, 4, srcSheet, aDoubleBorderItem);
-
- // add notes to A1:F4
-
- // add notes row 0
- ScAddress aAdrA1(0, 0, srcSheet);
- ScPostIt* pNoteA1 = m_pDoc->GetOrCreateNote(aAdrA1);
- pNoteA1->SetText(aAdrA1, "Hello world in A1");
- ScAddress aAdrB1(1, 0, srcSheet);
- ScPostIt* pNoteB1 = m_pDoc->GetOrCreateNote(aAdrB1);
- pNoteB1->SetText(aAdrB1, "Hello world in B1");
- // No note on C1
- ScAddress aAdrD1(3, 0, srcSheet);
- ScPostIt* pNoteD1 = m_pDoc->GetOrCreateNote(aAdrD1);
- pNoteD1->SetText(aAdrD1, "Hello world in D1");
- // No note on E1
- // No note on F1
-
- // add notes row 1
- ScAddress aAdrA2(0, 1, srcSheet);
- ScPostIt* pNoteA2 = m_pDoc->GetOrCreateNote(aAdrA2);
- pNoteA2->SetText(aAdrA2, "Hello world in A2");
- // No note on B2
- ScAddress aAdrC2(2, 1, srcSheet);
- ScPostIt* pNoteC2 = m_pDoc->GetOrCreateNote(aAdrC2);
- pNoteC2->SetText(aAdrC2, "Hello world in C2");
- ScAddress aAdrD2(3, 1, srcSheet);
- ScPostIt* pNoteD2 = m_pDoc->GetOrCreateNote(aAdrD2);
- pNoteD2->SetText(aAdrD2, "Hello world in D2");
- ScAddress aAdrE2(4, 2, srcSheet);
- ScPostIt* pNoteE2 = m_pDoc->GetOrCreateNote(aAdrE2);
- pNoteE2->SetText(aAdrE2, "Hello world in E2");
- ScAddress aAdrF2(5, 1, srcSheet);
- ScPostIt* pNoteF2 = m_pDoc->GetOrCreateNote(aAdrF2);
- pNoteF2->SetText(aAdrF2, "Hello world in F2");
-
- // add notes row 2
- ScAddress aAdrA3(0, 2, srcSheet);
- ScPostIt* pNoteA3 = m_pDoc->GetOrCreateNote(aAdrA3);
- pNoteA3->SetText(aAdrA3, "Hello world in A3");
- ScAddress aAdrB3(1, 2, srcSheet);
- ScPostIt* pNoteB3 = m_pDoc->GetOrCreateNote(aAdrB3);
- pNoteB3->SetText(aAdrB3, "Hello world in B3");
- ScAddress aAdrC3(2, 2, srcSheet);
- ScPostIt* pNoteC3 = m_pDoc->GetOrCreateNote(aAdrC3);
- pNoteC3->SetText(aAdrC3, "Hello world in C3");
- ScAddress aAdrD3(3, 2, srcSheet);
- ScPostIt* pNoteD3 = m_pDoc->GetOrCreateNote(aAdrD3);
- pNoteD3->SetText(aAdrD3, "Hello world in D3");
- // No note on E3
- // No note on F3
-
- // add notes row 3
- // No note on A4
- ScAddress aAdrB4(1, 3, srcSheet);
- ScPostIt* pNoteB4 = m_pDoc->GetOrCreateNote(aAdrB4);
- pNoteB4->SetText(aAdrB4, "Hello world in B4");
- ScAddress aAdrC4(2, 3, srcSheet);
- ScPostIt* pNoteC4 = m_pDoc->GetOrCreateNote(aAdrC4);
- pNoteC4->SetText(aAdrC4, "Hello world in C4");
- ScAddress aAdrD4(3, 3, srcSheet);
- ScPostIt* pNoteD4 = m_pDoc->GetOrCreateNote(aAdrD4);
- pNoteD4->SetText(aAdrD4, "Hello world in D4");
- ScAddress aAdrE4(4, 3, srcSheet);
- ScPostIt* pNoteE4 = m_pDoc->GetOrCreateNote(aAdrE4);
- pNoteE4->SetText(aAdrE4, "Hello world in E4");
- ScAddress aAdrF4(5, 3, srcSheet);
- ScPostIt* pNoteF4 = m_pDoc->GetOrCreateNote(aAdrF4);
- pNoteF4->SetText(aAdrF4, "Hello world in F4");
-
- // row 4 for multi range row selection
- ScAddress aAdrC5(2, 4, srcSheet);
- ScPostIt* pNoteC5 = m_pDoc->GetOrCreateNote(aAdrC5);
- pNoteC5->SetText(aAdrC5, "Hello world in C5");
-
- // Filter out row 1
- if (bApplyFilter)
- {
- ScDBData* pDBData
- = new ScDBData("TRANSPOSE_TEST_DATA", srcSheet, 0, 0, nSrcCols - 1, nSrcRows - 1);
- m_pDoc->SetAnonymousDBData(srcSheet, std::unique_ptr<ScDBData>(pDBData));
-
- pDBData->SetAutoFilter(true);
- ScRange aRange;
- pDBData->GetArea(aRange);
- m_pDoc->ApplyFlagsTab(aRange.aStart.Col(), aRange.aStart.Row(), aRange.aEnd.Col(),
- aRange.aStart.Row(), aRange.aStart.Tab(), ScMF::Auto);
-
- //create the query param
- ScQueryParam aParam;
- pDBData->GetQueryParam(aParam);
- ScQueryEntry& rEntry = aParam.GetEntry(0);
- rEntry.bDoQuery = true;
- rEntry.nField = 0;
- rEntry.eOp = SC_NOT_EQUAL;
- rEntry.GetQueryItem().mfVal = 2; // value of row A2 -> filtering row 1
- // add queryParam to database range.
- pDBData->SetQueryParam(aParam);
-
- // perform the query.
- m_pDoc->Query(srcSheet, aParam, true);
-
- // Check precondition for test: row 1 is hidden/filtered
- SCROW nRow1, nRow2;
- SCROW nFilteredRow1, nFilteredRow2;
- bool bHidden = m_pDoc->RowHidden(SCROW(1), srcSheet, &nRow1, &nRow2);
- CPPUNIT_ASSERT_MESSAGE("row 1 should be hidden", bHidden);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("row 1 should be hidden", SCROW(1), nRow1);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("row 1 should be hidden", SCROW(1), nRow2);
- bool bFiltered = m_pDoc->RowFiltered(SCROW(1), srcSheet, &nFilteredRow1, &nFilteredRow2);
- CPPUNIT_ASSERT_MESSAGE("row 1 should be filtered", bFiltered);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("row 1 should be filtered", SCROW(1), nFilteredRow1);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("row 1 should be filtered", SCROW(1), nFilteredRow2);
- }
-
- // create destination sheet
- const SCTAB destSheet = 1;
- m_pDoc->InsertTab(destSheet, "DestSheet");
- // set cells to 1000 to check empty cell behaviour and to detect destination range problems
- for (int i = 0; i < 10; ++i)
- for (int j = 0; j < 10; ++j)
- m_pDoc->SetValue(i, j, destSheet, 1000);
-
- // transpose clipboard, paste on DestSheet
- ScDocument aNewClipDoc(SCDOCMODE_CLIP);
- ScMarkData aDestMark(m_pDoc->GetSheetLimits());
- if (!bMultiRangeSelection)
- {
- ScRange aSrcRange(0, 0, srcSheet, nSrcCols - 1, nSrcRows - 1, srcSheet);
- copyToClip(m_pDoc, aSrcRange, &aNewClipDoc);
-
- // ScDocument::TransposeClip() and ScDocument::CopyFromClip() calls
- // analog to ScViewFunc::PasteFromClip()
- if (bTranspose)
- {
- ScDocumentUniquePtr pTransClip(new ScDocument(SCDOCMODE_CLIP));
- aNewClipDoc.TransposeClip(pTransClip.get(), aFlags, bAsLink, bIncludedFiltered);
- ScRange aDestRange(3, 1, destSheet, 3 + nSrcRows - 1, 1 + nSrcCols - 1,
- destSheet); //target: D2:F6
- aDestMark.SetMarkArea(aDestRange);
- m_pDoc->CopyFromClip(aDestRange, aDestMark, aFlags, nullptr, pTransClip.get(), true,
- bAsLink, bIncludedFiltered, bSkipEmpty);
- pTransClip.reset();
- }
- else
- {
- ScRange aDestRange(3, 1, destSheet, 3 + nSrcCols - 1, 1 + nSrcRows - 1,
- destSheet); //target: D2:I5
- aDestMark.SetMarkArea(aDestRange);
- m_pDoc->CopyFromClip(aDestRange, aDestMark, aFlags, nullptr, &aNewClipDoc, true,
- bAsLink, bIncludedFiltered, bSkipEmpty);
- }
- }
- else
- {
- ScMarkData aSrcMark(m_pDoc->GetSheetLimits());
- aSrcMark.SelectOneTable(0);
- ScClipParam aClipParam;
- aClipParam.meDirection = eDirection;
- if (eDirection == ScClipParam::Column)
- {
- aClipParam.maRanges.push_back(ScRange(0, 0, srcSheet, 1, 3, srcSheet)); // A1:B4
- aClipParam.maRanges.push_back(ScRange(3, 0, srcSheet, 5, 3, srcSheet)); // D1:F4
- aClipParam.maRanges.push_back(ScRange(7, 0, srcSheet, 7, 3, srcSheet)); // H1:H4
- }
- else if (eDirection == ScClipParam::Row)
- {
- aClipParam.maRanges.push_back(ScRange(0, 0, srcSheet, 5, 2, srcSheet)); // A1:F3
- aClipParam.maRanges.push_back(ScRange(0, 4, srcSheet, 5, 4, srcSheet)); // A5:F5
- aClipParam.maRanges.push_back(ScRange(0, 6, srcSheet, 5, 6, srcSheet)); // A7:F7
- }
- CPPUNIT_ASSERT(aClipParam.isMultiRange());
- m_pDoc->CopyToClip(aClipParam, &aNewClipDoc, &aSrcMark, false, false);
-
- // ScDocument::TransposeClip() and ScDocument::CopyMultiRangeFromClip() calls
- // analog to ScViewFunc::PasteFromClipToMultiRanges()
- if (bTranspose)
- {
- printRange(m_pDoc, aClipParam.getWholeRange(), "Src range");
- ScDocumentUniquePtr pTransClip(new ScDocument(SCDOCMODE_CLIP));
- aNewClipDoc.TransposeClip(pTransClip.get(), aFlags, bAsLink, bIncludedFiltered);
- ScRange aDestRange(3, 1, destSheet, 3 + nSrcRows - 1, 1 + nSrcCols - 1 - 1,
- destSheet); //target col: D2:G6, target row: D2:H6
- aDestMark.SetMarkArea(aDestRange);
- printRange(&aNewClipDoc, ScRange(0, 0, 0, nSrcCols, nSrcRows, 0),
- "Base doc (&aNewClipDoc)");
- printRange(pTransClip.get(), ScRange(0, 0, 0, nSrcCols, nSrcRows, 0),
- "Transposed filtered clipdoc (pTransClip.get())");
- m_pDoc->CopyMultiRangeFromClip(ScAddress(3, 1, destSheet), aDestMark, aFlags,
- pTransClip.get(), true, bAsLink && !bTranspose,
- bIncludedFiltered, bSkipEmpty);
- pTransClip.reset();
- printRange(m_pDoc, aDestRange, "Transposed dest sheet");
- }
- else
- {
- ScRange aDestRange(3, 1, destSheet, 3 + nSrcCols - 1 - 1, 1 + nSrcRows - 1,
- destSheet); //target col: D2:I5, target row: D2:I6
- aDestMark.SetMarkArea(aDestRange);
- m_pDoc->CopyMultiRangeFromClip(ScAddress(3, 1, destSheet), aDestMark, aFlags,
- &aNewClipDoc, true, bAsLink && !bTranspose,
- bIncludedFiltered, bSkipEmpty);
- }
- }
- if (bCalcAll)
- m_pDoc->CalcAll();
-
- // restore formula options back to default
- m_xDocShell->SetFormulaOptions(aOldOptions);
-}
-
-void Test::testCopyPasteSpecial()
-{
- executeCopyPasteSpecial(false, false, false, false, false, false);
- checkCopyPasteSpecial(false);
-}
-
-void Test::testCopyPasteSpecialFiltered()
-{
- executeCopyPasteSpecial(true, false, false, false, false, false);
- checkCopyPasteSpecialFiltered(false);
-}
-
-void Test::testCopyPasteSpecialIncludeFiltered()
-{
- // For bIncludeFiltered=true, the non-filtered outcome is expected
- executeCopyPasteSpecial(false, true, false, false, false, false);
- checkCopyPasteSpecial(false);
-}
-
-void Test::testCopyPasteSpecialFilteredIncludeFiltered()
-{
- // For bIncludeFiltered=true, the non-filtered outcome is expected
- executeCopyPasteSpecial(true, true, false, false, false, false);
- checkCopyPasteSpecial(false);
-}
-
-// similar to Test::testCopyPasteTranspose(), but this test is more complex
-void Test::testCopyPasteSpecialTranspose()
-{
- executeCopyPasteSpecial(false, false, false, true, false, false);
- checkCopyPasteSpecialTranspose(false);
-}
-
-// tdf#107348
-void Test::testCopyPasteSpecialFilteredTranspose()
-{
- executeCopyPasteSpecial(true, false, false, true, false, false);
- checkCopyPasteSpecialFilteredTranspose(false);
-}
-
-// tdf#107348
-void Test::testCopyPasteSpecialTransposeIncludeFiltered()
-{
- // For bIncludeFiltered=true, the non-filtered outcome is expected
- executeCopyPasteSpecial(true, true, false, true, false, false);
- checkCopyPasteSpecialTranspose(false);
-}
-
-void Test::testCopyPasteSpecialMultiRangeCol()
-{
- executeCopyPasteSpecial(false, false, false, false, true, false, ScClipParam::Column);
- checkCopyPasteSpecialMultiRangeCol(false);
-}
-
-void Test::testCopyPasteSpecialMultiRangeColIncludeFiltered()
-{
- // For bIncludeFiltered=true, the non-filtered outcome is expected
- executeCopyPasteSpecial(false, true, false, false, true, false, ScClipParam::Column);
- checkCopyPasteSpecialMultiRangeCol(false);
-}
-
-// tdf#45958
-void Test::testCopyPasteSpecialMultiRangeColFiltered()
-{
- executeCopyPasteSpecial(true, false, false, false, true, false, ScClipParam::Column);
- checkCopyPasteSpecialMultiRangeColFiltered(false);
-}
-
-// tdf#45958
-void Test::testCopyPasteSpecialMultiRangeColFilteredIncludeFiltered()
-{
- // For bIncludeFiltered=true, the non-filtered outcome is expected
- executeCopyPasteSpecial(true, true, false, false, true, false, ScClipParam::Column);
- checkCopyPasteSpecialMultiRangeCol(false);
-}
-
-void Test::testCopyPasteSpecialMultiRangeColTranspose()
-{
- executeCopyPasteSpecial(false, false, false, true, true, false, ScClipParam::Column);
- checkCopyPasteSpecialMultiRangeColTranspose(false);
-}
-
-// tdf#45958, tdf#107348
-void Test::testCopyPasteSpecialMultiRangeColFilteredTranspose()
-{
- executeCopyPasteSpecial(true, false, false, true, true, false, ScClipParam::Column);
- checkCopyPasteSpecialMultiRangeColFilteredTranspose(false);
-}
-
-// tdf#45958, tdf#107348
-void Test::testCopyPasteSpecialMultiRangeColFilteredIncludeFilteredTranspose()
-{
- // For bIncludeFiltered=true, the non-filtered outcome is expected
- executeCopyPasteSpecial(true, true, false, true, true, false, ScClipParam::Column);
- checkCopyPasteSpecialMultiRangeColTranspose(false);
-}
-
-void Test::testCopyPasteSpecialMultiRangeRow()
-{
- executeCopyPasteSpecial(false, false, false, false, true, false, ScClipParam::Row);
- checkCopyPasteSpecialMultiRangeRow(false);
-}
-
-void Test::testCopyPasteSpecialMultiRangeRowIncludeFiltered()
-{
- // For bIncludeFiltered=true, the non-filtered outcome is expected
- executeCopyPasteSpecial(false, true, false, false, true, false, ScClipParam::Row);
- checkCopyPasteSpecialMultiRangeRow(false);
-}
-
-// tdf#45958
-void Test::testCopyPasteSpecialMultiRangeRowFiltered()
-{
- executeCopyPasteSpecial(true, false, false, false, true, false, ScClipParam::Row);
- checkCopyPasteSpecialMultiRangeRowFiltered(false);
-}
-
-// tdf#45958
-void Test::testCopyPasteSpecialMultiRangeRowFilteredIncludeFiltered()
-{
- // For bIncludeFiltered=true, the non-filtered outcome is expected
- executeCopyPasteSpecial(true, true, false, false, true, false, ScClipParam::Row);
- checkCopyPasteSpecialMultiRangeRow(false);
-}
-
-void Test::testCopyPasteSpecialMultiRangeRowTranspose()
-{
- executeCopyPasteSpecial(false, false, false, true, true, false, ScClipParam::Row, true);
- checkCopyPasteSpecialMultiRangeRowTranspose(false);
-}
-
-// tdf#45958, tdf#107348
-void Test::testCopyPasteSpecialMultiRangeRowFilteredTranspose()
-{
- executeCopyPasteSpecial(true, false, false, true, true, false, ScClipParam::Row, true);
- checkCopyPasteSpecialMultiRangeRowFilteredTranspose(false);
-}
-
-// tdf#45958, tdf#107348
-void Test::testCopyPasteSpecialMultiRangeRowFilteredIncludeFilteredTranspose()
-{
- // For bIncludeFiltered=true, the non-filtered outcome is expected
- executeCopyPasteSpecial(true, true, false, true, true, false, ScClipParam::Row, true);
- checkCopyPasteSpecialMultiRangeRowTranspose(false);
-}
-
-void Test::testCopyPasteSpecialSkipEmpty()
-{
- executeCopyPasteSpecial(false, false, false, false, false, true);
- checkCopyPasteSpecial(true);
-}
-
-void Test::testCopyPasteSpecialSkipEmptyFiltered()
-{
- executeCopyPasteSpecial(true, false, false, false, false, true);
- checkCopyPasteSpecialFiltered(true);
-}
-
-void Test::testCopyPasteSpecialSkipEmptyIncludeFiltered()
-{
- // For bIncludeFiltered=true, the non-filtered outcome is expected
- executeCopyPasteSpecial(false, true, false, false, false, true);
- checkCopyPasteSpecial(true);
-}
-
-void Test::testCopyPasteSpecialSkipEmptyFilteredIncludeFiltered()
-{
- // For bIncludeFiltered=true, the non-filtered outcome is expected
- executeCopyPasteSpecial(true, true, false, false, false, true);
- checkCopyPasteSpecial(true);
-}
-
-// similar to Test::testCopyPasteTranspose(), but this test is more complex
-void Test::testCopyPasteSpecialSkipEmptyTranspose()
-{
- executeCopyPasteSpecial(false, false, false, true, false, true);
- checkCopyPasteSpecialTranspose(true);
-}
-
-// tdf#107348
-void Test::testCopyPasteSpecialSkipEmptyFilteredTranspose()
-{
- executeCopyPasteSpecial(true, false, false, true, false, true);
- checkCopyPasteSpecialFilteredTranspose(true);
-}
-
-// tdf#107348
-void Test::testCopyPasteSpecialSkipEmptyTransposeIncludeFiltered()
-{
- // For bIncludeFiltered=true, the non-filtered outcome is expected
- executeCopyPasteSpecial(true, true, false, true, false, true);
- checkCopyPasteSpecialTranspose(true);
-}
-
-void Test::testCopyPasteSpecialSkipEmptyMultiRangeCol()
-{
- executeCopyPasteSpecial(false, false, false, false, true, true, ScClipParam::Column);
- checkCopyPasteSpecialMultiRangeCol(true);
-}
-
-void Test::testCopyPasteSpecialSkipEmptyMultiRangeColIncludeFiltered()
-{
- // For bIncludeFiltered=true, the non-filtered outcome is expected
- executeCopyPasteSpecial(false, true, false, false, true, true, ScClipParam::Column);
- checkCopyPasteSpecialMultiRangeCol(true);
-}
-
-// tdf#45958
-void Test::testCopyPasteSpecialSkipEmptyMultiRangeColFiltered()
-{
- executeCopyPasteSpecial(true, false, false, false, true, true, ScClipParam::Column);
- checkCopyPasteSpecialMultiRangeColFiltered(true);
-}
-
-// tdf#45958
-void Test::testCopyPasteSpecialSkipEmptyMultiRangeColFilteredIncludeFiltered()
-{
- // For bIncludeFiltered=true, the non-filtered outcome is expected
- executeCopyPasteSpecial(true, true, false, false, true, true, ScClipParam::Column);
- checkCopyPasteSpecialMultiRangeCol(true);
-}
-
-void Test::testCopyPasteSpecialSkipEmptyMultiRangeColTranspose()
-{
- executeCopyPasteSpecial(false, false, false, true, true, true, ScClipParam::Column);
- checkCopyPasteSpecialMultiRangeColTranspose(true);
-}
-
-// tdf#45958, tdf#107348
-void Test::testCopyPasteSpecialSkipEmptyMultiRangeColFilteredTranspose()
-{
- // For bIncludeFiltered=true, the non-filtered outcome is expected
- executeCopyPasteSpecial(true, false, false, true, true, true, ScClipParam::Column);
- checkCopyPasteSpecialMultiRangeColFilteredTranspose(true);
-}
-
-// tdf#45958, tdf#107348
-void Test::testCopyPasteSpecialSkipEmptyMultiRangeColFilteredIncludeFilteredTranspose()
-{
- // For bIncludeFiltered=true, the non-filtered outcome is expected
- executeCopyPasteSpecial(true, true, false, true, true, true, ScClipParam::Column);
- checkCopyPasteSpecialMultiRangeColTranspose(true);
-}
-
-void Test::testCopyPasteSpecialSkipEmptyMultiRangeRow()
-{
- executeCopyPasteSpecial(false, false, false, false, true, true, ScClipParam::Row);
- checkCopyPasteSpecialMultiRangeRow(true);
-}
-
-void Test::testCopyPasteSpecialSkipEmptyMultiRangeRowIncludeFiltered()
-{
- // For bIncludeFiltered=true, the non-filtered outcome is expected
- executeCopyPasteSpecial(false, true, false, false, true, true, ScClipParam::Row);
- checkCopyPasteSpecialMultiRangeRow(true);
-}
-
-// tdf#45958
-void Test::testCopyPasteSpecialSkipEmptyMultiRangeRowFiltered()
-{
- executeCopyPasteSpecial(true, false, false, false, true, true, ScClipParam::Row);
- checkCopyPasteSpecialMultiRangeRowFiltered(true);
-}
-
-// tdf#45958
-void Test::testCopyPasteSpecialSkipEmptyMultiRangeRowFilteredIncludeFiltered()
-{
- // For bIncludeFiltered=true, the non-filtered outcome is expected
- executeCopyPasteSpecial(true, true, false, false, true, true, ScClipParam::Row);
- checkCopyPasteSpecialMultiRangeRow(true);
-}
-
-void Test::testCopyPasteSpecialSkipEmptyMultiRangeRowTranspose()
-{
- executeCopyPasteSpecial(false, false, false, true, true, true, ScClipParam::Row, true);
- checkCopyPasteSpecialMultiRangeRowTranspose(true);
-}
-
-// tdf#45958, tdf#107348
-void Test::testCopyPasteSpecialSkipEmptyMultiRangeRowFilteredTranspose()
-{
- executeCopyPasteSpecial(true, false, false, true, true, true, ScClipParam::Row, true);
- checkCopyPasteSpecialMultiRangeRowFilteredTranspose(true);
-}
-
-// tdf#45958, tdf#107348
-void Test::testCopyPasteSpecialSkipEmptyMultiRangeRowFilteredIncludeFilteredTranspose()
-{
- // For bIncludeFiltered=true, the non-filtered outcome is expected
- executeCopyPasteSpecial(true, true, false, true, true, true, ScClipParam::Row, true);
- checkCopyPasteSpecialMultiRangeRowTranspose(true);
-}
-
-// Base check, nothing filtered, nothing transposed
-void Test::checkCopyPasteSpecial(bool bSkipEmpty)
-{
- const SCTAB srcSheet = 0;
- const SCTAB destSheet = 1;
-
- ScFormulaOptions aOldOptions, aNewOptions;
- aOldOptions = SC_MOD()->GetFormulaOptions();
- aNewOptions.SetFormulaSepArg(";");
- m_xDocShell->SetFormulaOptions(aNewOptions);
-
- /*
- | D | E | F | G | H | I |
-
- 2 | 1 B*| =D2+10 *| a | R1 *| =D2+D4+60 | =SUMIF(D2:D5;"<4") |
- 3 | 2 B*| =D3+20 b | b *| R2 *| | *|
... etc. - the rest is truncated
More information about the Libreoffice-commits
mailing list