[Libreoffice-commits] core.git: sc/qa

Kohei Yoshida kohei.yoshida at collabora.com
Fri Mar 24 12:22:20 UTC 2017


 sc/qa/unit/ucalc.cxx         |   47 ++++++++++++++++++++++++++++
 sc/qa/unit/ucalc.hxx         |    5 +++
 sc/qa/unit/ucalc_formula.cxx |   71 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 123 insertions(+)

New commits:
commit 1ac30cf245454c6f7a777699436722a94a9e349c
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Thu Mar 23 21:17:31 2017 -0400

    tdf#105908: add test for this.
    
    Change-Id: I553c18107d469bd7dce37d673f958126455b4393
    Reviewed-on: https://gerrit.libreoffice.org/35608
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Kohei Yoshida <libreoffice at kohei.us>

diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index 8a0b48508017..0dcd60215edc 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -6765,6 +6765,53 @@ void Test::checkPrecisionAsShown( OUString& rCode, double fValue, double fExpect
     CPPUNIT_ASSERT_EQUAL_MESSAGE( aMessage.getStr(), fExpectedRoundVal, fRoundValue );
 }
 
+ScRange Test::insertRangeData(
+    ScDocument* pDoc, const ScAddress& rPos, const std::vector<std::vector<const char*>>& rData )
+{
+    if (rData.empty())
+        return ScRange(ScAddress::INITIALIZE_INVALID);
+
+    ScAddress aPos = rPos;
+
+    SCCOL nColWidth = 1;
+    for (const std::vector<const char*>& rRow : rData)
+        nColWidth = std::max<SCCOL>(nColWidth, rRow.size());
+
+    ScRange aRange(aPos);
+    aRange.aEnd.IncCol(nColWidth-1);
+    aRange.aEnd.IncRow(rData.size()-1);
+
+    clearRange(pDoc, aRange);
+
+    for (const std::vector<const char*>& rRow : rData)
+    {
+        aPos.SetCol(rPos.Col());
+
+        for (const char* pStr : rRow)
+        {
+            if (!pStr)
+            {
+                aPos.IncCol();
+                continue;
+            }
+
+            OUString aStr(pStr, strlen(pStr), RTL_TEXTENCODING_UTF8);
+
+            ScSetStringParam aParam; // Leave default.
+            aParam.meStartListening = sc::NoListening;
+            pDoc->SetString(aPos, aStr, &aParam);
+
+            aPos.IncCol();
+        }
+
+        aPos.IncRow();
+    }
+
+    pDoc->StartAllListeners(aRange);
+    printRange(pDoc, aRange, "Range data content");
+    return aRange;
+}
+
 void Test::testPrecisionAsShown()
 {
     m_pDoc->InsertTab(0, "Test");
diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx
index 4d3558a71393..d616f8cb5b9b 100644
--- a/sc/qa/unit/ucalc.hxx
+++ b/sc/qa/unit/ucalc.hxx
@@ -62,6 +62,9 @@ public:
 
     void checkPrecisionAsShown( OUString& rCode, double fValue, double fExpectedRoundVal );
 
+    ScRange insertRangeData(
+        ScDocument* pDoc, const ScAddress& rPos, const std::vector<std::vector<const char*>>& rData );
+
     template<size_t Size>
     static ScRange insertRangeData(
         ScDocument* pDoc, const ScAddress& rPos, const char* aData[][Size], size_t nRowCount )
@@ -151,6 +154,7 @@ public:
     void testFormulaRefUpdateMoveToSheet();
     void testFormulaRefUpdateDeleteContent();
     void testFormulaRefUpdateDeleteAndShiftLeft();
+    void testFormulaRefUpdateDeleteAndShiftLeft2();
     void testFormulaRefUpdateDeleteAndShiftUp();
     void testFormulaRefUpdateName();
     void testFormulaRefUpdateNameMove();
@@ -550,6 +554,7 @@ public:
     CPPUNIT_TEST(testFormulaRefUpdateMoveToSheet);
     CPPUNIT_TEST(testFormulaRefUpdateDeleteContent);
     CPPUNIT_TEST(testFormulaRefUpdateDeleteAndShiftLeft);
+    CPPUNIT_TEST(testFormulaRefUpdateDeleteAndShiftLeft2);
     CPPUNIT_TEST(testFormulaRefUpdateDeleteAndShiftUp);
     CPPUNIT_TEST(testFormulaRefUpdateName);
     CPPUNIT_TEST(testFormulaRefUpdateNameMove);
diff --git a/sc/qa/unit/ucalc_formula.cxx b/sc/qa/unit/ucalc_formula.cxx
index ea3eea69cc96..c7f47709eca1 100644
--- a/sc/qa/unit/ucalc_formula.cxx
+++ b/sc/qa/unit/ucalc_formula.cxx
@@ -2447,6 +2447,77 @@ void Test::testFormulaRefUpdateDeleteAndShiftLeft()
     m_pDoc->DeleteTab(0);
 }
 
+void Test::testFormulaRefUpdateDeleteAndShiftLeft2()
+{
+    sc::AutoCalcSwitch aACSwitch(*m_pDoc, true); // turn auto calc on.
+
+    m_pDoc->InsertTab(0, "Test");
+
+    std::vector<std::vector<const char*>> aData = {
+        { "1", "=COUNT($A$1:$A$4)", "=COUNT(A1)" },
+        { "2", "=COUNT($A$1:$A$4)", "=COUNT(A2)" },
+        { "3", "=COUNT($A$1:$A$4)", "=COUNT(A3)" },
+        { "4", "=COUNT($A$1:$A$4)", "=COUNT(A4)" },
+    };
+
+    insertRangeData(m_pDoc, ScAddress(), aData);
+
+    auto funcCheckOriginal = [&]()
+    {
+        CPPUNIT_ASSERT_EQUAL(1.0, m_pDoc->GetValue(ScAddress(0,0,0))); // A1
+        CPPUNIT_ASSERT_EQUAL(2.0, m_pDoc->GetValue(ScAddress(0,1,0))); // A2
+        CPPUNIT_ASSERT_EQUAL(3.0, m_pDoc->GetValue(ScAddress(0,2,0))); // A3
+        CPPUNIT_ASSERT_EQUAL(4.0, m_pDoc->GetValue(ScAddress(0,3,0))); // A4
+
+        CPPUNIT_ASSERT_EQUAL(4.0, m_pDoc->GetValue(ScAddress(1,0,0))); // B1
+        CPPUNIT_ASSERT_EQUAL(4.0, m_pDoc->GetValue(ScAddress(1,1,0))); // B2
+        CPPUNIT_ASSERT_EQUAL(4.0, m_pDoc->GetValue(ScAddress(1,2,0))); // B3
+        CPPUNIT_ASSERT_EQUAL(4.0, m_pDoc->GetValue(ScAddress(1,3,0))); // B4
+
+        CPPUNIT_ASSERT_EQUAL(1.0, m_pDoc->GetValue(ScAddress(2,0,0))); // C1
+        CPPUNIT_ASSERT_EQUAL(1.0, m_pDoc->GetValue(ScAddress(2,1,0))); // C2
+        CPPUNIT_ASSERT_EQUAL(1.0, m_pDoc->GetValue(ScAddress(2,2,0))); // C3
+        CPPUNIT_ASSERT_EQUAL(1.0, m_pDoc->GetValue(ScAddress(2,3,0))); // C4
+    };
+
+    auto funcCheckDeleted = [&]()
+    {
+        CPPUNIT_ASSERT_EQUAL(OUString("#REF!"), m_pDoc->GetString(ScAddress(0,0,0))); // A1
+        CPPUNIT_ASSERT_EQUAL(OUString("#REF!"), m_pDoc->GetString(ScAddress(0,1,0))); // A2
+        CPPUNIT_ASSERT_EQUAL(OUString("#REF!"), m_pDoc->GetString(ScAddress(0,2,0))); // A3
+        CPPUNIT_ASSERT_EQUAL(OUString("#REF!"), m_pDoc->GetString(ScAddress(0,3,0))); // A4
+
+        CPPUNIT_ASSERT_EQUAL(OUString("#REF!"), m_pDoc->GetString(ScAddress(1,0,0))); // B1
+        CPPUNIT_ASSERT_EQUAL(OUString("#REF!"), m_pDoc->GetString(ScAddress(1,1,0))); // B2
+        CPPUNIT_ASSERT_EQUAL(OUString("#REF!"), m_pDoc->GetString(ScAddress(1,2,0))); // B3
+        CPPUNIT_ASSERT_EQUAL(OUString("#REF!"), m_pDoc->GetString(ScAddress(1,3,0))); // B4
+    };
+
+    funcCheckOriginal();
+
+    // Delete Column A.
+    ScMarkData aMark;
+    aMark.SelectOneTable(0);
+    ScDocFunc& rFunc = getDocShell().GetDocFunc();
+    bool bDeleted = rFunc.DeleteCells(ScRange(0,0,0,0,MAXROW,0), &aMark, DEL_CELLSLEFT, true);
+    CPPUNIT_ASSERT(bDeleted);
+
+    funcCheckDeleted();
+
+    // Undo and check.
+    SfxUndoManager* pUndo = m_pDoc->GetUndoManager();
+    CPPUNIT_ASSERT(pUndo);
+
+    pUndo->Undo();
+    funcCheckOriginal();
+
+    // Redo and check.
+    pUndo->Redo();
+    funcCheckDeleted();
+
+    m_pDoc->DeleteTab(0);
+}
+
 void Test::testFormulaRefUpdateDeleteAndShiftUp()
 {
     sc::AutoCalcSwitch aACSwitch(*m_pDoc, true); // turn auto calc on.


More information about the Libreoffice-commits mailing list