diff options
-rw-r--r-- | sc/Library_scqahelper.mk | 2 | ||||
-rw-r--r-- | sc/qa/unit/helper/sorthelper.hxx | 55 | ||||
-rw-r--r-- | sc/qa/unit/ucalc_sort.cxx | 26 |
3 files changed, 76 insertions, 7 deletions
diff --git a/sc/Library_scqahelper.mk b/sc/Library_scqahelper.mk index be7f23088749..a91d2c026433 100644 --- a/sc/Library_scqahelper.mk +++ b/sc/Library_scqahelper.mk @@ -47,7 +47,7 @@ $(eval $(call gb_Library_use_libraries,scqahelper,\ svl \ svt \ svx \ - svxcore \ + svxcore \ test \ tl \ unotest \ diff --git a/sc/qa/unit/helper/sorthelper.hxx b/sc/qa/unit/helper/sorthelper.hxx new file mode 100644 index 000000000000..e82b8c2e8248 --- /dev/null +++ b/sc/qa/unit/helper/sorthelper.hxx @@ -0,0 +1,55 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef INCLUDED_SC_QA_SORT_HELPER_QAHELPER_HXX +#define INCLUDED_SC_QA_SORT_HELPER_QAHELPER_HXX + +// Unfortunately requires linkage to sc/ internals so +// can't live in qahelper itself. +#include "inputopt.hxx" + +/** + * Temporarily set the sorting type. + */ +class SortTypeSetter { + bool mbSortRefUpdate; +public: + SortTypeSetter(bool bSortRefUpdate) + { + mbSortRefUpdate = changeTo(bSortRefUpdate); + } + bool changeTo(bool bSortRefUpdate) + { + ScInputOptions aInputOptions = SC_MOD()->GetInputOptions(); + bool bRet = aInputOptions.GetSortRefUpdate(); + aInputOptions.SetSortRefUpdate(bSortRefUpdate); + SC_MOD()->SetInputOptions(aInputOptions); + return bRet; + } + virtual ~SortTypeSetter() + { + changeTo(mbSortRefUpdate); + } +}; + +class SortRefNoUpdateSetter : private SortTypeSetter +{ +public: + SortRefNoUpdateSetter() : SortTypeSetter(false) {} +}; + +class SortRefUpdateSetter : private SortTypeSetter +{ +public: + SortRefUpdateSetter() : SortTypeSetter(true) {} +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/unit/ucalc_sort.cxx b/sc/qa/unit/ucalc_sort.cxx index f81a39433c18..ce6b9b3304bf 100644 --- a/sc/qa/unit/ucalc_sort.cxx +++ b/sc/qa/unit/ucalc_sort.cxx @@ -8,6 +8,7 @@ */ #include "ucalc.hxx" +#include "helper/sorthelper.hxx" #include <postit.hxx> #include <sortparam.hxx> @@ -18,7 +19,6 @@ #include <globalnames.hxx> #include <dbdocfun.hxx> #include <scitems.hxx> -#include <inputopt.hxx> #include <editutil.hxx> #include <sal/config.h> @@ -117,6 +117,8 @@ void Test::testSort() void Test::testSortHorizontal() { + SortRefUpdateSetter aUpdateSet; + ScFormulaOptions aOptions; aOptions.SetFormulaSepArg(";"); aOptions.SetFormulaSepArrayCol(";"); @@ -361,6 +363,8 @@ void Test::testSortSingleRow() // if cells in the sort are referenced by formulas void Test::testSortWithFormulaRefs() { + SortRefUpdateSetter aUpdateSet; + m_pDoc->InsertTab(0, "List1"); m_pDoc->InsertTab(1, "List2"); @@ -460,6 +464,8 @@ void Test::testSortWithStrings() void Test::testSortInFormulaGroup() { + SortRefUpdateSetter aUpdateSet; + static struct { SCCOL nCol; SCROW nRow; @@ -691,6 +697,8 @@ void Test::testSortWithCellFormats() void Test::testSortRefUpdate() { + SortTypeSetter aSortTypeSet(true); + sc::AutoCalcSwitch aACSwitch(*m_pDoc, true); // turn auto calc on. FormulaGrammarSwitch aFGSwitch(m_pDoc, formula::FormulaGrammar::GRAM_ENGLISH_XL_R1C1); @@ -811,8 +819,7 @@ void Test::testSortRefUpdate() m_pDoc->SetString(ScAddress(2,1+i,0), "=RC[-2]"); // Turn off reference update on sort. - ScInputOptions aInputOption = SC_MOD()->GetInputOptions(); - aInputOption.SetSortRefUpdate(false); + aSortTypeSet.changeTo(false); bSorted = aFunc.Sort(0, aSortData, true, true, true); CPPUNIT_ASSERT(bSorted); @@ -837,14 +844,13 @@ void Test::testSortRefUpdate() CPPUNIT_ASSERT_EQUAL(fCheck, m_pDoc->GetValue(ScAddress(2,i+1,0))); // column C } - // Turn it back on. - aInputOption.SetSortRefUpdate(true); - m_pDoc->DeleteTab(0); } void Test::testSortRefUpdate2() { + SortRefUpdateSetter aUpdateSet; + sc::AutoCalcSwitch aACSwitch(*m_pDoc, true); // turn auto calc on. FormulaGrammarSwitch aFGSwitch(m_pDoc, formula::FormulaGrammar::GRAM_ENGLISH_XL_R1C1); @@ -932,6 +938,8 @@ void Test::testSortRefUpdate2() void Test::testSortRefUpdate3() { + SortRefUpdateSetter aUpdateSet; + sc::AutoCalcSwitch aACSwitch(*m_pDoc, true); // turn auto calc on. m_pDoc->InsertTab(0, "Sort"); @@ -1020,6 +1028,8 @@ void Test::testSortRefUpdate3() // testRefInterne.ods void Test::testSortRefUpdate4() { + SortRefUpdateSetter aUpdateSet; + sc::AutoCalcSwitch aACSwitch(*m_pDoc, true); // turn auto calc on. m_pDoc->InsertTab(0, "Sort"); m_pDoc->InsertTab(1, "Lesson1"); @@ -1217,6 +1227,8 @@ void Test::testSortRefUpdate4() * before midnight, ermm.. */ void Test::testSortRefUpdate5() { + SortRefUpdateSetter aUpdateSet; + sc::AutoCalcSwitch aACSwitch(*m_pDoc, true); // turn auto calc on. m_pDoc->InsertTab(0, "Sort"); @@ -1388,6 +1400,8 @@ void Test::testSortOutOfPlaceResult() void Test::testSortPartialFormulaGroup() { + SortRefUpdateSetter aUpdateSet; + sc::AutoCalcSwitch aACSwitch(*m_pDoc, true); // turn auto calc on. FormulaGrammarSwitch aFGSwitch(m_pDoc, formula::FormulaGrammar::GRAM_ENGLISH_XL_R1C1); |