[Libreoffice-commits] core.git: Branch 'libreoffice-5-4' - sc/qa sc/source

Dennis Francis dennis.francis at collabora.co.uk
Wed Jul 19 18:57:51 UTC 2017


 sc/qa/unit/ucalc.hxx                |    2 ++
 sc/qa/unit/ucalc_formula.cxx        |   34 ++++++++++++++++++++++++++++++++++
 sc/source/core/data/formulacell.cxx |    4 ++++
 3 files changed, 40 insertions(+)

New commits:
commit f5661ec96ea4e30abea2ad0b218024c6c747071b
Author: Dennis Francis <dennis.francis at collabora.co.uk>
Date:   Mon Jul 17 19:10:44 2017 +0530

    tdf#93328 : Assign the ScInterpreter results back to ScFormulaCell...
    
    when the formula cell type is unknown before interpreting, otherwise
    the cell is treated as of type string later when used by the
    interpreter.
    
    Added unit-test testIterations() in ucalc that tests the
    establishment of circular chain of references and editing of a
    formula cell that already belong to the circular chain.
    
    Change-Id: Ib13b05b20d17c0696fce0ac9eefd9e621bdc0c5f
    Reviewed-on: https://gerrit.libreoffice.org/40165
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Eike Rathke <erack at redhat.com>
    Tested-by: Eike Rathke <erack at redhat.com>
    (cherry picked from commit 5f2bcde100c278315609c221c48ff03aacdf9bdc)
    Reviewed-on: https://gerrit.libreoffice.org/40199

diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx
index bddf2eda1ff8..845599edf38e 100644
--- a/sc/qa/unit/ucalc.hxx
+++ b/sc/qa/unit/ucalc.hxx
@@ -218,6 +218,7 @@ public:
     void testMatConcatReplication();
     void testRefR1C1WholeCol();
     void testRefR1C1WholeRow();
+    void testIterations();
 
     void testExternalRef();
     void testExternalRefFunctions();
@@ -610,6 +611,7 @@ public:
     CPPUNIT_TEST(testFuncGETPIVOTDATALeafAccess);
     CPPUNIT_TEST(testRefR1C1WholeCol);
     CPPUNIT_TEST(testRefR1C1WholeRow);
+    CPPUNIT_TEST(testIterations);
     CPPUNIT_TEST(testMatrixOp);
     CPPUNIT_TEST(testFuncRangeOp);
     CPPUNIT_TEST(testFuncFORMULA);
diff --git a/sc/qa/unit/ucalc_formula.cxx b/sc/qa/unit/ucalc_formula.cxx
index 3f04ff0a0c45..277b224da8a7 100644
--- a/sc/qa/unit/ucalc_formula.cxx
+++ b/sc/qa/unit/ucalc_formula.cxx
@@ -8030,4 +8030,38 @@ void Test::testFuncRowsHidden()
     m_pDoc->DeleteTab(0);
 }
 
+// Test iterations with circular chain of references.
+void Test::testIterations()
+{
+    ScDocOptions aDocOpts = m_pDoc->GetDocOptions();
+    aDocOpts.SetIter( true );
+    m_pDoc->SetDocOptions( aDocOpts );
+
+    m_pDoc->InsertTab(0, "Test");
+
+    m_pDoc->SetValue( 0, 0, 0, 0.01 );         // A1
+    m_pDoc->SetString( 0, 1, 0, "=A1" );       // A2
+    m_pDoc->SetString( 0, 2, 0, "=COS(A2)" );  // A3
+    m_pDoc->CalcAll();
+
+    // Establish reference cycle for the computation of the fixed point of COS() function
+    m_pDoc->SetString( 0, 0, 0, "=A3" );       // A1
+    m_pDoc->CalcAll();
+
+    CPPUNIT_ASSERT_EQUAL_MESSAGE( "Cell A3 should not have any formula error", FormulaError::NONE, m_pDoc->GetErrCode( ScAddress( 0, 2, 0) ) );
+    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Iterations to calculate fixed point of cos() failed", 0.7387, m_pDoc->GetValue(0, 2, 0), 1e-4 );
+
+    // Modify the formula
+    m_pDoc->SetString( 0, 2, 0, "=COS(A2)+0.001" );  // A3
+    m_pDoc->CalcAll();
+
+    CPPUNIT_ASSERT_EQUAL_MESSAGE( "Cell A3 should not have any formula error after perturbation", FormulaError::NONE, m_pDoc->GetErrCode( ScAddress( 0, 2, 0) ) );
+    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Iterations to calculate perturbed fixed point of cos() failed", 0.7399, m_pDoc->GetValue(0, 2, 0), 1e-4 );
+
+    m_pDoc->DeleteTab(0);
+
+    aDocOpts.SetIter( false );
+    m_pDoc->SetDocOptions( aDocOpts );
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx
index 630ba6208869..2555c15b6371 100644
--- a/sc/source/core/data/formulacell.cxx
+++ b/sc/source/core/data/formulacell.cxx
@@ -1806,6 +1806,10 @@ void ScFormulaCell::InterpretTail( ScInterpretTailParameter eTailParam )
         {
             if (nSeenInIteration > 0)
                 --nSeenInIteration;     // retry when iteration is resumed
+
+            if ( aResult.GetType() == formula::svUnknown )
+                aResult.SetToken( pInterpreter->GetResultToken().get() );
+
             return;
         }
         bRunning = bOldRunning;


More information about the Libreoffice-commits mailing list