sc/inc/document.hxx              |    2 +-
 sc/qa/unit/GoalSeekTest.cxx      |   38 ++++++++++++++++++++++++++++++++++++++
 sc/source/core/data/documen4.cxx |    4 +---
 sc/source/ui/view/viewfun2.cxx   |    3 +--
 4 files changed, 41 insertions(+), 6 deletions(-)

New commits:
commit 302029b9cd41ac31a5be3787147a86a4f9e507de
Author:     Xisco Fauli <xiscofa...@libreoffice.org>
AuthorDate: Mon Jun 17 17:41:54 2024 +0200
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Tue Jun 18 00:07:56 2024 +0200

    tdf#161616: do not set error when XGoalSeek fails
    
    Change-Id: I2fcec37cd9d22862dd136c97e5b4097e69fd41cc
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/169035
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/169050

diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index 30b7524a2b6e..d0e825721740 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -1982,7 +1982,7 @@ public:
     // Goal Seek solver
     bool               Solver( SCCOL nFCol, SCROW nFRow, SCTAB nFTab,
                                SCCOL nVCol, SCROW nVRow, SCTAB nVTab,
-                               const OUString& sValStr, double& nX, bool setNA 
= true);
+                               const OUString& sValStr, double& nX);
     const ScGoalSeekSettings& GetGoalSeekSettings() { return 
maGoalSeekSettings; }
     void               SetGoalSeekSettings(const ScGoalSeekSettings& 
rNewSettings) { maGoalSeekSettings = rNewSettings; }
 
diff --git a/sc/qa/unit/GoalSeekTest.cxx b/sc/qa/unit/GoalSeekTest.cxx
index aab6d0ef2dba..b9a3bbc6dbba 100644
--- a/sc/qa/unit/GoalSeekTest.cxx
+++ b/sc/qa/unit/GoalSeekTest.cxx
@@ -44,6 +44,7 @@ CPPUNIT_TEST_FIXTURE(ScGoalSeekTest, testTdf161511)
     // Without the fix in place, this test would have crashed
     sheet::GoalResult res = pModelObj->seekGoal(aFormulaCell, aVariableCell, 
"100");
     CPPUNIT_ASSERT_EQUAL(0.0, res.Result);
+    CPPUNIT_ASSERT_EQUAL(DBL_MAX, res.Divergence);
 }
 
 CPPUNIT_TEST_FIXTURE(ScGoalSeekTest, testTdf68034)
@@ -69,6 +70,43 @@ CPPUNIT_TEST_FIXTURE(ScGoalSeekTest, testTdf68034)
     // - Expected: 4
     // - Actual  : 0
     CPPUNIT_ASSERT_EQUAL(4.0, res.Result);
+    CPPUNIT_ASSERT_EQUAL(0.0, res.Divergence);
+}
+
+CPPUNIT_TEST_FIXTURE(ScGoalSeekTest, testTdf161616)
+{
+    createScDoc();
+
+    insertStringToCell(u"A1"_ustr, u"250");
+    insertStringToCell(u"B1"_ustr, u"0.25");
+    insertStringToCell(u"C1"_ustr, u"200");
+    insertStringToCell(u"D1"_ustr, u"= A1 * B1 / C1");
+
+    table::CellAddress aVariableCell;
+    aVariableCell.Sheet = 0;
+    aVariableCell.Row = 0;
+    aVariableCell.Column = 3;
+    table::CellAddress aFormulaCell;
+    aFormulaCell.Sheet = 0;
+    aFormulaCell.Row = 0;
+    aFormulaCell.Column = 4;
+
+    ScModelObj* pModelObj = 
comphelper::getFromUnoTunnel<ScModelObj>(mxComponent);
+    CPPUNIT_ASSERT(pModelObj);
+
+    sheet::GoalResult res = pModelObj->seekGoal(aFormulaCell, aVariableCell, 
"100");
+    CPPUNIT_ASSERT_EQUAL(0.0, res.Result);
+    CPPUNIT_ASSERT_EQUAL(DBL_MAX, res.Divergence);
+
+    ScDocument* pDoc = getScDoc();
+    CPPUNIT_ASSERT_EQUAL(u"250"_ustr, pDoc->GetString(ScAddress(0, 0, 0)));
+    CPPUNIT_ASSERT_EQUAL(u"0.25"_ustr, pDoc->GetString(ScAddress(1, 0, 0)));
+    CPPUNIT_ASSERT_EQUAL(u"200"_ustr, pDoc->GetString(ScAddress(2, 0, 0)));
+
+    // Without the fix in place, this test would have failed with
+    // - Expected: 0.3125
+    // - Actual  : #N/A
+    CPPUNIT_ASSERT_EQUAL(u"0.3125"_ustr, pDoc->GetString(ScAddress(3, 0, 0)));
 }
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sc/source/core/data/documen4.cxx b/sc/source/core/data/documen4.cxx
index 76c1cafb0310..077af2b64ecd 100644
--- a/sc/source/core/data/documen4.cxx
+++ b/sc/source/core/data/documen4.cxx
@@ -72,7 +72,7 @@ using namespace formula;
 */
 bool ScDocument::Solver(SCCOL nFCol, SCROW nFRow, SCTAB nFTab,
                         SCCOL nVCol, SCROW nVRow, SCTAB nVTab,
-                        const OUString& sValStr, double& nX, bool setNA)
+                        const OUString& sValStr, double& nX)
 {
     bool bRet = false;
     nX = 0.0;
@@ -246,8 +246,6 @@ bool ScDocument::Solver(SCCOL nFCol, SCROW nFRow, SCTAB 
nFTab,
         SetDirty( aVRange, false );
         pFormula->Interpret();
     }
-    if (!bRet && setNA)
-        SetError(nVCol, nVRow, nVTab, FormulaError::NotAvailable);
     return bRet;
 }
 
diff --git a/sc/source/ui/view/viewfun2.cxx b/sc/source/ui/view/viewfun2.cxx
index 2254ae4b93d6..6c27c97a0c28 100644
--- a/sc/source/ui/view/viewfun2.cxx
+++ b/sc/source/ui/view/viewfun2.cxx
@@ -2296,8 +2296,7 @@ void ScViewFunc::Solve( const ScSolveParam& rParam )
                     rParam.aRefFormulaCell.Tab(),
                     nDestCol, nDestRow, nDestTab,
                     aTargetValStr,
-                    nSolveResult,
-                    false); // Do not set #NA! on error
+                    nSolveResult);
 
     GetFrameWin()->LeaveWait();
 

Reply via email to