Add a unit test for LocalizeDigitsInString

Change-Id: I51fb04dbc542b4052a31e8c96552406a1d6947e7
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193461
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
Neil Roberts
2025-11-05 19:21:18 +01:00
committed by Noel Grandin
parent 117d9624a3
commit 95621a71f9
3 changed files with 91 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t; fill-column: 100 -*-
#
# 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,vcl_localize_digits))
$(eval $(call gb_CppunitTest_set_include,vcl_localize_digits,\
$$(INCLUDE) \
-I$(SRCDIR)/vcl/inc \
))
$(eval $(call gb_CppunitTest_add_exception_objects,vcl_localize_digits, \
vcl/qa/cppunit/LocalizeDigits \
))
$(eval $(call gb_CppunitTest_use_libraries,vcl_localize_digits, \
sal \
vcl \
))
# vim: set noet sw=4 ts=4:
+1
View File
@@ -254,6 +254,7 @@ $(eval $(call gb_Module_add_check_targets,vcl,\
CppunitTest_vcl_skia) \
CppunitTest_vcl_filter_igif \
CppunitTest_vcl_unit_conversion \
CppunitTest_vcl_localize_digits \
))
ifeq ($(USING_X11),TRUE)
+64
View File
@@ -0,0 +1,64 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* 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 <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/plugin/TestPlugIn.h>
#include <vcl/svapp.hxx>
namespace
{
CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, LocalDigits)
{
// Test the case where there are no digits to convert
OUString sNoDigits = "hello";
sal_Int32 nLen = sNoDigits.getLength();
// It should return the same string
CPPUNIT_ASSERT_EQUAL(reinterpret_cast<sal_uIntPtr>(sNoDigits.getStr()),
reinterpret_cast<sal_uIntPtr>(
LocalizeDigitsInString(sNoDigits, LANGUAGE_FARSI, 0, nLen).getStr()));
// The length should not change
CPPUNIT_ASSERT_EQUAL(sNoDigits.getLength(), nLen);
// Test the case where there are digits but they are already correct for the locale.
OUString sDozen = "There are 12 eggs in a dozen.";
nLen = sDozen.getLength();
// It should return the same string
CPPUNIT_ASSERT_EQUAL(reinterpret_cast<sal_uIntPtr>(sDozen.getStr()),
reinterpret_cast<sal_uIntPtr>(
LocalizeDigitsInString(sDozen, LANGUAGE_SYSTEM, 0, nLen).getStr()));
// The length should not change
CPPUNIT_ASSERT_EQUAL(sDozen.getLength(), nLen);
// Test an actual conversion
CPPUNIT_ASSERT_EQUAL(u"There are ۱۲ eggs in a dozen."_ustr,
LocalizeDigitsInString(sDozen, LANGUAGE_FARSI, 0, nLen));
CPPUNIT_ASSERT_EQUAL(sDozen.getLength(), nLen);
// Test converting a subrange
nLen = 12;
CPPUNIT_ASSERT_EQUAL(
u"There are ۱۲ eggs in a dozen but 13 in a baker's dozen."_ustr,
LocalizeDigitsInString("There are 12 eggs in a dozen but 13 in a baker's dozen.",
LANGUAGE_FARSI, 2, nLen));
CPPUNIT_ASSERT_EQUAL(sal_Int32(12), nLen);
// Test with characters outside of the bmp
CPPUNIT_ASSERT_EQUAL(
u"𐑞𐑺 𐑸 ۱۲ 𐑧𐑜𐑟 𐑦𐑯 𐑩 𐑚𐑱𐑒𐑼𐑟 𐑛𐑳𐑟𐑩𐑯."_ustr,
LocalizeDigitsInString(u"𐑞𐑺 𐑸 12 𐑧𐑜𐑟 𐑦𐑯 𐑩 𐑚𐑱𐑒𐑼𐑟 𐑛𐑳𐑟𐑩𐑯."_ustr, LANGUAGE_FARSI));
}
} // namespace
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */