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

Generated by: LCOV version 1.10