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