/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * 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/.
*/
// Cannot be moved to qahelper since ScDocument::CopyToDocument() is not SC_DLLPUBLIC /** Executes the same steps for undo as ScViewFunc::PasteFromClip(). */ void TestCopyPaste::prepareUndoBeforePaste(bool bCut, ScDocumentUniquePtr& pPasteUndoDoc,
std::unique_ptr<ScDocument>& pPasteRefUndoDoc, const ScMarkData& rDestMark, const ScRange& rDestRange,
std::unique_ptr<ScRefUndoData>& pUndoData)
{
InsertDeleteFlags nUndoFlags = InsertDeleteFlags::CONTENTS;
SCTAB nTabCount = m_pDoc->GetTableCount();
pPasteUndoDoc.reset(new ScDocument(SCDOCMODE_UNDO));
pPasteUndoDoc->InitUndoSelected(*m_pDoc, rDestMark, false, false); // all sheets - CopyToDocument skips those that don't exist in pUndoDoc
m_pDoc->CopyToDocument(rDestRange.aStart.Col(), rDestRange.aStart.Row(), 0,
rDestRange.aEnd.Col(), rDestRange.aEnd.Row(), nTabCount - 1, nUndoFlags, false, *pPasteUndoDoc);
if (bCut)
{ // save changed references
pPasteRefUndoDoc.reset(new ScDocument(SCDOCMODE_UNDO));
pPasteRefUndoDoc->InitUndo(*m_pDoc, 0, nTabCount - 1);
pUndoData.reset(new ScRefUndoData(*m_pDoc));
}
}
// Cannot be moved to qahelper since ScDocument::CopyToDocument() is not SC_DLLPUBLIC /** Executes the same steps for undo as ScViewFunc::PasteFromClip(). */ void TestCopyPaste::prepareUndoAfterPaste(ScDocumentUniquePtr& pPasteUndoDoc,
std::unique_ptr<ScDocument>& pPasteRefUndoDoc, const ScMarkData& rDestMark, const ScRange& rDestRange,
std::unique_ptr<ScRefUndoData>& pUndoData,
std::unique_ptr<ScUndoPaste>& pUndoPaste, bool bTranspose, bool bAsLink, bool bSkipEmpty, ScPasteFunc nFunction,
InsCellCmd eMoveMode)
{
InsertDeleteFlags nUndoFlags = InsertDeleteFlags::CONTENTS;
SCTAB nTabCount = m_pDoc->GetTableCount();
ScDocumentUniquePtr pPasteRedoDoc; // copy redo data after appearance of the first undo // don't create Redo-Doc without RefUndoDoc
if (pPasteRefUndoDoc)
{
pPasteRedoDoc.reset(new ScDocument(SCDOCMODE_UNDO));
pPasteRedoDoc->InitUndo(*m_pDoc, rDestRange.aStart.Tab(), rDestRange.aEnd.Tab(), false, false);
// add notes to A1:C1
setNote(0, 0, 0, u"Hello world in A1"_ustr); // empty cell content
setNote(1, 0, 0, u"Hello world in B1"_ustr); // formula cell content
setNote(2, 0, 0, u"Hello world in C1"_ustr); // string cell content
//check values after copying
OUString aString = m_pDoc->GetFormula(1, 1, 1);
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(u"LOCAL1"_ustr);
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(u"LOCAL2"_ustr);
CPPUNIT_ASSERT_MESSAGE("local2 should not be copied", !pLocal2);
pLocal3 = m_pDoc->GetRangeName(1)->findByUpperName(u"LOCAL3"_ustr);
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(u"LOCAL4"_ustr);
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(u"LOCAL5"_ustr);
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(0, 1, 1));
CPPUNIT_ASSERT_MESSAGE("There should be a note on Sheet2.B2", m_pDoc->HasNote(1, 1, 1));
CPPUNIT_ASSERT_MESSAGE("There should be a note on Sheet2.C2", m_pDoc->HasNote(2, 1, 1));
CPPUNIT_ASSERT_EQUAL_MESSAGE( "Note content on Sheet1.A1 not copied to Sheet2.A2, empty cell content",
m_pDoc->GetNote(0, 0, 0)->GetText(), m_pDoc->GetNote(0, 1, 1)->GetText());
CPPUNIT_ASSERT_EQUAL_MESSAGE( "Note content on Sheet1.B1 not copied to Sheet2.B2, formula cell content",
m_pDoc->GetNote(1, 0, 0)->GetText(), m_pDoc->GetNote(1, 1, 1)->GetText());
CPPUNIT_ASSERT_EQUAL_MESSAGE( "Note content on Sheet1.C1 not copied to Sheet2.C2, string cell content",
m_pDoc->GetNote(2, 0, 0)->GetText(), m_pDoc->GetNote(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", 0, fValue);
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(0, 1, 1));
CPPUNIT_ASSERT_MESSAGE("after undo, note on B2 should be removed", !m_pDoc->HasNote(1, 1, 1));
CPPUNIT_ASSERT_MESSAGE("after undo, note on C2 should be removed", !m_pDoc->HasNote(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", u"test"_ustr, aString);
aString = m_pDoc->GetFormula(1, 1, 1);
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(0, 1, 1));
CPPUNIT_ASSERT_MESSAGE("After Redo, there should be a note on Sheet2.B2",
m_pDoc->HasNote(1, 1, 1));
CPPUNIT_ASSERT_MESSAGE("After Redo, there should be a note on Sheet2.C2",
m_pDoc->HasNote(2, 1, 1));
CPPUNIT_ASSERT_EQUAL_MESSAGE("After Redo, note again on Sheet2.A2, empty cell content",
getNote(0, 0, 0), getNote(0, 1, 1));
CPPUNIT_ASSERT_EQUAL_MESSAGE("After Redo, note again on Sheet2.B2, formula cell content",
getNote(1, 0, 0), getNote(1, 1, 1));
CPPUNIT_ASSERT_EQUAL_MESSAGE("After Redo, note again on Sheet2.C2, string cell content",
getNote(2, 0, 0), getNote(2, 1, 1));
// 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);
// The global2 range must not have changed.
pGlobal2 = m_pDoc->GetRangeName()->findByUpperName(u"GLOBAL2"_ustr);
CPPUNIT_ASSERT_MESSAGE("GLOBAL2 name not found", pGlobal2);
OUString aSymbol = pGlobal2->GetSymbol();
CPPUNIT_ASSERT_EQUAL_MESSAGE("GLOBAL2 named range changed", aGlobal2Symbol, aSymbol);
m_pDoc->DeleteTab(1);
m_pDoc->DeleteTab(0);
}
CPPUNIT_TEST_FIXTURE(TestCopyPaste, testCopyPasteAsLink)
{
sc::AutoCalcSwitch aACSwitch(*m_pDoc, true); // Turn on auto calc.
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);
// 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());
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());
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());
// add notes to A1:C1
setNote(0, 0, 0, u"Hello world in A1"_ustr); // numerical cell content
setNote(1, 0, 0, u"Hello world in B1"_ustr); // formula cell content
setNote(2, 0, 0, u"Hello world in C1"_ustr); // string cell content
// transpose clipboard, paste and check on Sheet2
m_pDoc->InsertTab(1, u"Sheet2"_ustr);
//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", u"test"_ustr, 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);
aString = m_pDoc->GetFormula(3, 2, 1);
CPPUNIT_ASSERT_EQUAL_MESSAGE("transposed formula should point on Sheet2.D2", u"=D2+1"_ustr,
aString);
// check notes after transposed copy/paste
CPPUNIT_ASSERT_MESSAGE("There should be a note on Sheet2.D2", m_pDoc->HasNote(3, 1, 1));
CPPUNIT_ASSERT_MESSAGE("There should be a note on Sheet2.D3", m_pDoc->HasNote(3, 2, 1));
CPPUNIT_ASSERT_MESSAGE("There should be a note on Sheet2.D4", m_pDoc->HasNote(3, 3, 1));
CPPUNIT_ASSERT_EQUAL_MESSAGE("Content of cell note on Sheet2.D2", getNote(0, 0, 0),
getNote(3, 1, 1));
CPPUNIT_ASSERT_EQUAL_MESSAGE("Content of cell note on Sheet2.D3", getNote(1, 0, 0),
getNote(3, 2, 1));
CPPUNIT_ASSERT_EQUAL_MESSAGE("Content of cell note on Sheet2.D4", getNote(2, 0, 0),
getNote(3, 3, 1));
// 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);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Cell B2", u"=$Sheet1.$A$1"_ustr,
m_pDoc->GetFormula(1, 1, destSheet));
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);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Cell C2", u"=$Sheet1.$A$2"_ustr,
m_pDoc->GetFormula(2, 1, destSheet));
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);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Cell E2", u"=$Sheet1.$A$4"_ustr,
m_pDoc->GetFormula(4, 1, destSheet));
CPPUNIT_ASSERT_EQUAL(4.0, pFC->GetValue());
//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);
// 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);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Cell B2", u"=$Sheet1.$A$1"_ustr,
m_pDoc->GetFormula(1, 1, destSheet));
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);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Cell D2", u"=$Sheet1.$A$4"_ustr,
m_pDoc->GetFormula(3, 1, destSheet));
CPPUNIT_ASSERT_EQUAL(4.0, pFC->GetValue());
// 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);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Cell B2", u"=$Sheet1.$A$1"_ustr,
m_pDoc->GetFormula(1, 1, destSheet));
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);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Cell B3", u"=$Sheet1.$B$1"_ustr,
m_pDoc->GetFormula(1, 2, destSheet));
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);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Cell B5", u"=$Sheet1.$D$1"_ustr,
m_pDoc->GetFormula(1, 4, destSheet));
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);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Cell C2", u"=$Sheet1.$A$3"_ustr,
m_pDoc->GetFormula(2, 1, destSheet));
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);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Cell C3", u"=$Sheet1.$B$3"_ustr,
m_pDoc->GetFormula(2, 2, destSheet));
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);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Cell C5", u"=$Sheet1.$D$3"_ustr,
m_pDoc->GetFormula(2, 4, destSheet));
CPPUNIT_ASSERT_EQUAL(14.0, pFC->GetValue());
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
// 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);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Cell B2", u"=$Sheet1.$A$1"_ustr,
m_pDoc->GetFormula(1, 1, destSheet));
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);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Cell B3", u"=$Sheet1.$B$1"_ustr,
m_pDoc->GetFormula(1, 2, destSheet));
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);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Cell B5", u"=$Sheet1.$D$1"_ustr,
m_pDoc->GetFormula(1, 4, destSheet));
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);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Cell C2", u"=$Sheet1.$A$3"_ustr,
m_pDoc->GetFormula(2, 1, destSheet));
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);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Cell C3", u"=$Sheet1.$B$3"_ustr,
m_pDoc->GetFormula(2, 2, destSheet));
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);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Cell C5", u"=$Sheet1.$D$3"_ustr,
m_pDoc->GetFormula(2, 4, destSheet));
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);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Cell D2", u"=$Sheet1.$A$6"_ustr,
m_pDoc->GetFormula(3, 1, destSheet));
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);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Cell D3", u"=$Sheet1.$B$6"_ustr,
m_pDoc->GetFormula(3, 2, destSheet));
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);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Cell D5", u"=$Sheet1.$D$6"_ustr,
m_pDoc->GetFormula(3, 4, destSheet));
CPPUNIT_ASSERT_EQUAL(114.0, pFC->GetValue());
// 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);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Cell B2", u"=$Sheet1.$A$1"_ustr,
m_pDoc->GetFormula(1, 1, destSheet));
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);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Cell C2", u"=$Sheet1.$A$2"_ustr,
m_pDoc->GetFormula(2, 1, destSheet));
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);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Cell E2", u"=$Sheet1.$A$4"_ustr,
m_pDoc->GetFormula(4, 1, destSheet));
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);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Cell B3", u"=$Sheet1.$C$1"_ustr,
m_pDoc->GetFormula(1, 2, destSheet));
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);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Cell C3", u"=$Sheet1.$C$2"_ustr,
m_pDoc->GetFormula(2, 2, destSheet));
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);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Cell E3", u"=$Sheet1.$C$4"_ustr,
m_pDoc->GetFormula(4, 2, destSheet));
CPPUNIT_ASSERT_EQUAL(14.0, pFC->GetValue());
// 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);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Cell B2", u"=$Sheet1.$A$1"_ustr,
m_pDoc->GetFormula(1, 1, destSheet));
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);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Cell D2", u"=$Sheet1.$A$4"_ustr,
m_pDoc->GetFormula(3, 1, destSheet));
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);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Cell B3", u"=$Sheet1.$C$1"_ustr,
m_pDoc->GetFormula(1, 2, destSheet));
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);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Cell D3", u"=$Sheet1.$C$4"_ustr,
m_pDoc->GetFormula(3, 2, destSheet));
CPPUNIT_ASSERT_EQUAL(14.0, pFC->GetValue());
// 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);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Cell B2", u"=$Sheet1.$A$1"_ustr,
m_pDoc->GetFormula(1, 1, destSheet));
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);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Cell C2", u"=$Sheet1.$A$2"_ustr,
m_pDoc->GetFormula(2, 1, destSheet));
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);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Cell D2", u"=$Sheet1.$A$3"_ustr,
m_pDoc->GetFormula(3, 1, destSheet));
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);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Cell E2", u"=$Sheet1.$A$4"_ustr,
m_pDoc->GetFormula(4, 1, destSheet));
CPPUNIT_ASSERT_EQUAL(4.0, pFC->GetValue());
//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);
// 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);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Cell B2", u"=$Sheet1.$A$1"_ustr,
m_pDoc->GetFormula(1, 1, destSheet));
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);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Cell C2", u"=$Sheet1.$A$3"_ustr,
m_pDoc->GetFormula(2, 1, destSheet));
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);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Cell D2", u"=$Sheet1.$A$4"_ustr,
m_pDoc->GetFormula(3, 1, destSheet));
CPPUNIT_ASSERT_EQUAL(4.0, pFC->GetValue());
// 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 TestCopyPaste::executeCopyPasteSpecial(const SCTAB srcSheet, const SCTAB destSheet, bool bApplyFilter, bool bIncludedFiltered, bool bAsLink, bool bTranspose, bool bMultiRangeSelection,
--> --------------------
--> maximum size reached
--> --------------------
Messung V0.5
¤ Dauer der Verarbeitung: 0.34 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.