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 <com/sun/star/i18n/XCharacterClassification.hpp>
11 #include <unotest/bootstrapfixturebase.hxx>
13 using namespace ::com::sun::star
;
15 class TestCharacterClassification
: public test::BootstrapFixtureBase
18 virtual void setUp() override
;
19 virtual void tearDown() override
;
22 void testStringType();
24 CPPUNIT_TEST_SUITE(TestCharacterClassification
);
25 CPPUNIT_TEST(testTitleCase
);
26 CPPUNIT_TEST(testStringType
);
27 CPPUNIT_TEST_SUITE_END();
29 uno::Reference
<i18n::XCharacterClassification
> m_xCC
;
32 //A test to ensure that our Title Case functionality is working
33 //http://lists.freedesktop.org/archives/libreoffice/2012-June/032767.html
34 //https://bz.apache.org/ooo/show_bug.cgi?id=30863
35 void TestCharacterClassification::testTitleCase()
38 aLocale
.Language
= "en";
39 aLocale
.Country
= "US";
43 OUString
sTest("Some text");
44 OUString sTitleCase
= m_xCC
->toTitle(sTest
, 0, sTest
.getLength(), aLocale
);
45 CPPUNIT_ASSERT_EQUAL_MESSAGE("Should be title", OUString("Some Text"), sTitleCase
);
46 OUString sUpperCase
= m_xCC
->toUpper(sTest
, 0, sTest
.getLength(), aLocale
);
47 CPPUNIT_ASSERT_EQUAL_MESSAGE("Should be upper", OUString("SOME TEXT"), sUpperCase
);
48 OUString sLowerCase
= m_xCC
->toLower(sTest
, 0, sTest
.getLength(), aLocale
);
49 CPPUNIT_ASSERT_EQUAL_MESSAGE("Should be lower ", OUString("some text"), sLowerCase
);
54 const sal_Unicode LATINSMALLLETTERDZ
[] = { 0x01F3 };
55 OUString
aTest(LATINSMALLLETTERDZ
, SAL_N_ELEMENTS(LATINSMALLLETTERDZ
));
56 OUString sTitleCase
= m_xCC
->toTitle(aTest
, 0, aTest
.getLength(), aLocale
);
57 CPPUNIT_ASSERT_MESSAGE("Should be title", sTitleCase
.getLength() == 1 && sTitleCase
[0] == 0x01F2);
58 OUString sUpperCase
= m_xCC
->toUpper(aTest
, 0, aTest
.getLength(), aLocale
);
59 CPPUNIT_ASSERT_MESSAGE("Should be upper", sUpperCase
.getLength() == 1 && sUpperCase
[0] == 0x01F1);
60 OUString sLowerCase
= m_xCC
->toLower(aTest
, 0, aTest
.getLength(), aLocale
);
61 CPPUNIT_ASSERT_MESSAGE("Should be lower ", sLowerCase
.getLength() == 1 && sLowerCase
[0] == 0x01F3);
65 //https://bugs.libreoffice.org/show_bug.cgi?id=69641
66 void TestCharacterClassification::testStringType()
69 aLocale
.Language
= "en";
70 aLocale
.Country
= "US";
74 OUString
sTest("Some text");
75 sal_Int32 nResult
= m_xCC
->getStringType(sTest
, 0, sTest
.getLength(), aLocale
);
76 CPPUNIT_ASSERT_EQUAL(sal_Int32(230), nResult
);
81 const sal_Unicode MATHEMATICAL_ITALIC_SMALL_THETA
[] = { 0xD835, 0xDF03 };
82 OUString
sTest(MATHEMATICAL_ITALIC_SMALL_THETA
, SAL_N_ELEMENTS(MATHEMATICAL_ITALIC_SMALL_THETA
));
83 sal_Int32 nResult
= m_xCC
->getStringType(sTest
, 0, sTest
.getLength(), aLocale
);
84 CPPUNIT_ASSERT_EQUAL(sal_Int32(228), nResult
);
89 void TestCharacterClassification::setUp()
91 BootstrapFixtureBase::setUp();
92 m_xCC
.set(m_xSFactory
->createInstance("com.sun.star.i18n.CharacterClassification"), uno::UNO_QUERY_THROW
);
95 void TestCharacterClassification::tearDown()
97 BootstrapFixtureBase::tearDown();
101 CPPUNIT_TEST_SUITE_REGISTRATION(TestCharacterClassification
);
103 CPPUNIT_PLUGIN_IMPLEMENT();
105 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */