[Libreoffice-commits] core.git: Branch 'private/kohei/sort-ref-update' - sc/qa

Kohei Yoshida kohei.yoshida at collabora.com
Sun Jul 13 17:41:57 PDT 2014


 sc/qa/unit/ucalc.cxx |   86 +++++++++++++++++++++++++++++++++++++++++++++++++++
 sc/qa/unit/ucalc.hxx |    2 +
 2 files changed, 88 insertions(+)

New commits:
commit 5ed9dea7fa3df2bebcda116734dc8643eb35be18
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Sun Jul 13 20:41:18 2014 -0400

    fdo#81309: Write another test.
    
    Value and formula cells within the same sorted column.
    
    Change-Id: I62f1ee73c118a938d224bb11d2fbbc9ea386fbd3

diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index f597c39..e8aa49c 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -5529,6 +5529,92 @@ void Test::testSortRefUpdate2()
     m_pDoc->DeleteTab(0);
 }
 
+void Test::testSortRefUpdate3()
+{
+    sc::AutoCalcSwitch aACSwitch(*m_pDoc, true); // turn auto calc on.
+    m_pDoc->InsertTab(0, "Sort");
+
+    const char* pData[] = {
+        "Header",
+        "1",
+        "=A2+10",
+        "2",
+        "=A4+10",
+        "=A2+A4",
+        0 // terminator
+    };
+
+    for (SCROW i = 0; pData[i]; ++i)
+        m_pDoc->SetString(ScAddress(0,i,0), OUString::createFromAscii(pData[i]));
+
+    // Check the initial values.
+    CPPUNIT_ASSERT_EQUAL(OUString("Header"), m_pDoc->GetString(ScAddress(0,0,0)));
+    CPPUNIT_ASSERT_EQUAL( 1.0, m_pDoc->GetValue(ScAddress(0,1,0)));
+    CPPUNIT_ASSERT_EQUAL(11.0, m_pDoc->GetValue(ScAddress(0,2,0)));
+    CPPUNIT_ASSERT_EQUAL( 2.0, m_pDoc->GetValue(ScAddress(0,3,0)));
+    CPPUNIT_ASSERT_EQUAL(12.0, m_pDoc->GetValue(ScAddress(0,4,0)));
+    CPPUNIT_ASSERT_EQUAL( 3.0, m_pDoc->GetValue(ScAddress(0,5,0)));
+
+    ScDBDocFunc aFunc(getDocShell());
+
+    // Sort A1:A6.
+    m_pDoc->SetAnonymousDBData(
+        0, new ScDBData(STR_DB_LOCAL_NONAME, 0, 0, 0, 0, 5));
+
+    // Sort A1:B5 by column A (with a row header).
+    ScSortParam aSortData;
+    aSortData.nCol1 = 0;
+    aSortData.nCol2 = 0;
+    aSortData.nRow1 = 0;
+    aSortData.nRow2 = 5;
+    aSortData.bHasHeader = true;
+    aSortData.maKeyState[0].bDoSort = true;
+    aSortData.maKeyState[0].nField = 0;
+    aSortData.maKeyState[0].bAscending = true;
+    bool bSorted = aFunc.Sort(0, aSortData, true, true, true);
+    CPPUNIT_ASSERT(bSorted);
+
+    // Check the sorted values.
+    m_pDoc->CalcAll();
+    CPPUNIT_ASSERT_EQUAL(OUString("Header"), m_pDoc->GetString(ScAddress(0,0,0)));
+    CPPUNIT_ASSERT_EQUAL( 1.0, m_pDoc->GetValue(ScAddress(0,1,0)));
+    CPPUNIT_ASSERT_EQUAL( 2.0, m_pDoc->GetValue(ScAddress(0,2,0)));
+    CPPUNIT_ASSERT_EQUAL( 3.0, m_pDoc->GetValue(ScAddress(0,3,0)));
+    CPPUNIT_ASSERT_EQUAL(11.0, m_pDoc->GetValue(ScAddress(0,4,0)));
+    CPPUNIT_ASSERT_EQUAL(12.0, m_pDoc->GetValue(ScAddress(0,5,0)));
+
+    // Make sure the formula cells have been adjusted correctly.
+    if (!checkFormula(*m_pDoc, ScAddress(0,3,0), "A2+A3"))
+        CPPUNIT_FAIL("Wrong formula in A4.");
+    if (!checkFormula(*m_pDoc, ScAddress(0,4,0), "A2+10"))
+        CPPUNIT_FAIL("Wrong formula in A5.");
+    if (!checkFormula(*m_pDoc, ScAddress(0,5,0), "A3+10"))
+        CPPUNIT_FAIL("Wrong formula in A6.");
+
+    // Undo and check the result.
+    SfxUndoManager* pUndoMgr = m_pDoc->GetUndoManager();
+    pUndoMgr->Undo();
+    m_pDoc->CalcAll();
+    CPPUNIT_ASSERT_EQUAL(OUString("Header"), m_pDoc->GetString(ScAddress(0,0,0)));
+    CPPUNIT_ASSERT_EQUAL( 1.0, m_pDoc->GetValue(ScAddress(0,1,0)));
+    CPPUNIT_ASSERT_EQUAL(11.0, m_pDoc->GetValue(ScAddress(0,2,0)));
+    CPPUNIT_ASSERT_EQUAL( 2.0, m_pDoc->GetValue(ScAddress(0,3,0)));
+    CPPUNIT_ASSERT_EQUAL(12.0, m_pDoc->GetValue(ScAddress(0,4,0)));
+    CPPUNIT_ASSERT_EQUAL( 3.0, m_pDoc->GetValue(ScAddress(0,5,0)));
+
+    // Redo and check the result.
+    pUndoMgr->Redo();
+    m_pDoc->CalcAll();
+    CPPUNIT_ASSERT_EQUAL(OUString("Header"), m_pDoc->GetString(ScAddress(0,0,0)));
+    CPPUNIT_ASSERT_EQUAL( 1.0, m_pDoc->GetValue(ScAddress(0,1,0)));
+    CPPUNIT_ASSERT_EQUAL( 2.0, m_pDoc->GetValue(ScAddress(0,2,0)));
+    CPPUNIT_ASSERT_EQUAL( 3.0, m_pDoc->GetValue(ScAddress(0,3,0)));
+    CPPUNIT_ASSERT_EQUAL(11.0, m_pDoc->GetValue(ScAddress(0,4,0)));
+    CPPUNIT_ASSERT_EQUAL(12.0, m_pDoc->GetValue(ScAddress(0,5,0)));
+
+    m_pDoc->DeleteTab(0);
+}
+
 void Test::testShiftCells()
 {
     m_pDoc->InsertTab(0, "foo");
diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx
index 5b75a17..7725f30 100644
--- a/sc/qa/unit/ucalc.hxx
+++ b/sc/qa/unit/ucalc.hxx
@@ -348,6 +348,7 @@ public:
     void testSortWithCellFormats();
     void testSortRefUpdate();
     void testSortRefUpdate2();
+    void testSortRefUpdate3();
     void testShiftCells();
 
     void testNoteBasic();
@@ -519,6 +520,7 @@ public:
     CPPUNIT_TEST(testSortWithCellFormats);
     CPPUNIT_TEST(testSortRefUpdate);
     CPPUNIT_TEST(testSortRefUpdate2);
+    CPPUNIT_TEST(testSortRefUpdate3);
     CPPUNIT_TEST(testShiftCells);
     CPPUNIT_TEST(testNoteBasic);
     CPPUNIT_TEST(testNoteDeleteRow);


More information about the Libreoffice-commits mailing list