[Libreoffice-commits] core.git: Branch 'feature/formula-core-rework' - sc/qa

Kohei Yoshida kohei.yoshida at gmail.com
Mon May 20 13:59:39 PDT 2013


 sc/qa/unit/ucalc.cxx |   92 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 92 insertions(+)

New commits:
commit a66ac2a1bb0e5063e42651bff9c81e20c81a7941
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Mon May 20 17:01:12 2013 -0400

    Another performance scenario. Pasting of cells interspersed with empty ones.
    
    Change-Id: Ia03af65dc1daf13e1228cacc20ce931839305ab8

diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index 3506a29..62d6546 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);
 }
 


More information about the Libreoffice-commits mailing list