LCOV - code coverage report
Current view: top level - i18npool/qa/cppunit - test_characterclassification.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 50 50 100.0 %
Date: 2014-11-03 Functions: 13 14 92.9 %
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          12 : 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           4 :     CPPUNIT_TEST_SUITE(TestCharacterClassification);
      33           2 :     CPPUNIT_TEST(testTitleCase);
      34           2 :     CPPUNIT_TEST(testStringType);
      35           4 :     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://issues.apache.org/ooo/show_bug.cgi?id=30863
      43           2 : void TestCharacterClassification::testTitleCase()
      44             : {
      45           2 :     lang::Locale aLocale;
      46           2 :     aLocale.Language = "en";
      47           2 :     aLocale.Country = "US";
      48             : 
      49             :     {
      50             :         //basic example
      51           2 :         OUString sTest("Some text");
      52           4 :         OUString sTitleCase = m_xCC->toTitle(sTest, 0, sTest.getLength(), aLocale);
      53           2 :         CPPUNIT_ASSERT_MESSAGE("Should be title", sTitleCase == "Some Text");
      54           4 :         OUString sUpperCase = m_xCC->toUpper(sTest, 0, sTest.getLength(), aLocale);
      55           2 :         CPPUNIT_ASSERT_MESSAGE("Should be upper", sUpperCase == "SOME TEXT");
      56           4 :         OUString sLowerCase = m_xCC->toLower(sTest, 0, sTest.getLength(), aLocale);
      57           4 :         CPPUNIT_ASSERT_MESSAGE("Should be lower ", sLowerCase == "some text");
      58             :     }
      59             : 
      60             :     {
      61             :         //tricky one
      62           2 :         const sal_Unicode LATINSMALLLETTERDZ[] = { 0x01F3 };
      63           2 :         OUString aTest(LATINSMALLLETTERDZ, SAL_N_ELEMENTS(LATINSMALLLETTERDZ));
      64           4 :         OUString sTitleCase = m_xCC->toTitle(aTest, 0, aTest.getLength(), aLocale);
      65           2 :         CPPUNIT_ASSERT_MESSAGE("Should be title", sTitleCase.getLength() == 1 && sTitleCase[0] == 0x01F2);
      66           4 :         OUString sUpperCase = m_xCC->toUpper(aTest, 0, aTest.getLength(), aLocale);
      67           2 :         CPPUNIT_ASSERT_MESSAGE("Should be upper", sUpperCase.getLength() == 1 && sUpperCase[0] == 0x01F1);
      68           4 :         OUString sLowerCase = m_xCC->toLower(aTest, 0, aTest.getLength(), aLocale);
      69           4 :         CPPUNIT_ASSERT_MESSAGE("Should be lower ", sLowerCase.getLength() == 1 && sLowerCase[0] == 0x01F3);
      70           2 :     }
      71           2 : }
      72             : 
      73             : //https://bugs.libreoffice.org/show_bug.cgi?id=69641
      74           2 : void TestCharacterClassification::testStringType()
      75             : {
      76           2 :     lang::Locale aLocale;
      77           2 :     aLocale.Language = "en";
      78           2 :     aLocale.Country = "US";
      79             : 
      80             :     {
      81             :         //simple case
      82           2 :         OUString sTest("Some text");
      83           2 :         sal_Int32 nResult = m_xCC->getStringType(sTest, 0, sTest.getLength(), aLocale);
      84           2 :         CPPUNIT_ASSERT_EQUAL(nResult, sal_Int32(230));
      85             :     }
      86             : 
      87             :     {
      88             :         //tricky case
      89           2 :         const sal_Unicode MATHEMATICAL_ITALIC_SMALL_THETA[] = { 0xD835, 0xDF03 };
      90           2 :         OUString sTest(MATHEMATICAL_ITALIC_SMALL_THETA, SAL_N_ELEMENTS(MATHEMATICAL_ITALIC_SMALL_THETA));
      91           2 :         sal_Int32 nResult = m_xCC->getStringType(sTest, 0, sTest.getLength(), aLocale);
      92           2 :         CPPUNIT_ASSERT_EQUAL(nResult, sal_Int32(228));
      93           2 :     }
      94             : 
      95           2 : }
      96             : 
      97           4 : void TestCharacterClassification::setUp()
      98             : {
      99           4 :     BootstrapFixtureBase::setUp();
     100          12 :     m_xCC = uno::Reference< i18n::XCharacterClassification >(m_xSFactory->createInstance(
     101           8 :         "com.sun.star.i18n.CharacterClassification"), uno::UNO_QUERY_THROW);
     102           4 : }
     103             : 
     104           4 : void TestCharacterClassification::tearDown()
     105             : {
     106           4 :     BootstrapFixtureBase::tearDown();
     107           4 :     m_xCC.clear();
     108           4 : }
     109             : 
     110           2 : CPPUNIT_TEST_SUITE_REGISTRATION(TestCharacterClassification);
     111             : 
     112           8 : CPPUNIT_PLUGIN_IMPLEMENT();
     113             : 
     114             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10