diff options
author | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-05-20 17:01:12 -0400 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-05-20 20:19:29 -0400 |
commit | 1cd034088c8e0d44ba51b3b3b247a05ad309e0ed (patch) | |
tree | 08275b82068a92b80fa5d35ff06308c546798992 | |
parent | 42855ef3a1c78f8dbd10ab8cad6d3cdbc7e8fc9e (diff) |
Another performance scenario. Pasting of cells interspersed with empty ones.
Change-Id: Ia03af65dc1daf13e1228cacc20ce931839305ab8
-rw-r--r-- | sc/qa/unit/ucalc.cxx | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx index 3506a29e8c78..62d6546486af 100644 --- a/sc/qa/unit/ucalc.cxx +++ b/sc/qa/unit/ucalc.cxx @@ -535,6 +535,9 @@ void Test::testPerf() CPPUNIT_ASSERT_MESSAGE("Column B shouldn't have any broadcasters.", !m_pDoc->HasBroadcaster(0,1)); { + // Measure the performance of repeat-pasting a single cell to a large + // cell range, undoing it, and redoing it. + ScAddress aPos(0,0,0); m_pDoc->SetString(aPos, "test"); ScMarkData aMark; @@ -610,6 +613,95 @@ void Test::testPerf() CPPUNIT_ASSERT_EQUAL(m_pDoc->GetString(aPos), m_pDoc->GetString(aPasteRange.aEnd)); } + clearRange(m_pDoc, ScRange(0,0,0,1,MAXROW,0)); // Clear columns A:B. + CPPUNIT_ASSERT_MESSAGE("Column A shouldn't have any broadcasters.", !m_pDoc->HasBroadcaster(0,0)); + CPPUNIT_ASSERT_MESSAGE("Column B shouldn't have any broadcasters.", !m_pDoc->HasBroadcaster(0,1)); + + { + // Measure the performance of repeat-pasting 2 adjacent cells to a + // large cell range, undoing it, and redoing it. The bottom one of + // the two source cells is empty. + + ScRange aSrcRange(0,0,0,0,1,0); // A1:A2 + + ScAddress aPos(0,0,0); + m_pDoc->SetValue(aPos, 12); + ScMarkData aMark; + aMark.SetMarkArea(aSrcRange); + + // Copy to clipboard. + ScDocument aClipDoc(SCDOCMODE_CLIP); + ScClipParam aParam(aSrcRange, false); + m_pDoc->CopyToClip(aParam, &aClipDoc, &aMark); + CPPUNIT_ASSERT_EQUAL(m_pDoc->GetString(aPos), aClipDoc.GetString(aPos)); + + ScDocument* pUndoDoc = new ScDocument(SCDOCMODE_UNDO); + pUndoDoc->InitUndo(m_pDoc, 0, 0); + m_pDoc->CopyToDocument(aSrcRange, IDF_CONTENTS, false, pUndoDoc, &aMark); + + // Paste it to A3:A100001, and measure its duration. + ScRange aPasteRange(0,2,0,0,100000,0); + aMark.SetMarkArea(aPasteRange); + + { + MeasureTimeSwitch aTime(diff); + m_pDoc->CopyFromClip(aPasteRange, aMark, IDF_CONTENTS, pUndoDoc, &aClipDoc); + } + if (diff >= 1.0) + { + std::ostringstream os; + os << "Pasting A1:A2 to A3:A100001 took " << diff << " seconds. It should be instant."; + CPPUNIT_FAIL(os.str().c_str()); + } + + ScDocument* pRedoDoc = new ScDocument(SCDOCMODE_UNDO); + pRedoDoc->InitUndo(m_pDoc, 0, 0); + m_pDoc->CopyToDocument(aPasteRange, IDF_CONTENTS, false, pRedoDoc, &aMark); + + // Create an undo object for this. + ScRefUndoData* pRefUndoData = new ScRefUndoData(m_pDoc); + ScUndoPaste aUndo(&(*m_xDocShRef), aPasteRange, aMark, pUndoDoc, pRedoDoc, IDF_CONTENTS, pRefUndoData); + + // Make sure it did what it's supposed to do. + CPPUNIT_ASSERT_EQUAL(m_pDoc->GetString(aPos), m_pDoc->GetString(aPasteRange.aStart)); + CPPUNIT_ASSERT_EQUAL(m_pDoc->GetString(aPos), m_pDoc->GetString(aPasteRange.aEnd)); + ScAddress aTmp = aPasteRange.aStart; + aTmp.IncRow(); + CPPUNIT_ASSERT_EQUAL(CELLTYPE_NONE, m_pDoc->GetCellType(aTmp)); + + { + MeasureTimeSwitch aTime(diff); + aUndo.Undo(); + } + if (diff >= 1.0) + { + std::ostringstream os; + os << "Undoing took " << diff << " seconds. It should be instant."; + CPPUNIT_FAIL(os.str().c_str()); + } + + // Make sure it's really undone. + CPPUNIT_ASSERT_EQUAL(CELLTYPE_VALUE, m_pDoc->GetCellType(aPos)); + CPPUNIT_ASSERT_EQUAL(CELLTYPE_NONE, m_pDoc->GetCellType(aPasteRange.aStart)); + CPPUNIT_ASSERT_EQUAL(CELLTYPE_NONE, m_pDoc->GetCellType(aPasteRange.aEnd)); + + // Now redo. + { + MeasureTimeSwitch aTime(diff); + aUndo.Redo(); + } + if (diff >= 1.0) + { + std::ostringstream os; + os << "Redoing took " << diff << " seconds. It should be instant."; + CPPUNIT_FAIL(os.str().c_str()); + } + + // Make sure it's really redone. + CPPUNIT_ASSERT_EQUAL(m_pDoc->GetString(aPos), m_pDoc->GetString(aPasteRange.aStart)); + CPPUNIT_ASSERT_EQUAL(m_pDoc->GetString(aPos), m_pDoc->GetString(aPasteRange.aEnd)); + } + m_pDoc->DeleteTab(0); } |