From f1872f6e47478dfd990c0031e823624de60fa079 Mon Sep 17 00:00:00 2001 From: Xisco Fauli Date: Fri, 14 Jun 2024 14:40:05 +0200 Subject: [PATCH] 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 --- sc/CppunitTest_sc_goal_seek_test.mk | 76 +++++++++++++++++++++++++++++ sc/Module_sc.mk | 1 + sc/qa/unit/GoalSeekTest.cxx | 51 +++++++++++++++++++ 3 files changed, 128 insertions(+) create mode 100644 sc/CppunitTest_sc_goal_seek_test.mk create mode 100644 sc/qa/unit/GoalSeekTest.cxx 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 + +#include "helper/qahelper.hxx" +#include + +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(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: */