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/compbase1.hxx>
11 #include <cppuhelper/bootstrap.hxx>
12 #include <cppuhelper/basemutex.hxx>
13 #include <com/sun/star/i18n/XCharacterClassification.hpp>
14 #include <unotest/bootstrapfixturebase.hxx>
16 #include <rtl/strbuf.hxx>
17 #include <rtl/ustrbuf.hxx>
21 using namespace ::com::sun::star
;
23 class TestCharacterClassification
: public test::BootstrapFixtureBase
27 virtual void tearDown();
30 void testStringType();
32 CPPUNIT_TEST_SUITE(TestCharacterClassification
);
33 CPPUNIT_TEST(testTitleCase
);
34 CPPUNIT_TEST(testStringType
);
35 CPPUNIT_TEST_SUITE_END();
37 uno::Reference
<i18n::XCharacterClassification
> m_xCC
;
40 //A test to ensure that our Title Case functionality is working
41 //http://lists.freedesktop.org/archives/libreoffice/2012-June/032767.html
42 //https://issues.apache.org/ooo/show_bug.cgi?id=30863
43 void TestCharacterClassification::testTitleCase()
46 aLocale
.Language
= "en";
47 aLocale
.Country
= "US";
51 OUString
sTest("Some text");
52 OUString sTitleCase
= m_xCC
->toTitle(sTest
, 0, sTest
.getLength(), aLocale
);
53 CPPUNIT_ASSERT_MESSAGE("Should be title", sTitleCase
== "Some Text");
54 OUString sUpperCase
= m_xCC
->toUpper(sTest
, 0, sTest
.getLength(), aLocale
);
55 CPPUNIT_ASSERT_MESSAGE("Should be upper", sUpperCase
== "SOME TEXT");
56 OUString sLowerCase
= m_xCC
->toLower(sTest
, 0, sTest
.getLength(), aLocale
);
57 CPPUNIT_ASSERT_MESSAGE("Should be lower ", sLowerCase
== "some text");
62 const sal_Unicode LATINSMALLLETTERDZ
[] = { 0x01F3 };
63 OUString
aTest(LATINSMALLLETTERDZ
, SAL_N_ELEMENTS(LATINSMALLLETTERDZ
));
64 OUString sTitleCase
= m_xCC
->toTitle(aTest
, 0, aTest
.getLength(), aLocale
);
65 CPPUNIT_ASSERT_MESSAGE("Should be title", sTitleCase
.getLength() == 1 && sTitleCase
[0] == 0x01F2);
66 OUString sUpperCase
= m_xCC
->toUpper(aTest
, 0, aTest
.getLength(), aLocale
);
67 CPPUNIT_ASSERT_MESSAGE("Should be upper", sUpperCase
.getLength() == 1 && sUpperCase
[0] == 0x01F1);
68 OUString sLowerCase
= m_xCC
->toLower(aTest
, 0, aTest
.getLength(), aLocale
);
69 CPPUNIT_ASSERT_MESSAGE("Should be lower ", sLowerCase
.getLength() == 1 && sLowerCase
[0] == 0x01F3);
73 //https://bugs.libreoffice.org/show_bug.cgi?id=69641
74 void TestCharacterClassification::testStringType()
77 aLocale
.Language
= "en";
78 aLocale
.Country
= "US";
82 OUString
sTest("Some text");
83 sal_Int32 nResult
= m_xCC
->getStringType(sTest
, 0, sTest
.getLength(), aLocale
);
84 CPPUNIT_ASSERT_EQUAL(nResult
, sal_Int32(230));
89 const sal_Unicode MATHEMATICAL_ITALIC_SMALL_THETA
[] = { 0xD835, 0xDF03 };
90 OUString
sTest(MATHEMATICAL_ITALIC_SMALL_THETA
, SAL_N_ELEMENTS(MATHEMATICAL_ITALIC_SMALL_THETA
));
91 sal_Int32 nResult
= m_xCC
->getStringType(sTest
, 0, sTest
.getLength(), aLocale
);
92 CPPUNIT_ASSERT_EQUAL(nResult
, sal_Int32(228));
97 void TestCharacterClassification::setUp()
99 BootstrapFixtureBase::setUp();
100 m_xCC
= uno::Reference
< i18n::XCharacterClassification
>(m_xSFactory
->createInstance(
101 "com.sun.star.i18n.CharacterClassification"), uno::UNO_QUERY_THROW
);
104 void TestCharacterClassification::tearDown()
106 BootstrapFixtureBase::tearDown();
110 CPPUNIT_TEST_SUITE_REGISTRATION(TestCharacterClassification
);
112 CPPUNIT_PLUGIN_IMPLEMENT();
114 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */