LCOV - code coverage report
Current view: top level - i18npool/qa/cppunit - test_characterclassification.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 50 50 100.0 %
Date: 2015-06-13 12:38:46 Functions: 16 17 94.1 %
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             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  */
       9             : 
      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>
      15             : 
      16             : #include <rtl/strbuf.hxx>
      17             : #include <rtl/ustrbuf.hxx>
      18             : 
      19             : #include <string.h>
      20             : 
      21             : using namespace ::com::sun::star;
      22             : 
      23           6 : class TestCharacterClassification : public test::BootstrapFixtureBase
      24             : {
      25             : public:
      26             :     virtual void setUp() SAL_OVERRIDE;
      27             :     virtual void tearDown() SAL_OVERRIDE;
      28             : 
      29             :     void testTitleCase();
      30             :     void testStringType();
      31             : 
      32           2 :     CPPUNIT_TEST_SUITE(TestCharacterClassification);
      33           1 :     CPPUNIT_TEST(testTitleCase);
      34           1 :     CPPUNIT_TEST(testStringType);
      35           5 :     CPPUNIT_TEST_SUITE_END();
      36             : private:
      37             :     uno::Reference<i18n::XCharacterClassification> m_xCC;
      38             : };
      39             : 
      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://bz.apache.org/ooo/show_bug.cgi?id=30863
      43           1 : void TestCharacterClassification::testTitleCase()
      44             : {
      45           1 :     lang::Locale aLocale;
      46           1 :     aLocale.Language = "en";
      47           1 :     aLocale.Country = "US";
      48             : 
      49             :     {
      50             :         //basic example
      51           1 :         OUString sTest("Some text");
      52           2 :         OUString sTitleCase = m_xCC->toTitle(sTest, 0, sTest.getLength(), aLocale);
      53           1 :         CPPUNIT_ASSERT_MESSAGE("Should be title", sTitleCase == "Some Text");
      54           2 :         OUString sUpperCase = m_xCC->toUpper(sTest, 0, sTest.getLength(), aLocale);
      55           1 :         CPPUNIT_ASSERT_MESSAGE("Should be upper", sUpperCase == "SOME TEXT");
      56           2 :         OUString sLowerCase = m_xCC->toLower(sTest, 0, sTest.getLength(), aLocale);
      57           2 :         CPPUNIT_ASSERT_MESSAGE("Should be lower ", sLowerCase == "some text");
      58             :     }
      59             : 
      60             :     {
      61             :         //tricky one
      62           1 :         const sal_Unicode LATINSMALLLETTERDZ[] = { 0x01F3 };
      63           1 :         OUString aTest(LATINSMALLLETTERDZ, SAL_N_ELEMENTS(LATINSMALLLETTERDZ));
      64           2 :         OUString sTitleCase = m_xCC->toTitle(aTest, 0, aTest.getLength(), aLocale);
      65           1 :         CPPUNIT_ASSERT_MESSAGE("Should be title", sTitleCase.getLength() == 1 && sTitleCase[0] == 0x01F2);
      66           2 :         OUString sUpperCase = m_xCC->toUpper(aTest, 0, aTest.getLength(), aLocale);
      67           1 :         CPPUNIT_ASSERT_MESSAGE("Should be upper", sUpperCase.getLength() == 1 && sUpperCase[0] == 0x01F1);
      68           2 :         OUString sLowerCase = m_xCC->toLower(aTest, 0, aTest.getLength(), aLocale);
      69           2 :         CPPUNIT_ASSERT_MESSAGE("Should be lower ", sLowerCase.getLength() == 1 && sLowerCase[0] == 0x01F3);
      70           1 :     }
      71           1 : }
      72             : 
      73             : //https://bugs.libreoffice.org/show_bug.cgi?id=69641
      74           1 : void TestCharacterClassification::testStringType()
      75             : {
      76           1 :     lang::Locale aLocale;
      77           1 :     aLocale.Language = "en";
      78           1 :     aLocale.Country = "US";
      79             : 
      80             :     {
      81             :         //simple case
      82           1 :         OUString sTest("Some text");
      83           1 :         sal_Int32 nResult = m_xCC->getStringType(sTest, 0, sTest.getLength(), aLocale);
      84           1 :         CPPUNIT_ASSERT_EQUAL(nResult, sal_Int32(230));
      85             :     }
      86             : 
      87             :     {
      88             :         //tricky case
      89           1 :         const sal_Unicode MATHEMATICAL_ITALIC_SMALL_THETA[] = { 0xD835, 0xDF03 };
      90           1 :         OUString sTest(MATHEMATICAL_ITALIC_SMALL_THETA, SAL_N_ELEMENTS(MATHEMATICAL_ITALIC_SMALL_THETA));
      91           1 :         sal_Int32 nResult = m_xCC->getStringType(sTest, 0, sTest.getLength(), aLocale);
      92           1 :         CPPUNIT_ASSERT_EQUAL(nResult, sal_Int32(228));
      93           1 :     }
      94             : 
      95           1 : }
      96             : 
      97           2 : void TestCharacterClassification::setUp()
      98             : {
      99           2 :     BootstrapFixtureBase::setUp();
     100           6 :     m_xCC = uno::Reference< i18n::XCharacterClassification >(m_xSFactory->createInstance(
     101           4 :         "com.sun.star.i18n.CharacterClassification"), uno::UNO_QUERY_THROW);
     102           2 : }
     103             : 
     104           2 : void TestCharacterClassification::tearDown()
     105             : {
     106           2 :     BootstrapFixtureBase::tearDown();
     107           2 :     m_xCC.clear();
     108           2 : }
     109             : 
     110           1 : CPPUNIT_TEST_SUITE_REGISTRATION(TestCharacterClassification);
     111             : 
     112           4 : CPPUNIT_PLUGIN_IMPLEMENT();
     113             : 
     114             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11