Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * Version: MPL 1.1 / GPLv3+ / LGPLv3+
4 : : *
5 : : * The contents of this file are subject to the Mozilla Public License Version
6 : : * 1.1 (the "License"); you may not use this file except in compliance with
7 : : * the License. You may obtain a copy of the License at
8 : : * http://www.mozilla.org/MPL/
9 : : *
10 : : * Software distributed under the License is distributed on an "AS IS" basis,
11 : : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : : * for the specific language governing rights and limitations under the
13 : : * License.
14 : : *
15 : : * The Initial Developer of the Original Code is
16 : : * Caolán McNamara <caolanm@redhat.com>
17 : : *
18 : : * Contributor(s):
19 : : * Caolán McNamara <caolanm@redhat.com>
20 : : *
21 : : * Alternatively, the contents of this file may be used under the terms of
22 : : * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
23 : : * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
24 : : * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
25 : : * instead of those above.
26 : : */
27 : :
28 : : #include <cppuhelper/compbase1.hxx>
29 : : #include <cppuhelper/bootstrap.hxx>
30 : : #include <cppuhelper/basemutex.hxx>
31 : : #include <com/sun/star/i18n/XCharacterClassification.hpp>
32 : : #include <unotest/bootstrapfixturebase.hxx>
33 : :
34 : : #include <rtl/strbuf.hxx>
35 : : #include <rtl/ustrbuf.hxx>
36 : :
37 : : #include <string.h>
38 : :
39 : : using namespace ::com::sun::star;
40 : :
41 [ - + ]: 9 : class TestCharacterClassification : public test::BootstrapFixtureBase
42 : : {
43 : : public:
44 : : virtual void setUp();
45 : : virtual void tearDown();
46 : :
47 : : void testTitleCase();
48 : :
49 [ + - ][ + - ]: 6 : CPPUNIT_TEST_SUITE(TestCharacterClassification);
[ + - ][ + - ]
[ # # ]
50 [ + - ][ + - ]: 3 : CPPUNIT_TEST(testTitleCase);
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
51 [ + - ][ + - ]: 6 : CPPUNIT_TEST_SUITE_END();
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
52 : : private:
53 : : uno::Reference<i18n::XCharacterClassification> m_xCC;
54 : : };
55 : :
56 : : //A test to ensure that our Title Case functionality is working
57 : : //http://lists.freedesktop.org/archives/libreoffice/2012-June/032767.html
58 : : //https://issues.apache.org/ooo/show_bug.cgi?id=30863
59 : 3 : void TestCharacterClassification::testTitleCase()
60 : : {
61 : 3 : lang::Locale aLocale;
62 [ + - ]: 3 : aLocale.Language = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("en"));
63 [ + - ]: 3 : aLocale.Country = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("US"));
64 : :
65 : : {
66 : : //basic example
67 : 3 : ::rtl::OUString sTest("Some text");
68 [ + - ][ + - ]: 3 : ::rtl::OUString sTitleCase = m_xCC->toTitle(sTest, 0, sTest.getLength(), aLocale);
69 [ + - ][ + - ]: 3 : CPPUNIT_ASSERT_MESSAGE("Should be title", sTitleCase == "Some Text");
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
70 [ + - ][ + - ]: 3 : ::rtl::OUString sUpperCase = m_xCC->toUpper(sTest, 0, sTest.getLength(), aLocale);
71 [ + - ][ + - ]: 3 : CPPUNIT_ASSERT_MESSAGE("Should be upper", sUpperCase == "SOME TEXT");
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
72 [ + - ][ + - ]: 3 : ::rtl::OUString sLowerCase = m_xCC->toLower(sTest, 0, sTest.getLength(), aLocale);
73 [ + - ][ + - ]: 3 : CPPUNIT_ASSERT_MESSAGE("Should be lower ", sLowerCase == "some text");
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
74 : : }
75 : :
76 : : {
77 : : //tricky one
78 : 3 : const sal_Unicode LATINSMALLLETTERDZ[] = { 0x01F3 };
79 : 3 : ::rtl::OUString aTest(LATINSMALLLETTERDZ, SAL_N_ELEMENTS(LATINSMALLLETTERDZ));
80 : 3 : ::rtl::OUString sTest(aTest);
81 [ + - ][ + - ]: 3 : ::rtl::OUString sTitleCase = m_xCC->toTitle(aTest, 0, aTest.getLength(), aLocale);
82 [ + - ][ + - ]: 3 : CPPUNIT_ASSERT_MESSAGE("Should be title", sTitleCase.getLength() == 1 && sTitleCase[0] == 0x01F2);
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ - + ]
[ + - ][ + - ]
[ + - ]
83 [ + - ][ + - ]: 3 : ::rtl::OUString sUpperCase = m_xCC->toUpper(aTest, 0, aTest.getLength(), aLocale);
84 [ + - ][ + - ]: 3 : CPPUNIT_ASSERT_MESSAGE("Should be upper", sUpperCase.getLength() == 1 && sUpperCase[0] == 0x01F1);
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ - + ]
[ + - ][ + - ]
[ + - ]
85 [ + - ][ + - ]: 3 : ::rtl::OUString sLowerCase = m_xCC->toLower(aTest, 0, aTest.getLength(), aLocale);
86 [ + - ][ + - ]: 3 : CPPUNIT_ASSERT_MESSAGE("Should be lower ", sLowerCase.getLength() == 1 && sLowerCase[0] == 0x01F3);
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ - + ]
[ + - ][ + - ]
[ + - ]
87 : 3 : }
88 : 3 : }
89 : :
90 : 3 : void TestCharacterClassification::setUp()
91 : : {
92 : 3 : BootstrapFixtureBase::setUp();
93 : 3 : m_xCC = uno::Reference< i18n::XCharacterClassification >(m_xSFactory->createInstance(
94 [ + - ][ + - ]: 3 : "com.sun.star.i18n.CharacterClassification"), uno::UNO_QUERY_THROW);
[ + - ]
95 : 3 : }
96 : :
97 : 3 : void TestCharacterClassification::tearDown()
98 : : {
99 : 3 : BootstrapFixtureBase::tearDown();
100 : 3 : m_xCC.clear();
101 : 3 : }
102 : :
103 : 3 : CPPUNIT_TEST_SUITE_REGISTRATION(TestCharacterClassification);
104 : :
105 [ + - ][ + - ]: 12 : CPPUNIT_PLUGIN_IMPLEMENT();
[ + - ][ + - ]
[ + - ][ # # ]
106 : :
107 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|