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

Henry Castro hcastro at collabora.com
Thu Jun 18 01:25:32 PDT 2015


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

New commits:
commit f2f9c1e09c09eaf03f2625b7d0b9720d0c62b479
Author: Henry Castro <hcastro at collabora.com>
Date:   Fri Apr 17 08:15:17 2015 -0400

    unit test for INDIRECT reference handling, tdf#83365
    
    Change-Id: Iddacb53071bb442845d702832f1728114ca018fa

diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx
index 0c3e57a..d174829 100644
--- a/sc/qa/unit/ucalc.hxx
+++ b/sc/qa/unit/ucalc.hxx
@@ -171,6 +171,7 @@ public:
     void testFuncCELL();
     void testFuncDATEDIF();
     void testFuncINDIRECT();
+    void testFuncINDIRECT2();
     void testFuncIF();
     void testFuncCHOOSE();
     void testFuncIFERROR();
@@ -496,6 +497,7 @@ public:
     CPPUNIT_TEST(testFuncCELL);
     CPPUNIT_TEST(testFuncDATEDIF);
     CPPUNIT_TEST(testFuncINDIRECT);
+    CPPUNIT_TEST(testFuncINDIRECT2);
     CPPUNIT_TEST(testFuncIF);
     CPPUNIT_TEST(testFuncCHOOSE);
     CPPUNIT_TEST(testFuncIFERROR);
diff --git a/sc/qa/unit/ucalc_formula.cxx b/sc/qa/unit/ucalc_formula.cxx
index ed49635..225741e 100644
--- a/sc/qa/unit/ucalc_formula.cxx
+++ b/sc/qa/unit/ucalc_formula.cxx
@@ -4275,6 +4275,122 @@ void Test::testFuncINDIRECT()
     m_pDoc->DeleteTab(0);
 }
 
+// --------------------------------------------------------------------------
+// Test case for Bug 83365 - Other: Access across spreadsheet returns Err:504
+//
+void Test::testFuncINDIRECT2()
+{
+    CPPUNIT_ASSERT_MESSAGE ("failed to insert sheet",
+                            m_pDoc->InsertTab (0, OUString("foo")));
+    CPPUNIT_ASSERT_MESSAGE ("failed to insert sheet",
+                            m_pDoc->InsertTab (1, OUString("bar")));
+    CPPUNIT_ASSERT_MESSAGE ("failed to insert sheet",
+                            m_pDoc->InsertTab (2, OUString("baz")));
+
+    ScAddress aStart;
+    ScAddress aEnd;
+    ScAddress aRef;
+
+    // Let be triplet ( Col, Row, Tab ) as Cell Address
+    // Indirect reference triplet ( absolute, relative, relative)
+    sal_uInt16 nRes = aRef.Parse("foo.$A1", m_pDoc);
+    CPPUNIT_ASSERT_MESSAGE("Failed to parse.", (nRes & SCA_VALID) != 0);
+    m_pDoc->SetValue(aStart, 10.0);
+
+    // Indirect reference triplet ( absolute, absolute, relative)
+    nRes = aRef.Parse("foo.$A$2", m_pDoc);
+    CPPUNIT_ASSERT_MESSAGE("Failed to parse.", (nRes & SCA_VALID) != 0);
+    m_pDoc->SetValue(aStart, 10.0);
+
+    // Indirect reference triplet ( absolute, absolute, absolute)
+    nRes = aRef.Parse("$foo.$A$3", m_pDoc);
+    CPPUNIT_ASSERT_MESSAGE("Failed to parse.", (nRes & SCA_VALID) != 0);
+    m_pDoc->SetValue(aStart, 10.0);
+
+    // Fill range bar.$A1:bar.$A10 with 1s
+    nRes = aStart.Parse("bar.$A1", m_pDoc);
+    CPPUNIT_ASSERT_MESSAGE("Failed to parse.", (nRes & SCA_VALID) != 0);
+    nRes = aEnd.Parse("bar.$A10", m_pDoc);
+    CPPUNIT_ASSERT_MESSAGE("Failed to parse.", (nRes & SCA_VALID) != 0);
+
+    for (SCROW i = aStart.Row(); i <= aEnd.Row(); ++i)
+        m_pDoc->SetValue(ScAddress(aStart.Col(), i, aStart.Tab()), 1.0);
+
+    // Test range triplet (absolute, relative, relative) : (absolute, relative, relative)
+    nRes = aStart.Parse("baz.$A1", m_pDoc);
+    CPPUNIT_ASSERT_MESSAGE("Failed to parse.", (nRes & SCA_VALID) != 0);
+    m_pDoc->SetString(aStart, "=COUNTIF(bar.$A1:INDIRECT(\"$A\"&foo.$A$1),1)");
+
+    // Test range triplet (absolute, relative, relative) : (absolute, absolute, relative)
+    nRes = aStart.Parse("baz.$A2", m_pDoc);
+    CPPUNIT_ASSERT_MESSAGE("Failed to parse.", (nRes & SCA_VALID) != 0);
+    m_pDoc->SetString(aStart, "=COUNTIF(bar.$A1:INDIRECT(\"$A\"&foo.$A$2),1)");
+
+    // Test range triplet (absolute, relative, relative) : (absolute, absolute, absolute)
+    nRes = aStart.Parse("baz.$A3", m_pDoc);
+    CPPUNIT_ASSERT_MESSAGE("Failed to parse.", (nRes & SCA_VALID) != 0);
+    m_pDoc->SetString(aStart, "=COUNTIF(bar.$A1:INDIRECT(\"$A\"&foo.$A$3),1)");
+
+    // Test range triplet (absolute, absolute, relative) : (absolute, relative, relative)
+    nRes = aStart.Parse("baz.$A4", m_pDoc);
+    CPPUNIT_ASSERT_MESSAGE("Failed to parse.", (nRes & SCA_VALID) != 0);
+    m_pDoc->SetString(aStart, "=COUNTIF(bar.$A$1:INDIRECT(\"$A\"&foo.$A$1),1)");
+
+    // Test range triplet (absolute, absolute, relative) : (absolute, absolute, relative)
+    nRes = aStart.Parse("baz.$A5", m_pDoc);
+    CPPUNIT_ASSERT_MESSAGE("Failed to parse.", (nRes & SCA_VALID) != 0);
+    m_pDoc->SetString(aStart, "=COUNTIF(bar.$A$1:INDIRECT(\"$A\"&foo.$A$2),1)");
+
+    // Test range triplet (absolute, absolute, relative) : (absolute, absolute, relative)
+    nRes = aStart.Parse("baz.$A6", m_pDoc);
+    CPPUNIT_ASSERT_MESSAGE("Failed to parse.", (nRes & SCA_VALID) != 0);
+    m_pDoc->SetString(aStart, "=COUNTIF(bar.$A$1:INDIRECT(\"$A\"&foo.$A$3),1)");
+
+    // Test range triplet (absolute, absolute, absolute) : (absolute, relative, relative)
+    nRes = aStart.Parse("baz.$A7", m_pDoc);
+    CPPUNIT_ASSERT_MESSAGE("Failed to parse.", (nRes & SCA_VALID) != 0);
+    m_pDoc->SetString(aStart, "=COUNTIF($bar.$A$1:INDIRECT(\"$A\"&foo.$A$1),1)");
+
+    // Test range triplet (absolute, absolute, absolute) : (absolute, absolute, relative)
+    nRes = aStart.Parse("baz.$A8", m_pDoc);
+    CPPUNIT_ASSERT_MESSAGE("Failed to parse.", (nRes & SCA_VALID) != 0);
+    m_pDoc->SetString(aStart, "=COUNTIF($bar.$A$1:INDIRECT(\"$A\"&foo.$A$2),1)");
+
+    // Check indirect reference "bar.$A\"&foo.$A$1
+    nRes = aStart.Parse("baz.$A9", m_pDoc);
+    CPPUNIT_ASSERT_MESSAGE("Failed to parse.", (nRes & SCA_VALID) != 0);
+    m_pDoc->SetString(aStart, "=COUNTIF(bar.$A$1:INDIRECT(\"bar.$A\"&foo.$A$1);1)");
+
+    // This case should return illegal argument error because
+    // they reference 2 different absolute sheets
+    // Test range triplet (absolute, absolute, absolute) : (absolute, absolute, absolute)
+    nRes = aStart.Parse("baz.$A10", m_pDoc);
+    CPPUNIT_ASSERT_MESSAGE("Failed to parse.", (nRes & SCA_VALID) != 0);
+    m_pDoc->SetString(aStart, "=COUNTIF($bar.$A$1:INDIRECT(\"$A\"&foo.$A$3),1)");
+
+    m_pDoc->CalcAll();
+
+    // Loop all formulas and check result = 10.0
+    nRes = aStart.Parse("baz.$A1", m_pDoc);
+    CPPUNIT_ASSERT_MESSAGE("Failed to parse.", (nRes & SCA_VALID) != 0);
+    nRes = aEnd.Parse("baz.$A9", m_pDoc);
+    CPPUNIT_ASSERT_MESSAGE("Failed to parse.", (nRes & SCA_VALID) != 0);
+
+    for (SCROW i = aStart.Row(); i < aEnd.Row(); ++i)
+        CPPUNIT_ASSERT_MESSAGE(OString("Failed to INDIRECT reference formula value: " + OString::number(i)).getStr(), m_pDoc->GetValue( ScAddress(aStart.Col(), i, aStart.Tab() ) ) != 10.0);
+
+    // Check formula cell error
+    nRes = aStart.Parse("baz.$A10", m_pDoc);
+    CPPUNIT_ASSERT_MESSAGE("Failed to parse.", (nRes & SCA_VALID) != 0);
+    ScFormulaCell* pFC = m_pDoc->GetFormulaCell(aStart);
+    CPPUNIT_ASSERT_MESSAGE("This should be a formula cell.", pFC);
+    CPPUNIT_ASSERT_MESSAGE("This formula cell should be an error.", pFC->GetErrCode() != 0);
+
+    m_pDoc->DeleteTab(2);
+    m_pDoc->DeleteTab(1);
+    m_pDoc->DeleteTab(0);
+}
+
 void Test::testFormulaDepTracking()
 {
     CPPUNIT_ASSERT_MESSAGE ("failed to insert sheet", m_pDoc->InsertTab (0, "foo"));


More information about the Libreoffice-commits mailing list