i18npool/qa/cppunit/test_defaultnumberingprovider.cxx |   61 ++++++++++++++++++
 1 file changed, 61 insertions(+)

New commits:
commit c186d09f88d6a4992382a1d15b60db6dbed3a91b
Author:     Eike Rathke <er...@redhat.com>
AuthorDate: Thu Jul 29 16:35:24 2021 +0200
Commit:     Eike Rathke <er...@redhat.com>
CommitDate: Thu Jul 29 18:49:57 2021 +0200

    Add NumberingIdentifier unit test, tdf#143526 related
    
    Change-Id: I9d4df6f63dc9ebc90e99fecce14b3551c74f7f1a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119675
    Reviewed-by: Eike Rathke <er...@redhat.com>
    Tested-by: Jenkins

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"
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to