sc/CppunitTest_sc_goal_seek_test.mk |   76 ++++++++++++++++++++++++++++++++++++
 sc/Module_sc.mk                     |    1 
 sc/qa/unit/GoalSeekTest.cxx         |   76 ++++++++++++++++++++++++++++++++++++
 3 files changed, 153 insertions(+)

New commits:
commit 18d2004f34baa15b86d167836e6f04ecbba4dbc3
Author:     Xisco Fauli <[email protected]>
AuthorDate: Fri Jun 14 16:07:51 2024 +0200
Commit:     Xisco Fauli <[email protected]>
CommitDate: Tue Jun 18 00:07:46 2024 +0200

    tdf#68034: sc_goal_seek: Add unittest
    
    Change-Id: I675d59cd7e22c09ea1c673e016d71f8d3ed404a5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168890
    Reviewed-by: Xisco Fauli <[email protected]>
    Tested-by: Jenkins
    Signed-off-by: Xisco Fauli <[email protected]>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/169049

diff --git a/sc/qa/unit/GoalSeekTest.cxx b/sc/qa/unit/GoalSeekTest.cxx
index ea0920ba8760..aab6d0ef2dba 100644
--- a/sc/qa/unit/GoalSeekTest.cxx
+++ b/sc/qa/unit/GoalSeekTest.cxx
@@ -46,6 +46,31 @@ CPPUNIT_TEST_FIXTURE(ScGoalSeekTest, testTdf161511)
     CPPUNIT_ASSERT_EQUAL(0.0, res.Result);
 }
 
+CPPUNIT_TEST_FIXTURE(ScGoalSeekTest, testTdf68034)
+{
+    createScDoc();
+
+    insertStringToCell(u"A1"_ustr, u"=SQRT(B1)");
+
+    table::CellAddress aVariableCell;
+    aVariableCell.Sheet = 0;
+    aVariableCell.Row = 0;
+    aVariableCell.Column = 1;
+    table::CellAddress aFormulaCell;
+    aFormulaCell.Sheet = 0;
+    aFormulaCell.Row = 0;
+    aFormulaCell.Column = 0;
+
+    ScModelObj* pModelObj = 
comphelper::getFromUnoTunnel<ScModelObj>(mxComponent);
+    CPPUNIT_ASSERT(pModelObj);
+
+    sheet::GoalResult res = pModelObj->seekGoal(aFormulaCell, aVariableCell, 
"2");
+    // Without the fix in place, this test would have failed with
+    // - Expected: 4
+    // - Actual  : 0
+    CPPUNIT_ASSERT_EQUAL(4.0, res.Result);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit cee79f814756c0461e2793d5b01bb96e70b232af
Author:     Xisco Fauli <[email protected]>
AuthorDate: Fri Jun 14 14:40:05 2024 +0200
Commit:     Xisco Fauli <[email protected]>
CommitDate: Tue Jun 18 00:07:35 2024 +0200

    tdf#161511: sc_goal_seek: Add unittest
    
    Change-Id: Icc05195a4870d5bb4f8c5ffc9b3bcae89367a89d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168866
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <[email protected]>
    Signed-off-by: Xisco Fauli <[email protected]>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/169048

diff --git a/sc/CppunitTest_sc_goal_seek_test.mk 
b/sc/CppunitTest_sc_goal_seek_test.mk
new file mode 100644
index 000000000000..f4f91d9a9b1c
--- /dev/null
+++ b/sc/CppunitTest_sc_goal_seek_test.mk
@@ -0,0 +1,76 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#*************************************************************************
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+#*************************************************************************
+
+$(eval $(call gb_CppunitTest_CppunitTest,sc_goal_seek_test))
+
+$(eval $(call gb_CppunitTest_use_common_precompiled_header,sc_goal_seek_test))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,sc_goal_seek_test, \
+    sc/qa/unit/GoalSeekTest \
+))
+
+$(eval $(call gb_CppunitTest_use_externals,sc_goal_seek_test, \
+    boost_headers \
+    mdds_headers \
+    libxml2 \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,sc_goal_seek_test, \
+    basegfx \
+    comphelper \
+    cppu \
+    cppuhelper \
+    docmodel \
+    sal \
+    salhelper \
+    sax \
+    sc \
+    scqahelper \
+    sfx \
+    subsequenttest \
+    test \
+    tl \
+    unotest \
+    utl \
+    vcl \
+))
+
+$(eval $(call gb_CppunitTest_use_externals,sc_goal_seek_test,\
+    boost_headers \
+))
+
+$(eval $(call gb_CppunitTest_set_include,sc_goal_seek_test,\
+    -I$(SRCDIR)/sc/source/ui/inc \
+    -I$(SRCDIR)/sc/inc \
+    $$(INCLUDE) \
+))
+
+$(eval $(call gb_CppunitTest_use_api,sc_goal_seek_test,\
+    offapi \
+    udkapi \
+))
+
+$(eval $(call gb_CppunitTest_use_sdk_api,sc_goal_seek_test))
+
+$(eval $(call gb_CppunitTest_use_ure,sc_goal_seek_test))
+$(eval $(call gb_CppunitTest_use_vcl,sc_goal_seek_test))
+
+$(eval $(call gb_CppunitTest_use_rdb,sc_goal_seek_test,services))
+
+$(eval $(call gb_CppunitTest_use_components,sc_goal_seek_test))
+
+$(eval $(call gb_CppunitTest_use_configuration,sc_goal_seek_test))
+
+$(eval $(call gb_CppunitTest_add_arguments,sc_goal_seek_test, \
+    
-env:arg-env=$(gb_Helper_LIBRARY_PATH_VAR)"$$$${$(gb_Helper_LIBRARY_PATH_VAR)+=$$$$$(gb_Helper_LIBRARY_PATH_VAR)}"
 \
+))
+
+# vim: set noet sw=4 ts=4:
diff --git a/sc/Module_sc.mk b/sc/Module_sc.mk
index 25b43c6b19df..ab9dada68aa7 100644
--- a/sc/Module_sc.mk
+++ b/sc/Module_sc.mk
@@ -81,6 +81,7 @@ $(eval $(call gb_Module_add_slowcheck_targets,sc, \
        CppunitTest_sc_cond_format_merge \
        CppunitTest_sc_copypaste \
        CppunitTest_sc_html_export_test \
+       CppunitTest_sc_goal_seek_test \
        CppunitTest_sc_macros_test \
        CppunitTest_sc_new_cond_format_api \
        CppunitTest_sc_pdf_export \
diff --git a/sc/qa/unit/GoalSeekTest.cxx b/sc/qa/unit/GoalSeekTest.cxx
new file mode 100644
index 000000000000..ea0920ba8760
--- /dev/null
+++ b/sc/qa/unit/GoalSeekTest.cxx
@@ -0,0 +1,51 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <sal/config.h>
+
+#include "helper/qahelper.hxx"
+#include <comphelper/servicehelper.hxx>
+
+using namespace ::com::sun::star;
+
+class ScGoalSeekTest : public ScModelTestBase
+{
+public:
+    ScGoalSeekTest();
+};
+
+ScGoalSeekTest::ScGoalSeekTest()
+    : ScModelTestBase(u"/sc/qa/unit/data/"_ustr)
+{
+}
+
+CPPUNIT_TEST_FIXTURE(ScGoalSeekTest, testTdf161511)
+{
+    createScDoc();
+
+    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);
+
+    // 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_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Reply via email to