LCOV - code coverage report
Current view: top level - libreoffice/sal/qa/rtl/locale - rtl_locale.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 142 142 100.0 %
Date: 2012-12-27 Functions: 72 73 98.6 %
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             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <sal/types.h>
      21             : #include <osl/thread.h>
      22             : #include <rtl/locale.h>
      23             : #include <rtl/ustring.hxx>
      24             : 
      25             : #include <cppunit/TestFixture.h>
      26             : #include <cppunit/extensions/HelperMacros.h>
      27             : #include <cppunit/plugin/TestPlugIn.h>
      28             : 
      29             : namespace rtl_locale
      30             : {
      31             :     // default locale for test purpose
      32          13 :     void setDefaultLocale()
      33             :     {
      34          13 :         rtl_locale_setDefault(rtl::OUString("de").getStr(), rtl::OUString("DE").getStr(), /* rtl::OUString() */ rtl::OUString("hochdeutsch").getStr() );
      35          13 :     }
      36             : 
      37           3 : class getDefault : public CppUnit::TestFixture
      38             : {
      39             : public:
      40             :     // initialise your test code values here.
      41           1 :     void setUp()
      42             :     {
      43             :         // start message
      44           1 :         rtl_locale::setDefaultLocale();
      45           1 :     }
      46             : 
      47           1 :     void tearDown()
      48             :     {
      49           1 :     }
      50             : 
      51           1 :     void getDefault_001()
      52             :     {
      53           1 :         rtl_Locale* pData = rtl_locale_getDefault();
      54           1 :         CPPUNIT_ASSERT_MESSAGE("locale must not null", pData != NULL);
      55           1 :     }
      56             : 
      57             :     // Change the following lines only, if you add, remove or rename
      58             :     // member functions of the current class,
      59             :     // because these macros are need by auto register mechanism.
      60             : 
      61           2 :     CPPUNIT_TEST_SUITE(getDefault);
      62           1 :     CPPUNIT_TEST(getDefault_001);
      63           2 :     CPPUNIT_TEST_SUITE_END();
      64             : }; // class getDefault
      65             : 
      66             : 
      67           3 : class setDefault : public CppUnit::TestFixture
      68             : {
      69             : public:
      70             :     // initialise your test code values here.
      71           1 :     void setUp()
      72             :     {
      73             :         // start message
      74           1 :         rtl_locale::setDefaultLocale();
      75           1 :     }
      76             : 
      77           1 :     void tearDown()
      78             :     {
      79           1 :         setDefaultLocale();
      80           1 :     }
      81             : 
      82             :     // insert your test code here.
      83           1 :     void setDefault_001()
      84             :     {
      85           1 :         rtl_locale_setDefault(rtl::OUString("en").getStr(), rtl::OUString("US").getStr(), rtl::OUString().getStr());
      86           1 :         rtl_Locale* pData = rtl_locale_getDefault();
      87           1 :         CPPUNIT_ASSERT_MESSAGE("locale must not null", pData != NULL);
      88             : 
      89             :         // be sure to not GPF
      90           1 :     }
      91             : 
      92             :     // Change the following lines only, if you add, remove or rename
      93             :     // member functions of the current class,
      94             :     // because these macros are need by auto register mechanism.
      95             : 
      96           2 :     CPPUNIT_TEST_SUITE(setDefault);
      97           1 :     CPPUNIT_TEST(setDefault_001);
      98           2 :     CPPUNIT_TEST_SUITE_END();
      99             : }; // class setDefault
     100             : 
     101             : 
     102           6 : class getLanguage : public CppUnit::TestFixture
     103             : {
     104             : public:
     105             :     // initialise your test code values here.
     106           2 :     void setUp()
     107             :     {
     108             :         // start message
     109           2 :         rtl_locale::setDefaultLocale();
     110           2 :     }
     111             : 
     112           2 :     void tearDown()
     113             :     {
     114           2 :     }
     115             : 
     116             :     // insert your test code here.
     117           1 :     void getLanguage_001()
     118             :     {
     119           1 :         rtl_Locale* pData = rtl_locale_getDefault();
     120           1 :         rtl::OUString suLanguage = pData->Language;
     121           1 :         CPPUNIT_ASSERT_MESSAGE( "locale language must be 'de'", suLanguage == "de" );
     122           1 :     }
     123           1 :     void getLanguage_002()
     124             :     {
     125           1 :         rtl_Locale* pData = rtl_locale_getDefault();
     126           1 :         rtl::OUString suLanguage(rtl_locale_getLanguage(pData), SAL_NO_ACQUIRE);
     127           1 :         CPPUNIT_ASSERT_MESSAGE( "locale language must be 'de'", suLanguage == "de" );
     128           1 :     }
     129             : 
     130             :     // Change the following lines only, if you add, remove or rename
     131             :     // member functions of the current class,
     132             :     // because these macros are need by auto register mechanism.
     133             : 
     134           2 :     CPPUNIT_TEST_SUITE(getLanguage);
     135           1 :     CPPUNIT_TEST(getLanguage_001);
     136           1 :     CPPUNIT_TEST(getLanguage_002);
     137           2 :     CPPUNIT_TEST_SUITE_END();
     138             : }; // class getLanguage
     139             : 
     140             : 
     141           6 : class getCountry : public CppUnit::TestFixture
     142             : {
     143             : public:
     144             :     // initialise your test code values here.
     145           2 :     void setUp()
     146             :     {
     147             :         // start message
     148           2 :         rtl_locale::setDefaultLocale();
     149           2 :     }
     150             : 
     151           2 :     void tearDown()
     152             :     {
     153           2 :     }
     154             : 
     155             :     // insert your test code here.
     156           1 :     void getCountry_001()
     157             :     {
     158           1 :         rtl_Locale* pData = rtl_locale_getDefault();
     159           1 :         rtl::OUString suCountry = pData->Country;
     160           1 :         CPPUNIT_ASSERT_MESSAGE( "locale country must be 'DE'", suCountry == "DE" );
     161           1 :     }
     162           1 :     void getCountry_002()
     163             :     {
     164           1 :         rtl_Locale* pData = rtl_locale_getDefault();
     165           1 :         rtl::OUString suCountry(rtl_locale_getCountry(pData), SAL_NO_ACQUIRE);
     166           1 :         CPPUNIT_ASSERT_MESSAGE( "locale country must be 'DE'", suCountry == "DE" );
     167           1 :     }
     168             : 
     169             :     // Change the following lines only, if you add, remove or rename
     170             :     // member functions of the current class,
     171             :     // because these macros are need by auto register mechanism.
     172             : 
     173           2 :     CPPUNIT_TEST_SUITE(getCountry);
     174           1 :     CPPUNIT_TEST(getCountry_001);
     175           1 :     CPPUNIT_TEST(getCountry_002);
     176           2 :     CPPUNIT_TEST_SUITE_END();
     177             : }; // class getCountry
     178             : 
     179             : 
     180           6 : class getVariant : public CppUnit::TestFixture
     181             : {
     182             : public:
     183             :     // initialise your test code values here.
     184           2 :     void setUp()
     185             :     {
     186             :         // start message
     187           2 :         rtl_locale::setDefaultLocale();
     188           2 :     }
     189             : 
     190           2 :     void tearDown()
     191             :     {
     192           2 :     }
     193             : 
     194             :     // insert your test code here.
     195           1 :     void getVariant_001()
     196             :     {
     197           1 :         rtl_Locale* pData = rtl_locale_getDefault();
     198           1 :         rtl::OUString suVariant = pData->Variant;
     199           1 :         CPPUNIT_ASSERT_MESSAGE( "locale variant must be 'hochdeutsch'", suVariant == "hochdeutsch" );
     200           1 :     }
     201           1 :     void getVariant_002()
     202             :     {
     203           1 :         rtl_Locale* pData = rtl_locale_getDefault();
     204           1 :         rtl::OUString suVariant(rtl_locale_getVariant(pData), SAL_NO_ACQUIRE);
     205           1 :         CPPUNIT_ASSERT_MESSAGE( "locale variant must be 'hochdeutsch'", suVariant == "hochdeutsch" );
     206           1 :     }
     207             : 
     208             :     // Change the following lines only, if you add, remove or rename
     209             :     // member functions of the current class,
     210             :     // because these macros are need by auto register mechanism.
     211             : 
     212           2 :     CPPUNIT_TEST_SUITE(getVariant);
     213           1 :     CPPUNIT_TEST(getVariant_001);
     214           1 :     CPPUNIT_TEST(getVariant_002);
     215           2 :     CPPUNIT_TEST_SUITE_END();
     216             : }; // class getVariant
     217             : 
     218             : 
     219           6 : class hashCode : public CppUnit::TestFixture
     220             : {
     221             : public:
     222             :     // initialise your test code values here.
     223           2 :     void setUp()
     224             :     {
     225             :         // start message
     226           2 :         rtl_locale::setDefaultLocale();
     227           2 :     }
     228             : 
     229           2 :     void tearDown()
     230             :     {
     231           2 :     }
     232             : 
     233             :     // insert your test code here.
     234           1 :     void hashCode_001()
     235             :     {
     236           1 :         rtl_Locale* pData = rtl_locale_getDefault();
     237           1 :         sal_Int32 nHashCode = pData->HashCode;
     238           1 :         CPPUNIT_ASSERT_MESSAGE("locale hashcode must be 3831", nHashCode != 0);
     239           1 :     }
     240           1 :     void hashCode_002()
     241             :     {
     242           1 :         rtl_Locale* pData = rtl_locale_getDefault();
     243           1 :         sal_Int32 nHashCode = rtl_locale_hashCode(pData);
     244           1 :         CPPUNIT_ASSERT_MESSAGE("locale hashcode must be 3831", nHashCode != 0);
     245           1 :     }
     246             : 
     247             :     // Change the following lines only, if you add, remove or rename
     248             :     // member functions of the current class,
     249             :     // because these macros are need by auto register mechanism.
     250             : 
     251           2 :     CPPUNIT_TEST_SUITE(hashCode);
     252           1 :     CPPUNIT_TEST(hashCode_001);
     253           1 :     CPPUNIT_TEST(hashCode_002);
     254           2 :     CPPUNIT_TEST_SUITE_END();
     255             : }; // class hashCode
     256             : 
     257             : 
     258           6 : class equals : public CppUnit::TestFixture
     259             : {
     260             : public:
     261             :     // initialise your test code values here.
     262           2 :     void setUp()
     263             :     {
     264             :         // start message
     265           2 :         rtl_locale::setDefaultLocale();
     266           2 :     }
     267             : 
     268           2 :     void tearDown()
     269             :     {
     270           2 :     }
     271             : 
     272             :     // insert your test code here.
     273           1 :     void equals_001()
     274             :     {
     275           1 :         rtl_Locale* pData1 = rtl_locale_register(rtl::OUString("en").getStr(), rtl::OUString("US").getStr(), rtl::OUString().getStr());
     276           1 :         rtl_Locale* pData2 = rtl_locale_register(rtl::OUString("en").getStr(), rtl::OUString("US").getStr(), rtl::OUString().getStr());
     277             : 
     278           1 :         sal_Bool bLocaleAreEqual = sal_False;
     279           1 :         bLocaleAreEqual = (pData1 == pData2);
     280             : 
     281           1 :         CPPUNIT_ASSERT_MESSAGE("check operator ==()", bLocaleAreEqual == sal_True);
     282           1 :     }
     283             : 
     284           1 :     void equals_002()
     285             :     {
     286           1 :         rtl_Locale* pData1 = rtl_locale_register(rtl::OUString("en").getStr(), rtl::OUString("US").getStr(), rtl::OUString().getStr());
     287           1 :         rtl_Locale* pData2 = rtl_locale_register(rtl::OUString("en").getStr(), rtl::OUString("US").getStr(), rtl::OUString().getStr());
     288             : 
     289           1 :         sal_Int32 nEqual = rtl_locale_equals(pData1, pData2);
     290           1 :         CPPUNIT_ASSERT(nEqual != 0);
     291           1 :     }
     292             : 
     293             :     // Change the following lines only, if you add, remove or rename
     294             :     // member functions of the current class,
     295             :     // because these macros are need by auto register mechanism.
     296             : 
     297           2 :     CPPUNIT_TEST_SUITE(equals);
     298           1 :     CPPUNIT_TEST(equals_001);
     299           1 :     CPPUNIT_TEST(equals_002);
     300           2 :     CPPUNIT_TEST_SUITE_END();
     301             : }; // class equals
     302             : 
     303             : // -----------------------------------------------------------------------------
     304           1 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_locale::getDefault);
     305           1 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_locale::setDefault);
     306           1 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_locale::getLanguage);
     307           1 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_locale::getCountry);
     308           1 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_locale::getVariant);
     309           1 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_locale::hashCode);
     310           1 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_locale::equals);
     311             : } // namespace rtl_locale
     312             : 
     313             : 
     314             : // -----------------------------------------------------------------------------
     315             : 
     316             : // this macro creates an empty function, which will called by the RegisterAllFunctions()
     317             : // to let the user the possibility to also register some functions by hand.
     318             : 
     319           4 : CPPUNIT_PLUGIN_IMPLEMENT();
     320             : 
     321             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10