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

Michael Meeks michael.meeks at collabora.com
Fri Nov 11 15:41:47 UTC 2016


 sc/qa/extras/sccellrangeobj.cxx  |   33 ++++++++++++++++++++++++++++++++-
 sc/source/ui/unoobj/cellsuno.cxx |    8 ++++++++
 2 files changed, 40 insertions(+), 1 deletion(-)

New commits:
commit 99316fc0c830ae6c827d9b7f56bf057ff7731ed5
Author: Michael Meeks <michael.meeks at collabora.com>
Date:   Thu Nov 10 19:11:07 2016 +0000

    tdf#103632 - sc: OOB sort fields unit test.
    
    Change-Id: I6734d51c8f9c4ca5a01c3e54a71f83ba15db508d
    Reviewed-on: https://gerrit.libreoffice.org/30761
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Michael Meeks <michael.meeks at collabora.com>

diff --git a/sc/qa/extras/sccellrangeobj.cxx b/sc/qa/extras/sccellrangeobj.cxx
index a81377e..12e2864 100644
--- a/sc/qa/extras/sccellrangeobj.cxx
+++ b/sc/qa/extras/sccellrangeobj.cxx
@@ -17,13 +17,15 @@
 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
 #include <com/sun/star/sheet/XSpreadsheet.hpp>
 #include <com/sun/star/table/XCellRange.hpp>
+#include <com/sun/star/util/XSortable.hpp>
+#include <com/sun/star/util/SortField.hpp>
 
 using namespace css;
 using namespace css::uno;
 
 namespace sc_apitest {
 
-#define NUMBER_OF_TESTS 14
+#define NUMBER_OF_TESTS 15
 
 class ScCellRangeObj : public CalcUnoApiTest, public apitest::XCellRangesQuery, public apitest::CellProperties,
                         public apitest::XSearchable, public apitest::XReplaceable, public apitest::XCellRangeData
@@ -35,6 +37,8 @@ public:
     virtual void tearDown() override;
     virtual uno::Reference< uno::XInterface > init() override;
     virtual uno::Reference< uno::XInterface > getXCellRangeData() override;
+    void testSortOOB();
+
 
     CPPUNIT_TEST_SUITE(ScCellRangeObj);
     CPPUNIT_TEST(testQueryColumnDifference);
@@ -52,6 +56,7 @@ public:
     CPPUNIT_TEST(testCreateReplaceDescriptor);
     CPPUNIT_TEST(testGetDataArray);
     CPPUNIT_TEST(testSetDataArray);
+    CPPUNIT_TEST(testSortOOB);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -109,6 +114,32 @@ uno::Reference< uno::XInterface > ScCellRangeObj::getXCellRangeData()
     return xReturn;
 }
 
+void ScCellRangeObj::testSortOOB()
+{
+    uno::Reference<util::XSortable> xSortable(init(),UNO_QUERY_THROW);
+    try {
+        uno::Sequence<beans::PropertyValue> aEmptyDescriptor;
+        xSortable->sort(aEmptyDescriptor);
+    } catch (const uno::Exception &) {
+        CPPUNIT_FAIL("exception thrown during empty sort");
+    }
+
+    try {
+        uno::Sequence<beans::PropertyValue> aProps(1);
+        uno::Sequence<util::SortField> aSort(1);
+
+        aSort[0].Field = 0xffffff;
+        aSort[0].SortAscending = true;
+
+        aProps[0].Name = "SortFields";
+        aProps[0].Value = uno::makeAny(aSort);
+
+        xSortable->sort(aProps);
+    } catch (const uno::Exception &) {
+        CPPUNIT_FAIL("exception thrown during OOB sort");
+    }
+}
+
 void ScCellRangeObj::setUp()
 {
     nTest++;
commit b8fa4d1b2d135cabc9eb5162ca0c5af649f1cdaf
Author: Michael Meeks <michael.meeks at collabora.com>
Date:   Fri Nov 4 21:14:34 2016 +0000

    tdf#103632 - sc: tolerate OOB sort fields from UNO API.
    
    Change-Id: Ie04b4281947a05572672838b3b4b5c6173d8fa0b
    Reviewed-on: https://gerrit.libreoffice.org/30576
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Michael Meeks <michael.meeks at collabora.com>

diff --git a/sc/source/ui/unoobj/cellsuno.cxx b/sc/source/ui/unoobj/cellsuno.cxx
index 49ac5e2..a1084a6 100644
--- a/sc/source/ui/unoobj/cellsuno.cxx
+++ b/sc/source/ui/unoobj/cellsuno.cxx
@@ -5598,8 +5598,16 @@ void SAL_CALL ScCellRangeObj::sort( const uno::Sequence<beans::PropertyValue>& a
         SCCOLROW nFieldStart = aParam.bByRow ?
             static_cast<SCCOLROW>(aRange.aStart.Col()) :
             static_cast<SCCOLROW>(aRange.aStart.Row());
+        SCCOLROW nFieldEnd = aParam.bByRow ?
+            static_cast<SCCOLROW>(aRange.aEnd.Col()) :
+            static_cast<SCCOLROW>(aRange.aEnd.Row());
         for (i=0; i<aParam.GetSortKeyCount(); i++)
+        {
             aParam.maKeyState[i].nField += nFieldStart;
+            // tdf#103632 - sanity check poorly behaved macros.
+            if (aParam.maKeyState[i].nField > nFieldEnd)
+                aParam.maKeyState[i].nField = nFieldEnd;
+        }
 
         SCTAB nTab = aRange.aStart.Tab();
         aParam.nCol1 = aRange.aStart.Col();


More information about the Libreoffice-commits mailing list