LCOV - code coverage report
Current view: top level - libreoffice/i18npool/qa/cppunit - test_characterclassification.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 37 37 100.0 %
Date: 2012-12-27 Functions: 12 13 92.3 %
Legend: Lines: hit not hit

          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           3 : class TestCharacterClassification : public test::BootstrapFixtureBase
      42             : {
      43             : public:
      44             :     virtual void setUp();
      45             :     virtual void tearDown();
      46             : 
      47             :     void testTitleCase();
      48             : 
      49           2 :     CPPUNIT_TEST_SUITE(TestCharacterClassification);
      50           1 :     CPPUNIT_TEST(testTitleCase);
      51           2 :     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           1 : void TestCharacterClassification::testTitleCase()
      60             : {
      61           1 :     lang::Locale aLocale;
      62           1 :     aLocale.Language = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("en"));
      63           1 :     aLocale.Country = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("US"));
      64             : 
      65             :     {
      66             :         //basic example
      67           1 :         ::rtl::OUString sTest("Some text");
      68           1 :         ::rtl::OUString sTitleCase = m_xCC->toTitle(sTest, 0, sTest.getLength(), aLocale);
      69           1 :         CPPUNIT_ASSERT_MESSAGE("Should be title", sTitleCase == "Some Text");
      70           1 :         ::rtl::OUString sUpperCase = m_xCC->toUpper(sTest, 0, sTest.getLength(), aLocale);
      71           1 :         CPPUNIT_ASSERT_MESSAGE("Should be upper", sUpperCase == "SOME TEXT");
      72           1 :         ::rtl::OUString sLowerCase = m_xCC->toLower(sTest, 0, sTest.getLength(), aLocale);
      73           1 :         CPPUNIT_ASSERT_MESSAGE("Should be lower ", sLowerCase == "some text");
      74             :     }
      75             : 
      76             :     {
      77             :         //tricky one
      78           1 :         const sal_Unicode LATINSMALLLETTERDZ[] = { 0x01F3 };
      79           1 :         ::rtl::OUString aTest(LATINSMALLLETTERDZ, SAL_N_ELEMENTS(LATINSMALLLETTERDZ));
      80           1 :         ::rtl::OUString sTest(aTest);
      81           1 :         ::rtl::OUString sTitleCase = m_xCC->toTitle(aTest, 0, aTest.getLength(), aLocale);
      82           1 :         CPPUNIT_ASSERT_MESSAGE("Should be title", sTitleCase.getLength() == 1 && sTitleCase[0] == 0x01F2);
      83           1 :         ::rtl::OUString sUpperCase = m_xCC->toUpper(aTest, 0, aTest.getLength(), aLocale);
      84           1 :         CPPUNIT_ASSERT_MESSAGE("Should be upper", sUpperCase.getLength() == 1 && sUpperCase[0] == 0x01F1);
      85           1 :         ::rtl::OUString sLowerCase = m_xCC->toLower(aTest, 0, aTest.getLength(), aLocale);
      86           1 :         CPPUNIT_ASSERT_MESSAGE("Should be lower ", sLowerCase.getLength() == 1 && sLowerCase[0] == 0x01F3);
      87           1 :     }
      88           1 : }
      89             : 
      90           1 : void TestCharacterClassification::setUp()
      91             : {
      92           1 :     BootstrapFixtureBase::setUp();
      93           1 :     m_xCC = uno::Reference< i18n::XCharacterClassification >(m_xSFactory->createInstance(
      94           1 :         "com.sun.star.i18n.CharacterClassification"), uno::UNO_QUERY_THROW);
      95           1 : }
      96             : 
      97           1 : void TestCharacterClassification::tearDown()
      98             : {
      99           1 :     BootstrapFixtureBase::tearDown();
     100           1 :     m_xCC.clear();
     101           1 : }
     102             : 
     103           1 : CPPUNIT_TEST_SUITE_REGISTRATION(TestCharacterClassification);
     104             : 
     105           4 : CPPUNIT_PLUGIN_IMPLEMENT();
     106             : 
     107             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10