[Libreoffice-commits] core.git: Branch 'private/kohei/calc-sort-fix' - sc/qa sc/source

Kohei Yoshida kohei.yoshida at collabora.com
Wed Apr 23 07:40:46 PDT 2014


 sc/qa/unit/data/ods/shared-formula/sort-crash.ods |binary
 sc/qa/unit/filters-test.cxx                       |   54 ++++++++++++++++++++++
 sc/source/ui/inc/dbdocfun.hxx                     |    4 -
 3 files changed, 56 insertions(+), 2 deletions(-)

New commits:
commit 0a038c4992e68814ee4dd46f87f464f91b538a48
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Wed Apr 23 10:06:53 2014 -0400

    fdo#76607: Writer unit test for this.
    
    Change-Id: Ia69283a9998c233784c0da0f7a65f58a6c102596

diff --git a/sc/qa/unit/data/ods/shared-formula/sort-crash.ods b/sc/qa/unit/data/ods/shared-formula/sort-crash.ods
new file mode 100644
index 0000000..21f3d2e
Binary files /dev/null and b/sc/qa/unit/data/ods/shared-formula/sort-crash.ods differ
diff --git a/sc/qa/unit/filters-test.cxx b/sc/qa/unit/filters-test.cxx
index 43692b5..bad9269 100644
--- a/sc/qa/unit/filters-test.cxx
+++ b/sc/qa/unit/filters-test.cxx
@@ -32,6 +32,9 @@
 #include "userdat.hxx"
 #include "formulacell.hxx"
 #include "tabprotection.hxx"
+#include <dbdocfun.hxx>
+#include <globalnames.hxx>
+#include <dbdata.hxx>
 
 #include <svx/svdpage.hxx>
 
@@ -72,6 +75,7 @@ public:
     void testLegacyCellAnchoredRotatedShape();
     void testEnhancedProtectionXLS();
     void testEnhancedProtectionXLSX();
+    void testSortWithSharedFormulasODS();
 
     CPPUNIT_TEST_SUITE(ScFiltersTest);
     CPPUNIT_TEST(testCVEs);
@@ -87,6 +91,7 @@ public:
     CPPUNIT_TEST(testLegacyCellAnchoredRotatedShape);
     CPPUNIT_TEST(testEnhancedProtectionXLS);
     CPPUNIT_TEST(testEnhancedProtectionXLSX);
+    CPPUNIT_TEST(testSortWithSharedFormulasODS);
 
     CPPUNIT_TEST_SUITE_END();
 
@@ -538,6 +543,55 @@ void ScFiltersTest::testEnhancedProtectionXLSX()
     xDocSh->DoClose();
 }
 
+void ScFiltersTest::testSortWithSharedFormulasODS()
+{
+    ScDocShellRef xDocSh = loadDoc("shared-formula/sort-crash.", ODS, true);
+    CPPUNIT_ASSERT(xDocSh.Is());
+    ScDocument* pDoc = xDocSh->GetDocument();
+
+    // E2:E10 should be shared.
+    const ScFormulaCell* pFC = pDoc->GetFormulaCell(ScAddress(4,1,0));
+    CPPUNIT_ASSERT(pFC);
+    CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(1), pFC->GetSharedTopRow());
+    CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(9), pFC->GetSharedLength());
+
+    // E12:E17 should be shared.
+    pFC = pDoc->GetFormulaCell(ScAddress(4,11,0));
+    CPPUNIT_ASSERT(pFC);
+    CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(11), pFC->GetSharedTopRow());
+    CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(6), pFC->GetSharedLength());
+
+    // Set A1:E17 as an anonymous database range to sheet, or else Calc would
+    // refuse to sort the range.
+    ScDBData* pDBData = new ScDBData(STR_DB_LOCAL_NONAME, 0, 0, 0, 4, 16, true, true);
+    pDoc->SetAnonymousDBData(0, pDBData);
+
+    // Sort ascending by Column E.
+
+    ScSortParam aSortData;
+    aSortData.nCol1 = 0;
+    aSortData.nCol2 = 4;
+    aSortData.nRow1 = 0;
+    aSortData.nRow2 = 16;
+    aSortData.bHasHeader = true;
+    aSortData.maKeyState[0].bDoSort = true;
+    aSortData.maKeyState[0].nField = 4;
+    aSortData.maKeyState[0].bAscending = true;
+
+    // Do the sorting.  This should not crash.
+    ScDBDocFunc aFunc(*xDocSh);
+    bool bSorted = aFunc.Sort(0, aSortData, true, true, true);
+    CPPUNIT_ASSERT(bSorted);
+
+    // After the sort, E2:E16 should be shared.
+    pFC = pDoc->GetFormulaCell(ScAddress(4,1,0));
+    CPPUNIT_ASSERT(pFC);
+    CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(1), pFC->GetSharedTopRow());
+    CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(15), pFC->GetSharedLength());
+
+    xDocSh->DoClose();
+}
+
 ScFiltersTest::ScFiltersTest()
       : ScBootstrapFixture( "/sc/qa/unit/data" )
 {
diff --git a/sc/source/ui/inc/dbdocfun.hxx b/sc/source/ui/inc/dbdocfun.hxx
index 98385b1..9fad8042 100644
--- a/sc/source/ui/inc/dbdocfun.hxx
+++ b/sc/source/ui/inc/dbdocfun.hxx
@@ -70,8 +70,8 @@ public:
 
     static void     ShowInBeamer( const ScImportParam& rParam, SfxViewFrame* pFrame );
 
-    bool            Sort( SCTAB nTab, const ScSortParam& rSortParam,
-                            bool bRecord, bool bPaint, bool bApi );
+    SC_DLLPUBLIC bool Sort(
+        SCTAB nTab, const ScSortParam& rSortParam, bool bRecord, bool bPaint, bool bApi );
 
     SC_DLLPUBLIC bool           Query( SCTAB nTab, const ScQueryParam& rQueryParam,
                             const ScRange* pAdvSource, bool bRecord, bool bApi );


More information about the Libreoffice-commits mailing list