LCOV - code coverage report
Current view: top level - sal/qa/osl/module - osl_Module.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 152 159 95.6 %
Date: 2012-08-25 Functions: 63 65 96.9 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 355 804 44.2 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            :  /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : //------------------------------------------------------------------------
      31                 :            : // include files
      32                 :            : //------------------------------------------------------------------------
      33                 :            : #include <osl_Module_Const.h>
      34                 :            : 
      35                 :            : using namespace osl;
      36                 :            : 
      37                 :            : using ::rtl::OUString;
      38                 :            : using ::rtl::OUStringToOString;
      39                 :            : using ::rtl::OString;
      40                 :            : //------------------------------------------------------------------------
      41                 :            : // helper functions and classes
      42                 :            : //------------------------------------------------------------------------
      43                 :            : 
      44                 :            : /** print Boolean value.
      45                 :            : */
      46                 :            : inline void printBool( sal_Bool bOk )
      47                 :            : {
      48                 :            :     printf("#printBool# " );
      49                 :            :     ( sal_True == bOk ) ? printf( "TRUE!\n" )
      50                 :            :                         : printf( "FALSE!\n" );
      51                 :            : }
      52                 :            : 
      53                 :            : /** print a UNI_CODE String.
      54                 :            : */
      55                 :            : inline void printUString( const ::rtl::OUString & str )
      56                 :            : {
      57                 :            :     rtl::OString aString;
      58                 :            : 
      59                 :            :     printf("#printUString_u# " );
      60                 :            :     aString = ::rtl::OUStringToOString( str, RTL_TEXTENCODING_ASCII_US );
      61                 :            :     printf("%s\n", aString.getStr( ) );
      62                 :            : }
      63                 :            : 
      64                 :            : /** get dll file URL.
      65                 :            : */
      66                 :         50 : inline ::rtl::OUString getDllURL( void )
      67                 :            : {
      68                 :            : #if ( defined WNT )        // lib in Unix and lib in Windows are not same in file name.
      69                 :            :     ::rtl::OUString libPath( "test_Module_DLL.dll" );
      70                 :            : #else
      71                 :         50 :     ::rtl::OUString libPath( "libtest_Module_DLL.so" );
      72                 :            : #endif
      73                 :            : 
      74                 :         50 :     ::rtl::OUString dirPath, dllPath;
      75         [ +  - ]:         50 :     osl::Module::getUrlFromAddress( ( void* ) &getDllURL, dirPath );
      76                 :         50 :     dirPath = dirPath.copy( 0, dirPath.lastIndexOf('/') + 1);
      77         [ +  - ]:         50 :     osl::FileBase::getAbsoluteFileURL( dirPath, libPath, dllPath );
      78                 :            : 
      79                 :         50 :     return dllPath;
      80                 :            : }
      81                 :            : 
      82                 :            : inline sal_Bool isURL( const ::rtl::OUString pathname )
      83                 :            : {
      84                 :            :     ::rtl::OUString aPreURL( "file:///" );
      85                 :            :     return ( ( pathname.indexOf( aPreURL ) == 0 ) ? sal_True : sal_False );
      86                 :            : }
      87                 :            : 
      88                 :            : /** create a temp test directory using OUString name of full qualified URL or system path.
      89                 :            : */
      90                 :            : inline void createTestDirectory( const ::rtl::OUString dirname )
      91                 :            : {
      92                 :            :     ::rtl::OUString     aPathURL   = dirname.copy( 0 );
      93                 :            :     ::osl::FileBase::RC nError;
      94                 :            : 
      95                 :            :     if ( !isURL( dirname ) )
      96                 :            :         ::osl::FileBase::getFileURLFromSystemPath( dirname, aPathURL ); //convert if not full qualified URL
      97                 :            :     nError = ::osl::Directory::create( aPathURL );
      98                 :            :     CPPUNIT_ASSERT_MESSAGE( "In createTestDirectory Function: creation: ", ( ::osl::FileBase::E_None == nError ) || ( nError == ::osl::FileBase::E_EXIST ) );
      99                 :            : }
     100                 :            : 
     101                 :            : /** delete a temp test directory using OUString name of full qualified URL or system path.
     102                 :            : */
     103                 :            : inline void deleteTestDirectory( const ::rtl::OUString dirname )
     104                 :            : {
     105                 :            :     ::rtl::OUString     aPathURL   = dirname.copy( 0 );
     106                 :            :     ::osl::FileBase::RC nError;
     107                 :            :     if ( !isURL( dirname ) )
     108                 :            :         ::osl::FileBase::getFileURLFromSystemPath( dirname, aPathURL ); //convert if not full qualified URL
     109                 :            : 
     110                 :            :     ::osl::Directory testDir( aPathURL );
     111                 :            :     if ( testDir.isOpen( ) == sal_True )
     112                 :            :     {
     113                 :            :             testDir.close( );  //close if still open.
     114                 :            :         }
     115                 :            : 
     116                 :            :     nError = ::osl::Directory::remove( aPathURL );
     117                 :            :      CPPUNIT_ASSERT_MESSAGE( "In deleteTestDirectory function: remove ", ( ::osl::FileBase::E_None == nError ) || ( nError == ::osl::FileBase::E_NOENT ) );
     118                 :            : }
     119                 :            : 
     120                 :            : //check if the file exist
     121                 :            : inline sal_Bool ifFileExist( const ::rtl::OUString & str )
     122                 :            : {
     123                 :            :     ::rtl::OUString     aUStr;
     124                 :            :     if ( isURL( str ) )
     125                 :            :         ::osl::FileBase::getSystemPathFromFileURL( str, aUStr );
     126                 :            :     else
     127                 :            :         return sal_False;
     128                 :            : 
     129                 :            :     ::osl::File strFile( aUStr );
     130                 :            :     ::osl::FileBase::RC nError = strFile.open( osl_File_OpenFlag_Read );
     131                 :            :     if ( ::File::E_NOENT == nError )
     132                 :            :         return sal_False;
     133                 :            :     else{
     134                 :            :         strFile.close( );
     135                 :            :         return sal_True;
     136                 :            :     }
     137                 :            : }
     138                 :            : 
     139                 :            : /** detete a temp test file using OUString name.
     140                 :            : */
     141                 :            : inline void deleteTestFile( const ::rtl::OUString filename )
     142                 :            : {
     143                 :            :     ::rtl::OUString aPathURL   = filename.copy( 0 );
     144                 :            :     ::osl::FileBase::RC nError;
     145                 :            : 
     146                 :            :     if ( !isURL( filename ) )
     147                 :            :         ::osl::FileBase::getFileURLFromSystemPath( filename, aPathURL ); //convert if not full qualified URL
     148                 :            : 
     149                 :            :     nError = ::osl::File::setAttributes( aPathURL, osl_File_Attribute_GrpWrite| osl_File_Attribute_OwnWrite| osl_File_Attribute_OthWrite ); // if readonly, make writtenable.
     150                 :            :     CPPUNIT_ASSERT_MESSAGE( "In deleteTestFile Function: set writtenable ", ( ::osl::FileBase::E_None == nError ) || ( ::osl::FileBase::E_NOENT == nError ) );
     151                 :            : 
     152                 :            :     nError = ::osl::File::remove( aPathURL );
     153                 :            :     CPPUNIT_ASSERT_MESSAGE( "In deleteTestFile Function: remove ", ( ::osl::FileBase::E_None == nError ) || ( nError == ::osl::FileBase::E_NOENT ) );
     154                 :            : }
     155                 :            : 
     156                 :            : 
     157                 :            : //------------------------------------------------------------------------
     158                 :            : // test code start here
     159                 :            : //------------------------------------------------------------------------
     160                 :            : 
     161                 :            : namespace osl_Module
     162                 :            : {
     163                 :            : 
     164                 :            :     /** class and member function that is available for module test :
     165                 :            :     */
     166                 :            : 
     167                 :            :     class testClass
     168                 :            :     {
     169                 :            :     public:
     170                 :          0 :         static void myFunc()
     171                 :            :         {
     172                 :          0 :             printf("#Sun Microsystem\n");
     173                 :          0 :         };
     174                 :            :     };
     175                 :            : 
     176                 :            : 
     177                 :            :     /** testing the methods:
     178                 :            :         Module();
     179                 :            :         Module( const ::rtl::OUString& strModuleName, sal_Int32 nRtldMode = SAL_LOADMODULE_DEFAULT);
     180                 :            :     */
     181         [ -  + ]:         30 :     class ctors : public CppUnit::TestFixture
     182                 :            :     {
     183                 :            :     public:
     184                 :            :         sal_Bool bRes, bRes1;
     185                 :            : 
     186                 :          5 :         void ctors_none( )
     187                 :            :         {
     188                 :          5 :             ::osl::Module aMod;
     189                 :          5 :             bRes = aMod.is();
     190                 :            : 
     191 [ +  - ][ +  - ]:         10 :             CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor without parameter.",
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     192   [ +  -  +  - ]:         10 :                                     sal_False == bRes  );
     193                 :          5 :         }
     194                 :            : 
     195                 :          5 :         void ctors_name_mode( )
     196                 :            :         {
     197                 :          5 :             OUString aFileURL;
     198         [ +  - ]:          5 :             bRes = osl::Module::getUrlFromAddress( ( void* ) &::osl_Module::testClass::myFunc, aFileURL );
     199                 :            : 
     200         [ -  + ]:          5 :             if ( !( bRes ) )
     201                 :            :             {
     202 [ #  # ][ #  # ]:          0 :                 CPPUNIT_ASSERT_MESSAGE("Cannot locate current module.",  sal_False  );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     203                 :            :             }
     204                 :            : 
     205         [ +  - ]:          5 :             ::osl::Module aMod( aFileURL );
     206                 :          5 :             bRes = aMod.is( );
     207         [ +  - ]:          5 :             aMod.unload( );
     208                 :            : 
     209 [ +  - ][ +  - ]:         10 :             CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with load action.",
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     210   [ +  -  +  - ]:         10 :                                     sal_True == bRes  );
     211                 :          5 :         }
     212                 :            : 
     213 [ +  - ][ +  - ]:         10 :         CPPUNIT_TEST_SUITE( ctors );
         [ +  - ][ +  - ]
                 [ #  # ]
     214 [ +  - ][ +  - ]:          5 :         CPPUNIT_TEST( ctors_none );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     215 [ +  - ][ +  - ]:          5 :         CPPUNIT_TEST( ctors_name_mode );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     216 [ +  - ][ +  - ]:         10 :         CPPUNIT_TEST_SUITE_END( );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     217                 :            :     }; // class ctors
     218                 :            : 
     219                 :            : 
     220                 :            :     /** testing the methods:
     221                 :            :         static sal_Bool getUrlFromAddress(void * addr, ::rtl::OUString & libraryUrl)
     222                 :            :     */
     223         [ -  + ]:         30 :     class getUrlFromAddress : public CppUnit::TestFixture
     224                 :            :     {
     225                 :            :     public:
     226                 :            :         sal_Bool bRes, bRes1;
     227                 :            : 
     228                 :          5 :         void getUrlFromAddress_001( )
     229                 :            :         {
     230                 :          5 :             OUString aFileURL;
     231         [ +  - ]:          5 :             bRes = osl::Module::getUrlFromAddress( ( void* ) &::osl_Module::testClass::myFunc, aFileURL ) ;
     232         [ -  + ]:          5 :             if ( !( bRes ) )
     233                 :            :             {
     234 [ #  # ][ #  # ]:          0 :                 CPPUNIT_ASSERT_MESSAGE("Cannot locate current module.",  sal_False  );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     235                 :            :             }
     236                 :            : 
     237 [ +  - ][ +  - ]:         10 :             CPPUNIT_ASSERT_MESSAGE( "#test comment#: test get Module URL from address.",
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ -  + ]
         [ +  - ][ +  - ]
     238         [ +  - ]:         10 :                                     sal_True == bRes && 0 < aFileURL.lastIndexOf('/')  );
     239                 :          5 :         }
     240                 :            : 
     241                 :          5 :         void getUrlFromAddress_002( )
     242                 :            :         {
     243                 :            : #if !defined( MACOSX )
     244                 :            :             // TODO: Find out why this fails on Mac OS X
     245 [ +  - ][ +  - ]:          5 :             ::osl::Module aMod( getDllURL( ) );
     246         [ +  - ]:          5 :             FuncPtr pFunc = ( FuncPtr ) aMod.getSymbol( rtl::OUString("firstfunc") );
     247                 :            : 
     248                 :          5 :             OUString aFileURL;
     249         [ +  - ]:          5 :             bRes = osl::Module::getUrlFromAddress( ( void* )pFunc, aFileURL );
     250         [ -  + ]:          5 :             if ( !( bRes  ) )
     251                 :            :             {
     252 [ #  # ][ #  # ]:          0 :                 CPPUNIT_ASSERT_MESSAGE("Cannot locate current module.",  sal_False  );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     253                 :            :             }
     254         [ +  - ]:          5 :             aMod.unload( );
     255                 :            : 
     256 [ +  - ][ +  - ]:         10 :             CPPUNIT_ASSERT_MESSAGE( "#test comment#: load an external library, get its function address and get its URL.",
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ -  + ]
         [ +  - ][ +  - ]
         [ +  - ][ #  # ]
     257   [ +  -  +  - ]:         10 :                                     sal_True == bRes && 0 < aFileURL.lastIndexOf('/') && aFileURL.equalsIgnoreAsciiCase( getDllURL( ) ) );
     258                 :            : #endif
     259                 :          5 :         }
     260                 :            : 
     261                 :            :         /* tester comments: another case is getFunctionSymbol_001*/
     262                 :            : 
     263 [ +  - ][ +  - ]:         10 :         CPPUNIT_TEST_SUITE( getUrlFromAddress );
         [ +  - ][ +  - ]
                 [ #  # ]
     264 [ +  - ][ +  - ]:          5 :         CPPUNIT_TEST( getUrlFromAddress_001 );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     265 [ +  - ][ +  - ]:          5 :         CPPUNIT_TEST( getUrlFromAddress_002 );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     266 [ +  - ][ +  - ]:         10 :         CPPUNIT_TEST_SUITE_END( );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     267                 :            :     }; // class getUrlFromAddress
     268                 :            : 
     269                 :            : 
     270                 :            :     /** testing the method:
     271                 :            :         sal_Bool SAL_CALL load( const ::rtl::OUString& strModuleName,
     272                 :            :                                                  sal_Int32 nRtldMode = SAL_LOADMODULE_DEFAULT)
     273                 :            :     */
     274         [ -  + ]:         15 :     class load : public CppUnit::TestFixture
     275                 :            :     {
     276                 :            :     public:
     277                 :            :         sal_Bool bRes, bRes1;
     278                 :            : 
     279                 :          5 :         void load_001( )
     280                 :            :         {
     281 [ +  - ][ +  - ]:          5 :             ::osl::Module aMod( getDllURL( ) );
     282                 :          5 :             ::osl::Module aMod1;
     283                 :            : 
     284 [ +  - ][ +  - ]:          5 :             aMod1.load( getDllURL( ) );
     285                 :          5 :             bRes = oslModule(aMod) == oslModule(aMod1);
     286         [ +  - ]:          5 :             aMod.unload( );
     287         [ +  - ]:          5 :             aMod1.unload( );
     288                 :            : 
     289 [ +  - ][ +  - ]:         10 :             CPPUNIT_ASSERT_MESSAGE( "#test comment#: load function should do the same thing as constructor with library name.",
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     290   [ +  -  +  - ]:         10 :                                     sal_True == bRes  );
                 [ +  - ]
     291                 :          5 :         }
     292                 :            : 
     293 [ +  - ][ +  - ]:         10 :         CPPUNIT_TEST_SUITE( load );
         [ +  - ][ +  - ]
                 [ #  # ]
     294 [ +  - ][ +  - ]:          5 :         CPPUNIT_TEST( load_001 );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     295 [ +  - ][ +  - ]:         10 :         CPPUNIT_TEST_SUITE_END( );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     296                 :            :     }; // class load
     297                 :            : 
     298                 :            : 
     299                 :            :     /** testing the method:
     300                 :            :         void SAL_CALL unload()
     301                 :            :     */
     302         [ -  + ]:         15 :     class unload : public CppUnit::TestFixture
     303                 :            :     {
     304                 :            :     public:
     305                 :            :         sal_Bool bRes, bRes1;
     306                 :            : 
     307                 :          5 :         void unload_001( )
     308                 :            :         {
     309 [ +  - ][ +  - ]:          5 :             ::osl::Module aMod( getDllURL( ) );
     310                 :            : 
     311         [ +  - ]:          5 :             aMod.unload( );
     312                 :          5 :             bRes = oslModule(aMod) ==NULL;
     313                 :            : 
     314 [ +  - ][ +  - ]:         10 :             CPPUNIT_ASSERT_MESSAGE( "#test comment#: unload function should do the same thing as destructor.",
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     315   [ +  -  +  - ]:         10 :                                     sal_True == bRes  );
     316                 :          5 :         }
     317                 :            : 
     318 [ +  - ][ +  - ]:         10 :         CPPUNIT_TEST_SUITE( unload );
         [ +  - ][ +  - ]
                 [ #  # ]
     319 [ +  - ][ +  - ]:          5 :         CPPUNIT_TEST( unload_001 );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     320 [ +  - ][ +  - ]:         10 :         CPPUNIT_TEST_SUITE_END( );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     321                 :            :     }; // class unload
     322                 :            : 
     323                 :            : 
     324                 :            :     /** testing the methods:
     325                 :            :         sal_Bool SAL_CALL is() const
     326                 :            :     */
     327         [ -  + ]:         15 :     class is : public CppUnit::TestFixture
     328                 :            :     {
     329                 :            :     public:
     330                 :            :         sal_Bool bRes, bRes1;
     331                 :            : 
     332                 :          5 :         void is_001( )
     333                 :            :         {
     334                 :          5 :             OUString aFileURL;
     335         [ +  - ]:          5 :             bRes = osl::Module::getUrlFromAddress( ( void* ) &::osl_Module::testClass::myFunc, aFileURL );
     336         [ -  + ]:          5 :             if ( !( bRes  ) )
     337                 :            :             {
     338 [ #  # ][ #  # ]:          0 :                 CPPUNIT_ASSERT_MESSAGE("Cannot locate current module - using executable instead",  sal_False  );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     339                 :            :             }
     340                 :            : 
     341                 :          5 :             ::osl::Module aMod;
     342                 :          5 :             bRes = aMod.is( );
     343         [ +  - ]:          5 :             aMod.load( aFileURL );
     344                 :          5 :             bRes1 = aMod.is( );
     345         [ +  - ]:          5 :             aMod.unload( );
     346                 :            : 
     347 [ +  - ][ +  - ]:         10 :             CPPUNIT_ASSERT_MESSAGE( "#test comment#: test if a module is a loaded module.",
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ -  + ]
         [ +  - ][ +  - ]
     348   [ +  -  +  - ]:         10 :                                      sal_False == bRes && sal_True == bRes1);
     349                 :          5 :         }
     350 [ +  - ][ +  - ]:         10 :         CPPUNIT_TEST_SUITE( is );
         [ +  - ][ +  - ]
                 [ #  # ]
     351 [ +  - ][ +  - ]:          5 :         CPPUNIT_TEST( is_001 );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     352 [ +  - ][ +  - ]:         10 :         CPPUNIT_TEST_SUITE_END( );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     353                 :            :     }; // class is
     354                 :            : 
     355                 :            : 
     356                 :            :     /** testing the methods:
     357                 :            :         void* SAL_CALL getSymbol( const ::rtl::OUString& strSymbolName)
     358                 :            :     */
     359         [ -  + ]:         15 :     class getSymbol : public CppUnit::TestFixture
     360                 :            :     {
     361                 :            :     public:
     362                 :            :         sal_Bool bRes;
     363                 :            : 
     364                 :          5 :         void getSymbol_001( )
     365                 :            :         {
     366                 :            : #if !defined( MACOSX )
     367                 :            :             // TODO: Find out why this fails on Mac OS X
     368 [ +  - ][ +  - ]:          5 :             ::osl::Module aMod( getDllURL( ) );
     369         [ +  - ]:          5 :             FuncPtr pFunc = ( FuncPtr ) aMod.getSymbol( rtl::OUString("firstfunc") );
     370                 :          5 :             bRes = sal_False;
     371         [ +  - ]:          5 :             if ( pFunc )
     372         [ +  - ]:          5 :                 bRes = pFunc( bRes );
     373         [ +  - ]:          5 :             aMod.unload();
     374                 :            : 
     375 [ +  - ][ +  - ]:         10 :             CPPUNIT_ASSERT_MESSAGE( "#test comment#: load a dll and call one function in it.",
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     376   [ +  -  +  - ]:         10 :                                      sal_True == bRes );
     377                 :            : #endif
     378                 :          5 :         }
     379                 :            : 
     380 [ +  - ][ +  - ]:         10 :         CPPUNIT_TEST_SUITE( getSymbol );
         [ +  - ][ +  - ]
                 [ #  # ]
     381 [ +  - ][ +  - ]:          5 :         CPPUNIT_TEST( getSymbol_001 );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     382 [ +  - ][ +  - ]:         10 :         CPPUNIT_TEST_SUITE_END( );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     383                 :            :     }; // class getSymbol
     384                 :            : 
     385                 :            : 
     386                 :            :     /** testing the methods:
     387                 :            :         operator oslModule() const
     388                 :            :     */
     389         [ -  + ]:         30 :     class optr_oslModule : public CppUnit::TestFixture
     390                 :            :     {
     391                 :            :     public:
     392                 :            :         sal_Bool bRes, bRes1;
     393                 :            : 
     394                 :          5 :         void optr_oslModule_001( )
     395                 :            :         {
     396                 :            : #if !defined( MACOSX )
     397                 :            :             // TODO: Find out why this fails on Mac OS X
     398                 :          5 :             ::osl::Module aMod;
     399                 :          5 :             bRes = ( (oslModule)aMod == NULL );
     400                 :            : 
     401 [ +  - ][ +  - ]:          5 :             aMod.load( getDllURL( ) );
     402                 :          5 :             bRes1 = (oslModule)aMod != NULL;
     403                 :            : 
     404         [ +  - ]:          5 :             aMod.unload( );
     405                 :            : 
     406 [ +  - ][ +  - ]:         10 :             CPPUNIT_ASSERT_MESSAGE( "#test comment#: the m_Module of a Module instance will be NULL when is not loaded, it will not be NULL after loaded.",
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ -  + ]
         [ +  - ][ +  - ]
     407   [ +  -  +  - ]:         10 :                                      sal_True == bRes && sal_True == bRes1);
     408                 :            : #endif
     409                 :          5 :         }
     410                 :            : 
     411                 :          5 :         void optr_oslModule_002( )
     412                 :            :         {
     413                 :            : #if !defined( MACOSX )
     414                 :            :             // TODO: Find out why this fails on Mac OS X
     415 [ +  - ][ +  - ]:          5 :             ::osl::Module aMod( getDllURL( ) );
     416                 :          5 :             ::rtl::OUString funcName( "firstfunc" );
     417                 :            : 
     418         [ +  - ]:          5 :             FuncPtr pFunc = ( FuncPtr ) osl_getSymbol( (oslModule)aMod, funcName.pData );
     419                 :          5 :             bRes = sal_False;
     420         [ +  - ]:          5 :             if ( pFunc )
     421         [ +  - ]:          5 :                 bRes = pFunc( bRes );
     422                 :            : 
     423         [ +  - ]:          5 :             aMod.unload();
     424                 :            : 
     425 [ +  - ][ +  - ]:         10 :             CPPUNIT_ASSERT_MESSAGE( "#test comment#: use m_Module to call osl_getSymbol() function.",
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     426   [ +  -  +  - ]:         10 :                                      sal_True == bRes  );
     427                 :            : #endif
     428                 :          5 :         }
     429                 :            : 
     430 [ +  - ][ +  - ]:         10 :         CPPUNIT_TEST_SUITE( optr_oslModule );
         [ +  - ][ +  - ]
                 [ #  # ]
     431 [ +  - ][ +  - ]:          5 :         CPPUNIT_TEST( optr_oslModule_001 );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     432 [ +  - ][ +  - ]:          5 :         CPPUNIT_TEST( optr_oslModule_002 );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     433 [ +  - ][ +  - ]:         10 :         CPPUNIT_TEST_SUITE_END( );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     434                 :            :     }; // class optr_oslModule
     435                 :            : 
     436                 :            :     /** testing the methods:
     437                 :            :         oslGenericFunction SAL_CALL getFunctionSymbol( const ::rtl::OUString& ustrFunctionSymbolName )
     438                 :            :     */
     439         [ -  + ]:         15 :     class getFunctionSymbol : public CppUnit::TestFixture
     440                 :            :     {
     441                 :            :     public:
     442                 :            :         sal_Bool bRes, bRes1;
     443                 :            : 
     444                 :          5 :         void getFunctionSymbol_001( )
     445                 :            :         {
     446                 :            : #if !defined( MACOSX )
     447                 :            :             // TODO: Find out why this fails on Mac OS X
     448 [ +  - ][ +  - ]:          5 :             ::osl::Module aMod( getDllURL( ) );
     449         [ +  - ]:          5 :             oslGenericFunction oslFunc = aMod.getFunctionSymbol( rtl::OUString("firstfunc") );
     450                 :          5 :             ::rtl::OUString aLibraryURL;
     451         [ +  - ]:          5 :             bRes = ::osl::Module::getUrlFromAddress( oslFunc, aLibraryURL);
     452         [ +  - ]:          5 :             aMod.unload();
     453 [ +  - ][ +  - ]:         10 :             CPPUNIT_ASSERT_MESSAGE( "#test comment#: load a dll and get its function addr and get its URL.",
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ -  + ][ +  - ]
         [ +  - ][ +  - ]
                 [ #  # ]
     454   [ +  -  +  - ]:         10 :                  sal_True == bRes && aLibraryURL.equalsIgnoreAsciiCase( getDllURL() ) );
     455                 :            : #endif
     456                 :          5 :         }
     457                 :            : 
     458 [ +  - ][ +  - ]:         10 :         CPPUNIT_TEST_SUITE( getFunctionSymbol );
         [ +  - ][ +  - ]
                 [ #  # ]
     459 [ +  - ][ +  - ]:          5 :         CPPUNIT_TEST( getFunctionSymbol_001 );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     460 [ +  - ][ +  - ]:         10 :         CPPUNIT_TEST_SUITE_END( );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     461                 :            :     }; // class getFunctionSymbol
     462                 :            : 
     463                 :            : // -----------------------------------------------------------------------------
     464                 :          5 : CPPUNIT_TEST_SUITE_REGISTRATION(osl_Module::ctors);
     465                 :          5 : CPPUNIT_TEST_SUITE_REGISTRATION(osl_Module::getUrlFromAddress);
     466                 :          5 : CPPUNIT_TEST_SUITE_REGISTRATION(osl_Module::load);
     467                 :          5 : CPPUNIT_TEST_SUITE_REGISTRATION(osl_Module::unload);
     468                 :          5 : CPPUNIT_TEST_SUITE_REGISTRATION(osl_Module::is);
     469                 :          5 : CPPUNIT_TEST_SUITE_REGISTRATION(osl_Module::getSymbol);
     470                 :          5 : CPPUNIT_TEST_SUITE_REGISTRATION(osl_Module::optr_oslModule);
     471                 :          5 : CPPUNIT_TEST_SUITE_REGISTRATION(osl_Module::getFunctionSymbol);
     472                 :            : // -----------------------------------------------------------------------------
     473                 :            : 
     474                 :            : } // namespace osl_Module
     475                 :            : 
     476                 :            : // -----------------------------------------------------------------------------
     477                 :            : 
     478                 :            : // this macro creates an empty function, which will called by the RegisterAllFunctions()
     479                 :            : // to let the user the possibility to also register some functions by hand.
     480 [ +  - ][ +  - ]:         20 : CPPUNIT_PLUGIN_IMPLEMENT();
         [ +  - ][ +  - ]
         [ +  - ][ #  # ]
     481                 :            : 
     482                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10