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

Eike Rathke erack at redhat.com
Fri Jun 19 07:52:27 PDT 2015


 sc/qa/unit/ucalc.hxx         |    2 
 sc/qa/unit/ucalc_formula.cxx |   94 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 96 insertions(+)

New commits:
commit 72be3521524f1c01842010f26c234f4e6cceb358
Author: Eike Rathke <erack at redhat.com>
Date:   Fri Jun 19 16:49:29 2015 +0200

    add unit test for ocRangeOp and ScComplexRefData::Extend()
    
    Change-Id: Iae97c409a84f47d591ef8adf8e42fb6f52c104e2

diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx
index d174829..6e65771 100644
--- a/sc/qa/unit/ucalc.hxx
+++ b/sc/qa/unit/ucalc.hxx
@@ -180,6 +180,7 @@ public:
     void testFuncGETPIVOTDATA();
     void testFuncGETPIVOTDATALeafAccess();
     void testMatrixOp();
+    void testFuncRangeOp();
 
     void testExternalRef();
     void testExternalRefFunctions();
@@ -504,6 +505,7 @@ public:
     CPPUNIT_TEST(testFuncGETPIVOTDATA);
     CPPUNIT_TEST(testFuncGETPIVOTDATALeafAccess);
     CPPUNIT_TEST(testMatrixOp);
+    CPPUNIT_TEST(testFuncRangeOp);
     CPPUNIT_TEST(testExternalRef);
     CPPUNIT_TEST(testExternalRefFunctions);
     CPPUNIT_TEST(testCopyToDocument);
diff --git a/sc/qa/unit/ucalc_formula.cxx b/sc/qa/unit/ucalc_formula.cxx
index 6219eaa..b7ced94 100644
--- a/sc/qa/unit/ucalc_formula.cxx
+++ b/sc/qa/unit/ucalc_formula.cxx
@@ -5045,4 +5045,98 @@ void Test::testMatrixOp()
     m_pDoc->DeleteTab(0);
 }
 
