LCOV - code coverage report
Current view: top level - basic/qa/cppunit - basic_coverage.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 70 75 93.3 %
Date: 2014-04-11 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           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           2 :     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          13 : void Coverage::test_success()
      68             : {
      69          13 :     m_nb_tests_ok += 1;
      70          13 :     fprintf(stderr,"%s,PASS\n", OUStringToOString( m_sCurrentTest, RTL_TEXTENCODING_UTF8 ).getStr() );
      71          13 : }
      72             : 
      73          13 : void Coverage::run_test(const OUString& sFileURL)
      74             : {
      75          13 :     m_sCurrentTest = sFileURL;
      76          13 :     bool result = false;
      77          13 :     MacroSnippet testMacro;
      78          13 :     testMacro.LoadSourceFromFile( sFileURL );
      79          13 :     testMacro.Compile();
      80          13 :     if( !testMacro.HasError() )
      81             :     {
      82          13 :         SbxVariableRef pResult = testMacro.Run();
      83          13 :         if( pResult && pResult->GetInteger() == 1 )
      84             :         {
      85          13 :             result = true;
      86          13 :         }
      87             :     }
      88          13 :     if(result)
      89             :     {
      90          13 :         test_success();
      91             :     }
      92             :     else
      93             :     {
      94           0 :         test_failed();
      95          13 :     }
      96          13 : }
      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          14 :         while (aDir.getNextItem(aItem) == osl::FileBase::E_None)
     108             :         {
     109          12 :             aItem.getFileStatus(aFileStatus);
     110          12 :             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          18 :         while (aDir.getNextItem(aItem) == osl::FileBase::E_None)
     125             :         {
     126          14 :             aItem.getFileStatus(aFileStatus);
     127          14 :             if(aFileStatus.isRegular())
     128             :             {
     129          13 :                 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(void)
     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.10