LCOV - code coverage report
Current view: top level - sal/qa/rtl/locale - rtl_locale.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 142 142 100.0 %
Date: 2015-06-13 12:38:46 Functions: 93 94 98.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             :  * 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() SAL_OVERRIDE
      42             :     {
      43             :         // start message
      44           1 :         rtl_locale::setDefaultLocale();
      45           1 :     }
      46             : 
      47           1 :     void tearDown() SAL_OVERRIDE
      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           5 :     CPPUNIT_TEST_SUITE_END();
      64             : }; // class getDefault
      65             : 
      66           3 : class setDefault : public CppUnit::TestFixture
      67             : {
      68             : public:
      69             :     // initialise your test code values here.
      70           1 :     void setUp() SAL_OVERRIDE
      71             :     {
      72             :         // start message
      73           1 :         rtl_locale::setDefaultLocale();
      74           1 :     }
      75             : 
      76           1 :     void tearDown() SAL_OVERRIDE
      77             :     {
      78           1 :         setDefaultLocale();
      79           1 :     }
      80             : 
      81             :     // insert your test code here.
      82           1 :     void setDefault_001()
      83             :     {
      84           1 :         rtl_locale_setDefault(rtl::OUString("en").getStr(), rtl::OUString("US").getStr(), rtl::OUString().getStr());
      85           1 :         rtl_Locale* pData = rtl_locale_getDefault();
      86           1 :         CPPUNIT_ASSERT_MESSAGE("locale must not null", pData != NULL);
      87             : 
      88             :         // be sure to not GPF
      89           1 :     }
      90             : 
      91             :     // Change the following lines only, if you add, remove or rename
      92             :     // member functions of the current class,
      93             :     // because these macros are need by auto register mechanism.
      94             : 
      95           2 :     CPPUNIT_TEST_SUITE(setDefault);
      96           1 :     CPPUNIT_TEST(setDefault_001);
      97           5 :     CPPUNIT_TEST_SUITE_END();
      98             : }; // class setDefault
      99             : 
     100           6 : class getLanguage : public CppUnit::TestFixture
     101             : {
     102             : public:
     103             :     // initialise your test code values here.
     104           2 :     void setUp() SAL_OVERRIDE
     105             :     {
     106             :         // start message
     107           2 :         rtl_locale::setDefaultLocale();
     108           2 :     }
     109             : 
     110           2 :     void tearDown() SAL_OVERRIDE
     111             :     {
     112           2 :     }
     113             : 
     114             :     // insert your test code here.
     115           1 :     void getLanguage_001()
     116             :     {
     117           1 :         rtl_Locale* pData = rtl_locale_getDefault();
     118           1 :         rtl::OUString suLanguage = pData->Language;
     119           1 :         CPPUNIT_ASSERT_MESSAGE( "locale language must be 'de'", suLanguage == "de" );
     120           1 :     }
     121           1 :     void getLanguage_002()
     122             :     {
     123           1 :         rtl_Locale* pData = rtl_locale_getDefault();
     124           1 :         rtl::OUString suLanguage(rtl_locale_getLanguage(pData), SAL_NO_ACQUIRE);
     125           1 :         CPPUNIT_ASSERT_MESSAGE( "locale language must be 'de'", suLanguage == "de" );
     126           1 :     }
     127             : 
     128             :     // Change the following lines only, if you add, remove or rename
     129             :     // member functions of the current class,
     130             :     // because these macros are need by auto register mechanism.
     131             : 
     132           2 :     CPPUNIT_TEST_SUITE(getLanguage);
     133           1 :     CPPUNIT_TEST(getLanguage_001);
     134           1 :     CPPUNIT_TEST(getLanguage_002);
     135           5 :     CPPUNIT_TEST_SUITE_END();
     136             : }; // class getLanguage
     137             : 
     138           6 : class getCountry : public CppUnit::TestFixture
     139             : {
     140             : public:
     141             :     // initialise your test code values here.
     142           2 :     void setUp() SAL_OVERRIDE
     143             :     {
     144             :         // start message
     145           2 :         rtl_locale::setDefaultLocale();
     146           2 :     }
     147             : 
     148           2 :     void tearDown() SAL_OVERRIDE
     149             :     {
     150           2 :     }
     151             : 
     152             :     // insert your test code here.
     153           1 :     void getCountry_001()
     154             :     {
     155           1 :         rtl_Locale* pData = rtl_locale_getDefault();
     156           1 :         rtl::OUString suCountry = pData->Country;
     157           1 :         CPPUNIT_ASSERT_MESSAGE( "locale country must be 'DE'", suCountry == "DE" );
     158           1 :     }
     159           1 :     void getCountry_002()
     160             :     {
     161           1 :         rtl_Locale* pData = rtl_locale_getDefault();
     162           1 :         rtl::OUString suCountry(rtl_locale_getCountry(pData), SAL_NO_ACQUIRE);
     163           1 :         CPPUNIT_ASSERT_MESSAGE( "locale country must be 'DE'", suCountry == "DE" );
     164           1 :     }
     165             : 
     166             :     // Change the following lines only, if you add, remove or rename
     167             :     // member functions of the current class,
     168             :     // because these macros are need by auto register mechanism.
     169             : 
     170           2 :     CPPUNIT_TEST_SUITE(getCountry);
     171           1 :     CPPUNIT_TEST(getCountry_001);
     172           1 :     CPPUNIT_TEST(getCountry_002);
     173           5 :     CPPUNIT_TEST_SUITE_END();
     174             : }; // class getCountry
     175             : 
     176           6 : class getVariant : public CppUnit::TestFixture
     177             : {
     178             : public:
     179             :     // initialise your test code values here.
     180           2 :     void setUp() SAL_OVERRIDE
     181             :     {
     182             :         // start message
     183           2 :         rtl_locale::setDefaultLocale();
     184           2 :     }
     185             : 
     186           2 :     void tearDown() SAL_OVERRIDE
     187             :     {
     188           2 :     }
     189             : 
     190             :     // insert your test code here.
     191           1 :     void getVariant_001()
     192             :     {
     193           1 :         rtl_Locale* pData = rtl_locale_getDefault();
     194           1 :         rtl::OUString suVariant = pData->Variant;
     195           1 :         CPPUNIT_ASSERT_MESSAGE( "locale variant must be 'hochdeutsch'", suVariant == "hochdeutsch" );
     196           1 :     }
     197           1 :     void getVariant_002()
     198             :     {
     199           1 :         rtl_Locale* pData = rtl_locale_getDefault();
     200           1 :         rtl::OUString suVariant(rtl_locale_getVariant(pData), SAL_NO_ACQUIRE);
     201           1 :         CPPUNIT_ASSERT_MESSAGE( "locale variant must be 'hochdeutsch'", suVariant == "hochdeutsch" );
     202           1 :     }
     203             : 
     204             :     // Change the following lines only, if you add, remove or rename
     205             :     // member functions of the current class,
     206             :     // because these macros are need by auto register mechanism.
     207             : 
     208           2 :     CPPUNIT_TEST_SUITE(getVariant);
     209           1 :     CPPUNIT_TEST(getVariant_001);
     210           1 :     CPPUNIT_TEST(getVariant_002);
     211           5 :     CPPUNIT_TEST_SUITE_END();
     212             : }; // class getVariant
     213             : 
     214           6 : class hashCode : public CppUnit::TestFixture
     215             : {
     216             : public:
     217             :     // initialise your test code values here.
     218           2 :     void setUp() SAL_OVERRIDE
     219             :     {
     220             :         // start message
     221           2 :         rtl_locale::setDefaultLocale();
     222           2 :     }
     223             : 
     224           2 :     void tearDown() SAL_OVERRIDE
     225             :     {
     226           2 :     }
     227             : 
     228             :     // insert your test code here.
     229           1 :     void hashCode_001()
     230             :     {
     231           1 :         rtl_Locale* pData = rtl_locale_getDefault();
     232           1 :         sal_Int32 nHashCode = pData->HashCode;
     233           1 :         CPPUNIT_ASSERT_MESSAGE("locale hashcode must be 3831", nHashCode != 0);
     234           1 :     }
     235           1 :     void hashCode_002()
     236             :     {
     237           1 :         rtl_Locale* pData = rtl_locale_getDefault();
     238           1 :         sal_Int32 nHashCode = rtl_locale_hashCode(pData);
     239           1 :         CPPUNIT_ASSERT_MESSAGE("locale hashcode must be 3831", nHashCode != 0);
     240           1 :     }
     241             : 
     242             :     // Change the following lines only, if you add, remove or rename
     243             :     // member functions of the current class,
     244             :     // because these macros are need by auto register mechanism.
     245             : 
     246           2 :     CPPUNIT_TEST_SUITE(hashCode);
     247           1 :     CPPUNIT_TEST(hashCode_001);
     248           1 :     CPPUNIT_TEST(hashCode_002);
     249           5 :     CPPUNIT_TEST_SUITE_END();
     250             : }; // class hashCode
     251             : 
     252           6 : class equals : public CppUnit::TestFixture
     253             : {
     254             : public:
     255             :     // initialise your test code values here.
     256           2 :     void setUp() SAL_OVERRIDE
     257             :     {
     258             :         // start message
     259           2 :         rtl_locale::setDefaultLocale();
     260           2 :     }
     261             : 
     262           2 :     void tearDown() SAL_OVERRIDE
     263             :     {
     264           2 :     }
     265             : 
     266             :     // insert your test code here.
     267           1 :     void equals_001()
     268             :     {
     269           1 :         rtl_Locale* pData1 = rtl_locale_register(rtl::OUString("en").getStr(), rtl::OUString("US").getStr(), rtl::OUString().getStr());
     270           1 :         rtl_Locale* pData2 = rtl_locale_register(rtl::OUString("en").getStr(), rtl::OUString("US").getStr(), rtl::OUString().getStr());
     271             : 
     272           1 :         bool bLocaleAreEqual = false;
     273           1 :         bLocaleAreEqual = (pData1 == pData2);
     274             : 
     275           1 :         CPPUNIT_ASSERT_MESSAGE("check operator ==()", bLocaleAreEqual);
     276           1 :     }
     277             : 
     278           1 :     void equals_002()
     279             :     {
     280           1 :         rtl_Locale* pData1 = rtl_locale_register(rtl::OUString("en").getStr(), rtl::OUString("US").getStr(), rtl::OUString().getStr());
     281           1 :         rtl_Locale* pData2 = rtl_locale_register(rtl::OUString("en").getStr(), rtl::OUString("US").getStr(), rtl::OUString().getStr());
     282             : 
     283           1 :         sal_Int32 nEqual = rtl_locale_equals(pData1, pData2);
     284           1 :         CPPUNIT_ASSERT(nEqual != 0);
     285           1 :     }
     286             : 
     287             :     // Change the following lines only, if you add, remove or rename
     288             :     // member functions of the current class,
     289             :     // because these macros are need by auto register mechanism.
     290             : 
     291           2 :     CPPUNIT_TEST_SUITE(equals);
     292           1 :     CPPUNIT_TEST(equals_001);
     293           1 :     CPPUNIT_TEST(equals_002);
     294           5 :     CPPUNIT_TEST_SUITE_END();
     295             : }; // class equals
     296             : 
     297           1 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_locale::getDefault);
     298           1 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_locale::setDefault);
     299           1 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_locale::getLanguage);
     300           1 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_locale::getCountry);
     301           1 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_locale::getVariant);
     302           1 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_locale::hashCode);
     303           1 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_locale::equals);
     304             : } // namespace rtl_locale
     305             : 
     306             : // this macro creates an empty function, which will called by the RegisterAllFunctions()
     307             : // to let the user the possibility to also register some functions by hand.
     308             : 
     309           4 : CPPUNIT_PLUGIN_IMPLEMENT();
     310             : 
     311             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11