+void Test::testFuncRangeOp()
+{
+    sc::AutoCalcSwitch aACSwitch(*m_pDoc, true); // turn on auto calc.
+
+    m_pDoc->InsertTab(0, "Sheet1");
+    m_pDoc->InsertTab(1, "Sheet2");
+    m_pDoc->InsertTab(2, "Sheet3");
+
+    // Sheet1.B1:B3
+    m_pDoc->SetValue(1,0,0, 1.0);
+    m_pDoc->SetValue(1,1,0, 2.0);
+    m_pDoc->SetValue(1,2,0, 4.0);
+    // Sheet2.B1:B3
+    m_pDoc->SetValue(1,0,1, 8.0);
+    m_pDoc->SetValue(1,1,1, 16.0);
+    m_pDoc->SetValue(1,2,1, 32.0);
+    // Sheet3.B1:B3
+    m_pDoc->SetValue(1,0,2, 64.0);
+    m_pDoc->SetValue(1,1,2, 128.0);
+    m_pDoc->SetValue(1,2,2, 256.0);
+
+    // Range operator should extend concatenated literal references during
+    // parse time already, so with this we can test ScComplexRefData::Extend()
+
+    // Current sheet is Sheet1, so B1:B2 implies relative Sheet1.B1:B2
+
+    ScAddress aPos(0,0,0);
+    m_pDoc->SetString( aPos, "=SUM(B1:B2:B3)");
+    if (!checkFormula( *m_pDoc, aPos, "SUM(B1:B3)"))
+        CPPUNIT_FAIL("Wrong formula.");
+    CPPUNIT_ASSERT_EQUAL( 7.0, m_pDoc->GetValue(aPos));
+
+    aPos.IncRow();
+    m_pDoc->SetString( aPos, "=SUM(B1:B3:B2)");
+    if (!checkFormula( *m_pDoc, aPos, "SUM(B1:B3)"))
+        CPPUNIT_FAIL("Wrong formula.");
+    CPPUNIT_ASSERT_EQUAL( 7.0, m_pDoc->GetValue(aPos));
+
+    aPos.IncRow();
+    m_pDoc->SetString( aPos, "=SUM(B2:B3:B1)");
+    if (!checkFormula( *m_pDoc, aPos, "SUM(B1:B3)"))
+        CPPUNIT_FAIL("Wrong formula.");
+    CPPUNIT_ASSERT_EQUAL( 7.0, m_pDoc->GetValue(aPos));
+
+    aPos.IncRow();
+    m_pDoc->SetString( aPos, "=SUM(Sheet2.B1:B2:B3)");
+    if (!checkFormula( *m_pDoc, aPos, "SUM(Sheet2.B1:B3)"))
+        CPPUNIT_FAIL("Wrong formula.");
+    CPPUNIT_ASSERT_EQUAL( 56.0, m_pDoc->GetValue(aPos));
+
+    aPos.IncRow();
+    m_pDoc->SetString( aPos, "=SUM(B2:B2:Sheet1.B2)");
+    if (!checkFormula( *m_pDoc, aPos, "SUM(Sheet1.B2:B2)"))
+        CPPUNIT_FAIL("Wrong formula.");
+    CPPUNIT_ASSERT_EQUAL( 2.0, m_pDoc->GetValue(aPos));
+
+    aPos.IncRow();
+    m_pDoc->SetString( aPos, "=SUM(B2:B3:Sheet2.B1)");
+    if (!checkFormula( *m_pDoc, aPos, "SUM(Sheet1.B1:Sheet2.B3)"))
+        CPPUNIT_FAIL("Wrong formula.");
+    CPPUNIT_ASSERT_EQUAL( 63.0, m_pDoc->GetValue(aPos));
+
+    aPos.IncRow();
+    m_pDoc->SetString( aPos, "=SUM(Sheet1.B1:Sheet2.B2:Sheet3.B3)");
+    if (!checkFormula( *m_pDoc, aPos, "SUM(Sheet1.B1:Sheet3.B3)"))
+        CPPUNIT_FAIL("Wrong formula.");
+    CPPUNIT_ASSERT_EQUAL( 511.0, m_pDoc->GetValue(aPos));
+
+    // B1:Sheet2.B2 would be ambiguous, Sheet1.B1:Sheet2.B2 or Sheet2.B1:B2
+    // The actual representation of the error case may change, so this test may
+    // have to be adapted.
+    aPos.IncRow();
+    m_pDoc->SetString( aPos, "=SUM(B1:Sheet2.B2:Sheet3.B3)");
+    if (!checkFormula( *m_pDoc, aPos, "SUM(#REF!.B2:#REF!.B3)"))
+        CPPUNIT_FAIL("Wrong formula.");
+    CPPUNIT_ASSERT_EQUAL( OUString("#REF!"), m_pDoc->GetString(aPos));
+
+    aPos.IncRow();
+    m_pDoc->SetString( aPos, "=SUM(Sheet1.B1:Sheet3.B2:Sheet2.B3)");
+    if (!checkFormula( *m_pDoc, aPos, "SUM(Sheet1.B1:Sheet3.B3)"))
+        CPPUNIT_FAIL("Wrong formula.");
+    CPPUNIT_ASSERT_EQUAL( 511.0, m_pDoc->GetValue(aPos));
+
+    aPos.IncRow();
+    m_pDoc->SetString( aPos, "=SUM(B$2:B$2:B2)");
+    if (!checkFormula( *m_pDoc, aPos, "SUM(B$2:B2)"))
+        CPPUNIT_FAIL("Wrong formula.");
+    CPPUNIT_ASSERT_EQUAL( 2.0, m_pDoc->GetValue(aPos));
+
+    m_pDoc->DeleteTab(2);
+    m_pDoc->DeleteTab(1);
+    m_pDoc->DeleteTab(0);
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list