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

Generated by: LCOV version 1.11