diff options
author | Eike Rathke <erack@redhat.com> | 2021-07-29 16:35:24 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2021-07-29 18:49:57 +0200 |
commit | c186d09f88d6a4992382a1d15b60db6dbed3a91b (patch) | |
tree | 10745f1e84ff78f7f9fd3b66ccd9f81a60df85a5 | |
parent | 8ede3362a2a32c7f74e73265599429840544029d (diff) |
Add NumberingIdentifier unit test, tdf#143526 related
Change-Id: I9d4df6f63dc9ebc90e99fecce14b3551c74f7f1a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119675
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Jenkins
-rw-r--r-- | i18npool/qa/cppunit/test_defaultnumberingprovider.cxx | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/i18npool/qa/cppunit/test_defaultnumberingprovider.cxx b/i18npool/qa/cppunit/test_defaultnumberingprovider.cxx index dbe55050a01c..4770abb93808 100644 --- a/i18npool/qa/cppunit/test_defaultnumberingprovider.cxx +++ b/i18npool/qa/cppunit/test_defaultnumberingprovider.cxx @@ -12,9 +12,12 @@ #include <com/sun/star/style/NumberingType.hpp> #include <com/sun/star/text/DefaultNumberingProvider.hpp> #include <com/sun/star/text/XNumberingFormatter.hpp> +#include <com/sun/star/text/XNumberingTypeInfo.hpp> #include <comphelper/propertyvalue.hxx> +#include <unordered_map> + using namespace ::com::sun::star; /// i18npool defaultnumberingprovider tests. @@ -22,6 +25,64 @@ class I18npoolDefaultnumberingproviderTest : public test::BootstrapFixture { }; +CPPUNIT_TEST_FIXTURE(I18npoolDefaultnumberingproviderTest, testNumberingIdentifiers) +{ + // All numbering identifiers must be unique. + std::unordered_map<OUString, sal_Int16> aMap; + std::vector<OString> aFail; + + uno::Reference<text::XNumberingTypeInfo> xFormatter( + text::DefaultNumberingProvider::create(mxComponentContext), uno::UNO_QUERY); + + // Do not use getSupportedNumberingTypes() because it depends on + // configuration whether CTL and CJK numberings are included or not. + // Also do not test for known values of + // offapi/com/sun/star/style/NumberingType.idl and miss newly added values. + // Instead, enumerate until an empty ID is returned but also check there + // are at least the known NumberingType values covered, just in case the + // table wasn't maintained. So this may have to be adapted from time to + // time. + constexpr sal_Int16 kLastKnown = css::style::NumberingType::NUMBER_LEGAL_KO; + for (sal_Int16 i = 0; i < SAL_MAX_INT16; ++i) + { + OUString aID(xFormatter->getNumberingIdentifier(i)); + if (aID.isEmpty() && i > kLastKnown) + break; // for + + switch (i) + { + case css::style::NumberingType::TRANSLITERATION: + // TODO: why does this have no identifier? + case css::style::NumberingType::NUMBER_UPPER_KO: + // FIXME: duplicate of NUMBER_UPPER_ZH_TW + case css::style::NumberingType::NUMBER_INDIC_DEVANAGARI: + // FIXME: duplicate of NUMBER_EAST_ARABIC_INDIC + case css::style::NumberingType::NUMBER_DIGITAL_KO: + // FIXME: duplicate of NUMBER_HANGUL_KO + case css::style::NumberingType::NUMBER_DIGITAL2_KO: + // FIXME: duplicate of NUMBER_LOWER_ZH + break; + default: + if (aID.isEmpty() || !aMap.insert(std::pair(aID, i)).second) + { + aFail.emplace_back( + "Numbering: " + OString::number(i) + " \"" + aID.toUtf8() + "\"" + + (aID.isEmpty() ? "" + : OString(" duplicate of " + OString::number(aMap[aID]))) + + "\n"); + } + } + } + + if (!aFail.empty()) + { + OString aMsg("Not unique numbering identifiers:\n"); + for (auto const& r : aFail) + aMsg += r; + CPPUNIT_ASSERT_MESSAGE(aMsg.getStr(), false); + } +} + CPPUNIT_TEST_FIXTURE(I18npoolDefaultnumberingproviderTest, testArabicZero) { // 1 -> "01" |