merge the formfield patch from ooo-build
[ooovba.git] / sal / qa / osl / file / osl_File.cxx
blob2a6fbeacc4d7245bbb51ed05b61ad2eb180ee09f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: osl_File.cxx,v $
10 * $Revision: 1.14 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sal.hxx"
34 //------------------------------------------------------------------------
35 // include files
36 //------------------------------------------------------------------------
37 #include <sal/types.h>
38 #include <rtl/ustring.hxx>
39 #include <rtl/ustrbuf.hxx>
41 #include "osl/thread.h"
43 #include "rtl/ustrbuf.hxx"
44 #include <osl/file.hxx>
45 #include <osl_File_Const.h>
47 #include <cppunit/simpleheader.hxx>
49 // #ifdef WNT
50 // # define UNICODE
51 // # define WIN32_LEAN_AND_MEAN
52 // # include <windows.h>
53 // # include <tchar.h>
54 // #endif
57 using namespace osl;
58 using namespace rtl;
60 //------------------------------------------------------------------------
61 // helper functions
62 //------------------------------------------------------------------------
64 /** detailed wrong message.
66 inline ::rtl::OString errorToString( const ::osl::FileBase::RC _nError )
68 ::rtl::OString sResult;
69 switch ( _nError ) {
70 case ::osl::FileBase::E_None:
71 sResult = "Success";
72 break;
73 case ::osl::FileBase::E_PERM:
74 sResult = "Operation not permitted";
75 break;
76 case ::osl::FileBase::E_NOENT:
77 sResult = "No such file or directory";
78 break;
79 case ::osl::FileBase::E_EXIST:
80 sResult = "Already Exist";
81 break;
82 case ::osl::FileBase::E_ACCES:
83 sResult = "Permission denied";
84 break;
85 case ::osl::FileBase::E_INVAL:
86 sResult = "The format of the parameters was not valid";
87 break;
88 case ::osl::FileBase::E_NOTDIR:
89 sResult = "Not a directory";
90 break;
91 case ::osl::FileBase::E_ISDIR:
92 sResult = "Is a directory";
93 break;
94 case ::osl::FileBase::E_BADF:
95 sResult = "Bad file";
96 break;
97 case ::osl::FileBase::E_NOTEMPTY:
98 sResult = "The directory is not empty";
99 break;
100 default:
101 sResult = "Unknown Error";
102 break;
104 return sResult;
107 rtl::OUString errorToStr( ::osl::FileBase::RC const& nError)
109 rtl::OUStringBuffer suBuf;
110 suBuf.append( rtl::OUString::createFromAscii("The returned error is: ") );
111 suBuf.append( rtl::OStringToOUString(errorToString(nError), RTL_TEXTENCODING_ASCII_US) );
112 suBuf.append( rtl::OUString::createFromAscii("!\n") );
113 return suBuf.makeStringAndClear();
116 /** print a file type name.
118 inline void printFileType( const ::osl::FileStatus::Type nType )
120 t_print( "#printFileType# " );
121 switch ( nType ) {
122 case ::osl::FileStatus::Directory:
123 t_print( "This file is a: Directory.\n" );
124 break;
125 case ::osl::FileStatus::Volume:
126 t_print( "This file is a: volume device.\n" );
127 break;
128 case ::osl::FileStatus::Regular:
129 t_print( "This file is a: regular file.\n" );
130 break;
131 case ::osl::FileStatus::Fifo:
132 t_print( "This file is a: fifo.\n" );
133 break;
134 case ::osl::FileStatus::Socket:
135 t_print( "This file is a: socket.\n" );
136 break;
137 case ::osl::FileStatus::Link:
138 t_print( "This file is a: link file.\n" );
139 break;
140 case ::osl::FileStatus::Special:
141 t_print( "This file is a: special.\n" );
142 break;
143 case ::osl::FileStatus::Unknown:
144 t_print( "The file type is unknown %d \n", nType );
145 break;
149 /** print a file attributes.
151 inline void printFileAttributes( const sal_Int64 nAttributes )
153 t_print( "#printFileAttributes# This file is a: (" );
154 if ( ( nAttributes | Attribute_ReadOnly ) == nAttributes )
155 t_print( " ReadOnly " );
156 if ( ( nAttributes | Attribute_Hidden ) == nAttributes )
157 t_print( " Hidden " );
158 if ( ( nAttributes | Attribute_Executable ) == nAttributes )
159 t_print( " Executable " );
160 if ( ( nAttributes | Attribute_GrpWrite ) == nAttributes )
161 t_print( " GrpWrite " );
162 if ( ( nAttributes | Attribute_GrpRead ) == nAttributes )
163 t_print( " GrpRead " );
164 if ( ( nAttributes | Attribute_GrpExe ) == nAttributes )
165 t_print( " GrpExe " );
166 if ( ( nAttributes | Attribute_OwnWrite ) == nAttributes )
167 t_print( " OwnWrite " );
168 if ( ( nAttributes | Attribute_OwnRead ) == nAttributes )
169 t_print( " OwnRead " );
170 if ( ( nAttributes | Attribute_OwnExe ) == nAttributes )
171 t_print( " OwnExe " );
172 if ( ( nAttributes | Attribute_OthWrite ) == nAttributes )
173 t_print( " OthWrite " );
174 if ( ( nAttributes | Attribute_OthRead ) == nAttributes )
175 t_print( " OthRead " );
176 if ( ( nAttributes | Attribute_OthExe ) == nAttributes )
177 t_print( " OthExe " );
178 t_print( ") file!\n" );
181 /** print a UNI_CODE file name.
183 inline void printFileName( const ::rtl::OUString & str )
185 rtl::OString aString;
187 t_print( "#printFileName_u# " );
188 aString = ::rtl::OUStringToOString( str, RTL_TEXTENCODING_ASCII_US );
189 t_print( "%s\n", aString.getStr( ) );
192 /** print a ASCII_CODE file name.
194 inline void printFileName( const sal_Char * str )
196 t_print( "#printFileName_a# " );
197 t_print( "%s\n", str );
200 /** print an output wrong message.
202 inline void printError( const ::osl::FileBase::RC nError )
204 t_print( "#printError# " );
205 printFileName( errorToStr(nError) );
208 /** print an signed Integer Number.
210 inline void printInt( sal_Int64 i )
212 t_print( "#printInt_i64# " );
213 t_print( "The Integer64 is %lld\n", i);
216 /** print an unsigned Integer Number.
218 inline void printInt( sal_uInt64 i )
220 t_print( "#printInt_u64# " );
221 t_print( "The unsigned Integer64 is %llu\n", i);
224 /** print Boolean value.
226 inline void printBool( sal_Bool bOk )
228 t_print( "#printBool# " );
229 ( sal_True == bOk ) ? t_print( "YES!\n" ): t_print( "NO!\n" );
232 /** print struct TimeValue in local time format.
234 inline void printTime( TimeValue *tv )
236 oslDateTime *pDateTime = ( oslDateTime* )malloc( sizeof( oslDateTime ) ) ;
237 CPPUNIT_ASSERT_MESSAGE( "Error in printTime() function,malloc ", pDateTime != NULL );
238 TimeValue *pLocalTV = ( TimeValue* )malloc( sizeof( TimeValue ) );
239 CPPUNIT_ASSERT_MESSAGE( "Error in printTime() function,malloc ", pLocalTV != NULL );
241 CPPUNIT_ASSERT_MESSAGE( "Error in printTime() function,osl_getLocalTimeFromSystemTime ",sal_True == osl_getLocalTimeFromSystemTime( tv, pLocalTV ) );
242 CPPUNIT_ASSERT_MESSAGE( "Error in printTime() function,osl_gepDateTimeFromTimeValue ",sal_True == osl_getDateTimeFromTimeValue( pLocalTV, pDateTime ) );
244 t_print( "#printTime# " );
245 t_print( " Time is: %d/%d/%d ", pDateTime->Month, pDateTime->Day, pDateTime->Year);
246 switch ( pDateTime->DayOfWeek )
248 case 0: t_print("Sun. "); break;
249 case 1: t_print("Mon. "); break;
250 case 2: t_print("Tue. "); break;
251 case 3: t_print("Thr. "); break;
252 case 4: t_print("Wen. "); break;
253 case 5: t_print("Fri. "); break;
254 case 6: t_print("Sat. "); break;
256 t_print( " %d:%d:%d %d nsecs\n", pDateTime->Hours, pDateTime->Minutes, pDateTime->Seconds, pDateTime->NanoSeconds);
258 free( pDateTime );
259 free( pLocalTV );
262 /** compare two TimeValue, unit is "ms", since Windows time precision is better than UNX.
265 #if ( defined UNX ) || ( defined OS2 ) //precision of time in Windows is better than UNX
266 # define delta 2000 //time precision, 2000ms
267 #else
268 # define delta 1800 //time precision, 1.8s
269 #endif
271 inline sal_Int64 t_abs64(sal_Int64 _nValue)
273 // std::abs() seems to have some ambiguity problems (so-texas)
274 // return abs(_nValue);
275 t_print("t_abs64(%ld)\n", _nValue);
276 // CPPUNIT_ASSERT(_nValue < 2147483647);
278 if (_nValue < 0)
280 _nValue = -_nValue;
282 return _nValue;
285 inline sal_Bool t_compareTime( TimeValue *m_aEndTime, TimeValue *m_aStartTime, sal_Int32 nDelta)
287 // sal_uInt64 uTimeValue;
288 // sal_Int64 iTimeValue;
290 // iTimeValue = t_abs64(( tv1->Seconds - tv2->Seconds) * 1000000000 + tv1->Nanosec - tv2->Nanosec);
291 // uTimeValue = ( iTimeValue / 1000000 );
293 sal_Int32 nDeltaSeconds = m_aEndTime->Seconds - m_aStartTime->Seconds;
294 sal_Int32 nDeltaNanoSec = sal_Int32(m_aEndTime->Nanosec) - sal_Int32(m_aStartTime->Nanosec);
295 if (nDeltaNanoSec < 0)
297 nDeltaNanoSec = 1000000000 + nDeltaNanoSec;
298 nDeltaSeconds--;
301 sal_Int32 nDeltaMilliSec = (nDeltaSeconds * 1000) + (nDeltaNanoSec / 1000000);
302 return ( nDeltaMilliSec < nDelta );
305 /** compare two OUString file name.
307 inline sal_Bool compareFileName( const ::rtl::OUString & ustr1, const ::rtl::OUString & ustr2 )
309 sal_Bool bOk;
310 //on Windows, the seperatar is '\', so here change to '/', then compare
311 #if defined (WNT )
312 ::rtl::OUString ustr1new,ustr2new;
313 sal_Unicode reverseSlash = (sal_Unicode)'\\';
315 if (ustr1.lastIndexOf(reverseSlash) != -1)
316 ustr1new = ustr1.replace(reverseSlash,(sal_Unicode)'/');
317 else
318 ustr1new = ustr1;
319 if (ustr2.lastIndexOf(reverseSlash) != -1)
320 ustr2new = ustr2.replace(reverseSlash,(sal_Unicode)'/');
321 else
322 ustr2new = ustr2;
323 bOk = ustr1new.equalsIgnoreAsciiCase( ustr2new ) ;
324 #else
325 bOk = ustr1.equalsIgnoreAsciiCase( ustr2 );
326 #endif
327 return bOk;
330 /** compare a OUString and an ASCII file name.
332 inline sal_Bool compareFileName( const ::rtl::OUString & ustr, const sal_Char *astr )
334 (void)ustr;
335 ::rtl::OUString ustr1 = rtl::OUString::createFromAscii( astr );
336 sal_Bool bOk = ustr1.equalsIgnoreAsciiCase( ustr1 );
338 return bOk;
341 /** simple version to judge if a file name or directory name is a URL or a system path, just to see if it
342 is start with "file:///";.
344 inline sal_Bool isURL( const sal_Char *pathname )
346 return ( 0 == strncmp( pathname, FILE_PREFIX, sizeof( FILE_PREFIX ) - 1 ) );
349 /** simple version to judge if a file name or directory name is a URL or a system path, just to see if it
350 is start with "file:///";.
352 inline sal_Bool isURL( const ::rtl::OUString pathname )
354 return ( ( pathname.indexOf( aPreURL ) == 0 ) ? sal_True : sal_False );
357 /** concat two part to form a URL or system path, add PATH_SEPERATOR between them if necessary, add "file:///" to begining if necessary.
359 inline void concatURL( ::rtl::OUString & pathname1, const ::rtl::OUString & pathname2 )
361 //check if pathname1 is full qualified URL;
362 if ( !isURL( pathname1 ) )
364 ::rtl::OUString aPathName = pathname1.copy( 0 );
365 ::osl::FileBase::getFileURLFromSystemPath( pathname1, aPathName ); //convert if not full qualified URL
366 pathname1 = aPathName.copy( 0 );
369 sal_Int32 index = 0;
370 //check if '/' is in the end of pathname1 or at the begin of pathname2;
371 if ( ( ( index = pathname1.lastIndexOf( aSlashURL ) ) != ( pathname1.getLength( ) - 1 ) ) &&
372 ( ( index = pathname2.indexOf( aSlashURL ) ) != 0 ) )
373 pathname1 += aSlashURL;
374 pathname1 += pathname2;
377 /** create a temp test file using OUString name of full qualified URL or system path.
379 inline void createTestFile( const ::rtl::OUString filename )
381 ::rtl::OUString aPathURL = filename.copy( 0 );
382 ::osl::FileBase::RC nError;
384 if ( !isURL( filename ) )
385 ::osl::FileBase::getFileURLFromSystemPath( filename, aPathURL ); //convert if not full qualified URL
387 //::std::auto_ptr<File> pFile( new File( aPathURL ) );
388 File aFile(aPathURL);
389 //nError = pFile->open( OpenFlag_Read | OpenFlag_Write | OpenFlag_Create );
390 nError = aFile.open( OpenFlag_Read | OpenFlag_Write | OpenFlag_Create );
391 //CPPUNIT_ASSERT_MESSAGE( "In createTestFile Function: creation ", ( ::osl::FileBase::E_None == nError ) || ( nError == ::osl::FileBase::E_EXIST ) );
392 if ( ( ::osl::FileBase::E_None != nError ) && ( nError != ::osl::FileBase::E_EXIST ))
394 t_print("createTestFile failed!\n");
396 aFile.close();
400 /** create a temp test file using OUString name of full qualified URL or system path in a base directory.
402 inline void createTestFile( const ::rtl::OUString basename, const ::rtl::OUString filename )
404 ::rtl::OUString aBaseURL = basename.copy( 0 );
406 concatURL( aBaseURL, filename );
407 createTestFile( aBaseURL );
410 /** detete a temp test file using OUString name.
412 inline void deleteTestFile( const ::rtl::OUString filename )
414 // LLA: t_print("deleteTestFile\n");
415 ::rtl::OUString aPathURL = filename.copy( 0 );
416 ::osl::FileBase::RC nError;
418 if ( !isURL( filename ) )
419 ::osl::FileBase::getFileURLFromSystemPath( filename, aPathURL ); //convert if not full qualified URL
421 nError = ::osl::File::setAttributes( aPathURL, Attribute_GrpWrite| Attribute_OwnWrite| Attribute_OthWrite ); // if readonly, make writtenable.
422 CPPUNIT_ASSERT_MESSAGE( "In deleteTestFile Function: set writtenable ", ( ::osl::FileBase::E_None == nError ) || ( ::osl::FileBase::E_NOENT == nError ) );
424 nError = ::osl::File::remove( aPathURL );
425 CPPUNIT_ASSERT_MESSAGE( "In deleteTestFile Function: remove ", ( ::osl::FileBase::E_None == nError ) || ( nError == ::osl::FileBase::E_NOENT ) );
428 /** delete a temp test file using OUString name of full qualified URL or system path in a base directory.
430 inline void deleteTestFile( const ::rtl::OUString basename, const ::rtl::OUString filename )
432 ::rtl::OUString aBaseURL = basename.copy( 0 );
434 concatURL( aBaseURL, filename );
435 deleteTestFile( aBaseURL );
438 /** create a temp test directory using OUString name of full qualified URL or system path.
440 inline void createTestDirectory( const ::rtl::OUString dirname )
442 ::rtl::OUString aPathURL = dirname.copy( 0 );
443 ::osl::FileBase::RC nError;
445 if ( !isURL( dirname ) )
446 ::osl::FileBase::getFileURLFromSystemPath( dirname, aPathURL ); //convert if not full qualified URL
447 nError = ::osl::Directory::create( aPathURL );
448 //CPPUNIT_ASSERT_MESSAGE( "In createTestDirectory Function: creation: ", ( ::osl::FileBase::E_None == nError ) || ( nError == ::osl::FileBase::E_EXIST ) );
449 if ( ( ::osl::FileBase::E_None != nError ) && ( nError != ::osl::FileBase::E_EXIST ))
450 t_print("createTestDirectory failed!\n");
453 /** create a temp test directory using OUString name of full qualified URL or system path in a base directory.
455 inline void createTestDirectory( const ::rtl::OUString basename, const ::rtl::OUString dirname )
457 ::rtl::OUString aBaseURL = basename.copy( 0 );
458 ::rtl::OString aString;
460 concatURL( aBaseURL, dirname );
461 createTestDirectory( aBaseURL );
464 /** delete a temp test directory using OUString name of full qualified URL or system path.
466 inline void deleteTestDirectory( const ::rtl::OUString dirname )
468 // LLA: t_print("deleteTestDirectory\n");
469 ::rtl::OUString aPathURL = dirname.copy( 0 );
470 ::osl::FileBase::RC nError;
471 // LLA: printFileName(aPathURL);
472 if ( !isURL( dirname ) )
473 ::osl::FileBase::getFileURLFromSystemPath( dirname, aPathURL ); //convert if not full qualified URL
475 ::osl::Directory testDir( aPathURL );
476 if ( testDir.isOpen( ) == sal_True )
478 // LLA: t_print("#close Dir\n");
479 testDir.close( ); //close if still open.
482 nError = ::osl::Directory::remove( aPathURL );
483 // LLA: printError(nError);
484 // LLA: if (( ::osl::FileBase::E_None == nError ))
485 // LLA: {
486 // LLA: t_print("nError == E_None\n");
487 // LLA: }
488 // LLA: else if ( ( nError == ::osl::FileBase::E_NOENT ))
489 // LLA: {
490 // LLA: t_print("nError == E_NOENT\n");
491 // LLA: }
492 // LLA: else
493 // LLA: {
494 // LLA: // t_print("nError == %d\n", nError);
495 // LLA: }
496 rtl::OUString strError = rtl::OUString::createFromAscii( "In deleteTestDirectory function: remove Directory ");
497 strError += aPathURL;
498 CPPUNIT_ASSERT_MESSAGE( strError, ( ::osl::FileBase::E_None == nError ) || ( nError == ::osl::FileBase::E_NOENT ) );
499 // LLA: if (! ( ::osl::FileBase::E_None == nError ) || ( nError == ::osl::FileBase::E_NOENT ))
500 // LLA: {
501 // LLA: t_print("In deleteTestDirectory function: remove\n");
502 // LLA: }
505 /** delete a temp test directory using OUString name of full qualified URL or system path in a base directory.
507 inline void deleteTestDirectory( const ::rtl::OUString basename, const ::rtl::OUString dirname )
509 ::rtl::OUString aBaseURL = basename.copy( 0 );
511 concatURL( aBaseURL, dirname );
512 deleteTestDirectory( aBaseURL );
516 /** Check for the file and directory access right.
518 typedef enum {
519 osl_Check_Mode_Exist,
520 osl_Check_Mode_OpenAccess,
521 osl_Check_Mode_ReadAccess,
522 osl_Check_Mode_WriteAccess
523 } oslCheckMode;
525 // not used here
526 inline sal_Bool checkFile( const ::rtl::OUString & str, oslCheckMode nCheckMode )
528 ::osl::FileBase::RC nError1, nError2;
529 ::osl::File testFile( str );
530 sal_Bool bCheckResult;
532 bCheckResult = sal_False;
533 nError1 = testFile.open ( OpenFlag_Read );
534 if ( ( ::osl::FileBase::E_NOENT != nError1 ) && ( ::osl::FileBase::E_ACCES != nError1 ) ){
536 switch ( nCheckMode ) {
537 case osl_Check_Mode_Exist:
538 /// check if the file is exist.
539 if ( ::osl::FileBase::E_None == nError1 )
540 bCheckResult = sal_True;
541 break;
542 case osl_Check_Mode_OpenAccess:
543 /// check if the file is openable.
544 if ( ::osl::FileBase::E_None == nError1 )
545 bCheckResult = sal_True;
546 break;
547 case osl_Check_Mode_WriteAccess:
548 /// check the file name and whether it can be write.
549 /// write chars into the file.
550 //testFile.close( );
551 //testFile.open( OpenFlag_Write );
552 sal_uInt64 nCount_write;
553 nError2 = testFile.write( pBuffer_Char, 10, nCount_write );
554 if ( ::osl::FileBase::E_None == nError2 )
555 bCheckResult = sal_True;
556 break;
558 default:
559 bCheckResult = sal_False;
560 }/// swith
562 nError2 = testFile.close( );
563 CPPUNIT_ASSERT_MESSAGE( " in CheckFile() function, close file ", nError2 == FileBase::E_None );
567 return bCheckResult;
570 //check if the file exist
571 inline sal_Bool ifFileExist( const ::rtl::OUString & str )
573 sal_Bool bCheckResult = sal_False;
575 /*#ifdef WNT
576 ::rtl::OUString aUStr = str.copy( 0 );
577 if ( isURL( str ) )
578 ::osl::FileBase::getSystemPathFromFileURL( str, aUStr );
580 ::rtl::OString aString = ::rtl::OUStringToOString( aUStr, RTL_TEXTENCODING_ASCII_US );
581 const char *path = aString.getStr( );
582 if (( _access( path, 0 ) ) != -1 )
583 bCheckResult = sal_True;
584 #else*/
585 ::rtl::OString aString = ::rtl::OUStringToOString( str, RTL_TEXTENCODING_ASCII_US );
586 // const char *path = aString.getStr( );
587 ::osl::File testFile( str );
588 bCheckResult = ( osl::FileBase::E_None == testFile.open( OpenFlag_Read ) );
589 //if (bCheckResult)
590 //t_print("%s exist!\n", path);
591 //else
592 //t_print("%s not exist!\n", path);
593 //#endif
594 return bCheckResult;
598 //check if the file can be writen
599 inline sal_Bool ifFileCanWrite( const ::rtl::OUString & str )
601 sal_Bool bCheckResult = sal_False;
602 //on Windows, the file has no write right, but can be written
603 #ifdef WNT
604 ::rtl::OUString aUStr = str.copy( 0 );
605 if ( isURL( str ) )
606 ::osl::FileBase::getSystemPathFromFileURL( str, aUStr );
608 ::rtl::OString aString = ::rtl::OUStringToOString( aUStr, RTL_TEXTENCODING_ASCII_US );
609 const char *path = aString.getStr( );
610 if (( _access( path, 2 ) ) != -1 )
611 bCheckResult = sal_True;
612 //on UNX, just test if open success with OpenFlag_Write
613 #else
614 ::osl::File testFile( str );
615 bCheckResult = (osl::FileBase::E_None == testFile.open( OpenFlag_Write ));
616 #endif
617 return bCheckResult;
620 inline sal_Bool checkDirectory( const ::rtl::OUString & str, oslCheckMode nCheckMode )
622 rtl::OUString aUString;
623 DirectoryItem rItem;
624 FileBase::RC rc;
625 sal_Bool bCheckResult= sal_False;
627 //::std::auto_ptr<Directory> pDir( new Directory( str ) );
628 Directory aDir( str );
629 rc = aDir.open( );
631 if ( ( ::osl::FileBase::E_NOENT != rc ) && ( ::osl::FileBase::E_ACCES != rc ) ){
633 switch ( nCheckMode ) {
634 case osl_Check_Mode_Exist:
635 if ( rc == ::osl::FileBase::E_None )
636 bCheckResult = sal_True;
637 break;
638 case osl_Check_Mode_OpenAccess:
639 if ( rc == ::osl::FileBase::E_None )
640 bCheckResult = sal_True;
641 break;
642 case osl_Check_Mode_ReadAccess:
643 //rc = pDir->getNextItem( rItem, 0 );
644 rc = aDir.getNextItem( rItem, 0 );
645 if ( ( rc == ::osl::FileBase::E_None ) || ( rc == ::osl::FileBase::E_NOENT ) )
646 bCheckResult = sal_True;
647 else
648 bCheckResult = sal_False;
649 break;
650 case osl_Check_Mode_WriteAccess:
651 ( ( aUString += str ) += aSlashURL ) += aTmpName2;
652 //if ( ( rc = pDir->create( aUString ) ) == ::osl::FileBase::E_None )
653 if ( ( rc = Directory::create( aUString ) ) == ::osl::FileBase::E_None )
655 bCheckResult = sal_True;
656 //rc = pDir->remove( aUString );
657 rc = Directory::remove( aUString );
658 CPPUNIT_ASSERT( rc == ::osl::FileBase::E_None );
660 else
661 bCheckResult = sal_False;
662 break;
664 default:
665 bCheckResult = sal_False;
666 }// switch
668 rc = aDir.close( );
669 CPPUNIT_ASSERT( rc == FileBase::E_None );
671 }//if
673 return bCheckResult;
676 /** construct error message
678 inline ::rtl::OUString outputError( const ::rtl::OUString & returnVal, const ::rtl::OUString & rightVal, const sal_Char * msg = "")
680 ::rtl::OUString aUString;
681 if ( returnVal.equals( rightVal ) )
682 return aUString;
683 aUString += ::rtl::OUString::createFromAscii(msg);
684 aUString += ::rtl::OUString::createFromAscii(": the returned value is '");
685 aUString += returnVal;
686 aUString += ::rtl::OUString::createFromAscii("', but the value should be '");
687 aUString += rightVal;
688 aUString += ::rtl::OUString::createFromAscii("'.");
689 return aUString;
692 /** Change file mode, two version in UNIX and Windows;.
694 #if ( defined UNX ) || ( defined OS2 ) //chmod() method is differ in Windows
695 inline void changeFileMode( ::rtl::OUString & filepath, sal_Int32 mode )
697 rtl::OString aString;
698 rtl::OUString aUStr = filepath.copy( 0 );
700 if ( isURL( filepath ) )
701 ::osl::FileBase::getSystemPathFromFileURL( filepath, aUStr );
702 aString = ::rtl::OUStringToOString( aUStr, RTL_TEXTENCODING_ASCII_US );
703 chmod( aString.getStr( ), mode );
705 #else //Windows version
706 inline void changeFileMode( ::rtl::OUString & filepath, sal_Int32 mode )
708 (void)filepath;
709 (void)mode;
710 t_print("this method is not implemented yet");
712 #endif
714 inline ::rtl::OUString getCurrentPID( void );
718 //------------------------------------------------------------------------
719 // Beginning of the test cases for FileBase class
720 //------------------------------------------------------------------------
721 namespace osl_FileBase
724 #if 0 //~ this function has been deprecated
725 //---------------------------------------------------------------------
726 // testing the method
727 // static inline RC getCanonicalName( const ::rtl::OUString& ustrRequestedURL, ::rtl::OUString& ustrValidURL )
729 // The illegal characters are ;+=[]',\"*\\<>/?:|.
730 // because getCanonicalName method is not implemented yet and will be deprecated in the future, this test is not necessary.
731 //---------------------------------------------------------------------
733 class getCanonicalName:public CppUnit::TestFixture
736 public:
737 ::osl::FileBase::RC nError;
739 void getCanonicalName_001( )
741 ::rtl::OUString aUStr_ValidURL;
742 nError = ::osl::FileBase::getCanonicalName( aCanURL1, aUStr_ValidURL );
744 CPPUNIT_ASSERT_MESSAGE("test for getCanonicalName function: check valid and unused file name",
745 ( osl::FileBase::E_None == nError ) && aUStr_ValidURL.equalsIgnoreAsciiCase( aCanURL1 ) );
748 void getCanonicalName_002( )
750 ::rtl::OUString aUStr_ValidURL;
752 createTestFile( aCanURL1 );
753 nError = ::osl::FileBase::getCanonicalName( aCanURL1, aUStr_ValidURL );
754 deleteTestFile( aCanURL1 );
756 CPPUNIT_ASSERT_MESSAGE( " test for getCanonicalName function: an existed file name, should different from the request, it did not passed(W32)(UNX)",
757 ( osl::FileBase::E_None == nError ) && aUStr_ValidURL.equalsIgnoreAsciiCase( aCanURL1 ) );
760 void getCanonicalName_003( )
762 ::rtl::OUString aUStr_ValidURL;
763 nError = ::osl::FileBase::getCanonicalName ( aCanURL2, aUStr_ValidURL );
765 CPPUNIT_ASSERT_MESSAGE( " test for getCanonicalName function: invalid file name, should different from the request, it did not passed(W32)(UNX)",
766 ( osl::FileBase::E_None == nError ) && aUStr_ValidURL.equalsIgnoreAsciiCase( aCanURL2 ) );
769 CPPUNIT_TEST_SUITE( getCanonicalName );
770 CPPUNIT_TEST( getCanonicalName_001 );
771 CPPUNIT_TEST( getCanonicalName_002 );
772 CPPUNIT_TEST( getCanonicalName_003 );
773 CPPUNIT_TEST_SUITE_END( );
774 };// class getCanonicalName
775 #endif
777 //---------------------------------------------------------------------
778 // testing the method
779 // static inline RC getAbsoluteFileURL( const ::rtl::OUString& ustrBaseDirectoryURL,
780 // const ::rtl::OUString& ustrRelativeFileURL,
781 // ::rtl::OUString& ustrAbsoluteFileURL )
782 //---------------------------------------------------------------------
784 class getAbsoluteFileURL:public CppUnit::TestFixture
786 //::osl::FileBase aFileBase;
787 ::rtl::OUString aResultURL1, aResultURL2, aResultURL3, aResultURL4, aResultURL5, aResultURL6;
788 // ::osl::FileBase::RC nError;
789 sal_Bool bOk;
791 public:
793 void check_getAbsoluteFileURL( rtl::OUString const& _suBaseURL, rtl::OString const& _sRelativeURL, ::osl::FileBase::RC _nAssumeError, rtl::OUString const& _suAssumeResultStr );
795 void getAbsoluteFileURL_001_1();
796 void getAbsoluteFileURL_001_2();
797 void getAbsoluteFileURL_001_3();
798 void getAbsoluteFileURL_001_4();
799 void getAbsoluteFileURL_001_5();
800 void getAbsoluteFileURL_001_6();
801 void getAbsoluteFileURL_001_7();
802 void getAbsoluteFileURL_001_8();
803 void getAbsoluteFileURL_002();
804 void getAbsoluteFileURL_003();
805 void getAbsoluteFileURL_004();
807 CPPUNIT_TEST_SUITE( getAbsoluteFileURL );
808 CPPUNIT_TEST( getAbsoluteFileURL_001_1 );
809 CPPUNIT_TEST( getAbsoluteFileURL_001_2 );
810 CPPUNIT_TEST( getAbsoluteFileURL_001_3 );
811 CPPUNIT_TEST( getAbsoluteFileURL_001_4 );
812 CPPUNIT_TEST( getAbsoluteFileURL_001_5 );
813 CPPUNIT_TEST( getAbsoluteFileURL_001_6 );
814 CPPUNIT_TEST( getAbsoluteFileURL_001_7 );
815 CPPUNIT_TEST( getAbsoluteFileURL_001_8 );
816 CPPUNIT_TEST( getAbsoluteFileURL_002 );
817 CPPUNIT_TEST( getAbsoluteFileURL_003 );
818 CPPUNIT_TEST( getAbsoluteFileURL_004 );
819 CPPUNIT_TEST_SUITE_END( );
821 }; //class getAbsoluteFileURL
823 /* use coding format as same as getSystemPathFromFileURL
824 // initialization
825 void setUp( )
827 sal_Char pResultURL1[] = "/relative/file1";
828 sal_Char pResultURL2[] = "/relative/file2";
829 sal_Char pResultURL3[] = "/file3";
830 sal_Char pResultURL4[] = "/file4";
831 sal_Char pResultURL5[] = "/canonical.name";
832 sal_Char pResultURL6[] = "/relative/";
833 aResultURL1 = aUserDirectoryURL.concat( rtl::OUString::createFromAscii( pResultURL1 ) );
834 aResultURL2 = aUserDirectoryURL.concat( rtl::OUString::createFromAscii( pResultURL2 ) );
835 aResultURL3 = aUserDirectoryURL.concat( rtl::OUString::createFromAscii( pResultURL3 ) );
836 aResultURL4 = aUserDirectoryURL.concat( rtl::OUString::createFromAscii( pResultURL4 ) );
837 aResultURL5 = aUserDirectoryURL.concat( rtl::OUString::createFromAscii( pResultURL5 ) );
838 aResultURL6 = aUserDirectoryURL.concat( rtl::OUString::createFromAscii( pResultURL6 ) );
841 void tearDown( )
845 // test code
846 void getAbsoluteFileURL_001( )
848 ::rtl::OUString aUStr_AbsURL;
850 ::osl::FileBase::RC nError11 = aFileBase.getAbsoluteFileURL( aUserDirectoryURL, aRelURL1, aUStr_AbsURL );
851 ::rtl::OUString suError = ::rtl::OUString::createFromAscii("test for getAbsoluteFileURL(' ");
852 suError += aUserDirectoryURL;
853 suError += ::rtl::OUString::createFromAscii("', '");
854 suError += aRelURL1;
855 suError += ::rtl::OUString::createFromAscii("', '");
856 suError += aUStr_AbsURL;
857 suError += outputError( aUStr_AbsURL, aResultURL1, "' ),");
859 sal_Bool nError12 = aUStr_AbsURL.equals( aResultURL1 );
860 ::osl::FileBase::RC nError21 = aFileBase.getAbsoluteFileURL( aUserDirectoryURL, aRelURL2, aUStr_AbsURL );
861 sal_Bool nError22 = aUStr_AbsURL.equals( aResultURL2 );
862 ::osl::FileBase::RC nError31 = aFileBase.getAbsoluteFileURL( aUserDirectoryURL, aRelURL3, aUStr_AbsURL );
863 sal_Bool nError32 = aUStr_AbsURL.equals( aResultURL3 );
864 ::osl::FileBase::RC nError41 = aFileBase.getAbsoluteFileURL( aUserDirectoryURL, aRelURL4, aUStr_AbsURL );
865 sal_Bool nError42 = aUStr_AbsURL.equals( aResultURL4 );
866 ::osl::FileBase::RC nError61 = aFileBase.getAbsoluteFileURL( aUserDirectoryURL, aRelURL6, aUStr_AbsURL );
867 sal_Bool nError62 = aUStr_AbsURL.equals( aResultURL6 );
868 printFileName( aUStr_AbsURL );
869 printFileName( aResultURL6 );
871 CPPUNIT_ASSERT_MESSAGE("test for getAbsoluteFileURL function: valid file name with valid directory",
872 ( ::osl::FileBase::E_None == nError11 ) && ( sal_True == nError12 ) &&
873 ( ::osl::FileBase::E_None == nError21 ) && ( sal_True == nError22 ) &&
874 ( ::osl::FileBase::E_None == nError31 ) && ( sal_True == nError32 ) &&
875 ( ::osl::FileBase::E_None == nError41 ) && ( sal_True == nError42 ) &&
876 ( ::osl::FileBase::E_None == nError61 ) && ( sal_True == nError62 ) );
880 #if ( defined UNX ) || ( defined OS2 ) //Link is not defined in Windows
881 void getAbsoluteFileURL_002( )
883 ::rtl::OUString aUStr_AbsURL, aUStr_LnkFileSys( aTempDirectorySys ), aUStr_SrcFileSys( aTempDirectorySys );
884 ( ( aUStr_LnkFileSys += aSlashURL ) += getCurrentPID( ) ) += ::rtl::OUString::createFromAscii("/link.file");
885 ( ( aUStr_SrcFileSys += aSlashURL ) += getCurrentPID( ) ) += ::rtl::OUString::createFromAscii("/canonical.name");
887 rtl::OString strLinkFileName, strSrcFileName;
888 strLinkFileName = OUStringToOString( aUStr_LnkFileSys, RTL_TEXTENCODING_ASCII_US );
889 strSrcFileName = OUStringToOString( aUStr_SrcFileSys, RTL_TEXTENCODING_ASCII_US );
891 createTestFile( aCanURL1 );
892 sal_Int32 fd = symlink( strSrcFileName.getStr(), strLinkFileName.getStr() );
893 CPPUNIT_ASSERT( fd == 0 );
895 nError = aFileBase.getAbsoluteFileURL( aUserDirectoryURL, aLnkURL1, aUStr_AbsURL );
896 bOk = aUStr_AbsURL.equals( aResultURL5 );
898 ::rtl::OUString suError = ::rtl::OUString::createFromAscii("test for getAbsoluteFileURL(' ");
899 suError += aUserDirectoryURL;
900 suError += ::rtl::OUString::createFromAscii("', '");
901 suError += aLnkURL1;
902 suError += ::rtl::OUString::createFromAscii("', '");
903 suError += aUStr_AbsURL;
904 suError += outputError( aUStr_AbsURL, aResultURL5, "' ),");
905 //printFileName(suError);
907 deleteTestFile( aCanURL1 );
908 fd = remove( strLinkFileName.getStr() );
909 CPPUNIT_ASSERT( fd == 0 );
911 CPPUNIT_ASSERT_MESSAGE("test for getAbsoluteFileURL function: URL contain link( Solaris version )",
912 ( ::osl::FileBase::E_None == nError ) && ( sal_True == bOk ) );
914 #else //Windows version
915 void getAbsoluteFileURL_002( )
917 CPPUNIT_ASSERT_MESSAGE("test for getAbsoluteFileURL function: URL contain link( Windows version )",
918 1 );
920 #endif
922 void getAbsoluteFileURL_003( )
924 // LLA: may be a wrong test, aTmpName1 not a real URL
925 #if 0
926 ::rtl::OUString aUStr_AbsURL;
928 nError = aFileBase.getAbsoluteFileURL( aTmpName1, aRelURL1, aUStr_AbsURL ); //base dir invalid error
929 ::rtl::OUString suError = ::rtl::OUString::createFromAscii("test for getAbsoluteFileURL('");
930 suError += aTmpName1;
931 suError += ::rtl::OUString::createFromAscii("', '");
932 suError += aRelURL1;
933 suError += ::rtl::OUString::createFromAscii("', '");
934 suError += aUStr_AbsURL;
935 suError += ::rtl::OUString::createFromAscii("' ),Parameter is invalid. it ignore the invalid base in Windows, did not pass in (W32), the reason maybe caused by the similar bug with getSystemPathFromFileURL() ");
937 CPPUNIT_ASSERT_MESSAGE( suError, ( ::osl::FileBase::E_INVAL == nError ) );
938 #endif
941 //use ".." in relartive path, the BasePath must exist on the file system
942 void getAbsoluteFileURL_004( )
944 //create two level directories under $Temp/PID/
945 ::rtl::OUString aUStrUpBase = aUserDirectoryURL + ::rtl::OUString::createFromAscii("/test1");
946 createTestDirectory( aUStrUpBase );
947 ::rtl::OUString aUStrBase = aUserDirectoryURL + ::rtl::OUString::createFromAscii("/test1/dir1");
948 createTestDirectory( aUStrBase );
950 ::rtl::OUString aUStrRelar = ::rtl::OUString::createFromAscii("../../mytestfile");
951 ::rtl::OUString aUStr_AbsURL;
952 ::rtl::OUString aResultURL6 = aUserDirectoryURL + ::rtl::OUString::createFromAscii("/mytestfile");
954 nError = aFileBase.getAbsoluteFileURL( aUStrBase, aUStrRelar, aUStr_AbsURL );
955 bOk = aUStr_AbsURL.equals( aResultURL6 );
956 ::rtl::OUString suError = ::rtl::OUString::createFromAscii("test for getAbsoluteFileURL('");
957 suError += aUStrBase;
958 suError += ::rtl::OUString::createFromAscii("', '");
959 suError += aUStrRelar;
960 suError += ::rtl::OUString::createFromAscii("', '");
961 suError += aUStr_AbsURL;
962 suError += outputError( aUStr_AbsURL, aResultURL6, "' ), did not pass on Win32 ");
964 deleteTestDirectory( aUStrBase );
965 deleteTestDirectory( aUStrUpBase );
967 CPPUNIT_ASSERT_MESSAGE( suError, ( ::osl::FileBase::E_None == nError ) && ( sal_True == bOk ) );
970 CPPUNIT_TEST_SUITE( getAbsoluteFileURL );
971 CPPUNIT_TEST( getAbsoluteFileURL_001 );
972 CPPUNIT_TEST( getAbsoluteFileURL_002 );
973 CPPUNIT_TEST( getAbsoluteFileURL_003 );
974 CPPUNIT_TEST( getAbsoluteFileURL_004 );
975 CPPUNIT_TEST_SUITE_END( );
976 };// class getAbsoluteFileURL*/
978 void getAbsoluteFileURL::check_getAbsoluteFileURL( rtl::OUString const& _suBaseURL, rtl::OString const& _sRelativeURL, ::osl::FileBase::RC _nAssumeError, rtl::OUString const& _suAssumeResultStr )
980 rtl::OUString suRelativeURL = rtl::OStringToOUString(_sRelativeURL, RTL_TEXTENCODING_UTF8);
981 rtl::OString sBaseURL = rtl::OUStringToOString(_suBaseURL, RTL_TEXTENCODING_UTF8);
982 rtl::OUString suResultURL;
983 osl::FileBase::RC nError = FileBase::getAbsoluteFileURL( _suBaseURL, suRelativeURL, suResultURL );
984 rtl::OString sResultURL = rtl::OUStringToOString( suResultURL, RTL_TEXTENCODING_UTF8);
985 rtl::OString sError = errorToString(nError);
986 t_print("getAbsoluteFileURL('%s','%s') deliver absolute URL: '%s', error '%s'\n", sBaseURL.getStr(), _sRelativeURL.getStr(),sResultURL.getStr(), sError.getStr() );
987 CPPUNIT_ASSERT_MESSAGE( "Assumption is wrong: error number is wrong", nError == _nAssumeError );
988 if ( nError == ::osl::FileBase::E_None )
990 sal_Bool bStrAreEqual = _suAssumeResultStr.equals( suResultURL );
991 CPPUNIT_ASSERT_MESSAGE( "Assumption is wrong: ResultURL is not equal to expected URL ", bStrAreEqual == sal_True );
995 void getAbsoluteFileURL::getAbsoluteFileURL_001_1()
997 rtl::OUString suAssume = aUserDirectoryURL.concat( rtl::OUString::createFromAscii("/relative/file1") );
998 check_getAbsoluteFileURL( aUserDirectoryURL, "relative/file1",::osl::FileBase::E_None, suAssume );
1000 void getAbsoluteFileURL::getAbsoluteFileURL_001_2()
1002 rtl::OUString suAssume = aUserDirectoryURL.concat( rtl::OUString::createFromAscii("/relative/file2") );
1003 check_getAbsoluteFileURL( aUserDirectoryURL, "relative/./file2",::osl::FileBase::E_None, suAssume );
1005 void getAbsoluteFileURL::getAbsoluteFileURL_001_3()
1007 rtl::OUString suAssume = aUserDirectoryURL.concat( rtl::OUString::createFromAscii("/file3") );
1008 check_getAbsoluteFileURL( aUserDirectoryURL, "relative/../file3",::osl::FileBase::E_None, suAssume );
1010 void getAbsoluteFileURL::getAbsoluteFileURL_001_4()
1012 rtl::OUString suAssume = aUserDirectoryURL.concat( rtl::OUString::createFromAscii("/file4") );
1013 check_getAbsoluteFileURL( aUserDirectoryURL, "././relative/../file4",::osl::FileBase::E_None, suAssume );
1015 void getAbsoluteFileURL::getAbsoluteFileURL_001_5()
1017 rtl::OUString suAssume;
1018 #if ( defined UNX )
1019 suAssume = aUserDirectoryURL.concat( rtl::OUString::createFromAscii("/relative/") );
1020 #else
1021 suAssume = aUserDirectoryURL.concat( rtl::OUString::createFromAscii("/relative") );
1022 #endif
1023 check_getAbsoluteFileURL( aUserDirectoryURL, "././relative/.",::osl::FileBase::E_None, suAssume );
1025 void getAbsoluteFileURL::getAbsoluteFileURL_001_6()
1027 rtl::OUString suAssume = aUserDirectoryURL.concat( rtl::OUString::createFromAscii("/.relative") );
1028 check_getAbsoluteFileURL( aUserDirectoryURL, "./.relative",::osl::FileBase::E_None, suAssume );
1030 void getAbsoluteFileURL::getAbsoluteFileURL_001_7()
1032 rtl::OUString suAssume;
1033 #if (defined UNX )
1034 suAssume = aUserDirectoryURL.concat( rtl::OUString::createFromAscii("/.a/") );
1035 #else //windows
1036 suAssume = aUserDirectoryURL.concat( rtl::OUString::createFromAscii("/.a") );
1037 #endif
1038 check_getAbsoluteFileURL( aUserDirectoryURL, "./.a/mydir/..",::osl::FileBase::E_None, suAssume );
1040 void getAbsoluteFileURL::getAbsoluteFileURL_001_8()
1042 rtl::OUString suAssume = aUserDirectoryURL.concat( rtl::OUString::createFromAscii("/tmp/ok") );
1043 #if ( defined UNX ) || ( defined OS2 )
1044 check_getAbsoluteFileURL( aUserDirectoryURL, "tmp//ok",::osl::FileBase::E_None, suAssume );
1045 #else
1046 check_getAbsoluteFileURL( aUserDirectoryURL, "tmp//ok",::osl::FileBase::E_INVAL, suAssume );
1047 #endif
1049 void getAbsoluteFileURL::getAbsoluteFileURL_002()
1051 #if ( defined UNX ) || ( defined OS2 ) //Link is not defined in Windows
1052 ::rtl::OUString aUStr_AbsURL, aUStr_LnkFileSys( aTempDirectorySys ), aUStr_SrcFileSys( aTempDirectorySys );
1053 ( ( aUStr_LnkFileSys += aSlashURL ) += getCurrentPID( ) ) += ::rtl::OUString::createFromAscii("/link.file");
1054 ( ( aUStr_SrcFileSys += aSlashURL ) += getCurrentPID( ) ) += ::rtl::OUString::createFromAscii("/canonical.name");
1056 rtl::OString strLinkFileName, strSrcFileName;
1057 strLinkFileName = OUStringToOString( aUStr_LnkFileSys, RTL_TEXTENCODING_ASCII_US );
1058 strSrcFileName = OUStringToOString( aUStr_SrcFileSys, RTL_TEXTENCODING_ASCII_US );
1060 createTestFile( aCanURL1 );
1061 sal_Int32 fd = symlink( strSrcFileName.getStr(), strLinkFileName.getStr() );
1062 CPPUNIT_ASSERT( fd == 0 );
1063 rtl::OString sLnkURL = OUStringToOString( aLnkURL1, RTL_TEXTENCODING_ASCII_US );
1064 rtl::OUString suAssume = aUserDirectoryURL.concat( rtl::OUString::createFromAscii("/canonical.name") );
1065 check_getAbsoluteFileURL( aUserDirectoryURL, sLnkURL, ::osl::FileBase::E_None, suAssume );
1066 deleteTestFile( aCanURL1 );
1067 fd = remove( strLinkFileName.getStr() );
1068 CPPUNIT_ASSERT( fd == 0 );
1069 #endif
1071 //please see line# 930
1072 void getAbsoluteFileURL::getAbsoluteFileURL_003()
1075 void getAbsoluteFileURL::getAbsoluteFileURL_004()
1077 //create two level directories under $Temp/PID/
1078 ::rtl::OUString aUStrUpBase = aUserDirectoryURL + ::rtl::OUString::createFromAscii("/test1");
1079 createTestDirectory( aUStrUpBase );
1080 ::rtl::OUString aUStrBase = aUserDirectoryURL + ::rtl::OUString::createFromAscii("/test1/dir1");
1081 createTestDirectory( aUStrBase );
1083 ::rtl::OUString suAssume = aUserDirectoryURL.concat( ::rtl::OUString::createFromAscii("/mytestfile") );
1084 check_getAbsoluteFileURL( aUStrBase, "../../mytestfile" , ::osl::FileBase::E_None, suAssume );
1085 deleteTestDirectory( aUStrBase );
1086 deleteTestDirectory( aUStrUpBase );
1088 //---------------------------------------------------------------------
1089 // testing two methods:
1090 // static inline RC getSystemPathFromFileURL( const ::rtl::OUString& ustrFileURL,
1091 // ::rtl::OUString& ustrSystemPath )
1092 // static RC getFileURLFromSystemPath( const ::rtl::OUString & ustrSystemPath,
1093 // ::rtl::OUString & ustrFileURL );
1094 //---------------------------------------------------------------------
1095 class SystemPath_FileURL:public CppUnit::TestFixture
1097 //::osl::FileBase aFileBase;
1098 // ::rtl::OUString aUStr;
1099 // ::osl::FileBase::RC nError;
1101 //void check_getSystemPathFromFileURL(rtl::OString const& _sURL, ::osl::FileBase::RC _nAssumeError, rtl::OString const& _sAssumeResultStr);
1102 void check_SystemPath_FileURL(rtl::OString const& _sSource, ::osl::FileBase::RC _nAssumeError, rtl::OString const& _sAssumeResultStr, sal_Bool bDirection = sal_True );
1103 void checkWNTBehaviour_getSystemPathFromFileURL(rtl::OString const& _sURL, ::osl::FileBase::RC _nAssumeError, rtl::OString const& _sWNTAssumeResultString );
1104 void checkUNXBehaviour_getSystemPathFromFileURL(rtl::OString const& _sURL, ::osl::FileBase::RC _nAssumeError, rtl::OString const& _sUnixAssumeResultString );
1105 void checkWNTBehaviour_getFileURLFromSystemPath(rtl::OString const& _sSysPath, ::osl::FileBase::RC _nAssumeError, rtl::OString const& _sWNTAssumeResultString);
1106 void checkUNXBehaviour_getFileURLFromSystemPath(rtl::OString const& _sSysPath, ::osl::FileBase::RC _nAssumeError, rtl::OString const& _sUnixAssumeResultString);
1108 public:
1109 // test code.
1110 void getSystemPathFromFileURL_001_1( );
1111 void getSystemPathFromFileURL_001_2( );
1112 void getSystemPathFromFileURL_001_21( );
1113 void getSystemPathFromFileURL_001_22( );
1114 void getSystemPathFromFileURL_001_3( );
1115 void getSystemPathFromFileURL_001_31( );
1116 void getSystemPathFromFileURL_001_4( );
1117 void getSystemPathFromFileURL_001_41( );
1118 void getSystemPathFromFileURL_001_5( );
1119 void getSystemPathFromFileURL_001_51( );
1120 void getSystemPathFromFileURL_001_52( );
1121 void getSystemPathFromFileURL_001_53( );
1122 void getSystemPathFromFileURL_001_6( );
1123 void getSystemPathFromFileURL_001_61( );
1124 void getSystemPathFromFileURL_001_7( );
1125 void getSystemPathFromFileURL_001_71( );
1126 void getSystemPathFromFileURL_001_8( );
1127 void getSystemPathFromFileURL_001_81( );
1128 void getSystemPathFromFileURL_001_9( );
1129 void getSystemPathFromFileURL_001_91( );
1130 void getSystemPathFromFileURL_001_92( );
1131 void getSystemPathFromFileURL_004( );
1132 void getSystemPathFromFileURL_005( );
1134 //test case fot getFileURLFromSystemPath
1135 void getFileURLFromSystemPath_001( );
1136 void getFileURLFromSystemPath_002( );
1137 void getFileURLFromSystemPath_003( );
1138 void getFileURLFromSystemPath_004( );
1139 void getFileURLFromSystemPath_005( );
1141 CPPUNIT_TEST_SUITE( SystemPath_FileURL );
1142 CPPUNIT_TEST( getSystemPathFromFileURL_001_1 );
1143 CPPUNIT_TEST( getSystemPathFromFileURL_001_2 );
1144 CPPUNIT_TEST( getSystemPathFromFileURL_001_21 );
1145 CPPUNIT_TEST( getSystemPathFromFileURL_001_22 );
1146 CPPUNIT_TEST( getSystemPathFromFileURL_001_3 );
1147 CPPUNIT_TEST( getSystemPathFromFileURL_001_31 );
1148 CPPUNIT_TEST( getSystemPathFromFileURL_001_4 );
1149 CPPUNIT_TEST( getSystemPathFromFileURL_001_41 );
1150 CPPUNIT_TEST( getSystemPathFromFileURL_001_5 );
1151 CPPUNIT_TEST( getSystemPathFromFileURL_001_51 );
1152 CPPUNIT_TEST( getSystemPathFromFileURL_001_52 );
1153 CPPUNIT_TEST( getSystemPathFromFileURL_001_53 );
1154 CPPUNIT_TEST( getSystemPathFromFileURL_001_6 );
1155 CPPUNIT_TEST( getSystemPathFromFileURL_001_61 );
1156 CPPUNIT_TEST( getSystemPathFromFileURL_001_7 );
1157 CPPUNIT_TEST( getSystemPathFromFileURL_001_71 );
1158 CPPUNIT_TEST( getSystemPathFromFileURL_001_8 );
1159 CPPUNIT_TEST( getSystemPathFromFileURL_001_81 );
1160 CPPUNIT_TEST( getSystemPathFromFileURL_001_9 );
1161 CPPUNIT_TEST( getSystemPathFromFileURL_001_91 );
1162 CPPUNIT_TEST( getSystemPathFromFileURL_001_92 );
1163 CPPUNIT_TEST( getSystemPathFromFileURL_004 );
1164 CPPUNIT_TEST( getSystemPathFromFileURL_005 );
1165 CPPUNIT_TEST( getFileURLFromSystemPath_001 );
1166 CPPUNIT_TEST( getFileURLFromSystemPath_002 );
1167 CPPUNIT_TEST( getFileURLFromSystemPath_003 );
1168 CPPUNIT_TEST( getFileURLFromSystemPath_004 );
1169 CPPUNIT_TEST( getFileURLFromSystemPath_005 );
1170 CPPUNIT_TEST_SUITE_END( );
1171 };// class SystemPath_FileURL
1174 // test code.
1176 /* void getSystemPathFromFileURL::check_getSystemPathFromFileURL(rtl::OString const& _sURL, ::osl::FileBase::RC _nAssumeError, rtl::OString const& _sAssumeResultStr)
1178 // PRE: URL as String
1179 rtl::OUString suURL;
1180 rtl::OUString suStr;
1181 suURL = rtl::OStringToOUString(_sURL, RTL_TEXTENCODING_UTF8);
1182 ::osl::FileBase::RC nError = osl::FileBase::getSystemPathFromFileURL( suURL, suStr ); // start with /
1184 // if the given string is gt length 0,
1185 // we check also this string
1186 rtl::OString sStr = rtl::OUStringToOString(suStr, RTL_TEXTENCODING_UTF8);
1187 rtl::OString sError = errorToString(nError);
1188 t_print("getSystemPathFromFileURL('%s') deliver system path: '%s', error '%s'\n", _sURL.getStr(), sStr.getStr(), sError.getStr() );
1190 // rtl::OUString suStrEncode = rtl::Uri::encode(suStr, rtl_UriCharClassUnoParamValue, rtl_UriEncodeKeepEscapes, RTL_TEXTENCODING_UTF8);
1191 // sStr = rtl::OUStringToOString(suStr, RTL_TEXTENCODING_UTF8);
1192 // t_print("UTF8: %s\n", sStr.getStr() );
1194 if (_sAssumeResultStr.getLength() > 0)
1196 sal_Bool bStrAreEqual = _sAssumeResultStr.equals(sStr);
1197 CPPUNIT_ASSERT_MESSAGE( "Assumption is wrong",
1198 nError == _nAssumeError && bStrAreEqual == sal_True );
1200 else
1202 CPPUNIT_ASSERT_MESSAGE( "Assumption is wrong", nError == _nAssumeError );
1206 // if bDirection==sal_True, check getSystemPathFromFileURL
1207 // if bDirection==sal_False, check getFileURLFromSystemPath
1208 void SystemPath_FileURL::check_SystemPath_FileURL(rtl::OString const& _sSource, ::osl::FileBase::RC _nAssumeError, rtl::OString const& _sAssumeResultStr, sal_Bool bDirection)
1210 // PRE: URL as String
1211 rtl::OUString suSource;
1212 rtl::OUString suStr;
1213 suSource = rtl::OStringToOUString(_sSource, RTL_TEXTENCODING_UTF8);
1214 ::osl::FileBase::RC nError;
1215 if ( bDirection == sal_True )
1216 nError = osl::FileBase::getSystemPathFromFileURL( suSource, suStr );
1217 else
1218 nError = osl::FileBase::getFileURLFromSystemPath( suSource, suStr );
1220 // if the given string is gt length 0,
1221 // we check also this string
1222 rtl::OString sStr = rtl::OUStringToOString(suStr, RTL_TEXTENCODING_UTF8);
1223 rtl::OString sError = errorToString(nError);
1224 if ( bDirection == sal_True )
1225 t_print("getSystemPathFromFileURL('%s') deliver system path: '%s', error '%s'\n", _sSource.getStr(), sStr.getStr(), sError.getStr() );
1226 else
1227 t_print("getFileURLFromSystemPath('%s') deliver File URL: '%s', error '%s'\n", _sSource.getStr(), sStr.getStr(), sError.getStr() );
1229 // rtl::OUString suStrEncode = rtl::Uri::encode(suStr, rtl_UriCharClassUnoParamValue, rtl_UriEncodeKeepEscapes, RTL_TEXTENCODING_UTF8);
1230 // sStr = rtl::OUStringToOString(suStr, RTL_TEXTENCODING_UTF8);
1231 // t_print("UTF8: %s\n", sStr.getStr() );
1233 if (_sAssumeResultStr.getLength() > 0)
1235 sal_Bool bStrAreEqual = _sAssumeResultStr.equals(sStr);
1236 CPPUNIT_ASSERT_MESSAGE( "Assumption is wrong",
1237 nError == _nAssumeError && bStrAreEqual == sal_True );
1239 else
1241 CPPUNIT_ASSERT_MESSAGE( "Assumption is wrong", nError == _nAssumeError );
1244 void SystemPath_FileURL::checkWNTBehaviour_getSystemPathFromFileURL(rtl::OString const& _sURL, ::osl::FileBase::RC _nAssumeError, rtl::OString const& _sWNTAssumeResultString)
1246 #if ( defined WNT )
1247 check_SystemPath_FileURL(_sURL, _nAssumeError, _sWNTAssumeResultString);
1248 #else
1249 (void)_sURL;
1250 (void)_nAssumeError;
1251 (void)_sWNTAssumeResultString;
1252 #endif
1255 void SystemPath_FileURL::checkUNXBehaviour_getSystemPathFromFileURL(rtl::OString const& _sURL, ::osl::FileBase::RC _nAssumeError, rtl::OString const& _sUnixAssumeResultString)
1257 #if ( defined UNX )
1258 check_SystemPath_FileURL(_sURL, _nAssumeError, _sUnixAssumeResultString);
1259 #else
1260 (void)_sURL;
1261 (void)_nAssumeError;
1262 (void)_sUnixAssumeResultString;
1263 #endif
1266 void SystemPath_FileURL::checkWNTBehaviour_getFileURLFromSystemPath(rtl::OString const& _sSysPath, ::osl::FileBase::RC _nAssumeError, rtl::OString const& _sWNTAssumeResultString)
1268 #if ( defined WNT )
1269 check_SystemPath_FileURL(_sSysPath, _nAssumeError, _sWNTAssumeResultString, sal_False );
1270 #else
1271 (void)_sSysPath;
1272 (void)_nAssumeError;
1273 (void)_sWNTAssumeResultString;
1274 #endif
1277 void SystemPath_FileURL::checkUNXBehaviour_getFileURLFromSystemPath(rtl::OString const& _sSysPath, ::osl::FileBase::RC _nAssumeError, rtl::OString const& _sUnixAssumeResultString)
1279 #if ( defined UNX )
1280 check_SystemPath_FileURL(_sSysPath, _nAssumeError, _sUnixAssumeResultString, sal_False );
1281 #else
1282 (void)_sSysPath;
1283 (void)_nAssumeError;
1284 (void)_sUnixAssumeResultString;
1285 #endif
1288 /** LLA: Test for getSystemPathFromFileURL()
1289 this test is splitted into 2 different OS tests,
1290 the first function checkUNXBehaviour... runs only on Unix based Systems,
1291 the second only on windows based systems
1292 the first parameter are a file URL where we want to get the system path of,
1293 the second parameter is the assumed error of the osl_getSystemPathFromFileURL() function,
1294 the thrid parameter is the assumed result string, the string will only test, if it's length is greater 0
1297 void SystemPath_FileURL::getSystemPathFromFileURL_001_1()
1299 rtl::OString sURL("");
1300 checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, "");
1301 checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, "");
1304 void SystemPath_FileURL::getSystemPathFromFileURL_001_2()
1306 rtl::OString sURL("/");
1307 checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, "");
1308 checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "\\");
1310 void SystemPath_FileURL::getSystemPathFromFileURL_001_21()
1312 // rtl::OString sURL("%2f");
1313 rtl::OString sURL("%2F");
1314 checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "/"); // LLA: this is may be a BUG
1315 checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, "");
1317 void SystemPath_FileURL::getSystemPathFromFileURL_001_22()
1319 rtl::OString sURL("file:///tmp%2Fmydir");
1320 checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, "");
1321 checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, "");
1323 void SystemPath_FileURL::getSystemPathFromFileURL_001_3()
1325 rtl::OString sURL("a");
1326 checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "a");
1327 checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "a");
1329 void SystemPath_FileURL::getSystemPathFromFileURL_001_31()
1331 rtl::OString sURL("tmpname");
1332 checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "tmpname");
1333 checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "tmpname");
1335 void SystemPath_FileURL::getSystemPathFromFileURL_001_4()
1337 rtl::OString sURL("file://");
1338 checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "");
1339 checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, "");
1341 void SystemPath_FileURL::getSystemPathFromFileURL_001_41()
1343 rtl::OString sURL("file://localhost/tmp");
1344 checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "");
1345 checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, "");
1347 void SystemPath_FileURL::getSystemPathFromFileURL_001_5()
1349 rtl::OString sURL("file:///tmp");
1350 checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "/tmp");
1351 checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, "");
1353 void SystemPath_FileURL::getSystemPathFromFileURL_001_51()
1355 rtl::OString sURL("file://c:/tmp");
1356 checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "c:/tmp"); // LLA: this is may be a BUG
1357 checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, "");
1359 void SystemPath_FileURL::getSystemPathFromFileURL_001_52()
1361 rtl::OString sURL("file:///c:/tmp");
1362 checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "/c:/tmp");
1363 checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "c:\\tmp");
1365 void SystemPath_FileURL::getSystemPathFromFileURL_001_53()
1367 // LLA: is this a legal file path?
1368 rtl::OString sURL("file:///c|/tmp");
1369 checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "/c|/tmp");
1370 checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "c:\\tmp");
1372 void SystemPath_FileURL::getSystemPathFromFileURL_001_6()
1374 rtl::OString sURL("file:///tmp/first");
1375 checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "/tmp/first");
1376 checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, "");
1378 void SystemPath_FileURL::getSystemPathFromFileURL_001_61()
1380 rtl::OString sURL("file:///c:/tmp/first");
1381 checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "/c:/tmp/first");
1382 checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "c:\\tmp\\first");
1384 void SystemPath_FileURL::getSystemPathFromFileURL_001_7()
1386 rtl::OString sURL("file:///tmp/../second");
1387 checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "/tmp/../second"); // LLA: may be a BUG
1388 checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, "");
1390 void SystemPath_FileURL::getSystemPathFromFileURL_001_71()
1392 rtl::OString sURL("file:///c:/tmp/../second");
1393 checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "/c:/tmp/../second");
1394 checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "c:\\tmp\\..\\second");
1396 void SystemPath_FileURL::getSystemPathFromFileURL_001_8()
1398 rtl::OString sURL("../tmp");
1399 checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "../tmp");
1400 checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "..\\tmp");
1402 void SystemPath_FileURL::getSystemPathFromFileURL_001_81()
1404 rtl::OString sURL("file://~/tmp");
1405 char* home_path;
1406 home_path = getenv("HOME");
1407 rtl::OString expResult(home_path);
1408 expResult += "/tmp";
1409 checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, expResult );
1410 // checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "\\tmp");
1412 void SystemPath_FileURL::getSystemPathFromFileURL_001_9()
1414 rtl::OString sURL("file:///tmp/first%20second");
1415 checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "/tmp/first second");
1416 checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, "");
1418 void SystemPath_FileURL::getSystemPathFromFileURL_001_91()
1420 rtl::OString sURL("file:///c:/tmp/first%20second");
1421 checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "/c:/tmp/first second");
1422 checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "c:\\tmp\\first second");
1425 void SystemPath_FileURL::getSystemPathFromFileURL_001_92()
1427 rtl::OString sURL("ca@#;+.,$///78no%01ni..name");
1428 checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "");
1429 checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, "");
1432 #if 0
1433 void SystemPath_FileURL::getSystemPathFromFileURL_003( )
1435 // LLA: ???
1436 //!! seams to be, that the directories do not pass together
1437 ::rtl::OUString aUStr;
1438 ::rtl::OUString aRelativeURL = ::rtl::OUString::createFromAscii("../../relartive/file3");
1439 ::rtl::OUString aResultURL ( aSysPath4 );
1440 ::osl::FileBase::RC nError = osl::FileBase::getSystemPathFromFileURL( aRelativeURL, aUStr );
1442 sal_Bool bOk = compareFileName( aUStr, aResultURL );
1444 ::rtl::OUString suError = ::rtl::OUString::createFromAscii("test for getSystemPathFromFileURL(");
1445 suError += aRelativeURL;
1446 suError += ::rtl::OUString::createFromAscii(") function:use a relative file URL, did not pass in(W32), it did not specified in method declaration of relative path issue, ");
1447 suError += outputError(aUStr, aResultURL);
1448 CPPUNIT_ASSERT_MESSAGE( suError, ( osl::FileBase::E_None == nError ) && ( sal_True == bOk ) );
1450 #endif
1452 //normal legal case
1453 void SystemPath_FileURL::getSystemPathFromFileURL_004( )
1455 ::rtl::OUString aUStr;
1456 ::rtl::OUString aNormalURL( aTmpName6 );
1457 ::rtl::OUString aResultURL ( aSysPath4 );
1458 ::osl::FileBase::RC nError = osl::FileBase::getSystemPathFromFileURL( aNormalURL, aUStr );
1460 sal_Bool bOk = compareFileName( aUStr, aResultURL );
1462 ::rtl::OUString suError = ::rtl::OUString::createFromAscii("test for getSystemPathFromFileURL(' ");
1463 suError += aNormalURL;
1464 suError += ::rtl::OUString::createFromAscii(" ') function:use an absolute file URL, ");
1465 suError += outputError(aUStr, aResultURL);
1467 CPPUNIT_ASSERT_MESSAGE( suError, ( osl::FileBase::E_None == nError ) && ( sal_True == bOk ) );
1471 //CJK charactors case
1472 void SystemPath_FileURL::getSystemPathFromFileURL_005( )
1474 ::rtl::OUString aUStr;
1475 createTestDirectory( aTmpName10 );
1476 ::rtl::OUString aNormalURL( aTmpName10 );
1477 ::rtl::OUString aResultURL ( aSysPath5 );
1479 ::osl::FileBase::RC nError = osl::FileBase::getSystemPathFromFileURL( aNormalURL, aUStr );
1481 sal_Bool bOk = compareFileName( aUStr, aResultURL );
1483 ::rtl::OUString suError = ::rtl::OUString::createFromAscii("test for getSystemPathFromFileURL(' ");
1484 suError += aNormalURL;
1485 suError += ::rtl::OUString::createFromAscii(" ') function:use a CJK coded absolute URL, ");
1486 suError += outputError(aUStr, aResultURL);
1487 deleteTestDirectory( aTmpName10 );
1489 CPPUNIT_ASSERT_MESSAGE( suError, ( osl::FileBase::E_None == nError ) && ( sal_True == bOk ) );
1491 void SystemPath_FileURL::getFileURLFromSystemPath_001()
1493 rtl::OString sSysPath("~/tmp");
1494 char* home_path;
1495 home_path = getenv("HOME");
1496 rtl::OString expResult(home_path);
1497 expResult = "file://"+ expResult + "/tmp";
1498 checkUNXBehaviour_getFileURLFromSystemPath(sSysPath, osl::FileBase::E_None, expResult );
1499 checkWNTBehaviour_getFileURLFromSystemPath(sSysPath, osl::FileBase::E_None, "~/tmp");
1501 void SystemPath_FileURL::getFileURLFromSystemPath_002()
1503 rtl::OString sSysPath("c:/tmp");
1504 checkUNXBehaviour_getFileURLFromSystemPath(sSysPath, osl::FileBase::E_None, "c:/tmp");
1505 checkWNTBehaviour_getFileURLFromSystemPath(sSysPath, osl::FileBase::E_None, "file:///c:/tmp");
1507 void SystemPath_FileURL::getFileURLFromSystemPath_003()
1509 rtl::OString sSysPath("file:///temp");
1510 checkUNXBehaviour_getFileURLFromSystemPath(sSysPath, osl::FileBase::E_INVAL, "");
1511 checkWNTBehaviour_getFileURLFromSystemPath(sSysPath, osl::FileBase::E_INVAL, "");
1513 void SystemPath_FileURL::getFileURLFromSystemPath_004()
1515 rtl::OString sSysPath("//tmp//first start");
1516 checkUNXBehaviour_getFileURLFromSystemPath(sSysPath, osl::FileBase::E_None, "file:///tmp/first%20start");
1517 checkWNTBehaviour_getFileURLFromSystemPath(sSysPath, osl::FileBase::E_INVAL, "");
1519 void SystemPath_FileURL::getFileURLFromSystemPath_005()
1521 rtl::OString sSysPath("");
1522 checkUNXBehaviour_getFileURLFromSystemPath(sSysPath, osl::FileBase::E_INVAL, "");
1523 checkWNTBehaviour_getFileURLFromSystemPath(sSysPath, osl::FileBase::E_INVAL, "");
1525 // start with "~user", not impletment
1526 // void SystemPath_FileURL::getFileURLFromSystemPath_006()
1531 //---------------------------------------------------------------------
1532 // testing the method
1533 // static inline RC searchFileURL( const ::rtl::OUString& ustrFileName,
1534 // const ::rtl::OUString& ustrSearchPath,
1535 // ::rtl::OUString& ustrFileURL )
1536 //---------------------------------------------------------------------
1537 class searchFileURL:public CppUnit::TestFixture
1539 //::osl::FileBase aFileBase;
1540 ::rtl::OUString aUStr;
1541 ::osl::FileBase::RC nError1, nError2, nError3,nError4;
1543 public:
1545 // test code.
1546 void searchFileURL_001( )
1548 /* search file is passed by system filename */
1549 nError1 = ::osl::FileBase::searchFileURL( aTmpName1, aUserDirectorySys, aUStr );
1550 /* search file is passed by full qualified file URL */
1551 nError2 = ::osl::FileBase::searchFileURL( aCanURL1, aUserDirectorySys, aUStr );
1552 /* search file is passed by relative file path */
1553 nError3 = ::osl::FileBase::searchFileURL( aRelURL4, aUserDirectorySys, aUStr );
1555 CPPUNIT_ASSERT_MESSAGE( "test for searchFileURL function: system filename/URL filename/relative path, system directory, searched files that is not exist, but it reply invalid error, did not pass in (W32) ",
1556 ( osl::FileBase::E_NOENT == nError1 ) &&
1557 ( osl::FileBase::E_NOENT == nError2 ) &&
1558 ( osl::FileBase::E_NOENT == nError3 ));
1561 void searchFileURL_002( )
1563 /* search file is passed by system filename */
1564 nError1 = ::osl::FileBase::searchFileURL( aTempDirectorySys, aRootSys, aUStr );
1565 sal_Bool bOk1 = compareFileName( aUStr, aTempDirectoryURL );
1566 /* search file is passed by full qualified file URL */
1567 nError2 = ::osl::FileBase::searchFileURL( aTempDirectoryURL, aRootSys, aUStr );
1568 sal_Bool bOk2 = compareFileName( aUStr, aTempDirectoryURL );
1569 /* search file is passed by relative file path */
1570 nError3 = ::osl::FileBase::searchFileURL( aRelURL5, aRootSys, aUStr );
1571 sal_Bool bOk3 = compareFileName( aUStr, aTempDirectoryURL );
1572 /* search file is passed by an exist file */
1573 createTestFile( aCanURL1 );
1574 nError4 = ::osl::FileBase::searchFileURL( aCanURL4, aUserDirectorySys, aUStr );
1575 sal_Bool bOk4 = compareFileName( aUStr, aCanURL1 );
1576 deleteTestFile( aCanURL1 );
1578 CPPUNIT_ASSERT_MESSAGE( "test for searchFileURL function: system filename/URL filename/relative path, system directory, searched file already exist.",
1579 ( osl::FileBase::E_None == nError1 ) &&
1580 ( osl::FileBase::E_None == nError2 ) &&
1581 ( osl::FileBase::E_None == nError3 ) &&
1582 ( osl::FileBase::E_None == nError4 ) &&
1583 ( sal_True == bOk1 ) &&
1584 ( sal_True == bOk2 ) &&
1585 ( sal_True == bOk3 ) &&
1586 ( sal_True == bOk4 ) );
1590 void searchFileURL_003( )
1592 OSLTEST_DECLARE( SystemPathList, TEST_PLATFORM_ROOT":"TEST_PLATFORM_ROOT TEST_PLATFORM_TEMP":"TEST_PLATFORM_ROOT"system/path" );
1593 nError1 = ::osl::FileBase::searchFileURL( aUserDirectoryURL, aSystemPathList, aUStr );
1594 sal_Bool bOk = compareFileName( aUStr, aUserDirectoryURL );
1595 CPPUNIT_ASSERT_MESSAGE( "test for searchFileURL function: search directory is a list of system paths",
1596 ( osl::FileBase::E_None == nError1 ) &&
1597 ( sal_True == bOk ) );
1600 void searchFileURL_004( )
1602 OSLTEST_DECLARE( SystemPathList, TEST_PLATFORM_ROOT PATH_LIST_DELIMITER TEST_PLATFORM_ROOT TEST_PLATFORM_TEMP PATH_LIST_DELIMITER TEST_PLATFORM_ROOT "system/path/../name" );
1603 nError1 = ::osl::FileBase::searchFileURL( aUserDirectoryURL, aSystemPathList, aUStr );
1604 sal_Bool bOk = compareFileName( aUStr, aUserDirectoryURL );
1605 CPPUNIT_ASSERT_MESSAGE( "test for searchFileURL function: search directory is a list of system paths",
1606 ( osl::FileBase::E_None == nError1 ) &&
1607 ( sal_True == bOk ) );
1610 void searchFileURL_005( )
1612 nError1 = ::osl::FileBase::searchFileURL( aUserDirectoryURL, aNullURL, aUStr );
1613 sal_Bool bOk = compareFileName( aUStr, aUserDirectoryURL );
1614 CPPUNIT_ASSERT_MESSAGE( "test for searchFileURL function: search directory is NULL",
1615 ( osl::FileBase::E_None == nError1 ) &&
1616 ( sal_True == bOk ) );
1619 CPPUNIT_TEST_SUITE( searchFileURL );
1620 CPPUNIT_TEST( searchFileURL_001 );
1621 CPPUNIT_TEST( searchFileURL_002 );
1622 CPPUNIT_TEST( searchFileURL_003 );
1623 CPPUNIT_TEST( searchFileURL_004 );
1624 CPPUNIT_TEST( searchFileURL_005 );
1625 CPPUNIT_TEST_SUITE_END( );
1626 };// class searchFileURL
1629 //---------------------------------------------------------------------
1630 // testing the method
1631 // static inline RC getTempDirURL( ::rtl::OUString& ustrTempDirURL )
1632 //---------------------------------------------------------------------
1633 class getTempDirURL:public CppUnit::TestFixture
1635 //::osl::FileBase aFileBase;
1636 ::rtl::OUString aUStr;
1637 ::osl::FileBase::RC nError;
1639 public:
1640 // initialization
1641 void setUp( )
1643 nError = FileBase::getTempDirURL( aUStr );
1646 void tearDown( )
1650 // test code.
1651 void getTempDirURL_001( )
1654 CPPUNIT_ASSERT_MESSAGE( "test for getTempDirURL function: excution",
1655 ( osl::FileBase::E_None == nError ) );
1658 void getTempDirURL_002( )
1660 CPPUNIT_ASSERT_MESSAGE( "test for getTempDirURL function: test for open and write access rights",
1661 checkDirectory( aUStr, osl_Check_Mode_OpenAccess ) &&
1662 checkDirectory( aUStr, osl_Check_Mode_ReadAccess ) &&
1663 checkDirectory( aUStr,osl_Check_Mode_WriteAccess ) );
1666 CPPUNIT_TEST_SUITE( getTempDirURL );
1667 CPPUNIT_TEST( getTempDirURL_001 );
1668 CPPUNIT_TEST( getTempDirURL_002 );
1669 CPPUNIT_TEST_SUITE_END( );
1670 };// class getTempDirURL
1673 //---------------------------------------------------------------------
1674 // testing the method
1675 // static inline RC createTempFile( ::rtl::OUString* pustrDirectoryURL,
1676 // oslFileHandle* pHandle,
1677 // ::rtl::OUString* pustrTempFileURL)
1678 //---------------------------------------------------------------------
1679 class createTempFile:public CppUnit::TestFixture
1681 //::osl::FileBase aFileBase;
1682 ::osl::FileBase::RC nError1, nError2;
1683 sal_Bool bOK;
1685 oslFileHandle *pHandle;
1686 ::rtl::OUString *pUStr_DirURL;
1687 ::rtl::OUString *pUStr_FileURL;
1689 public:
1691 // initialization
1692 void setUp( )
1694 pHandle = new oslFileHandle();
1695 pUStr_DirURL = new ::rtl::OUString( aUserDirectoryURL );
1696 pUStr_FileURL = new ::rtl::OUString();
1697 //*pUStr_DirURL = aUserDirectoryURL; /// create temp file in /tmp/PID or c:\temp\PID.*/
1700 void tearDown( )
1702 delete pUStr_DirURL;
1703 delete pUStr_FileURL;
1704 delete pHandle;
1707 // test code.
1708 void createTempFile_001( )
1710 nError1 = FileBase::createTempFile( pUStr_DirURL, pHandle, pUStr_FileURL );
1711 ::osl::File testFile( *pUStr_FileURL );
1712 //printFileName(*pUStr_FileURL);
1713 nError2 = testFile.open( OpenFlag_Create );
1714 if ( osl::FileBase::E_EXIST == nError2 ) {
1715 osl_closeFile( *pHandle );
1716 deleteTestFile( *pUStr_FileURL );
1719 CPPUNIT_ASSERT_MESSAGE( "test for createTempFile function: create temp file and test the existence",
1720 ( osl::FileBase::E_None == nError1 ) && ( pHandle != NULL ) && ( osl::FileBase::E_EXIST== nError2 ) );
1723 void createTempFile_002( )
1725 bOK = sal_False;
1726 nError1 = FileBase::createTempFile( pUStr_DirURL, pHandle, pUStr_FileURL );
1727 ::osl::File testFile( *pUStr_FileURL );
1728 nError2 = testFile.open( OpenFlag_Create );
1730 CPPUNIT_ASSERT_MESSAGE( "createTempFile function: create a temp file, but it does not exist",
1731 ( osl::FileBase::E_None == nError1 ) && ( pHandle != NULL ) &&
1732 ( osl::FileBase::E_EXIST == nError2 ) );
1734 //check file if have the write permission
1735 if ( osl::FileBase::E_EXIST == nError2 ) {
1736 bOK = ifFileCanWrite( *pUStr_FileURL );
1737 osl_closeFile( *pHandle );
1738 deleteTestFile( *pUStr_FileURL );
1741 CPPUNIT_ASSERT_MESSAGE( "test for open and write access rights, in (W32), it did not have write access right, but it should be writtenable.",
1742 ( sal_True == bOK ) );
1745 void createTempFile_003( )
1747 nError1 = FileBase::createTempFile( pUStr_DirURL, pHandle, 0 );
1748 //the temp file will be removed when return from createTempFile
1749 bOK = ( pHandle != NULL && pHandle != 0);
1750 if ( sal_True == bOK )
1751 osl_closeFile( *pHandle );
1753 CPPUNIT_ASSERT_MESSAGE( "test for createTempFile function: set pUStrFileURL to 0 to let it remove the file after call.",
1754 ( ::osl::FileBase::E_None == nError1 ) &&( sal_True == bOK ) );
1756 void createTempFile_004( )
1758 nError1 = FileBase::createTempFile( pUStr_DirURL, 0, pUStr_FileURL );
1759 bOK = ( pUStr_FileURL != 0);
1760 ::osl::File testFile( *pUStr_FileURL );
1761 nError2 = testFile.open( OpenFlag_Create );
1762 deleteTestFile( *pUStr_FileURL );
1763 CPPUNIT_ASSERT_MESSAGE( "createTempFile function: create a temp file, but it does not exist",
1764 ( osl::FileBase::E_None == nError1 ) && ( osl::FileBase::E_EXIST == nError2 ) &&( sal_True == bOK ) );
1768 CPPUNIT_TEST_SUITE( createTempFile );
1769 CPPUNIT_TEST( createTempFile_001 );
1770 CPPUNIT_TEST( createTempFile_002 );
1771 CPPUNIT_TEST( createTempFile_003 );
1772 CPPUNIT_TEST( createTempFile_004 );
1773 CPPUNIT_TEST_SUITE_END( );
1774 };// class createTempFile
1776 // -----------------------------------------------------------------------------
1777 #if 0 //~ this function has been deprecated.
1778 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileBase::getCanonicalName, "osl_FileBase" );
1779 #endif
1780 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileBase::getAbsoluteFileURL, "osl_FileBase" );
1781 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileBase::SystemPath_FileURL, "osl_FileBase" );
1782 // CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileBase::getFileURLFromSystemPath, "osl_FileBase" );
1783 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileBase::searchFileURL, "osl_FileBase" );
1784 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileBase::getTempDirURL, "osl_FileBase" );
1785 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileBase::createTempFile, "osl_FileBase" );
1786 }// namespace osl_FileBase
1789 //------------------------------------------------------------------------
1790 // Beginning of the test cases for VolumeDevice class
1791 //------------------------------------------------------------------------
1793 #if 0 //~ this Class has been deprecated
1794 namespace osl_VolumeDevice
1797 //---------------------------------------------------------------------
1798 // testing the method
1799 // VolumeDevice() : _aHandle( NULL )
1800 //---------------------------------------------------------------------
1801 class ctors : public CppUnit::TestFixture
1803 ::osl::VolumeDevice aVolumeDevice;
1804 ::rtl::OUString aUStr;
1805 ::osl::FileBase::RC nError1, nError2;
1807 public:
1808 // initialization
1809 void setUp( )
1813 void tearDown( )
1817 // test code.
1818 void ctors_001( )
1820 ::osl::VolumeDevice aVolumeDevice1;
1822 CPPUNIT_ASSERT_MESSAGE( "test for ctors function: Constructor for VolumeDevice with no args.",
1823 ( osl::FileBase::E_None != aVolumeDevice1.automount( ) ) &&
1824 ( osl::FileBase::E_None != aVolumeDevice1.unmount( ) ) &&
1825 ( aNullURL.equals( aVolumeDevice1.getMountPath( ) ) ) );
1828 void ctors_002( )
1830 ::osl::VolumeInfo aVolumeInfo( VolumeInfoMask_Attributes );
1831 nError1 = ::osl::Directory::getVolumeInfo( aRootURL, aVolumeInfo );
1832 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
1834 ::osl::VolumeDevice aVolumeDevice1( aVolumeInfo.getDeviceHandle( ) );
1835 sal_Bool bOk = compareFileName( aNullURL, aVolumeDevice1.getMountPath( ) );
1836 CPPUNIT_ASSERT_MESSAGE( "test for ctors function: Copy constructor for VolumeDevice, the copied VolumeDevice should have a mount path file:///, but it returned an empty OUString, it also may be the error from getDeviceHandle(), it did not pass in (UNX), (W32).",
1837 sal_False == bOk );
1840 void ctors_003( )
1842 ::osl::VolumeInfo aVolumeInfo( VolumeInfoMask_Attributes );
1843 nError1 = ::osl::Directory::getVolumeInfo( aRootURL, aVolumeInfo );
1844 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
1846 ::osl::VolumeDevice aVolumeDevice1 = aVolumeInfo.getDeviceHandle( );
1847 sal_Bool bOk = compareFileName( aNullURL, aVolumeDevice1.getMountPath( ) );
1848 CPPUNIT_ASSERT_MESSAGE( "test for ctors function: Assigned operator for VolumeDevice, the assigned VolumeDevice should have a mount path file:///, but it returned an empty OUString, it also may be the error from getDeviceHandle(),it did not pass in (UNX), (W32).",
1849 sal_False == bOk );
1852 CPPUNIT_TEST_SUITE( ctors );
1853 CPPUNIT_TEST( ctors_001 );
1854 CPPUNIT_TEST( ctors_002 );
1855 CPPUNIT_TEST( ctors_003 );
1856 CPPUNIT_TEST_SUITE_END( );
1857 };// class ctors
1860 //---------------------------------------------------------------------
1861 // testing the method
1862 // inline RC automount()
1863 //---------------------------------------------------------------------
1864 class automount : public CppUnit::TestFixture
1866 ::osl::VolumeDevice aVolumeDevice;
1867 ::rtl::OUString aUStr;
1868 ::osl::FileBase::RC nError1, nError2;
1870 public:
1871 // initialization
1872 void setUp( )
1876 void tearDown( )
1881 // test code.
1882 void automount_001( )
1884 ::osl::VolumeDevice aVolumeDevice1;
1885 nError1 = aVolumeDevice1.automount( );
1887 CPPUNIT_ASSERT_MESSAGE( "test for automount function: invalid parameter.",
1888 ( osl::FileBase::E_INVAL == nError1 ) );
1891 void automount_002( )
1893 ::osl::VolumeInfo aVolumeInfo( VolumeInfoMask_Attributes );
1894 nError1 = ::osl::Directory::getVolumeInfo( aVolURL2, aVolumeInfo );
1895 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
1897 ::osl::VolumeDevice aVolumeDevice1( aVolumeInfo.getDeviceHandle( ) );
1898 nError1 = aVolumeDevice1.unmount( );
1899 nError1 = aVolumeDevice1.automount( );
1900 CPPUNIT_ASSERT_MESSAGE( "test for automount function: this test is not implemented yet, it did not pass in (UNX), (W32).",
1901 ( osl::FileBase::E_None == nError1 ) );
1904 CPPUNIT_TEST_SUITE( automount );
1905 CPPUNIT_TEST( automount_001 );
1906 CPPUNIT_TEST( automount_002 );
1907 CPPUNIT_TEST_SUITE_END( );
1908 };// class automount
1911 // -----------------------------------------------------------------------------
1912 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeDevice::ctors, "osl_VolumeDevice" );
1913 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeDevice::automount, "osl_VolumeDevice" );
1914 }// namespace osl_VolumeDevice
1915 #endif
1918 //------------------------------------------------------------------------
1919 // Beginning of the test cases for VolumeInfo class
1920 //------------------------------------------------------------------------
1921 namespace osl_VolumeInfo
1924 //---------------------------------------------------------------------
1925 // testing the method
1926 // VolumeInfo( sal_uInt32 nMask ): _nMask( nMask )
1927 //---------------------------------------------------------------------
1928 class ctors : public CppUnit::TestFixture
1930 ::rtl::OUString aUStr;
1931 ::osl::FileBase::RC nError1, nError2;
1933 ::osl::VolumeDevice aVolumeDevice1;
1935 public:
1936 // initialization
1937 void setUp( )
1941 void tearDown( )
1945 // test code.
1946 void ctors_001( )
1948 ::osl::VolumeInfo aVolumeInfo( 0 );
1949 nError1 = ::osl::Directory::getVolumeInfo( aRootURL, aVolumeInfo );
1950 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
1951 sal_uInt64 uiTotalSpace = aVolumeInfo.getTotalSpace( );
1952 sal_uInt32 uiMaxPathLength = aVolumeInfo.getMaxPathLength( );
1953 aUStr = aVolumeInfo.getFileSystemName( );
1955 CPPUNIT_ASSERT_MESSAGE( "test for ctors function: mask is empty",
1956 ( 0 == uiTotalSpace ) &&
1957 ( 0 == uiMaxPathLength ) &&
1958 sal_True == compareFileName( aUStr, aNullURL ) );
1961 #if ( defined UNX ) || ( defined OS2 )
1962 void ctors_002( )
1964 ::osl::VolumeInfo aVolumeInfo( VolumeInfoMask_TotalSpace |
1965 VolumeInfoMask_UsedSpace |
1966 VolumeInfoMask_FileSystemName );
1967 nError1 = ::osl::Directory::getVolumeInfo( aVolURL4, aVolumeInfo );
1968 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
1969 //CPPUNIT_ASSERT( aVolumeInfo.isValid( mask ) );
1970 sal_uInt64 uiTotalSpace = aVolumeInfo.getTotalSpace( );
1971 sal_uInt64 uiUsedSpace = aVolumeInfo.getUsedSpace( );
1972 aUStr = aVolumeInfo.getFileSystemName( );
1974 CPPUNIT_ASSERT_MESSAGE( "test for ctors function: mask is specified as certain valid fields, and get the masked fields",
1975 ( 0 != uiTotalSpace ) &&
1976 ( 0 != uiUsedSpace ) &&
1977 sal_True == compareFileName( aUStr, "nfs" ) );
1979 #else /// Windows version,here we can not determine whichvolume in Windows is serve as an nfs volume.
1980 void ctors_002( )
1982 CPPUNIT_ASSERT_MESSAGE( "test for ctors function: mask is specified as certain valid fields, and get the masked fields( Windows version )",
1983 1 == 1 );
1985 #endif
1987 void ctors_003( )
1990 sal_Int32 mask1 = VolumeInfoMask_FreeSpace;
1991 ::osl::VolumeInfo aVolumeInfo1( mask1 );
1992 nError1 = ::osl::Directory::getVolumeInfo( aRootURL, aVolumeInfo1 );
1993 CPPUNIT_ASSERT( sal_True == aVolumeInfo1.isValid( mask1 ) );
1994 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
1996 sal_uInt64 uiTotalSpace1 = aVolumeInfo1.getTotalSpace( );
1997 aUStr = aVolumeInfo1.getFileSystemName( );
1999 sal_Int32 mask2 = VolumeInfoMask_TotalSpace;
2000 ::osl::VolumeInfo aVolumeInfo2( mask2 );
2001 nError2 = ::osl::Directory::getVolumeInfo( aRootURL, aVolumeInfo2 );
2002 CPPUNIT_ASSERT( sal_True == aVolumeInfo2.isValid( mask2 ) );
2003 CPPUNIT_ASSERT( osl::FileBase::E_None == nError2 );
2005 sal_uInt64 uiTotalSpace2 = aVolumeInfo2.getTotalSpace( );
2007 CPPUNIT_ASSERT_MESSAGE( "test for ctors function: mask is specified as certain valid fields, but get unmasked fields, use mask to FreeSpace, but I can get TotalSpace, did not pass in (UNX)(W32)",
2008 ( 0 == uiTotalSpace1 ) && ( 0 != uiTotalSpace2 ) &&
2009 sal_True == compareFileName( aUStr, aNullURL ) );
2012 CPPUNIT_TEST_SUITE( ctors );
2013 CPPUNIT_TEST( ctors_001 );
2014 CPPUNIT_TEST( ctors_002 );
2015 CPPUNIT_TEST( ctors_003 );
2016 CPPUNIT_TEST_SUITE_END( );
2017 };// class ctors
2020 //---------------------------------------------------------------------
2021 // testing the method
2022 // inline sal_Bool isValid( sal_uInt32 nMask ) const
2023 //---------------------------------------------------------------------
2024 class isValid : public CppUnit::TestFixture
2026 ::osl::VolumeDevice aVolumeDevice;
2027 ::rtl::OUString aUStr;
2028 ::osl::FileBase::RC nError1, nError2;
2030 public:
2031 // initialization
2032 void setUp( )
2036 void tearDown( )
2041 // test code.
2042 void isValid_001( )
2044 sal_Int32 mask = 0;
2045 ::osl::VolumeInfo aVolumeInfo( mask );
2046 nError1 = ::osl::Directory::getVolumeInfo( aVolURL4, aVolumeInfo );
2047 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2049 CPPUNIT_ASSERT_MESSAGE( "test for isValid function: no fields specified.",
2050 sal_True == aVolumeInfo.isValid( mask ) );
2053 #if ( defined UNX ) || ( defined OS2 )
2054 void isValid_002( )
2056 sal_Int32 mask = VolumeInfoMask_Attributes | VolumeInfoMask_TotalSpace | osl_VolumeInfo_Mask_UsedSpace |
2057 osl_VolumeInfo_Mask_FreeSpace | osl_VolumeInfo_Mask_MaxNameLength |
2058 osl_VolumeInfo_Mask_MaxPathLength | osl_VolumeInfo_Mask_FileSystemName;
2059 ::osl::VolumeInfo aVolumeInfo( mask );
2060 nError1 = ::osl::Directory::getVolumeInfo( aVolURL4, aVolumeInfo );
2061 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2063 CPPUNIT_ASSERT_MESSAGE( "test for isValid function: all valid fields specified for a nfs volume.",
2064 sal_True == aVolumeInfo.isValid( mask ) );
2066 #else /// Windows version,here we can not determine whichvolume in Windows is serve as an nfs volume.
2067 void isValid_002( )
2069 CPPUNIT_ASSERT_MESSAGE( "test for isValid function: all valid fields specified for a nfs volume.( Windows version )",
2070 1 == 1 );
2072 #endif
2074 void isValid_003( )
2076 ::osl::VolumeDevice aVolumeDevice1;
2077 sal_Int32 mask = VolumeInfoMask_Attributes;
2078 ::osl::VolumeInfo aVolumeInfo( mask );
2079 nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
2080 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2081 sal_Bool bOk1 = aVolumeInfo.isValid( mask );
2083 nError1 = ::osl::Directory::getVolumeInfo( aVolURL2, aVolumeInfo );
2084 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2085 sal_Bool bOk2 = aVolumeInfo.isValid( mask );
2087 CPPUNIT_ASSERT_MESSAGE( "test for isValid function: VolumeInfoMask_Attributes, it should be valid for some volume such as /, floppy, cdrom, etc. but it did not pass",
2088 ( sal_True == bOk1 ) && ( sal_True == bOk2 ) );
2091 CPPUNIT_TEST_SUITE( isValid );
2092 CPPUNIT_TEST( isValid_001 );
2093 CPPUNIT_TEST( isValid_002 );
2094 CPPUNIT_TEST( isValid_003 );
2095 CPPUNIT_TEST_SUITE_END( );
2096 };// class isValid
2098 //---------------------------------------------------------------------
2099 // testing the method
2100 // inline sal_Bool getRemoteFlag() const
2101 //---------------------------------------------------------------------
2102 class getRemoteFlag : public CppUnit::TestFixture
2104 ::osl::VolumeDevice aVolumeDevice;
2105 ::rtl::OUString aUStr;
2106 ::osl::FileBase::RC nError1, nError2;
2108 public:
2109 // test code.
2110 void getRemoteFlag_001( )
2112 sal_Int32 mask = VolumeInfoMask_Attributes;
2113 ::osl::VolumeInfo aVolumeInfo( mask );
2114 nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
2115 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2116 sal_Bool bOk = aVolumeInfo.getRemoteFlag( );
2118 CPPUNIT_ASSERT_MESSAGE( "test for getRemoteFlag function: get a volume device which is not remote.",
2119 ( sal_False == bOk ) );
2122 #if ( defined UNX ) || ( defined OS2 ) //remote Volume is different in Solaris and Windows
2123 void getRemoteFlag_002( )
2125 sal_Int32 mask = VolumeInfoMask_Attributes;
2126 ::osl::VolumeInfo aVolumeInfo( mask );
2127 nError1 = ::osl::Directory::getVolumeInfo( aVolURL4, aVolumeInfo );
2128 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2129 sal_Bool bOk = aVolumeInfo.getRemoteFlag( );
2131 CPPUNIT_ASSERT_MESSAGE( "test for getRemoteFlag function: get a volume device which is remote( Solaris version ).",
2132 ( sal_True == bOk ) );
2134 #else //Windows version
2135 void getRemoteFlag_002( )
2137 CPPUNIT_ASSERT_MESSAGE( "test for getRemoteFlag function: get a volume device which is remote( Windows version )",
2138 1 == 1 );
2140 #endif
2142 CPPUNIT_TEST_SUITE( getRemoteFlag );
2143 CPPUNIT_TEST( getRemoteFlag_001 );
2144 CPPUNIT_TEST( getRemoteFlag_002 );
2145 CPPUNIT_TEST_SUITE_END( );
2146 };// class getRemoteFlag
2148 //---------------------------------------------------------------------
2149 // testing the method
2150 // inline sal_Bool getRemoveableFlag() const
2151 //---------------------------------------------------------------------
2152 class getRemoveableFlag : public CppUnit::TestFixture
2154 ::osl::FileBase::RC nError1, nError2;
2156 public:
2157 // test code.
2158 void getRemoveableFlag_001( )
2160 sal_Int32 mask = VolumeInfoMask_Attributes;
2161 ::osl::VolumeInfo aVolumeInfo( mask );
2162 nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
2163 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2164 sal_Bool bOk = aVolumeInfo.getRemoveableFlag( );
2166 CPPUNIT_ASSERT_MESSAGE( "test for getRemoveableFlag function: get a volume device which is not removable.",
2167 sal_False == bOk );
2170 void getRemoveableFlag_002( )
2172 sal_Int32 mask = VolumeInfoMask_Attributes;
2173 ::osl::VolumeInfo aVolumeInfo( mask );
2174 nError1 = ::osl::Directory::getVolumeInfo( aVolURL2, aVolumeInfo );
2175 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2176 sal_Bool bOk = aVolumeInfo.getRemoveableFlag( );
2178 CPPUNIT_ASSERT_MESSAGE( "test for getRemoveableFlag function: get a volume device which is removable, not sure, here we use floppy disk, but it did not pass.",
2179 sal_True == bOk );
2181 CPPUNIT_TEST_SUITE( getRemoveableFlag );
2182 CPPUNIT_TEST( getRemoveableFlag_001 );
2183 CPPUNIT_TEST( getRemoveableFlag_002 );
2184 CPPUNIT_TEST_SUITE_END( );
2185 };// class getRemoveableFlag
2188 //---------------------------------------------------------------------
2189 // testing the method
2190 // inline sal_Bool getCompactDiscFlag() const
2191 //---------------------------------------------------------------------
2192 class getCompactDiscFlag : public CppUnit::TestFixture
2194 ::osl::FileBase::RC nError1;
2196 public:
2197 // test code.
2198 void getCompactDiscFlag_001( )
2200 sal_Int32 mask = VolumeInfoMask_Attributes;
2201 ::osl::VolumeInfo aVolumeInfo( mask );
2202 nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
2203 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2204 sal_Bool bOk = aVolumeInfo.getCompactDiscFlag( );
2206 CPPUNIT_ASSERT_MESSAGE( "test for getCompactDiscFlag function: get a volume device which is not a cdrom.",
2207 ( sal_False == bOk ) );
2210 void getCompactDiscFlag_002( )
2212 sal_Int32 mask = VolumeInfoMask_Attributes;
2213 ::osl::VolumeInfo aVolumeInfo( mask );
2214 nError1 = ::osl::Directory::getVolumeInfo( aVolURL6, aVolumeInfo );
2215 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2216 sal_Bool bOk = aVolumeInfo.getCompactDiscFlag( );
2218 CPPUNIT_ASSERT_MESSAGE( "test for getCompactDiscFlag function: get a cdrom volume device flag, it did not pass.",
2219 ( sal_True == bOk ) );
2221 CPPUNIT_TEST_SUITE( getCompactDiscFlag );
2222 CPPUNIT_TEST( getCompactDiscFlag_001 );
2223 CPPUNIT_TEST( getCompactDiscFlag_002 );
2224 CPPUNIT_TEST_SUITE_END( );
2225 };// class getCompactDiscFlag
2228 //---------------------------------------------------------------------
2229 // testing the method
2230 // inline sal_Bool getFloppyDiskFlag() const
2231 //---------------------------------------------------------------------
2232 class getFloppyDiskFlag : public CppUnit::TestFixture
2234 ::osl::FileBase::RC nError1;
2236 public:
2237 // test code.
2238 void getFloppyDiskFlag_001( )
2240 sal_Int32 mask = VolumeInfoMask_Attributes;
2241 ::osl::VolumeInfo aVolumeInfo( mask );
2242 nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
2243 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2244 sal_Bool bOk = aVolumeInfo.getFloppyDiskFlag( );
2246 CPPUNIT_ASSERT_MESSAGE( "test for getFloppyDiskFlag function: get a volume device which is not a floppy disk.",
2247 ( sal_False == bOk ) );
2250 void getFloppyDiskFlag_002( )
2252 sal_Int32 mask = VolumeInfoMask_Attributes;
2253 ::osl::VolumeInfo aVolumeInfo( mask );
2254 nError1 = ::osl::Directory::getVolumeInfo( aVolURL2, aVolumeInfo );
2255 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2256 sal_Bool bOk = aVolumeInfo.getFloppyDiskFlag( );
2258 CPPUNIT_ASSERT_MESSAGE( "test for getFloppyDiskFlag function: get a floppy volume device flag, it did not pass.",
2259 ( sal_True == bOk ) );
2261 CPPUNIT_TEST_SUITE( getFloppyDiskFlag );
2262 CPPUNIT_TEST( getFloppyDiskFlag_001 );
2263 CPPUNIT_TEST( getFloppyDiskFlag_002 );
2264 CPPUNIT_TEST_SUITE_END( );
2265 };// class getFloppyDiskFlag
2268 //---------------------------------------------------------------------
2269 // testing the method
2270 // inline sal_Bool getFixedDiskFlag() const
2271 //---------------------------------------------------------------------
2272 class getFixedDiskFlag : public CppUnit::TestFixture
2274 ::osl::FileBase::RC nError1;
2276 public:
2277 // test code.
2278 void getFixedDiskFlag_001( )
2280 sal_Int32 mask = VolumeInfoMask_Attributes;
2281 ::osl::VolumeInfo aVolumeInfo( mask );
2282 nError1 = ::osl::Directory::getVolumeInfo( aVolURL2, aVolumeInfo );
2283 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2284 sal_Bool bOk = aVolumeInfo.getFixedDiskFlag( );
2286 CPPUNIT_ASSERT_MESSAGE( "test for getFixedDiskFlag function: get a volume device which is not a fixed disk.",
2287 ( sal_False == bOk ) );
2290 void getFixedDiskFlag_002( )
2292 sal_Int32 mask = VolumeInfoMask_Attributes;
2293 ::osl::VolumeInfo aVolumeInfo( mask );
2294 nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
2295 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2296 sal_Bool bOk = aVolumeInfo.getFixedDiskFlag( );
2298 CPPUNIT_ASSERT_MESSAGE( "test for getFixedDiskFlag function: get a fixed disk volume device flag, it did not pass.",
2299 ( sal_True == bOk ) );
2301 CPPUNIT_TEST_SUITE( getFixedDiskFlag );
2302 CPPUNIT_TEST( getFixedDiskFlag_001 );
2303 CPPUNIT_TEST( getFixedDiskFlag_002 );
2304 CPPUNIT_TEST_SUITE_END( );
2305 };// class getFixedDiskFlag
2307 //---------------------------------------------------------------------
2308 // testing the method
2309 // inline sal_Bool getRAMDiskFlag() const
2310 //---------------------------------------------------------------------
2311 class getRAMDiskFlag : public CppUnit::TestFixture
2313 ::osl::FileBase::RC nError1;
2315 public:
2316 // test code.
2317 void getRAMDiskFlag_001( )
2319 sal_Int32 mask = VolumeInfoMask_Attributes;
2320 ::osl::VolumeInfo aVolumeInfo( mask );
2321 nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
2322 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2323 sal_Bool bOk = aVolumeInfo.getRAMDiskFlag( );
2325 CPPUNIT_ASSERT_MESSAGE( "test for getRAMDiskFlag function: get a volume device which is not a RAM disk.",
2326 ( sal_False == bOk ) );
2329 void getRAMDiskFlag_002( )
2331 sal_Int32 mask = VolumeInfoMask_Attributes;
2332 ::osl::VolumeInfo aVolumeInfo( mask );
2333 nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
2334 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2335 sal_Bool bOk = aVolumeInfo.getRAMDiskFlag( );
2337 CPPUNIT_ASSERT_MESSAGE( "test for getRAMDiskFlag function: FIX ME, don't know how to get a RAM disk flag, perhaps Windows 98 boot disk can create a RAM disk, it did not pass in (UNX)(W32).",
2338 ( sal_True == bOk ) );
2340 CPPUNIT_TEST_SUITE( getRAMDiskFlag );
2341 CPPUNIT_TEST( getRAMDiskFlag_001 );
2342 CPPUNIT_TEST( getRAMDiskFlag_002 );
2343 CPPUNIT_TEST_SUITE_END( );
2344 };// class getRAMDiskFlag
2347 //---------------------------------------------------------------------
2348 // testing the method
2349 // inline sal_uInt64 getTotalSpace() const
2350 //---------------------------------------------------------------------
2351 class getTotalSpace : public CppUnit::TestFixture
2353 ::osl::FileBase::RC nError1;
2355 public:
2356 // test code.
2357 void getTotalSpace_001( )
2359 sal_Int32 mask = VolumeInfoMask_TotalSpace;
2360 ::osl::VolumeInfo aVolumeInfo( mask );
2361 nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
2362 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2363 CPPUNIT_ASSERT( sal_True == aVolumeInfo.isValid( mask ) );
2364 sal_uInt64 uiTotalSpace = aVolumeInfo.getTotalSpace( );
2366 CPPUNIT_ASSERT_MESSAGE( "test for getTotalSpace function: get total space of Fixed disk volume mounted on /, it should not be 0",
2367 0 != uiTotalSpace );
2370 #if defined( UNX )
2371 void getTotalSpace_002( )
2373 sal_Int32 mask = VolumeInfoMask_TotalSpace;
2374 ::osl::VolumeInfo aVolumeInfo( mask );
2375 nError1 = ::osl::Directory::getVolumeInfo( aVolURL3, aVolumeInfo );
2376 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2377 CPPUNIT_ASSERT( sal_True == aVolumeInfo.isValid( mask ) );
2378 sal_uInt64 uiTotalSpace = aVolumeInfo.getTotalSpace( );
2380 CPPUNIT_ASSERT_MESSAGE( "test for getTotalSpace function: get total space of /proc, it should be 0",
2381 0 == uiTotalSpace );
2383 #else /// Windows version, in Windows, there is no /proc directory
2384 void getTotalSpace_002( )
2386 CPPUNIT_ASSERT_MESSAGE( "test for getTotalSpace function:not applicable for /proc( Windows version )",
2387 1 == 1 );
2389 #endif
2393 #if defined(SOLARIS)
2394 void getTotalSpace_003( )
2396 struct statvfs aStatFS;
2397 static const sal_Char name[] = "/";
2399 memset (&aStatFS, 0, sizeof(aStatFS));
2400 statvfs( name, &aStatFS);
2401 sal_uInt64 TotalSpace = aStatFS.f_frsize * aStatFS.f_blocks ;
2403 sal_Int32 mask = VolumeInfoMask_TotalSpace;
2404 ::osl::VolumeInfo aVolumeInfo( mask );
2405 nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
2406 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2407 CPPUNIT_ASSERT( sal_True == aVolumeInfo.isValid( mask ) );
2408 sal_uInt64 uiTotalSpace = aVolumeInfo.getTotalSpace( );
2410 CPPUNIT_ASSERT_MESSAGE( "test for getTotalSpace function: get total space by hand, then compare with getTotalSpace, it did not pass",
2411 uiTotalSpace == TotalSpace );
2413 #else /// Windows version
2414 void getTotalSpace_003( )
2416 CPPUNIT_ASSERT_MESSAGE( "test for getTotalSpace function:not implemented yet( Windows version )",
2417 1 == 1 );
2419 #endif
2421 CPPUNIT_TEST_SUITE( getTotalSpace );
2422 CPPUNIT_TEST( getTotalSpace_001 );
2423 CPPUNIT_TEST( getTotalSpace_002 );
2424 CPPUNIT_TEST( getTotalSpace_003 );
2425 CPPUNIT_TEST_SUITE_END( );
2426 };// class getTotalSpace
2428 //---------------------------------------------------------------------
2429 // testing the method
2430 // inline sal_uInt64 getFreeSpace() const
2431 //---------------------------------------------------------------------
2432 class getFreeSpace : public CppUnit::TestFixture
2434 ::osl::FileBase::RC nError1;
2436 public:
2437 // test code.
2438 void getFreeSpace_001( )
2440 sal_Int32 mask = VolumeInfoMask_FreeSpace;
2441 ::osl::VolumeInfo aVolumeInfo( mask );
2442 nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
2443 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2444 CPPUNIT_ASSERT( sal_True == aVolumeInfo.isValid( mask ) );
2445 sal_uInt64 uiFreeSpace = aVolumeInfo.getFreeSpace( );
2447 CPPUNIT_ASSERT_MESSAGE( "test for getFreeSpace function: get free space of Fixed disk volume mounted on /, it should not be 0, suggestion: returned value, -1 is better, since some times the free space may be 0",
2448 0 != uiFreeSpace );
2451 #if defined( UNX )
2452 void getFreeSpace_002( )
2454 sal_Int32 mask = VolumeInfoMask_FreeSpace;
2455 ::osl::VolumeInfo aVolumeInfo( mask );
2456 nError1 = ::osl::Directory::getVolumeInfo( aVolURL3, aVolumeInfo );
2457 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2458 CPPUNIT_ASSERT( sal_True == aVolumeInfo.isValid( mask ) );
2459 sal_uInt64 uiFreeSpace = aVolumeInfo.getFreeSpace( );
2461 CPPUNIT_ASSERT_MESSAGE( "test for getFreeSpace function: get free space of /proc, it should be 0",
2462 0 == uiFreeSpace );
2464 #else /// Windows version, in Windows, there is no /proc directory
2465 void getFreeSpace_002( )
2467 CPPUNIT_ASSERT_MESSAGE( "test for getFreeSpace function: not applicable for /proc( Windows version )",
2468 1 == 1 );
2470 #endif
2473 #if defined(SOLARIS)
2474 void getFreeSpace_003( )
2476 struct statvfs aStatFS;
2477 static const sal_Char name[] = "/";
2479 memset (&aStatFS, 0, sizeof(aStatFS));
2480 statvfs( name, &aStatFS);
2481 sal_uInt64 FreeSpace = aStatFS.f_bfree * aStatFS.f_frsize ;
2483 sal_Int32 mask = VolumeInfoMask_FreeSpace;
2484 ::osl::VolumeInfo aVolumeInfo( mask );
2485 nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
2486 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2487 CPPUNIT_ASSERT( sal_True == aVolumeInfo.isValid( mask ) );
2488 sal_uInt64 uiFreeSpace = aVolumeInfo.getFreeSpace( );
2490 CPPUNIT_ASSERT_MESSAGE( "test for getFreeSpace function: get free space by hand, then compare with getFreeSpace, it did not pass",
2491 uiFreeSpace == FreeSpace );
2493 #else //Windows version
2494 void getFreeSpace_003( )
2496 CPPUNIT_ASSERT_MESSAGE( "test for getFreeSpace function: not implemented yet( Windows version )",
2497 1 == 1 );
2499 #endif
2502 CPPUNIT_TEST_SUITE( getFreeSpace );
2503 CPPUNIT_TEST( getFreeSpace_001 );
2504 CPPUNIT_TEST( getFreeSpace_002 );
2505 CPPUNIT_TEST( getFreeSpace_003 );
2506 CPPUNIT_TEST_SUITE_END( );
2507 };// class getFreeSpace
2509 //---------------------------------------------------------------------
2510 // testing the method
2511 // inline sal_uInt64 getUsedSpace() const
2512 //---------------------------------------------------------------------
2513 class getUsedSpace : public CppUnit::TestFixture
2515 ::osl::FileBase::RC nError1;
2517 public:
2518 // test code.
2519 void getUsedSpace_001( )
2521 sal_Int32 mask = VolumeInfoMask_UsedSpace;
2522 ::osl::VolumeInfo aVolumeInfo( mask );
2523 nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
2524 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2525 CPPUNIT_ASSERT( sal_True == aVolumeInfo.isValid( mask ) );
2526 sal_uInt64 uiUsedSpace = aVolumeInfo.getUsedSpace( );
2528 CPPUNIT_ASSERT_MESSAGE( "test for getUsedSpace function: get used space of Fixed disk volume mounted on /, it should not be 0, suggestion: returned value, -1 is better, since some times the used space may be 0",
2529 0 != uiUsedSpace );
2532 #if defined( UNX )
2533 void getUsedSpace_002( )
2535 sal_Int32 mask = VolumeInfoMask_UsedSpace;
2536 ::osl::VolumeInfo aVolumeInfo( mask );
2537 nError1 = ::osl::Directory::getVolumeInfo( aVolURL3, aVolumeInfo );
2538 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2539 CPPUNIT_ASSERT( sal_True == aVolumeInfo.isValid( mask ) );
2540 sal_uInt64 uiUsedSpace = aVolumeInfo.getUsedSpace( );
2542 CPPUNIT_ASSERT_MESSAGE( "test for getUsedSpace function: get used space of /proc, it should be 0",
2543 0 == uiUsedSpace );
2545 #else /// Windows version, in Windows, there is no /proc directory
2546 void getUsedSpace_002( )
2548 CPPUNIT_ASSERT_MESSAGE( "test for getUsedSpace function: not applicable for /proc( Windows version )",
2549 1 == 1 );
2551 #endif
2554 #if defined(SOLARIS)
2555 void getUsedSpace_003( )
2557 struct statvfs aStatFS;
2558 static const sal_Char name[] = "/";
2560 memset (&aStatFS, 0, sizeof(aStatFS));
2561 statvfs( name, &aStatFS);
2562 sal_uInt64 UsedSpace = ( aStatFS.f_blocks - aStatFS.f_bavail ) * aStatFS.f_frsize;
2565 sal_Int32 mask = VolumeInfoMask_UsedSpace;
2566 ::osl::VolumeInfo aVolumeInfo( mask );
2567 nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
2568 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2569 CPPUNIT_ASSERT( sal_True == aVolumeInfo.isValid( mask ) );
2570 sal_uInt64 uiUsedSpace = aVolumeInfo.getUsedSpace( );
2572 CPPUNIT_ASSERT_MESSAGE( "test for getUsedSpace function: get used space by hand, then compare with getUsedSpace, it did not pass",
2573 uiUsedSpace == UsedSpace );
2575 #else //Windows version
2576 void getUsedSpace_003( )
2578 CPPUNIT_ASSERT_MESSAGE( "test for getUsedSpace function: not implemented yet( Windows version )",
2579 1 == 1 );
2581 #endif
2584 CPPUNIT_TEST_SUITE( getUsedSpace );
2585 CPPUNIT_TEST( getUsedSpace_001 );
2586 CPPUNIT_TEST( getUsedSpace_002 );
2587 CPPUNIT_TEST( getUsedSpace_003 );
2588 CPPUNIT_TEST_SUITE_END( );
2589 };// class getUsedSpace
2592 //---------------------------------------------------------------------
2593 // testing the method
2594 // inline sal_uInt32 getMaxNameLength() const
2595 //---------------------------------------------------------------------
2596 class getMaxNameLength : public CppUnit::TestFixture
2598 ::osl::FileBase::RC nError1;
2600 public:
2601 // test code.
2602 void getMaxNameLength_001( )
2604 sal_Int32 mask = VolumeInfoMask_MaxNameLength;
2605 ::osl::VolumeInfo aVolumeInfo( mask );
2606 nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
2607 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2608 CPPUNIT_ASSERT( sal_True == aVolumeInfo.isValid( mask ) );
2609 sal_uInt32 uiMaxNameLength = aVolumeInfo.getMaxNameLength( );
2611 CPPUNIT_ASSERT_MESSAGE( "test for getMaxNameLength function: get max name length of Fixed disk volume mounted on /, it should not be 0",
2612 0 != uiMaxNameLength );
2616 #if ( defined UNX ) || ( defined OS2 )
2617 void getMaxNameLength_002( )
2619 struct statvfs aStatFS;
2620 static const sal_Char name[] = "/";
2622 memset (&aStatFS, 0, sizeof(aStatFS));
2623 statvfs( name, &aStatFS);
2624 sal_uInt64 MaxNameLength = aStatFS.f_namemax;
2626 sal_Int32 mask = VolumeInfoMask_MaxNameLength;
2627 ::osl::VolumeInfo aVolumeInfo( mask );
2628 nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
2629 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2630 CPPUNIT_ASSERT( sal_True == aVolumeInfo.isValid( mask ) );
2631 sal_uInt64 uiMaxNameLength = aVolumeInfo.getMaxNameLength( );
2633 CPPUNIT_ASSERT_MESSAGE( "test for getMaxNameLength function: get max name length by hand, then compare with getMaxNameLength",
2634 uiMaxNameLength == MaxNameLength );
2636 #else //Windows version
2637 void getMaxNameLength_002( )
2639 CPPUNIT_ASSERT_MESSAGE( "test for getMaxNameLength function: not implemented yet( Windows version )",
2640 1 == 1 );
2642 #endif
2644 CPPUNIT_TEST_SUITE( getMaxNameLength );
2645 CPPUNIT_TEST( getMaxNameLength_001 );
2646 CPPUNIT_TEST( getMaxNameLength_002 );
2647 CPPUNIT_TEST_SUITE_END( );
2648 };// class getMaxNameLength
2651 //---------------------------------------------------------------------
2652 // testing the method
2653 // inline sal_uInt32 getMaxPathLength() const
2654 //---------------------------------------------------------------------
2655 class getMaxPathLength : public CppUnit::TestFixture
2657 ::osl::FileBase::RC nError1;
2659 public:
2660 // test code.
2661 void getMaxPathLength_001( )
2663 sal_Int32 mask = VolumeInfoMask_MaxPathLength;
2664 ::osl::VolumeInfo aVolumeInfo( mask );
2665 nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
2666 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2667 CPPUNIT_ASSERT( sal_True == aVolumeInfo.isValid( mask ) );
2668 sal_uInt32 uiMaxPathLength = aVolumeInfo.getMaxPathLength( );
2670 CPPUNIT_ASSERT_MESSAGE( "test for getMaxPathLength function: get max path length of Fixed disk volume mounted on /, it should not be 0",
2671 0 != uiMaxPathLength );
2675 #if ( defined UNX ) || ( defined OS2 )
2676 void getMaxPathLength_002( )
2678 sal_Int32 mask = VolumeInfoMask_MaxPathLength;
2679 ::osl::VolumeInfo aVolumeInfo( mask );
2680 nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
2681 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2682 CPPUNIT_ASSERT( sal_True == aVolumeInfo.isValid( mask ) );
2683 sal_uInt64 uiMaxPathLength = aVolumeInfo.getMaxPathLength( );
2685 CPPUNIT_ASSERT_MESSAGE( "test for getMaxPathLength function: get max path length by hand, then compare with getMaxPathLength",
2686 uiMaxPathLength == PATH_MAX );
2688 #else //Windows version
2689 void getMaxPathLength_002( )
2691 CPPUNIT_ASSERT_MESSAGE( "test for getMaxPathLength function: not implemented yet( Windows version )",
2692 1 == 1 );
2694 #endif
2697 CPPUNIT_TEST_SUITE( getMaxPathLength );
2698 CPPUNIT_TEST( getMaxPathLength_001 );
2699 CPPUNIT_TEST( getMaxPathLength_002 );
2700 CPPUNIT_TEST_SUITE_END( );
2701 };// class getMaxPathLength
2704 //---------------------------------------------------------------------
2705 // testing the method
2706 // inline ::rtl::OUString getFileSystemName() const
2707 //---------------------------------------------------------------------
2708 class getFileSystemName : public CppUnit::TestFixture
2710 ::rtl::OUString aUStr;
2711 ::osl::FileBase::RC nError1;
2713 public:
2714 // test code.
2715 void getFileSystemName_001( )
2717 sal_Int32 mask = VolumeInfoMask_FileSystemName;
2718 ::osl::VolumeInfo aVolumeInfo( mask );
2719 nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
2720 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2721 CPPUNIT_ASSERT( sal_True == aVolumeInfo.isValid( mask ) );
2722 aUStr = aVolumeInfo.getFileSystemName( );
2724 CPPUNIT_ASSERT_MESSAGE( "test for getFileSystemName function: get file system name of Fixed disk volume mounted on /, it should not be empty string",
2725 sal_False == compareFileName( aNullURL, aUStr ) );
2729 #if defined(SOLARIS)
2730 void getFileSystemName_002( )
2732 struct statvfs aStatFS;
2733 static const sal_Char name[] = "/";
2735 memset (&aStatFS, 0, sizeof(aStatFS));
2736 statvfs( name, &aStatFS);
2737 sal_Char * astrFileSystemName = aStatFS.f_basetype;
2739 sal_Int32 mask = VolumeInfoMask_FileSystemName;
2740 ::osl::VolumeInfo aVolumeInfo( mask );
2741 nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
2742 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2743 CPPUNIT_ASSERT( sal_True == aVolumeInfo.isValid( mask ) );
2744 aUStr = aVolumeInfo.getFileSystemName( );
2746 CPPUNIT_ASSERT_MESSAGE( "test for getFileSystemName function: get file system name by hand, then compare with getFileSystemName",
2747 sal_True == compareFileName( aUStr, astrFileSystemName ) );
2749 #else //Windows version
2750 void getFileSystemName_002( )
2752 CPPUNIT_ASSERT_MESSAGE( "test for getFileSystemName function: not implemented yet( Windows version )",
2753 1 == 1 );
2755 #endif
2758 CPPUNIT_TEST_SUITE( getFileSystemName );
2759 CPPUNIT_TEST( getFileSystemName_001 );
2760 CPPUNIT_TEST( getFileSystemName_002 );
2761 CPPUNIT_TEST_SUITE_END( );
2762 };// class getFileSystemName
2764 //---------------------------------------------------------------------
2765 // testing the method
2766 // inline VolumeDevice getDeviceHandle() const
2767 //---------------------------------------------------------------------
2768 class getDeviceHandle : public CppUnit::TestFixture
2770 ::rtl::OUString aUStr;
2771 ::osl::FileBase::RC nError1;
2773 public:
2774 // test code.
2775 void getDeviceHandle_001( )
2777 ::osl::VolumeInfo aVolumeInfo( VolumeInfoMask_Attributes );
2778 nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
2779 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2781 ::osl::VolumeDevice aVolumeDevice1( aVolumeInfo.getDeviceHandle( ) );
2782 sal_Bool bOk = compareFileName( aNullURL, aVolumeDevice1.getMountPath( ) );
2784 CPPUNIT_ASSERT_MESSAGE( "test for getDeviceHandle function: get device handle of Fixed disk volume mounted on /, it should not be NULL, it did not pass in (W32) (UNX).",
2785 ( sal_False == bOk ) );
2788 CPPUNIT_TEST_SUITE( getDeviceHandle );
2789 CPPUNIT_TEST( getDeviceHandle_001 );
2790 CPPUNIT_TEST_SUITE_END( );
2791 };// class getDeviceHandle
2794 // -----------------------------------------------------------------------------
2795 /*CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeInfo::ctors, "osl_VolumeInfo" );
2796 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeInfo::isValid, "osl_VolumeInfo" );
2797 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeInfo::getRemoteFlag, "osl_VolumeInfo" );
2798 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeInfo::getRemoveableFlag, "osl_VolumeInfo" );
2799 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeInfo::getCompactDiscFlag, "osl_VolumeInfo" );
2800 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeInfo::getFloppyDiskFlag, "osl_VolumeInfo" );
2801 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeInfo::getFixedDiskFlag, "osl_VolumeInfo" );
2802 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeInfo::getRAMDiskFlag, "osl_VolumeInfo" );
2803 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeInfo::getTotalSpace, "osl_VolumeInfo" );
2804 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeInfo::getFreeSpace, "osl_VolumeInfo" );
2805 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeInfo::getUsedSpace, "osl_VolumeInfo" );
2806 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeInfo::getMaxNameLength, "osl_VolumeInfo" );
2807 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeInfo::getMaxPathLength, "osl_VolumeInfo" );
2808 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeInfo::getFileSystemName, "osl_VolumeInfo" );
2809 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeInfo::getDeviceHandle, "osl_VolumeInfo" );*/
2810 }// namespace osl_VolumeInfo
2814 //------------------------------------------------------------------------
2815 // Beginning of the test cases for VolumeDevice class
2816 //------------------------------------------------------------------------
2817 namespace osl_FileStatus
2820 //---------------------------------------------------------------------
2821 // testing the method
2822 // FileStatus( sal_uInt32 nMask ): _nMask( nMask )
2823 //---------------------------------------------------------------------
2824 class ctors : public CppUnit::TestFixture
2826 ::rtl::OUString aUStr;
2827 ::osl::FileBase::RC nError1, nError2;
2828 ::osl::DirectoryItem rItem;
2830 public:
2831 // initialization
2832 void setUp( )
2834 // create a tempfile in $TEMP/tmpdir/tmpname.
2835 createTestDirectory( aTmpName3 );
2836 createTestFile( aTmpName4 );
2838 ::std::auto_ptr<Directory> pDir( new Directory( aTmpName3 ) );
2839 nError1 = pDir->open( );
2840 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
2841 nError1 = pDir->getNextItem( rItem, 0 );
2842 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
2843 pDir->close();
2845 Directory aDir( aTmpName3 );
2846 nError1 = aDir.open();
2847 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
2848 nError1 = aDir.getNextItem( rItem, 0 );
2849 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
2850 aDir.close();
2854 void tearDown( )
2856 // remove the tempfile in $TEMP/tmpdir/tmpname.
2857 deleteTestFile( aTmpName4 );
2858 deleteTestDirectory( aTmpName3 );
2861 // test code.
2862 void ctors_001( )
2864 ::osl::FileStatus rFileStatus( FileStatusMask_All );
2865 nError1 = rItem.getFileStatus( rFileStatus );
2866 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
2867 aUStr = rFileStatus.getFileName( );
2869 CPPUNIT_ASSERT_MESSAGE( "test for ctors function: mask all and see the file name",
2870 sal_True == compareFileName( aUStr, aTmpName2) );
2873 void ctors_002( )
2875 ::osl::FileStatus rFileStatus( 0 );
2876 nError1 = rItem.getFileStatus( rFileStatus );
2877 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
2878 aUStr = rFileStatus.getFileName( );
2880 CPPUNIT_ASSERT_MESSAGE( "test for ctors function: mask is empty",
2881 sal_True == compareFileName( aUStr, aNullURL) );
2884 CPPUNIT_TEST_SUITE( ctors );
2885 CPPUNIT_TEST( ctors_001 );
2886 CPPUNIT_TEST( ctors_002 );
2887 CPPUNIT_TEST_SUITE_END( );
2888 };// class ctors
2891 //---------------------------------------------------------------------
2892 // testing the method
2893 // inline sal_Bool isValid( sal_uInt32 nMask ) const
2894 //---------------------------------------------------------------------
2895 class isValid : public CppUnit::TestFixture
2897 ::rtl::OUString aUStr;
2898 ::osl::Directory *pDir;
2899 ::osl::DirectoryItem rItem_file, rItem_link;
2901 public:
2902 // initialization
2903 void setUp( )
2905 // create a tempfile in $TEMP/tmpdir/tmpname.
2906 createTestDirectory( aTmpName3 );
2907 createTestFile( aTmpName4 );
2909 pDir = new Directory( aTmpName3 );
2910 //::std::auto_ptr<Directory> pDir( new Directory( aTmpName3 ) );
2911 ::osl::FileBase::RC nError1 = pDir->open( );
2912 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
2913 nError1 = pDir->getNextItem( rItem_file, 1 );
2914 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
2917 void tearDown( )
2919 ::osl::FileBase::RC nError1 = pDir->close( );
2920 delete pDir;
2921 CPPUNIT_ASSERT_MESSAGE( errorToStr(nError1), ::osl::FileBase::E_None == nError1 );
2923 // remove the tempfile in $TEMP/tmpdir/tmpname.
2924 deleteTestFile( aTmpName4 );
2925 deleteTestDirectory( aTmpName3 );
2928 // test code.
2929 void isValid_001( )
2931 sal_uInt32 mask = 0;
2932 ::osl::FileStatus rFileStatus( mask );
2933 ::osl::FileBase::RC nError1 = rItem_file.getFileStatus( rFileStatus );
2934 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
2935 sal_Bool bOk = rFileStatus.isValid( mask );
2937 CPPUNIT_ASSERT_MESSAGE( "test for isValid function: no fields specified",
2938 ( sal_True == bOk ) );
2941 void check_FileStatus(::osl::FileStatus const& _aStatus)
2943 rtl::OString sStat;
2944 if (_aStatus.isValid(FileStatusMask_Type))
2946 sStat += "type ";
2948 if (_aStatus.isValid(FileStatusMask_Attributes))
2950 sStat += "attributes ";
2952 if (_aStatus.isValid(FileStatusMask_CreationTime))
2954 sStat += "ctime ";
2956 if (_aStatus.isValid(FileStatusMask_AccessTime))
2958 sStat += "atime ";
2960 if (_aStatus.isValid(FileStatusMask_ModifyTime))
2962 sStat += "mtime ";
2964 if (_aStatus.isValid(FileStatusMask_FileSize))
2966 sStat += "filesize ";
2968 if (_aStatus.isValid(FileStatusMask_FileName))
2970 sStat += "filename ";
2972 if (_aStatus.isValid(FileStatusMask_FileURL))
2974 sStat += "fileurl ";
2976 t_print("mask: %s\n", sStat.getStr());
2979 void isValid_002( )
2981 createTestFile( aTmpName6 );
2982 sal_uInt32 mask_file = ( FileStatusMask_Type | FileStatusMask_Attributes |
2983 FileStatusMask_CreationTime | FileStatusMask_AccessTime |
2984 FileStatusMask_ModifyTime | FileStatusMask_FileSize |
2985 FileStatusMask_FileName | FileStatusMask_FileURL) ;
2986 ::osl::FileStatus rFileStatus( mask_file );
2987 ::osl::FileBase::RC nError1 = ::osl::DirectoryItem::get( aTmpName6, rItem_file );
2988 nError1 = rItem_file.getFileStatus( rFileStatus );
2990 CPPUNIT_ASSERT_MESSAGE( errorToStr(nError1), ::osl::FileBase::E_None == nError1 );
2992 // LLA: this is wrong, we never should try to check on all masks
2993 // only on one.
2994 // Second, it's not a bug, if a value is not valid, it's an unhandled feature.
2996 // sal_Bool bOk = rFileStatus.isValid( mask_file );
2998 check_FileStatus(rFileStatus);
2999 deleteTestFile( aTmpName6 );
3001 // CPPUNIT_ASSERT_MESSAGE( "test for isValid function: regular file mask fields test, #FileStatusMask_CreationTime# should be valid field for regular file, but feedback is invalid",
3002 // ( sal_True == bOk ) );
3005 //Link is not defined in Windows, and on Linux, we can not get the directory item of the link file
3006 // LLA: we have to differ to filesystems, normal filesystems support links (EXT2, ...)
3007 // castrated filesystems don't (FAT, FAT32)
3008 // Windows NT NTFS support links, but the windows api don't :-(
3010 void isValid_003( )
3012 #if defined ( UNX )
3013 // ::osl::FileBase::RC nError;
3014 sal_Int32 fd;
3016 ::rtl::OUString aUStr_LnkFileSys( aTempDirectorySys ), aUStr_SrcFileSys( aTempDirectorySys );
3017 ( ( aUStr_LnkFileSys += aSlashURL ) += getCurrentPID( ) ) += ::rtl::OUString::createFromAscii("/tmpdir/link.file");
3018 ( ( aUStr_SrcFileSys += aSlashURL ) += getCurrentPID( ) ) += ::rtl::OUString::createFromAscii("/tmpdir/tmpname");
3020 rtl::OString strLinkFileName;
3021 rtl::OString strSrcFileName;
3022 strLinkFileName = OUStringToOString( aUStr_LnkFileSys, RTL_TEXTENCODING_ASCII_US );
3023 strSrcFileName = OUStringToOString( aUStr_SrcFileSys, RTL_TEXTENCODING_ASCII_US );
3025 //create a link file and link it to file "/tmp/PID/tmpdir/tmpname"
3026 fd = symlink( strSrcFileName.getStr(), strLinkFileName.getStr() );
3027 CPPUNIT_ASSERT( fd == 0 );
3029 // testDirectory is "/tmp/PID/tmpdir/"
3030 ::osl::Directory testDirectory( aTmpName3 );
3031 ::osl::FileBase::RC nError1 = testDirectory.open( );
3032 ::rtl::OUString aFileName = ::rtl::OUString::createFromAscii("link.file");
3033 sal_Bool bOk = sal_False;
3034 while (1) {
3035 nError1 = testDirectory.getNextItem( rItem_link, 4 );
3036 if (::osl::FileBase::E_None == nError1) {
3037 sal_uInt32 mask_link = FileStatusMask_FileName | FileStatusMask_LinkTargetURL;
3038 ::osl::FileStatus rFileStatus( mask_link );
3039 rItem_link.getFileStatus( rFileStatus );
3040 //printFileName( rFileStatus.getFileName( ) );
3041 if ( compareFileName( rFileStatus.getFileName( ), aFileName) == sal_True )
3043 //t_print("find the link file");
3044 if ( sal_True == rFileStatus.isValid( FileStatusMask_LinkTargetURL ) )
3046 bOk = sal_True;
3047 break;
3051 else
3052 break;
3055 fd = remove( strLinkFileName );
3056 CPPUNIT_ASSERT( fd == 0 );
3058 CPPUNIT_ASSERT_MESSAGE("test for isValid function: link file, check for LinkTargetURL",
3059 ( sal_True == bOk ) );
3060 #endif
3063 void isValid_004( )
3065 sal_uInt32 mask_file_all = FileStatusMask_All;
3066 ::osl::FileStatus rFileStatus_all( mask_file_all );
3067 ::osl::FileBase::RC nError1 = rItem_file.getFileStatus( rFileStatus_all );
3068 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
3070 check_FileStatus(rFileStatus_all);
3071 // LLA: this is wrong
3072 // sal_Bool bOk1 = rFileStatus_all.isValid( mask_file_all );
3074 sal_uInt32 mask_file_val = FileStatusMask_Validate;
3075 ::osl::FileStatus rFileStatus_val( mask_file_val );
3076 nError1 = rItem_file.getFileStatus( rFileStatus_val );
3077 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
3078 // sal_Bool bOk2 = rFileStatus_val.isValid( mask_file_val );
3080 check_FileStatus(rFileStatus_val);
3081 // CPPUNIT_ASSERT_MESSAGE( "test for isValid function: check for Mask_All and Validate, really not sure what validate used for and how to use it, help me. did not pass (W32)(UNX).",
3082 // ( sal_False == bOk1 ) && ( sal_True == bOk2 ) );
3086 CPPUNIT_TEST_SUITE( isValid );
3087 CPPUNIT_TEST( isValid_001 );
3088 CPPUNIT_TEST( isValid_002 );
3089 CPPUNIT_TEST( isValid_003 );
3090 CPPUNIT_TEST( isValid_004 );
3091 CPPUNIT_TEST_SUITE_END( );
3092 };// class ctors
3095 //---------------------------------------------------------------------
3096 // testing the method
3097 // inline Type getFileType() const
3098 //---------------------------------------------------------------------
3099 class getFileType : public CppUnit::TestFixture
3101 ::rtl::OUString aUStr;
3102 ::osl::FileBase::RC nError1, nError2;
3104 ::osl::DirectoryItem m_aItem_1, m_aItem_2, m_aVolumeItem, m_aFifoItem;
3105 ::osl::DirectoryItem m_aLinkItem, m_aSocketItem, m_aSpecialItem;
3107 public:
3108 // initialization
3109 void setUp( )
3111 // create a tempfile: $TEMP/tmpdir/tmpname.
3112 // a tempdirectory: $TEMP/tmpdir/tmpdir.
3113 // use $ROOT/staroffice as volume ---> use dev/fd as volume.
3114 // and get their directory item.
3115 createTestDirectory( aTmpName3 );
3116 //printFileName( aTmpName2);
3117 createTestFile( aTmpName3, aTmpName2 );
3118 createTestDirectory( aTmpName3, aTmpName1 );
3120 ::std::auto_ptr<Directory> pDir( new Directory( aTmpName3 ) );
3121 nError1 = pDir->open( );
3122 CPPUNIT_ASSERT_MESSAGE("open aTmpName3 failed!", ::osl::FileBase::E_None == nError1 );
3123 //getNextItem can not assure which item retrieved
3124 nError1 = pDir->getNextItem( m_aItem_1, 1 );
3125 CPPUNIT_ASSERT_MESSAGE("get first item failed!", ::osl::FileBase::E_None == nError1 );
3127 nError1 = pDir->getNextItem( m_aItem_2 );
3128 CPPUNIT_ASSERT_MESSAGE("get second item failed!", ::osl::FileBase::E_None == nError1 );
3129 pDir->close();
3130 //mindy: failed on my RH9,so removed temporaly
3131 //nError1 = ::osl::DirectoryItem::get( aVolURL2, m_aVolumeItem );
3132 //CPPUNIT_ASSERT_MESSAGE("get volume item failed!", ::osl::FileBase::E_None == nError1 );
3136 void tearDown( )
3138 // remove all in $TEMP/tmpdir.
3139 deleteTestDirectory( aTmpName3, aTmpName1 );
3140 deleteTestFile( aTmpName3, aTmpName2 );
3141 deleteTestDirectory( aTmpName3 );
3144 // test code.
3145 void getFileType_001( )
3147 ::osl::FileStatus rFileStatus( FileStatusMask_Type | FileStatusMask_FileName );
3148 nError1 = m_aItem_1.getFileStatus( rFileStatus );
3149 CPPUNIT_ASSERT_MESSAGE("getFileStatus failed", ::osl::FileBase::E_None == nError1 );
3151 check_FileType(rFileStatus);
3154 void check_FileType(osl::FileStatus const& _rFileStatus )
3156 sal_Bool bOK = sal_False;
3157 if ( _rFileStatus.isValid(FileStatusMask_FileName))
3159 rtl::OUString suFilename = _rFileStatus.getFileName();
3161 if ( _rFileStatus.isValid(FileStatusMask_Type))
3163 osl::FileStatus::Type eType = _rFileStatus.getFileType( );
3165 if ( compareFileName( suFilename, aTmpName2) == sal_True )
3167 // regular
3168 bOK = ( eType == osl::FileStatus::Regular );
3170 if ( compareFileName( suFilename, aTmpName1) == sal_True )
3172 // directory
3173 bOK = ( eType == ::osl::FileStatus::Directory );
3176 CPPUNIT_ASSERT_MESSAGE( "test for getFileType function: ",
3177 ( bOK == sal_True ) );
3180 // LLA: it's not a bug, if a FileStatus not exist, so no else
3183 void getFileType_002( )
3185 ::osl::FileStatus rFileStatus( FileStatusMask_Type | FileStatusMask_FileName );
3186 nError1 = m_aItem_2.getFileStatus( rFileStatus );
3188 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
3189 check_FileType(rFileStatus);
3192 void getFileType_003( )
3194 #if 0
3195 // LLA: this have to be discussed.
3196 ::osl::FileStatus rFileStatus( FileStatusMask_Type );
3197 nError1 = m_aVolumeItem.getFileStatus( rFileStatus );
3198 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
3200 if (rFileStatus.isValid(FileStatusMask_Type))
3202 osl::FileStatus::Type eType = rFileStatus.getFileType( );
3204 CPPUNIT_ASSERT_MESSAGE( "test for getFileType function: Volume, it seems the volume part of the field is not implemented, it did not pass in (W32)(UNX).",
3205 ( eType == ::osl::FileStatus::Volume ) );
3207 #endif
3211 void getFileType_004( )
3213 #if ( defined UNX ) || ( defined OS2 ) //Fifo creation is differ in Windows
3215 //create a fifo in $ROOT/tmp/tmpdir, get its DirectoryItem.
3216 rtl::OString strFifoSys;
3217 strFifoSys = OUStringToOString( aFifoSys, RTL_TEXTENCODING_ASCII_US );
3218 ::rtl::OUString aFifoURL;
3220 int fd = mkfifo( strFifoSys.getStr(), O_RDWR | O_CREAT );
3221 CPPUNIT_ASSERT_MESSAGE("mkfifo failed!", fd == 0 );
3222 ::osl::FileBase::getFileURLFromSystemPath( aFifoSys, aFifoURL );
3224 nError1 = ::osl::DirectoryItem::get( aFifoURL, m_aFifoItem );
3225 CPPUNIT_ASSERT_MESSAGE("get item failed!", ::osl::FileBase::E_None == nError1 );
3227 //check for File type
3228 ::osl::FileStatus rFileStatus( FileStatusMask_Type );
3229 nError1 = m_aFifoItem.getFileStatus( rFileStatus );
3230 CPPUNIT_ASSERT_MESSAGE("get Status failed!", ::osl::FileBase::E_None == nError1 );
3232 //delete fifo
3233 nError1 = ::osl::File::remove( aFifoURL );
3234 CPPUNIT_ASSERT_MESSAGE("remove file failed!", ::osl::FileBase::E_None == nError1 );
3236 if (rFileStatus.isValid(FileStatusMask_Type))
3238 osl::FileStatus::Type eType = rFileStatus.getFileType( );
3240 CPPUNIT_ASSERT_MESSAGE( "test for getFileType function: Fifo, Solaris version ",
3241 ( eType == ::osl::FileStatus::Fifo ) );
3243 #endif
3247 * LLA: removed, m_aSocketItem is wrong initialised.
3250 // LLA: void getFileType_005( )
3251 // LLA: {
3252 // LLA: #if defined ( SOLARIS ) //Socket file may differ in Windows
3253 // LLA: // nError1 = ::osl::DirectoryItem::get( aTypeURL1, m_aSocketItem );
3254 // LLA: nError1 = ::osl::DirectoryItem::get( rtl::OUString::createFromAscii("/dev/null"), m_aSocketItem );
3255 // LLA: printError(nError1);
3256 // LLA: CPPUNIT_ASSERT_MESSAGE("get Socket type file failed", ::osl::FileBase::E_None == nError1 );
3257 // LLA:
3258 // LLA: //check for File type
3259 // LLA: ::osl::FileStatus rFileStatus( FileStatusMask_Type );
3260 // LLA:
3261 // LLA: nError1 = m_aSocketItem.getFileStatus( rFileStatus );
3262 // LLA: CPPUNIT_ASSERT_MESSAGE("getFileStatus failed", ::osl::FileBase::E_None == nError1 );
3263 // LLA:
3264 // LLA: if (rFileStatus.isValid( FileStatusMask_Type ))
3265 // LLA: {
3266 // LLA: osl::FileStatus::Type eType = rFileStatus.getFileType( );
3267 // LLA: printFileType(eType);
3268 // LLA: CPPUNIT_ASSERT_MESSAGE( "test for getFileType function: Socket, Solaris version ",
3269 // LLA: ( eType == ::osl::FileStatus::Socket ) );
3270 // LLA: }
3271 // LLA: #endif
3272 // LLA: }
3275 // deprecated since there is a same case Directory::getNextItem_004
3276 /*#if defined 0 //( UNX ) //( SOLARIS ) //Link file is not defined in Windows
3277 void getFileType_006( )
3279 nError1 = ::osl::DirectoryItem::get( aTypeURL3, m_aLinkItem );
3280 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
3282 //check for File type
3283 ::osl::FileStatus rFileStatus( FileStatusMask_Type );
3284 nError1 = m_aLinkItem.getFileStatus( rFileStatus );
3285 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
3287 CPPUNIT_ASSERT_MESSAGE( "test for getFileType function: Link, UNX version ",
3288 ( ::osl::FileStatus::Link == rFileStatus.getFileType( ) ) );
3290 #endif */
3292 void getFileType_007( )
3294 #if defined ( SOLARIS ) //Special file is differ in Windows
3295 nError1 = ::osl::DirectoryItem::get( aTypeURL2, m_aSpecialItem );
3296 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
3298 //check for File type
3299 ::osl::FileStatus rFileStatus( FileStatusMask_Type );
3300 nError1 = m_aSpecialItem.getFileStatus( rFileStatus );
3301 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
3303 if (rFileStatus.isValid(FileStatusMask_Type))
3305 osl::FileStatus::Type eType = rFileStatus.getFileType( );
3308 CPPUNIT_ASSERT_MESSAGE( "test for getFileType function: Special, Solaris version ",
3309 ( eType == ::osl::FileStatus::Special ) );
3311 #endif
3314 CPPUNIT_TEST_SUITE( getFileType );
3315 CPPUNIT_TEST( getFileType_001 );
3316 CPPUNIT_TEST( getFileType_002 );
3317 CPPUNIT_TEST( getFileType_003 );
3318 CPPUNIT_TEST( getFileType_004 );
3319 // LLA: CPPUNIT_TEST( getFileType_005 );
3320 //CPPUNIT_TEST( getFileType_006 );
3321 CPPUNIT_TEST( getFileType_007 );
3322 CPPUNIT_TEST_SUITE_END( );
3323 };// class getFileType
3325 //---------------------------------------------------------------------
3326 // testing the method
3327 // inline sal_uInt64 getAttributes() const
3328 //---------------------------------------------------------------------
3329 class getAttributes : public CppUnit::TestFixture
3331 ::rtl::OUString aTypeURL, aTypeURL_Hid;
3332 ::osl::FileBase::RC nError;
3333 ::osl::DirectoryItem rItem, rItem_hidden;
3335 public:
3336 // initialization
3337 void setUp( )
3339 aTypeURL = aUserDirectoryURL.copy( 0 );
3340 concatURL( aTypeURL, aTmpName2 );
3341 createTestFile( aTypeURL );
3342 nError = ::osl::DirectoryItem::get( aTypeURL, rItem );
3343 CPPUNIT_ASSERT( nError == FileBase::E_None );
3345 aTypeURL_Hid = aUserDirectoryURL.copy( 0 );
3346 concatURL( aTypeURL_Hid, aHidURL1 );
3347 createTestFile( aTypeURL_Hid );
3348 nError = ::osl::DirectoryItem::get( aTypeURL_Hid, rItem_hidden );
3349 CPPUNIT_ASSERT( nError == FileBase::E_None );
3352 void tearDown( )
3354 deleteTestFile( aTypeURL );
3355 deleteTestFile( aTypeURL_Hid );
3358 // test code.
3359 #if ( defined UNX ) || ( defined OS2 )
3360 //windows only 3 file attributes: normal, readonly, hidden
3361 void getAttributes_001( )
3363 changeFileMode( aTypeURL, S_IRUSR | S_IRGRP | S_IROTH );
3365 ::osl::FileStatus rFileStatus( FileStatusMask_Attributes );
3366 nError = rItem.getFileStatus( rFileStatus );
3367 CPPUNIT_ASSERT( nError == FileBase::E_None );
3369 CPPUNIT_ASSERT_MESSAGE( "test for getAttributes function: ReadOnly, GrpRead, OwnRead, OthRead( UNX version ) ",
3370 ( Attribute_ReadOnly | Attribute_GrpRead | Attribute_OwnRead | Attribute_OthRead ) ==
3371 rFileStatus.getAttributes( ) );
3373 #else //Windows version
3374 void getAttributes_001( )
3376 CPPUNIT_ASSERT_MESSAGE( "test for getAttributes function: ReadOnly, GrpRead, OwnRead, OthRead( Windows version )",
3377 1 == 1 );
3379 #endif
3382 void getAttributes_002( )
3384 #if ( defined UNX ) || ( defined OS2 )
3385 changeFileMode( aTypeURL, S_IXUSR | S_IXGRP | S_IXOTH );
3387 ::osl::FileStatus rFileStatus( FileStatusMask_Attributes );
3388 nError = rItem.getFileStatus( rFileStatus );
3389 CPPUNIT_ASSERT( nError == FileBase::E_None );
3391 CPPUNIT_ASSERT_MESSAGE( "test for getAttributes function: Executable, GrpExe, OwnExe, OthExe, the result is Readonly, Executable, GrpExe, OwnExe, OthExe, it partly not pass( Solaris version )",
3392 ( Attribute_ReadOnly | Attribute_Executable | Attribute_GrpExe | Attribute_OwnExe | Attribute_OthExe ) ==
3393 rFileStatus.getAttributes( ) );
3394 #endif
3398 #if ( defined UNX ) || ( defined OS2 )
3399 void getAttributes_003( )
3401 changeFileMode( aTypeURL, S_IWUSR | S_IWGRP | S_IWOTH );
3403 ::osl::FileStatus rFileStatus( FileStatusMask_Attributes );
3404 nError = rItem.getFileStatus( rFileStatus );
3405 CPPUNIT_ASSERT( nError == FileBase::E_None );
3407 CPPUNIT_ASSERT_MESSAGE( "test for getAttributes function: GrpWrite, OwnWrite, OthWrite( Solaris version )",
3408 ( Attribute_GrpWrite | Attribute_OwnWrite | Attribute_OthWrite ) ==
3409 rFileStatus.getAttributes( ) );
3411 #else //Windows version
3412 void getAttributes_003( )
3414 CPPUNIT_ASSERT_MESSAGE( "test for getAttributes function: GrpWrite, OwnWrite, OthWrite( Windows version )",
3415 1 == 1 );
3417 #endif
3419 #if ( defined UNX ) || ( defined OS2 ) //hidden file definition may different in Windows
3420 void getAttributes_004( )
3422 sal_Int32 test_Attributes = Attribute_Hidden;
3423 ::osl::FileStatus rFileStatus( FileStatusMask_Attributes );
3424 nError = rItem_hidden.getFileStatus( rFileStatus );
3425 CPPUNIT_ASSERT( nError == FileBase::E_None );
3426 test_Attributes &= rFileStatus.getAttributes( );
3428 CPPUNIT_ASSERT_MESSAGE( "test for getAttributes function: Hidden files( Solaris version )",
3429 test_Attributes == Attribute_Hidden );
3431 #else //Windows version
3432 void getAttributes_004( )
3434 ::rtl::OUString aUserHiddenFileURL = ::rtl::OUString::createFromAscii("file:///c:/AUTOEXEC.BAT");
3435 nError = ::osl::DirectoryItem::get( aUserHiddenFileURL, rItem_hidden );
3436 //printFileName( aUserHiddenFileURL );
3437 CPPUNIT_ASSERT_MESSAGE("get item fail", nError == FileBase::E_None );
3438 ::osl::FileStatus rFileStatus( FileStatusMask_Attributes );
3439 nError = rItem_hidden.getFileStatus( rFileStatus );
3440 CPPUNIT_ASSERT( nError == FileBase::E_None );
3442 CPPUNIT_ASSERT_MESSAGE( "Hidden files(Windows version), please check if hidden file c:/AUTOEXEC.BAT exists ",
3443 (rFileStatus.getAttributes( ) & Attribute_Hidden)!= 0 );
3445 #endif
3447 CPPUNIT_TEST_SUITE( getAttributes );
3448 CPPUNIT_TEST( getAttributes_001 );
3449 CPPUNIT_TEST( getAttributes_002 );
3450 CPPUNIT_TEST( getAttributes_003 );
3451 CPPUNIT_TEST( getAttributes_004 );
3452 CPPUNIT_TEST_SUITE_END( );
3453 };// class getAttributes
3455 //---------------------------------------------------------------------
3456 // testing the method
3457 // inline TimeValue getAccessTime() const
3458 //---------------------------------------------------------------------
3459 class getAccessTime : public CppUnit::TestFixture
3461 ::rtl::OUString aTypeURL;
3462 ::osl::FileBase::RC nError;
3463 ::osl::DirectoryItem rItem;
3465 public:
3466 // initialization
3467 void setUp( )
3469 aTypeURL = aUserDirectoryURL.copy( 0 );
3470 concatURL( aTypeURL, aTmpName2 );
3471 createTestFile( aTypeURL );
3472 nError = ::osl::DirectoryItem::get( aTypeURL, rItem );
3473 CPPUNIT_ASSERT( nError == FileBase::E_None );
3477 void tearDown( )
3479 deleteTestFile( aTypeURL );
3482 // test code.
3483 void getAccessTime_001( )
3485 TimeValue *pTV_current = NULL;
3486 CPPUNIT_ASSERT( ( pTV_current = ( TimeValue* )malloc( sizeof( TimeValue ) ) ) != NULL );
3487 TimeValue *pTV_access = NULL;
3488 CPPUNIT_ASSERT( ( pTV_access = ( TimeValue* )malloc( sizeof( TimeValue ) ) ) != NULL );
3490 ::osl::FileStatus rFileStatus( FileStatusMask_AccessTime );
3491 nError = rItem.getFileStatus( rFileStatus );
3492 sal_Bool bOk = osl_getSystemTime( pTV_current );
3493 CPPUNIT_ASSERT( sal_True == bOk && nError == FileBase::E_None );
3495 *pTV_access = rFileStatus.getAccessTime( );
3497 sal_Bool bOK = t_compareTime( pTV_access, pTV_current, delta );
3498 free( pTV_current );
3499 free( pTV_access );
3501 CPPUNIT_ASSERT_MESSAGE( "test for getAccessTime function: This test turns out that UNX pricision is no more than 1 sec, don't know how to test this function, in Windows test, it lost hour min sec, only have date time. ",
3502 sal_True == bOK );
3505 CPPUNIT_TEST_SUITE( getAccessTime );
3506 CPPUNIT_TEST( getAccessTime_001 );
3507 CPPUNIT_TEST_SUITE_END( );
3508 };// class getAccessTime
3510 //---------------------------------------------------------------------
3511 // testing the method
3512 // inline TimeValue getModifyTime() const
3513 //---------------------------------------------------------------------
3514 class getModifyTime : public CppUnit::TestFixture
3516 ::rtl::OUString aTypeURL;
3517 ::osl::FileBase::RC nError;
3518 ::osl::DirectoryItem rItem;
3520 public:
3522 // test code.
3523 void getModifyTime_001( )
3525 TimeValue *pTV_current = NULL;
3526 CPPUNIT_ASSERT( ( pTV_current = ( TimeValue* )malloc( sizeof( TimeValue ) ) ) != NULL );
3528 //create file
3529 aTypeURL = aUserDirectoryURL.copy( 0 );
3530 concatURL( aTypeURL, aTmpName2 );
3531 createTestFile( aTypeURL );
3533 //get current time
3534 sal_Bool bOk = osl_getSystemTime( pTV_current );
3535 CPPUNIT_ASSERT( sal_True == bOk );
3537 //get instance item and filestatus
3538 nError = ::osl::DirectoryItem::get( aTypeURL, rItem );
3539 CPPUNIT_ASSERT( nError == FileBase::E_None );
3540 ::osl::FileStatus rFileStatus( FileStatusMask_ModifyTime );
3541 nError = rItem.getFileStatus( rFileStatus );
3542 CPPUNIT_ASSERT( nError == FileBase::E_None );
3544 //get modify time
3545 TimeValue *pTV_modify = NULL;
3546 CPPUNIT_ASSERT( ( pTV_modify = ( TimeValue* )malloc( sizeof( TimeValue ) ) ) != NULL );
3547 *pTV_modify = rFileStatus.getModifyTime( );
3549 sal_Bool bOK = t_compareTime( pTV_modify, pTV_current, delta );
3550 //delete file
3551 deleteTestFile( aTypeURL );
3552 free( pTV_current );
3554 CPPUNIT_ASSERT_MESSAGE( "test for getModifyTime function: This test turns out that UNX pricision is no more than 1 sec, don't know how to improve this function. ",
3555 sal_True == bOK );
3558 CPPUNIT_TEST_SUITE( getModifyTime );
3559 CPPUNIT_TEST( getModifyTime_001 );
3560 CPPUNIT_TEST_SUITE_END( );
3561 };// class getModifyTime
3564 //---------------------------------------------------------------------
3565 // testing the method
3566 // inline sal_uInt64 getFileSize() const
3567 //---------------------------------------------------------------------
3568 class getFileSize : public CppUnit::TestFixture
3570 ::rtl::OUString aTypeURL;
3571 ::osl::FileBase::RC nError;
3572 ::osl::DirectoryItem rItem;
3574 public:
3575 // initialization
3576 void setUp( )
3578 aTypeURL = aUserDirectoryURL.copy( 0 );
3579 concatURL( aTypeURL, aTmpName2 );
3580 createTestFile( aTypeURL );
3581 nError = ::osl::DirectoryItem::get( aTypeURL, rItem );
3582 CPPUNIT_ASSERT( nError == FileBase::E_None );
3585 void tearDown( )
3587 deleteTestFile( aTypeURL );
3590 // test code.
3591 void getFileSize_001( )
3593 ::osl::FileStatus rFileStatus( FileStatusMask_FileSize );
3594 nError = rItem.getFileStatus( rFileStatus );
3595 CPPUNIT_ASSERT( nError == FileBase::E_None );
3597 sal_uInt64 uFileSize = rFileStatus.getFileSize( );
3599 CPPUNIT_ASSERT_MESSAGE( "test for getFileSize function: empty file ",
3600 0 == uFileSize );
3603 void getFileSize_002( )
3605 ::osl::File testfile( aTypeURL );
3606 nError = testfile.open( OpenFlag_Write | OpenFlag_Read );
3607 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError );
3608 nError = testfile.setSize( TEST_FILE_SIZE );
3609 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError );
3611 nError = ::osl::DirectoryItem::get( aTypeURL, rItem );
3612 CPPUNIT_ASSERT( nError == FileBase::E_None );
3613 ::osl::FileStatus rFileStatus( FileStatusMask_FileSize );
3614 nError = rItem.getFileStatus( rFileStatus );
3615 CPPUNIT_ASSERT( nError == FileBase::E_None );
3616 sal_uInt64 uFileSize = rFileStatus.getFileSize( );
3618 CPPUNIT_ASSERT_MESSAGE( "test for getFileSize function: file with size of TEST_FILE_SIZE, did not pass in (W32). ",
3619 TEST_FILE_SIZE == uFileSize );
3621 CPPUNIT_TEST_SUITE( getFileSize );
3622 CPPUNIT_TEST( getFileSize_001 );
3623 CPPUNIT_TEST( getFileSize_002 );
3624 CPPUNIT_TEST_SUITE_END( );
3625 };// class getFileSize
3627 //---------------------------------------------------------------------
3628 // testing the method
3629 // inline ::rtl::OUString getFileName() const
3630 //---------------------------------------------------------------------
3631 class getFileName : public CppUnit::TestFixture
3633 ::rtl::OUString aTypeURL;
3634 ::osl::FileBase::RC nError;
3635 ::osl::DirectoryItem rItem;
3637 public:
3638 // initialization
3639 void setUp( )
3641 aTypeURL = aUserDirectoryURL.copy( 0 );
3642 concatURL( aTypeURL, aTmpName2 );
3643 createTestFile( aTypeURL );
3644 nError = ::osl::DirectoryItem::get( aTypeURL, rItem );
3645 CPPUNIT_ASSERT( nError == FileBase::E_None );
3648 void tearDown( )
3650 deleteTestFile( aTypeURL );
3653 // test code.
3654 void getFileName_001( )
3656 ::osl::FileStatus rFileStatus( FileStatusMask_FileName );
3657 nError = rItem.getFileStatus( rFileStatus );
3658 CPPUNIT_ASSERT( nError == FileBase::E_None );
3660 ::rtl::OUString aFileName = rFileStatus.getFileName( );
3662 CPPUNIT_ASSERT_MESSAGE( "test for getFileName function: name compare with specify",
3663 sal_True == compareFileName( aFileName, aTmpName2 ) );
3666 CPPUNIT_TEST_SUITE( getFileName );
3667 CPPUNIT_TEST( getFileName_001 );
3668 CPPUNIT_TEST_SUITE_END( );
3669 };// class getFileName
3671 //---------------------------------------------------------------------
3672 // testing the method
3673 // inline ::rtl::OUString getFileURL() const
3674 //---------------------------------------------------------------------
3675 class getFileURL : public CppUnit::TestFixture
3677 ::rtl::OUString aTypeURL;
3678 ::osl::FileBase::RC nError;
3679 ::osl::DirectoryItem rItem;
3681 public:
3682 // initialization
3683 void setUp( )
3685 createTestFile( aTmpName6 );
3686 nError = ::osl::DirectoryItem::get( aTmpName6, rItem );
3687 CPPUNIT_ASSERT( nError == FileBase::E_None );
3690 void tearDown( )
3692 deleteTestFile( aTmpName6 );
3695 // test code.
3696 void getFileURL_001( )
3698 ::osl::FileStatus rFileStatus( FileStatusMask_FileURL );
3699 nError = rItem.getFileStatus( rFileStatus );
3700 CPPUNIT_ASSERT( nError == FileBase::E_None );
3702 ::rtl::OUString aFileURL = rFileStatus.getFileURL( );
3704 CPPUNIT_ASSERT_MESSAGE( "test for getFileURL function: ",
3705 sal_True == compareFileName( aFileURL, aTmpName6 ) );
3708 CPPUNIT_TEST_SUITE( getFileURL );
3709 CPPUNIT_TEST( getFileURL_001 );
3710 CPPUNIT_TEST_SUITE_END( );
3711 };// class getFileURL
3713 //---------------------------------------------------------------------
3714 // testing the method
3715 // inline ::rtl::OUString getLinkTargetURL() const
3716 //---------------------------------------------------------------------
3717 class getLinkTargetURL : public CppUnit::TestFixture
3719 ::rtl::OUString aTypeURL;
3720 ::osl::FileBase::RC nError;
3721 ::osl::DirectoryItem rItem;
3723 public:
3724 // test code.
3725 // initialization
3726 void setUp( )
3728 aTypeURL = aUserDirectoryURL.copy( 0 );
3729 concatURL( aTypeURL, aTmpName2 );
3730 createTestFile( aTypeURL );
3733 void tearDown( )
3735 deleteTestFile( aTypeURL );
3738 #if ( defined UNX ) || ( defined OS2 ) //Link file is not define in Windows
3739 void getLinkTargetURL_001( )
3741 //create a link file;
3742 ::rtl::OUString aUStr_LnkFileSys( aTempDirectorySys ), aUStr_SrcFileSys( aTempDirectorySys );
3743 ( ( aUStr_LnkFileSys += aSlashURL ) += getCurrentPID( ) ) += ::rtl::OUString::createFromAscii("/link.file");
3744 ( ( aUStr_SrcFileSys += aSlashURL ) += getCurrentPID( ) ) += ::rtl::OUString::createFromAscii("/tmpname");
3746 rtl::OString strLinkFileName, strSrcFileName;
3747 strLinkFileName = OUStringToOString( aUStr_LnkFileSys, RTL_TEXTENCODING_ASCII_US );
3748 strSrcFileName = OUStringToOString( aUStr_SrcFileSys, RTL_TEXTENCODING_ASCII_US );
3750 sal_Int32 fd;
3751 fd = symlink( strSrcFileName.getStr(), strLinkFileName.getStr() );
3752 CPPUNIT_ASSERT_MESSAGE( "in creating link file", fd == 0 );
3754 //get linkTarget URL
3755 nError = ::osl::DirectoryItem::get( aLnkURL1, rItem );
3756 CPPUNIT_ASSERT_MESSAGE( "in getting link file item", nError == FileBase::E_None );
3758 ::osl::FileStatus rFileStatus( FileStatusMask_LinkTargetURL );
3759 nError = rItem.getFileStatus( rFileStatus );
3760 CPPUNIT_ASSERT_MESSAGE( "in getting link file status", nError == FileBase::E_None );
3761 ::rtl::OUString aFileURL = rFileStatus.getLinkTargetURL( );
3763 //remove link file
3764 fd = remove( strLinkFileName.getStr() );
3765 CPPUNIT_ASSERT_MESSAGE( "in deleting link file", fd == 0 );
3767 CPPUNIT_ASSERT_MESSAGE( "test for getLinkTargetURL function: Solaris version, creat a file, and a link file link to it, get its LinkTargetURL and compare",
3768 sal_True == compareFileName( aFileURL, aTypeURL ) );
3770 #else
3771 void getLinkTargetURL_001( )
3773 CPPUNIT_ASSERT_MESSAGE( "test for getLinkTargetURL function: Windows version, not tested",
3774 1 );
3776 #endif
3778 CPPUNIT_TEST_SUITE( getLinkTargetURL );
3779 CPPUNIT_TEST( getLinkTargetURL_001 );
3780 CPPUNIT_TEST_SUITE_END( );
3781 };// class getLinkTargetURL
3783 // -----------------------------------------------------------------------------
3784 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileStatus::ctors, "osl_FileStatus" );
3785 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileStatus::isValid, "osl_FileStatus" );
3786 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileStatus::getFileType, "osl_FileStatus" );
3787 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileStatus::getAttributes, "osl_FileStatus" );
3788 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileStatus::getAccessTime, "osl_FileStatus" );
3789 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileStatus::getModifyTime, "osl_FileStatus" );
3790 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileStatus::getFileSize, "osl_FileStatus" );
3791 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileStatus::getFileName, "osl_FileStatus" );
3792 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileStatus::getFileURL, "osl_FileStatus" );
3793 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileStatus::getLinkTargetURL, "osl_FileStatus" );
3794 }// namespace osl_FileStatus
3798 //------------------------------------------------------------------------
3799 // Beginning of the test cases for File class
3800 //------------------------------------------------------------------------
3801 namespace osl_File
3803 //---------------------------------------------------------------------
3804 // testing the method
3805 // File( const ::rtl::OUString& ustrFileURL )
3806 //---------------------------------------------------------------------
3807 class ctors : public CppUnit::TestFixture
3809 // ::osl::FileBase::RC nError1;
3811 public:
3812 // initialization
3813 void setUp( )
3815 // create a tempfile in $TEMP/tmpdir/tmpname.
3816 createTestDirectory( aTmpName3 );
3817 createTestFile( aTmpName4 );
3820 void tearDown( )
3822 // remove the tempfile in $TEMP/tmpdir/tmpname.
3823 deleteTestFile( aTmpName4 );
3824 deleteTestDirectory( aTmpName3 );
3827 // test code.
3828 void ctors_001( )
3830 ::osl::File testFile( aTmpName4 );
3832 ::osl::FileBase::RC nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write );
3833 ::osl::FileBase::RC nError2 = testFile.close( );
3834 CPPUNIT_ASSERT_MESSAGE( "test for ctors function: initialize a File and test its open and close",
3835 ( ::osl::FileBase::E_None == nError1 ) && ( ::osl::FileBase::E_None == nError2 ) );
3838 void ctors_002( )
3840 ::osl::File testFile( aTmpName5 );
3841 sal_Char buffer[30] = "Test for File constructor";
3842 sal_uInt64 nCount;
3844 ::osl::FileBase::RC nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write );
3845 ::osl::FileBase::RC nError2 = testFile.write( buffer, 30, nCount );
3846 testFile.close( );
3848 CPPUNIT_ASSERT_MESSAGE( "test for ctors function: test relative file URL, this test show that relative file URL is also acceptable",
3849 ( ::osl::FileBase::E_None == nError1 ) && ( ::osl::FileBase::E_None == nError2 ) );
3852 CPPUNIT_TEST_SUITE( ctors );
3853 CPPUNIT_TEST( ctors_001 );
3854 CPPUNIT_TEST( ctors_002 );
3855 CPPUNIT_TEST_SUITE_END( );
3856 };// class ctors
3858 //---------------------------------------------------------------------
3859 // testing the method
3860 // inline RC open( sal_uInt32 uFlags )
3861 //---------------------------------------------------------------------
3862 class open : public CppUnit::TestFixture
3864 ::osl::FileBase::RC nError1, nError2, nError3;
3866 public:
3867 // initialization
3868 void setUp( )
3870 // create a tempfile in $TEMP/tmpdir/tmpname.
3871 createTestDirectory( aTmpName3 );
3872 createTestFile( aTmpName4 );
3875 void tearDown( )
3877 // remove the tempfile in $TEMP/tmpdir/tmpname.
3878 deleteTestFile( aTmpName4 );
3879 deleteTestDirectory( aTmpName3 );
3882 // test code.
3883 void open_001( )
3885 ::osl::File testFile( aTmpName4 );
3887 nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write );
3888 nError2 = testFile.close( );
3889 CPPUNIT_ASSERT_MESSAGE("close error", ::osl::FileBase::E_None == nError2 );
3891 CPPUNIT_ASSERT_MESSAGE( "test for open function: open a regular file",
3892 ::osl::FileBase::E_None == nError1 );
3895 void open_002( )
3897 ::osl::File testFile( aTmpName3 );
3899 nError1 = testFile.open( OpenFlag_Read );
3901 CPPUNIT_ASSERT_MESSAGE( "test for open function: open a directory",
3902 ( File::E_INVAL == nError1 ) || ( File::E_ACCES == nError1 ) );
3905 void open_003( )
3907 ::osl::File testFile( aCanURL1 );
3909 nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write );
3911 CPPUNIT_ASSERT_MESSAGE( "test for open function: open a non-exist file",
3912 File::E_NOENT == nError1 );
3915 void open_004( )
3917 ::rtl::OUString aTestFile( aRootURL );
3918 concatURL( aTestFile, aTmpName2 );
3919 ::osl::File testFile( aTestFile );
3921 nError1 = testFile.open( OpenFlag_Create );
3922 sal_Bool bOK = ( File::E_ACCES == nError1 );
3923 #if defined (WNT )
3924 bOK = sal_True; /// in Windows, you can create file in c:/ any way.
3925 testFile.close( );
3926 deleteTestFile( aTestFile);
3927 #endif
3929 CPPUNIT_ASSERT_MESSAGE( "test for open function: create an illegal file",
3930 bOK == sal_True );
3933 void open_005( )
3935 ::osl::File testFile( aTmpName4 );
3937 nError1 = testFile.open( OpenFlag_Create );
3939 CPPUNIT_ASSERT_MESSAGE( "test for open function: create an exist file",
3940 File::E_EXIST == nError1 );
3943 void open_006( )
3945 ::osl::File testFile( aCanURL1 );
3946 sal_Char buffer_write[30] = "Test for File open";
3947 sal_Char buffer_read[30];
3948 sal_uInt64 nCount_write, nCount_read;
3950 nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write | OpenFlag_Create );
3951 nError2 = testFile.write( buffer_write, 30, nCount_write );
3952 ::osl::FileBase::RC nError4 = testFile.setPos( Pos_Absolut, 0 );
3953 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError4 );
3954 nError3 = testFile.read( buffer_read, 10, nCount_read );
3956 ::osl::FileBase::RC nError5 = testFile.close( );
3957 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError5 );
3958 ::osl::FileBase::RC nError6 = testFile.remove( aCanURL1 );
3959 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError6 );
3961 CPPUNIT_ASSERT_MESSAGE( "test for open function: test for OpenFlag_Read,OpenFlag_Write and OpenFlag_Create",
3962 ( ::osl::FileBase::E_None == nError1 ) &&
3963 ( ::osl::FileBase::E_None == nError2 ) &&
3964 ( ::osl::FileBase::E_None == nError3 ) &&
3965 ( 30 == nCount_write ) &&
3966 ( 10 == nCount_read ) );
3969 CPPUNIT_TEST_SUITE( open );
3970 CPPUNIT_TEST( open_001 );
3971 CPPUNIT_TEST( open_002 );
3972 CPPUNIT_TEST( open_003 );
3973 CPPUNIT_TEST( open_004 );
3974 CPPUNIT_TEST( open_005 );
3975 CPPUNIT_TEST( open_006 );
3976 CPPUNIT_TEST_SUITE_END( );
3977 };// class open
3979 //---------------------------------------------------------------------
3980 // testing the method
3981 // inline RC close()
3982 //---------------------------------------------------------------------
3983 class close : public CppUnit::TestFixture
3985 ::osl::FileBase::RC nError1, nError2, nError3;
3987 public:
3988 // initialization
3989 void setUp( )
3991 // create a tempfile in $TEMP/tmpdir/tmpname.
3992 createTestDirectory( aTmpName3 );
3993 createTestFile( aTmpName4 );
3996 void tearDown( )
3998 // remove the tempfile in $TEMP/tmpdir/tmpname.
3999 deleteTestFile( aTmpName4 );
4000 deleteTestDirectory( aTmpName3 );
4003 // test code.
4004 void close_001( )
4006 ::osl::File testFile( aTmpName4 );
4008 nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write );
4009 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4011 nError2 = testFile.close( );
4013 CPPUNIT_ASSERT_MESSAGE( "test for close function: close a regular file",
4014 ::osl::FileBase::E_None == nError2 );
4017 void close_002( )
4019 ::osl::File testFile( aTmpName4 );
4021 nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write );
4022 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4024 nError2 = testFile.close( );
4026 nError3 = testFile.setPos( Pos_Absolut, 0 );
4028 CPPUNIT_ASSERT_MESSAGE( "test for close function: manipulate a file after it has been closed",
4029 ( ::osl::FileBase::E_None == nError2 ) &&
4030 ( ::osl::FileBase::E_None != nError3 ) );
4033 CPPUNIT_TEST_SUITE( close );
4034 CPPUNIT_TEST( close_001 );
4035 CPPUNIT_TEST( close_002 );
4036 CPPUNIT_TEST_SUITE_END( );
4037 };// class close
4040 //---------------------------------------------------------------------
4041 // testing the method
4042 // inline RC setPos( sal_uInt32 uHow, sal_Int64 uPos )
4043 //---------------------------------------------------------------------
4044 class setPos : public CppUnit::TestFixture
4046 ::osl::FileBase::RC nError1;
4047 sal_uInt64 nCount_write, nCount_read;
4049 public:
4050 // initialization
4051 void setUp( )
4053 // create a tempfile in $TEMP/tmpdir/tmpname.
4054 createTestDirectory( aTmpName3 );
4055 createTestFile( aTmpName4 );
4057 //write chars into the file.
4058 ::osl::File testFile( aTmpName4 );
4060 nError1 = testFile.open( OpenFlag_Write );
4061 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4062 nError1 = testFile.write( pBuffer_Char, sizeof( pBuffer_Char ), nCount_write );
4063 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4064 nError1 = testFile.close( );
4065 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4068 void tearDown( )
4070 // remove the tempfile in $TEMP/tmpdir/tmpname.
4071 deleteTestFile( aTmpName4 );
4072 deleteTestDirectory( aTmpName3 );
4075 // test code.
4076 void setPos_001( )
4078 ::osl::File testFile( aTmpName4 );
4079 sal_Char buffer_read[2];
4081 nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write );
4082 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4083 nError1 = testFile.setPos( Pos_Absolut, 26 );
4084 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4085 nError1 = testFile.read( buffer_read, 1, nCount_read );
4086 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4087 nError1 = testFile.close( );
4088 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4090 CPPUNIT_ASSERT_MESSAGE( "test for setPos function: test for Pos_Absolut, set the position to 26, test if the 26th char in file is correct",
4091 buffer_read[0] == pBuffer_Char[26] );
4094 void setPos_002( )
4096 ::osl::File testFile( aTmpName4 );
4097 sal_Char buffer_read[2];
4099 nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write );
4100 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4101 nError1 = testFile.setPos( Pos_Absolut, sizeof( pBuffer_Char ) - 2 );
4102 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4103 nError1 = testFile.setPos( Pos_Current, 0);
4104 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4105 nError1 = testFile.read( buffer_read, 1, nCount_read );
4106 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4107 nError1 = testFile.close( );
4108 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4110 CPPUNIT_ASSERT_MESSAGE( "test for setPos function: test for Pos_Current, set the position to end, test if the ( end -1 ) char in file is correct",
4111 buffer_read[0] == pBuffer_Char[sizeof( pBuffer_Char ) - 2] );
4114 void setPos_003( )
4116 ::osl::File testFile( aTmpName4 );
4117 sal_Char buffer_read[2];
4119 nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write );
4120 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4121 //the file size is smaller than 100
4122 nError1 = testFile.setPos( Pos_End, -100 );
4123 CPPUNIT_ASSERT_MESSAGE( "should return error", ::osl::FileBase::E_INVAL == nError1 );
4125 nError1 = testFile.setPos( Pos_End, -53 );
4126 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4127 nError1 = testFile.read( buffer_read, 1, nCount_read );
4128 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4129 nError1 = testFile.close( );
4130 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4132 CPPUNIT_ASSERT_MESSAGE( "test for setPos function: test for Pos_End, set the position to end, test if the first char in file is correct",
4133 buffer_read[0] == pBuffer_Char[0] );
4136 CPPUNIT_TEST_SUITE( setPos );
4137 CPPUNIT_TEST( setPos_001 );
4138 CPPUNIT_TEST( setPos_002 );
4139 CPPUNIT_TEST( setPos_003 );
4140 CPPUNIT_TEST_SUITE_END( );
4141 };// class setPos
4143 //---------------------------------------------------------------------
4144 // testing the method
4145 // inline RC getPos( sal_uInt64& uPos )
4146 //---------------------------------------------------------------------
4147 class getPos : public CppUnit::TestFixture
4149 ::osl::FileBase::RC nError1;
4150 sal_uInt64 nCount_write, nCount_read;
4152 public:
4153 // initialization
4154 void setUp( )
4156 // create a tempfile in $TEMP/tmpdir/tmpname.
4157 createTestDirectory( aTmpName3 );
4158 createTestFile( aTmpName4 );
4160 //write chars into the file.
4161 ::osl::File testFile( aTmpName4 );
4163 nError1 = testFile.open( OpenFlag_Write );
4164 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4165 nError1 = testFile.write( pBuffer_Char, sizeof( pBuffer_Char ), nCount_write );
4166 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4167 nError1 = testFile.close( );
4168 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4171 void tearDown( )
4173 // remove the tempfile in $TEMP/tmpdir/tmpname.
4174 deleteTestFile( aTmpName4 );
4175 deleteTestDirectory( aTmpName3 );
4178 // test code.
4179 void getPos_001( )
4181 ::osl::File testFile( aTmpName4 );
4182 sal_uInt64 nFilePointer;
4184 nError1 = testFile.getPos( nFilePointer );
4185 CPPUNIT_ASSERT( ::osl::FileBase::E_INVAL == nError1 );
4187 nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write );
4188 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4190 nError1 = testFile.setPos( Pos_Absolut, 26 );
4191 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4192 nError1 = testFile.getPos( nFilePointer );
4193 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4195 nError1 = testFile.close( );
4196 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4198 CPPUNIT_ASSERT_MESSAGE( "test for getPos function: set the position to 26, get position and check if it is right",
4199 26 == nFilePointer );
4202 CPPUNIT_TEST_SUITE( getPos );
4203 CPPUNIT_TEST( getPos_001 );
4204 CPPUNIT_TEST_SUITE_END( );
4205 };// class getPos
4208 //---------------------------------------------------------------------
4209 // testing the method
4210 // inline RC isEndOfFile( sal_Bool *pIsEOF )
4211 //---------------------------------------------------------------------
4212 class isEndOfFile : public CppUnit::TestFixture
4214 ::osl::FileBase::RC nError1;
4215 sal_uInt64 nCount_write, nCount_read;
4217 public:
4218 // initialization
4219 void setUp( )
4221 // create a tempfile in $TEMP/tmpdir/tmpname.
4222 createTestDirectory( aTmpName3 );
4223 createTestFile( aTmpName4 );
4225 //write chars into the file.
4226 ::osl::File testFile( aTmpName4 );
4228 nError1 = testFile.open( OpenFlag_Write );
4229 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4230 nError1 = testFile.write( pBuffer_Char, sizeof( pBuffer_Char ), nCount_write );
4231 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4232 nError1 = testFile.close( );
4233 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4236 void tearDown( )
4238 // remove the tempfile in $TEMP/tmpdir/tmpname.
4239 deleteTestFile( aTmpName4 );
4240 deleteTestDirectory( aTmpName3 );
4243 // test code.
4244 void isEndOfFile_001( )
4246 ::osl::File testFile( aTmpName4 );
4247 sal_Bool bEOF = sal_False;
4248 sal_Bool *pEOF = &bEOF;
4251 nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write );
4252 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4254 nError1 = testFile.setPos( Pos_End, 0 );
4255 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4256 nError1 = testFile.isEndOfFile( pEOF );
4257 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4259 nError1 = testFile.close( );
4260 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4262 CPPUNIT_ASSERT_MESSAGE( "test for isEndOfFile function: set the position to end, check if reach end",
4263 sal_True == *pEOF );
4266 void isEndOfFile_002( )
4268 ::osl::File testFile( aTmpName4 );
4269 sal_Bool bEOF = sal_False;
4270 sal_Bool *pEOF = &bEOF;
4271 sal_uInt64 nFilePointer = 0;
4273 nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write );
4274 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4276 nError1 = testFile.setPos( Pos_Absolut, 0 );
4277 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4278 *pEOF = sal_False;
4279 while ( !( *pEOF ) )
4281 nError1 = testFile.isEndOfFile( pEOF );
4282 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4283 nError1 = testFile.setPos( Pos_Current, 1 );
4284 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4286 nError1 = testFile.getPos( nFilePointer );
4287 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4289 nError1 = testFile.close( );
4290 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4292 CPPUNIT_ASSERT_MESSAGE( "test for isEndOfFile function: use isEndOfFile to move pointer step by step",
4293 sizeof( pBuffer_Char ) + 1 == nFilePointer );
4295 CPPUNIT_TEST_SUITE( isEndOfFile );
4296 CPPUNIT_TEST( isEndOfFile_001 );
4297 CPPUNIT_TEST( isEndOfFile_002 );
4298 CPPUNIT_TEST_SUITE_END( );
4299 };// class isEndOfFile
4302 //---------------------------------------------------------------------
4303 // testing the method
4304 // inline RC setSize( sal_uInt64 uSize )
4305 //---------------------------------------------------------------------
4306 class setSize : public CppUnit::TestFixture
4308 ::osl::FileBase::RC nError1;
4309 sal_uInt64 nCount_write, nCount_read;
4311 public:
4312 // initialization
4313 void setUp( )
4315 // create a tempfile in $TEMP/tmpdir/tmpname.
4316 createTestDirectory( aTmpName3 );
4317 createTestFile( aTmpName4 );
4319 //write chars into the file.
4320 ::osl::File testFile( aTmpName4 );
4322 nError1 = testFile.open( OpenFlag_Write );
4323 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4324 nError1 = testFile.write( pBuffer_Char, sizeof( pBuffer_Char ), nCount_write );
4325 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4326 nError1 = testFile.close( );
4327 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4330 void tearDown( )
4332 // remove the tempfile in $TEMP/tmpdir/tmpname.
4333 deleteTestFile( aTmpName4 );
4334 deleteTestDirectory( aTmpName3 );
4337 // test code.
4338 void setSize_001( )
4340 ::osl::File testFile( aTmpName4 );
4341 // sal_Bool bEOF = sal_False;
4342 // sal_Bool *pEOF = &bEOF;
4343 sal_uInt64 nFilePointer;
4346 nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write );
4347 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4349 //enlarge the file to size of 100;
4350 nError1 = testFile.setSize( 100 );
4351 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4353 //get the file size;
4354 nError1 = testFile.setPos( Pos_End, 0 );
4355 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4356 nError1 = testFile.getPos( nFilePointer );
4357 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4359 nError1 = testFile.close( );
4360 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4362 CPPUNIT_ASSERT_MESSAGE( "test for setSize function: enlarge the file ",
4363 100 == nFilePointer );
4366 void setSize_002( )
4368 ::osl::File testFile( aTmpName4 );
4369 // sal_Bool bEOF = sal_False;
4370 // sal_Bool *pEOF = &bEOF;
4371 sal_uInt64 nFilePointer;
4374 nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write );
4375 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4377 //enlarge the file to size of 100;
4378 nError1 = testFile.setSize( 10 );
4379 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4381 //get the file size;
4382 nError1 = testFile.setPos( Pos_End, 0 );
4383 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4384 nError1 = testFile.getPos( nFilePointer );
4385 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4387 nError1 = testFile.close( );
4388 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4390 CPPUNIT_ASSERT_MESSAGE( "test for setSize function: truncate the file ",
4391 10 == nFilePointer );
4393 /* void setSize_003( )
4395 ::osl::File testFile( aTmpName4 );
4396 // sal_Bool bEOF = sal_False;
4397 // sal_Bool *pEOF = &bEOF;
4398 sal_uInt64 nFilePointer;
4401 nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write );
4402 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4404 //enlarge the file to size of 100;
4405 nError1 = testFile.setSize( 10 );
4406 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4408 //get the file size;
4409 nError1 = testFile.setPos( Pos_End, 0 );
4410 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4411 nError1 = testFile.getPos( nFilePointer );
4412 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4414 nError1 = testFile.close( );
4415 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4417 CPPUNIT_ASSERT_MESSAGE( "test for setSize function: truncate the file ",
4418 10 == nFilePointer );
4422 CPPUNIT_TEST_SUITE( setSize );
4423 CPPUNIT_TEST( setSize_001 );
4424 CPPUNIT_TEST( setSize_002 );
4425 CPPUNIT_TEST_SUITE_END( );
4426 };// class setSize
4429 //---------------------------------------------------------------------
4430 // testing the method
4431 // inline RC read( void *pBuffer, sal_uInt64 uBytesRequested, sal_uInt64& rBytesRead )
4432 //---------------------------------------------------------------------
4433 class read : public CppUnit::TestFixture
4435 ::osl::FileBase::RC nError1;
4436 sal_uInt64 nCount_write, nCount_read;
4438 public:
4439 // initialization
4440 void setUp( )
4442 // create a tempfile in $TEMP/tmpdir/tmpname.
4443 createTestDirectory( aTmpName3 );
4444 createTestFile( aTmpName4 );
4446 //write chars into the file.
4447 ::osl::File testFile( aTmpName4 );
4449 nError1 = testFile.open( OpenFlag_Write );
4450 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4451 nError1 = testFile.write( pBuffer_Char, sizeof( pBuffer_Char ), nCount_write );
4452 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4453 nError1 = testFile.close( );
4454 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4457 void tearDown( )
4459 // remove the tempfile in $TEMP/tmpdir/tmpname.
4460 deleteTestFile( aTmpName4 );
4461 deleteTestDirectory( aTmpName3 );
4464 // test code.
4465 void read_001( )
4467 ::osl::File testFile( aTmpName4 );
4468 sal_uInt64 nFilePointer;
4469 sal_Char buffer_read[10];
4472 nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write );
4473 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4475 nError1 = testFile.read( buffer_read, 10, nCount_read );
4476 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4477 nError1 = testFile.getPos( nFilePointer );
4478 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4480 nError1 = testFile.close( );
4481 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4483 CPPUNIT_ASSERT_MESSAGE( "test for read function: read whole content in the file to a buffer",
4484 ( 10 == nFilePointer ) && ( 0 == strncmp( buffer_read, pBuffer_Char, 10 ) ) );
4487 void read_002( )
4489 ::osl::File testFile( aTmpName4 );
4490 sal_uInt64 nFilePointer;
4491 sal_Char buffer_read[26];
4494 nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write );
4495 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4497 nError1 = testFile.setPos( Pos_Absolut, 26 );
4498 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4499 nError1 = testFile.read( buffer_read, 26, nCount_read );
4500 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4501 nError1 = testFile.getPos( nFilePointer );
4502 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4504 nError1 = testFile.close( );
4505 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4507 CPPUNIT_ASSERT_MESSAGE( "test for read function: read from a special positon in the file",
4508 ( 52 == nFilePointer ) && ( 26 == nCount_read ) && ( 0 == strncmp( buffer_read, &pBuffer_Char[26], 26 ) ) );
4511 CPPUNIT_TEST_SUITE( read );
4512 CPPUNIT_TEST( read_001 );
4513 CPPUNIT_TEST( read_002 );
4514 CPPUNIT_TEST_SUITE_END( );
4515 };// class read
4517 //---------------------------------------------------------------------
4518 // testing the method
4519 // inline RC write(const void *pBuffer, sal_uInt64 uBytesToWrite, sal_uInt64& rBytesWritten)
4520 //---------------------------------------------------------------------
4521 class write : public CppUnit::TestFixture
4523 ::osl::FileBase::RC nError1;
4524 sal_uInt64 nCount_write, nCount_read;
4526 public:
4527 // initialization
4528 void setUp( )
4530 // create a tempfile in $TEMP/tmpname.
4531 createTestFile( aTmpName6 );
4534 void tearDown( )
4536 // remove the tempfile in $TEMP/tmpname.
4537 deleteTestFile( aTmpName6 );
4540 // test code.
4541 void write_001( )
4543 ::osl::File testFile( aTmpName6 );
4544 sal_uInt64 nFilePointer;
4545 sal_Char buffer_read[10];
4547 nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write );
4548 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4550 //write chars into the file.
4551 nError1 = testFile.write( pBuffer_Char, 10, nCount_write );
4552 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4553 //get the current pointer;
4554 nError1 = testFile.getPos( nFilePointer );
4555 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4556 //reset pointer to the begining;
4557 nError1 = testFile.setPos( Pos_Absolut, 0 );
4558 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4559 nError1 = testFile.read( buffer_read, 10, nCount_read );
4560 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4562 nError1 = testFile.close( );
4563 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4565 CPPUNIT_ASSERT_MESSAGE( "test for write function: read whole content in the file to a buffer. Note, buffer size can not smaller than the read size",
4566 ( 10 == nFilePointer ) &&
4567 ( 0 == strncmp( buffer_read, pBuffer_Char, 10 ) ) &&
4568 ( 10 == nCount_write ) );
4571 CPPUNIT_TEST_SUITE( write );
4572 CPPUNIT_TEST( write_001 );
4573 CPPUNIT_TEST_SUITE_END( );
4574 };// class write
4576 //---------------------------------------------------------------------
4577 // testing the method
4578 // inline RC readLine( ::rtl::ByteSequence& aSeq )
4579 //---------------------------------------------------------------------
4580 class readLine : public CppUnit::TestFixture
4582 ::osl::FileBase::RC nError1;
4583 sal_uInt64 nCount_write, nCount_read;
4584 ::rtl::ByteSequence aSequence;
4586 public:
4587 // initialization
4588 void setUp( )
4590 // create a tempfile in $TEMP/tmpname.
4591 createTestFile( aTmpName6 );
4593 //write some strings into the file.
4594 ::osl::File testFile( aTmpName6 );
4595 sal_Char ppStrSeq[3][27] = { "abcde\n",
4596 "1234567890\n",
4597 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
4600 nError1 = testFile.open( OpenFlag_Write );
4601 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4603 for ( int nCount = 0; nCount < 3; nCount++ )
4605 nError1 = testFile.write( ppStrSeq[nCount], strlen( ppStrSeq[nCount] ), nCount_write );
4606 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4609 nError1 = testFile.close( );
4610 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4613 void tearDown( )
4615 // remove the tempfile in $TEMP/tmpname.
4616 deleteTestFile( aTmpName6 );
4619 // test code.
4620 void readLine_001( )
4622 ::osl::File testFile( aTmpName6 );
4624 nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write );
4625 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4626 nError1 = testFile.readLine( aSequence );
4627 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4629 CPPUNIT_ASSERT_MESSAGE( "test for readLine function: read the first line of the file.",
4630 ( ::osl::FileBase::E_None == nError1 ) &&
4631 ( 0 == strncmp( ( const char * )aSequence.getArray( ), pBuffer_Char, 5 ) ) );
4634 void readLine_002( )
4636 ::osl::File testFile( aTmpName6 );
4637 sal_Bool bEOF = sal_False;
4638 sal_Bool *pEOF = &bEOF;
4640 nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write );
4641 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4642 for ( int nCount = 0; nCount < 3; nCount++ )
4644 nError1 = testFile.readLine( aSequence );
4645 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4647 nError1 = testFile.isEndOfFile( pEOF );
4648 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4650 CPPUNIT_ASSERT_MESSAGE( "test for readLine function: read three lines of the file and check the file pointer moving.",
4651 *pEOF &&
4652 ( 0 == strncmp( ( const char * )aSequence.getArray( ), &pBuffer_Char[26], 26 ) ) );
4654 CPPUNIT_TEST_SUITE( readLine );
4655 CPPUNIT_TEST( readLine_001 );
4656 CPPUNIT_TEST( readLine_002 );
4657 CPPUNIT_TEST_SUITE_END( );
4658 };// class readLine
4660 //---------------------------------------------------------------------
4661 // testing the method
4662 // inline static RC copy( const ::rtl::OUString& ustrSourceFileURL, const ::rtl::OUString& ustrDestFileURL )
4663 //---------------------------------------------------------------------
4664 class copy : public CppUnit::TestFixture
4666 ::osl::FileBase::RC nError1;
4667 sal_uInt64 nCount_write, nCount_read;
4669 public:
4670 // initialization
4671 void setUp( )
4673 // create a tempfile in $TEMP/tmpdir/tmpname.
4674 createTestDirectory( aTmpName3 );
4675 createTestFile( aTmpName4 );
4677 //write chars into the file.
4678 ::osl::File testFile( aTmpName4 );
4680 nError1 = testFile.open( OpenFlag_Write );
4681 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4682 nError1 = testFile.write( pBuffer_Char, sizeof( pBuffer_Char ), nCount_write );
4683 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4684 nError1 = testFile.close( );
4685 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4688 void tearDown( )
4690 // remove the tempfile in $TEMP/tmpdir/tmpname.
4691 deleteTestFile( aTmpName4 );
4692 deleteTestDirectory( aTmpName3 );
4695 // test code.
4696 void copy_001( )
4698 ::osl::File testFile( aTmpName6 );
4700 //copy $TEMP/tmpdir/tmpname to $TEMP/tmpname.
4701 nError1 = ::osl::File::copy( aTmpName4, aTmpName6 );
4702 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4703 //check
4704 nError1 = testFile.open( OpenFlag_Create );
4705 deleteTestFile( aTmpName6 );
4707 CPPUNIT_ASSERT_MESSAGE( "test for copy function: copy file to upper directory",
4708 ::osl::FileBase::E_EXIST == nError1 );
4711 void copy_002( )
4713 //copy $TEMP/tmpdir/tmpname to $TEMP/tmpdir.
4714 nError1 = ::osl::File::copy( aTmpName4, aTmpName3 );
4716 CPPUNIT_ASSERT_MESSAGE( "test for copy function: use directory as destination",
4717 ( ::osl::FileBase::E_ISDIR == nError1 ) ||( ::osl::FileBase::E_ACCES == nError1 ) );
4720 void copy_003( )
4722 //copy $TEMP/tmpdir/tmpname to $ROOT/tmpname.
4723 nError1 = ::osl::File::copy( aTmpName4, aTmpName7 );
4724 #if defined (WNT )
4725 nError1 = ::osl::FileBase::E_ACCES; /// for Windows, c:/ is writtenable any way.
4726 deleteTestFile( aTmpName7);
4727 #endif
4728 CPPUNIT_ASSERT_MESSAGE( "test for copy function: copy to an illigal place",
4729 ::osl::FileBase::E_ACCES == nError1 );
4732 void copy_004( )
4734 //copy $TEMP/tmpname to $TEMP/tmpdir/tmpname.
4735 nError1 = ::osl::File::copy( aTmpName6, aTmpName4 );
4737 CPPUNIT_ASSERT_MESSAGE( "test for copy function: copy a not exist file",
4738 ::osl::FileBase::E_NOENT == nError1 );
4741 void copy_005( )
4743 //copy $TEMP/tmpname to $TEMP/system.path using system path.
4744 nError1 = ::osl::File::copy( aTmpName6, aSysPath1 );
4746 CPPUNIT_ASSERT_MESSAGE( "test for copy function: copy a file using system file path",
4747 ::osl::FileBase::E_INVAL == nError1 );
4749 void copy_006( )
4751 createTestFile( aTmpName6 );
4752 File tmpFile( aTmpName6 );
4753 FileBase::RC err = tmpFile.open( OpenFlag_Write | OpenFlag_Read );
4754 (void)err;
4755 tmpFile.setSize( 200 );
4756 tmpFile.close();
4757 //copy to new path
4758 nError1 = ::osl::File::copy( aTmpName6, aTmpName4 );
4759 CPPUNIT_ASSERT( nError1 == FileBase::E_None );
4761 //check if is the new file
4762 File newFile( aTmpName4 );
4763 newFile.open( OpenFlag_Write | OpenFlag_Read );
4764 newFile.setPos( Pos_End, 0 );
4765 // CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4766 sal_uInt64 nFilePointer;
4767 nError1 = newFile.getPos( nFilePointer );
4768 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4769 newFile.close( );
4770 deleteTestFile( aTmpName6 );
4771 CPPUNIT_ASSERT_MESSAGE( "test for copy function: the dest file exist",
4772 nFilePointer == 200 );
4774 //copyLink has not been impletmented yet
4775 void copy_007( )
4777 #if ( defined UNX )
4779 CPPUNIT_ASSERT_MESSAGE( "test for copy function: source file is link file",
4780 ::osl::FileBase::E_INVAL == nError1 );
4781 #endif
4784 CPPUNIT_TEST_SUITE( copy );
4785 CPPUNIT_TEST( copy_001 );
4786 CPPUNIT_TEST( copy_002 );
4787 CPPUNIT_TEST( copy_003 );
4788 CPPUNIT_TEST( copy_004 );
4789 CPPUNIT_TEST( copy_005 );
4790 CPPUNIT_TEST( copy_006 );
4791 CPPUNIT_TEST_SUITE_END( );
4792 };// class copy
4794 //---------------------------------------------------------------------
4795 // testing the method
4796 // inline static RC move( const ::rtl::OUString& ustrSourceFileURL, const ::rtl::OUString& ustrDestFileURL )
4797 //---------------------------------------------------------------------
4798 class move : public CppUnit::TestFixture
4800 ::osl::FileBase::RC nError1, nError2;
4801 sal_uInt64 nCount_write, nCount_read;
4803 public:
4804 // initialization
4805 void setUp( )
4807 // create a tempfile in $TEMP/tmpdir/tmpname.
4808 createTestDirectory( aTmpName3 );
4809 createTestFile( aTmpName4 );
4811 //write chars into the file.
4812 ::osl::File testFile( aTmpName4 );
4814 nError1 = testFile.open( OpenFlag_Write );
4815 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4816 nError1 = testFile.write( pBuffer_Char, sizeof( pBuffer_Char ), nCount_write );
4817 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4818 nError1 = testFile.close( );
4819 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4822 void tearDown( )
4824 // remove the tempfile in $TEMP/tmpdir/tmpname.
4825 deleteTestFile( aTmpName4 );
4826 deleteTestDirectory( aTmpName3 );
4829 // test code.
4830 void move_001( )
4832 //rename $TEMP/tmpdir/tmpname to $TEMP/canonical.name.
4833 nError1 = ::osl::File::move( aTmpName4, aCanURL1 );
4834 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4835 //check
4836 ::osl::File testFile( aCanURL1 );
4837 nError2 = testFile.open( OpenFlag_Create );
4838 deleteTestFile( aCanURL1 );
4840 CPPUNIT_ASSERT_MESSAGE( "test for move function: rename file to another directory",
4841 ::osl::FileBase::E_EXIST == nError2 );
4844 void move_002( )
4846 //move $TEMP/tmpdir/tmpname to $TEMP/tmpdir.
4847 nError1 = ::osl::File::move( aTmpName4, aTmpName3 );
4848 //returned ::osl::FileBase::E_ACCES on WNT
4849 CPPUNIT_ASSERT_MESSAGE( "test for move function: use directory as destination",
4850 ( ::osl::FileBase::E_ACCES == nError1 || ::osl::FileBase::E_ISDIR == nError1 ) ||( ::osl::FileBase::E_EXIST == nError1 ) );
4853 void move_003( )
4855 //move $TEMP/tmpdir/tmpname to $ROOT/tmpname.
4856 nError1 = ::osl::File::move( aTmpName4, aTmpName7 );
4857 #if defined (WNT )
4858 nError1 = ::osl::FileBase::E_ACCES; /// for Windows, c:/ is writtenable any way.
4859 deleteTestFile( aTmpName7);
4860 #endif
4862 CPPUNIT_ASSERT_MESSAGE( "test for move function: move to an illigal place",
4863 ::osl::FileBase::E_ACCES == nError1 );
4866 void move_004( )
4868 //move $TEMP/tmpname to $TEMP/tmpdir/tmpname.
4869 nError1 = ::osl::File::move( aTmpName6, aTmpName4 );
4871 CPPUNIT_ASSERT_MESSAGE( "test for move function: move a not exist file",
4872 ::osl::FileBase::E_NOENT == nError1 );
4875 void move_005( )
4877 //move $TEMP/tmpname to $TEMP/system.path using system path.
4878 nError1 = ::osl::File::move( aTmpName6, aSysPath1 );
4880 CPPUNIT_ASSERT_MESSAGE( "test for move function: move a file using system file",
4881 ::osl::FileBase::E_INVAL == nError1 );
4884 void move_006( )
4886 //move directory $TEMP/tmpname to $TEMP/tmpdir/tmpname.
4887 createTestDirectory( aTmpName6 );
4888 nError1 = ::osl::File::move( aTmpName6, aTmpName4 );
4889 //move file $TEMP/tmpdir/tmpname to $TEMP/tmpname
4890 nError2 = ::osl::File::move( aTmpName4, aTmpName6 );
4891 deleteTestDirectory( aTmpName6 );
4892 #if defined ( WNT )
4893 deleteTestDirectory( aTmpName4 );// in Windows, it can be moved!!!!! this is only for not influence the following test.
4894 deleteTestFile( aTmpName6 );
4895 nError1 = ::osl::FileBase::E_NOTDIR;
4896 nError2 = ::osl::FileBase::E_ISDIR;
4897 #endif
4898 CPPUNIT_ASSERT_MESSAGE( "test for move function: move a directory to an exist file with same name, did not pass in (W32)",
4899 ::osl::FileBase::E_NOTDIR == nError1 && ::osl::FileBase::E_ISDIR == nError2 );
4902 void move_007( )
4904 //create directory $TEMP/tmpname.
4905 createTestDirectory( aTmpName6 );
4906 //move directory $TEMP/tmpdir to $TEMP/tmpname/tmpdir
4907 nError1 = ::osl::File::move( aTmpName3, aTmpName8 );
4908 //check
4909 nError2 = ::osl::Directory::create( aTmpName8 );
4910 ::osl::File::move( aTmpName8, aTmpName3 );
4911 deleteTestDirectory( aTmpName6 );
4913 CPPUNIT_ASSERT_MESSAGE( "test for move function: move a directory to an exist file with same name",
4914 (::osl::FileBase::E_None == nError1 ) &&
4915 (::osl::FileBase::E_EXIST == nError2 ) );
4917 // oldpath and newpath are not on the same filesystem.EXDEV,no such error no on Solaris, only on linux
4918 void move_008( )
4920 CPPUNIT_ASSERT_MESSAGE( "oldpath and newpath are not on the same filesystem, should error returns",
4921 ::osl::FileBase::E_None == nError1 );
4923 //bugid# 115420, after the bug fix, add the case
4924 void move_009( )
4926 //create directory $TEMP/tmpname.
4927 createTestDirectory( aTmpName6 );
4928 //create directory $TEMP/tmpname/tmpdir
4929 createTestDirectory( aTmpName8 );
4930 //move directory $TEMP/tmpname to $TEMP/tmpname/tmpdir/tmpname
4931 rtl::OUString newName = aTmpName8 + OUString::createFromAscii("/tmpname");
4932 //printFileName( newName );
4933 nError1 = ::osl::File::move( aTmpName3, newName );
4934 //deleteTestDirectory( newName + OUString::createFromAscii("/tmpname") );
4935 //deleteTestDirectory( newName );
4936 deleteTestDirectory( aTmpName8 );
4937 deleteTestDirectory( aTmpName6 );
4938 CPPUNIT_ASSERT_MESSAGE( "test for move function: move a directory to it's subdirectory",
4939 ::osl::FileBase::E_None != nError1 );
4942 CPPUNIT_TEST_SUITE( move );
4943 CPPUNIT_TEST( move_001 );
4944 CPPUNIT_TEST( move_002 );
4945 CPPUNIT_TEST( move_003 );
4946 CPPUNIT_TEST( move_004 );
4947 CPPUNIT_TEST( move_005 );
4948 CPPUNIT_TEST( move_006 );
4949 CPPUNIT_TEST( move_007 );
4950 // CPPUNIT_TEST( move_008 );
4951 //CPPUNIT_TEST( move_009 );
4952 CPPUNIT_TEST_SUITE_END( );
4953 };// class move
4956 //---------------------------------------------------------------------
4957 // testing the method
4958 // inline static RC remove( const ::rtl::OUString& ustrFileURL )
4959 //---------------------------------------------------------------------
4960 class remove : public CppUnit::TestFixture
4962 ::osl::FileBase::RC nError1, nError2;
4963 sal_uInt64 nCount_write, nCount_read;
4965 public:
4966 // initialization
4967 void setUp( )
4969 // create a tempfile in $TEMP/tmpdir/tmpname.
4970 createTestDirectory( aTmpName3 );
4971 createTestFile( aTmpName4 );
4973 //write chars into the file.
4974 ::osl::File testFile( aTmpName4 );
4976 nError1 = testFile.open( OpenFlag_Write );
4977 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4978 nError1 = testFile.write( pBuffer_Char, sizeof( pBuffer_Char ), nCount_write );
4979 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4980 nError1 = testFile.close( );
4981 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4984 void tearDown( )
4986 // remove the tempfile in $TEMP/tmpdir/tmpname.
4987 deleteTestFile( aTmpName4 );
4988 deleteTestDirectory( aTmpName3 );
4991 // test code.
4992 void remove_001( )
4994 //remove $TEMP/tmpdir/tmpname.
4995 nError1 = ::osl::File::remove( aTmpName4 );
4996 //check
4997 ::osl::File testFile( aTmpName4 );
4998 nError2 = testFile.open( OpenFlag_Create );
5000 CPPUNIT_ASSERT_MESSAGE( "test for remove function: remove a file",
5001 ( ::osl::FileBase::E_None == nError1 ) &&
5002 ( ::osl::FileBase::E_EXIST != nError2 ) );
5005 void remove_002( )
5007 //remove $TEMP/tmpname.
5008 nError1 = ::osl::File::remove( aTmpName6 );
5010 CPPUNIT_ASSERT_MESSAGE( "test for remove function: remove a file not exist",
5011 ( ::osl::FileBase::E_NOENT == nError1 ) );
5014 void remove_003( )
5016 //remove $TEMP/system/path.
5017 nError1 = ::osl::File::remove( aSysPath2 );
5019 CPPUNIT_ASSERT_MESSAGE( "test for remove function: removing a file not using full qualified URL",
5020 ( ::osl::FileBase::E_INVAL == nError1 ) );
5023 void remove_004( )
5025 //remove $TEMP/tmpdir.
5026 nError1 = ::osl::File::remove( aTmpName3 );
5028 CPPUNIT_ASSERT_MESSAGE( "test for remove function: remove a directory",
5029 ( ::osl::FileBase::E_ISDIR == nError1 ) || ( ::osl::FileBase::E_ACCES == nError1 ));
5032 CPPUNIT_TEST_SUITE( remove );
5033 CPPUNIT_TEST( remove_001 );
5034 CPPUNIT_TEST( remove_002 );
5035 CPPUNIT_TEST( remove_003 );
5036 CPPUNIT_TEST( remove_004 );
5037 CPPUNIT_TEST_SUITE_END( );
5038 };// class remove
5041 //---------------------------------------------------------------------
5042 // testing the method
5043 // inline static RC setAttributes( const ::rtl::OUString& ustrFileURL, sal_uInt64 uAttributes )
5044 //---------------------------------------------------------------------
5045 class setAttributes : public CppUnit::TestFixture
5047 ::osl::FileBase::RC nError1, nError2;
5048 ::osl::DirectoryItem rItem, rItem_hidden;
5050 public:
5051 // initialization
5052 void setUp( )
5054 // create a tempfile in $TEMP/tmpdir/tmpname.
5055 createTestFile( aTmpName6 );
5058 void tearDown( )
5060 // remove the tempfile in $TEMP/tmpdir/tmpname.
5061 deleteTestFile( aTmpName6 );
5064 // test code.
5065 void setAttributes_001( )
5067 //on windows, only can set 2 attributes: Attribute_ReadOnly, Attribute_HIDDEN
5068 #ifdef UNX
5069 //set the file to readonly
5070 nError2 = ::osl::File::setAttributes( aTmpName6, Attribute_ReadOnly | Attribute_GrpRead | Attribute_OwnRead | Attribute_OthRead );
5071 CPPUNIT_ASSERT( nError2 == FileBase::E_None);
5072 nError1 = ::osl::DirectoryItem::get( aTmpName6, rItem );
5073 CPPUNIT_ASSERT( nError1 == FileBase::E_None);
5074 //get the file attributes
5075 ::osl::FileStatus rFileStatus( FileStatusMask_Attributes );
5076 nError1 = rItem.getFileStatus( rFileStatus );
5077 CPPUNIT_ASSERT( nError1 == FileBase::E_None );
5079 CPPUNIT_ASSERT_MESSAGE( "test for setAttributes function: set file attributes and get it to verify.",
5080 ( Attribute_ReadOnly | Attribute_GrpRead | Attribute_OwnRead | Attribute_OthRead ) ==
5081 rFileStatus.getAttributes( ) );
5082 #else
5083 //please see GetFileAttributes
5084 nError2 = ::osl::File::setAttributes( aTmpName6, Attribute_ReadOnly );
5085 CPPUNIT_ASSERT( nError2 == FileBase::E_None);
5086 nError1 = ::osl::DirectoryItem::get( aTmpName6, rItem );
5087 CPPUNIT_ASSERT( nError1 == FileBase::E_None);
5088 //get the file attributes
5089 ::osl::FileStatus rFileStatus( FileStatusMask_Attributes );
5090 nError1 = rItem.getFileStatus( rFileStatus );
5091 CPPUNIT_ASSERT( nError1 == FileBase::E_None );
5092 //here the file has 2 Attributes: FILE_ATTRIBUTE_READONLY and FILE_ATTRIBUTE_NORMAL,
5093 // but FILE_ATTRIBUTE_NORMAL is valid only if used alone, so this is maybe a bug
5094 /*::rtl::OString aString = ::rtl::OUStringToOString( aTmpName6, RTL_TEXTENCODING_ASCII_US );
5095 DWORD dwFileAttributes = GetFileAttributes( aString.getStr( ) );
5096 if (dwFileAttributes & FILE_ATTRIBUTE_NORMAL)
5097 t_print("has normal attribute");
5098 if (dwFileAttributes & FILE_ATTRIBUTE_READONLY)
5099 t_print("has readonly attribute");
5101 CPPUNIT_ASSERT_MESSAGE( "test for setAttributes function: set file attributes READONLY and get it to verify.",
5102 (Attribute_ReadOnly & rFileStatus.getAttributes( )) != 0 );
5103 #endif
5105 void setAttributes_002( )
5107 //on UNX, can not set hidden attribute to file, rename file can set the attribute
5108 #ifdef WNT
5109 //set the file to hidden
5110 nError2 = ::osl::File::setAttributes( aTmpName6, Attribute_Hidden);
5112 CPPUNIT_ASSERT( nError2 == FileBase::E_None);
5113 nError1 = ::osl::DirectoryItem::get( aTmpName6, rItem );
5114 CPPUNIT_ASSERT( nError1 == FileBase::E_None);
5115 //get the file attributes
5116 ::osl::FileStatus rFileStatus( FileStatusMask_Attributes );
5117 nError1 = rItem.getFileStatus( rFileStatus );
5118 CPPUNIT_ASSERT( nError1 == FileBase::E_None );
5120 CPPUNIT_ASSERT_MESSAGE( "test for setAttributes function: set file attributes and get it to verify.",
5121 (Attribute_Hidden & rFileStatus.getAttributes( )) != 0 );
5122 #endif
5125 CPPUNIT_TEST_SUITE( setAttributes );
5126 CPPUNIT_TEST( setAttributes_001 );
5127 CPPUNIT_TEST( setAttributes_002 );
5128 CPPUNIT_TEST_SUITE_END( );
5129 };// class setAttributes
5132 //---------------------------------------------------------------------
5133 // testing the method
5134 // inline static RC setTime(
5135 // const ::rtl::OUString& ustrFileURL,
5136 // const TimeValue& rCreationTime,
5137 // const TimeValue& rLastAccessTime,
5138 // const TimeValue& rLastWriteTime )
5139 //---------------------------------------------------------------------
5140 class setTime : public CppUnit::TestFixture
5142 ::osl::FileBase::RC nError1, nError2;
5143 ::osl::DirectoryItem rItem;
5145 public:
5146 // initialization
5147 void setUp( )
5149 // create a tempfile in $TEMP/tmpdir/tmpname.
5150 createTestFile( aTmpName6 );
5153 void tearDown( )
5155 // remove the tempfile in $TEMP/tmpdir/tmpname.
5156 deleteTestFile( aTmpName6 );
5159 // test code.
5160 void setTime_001( )
5162 TimeValue *pTV_current = NULL;
5163 CPPUNIT_ASSERT( ( pTV_current = ( TimeValue* )malloc( sizeof( TimeValue ) ) ) != NULL );
5164 TimeValue *pTV_creation = NULL;
5165 CPPUNIT_ASSERT( ( pTV_creation = ( TimeValue* )malloc( sizeof( TimeValue ) ) ) != NULL );
5166 TimeValue *pTV_access = NULL;
5167 CPPUNIT_ASSERT( ( pTV_access = ( TimeValue* )malloc( sizeof( TimeValue ) ) ) != NULL );
5168 TimeValue *pTV_modify = NULL;
5169 CPPUNIT_ASSERT( ( pTV_modify = ( TimeValue* )malloc( sizeof( TimeValue ) ) ) != NULL );
5171 //get current time
5172 sal_Bool bOk = osl_getSystemTime( pTV_current );
5173 CPPUNIT_ASSERT( sal_True == bOk );
5175 //set the file time
5176 nError2 = ::osl::File::setTime( aTmpName6, *pTV_current, *pTV_current, *pTV_current );
5177 CPPUNIT_ASSERT_MESSAGE( errorToStr( nError2 ), nError2 == FileBase::E_None);
5179 //get the file access time, creation time, modify time
5180 nError1 = ::osl::DirectoryItem::get( aTmpName6, rItem );
5181 CPPUNIT_ASSERT_MESSAGE( errorToStr( nError1 ), nError1 == FileBase::E_None);
5183 ::osl::FileStatus rFileStatus( FileStatusMask_AccessTime );
5184 nError1 = rItem.getFileStatus( rFileStatus );
5185 CPPUNIT_ASSERT_MESSAGE( errorToStr( nError1 ),nError1 == FileBase::E_None );
5186 *pTV_access = rFileStatus.getAccessTime( );
5188 ::osl::FileStatus rFileStatus1( FileStatusMask_CreationTime );
5189 nError1 = rItem.getFileStatus( rFileStatus1 );
5190 CPPUNIT_ASSERT_MESSAGE( errorToStr( nError1 ), nError1 == FileBase::E_None );
5191 *pTV_creation = rFileStatus1.getCreationTime( );
5193 ::osl::FileStatus rFileStatus2( FileStatusMask_ModifyTime );
5194 nError1 = rItem.getFileStatus( rFileStatus2 );
5195 CPPUNIT_ASSERT_MESSAGE( errorToStr( nError1 ), nError1 == FileBase::E_None );
5196 *pTV_modify = rFileStatus2.getModifyTime( );
5198 CPPUNIT_ASSERT_MESSAGE( "test for setTime function: set access time then get it. time precision is still a problem for it cut off the nanosec.",
5199 sal_True == t_compareTime( pTV_access, pTV_current, delta ) );
5200 #if defined ( WNT )
5201 //Unfortunately there is no way to get the creation time of a file under Unix (its a Windows only feature).
5202 //That means the flag osl_FileStatus_Mask_CreationTime should be deprecated under Unix.
5203 CPPUNIT_ASSERT_MESSAGE( "test for setTime function: set creation time then get it. ",
5204 sal_True == t_compareTime( pTV_creation, pTV_current, delta ) ) ;
5205 #endif
5206 CPPUNIT_ASSERT_MESSAGE( "test for setTime function: set modify time then get it. ",
5207 sal_True == t_compareTime( pTV_modify, pTV_current, delta ) );
5208 free( pTV_current );
5209 free( pTV_creation );
5210 free( pTV_access );
5211 free( pTV_modify );
5214 CPPUNIT_TEST_SUITE( setTime );
5215 CPPUNIT_TEST( setTime_001 );
5216 CPPUNIT_TEST_SUITE_END( );
5217 };// class setTime
5219 //---------------------------------------------------------------------
5220 // testing the method
5221 // inline static RC sync()
5222 //---------------------------------------------------------------------
5223 class sync : public CppUnit::TestFixture
5225 ::osl::FileBase::RC nError1, nError2;
5226 ::osl::DirectoryItem rItem;
5228 public:
5229 // initialization
5230 void setUp( )
5232 // create a tempfile in $TEMP/tmpdir/tmpname.
5233 createTestFile( aTmpName6 );
5237 void tearDown( )
5239 // remove the tempfile in $TEMP/tmpdir/tmpname.
5240 deleteTestFile( aTmpName6 );
5243 // test case: if The file is located on a read only file system.
5244 void sync_001( )
5246 #ifdef UNX
5247 nError1 = ::osl::DirectoryItem::get( aTmpName6, rItem );
5248 CPPUNIT_ASSERT( nError1 == FileBase::E_None);
5250 File tmp_file( aTmpName6 );
5251 FileBase::RC err = tmp_file.open(osl_File_OpenFlag_Write );
5253 CPPUNIT_ASSERT_MESSAGE("File open failed", err == FileBase::E_None);
5255 char buffer[50000];
5256 sal_uInt64 written = 0;
5257 nError1 = tmp_file.write((void*)buffer, sizeof(buffer), written);
5258 CPPUNIT_ASSERT_MESSAGE("write failed!", nError1 == FileBase::E_None);
5260 //set the file to readonly
5261 nError2 = ::osl::File::setAttributes( aTmpName6, Attribute_ReadOnly | Attribute_GrpRead | Attribute_OwnRead | Attribute_OthRead );
5262 CPPUNIT_ASSERT( nError2 == FileBase::E_None);
5264 nError2 = tmp_file.sync();
5266 CPPUNIT_ASSERT_MESSAGE("can not sync to readonly file!", nError2 == FileBase::E_None);
5268 tmp_file.close();
5269 #endif
5271 //test case:no enough space, how to create such case???see test_cpy_wrt_file.cxx::test_osl_writeFile
5275 CPPUNIT_TEST_SUITE( sync );
5276 CPPUNIT_TEST( sync_001 );
5277 CPPUNIT_TEST_SUITE_END( );
5278 };// class setTime
5280 // -----------------------------------------------------------------------------
5281 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::ctors, "osl_File" );
5282 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::open, "osl_File" );
5283 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::close, "osl_File" );
5284 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::setPos, "osl_File" );
5285 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::getPos, "osl_File" );
5286 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::isEndOfFile, "osl_File" );
5287 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::setSize, "osl_File" );
5288 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::read, "osl_File" );
5289 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::write, "osl_File" );
5290 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::readLine, "osl_File" );
5291 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::copy, "osl_File" );
5292 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::move, "osl_File" );
5293 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::remove, "osl_File" );
5294 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::setAttributes, "osl_File" );
5295 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::setTime, "osl_File" );
5296 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::sync, "osl_File" );
5298 }// namespace osl_File
5301 //------------------------------------------------------------------------
5302 // Beginning of the test cases for DirectoryItem class
5303 //------------------------------------------------------------------------
5304 namespace osl_DirectoryItem
5306 //---------------------------------------------------------------------
5307 // testing the method
5308 // DirectoryItem(): _pData( NULL )
5309 //---------------------------------------------------------------------
5310 class ctors : public CppUnit::TestFixture
5312 ::osl::FileBase::RC nError1, nError2;
5314 public:
5315 // initialization
5316 void setUp( )
5318 // create a tempfile in $TEMP/tmpname.
5319 createTestFile( aTmpName6 );
5322 void tearDown( )
5324 // remove the tempfile in $TEMP/tmpname.
5325 deleteTestFile( aTmpName6 );
5328 // test code.
5329 void ctors_001( )
5331 ::osl::File testFile( aTmpName6 );
5332 ::osl::DirectoryItem rItem; //constructor
5334 //get the DirectoryItem.
5335 nError1 = ::osl::DirectoryItem::get( aTmpName6, rItem );
5336 CPPUNIT_ASSERT( FileBase::E_None == nError1 );
5338 CPPUNIT_ASSERT_MESSAGE( "test for ctors function: initialize a new instance of DirectoryItem and get an item to check.",
5339 ::osl::FileBase::E_None == nError1 );
5342 CPPUNIT_TEST_SUITE( ctors );
5343 CPPUNIT_TEST( ctors_001 );
5344 CPPUNIT_TEST_SUITE_END( );
5345 };// class ctors
5347 //---------------------------------------------------------------------
5348 // testing the method
5349 // DirectoryItem( const DirectoryItem& rItem ): _pData( rItem._pData)
5350 //---------------------------------------------------------------------
5351 class copy_assin_Ctors : public CppUnit::TestFixture
5353 ::osl::FileBase::RC nError1, nError2;
5355 public:
5356 // initialization
5357 void setUp( )
5359 // create a tempfile in $TEMP/tmpname.
5360 createTestFile( aTmpName6 );
5363 void tearDown( )
5365 // remove the tempfile in $TEMP/tmpname.
5366 deleteTestFile( aTmpName6 );
5369 // test code.
5370 void copy_assin_Ctors_001( )
5372 ::osl::DirectoryItem rItem; //constructor
5373 //get the DirectoryItem.
5374 nError1 = ::osl::DirectoryItem::get( aTmpName6, rItem );
5375 CPPUNIT_ASSERT( FileBase::E_None == nError1 );
5377 ::osl::DirectoryItem copyItem( rItem ); //copy constructor
5378 ::osl::FileStatus rFileStatus( FileStatusMask_FileName );
5379 nError1 = copyItem.getFileStatus( rFileStatus );
5380 CPPUNIT_ASSERT( nError1 == FileBase::E_None );
5382 CPPUNIT_ASSERT_MESSAGE( "test for copy_assin_Ctors function: use copy constructor to get an item and check filename.",
5383 ( sal_True == compareFileName( rFileStatus.getFileName( ), aTmpName2 ) ) );
5386 void copy_assin_Ctors_002( )
5388 ::osl::DirectoryItem rItem; //constructor
5389 //get the DirectoryItem.
5390 nError1 = ::osl::DirectoryItem::get( aTmpName6, rItem );
5391 CPPUNIT_ASSERT( FileBase::E_None == nError1 );
5393 ::osl::DirectoryItem copyItem;
5394 copyItem = rItem; //assinment operator
5395 ::osl::FileStatus rFileStatus( FileStatusMask_FileName );
5396 nError1 = copyItem.getFileStatus( rFileStatus );
5397 CPPUNIT_ASSERT( nError1 == FileBase::E_None );
5399 CPPUNIT_ASSERT_MESSAGE( "test for copy_assin_Ctors function: test assinment operator here since it is same as copy constructor in test way.",
5400 ( sal_True == compareFileName( rFileStatus.getFileName( ), aTmpName2 ) ) );
5403 CPPUNIT_TEST_SUITE( copy_assin_Ctors );
5404 CPPUNIT_TEST( copy_assin_Ctors_001 );
5405 CPPUNIT_TEST( copy_assin_Ctors_002 );
5406 CPPUNIT_TEST_SUITE_END( );
5407 };// class copy_assin_Ctors
5409 //---------------------------------------------------------------------
5410 // testing the method
5411 // inline sal_Bool is()
5412 //---------------------------------------------------------------------
5413 class is : public CppUnit::TestFixture
5415 ::osl::FileBase::RC nError1, nError2;
5417 public:
5418 // initialization
5419 void setUp( )
5421 // create a tempfile in $TEMP/tmpname.
5422 createTestFile( aTmpName6 );
5425 void tearDown( )
5427 // remove the tempfile in $TEMP/tmpname.
5428 deleteTestFile( aTmpName6 );
5431 // test code.
5432 void is_001( )
5434 ::osl::DirectoryItem rItem; //constructor
5436 CPPUNIT_ASSERT_MESSAGE( "test for is function: use an uninitialized instance.",
5437 !rItem.is( ) );
5440 void is_002( )
5442 ::osl::DirectoryItem rItem; //constructor
5443 //get the DirectoryItem.
5444 nError1 = ::osl::DirectoryItem::get( aTmpName6, rItem );
5445 CPPUNIT_ASSERT( FileBase::E_None == nError1 );
5447 CPPUNIT_ASSERT_MESSAGE( "test for is function: use an uninitialized instance.",
5448 ( sal_True == rItem.is( ) ) );
5451 CPPUNIT_TEST_SUITE( is );
5452 CPPUNIT_TEST( is_001 );
5453 CPPUNIT_TEST( is_002 );
5454 CPPUNIT_TEST_SUITE_END( );
5455 };// class is
5457 //---------------------------------------------------------------------
5458 // testing the method
5459 // static inline RC get( const ::rtl::OUString& ustrFileURL, DirectoryItem& rItem )
5460 //---------------------------------------------------------------------
5461 class get : public CppUnit::TestFixture
5463 ::osl::FileBase::RC nError1, nError2;
5465 public:
5466 // initialization
5467 void setUp( )
5469 // create a tempfile in $TEMP/tmpname.
5470 createTestFile( aTmpName6 );
5473 void tearDown( )
5475 // remove the tempfile in $TEMP/tmpname.
5476 deleteTestFile( aTmpName6 );
5479 // test code.
5480 void get_001( )
5482 ::osl::DirectoryItem rItem; //constructor
5483 //get the DirectoryItem.
5484 nError2 = ::osl::DirectoryItem::get( aTmpName6, rItem );
5486 //check the file name
5487 ::osl::FileStatus rFileStatus( FileStatusMask_FileName );
5488 nError1 = rItem.getFileStatus( rFileStatus );
5489 CPPUNIT_ASSERT( nError1 == FileBase::E_None );
5491 CPPUNIT_ASSERT_MESSAGE( "test for get function: use copy constructor to get an item and check filename.",
5492 ( ::osl::FileBase::E_None == nError2 ) &&
5493 ( sal_True == compareFileName( rFileStatus.getFileName( ), aTmpName2 ) ) );
5496 void get_002( )
5498 ::osl::DirectoryItem rItem;
5499 //get the DirectoryItem.
5500 nError1 = ::osl::DirectoryItem::get( aSysPath1, rItem );
5502 CPPUNIT_ASSERT_MESSAGE( "test for get function: use a system name instead of a URL.",
5503 FileBase::E_INVAL == nError1 );
5506 void get_003( )
5508 ::osl::DirectoryItem rItem;
5509 //get the DirectoryItem.
5510 nError1 = ::osl::DirectoryItem::get( aTmpName3, rItem );
5512 CPPUNIT_ASSERT_MESSAGE( "test for get function: use a non existed file URL.",
5513 FileBase::E_NOENT == nError1 );
5516 CPPUNIT_TEST_SUITE( get );
5517 CPPUNIT_TEST( get_001 );
5518 CPPUNIT_TEST( get_002 );
5519 CPPUNIT_TEST( get_003 );
5520 CPPUNIT_TEST_SUITE_END( );
5521 };// class get
5523 //---------------------------------------------------------------------
5524 // testing the method
5525 // inline RC getFileStatus( FileStatus& rStatus )
5526 //---------------------------------------------------------------------
5527 class getFileStatus : public CppUnit::TestFixture
5529 ::osl::FileBase::RC nError1, nError2;
5531 public:
5532 // initialization
5533 void setUp( )
5535 // create a tempfile in $TEMP/tmpdir/tmpname.
5536 createTestDirectory( aTmpName3 );
5537 createTestFile( aTmpName4 );
5540 void tearDown( )
5542 // remove the tempfile in $TEMP/tmpdir/tmpname.
5543 deleteTestFile( aTmpName4 );
5544 deleteTestDirectory( aTmpName3 );
5547 // test code.
5548 void getFileStatus_001( )
5550 ::osl::DirectoryItem rItem; //constructor
5551 //get the DirectoryItem.
5552 nError1 = ::osl::DirectoryItem::get( aTmpName4, rItem );
5553 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
5555 //check the file name
5556 ::osl::FileStatus rFileStatus( FileStatusMask_FileName );
5557 nError2 = rItem.getFileStatus( rFileStatus );
5559 CPPUNIT_ASSERT_MESSAGE( "test for getFileStatus function: get file status and check filename",
5560 ( ::osl::FileBase::E_None == nError2 ) &&
5561 ( sal_True == compareFileName( rFileStatus.getFileName( ), aTmpName2 ) ) );
5564 void getFileStatus_002( )
5566 ::osl::DirectoryItem rItem; //constructor
5567 //get the DirectoryItem.
5568 nError1 = ::osl::DirectoryItem::get( aTmpName6, rItem );
5570 //check the file name
5571 ::osl::FileStatus rFileStatus( FileStatusMask_FileName );
5572 nError2 = rItem.getFileStatus( rFileStatus );
5574 CPPUNIT_ASSERT_MESSAGE( "test for getFileStatus function: file not existed",
5575 ( ::osl::FileBase::E_INVAL == nError2 ) );
5578 void getFileStatus_003( )
5580 ::osl::DirectoryItem rItem; //constructor
5581 //get the DirectoryItem.
5582 nError1 = ::osl::DirectoryItem::get( aTmpName3, rItem );
5583 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
5585 //check the file name
5586 ::osl::FileStatus rFileStatus( FileStatusMask_FileName );
5587 nError2 = rItem.getFileStatus( rFileStatus );
5589 CPPUNIT_ASSERT_MESSAGE( "test for getFileStatus function: get directory information",
5590 ( ::osl::FileBase::E_None == nError2 ) &&
5591 ( sal_True == compareFileName( rFileStatus.getFileName( ), aTmpName1 ) ) );
5595 CPPUNIT_TEST_SUITE( getFileStatus );
5596 CPPUNIT_TEST( getFileStatus_001 );
5597 CPPUNIT_TEST( getFileStatus_002 );
5598 CPPUNIT_TEST( getFileStatus_003 );
5599 CPPUNIT_TEST_SUITE_END( );
5600 };// class getFileStatus
5604 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_DirectoryItem::ctors, "osl_DirectoryItem" );
5605 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_DirectoryItem::copy_assin_Ctors, "osl_DirectoryItem" );
5606 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_DirectoryItem::is, "osl_DirectoryItem" );
5607 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_DirectoryItem::get, "osl_DirectoryItem" );
5608 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_DirectoryItem::getFileStatus, "osl_DirectoryItem" );
5609 }// namespace osl_DirectoryItem
5612 //------------------------------------------------------------------------
5613 // Beginning of the test cases for Directory class
5614 //------------------------------------------------------------------------
5615 namespace osl_Directory
5617 //---------------------------------------------------------------------
5618 // testing the method
5619 // Directory( const ::rtl::OUString& strPath ): _pData( 0 ), _aPath( strPath )
5620 //---------------------------------------------------------------------
5621 class ctors : public CppUnit::TestFixture
5623 ::osl::FileBase::RC nError1, nError2;
5625 public:
5626 // initialization
5627 void setUp( )
5629 // create a tempfile in $TEMP/tmpdir/tmpname.
5630 createTestDirectory( aTmpName3 );
5631 createTestFile( aTmpName4 );
5634 void tearDown( )
5636 // remove the tempfile in $TEMP/tmpdir/tmpname.
5637 deleteTestFile( aTmpName4 );
5638 deleteTestDirectory( aTmpName3 );
5639 // LLA: t_print("tearDown done.\n");
5642 // test code.
5643 void ctors_001( )
5645 ::osl::Directory testDirectory( aTmpName3 ); //constructor
5647 //open a directory
5648 nError1 = testDirectory.open( );
5649 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
5650 //close a directory
5651 nError2 = testDirectory.close( );
5652 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError2 );
5654 CPPUNIT_ASSERT_MESSAGE( "test for ctors function: create an instance and check open and close",
5655 ( ::osl::FileBase::E_None == nError1 ) &&
5656 ( ::osl::FileBase::E_None == nError2 ) );
5659 void ctors_002( )
5661 ::osl::Directory testDirectory( aTmpName9 ); //constructor
5663 //open a directory
5664 nError1 = testDirectory.open( );
5665 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
5666 //close a directory
5667 nError2 = testDirectory.close( );
5668 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError2 );
5670 CPPUNIT_ASSERT_MESSAGE( "test for ctors function: relative URL, :-), it is also worked",
5671 ( ::osl::FileBase::E_None == nError1 ) &&
5672 ( ::osl::FileBase::E_None == nError2 ) );
5675 CPPUNIT_TEST_SUITE( ctors );
5676 CPPUNIT_TEST( ctors_001 );
5677 CPPUNIT_TEST( ctors_002 );
5678 CPPUNIT_TEST_SUITE_END( );
5679 };// class ctors
5681 //---------------------------------------------------------------------
5682 // testing the method
5683 // inline RC open()
5684 //---------------------------------------------------------------------
5685 class open : public CppUnit::TestFixture
5687 ::osl::FileBase::RC nError1, nError2;
5689 public:
5690 // initialization
5691 void setUp( )
5693 // create a tempfile in $TEMP/tmpdir/tmpname.
5694 createTestDirectory( aTmpName3 );
5695 createTestFile( aTmpName4 );
5698 void tearDown( )
5700 // remove the tempfile in $TEMP/tmpdir/tmpname.
5701 deleteTestFile( aTmpName4 );
5702 deleteTestDirectory( aTmpName3 );
5705 // test code.
5706 void open_001( )
5708 ::osl::Directory testDirectory( aTmpName3 ); //constructor
5710 //open a directory
5711 nError1 = testDirectory.open( );
5712 //check if directory is opened.
5713 sal_Bool bOk = testDirectory.isOpen( );
5714 //close a directory
5715 nError2 = testDirectory.close( );
5717 CPPUNIT_ASSERT_MESSAGE( "test for open function: open a directory and check for open",
5718 ( sal_True == bOk ) &&
5719 ( ::osl::FileBase::E_None == nError1 ) &&
5720 ( ::osl::FileBase::E_None == nError2 ) );
5723 void open_002( )
5725 ::osl::Directory testDirectory( aTmpName6 ); //constructor
5727 //open a directory
5728 nError1 = testDirectory.open( );
5729 if ( ::osl::FileBase::E_None == nError1 )
5731 nError2 = testDirectory.close( );
5732 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError2 );
5735 CPPUNIT_ASSERT_MESSAGE( "test for open function: open a file that is not existed",
5736 ( ::osl::FileBase::E_NOENT == nError1 ) );
5739 void open_003( )
5741 ::osl::Directory testDirectory( aUserDirectorySys ); //constructor
5743 //open a directory
5744 nError1 = testDirectory.open( );
5745 if ( ::osl::FileBase::E_None == nError1 )
5747 nError2 = testDirectory.close( );
5748 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError2 );
5751 CPPUNIT_ASSERT_MESSAGE( "test for open function: using system path",
5752 ( ::osl::FileBase::E_INVAL == nError1 ) );
5755 void open_004( )
5757 ::osl::Directory testDirectory( aTmpName4 ); //constructor
5759 //open a directory
5760 nError1 = testDirectory.open( );
5761 if ( ::osl::FileBase::E_None == nError1 )
5763 nError2 = testDirectory.close( );
5764 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError2 );
5767 CPPUNIT_ASSERT_MESSAGE( "test for open function: open a file instead of a directory",
5768 ( ::osl::FileBase::E_NOTDIR == nError1 ) || ( ::osl::FileBase::E_ACCES ) );
5771 CPPUNIT_TEST_SUITE( open );
5772 CPPUNIT_TEST( open_001 );
5773 CPPUNIT_TEST( open_002 );
5774 CPPUNIT_TEST( open_003 );
5775 CPPUNIT_TEST( open_004 );
5776 CPPUNIT_TEST_SUITE_END( );
5777 };// class open
5779 //---------------------------------------------------------------------
5780 // testing the method
5781 // inline sal_Bool isOpen() { return _pData != NULL; };
5782 //---------------------------------------------------------------------
5783 class isOpen : public CppUnit::TestFixture
5785 ::osl::FileBase::RC nError1, nError2;
5787 public:
5788 // initialization
5789 void setUp( )
5791 // create a tempfile in $TEMP/tmpdir/tmpname.
5792 createTestDirectory( aTmpName3 );
5793 createTestFile( aTmpName4 );
5796 void tearDown( )
5798 // remove the tempfile in $TEMP/tmpdir/tmpname.
5799 deleteTestFile( aTmpName4 );
5800 deleteTestDirectory( aTmpName3 );
5803 // test code.
5804 void isOpen_001( )
5806 ::osl::Directory testDirectory( aTmpName3 ); //constructor
5808 //open a directory
5809 nError1 = testDirectory.open( );
5810 //check if directory is opened.
5811 sal_Bool bOk = testDirectory.isOpen( );
5812 //close a directory
5813 nError2 = testDirectory.close( );
5815 CPPUNIT_ASSERT_MESSAGE( "test for isOpen function: open a directory and check for open",
5816 ( sal_True == bOk ) );
5819 void isOpen_002( )
5821 ::osl::Directory testDirectory( aTmpName3 ); //constructor
5823 //check if directory is opened.
5824 sal_Bool bOk = testDirectory.isOpen( );
5826 CPPUNIT_ASSERT_MESSAGE( "test for isOpen function: do not open a directory and check for open",
5827 !( sal_True == bOk ) );
5830 CPPUNIT_TEST_SUITE( isOpen );
5831 CPPUNIT_TEST( isOpen_001 );
5832 CPPUNIT_TEST( isOpen_002 );
5833 CPPUNIT_TEST_SUITE_END( );
5834 };// class isOpen
5836 //---------------------------------------------------------------------
5837 // testing the method
5838 // inline RC close()
5839 //---------------------------------------------------------------------
5840 class close : public CppUnit::TestFixture
5842 ::osl::FileBase::RC nError1, nError2;
5844 public:
5845 // initialization
5846 void setUp( )
5848 // create a tempdirectory : $TEMP/tmpdir.
5849 createTestDirectory( aTmpName3 );
5852 void tearDown( )
5854 // remove a tempdirectory : $TEMP/tmpdir.
5855 deleteTestDirectory( aTmpName3 );
5858 // test code.
5859 void close_001( )
5861 ::osl::Directory testDirectory( aTmpName3 ); //constructor
5863 //open a directory
5864 nError1 = testDirectory.open( );
5865 //close a directory
5866 nError2 = testDirectory.close( );
5867 //check if directory is opened.
5868 sal_Bool bOk = testDirectory.isOpen( );
5870 CPPUNIT_ASSERT_MESSAGE( "test for isOpen function: close a directory and check for open",
5871 !( sal_True == bOk ) );
5874 void close_002( )
5876 ::osl::Directory testDirectory( aTmpName3 ); //constructor
5878 //close a directory
5879 nError1 = testDirectory.close( );
5881 CPPUNIT_ASSERT_MESSAGE( "test for isOpen function: close a not opened directory",
5882 ( ::osl::FileBase::E_BADF == nError1 ) );
5886 CPPUNIT_TEST_SUITE( close );
5887 CPPUNIT_TEST( close_001 );
5888 CPPUNIT_TEST( close_002 );
5889 CPPUNIT_TEST_SUITE_END( );
5890 };// class close
5892 //---------------------------------------------------------------------
5893 // testing the method
5894 // inline RC reset()
5895 //---------------------------------------------------------------------
5896 class reset : public CppUnit::TestFixture
5898 ::osl::FileBase::RC nError1, nError2;
5899 ::osl::DirectoryItem rItem;
5901 public:
5902 // initialization
5903 void setUp( )
5905 // create a tempdirectory : $TEMP/tmpdir.
5906 createTestDirectory( aTmpName3 );
5907 // create three files : $TEMP/tmpdir/tmpname, $TEMP/tmpdir/tmpdir, $TEMP/tmpdir/hiddenfile,
5908 createTestFile( aTmpName3, aTmpName2);
5909 createTestFile( aTmpName3, aTmpName1);
5910 createTestFile( aTmpName3, aHidURL1);
5913 void tearDown( )
5915 // remove three files : $TEMP/tmpdir/tmpname, $TEMP/tmpdir/tmpdir, $TEMP/tmpdir/hiddenfile,
5916 deleteTestFile( aTmpName3, aHidURL1);
5917 deleteTestFile( aTmpName3, aTmpName1);
5918 deleteTestFile( aTmpName3, aTmpName2);
5919 // remove a tempdirectory : $TEMP/tmpdir.
5920 deleteTestDirectory( aTmpName3 );
5923 // test code.
5924 void reset_001( )
5926 ::osl::Directory testDirectory( aTmpName3 ); //constructor
5928 //open a directory
5929 nError1 = testDirectory.open( );
5930 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
5931 //get first Item
5932 nError1 = testDirectory.getNextItem( rItem, 1 );
5933 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
5934 //get second Item
5935 //mindy: nError1 = testDirectory.getNextItem( rItem, 0 );
5936 //mindy: CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
5938 //reset enumeration
5939 nError2 = testDirectory.reset( );
5940 //get reseted Item, if reset does not work, getNextItem() should return the second Item (aTmpName1)
5941 nError1 = testDirectory.getNextItem( rItem, 0 );
5942 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
5944 //check the file name
5945 ::osl::FileStatus rFileStatus( FileStatusMask_FileName );
5946 nError1 = rItem.getFileStatus( rFileStatus );
5947 //close a directory
5948 nError1 = testDirectory.close( );
5949 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
5951 sal_Bool bOK1,bOK2;
5952 bOK1 = compareFileName( rFileStatus.getFileName( ), aTmpName2 );
5953 bOK2 = compareFileName( rFileStatus.getFileName( ), aHidURL1 );
5955 CPPUNIT_ASSERT_MESSAGE( "test for reset function: get two directory item, reset it, then get again, check the filename",
5956 ( ::osl::FileBase::E_None == nError2 ) &&
5957 ( sal_True == bOK1 || bOK2 ) );
5960 void reset_002( )
5962 ::osl::Directory testDirectory( aTmpName6 ); //constructor
5964 //close a directory
5965 nError1 = testDirectory.reset( );
5967 CPPUNIT_ASSERT_MESSAGE( "test for reset function: reset a non existed directory",
5968 ( ::osl::FileBase::E_NOENT == nError1 ) );
5972 void reset_003( )
5974 ::osl::Directory testDirectory( aTmpName4 ); //constructor
5976 //close a directory
5977 nError1 = testDirectory.reset( );
5979 CPPUNIT_ASSERT_MESSAGE( "test for reset function: reset a file instead of a directory",
5980 ( ::osl::FileBase::E_NOTDIR == nError1 ) || ( ::osl::FileBase::E_NOENT == nError1 ) );
5983 void reset_004( )
5985 ::osl::Directory testDirectory( aUserDirectorySys ); //constructor
5987 //close a directory
5988 nError1 = testDirectory.reset( );
5990 CPPUNIT_ASSERT_MESSAGE( "test for reset function: use a system path",
5991 ( ::osl::FileBase::E_INVAL == nError1 ) );
5994 CPPUNIT_TEST_SUITE( reset );
5995 CPPUNIT_TEST( reset_001 );
5996 CPPUNIT_TEST( reset_002 );
5997 CPPUNIT_TEST( reset_003 );
5998 CPPUNIT_TEST( reset_004 );
5999 CPPUNIT_TEST_SUITE_END( );
6000 };// class reset
6002 //---------------------------------------------------------------------
6003 // testing the method
6004 // inline RC getNextItem( DirectoryItem& rItem, sal_uInt32 nHint = 0 )
6005 //---------------------------------------------------------------------
6006 class getNextItem : public CppUnit::TestFixture
6008 ::osl::FileBase::RC nError1, nError2;
6009 ::osl::DirectoryItem rItem;
6011 public:
6012 // initialization
6013 void setUp( )
6015 // create a tempdirectory : $TEMP/tmpdir.
6016 createTestDirectory( aTmpName3 );
6017 // create three files : $TEMP/tmpdir/tmpname, $TEMP/tmpdir/tmpdir, $TEMP/tmpdir/hiddenfile,
6018 createTestFile( aTmpName3, aTmpName2 );
6019 createTestFile( aTmpName3, aTmpName1 );
6020 createTestFile( aTmpName3, aHidURL1 );
6024 void tearDown( )
6026 // remove three files : $TEMP/tmpdir/tmpname, $TEMP/tmpdir/tmpdir, $TEMP/tmpdir/hiddenfile,
6027 deleteTestFile( aTmpName3, aHidURL1 );
6028 deleteTestFile( aTmpName3, aTmpName1 );
6029 deleteTestFile( aTmpName3, aTmpName2 );
6030 // remove a tempdirectory : $TEMP/tmpdir.
6031 deleteTestDirectory( aTmpName3 );
6034 // test code.
6035 void getNextItem_001( )
6037 ::osl::Directory testDirectory( aTmpName3 ); //constructor
6039 //open a directory
6040 nError1 = testDirectory.open( );
6041 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
6043 //check the file name
6044 ::rtl::OUString strFilename;
6045 sal_Bool bOk1 = sal_False;
6046 sal_Bool bOk2 = sal_False;
6047 sal_Bool bOk3 = sal_False;
6048 ::osl::FileStatus rFileStatus( FileStatusMask_FileName );
6049 for ( int nCount = 0; nCount < 3; nCount++ )
6051 //get three Items
6052 nError1 = testDirectory.getNextItem( rItem, 2 );
6053 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
6054 nError1 = rItem.getFileStatus( rFileStatus );
6055 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
6056 switch ( nCount )
6058 case 0: bOk1 = compareFileName( rFileStatus.getFileName( ), aTmpName2 ) || compareFileName( rFileStatus.getFileName( ), aHidURL1);
6059 break;
6060 case 1: bOk2 = compareFileName( rFileStatus.getFileName( ), aTmpName1 );
6061 break;
6062 case 2: bOk3 = compareFileName( rFileStatus.getFileName( ), aHidURL1) || compareFileName( rFileStatus.getFileName( ), aTmpName2 );
6066 //close a directory
6067 nError1 = testDirectory.close( );
6068 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
6070 CPPUNIT_ASSERT_MESSAGE( "test for getNextItem function: retrive three items and check their names.",
6071 ( sal_True == bOk1 ) && ( sal_True == bOk2 ) && ( sal_True == bOk3 ) );
6074 void getNextItem_002( )
6076 ::osl::Directory testDirectory( aTmpName3 ); //constructor
6077 nError1 = testDirectory.getNextItem( rItem );
6079 CPPUNIT_ASSERT_MESSAGE( "test for getNextItem function: retrive an item in a directory which is not opened, also test for nHint's default value.",
6080 ( ::osl::FileBase::E_INVAL == nError1 ) );
6083 void getNextItem_003( )
6085 ::osl::Directory testDirectory( aTmpName3 ); //constructor
6087 //open a directory
6088 nError1 = testDirectory.open( );
6089 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
6091 for ( int nCount = 0; nCount < 4; nCount++ )
6093 nError2 = testDirectory.getNextItem( rItem, 3 );
6096 //close a directory
6097 nError1 = testDirectory.close( );
6098 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
6100 CPPUNIT_ASSERT_MESSAGE( "test for getNextItem function: retrive 4 times in a directory which contain only 3 files.",
6101 ( ::osl::FileBase::E_NOENT == nError2 ) );
6104 void getNextItem_004( )
6106 //create a link file(can not on Windows), then check if getNextItem can get it.
6107 #ifdef UNX
6108 sal_Bool bOK = sal_False;
6109 ::rtl::OUString aUStr_LnkFileSys( aTempDirectorySys ), aUStr_SrcFileSys( aTempDirectorySys );
6110 ( ( aUStr_LnkFileSys += aSlashURL ) += getCurrentPID( ) ) += ::rtl::OUString::createFromAscii("/tmpdir/link.file");
6111 ( ( aUStr_SrcFileSys += aSlashURL ) += getCurrentPID( ) ) += ::rtl::OUString::createFromAscii("/tmpdir/tmpname");
6112 rtl::OString strLinkFileName, strSrcFileName;
6113 strLinkFileName = OUStringToOString( aUStr_LnkFileSys, RTL_TEXTENCODING_ASCII_US );
6114 strSrcFileName = OUStringToOString( aUStr_SrcFileSys, RTL_TEXTENCODING_ASCII_US );
6116 //create a link file and link it to file "/tmp/PID/tmpdir/tmpname"
6117 sal_Int32 fd = symlink( strSrcFileName.getStr(), strLinkFileName.getStr() );
6118 CPPUNIT_ASSERT( fd == 0 );
6119 ::osl::Directory testDirectory( aTmpName3 );
6121 //open a directory
6122 nError1 = testDirectory.open( );
6123 ::rtl::OUString aFileName = ::rtl::OUString::createFromAscii("link.file");
6125 while (1) {
6126 nError1 = testDirectory.getNextItem( rItem, 4 );
6127 if (::osl::FileBase::E_None == nError1) {
6128 ::osl::FileStatus rFileStatus( FileStatusMask_FileName | FileStatusMask_Type );
6129 rItem.getFileStatus( rFileStatus );
6130 if ( compareFileName( rFileStatus.getFileName( ), aFileName) == sal_True )
6132 if ( FileStatus::Link == rFileStatus.getFileType( ))
6134 bOK = sal_True;
6135 break;
6139 else
6140 break;
6142 fd = std::remove( strLinkFileName.getStr() );
6143 CPPUNIT_ASSERT_MESSAGE( "remove link file failed", fd == 0 );
6144 CPPUNIT_ASSERT_MESSAGE( "test for getNextItem function: check if can retrieve the link file name",
6145 ( bOK == sal_True ) );
6146 #endif
6149 CPPUNIT_TEST_SUITE( getNextItem );
6150 CPPUNIT_TEST( getNextItem_001 );
6151 CPPUNIT_TEST( getNextItem_002 );
6152 CPPUNIT_TEST( getNextItem_003 );
6153 CPPUNIT_TEST( getNextItem_004 );
6154 CPPUNIT_TEST_SUITE_END( );
6155 };// class getNextItem
6157 //---------------------------------------------------------------------
6158 // testing the method
6159 // inline static RC getVolumeInfo( const ::rtl::OUString& ustrDirectoryURL, VolumeInfo& rInfo )
6160 //---------------------------------------------------------------------
6161 class getVolumeInfo : public CppUnit::TestFixture
6163 ::osl::FileBase::RC nError1, nError2;
6165 public:
6167 // test code.
6168 void checkValidMask(osl::VolumeInfo const& _aVolumeInfo, sal_Int32 _nMask)
6170 if (_nMask == VolumeInfoMask_FileSystemName)
6172 //get file system name
6173 ::rtl::OUString aFileSysName( aNullURL );
6174 aFileSysName = _aVolumeInfo.getFileSystemName( );
6176 sal_Bool bRes2 = compareFileName( aFileSysName, aNullURL );
6177 CPPUNIT_ASSERT_MESSAGE( "test for getVolumeInfo function: getVolumeInfo of root directory.",
6178 ( osl::FileBase::E_None == nError1 ) &&
6179 ( sal_False == bRes2 ) );
6181 if (_nMask == VolumeInfoMask_Attributes)
6183 sal_Bool b1 = _aVolumeInfo.getRemoteFlag();
6184 sal_Bool b2 = _aVolumeInfo.getRemoveableFlag();
6185 sal_Bool b3 = _aVolumeInfo.getCompactDiscFlag();
6186 sal_Bool b4 = _aVolumeInfo.getFloppyDiskFlag();
6187 sal_Bool b5 = _aVolumeInfo.getFixedDiskFlag();
6188 sal_Bool b6 = _aVolumeInfo.getRAMDiskFlag();
6190 rtl::OString sAttr;
6191 if (b1) sAttr = "Remote";
6192 if (b2) sAttr += " Removeable";
6193 if (b3) sAttr += " CDROM";
6194 if (b4) sAttr += " Floppy";
6195 if (b5) sAttr += " FixedDisk";
6196 if (b6) sAttr += " RAMDisk";
6198 t_print("Attributes: %s\n", sAttr.getStr() );
6200 if (_nMask == VolumeInfoMask_TotalSpace)
6202 // within Linux, df / * 1024 bytes is the result
6203 sal_uInt64 nSize = _aVolumeInfo.getTotalSpace();
6204 t_print("Total space: %lld\n", nSize);
6206 if (_nMask == VolumeInfoMask_UsedSpace)
6208 sal_uInt64 nSize = _aVolumeInfo.getUsedSpace();
6209 t_print(" Used space: %lld\n", nSize);
6211 if (_nMask == VolumeInfoMask_FreeSpace)
6213 sal_uInt64 nSize = _aVolumeInfo.getFreeSpace();
6214 t_print(" Free space: %lld\n", nSize);
6216 if (_nMask == VolumeInfoMask_MaxNameLength)
6218 sal_uInt32 nLength = _aVolumeInfo.getMaxNameLength();
6219 t_print("max name length: %ld\n", nLength);
6221 if (_nMask == VolumeInfoMask_MaxPathLength)
6223 sal_uInt32 nLength = _aVolumeInfo.getMaxPathLength();
6224 t_print("max path length: %ld\n", nLength);
6226 if (_nMask == VolumeInfoMask_FileSystemCaseHandling)
6228 bool bIsCase = _aVolumeInfo.isCaseSensitiveFileSystem();
6229 t_print("filesystem case sensitive: %s\n", bIsCase ? "yes" : "no");
6233 void checkVolumeInfo(sal_Int32 _nMask)
6235 ::osl::VolumeInfo aVolumeInfo( _nMask );
6236 //call getVolumeInfo here
6237 nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
6238 // LLA: IMHO it's not a bug, if VolumeInfo is not valid, it's a feature
6239 // LLA: CPPUNIT_ASSERT_MESSAGE("mask is not valid", sal_True == aVolumeInfo.isValid( _nMask ) );
6240 if (aVolumeInfo.isValid( _nMask))
6242 checkValidMask(aVolumeInfo, _nMask);
6247 void getVolumeInfo_001_1( )
6249 sal_Int32 mask = VolumeInfoMask_FileSystemName;
6250 checkVolumeInfo(mask);
6252 void getVolumeInfo_001_2( )
6254 sal_Int32 mask = VolumeInfoMask_Attributes;
6255 checkVolumeInfo(mask);
6257 void getVolumeInfo_001_3( )
6259 sal_Int32 mask = VolumeInfoMask_TotalSpace;
6260 checkVolumeInfo(mask);
6262 void getVolumeInfo_001_4( )
6264 sal_Int32 mask = VolumeInfoMask_UsedSpace;
6265 checkVolumeInfo(mask);
6267 void getVolumeInfo_001_5( )
6269 sal_Int32 mask = VolumeInfoMask_FreeSpace;
6270 checkVolumeInfo(mask);
6272 void getVolumeInfo_001_6( )
6274 sal_Int32 mask = VolumeInfoMask_MaxNameLength;
6275 checkVolumeInfo(mask);
6277 void getVolumeInfo_001_7( )
6279 sal_Int32 mask = VolumeInfoMask_MaxPathLength;
6280 checkVolumeInfo(mask);
6282 void getVolumeInfo_001_8( )
6284 sal_Int32 mask = VolumeInfoMask_FileSystemCaseHandling;
6285 checkVolumeInfo(mask);
6288 void getVolumeInfo_002( )
6290 sal_Int32 mask = VolumeInfoMask_FileSystemName;
6291 ::osl::VolumeInfo aVolumeInfo( mask );
6292 //call getVolumeInfo here
6294 // LLA: rtl::OUString aRootSysURL;
6295 // LLA: nError1 = osl::File::getFileURLFromSystemPath(aRootSys, aRootSysURL);
6296 // LLA:
6297 // LLA: CPPUNIT_ASSERT_MESSAGE( "can't convert root path to file url",
6298 // LLA: ( osl::FileBase::E_NONE == nError1 ) );
6300 nError1 = ::osl::Directory::getVolumeInfo( aRootSys, aVolumeInfo );
6302 CPPUNIT_ASSERT_MESSAGE( "test for getVolumeInfo function: use system path as parameter.",
6303 ( osl::FileBase::E_INVAL == nError1 ) );
6306 void getVolumeInfo_003( )
6308 sal_Int32 mask = VolumeInfoMask_FileSystemName;
6309 ::osl::VolumeInfo aVolumeInfo( mask );
6310 //call getVolumeInfo here
6311 nError1 = ::osl::Directory::getVolumeInfo( aTmpName3, aVolumeInfo );
6313 // LLA: in Windows, it reply no error, it did not pass in (W32).
6314 #ifdef UNX
6315 CPPUNIT_ASSERT_MESSAGE( "test for getVolumeInfo function: non-existence test. ",
6316 ( osl::FileBase::E_NOENT == nError1 ) );
6317 #endif
6320 CPPUNIT_TEST_SUITE( getVolumeInfo );
6321 CPPUNIT_TEST( getVolumeInfo_001_1 );
6322 CPPUNIT_TEST( getVolumeInfo_001_2 );
6323 CPPUNIT_TEST( getVolumeInfo_001_3 );
6324 CPPUNIT_TEST( getVolumeInfo_001_4 );
6325 CPPUNIT_TEST( getVolumeInfo_001_5 );
6326 CPPUNIT_TEST( getVolumeInfo_001_6 );
6327 CPPUNIT_TEST( getVolumeInfo_001_7 );
6328 CPPUNIT_TEST( getVolumeInfo_001_8 );
6329 CPPUNIT_TEST( getVolumeInfo_002 );
6330 CPPUNIT_TEST( getVolumeInfo_003 );
6331 CPPUNIT_TEST_SUITE_END( );
6332 };// class getVolumeInfo
6335 //---------------------------------------------------------------------
6336 // testing the method
6337 // inline static RC create( const ::rtl::OUString& ustrDirectoryURL )
6338 //---------------------------------------------------------------------
6339 class create : public CppUnit::TestFixture
6341 ::osl::FileBase::RC nError1, nError2;
6343 public:
6345 // test code.
6346 void create_001( )
6348 //create directory in $TEMP/tmpdir
6349 nError1 = ::osl::Directory::create( aTmpName3 );
6350 //check for existence
6351 nError2 = ::osl::Directory::create( aTmpName3 );
6352 //remove it
6353 deleteTestDirectory( aTmpName3 );
6355 CPPUNIT_ASSERT_MESSAGE( "test for create function: create a directory and check its existence.",
6356 ( osl::FileBase::E_None == nError1 ) &&
6357 ( osl::FileBase::E_EXIST== nError2 ) );
6360 void create_002( )
6362 //create directory in /tmpname
6363 nError1 = ::osl::Directory::create( aTmpName7 );
6364 #if defined (WNT )
6365 nError1 = osl::FileBase::E_ACCES; /// in Windows, you can create directory in c:/ any way.
6366 deleteTestDirectory( aTmpName7 );
6367 #endif
6369 CPPUNIT_ASSERT_MESSAGE( "test for create function: create a directory in root for access test.",
6370 ( osl::FileBase::E_ACCES == nError1 ) );
6373 void create_003( )
6375 //create directory in /tmpname
6376 nError1 = ::osl::Directory::create( aSysPath1 );
6378 CPPUNIT_ASSERT_MESSAGE( "test for create function: create a directory using system path.",
6379 ( osl::FileBase::E_INVAL == nError1 ) );
6382 CPPUNIT_TEST_SUITE( create );
6383 CPPUNIT_TEST( create_001 );
6384 CPPUNIT_TEST( create_002 );
6385 CPPUNIT_TEST( create_003 );
6386 CPPUNIT_TEST_SUITE_END( );
6387 };// class create
6389 //---------------------------------------------------------------------
6390 // testing the method
6391 // inline static RC remove( const ::rtl::OUString& ustrDirectoryURL )
6392 //---------------------------------------------------------------------
6393 class remove : public CppUnit::TestFixture
6395 ::osl::FileBase::RC nError1, nError2;
6397 public:
6399 // test code.
6400 void remove_001( )
6402 //create directory in $TEMP/tmpdir
6403 nError1 = ::osl::Directory::create( aTmpName3 );
6404 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
6405 //remove it
6406 nError1 = ::osl::Directory::remove( aTmpName3 );
6407 //check for existence
6408 ::osl::Directory rDirectory( aTmpName3 );
6409 nError2 = rDirectory.open( );
6411 CPPUNIT_ASSERT_MESSAGE( "test for remove function: remove a directory and check its existence.",
6412 ( osl::FileBase::E_None == nError1 ) &&
6413 ( osl::FileBase::E_NOENT == nError2 ) );
6416 void remove_002( )
6418 //create directory in $TEMP/tmpdir
6419 nError1 = ::osl::Directory::create( aTmpName3 );
6420 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
6421 //try to remove it by system path
6422 nError1 = ::osl::Directory::remove( aSysPath3 );
6423 //check for existence
6424 ::osl::Directory rDirectory( aTmpName3 );
6425 nError2 = rDirectory.open( );
6426 if ( osl::FileBase::E_NOENT != nError2 )
6427 ::osl::Directory::remove( aTmpName3 );
6429 CPPUNIT_ASSERT_MESSAGE( "test for remove function: remove a directory by its system path, and check its existence.",
6430 ( osl::FileBase::E_INVAL == nError1 ) );
6433 void remove_003( )
6435 //try to remove a non-existed directory
6436 nError1 = ::osl::Directory::remove( aTmpName6 );
6438 CPPUNIT_ASSERT_MESSAGE( "test for remove function: try to remove a non-existed directory.",
6439 ( osl::FileBase::E_NOENT == nError1 ) );
6442 void remove_004( )
6444 createTestFile( aTmpName6 );
6445 sal_Bool bExist = ifFileExist( aTmpName6 );
6446 //try to remove file.
6447 nError1 = ::osl::Directory::remove( aTmpName6 );
6448 deleteTestFile( aTmpName6 );
6450 CPPUNIT_ASSERT_MESSAGE( "test for remove function: try to remove a file but not directory.",
6451 bExist == sal_True &&(( osl::FileBase::E_NOTDIR == nError1 ) || ( osl::FileBase::E_NOENT == nError1 )) );
6454 void remove_005( )
6456 createTestDirectory( aTmpName3 );
6457 createTestFile( aTmpName4 );
6458 nError1 = ::osl::Directory::remove( aTmpName3 );
6459 deleteTestFile( aTmpName4 );
6460 deleteTestDirectory( aTmpName3 );
6461 ::rtl::OUString suError = ::rtl::OUString::createFromAscii("test for remove function: try to remove a directory that is not empty.") + errorToStr( nError1 );
6462 #if defined ( SOLARIS )
6463 //on UNX, the implementation uses rmdir(), which EEXIST is thrown on Solaris when the directory is not empty, refer to: 'man -s 2 rmdir', while on linux, ENOTEMPTY is thrown.
6464 //EEXIST The directory contains entries other than those for "." and "..".
6465 t_print("#Solaris test\n");
6466 CPPUNIT_ASSERT_MESSAGE( suError, ( osl::FileBase::E_EXIST == nError1 ) );
6467 #else
6468 CPPUNIT_ASSERT_MESSAGE( suError, ( osl::FileBase::E_NOTEMPTY == nError1 ) );
6469 #endif
6472 CPPUNIT_TEST_SUITE( remove );
6473 CPPUNIT_TEST( remove_001 );
6474 CPPUNIT_TEST( remove_002 );
6475 CPPUNIT_TEST( remove_003 );
6476 CPPUNIT_TEST( remove_004 );
6477 CPPUNIT_TEST( remove_005 );
6478 CPPUNIT_TEST_SUITE_END( );
6479 };// class remove
6481 //########################################
6482 // TEST Directory::createPath
6483 //########################################
6485 #ifdef WNT
6486 # define PATH_BUFFER_SIZE MAX_PATH
6487 #else
6488 # define PATH_BUFFER_SIZE PATH_MAX
6489 #endif
6491 char TEST_PATH_POSTFIX[] = "hello/world";
6493 //########################################
6494 OUString get_test_path()
6496 OUString tmp;
6497 FileBase::RC rc = FileBase::getTempDirURL(tmp);
6499 CPPUNIT_ASSERT_MESSAGE
6501 "Test path creation failed",
6502 rc == FileBase::E_None
6505 OUStringBuffer b(tmp);
6506 if (tmp.lastIndexOf('/') != (tmp.getLength() - 1))
6507 b.appendAscii("/");
6509 b.appendAscii(TEST_PATH_POSTFIX);
6511 return b.makeStringAndClear();
6514 //########################################
6515 void rm_test_path(const OUString& path)
6517 sal_Unicode buffer[PATH_BUFFER_SIZE];
6518 rtl_copyMemory(buffer, path.getStr(), (path.getLength() + 1) * sizeof(sal_Unicode));
6520 sal_Int32 i = rtl_ustr_lastIndexOfChar(buffer, '/');
6521 if (i == path.getLength())
6522 buffer[i] = 0;
6524 Directory::remove(buffer);
6526 i = rtl_ustr_lastIndexOfChar(buffer, '/');
6527 buffer[i] = 0;
6528 Directory::remove(buffer);
6531 //########################################
6532 class DirCreatedObserver : public DirectoryCreationObserver
6534 public:
6535 DirCreatedObserver() : i(0)
6539 virtual void DirectoryCreated(const rtl::OUString& /*aDirectoryUrl*/)
6541 i++;
6544 int number_of_dirs_created() const
6546 return i;
6549 private:
6550 int i;
6554 //########################################
6555 class createPath : public CppUnit::TestFixture
6557 public:
6558 //##########################################
6559 createPath()
6562 //##########################################
6563 void with_relative_path()
6565 FileBase::RC rc = Directory::createPath(
6566 OUString::createFromAscii(TEST_PATH_POSTFIX));
6568 CPPUNIT_ASSERT_MESSAGE
6570 "osl_createDirectoryPath contract broken",
6571 rc == FileBase::E_INVAL
6575 //##########################################
6576 void without_callback()
6578 OUString tp_url = get_test_path();
6580 rm_test_path(tp_url);
6582 FileBase::RC rc = Directory::createPath(tp_url);
6584 CPPUNIT_ASSERT_MESSAGE
6586 "osl_createDirectoryPath failed",
6587 rc == FileBase::E_None
6591 //##########################################
6592 void with_callback()
6594 OUString tp_url = get_test_path();
6596 rm_test_path(tp_url);
6598 DirCreatedObserver* observer = new DirCreatedObserver;
6599 FileBase::RC rc = Directory::createPath(tp_url, observer);
6600 int nDirs = observer->number_of_dirs_created();
6601 delete observer;
6602 CPPUNIT_ASSERT_MESSAGE
6604 "osl_createDirectoryPath failed",
6605 (rc == FileBase::E_None) && (nDirs > 0)
6610 #ifdef WNT
6612 //##########################################
6613 char* get_unused_drive_letter()
6615 static char m_aBuff[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
6617 DWORD ld = GetLogicalDrives();
6618 DWORD i = 4;
6619 DWORD j = 2;
6621 while ((ld & i) && (i > 1))
6622 { i = i << 1; j++; }
6624 if (i > 2)
6625 return m_aBuff + j;
6627 return NULL;
6630 //##########################################
6631 void at_invalid_logical_drive()
6633 char* drv = get_unused_drive_letter();
6634 char buff[PATH_BUFFER_SIZE];
6635 rtl_zeroMemory(buff, sizeof(buff));
6637 strncpy(buff, drv, 1);
6638 strcat(buff, ":\\");
6639 strcat(buff, TEST_PATH_POSTFIX);
6641 OUString path = OUString::createFromAscii(buff);
6642 OUString tp_url;
6643 FileBase::getFileURLFromSystemPath(path, tp_url);
6645 FileBase::RC rc = Directory::createPath(tp_url);
6647 CPPUNIT_ASSERT_MESSAGE
6649 "osl_createDirectoryPath doesn't fail on unused logical drive letters",
6650 rc != FileBase::E_None
6654 //##########################################
6655 void with_UNC_path()
6658 OUString tp_unc = OUString::createFromAscii("\\\\Tra-1\\TRA_D\\hello\\world\\");
6659 OUString tp_url;
6660 FileBase::getFileURLFromSystemPath(tp_unc, tp_url);
6662 FileBase::RC rc = Directory::createPath(tp_url);
6664 CPPUNIT_ASSERT_MESSAGE
6666 "osl_createDirectoryPath fails with UNC path",
6667 rc == FileBase::E_None
6671 #endif /* WNT */
6673 CPPUNIT_TEST_SUITE(createPath);
6674 CPPUNIT_TEST(with_relative_path);
6675 CPPUNIT_TEST(without_callback);
6676 CPPUNIT_TEST(with_callback);
6677 #ifdef WNT
6678 CPPUNIT_TEST(at_invalid_logical_drive);
6680 // adapt the UNC path in method createDirectoryPath_with_UNC_path
6681 // in order to run this test successfully
6682 //CPPUNIT_TEST(with_UNC_path);
6683 #endif
6684 CPPUNIT_TEST_SUITE_END();
6686 }; // class createPath
6688 // -----------------------------------------------------------------------------
6689 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_Directory::ctors, "osl_Directory" );
6690 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_Directory::open, "osl_Directory" );
6691 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_Directory::isOpen, "osl_Directory" );
6692 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_Directory::close, "osl_Directory" );
6693 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_Directory::reset, "osl_Directory" );
6694 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_Directory::getNextItem, "osl_Directory" );
6695 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_Directory::getVolumeInfo, "osl_Directory" );
6696 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_Directory::create, "osl_Directory" );
6697 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_Directory::remove, "osl_Directory" );
6698 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_Directory::createPath, "osl_Directory" );
6699 }// namespace osl_Directory
6702 // -----------------------------------------------------------------------------
6703 // this macro creates an empty function, which will called by the RegisterAllFunctions()
6704 // to let the user the possibility to also register some functions by hand.
6705 // -----------------------------------------------------------------------------
6707 /// NOADDITIONAL;
6711 /** get Current PID.
6713 inline ::rtl::OUString getCurrentPID( )
6715 //~ Get current PID and turn it into OUString;
6716 int nPID = 0;
6717 #ifdef WNT
6718 nPID = GetCurrentProcessId();
6719 #else
6720 nPID = getpid();
6721 #endif
6722 return ( ::rtl::OUString::valueOf( ( long )nPID ) );
6726 /** Insert Current PID to the URL to avoid access violation between multiuser execution.
6728 inline void insertPID( ::rtl::OUString & pathname )
6730 //~ check if the path contain the temp directory, do nothing changes if not;
6731 if ( pathname.indexOf( aTempDirectoryURL ) && pathname.indexOf( aTempDirectorySys ) )
6732 return;
6734 //~ format pathname to TEMP/USERPID/URL style;
6735 if ( !pathname.indexOf( aTempDirectoryURL ) )
6737 ::rtl::OUString strPID( getCurrentPID( ) );
6738 ::rtl::OUString pathLeft = aTempDirectoryURL.copy( 0 );
6739 ::rtl::OUString pathRight = pathname.copy( aTempDirectoryURL.getLength( ) );
6740 pathname = pathLeft.copy( 0 );
6741 ( ( pathname += aSlashURL ) += strPID ) += pathRight;
6743 else
6745 ::rtl::OUString strPID( getCurrentPID( ) );
6746 ::rtl::OUString pathLeft = aTempDirectorySys.copy( 0 );
6747 ::rtl::OUString pathRight = pathname.copy( aTempDirectorySys.getLength( ) );
6748 pathname = pathLeft.copy( 0 );
6749 ( ( pathname += aSlashURL ) += strPID ) += pathRight;
6755 /** to do some initialized work, we replace the NOADDITIONAL macro with the initialize work which
6756 will check the file and directory existence. and set some variables for test use.
6757 to simplify the initialize work, we seperate it into UNIX section and Windows section, the main task
6758 of initialization is adapt all URL defined in osl_File_Const.h to TEMP/USERPID/URL style format,
6759 since there may be an instance that multiuser execute test at the same time, and the temp file
6760 may not be clean up in this case due to access right problem.
6762 void RegisterAdditionalFunctions( FktRegFuncPtr _pFunc )
6764 (void)_pFunc;
6765 t_print( "Initializing..." );
6767 //~ make sure the c:\temp exist, if not, create it.
6768 #if ( defined WNT )
6769 if ( checkDirectory( aTempDirectoryURL, osl_Check_Mode_Exist ) != sal_True ) {
6770 t_print( "\n#C:\\temp is not exist, now creating\n" );
6771 createTestDirectory( aTempDirectoryURL );
6773 #endif
6775 //~ make sure the c:\temp\PID or /tmp/PID exist, if not, create it. initialize the user directory.
6776 ( aUserDirectoryURL += aSlashURL ) += getCurrentPID( );
6777 ( aUserDirectorySys += aSlashURL ) += getCurrentPID( );
6779 if ( checkDirectory( aUserDirectoryURL, osl_Check_Mode_Exist ) != sal_True ) {
6780 createTestDirectory( aUserDirectoryURL );
6783 //~ adapt all URL to the TEMP/USERPID/URL format;
6784 insertPID( aCanURL1 );
6785 insertPID( aTmpName3 );
6786 insertPID( aTmpName4 );
6787 insertPID( aTmpName5 );
6788 insertPID( aTmpName6 );
6789 insertPID( aTmpName8 );
6790 insertPID( aTmpName9 );
6791 insertPID( aLnkURL1 );
6792 insertPID( aFifoSys );
6793 insertPID( aSysPath1 );
6794 insertPID( aSysPath2 );
6795 insertPID( aSysPath3 );
6796 insertPID( aSysPath4 );
6798 t_print( "Done.\n" );
6803 //~ do some clean up work after all test completed.
6804 class GlobalObject
6806 public:
6807 ~GlobalObject()
6811 //~ make sure the c:\temp\PID or /tmp/PID exist, if yes, delete it.
6812 t_print( "\n#Do some clean-ups ...\n" );
6813 if ( checkDirectory( aUserDirectoryURL, osl_Check_Mode_Exist ) == sal_True ) {
6814 deleteTestDirectory( aUserDirectoryURL );
6817 // LLA: t_print("after deleteTestDirectory\n");
6818 //~ special clean up task in Windows and Unix seperately;
6819 #if ( defined UNX ) || ( defined OS2 )
6820 //~ some clean up task for UNIX OS
6822 #else
6823 //~ some clean up task for Windows OS
6824 //~ check if some files are in the way, remove them if necessary.
6825 if ( ifFileExist( aTmpName6 ) == sal_True )
6826 deleteTestFile( aTmpName6 );
6827 if ( ifFileExist( aTmpName4 ) == sal_True )
6828 deleteTestFile( aTmpName4 );
6829 if ( checkDirectory( aTmpName4, osl_Check_Mode_Exist ) == sal_True )
6830 deleteTestDirectory( aTmpName4 );
6831 if ( ifFileExist( aTmpName3 ) == sal_True )
6832 deleteTestFile( aTmpName3 );
6833 if ( checkDirectory( aTmpName3, osl_Check_Mode_Exist ) == sal_True )
6834 deleteTestDirectory( aTmpName3 );
6836 ::rtl::OUString aUStr( aUserDirectoryURL );
6837 concatURL( aUStr, aHidURL1 );
6838 if ( ifFileExist( aUStr ) == sal_True )
6839 deleteTestFile( aUStr );
6841 ::rtl::OUString aUStr1( aRootURL );
6842 concatURL( aUStr1, aTmpName2 );
6843 if ( ifFileExist( aUStr1 ) == sal_True )
6844 deleteTestFile( aUStr1 );
6845 #endif
6848 catch (CppUnit::Exception &e)
6850 t_print("Exception caught in GlobalObject dtor(). Exception message: '%s'. Source line: %d\n", e.what(), e.sourceLine().lineNumber());
6852 catch (...)
6854 t_print("Exception caught (...) in GlobalObject dtor()\n");
6859 GlobalObject theGlobalObject;