LCOV - code coverage report
Current view: top level - sal/qa/rtl/locale - rtl_locale.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 142 142 100.0 %
Date: 2014-11-03 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() SAL_OVERRIDE
      42             :     {
      43             :         // start message
      44           2 :         rtl_locale::setDefaultLocale();
      45           2 :     }
      46             : 
      47           2 :     void tearDown() SAL_OVERRIDE
      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           6 : class setDefault : public CppUnit::TestFixture
      67             : {
      68             : public:
      69             :     // initialise your test code values here.
      70           2 :     void setUp() SAL_OVERRIDE
      71             :     {
      72             :         // start message
      73           2 :         rtl_locale::setDefaultLocale();
      74           2 :     }
      75             : 
      76           2 :     void tearDown() SAL_OVERRIDE
      77             :     {
      78           2 :         setDefaultLocale();
      79           2 :     }
      80             : 
      81             :     // insert your test code here.
      82           2 :     void setDefault_001()
      83             :     {
      84           2 :         rtl_locale_setDefault(rtl::OUString("en").getStr(), rtl::OUString("US").getStr(), rtl::OUString().getStr());
      85           2 :         rtl_Locale* pData = rtl_locale_getDefault();
      86           2 :         CPPUNIT_ASSERT_MESSAGE("locale must not null", pData != NULL);
      87             : 
      88             :         // be sure to not GPF
      89           2 :     }
      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           4 :     CPPUNIT_TEST_SUITE(setDefault);
      96           2 :     CPPUNIT_TEST(setDefault_001);
      97           4 :     CPPUNIT_TEST_SUITE_END();
      98             : }; // class setDefault
      99             : 
     100          12 : class getLanguage : public CppUnit::TestFixture
     101             : {
     102             : public:
     103             :     // initialise your test code values here.
     104           4 :     void setUp() SAL_OVERRIDE
     105             :     {
     106             :         // start message
     107           4 :         rtl_locale::setDefaultLocale();
     108           4 :     }
     109             : 
     110           4 :     void tearDown() SAL_OVERRIDE
     111             :     {
     112           4 :     }
     113             : 
     114             :     // insert your test code here.
     115           2 :     void getLanguage_001()
     116             :     {
     117           2 :         rtl_Locale* pData = rtl_locale_getDefault();
     118           2 :         rtl::OUString suLanguage = pData->Language;
     119           2 :         CPPUNIT_ASSERT_MESSAGE( "locale language must be 'de'", suLanguage == "de" );
     120           2 :     }
     121           2 :     void getLanguage_002()
     122             :     {
     123           2 :         rtl_Locale* pData = rtl_locale_getDefault();
     124           2 :         rtl::OUString suLanguage(rtl_locale_getLanguage(pData), SAL_NO_ACQUIRE);
     125           2 :         CPPUNIT_ASSERT_MESSAGE( "locale language must be 'de'", suLanguage == "de" );
     126           2 :     }
     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           4 :     CPPUNIT_TEST_SUITE(getLanguage);
     133           2 :     CPPUNIT_TEST(getLanguage_001);
     134           2 :     CPPUNIT_TEST(getLanguage_002);
     135           4 :     CPPUNIT_TEST_SUITE_END();
     136             : }; // class getLanguage
     137             : 
     138          12 : class getCountry : public CppUnit::TestFixture
     139             : {
     140             : public:
     141             :     // initialise your test code values here.
     142           4 :     void setUp() SAL_OVERRIDE
     143             :     {
     144             :         // start message
     145           4 :         rtl_locale::setDefaultLocale();
     146           4 :     }
     147             : 
     148           4 :     void tearDown() SAL_OVERRIDE
     149             :     {
     150           4 :     }
     151             : 
     152             :     // insert your test code here.
     153           2 :     void getCountry_001()
     154             :     {
     155           2 :         rtl_Locale* pData = rtl_locale_getDefault();
     156           2 :         rtl::OUString suCountry = pData->Country;
     157           2 :         CPPUNIT_ASSERT_MESSAGE( "locale country must be 'DE'", suCountry == "DE" );
     158           2 :     }
     159           2 :     void getCountry_002()
     160             :     {
     161           2 :         rtl_Locale* pData = rtl_locale_getDefault();
     162           2 :         rtl::OUString suCountry(rtl_locale_getCountry(pData), SAL_NO_ACQUIRE);
     163           2 :         CPPUNIT_ASSERT_MESSAGE( "locale country must be 'DE'", suCountry == "DE" );
     164           2 :     }
     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           4 :     CPPUNIT_TEST_SUITE(getCountry);
     171           2 :     CPPUNIT_TEST(getCountry_001);
     172           2 :     CPPUNIT_TEST(getCountry_002);
     173           4 :     CPPUNIT_TEST_SUITE_END();
     174             : }; // class getCountry
     175             : 
     176          12 : class getVariant : public CppUnit::TestFixture
     177             : {
     178             : public:
     179             :     // initialise your test code values here.
     180           4 :     void setUp() SAL_OVERRIDE
     181             :     {
     182             :         // start message
     183           4 :         rtl_locale::setDefaultLocale();
     184           4 :     }
     185             : 
     186           4 :     void tearDown() SAL_OVERRIDE
     187             :     {
     188           4 :     }
     189             : 
     190             :     // insert your test code here.
     191           2 :     void getVariant_001()
     192             :     {
     193           2 :         rtl_Locale* pData = rtl_locale_getDefault();
     194           2 :         rtl::OUString suVariant = pData->Variant;
     195           2 :         CPPUNIT_ASSERT_MESSAGE( "locale variant must be 'hochdeutsch'", suVariant == "hochdeutsch" );
     196           2 :     }
     197           2 :     void getVariant_002()
     198             :     {
     199           2 :         rtl_Locale* pData = rtl_locale_getDefault();
     200           2 :         rtl::OUString suVariant(rtl_locale_getVariant(pData), SAL_NO_ACQUIRE);
     201           2 :         CPPUNIT_ASSERT_MESSAGE( "locale variant must be 'hochdeutsch'", suVariant == "hochdeutsch" );
     202           2 :     }
     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           4 :     CPPUNIT_TEST_SUITE(getVariant);
     209           2 :     CPPUNIT_TEST(getVariant_001);
     210           2 :     CPPUNIT_TEST(getVariant_002);
     211           4 :     CPPUNIT_TEST_SUITE_END();
     212             : }; // class getVariant
     213             : 
     214          12 : class hashCode : public CppUnit::TestFixture
     215             : {
     216             : public:
     217             :     // initialise your test code values here.
     218           4 :     void setUp() SAL_OVERRIDE
     219             :     {
     220             :         // start message
     221           4 :         rtl_locale::setDefaultLocale();
     222           4 :     }
     223             : 
     224           4 :     void tearDown() SAL_OVERRIDE
     225             :     {
     226           4 :     }
     227             : 
     228             :     // insert your test code here.
     229           2 :     void hashCode_001()
     230             :     {
     231           2 :         rtl_Locale* pData = rtl_locale_getDefault();
     232           2 :         sal_Int32 nHashCode = pData->HashCode;
     233           2 :         CPPUNIT_ASSERT_MESSAGE("locale hashcode must be 3831", nHashCode != 0);
     234           2 :     }
     235           2 :     void hashCode_002()
     236             :     {
     237           2 :         rtl_Locale* pData = rtl_locale_getDefault();
     238           2 :         sal_Int32 nHashCode = rtl_locale_hashCode(pData);
     239           2 :         CPPUNIT_ASSERT_MESSAGE("locale hashcode must be 3831", nHashCode != 0);
     240           2 :     }
     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           4 :     CPPUNIT_TEST_SUITE(hashCode);
     247           2 :     CPPUNIT_TEST(hashCode_001);
     248           2 :     CPPUNIT_TEST(hashCode_002);
     249           4 :     CPPUNIT_TEST_SUITE_END();
     250             : }; // class hashCode
     251             : 
     252          12 : class equals : public CppUnit::TestFixture
     253             : {
     254             : public:
     255             :     // initialise your test code values here.
     256           4 :     void setUp() SAL_OVERRIDE
     257             :     {
     258             :         // start message
     259           4 :         rtl_locale::setDefaultLocale();
     260           4 :     }
     261             : 
     262           4 :     void tearDown() SAL_OVERRIDE
     263             :     {
     264           4 :     }
     265             : 
     266             :     // insert your test code here.
     267           2 :     void equals_001()
     268             :     {
     269           2 :         rtl_Locale* pData1 = rtl_locale_register(rtl::OUString("en").getStr(), rtl::OUString("US").getStr(), rtl::OUString().getStr());
     270           2 :         rtl_Locale* pData2 = rtl_locale_register(rtl::OUString("en").getStr(), rtl::OUString("US").getStr(), rtl::OUString().getStr());
     271             : 
     272           2 :         bool bLocaleAreEqual = false;
     273           2 :         bLocaleAreEqual = (pData1 == pData2);
     274             : 
     275           2 :         CPPUNIT_ASSERT_MESSAGE("check operator ==()", bLocaleAreEqual);
     276           2 :     }
     277             : 
     278           2 :     void equals_002()
     279             :     {
     280           2 :         rtl_Locale* pData1 = rtl_locale_register(rtl::OUString("en").getStr(), rtl::OUString("US").getStr(), rtl::OUString().getStr());
     281           2 :         rtl_Locale* pData2 = rtl_locale_register(rtl::OUString("en").getStr(), rtl::OUString("US").getStr(), rtl::OUString().getStr());
     282             : 
     283           2 :         sal_Int32 nEqual = rtl_locale_equals(pData1, pData2);
     284           2 :         CPPUNIT_ASSERT(nEqual != 0);
     285           2 :     }
     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           4 :     CPPUNIT_TEST_SUITE(equals);
     292           2 :     CPPUNIT_TEST(equals_001);
     293           2 :     CPPUNIT_TEST(equals_002);
     294           4 :     CPPUNIT_TEST_SUITE_END();
     295             : }; // class equals
     296             : 
     297           2 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_locale::getDefault);
     298           2 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_locale::setDefault);
     299           2 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_locale::getLanguage);
     300           2 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_locale::getCountry);
     301           2 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_locale::getVariant);
     302           2 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_locale::hashCode);
     303           2 : 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           8 : CPPUNIT_PLUGIN_IMPLEMENT();
     310             : 
     311             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10