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-17 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          26 :     void setDefaultLocale()
      33             :     {
      34          26 :         rtl_locale_setDefault(rtl::OUString("de").getStr(), rtl::OUString("DE").getStr(), /* rtl::OUString() */ rtl::OUString("hochdeutsch").getStr() );
      35          26 :     }
      36             : 
      37           6 : class getDefault : public CppUnit::TestFixture
      38             : {
      39             : public:
      40             :     // initialise your test code values here.
      41           2 :     void setUp()
      42             :     {
      43             :         // start message
      44           2 :         rtl_locale::setDefaultLocale();
      45           2 :     }
      46             : 
      47           2 :     void tearDown()
      48             :     {
      49           2 :     }
      50             : 
      51           2 :     void getDefault_001()
      52             :     {
      53           2 :         rtl_Locale* pData = rtl_locale_getDefault();
      54           2 :         CPPUNIT_ASSERT_MESSAGE("locale must not null", pData != NULL);
      55           2 :     }
      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           4 :     CPPUNIT_TEST_SUITE(getDefault);
      62           2 :     CPPUNIT_TEST(getDefault_001);
      63           4 :     CPPUNIT_TEST_SUITE_END();
      64             : }; // class getDefault
      65             : 
      66             : 
      67           6 : class setDefault : public CppUnit::TestFixture
      68             : {
      69             : public:
      70             :     // initialise your test code values here.
      71           2 :     void setUp()
      72             :     {
      73             :         // start message
      74           2 :         rtl_locale::setDefaultLocale();
      75           2 :     }
      76             : 
      77           2 :     void tearDown()
      78             :     {
      79           2 :         setDefaultLocale();
      80           2 :     }
      81             : 
      82             :     // insert your test code here.
      83           2 :     void setDefault_001()
      84             :     {
      85           2 :         rtl_locale_setDefault(rtl::OUString("en").getStr(), rtl::OUString("US").getStr(), rtl::OUString().getStr());
      86           2 :         rtl_Locale* pData = rtl_locale_getDefault();
      87           2 :         CPPUNIT_ASSERT_MESSAGE("locale must not null", pData != NULL);
      88             : 
      89             :         // be sure to not GPF
      90           2 :     }
      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           4 :     CPPUNIT_TEST_SUITE(setDefault);
      97           2 :     CPPUNIT_TEST(setDefault_001);
      98           4 :     CPPUNIT_TEST_SUITE_END();
      99             : }; // class setDefault
     100             : 
     101             : 
     102          12 : class getLanguage : public CppUnit::TestFixture
     103             : {
     104             : public:
     105             :     // initialise your test code values here.
     106           4 :     void setUp()
     107             :     {
     108             :         // start message
     109           4 :         rtl_locale::setDefaultLocale();
     110           4 :     }
     111             : 
     112           4 :     void tearDown()
     113             :     {
     114           4 :     }
     115             : 
     116             :     // insert your test code here.
     117           2 :     void getLanguage_001()
     118             :     {
     119           2 :         rtl_Locale* pData = rtl_locale_getDefault();
     120           2 :         rtl::OUString suLanguage = pData->Language;
     121           2 :         CPPUNIT_ASSERT_MESSAGE( "locale language must be 'de'", suLanguage == "de" );
     122           2 :     }
     123           2 :     void getLanguage_002()
     124             :     {
     125           2 :         rtl_Locale* pData = rtl_locale_getDefault();
     126           2 :         rtl::OUString suLanguage(rtl_locale_getLanguage(pData), SAL_NO_ACQUIRE);
     127           2 :         CPPUNIT_ASSERT_MESSAGE( "locale language must be 'de'", suLanguage == "de" );
     128           2 :     }
     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           4 :     CPPUNIT_TEST_SUITE(getLanguage);
     135           2 :     CPPUNIT_TEST(getLanguage_001);
     136           2 :     CPPUNIT_TEST(getLanguage_002);
     137           4 :     CPPUNIT_TEST_SUITE_END();
     138             : }; // class getLanguage
     139             : 
     140             : 
     141          12 : class getCountry : public CppUnit::TestFixture
     142             : {
     143             : public:
     144             :     // initialise your test code values here.
     145           4 :     void setUp()
     146             :     {
     147             :         // start message
     148           4 :         rtl_locale::setDefaultLocale();
     149           4 :     }
     150             : 
     151           4 :     void tearDown()
     152             :     {
     153           4 :     }
     154             : 
     155             :     // insert your test code here.
     156           2 :     void getCountry_001()
     157             :     {
     158           2 :         rtl_Locale* pData = rtl_locale_getDefault();
     159           2 :         rtl::OUString suCountry = pData->Country;
     160           2 :         CPPUNIT_ASSERT_MESSAGE( "locale country must be 'DE'", suCountry == "DE" );
     161           2 :     }
     162           2 :     void getCountry_002()
     163             :     {
     164           2 :         rtl_Locale* pData = rtl_locale_getDefault();
     165           2 :         rtl::OUString suCountry(rtl_locale_getCountry(pData), SAL_NO_ACQUIRE);
     166           2 :         CPPUNIT_ASSERT_MESSAGE( "locale country must be 'DE'", suCountry == "DE" );
     167           2 :     }
     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           4 :     CPPUNIT_TEST_SUITE(getCountry);
     174           2 :     CPPUNIT_TEST(getCountry_001);
     175           2 :     CPPUNIT_TEST(getCountry_002);
     176           4 :     CPPUNIT_TEST_SUITE_END();
     177             : }; // class getCountry
     178             : 
     179             : 
     180          12 : class getVariant : public CppUnit::TestFixture
     181             : {
     182             : public:
     183             :     // initialise your test code values here.
     184           4 :     void setUp()
     185             :     {
     186             :         // start message
     187           4 :         rtl_locale::setDefaultLocale();
     188           4 :     }
     189             : 
     190           4 :     void tearDown()
     191             :     {
     192           4 :     }
     193             : 
     194             :     // insert your test code here.
     195           2 :     void getVariant_001()
     196             :     {
     197           2 :         rtl_Locale* pData = rtl_locale_getDefault();
     198           2 :         rtl::OUString suVariant = pData->Variant;
     199           2 :         CPPUNIT_ASSERT_MESSAGE( "locale variant must be 'hochdeutsch'", suVariant == "hochdeutsch" );
     200           2 :     }
     201           2 :     void getVariant_002()
     202             :     {
     203           2 :         rtl_Locale* pData = rtl_locale_getDefault();
     204           2 :         rtl::OUString suVariant(rtl_locale_getVariant(pData), SAL_NO_ACQUIRE);
     205           2 :         CPPUNIT_ASSERT_MESSAGE( "locale variant must be 'hochdeutsch'", suVariant == "hochdeutsch" );
     206           2 :     }
     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           4 :     CPPUNIT_TEST_SUITE(getVariant);
     213           2 :     CPPUNIT_TEST(getVariant_001);
     214           2 :     CPPUNIT_TEST(getVariant_002);
     215           4 :     CPPUNIT_TEST_SUITE_END();
     216             : }; // class getVariant
     217             : 
     218             : 
     219          12 : class hashCode : public CppUnit::TestFixture
     220             : {
     221             : public:
     222             :     // initialise your test code values here.
     223           4 :     void setUp()
     224             :     {
     225             :         // start message
     226           4 :         rtl_locale::setDefaultLocale();
     227           4 :     }
     228             : 
     229           4 :     void tearDown()
     230             :     {
     231           4 :     }
     232             : 
     233             :     // insert your test code here.
     234           2 :     void hashCode_001()
     235             :     {
     236           2 :         rtl_Locale* pData = rtl_locale_getDefault();
     237           2 :         sal_Int32 nHashCode = pData->HashCode;
     238           2 :         CPPUNIT_ASSERT_MESSAGE("locale hashcode must be 3831", nHashCode != 0);
     239           2 :     }
     240           2 :     void hashCode_002()
     241             :     {
     242           2 :         rtl_Locale* pData = rtl_locale_getDefault();
     243           2 :         sal_Int32 nHashCode = rtl_locale_hashCode(pData);
     244           2 :         CPPUNIT_ASSERT_MESSAGE("locale hashcode must be 3831", nHashCode != 0);
     245           2 :     }
     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           4 :     CPPUNIT_TEST_SUITE(hashCode);
     252           2 :     CPPUNIT_TEST(hashCode_001);
     253           2 :     CPPUNIT_TEST(hashCode_002);
     254           4 :     CPPUNIT_TEST_SUITE_END();
     255             : }; // class hashCode
     256             : 
     257             : 
     258          12 : class equals : public CppUnit::TestFixture
     259             : {
     260             : public:
     261             :     // initialise your test code values here.
     262           4 :     void setUp()
     263             :     {
     264             :         // start message
     265           4 :         rtl_locale::setDefaultLocale();
     266           4 :     }
     267             : 
     268           4 :     void tearDown()
     269             :     {
     270           4 :     }
     271             : 
     272             :     // insert your test code here.
     273           2 :     void equals_001()
     274             :     {
     275           2 :         rtl_Locale* pData1 = rtl_locale_register(rtl::OUString("en").getStr(), rtl::OUString("US").getStr(), rtl::OUString().getStr());
     276           2 :         rtl_Locale* pData2 = rtl_locale_register(rtl::OUString("en").getStr(), rtl::OUString("US").getStr(), rtl::OUString().getStr());
     277             : 
     278           2 :         sal_Bool bLocaleAreEqual = sal_False;
     279           2 :         bLocaleAreEqual = (pData1 == pData2);
     280             : 
     281           2 :         CPPUNIT_ASSERT_MESSAGE("check operator ==()", bLocaleAreEqual == sal_True);
     282           2 :     }
     283             : 
     284           2 :     void equals_002()
     285             :     {
     286           2 :         rtl_Locale* pData1 = rtl_locale_register(rtl::OUString("en").getStr(), rtl::OUString("US").getStr(), rtl::OUString().getStr());
     287           2 :         rtl_Locale* pData2 = rtl_locale_register(rtl::OUString("en").getStr(), rtl::OUString("US").getStr(), rtl::OUString().getStr());
     288             : 
     289           2 :         sal_Int32 nEqual = rtl_locale_equals(pData1, pData2);
     290           2 :         CPPUNIT_ASSERT(nEqual != 0);
     291           2 :     }
     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           4 :     CPPUNIT_TEST_SUITE(equals);
     298           2 :     CPPUNIT_TEST(equals_001);
     299           2 :     CPPUNIT_TEST(equals_002);
     300           4 :     CPPUNIT_TEST_SUITE_END();
     301             : }; // class equals
     302             : 
     303             : // -----------------------------------------------------------------------------
     304           2 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_locale::getDefault);
     305           2 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_locale::setDefault);
     306           2 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_locale::getLanguage);
     307           2 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_locale::getCountry);
     308           2 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_locale::getVariant);
     309           2 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_locale::hashCode);
     310           2 : 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           8 : CPPUNIT_PLUGIN_IMPLEMENT();
     320             : 
     321             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10