From 2a4e767ea83e49fafb639e66e74403c2ff9270ac Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Tue, 3 Mar 2020 09:27:01 +0100 Subject: sw padded numbering: add layout lcl_formatArabicZero() looks a bit over-complicated with its hardcoded limit of 2. Word supports limits of 3, 4 and 5 as well, so prepare for handling them in a generic way. (cherry picked from commit 642b7706101a991efc7e312f59dece640d8bfb60) Change-Id: If6e5634b11616f0ac05e1387016e22f4b171bbfb --- ...ppunitTest_i18npool_defaultnumberingprovider.mk | 44 +++++++++++++++++ i18npool/Module_i18npool.mk | 1 + .../qa/cppunit/test_defaultnumberingprovider.cxx | 57 ++++++++++++++++++++++ .../defaultnumberingprovider.cxx | 28 +++++++++++ 4 files changed, 130 insertions(+) create mode 100644 i18npool/CppunitTest_i18npool_defaultnumberingprovider.mk create mode 100644 i18npool/qa/cppunit/test_defaultnumberingprovider.cxx (limited to 'i18npool') diff --git a/i18npool/CppunitTest_i18npool_defaultnumberingprovider.mk b/i18npool/CppunitTest_i18npool_defaultnumberingprovider.mk new file mode 100644 index 000000000000..421affb90b35 --- /dev/null +++ b/i18npool/CppunitTest_i18npool_defaultnumberingprovider.mk @@ -0,0 +1,44 @@ +# -*- 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,i18npool_defaultnumberingprovider)) + +$(eval $(call gb_CppunitTest_use_externals,i18npool_defaultnumberingprovider,\ + boost_headers \ +)) + +$(eval $(call gb_CppunitTest_add_exception_objects,i18npool_defaultnumberingprovider, \ + i18npool/qa/cppunit/test_defaultnumberingprovider \ +)) + +$(eval $(call gb_CppunitTest_use_libraries,i18npool_defaultnumberingprovider, \ + comphelper \ + cppu \ + sal \ + test \ + unotest \ + utl \ +)) + +$(eval $(call gb_CppunitTest_use_sdk_api,i18npool_defaultnumberingprovider)) + +$(eval $(call gb_CppunitTest_use_ure,i18npool_defaultnumberingprovider)) +$(eval $(call gb_CppunitTest_use_vcl,i18npool_defaultnumberingprovider)) + +$(eval $(call gb_CppunitTest_use_rdb,i18npool_defaultnumberingprovider,services)) + +$(eval $(call gb_CppunitTest_use_custom_headers,i18npool_defaultnumberingprovider,\ + officecfg/registry \ +)) + +$(eval $(call gb_CppunitTest_use_configuration,i18npool_defaultnumberingprovider)) + +# vim: set noet sw=4 ts=4: diff --git a/i18npool/Module_i18npool.mk b/i18npool/Module_i18npool.mk index 0e1f5e6cef72..8a770bb4f0e3 100644 --- a/i18npool/Module_i18npool.mk +++ b/i18npool/Module_i18npool.mk @@ -43,6 +43,7 @@ $(eval $(call gb_Module_add_check_targets,i18npool,\ CppunitTest_i18npool_test_characterclassification \ CppunitTest_i18npool_test_ordinalsuffix \ CppunitTest_i18npool_test_textsearch \ + CppunitTest_i18npool_defaultnumberingprovider \ )) # vim: set noet sw=4 ts=4: diff --git a/i18npool/qa/cppunit/test_defaultnumberingprovider.cxx b/i18npool/qa/cppunit/test_defaultnumberingprovider.cxx new file mode 100644 index 000000000000..2a1cb55502e2 --- /dev/null +++ b/i18npool/qa/cppunit/test_defaultnumberingprovider.cxx @@ -0,0 +1,57 @@ +/* -*- 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 +#include + +#include +#include + +using namespace ::com::sun::star; + +/// i18npool defaultnumberingprovider tests. +class I18npoolDefaultnumberingproviderTest : public test::BootstrapFixture +{ +}; + +CPPUNIT_TEST_FIXTURE(I18npoolDefaultnumberingproviderTest, testArabicZero) +{ + uno::Reference xComponentContext + = comphelper::getComponentContext(getMultiServiceFactory()); + + // 1 -> "01" + uno::Reference xFormatter( + text::DefaultNumberingProvider::create(xComponentContext), uno::UNO_QUERY); + uno::Sequence aProperties = { + comphelper::makePropertyValue("NumberingType", + static_cast(style::NumberingType::ARABIC_ZERO)), + comphelper::makePropertyValue("Value", static_cast(1)), + }; + lang::Locale aLocale; + OUString aActual = xFormatter->makeNumberingString(aProperties, aLocale); + // Without the accompanying fix in place, this test would have failed with a + // lang.IllegalArgumentException, support for ARABIC_ZERO was missing. + CPPUNIT_ASSERT_EQUAL(OUString("01"), aActual); + + // 10 -> "10" + aProperties = { + comphelper::makePropertyValue("NumberingType", + static_cast(style::NumberingType::ARABIC_ZERO)), + comphelper::makePropertyValue("Value", static_cast(10)), + }; + aActual = xFormatter->makeNumberingString(aProperties, aLocale); + CPPUNIT_ASSERT_EQUAL(OUString("10"), aActual); +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/i18npool/source/defaultnumberingprovider/defaultnumberingprovider.cxx b/i18npool/source/defaultnumberingprovider/defaultnumberingprovider.cxx index a81b00143989..372837595708 100644 --- a/i18npool/source/defaultnumberingprovider/defaultnumberingprovider.cxx +++ b/i18npool/source/defaultnumberingprovider/defaultnumberingprovider.cxx @@ -552,6 +552,30 @@ bool should_ignore( const OUString& s ) return s == " " || (!s.isEmpty() && s[0]==0); } +/** + * Turn nNumber into a string and pad the result to 2 using zero characters. + */ +static OUString lcl_formatArabicZero(sal_Int32 nNumber) +{ + sal_Int32 nLimit = 2; + OUString aRet = OUString::number(nNumber); + sal_Int32 nDiff = nLimit - aRet.getLength(); + + if (nDiff <= 0) + { + return aRet; + } + + OUStringBuffer aBuffer; + aBuffer.setLength(nDiff); + for (sal_Int32 i = 0; i < nDiff; ++i) + { + aBuffer[i] = '0'; + } + aBuffer.append(aRet); + return aBuffer.makeStringAndClear(); +} + static Any getPropertyByName( const Sequence& aProperties, const char* name, bool bRequired ) @@ -913,6 +937,10 @@ DefaultNumberingProvider::makeNumberingString( const Sequence