From 93987194f5dee2b917e32c18b8a377be95f0ab71 Mon Sep 17 00:00:00 2001 From: Xisco Fauli Date: Fri, 28 Jun 2024 15:17:56 +0200 Subject: [PATCH] tdf#92029: sw_autocorrect: Add unittest Change-Id: I7ac855ac826353869c3a905ea70448d0c8dc1b76 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/169711 Tested-by: Jenkins Reviewed-by: Xisco Fauli --- sw/CppunitTest_sw_autocorrect.mk | 78 ++++++++++++++++++++++++ sw/Module_sw.mk | 1 + sw/qa/extras/autocorrect/autocorrect.cxx | 43 +++++++++++++ sw/qa/extras/autocorrect/data/nl-BE.fodt | 14 +++++ 4 files changed, 136 insertions(+) create mode 100644 sw/CppunitTest_sw_autocorrect.mk create mode 100644 sw/qa/extras/autocorrect/autocorrect.cxx create mode 100644 sw/qa/extras/autocorrect/data/nl-BE.fodt diff --git a/sw/CppunitTest_sw_autocorrect.mk b/sw/CppunitTest_sw_autocorrect.mk new file mode 100644 index 000000000000..7122b48b3d45 --- /dev/null +++ b/sw/CppunitTest_sw_autocorrect.mk @@ -0,0 +1,78 @@ +# -*- 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,sw_autocorrect)) + +$(eval $(call gb_CppunitTest_use_common_precompiled_header,sw_autocorrect)) + +$(eval $(call gb_CppunitTest_add_exception_objects,sw_autocorrect, \ + sw/qa/extras/autocorrect/autocorrect \ +)) + +$(eval $(call gb_CppunitTest_use_libraries,sw_autocorrect, \ + comphelper \ + cppu \ + cppuhelper \ + editeng \ + sal \ + sfx \ + subsequenttest \ + svl \ + svx \ + svxcore \ + sw \ + swqahelper \ + test \ + unotest \ + utl \ + vcl \ + tl \ +)) + +$(eval $(call gb_CppunitTest_use_externals,sw_autocorrect,\ + boost_headers \ + libxml2 \ +)) + +$(eval $(call gb_CppunitTest_set_include,sw_autocorrect,\ + -I$(SRCDIR)/sw/inc \ + -I$(SRCDIR)/sw/source/core/inc \ + -I$(SRCDIR)/sw/source/uibase/inc \ + -I$(SRCDIR)/sw/qa/inc \ + $$(INCLUDE) \ +)) + +$(eval $(call gb_CppunitTest_use_api,sw_autocorrect,\ + udkapi \ + offapi \ + oovbaapi \ +)) + +$(eval $(call gb_CppunitTest_use_ure,sw_autocorrect)) +$(eval $(call gb_CppunitTest_use_vcl,sw_autocorrect)) + +$(eval $(call gb_CppunitTest_use_rdb,sw_autocorrect,services)) + +$(eval $(call gb_CppunitTest_use_custom_headers,sw_autocorrect,\ + officecfg/registry \ +)) + +$(eval $(call gb_CppunitTest_use_configuration,sw_autocorrect)) + +$(eval $(call gb_CppunitTest_use_uiconfigs,sw_autocorrect, \ + modules/swriter \ +)) + +$(eval $(call gb_CppunitTest_use_more_fonts,sw_autocorrect)) + +ifneq ($(filter MORE_FONTS,$(BUILD_TYPE)),) +$(eval $(call gb_CppunitTest_set_non_application_font_use,sw_autocorrect,abort)) +endif + +# vim: set noet sw=4 ts=4: diff --git a/sw/Module_sw.mk b/sw/Module_sw.mk index 2db6fbace5f5..941de1a43ff7 100644 --- a/sw/Module_sw.mk +++ b/sw/Module_sw.mk @@ -136,6 +136,7 @@ $(eval $(call gb_Module_add_slowcheck_targets,sw,\ CppunitTest_sw_accessible_relation_set \ CppunitTest_sw_apiterminate \ CppunitTest_sw_apitests \ + CppunitTest_sw_autocorrect \ CppunitTest_sw_unowriter \ CppunitTest_sw_core_text \ CppunitTest_sw_core_doc \ diff --git a/sw/qa/extras/autocorrect/autocorrect.cxx b/sw/qa/extras/autocorrect/autocorrect.cxx new file mode 100644 index 000000000000..bc06aaece662 --- /dev/null +++ b/sw/qa/extras/autocorrect/autocorrect.cxx @@ -0,0 +1,43 @@ +/* -*- 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 +#include + +// If you want to add a test for a language that doesn't exists yet +// copy an existing document and adapt "fo:language" and "fo:country" + +class SwAutoCorrect : public SwModelTestBase +{ +public: + SwAutoCorrect() + : SwModelTestBase(u"/sw/qa/extras/autocorrect/data/"_ustr) + { + } +}; + +CPPUNIT_TEST_FIXTURE(SwAutoCorrect, nl_BE) +{ + createSwDoc("nl-BE.fodt"); + + SwXTextDocument* pTextDoc = dynamic_cast(mxComponent.get()); + + // tdf#92029: Without the fix in place, this test would have failed with + // - Expected: Ik ben ’s morgens opgestaan + // - Actual : Ik ben ‘s morgens opgestaan + emulateTyping(*pTextDoc, u"Ik ben 's morgens opgestaan"); + OUString sReplaced(u"Ik ben ’s morgens opgestaan"_ustr); + CPPUNIT_ASSERT_EQUAL(sReplaced, getParagraph(1)->getString()); +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/qa/extras/autocorrect/data/nl-BE.fodt b/sw/qa/extras/autocorrect/data/nl-BE.fodt new file mode 100644 index 000000000000..06843555cb5d --- /dev/null +++ b/sw/qa/extras/autocorrect/data/nl-BE.fodt @@ -0,0 +1,14 @@ + + + + + + + + + + + + + +