LCOV - code coverage report
Current view: top level - sal/qa/rtl/locale - rtl_locale.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 145 145 100.0 %
Date: 2012-08-25 Functions: 73 74 98.6 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 309 634 48.7 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <sal/types.h>
      30                 :            : #include <osl/thread.h>
      31                 :            : #include <rtl/locale.hxx>
      32                 :            : 
      33                 :            : #include <cppunit/TestFixture.h>
      34                 :            : #include <cppunit/extensions/HelperMacros.h>
      35                 :            : #include <cppunit/plugin/TestPlugIn.h>
      36                 :            : 
      37                 :            : namespace rtl_locale
      38                 :            : {
      39                 :            :     // default locale for test purpose
      40                 :         70 :     void setDefaultLocale()
      41                 :            :     {
      42         [ +  - ]:         70 :         rtl::OLocale::setDefault(rtl::OUString("de"), rtl::OUString("DE"), /* rtl::OUString() */ rtl::OUString("hochdeutsch") );
      43                 :         70 :     }
      44                 :            : 
      45         [ -  + ]:         30 : class getDefault : public CppUnit::TestFixture
      46                 :            : {
      47                 :            : public:
      48                 :            :     // initialise your test code values here.
      49                 :         10 :     void setUp()
      50                 :            :     {
      51                 :            :         // start message
      52                 :         10 :         rtl_locale::setDefaultLocale();
      53                 :         10 :     }
      54                 :            : 
      55                 :         10 :     void tearDown()
      56                 :            :     {
      57                 :         10 :     }
      58                 :            : 
      59                 :            :     // insert your test code here.
      60                 :          5 :     void getDefault_000()
      61                 :            :     {
      62                 :            :         // this is demonstration code
      63                 :            :         // CPPUNIT_ASSERT_MESSAGE("a message", 1 == 1);
      64                 :            : 
      65                 :            :         // due to the fact, we set the default locale at first, this test is no longer possible
      66                 :            :        // ::rtl::OLocale aLocale = ::rtl::OLocale::getDefault();
      67                 :            :         // CPPUNIT_ASSERT_MESSAGE("locale must be null", aLocale.getData() == NULL);
      68                 :            : 
      69                 :          5 :     }
      70                 :            : 
      71                 :          5 :     void getDefault_001()
      72                 :            :     {
      73                 :            :         // rtl::OLocale::setDefault(rtl::OUString("de"), rtl::OUString("DE"), rtl::OUString());
      74         [ +  - ]:          5 :        rtl::OLocale aLocale = ::rtl::OLocale::getDefault();
      75 [ +  - ][ +  - ]:          5 :         CPPUNIT_ASSERT_MESSAGE("locale must not null", aLocale.getData() != NULL);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
      76                 :          5 :     }
      77                 :            : 
      78                 :            :     // Change the following lines only, if you add, remove or rename
      79                 :            :     // member functions of the current class,
      80                 :            :     // because these macros are need by auto register mechanism.
      81                 :            : 
      82 [ +  - ][ +  - ]:         10 :     CPPUNIT_TEST_SUITE(getDefault);
         [ +  - ][ +  - ]
                 [ #  # ]
      83 [ +  - ][ +  - ]:          5 :     CPPUNIT_TEST(getDefault_000);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
      84 [ +  - ][ +  - ]:          5 :     CPPUNIT_TEST(getDefault_001);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
      85 [ +  - ][ +  - ]:         10 :     CPPUNIT_TEST_SUITE_END();
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
      86                 :            : }; // class getDefault
      87                 :            : 
      88                 :            : 
      89         [ -  + ]:         15 : class setDefault : public CppUnit::TestFixture
      90                 :            : {
      91                 :            : public:
      92                 :            :     // initialise your test code values here.
      93                 :          5 :     void setUp()
      94                 :            :     {
      95                 :            :         // start message
      96                 :          5 :         rtl_locale::setDefaultLocale();
      97                 :          5 :     }
      98                 :            : 
      99                 :          5 :     void tearDown()
     100                 :            :     {
     101                 :          5 :         setDefaultLocale();
     102                 :          5 :     }
     103                 :            : 
     104                 :            :     // insert your test code here.
     105                 :          5 :     void setDefault_001()
     106                 :            :     {
     107         [ +  - ]:          5 :         rtl::OLocale::setDefault(rtl::OUString("en"), rtl::OUString("US"), rtl::OUString());
     108         [ +  - ]:          5 :        rtl::OLocale aLocale = ::rtl::OLocale::getDefault();
     109 [ +  - ][ +  - ]:          5 :         CPPUNIT_ASSERT_MESSAGE("locale must not null", aLocale.getData() != NULL);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     110                 :            : 
     111                 :            :         // be sure to not GPF
     112                 :          5 :     }
     113                 :            : 
     114                 :            :     // Change the following lines only, if you add, remove or rename
     115                 :            :     // member functions of the current class,
     116                 :            :     // because these macros are need by auto register mechanism.
     117                 :            : 
     118 [ +  - ][ +  - ]:         10 :     CPPUNIT_TEST_SUITE(setDefault);
         [ +  - ][ +  - ]
                 [ #  # ]
     119 [ +  - ][ +  - ]:          5 :     CPPUNIT_TEST(setDefault_001);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     120 [ +  - ][ +  - ]:         10 :     CPPUNIT_TEST_SUITE_END();
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     121                 :            : }; // class setDefault
     122                 :            : 
     123                 :            : 
     124         [ -  + ]:         30 : class getLanguage : public CppUnit::TestFixture
     125                 :            : {
     126                 :            : public:
     127                 :            :     // initialise your test code values here.
     128                 :         10 :     void setUp()
     129                 :            :     {
     130                 :            :         // start message
     131                 :         10 :         rtl_locale::setDefaultLocale();
     132                 :         10 :     }
     133                 :            : 
     134                 :         10 :     void tearDown()
     135                 :            :     {
     136                 :         10 :     }
     137                 :            : 
     138                 :            :     // insert your test code here.
     139                 :          5 :     void getLanguage_001()
     140                 :            :     {
     141         [ +  - ]:          5 :         rtl::OLocale aLocale = ::rtl::OLocale::getDefault();
     142                 :          5 :         rtl::OUString suLanguage = aLocale.getLanguage();
     143 [ +  - ][ +  - ]:          5 :         CPPUNIT_ASSERT_MESSAGE( "locale language must be 'de'", suLanguage == "de" );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     144                 :          5 :     }
     145                 :          5 :     void getLanguage_002()
     146                 :            :     {
     147         [ +  - ]:          5 :         rtl::OLocale aLocale = ::rtl::OLocale::getDefault();
     148         [ +  - ]:          5 :         rtl::OUString suLanguage(rtl_locale_getLanguage(aLocale.getData()), SAL_NO_ACQUIRE);
     149 [ +  - ][ +  - ]:          5 :         CPPUNIT_ASSERT_MESSAGE( "locale language must be 'de'", suLanguage == "de" );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     150                 :          5 :     }
     151                 :            : 
     152                 :            :     // Change the following lines only, if you add, remove or rename
     153                 :            :     // member functions of the current class,
     154                 :            :     // because these macros are need by auto register mechanism.
     155                 :            : 
     156 [ +  - ][ +  - ]:         10 :     CPPUNIT_TEST_SUITE(getLanguage);
         [ +  - ][ +  - ]
                 [ #  # ]
     157 [ +  - ][ +  - ]:          5 :     CPPUNIT_TEST(getLanguage_001);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     158 [ +  - ][ +  - ]:          5 :     CPPUNIT_TEST(getLanguage_002);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     159 [ +  - ][ +  - ]:         10 :     CPPUNIT_TEST_SUITE_END();
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     160                 :            : }; // class getLanguage
     161                 :            : 
     162                 :            : 
     163         [ -  + ]:         30 : class getCountry : public CppUnit::TestFixture
     164                 :            : {
     165                 :            : public:
     166                 :            :     // initialise your test code values here.
     167                 :         10 :     void setUp()
     168                 :            :     {
     169                 :            :         // start message
     170                 :         10 :         rtl_locale::setDefaultLocale();
     171                 :         10 :     }
     172                 :            : 
     173                 :         10 :     void tearDown()
     174                 :            :     {
     175                 :         10 :     }
     176                 :            : 
     177                 :            :     // insert your test code here.
     178                 :          5 :     void getCountry_001()
     179                 :            :     {
     180         [ +  - ]:          5 :         rtl::OLocale aLocale = ::rtl::OLocale::getDefault();
     181                 :          5 :         rtl::OUString suCountry = aLocale.getCountry();
     182 [ +  - ][ +  - ]:          5 :         CPPUNIT_ASSERT_MESSAGE( "locale country must be 'DE'", suCountry == "DE" );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     183                 :          5 :     }
     184                 :          5 :     void getCountry_002()
     185                 :            :     {
     186         [ +  - ]:          5 :         rtl::OLocale aLocale = ::rtl::OLocale::getDefault();
     187         [ +  - ]:          5 :         rtl::OUString suCountry(rtl_locale_getCountry(aLocale.getData()), SAL_NO_ACQUIRE);
     188 [ +  - ][ +  - ]:          5 :         CPPUNIT_ASSERT_MESSAGE( "locale country must be 'DE'", suCountry == "DE" );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     189                 :          5 :     }
     190                 :            : 
     191                 :            :     // Change the following lines only, if you add, remove or rename
     192                 :            :     // member functions of the current class,
     193                 :            :     // because these macros are need by auto register mechanism.
     194                 :            : 
     195 [ +  - ][ +  - ]:         10 :     CPPUNIT_TEST_SUITE(getCountry);
         [ +  - ][ +  - ]
                 [ #  # ]
     196 [ +  - ][ +  - ]:          5 :     CPPUNIT_TEST(getCountry_001);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     197 [ +  - ][ +  - ]:          5 :     CPPUNIT_TEST(getCountry_002);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     198 [ +  - ][ +  - ]:         10 :     CPPUNIT_TEST_SUITE_END();
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     199                 :            : }; // class getCountry
     200                 :            : 
     201                 :            : 
     202         [ -  + ]:         30 : class getVariant : public CppUnit::TestFixture
     203                 :            : {
     204                 :            : public:
     205                 :            :     // initialise your test code values here.
     206                 :         10 :     void setUp()
     207                 :            :     {
     208                 :            :         // start message
     209                 :         10 :         rtl_locale::setDefaultLocale();
     210                 :         10 :     }
     211                 :            : 
     212                 :         10 :     void tearDown()
     213                 :            :     {
     214                 :         10 :     }
     215                 :            : 
     216                 :            :     // insert your test code here.
     217                 :          5 :     void getVariant_001()
     218                 :            :     {
     219         [ +  - ]:          5 :         rtl::OLocale aLocale = ::rtl::OLocale::getDefault();
     220                 :          5 :         rtl::OUString suVariant = aLocale.getVariant();
     221 [ +  - ][ +  - ]:          5 :         CPPUNIT_ASSERT_MESSAGE( "locale variant must be 'hochdeutsch'", suVariant == "hochdeutsch" );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     222                 :          5 :     }
     223                 :          5 :     void getVariant_002()
     224                 :            :     {
     225         [ +  - ]:          5 :         rtl::OLocale aLocale = ::rtl::OLocale::getDefault();
     226         [ +  - ]:          5 :         rtl::OUString suVariant(rtl_locale_getVariant(aLocale.getData()), SAL_NO_ACQUIRE);
     227 [ +  - ][ +  - ]:          5 :         CPPUNIT_ASSERT_MESSAGE( "locale variant must be 'hochdeutsch'", suVariant == "hochdeutsch" );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     228                 :          5 :     }
     229                 :            : 
     230                 :            :     // Change the following lines only, if you add, remove or rename
     231                 :            :     // member functions of the current class,
     232                 :            :     // because these macros are need by auto register mechanism.
     233                 :            : 
     234 [ +  - ][ +  - ]:         10 :     CPPUNIT_TEST_SUITE(getVariant);
         [ +  - ][ +  - ]
                 [ #  # ]
     235 [ +  - ][ +  - ]:          5 :     CPPUNIT_TEST(getVariant_001);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     236 [ +  - ][ +  - ]:          5 :     CPPUNIT_TEST(getVariant_002);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     237 [ +  - ][ +  - ]:         10 :     CPPUNIT_TEST_SUITE_END();
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     238                 :            : }; // class getVariant
     239                 :            : 
     240                 :            : 
     241         [ -  + ]:         30 : class hashCode : public CppUnit::TestFixture
     242                 :            : {
     243                 :            : public:
     244                 :            :     // initialise your test code values here.
     245                 :         10 :     void setUp()
     246                 :            :     {
     247                 :            :         // start message
     248                 :         10 :         rtl_locale::setDefaultLocale();
     249                 :         10 :     }
     250                 :            : 
     251                 :         10 :     void tearDown()
     252                 :            :     {
     253                 :         10 :     }
     254                 :            : 
     255                 :            :     // insert your test code here.
     256                 :          5 :     void hashCode_001()
     257                 :            :     {
     258         [ +  - ]:          5 :         rtl::OLocale aLocale = ::rtl::OLocale::getDefault();
     259                 :          5 :         sal_Int32 nHashCode = aLocale.hashCode();
     260 [ +  - ][ +  - ]:          5 :         CPPUNIT_ASSERT_MESSAGE("locale hashcode must be 3831", nHashCode != 0);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     261                 :          5 :     }
     262                 :          5 :     void hashCode_002()
     263                 :            :     {
     264         [ +  - ]:          5 :         rtl::OLocale aLocale = ::rtl::OLocale::getDefault();
     265         [ +  - ]:          5 :         sal_Int32 nHashCode = rtl_locale_hashCode(aLocale.getData());
     266 [ +  - ][ +  - ]:          5 :         CPPUNIT_ASSERT_MESSAGE("locale hashcode must be 3831", nHashCode != 0);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     267                 :          5 :     }
     268                 :            : 
     269                 :            :     // Change the following lines only, if you add, remove or rename
     270                 :            :     // member functions of the current class,
     271                 :            :     // because these macros are need by auto register mechanism.
     272                 :            : 
     273 [ +  - ][ +  - ]:         10 :     CPPUNIT_TEST_SUITE(hashCode);
         [ +  - ][ +  - ]
                 [ #  # ]
     274 [ +  - ][ +  - ]:          5 :     CPPUNIT_TEST(hashCode_001);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     275 [ +  - ][ +  - ]:          5 :     CPPUNIT_TEST(hashCode_002);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     276 [ +  - ][ +  - ]:         10 :     CPPUNIT_TEST_SUITE_END();
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     277                 :            : }; // class hashCode
     278                 :            : 
     279                 :            : 
     280         [ -  + ]:         30 : class equals : public CppUnit::TestFixture
     281                 :            : {
     282                 :            : public:
     283                 :            :     // initialise your test code values here.
     284                 :         10 :     void setUp()
     285                 :            :     {
     286                 :            :         // start message
     287                 :         10 :         rtl_locale::setDefaultLocale();
     288                 :         10 :     }
     289                 :            : 
     290                 :         10 :     void tearDown()
     291                 :            :     {
     292                 :         10 :     }
     293                 :            : 
     294                 :            :     // insert your test code here.
     295                 :          5 :     void equals_001()
     296                 :            :     {
     297         [ +  - ]:          5 :         rtl::OLocale aLocale1 = rtl::OLocale::registerLocale(rtl::OUString("en"), rtl::OUString("US"), rtl::OUString());
     298         [ +  - ]:          5 :         rtl::OLocale aLocale2 = rtl::OLocale::registerLocale(rtl::OUString("en"), rtl::OUString("US"));
     299                 :            : 
     300                 :          5 :         sal_Bool bLocaleAreEqual = sal_False;
     301                 :          5 :         bLocaleAreEqual = (aLocale1 == aLocale2);
     302                 :            : 
     303 [ +  - ][ +  - ]:          5 :         CPPUNIT_ASSERT_MESSAGE("check operator ==()", bLocaleAreEqual == sal_True);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     304                 :          5 :     }
     305                 :            : 
     306                 :          5 :     void equals_002()
     307                 :            :     {
     308         [ +  - ]:          5 :         rtl::OLocale aLocale1 = rtl::OLocale::registerLocale(rtl::OUString("en"), rtl::OUString("US"), rtl::OUString());
     309         [ +  - ]:          5 :         rtl::OLocale aLocale2 = rtl::OLocale::registerLocale(rtl::OUString("en"), rtl::OUString("US"));
     310                 :            : 
     311         [ +  - ]:          5 :         sal_Int32 nEqual = rtl_locale_equals(aLocale1.getData(), aLocale2.getData());
     312 [ +  - ][ +  - ]:          5 :         CPPUNIT_ASSERT(nEqual != 0);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     313                 :          5 :     }
     314                 :            : 
     315                 :            :     // Change the following lines only, if you add, remove or rename
     316                 :            :     // member functions of the current class,
     317                 :            :     // because these macros are need by auto register mechanism.
     318                 :            : 
     319 [ +  - ][ +  - ]:         10 :     CPPUNIT_TEST_SUITE(equals);
         [ +  - ][ +  - ]
                 [ #  # ]
     320 [ +  - ][ +  - ]:          5 :     CPPUNIT_TEST(equals_001);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     321 [ +  - ][ +  - ]:          5 :     CPPUNIT_TEST(equals_002);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     322 [ +  - ][ +  - ]:         10 :     CPPUNIT_TEST_SUITE_END();
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     323                 :            : }; // class equals
     324                 :            : 
     325                 :            : // -----------------------------------------------------------------------------
     326                 :          5 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_locale::getDefault);
     327                 :          5 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_locale::setDefault);
     328                 :          5 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_locale::getLanguage);
     329                 :          5 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_locale::getCountry);
     330                 :          5 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_locale::getVariant);
     331                 :          5 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_locale::hashCode);
     332                 :          5 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_locale::equals);
     333                 :            : } // namespace rtl_locale
     334                 :            : 
     335                 :            : 
     336                 :            : // -----------------------------------------------------------------------------
     337                 :            : 
     338                 :            : // this macro creates an empty function, which will called by the RegisterAllFunctions()
     339                 :            : // to let the user the possibility to also register some functions by hand.
     340                 :            : 
     341 [ +  - ][ +  - ]:         20 : CPPUNIT_PLUGIN_IMPLEMENT();
         [ +  - ][ +  - ]
         [ +  - ][ #  # ]
     342                 :            : 
     343                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10