summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKohei Yoshida <kyoshida@novell.com>2011-04-18 13:29:36 -0400
committerKohei Yoshida <kyoshida@novell.com>2011-04-18 13:29:36 -0400
commit1996fa8117e90519bd74a51a6dfadd947aec7e9a (patch)
tree6e81faf67a9f18b68dfd6a1dfab5f22a3f489312
parent79fc818ea9cbebf4345273c41d2959d1c8f51598 (diff)
New unit test for toggling relative/absolute reference (Shift-F4).
-rw-r--r--sc/qa/unit/ucalc.cxx86
1 files changed, 86 insertions, 0 deletions
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index bdd58beff..4d16e61a3 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -57,6 +57,7 @@
#include "scmatrix.hxx"
#include "drwlayer.hxx"
#include "scitems.hxx"
+#include "reffind.hxx"
#include "docsh.hxx"
#include "funcdesc.hxx"
@@ -252,6 +253,13 @@ 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);
@@ -269,6 +277,7 @@ public:
CPPUNIT_TEST(testStreamValid);
CPPUNIT_TEST(testFunctionLists);
CPPUNIT_TEST(testCVEs);
+ CPPUNIT_TEST(testToggleRefFlag);
CPPUNIT_TEST_SUITE_END();
private:
@@ -1640,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("Does not equal the original text.", aFormula.equalsAscii("=$B$100"));
+
+ // column absolute / row absolute -> column relative / row absolute
+ aFinder.ToggleRel(0, aFormula.getLength());
+ aFormula = aFinder.GetText();
+ CPPUNIT_ASSERT_MESSAGE("Does not equal the original text.", aFormula.equalsAscii("=B$100"));
+
+ // column relative / row absolute -> column absolute / row relative
+ aFinder.ToggleRel(0, aFormula.getLength());
+ aFormula = aFinder.GetText();
+ CPPUNIT_ASSERT_MESSAGE("Does not equal the original text.", aFormula.equalsAscii("=$B100"));
+
+ // column absolute / row relative -> column relative / row relative
+ aFinder.ToggleRel(0, aFormula.getLength());
+ aFormula = aFinder.GetText();
+ CPPUNIT_ASSERT_MESSAGE("Does not equal the original text.", 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("Does not equal the original text.", aFormula.equalsAscii("=R2C[-3]"));
+
+ // column relative / row absolute - > column absolute / row relative
+ aFinder.ToggleRel(0, aFormula.getLength());
+ aFormula = aFinder.GetText();
+ CPPUNIT_ASSERT_MESSAGE("Does not equal the original text.", aFormula.equalsAscii("=R[-4]C1"));
+
+ // column absolute / row relative -> column relative / row relative
+ aFinder.ToggleRel(0, aFormula.getLength());
+ aFormula = aFinder.GetText();
+ CPPUNIT_ASSERT_MESSAGE("Does not equal the original text.", 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("Does not equal the original text.", 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);
}