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

Kohei Yoshida kohei.yoshida at collabora.com
Sat Jul 12 19:10:05 PDT 2014


 sc/qa/unit/ucalc.cxx               |   68 +++++++++++++++++++++++++++++++++++++
 sc/qa/unit/ucalc.hxx               |    2 +
 sc/source/ui/docshell/dbdocfun.cxx |    4 +-
 3 files changed, 73 insertions(+), 1 deletion(-)

New commits:
commit 47a82452b5040cd712ffafb7d153fd18940ee1af
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Sat Jul 12 22:09:10 2014 -0400

    Add another test case.
    
    Change-Id: I1664bc3faf44abc978391d0f97820c468f4419b0

diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index b10bf54..7708427 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -5058,6 +5058,38 @@ void Test::testSortSingleRow()
     bool bSorted = aFunc.Sort(0, aSortData, true, true, true);
     CPPUNIT_ASSERT(bSorted);
 
+    // Another test case - single row horizontal sort with header column.
+    clearSheet(m_pDoc, 0);
+
+    // A1:G1
+    m_pDoc->SetString(ScAddress(0,0,0), "Header");
+    m_pDoc->SetValue(ScAddress(1,0,0),  1.0);
+    m_pDoc->SetValue(ScAddress(2,0,0), 10.0);
+    m_pDoc->SetValue(ScAddress(3,0,0),  3.0);
+    m_pDoc->SetValue(ScAddress(4,0,0),  9.0);
+    m_pDoc->SetValue(ScAddress(5,0,0), 12.0);
+    m_pDoc->SetValue(ScAddress(6,0,0),  2.0);
+
+    // Define A1:G1 as sheet-local anonymous database range.
+    m_pDoc->SetAnonymousDBData(
+        0, new ScDBData(STR_DB_LOCAL_NONAME, 0, 0, 0, 6, 0, false, true));
+
+    // Update the sort data.
+    aSortData.nCol1 = 0;
+    aSortData.nCol2 = 6;
+    aSortData.bByRow = false;
+    bSorted = aFunc.Sort(0, aSortData, true, true, true);
+    CPPUNIT_ASSERT(bSorted);
+
+    // Check the result.
+    CPPUNIT_ASSERT_EQUAL(OUString("Header"), m_pDoc->GetString(ScAddress(0,0,0)));
+    CPPUNIT_ASSERT_EQUAL( 1.0, m_pDoc->GetValue(ScAddress(1,0,0)));
+    CPPUNIT_ASSERT_EQUAL( 2.0, m_pDoc->GetValue(ScAddress(2,0,0)));
+    CPPUNIT_ASSERT_EQUAL( 3.0, m_pDoc->GetValue(ScAddress(3,0,0)));
+    CPPUNIT_ASSERT_EQUAL( 9.0, m_pDoc->GetValue(ScAddress(4,0,0)));
+    CPPUNIT_ASSERT_EQUAL(10.0, m_pDoc->GetValue(ScAddress(5,0,0)));
+    CPPUNIT_ASSERT_EQUAL(12.0, m_pDoc->GetValue(ScAddress(6,0,0)));
+
     m_pDoc->DeleteTab(0);
 }
 
commit 9e5b1eb98b8e97b184f8c6876b154f47b6e0730d
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Sat Jul 12 21:55:59 2014 -0400

    fdo#80462: Write test for this.
    
    Change-Id: Icdc83c0264fd76239e8c8772c207cc22ce969a76

diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index af272a5..b10bf54 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -5025,6 +5025,42 @@ void Test::testSortHorizontal()
     m_pDoc->DeleteTab(0);
 }
 
+void Test::testSortSingleRow()
+{
+    // This test case is from fdo#80462.
+
+    m_pDoc->InsertTab(0, "Test");
+
+    // Sort range consists of only one row.
+    m_pDoc->SetString(ScAddress(0,0,0), "X");
+    m_pDoc->SetString(ScAddress(1,0,0), "Y");
+
+    // Define A1:B1 as sheet-local anonymous database range.
+    m_pDoc->SetAnonymousDBData(
+        0, new ScDBData(STR_DB_LOCAL_NONAME, 0, 0, 0, 1, 0));
+
+    // Sort A1:B1 horizontally, ascending by row 1.
+    ScDBDocFunc aFunc(getDocShell());
+
+    ScSortParam aSortData;
+    aSortData.nCol1 = 0;
+    aSortData.nCol2 = 1;
+    aSortData.nRow1 = 0;
+    aSortData.nRow2 = 0;
+    aSortData.bHasHeader = true;
+    aSortData.bByRow = true;
+    aSortData.bIncludePattern = true;
+    aSortData.maKeyState[0].bDoSort = true;
+    aSortData.maKeyState[0].nField = 0;
+    aSortData.maKeyState[0].bAscending = true;
+
+    // Do the sorting.  This should not crash.
+    bool bSorted = aFunc.Sort(0, aSortData, true, true, true);
+    CPPUNIT_ASSERT(bSorted);
+
+    m_pDoc->DeleteTab(0);
+}
+
 void Test::testSortInFormulaGroup()
 {
     static struct {
diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx
index 2df47c0..c592e69 100644
--- a/sc/qa/unit/ucalc.hxx
+++ b/sc/qa/unit/ucalc.hxx
@@ -341,6 +341,7 @@ public:
     void testFindAreaPosColRight();
     void testSort();
     void testSortHorizontal();
+    void testSortSingleRow();
     void testSortWithFormulaRefs();
     void testSortWithStrings();
     void testSortInFormulaGroup();
@@ -509,6 +510,7 @@ public:
     CPPUNIT_TEST(testFindAreaPosColRight);
     CPPUNIT_TEST(testSort);
     CPPUNIT_TEST(testSortHorizontal);
+    CPPUNIT_TEST(testSortSingleRow);
     CPPUNIT_TEST(testSortWithFormulaRefs);
     CPPUNIT_TEST(testSortWithStrings);
     CPPUNIT_TEST(testSortInFormulaGroup);
commit 5902dcf0995cdd0a6c1dbd1f9c21b0b2b3f5609f
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Sat Jul 12 21:46:13 2014 -0400

    fdo#80462: Don't always increment the start row position.
    
    Sometimes someone might attempt to sort only a single row.
    
    Change-Id: Ie29d4cf7ec0bd3a5c945997083368b6ef6074268

diff --git a/sc/source/ui/docshell/dbdocfun.cxx b/sc/source/ui/docshell/dbdocfun.cxx
index 1c7ad53..94578f2 100644
--- a/sc/source/ui/docshell/dbdocfun.cxx
+++ b/sc/source/ui/docshell/dbdocfun.cxx
@@ -489,7 +489,9 @@ bool ScDBDocFunc::Sort( SCTAB nTab, const ScSortParam& rSortParam,
 
     WaitObject aWait( rDocShell.GetActiveDialogParent() );
 
-    SCROW nStartRow = aLocalParam.nRow1 + (aLocalParam.bHasHeader ? 1 : 0);
+    SCROW nStartRow = aLocalParam.nRow1;
+    if (aLocalParam.bByRow && aLocalParam.bHasHeader && nStartRow < aLocalParam.nRow2)
+        ++nStartRow;
 
     // Calculate the script types for all cells in the sort range beforehand.
     // This will speed up the row height adjustment that takes place after the


More information about the Libreoffice-commits mailing list