summaryrefslogtreecommitdiff
path: root/sc/qa/unit/ucalc.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'sc/qa/unit/ucalc.cxx')
-rw-r--r--sc/qa/unit/ucalc.cxx123
1 files changed, 115 insertions, 8 deletions
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index d742718417ad..4d15f31a6371 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -39,12 +39,8 @@
// the need for manually calling regcomp and knowing what
// services we need, and in what .so they are implemented
-#include "precompiled_sc.hxx"
-#include <cppunit/TestAssert.h>
-#include <cppunit/TestFixture.h>
-#include <cppunit/extensions/HelperMacros.h>
-#include <cppunit/plugin/TestPlugIn.h>
+#include <sal/cppunit.h>
#include <sal/config.h>
#include <osl/file.hxx>
@@ -61,6 +57,7 @@
#include "scmatrix.hxx"
#include "drwlayer.hxx"
#include "scitems.hxx"
+#include "reffind.hxx"
#include "docsh.hxx"
#include "funcdesc.hxx"
@@ -229,6 +226,7 @@ public:
void testInput();
void testSUM();
void testVolatileFunc();
+ void testFuncParam();
void testNamedRange();
void testCSV();
void testMatrix();
@@ -255,11 +253,19 @@ public:
*/
void testCVEs();
+ /**
+ * Test toggling relative/absolute flag of cell and cell range references.
+ * This corresponds with hitting Shift-F4 while the cursor is on a formula
+ * cell.
+ */
+ void testToggleRefFlag();
+
CPPUNIT_TEST_SUITE(Test);
CPPUNIT_TEST(testCollator);
CPPUNIT_TEST(testInput);
CPPUNIT_TEST(testSUM);
CPPUNIT_TEST(testVolatileFunc);
+ CPPUNIT_TEST(testFuncParam);
CPPUNIT_TEST(testNamedRange);
CPPUNIT_TEST(testCSV);
CPPUNIT_TEST(testMatrix);
@@ -271,6 +277,7 @@ public:
CPPUNIT_TEST(testStreamValid);
CPPUNIT_TEST(testFunctionLists);
CPPUNIT_TEST(testCVEs);
+ CPPUNIT_TEST(testToggleRefFlag);
CPPUNIT_TEST_SUITE_END();
private:
@@ -412,6 +419,29 @@ void Test::testVolatileFunc()
m_pDoc->DeleteTab(0);
}
+void Test::testFuncParam()
+{
+ rtl::OUString aTabName(RTL_CONSTASCII_USTRINGPARAM("foo"));
+ CPPUNIT_ASSERT_MESSAGE ("failed to insert sheet",
+ m_pDoc->InsertTab (0, aTabName));
+
+ // First, the normal case, with no missing parameters.
+ m_pDoc->SetString(0, 0, 0, OUString(RTL_CONSTASCII_USTRINGPARAM("=AVERAGE(1;2;3)")));
+ m_pDoc->CalcFormulaTree(false, true);
+ double val;
+ m_pDoc->GetValue(0, 0, 0, val);
+ CPPUNIT_ASSERT_MESSAGE("incorrect result", val == 2);
+
+ // Now function with missing parameters. Missing values should be treated
+ // as zeros.
+ m_pDoc->SetString(0, 0, 0, OUString(RTL_CONSTASCII_USTRINGPARAM("=AVERAGE(1;;;)")));
+ m_pDoc->CalcFormulaTree(false, true);
+ m_pDoc->GetValue(0, 0, 0, val);
+ CPPUNIT_ASSERT_MESSAGE("incorrect result", val == 0.25);
+
+ m_pDoc->DeleteTab(0);
+}
+
void Test::testNamedRange()
{
rtl::OUString aTabName(RTL_CONSTASCII_USTRINGPARAM("Sheet1"));
@@ -491,15 +521,15 @@ void Test::testCVEs()
bool bResult;
bResult = testLoad(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Quattro Pro 6.0")),
- m_aPWDURL + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/CVE/CVE-2007-5745-1.wb2")));
+ m_aPWDURL + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/qa/unit/CVE/CVE-2007-5745-1.wb2")));
CPPUNIT_ASSERT_MESSAGE("CVE-2007-5745 regression", bResult == true);
bResult = testLoad(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Quattro Pro 6.0")),
- m_aPWDURL + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/CVE/CVE-2007-5745-2.wb2")));
+ m_aPWDURL + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/qa/unit/CVE/CVE-2007-5745-2.wb2")));
CPPUNIT_ASSERT_MESSAGE("CVE-2007-5745 regression", bResult == true);
bResult = testLoad(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Quattro Pro 6.0")),
- m_aPWDURL + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/CVE/CVE-2007-5747-1.wb2")));
+ m_aPWDURL + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/qa/unit/CVE/CVE-2007-5747-1.wb2")));
CPPUNIT_ASSERT_MESSAGE("CVE-2007-5747 regression", bResult == false);
}
@@ -1619,6 +1649,83 @@ void Test::testGraphicsInGroup()
m_pDoc->DeleteTab(0);
}
+void Test::testToggleRefFlag()
+{
+ // In this test, there is no need to insert formula string into a cell in
+ // the document, as ScRefFinder does not depend on the content of the
+ // document except for the sheet names.
+
+ OUString aTabName(RTL_CONSTASCII_USTRINGPARAM("Test"));
+ m_pDoc->InsertTab(0, aTabName);
+
+ {
+ // Calc A1: basic 2D reference
+
+ OUString aFormula(RTL_CONSTASCII_USTRINGPARAM("=B100"));
+ ScAddress aPos(1, 5, 0);
+ ScRefFinder aFinder(aFormula, aPos, m_pDoc, formula::FormulaGrammar::CONV_OOO);
+
+ // Original
+ CPPUNIT_ASSERT_MESSAGE("Does not equal the original text.", aFormula.equals(aFinder.GetText()));
+
+ // column relative / row relative -> column absolute / row absolute
+ aFinder.ToggleRel(0, aFormula.getLength());
+ aFormula = aFinder.GetText();
+ CPPUNIT_ASSERT_MESSAGE("Wrong conversion.", aFormula.equalsAscii("=$B$100"));
+
+ // column absolute / row absolute -> column relative / row absolute
+ aFinder.ToggleRel(0, aFormula.getLength());
+ aFormula = aFinder.GetText();
+ CPPUNIT_ASSERT_MESSAGE("Wrong conversion.", aFormula.equalsAscii("=B$100"));
+
+ // column relative / row absolute -> column absolute / row relative
+ aFinder.ToggleRel(0, aFormula.getLength());
+ aFormula = aFinder.GetText();
+ CPPUNIT_ASSERT_MESSAGE("Wrong conversion.", aFormula.equalsAscii("=$B100"));
+
+ // column absolute / row relative -> column relative / row relative
+ aFinder.ToggleRel(0, aFormula.getLength());
+ aFormula = aFinder.GetText();
+ CPPUNIT_ASSERT_MESSAGE("Wrong conversion.", aFormula.equalsAscii("=B100"));
+ }
+
+ {
+ // Excel R1C1: basic 2D reference
+
+ OUString aFormula(RTL_CONSTASCII_USTRINGPARAM("=R2C1"));
+ ScAddress aPos(3, 5, 0);
+ ScRefFinder aFinder(aFormula, aPos, m_pDoc, formula::FormulaGrammar::CONV_XL_R1C1);
+
+ // Original
+ CPPUNIT_ASSERT_MESSAGE("Does not equal the original text.", aFormula.equals(aFinder.GetText()));
+
+ // column absolute / row absolute -> column relative / row absolute
+ aFinder.ToggleRel(0, aFormula.getLength());
+ aFormula = aFinder.GetText();
+ CPPUNIT_ASSERT_MESSAGE("Wrong conversion.", aFormula.equalsAscii("=R2C[-3]"));
+
+ // column relative / row absolute - > column absolute / row relative
+ aFinder.ToggleRel(0, aFormula.getLength());
+ aFormula = aFinder.GetText();
+ CPPUNIT_ASSERT_MESSAGE("Wrong conversion.", aFormula.equalsAscii("=R[-4]C1"));
+
+ // column absolute / row relative -> column relative / row relative
+ aFinder.ToggleRel(0, aFormula.getLength());
+ aFormula = aFinder.GetText();
+ CPPUNIT_ASSERT_MESSAGE("Wrong conversion.", aFormula.equalsAscii("=R[-4]C[-3]"));
+
+ // column relative / row relative -> column absolute / row absolute
+ aFinder.ToggleRel(0, aFormula.getLength());
+ aFormula = aFinder.GetText();
+ CPPUNIT_ASSERT_MESSAGE("Wrong conversion.", aFormula.equalsAscii("=R2C1"));
+ }
+
+ // TODO: Add more test cases esp. for 3D references, Excel A1 syntax, and
+ // partial selection within formula string.
+
+ m_pDoc->DeleteTab(0);
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(Test);
}