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 <cppuhelper/bootstrap.hxx>
11 #include <cppuhelper/basemutex.hxx>
12 #include <com/sun/star/i18n/XCharacterClassification.hpp>
13 #include <unotest/bootstrapfixturebase.hxx>
15 #include <rtl/strbuf.hxx>
16 #include <rtl/ustrbuf.hxx>
20 using namespace ::com::sun::star
;
22 class TestCharacterClassification
: public test::BootstrapFixtureBase
25 virtual void setUp() override
;
26 virtual void tearDown() override
;
29 void testStringType();
31 CPPUNIT_TEST_SUITE(TestCharacterClassification
);
32 CPPUNIT_TEST(testTitleCase
);
33 CPPUNIT_TEST(testStringType
);
34 CPPUNIT_TEST_SUITE_END();
36 uno::Reference
<i18n::XCharacterClassification
> m_xCC
;
39 //A test to ensure that our Title Case functionality is working
40 //http://lists.freedesktop.org/archives/libreoffice/2012-June/032767.html
41 //https://bz.apache.org/ooo/show_bug.cgi?id=30863
42 void TestCharacterClassification::testTitleCase()
45 aLocale
.Language
= "en";
46 aLocale
.Country
= "US";
50 OUString
sTest("Some text");
51 OUString sTitleCase
= m_xCC
->toTitle(sTest
, 0, sTest
.getLength(), aLocale
);
52 CPPUNIT_ASSERT_EQUAL_MESSAGE("Should be title", OUString("Some Text"), sTitleCase
);
53 OUString sUpperCase
= m_xCC
->toUpper(sTest
, 0, sTest
.getLength(), aLocale
);
54 CPPUNIT_ASSERT_EQUAL_MESSAGE("Should be upper", OUString("SOME TEXT"), sUpperCase
);
55 OUString sLowerCase
= m_xCC
->toLower(sTest
, 0, sTest
.getLength(), aLocale
);
56 CPPUNIT_ASSERT_EQUAL_MESSAGE("Should be lower ", OUString("some text"), sLowerCase
);
61 const sal_Unicode LATINSMALLLETTERDZ
[] = { 0x01F3 };
62 OUString
aTest(LATINSMALLLETTERDZ
, SAL_N_ELEMENTS(LATINSMALLLETTERDZ
));
63 OUString sTitleCase
= m_xCC
->toTitle(aTest
, 0, aTest
.getLength(), aLocale
);
64 CPPUNIT_ASSERT_MESSAGE("Should be title", sTitleCase
.getLength() == 1 && sTitleCase
[0] == 0x01F2);
65 OUString sUpperCase
= m_xCC
->toUpper(aTest
, 0, aTest
.getLength(), aLocale
);
66 CPPUNIT_ASSERT_MESSAGE("Should be upper", sUpperCase
.getLength() == 1 && sUpperCase
[0] == 0x01F1);
67 OUString sLowerCase
= m_xCC
->toLower(aTest
, 0, aTest
.getLength(), aLocale
);
68 CPPUNIT_ASSERT_MESSAGE("Should be lower ", sLowerCase
.getLength() == 1 && sLowerCase
[0] == 0x01F3);
72 //https://bugs.libreoffice.org/show_bug.cgi?id=69641
73 void TestCharacterClassification::testStringType()
76 aLocale
.Language
= "en";
77 aLocale
.Country
= "US";
81 OUString
sTest("Some text");
82 sal_Int32 nResult
= m_xCC
->getStringType(sTest
, 0, sTest
.getLength(), aLocale
);
83 CPPUNIT_ASSERT_EQUAL(sal_Int32(230), nResult
);
88 const sal_Unicode MATHEMATICAL_ITALIC_SMALL_THETA
[] = { 0xD835, 0xDF03 };
89 OUString
sTest(MATHEMATICAL_ITALIC_SMALL_THETA
, SAL_N_ELEMENTS(MATHEMATICAL_ITALIC_SMALL_THETA
));
90 sal_Int32 nResult
= m_xCC
->getStringType(sTest
, 0, sTest
.getLength(), aLocale
);
91 CPPUNIT_ASSERT_EQUAL(sal_Int32(228), nResult
);
96 void TestCharacterClassification::setUp()
98 BootstrapFixtureBase::setUp();
99 m_xCC
.set(m_xSFactory
->createInstance("com.sun.star.i18n.CharacterClassification"), uno::UNO_QUERY_THROW
);
102 void TestCharacterClassification::tearDown()
104 BootstrapFixtureBase::tearDown();
108 CPPUNIT_TEST_SUITE_REGISTRATION(TestCharacterClassification
);
110 CPPUNIT_PLUGIN_IMPLEMENT();
112 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */