summaryrefslogtreecommitdiff
path: root/sc/qa/unit
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2014-08-15 16:55:20 +0200
committerEike Rathke <erack@redhat.com>2014-08-15 16:56:55 +0200
commit1d67f3661cdf1fadf498ae77f9d8ee9c2e026f31 (patch)
tree8a251516915c7d17698328f184f7d114b9d4953d /sc/qa/unit
parent028c9662af563d22303b669072ac21195ea955b1 (diff)
unit test for sort with sheet references and external references, fdo#77018
Change-Id: I4b60fe3f3594fbe13ae25ac29c8701d80870595e
Diffstat (limited to 'sc/qa/unit')
-rw-r--r--sc/qa/unit/data/ods/sort-with-sheet-external-references.odsbin0 -> 28812 bytes
-rw-r--r--sc/qa/unit/filters-test.cxx82
2 files changed, 82 insertions, 0 deletions
diff --git a/sc/qa/unit/data/ods/sort-with-sheet-external-references.ods b/sc/qa/unit/data/ods/sort-with-sheet-external-references.ods
new file mode 100644
index 000000000000..439ee38d9b56
--- /dev/null
+++ b/sc/qa/unit/data/ods/sort-with-sheet-external-references.ods
Binary files differ
diff --git a/sc/qa/unit/filters-test.cxx b/sc/qa/unit/filters-test.cxx
index 1aa9c7085b4c..d50a6f881071 100644
--- a/sc/qa/unit/filters-test.cxx
+++ b/sc/qa/unit/filters-test.cxx
@@ -36,6 +36,7 @@
#include <globalnames.hxx>
#include <dbdata.hxx>
#include <sortparam.hxx>
+#include "scopetools.hxx"
#include <svx/svdpage.hxx>
@@ -77,6 +78,8 @@ public:
void testEnhancedProtectionXLS();
void testEnhancedProtectionXLSX();
void testSortWithSharedFormulasODS();
+ void testSortWithSheetExternalReferencesODS();
+ void testSortWithSheetExternalReferencesODS_Impl( ScDocShellRef xDocShRef, SCROW nRow1, SCROW nRow2 );
CPPUNIT_TEST_SUITE(ScFiltersTest);
CPPUNIT_TEST(testCVEs);
@@ -94,6 +97,7 @@ public:
CPPUNIT_TEST(testEnhancedProtectionXLS);
CPPUNIT_TEST(testEnhancedProtectionXLSX);
CPPUNIT_TEST(testSortWithSharedFormulasODS);
+ CPPUNIT_TEST(testSortWithSheetExternalReferencesODS);
CPPUNIT_TEST_SUITE_END();
@@ -598,6 +602,84 @@ void ScFiltersTest::testSortWithSharedFormulasODS()
xDocSh->DoClose();
}
+// https://bugs.freedesktop.org/attachment.cgi?id=100089 from fdo#77018
+// mentioned also in fdo#79441
+// Document contains cached external references.
+void ScFiltersTest::testSortWithSheetExternalReferencesODS()
+{
+ ScDocShellRef xDocSh = loadDoc("sort-with-sheet-external-references.", ODS, true);
+ CPPUNIT_ASSERT(xDocSh.Is());
+ ScDocument& rDoc = xDocSh->GetDocument();
+ sc::AutoCalcSwitch aACSwitch(rDoc, true); // turn auto calc on.
+ rDoc.CalcAll();
+
+ // Sort A15:D20 with relative row references.
+ testSortWithSheetExternalReferencesODS_Impl( xDocSh, 14, 19);
+
+ // Sort A23:D28 with absolute row references.
+ testSortWithSheetExternalReferencesODS_Impl( xDocSh, 22, 27);
+
+ xDocSh->DoClose();
+}
+
+void ScFiltersTest::testSortWithSheetExternalReferencesODS_Impl( ScDocShellRef xDocSh, SCROW nRow1, SCROW nRow2 )
+{
+ ScDocument& rDoc = xDocSh->GetDocument();
+
+ // Check the original data is there.
+ for (SCROW nRow=nRow1+1; nRow <= nRow2; ++nRow)
+ {
+ double aCheck[] = { 1, 2, 3, 4, 5 };
+ CPPUNIT_ASSERT_EQUAL( aCheck[nRow-nRow1-1], rDoc.GetValue( ScAddress(0,nRow,0)));
+ }
+ for (SCROW nRow=nRow1+1; nRow <= nRow2; ++nRow)
+ {
+ for (SCCOL nCol=1; nCol <= 3; ++nCol)
+ {
+ double aCheck[] = { 1, 12, 123, 1234, 12345 };
+ CPPUNIT_ASSERT_EQUAL( aCheck[nRow-nRow1-1], rDoc.GetValue( ScAddress(nCol,nRow,0)));
+ }
+ }
+
+ // Set as an anonymous database range to sort.
+ ScDBData* pDBData = new ScDBData(STR_DB_LOCAL_NONAME, 0, 0, nRow1, 3, nRow2, true, true);
+ rDoc.SetAnonymousDBData(0, pDBData);
+
+ // Sort descending by Column A.
+ ScSortParam aSortData;
+ aSortData.nCol1 = 0;
+ aSortData.nCol2 = 3;
+ aSortData.nRow1 = nRow1;
+ aSortData.nRow2 = nRow2;
+ aSortData.bHasHeader = true;
+ aSortData.maKeyState[0].bDoSort = true;
+ aSortData.maKeyState[0].nField = 0;
+ aSortData.maKeyState[0].bAscending = false;
+
+ // Do the sorting.
+ ScDBDocFunc aFunc(*xDocSh);
+ bool bSorted = aFunc.Sort(0, aSortData, true, true, true);
+ CPPUNIT_ASSERT(bSorted);
+ rDoc.CalcAll();
+
+ // Check the sort and that all sheet references and external references are
+ // adjusted to point to the original location.
+ for (SCROW nRow=nRow1+1; nRow <= nRow2; ++nRow)
+ {
+ double aCheck[] = { 5, 4, 3, 2, 1 };
+ CPPUNIT_ASSERT_EQUAL( aCheck[nRow-nRow1-1], rDoc.GetValue( ScAddress(0,nRow,0)));
+ }
+ for (SCROW nRow=nRow1+1; nRow <= nRow2; ++nRow)
+ {
+ for (SCCOL nCol=1; nCol <= 3; ++nCol)
+ {
+ double aCheck[] = { 12345, 1234, 123, 12, 1 };
+ CPPUNIT_ASSERT_EQUAL( aCheck[nRow-nRow1-1], rDoc.GetValue( ScAddress(nCol,nRow,0)));
+ }
+ }
+}
+
+
ScFiltersTest::ScFiltersTest()
: ScBootstrapFixture( "/sc/qa/unit/data" )
{