1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include <test/bootstrapfixture.hxx>
12 #include <com/sun/star/style/NumberingType.hpp>
13 #include <com/sun/star/text/DefaultNumberingProvider.hpp>
14 #include <com/sun/star/text/XNumberingFormatter.hpp>
15 #include <com/sun/star/text/XNumberingTypeInfo.hpp>
17 #include <comphelper/propertyvalue.hxx>
19 #include <unordered_map>
21 using namespace ::com::sun::star
;
23 /// i18npool defaultnumberingprovider tests.
24 class I18npoolDefaultnumberingproviderTest
: public test::BootstrapFixture
28 CPPUNIT_TEST_FIXTURE(I18npoolDefaultnumberingproviderTest
, testNumberingIdentifiers
)
30 // All numbering identifiers must be unique.
31 std::unordered_map
<OUString
, sal_Int16
> aMap
;
32 std::vector
<OString
> aFail
;
34 uno::Reference
<text::XNumberingTypeInfo
> xFormatter(
35 text::DefaultNumberingProvider::create(mxComponentContext
), uno::UNO_QUERY
);
37 // Do not use getSupportedNumberingTypes() because it depends on
38 // configuration whether CTL and CJK numberings are included or not.
39 // Also do not test for known values of
40 // offapi/com/sun/star/style/NumberingType.idl and miss newly added values.
41 // Instead, enumerate until an empty ID is returned but also check there
42 // are at least the known NumberingType values covered, just in case the
43 // table wasn't maintained. So this may have to be adapted from time to
45 constexpr sal_Int16 kLastKnown
= css::style::NumberingType::NUMBER_LEGAL_KO
;
46 for (sal_Int16 i
= 0; i
< SAL_MAX_INT16
; ++i
)
48 OUString
aID(xFormatter
->getNumberingIdentifier(i
));
49 if (aID
.isEmpty() && i
> kLastKnown
)
54 case css::style::NumberingType::TRANSLITERATION
:
55 // TODO: why does this have no identifier?
56 case css::style::NumberingType::NUMBER_UPPER_KO
:
57 // FIXME: duplicate of NUMBER_UPPER_ZH_TW
58 case css::style::NumberingType::NUMBER_INDIC_DEVANAGARI
:
59 // FIXME: duplicate of NUMBER_EAST_ARABIC_INDIC
62 if (aID
.isEmpty() || !aMap
.insert(std::pair(aID
, i
)).second
)
65 "Numbering: " + OString::number(i
) + " \"" + aID
.toUtf8() + "\""
67 : OString(" duplicate of " + OString::number(aMap
[aID
])))
75 OString
aMsg("Not unique numbering identifiers:\n");
76 for (auto const& r
: aFail
)
78 CPPUNIT_ASSERT_MESSAGE(aMsg
.getStr(), false);
82 CPPUNIT_TEST_FIXTURE(I18npoolDefaultnumberingproviderTest
, testArabicZero
)
85 uno::Reference
<text::XNumberingFormatter
> xFormatter(
86 text::DefaultNumberingProvider::create(mxComponentContext
), uno::UNO_QUERY
);
87 uno::Sequence
<beans::PropertyValue
> aProperties
= {
88 comphelper::makePropertyValue("NumberingType",
89 static_cast<sal_uInt16
>(style::NumberingType::ARABIC_ZERO
)),
90 comphelper::makePropertyValue("Value", static_cast<sal_Int32
>(1)),
93 OUString aActual
= xFormatter
->makeNumberingString(aProperties
, aLocale
);
94 // Without the accompanying fix in place, this test would have failed with a
95 // lang.IllegalArgumentException, support for ARABIC_ZERO was missing.
96 CPPUNIT_ASSERT_EQUAL(OUString("01"), aActual
);
100 comphelper::makePropertyValue("NumberingType",
101 static_cast<sal_uInt16
>(style::NumberingType::ARABIC_ZERO
)),
102 comphelper::makePropertyValue("Value", static_cast<sal_Int32
>(10)),
104 aActual
= xFormatter
->makeNumberingString(aProperties
, aLocale
);
105 CPPUNIT_ASSERT_EQUAL(OUString("10"), aActual
);
108 CPPUNIT_TEST_FIXTURE(I18npoolDefaultnumberingproviderTest
, testArabicZero3
)
111 uno::Reference
<text::XNumberingFormatter
> xFormatter(
112 text::DefaultNumberingProvider::create(mxComponentContext
), uno::UNO_QUERY
);
113 uno::Sequence
<beans::PropertyValue
> aProperties
= {
114 comphelper::makePropertyValue("NumberingType",
115 static_cast<sal_uInt16
>(style::NumberingType::ARABIC_ZERO3
)),
116 comphelper::makePropertyValue("Value", static_cast<sal_Int32
>(10)),
118 lang::Locale aLocale
;
119 OUString aActual
= xFormatter
->makeNumberingString(aProperties
, aLocale
);
120 // Without the accompanying fix in place, this test would have failed with a
121 // lang.IllegalArgumentException, support for ARABIC_ZERO3 was missing.
122 CPPUNIT_ASSERT_EQUAL(OUString("010"), aActual
);
126 comphelper::makePropertyValue("NumberingType",
127 static_cast<sal_uInt16
>(style::NumberingType::ARABIC_ZERO3
)),
128 comphelper::makePropertyValue("Value", static_cast<sal_Int32
>(100)),
130 aActual
= xFormatter
->makeNumberingString(aProperties
, aLocale
);
131 CPPUNIT_ASSERT_EQUAL(OUString("100"), aActual
);
134 CPPUNIT_TEST_FIXTURE(I18npoolDefaultnumberingproviderTest
, testArabicZero4
)
137 uno::Reference
<text::XNumberingFormatter
> xFormatter(
138 text::DefaultNumberingProvider::create(mxComponentContext
), uno::UNO_QUERY
);
139 uno::Sequence
<beans::PropertyValue
> aProperties
= {
140 comphelper::makePropertyValue("NumberingType",
141 static_cast<sal_uInt16
>(style::NumberingType::ARABIC_ZERO4
)),
142 comphelper::makePropertyValue("Value", static_cast<sal_Int32
>(100)),
144 lang::Locale aLocale
;
145 OUString aActual
= xFormatter
->makeNumberingString(aProperties
, aLocale
);
146 // Without the accompanying fix in place, this test would have failed with a
147 // lang.IllegalArgumentException, support for ARABIC_ZERO4 was missing.
148 CPPUNIT_ASSERT_EQUAL(OUString("0100"), aActual
);
152 comphelper::makePropertyValue("NumberingType",
153 static_cast<sal_uInt16
>(style::NumberingType::ARABIC_ZERO4
)),
154 comphelper::makePropertyValue("Value", static_cast<sal_Int32
>(1000)),
156 aActual
= xFormatter
->makeNumberingString(aProperties
, aLocale
);
157 CPPUNIT_ASSERT_EQUAL(OUString("1000"), aActual
);
160 CPPUNIT_TEST_FIXTURE(I18npoolDefaultnumberingproviderTest
, testArabicZero5
)
163 uno::Reference
<text::XNumberingFormatter
> xFormatter(
164 text::DefaultNumberingProvider::create(mxComponentContext
), uno::UNO_QUERY
);
165 uno::Sequence
<beans::PropertyValue
> aProperties
= {
166 comphelper::makePropertyValue("NumberingType",
167 static_cast<sal_uInt16
>(style::NumberingType::ARABIC_ZERO5
)),
168 comphelper::makePropertyValue("Value", static_cast<sal_Int32
>(1000)),
170 lang::Locale aLocale
;
171 OUString aActual
= xFormatter
->makeNumberingString(aProperties
, aLocale
);
172 // Without the accompanying fix in place, this test would have failed with a
173 // lang.IllegalArgumentException, support for ARABIC_ZERO5 was missing.
174 CPPUNIT_ASSERT_EQUAL(OUString("01000"), aActual
);
178 comphelper::makePropertyValue("NumberingType",
179 static_cast<sal_uInt16
>(style::NumberingType::ARABIC_ZERO5
)),
180 comphelper::makePropertyValue("Value", static_cast<sal_Int32
>(10000)),
182 aActual
= xFormatter
->makeNumberingString(aProperties
, aLocale
);
183 CPPUNIT_ASSERT_EQUAL(OUString("10000"), aActual
);
186 CPPUNIT_TEST_FIXTURE(I18npoolDefaultnumberingproviderTest
, testKoreanCounting
)
189 uno::Reference
<text::XNumberingFormatter
> xFormatter(
190 text::DefaultNumberingProvider::create(mxComponentContext
), uno::UNO_QUERY
);
191 uno::Sequence
<beans::PropertyValue
> aProperties
= {
192 comphelper::makePropertyValue(
193 "NumberingType", static_cast<sal_uInt16
>(style::NumberingType::NUMBER_HANGUL_KO
)),
194 comphelper::makePropertyValue("Value", static_cast<sal_Int32
>(1)),
196 lang::Locale aLocale
;
197 OUString aActual
= xFormatter
->makeNumberingString(aProperties
, aLocale
);
198 // Without the accompanying fix in place, this test would have failed with a
199 // lang.IllegalArgumentException, support for NUMBER_HANGUL_KO was missing.
200 CPPUNIT_ASSERT_EQUAL(OUString(u
"\uc77c"), aActual
);
204 comphelper::makePropertyValue(
205 "NumberingType", static_cast<sal_uInt16
>(style::NumberingType::NUMBER_HANGUL_KO
)),
206 comphelper::makePropertyValue("Value", static_cast<sal_Int32
>(10)),
208 aActual
= xFormatter
->makeNumberingString(aProperties
, aLocale
);
209 CPPUNIT_ASSERT_EQUAL(OUString(u
"\uc2ed"), aActual
);
213 comphelper::makePropertyValue(
214 "NumberingType", static_cast<sal_uInt16
>(style::NumberingType::NUMBER_HANGUL_KO
)),
215 comphelper::makePropertyValue("Value", static_cast<sal_Int32
>(100)),
217 aActual
= xFormatter
->makeNumberingString(aProperties
, aLocale
);
218 CPPUNIT_ASSERT_EQUAL(OUString(u
"\ubc31"), aActual
);
221 CPPUNIT_TEST_FIXTURE(I18npoolDefaultnumberingproviderTest
, testKoreanLegal
)
224 uno::Reference
<text::XNumberingFormatter
> xFormatter(
225 text::DefaultNumberingProvider::create(mxComponentContext
), uno::UNO_QUERY
);
226 uno::Sequence
<beans::PropertyValue
> aProperties
= {
227 comphelper::makePropertyValue(
228 "NumberingType", static_cast<sal_uInt16
>(style::NumberingType::NUMBER_LEGAL_KO
)),
229 comphelper::makePropertyValue("Value", static_cast<sal_Int32
>(1)),
231 lang::Locale aLocale
;
232 OUString aActual
= xFormatter
->makeNumberingString(aProperties
, aLocale
);
233 // Without the accompanying fix in place, this test would have failed with a
234 // lang.IllegalArgumentException, support for NUMBER_LEGAL_KO was missing.
235 CPPUNIT_ASSERT_EQUAL(OUString(u
"\ud558\ub098"), aActual
);
239 comphelper::makePropertyValue(
240 "NumberingType", static_cast<sal_uInt16
>(style::NumberingType::NUMBER_LEGAL_KO
)),
241 comphelper::makePropertyValue("Value", static_cast<sal_Int32
>(2)),
243 aActual
= xFormatter
->makeNumberingString(aProperties
, aLocale
);
244 CPPUNIT_ASSERT_EQUAL(OUString(u
"\ub458"), aActual
);
248 comphelper::makePropertyValue(
249 "NumberingType", static_cast<sal_uInt16
>(style::NumberingType::NUMBER_LEGAL_KO
)),
250 comphelper::makePropertyValue("Value", static_cast<sal_Int32
>(3)),
252 aActual
= xFormatter
->makeNumberingString(aProperties
, aLocale
);
253 CPPUNIT_ASSERT_EQUAL(OUString(u
"\uc14b"), aActual
);
257 comphelper::makePropertyValue(
258 "NumberingType", static_cast<sal_uInt16
>(style::NumberingType::NUMBER_LEGAL_KO
)),
259 comphelper::makePropertyValue("Value", static_cast<sal_Int32
>(4)),
261 aActual
= xFormatter
->makeNumberingString(aProperties
, aLocale
);
262 CPPUNIT_ASSERT_EQUAL(OUString(u
"\ub137"), aActual
);
266 comphelper::makePropertyValue(
267 "NumberingType", static_cast<sal_uInt16
>(style::NumberingType::NUMBER_LEGAL_KO
)),
268 comphelper::makePropertyValue("Value", static_cast<sal_Int32
>(5)),
270 aActual
= xFormatter
->makeNumberingString(aProperties
, aLocale
);
271 CPPUNIT_ASSERT_EQUAL(OUString(u
"\ub2e4\uc12f"), aActual
);
274 comphelper::makePropertyValue(
275 "NumberingType", static_cast<sal_uInt16
>(style::NumberingType::NUMBER_LEGAL_KO
)),
276 comphelper::makePropertyValue("Value", static_cast<sal_Int32
>(6)),
278 aActual
= xFormatter
->makeNumberingString(aProperties
, aLocale
);
279 CPPUNIT_ASSERT_EQUAL(OUString(u
"\uc5ec\uc12f"), aActual
);
282 comphelper::makePropertyValue(
283 "NumberingType", static_cast<sal_uInt16
>(style::NumberingType::NUMBER_LEGAL_KO
)),
284 comphelper::makePropertyValue("Value", static_cast<sal_Int32
>(7)),
286 aActual
= xFormatter
->makeNumberingString(aProperties
, aLocale
);
287 CPPUNIT_ASSERT_EQUAL(OUString(u
"\uc77c\uacf1"), aActual
);
291 comphelper::makePropertyValue(
292 "NumberingType", static_cast<sal_uInt16
>(style::NumberingType::NUMBER_LEGAL_KO
)),
293 comphelper::makePropertyValue("Value", static_cast<sal_Int32
>(8)),
295 aActual
= xFormatter
->makeNumberingString(aProperties
, aLocale
);
296 CPPUNIT_ASSERT_EQUAL(OUString(u
"\uc5ec\ub35f"), aActual
);
300 comphelper::makePropertyValue(
301 "NumberingType", static_cast<sal_uInt16
>(style::NumberingType::NUMBER_LEGAL_KO
)),
302 comphelper::makePropertyValue("Value", static_cast<sal_Int32
>(9)),
304 aActual
= xFormatter
->makeNumberingString(aProperties
, aLocale
);
305 CPPUNIT_ASSERT_EQUAL(OUString(u
"\uc544\ud649"), aActual
);
309 comphelper::makePropertyValue(
310 "NumberingType", static_cast<sal_uInt16
>(style::NumberingType::NUMBER_LEGAL_KO
)),
311 comphelper::makePropertyValue("Value", static_cast<sal_Int32
>(10)),
313 aActual
= xFormatter
->makeNumberingString(aProperties
, aLocale
);
314 CPPUNIT_ASSERT_EQUAL(OUString(u
"\uc5f4"), aActual
);
318 comphelper::makePropertyValue(
319 "NumberingType", static_cast<sal_uInt16
>(style::NumberingType::NUMBER_LEGAL_KO
)),
320 comphelper::makePropertyValue("Value", static_cast<sal_Int32
>(21)),
322 aActual
= xFormatter
->makeNumberingString(aProperties
, aLocale
);
323 CPPUNIT_ASSERT_EQUAL(OUString(u
"\uc2a4\ubb3c\ud558\ub098"), aActual
);
327 comphelper::makePropertyValue(
328 "NumberingType", static_cast<sal_uInt16
>(style::NumberingType::NUMBER_LEGAL_KO
)),
329 comphelper::makePropertyValue("Value", static_cast<sal_Int32
>(32)),
331 aActual
= xFormatter
->makeNumberingString(aProperties
, aLocale
);
332 CPPUNIT_ASSERT_EQUAL(OUString(u
"\uc11c\ub978\ub458"), aActual
);
336 comphelper::makePropertyValue(
337 "NumberingType", static_cast<sal_uInt16
>(style::NumberingType::NUMBER_LEGAL_KO
)),
338 comphelper::makePropertyValue("Value", static_cast<sal_Int32
>(43)),
340 aActual
= xFormatter
->makeNumberingString(aProperties
, aLocale
);
341 CPPUNIT_ASSERT_EQUAL(OUString(u
"\ub9c8\ud754\uc14b"), aActual
);
345 comphelper::makePropertyValue(
346 "NumberingType", static_cast<sal_uInt16
>(style::NumberingType::NUMBER_LEGAL_KO
)),
347 comphelper::makePropertyValue("Value", static_cast<sal_Int32
>(54)),
349 aActual
= xFormatter
->makeNumberingString(aProperties
, aLocale
);
350 CPPUNIT_ASSERT_EQUAL(OUString(u
"\uc270\ub137"), aActual
);
354 comphelper::makePropertyValue(
355 "NumberingType", static_cast<sal_uInt16
>(style::NumberingType::NUMBER_LEGAL_KO
)),
356 comphelper::makePropertyValue("Value", static_cast<sal_Int32
>(65)),
358 aActual
= xFormatter
->makeNumberingString(aProperties
, aLocale
);
359 CPPUNIT_ASSERT_EQUAL(OUString(u
"\uc608\uc21c\ub2e4\uc12f"), aActual
);
363 comphelper::makePropertyValue(
364 "NumberingType", static_cast<sal_uInt16
>(style::NumberingType::NUMBER_LEGAL_KO
)),
365 comphelper::makePropertyValue("Value", static_cast<sal_Int32
>(76)),
367 aActual
= xFormatter
->makeNumberingString(aProperties
, aLocale
);
368 CPPUNIT_ASSERT_EQUAL(OUString(u
"\uc77c\ud754\uc5ec\uc12f"), aActual
);
372 comphelper::makePropertyValue(
373 "NumberingType", static_cast<sal_uInt16
>(style::NumberingType::NUMBER_LEGAL_KO
)),
374 comphelper::makePropertyValue("Value", static_cast<sal_Int32
>(87)),
376 aActual
= xFormatter
->makeNumberingString(aProperties
, aLocale
);
377 CPPUNIT_ASSERT_EQUAL(OUString(u
"\uc5ec\ub4e0\uc77c\uacf1"), aActual
);
381 comphelper::makePropertyValue(
382 "NumberingType", static_cast<sal_uInt16
>(style::NumberingType::NUMBER_LEGAL_KO
)),
383 comphelper::makePropertyValue("Value", static_cast<sal_Int32
>(98)),
385 aActual
= xFormatter
->makeNumberingString(aProperties
, aLocale
);
386 CPPUNIT_ASSERT_EQUAL(OUString(u
"\uc544\ud754\uc5ec\ub35f"), aActual
);
390 comphelper::makePropertyValue(
391 "NumberingType", static_cast<sal_uInt16
>(style::NumberingType::NUMBER_LEGAL_KO
)),
392 comphelper::makePropertyValue("Value", static_cast<sal_Int32
>(99)),
394 aActual
= xFormatter
->makeNumberingString(aProperties
, aLocale
);
395 CPPUNIT_ASSERT_EQUAL(OUString(u
"\uc544\ud754\uc544\ud649"), aActual
);
398 CPPUNIT_TEST_FIXTURE(I18npoolDefaultnumberingproviderTest
, testKoreanDigital
)
401 uno::Reference
<text::XNumberingFormatter
> xFormatter(
402 text::DefaultNumberingProvider::create(mxComponentContext
), uno::UNO_QUERY
);
403 uno::Sequence
<beans::PropertyValue
> aProperties
= {
404 comphelper::makePropertyValue(
405 "NumberingType", static_cast<sal_uInt16
>(style::NumberingType::NUMBER_DIGITAL_KO
)),
406 comphelper::makePropertyValue("Value", static_cast<sal_Int32
>(1)),
408 lang::Locale aLocale
;
409 OUString aActual
= xFormatter
->makeNumberingString(aProperties
, aLocale
);
410 // Without the accompanying fix in place, this test would have failed with a
411 // lang.IllegalArgumentException, support for NUMBER_DIGITAL_KO was missing.
412 CPPUNIT_ASSERT_EQUAL(OUString(u
"\uc77c"), aActual
);
416 comphelper::makePropertyValue(
417 "NumberingType", static_cast<sal_uInt16
>(style::NumberingType::NUMBER_DIGITAL_KO
)),
418 comphelper::makePropertyValue("Value", static_cast<sal_Int32
>(10)),
420 aActual
= xFormatter
->makeNumberingString(aProperties
, aLocale
);
421 CPPUNIT_ASSERT_EQUAL(OUString(u
"\uc77c\uc601"), aActual
);
425 comphelper::makePropertyValue(
426 "NumberingType", static_cast<sal_uInt16
>(style::NumberingType::NUMBER_DIGITAL_KO
)),
427 comphelper::makePropertyValue("Value", static_cast<sal_Int32
>(100)),
429 aActual
= xFormatter
->makeNumberingString(aProperties
, aLocale
);
430 CPPUNIT_ASSERT_EQUAL(OUString(u
"\uc77c\uc601\uc601"), aActual
);
433 CPPUNIT_TEST_FIXTURE(I18npoolDefaultnumberingproviderTest
, testKoreanDigital2
)
436 uno::Reference
<text::XNumberingFormatter
> xFormatter(
437 text::DefaultNumberingProvider::create(mxComponentContext
), uno::UNO_QUERY
);
438 uno::Sequence
<beans::PropertyValue
> aProperties
= {
439 comphelper::makePropertyValue(
440 "NumberingType", static_cast<sal_uInt16
>(style::NumberingType::NUMBER_DIGITAL2_KO
)),
441 comphelper::makePropertyValue("Value", static_cast<sal_Int32
>(1)),
443 lang::Locale aLocale
;
444 OUString aActual
= xFormatter
->makeNumberingString(aProperties
, aLocale
);
445 // Without the accompanying fix in place, this test would have failed with a
446 // lang.IllegalArgumentException, support for NUMBER_DIGITAL2_KO was missing.
447 CPPUNIT_ASSERT_EQUAL(OUString(u
"\u4e00"), aActual
);
451 comphelper::makePropertyValue(
452 "NumberingType", static_cast<sal_uInt16
>(style::NumberingType::NUMBER_DIGITAL2_KO
)),
453 comphelper::makePropertyValue("Value", static_cast<sal_Int32
>(10)),
455 aActual
= xFormatter
->makeNumberingString(aProperties
, aLocale
);
456 CPPUNIT_ASSERT_EQUAL(OUString(u
"\u4e00\u96f6"), aActual
);
460 comphelper::makePropertyValue(
461 "NumberingType", static_cast<sal_uInt16
>(style::NumberingType::NUMBER_DIGITAL2_KO
)),
462 comphelper::makePropertyValue("Value", static_cast<sal_Int32
>(100)),
464 aActual
= xFormatter
->makeNumberingString(aProperties
, aLocale
);
465 CPPUNIT_ASSERT_EQUAL(OUString(u
"\u4e00\u96f6\u96f6"), aActual
);
468 CPPUNIT_PLUGIN_IMPLEMENT();
470 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */