Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / i18npool / qa / cppunit / test_characterclassification.cxx
blob846477d615f14d39a761c6d700accb9b9f4b3f0d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
10 #include <com/sun/star/i18n/XCharacterClassification.hpp>
11 #include <o3tl/cppunittraitshelper.hxx>
12 #include <unotest/bootstrapfixturebase.hxx>
14 using namespace ::com::sun::star;
16 class TestCharacterClassification : public test::BootstrapFixtureBase
18 public:
19 virtual void setUp() override;
20 virtual void tearDown() override;
22 void testTitleCase();
23 void testStringType();
25 CPPUNIT_TEST_SUITE(TestCharacterClassification);
26 CPPUNIT_TEST(testTitleCase);
27 CPPUNIT_TEST(testStringType);
28 CPPUNIT_TEST_SUITE_END();
29 private:
30 uno::Reference<i18n::XCharacterClassification> m_xCC;
33 //A test to ensure that our Title Case functionality is working
34 //http://lists.freedesktop.org/archives/libreoffice/2012-June/032767.html
35 //https://bz.apache.org/ooo/show_bug.cgi?id=30863
36 void TestCharacterClassification::testTitleCase()
38 lang::Locale aLocale;
39 aLocale.Language = "en";
40 aLocale.Country = "US";
43 //basic example
44 OUString sTest("Some text");
45 OUString sTitleCase = m_xCC->toTitle(sTest, 0, sTest.getLength(), aLocale);
46 CPPUNIT_ASSERT_EQUAL_MESSAGE("Should be title", OUString("Some Text"), sTitleCase);
47 OUString sUpperCase = m_xCC->toUpper(sTest, 0, sTest.getLength(), aLocale);
48 CPPUNIT_ASSERT_EQUAL_MESSAGE("Should be upper", OUString("SOME TEXT"), sUpperCase);
49 OUString sLowerCase = m_xCC->toLower(sTest, 0, sTest.getLength(), aLocale);
50 CPPUNIT_ASSERT_EQUAL_MESSAGE("Should be lower ", OUString("some text"), sLowerCase);
54 //tricky one
55 static constexpr OUStringLiteral aTest = u"\u01F3"; // LATIN SMALL LETTER DZ
56 OUString sTitleCase = m_xCC->toTitle(aTest, 0, aTest.getLength(), aLocale);
57 CPPUNIT_ASSERT_EQUAL_MESSAGE("Should be title", sal_Int32(1), sTitleCase.getLength());
58 CPPUNIT_ASSERT_EQUAL_MESSAGE("Should be title", u'\u01F2', sTitleCase[0]);
59 OUString sUpperCase = m_xCC->toUpper(aTest, 0, aTest.getLength(), aLocale);
60 CPPUNIT_ASSERT_EQUAL_MESSAGE("Should be upper", sal_Int32(1), sUpperCase.getLength());
61 CPPUNIT_ASSERT_EQUAL_MESSAGE("Should be upper", u'\u01F1', sUpperCase[0]);
62 OUString sLowerCase = m_xCC->toLower(aTest, 0, aTest.getLength(), aLocale);
63 CPPUNIT_ASSERT_EQUAL_MESSAGE("Should be lower ", sal_Int32(1), sLowerCase.getLength());
64 CPPUNIT_ASSERT_EQUAL_MESSAGE("Should be lower ", u'\u01F3', sLowerCase[0]);
68 //https://bugs.libreoffice.org/show_bug.cgi?id=69641
69 void TestCharacterClassification::testStringType()
71 lang::Locale aLocale;
72 aLocale.Language = "en";
73 aLocale.Country = "US";
76 //simple case
77 OUString sTest("Some text");
78 sal_Int32 nResult = m_xCC->getStringType(sTest, 0, sTest.getLength(), aLocale);
79 CPPUNIT_ASSERT_EQUAL(sal_Int32(230), nResult);
83 //tricky case
84 static constexpr OUStringLiteral sTest = u"\U0001D703"; // MATHEMATICAL ITALIC SMALL THETA
85 sal_Int32 nResult = m_xCC->getStringType(sTest, 0, sTest.getLength(), aLocale);
86 CPPUNIT_ASSERT_EQUAL(sal_Int32(228), nResult);
91 void TestCharacterClassification::setUp()
93 BootstrapFixtureBase::setUp();
94 m_xCC.set(m_xSFactory->createInstance("com.sun.star.i18n.CharacterClassification"), uno::UNO_QUERY_THROW);
97 void TestCharacterClassification::tearDown()
99 BootstrapFixtureBase::tearDown();
100 m_xCC.clear();
103 CPPUNIT_TEST_SUITE_REGISTRATION(TestCharacterClassification);
105 CPPUNIT_PLUGIN_IMPLEMENT();
107 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */