187d2adbcSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 387d2adbcSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 487d2adbcSAndrew Rist * or more contributor license agreements. See the NOTICE file 587d2adbcSAndrew Rist * distributed with this work for additional information 687d2adbcSAndrew Rist * regarding copyright ownership. The ASF licenses this file 787d2adbcSAndrew Rist * to you under the Apache License, Version 2.0 (the 887d2adbcSAndrew Rist * "License"); you may not use this file except in compliance 987d2adbcSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 1187d2adbcSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 1387d2adbcSAndrew Rist * Unless required by applicable law or agreed to in writing, 1487d2adbcSAndrew Rist * software distributed under the License is distributed on an 1587d2adbcSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1687d2adbcSAndrew Rist * KIND, either express or implied. See the License for the 1787d2adbcSAndrew Rist * specific language governing permissions and limitations 1887d2adbcSAndrew Rist * under the License. 19cdf0e10cSrcweir * 2087d2adbcSAndrew Rist *************************************************************/ 2187d2adbcSAndrew Rist 2287d2adbcSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_sal.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir //------------------------------------------------------------------------ 28cdf0e10cSrcweir // include files 29cdf0e10cSrcweir //------------------------------------------------------------------------ 30cdf0e10cSrcweir #include <osl_Module_Const.h> 31*85328e2aSDamjan Jovanovic #include "gtest/gtest.h" 32cdf0e10cSrcweir 33cdf0e10cSrcweir using namespace osl; 34cdf0e10cSrcweir using namespace rtl; 35cdf0e10cSrcweir 36cdf0e10cSrcweir 37cdf0e10cSrcweir //------------------------------------------------------------------------ 38cdf0e10cSrcweir // helper functions and classes 39cdf0e10cSrcweir //------------------------------------------------------------------------ 40cdf0e10cSrcweir 41cdf0e10cSrcweir /** print Boolean value. 42cdf0e10cSrcweir */ 43cdf0e10cSrcweir inline void printBool( sal_Bool bOk ) 44cdf0e10cSrcweir { 45*85328e2aSDamjan Jovanovic printf("#printBool# " ); 46*85328e2aSDamjan Jovanovic ( sal_True == bOk ) ? printf("TRUE!\n" ): printf("FALSE!\n" ); 47cdf0e10cSrcweir } 48cdf0e10cSrcweir 49cdf0e10cSrcweir /** print a UNI_CODE String. 50cdf0e10cSrcweir */ 51cdf0e10cSrcweir inline void printUString( const ::rtl::OUString & str ) 52cdf0e10cSrcweir { 53cdf0e10cSrcweir rtl::OString aString; 54cdf0e10cSrcweir 55*85328e2aSDamjan Jovanovic printf("#printUString_u# " ); 56cdf0e10cSrcweir aString = ::rtl::OUStringToOString( str, RTL_TEXTENCODING_ASCII_US ); 57*85328e2aSDamjan Jovanovic printf("%s\n", aString.getStr( ) ); 58cdf0e10cSrcweir } 59cdf0e10cSrcweir 60cdf0e10cSrcweir /** get dll file URL. 61cdf0e10cSrcweir */ 62cdf0e10cSrcweir inline ::rtl::OUString getDllURL( void ) 63cdf0e10cSrcweir { 64cdf0e10cSrcweir #if ( defined WNT ) // lib in Unix and lib in Windows are not same in file name. 65cdf0e10cSrcweir ::rtl::OUString libPath( rtl::OUString::createFromAscii( "Module_DLL.dll" ) ); 66cdf0e10cSrcweir #else 67cdf0e10cSrcweir ::rtl::OUString libPath( rtl::OUString::createFromAscii( "libModule_DLL.so" ) ); 68cdf0e10cSrcweir #endif 69cdf0e10cSrcweir 70cdf0e10cSrcweir ::rtl::OUString dirPath, dllPath; 71cdf0e10cSrcweir osl::Module::getUrlFromAddress( ( void* ) &getDllURL, dirPath ); 72*85328e2aSDamjan Jovanovic // file:///aoo/main/sal/unx/bin/osl_Module 73*85328e2aSDamjan Jovanovic dirPath = dirPath.copy( 0, dirPath.lastIndexOf('/')); 74*85328e2aSDamjan Jovanovic // file:///aoo/main/sal/unx/bin 75cdf0e10cSrcweir dirPath = dirPath.copy( 0, dirPath.lastIndexOf('/') + 1); 76*85328e2aSDamjan Jovanovic // file:///aoo/main/sal/unx/ 77*85328e2aSDamjan Jovanovic dirPath = dirPath + rtl::OUString::createFromAscii( "lib/" ); 78*85328e2aSDamjan Jovanovic // file:///aoo/main/sal/unx/lib/ 79cdf0e10cSrcweir osl::FileBase::getAbsoluteFileURL( dirPath, libPath, dllPath ); 80cdf0e10cSrcweir 81*85328e2aSDamjan Jovanovic rtl::OString aOString = ::rtl::OUStringToOString (dllPath, RTL_TEXTENCODING_UTF8); 82*85328e2aSDamjan Jovanovic printf("getDllURL() returning %s\n", aOString.getStr()); 83cdf0e10cSrcweir return dllPath; 84cdf0e10cSrcweir } 85cdf0e10cSrcweir 86cdf0e10cSrcweir /** print a UNI_CODE file name. 87cdf0e10cSrcweir */ 88cdf0e10cSrcweir inline void printFileName( const ::rtl::OUString & str ) 89cdf0e10cSrcweir { 90cdf0e10cSrcweir rtl::OString aString; 91cdf0e10cSrcweir 92*85328e2aSDamjan Jovanovic printf("#printFileName_u# " ); 93cdf0e10cSrcweir aString = ::rtl::OUStringToOString( str, RTL_TEXTENCODING_ASCII_US ); 94*85328e2aSDamjan Jovanovic printf("%s\n", aString.getStr( ) ); 95cdf0e10cSrcweir } 96cdf0e10cSrcweir 97cdf0e10cSrcweir inline sal_Bool isURL( const ::rtl::OUString pathname ) 98cdf0e10cSrcweir { 99cdf0e10cSrcweir ::rtl::OUString aPreURL( rtl::OUString::createFromAscii( "file:///" ) ); 100cdf0e10cSrcweir return ( ( pathname.indexOf( aPreURL ) == 0 ) ? sal_True : sal_False ); 101cdf0e10cSrcweir } 102cdf0e10cSrcweir 103cdf0e10cSrcweir /** create a temp test directory using OUString name of full qualified URL or system path. 104cdf0e10cSrcweir */ 105cdf0e10cSrcweir inline void createTestDirectory( const ::rtl::OUString dirname ) 106cdf0e10cSrcweir { 107cdf0e10cSrcweir ::rtl::OUString aPathURL = dirname.copy( 0 ); 108cdf0e10cSrcweir ::osl::FileBase::RC nError; 109cdf0e10cSrcweir 110cdf0e10cSrcweir if ( !isURL( dirname ) ) 111cdf0e10cSrcweir ::osl::FileBase::getFileURLFromSystemPath( dirname, aPathURL ); //convert if not full qualified URL 112cdf0e10cSrcweir nError = ::osl::Directory::create( aPathURL ); 113*85328e2aSDamjan Jovanovic ASSERT_TRUE(( ::osl::FileBase::E_None == nError ) || ( nError == ::osl::FileBase::E_EXIST )) << "In createTestDirectory Function: creation: "; 114cdf0e10cSrcweir } 115cdf0e10cSrcweir 116cdf0e10cSrcweir /** delete a temp test directory using OUString name of full qualified URL or system path. 117cdf0e10cSrcweir */ 118cdf0e10cSrcweir inline void deleteTestDirectory( const ::rtl::OUString dirname ) 119cdf0e10cSrcweir { 120cdf0e10cSrcweir ::rtl::OUString aPathURL = dirname.copy( 0 ); 121cdf0e10cSrcweir ::osl::FileBase::RC nError; 122cdf0e10cSrcweir if ( !isURL( dirname ) ) 123cdf0e10cSrcweir ::osl::FileBase::getFileURLFromSystemPath( dirname, aPathURL ); //convert if not full qualified URL 124cdf0e10cSrcweir 125cdf0e10cSrcweir ::osl::Directory testDir( aPathURL ); 126cdf0e10cSrcweir if ( testDir.isOpen( ) == sal_True ) 127cdf0e10cSrcweir { 128cdf0e10cSrcweir testDir.close( ); //close if still open. 129cdf0e10cSrcweir } 130cdf0e10cSrcweir 131cdf0e10cSrcweir nError = ::osl::Directory::remove( aPathURL ); 132*85328e2aSDamjan Jovanovic ASSERT_TRUE(( ::osl::FileBase::E_None == nError ) || ( nError == ::osl::FileBase::E_NOENT )) << "In deleteTestDirectory function: remove "; 133cdf0e10cSrcweir } 134cdf0e10cSrcweir 135cdf0e10cSrcweir //check if the file exist 136cdf0e10cSrcweir inline sal_Bool ifFileExist( const ::rtl::OUString & str ) 137cdf0e10cSrcweir { 138cdf0e10cSrcweir ::rtl::OUString aUStr; 139cdf0e10cSrcweir if ( isURL( str ) ) 140cdf0e10cSrcweir ::osl::FileBase::getSystemPathFromFileURL( str, aUStr ); 141cdf0e10cSrcweir else 142cdf0e10cSrcweir return sal_False; 143cdf0e10cSrcweir 144cdf0e10cSrcweir ::osl::File strFile( aUStr ); 145cdf0e10cSrcweir ::osl::FileBase::RC nError = strFile.open( OpenFlag_Read ); 146cdf0e10cSrcweir if ( ::File::E_NOENT == nError ) 147cdf0e10cSrcweir return sal_False; 148cdf0e10cSrcweir else{ 149cdf0e10cSrcweir strFile.close( ); 150cdf0e10cSrcweir return sal_True; 151cdf0e10cSrcweir } 152cdf0e10cSrcweir } 153cdf0e10cSrcweir 154cdf0e10cSrcweir /** detete a temp test file using OUString name. 155cdf0e10cSrcweir */ 156cdf0e10cSrcweir inline void deleteTestFile( const ::rtl::OUString filename ) 157cdf0e10cSrcweir { 158cdf0e10cSrcweir ::rtl::OUString aPathURL = filename.copy( 0 ); 159cdf0e10cSrcweir ::osl::FileBase::RC nError; 160cdf0e10cSrcweir 161cdf0e10cSrcweir if ( !isURL( filename ) ) 162cdf0e10cSrcweir ::osl::FileBase::getFileURLFromSystemPath( filename, aPathURL ); //convert if not full qualified URL 163cdf0e10cSrcweir 164cdf0e10cSrcweir nError = ::osl::File::setAttributes( aPathURL, Attribute_GrpWrite| Attribute_OwnWrite| Attribute_OthWrite ); // if readonly, make writtenable. 165*85328e2aSDamjan Jovanovic ASSERT_TRUE(( ::osl::FileBase::E_None == nError ) || ( ::osl::FileBase::E_NOENT == nError )) << "In deleteTestFile Function: set writtenable "; 166cdf0e10cSrcweir 167cdf0e10cSrcweir nError = ::osl::File::remove( aPathURL ); 168*85328e2aSDamjan Jovanovic ASSERT_TRUE(( ::osl::FileBase::E_None == nError ) || ( nError == ::osl::FileBase::E_NOENT )) << "In deleteTestFile Function: remove "; 169cdf0e10cSrcweir } 170cdf0e10cSrcweir 171cdf0e10cSrcweir 172cdf0e10cSrcweir //------------------------------------------------------------------------ 173cdf0e10cSrcweir // test code start here 174cdf0e10cSrcweir //------------------------------------------------------------------------ 175cdf0e10cSrcweir 176cdf0e10cSrcweir namespace osl_Module 177cdf0e10cSrcweir { 178cdf0e10cSrcweir 179cdf0e10cSrcweir /** class and member function that is available for module test : 180cdf0e10cSrcweir */ 181cdf0e10cSrcweir 182cdf0e10cSrcweir class testClass 183cdf0e10cSrcweir { 184cdf0e10cSrcweir public: 185cdf0e10cSrcweir static void myFunc() 186cdf0e10cSrcweir { 187*85328e2aSDamjan Jovanovic printf("#Sun Microsystem\n"); 188cdf0e10cSrcweir }; 189cdf0e10cSrcweir }; 190cdf0e10cSrcweir 191cdf0e10cSrcweir 192cdf0e10cSrcweir /** testing the methods: 193cdf0e10cSrcweir Module(); 194cdf0e10cSrcweir Module( const ::rtl::OUString& strModuleName, sal_Int32 nRtldMode = SAL_LOADMODULE_DEFAULT); 195cdf0e10cSrcweir */ 196*85328e2aSDamjan Jovanovic class ctors : public ::testing::Test 197cdf0e10cSrcweir { 198cdf0e10cSrcweir public: 199cdf0e10cSrcweir sal_Bool bRes, bRes1; 200*85328e2aSDamjan Jovanovic }; // class ctors 201cdf0e10cSrcweir 202*85328e2aSDamjan Jovanovic 203*85328e2aSDamjan Jovanovic TEST_F(ctors, ctors_none) 204cdf0e10cSrcweir { 205cdf0e10cSrcweir ::osl::Module aMod; 206cdf0e10cSrcweir bRes = aMod.is(); 207cdf0e10cSrcweir 208*85328e2aSDamjan Jovanovic ASSERT_TRUE( sal_False == bRes ) << "#test comment#: test constructor without parameter."; 209cdf0e10cSrcweir } 210cdf0e10cSrcweir 211*85328e2aSDamjan Jovanovic TEST_F(ctors, ctors_name_mode) 212cdf0e10cSrcweir { 213*85328e2aSDamjan Jovanovic ::osl::Module aMod( getDllURL( ) ); 214cdf0e10cSrcweir bRes = aMod.is( ); 215cdf0e10cSrcweir aMod.unload( ); 216cdf0e10cSrcweir 217*85328e2aSDamjan Jovanovic ASSERT_TRUE( sal_True == bRes ) << "#test comment#: test constructor with load action."; 218cdf0e10cSrcweir } 219cdf0e10cSrcweir 220cdf0e10cSrcweir /** testing the methods: 221cdf0e10cSrcweir static sal_Bool getUrlFromAddress(void * addr, ::rtl::OUString & libraryUrl) 222cdf0e10cSrcweir */ 223*85328e2aSDamjan Jovanovic class getUrlFromAddress : public ::testing::Test 224cdf0e10cSrcweir { 225cdf0e10cSrcweir public: 226cdf0e10cSrcweir sal_Bool bRes, bRes1; 227*85328e2aSDamjan Jovanovic }; // class getUrlFromAddress 228cdf0e10cSrcweir 229*85328e2aSDamjan Jovanovic /* tester comments: another case is getFunctionSymbol_001*/ 230*85328e2aSDamjan Jovanovic 231*85328e2aSDamjan Jovanovic TEST_F(getUrlFromAddress, getUrlFromAddress_001 ) 232cdf0e10cSrcweir { 233cdf0e10cSrcweir OUString aFileURL; 234cdf0e10cSrcweir bRes = osl::Module::getUrlFromAddress( ( void* ) &::osl_Module::testClass::myFunc, aFileURL ) ; 235cdf0e10cSrcweir if ( !( bRes ) ) 236cdf0e10cSrcweir { 237*85328e2aSDamjan Jovanovic ASSERT_TRUE(sal_False) << "Cannot locate current module."; 238cdf0e10cSrcweir } 239cdf0e10cSrcweir 240*85328e2aSDamjan Jovanovic ASSERT_TRUE(sal_True == bRes && 0 < aFileURL.lastIndexOf('/')) << "#test comment#: test get Module URL from address."; 241cdf0e10cSrcweir } 242cdf0e10cSrcweir 243*85328e2aSDamjan Jovanovic TEST_F(getUrlFromAddress, getUrlFromAddress_002 ) 244cdf0e10cSrcweir { 245cdf0e10cSrcweir ::osl::Module aMod( getDllURL( ) ); 246cdf0e10cSrcweir FuncPtr pFunc = ( FuncPtr ) aMod.getSymbol( rtl::OUString::createFromAscii( "firstfunc" ) ); 247cdf0e10cSrcweir 248cdf0e10cSrcweir OUString aFileURL; 249cdf0e10cSrcweir bRes = osl::Module::getUrlFromAddress( ( void* )pFunc, aFileURL ); 250cdf0e10cSrcweir if ( !( bRes ) ) 251cdf0e10cSrcweir { 252*85328e2aSDamjan Jovanovic ASSERT_TRUE(sal_False) << "Cannot locate current module."; 253cdf0e10cSrcweir } 254cdf0e10cSrcweir aMod.unload( ); 255cdf0e10cSrcweir 256*85328e2aSDamjan Jovanovic ASSERT_TRUE( sal_True == bRes && 0 < aFileURL.lastIndexOf('/') && aFileURL.equalsIgnoreAsciiCase( getDllURL( ) ) ) 257*85328e2aSDamjan Jovanovic << "#test comment#: load an external library, get its function address and get its URL."; 258cdf0e10cSrcweir } 259cdf0e10cSrcweir 260cdf0e10cSrcweir /** testing the method: 261cdf0e10cSrcweir sal_Bool SAL_CALL load( const ::rtl::OUString& strModuleName, 262cdf0e10cSrcweir sal_Int32 nRtldMode = SAL_LOADMODULE_DEFAULT) 263cdf0e10cSrcweir */ 264*85328e2aSDamjan Jovanovic class load : public ::testing::Test 265cdf0e10cSrcweir { 266cdf0e10cSrcweir public: 267cdf0e10cSrcweir sal_Bool bRes, bRes1; 268*85328e2aSDamjan Jovanovic }; // class load 269cdf0e10cSrcweir 270*85328e2aSDamjan Jovanovic TEST_F(load, load_001 ) 271cdf0e10cSrcweir { 272cdf0e10cSrcweir ::osl::Module aMod( getDllURL( ) ); 273cdf0e10cSrcweir ::osl::Module aMod1; 274cdf0e10cSrcweir 275cdf0e10cSrcweir aMod1.load( getDllURL( ) ); 276cdf0e10cSrcweir bRes = oslModule(aMod) == oslModule(aMod1); 277cdf0e10cSrcweir aMod.unload( ); 278cdf0e10cSrcweir aMod1.unload( ); 279cdf0e10cSrcweir 280*85328e2aSDamjan Jovanovic ASSERT_TRUE(sal_True == bRes) << "#test comment#: load function should do the same thing as constructor with library name."; 281cdf0e10cSrcweir } 282cdf0e10cSrcweir // load lib which is under a CJK directory 283*85328e2aSDamjan Jovanovic TEST_F(load, load_002 ) 284cdf0e10cSrcweir { 285cdf0e10cSrcweir #ifdef UNX 286cdf0e10cSrcweir //Can not get a CJK directory already exist, so here create one. Perhaps reason is encoding problem. 287cdf0e10cSrcweir ::rtl::OUString aPidDirURL = rtl::OUString::createFromAscii( "file:///tmp/" ) + ::rtl::OUString::valueOf( ( long )getpid( ) ); 288cdf0e10cSrcweir ::rtl::OUString aMyDirURL = aPidDirURL + aKname; 289cdf0e10cSrcweir createTestDirectory( aPidDirURL ); 290cdf0e10cSrcweir createTestDirectory( aMyDirURL ); 291cdf0e10cSrcweir 292cdf0e10cSrcweir ::rtl::OUString aDLLURL = aMyDirURL + rtl::OUString::createFromAscii( "/libModule_DLL.so" ); 293cdf0e10cSrcweir //check if the lib exist. 294cdf0e10cSrcweir //FIXME: if assert condition is false, the case will return, so the directory will not be clean-up 295*85328e2aSDamjan Jovanovic ASSERT_TRUE(ifFileExist( getDllURL( ) ) == sal_True) << "#Source file is not exist. please manually clean-up directory and file under /tmp"; 296cdf0e10cSrcweir ::osl::FileBase::RC nError = ::osl::File::copy( getDllURL( ), aDLLURL ); 297*85328e2aSDamjan Jovanovic ASSERT_TRUE(nError == ::osl::FileBase::E_None) << "#copy failed. please manually clean-up directory and file under /tmp"; 298cdf0e10cSrcweir //ifFileExist returned false but the file exist 299*85328e2aSDamjan Jovanovic ASSERT_TRUE( ifFileExist( aDLLURL ) == sal_True ) 300*85328e2aSDamjan Jovanovic << "#This file is not exist, copy failed. please manually clean-up directory and file under /tmp"; 301cdf0e10cSrcweir 302cdf0e10cSrcweir //test if can create a normal file 303cdf0e10cSrcweir ::rtl::OUString aFileURL = aMyDirURL + rtl::OUString::createFromAscii( "/test_file" ); 304cdf0e10cSrcweir ::osl::File testFile( aFileURL ); 305cdf0e10cSrcweir nError = testFile.open( OpenFlag_Create ); 306*85328e2aSDamjan Jovanovic ASSERT_TRUE(nError == ::osl::FileBase::E_None) << "#create failed. please manually clean-up directory and file under /tmp"; 307*85328e2aSDamjan Jovanovic ASSERT_TRUE( ifFileExist( aFileURL ) == sal_True ) 308*85328e2aSDamjan Jovanovic << "#This file is not exist, create failed. please manually clean-up directory and file under /tmp"; 309cdf0e10cSrcweir 310cdf0e10cSrcweir //load the copied dll 311cdf0e10cSrcweir ::osl::Module aMod( aDLLURL ); 312cdf0e10cSrcweir ::osl::Module aMod1; 313cdf0e10cSrcweir 314cdf0e10cSrcweir sal_Bool bOK = aMod1.load( aDLLURL ); 315cdf0e10cSrcweir bRes = oslModule(aMod) == oslModule(aMod1); 316cdf0e10cSrcweir aMod.unload( ); 317cdf0e10cSrcweir aMod1.unload( ); 318cdf0e10cSrcweir deleteTestFile( aFileURL ); 319cdf0e10cSrcweir deleteTestFile( aDLLURL ); 320cdf0e10cSrcweir deleteTestDirectory( aMyDirURL ); 321cdf0e10cSrcweir deleteTestDirectory( aPidDirURL ); 322cdf0e10cSrcweir 323*85328e2aSDamjan Jovanovic ASSERT_TRUE(sal_True == bRes && bOK == sal_True) << "#test comment#: load lib which is under a CJK directory."; 324cdf0e10cSrcweir #endif 325cdf0e10cSrcweir } 326cdf0e10cSrcweir 327cdf0e10cSrcweir /** testing the method: 328cdf0e10cSrcweir void SAL_CALL unload() 329cdf0e10cSrcweir */ 330*85328e2aSDamjan Jovanovic class unload : public ::testing::Test 331cdf0e10cSrcweir { 332cdf0e10cSrcweir public: 333cdf0e10cSrcweir sal_Bool bRes, bRes1; 334*85328e2aSDamjan Jovanovic }; // class unload 335cdf0e10cSrcweir 336*85328e2aSDamjan Jovanovic TEST_F(unload, unload_001) 337cdf0e10cSrcweir { 338cdf0e10cSrcweir ::osl::Module aMod( getDllURL( ) ); 339cdf0e10cSrcweir 340cdf0e10cSrcweir aMod.unload( ); 341cdf0e10cSrcweir bRes = oslModule(aMod) ==NULL; 342cdf0e10cSrcweir 343*85328e2aSDamjan Jovanovic ASSERT_TRUE(sal_True == bRes) << "#test comment#: unload function should do the same thing as destructor."; 344cdf0e10cSrcweir } 345cdf0e10cSrcweir 346cdf0e10cSrcweir /** testing the methods: 347cdf0e10cSrcweir sal_Bool SAL_CALL is() const 348cdf0e10cSrcweir */ 349*85328e2aSDamjan Jovanovic class is : public ::testing::Test 350cdf0e10cSrcweir { 351cdf0e10cSrcweir public: 352cdf0e10cSrcweir sal_Bool bRes, bRes1; 353*85328e2aSDamjan Jovanovic }; // class is 354cdf0e10cSrcweir 355*85328e2aSDamjan Jovanovic TEST_F(is, is_001) 356cdf0e10cSrcweir { 357cdf0e10cSrcweir ::osl::Module aMod; 358cdf0e10cSrcweir bRes = aMod.is( ); 359*85328e2aSDamjan Jovanovic aMod.load( getDllURL( ) ); 360cdf0e10cSrcweir bRes1 = aMod.is( ); 361cdf0e10cSrcweir aMod.unload( ); 362cdf0e10cSrcweir 363*85328e2aSDamjan Jovanovic ASSERT_TRUE(sal_False == bRes && sal_True == bRes1) << "#test comment#: test if a module is a loaded module."; 364cdf0e10cSrcweir } 365cdf0e10cSrcweir 366cdf0e10cSrcweir /** testing the methods: 367cdf0e10cSrcweir void* SAL_CALL getSymbol( const ::rtl::OUString& strSymbolName) 368cdf0e10cSrcweir */ 369*85328e2aSDamjan Jovanovic class getSymbol : public ::testing::Test 370cdf0e10cSrcweir { 371cdf0e10cSrcweir public: 372cdf0e10cSrcweir sal_Bool bRes; 373*85328e2aSDamjan Jovanovic }; // class getSymbol 374cdf0e10cSrcweir 375*85328e2aSDamjan Jovanovic TEST_F(getSymbol, getSymbol_001) 376cdf0e10cSrcweir { 377cdf0e10cSrcweir ::osl::Module aMod( getDllURL( ) ); 378cdf0e10cSrcweir FuncPtr pFunc = ( FuncPtr ) aMod.getSymbol( rtl::OUString::createFromAscii( "firstfunc" ) ); 379cdf0e10cSrcweir bRes = sal_False; 380cdf0e10cSrcweir if ( pFunc ) 381cdf0e10cSrcweir bRes = pFunc( bRes ); 382cdf0e10cSrcweir aMod.unload(); 383cdf0e10cSrcweir 384*85328e2aSDamjan Jovanovic ASSERT_TRUE(sal_True == bRes) << "#test comment#: load a dll and call one function in it."; 385cdf0e10cSrcweir } 386cdf0e10cSrcweir 387cdf0e10cSrcweir /** testing the methods: 388cdf0e10cSrcweir operator oslModule() const 389cdf0e10cSrcweir */ 390*85328e2aSDamjan Jovanovic class optr_oslModule : public ::testing::Test 391cdf0e10cSrcweir { 392cdf0e10cSrcweir public: 393cdf0e10cSrcweir sal_Bool bRes, bRes1; 394*85328e2aSDamjan Jovanovic }; // class optr_oslModule 395cdf0e10cSrcweir 396*85328e2aSDamjan Jovanovic TEST_F(optr_oslModule, optr_oslModule_001 ) 397cdf0e10cSrcweir { 398cdf0e10cSrcweir ::osl::Module aMod; 399cdf0e10cSrcweir bRes = ( (oslModule)aMod == NULL ); 400cdf0e10cSrcweir 401cdf0e10cSrcweir aMod.load( getDllURL( ) ); 402cdf0e10cSrcweir bRes1 = (oslModule)aMod != NULL; 403cdf0e10cSrcweir 404cdf0e10cSrcweir aMod.unload( ); 405cdf0e10cSrcweir 406*85328e2aSDamjan Jovanovic ASSERT_TRUE(sal_True == bRes && sal_True == bRes1) 407*85328e2aSDamjan Jovanovic << "#test comment#: the m_Module of a Module instance will be NULL when is not loaded, it will not be NULL after loaded."; 408cdf0e10cSrcweir } 409cdf0e10cSrcweir 410*85328e2aSDamjan Jovanovic TEST_F(optr_oslModule, optr_oslModule_002 ) 411cdf0e10cSrcweir { 412cdf0e10cSrcweir ::osl::Module aMod( getDllURL( ) ); 413cdf0e10cSrcweir ::rtl::OUString funcName(::rtl::OUString::createFromAscii( "firstfunc" ) ); 414cdf0e10cSrcweir 415cdf0e10cSrcweir FuncPtr pFunc = ( FuncPtr ) osl_getSymbol( (oslModule)aMod, funcName.pData ); 416cdf0e10cSrcweir bRes = sal_False; 417cdf0e10cSrcweir if ( pFunc ) 418cdf0e10cSrcweir bRes = pFunc( bRes ); 419cdf0e10cSrcweir 420cdf0e10cSrcweir aMod.unload(); 421cdf0e10cSrcweir 422*85328e2aSDamjan Jovanovic ASSERT_TRUE(sal_True == bRes) << "#test comment#: use m_Module to call osl_getSymbol() function."; 423cdf0e10cSrcweir } 424cdf0e10cSrcweir 425cdf0e10cSrcweir /** testing the methods: 426cdf0e10cSrcweir oslGenericFunction SAL_CALL getFunctionSymbol( const ::rtl::OUString& ustrFunctionSymbolName ) 427cdf0e10cSrcweir */ 428*85328e2aSDamjan Jovanovic class getFunctionSymbol : public ::testing::Test 429cdf0e10cSrcweir { 430cdf0e10cSrcweir public: 431cdf0e10cSrcweir sal_Bool bRes, bRes1; 432*85328e2aSDamjan Jovanovic }; // class getFunctionSymbol 433cdf0e10cSrcweir 434*85328e2aSDamjan Jovanovic TEST_F(getFunctionSymbol, getFunctionSymbol_001) 435cdf0e10cSrcweir { 436cdf0e10cSrcweir ::osl::Module aMod( getDllURL( ) ); 437cdf0e10cSrcweir oslGenericFunction oslFunc = aMod.getFunctionSymbol( rtl::OUString::createFromAscii( "firstfunc" ) ); 438cdf0e10cSrcweir ::rtl::OUString aLibraryURL; 439cdf0e10cSrcweir bRes = ::osl::Module::getUrlFromAddress( oslFunc, aLibraryURL); 440cdf0e10cSrcweir aMod.unload(); 441cdf0e10cSrcweir printFileName( aLibraryURL ); 442cdf0e10cSrcweir 443*85328e2aSDamjan Jovanovic ASSERT_TRUE(sal_True == bRes && aLibraryURL.equalsIgnoreAsciiCase( getDllURL() )) << "#test comment#: load a dll and get its function addr and get its URL."; 444cdf0e10cSrcweir } 445cdf0e10cSrcweir 446cdf0e10cSrcweir } // namespace osl_Module 447cdf0e10cSrcweir 448*85328e2aSDamjan Jovanovic int main(int argc, char **argv) 449*85328e2aSDamjan Jovanovic { 450*85328e2aSDamjan Jovanovic ::testing::InitGoogleTest(&argc, argv); 451*85328e2aSDamjan Jovanovic return RUN_ALL_TESTS(); 452*85328e2aSDamjan Jovanovic } 453