LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/basic/qa/cppunit - basic_coverage.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 69 78 88.5 %
Date: 2013-07-09 Functions: 14 17 82.4 %
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             : 
      10             : #include "basictest.hxx"
      11             : #include <osl/file.hxx>
      12             : #include "basic/sbmod.hxx"
      13             : #include "basic/sbmeth.hxx"
      14             : #include <i18nlangtag/languagetag.hxx>
      15             : #include <unotools/syslocaleoptions.hxx>
      16             : 
      17             : namespace
      18             : {
      19             : 
      20             : class Coverage : public test::BootstrapFixture
      21             : {
      22             : private:
      23             :     typedef std::vector< OUString > StringVec;
      24             :     int  m_nb_tests;
      25             :     int  m_nb_tests_ok;
      26             :     int  m_nb_tests_skipped;
      27             :     OUString m_sCurrentTest;
      28             :     void process_directory(OUString sDirName);
      29             :     void run_test(OUString sFileName);
      30             :     void test_start(OUString /* sFileName */);
      31             :     void test_failed(void);
      32             :     void test_success(void);
      33             :     void print_summary() {};
      34             :     StringVec get_subdirnames( const OUString& sDirName );
      35             : 
      36             : public:
      37             :     Coverage();
      38             :     ~Coverage();
      39             : 
      40             :     void Coverage_Iterator();
      41             : 
      42             :     // Adds code needed to register the test suite
      43           2 :     CPPUNIT_TEST_SUITE(Coverage);
      44             : 
      45             :     // Declares the method as a test to call
      46           1 :     CPPUNIT_TEST(Coverage_Iterator);
      47             : 
      48             :     // End of test suite definition
      49           2 :     CPPUNIT_TEST_SUITE_END();
      50             : };
      51             : 
      52           1 : Coverage::Coverage()
      53             :     : BootstrapFixture(true, false)
      54             :     , m_nb_tests(0)
      55             :     , m_nb_tests_ok(0)
      56           1 :     , m_nb_tests_skipped(0)
      57             : {
      58           1 : }
      59             : 
      60           3 : Coverage::~Coverage()
      61             : {
      62           1 :     fprintf(stderr,"basic coverage Summary : skipped:%d pass:%d\n", m_nb_tests_skipped, m_nb_tests_ok );
      63           2 : }
      64             : 
      65           0 : void Coverage::test_start(OUString sFileName)
      66             : {
      67           0 :     m_nb_tests += 1;
      68           0 :     m_sCurrentTest = sFileName;
      69           0 : }
      70             : 
      71           0 : void Coverage::test_failed()
      72             : {
      73           0 :     CPPUNIT_FAIL(
      74           0 :         OUStringToOString(m_sCurrentTest, RTL_TEXTENCODING_UTF8).getStr());
      75           0 : }
      76             : 
      77           5 : void Coverage::test_success()
      78             : {
      79           5 :     m_nb_tests_ok += 1;
      80           5 :     fprintf(stderr,"%s,PASS\n", OUStringToOString( m_sCurrentTest, RTL_TEXTENCODING_UTF8 ).getStr() );
      81           5 : }
      82             : 
      83           5 : void Coverage::run_test(OUString sFileURL)
      84             : {
      85           5 :     bool result = false;
      86           5 :     MacroSnippet testMacro;
      87           5 :     testMacro.LoadSourceFromFile( sFileURL );
      88           5 :     testMacro.Compile();
      89           5 :     if( !testMacro.HasError() )
      90             :     {
      91           5 :         SbxVariableRef pResult = testMacro.Run();
      92           5 :         if( pResult && pResult->GetInteger() == 1 )
      93             :         {
      94           5 :             result = true;
      95           5 :         }
      96             :     }
      97           5 :     if(result)
      98             :     {
      99           5 :         test_success();
     100             :     }
     101             :     else
     102             :     {
     103           0 :         test_failed();
     104           5 :     }
     105           5 : }
     106             : 
     107           1 : Coverage::StringVec Coverage::get_subdirnames( const OUString& sDirName )
     108             : {
     109           1 :     Coverage::StringVec sSubDirNames;
     110           2 :     osl::Directory aDir(sDirName);
     111           2 :     osl::DirectoryItem aItem;
     112           2 :     osl::FileStatus aFileStatus(osl_FileStatus_Mask_FileURL|osl_FileStatus_Mask_Type);
     113             : 
     114           1 :     if(osl::FileBase::E_None == aDir.open())
     115             :     {
     116           6 :         while (aDir.getNextItem(aItem) == osl::FileBase::E_None)
     117             :         {
     118           4 :             aItem.getFileStatus(aFileStatus);
     119           4 :             if(aFileStatus.isDirectory())
     120           1 :                 sSubDirNames.push_back( aFileStatus.getFileURL() );
     121             :         }
     122             :     }
     123           2 :     return sSubDirNames;
     124             : }
     125           2 : void Coverage::process_directory(OUString sDirName)
     126             : {
     127           2 :     osl::Directory aDir(sDirName);
     128           4 :     osl::DirectoryItem aItem;
     129           4 :     osl::FileStatus aFileStatus(osl_FileStatus_Mask_FileURL|osl_FileStatus_Mask_Type);
     130             : 
     131           2 :     if(osl::FileBase::E_None == aDir.open())
     132             :     {
     133          10 :         while (aDir.getNextItem(aItem) == osl::FileBase::E_None)
     134             :         {
     135           6 :             aItem.getFileStatus(aFileStatus);
     136           6 :             if(aFileStatus.isRegular())
     137             :             {
     138           5 :                 run_test(aFileStatus.getFileURL());
     139             :             }
     140             :         }
     141             :     }
     142             :     else
     143             :     {
     144             :     }
     145           4 :     fprintf(stderr,"end process directory\n");
     146           2 : }
     147             : 
     148           1 : void Coverage::Coverage_Iterator(void)
     149             : {
     150           1 :     OUString sDirName = getURLFromSrc("/basic/qa/basic_coverage/");
     151             : 
     152           1 :     CPPUNIT_ASSERT(!sDirName.isEmpty());
     153           1 :     process_directory(sDirName); // any files in the root test dir are run in test harness default locale ( en-US )
     154           2 :     Coverage::StringVec sLangDirs = get_subdirnames( sDirName );
     155             : 
     156           2 :     for ( Coverage::StringVec::iterator it = sLangDirs.begin(), it_end = sLangDirs.end(); it != it_end; ++it )
     157             :     {
     158           1 :         OUString sDir( *it );
     159           1 :         sal_Int32 nSlash = (*it).lastIndexOf('/');
     160           1 :         if ( nSlash != -1 )
     161             :         {
     162           1 :             OUString sLangISO = sDir.copy( nSlash + 1 );
     163           2 :             LanguageTag aLocale( sLangISO );
     164           1 :             if ( aLocale.isValidBcp47() )
     165             :             {
     166           1 :                 SvtSysLocaleOptions aLocalOptions;
     167             :                 // set locale for test dir
     168           1 :                 aLocalOptions.SetLocaleConfigString( sLangISO );
     169           1 :                 process_directory(sDir);
     170           1 :             }
     171             :         }
     172           2 :     }
     173           1 : }
     174             : 
     175           1 :   CPPUNIT_TEST_SUITE_REGISTRATION(Coverage);
     176             : 
     177             : }
     178           4 : CPPUNIT_PLUGIN_IMPLEMENT();
     179             : 
     180             : 
     181             : 
     182             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10