LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sal/qa/osl/file - osl_File.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 648 2577 25.1 %
Date: 2013-07-09 Functions: 135 560 24.1 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : //------------------------------------------------------------------------
      21             : // include files
      22             : //------------------------------------------------------------------------
      23             : #include <sal/types.h>
      24             : #include <rtl/ustring.hxx>
      25             : #include <rtl/ustrbuf.hxx>
      26             : 
      27             : #include "osl/thread.h"
      28             : 
      29             : #include "rtl/ustrbuf.hxx"
      30             : #include <osl/file.hxx>
      31             : #include <osl/detail/file.h>
      32             : #include <osl_File_Const.h>
      33             : 
      34             : #include <cppunit/TestFixture.h>
      35             : #include <cppunit/extensions/HelperMacros.h>
      36             : #include <cppunit/plugin/TestPlugIn.h>
      37             : 
      38             : #include <boost/scoped_ptr.hpp>
      39             : 
      40             : #ifdef WNT
      41             : #include <windows.h>
      42             : #endif
      43             : 
      44             : using namespace osl;
      45             : 
      46             : using ::rtl::OUString;
      47             : using ::rtl::OUStringToOString;
      48             : using ::rtl::OString;
      49             : using ::rtl::OStringToOUString;
      50             : 
      51             : //------------------------------------------------------------------------
      52             : // helper functions
      53             : //------------------------------------------------------------------------
      54             : 
      55             : /** detailed wrong message.
      56             : */
      57           1 : inline ::rtl::OString errorToString( const ::osl::FileBase::RC _nError )
      58             : {
      59           1 :     ::rtl::OString sResult;
      60           1 :     switch ( _nError ) {
      61             :         case ::osl::FileBase::E_None:
      62           0 :             sResult = "Success";
      63           0 :             break;
      64             :         case ::osl::FileBase::E_PERM:
      65           0 :             sResult = "Operation not permitted";
      66           0 :             break;
      67             :         case ::osl::FileBase::E_NOENT:
      68           0 :             sResult = "No such file or directory";
      69           0 :             break;
      70             :         case ::osl::FileBase::E_EXIST:
      71           0 :             sResult = "Already Exist";
      72           0 :             break;
      73             :         case ::osl::FileBase::E_ACCES:
      74           0 :             sResult = "Permission denied";
      75           0 :             break;
      76             :         case ::osl::FileBase::E_INVAL:
      77           0 :             sResult = "The format of the parameters was not valid";
      78           0 :             break;
      79             :         case ::osl::FileBase::E_NOTDIR:
      80           0 :             sResult = "Not a directory";
      81           0 :             break;
      82             :         case ::osl::FileBase::E_ISDIR:
      83           0 :             sResult = "Is a directory";
      84           0 :             break;
      85             :         case ::osl::FileBase::E_BADF:
      86           0 :             sResult = "Bad file";
      87           0 :             break;
      88             :         case ::osl::FileBase::E_NOTEMPTY:
      89           1 :             sResult = "The directory is not empty";
      90           1 :             break;
      91             :         default:
      92           0 :             sResult = "Unknown Error";
      93           0 :             break;
      94             :     }
      95           1 :     return sResult;
      96             : }
      97             : 
      98           1 : rtl::OString errorToStr( ::osl::FileBase::RC const& nError)
      99             : {
     100           1 :     rtl::OString suBuf;
     101           1 :     suBuf += "The returned error is: " ;
     102           1 :     suBuf += errorToString(nError);
     103           1 :     suBuf += "!\n";
     104           1 :     return suBuf;
     105             : }
     106             : 
     107             : /** print a file type name.
     108             : */
     109             : inline void printFileType( const ::osl::FileStatus::Type nType )
     110             : {
     111             :     printf( "#printFileType# " );
     112             :     switch ( nType ) {
     113             :         case ::osl::FileStatus::Directory:
     114             :             printf( "This file is a: Directory.\n" );
     115             :             break;
     116             :         case ::osl::FileStatus::Volume:
     117             :             printf( "This file is a: volume device.\n" );
     118             :             break;
     119             :         case ::osl::FileStatus::Regular:
     120             :             printf( "This file is a: regular file.\n" );
     121             :             break;
     122             :         case ::osl::FileStatus::Fifo:
     123             :             printf( "This file is a: fifo.\n" );
     124             :             break;
     125             :         case ::osl::FileStatus::Socket:
     126             :             printf( "This file is a: socket.\n" );
     127             :             break;
     128             :         case ::osl::FileStatus::Link:
     129             :             printf( "This file is a: link file.\n" );
     130             :             break;
     131             :         case ::osl::FileStatus::Special:
     132             :             printf( "This file is a: special.\n" );
     133             :             break;
     134             :         case ::osl::FileStatus::Unknown:
     135             :             printf( "The file type is unknown %d \n", nType );
     136             :             break;
     137             :     }
     138             : }
     139             : 
     140             : /** print a file attributes.
     141             : */
     142             : inline void printFileAttributes( const sal_Int64 nAttributes )
     143             : {
     144             :     printf( "#printFileAttributes# This file is a: (" );
     145             :     if ( ( nAttributes | osl_File_Attribute_ReadOnly ) == nAttributes )
     146             :             printf( " ReadOnly " );
     147             :     if ( ( nAttributes | osl_File_Attribute_Hidden ) == nAttributes )
     148             :             printf( " Hidden " );
     149             :     if ( ( nAttributes | osl_File_Attribute_Executable ) == nAttributes )
     150             :             printf( " Executable " );
     151             :     if ( ( nAttributes | osl_File_Attribute_GrpWrite ) == nAttributes )
     152             :             printf( " GrpWrite " );
     153             :     if ( ( nAttributes | osl_File_Attribute_GrpRead ) == nAttributes )
     154             :             printf( " GrpRead " );
     155             :     if ( ( nAttributes | osl_File_Attribute_GrpExe ) == nAttributes )
     156             :             printf( " GrpExe " );
     157             :     if ( ( nAttributes | osl_File_Attribute_OwnWrite ) == nAttributes )
     158             :             printf( " OwnWrite " );
     159             :     if ( ( nAttributes | osl_File_Attribute_OwnRead ) == nAttributes )
     160             :             printf( " OwnRead " );
     161             :     if ( ( nAttributes | osl_File_Attribute_OwnExe ) == nAttributes )
     162             :             printf( " OwnExe " );
     163             :     if ( ( nAttributes | osl_File_Attribute_OthWrite ) == nAttributes )
     164             :             printf( " OthWrite " );
     165             :     if ( ( nAttributes | osl_File_Attribute_OthRead ) == nAttributes )
     166             :             printf( " OthRead " );
     167             :     if ( ( nAttributes | osl_File_Attribute_OthExe ) == nAttributes )
     168             :             printf( " OthExe " );
     169             :     printf( ") file!\n" );
     170             : }
     171             : 
     172             : /** print an output wrong message.
     173             : */
     174             : inline void printError( const ::osl::FileBase::RC nError )
     175             : {
     176             :     printf( "#printError# " );
     177             :     printf( "%s\n", errorToStr(nError).getStr() );
     178             : }
     179             : 
     180             : /** print an signed Integer Number.
     181             : */
     182             : inline void printInt( sal_Int64 i )
     183             : {
     184             :     printf( "#printInt_i64# " );
     185             :     printf( "The Integer64 is %" SAL_PRIdINT64 "\n", i);
     186             : }
     187             : 
     188             : /** print an unsigned Integer Number.
     189             : */
     190             : inline void printInt( sal_uInt64 i )
     191             : {
     192             :     printf( "#printInt_u64# " );
     193             :     printf( "The unsigned Integer64 is %" SAL_PRIuUINT64 "\n", i);
     194             : }
     195             : 
     196             : /** print Boolean value.
     197             : */
     198             : inline void printBool( sal_Bool bOk )
     199             : {
     200             :     printf( "#printBool# " );
     201             :     ( sal_True == bOk ) ? printf( "YES!\n" ): printf( "NO!\n" );
     202             : }
     203             : 
     204             : /** print struct TimeValue in local time format.
     205             : */
     206             : inline void printTime( TimeValue *tv )
     207             : {
     208             :     oslDateTime *pDateTime = ( oslDateTime* )malloc( sizeof( oslDateTime ) ) ;
     209             :      CPPUNIT_ASSERT_MESSAGE( "Error in printTime() function,malloc ", pDateTime != NULL );
     210             :     TimeValue *pLocalTV = ( TimeValue* )malloc( sizeof( TimeValue ) );
     211             :      CPPUNIT_ASSERT_MESSAGE( "Error in printTime() function,malloc ", pLocalTV != NULL );
     212             : 
     213             :     CPPUNIT_ASSERT_MESSAGE( "Error in printTime() function,osl_getLocalTimeFromSystemTime ",sal_True == osl_getLocalTimeFromSystemTime( tv, pLocalTV ) );
     214             :     CPPUNIT_ASSERT_MESSAGE( "Error in printTime() function,osl_gepDateTimeFromTimeValue ",sal_True == osl_getDateTimeFromTimeValue( pLocalTV, pDateTime ) );
     215             : 
     216             :     printf( "#printTime# " );
     217             :      printf( " Time is: %d/%d/%d ", pDateTime->Month, pDateTime->Day, pDateTime->Year);
     218             :     switch ( pDateTime->DayOfWeek )
     219             :     {
     220             :         case 0: printf("Sun. "); break;
     221             :         case 1: printf("Mon. "); break;
     222             :         case 2: printf("Tue. "); break;
     223             :         case 3: printf("Wed. "); break;
     224             :         case 4: printf("Thu. "); break;
     225             :         case 5: printf("Fri. "); break;
     226             :         case 6: printf("Sat. "); break;
     227             :     }
     228             :     printf( " %d:%d:%d %d nsecs\n", pDateTime->Hours, pDateTime->Minutes, pDateTime->Seconds, (int) pDateTime->NanoSeconds);
     229             : 
     230             :     free( pDateTime );
     231             :     free( pLocalTV );
     232             : }
     233             : 
     234             : /** compare two TimeValue, unit is "ms", since Windows time precision is better than UNX.
     235             : */
     236             : /* FIXME: the above assertion is bogus */
     237             : 
     238             : #if ( defined UNX )                      //precision of time in Windows is better than UNX
     239             : #   define delta 2000                    //time precision, 2000ms
     240             : #else
     241             : #   define delta 1800                    //time precision, 1.8s
     242             : #endif
     243             : 
     244             : inline sal_Int64 t_abs64(sal_Int64 _nValue)
     245             : {
     246             :     // std::abs() seems to have some ambiguity problems (so-texas)
     247             :     // return abs(_nValue);
     248             :     printf("t_abs64(%ld)\n", (long) _nValue);
     249             :     // CPPUNIT_ASSERT(_nValue < 2147483647);
     250             : 
     251             :     if (_nValue < 0)
     252             :     {
     253             :         _nValue = -_nValue;
     254             :     }
     255             :     return _nValue;
     256             : }
     257             : 
     258           0 : inline sal_Bool t_compareTime( TimeValue *m_aEndTime,  TimeValue *m_aStartTime, sal_Int32 nDelta)
     259             : {
     260             :     // sal_uInt64 uTimeValue;
     261             :     // sal_Int64 iTimeValue;
     262             :     //
     263             :     // iTimeValue = t_abs64(( tv1->Seconds - tv2->Seconds) * 1000000000 + tv1->Nanosec - tv2->Nanosec);
     264             :     // uTimeValue = ( iTimeValue / 1000000 );
     265             : 
     266           0 :     sal_Int32 nDeltaSeconds = m_aEndTime->Seconds - m_aStartTime->Seconds;
     267           0 :     sal_Int32 nDeltaNanoSec = sal_Int32(m_aEndTime->Nanosec) - sal_Int32(m_aStartTime->Nanosec);
     268           0 :     if (nDeltaNanoSec < 0)
     269             :     {
     270           0 :         nDeltaNanoSec = 1000000000 + nDeltaNanoSec;
     271           0 :         nDeltaSeconds--;
     272             :     }
     273             : 
     274           0 :     sal_Int32 nDeltaMilliSec = (nDeltaSeconds * 1000) + (nDeltaNanoSec / 1000000);
     275           0 :     return ( nDeltaMilliSec < nDelta );
     276             : }
     277             : 
     278             : /** compare two OUString file name.
     279             : */
     280          10 : inline sal_Bool compareFileName( const ::rtl::OUString & ustr1, const ::rtl::OUString & ustr2 )
     281             : {
     282             :     sal_Bool bOk;
     283             : //on Windows, the separator is '\', so here change to '/', then compare
     284             : #if defined (WNT )
     285             :     ::rtl::OUString ustr1new,ustr2new;
     286             :     sal_Unicode reverseSlash = (sal_Unicode)'\\';
     287             : 
     288             :     if (ustr1.lastIndexOf(reverseSlash) != -1)
     289             :         ustr1new = ustr1.replace(reverseSlash,(sal_Unicode)'/');
     290             :     else
     291             :         ustr1new = ustr1;
     292             :     if (ustr2.lastIndexOf(reverseSlash) != -1)
     293             :         ustr2new = ustr2.replace(reverseSlash,(sal_Unicode)'/');
     294             :     else
     295             :         ustr2new = ustr2;
     296             :     bOk = ustr1new.equalsIgnoreAsciiCase( ustr2new )  ;
     297             : #else
     298          10 :     bOk = ustr1.equalsIgnoreAsciiCase( ustr2 );
     299             : #endif
     300          10 :     return bOk;
     301             : }
     302             : 
     303             : /** compare a OUString and an ASCII file name.
     304             : */
     305             : inline sal_Bool compareFileName( const ::rtl::OUString & ustr, const sal_Char *astr )
     306             : {
     307             :     (void)ustr;
     308             :     ::rtl::OUString ustr1 = rtl::OUString::createFromAscii( astr );
     309             :     sal_Bool bOk = ustr1.equalsIgnoreAsciiCase( ustr1 ); // TODO: does it really compare with the same var?
     310             : 
     311             :     return bOk;
     312             : }
     313             : 
     314             : /** simple version to judge if a file name or directory name is a URL or a system path, just to see if it
     315             :     is start with "file:///";.
     316             : */
     317             : inline sal_Bool isURL( const sal_Char *pathname )
     318             : {
     319             :     return ( 0 == strncmp( pathname, FILE_PREFIX, sizeof( FILE_PREFIX ) - 1 ) );
     320             : }
     321             : 
     322             : /** simple version to judge if a file name or directory name is a URL or a system path, just to see if it
     323             :     is start with "file:///";.
     324             : */
     325         155 : inline sal_Bool isURL( const ::rtl::OUString pathname )
     326             : {
     327         155 :     return ( ( pathname.indexOf( aPreURL ) == 0 ) ? sal_True : sal_False );
     328             : }
     329             : 
     330             : /** concat two part to form a URL or system path, add PATH_SEPARATOR between them if necessary, add "file:///" to beginning if necessary.
     331             : */
     332          48 : inline void concatURL( ::rtl::OUString & pathname1, const ::rtl::OUString & pathname2 )
     333             : {
     334             :     //check if pathname1 is full qualified URL;
     335          48 :     if ( !isURL( pathname1 ) )
     336             :     {
     337           0 :         ::rtl::OUString     aPathName   = pathname1.copy( 0 );
     338           0 :         ::osl::FileBase::getFileURLFromSystemPath( pathname1, aPathName ); //convert if not full qualified URL
     339           0 :         pathname1   = aPathName.copy( 0 );
     340             :     }
     341             : 
     342          48 :     sal_Int32 index = 0;
     343             :     //check if '/' is in the end of pathname1 or at the begin of pathname2;
     344          48 :     if ( ( ( index = pathname1.lastIndexOf( aSlashURL ) ) != ( pathname1.getLength() - 1 ) ) &&
     345             :          ( ( index = pathname2.indexOf( aSlashURL ) ) != 0 ) )
     346          48 :         pathname1 += aSlashURL;
     347          48 :     pathname1 += pathname2;
     348          48 : }
     349             : 
     350             : /** create a temp test file using OUString name of full qualified URL or system path.
     351             : */
     352          34 : inline void createTestFile( const ::rtl::OUString filename )
     353             : {
     354          34 :     ::rtl::OUString     aPathURL   = filename.copy( 0 );
     355             :     ::osl::FileBase::RC nError;
     356             : 
     357          34 :     if ( !isURL( filename ) )
     358           0 :         ::osl::FileBase::getFileURLFromSystemPath( filename, aPathURL ); //convert if not full qualified URL
     359             : 
     360          68 :     File aFile(aPathURL);
     361          34 :     nError = aFile.open( osl_File_OpenFlag_Read | osl_File_OpenFlag_Write | osl_File_OpenFlag_Create );
     362             :     //CPPUNIT_ASSERT_MESSAGE( "In createTestFile Function: creation ", ( ::osl::FileBase::E_None == nError ) || ( nError == ::osl::FileBase::E_EXIST ) );
     363          34 :     if ( ( ::osl::FileBase::E_None != nError ) && ( nError != ::osl::FileBase::E_EXIST ))
     364             :     {
     365           0 :         printf("createTestFile failed!\n");
     366             :     }
     367          68 :     aFile.close();
     368             : 
     369          34 : }
     370             : 
     371             : /** create a temp test file using OUString name of full qualified URL or system path in a base directory.
     372             : */
     373          24 : inline void createTestFile( const ::rtl::OUString basename, const ::rtl::OUString filename )
     374             : {
     375          24 :     ::rtl::OUString aBaseURL = basename.copy( 0 );
     376             : 
     377          24 :     concatURL( aBaseURL, filename );
     378          24 :     createTestFile( aBaseURL );
     379          24 : }
     380             : 
     381             : /** detete a temp test file using OUString name.
     382             : */
     383          34 : inline void deleteTestFile( const ::rtl::OUString filename )
     384             : {
     385             :     // LLA: printf("deleteTestFile\n");
     386          34 :     ::rtl::OUString     aPathURL   = filename.copy( 0 );
     387             :     ::osl::FileBase::RC nError;
     388             : 
     389          34 :     if ( !isURL( filename ) )
     390           0 :         ::osl::FileBase::getFileURLFromSystemPath( filename, aPathURL ); //convert if not full qualified URL
     391             : 
     392          34 :     nError = ::osl::File::setAttributes( aPathURL, osl_File_Attribute_GrpWrite| osl_File_Attribute_OwnWrite| osl_File_Attribute_OthWrite ); // if readonly, make writtenable.
     393          34 :     CPPUNIT_ASSERT_MESSAGE( "In deleteTestFile Function: set writtenable ", ( ::osl::FileBase::E_None == nError ) || ( ::osl::FileBase::E_NOENT == nError ) );
     394             : 
     395          34 :     nError = ::osl::File::remove( aPathURL );
     396          34 :     CPPUNIT_ASSERT_MESSAGE( "In deleteTestFile Function: remove ", ( ::osl::FileBase::E_None == nError ) || ( nError == ::osl::FileBase::E_NOENT ) );
     397          34 : }
     398             : 
     399             : /** delete a temp test file using OUString name of full qualified URL or system path in a base directory.
     400             : */
     401          24 : inline void deleteTestFile( const ::rtl::OUString basename, const ::rtl::OUString filename )
     402             : {
     403          24 :     ::rtl::OUString     aBaseURL   = basename.copy( 0 );
     404             : 
     405          24 :     concatURL( aBaseURL, filename );
     406          24 :     deleteTestFile( aBaseURL );
     407          24 : }
     408             : 
     409             : /** create a temp test directory using OUString name of full qualified URL or system path.
     410             : */
     411          19 : inline void createTestDirectory( const ::rtl::OUString dirname )
     412             : {
     413          19 :     ::rtl::OUString     aPathURL   = dirname.copy( 0 );
     414             :     ::osl::FileBase::RC nError;
     415             : 
     416          19 :     if ( !isURL( dirname ) )
     417           0 :         ::osl::FileBase::getFileURLFromSystemPath( dirname, aPathURL ); //convert if not full qualified URL
     418          19 :     nError = ::osl::Directory::create( aPathURL );
     419             :     //CPPUNIT_ASSERT_MESSAGE( "In createTestDirectory Function: creation: ", ( ::osl::FileBase::E_None == nError ) || ( nError == ::osl::FileBase::E_EXIST ) );
     420          19 :     if ( ( ::osl::FileBase::E_None != nError ) && ( nError != ::osl::FileBase::E_EXIST ))
     421           0 :       printf("createTestDirectory failed!\n");
     422          19 : }
     423             : 
     424             : /** create a temp test directory using OUString name of full qualified URL or system path in a base directory.
     425             : */
     426           0 : inline void createTestDirectory( const ::rtl::OUString basename, const ::rtl::OUString dirname )
     427             : {
     428           0 :     ::rtl::OUString     aBaseURL   = basename.copy( 0 );
     429             : 
     430           0 :     concatURL( aBaseURL, dirname );
     431           0 :     createTestDirectory( aBaseURL );
     432           0 : }
     433             : 
     434             : /** delete a temp test directory using OUString name of full qualified URL or system path.
     435             : */
     436          20 : inline void deleteTestDirectory( const ::rtl::OUString dirname )
     437             : {
     438          20 :     ::rtl::OUString     aPathURL   = dirname.copy( 0 );
     439             :     ::osl::FileBase::RC nError;
     440          20 :     if ( !isURL( dirname ) )
     441           0 :         ::osl::FileBase::getFileURLFromSystemPath( dirname, aPathURL ); //convert if not full qualified URL
     442             : 
     443          40 :     ::osl::Directory testDir( aPathURL );
     444          20 :     if ( testDir.isOpen() == sal_True )
     445           0 :         testDir.close();  //close if still open.
     446             : 
     447          20 :     nError = ::osl::Directory::remove( aPathURL );
     448             : 
     449          40 :     rtl::OString strError (RTL_CONSTASCII_STRINGPARAM("In deleteTestDirectory function: remove Directory "));
     450          20 :     strError += ::rtl::OUStringToOString( aPathURL, RTL_TEXTENCODING_ASCII_US );
     451          40 :     CPPUNIT_ASSERT_MESSAGE( strError.getStr(), ( ::osl::FileBase::E_None == nError ) || ( nError == ::osl::FileBase::E_NOENT ) );
     452          20 : }
     453             : 
     454             : /** delete a temp test directory using OUString name of full qualified URL or system path in a base directory.
     455             : */
     456           0 : inline void deleteTestDirectory( const ::rtl::OUString basename, const ::rtl::OUString dirname )
     457             : {
     458           0 :     ::rtl::OUString     aBaseURL   = basename.copy( 0 );
     459             : 
     460           0 :     concatURL( aBaseURL, dirname );
     461           0 :     deleteTestDirectory( aBaseURL );
     462           0 : }
     463             : 
     464             : 
     465             : /** Check for the file and directory access right.
     466             : */
     467             : typedef enum {
     468             :     osl_Check_Mode_Exist,
     469             :     osl_Check_Mode_OpenAccess,
     470             :     osl_Check_Mode_ReadAccess,
     471             :     osl_Check_Mode_WriteAccess
     472             : } oslCheckMode;
     473             : 
     474             : // not used here
     475             : inline sal_Bool checkFile( const ::rtl::OUString & str, oslCheckMode nCheckMode )
     476             : {
     477             :     ::osl::FileBase::RC   nError1, nError2;
     478             :     ::osl::File       testFile( str );
     479             :     sal_Bool          bCheckResult;
     480             : 
     481             :     bCheckResult = sal_False;
     482             :     nError1 = testFile.open ( osl_File_OpenFlag_Read );
     483             :     if ( ( ::osl::FileBase::E_NOENT != nError1 ) && ( ::osl::FileBase::E_ACCES != nError1 ) ){
     484             : 
     485             :         switch ( nCheckMode ) {
     486             :             case osl_Check_Mode_Exist:
     487             :                 /// check if the file is exist.
     488             :                 if ( ::osl::FileBase::E_None == nError1 )
     489             :                     bCheckResult = sal_True;
     490             :                 break;
     491             :             case osl_Check_Mode_OpenAccess:
     492             :                 /// check if the file is openable.
     493             :                 if ( ::osl::FileBase::E_None == nError1 )
     494             :                     bCheckResult = sal_True;
     495             :                 break;
     496             :             case osl_Check_Mode_WriteAccess:
     497             :                 /// check the file name and whether it can be written.
     498             :                 /// write chars into the file.
     499             :                 sal_uInt64 nCount_write;
     500             :                 nError2 = testFile.write( pBuffer_Char, 10, nCount_write );
     501             :                 if ( ::osl::FileBase::E_None == nError2 )
     502             :                     bCheckResult = sal_True;
     503             :                 break;
     504             : 
     505             :             default:
     506             :                 bCheckResult = sal_False;
     507             :         }/// swith
     508             : 
     509             :         nError2 = testFile.close();
     510             :         CPPUNIT_ASSERT_MESSAGE( " in CheckFile() function, close file ", nError2 == FileBase::E_None );
     511             : 
     512             :     }
     513             : 
     514             :     return bCheckResult;
     515             : }
     516             : 
     517             : //check if the file exist
     518           1 : inline sal_Bool ifFileExist( const ::rtl::OUString & str )
     519             : {
     520           1 :     ::osl::File testFile( str );
     521           1 :     return ( osl::FileBase::E_None == testFile.open( osl_File_OpenFlag_Read ) );
     522             : }
     523             : 
     524             : //check if the file can be written
     525           0 : inline sal_Bool ifFileCanWrite( const ::rtl::OUString & str )
     526             : {
     527           0 :     sal_Bool  bCheckResult = sal_False;
     528             :     //on Windows, the file has no write right, but can be written
     529             : #ifdef WNT
     530             :     ::rtl::OUString  aUStr  = str.copy( 0 );
     531             :     if ( isURL( str ) )
     532             :         ::osl::FileBase::getSystemPathFromFileURL( str, aUStr );
     533             : 
     534             :     ::rtl::OString aString = ::rtl::OUStringToOString( aUStr, RTL_TEXTENCODING_ASCII_US );
     535             :     const char *path = aString.getStr();
     536             :     if (( _access( path, 2 ) ) != -1 )
     537             :          bCheckResult = sal_True;
     538             :      //on UNX, just test if open success with osl_File_OpenFlag_Write
     539             : #else
     540           0 :     ::osl::File testFile( str );
     541           0 :     bCheckResult = (osl::FileBase::E_None == testFile.open( osl_File_OpenFlag_Write ));
     542             : #endif
     543           0 :     return bCheckResult;
     544             : }
     545             : 
     546           0 : inline sal_Bool checkDirectory( const ::rtl::OUString & str, oslCheckMode nCheckMode )
     547             : {
     548           0 :     rtl::OUString   aUString;
     549           0 :     DirectoryItem   rItem;
     550             :     FileBase::RC    rc;
     551           0 :     sal_Bool        bCheckResult= sal_False;
     552             : 
     553             :     //::std::auto_ptr<Directory> pDir( new Directory( str ) );
     554           0 :     Directory aDir( str );
     555           0 :     rc = aDir.open();
     556             : 
     557           0 :     if ( ( ::osl::FileBase::E_NOENT != rc ) && ( ::osl::FileBase::E_ACCES != rc ) ){
     558             : 
     559           0 :         switch ( nCheckMode ) {
     560             :             case osl_Check_Mode_Exist:
     561           0 :                 if ( rc == ::osl::FileBase::E_None )
     562           0 :                     bCheckResult = sal_True;
     563           0 :                 break;
     564             :             case osl_Check_Mode_OpenAccess:
     565           0 :                 if ( rc == ::osl::FileBase::E_None )
     566           0 :                     bCheckResult = sal_True;
     567           0 :                 break;
     568             :             case osl_Check_Mode_ReadAccess:
     569             :                 //rc = pDir->getNextItem( rItem, 0 );
     570           0 :                 rc = aDir.getNextItem( rItem, 0 );
     571           0 :                 if ( ( rc == ::osl::FileBase::E_None ) || ( rc == ::osl::FileBase::E_NOENT ) )
     572           0 :                     bCheckResult = sal_True;
     573             :                 else
     574           0 :                     bCheckResult = sal_False;
     575           0 :                 break;
     576             :             case osl_Check_Mode_WriteAccess:
     577           0 :                 ( ( aUString += str ) += aSlashURL ) += aTmpName2;
     578             :                 //if ( ( rc = pDir->create( aUString ) ) == ::osl::FileBase::E_None )
     579           0 :                 if ( ( rc = Directory::create( aUString ) ) == ::osl::FileBase::E_None )
     580             :                 {
     581           0 :                     bCheckResult = sal_True;
     582             :                     //rc = pDir->remove( aUString );
     583           0 :                     rc = Directory::remove( aUString );
     584           0 :                     CPPUNIT_ASSERT( rc == ::osl::FileBase::E_None );
     585             :                 }
     586             :                 else
     587           0 :                     bCheckResult = sal_False;
     588           0 :                 break;
     589             : 
     590             :             default:
     591           0 :                 bCheckResult = sal_False;
     592             :         }// switch
     593             : 
     594           0 :         rc = aDir.close();
     595           0 :         CPPUNIT_ASSERT( rc == FileBase::E_None );
     596             : 
     597             :     }//if
     598             : 
     599           0 :     return bCheckResult;
     600             : }
     601             : 
     602             : /** construct error message
     603             : */
     604           0 : inline ::rtl::OString outputError( const ::rtl::OString & returnVal, const ::rtl::OString & rightVal, const sal_Char * msg = "")
     605             : {
     606           0 :     ::rtl::OString aString;
     607           0 :     if ( returnVal.equals( rightVal ) )
     608           0 :         return aString;
     609           0 :     aString += msg;
     610           0 :     aString += ": the returned value is '";
     611           0 :     aString += returnVal;
     612           0 :     aString += "', but the value should be '";
     613           0 :     aString += rightVal;
     614           0 :     aString += "'.";
     615           0 :     return aString;
     616             : }
     617             : 
     618             : /** Change file mode, two version in UNIX and Windows;.
     619             : */
     620             : #if ( defined UNX )         //chmod() method is differ in Windows
     621           0 : inline void changeFileMode( ::rtl::OUString & filepath, sal_Int32 mode )
     622             : {
     623           0 :     rtl::OString    aString;
     624           0 :     rtl::OUString   aUStr  = filepath.copy( 0 );
     625             : 
     626           0 :     if ( isURL( filepath ) )
     627           0 :         ::osl::FileBase::getSystemPathFromFileURL( filepath, aUStr );
     628           0 :     aString = ::rtl::OUStringToOString( aUStr, RTL_TEXTENCODING_ASCII_US );
     629           0 :     chmod( aString.getStr(), mode );
     630           0 : }
     631             : #else                                          //Windows version
     632             : inline void changeFileMode( ::rtl::OUString & filepath, sal_Int32 mode )
     633             : {
     634             :     (void)filepath;
     635             :     (void)mode;
     636             :     printf("this method is not implemented yet");
     637             : }
     638             : #endif
     639             : 
     640             : inline ::rtl::OUString getCurrentPID( void );
     641             : 
     642             : 
     643             : 
     644             : //------------------------------------------------------------------------
     645             : // Beginning of the test cases for FileBase class
     646             : //------------------------------------------------------------------------
     647             : namespace osl_FileBase
     648             : {
     649             : 
     650             :     //---------------------------------------------------------------------
     651             :     // testing the method
     652             :     // static inline RC getAbsoluteFileURL( const ::rtl::OUString& ustrBaseDirectoryURL,
     653             :     //                                      const ::rtl::OUString& ustrRelativeFileURL,
     654             :     //                                      ::rtl::OUString& ustrAbsoluteFileURL )
     655             :     //---------------------------------------------------------------------
     656             : 
     657           0 :     class getAbsoluteFileURL:public CppUnit::TestFixture
     658             :     {
     659             :         //::osl::FileBase  aFileBase;
     660             :         ::rtl::OUString  aResultURL1, aResultURL2, aResultURL3, aResultURL4, aResultURL5, aResultURL6;
     661             :             // ::osl::FileBase::RC nError;
     662             : 
     663             :         public:
     664             : 
     665             :             void check_getAbsoluteFileURL( rtl::OUString const& _suBaseURL,  rtl::OString const& _sRelativeURL, ::osl::FileBase::RC _nAssumeError, rtl::OUString const& _suAssumeResultStr );
     666             : 
     667             :       void getAbsoluteFileURL_001_1();
     668             :       void getAbsoluteFileURL_001_2();
     669             :       void getAbsoluteFileURL_001_3();
     670             :       void getAbsoluteFileURL_001_4();
     671             :       void getAbsoluteFileURL_001_5();
     672             :       void getAbsoluteFileURL_001_6();
     673             :       void getAbsoluteFileURL_001_7();
     674             :       void getAbsoluteFileURL_001_8();
     675             :       void getAbsoluteFileURL_002();
     676             :       void getAbsoluteFileURL_003();
     677             :       void getAbsoluteFileURL_004();
     678             : 
     679           0 :         CPPUNIT_TEST_SUITE( getAbsoluteFileURL );
     680           0 :         CPPUNIT_TEST( getAbsoluteFileURL_001_1 );
     681           0 :       CPPUNIT_TEST( getAbsoluteFileURL_001_2 );
     682           0 :       CPPUNIT_TEST( getAbsoluteFileURL_001_3 );
     683           0 :       CPPUNIT_TEST( getAbsoluteFileURL_001_4 );
     684           0 :       CPPUNIT_TEST( getAbsoluteFileURL_001_5 );
     685           0 :       CPPUNIT_TEST( getAbsoluteFileURL_001_6 );
     686           0 :       CPPUNIT_TEST( getAbsoluteFileURL_001_7 );
     687           0 :       CPPUNIT_TEST( getAbsoluteFileURL_001_8 );
     688           0 :       CPPUNIT_TEST( getAbsoluteFileURL_002 );
     689           0 :       CPPUNIT_TEST( getAbsoluteFileURL_003 );
     690           0 :       CPPUNIT_TEST( getAbsoluteFileURL_004 );
     691           0 :       CPPUNIT_TEST_SUITE_END();
     692             : 
     693             :         }; //class getAbsoluteFileURL
     694             : 
     695           0 :     void getAbsoluteFileURL::check_getAbsoluteFileURL( rtl::OUString const& _suBaseURL,  rtl::OString const& _sRelativeURL, ::osl::FileBase::RC _nAssumeError, rtl::OUString const& _suAssumeResultStr )
     696             :     {
     697           0 :         rtl::OUString suRelativeURL = rtl::OStringToOUString(_sRelativeURL, RTL_TEXTENCODING_UTF8);
     698           0 :         rtl::OString sBaseURL = rtl::OUStringToOString(_suBaseURL, RTL_TEXTENCODING_UTF8);
     699           0 :         rtl::OUString suResultURL;
     700           0 :         osl::FileBase::RC nError = FileBase::getAbsoluteFileURL( _suBaseURL,  suRelativeURL, suResultURL );
     701           0 :         rtl::OString sResultURL = rtl::OUStringToOString( suResultURL, RTL_TEXTENCODING_UTF8);
     702           0 :         rtl::OString sError = errorToString(nError);
     703           0 :         printf("getAbsoluteFileURL('%s','%s') deliver absolute URL: '%s', error '%s'\n", sBaseURL.getStr(), _sRelativeURL.getStr(),sResultURL.getStr(), sError.getStr() );
     704           0 :         CPPUNIT_ASSERT_MESSAGE( "Assumption is wrong: error number is wrong", nError == _nAssumeError );
     705           0 :         if ( nError == ::osl::FileBase::E_None )
     706             :         {
     707           0 :             sal_Bool bStrAreEqual = _suAssumeResultStr.equals( suResultURL );
     708           0 :                     CPPUNIT_ASSERT_MESSAGE( "Assumption is wrong: ResultURL is not equal to expected URL ", bStrAreEqual == sal_True );
     709           0 :                 }
     710           0 :     }
     711             : 
     712           0 :   void getAbsoluteFileURL::getAbsoluteFileURL_001_1()
     713             :   {
     714           0 :     rtl::OUString suAssume = aUserDirectoryURL.concat( rtl::OUString("/relative/file1") );
     715           0 :     check_getAbsoluteFileURL( aUserDirectoryURL, "relative/file1",::osl::FileBase::E_None, suAssume );
     716           0 :   }
     717           0 :   void getAbsoluteFileURL::getAbsoluteFileURL_001_2()
     718             :   {
     719           0 :     rtl::OUString suAssume = aUserDirectoryURL.concat( rtl::OUString("/relative/file2") );
     720           0 :     check_getAbsoluteFileURL( aUserDirectoryURL, "relative/./file2",::osl::FileBase::E_None, suAssume );
     721           0 :   }
     722           0 :   void getAbsoluteFileURL::getAbsoluteFileURL_001_3()
     723             :   {
     724           0 :     rtl::OUString suAssume = aUserDirectoryURL.concat( rtl::OUString("/file3") );
     725           0 :     check_getAbsoluteFileURL( aUserDirectoryURL, "relative/../file3",::osl::FileBase::E_None, suAssume );
     726           0 :   }
     727           0 :   void getAbsoluteFileURL::getAbsoluteFileURL_001_4()
     728             :   {
     729           0 :     rtl::OUString suAssume = aUserDirectoryURL.concat( rtl::OUString("/file4") );
     730           0 :     check_getAbsoluteFileURL( aUserDirectoryURL, "././relative/../file4",::osl::FileBase::E_None, suAssume );
     731           0 :   }
     732           0 :   void getAbsoluteFileURL::getAbsoluteFileURL_001_5()
     733             :   {
     734           0 :     rtl::OUString suAssume;
     735             : #if ( defined UNX )
     736           0 :     suAssume = aUserDirectoryURL.concat( rtl::OUString("/relative/") );
     737             : #else
     738             :     suAssume = aUserDirectoryURL.concat( rtl::OUString("/relative") );
     739             : #endif
     740           0 :     check_getAbsoluteFileURL( aUserDirectoryURL, "././relative/.",::osl::FileBase::E_None, suAssume );
     741           0 :   }
     742           0 :   void getAbsoluteFileURL::getAbsoluteFileURL_001_6()
     743             :   {
     744           0 :     rtl::OUString suAssume = aUserDirectoryURL.concat( rtl::OUString("/.relative") );
     745           0 :     check_getAbsoluteFileURL( aUserDirectoryURL, "./.relative",::osl::FileBase::E_None, suAssume );
     746           0 :   }
     747           0 :   void getAbsoluteFileURL::getAbsoluteFileURL_001_7()
     748             :   {
     749           0 :     rtl::OUString suAssume;
     750             : #if (defined UNX )
     751           0 :     suAssume = aUserDirectoryURL.concat( rtl::OUString("/.a/") );
     752             : #else //windows
     753             :     suAssume = aUserDirectoryURL.concat( rtl::OUString("/.a") );
     754             : #endif
     755           0 :     check_getAbsoluteFileURL( aUserDirectoryURL, "./.a/mydir/..",::osl::FileBase::E_None, suAssume );
     756           0 :   }
     757           0 :   void getAbsoluteFileURL::getAbsoluteFileURL_001_8()
     758             :   {
     759           0 :     rtl::OUString suAssume = aUserDirectoryURL.concat( rtl::OUString("/tmp/ok") );
     760             : #if ( defined UNX )
     761           0 :     check_getAbsoluteFileURL( aUserDirectoryURL, "tmp//ok",::osl::FileBase::E_None, suAssume );
     762             : #else
     763             :     check_getAbsoluteFileURL( aUserDirectoryURL, "tmp//ok",::osl::FileBase::E_INVAL, suAssume );
     764             : #endif
     765           0 :   }
     766           0 :   void getAbsoluteFileURL::getAbsoluteFileURL_002()
     767             :   {
     768             : #if ( defined UNX )     //Link is not defined in Windows
     769           0 :         ::rtl::OUString aUStr_LnkFileSys( aTempDirectorySys ), aUStr_SrcFileSys( aTempDirectorySys );
     770           0 :         ( ( aUStr_LnkFileSys += aSlashURL ) += getCurrentPID() ) += ::rtl::OUString("/link.file");
     771           0 :         ( ( aUStr_SrcFileSys += aSlashURL ) += getCurrentPID() ) += ::rtl::OUString("/canonical.name");
     772             : 
     773           0 :                 rtl::OString strLinkFileName, strSrcFileName;
     774           0 :                 strLinkFileName = OUStringToOString( aUStr_LnkFileSys, RTL_TEXTENCODING_ASCII_US );
     775           0 :                 strSrcFileName =  OUStringToOString( aUStr_SrcFileSys, RTL_TEXTENCODING_ASCII_US );
     776             : 
     777           0 :         createTestFile( aCanURL1 );
     778           0 :                 sal_Int32 fd = symlink( strSrcFileName.getStr(), strLinkFileName.getStr() );
     779           0 :         CPPUNIT_ASSERT( fd == 0 );
     780           0 :         rtl::OString sLnkURL = OUStringToOString( aLnkURL1, RTL_TEXTENCODING_ASCII_US );
     781           0 :             rtl::OUString suAssume = aUserDirectoryURL.concat( rtl::OUString("/canonical.name") );
     782           0 :         check_getAbsoluteFileURL( aUserDirectoryURL, sLnkURL, ::osl::FileBase::E_None, suAssume );
     783           0 :         deleteTestFile( aCanURL1 );
     784           0 :                 fd = remove( strLinkFileName.getStr() );
     785           0 :         CPPUNIT_ASSERT( fd == 0 );
     786             : #endif
     787           0 :   }
     788             :   //please see line# 930
     789           0 :   void getAbsoluteFileURL::getAbsoluteFileURL_003()
     790             :   {
     791           0 :   }
     792           0 :     void getAbsoluteFileURL::getAbsoluteFileURL_004()
     793             :     {
     794             :         //create two level directories under $Temp/PID/
     795           0 :         ::rtl::OUString aUStrUpBase = aUserDirectoryURL + ::rtl::OUString("/test1");
     796           0 :         createTestDirectory( aUStrUpBase );
     797           0 :         ::rtl::OUString aUStrBase = aUserDirectoryURL + ::rtl::OUString("/test1/dir1");
     798           0 :         createTestDirectory( aUStrBase );
     799             : 
     800           0 :         ::rtl::OUString suAssume = aUserDirectoryURL.concat( ::rtl::OUString("/mytestfile") );
     801           0 :         check_getAbsoluteFileURL( aUStrBase, "../../mytestfile" , ::osl::FileBase::E_None, suAssume );
     802           0 :         deleteTestDirectory( aUStrBase );
     803           0 :         deleteTestDirectory( aUStrUpBase );
     804           0 :     }
     805             :     //---------------------------------------------------------------------
     806             :     // testing two methods:
     807             :     // static inline RC getSystemPathFromFileURL( const ::rtl::OUString& ustrFileURL,
     808             :     //                ::rtl::OUString& ustrSystemPath )
     809             :         // static RC getFileURLFromSystemPath( const ::rtl::OUString & ustrSystemPath,
     810             :         //                                ::rtl::OUString & ustrFileURL );
     811             :     //---------------------------------------------------------------------
     812           0 :     class SystemPath_FileURL:public CppUnit::TestFixture
     813             :     {
     814             :         //::osl::FileBase aFileBase;
     815             :         // ::rtl::OUString aUStr;
     816             :         // ::osl::FileBase::RC nError;
     817             : 
     818             :       //void check_getSystemPathFromFileURL(rtl::OString const& _sURL, ::osl::FileBase::RC _nAssumeError, rtl::OString const& _sAssumeResultStr);
     819             :       void check_SystemPath_FileURL(rtl::OString const& _sSource, ::osl::FileBase::RC _nAssumeError, rtl::OString const& _sAssumeResultStr, sal_Bool bDirection = sal_True );
     820             :       void checkWNTBehaviour_getSystemPathFromFileURL(rtl::OString const& _sURL, ::osl::FileBase::RC _nAssumeError, rtl::OString const& _sWNTAssumeResultString );
     821             :       void checkUNXBehaviour_getSystemPathFromFileURL(rtl::OString const& _sURL, ::osl::FileBase::RC _nAssumeError, rtl::OString const& _sUnixAssumeResultString );
     822             :       void checkWNTBehaviour_getFileURLFromSystemPath(rtl::OString const& _sSysPath, ::osl::FileBase::RC _nAssumeError, rtl::OString const& _sWNTAssumeResultString);
     823             :       void checkUNXBehaviour_getFileURLFromSystemPath(rtl::OString const& _sSysPath, ::osl::FileBase::RC _nAssumeError, rtl::OString const& _sUnixAssumeResultString);
     824             : 
     825             :     public:
     826             :         // test code.
     827             :         void getSystemPathFromFileURL_001_1();
     828             :         void getSystemPathFromFileURL_001_2();
     829             :         void getSystemPathFromFileURL_001_21();
     830             :         void getSystemPathFromFileURL_001_22();
     831             :         void getSystemPathFromFileURL_001_3();
     832             :         void getSystemPathFromFileURL_001_31();
     833             :         void getSystemPathFromFileURL_001_4();
     834             :         void getSystemPathFromFileURL_001_41();
     835             :         void getSystemPathFromFileURL_001_5();
     836             :         void getSystemPathFromFileURL_001_51();
     837             :         void getSystemPathFromFileURL_001_52();
     838             :         void getSystemPathFromFileURL_001_53();
     839             :         void getSystemPathFromFileURL_001_6();
     840             :         void getSystemPathFromFileURL_001_61();
     841             :         void getSystemPathFromFileURL_001_7();
     842             :         void getSystemPathFromFileURL_001_71();
     843             :         void getSystemPathFromFileURL_001_8();
     844             :             void getSystemPathFromFileURL_001_81();
     845             :         void getSystemPathFromFileURL_001_9();
     846             :         void getSystemPathFromFileURL_001_91();
     847             :         void getSystemPathFromFileURL_001_92();
     848             :         void getSystemPathFromFileURL_004();
     849             :         void getSystemPathFromFileURL_005();
     850             : 
     851             :       //test case fot getFileURLFromSystemPath
     852             :             void getFileURLFromSystemPath_001();
     853             :             void getFileURLFromSystemPath_002();
     854             :             void getFileURLFromSystemPath_003();
     855             :             void getFileURLFromSystemPath_004();
     856             :         void getFileURLFromSystemPath_005();
     857             : 
     858           0 :         CPPUNIT_TEST_SUITE( SystemPath_FileURL );
     859           0 :         CPPUNIT_TEST( getSystemPathFromFileURL_001_1 );
     860           0 :         CPPUNIT_TEST( getSystemPathFromFileURL_001_2 );
     861           0 :         CPPUNIT_TEST( getSystemPathFromFileURL_001_21 );
     862           0 :         CPPUNIT_TEST( getSystemPathFromFileURL_001_22 );
     863           0 :         CPPUNIT_TEST( getSystemPathFromFileURL_001_3 );
     864           0 :         CPPUNIT_TEST( getSystemPathFromFileURL_001_31 );
     865           0 :         CPPUNIT_TEST( getSystemPathFromFileURL_001_4 );
     866           0 :         CPPUNIT_TEST( getSystemPathFromFileURL_001_41 );
     867           0 :         CPPUNIT_TEST( getSystemPathFromFileURL_001_5 );
     868           0 :         CPPUNIT_TEST( getSystemPathFromFileURL_001_51 );
     869           0 :         CPPUNIT_TEST( getSystemPathFromFileURL_001_52 );
     870           0 :         CPPUNIT_TEST( getSystemPathFromFileURL_001_53 );
     871           0 :         CPPUNIT_TEST( getSystemPathFromFileURL_001_6 );
     872           0 :         CPPUNIT_TEST( getSystemPathFromFileURL_001_61 );
     873           0 :         CPPUNIT_TEST( getSystemPathFromFileURL_001_7 );
     874           0 :         CPPUNIT_TEST( getSystemPathFromFileURL_001_71 );
     875           0 :         CPPUNIT_TEST( getSystemPathFromFileURL_001_8 );
     876           0 :             CPPUNIT_TEST( getSystemPathFromFileURL_001_81 );
     877           0 :         CPPUNIT_TEST( getSystemPathFromFileURL_001_9 );
     878           0 :         CPPUNIT_TEST( getSystemPathFromFileURL_001_91 );
     879           0 :         CPPUNIT_TEST( getSystemPathFromFileURL_001_92 );
     880           0 :         CPPUNIT_TEST( getSystemPathFromFileURL_004 );
     881           0 :         CPPUNIT_TEST( getSystemPathFromFileURL_005 );
     882           0 :             CPPUNIT_TEST( getFileURLFromSystemPath_001 );
     883           0 :         CPPUNIT_TEST( getFileURLFromSystemPath_002 );
     884           0 :         CPPUNIT_TEST( getFileURLFromSystemPath_003 );
     885           0 :         CPPUNIT_TEST( getFileURLFromSystemPath_004 );
     886           0 :         CPPUNIT_TEST( getFileURLFromSystemPath_005 );
     887           0 :         CPPUNIT_TEST_SUITE_END();
     888             :     };// class SystemPath_FileURL
     889             : 
     890             : 
     891             :     // if bDirection==sal_True, check getSystemPathFromFileURL
     892             :     // if bDirection==sal_False, check getFileURLFromSystemPath
     893           0 :     void SystemPath_FileURL::check_SystemPath_FileURL(rtl::OString const& _sSource, ::osl::FileBase::RC _nAssumeError, rtl::OString const& _sAssumeResultStr, sal_Bool bDirection)
     894             :     {
     895             :         // PRE: URL as String
     896           0 :         rtl::OUString suSource;
     897           0 :         rtl::OUString suStr;
     898           0 :         suSource = rtl::OStringToOUString(_sSource, RTL_TEXTENCODING_UTF8);
     899             :     ::osl::FileBase::RC nError;
     900           0 :     if ( bDirection == sal_True )
     901           0 :       nError = osl::FileBase::getSystemPathFromFileURL( suSource, suStr );
     902             :     else
     903           0 :       nError = osl::FileBase::getFileURLFromSystemPath( suSource, suStr );
     904             : 
     905             :         // if the given string is gt length 0,
     906             :         // we check also this string
     907           0 :         rtl::OString sStr = rtl::OUStringToOString(suStr, RTL_TEXTENCODING_UTF8);
     908           0 :         rtl::OString sError = errorToString(nError);
     909           0 :     if ( bDirection == sal_True )
     910           0 :       printf("getSystemPathFromFileURL('%s') deliver system path: '%s', error '%s'\n", _sSource.getStr(), sStr.getStr(), sError.getStr() );
     911             :     else
     912           0 :       printf("getFileURLFromSystemPath('%s') deliver File URL: '%s', error '%s'\n", _sSource.getStr(), sStr.getStr(), sError.getStr() );
     913             : 
     914             :         // rtl::OUString suStrEncode = rtl::Uri::encode(suStr, rtl_UriCharClassUnoParamValue, rtl_UriEncodeKeepEscapes, RTL_TEXTENCODING_UTF8);
     915             :         // sStr = rtl::OUStringToOString(suStr, RTL_TEXTENCODING_UTF8);
     916             :         // printf("UTF8: %s\n", sStr.getStr() );
     917             : 
     918           0 :         if (!_sAssumeResultStr.isEmpty())
     919             :         {
     920           0 :             sal_Bool bStrAreEqual = _sAssumeResultStr.equals(sStr);
     921           0 :             CPPUNIT_ASSERT_MESSAGE( "Assumption is wrong",
     922           0 :                                     nError == _nAssumeError && bStrAreEqual == sal_True );
     923             :         }
     924             :         else
     925             :         {
     926           0 :             CPPUNIT_ASSERT_MESSAGE( "Assumption is wrong", nError == _nAssumeError );
     927           0 :         }
     928           0 :     }
     929           0 :     void SystemPath_FileURL::checkWNTBehaviour_getSystemPathFromFileURL(rtl::OString const& _sURL, ::osl::FileBase::RC _nAssumeError, rtl::OString const& _sWNTAssumeResultString)
     930             :     {
     931             : #if ( defined WNT )
     932             :         check_SystemPath_FileURL(_sURL, _nAssumeError, _sWNTAssumeResultString);
     933             : #else
     934             :         (void)_sURL;
     935             :         (void)_nAssumeError;
     936             :         (void)_sWNTAssumeResultString;
     937             : #endif
     938           0 :     }
     939             : 
     940           0 :     void SystemPath_FileURL::checkUNXBehaviour_getSystemPathFromFileURL(rtl::OString const& _sURL, ::osl::FileBase::RC _nAssumeError, rtl::OString const& _sUnixAssumeResultString)
     941             :     {
     942             : #if ( defined UNX )
     943           0 :         check_SystemPath_FileURL(_sURL, _nAssumeError, _sUnixAssumeResultString);
     944             : #else
     945             :         (void)_sURL;
     946             :         (void)_nAssumeError;
     947             :         (void)_sUnixAssumeResultString;
     948             : #endif
     949           0 :     }
     950             : 
     951           0 :     void SystemPath_FileURL::checkWNTBehaviour_getFileURLFromSystemPath(rtl::OString const& _sSysPath, ::osl::FileBase::RC _nAssumeError, rtl::OString const& _sWNTAssumeResultString)
     952             :     {
     953             : #if ( defined WNT )
     954             :         check_SystemPath_FileURL(_sSysPath, _nAssumeError, _sWNTAssumeResultString, sal_False );
     955             : #else
     956             :         (void)_sSysPath;
     957             :         (void)_nAssumeError;
     958             :         (void)_sWNTAssumeResultString;
     959             : #endif
     960           0 :     }
     961             : 
     962           0 :     void SystemPath_FileURL::checkUNXBehaviour_getFileURLFromSystemPath(rtl::OString const& _sSysPath, ::osl::FileBase::RC _nAssumeError, rtl::OString const& _sUnixAssumeResultString)
     963             :     {
     964             : #if ( defined UNX )
     965           0 :         check_SystemPath_FileURL(_sSysPath, _nAssumeError, _sUnixAssumeResultString, sal_False );
     966             : #else
     967             :         (void)_sSysPath;
     968             :         (void)_nAssumeError;
     969             :         (void)_sUnixAssumeResultString;
     970             : #endif
     971           0 :     }
     972             : 
     973             :     /** LLA: Test for getSystemPathFromFileURL()
     974             :         this test is splitted into 2 different OS tests,
     975             :         the first function checkUNXBehaviour... runs only on Unix based Systems,
     976             :         the second only on windows based systems
     977             :         the first parameter are a file URL where we want to get the system path of,
     978             :         the second parameter is the assumed error of the osl_getSystemPathFromFileURL() function,
     979             :         the third parameter is the assumed result string, the string will only test, if it's length is greater 0
     980             :     */
     981             : 
     982           0 :     void SystemPath_FileURL::getSystemPathFromFileURL_001_1()
     983             :     {
     984           0 :         rtl::OString sURL("");
     985           0 :         checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, "");
     986           0 :         checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, "");
     987           0 :     }
     988             : 
     989           0 :     void SystemPath_FileURL::getSystemPathFromFileURL_001_2()
     990             :     {
     991           0 :         rtl::OString sURL("/");
     992           0 :         checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, "");
     993           0 :         checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "\\");
     994           0 :     }
     995           0 :     void SystemPath_FileURL::getSystemPathFromFileURL_001_21()
     996             :     {
     997             :       //        rtl::OString sURL("%2f");
     998           0 :       rtl::OString sURL("%2F");
     999           0 :         checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "/"); // LLA: this is may be a BUG
    1000           0 :         checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, "");
    1001           0 :     }
    1002           0 :     void SystemPath_FileURL::getSystemPathFromFileURL_001_22()
    1003             :     {
    1004           0 :       rtl::OString sURL("file:///tmp%2Fmydir");
    1005           0 :         checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, "");
    1006           0 :         checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, "");
    1007           0 :     }
    1008           0 :     void SystemPath_FileURL::getSystemPathFromFileURL_001_3()
    1009             :     {
    1010           0 :         rtl::OString sURL("a");
    1011           0 :         checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "a");
    1012           0 :         checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "a");
    1013           0 :     }
    1014           0 :     void SystemPath_FileURL::getSystemPathFromFileURL_001_31()
    1015             :     {
    1016           0 :         rtl::OString sURL("tmpname");
    1017           0 :         checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "tmpname");
    1018           0 :         checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "tmpname");
    1019           0 :     }
    1020           0 :     void SystemPath_FileURL::getSystemPathFromFileURL_001_4()
    1021             :     {
    1022           0 :         rtl::OString sURL("file://");
    1023           0 :         checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "");
    1024           0 :         checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, "");
    1025           0 :     }
    1026           0 :     void SystemPath_FileURL::getSystemPathFromFileURL_001_41()
    1027             :     {
    1028           0 :         rtl::OString sURL("file://localhost/tmp");
    1029           0 :         checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "");
    1030           0 :         checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, "");
    1031           0 :     }
    1032           0 :     void SystemPath_FileURL::getSystemPathFromFileURL_001_5()
    1033             :     {
    1034           0 :         rtl::OString sURL("file:///tmp");
    1035           0 :         checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "/tmp");
    1036           0 :         checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, "");
    1037           0 :     }
    1038           0 :     void SystemPath_FileURL::getSystemPathFromFileURL_001_51()
    1039             :     {
    1040           0 :         rtl::OString sURL("file://c:/tmp");
    1041           0 :         checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "c:/tmp"); // LLA: this is may be a BUG
    1042           0 :         checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, "");
    1043           0 :     }
    1044           0 :     void SystemPath_FileURL::getSystemPathFromFileURL_001_52()
    1045             :     {
    1046           0 :         rtl::OString sURL("file:///c:/tmp");
    1047           0 :         checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "/c:/tmp");
    1048           0 :         checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "c:\\tmp");
    1049           0 :     }
    1050           0 :     void SystemPath_FileURL::getSystemPathFromFileURL_001_53()
    1051             :     {
    1052             : // LLA: is this a legal file path?
    1053           0 :         rtl::OString sURL("file:///c|/tmp");
    1054           0 :         checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "/c|/tmp");
    1055           0 :         checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "c:\\tmp");
    1056           0 :     }
    1057           0 :     void SystemPath_FileURL::getSystemPathFromFileURL_001_6()
    1058             :     {
    1059           0 :         rtl::OString sURL("file:///tmp/first");
    1060           0 :         checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "/tmp/first");
    1061           0 :         checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, "");
    1062           0 :     }
    1063           0 :     void SystemPath_FileURL::getSystemPathFromFileURL_001_61()
    1064             :     {
    1065           0 :         rtl::OString sURL("file:///c:/tmp/first");
    1066           0 :         checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "/c:/tmp/first");
    1067           0 :         checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "c:\\tmp\\first");
    1068           0 :     }
    1069           0 :     void SystemPath_FileURL::getSystemPathFromFileURL_001_7()
    1070             :     {
    1071           0 :         rtl::OString sURL("file:///tmp/../second");
    1072           0 :         checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "/tmp/../second"); // LLA: may be a BUG
    1073           0 :         checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, "");
    1074           0 :     }
    1075           0 :     void SystemPath_FileURL::getSystemPathFromFileURL_001_71()
    1076             :     {
    1077           0 :         rtl::OString sURL("file:///c:/tmp/../second");
    1078           0 :         checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "/c:/tmp/../second");
    1079           0 :         checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "c:\\tmp\\..\\second");
    1080           0 :     }
    1081           0 :     void SystemPath_FileURL::getSystemPathFromFileURL_001_8()
    1082             :     {
    1083           0 :         rtl::OString sURL("../tmp");
    1084           0 :         checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "../tmp");
    1085           0 :         checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "..\\tmp");
    1086           0 :     }
    1087           0 :     void SystemPath_FileURL::getSystemPathFromFileURL_001_81()
    1088             :     {
    1089           0 :         rtl::OString sURL("file://~/tmp");
    1090             :     char* home_path;
    1091           0 :     home_path = getenv("HOME");
    1092           0 :     rtl::OString expResult(home_path);
    1093           0 :     expResult += "/tmp";
    1094           0 :     checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, expResult );
    1095             :     //  checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "\\tmp");
    1096           0 :     }
    1097           0 :     void SystemPath_FileURL::getSystemPathFromFileURL_001_9()
    1098             :     {
    1099           0 :         rtl::OString sURL("file:///tmp/first%20second");
    1100           0 :         checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "/tmp/first second");
    1101           0 :         checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, "");
    1102           0 :     }
    1103           0 :     void SystemPath_FileURL::getSystemPathFromFileURL_001_91()
    1104             :     {
    1105           0 :         rtl::OString sURL("file:///c:/tmp/first%20second");
    1106           0 :         checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "/c:/tmp/first second");
    1107           0 :         checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "c:\\tmp\\first second");
    1108           0 :     }
    1109             : 
    1110           0 :     void SystemPath_FileURL::getSystemPathFromFileURL_001_92()
    1111             :     {
    1112           0 :         rtl::OString sURL("ca@#;+.,$///78no%01ni..name");
    1113           0 :         checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "");
    1114           0 :         checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, "");
    1115           0 :     }
    1116             : 
    1117             :         //normal legal case
    1118           0 :     void SystemPath_FileURL::getSystemPathFromFileURL_004()
    1119             :         {
    1120           0 :         ::rtl::OUString aUStr;
    1121           0 :         ::rtl::OUString aUNormalURL( aTmpName6 );
    1122           0 :         ::rtl::OUString aUResultURL ( aSysPath4 );
    1123           0 :         ::osl::FileBase::RC nError = osl::FileBase::getSystemPathFromFileURL( aUNormalURL, aUStr );
    1124             : 
    1125           0 :             sal_Bool bOk = compareFileName( aUStr, aUResultURL );
    1126             : 
    1127           0 :             ::rtl::OString sError("test for getSystemPathFromFileURL(' ");
    1128           0 :             sError += ::rtl::OUStringToOString( aUNormalURL, RTL_TEXTENCODING_ASCII_US );
    1129           0 :             sError += " ') function:use an absolute file URL, ";
    1130           0 :             sError += outputError(::rtl::OUStringToOString( aUStr, RTL_TEXTENCODING_ASCII_US ),
    1131           0 :                                 ::rtl::OUStringToOString( aUResultURL, RTL_TEXTENCODING_ASCII_US ));
    1132             : 
    1133           0 :             CPPUNIT_ASSERT_MESSAGE(sError.getStr(), ( osl::FileBase::E_None == nError ) && ( sal_True == bOk ) );
    1134             : 
    1135           0 :         }
    1136             : 
    1137             :         //CJK characters case
    1138           0 :     void SystemPath_FileURL::getSystemPathFromFileURL_005()
    1139             :         {
    1140           0 :             ::rtl::OUString aUStr;
    1141           0 :             createTestDirectory( aTmpName10 );
    1142           0 :             ::rtl::OUString aUNormalURL( aTmpName10 );
    1143           0 :             ::rtl::OUString aUResultURL ( aSysPath5 );
    1144             : 
    1145           0 :             ::osl::FileBase::RC nError = osl::FileBase::getSystemPathFromFileURL( aUNormalURL, aUStr );
    1146             : 
    1147           0 :             sal_Bool bOk = compareFileName( aUStr, aUResultURL );
    1148             : 
    1149           0 :             ::rtl::OString sError("test for getSystemPathFromFileURL(' ");
    1150           0 :             sError += ::rtl::OUStringToOString( aUNormalURL, RTL_TEXTENCODING_ASCII_US );
    1151           0 :             sError += " ') function:use a CJK coded absolute URL, ";
    1152           0 :             sError += outputError(::rtl::OUStringToOString( aUStr, RTL_TEXTENCODING_ASCII_US ),
    1153           0 :                                 ::rtl::OUStringToOString( aUResultURL, RTL_TEXTENCODING_ASCII_US ));
    1154           0 :             deleteTestDirectory( aTmpName10 );
    1155             : 
    1156           0 :             CPPUNIT_ASSERT_MESSAGE( sError.getStr(), ( osl::FileBase::E_None == nError ) && ( sal_True == bOk ) );
    1157           0 :         }
    1158             : 
    1159           0 :      void SystemPath_FileURL::getFileURLFromSystemPath_001()
    1160             :      {
    1161           0 :         rtl::OString sSysPath("~/tmp");
    1162             :         char* home_path;
    1163           0 :         home_path = getenv("HOME");
    1164           0 :         rtl::OString expResult(home_path);
    1165           0 :         expResult = "file://"+ expResult + "/tmp";
    1166           0 :         checkUNXBehaviour_getFileURLFromSystemPath(sSysPath, osl::FileBase::E_None, expResult );
    1167           0 :         checkWNTBehaviour_getFileURLFromSystemPath(sSysPath, osl::FileBase::E_None, "~/tmp");
    1168           0 :      }
    1169           0 :      void SystemPath_FileURL::getFileURLFromSystemPath_002()
    1170             :      {
    1171           0 :         rtl::OString sSysPath("c:/tmp");
    1172           0 :         checkUNXBehaviour_getFileURLFromSystemPath(sSysPath, osl::FileBase::E_None, "c:/tmp");
    1173           0 :         checkWNTBehaviour_getFileURLFromSystemPath(sSysPath, osl::FileBase::E_None, "file:///c:/tmp");
    1174           0 :      }
    1175           0 :      void SystemPath_FileURL::getFileURLFromSystemPath_003()
    1176             :      {
    1177           0 :         rtl::OString sSysPath("file:///temp");
    1178           0 :         checkUNXBehaviour_getFileURLFromSystemPath(sSysPath, osl::FileBase::E_INVAL, "");
    1179           0 :         checkWNTBehaviour_getFileURLFromSystemPath(sSysPath, osl::FileBase::E_INVAL, "");
    1180           0 :      }
    1181           0 :     void SystemPath_FileURL::getFileURLFromSystemPath_004()
    1182             :      {
    1183           0 :         rtl::OString sSysPath("//tmp//first start");
    1184           0 :         checkUNXBehaviour_getFileURLFromSystemPath(sSysPath, osl::FileBase::E_None, "file:///tmp/first%20start");
    1185           0 :         checkWNTBehaviour_getFileURLFromSystemPath(sSysPath, osl::FileBase::E_INVAL, "");
    1186           0 :      }
    1187           0 :      void SystemPath_FileURL::getFileURLFromSystemPath_005()
    1188             :      {
    1189           0 :         rtl::OString sSysPath("");
    1190           0 :         checkUNXBehaviour_getFileURLFromSystemPath(sSysPath, osl::FileBase::E_INVAL, "");
    1191           0 :         checkWNTBehaviour_getFileURLFromSystemPath(sSysPath, osl::FileBase::E_INVAL, "");
    1192           0 :      }
    1193             :          // start with "~user", not impletment
    1194             :     //      void SystemPath_FileURL::getFileURLFromSystemPath_006()
    1195             : 
    1196             : 
    1197             : 
    1198             : 
    1199             :     //---------------------------------------------------------------------
    1200             :     // testing the method
    1201             :     // static inline RC searchFileURL(  const ::rtl::OUString& ustrFileName,
    1202             :     //                                  const ::rtl::OUString& ustrSearchPath,
    1203             :     //                                  ::rtl::OUString& ustrFileURL )
    1204             :     //---------------------------------------------------------------------
    1205           0 :     class searchFileURL:public CppUnit::TestFixture
    1206             :     {
    1207             :         //::osl::FileBase aFileBase;
    1208             :         ::rtl::OUString aUStr;
    1209             :         ::osl::FileBase::RC nError1, nError2, nError3,nError4;
    1210             : 
    1211             :         public:
    1212             : 
    1213           0 :         searchFileURL()
    1214             :             : nError1(FileBase::E_None)
    1215             :             , nError2(FileBase::E_None)
    1216             :             , nError3(FileBase::E_None)
    1217           0 :             , nError4(FileBase::E_None) {}
    1218             :         // test code.
    1219           0 :         void searchFileURL_001()
    1220             :         {
    1221             :             /* search file is passed by system filename */
    1222           0 :             nError1 = ::osl::FileBase::searchFileURL( aTmpName1, aUserDirectorySys, aUStr );
    1223             :             /* search file is passed by full qualified file URL */
    1224           0 :             nError2 = ::osl::FileBase::searchFileURL( aCanURL1, aUserDirectorySys, aUStr );
    1225             :             /* search file is passed by relative file path */
    1226           0 :             nError3 = ::osl::FileBase::searchFileURL( aRelURL4, aUserDirectorySys, aUStr );
    1227             : 
    1228           0 :             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) ",
    1229             :                                      ( osl::FileBase::E_NOENT == nError1 ) &&
    1230             :                                      ( osl::FileBase::E_NOENT == nError2 ) &&
    1231           0 :                                     ( osl::FileBase::E_NOENT == nError3 ));
    1232           0 :         }
    1233             : 
    1234           0 :          void searchFileURL_002()
    1235             :         {
    1236             :             /* search file is passed by system filename */
    1237           0 :             nError1 = ::osl::FileBase::searchFileURL( aTempDirectorySys, aRootSys, aUStr );
    1238           0 :             sal_Bool bOk1 = compareFileName( aUStr, aTempDirectoryURL );
    1239             :             /* search file is passed by full qualified file URL */
    1240           0 :             nError2 = ::osl::FileBase::searchFileURL( aTempDirectoryURL, aRootSys, aUStr );
    1241           0 :             sal_Bool bOk2 = compareFileName( aUStr, aTempDirectoryURL );
    1242             :             /* search file is passed by relative file path */
    1243           0 :             nError3 = ::osl::FileBase::searchFileURL( aRelURL5, aRootSys, aUStr );
    1244           0 :             sal_Bool bOk3 = compareFileName( aUStr, aTempDirectoryURL );
    1245             :             /* search file is passed by an exist file */
    1246           0 :             createTestFile( aCanURL1 );
    1247           0 :             nError4 = ::osl::FileBase::searchFileURL( aCanURL4, aUserDirectorySys, aUStr );
    1248           0 :             sal_Bool bOk4 = compareFileName( aUStr, aCanURL1 );
    1249           0 :             deleteTestFile( aCanURL1 );
    1250             : 
    1251           0 :             CPPUNIT_ASSERT_MESSAGE( "test for searchFileURL function: system filename/URL filename/relative path, system directory, searched file already exist.",
    1252             :                                     ( osl::FileBase::E_None == nError1 ) &&
    1253             :                                     ( osl::FileBase::E_None == nError2 ) &&
    1254             :                                     ( osl::FileBase::E_None == nError3 ) &&
    1255             :                                     ( osl::FileBase::E_None == nError4 ) &&
    1256             :                                     ( sal_True == bOk1 ) &&
    1257             :                                     ( sal_True == bOk2 ) &&
    1258             :                                     ( sal_True == bOk3 ) &&
    1259           0 :                                     ( sal_True == bOk4 ) );
    1260           0 :         }
    1261             : 
    1262             : 
    1263           0 :         void searchFileURL_003()
    1264             :         {
    1265           0 :             OSLTEST_DECLARE( SystemPathList,  TEST_PLATFORM_ROOT ":" TEST_PLATFORM_ROOT TEST_PLATFORM_TEMP ":" TEST_PLATFORM_ROOT "system/path" );
    1266           0 :             nError1 = ::osl::FileBase::searchFileURL( aUserDirectoryURL, aSystemPathList, aUStr );
    1267           0 :             sal_Bool bOk = compareFileName( aUStr, aUserDirectoryURL );
    1268           0 :             CPPUNIT_ASSERT_MESSAGE( "test for searchFileURL function: search directory is a list of system paths",
    1269             :                                     ( osl::FileBase::E_None == nError1 ) &&
    1270           0 :                                     ( sal_True == bOk ) );
    1271           0 :         }
    1272             : 
    1273           0 :         void searchFileURL_004()
    1274             :         {
    1275           0 :             OSLTEST_DECLARE( SystemPathList,  TEST_PLATFORM_ROOT PATH_LIST_DELIMITER TEST_PLATFORM_ROOT TEST_PLATFORM_TEMP PATH_LIST_DELIMITER TEST_PLATFORM_ROOT "system/path/../name" );
    1276           0 :             nError1 = ::osl::FileBase::searchFileURL( aUserDirectoryURL, aSystemPathList, aUStr );
    1277           0 :             sal_Bool bOk = compareFileName( aUStr, aUserDirectoryURL );
    1278           0 :             CPPUNIT_ASSERT_MESSAGE( "test for searchFileURL function: search directory is a list of system paths",
    1279             :                                     ( osl::FileBase::E_None == nError1 ) &&
    1280           0 :                                     ( sal_True == bOk ) );
    1281           0 :         }
    1282             : 
    1283           0 :         void searchFileURL_005()
    1284             :         {
    1285           0 :             nError1 = ::osl::FileBase::searchFileURL( aUserDirectoryURL, aNullURL, aUStr );
    1286           0 :             sal_Bool bOk = compareFileName( aUStr, aUserDirectoryURL );
    1287           0 :             CPPUNIT_ASSERT_MESSAGE( "test for searchFileURL function: search directory is NULL",
    1288             :                                     ( osl::FileBase::E_None == nError1 ) &&
    1289           0 :                                     ( sal_True == bOk ) );
    1290           0 :         }
    1291             : 
    1292           0 :         CPPUNIT_TEST_SUITE( searchFileURL );
    1293           0 :         CPPUNIT_TEST( searchFileURL_001 );
    1294           0 :         CPPUNIT_TEST( searchFileURL_002 );
    1295           0 :         CPPUNIT_TEST( searchFileURL_003 );
    1296           0 :         CPPUNIT_TEST( searchFileURL_004 );
    1297           0 :         CPPUNIT_TEST( searchFileURL_005 );
    1298           0 :         CPPUNIT_TEST_SUITE_END();
    1299             :     };// class searchFileURL
    1300             : 
    1301             : 
    1302             :     //---------------------------------------------------------------------
    1303             :     // testing the method
    1304             :     // static inline RC getTempDirURL( ::rtl::OUString& ustrTempDirURL )
    1305             :     //---------------------------------------------------------------------
    1306           0 :     class getTempDirURL:public CppUnit::TestFixture
    1307             :     {
    1308             :         //::osl::FileBase aFileBase;
    1309             :         ::rtl::OUString aUStr;
    1310             :         ::osl::FileBase::RC nError;
    1311             : 
    1312             :         public:
    1313           0 :         getTempDirURL() :nError(FileBase::E_None) {}
    1314             :         // initialization
    1315           0 :         void setUp()
    1316             :         {
    1317           0 :              nError = FileBase::getTempDirURL( aUStr );
    1318           0 :         }
    1319             : 
    1320           0 :         void tearDown()
    1321             :         {
    1322           0 :         }
    1323             : 
    1324             :         // test code.
    1325           0 :         void getTempDirURL_001()
    1326             :         {
    1327             : 
    1328           0 :             CPPUNIT_ASSERT_MESSAGE( "test for getTempDirURL function: excution",
    1329           0 :                                      ( osl::FileBase::E_None == nError ) );
    1330           0 :         }
    1331             : 
    1332           0 :         void getTempDirURL_002()
    1333             :         {
    1334           0 :             CPPUNIT_ASSERT_MESSAGE( "test for getTempDirURL function: test for open and write access rights",
    1335             :                                     checkDirectory( aUStr, osl_Check_Mode_OpenAccess ) &&
    1336             :                                     checkDirectory( aUStr, osl_Check_Mode_ReadAccess ) &&
    1337           0 :                                     checkDirectory( aUStr,osl_Check_Mode_WriteAccess ) );
    1338           0 :         }
    1339             : 
    1340           0 :         CPPUNIT_TEST_SUITE( getTempDirURL );
    1341           0 :         CPPUNIT_TEST( getTempDirURL_001 );
    1342           0 :         CPPUNIT_TEST( getTempDirURL_002 );
    1343           0 :         CPPUNIT_TEST_SUITE_END();
    1344             :     };// class getTempDirURL
    1345             : 
    1346             : 
    1347             :     //---------------------------------------------------------------------
    1348             :     //  testing the method
    1349             :     //  static inline RC createTempFile( ::rtl::OUString* pustrDirectoryURL,
    1350             :     //                                   oslFileHandle* pHandle,
    1351             :     //                                   ::rtl::OUString* pustrTempFileURL)
    1352             :     //---------------------------------------------------------------------
    1353           0 :     class createTempFile:public CppUnit::TestFixture
    1354             :     {
    1355             :         //::osl::FileBase aFileBase;
    1356             :         ::osl::FileBase::RC nError1, nError2;
    1357             :         sal_Bool bOK;
    1358             : 
    1359             :         oslFileHandle   *pHandle;
    1360             :         ::rtl::OUString *pUStr_DirURL;
    1361             :         ::rtl::OUString *pUStr_FileURL;
    1362             : 
    1363             :         public:
    1364           0 :         createTempFile() :nError1(FileBase::E_None),nError2(FileBase::E_None) {}
    1365             : 
    1366             :         // initialization
    1367           0 :         void setUp()
    1368             :         {
    1369           0 :             pHandle = new oslFileHandle();
    1370           0 :             pUStr_DirURL = new ::rtl::OUString( aUserDirectoryURL );
    1371           0 :             pUStr_FileURL = new ::rtl::OUString();
    1372             :             //*pUStr_DirURL = aUserDirectoryURL;                /// create temp file in /tmp/PID or c:\temp\PID.*/
    1373           0 :         }
    1374             : 
    1375           0 :         void tearDown()
    1376             :         {
    1377           0 :             delete pUStr_DirURL;
    1378           0 :             delete pUStr_FileURL;
    1379           0 :             delete pHandle;
    1380           0 :         }
    1381             : 
    1382             :         // test code.
    1383           0 :         void createTempFile_001()
    1384             :         {
    1385           0 :             nError1 = FileBase::createTempFile( pUStr_DirURL, pHandle, pUStr_FileURL );
    1386           0 :             ::osl::File testFile( *pUStr_FileURL );
    1387           0 :             nError2 = testFile.open( osl_File_OpenFlag_Create );
    1388           0 :             if ( osl::FileBase::E_EXIST == nError2 )  {
    1389           0 :                 osl_closeFile( *pHandle );
    1390           0 :                 deleteTestFile( *pUStr_FileURL );
    1391             :             }
    1392             : 
    1393           0 :             CPPUNIT_ASSERT_MESSAGE( "test for createTempFile function: create temp file and test the existence",
    1394           0 :                                      ( osl::FileBase::E_None == nError1 ) && ( pHandle != NULL ) &&   ( osl::FileBase::E_EXIST== nError2 )   );
    1395           0 :         }
    1396             : 
    1397           0 :         void createTempFile_002()
    1398             :         {
    1399           0 :             bOK = sal_False;
    1400           0 :             nError1 = FileBase::createTempFile( pUStr_DirURL, pHandle, pUStr_FileURL );
    1401           0 :             ::osl::File testFile( *pUStr_FileURL );
    1402           0 :             nError2 = testFile.open( osl_File_OpenFlag_Create );
    1403             : 
    1404           0 :             CPPUNIT_ASSERT_MESSAGE( "createTempFile function: create a temp file, but it does not exist",
    1405             :                 ( osl::FileBase::E_None == nError1 ) && ( pHandle != NULL ) &&
    1406           0 :                 ( osl::FileBase::E_EXIST == nError2 ) );
    1407             : 
    1408             :             //check file if have the write permission
    1409           0 :             if ( osl::FileBase::E_EXIST == nError2 )  {
    1410           0 :                 bOK = ifFileCanWrite( *pUStr_FileURL );
    1411           0 :                 osl_closeFile( *pHandle );
    1412           0 :                 deleteTestFile( *pUStr_FileURL );
    1413             :             }
    1414             : 
    1415           0 :             CPPUNIT_ASSERT_MESSAGE( "test for open and write access rights, in (W32), it did not have write access right, but it should be writtenable.",
    1416           0 :                                      ( sal_True == bOK ) );
    1417           0 :         }
    1418             : 
    1419           0 :         void createTempFile_003()
    1420             :         {
    1421           0 :             nError1 = FileBase::createTempFile( pUStr_DirURL, pHandle, 0 );
    1422             :             //the temp file will be removed when return from createTempFile
    1423           0 :             bOK = ( pHandle != NULL && pHandle != 0);
    1424           0 :             if ( sal_True == bOK )
    1425           0 :                 osl_closeFile( *pHandle );
    1426             : 
    1427           0 :             CPPUNIT_ASSERT_MESSAGE( "test for createTempFile function: set pUStrFileURL to 0 to let it remove the file after call.",
    1428           0 :                                 ( ::osl::FileBase::E_None == nError1 ) &&( sal_True == bOK ) );
    1429           0 :         }
    1430           0 :         void createTempFile_004()
    1431             :         {
    1432           0 :             nError1 = FileBase::createTempFile( pUStr_DirURL, 0, pUStr_FileURL );
    1433           0 :             bOK = ( pUStr_FileURL != 0);
    1434           0 :             ::osl::File testFile( *pUStr_FileURL );
    1435           0 :             nError2 = testFile.open( osl_File_OpenFlag_Create );
    1436           0 :             deleteTestFile( *pUStr_FileURL );
    1437           0 :             CPPUNIT_ASSERT_MESSAGE( "createTempFile function: create a temp file, but it does not exist",
    1438           0 :                 ( osl::FileBase::E_None == nError1 ) && ( osl::FileBase::E_EXIST == nError2 ) &&( sal_True == bOK ) );
    1439             : 
    1440           0 :         }
    1441             : 
    1442           0 :         CPPUNIT_TEST_SUITE( createTempFile );
    1443           0 :         CPPUNIT_TEST( createTempFile_001 );
    1444           0 :         CPPUNIT_TEST( createTempFile_002 );
    1445           0 :         CPPUNIT_TEST( createTempFile_003 );
    1446           0 :         CPPUNIT_TEST( createTempFile_004 );
    1447           0 :         CPPUNIT_TEST_SUITE_END();
    1448             :     };// class createTempFile
    1449             : 
    1450             :     // -----------------------------------------------------------------------------
    1451           1 :     CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileBase::getAbsoluteFileURL, "osl_FileBase" );
    1452           1 :     CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileBase::SystemPath_FileURL, "osl_FileBase" );
    1453             :   //        CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileBase::getFileURLFromSystemPath, "osl_FileBase" );
    1454           1 :     CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileBase::searchFileURL, "osl_FileBase" );
    1455           1 :     CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileBase::getTempDirURL, "osl_FileBase" );
    1456           1 :     CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileBase::createTempFile, "osl_FileBase" );
    1457             : }// namespace osl_FileBase
    1458             : 
    1459             : 
    1460             : //------------------------------------------------------------------------
    1461             : // Beginning of the test cases for VolumeInfo class
    1462             : //------------------------------------------------------------------------
    1463             : namespace osl_VolumeInfo
    1464             : {
    1465             : 
    1466             :     //---------------------------------------------------------------------
    1467             :     //  testing the method
    1468             :     //  VolumeInfo( sal_uInt32 nMask ): _nMask( nMask )
    1469             :     //---------------------------------------------------------------------
    1470             :     class  ctors : public CppUnit::TestFixture
    1471             :     {
    1472             :         ::rtl::OUString aUStr;
    1473             :         ::osl::FileBase::RC nError1, nError2;
    1474             : 
    1475             :          ::osl::VolumeDevice aVolumeDevice1;
    1476             : 
    1477             :         public:
    1478             :         ctors() :nError1(FileBase::E_None),nError2(FileBase::E_None) {}
    1479             :         // initialization
    1480             :         void setUp()
    1481             :         {
    1482             :         }
    1483             : 
    1484             :         void tearDown()
    1485             :         {
    1486             :         }
    1487             : 
    1488             :         // test code.
    1489             :         void ctors_001()
    1490             :         {
    1491             :             ::osl::VolumeInfo   aVolumeInfo( 0 );
    1492             :             nError1 = ::osl::Directory::getVolumeInfo( aRootURL, aVolumeInfo );
    1493             :             CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
    1494             :             sal_uInt64 uiTotalSpace = aVolumeInfo.getTotalSpace();
    1495             :             sal_uInt32 uiMaxPathLength = aVolumeInfo.getMaxPathLength();
    1496             :             aUStr = aVolumeInfo.getFileSystemName();
    1497             : 
    1498             :             CPPUNIT_ASSERT_MESSAGE( "test for ctors function: mask is empty",
    1499             :                                      ( 0 == uiTotalSpace ) &&
    1500             :                                     ( 0 == uiMaxPathLength ) &&
    1501             :                                     sal_True == compareFileName( aUStr, aNullURL ) );
    1502             :         }
    1503             : 
    1504             : #if ( defined UNX )
    1505             :         void ctors_002()
    1506             :         {
    1507             :             ::osl::VolumeInfo   aVolumeInfo( osl_VolumeInfo_Mask_TotalSpace |
    1508             :                                              osl_VolumeInfo_Mask_UsedSpace |
    1509             :                                              osl_VolumeInfo_Mask_FileSystemName );
    1510             :             nError1 = ::osl::Directory::getVolumeInfo( aVolURL4, aVolumeInfo );
    1511             :             CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
    1512             :             //CPPUNIT_ASSERT( aVolumeInfo.isValid( mask ) );
    1513             :             sal_uInt64 uiTotalSpace = aVolumeInfo.getTotalSpace();
    1514             :             sal_uInt64 uiUsedSpace = aVolumeInfo.getUsedSpace();
    1515             :             aUStr = aVolumeInfo.getFileSystemName();
    1516             : 
    1517             :             CPPUNIT_ASSERT_MESSAGE( "test for ctors function: mask is specified as certain valid fields, and get the masked fields",
    1518             :                                      ( 0 != uiTotalSpace ) &&
    1519             :                                     ( 0 != uiUsedSpace ) &&
    1520             :                                     sal_True == compareFileName( aUStr, "nfs" ) );
    1521             :         }
    1522             : #else           /// Windows version,here we can not determine whichvolume in Windows is serve as an nfs volume.
    1523             :         void ctors_002()
    1524             :         {
    1525             :             CPPUNIT_ASSERT_MESSAGE( "test for ctors function: mask is specified as certain valid fields, and get the masked fields( Windows version )",
    1526             :                                      1 == 1 );
    1527             :         }
    1528             : #endif
    1529             : 
    1530             :         void ctors_003()
    1531             :         {
    1532             : 
    1533             :              sal_Int32 mask1 = osl_VolumeInfo_Mask_FreeSpace;
    1534             :             ::osl::VolumeInfo aVolumeInfo1( mask1 );
    1535             :             nError1 = ::osl::Directory::getVolumeInfo( aRootURL, aVolumeInfo1 );
    1536             :             CPPUNIT_ASSERT( sal_True == aVolumeInfo1.isValid( mask1 ) );
    1537             :             CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
    1538             : 
    1539             :             sal_uInt64 uiTotalSpace1 = aVolumeInfo1.getTotalSpace();
    1540             :             aUStr = aVolumeInfo1.getFileSystemName();
    1541             : 
    1542             :              sal_Int32 mask2 = osl_VolumeInfo_Mask_TotalSpace;
    1543             :             ::osl::VolumeInfo aVolumeInfo2( mask2 );
    1544             :             nError2 = ::osl::Directory::getVolumeInfo( aRootURL, aVolumeInfo2 );
    1545             :             CPPUNIT_ASSERT( sal_True == aVolumeInfo2.isValid( mask2 ) );
    1546             :             CPPUNIT_ASSERT( osl::FileBase::E_None == nError2 );
    1547             : 
    1548             :             sal_uInt64 uiTotalSpace2 = aVolumeInfo2.getTotalSpace();
    1549             : 
    1550             :             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)",
    1551             :                                      ( 0 == uiTotalSpace1 ) && ( 0 != uiTotalSpace2 ) &&
    1552             :                                     sal_True == compareFileName( aUStr, aNullURL ) );
    1553             :         }
    1554             : 
    1555             :         CPPUNIT_TEST_SUITE( ctors );
    1556             :         CPPUNIT_TEST( ctors_001 );
    1557             :         CPPUNIT_TEST( ctors_002 );
    1558             :         CPPUNIT_TEST( ctors_003 );
    1559             :         CPPUNIT_TEST_SUITE_END();
    1560             :     };// class ctors
    1561             : 
    1562             : 
    1563             :      //---------------------------------------------------------------------
    1564             :     //  testing the method
    1565             :     //  inline sal_Bool isValid( sal_uInt32 nMask ) const
    1566             :     //---------------------------------------------------------------------
    1567             :     class  isValid : public CppUnit::TestFixture
    1568             :     {
    1569             :         ::osl::VolumeDevice aVolumeDevice;
    1570             :         ::rtl::OUString aUStr;
    1571             :         ::osl::FileBase::RC nError1;
    1572             : 
    1573             :         public:
    1574             :         isValid() :nError1(FileBase::E_None) {}
    1575             :         // initialization
    1576             :         void setUp()
    1577             :         {
    1578             :         }
    1579             : 
    1580             :         void tearDown()
    1581             :         {
    1582             : 
    1583             :         }
    1584             : 
    1585             :         // test code.
    1586             :         void isValid_001()
    1587             :         {
    1588             :             sal_Int32 mask = 0;
    1589             :             ::osl::VolumeInfo aVolumeInfo( mask );
    1590             :             nError1 = ::osl::Directory::getVolumeInfo( aVolURL4, aVolumeInfo );
    1591             :             CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
    1592             : 
    1593             :             CPPUNIT_ASSERT_MESSAGE( "test for isValid function: no fields specified.",
    1594             :                                       sal_True == aVolumeInfo.isValid( mask ) );
    1595             :         }
    1596             : 
    1597             : #if ( defined UNX )
    1598             :           void isValid_002()
    1599             :         {
    1600             :             sal_Int32 mask = osl_VolumeInfo_Mask_Attributes | osl_VolumeInfo_Mask_TotalSpace | osl_VolumeInfo_Mask_UsedSpace |
    1601             :                              osl_VolumeInfo_Mask_FreeSpace | osl_VolumeInfo_Mask_MaxNameLength |
    1602             :                              osl_VolumeInfo_Mask_MaxPathLength | osl_VolumeInfo_Mask_FileSystemName;
    1603             :             ::osl::VolumeInfo aVolumeInfo( mask );
    1604             :             nError1 = ::osl::Directory::getVolumeInfo( aVolURL4, aVolumeInfo );
    1605             :             CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
    1606             : 
    1607             :             CPPUNIT_ASSERT_MESSAGE( "test for isValid function: all valid fields specified for a nfs volume.",
    1608             :                                      sal_True == aVolumeInfo.isValid( mask ) );
    1609             :         }
    1610             : #else           /// Windows version,here we can not determine whichvolume in Windows is serve as an nfs volume.
    1611             :         void isValid_002()
    1612             :         {
    1613             :             CPPUNIT_ASSERT_MESSAGE( "test for isValid function: all valid fields specified for a nfs volume.( Windows version )",
    1614             :                                      1 == 1 );
    1615             :         }
    1616             : #endif
    1617             : 
    1618             :          void isValid_003()
    1619             :         {
    1620             :              ::osl::VolumeDevice aVolumeDevice1;
    1621             :             sal_Int32 mask = osl_VolumeInfo_Mask_Attributes;
    1622             :             ::osl::VolumeInfo   aVolumeInfo( mask );
    1623             :             nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
    1624             :             CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
    1625             :             sal_Bool bOk1 = aVolumeInfo.isValid( mask );
    1626             : 
    1627             :             nError1 = ::osl::Directory::getVolumeInfo( aVolURL2, aVolumeInfo );
    1628             :             CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
    1629             :             sal_Bool bOk2 = aVolumeInfo.isValid( mask );
    1630             : 
    1631             :             CPPUNIT_ASSERT_MESSAGE( "test for isValid function: osl_VolumeInfo_Mask_Attributes, it should be valid for some volume such as /, floppy, cdrom, etc. but it did not pass",
    1632             :                                      ( sal_True == bOk1 ) && ( sal_True == bOk2 ) );
    1633             :         }
    1634             : 
    1635             :         CPPUNIT_TEST_SUITE( isValid );
    1636             :         CPPUNIT_TEST( isValid_001 );
    1637             :         CPPUNIT_TEST( isValid_002 );
    1638             :         CPPUNIT_TEST( isValid_003 );
    1639             :         CPPUNIT_TEST_SUITE_END();
    1640             :     };// class isValid
    1641             : 
    1642             :      //---------------------------------------------------------------------
    1643             :     //  testing the method
    1644             :     //  inline sal_Bool getRemoteFlag() const
    1645             :     //---------------------------------------------------------------------
    1646             :     class  getRemoteFlag : public CppUnit::TestFixture
    1647             :     {
    1648             :         ::osl::VolumeDevice aVolumeDevice;
    1649             :         ::rtl::OUString aUStr;
    1650             :         ::osl::FileBase::RC nError1;
    1651             : 
    1652             :         public:
    1653             :         getRemoteFlag() :nError1(FileBase::E_None) {}
    1654             :         // test code.
    1655             :         void getRemoteFlag_001()
    1656             :         {
    1657             :             sal_Int32 mask = osl_VolumeInfo_Mask_Attributes;
    1658             :             ::osl::VolumeInfo aVolumeInfo( mask );
    1659             :             nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
    1660             :             CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
    1661             :             sal_Bool bOk = aVolumeInfo.getRemoteFlag();
    1662             : 
    1663             :             CPPUNIT_ASSERT_MESSAGE( "test for getRemoteFlag function: get a volume device which is not remote.",
    1664             :                                      ( sal_False == bOk ) );
    1665             :         }
    1666             : 
    1667             :  #if ( defined UNX )        //remote Volume is different in Solaris and Windows
    1668             :         void getRemoteFlag_002()
    1669             :         {
    1670             :             sal_Int32 mask = osl_VolumeInfo_Mask_Attributes;
    1671             :             ::osl::VolumeInfo aVolumeInfo( mask );
    1672             :             nError1 = ::osl::Directory::getVolumeInfo( aVolURL4, aVolumeInfo );
    1673             :             CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
    1674             :             sal_Bool bOk = aVolumeInfo.getRemoteFlag();
    1675             : 
    1676             :             CPPUNIT_ASSERT_MESSAGE( "test for getRemoteFlag function: get a volume device which is remote( Solaris version ).",
    1677             :                                      ( sal_True == bOk ) );
    1678             :         }
    1679             : #else                                    //Windows version
    1680             :         void getRemoteFlag_002()
    1681             :         {
    1682             :             CPPUNIT_ASSERT_MESSAGE( "test for getRemoteFlag function: get a volume device which is remote( Windows version )",
    1683             :                                      1 == 1 );
    1684             :         }
    1685             : #endif
    1686             : 
    1687             :         CPPUNIT_TEST_SUITE( getRemoteFlag );
    1688             :         CPPUNIT_TEST( getRemoteFlag_001 );
    1689             :         CPPUNIT_TEST( getRemoteFlag_002 );
    1690             :         CPPUNIT_TEST_SUITE_END();
    1691             :     };// class getRemoteFlag
    1692             : 
    1693             :     //---------------------------------------------------------------------
    1694             :     //  testing the method
    1695             :     //  inline sal_Bool getRemoveableFlag() const
    1696             :     //---------------------------------------------------------------------
    1697             :     class  getRemoveableFlag : public CppUnit::TestFixture
    1698             :     {
    1699             :         ::osl::FileBase::RC nError1;
    1700             : 
    1701             :         public:
    1702             :         getRemoveableFlag() :nError1(FileBase::E_None) {}
    1703             :         // test code.
    1704             :         void getRemoveableFlag_001()
    1705             :         {
    1706             :             sal_Int32 mask = osl_VolumeInfo_Mask_Attributes;
    1707             :             ::osl::VolumeInfo aVolumeInfo( mask );
    1708             :             nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
    1709             :             CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
    1710             :             sal_Bool bOk = aVolumeInfo.getRemoveableFlag();
    1711             : 
    1712             :             CPPUNIT_ASSERT_MESSAGE( "test for getRemoveableFlag function: get a volume device which is not removable.",
    1713             :                                      sal_False == bOk );
    1714             :         }
    1715             : 
    1716             :         void getRemoveableFlag_002()
    1717             :         {
    1718             :             sal_Int32 mask = osl_VolumeInfo_Mask_Attributes;
    1719             :             ::osl::VolumeInfo aVolumeInfo( mask );
    1720             :             nError1 = ::osl::Directory::getVolumeInfo( aVolURL2, aVolumeInfo );
    1721             :             CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
    1722             :             sal_Bool bOk = aVolumeInfo.getRemoveableFlag();
    1723             : 
    1724             :             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.",
    1725             :                                      sal_True == bOk );
    1726             :         }
    1727             :         CPPUNIT_TEST_SUITE( getRemoveableFlag );
    1728             :         CPPUNIT_TEST( getRemoveableFlag_001 );
    1729             :         CPPUNIT_TEST( getRemoveableFlag_002 );
    1730             :         CPPUNIT_TEST_SUITE_END();
    1731             :     };// class getRemoveableFlag
    1732             : 
    1733             : 
    1734             :     //---------------------------------------------------------------------
    1735             :     //  testing the method
    1736             :     //  inline sal_Bool getCompactDiscFlag() const
    1737             :     //---------------------------------------------------------------------
    1738             :     class  getCompactDiscFlag : public CppUnit::TestFixture
    1739             :     {
    1740             :         ::osl::FileBase::RC nError1;
    1741             : 
    1742             :         public:
    1743             :         getCompactDiscFlag() :nError1(FileBase::E_None) {}
    1744             :         // test code.
    1745             :         void getCompactDiscFlag_001()
    1746             :         {
    1747             :             sal_Int32 mask = osl_VolumeInfo_Mask_Attributes;
    1748             :             ::osl::VolumeInfo aVolumeInfo( mask );
    1749             :             nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
    1750             :             CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
    1751             :             sal_Bool bOk = aVolumeInfo.getCompactDiscFlag();
    1752             : 
    1753             :             CPPUNIT_ASSERT_MESSAGE( "test for getCompactDiscFlag function: get a volume device which is not a cdrom.",
    1754             :                                       ( sal_False == bOk ) );
    1755             :         }
    1756             : 
    1757             :         void getCompactDiscFlag_002()
    1758             :         {
    1759             :              sal_Int32 mask = osl_VolumeInfo_Mask_Attributes;
    1760             :             ::osl::VolumeInfo aVolumeInfo( mask );
    1761             :             nError1 = ::osl::Directory::getVolumeInfo( aVolURL6, aVolumeInfo );
    1762             :             CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
    1763             :             sal_Bool bOk = aVolumeInfo.getCompactDiscFlag();
    1764             : 
    1765             :             CPPUNIT_ASSERT_MESSAGE( "test for getCompactDiscFlag function: get a cdrom volume device flag, it did not pass.",
    1766             :                                       ( sal_True == bOk ) );
    1767             :         }
    1768             :         CPPUNIT_TEST_SUITE( getCompactDiscFlag );
    1769             :         CPPUNIT_TEST( getCompactDiscFlag_001 );
    1770             :         CPPUNIT_TEST( getCompactDiscFlag_002 );
    1771             :         CPPUNIT_TEST_SUITE_END();
    1772             :     };// class getCompactDiscFlag
    1773             : 
    1774             : 
    1775             :     //---------------------------------------------------------------------
    1776             :     //  testing the method
    1777             :     //  inline sal_Bool getFloppyDiskFlag() const
    1778             :     //---------------------------------------------------------------------
    1779             :     class  getFloppyDiskFlag : public CppUnit::TestFixture
    1780             :     {
    1781             :         ::osl::FileBase::RC nError1;
    1782             : 
    1783             :         public:
    1784             :         getFloppyDiskFlag() :nError1(FileBase::E_None) {}
    1785             :         // test code.
    1786             :         void getFloppyDiskFlag_001()
    1787             :         {
    1788             :             sal_Int32 mask = osl_VolumeInfo_Mask_Attributes;
    1789             :             ::osl::VolumeInfo aVolumeInfo( mask );
    1790             :             nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
    1791             :             CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
    1792             :             sal_Bool bOk = aVolumeInfo.getFloppyDiskFlag();
    1793             : 
    1794             :             CPPUNIT_ASSERT_MESSAGE( "test for getFloppyDiskFlag function: get a volume device which is not a floppy disk.",
    1795             :                                       ( sal_False == bOk ) );
    1796             :         }
    1797             : 
    1798             :         void getFloppyDiskFlag_002()
    1799             :         {
    1800             :              sal_Int32 mask = osl_VolumeInfo_Mask_Attributes;
    1801             :             ::osl::VolumeInfo aVolumeInfo( mask );
    1802             :             nError1 = ::osl::Directory::getVolumeInfo( aVolURL2, aVolumeInfo );
    1803             :             CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
    1804             :             sal_Bool bOk = aVolumeInfo.getFloppyDiskFlag();
    1805             : 
    1806             :             CPPUNIT_ASSERT_MESSAGE( "test for getFloppyDiskFlag function: get a floppy volume device flag, it did not pass.",
    1807             :                                       ( sal_True == bOk ) );
    1808             :         }
    1809             :         CPPUNIT_TEST_SUITE( getFloppyDiskFlag );
    1810             :         CPPUNIT_TEST( getFloppyDiskFlag_001 );
    1811             :         CPPUNIT_TEST( getFloppyDiskFlag_002 );
    1812             :         CPPUNIT_TEST_SUITE_END();
    1813             :     };// class getFloppyDiskFlag
    1814             : 
    1815             : 
    1816             :     //---------------------------------------------------------------------
    1817             :     //  testing the method
    1818             :     //  inline sal_Bool getFixedDiskFlag() const
    1819             :     //---------------------------------------------------------------------
    1820             :     class  getFixedDiskFlag : public CppUnit::TestFixture
    1821             :     {
    1822             :         ::osl::FileBase::RC nError1;
    1823             : 
    1824             :         public:
    1825             :         getFixedDiskFlag() :nError1(FileBase::E_None) {}
    1826             :         // test code.
    1827             :         void getFixedDiskFlag_001()
    1828             :         {
    1829             :             sal_Int32 mask = osl_VolumeInfo_Mask_Attributes;
    1830             :             ::osl::VolumeInfo aVolumeInfo( mask );
    1831             :             nError1 = ::osl::Directory::getVolumeInfo( aVolURL2, aVolumeInfo );
    1832             :             CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
    1833             :             sal_Bool bOk = aVolumeInfo.getFixedDiskFlag();
    1834             : 
    1835             :             CPPUNIT_ASSERT_MESSAGE( "test for getFixedDiskFlag function: get a volume device which is not a fixed disk.",
    1836             :                                      ( sal_False == bOk ) );
    1837             :         }
    1838             : 
    1839             :         void getFixedDiskFlag_002()
    1840             :         {
    1841             :              sal_Int32 mask = osl_VolumeInfo_Mask_Attributes;
    1842             :             ::osl::VolumeInfo aVolumeInfo( mask );
    1843             :             nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
    1844             :             CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
    1845             :             sal_Bool bOk = aVolumeInfo.getFixedDiskFlag();
    1846             : 
    1847             :             CPPUNIT_ASSERT_MESSAGE( "test for getFixedDiskFlag function: get a fixed disk volume device flag, it did not pass.",
    1848             :                                      ( sal_True == bOk ) );
    1849             :         }
    1850             :         CPPUNIT_TEST_SUITE( getFixedDiskFlag );
    1851             :         CPPUNIT_TEST( getFixedDiskFlag_001 );
    1852             :         CPPUNIT_TEST( getFixedDiskFlag_002 );
    1853             :         CPPUNIT_TEST_SUITE_END();
    1854             :     };// class getFixedDiskFlag
    1855             : 
    1856             :     //---------------------------------------------------------------------
    1857             :     //  testing the method
    1858             :     //  inline sal_Bool getRAMDiskFlag() const
    1859             :     //---------------------------------------------------------------------
    1860             :     class  getRAMDiskFlag : public CppUnit::TestFixture
    1861             :     {
    1862             :         ::osl::FileBase::RC nError1;
    1863             : 
    1864             :         public:
    1865             :         getRAMDiskFlag() :nError1(FileBase::E_None) {}
    1866             :         // test code.
    1867             :         void getRAMDiskFlag_001()
    1868             :         {
    1869             :             sal_Int32 mask = osl_VolumeInfo_Mask_Attributes;
    1870             :             ::osl::VolumeInfo aVolumeInfo( mask );
    1871             :             nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
    1872             :             CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
    1873             :             sal_Bool bOk = aVolumeInfo.getRAMDiskFlag();
    1874             : 
    1875             :             CPPUNIT_ASSERT_MESSAGE( "test for getRAMDiskFlag function: get a volume device which is not a RAM disk.",
    1876             :                                      ( sal_False == bOk ) );
    1877             :         }
    1878             : 
    1879             :         void getRAMDiskFlag_002()
    1880             :         {
    1881             :              sal_Int32 mask = osl_VolumeInfo_Mask_Attributes;
    1882             :             ::osl::VolumeInfo aVolumeInfo( mask );
    1883             :             nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
    1884             :             CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
    1885             :             sal_Bool bOk = aVolumeInfo.getRAMDiskFlag();
    1886             : 
    1887             :             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).",
    1888             :                                      ( sal_True == bOk ) );
    1889             :         }
    1890             :         CPPUNIT_TEST_SUITE( getRAMDiskFlag );
    1891             :         CPPUNIT_TEST( getRAMDiskFlag_001 );
    1892             :         CPPUNIT_TEST( getRAMDiskFlag_002 );
    1893             :         CPPUNIT_TEST_SUITE_END();
    1894             :     };// class getRAMDiskFlag
    1895             : 
    1896             : 
    1897             :     //---------------------------------------------------------------------
    1898             :     //  testing the method
    1899             :     //  inline sal_uInt64 getTotalSpace() const
    1900             :     //---------------------------------------------------------------------
    1901             :     class  getTotalSpace : public CppUnit::TestFixture
    1902             :     {
    1903             :         ::osl::FileBase::RC nError1;
    1904             : 
    1905             :         public:
    1906             :         getTotalSpace() :nError1(FileBase::E_None) {}
    1907             :         // test code.
    1908             :         void getTotalSpace_001()
    1909             :         {
    1910             :             sal_Int32 mask = osl_VolumeInfo_Mask_TotalSpace;
    1911             :             ::osl::VolumeInfo aVolumeInfo( mask );
    1912             :             nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
    1913             :             CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
    1914             :             CPPUNIT_ASSERT( sal_True == aVolumeInfo.isValid( mask ) );
    1915             :             sal_uInt64 uiTotalSpace = aVolumeInfo.getTotalSpace();
    1916             : 
    1917             :             CPPUNIT_ASSERT_MESSAGE( "test for getTotalSpace function: get total space of Fixed disk volume mounted on /, it should not be 0",
    1918             :                                      0 != uiTotalSpace );
    1919             :         }
    1920             : 
    1921             :  #if defined( UNX )
    1922             :         void getTotalSpace_002()
    1923             :         {
    1924             :              sal_Int32 mask = osl_VolumeInfo_Mask_TotalSpace;
    1925             :             ::osl::VolumeInfo aVolumeInfo( mask );
    1926             :             nError1 = ::osl::Directory::getVolumeInfo( aVolURL3, aVolumeInfo );
    1927             :             CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
    1928             :             CPPUNIT_ASSERT( sal_True == aVolumeInfo.isValid( mask ) );
    1929             :             sal_uInt64 uiTotalSpace = aVolumeInfo.getTotalSpace();
    1930             : 
    1931             :             CPPUNIT_ASSERT_MESSAGE( "test for getTotalSpace function: get total space of /proc, it should be 0",
    1932             :                                      0 == uiTotalSpace );
    1933             :         }
    1934             : #else           /// Windows version, in Windows, there is no /proc directory
    1935             :         void getTotalSpace_002()
    1936             :         {
    1937             :             CPPUNIT_ASSERT_MESSAGE( "test for getTotalSpace function:not applicable for /proc( Windows version )",
    1938             :                                      1 == 1 );
    1939             :         }
    1940             : #endif
    1941             : 
    1942             : 
    1943             : 
    1944             : #if defined(SOLARIS)
    1945             :          void getTotalSpace_003()
    1946             :         {
    1947             :              struct statvfs aStatFS;
    1948             :             static const sal_Char  name[] = "/";
    1949             : 
    1950             :             memset (&aStatFS, 0, sizeof(aStatFS));
    1951             :             statvfs( name, &aStatFS);
    1952             :             sal_uInt64 TotalSpace = aStatFS.f_frsize * aStatFS.f_blocks ;
    1953             : 
    1954             :              sal_Int32 mask = osl_VolumeInfo_Mask_TotalSpace;
    1955             :             ::osl::VolumeInfo aVolumeInfo( mask );
    1956             :             nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
    1957             :             CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
    1958             :             CPPUNIT_ASSERT( sal_True == aVolumeInfo.isValid( mask ) );
    1959             :             sal_uInt64 uiTotalSpace = aVolumeInfo.getTotalSpace();
    1960             : 
    1961             :              CPPUNIT_ASSERT_MESSAGE( "test for getTotalSpace function: get total space by hand, then compare with getTotalSpace, it did not pass",
    1962             :                                      uiTotalSpace == TotalSpace );
    1963             :         }
    1964             : #else           /// Windows version
    1965             :         void getTotalSpace_003()
    1966             :         {
    1967             :             CPPUNIT_ASSERT_MESSAGE( "test for getTotalSpace function:not implemented yet( Windows version )",
    1968             :                                      1 == 1 );
    1969             :         }
    1970             : #endif
    1971             : 
    1972             :         CPPUNIT_TEST_SUITE( getTotalSpace );
    1973             :         CPPUNIT_TEST( getTotalSpace_001 );
    1974             :         CPPUNIT_TEST( getTotalSpace_002 );
    1975             :         CPPUNIT_TEST( getTotalSpace_003 );
    1976             :         CPPUNIT_TEST_SUITE_END();
    1977             :     };// class getTotalSpace
    1978             : 
    1979             :     //---------------------------------------------------------------------
    1980             :     //  testing the method
    1981             :     //  inline sal_uInt64 getFreeSpace() const
    1982             :     //---------------------------------------------------------------------
    1983             :     class  getFreeSpace : public CppUnit::TestFixture
    1984             :     {
    1985             :         ::osl::FileBase::RC nError1;
    1986             : 
    1987             :         public:
    1988             :         getFreeSpace() :nError1(FileBase::E_None) {}
    1989             :         // test code.
    1990             :         void getFreeSpace_001()
    1991             :         {
    1992             :             sal_Int32 mask = osl_VolumeInfo_Mask_FreeSpace;
    1993             :             ::osl::VolumeInfo aVolumeInfo( mask );
    1994             :             nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
    1995             :             CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
    1996             :             CPPUNIT_ASSERT( sal_True == aVolumeInfo.isValid( mask ) );
    1997             :             sal_uInt64 uiFreeSpace = aVolumeInfo.getFreeSpace();
    1998             : 
    1999             :             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",
    2000             :                                      0 != uiFreeSpace );
    2001             :         }
    2002             : 
    2003             : #if defined( UNX )
    2004             :           void getFreeSpace_002()
    2005             :         {
    2006             :              sal_Int32 mask = osl_VolumeInfo_Mask_FreeSpace;
    2007             :             ::osl::VolumeInfo aVolumeInfo( mask );
    2008             :             nError1 = ::osl::Directory::getVolumeInfo( aVolURL3, aVolumeInfo );
    2009             :             CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
    2010             :             CPPUNIT_ASSERT( sal_True == aVolumeInfo.isValid( mask ) );
    2011             :             sal_uInt64 uiFreeSpace = aVolumeInfo.getFreeSpace();
    2012             : 
    2013             :             CPPUNIT_ASSERT_MESSAGE( "test for getFreeSpace function: get free space of /proc, it should be 0",
    2014             :                                      0 == uiFreeSpace );
    2015             :         }
    2016             : #else           /// Windows version, in Windows, there is no /proc directory
    2017             :         void getFreeSpace_002()
    2018             :         {
    2019             :             CPPUNIT_ASSERT_MESSAGE( "test for getFreeSpace function: not applicable for /proc( Windows version )",
    2020             :                                      1 == 1 );
    2021             :         }
    2022             : #endif
    2023             : 
    2024             : 
    2025             : #if defined(SOLARIS)
    2026             :          void getFreeSpace_003()
    2027             :         {
    2028             :              struct statvfs aStatFS;
    2029             :             static const sal_Char  name[] = "/";
    2030             : 
    2031             :             memset (&aStatFS, 0, sizeof(aStatFS));
    2032             :             statvfs( name, &aStatFS);
    2033             :             sal_uInt64 FreeSpace = aStatFS.f_bfree * aStatFS.f_frsize  ;
    2034             : 
    2035             :              sal_Int32 mask = osl_VolumeInfo_Mask_FreeSpace;
    2036             :             ::osl::VolumeInfo aVolumeInfo( mask );
    2037             :             nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
    2038             :             CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
    2039             :             CPPUNIT_ASSERT( sal_True == aVolumeInfo.isValid( mask ) );
    2040             :             sal_uInt64 uiFreeSpace = aVolumeInfo.getFreeSpace();
    2041             : 
    2042             :              CPPUNIT_ASSERT_MESSAGE( "test for getFreeSpace function: get free space by hand, then compare with getFreeSpace, it did not pass",
    2043             :                                      uiFreeSpace == FreeSpace );
    2044             :         }
    2045             : #else                                    //Windows version
    2046             :         void getFreeSpace_003()
    2047             :         {
    2048             :             CPPUNIT_ASSERT_MESSAGE( "test for getFreeSpace function: not implemented yet( Windows version )",
    2049             :                                      1 == 1 );
    2050             :         }
    2051             : #endif
    2052             : 
    2053             : 
    2054             :         CPPUNIT_TEST_SUITE( getFreeSpace );
    2055             :         CPPUNIT_TEST( getFreeSpace_001 );
    2056             :          CPPUNIT_TEST( getFreeSpace_002 );
    2057             :         CPPUNIT_TEST( getFreeSpace_003 );
    2058             :         CPPUNIT_TEST_SUITE_END();
    2059             :     };// class getFreeSpace
    2060             : 
    2061             :     //---------------------------------------------------------------------
    2062             :     //  testing the method
    2063             :     //  inline sal_uInt64 getUsedSpace() const
    2064             :     //---------------------------------------------------------------------
    2065             :     class  getUsedSpace : public CppUnit::TestFixture
    2066             :     {
    2067             :         ::osl::FileBase::RC nError1;
    2068             : 
    2069             :         public:
    2070             :         getUsedSpace() :nError1(FileBase::E_None) {}
    2071             :         // test code.
    2072             :         void getUsedSpace_001()
    2073             :         {
    2074             :             sal_Int32 mask = osl_VolumeInfo_Mask_UsedSpace;
    2075             :             ::osl::VolumeInfo aVolumeInfo( mask );
    2076             :             nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
    2077             :             CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
    2078             :             CPPUNIT_ASSERT( sal_True == aVolumeInfo.isValid( mask ) );
    2079             :             sal_uInt64 uiUsedSpace = aVolumeInfo.getUsedSpace();
    2080             : 
    2081             :             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",
    2082             :                                      0 != uiUsedSpace );
    2083             :         }
    2084             : 
    2085             : #if defined( UNX )
    2086             :            void getUsedSpace_002()
    2087             :         {
    2088             :              sal_Int32 mask = osl_VolumeInfo_Mask_UsedSpace;
    2089             :             ::osl::VolumeInfo aVolumeInfo( mask );
    2090             :             nError1 = ::osl::Directory::getVolumeInfo( aVolURL3, aVolumeInfo );
    2091             :             CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
    2092             :             CPPUNIT_ASSERT( sal_True == aVolumeInfo.isValid( mask ) );
    2093             :             sal_uInt64 uiUsedSpace = aVolumeInfo.getUsedSpace();
    2094             : 
    2095             :             CPPUNIT_ASSERT_MESSAGE( "test for getUsedSpace function: get used space of /proc, it should be 0",
    2096             :                                      0 == uiUsedSpace );
    2097             :         }
    2098             : #else                                    /// Windows version, in Windows, there is no /proc directory
    2099             :         void getUsedSpace_002()
    2100             :         {
    2101             :             CPPUNIT_ASSERT_MESSAGE( "test for getUsedSpace function: not applicable for /proc( Windows version )",
    2102             :                                      1 == 1 );
    2103             :         }
    2104             : #endif
    2105             : 
    2106             : 
    2107             : #if defined(SOLARIS)
    2108             :          void getUsedSpace_003()
    2109             :         {
    2110             :              struct statvfs aStatFS;
    2111             :             static const sal_Char  name[] = "/";
    2112             : 
    2113             :             memset (&aStatFS, 0, sizeof(aStatFS));
    2114             :             statvfs( name, &aStatFS);
    2115             :             sal_uInt64 UsedSpace = ( aStatFS.f_blocks - aStatFS.f_bavail ) * aStatFS.f_frsize;
    2116             : 
    2117             : 
    2118             :              sal_Int32 mask = osl_VolumeInfo_Mask_UsedSpace;
    2119             :             ::osl::VolumeInfo aVolumeInfo( mask );
    2120             :             nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
    2121             :             CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
    2122             :             CPPUNIT_ASSERT( sal_True == aVolumeInfo.isValid( mask ) );
    2123             :             sal_uInt64 uiUsedSpace = aVolumeInfo.getUsedSpace();
    2124             : 
    2125             :              CPPUNIT_ASSERT_MESSAGE( "test for getUsedSpace function: get used space by hand, then compare with getUsedSpace, it did not pass",
    2126             :                                      uiUsedSpace == UsedSpace );
    2127             :         }
    2128             : #else                                    //Windows version
    2129             :         void getUsedSpace_003()
    2130             :         {
    2131             :             CPPUNIT_ASSERT_MESSAGE( "test for getUsedSpace function: not implemented yet( Windows version )",
    2132             :                                      1 == 1 );
    2133             :         }
    2134             : #endif
    2135             : 
    2136             : 
    2137             :         CPPUNIT_TEST_SUITE( getUsedSpace );
    2138             :          CPPUNIT_TEST( getUsedSpace_001 );
    2139             :          CPPUNIT_TEST( getUsedSpace_002 );
    2140             :         CPPUNIT_TEST( getUsedSpace_003 );
    2141             :          CPPUNIT_TEST_SUITE_END();
    2142             :     };// class getUsedSpace
    2143             : 
    2144             : 
    2145             :     //---------------------------------------------------------------------
    2146             :     //  testing the method
    2147             :     //  inline sal_uInt32 getMaxNameLength() const
    2148             :     //---------------------------------------------------------------------
    2149             :     class  getMaxNameLength : public CppUnit::TestFixture
    2150             :     {
    2151             :         ::osl::FileBase::RC nError1;
    2152             : 
    2153             :         public:
    2154             :         getMaxNameLength() :nError1(FileBase::E_None) {}
    2155             :         // test code.
    2156             :         void getMaxNameLength_001()
    2157             :         {
    2158             :             sal_Int32 mask = osl_VolumeInfo_Mask_MaxNameLength;
    2159             :             ::osl::VolumeInfo aVolumeInfo( mask );
    2160             :             nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
    2161             :             CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
    2162             :             CPPUNIT_ASSERT( sal_True == aVolumeInfo.isValid( mask ) );
    2163             :             sal_uInt32 uiMaxNameLength = aVolumeInfo.getMaxNameLength();
    2164             : 
    2165             :             CPPUNIT_ASSERT_MESSAGE( "test for getMaxNameLength function: get max name length of Fixed disk volume mounted on /, it should not be 0",
    2166             :                                      0 != uiMaxNameLength );
    2167             :         }
    2168             : 
    2169             : 
    2170             : #if defined(UNX) && !defined(ANDROID)
    2171             :          void getMaxNameLength_002()
    2172             :         {
    2173             :              struct statvfs aStatFS;
    2174             :             static const sal_Char  name[] = "/";
    2175             : 
    2176             :             memset (&aStatFS, 0, sizeof(aStatFS));
    2177             :             statvfs( name, &aStatFS);
    2178             :             sal_uInt64 MaxNameLength = aStatFS.f_namemax;
    2179             : 
    2180             :              sal_Int32 mask = osl_VolumeInfo_Mask_MaxNameLength;
    2181             :             ::osl::VolumeInfo aVolumeInfo( mask );
    2182             :             nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
    2183             :             CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
    2184             :             CPPUNIT_ASSERT( sal_True == aVolumeInfo.isValid( mask ) );
    2185             :             sal_uInt64 uiMaxNameLength = aVolumeInfo.getMaxNameLength();
    2186             : 
    2187             :              CPPUNIT_ASSERT_MESSAGE( "test for getMaxNameLength function: get max name length by hand, then compare with getMaxNameLength",
    2188             :                                      uiMaxNameLength == MaxNameLength );
    2189             :         }
    2190             : #else                                    //Windows version
    2191             :         void getMaxNameLength_002()
    2192             :         {
    2193             :             CPPUNIT_ASSERT_MESSAGE( "test for getMaxNameLength function: not implemented yet( Windows version )",
    2194             :                                      1 == 1 );
    2195             :         }
    2196             : #endif
    2197             : 
    2198             :         CPPUNIT_TEST_SUITE( getMaxNameLength );
    2199             :          CPPUNIT_TEST( getMaxNameLength_001 );
    2200             :         CPPUNIT_TEST( getMaxNameLength_002 );
    2201             :          CPPUNIT_TEST_SUITE_END();
    2202             :     };// class getMaxNameLength
    2203             : 
    2204             : 
    2205             :     //---------------------------------------------------------------------
    2206             :     //  testing the method
    2207             :     //  inline sal_uInt32 getMaxPathLength() const
    2208             :     //---------------------------------------------------------------------
    2209             :     class  getMaxPathLength : public CppUnit::TestFixture
    2210             :     {
    2211             :         ::osl::FileBase::RC nError1;
    2212             : 
    2213             :         public:
    2214             :         getMaxPathLength() :nError1(FileBase::E_None) {}
    2215             :         // test code.
    2216             :         void getMaxPathLength_001()
    2217             :         {
    2218             :             sal_Int32 mask = osl_VolumeInfo_Mask_MaxPathLength;
    2219             :             ::osl::VolumeInfo aVolumeInfo( mask );
    2220             :             nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
    2221             :             CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
    2222             :             CPPUNIT_ASSERT( sal_True == aVolumeInfo.isValid( mask ) );
    2223             :             sal_uInt32 uiMaxPathLength = aVolumeInfo.getMaxPathLength();
    2224             : 
    2225             :             CPPUNIT_ASSERT_MESSAGE( "test for getMaxPathLength function: get max path length of Fixed disk volume mounted on /, it should not be 0",
    2226             :                                      0 != uiMaxPathLength );
    2227             :         }
    2228             : 
    2229             : 
    2230             : #if ( defined UNX )
    2231             :          void getMaxPathLength_002()
    2232             :         {
    2233             :              sal_Int32 mask = osl_VolumeInfo_Mask_MaxPathLength;
    2234             :             ::osl::VolumeInfo aVolumeInfo( mask );
    2235             :             nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
    2236             :             CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
    2237             :             CPPUNIT_ASSERT( sal_True == aVolumeInfo.isValid( mask ) );
    2238             :             sal_uInt64 uiMaxPathLength = aVolumeInfo.getMaxPathLength();
    2239             : 
    2240             :              CPPUNIT_ASSERT_MESSAGE( "test for getMaxPathLength function: get max path length by hand, then compare with getMaxPathLength",
    2241             :                                      uiMaxPathLength == PATH_MAX );
    2242             :         }
    2243             : #else                                    //Windows version
    2244             :         void getMaxPathLength_002()
    2245             :         {
    2246             :             CPPUNIT_ASSERT_MESSAGE( "test for getMaxPathLength function: not implemented yet( Windows version )",
    2247             :                                      1 == 1 );
    2248             :         }
    2249             : #endif
    2250             : 
    2251             : 
    2252             :         CPPUNIT_TEST_SUITE( getMaxPathLength );
    2253             :          CPPUNIT_TEST( getMaxPathLength_001 );
    2254             :         CPPUNIT_TEST( getMaxPathLength_002 );
    2255             :          CPPUNIT_TEST_SUITE_END();
    2256             :     };// class getMaxPathLength
    2257             : 
    2258             : 
    2259             :     //---------------------------------------------------------------------
    2260             :     //  testing the method
    2261             :     //  inline ::rtl::OUString getFileSystemName() const
    2262             :     //---------------------------------------------------------------------
    2263             :     class  getFileSystemName : public CppUnit::TestFixture
    2264             :     {
    2265             :         ::rtl::OUString aUStr;
    2266             :         ::osl::FileBase::RC nError1;
    2267             : 
    2268             :         public:
    2269             :         getFileSystemName() :nError1(FileBase::E_None) {}
    2270             :         // test code.
    2271             :         void getFileSystemName_001()
    2272             :         {
    2273             :             sal_Int32 mask = osl_VolumeInfo_Mask_FileSystemName;
    2274             :             ::osl::VolumeInfo aVolumeInfo( mask );
    2275             :             nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
    2276             :             CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
    2277             :             CPPUNIT_ASSERT( sal_True == aVolumeInfo.isValid( mask ) );
    2278             :             aUStr = aVolumeInfo.getFileSystemName();
    2279             : 
    2280             :             CPPUNIT_ASSERT_MESSAGE( "test for getFileSystemName function: get file system name of Fixed disk volume mounted on /, it should not be empty string",
    2281             :                                      sal_False == compareFileName( aNullURL, aUStr ) );
    2282             :         }
    2283             : 
    2284             : 
    2285             : #if defined(SOLARIS)
    2286             :          void getFileSystemName_002()
    2287             :         {
    2288             :              struct statvfs aStatFS;
    2289             :             static const sal_Char  name[] = "/";
    2290             : 
    2291             :             memset (&aStatFS, 0, sizeof(aStatFS));
    2292             :             statvfs( name, &aStatFS);
    2293             :             sal_Char * astrFileSystemName = aStatFS.f_basetype;
    2294             : 
    2295             :              sal_Int32 mask = osl_VolumeInfo_Mask_FileSystemName;
    2296             :             ::osl::VolumeInfo aVolumeInfo( mask );
    2297             :             nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
    2298             :             CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
    2299             :             CPPUNIT_ASSERT( sal_True == aVolumeInfo.isValid( mask ) );
    2300             :             aUStr = aVolumeInfo.getFileSystemName();
    2301             : 
    2302             :              CPPUNIT_ASSERT_MESSAGE( "test for getFileSystemName function: get file system name by hand, then compare with getFileSystemName",
    2303             :                                      sal_True == compareFileName( aUStr, astrFileSystemName ) );
    2304             :         }
    2305             : #else                                    //Windows version
    2306             :         void getFileSystemName_002()
    2307             :         {
    2308             :             CPPUNIT_ASSERT_MESSAGE( "test for getFileSystemName function: not implemented yet( Windows version )",
    2309             :                                      1 == 1 );
    2310             :         }
    2311             : #endif
    2312             : 
    2313             : 
    2314             :         CPPUNIT_TEST_SUITE( getFileSystemName );
    2315             :          CPPUNIT_TEST( getFileSystemName_001 );
    2316             :         CPPUNIT_TEST( getFileSystemName_002 );
    2317             :          CPPUNIT_TEST_SUITE_END();
    2318             :     };// class getFileSystemName
    2319             : 
    2320             :     //---------------------------------------------------------------------
    2321             :     //  testing the method
    2322             :     //  inline VolumeDevice getDeviceHandle() const
    2323             :     //---------------------------------------------------------------------
    2324             :     class  getDeviceHandle : public CppUnit::TestFixture
    2325             :     {
    2326             :         ::rtl::OUString aUStr;
    2327             :         ::osl::FileBase::RC nError1;
    2328             : 
    2329             :         public:
    2330             :         getDeviceHandle() :nError1(FileBase::E_None) {}
    2331             :         // test code.
    2332             :         void getDeviceHandle_001()
    2333             :         {
    2334             :             ::osl::VolumeInfo   aVolumeInfo( osl_VolumeInfo_Mask_Attributes );
    2335             :             nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
    2336             :             CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
    2337             : 
    2338             :             ::osl::VolumeDevice aVolumeDevice1( aVolumeInfo.getDeviceHandle() );
    2339             :             sal_Bool bOk = compareFileName( aNullURL, aVolumeDevice1.getMountPath() );
    2340             : 
    2341             :             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).",
    2342             :                                      ( sal_False == bOk ) );
    2343             :         }
    2344             : 
    2345             :         CPPUNIT_TEST_SUITE( getDeviceHandle );
    2346             :          CPPUNIT_TEST( getDeviceHandle_001 );
    2347             :         CPPUNIT_TEST_SUITE_END();
    2348             :     };// class getDeviceHandle
    2349             : 
    2350             : 
    2351             :     // -----------------------------------------------------------------------------
    2352             :     /*CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeInfo::ctors, "osl_VolumeInfo" );
    2353             :     CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeInfo::isValid, "osl_VolumeInfo" );
    2354             :     CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeInfo::getRemoteFlag, "osl_VolumeInfo" );
    2355             :     CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeInfo::getRemoveableFlag, "osl_VolumeInfo" );
    2356             :     CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeInfo::getCompactDiscFlag, "osl_VolumeInfo" );
    2357             :     CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeInfo::getFloppyDiskFlag, "osl_VolumeInfo" );
    2358             :     CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeInfo::getFixedDiskFlag, "osl_VolumeInfo" );
    2359             :     CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeInfo::getRAMDiskFlag, "osl_VolumeInfo" );
    2360             :     CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeInfo::getTotalSpace, "osl_VolumeInfo" );
    2361             :     CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeInfo::getFreeSpace, "osl_VolumeInfo" );
    2362             :     CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeInfo::getUsedSpace, "osl_VolumeInfo" );
    2363             :     CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeInfo::getMaxNameLength, "osl_VolumeInfo" );
    2364             :     CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeInfo::getMaxPathLength, "osl_VolumeInfo" );
    2365             :     CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeInfo::getFileSystemName, "osl_VolumeInfo" );
    2366             :     CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeInfo::getDeviceHandle, "osl_VolumeInfo" );*/
    2367             : }// namespace osl_VolumeInfo
    2368             : 
    2369             : 
    2370             : 
    2371             : //------------------------------------------------------------------------
    2372             : // Beginning of the test cases for VolumeDevice class
    2373             : //------------------------------------------------------------------------
    2374             : namespace osl_FileStatus
    2375             : {
    2376             : 
    2377             :     //---------------------------------------------------------------------
    2378             :     //  testing the method
    2379             :     //  FileStatus( sal_uInt32 nMask ): _nMask( nMask )
    2380             :     //---------------------------------------------------------------------
    2381           0 :     class  ctors : public CppUnit::TestFixture
    2382             :     {
    2383             :         ::rtl::OUString         aUStr;
    2384             :         ::osl::FileBase::RC     nError1;
    2385             :         ::osl::DirectoryItem    rItem;
    2386             : 
    2387             :         public:
    2388           0 :         ctors() :nError1(FileBase::E_None) {}
    2389             :         // initialization
    2390           0 :         void setUp()
    2391             :         {
    2392             :             // create a tempfile in $TEMP/tmpdir/tmpname.
    2393           0 :             createTestDirectory( aTmpName3 );
    2394           0 :             createTestFile( aTmpName4 );
    2395             : 
    2396           0 :             ::std::auto_ptr<Directory> pDir( new Directory( aTmpName3 ) );
    2397           0 :             nError1 = pDir->open();
    2398           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    2399           0 :             nError1 = pDir->getNextItem( rItem, 0 );
    2400           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    2401           0 :             pDir->close();
    2402             :             /*
    2403             :             Directory aDir( aTmpName3 );
    2404             :             nError1 = aDir.open();
    2405             :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    2406             :             nError1 = aDir.getNextItem( rItem, 0 );
    2407             :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    2408             :             aDir.close();
    2409             :             */
    2410           0 :         }
    2411             : 
    2412           0 :         void tearDown()
    2413             :         {
    2414             :             // remove the tempfile in $TEMP/tmpdir/tmpname.
    2415           0 :             deleteTestFile( aTmpName4 );
    2416           0 :             deleteTestDirectory( aTmpName3 );
    2417           0 :         }
    2418             : 
    2419             :         // test code.
    2420           0 :         void ctors_001()
    2421             :         {
    2422           0 :              ::osl::FileStatus   rFileStatus( osl_FileStatus_Mask_All );
    2423           0 :             nError1 = rItem.getFileStatus( rFileStatus );
    2424           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    2425           0 :             aUStr = rFileStatus.getFileName();
    2426             : 
    2427           0 :             CPPUNIT_ASSERT_MESSAGE( "test for ctors function: mask all and see the file name",
    2428           0 :                                      sal_True == compareFileName( aUStr, aTmpName2)  );
    2429           0 :         }
    2430             : 
    2431           0 :         void ctors_002()
    2432             :         {
    2433           0 :              ::osl::FileStatus   rFileStatus( 0 );
    2434           0 :             nError1 = rItem.getFileStatus( rFileStatus );
    2435           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    2436           0 :             aUStr = rFileStatus.getFileName();
    2437             : 
    2438           0 :             CPPUNIT_ASSERT_MESSAGE( "test for ctors function: mask is empty",
    2439           0 :                                      sal_True == compareFileName( aUStr, aNullURL)  );
    2440           0 :         }
    2441             : 
    2442           0 :         CPPUNIT_TEST_SUITE( ctors );
    2443           0 :         CPPUNIT_TEST( ctors_001 );
    2444           0 :         CPPUNIT_TEST( ctors_002 );
    2445           0 :         CPPUNIT_TEST_SUITE_END();
    2446             :     };// class ctors
    2447             : 
    2448             : 
    2449             :     //---------------------------------------------------------------------
    2450             :     //  testing the method
    2451             :     //  inline sal_Bool isValid( sal_uInt32 nMask ) const
    2452             :     //---------------------------------------------------------------------
    2453           0 :     class  isValid : public CppUnit::TestFixture
    2454             :     {
    2455             :         ::rtl::OUString         aUStr;
    2456             :         ::osl::Directory        *pDir;
    2457             :         ::osl::DirectoryItem    rItem_file, rItem_link;
    2458             : 
    2459             :         public:
    2460             :         // initialization
    2461           0 :         void setUp()
    2462             :         {
    2463             :             // create a tempfile in $TEMP/tmpdir/tmpname.
    2464           0 :             createTestDirectory( aTmpName3 );
    2465           0 :             createTestFile( aTmpName4 );
    2466             : 
    2467           0 :             pDir = new Directory( aTmpName3 );
    2468             :             //::std::auto_ptr<Directory> pDir( new Directory( aTmpName3 ) );
    2469           0 :                     ::osl::FileBase::RC nError1 = pDir->open();
    2470           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    2471           0 :             nError1 = pDir->getNextItem( rItem_file, 1 );
    2472           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    2473           0 :         }
    2474             : 
    2475           0 :         void tearDown()
    2476             :         {
    2477           0 :                     ::osl::FileBase::RC nError1 = pDir->close();
    2478           0 :                     delete pDir;
    2479           0 :             CPPUNIT_ASSERT_MESSAGE( errorToStr(nError1).getStr(), ::osl::FileBase::E_None == nError1 );
    2480             : 
    2481             :             // remove the tempfile in $TEMP/tmpdir/tmpname.
    2482           0 :             deleteTestFile( aTmpName4 );
    2483           0 :             deleteTestDirectory( aTmpName3 );
    2484           0 :         }
    2485             : 
    2486             :         // test code.
    2487           0 :         void isValid_001()
    2488             :         {
    2489           0 :             sal_uInt32 mask = 0;
    2490           0 :              ::osl::FileStatus   rFileStatus( mask );
    2491           0 :                 ::osl::FileBase::RC nError1 = rItem_file.getFileStatus( rFileStatus );
    2492           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    2493           0 :             sal_Bool bOk = rFileStatus.isValid( mask );
    2494             : 
    2495           0 :             CPPUNIT_ASSERT_MESSAGE( "test for isValid function: no fields specified",
    2496           0 :                                      ( sal_True == bOk ) );
    2497           0 :         }
    2498             : 
    2499           0 :         void check_FileStatus(::osl::FileStatus const& _aStatus)
    2500             :             {
    2501           0 :                 rtl::OString sStat;
    2502           0 :                 if (_aStatus.isValid(osl_FileStatus_Mask_Type))
    2503             :                 {
    2504           0 :                     sStat += "type ";
    2505             :                 }
    2506           0 :                 if (_aStatus.isValid(osl_FileStatus_Mask_Attributes))
    2507             :                 {
    2508           0 :                     sStat += "attributes ";
    2509             :                 }
    2510           0 :                 if (_aStatus.isValid(osl_FileStatus_Mask_CreationTime))
    2511             :                 {
    2512           0 :                     sStat += "ctime ";
    2513             :                 }
    2514           0 :                 if (_aStatus.isValid(osl_FileStatus_Mask_AccessTime))
    2515             :                 {
    2516           0 :                     sStat += "atime ";
    2517             :                 }
    2518           0 :                 if (_aStatus.isValid(osl_FileStatus_Mask_ModifyTime))
    2519             :                 {
    2520           0 :                     sStat += "mtime ";
    2521             :                 }
    2522           0 :                 if (_aStatus.isValid(osl_FileStatus_Mask_FileSize))
    2523             :                 {
    2524           0 :                     sStat += "filesize ";
    2525             :                 }
    2526           0 :                 if (_aStatus.isValid(osl_FileStatus_Mask_FileName))
    2527             :                 {
    2528           0 :                     sStat += "filename ";
    2529             :                 }
    2530           0 :                 if (_aStatus.isValid(osl_FileStatus_Mask_FileURL))
    2531             :                 {
    2532           0 :                     sStat += "fileurl ";
    2533             :                 }
    2534           0 :                 printf("mask: %s\n", sStat.getStr());
    2535           0 :             }
    2536             : 
    2537           0 :         void isValid_002()
    2538             :         {
    2539           0 :             createTestFile( aTmpName6 );
    2540             :             sal_uInt32 mask_file = ( osl_FileStatus_Mask_Type | osl_FileStatus_Mask_Attributes |
    2541             :                                    osl_FileStatus_Mask_CreationTime | osl_FileStatus_Mask_AccessTime |
    2542             :                                    osl_FileStatus_Mask_ModifyTime   | osl_FileStatus_Mask_FileSize   |
    2543           0 :                                    osl_FileStatus_Mask_FileName     | osl_FileStatus_Mask_FileURL) ;
    2544           0 :              ::osl::FileStatus   rFileStatus( mask_file );
    2545           0 :                 ::osl::FileBase::RC nError1 = ::osl::DirectoryItem::get( aTmpName6, rItem_file );
    2546           0 :             nError1 = rItem_file.getFileStatus( rFileStatus );
    2547             : 
    2548           0 :             CPPUNIT_ASSERT_MESSAGE( errorToStr(nError1).getStr(), ::osl::FileBase::E_None == nError1 );
    2549             : 
    2550             : // LLA: this is wrong, we never should try to check on all masks
    2551             : //      only on one.
    2552             : //      Second, it's not a bug, if a value is not valid, it's an unhandled feature.
    2553             : 
    2554             : //      sal_Bool bOk = rFileStatus.isValid( mask_file );
    2555             : 
    2556           0 :                 check_FileStatus(rFileStatus);
    2557           0 :             deleteTestFile( aTmpName6 );
    2558             : 
    2559             :                 // CPPUNIT_ASSERT_MESSAGE( "test for isValid function: regular file mask fields test, #osl_FileStatus_Mask_CreationTime# should be valid field for regular file, but feedback is invalid",
    2560             :                 //                      ( sal_True == bOk ) );
    2561           0 :         }
    2562             : 
    2563             :         //Link is not defined in Windows, and on Linux, we can not get the directory item of the link file
    2564             :         // LLA: we have to differ to filesystems, normal filesystems support links (EXT2, ...)
    2565             :         //      castrated filesystems don't (FAT, FAT32)
    2566             :         //      Windows NT NTFS support links, but the windows api don't :-(
    2567             : 
    2568           0 :         void isValid_003()
    2569             :         {
    2570             : #if defined ( UNX )
    2571             :             // ::osl::FileBase::RC nError;
    2572             :             sal_Int32 fd;
    2573             : 
    2574           0 :             ::rtl::OUString aUStr_LnkFileSys( aTempDirectorySys ), aUStr_SrcFileSys( aTempDirectorySys );
    2575           0 :             ( ( aUStr_LnkFileSys += aSlashURL ) += getCurrentPID() ) += ::rtl::OUString("/tmpdir/link.file");
    2576           0 :             ( ( aUStr_SrcFileSys += aSlashURL ) += getCurrentPID() ) += ::rtl::OUString("/tmpdir/tmpname");
    2577             : 
    2578           0 :                 rtl::OString strLinkFileName;
    2579           0 :                 rtl::OString strSrcFileName;
    2580           0 :                 strLinkFileName = OUStringToOString( aUStr_LnkFileSys, RTL_TEXTENCODING_ASCII_US );
    2581           0 :                 strSrcFileName = OUStringToOString( aUStr_SrcFileSys, RTL_TEXTENCODING_ASCII_US );
    2582             : 
    2583             :             //create a link file and link it to file "/tmp/PID/tmpdir/tmpname"
    2584           0 :                 fd = symlink( strSrcFileName.getStr(), strLinkFileName.getStr() );
    2585           0 :             CPPUNIT_ASSERT( fd == 0 );
    2586             : 
    2587             :             // testDirectory is "/tmp/PID/tmpdir/"
    2588           0 :             ::osl::Directory testDirectory( aTmpName3 );
    2589           0 :                 ::osl::FileBase::RC nError1 = testDirectory.open();
    2590           0 :             ::rtl::OUString aFileName ("link.file");
    2591           0 :             sal_Bool bOk = sal_False;
    2592             :             while (1) {
    2593           0 :                 nError1 = testDirectory.getNextItem( rItem_link, 4 );
    2594           0 :                 if (::osl::FileBase::E_None == nError1) {
    2595           0 :                     sal_uInt32 mask_link = osl_FileStatus_Mask_FileName | osl_FileStatus_Mask_LinkTargetURL;
    2596           0 :                     ::osl::FileStatus   rFileStatus( mask_link );
    2597           0 :                     rItem_link.getFileStatus( rFileStatus );
    2598           0 :                     if ( compareFileName( rFileStatus.getFileName(), aFileName) == sal_True )
    2599             :                     {
    2600             :                         //printf("find the link file");
    2601           0 :                         if ( sal_True == rFileStatus.isValid( osl_FileStatus_Mask_LinkTargetURL ) )
    2602             :                         {
    2603           0 :                             bOk = sal_True;
    2604           0 :                             break;
    2605             :                         }
    2606           0 :                     }
    2607             :                 }
    2608             :                 else
    2609           0 :                     break;
    2610             :             };
    2611             : 
    2612           0 :             fd = remove( strLinkFileName.getStr() );
    2613           0 :             CPPUNIT_ASSERT( fd == 0 );
    2614             : 
    2615           0 :             CPPUNIT_ASSERT_MESSAGE("test for isValid function: link file, check for LinkTargetURL",
    2616           0 :                                      ( sal_True == bOk ) );
    2617             : #endif
    2618           0 :         }
    2619             : 
    2620           0 :         void isValid_004()
    2621             :         {
    2622           0 :             sal_uInt32 mask_file_all = osl_FileStatus_Mask_All;
    2623           0 :              ::osl::FileStatus   rFileStatus_all( mask_file_all );
    2624           0 :                 ::osl::FileBase::RC nError1 = rItem_file.getFileStatus( rFileStatus_all );
    2625           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    2626             : 
    2627           0 :                 check_FileStatus(rFileStatus_all);
    2628             : // LLA: this is wrong
    2629             : //          sal_Bool bOk1 = rFileStatus_all.isValid( mask_file_all );
    2630             : 
    2631           0 :             sal_uInt32 mask_file_val = osl_FileStatus_Mask_Validate;
    2632           0 :              ::osl::FileStatus   rFileStatus_val( mask_file_val );
    2633           0 :             nError1 = rItem_file.getFileStatus( rFileStatus_val );
    2634           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    2635             :                 // sal_Bool bOk2 = rFileStatus_val.isValid( mask_file_val );
    2636             : 
    2637           0 :                 check_FileStatus(rFileStatus_val);
    2638             :                 // 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).",
    2639             :                 //                      ( sal_False == bOk1 ) && ( sal_True == bOk2 )  );
    2640           0 :         }
    2641             : 
    2642             : 
    2643           0 :         CPPUNIT_TEST_SUITE( isValid );
    2644           0 :         CPPUNIT_TEST( isValid_001 );
    2645           0 :         CPPUNIT_TEST( isValid_002 );
    2646           0 :         CPPUNIT_TEST( isValid_003 );
    2647           0 :         CPPUNIT_TEST( isValid_004 );
    2648           0 :         CPPUNIT_TEST_SUITE_END();
    2649             :     };// class ctors
    2650             : 
    2651             : 
    2652             :     //---------------------------------------------------------------------
    2653             :     //  testing the method
    2654             :     //  inline Type getFileType() const
    2655             :     //---------------------------------------------------------------------
    2656           0 :     class  getFileType : public CppUnit::TestFixture
    2657             :     {
    2658             :         ::rtl::OUString         aUStr;
    2659             :         ::osl::FileBase::RC     nError1;
    2660             : 
    2661             :         ::osl::DirectoryItem    m_aItem_1, m_aItem_2, m_aVolumeItem, m_aFifoItem;
    2662             :         ::osl::DirectoryItem    m_aLinkItem, m_aSocketItem, m_aSpecialItem;
    2663             : 
    2664             :         public:
    2665           0 :         getFileType() :nError1(FileBase::E_None) {}
    2666             :         // initialization
    2667           0 :         void setUp()
    2668             :         {
    2669             :             // create a tempfile: $TEMP/tmpdir/tmpname.
    2670             :             //        a tempdirectory: $TEMP/tmpdir/tmpdir.
    2671             :             //        use $ROOT/staroffice as volume ---> use dev/fd as volume.
    2672             :             // and get their directory item.
    2673           0 :             createTestDirectory( aTmpName3 );
    2674           0 :             createTestFile( aTmpName3, aTmpName2 );
    2675           0 :             createTestDirectory( aTmpName3, aTmpName1 );
    2676             : 
    2677           0 :             boost::scoped_ptr<Directory> pDir( new Directory( aTmpName3 ) );
    2678           0 :             nError1 = pDir->open();
    2679           0 :             CPPUNIT_ASSERT_MESSAGE("open aTmpName3 failed!", ::osl::FileBase::E_None == nError1 );
    2680             :             //getNextItem can not assure which item retrieved
    2681           0 :                     nError1 = pDir->getNextItem( m_aItem_1, 1 );
    2682           0 :             CPPUNIT_ASSERT_MESSAGE("get first item failed!", ::osl::FileBase::E_None == nError1 );
    2683             : 
    2684           0 :                     nError1 = pDir->getNextItem( m_aItem_2 );
    2685           0 :             CPPUNIT_ASSERT_MESSAGE("get second item failed!", ::osl::FileBase::E_None == nError1 );
    2686           0 :             pDir->close();
    2687             :             //mindy: failed on my RH9,so removed temporaly
    2688             :             //nError1 = ::osl::DirectoryItem::get( aVolURL2, m_aVolumeItem );
    2689             :             //CPPUNIT_ASSERT_MESSAGE("get volume item failed!", ::osl::FileBase::E_None == nError1 );
    2690             : 
    2691           0 :         }
    2692             : 
    2693           0 :         void tearDown()
    2694             :         {
    2695             :             // remove all in $TEMP/tmpdir.
    2696           0 :             deleteTestDirectory( aTmpName3, aTmpName1 );
    2697           0 :             deleteTestFile( aTmpName3, aTmpName2 );
    2698           0 :             deleteTestDirectory( aTmpName3 );
    2699           0 :         }
    2700             : 
    2701             :         // test code.
    2702           0 :         void getFileType_001()
    2703             :         {
    2704           0 :              ::osl::FileStatus   rFileStatus( osl_FileStatus_Mask_Type | osl_FileStatus_Mask_FileName );
    2705           0 :             nError1 = m_aItem_1.getFileStatus( rFileStatus );
    2706           0 :             CPPUNIT_ASSERT_MESSAGE("getFileStatus failed", ::osl::FileBase::E_None == nError1 );
    2707             : 
    2708           0 :             check_FileType(rFileStatus);
    2709           0 :         }
    2710             : 
    2711           0 :         void check_FileType(osl::FileStatus const& _rFileStatus )
    2712             :         {
    2713           0 :             sal_Bool bOK = sal_False;
    2714           0 :                 if ( _rFileStatus.isValid(osl_FileStatus_Mask_FileName))
    2715             :                 {
    2716           0 :                     rtl::OUString suFilename = _rFileStatus.getFileName();
    2717             : 
    2718           0 :                     if ( _rFileStatus.isValid(osl_FileStatus_Mask_Type))
    2719             :                     {
    2720           0 :                         osl::FileStatus::Type eType = _rFileStatus.getFileType();
    2721             : 
    2722           0 :                         if ( compareFileName( suFilename, aTmpName2) == sal_True )
    2723             :                         {
    2724             :                             // regular
    2725           0 :                             bOK = ( eType == osl::FileStatus::Regular );
    2726             :                         }
    2727           0 :                         if ( compareFileName( suFilename, aTmpName1) == sal_True )
    2728             :                         {
    2729             :                             // directory
    2730           0 :                             bOK = ( eType == ::osl::FileStatus::Directory );
    2731             :                         }
    2732             : 
    2733           0 :                         CPPUNIT_ASSERT_MESSAGE( "test for getFileType function: ",
    2734           0 :                                      ( bOK == sal_True ) );
    2735           0 :         }
    2736             :                 }
    2737             :                 // LLA: it's not a bug, if a FileStatus not exist, so no else
    2738           0 :             }
    2739             : 
    2740           0 :         void getFileType_002()
    2741             :         {
    2742           0 :              ::osl::FileStatus   rFileStatus( osl_FileStatus_Mask_Type | osl_FileStatus_Mask_FileName );
    2743           0 :                 nError1 = m_aItem_2.getFileStatus( rFileStatus );
    2744             : 
    2745           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    2746           0 :                 check_FileType(rFileStatus);
    2747           0 :         }
    2748             : 
    2749           0 :         void getFileType_003()
    2750             :         {
    2751           0 :         }
    2752             : 
    2753           0 :         void getFileType_007()
    2754             :         {
    2755             : #if defined ( SOLARIS ) //Special file is differ in Windows
    2756             :                 nError1 = ::osl::DirectoryItem::get( aTypeURL2, m_aSpecialItem );
    2757             :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    2758             : 
    2759             :             //check for File type
    2760             :              ::osl::FileStatus   rFileStatus( osl_FileStatus_Mask_Type );
    2761             :             nError1 = m_aSpecialItem.getFileStatus( rFileStatus );
    2762             :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    2763             : 
    2764             :             if (rFileStatus.isValid(osl_FileStatus_Mask_Type))
    2765             :             {
    2766             :                 osl::FileStatus::Type eType = rFileStatus.getFileType();
    2767             : 
    2768             : 
    2769             :                 CPPUNIT_ASSERT_MESSAGE( "test for getFileType function: Special, Solaris version ",
    2770             :                                         ( eType == ::osl::FileStatus::Special ) );
    2771             :             }
    2772             : #endif
    2773           0 :         }
    2774             : 
    2775           0 :         CPPUNIT_TEST_SUITE( getFileType );
    2776           0 :         CPPUNIT_TEST( getFileType_001 );
    2777           0 :         CPPUNIT_TEST( getFileType_002 );
    2778           0 :         CPPUNIT_TEST( getFileType_003 );
    2779           0 :         CPPUNIT_TEST( getFileType_007 );
    2780           0 :         CPPUNIT_TEST_SUITE_END();
    2781             :     };// class getFileType
    2782             : 
    2783             :     //---------------------------------------------------------------------
    2784             :     //  testing the method
    2785             :     //  inline sal_uInt64 getAttributes() const
    2786             :     //---------------------------------------------------------------------
    2787           0 :     class  getAttributes : public CppUnit::TestFixture
    2788             :     {
    2789             :         ::rtl::OUString         aTypeURL, aTypeURL_Hid;
    2790             :         ::osl::FileBase::RC     nError;
    2791             :         ::osl::DirectoryItem    rItem, rItem_hidden;
    2792             : 
    2793             :         public:
    2794           0 :         getAttributes() :nError(FileBase::E_None) {}
    2795             :         // initialization
    2796           0 :         void setUp()
    2797             :         {
    2798           0 :             aTypeURL = aUserDirectoryURL.copy( 0 );
    2799           0 :             concatURL( aTypeURL, aTmpName2 );
    2800           0 :             createTestFile( aTypeURL );
    2801           0 :             nError = ::osl::DirectoryItem::get( aTypeURL, rItem );
    2802           0 :             CPPUNIT_ASSERT( nError == FileBase::E_None );
    2803             : 
    2804           0 :             aTypeURL_Hid = aUserDirectoryURL.copy( 0 );
    2805           0 :             concatURL( aTypeURL_Hid, aHidURL1 );
    2806           0 :             createTestFile( aTypeURL_Hid );
    2807           0 :             nError = ::osl::DirectoryItem::get( aTypeURL_Hid, rItem_hidden );
    2808           0 :             CPPUNIT_ASSERT( nError == FileBase::E_None );
    2809           0 :         }
    2810             : 
    2811           0 :         void tearDown()
    2812             :         {
    2813           0 :             deleteTestFile( aTypeURL );
    2814           0 :             deleteTestFile( aTypeURL_Hid );
    2815           0 :         }
    2816             : 
    2817             :         // test code.
    2818             : #if ( defined UNX )
    2819             : //windows only 3 file attributes: normal, readonly, hidden
    2820           0 :         void getAttributes_001()
    2821             :         {
    2822           0 :             changeFileMode( aTypeURL, S_IRUSR | S_IRGRP | S_IROTH );
    2823             : 
    2824           0 :               ::osl::FileStatus   rFileStatus( osl_FileStatus_Mask_Attributes );
    2825           0 :             nError = rItem.getFileStatus( rFileStatus );
    2826           0 :             CPPUNIT_ASSERT( nError == FileBase::E_None );
    2827             : 
    2828           0 :             CPPUNIT_ASSERT_MESSAGE( "test for getAttributes function: ReadOnly, GrpRead, OwnRead, OthRead( UNX version ) ",
    2829             :                                     ( osl_File_Attribute_ReadOnly | osl_File_Attribute_GrpRead | osl_File_Attribute_OwnRead | osl_File_Attribute_OthRead ) ==
    2830           0 :                                     rFileStatus.getAttributes() );
    2831           0 :         }
    2832             : #else                                    //Windows version
    2833             :         void getAttributes_001()
    2834             :         {
    2835             :             CPPUNIT_ASSERT_MESSAGE( "test for getAttributes function: ReadOnly, GrpRead, OwnRead, OthRead( Windows version )",
    2836             :                                      1 == 1 );
    2837             :         }
    2838             : #endif
    2839             : 
    2840             : 
    2841           0 :         void getAttributes_002()
    2842             :         {
    2843             : #if ( defined UNX )
    2844           0 :             changeFileMode( aTypeURL, S_IXUSR | S_IXGRP | S_IXOTH );
    2845             : 
    2846           0 :               ::osl::FileStatus   rFileStatus( osl_FileStatus_Mask_Attributes );
    2847           0 :             nError = rItem.getFileStatus( rFileStatus );
    2848           0 :             CPPUNIT_ASSERT( nError == FileBase::E_None );
    2849             : 
    2850           0 :             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 )",
    2851             :                                     ( osl_File_Attribute_ReadOnly | osl_File_Attribute_Executable | osl_File_Attribute_GrpExe | osl_File_Attribute_OwnExe | osl_File_Attribute_OthExe ) ==
    2852           0 :                                     rFileStatus.getAttributes() );
    2853             : #endif
    2854           0 :         }
    2855             : 
    2856             : 
    2857             : #if ( defined UNX )
    2858           0 :         void getAttributes_003()
    2859             :         {
    2860           0 :             changeFileMode( aTypeURL, S_IWUSR | S_IWGRP | S_IWOTH );
    2861             : 
    2862           0 :               ::osl::FileStatus   rFileStatus( osl_FileStatus_Mask_Attributes );
    2863           0 :             nError = rItem.getFileStatus( rFileStatus );
    2864           0 :             CPPUNIT_ASSERT( nError == FileBase::E_None );
    2865             : 
    2866           0 :             CPPUNIT_ASSERT_MESSAGE( "test for getAttributes function: GrpWrite, OwnWrite, OthWrite( Solaris version )",
    2867             :                                     ( osl_File_Attribute_GrpWrite | osl_File_Attribute_OwnWrite | osl_File_Attribute_OthWrite ) ==
    2868           0 :                                     rFileStatus.getAttributes() );
    2869           0 :         }
    2870             : #else                                    //Windows version
    2871             :         void getAttributes_003()
    2872             :         {
    2873             :             CPPUNIT_ASSERT_MESSAGE( "test for getAttributes function: GrpWrite, OwnWrite, OthWrite( Windows version )",
    2874             :                                      1 == 1 );
    2875             :         }
    2876             : #endif
    2877             : 
    2878             : #if ( defined UNX )                     //hidden file definition may different in Windows
    2879           0 :         void getAttributes_004()
    2880             :         {
    2881           0 :             sal_Int32 test_Attributes = osl_File_Attribute_Hidden;
    2882           0 :               ::osl::FileStatus   rFileStatus( osl_FileStatus_Mask_Attributes );
    2883           0 :             nError = rItem_hidden.getFileStatus( rFileStatus );
    2884           0 :             CPPUNIT_ASSERT( nError == FileBase::E_None );
    2885           0 :             test_Attributes &= rFileStatus.getAttributes();
    2886             : 
    2887           0 :             CPPUNIT_ASSERT_MESSAGE( "test for getAttributes function: Hidden files( Solaris version )",
    2888           0 :                                     test_Attributes == osl_File_Attribute_Hidden );
    2889           0 :         }
    2890             : #else                                    //Windows version
    2891             :         void getAttributes_004()
    2892             :         {
    2893             :             ::rtl::OUString aUserHiddenFileURL ("file:///c:/AUTOEXEC.BAT");
    2894             :             nError = ::osl::DirectoryItem::get( aUserHiddenFileURL, rItem_hidden );
    2895             :             CPPUNIT_ASSERT_MESSAGE("get item fail", nError == FileBase::E_None );
    2896             :               ::osl::FileStatus   rFileStatus( osl_FileStatus_Mask_Attributes );
    2897             :             nError = rItem_hidden.getFileStatus( rFileStatus );
    2898             :             CPPUNIT_ASSERT( nError == FileBase::E_None );
    2899             : 
    2900             :             CPPUNIT_ASSERT_MESSAGE( "Hidden files(Windows version), please check if hidden file c:/AUTOEXEC.BAT exists ",
    2901             :                                     (rFileStatus.getAttributes() & osl_File_Attribute_Hidden)!= 0 );
    2902             :         }
    2903             : #endif
    2904             : 
    2905           0 :         CPPUNIT_TEST_SUITE( getAttributes );
    2906           0 :         CPPUNIT_TEST( getAttributes_001 );
    2907           0 :         CPPUNIT_TEST( getAttributes_002 );
    2908           0 :         CPPUNIT_TEST( getAttributes_003 );
    2909           0 :         CPPUNIT_TEST( getAttributes_004 );
    2910           0 :         CPPUNIT_TEST_SUITE_END();
    2911             :     };// class getAttributes
    2912             : 
    2913             :     //---------------------------------------------------------------------
    2914             :     //  testing the method
    2915             :     //  inline TimeValue getAccessTime() const
    2916             :     //---------------------------------------------------------------------
    2917           0 :     class  getAccessTime : public CppUnit::TestFixture
    2918             :     {
    2919             :         ::rtl::OUString         aTypeURL;
    2920             :         ::osl::FileBase::RC     nError;
    2921             :         ::osl::DirectoryItem    rItem;
    2922             : 
    2923             :         public:
    2924           0 :         getAccessTime() :nError(FileBase::E_None) {}
    2925             :         // initialization
    2926           0 :         void setUp()
    2927             :         {
    2928           0 :             aTypeURL = aUserDirectoryURL.copy( 0 );
    2929           0 :             concatURL( aTypeURL, aTmpName2 );
    2930           0 :             createTestFile( aTypeURL );
    2931           0 :             nError = ::osl::DirectoryItem::get( aTypeURL, rItem );
    2932           0 :             CPPUNIT_ASSERT( nError == FileBase::E_None );
    2933             : 
    2934           0 :         }
    2935             : 
    2936           0 :         void tearDown()
    2937             :         {
    2938           0 :             deleteTestFile( aTypeURL );
    2939           0 :         }
    2940             : 
    2941             :         // test code.
    2942           0 :         void getAccessTime_001()
    2943             :         {
    2944           0 :             TimeValue *pTV_current = NULL;
    2945           0 :             CPPUNIT_ASSERT( ( pTV_current = ( TimeValue* )malloc( sizeof( TimeValue ) ) ) != NULL );
    2946           0 :             TimeValue *pTV_access = NULL;
    2947           0 :             CPPUNIT_ASSERT( ( pTV_access = ( TimeValue* )malloc( sizeof( TimeValue ) ) ) != NULL );
    2948             : 
    2949           0 :               ::osl::FileStatus   rFileStatus( osl_FileStatus_Mask_AccessTime );
    2950           0 :             nError = rItem.getFileStatus( rFileStatus );
    2951           0 :             sal_Bool bOk = osl_getSystemTime( pTV_current );
    2952           0 :             CPPUNIT_ASSERT( sal_True == bOk && nError == FileBase::E_None );
    2953             : 
    2954           0 :             *pTV_access = rFileStatus.getAccessTime();
    2955             : 
    2956           0 :             sal_Bool bOK = t_compareTime( pTV_access, pTV_current, delta );
    2957           0 :             free( pTV_current );
    2958           0 :             free( pTV_access );
    2959             : 
    2960           0 :             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. ",
    2961           0 :                                     sal_True == bOK );
    2962           0 :         }
    2963             : 
    2964           0 :         CPPUNIT_TEST_SUITE( getAccessTime );
    2965           0 :         CPPUNIT_TEST( getAccessTime_001 );
    2966           0 :         CPPUNIT_TEST_SUITE_END();
    2967             :     };// class getAccessTime
    2968             : 
    2969             :     //---------------------------------------------------------------------
    2970             :     //  testing the method
    2971             :     //  inline TimeValue getModifyTime() const
    2972             :     //---------------------------------------------------------------------
    2973           0 :     class  getModifyTime : public CppUnit::TestFixture
    2974             :     {
    2975             :         ::rtl::OUString         aTypeURL;
    2976             :         ::osl::FileBase::RC     nError;
    2977             :         ::osl::DirectoryItem    rItem;
    2978             : 
    2979             :         public:
    2980           0 :         getModifyTime() :nError(FileBase::E_None) {}
    2981             : 
    2982             : 
    2983             :         // test code.
    2984           0 :         void getModifyTime_001()
    2985             :         {
    2986           0 :             TimeValue *pTV_current = NULL;
    2987           0 :             CPPUNIT_ASSERT( ( pTV_current = ( TimeValue* )malloc( sizeof( TimeValue ) ) ) != NULL );
    2988             : 
    2989             :             //create file
    2990           0 :             aTypeURL = aUserDirectoryURL.copy( 0 );
    2991           0 :             concatURL( aTypeURL, aTmpName2 );
    2992           0 :             createTestFile( aTypeURL );
    2993             : 
    2994             :             //get current time
    2995           0 :             sal_Bool bOk = osl_getSystemTime( pTV_current );
    2996           0 :             CPPUNIT_ASSERT( sal_True == bOk );
    2997             : 
    2998             :             //get instance item and filestatus
    2999           0 :             nError = ::osl::DirectoryItem::get( aTypeURL, rItem );
    3000           0 :             CPPUNIT_ASSERT( nError == FileBase::E_None );
    3001           0 :             ::osl::FileStatus   rFileStatus( osl_FileStatus_Mask_ModifyTime );
    3002           0 :             nError = rItem.getFileStatus( rFileStatus );
    3003           0 :             CPPUNIT_ASSERT( nError == FileBase::E_None );
    3004             : 
    3005             :             //get modify time
    3006           0 :             TimeValue *pTV_modify = NULL;
    3007           0 :             CPPUNIT_ASSERT( ( pTV_modify = ( TimeValue* )malloc( sizeof( TimeValue ) ) ) != NULL );
    3008           0 :             *pTV_modify = rFileStatus.getModifyTime();
    3009             : 
    3010           0 :             sal_Bool bOK = t_compareTime( pTV_modify, pTV_current, delta );
    3011             :             //delete file
    3012           0 :             deleteTestFile( aTypeURL );
    3013           0 :             free( pTV_current );
    3014             : 
    3015           0 :             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.  ",
    3016           0 :                                     sal_True == bOK );
    3017           0 :         }
    3018             : 
    3019           0 :         CPPUNIT_TEST_SUITE( getModifyTime );
    3020           0 :         CPPUNIT_TEST( getModifyTime_001 );
    3021           0 :         CPPUNIT_TEST_SUITE_END();
    3022             :     };// class getModifyTime
    3023             : 
    3024             : 
    3025             :     //---------------------------------------------------------------------
    3026             :     //  testing the method
    3027             :     //  inline sal_uInt64 getFileSize() const
    3028             :     //---------------------------------------------------------------------
    3029           0 :     class  getFileSize : public CppUnit::TestFixture
    3030             :     {
    3031             :         ::rtl::OUString         aTypeURL;
    3032             :         ::osl::FileBase::RC     nError;
    3033             :         ::osl::DirectoryItem    rItem;
    3034             : 
    3035             :         public:
    3036             : 
    3037           0 :         getFileSize() :nError(FileBase::E_None) {}
    3038             : 
    3039             :         // initialization
    3040           0 :         void setUp()
    3041             :         {
    3042           0 :             aTypeURL = aUserDirectoryURL.copy( 0 );
    3043           0 :             concatURL( aTypeURL, aTmpName2 );
    3044           0 :             createTestFile( aTypeURL );
    3045           0 :             nError = ::osl::DirectoryItem::get( aTypeURL, rItem );
    3046           0 :             CPPUNIT_ASSERT( nError == FileBase::E_None );
    3047           0 :         }
    3048             : 
    3049           0 :         void tearDown()
    3050             :         {
    3051           0 :             deleteTestFile( aTypeURL );
    3052           0 :         }
    3053             : 
    3054             :         // test code.
    3055           0 :         void getFileSize_001()
    3056             :         {
    3057           0 :               ::osl::FileStatus   rFileStatus( osl_FileStatus_Mask_FileSize );
    3058           0 :             nError = rItem.getFileStatus( rFileStatus );
    3059           0 :             CPPUNIT_ASSERT( nError == FileBase::E_None );
    3060             : 
    3061           0 :             sal_uInt64 uFileSize = rFileStatus.getFileSize();
    3062             : 
    3063           0 :             CPPUNIT_ASSERT_MESSAGE( "test for getFileSize function: empty file ",
    3064           0 :                                     0 == uFileSize );
    3065           0 :         }
    3066             : 
    3067           0 :         void getFileSize_002()
    3068             :         {
    3069           0 :             ::osl::File testfile( aTypeURL );
    3070           0 :             nError = testfile.open( osl_File_OpenFlag_Write | osl_File_OpenFlag_Read );
    3071           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError );
    3072           0 :             nError = testfile.setSize( TEST_FILE_SIZE );
    3073           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError );
    3074             : 
    3075           0 :             nError = ::osl::DirectoryItem::get( aTypeURL, rItem );
    3076           0 :             CPPUNIT_ASSERT( nError == FileBase::E_None );
    3077           0 :               ::osl::FileStatus   rFileStatus( osl_FileStatus_Mask_FileSize );
    3078           0 :             nError = rItem.getFileStatus( rFileStatus );
    3079           0 :             CPPUNIT_ASSERT( nError == FileBase::E_None );
    3080           0 :             sal_uInt64 uFileSize = rFileStatus.getFileSize();
    3081             : 
    3082           0 :             CPPUNIT_ASSERT_MESSAGE( "test for getFileSize function: file with size of TEST_FILE_SIZE, did not pass in (W32). ",
    3083           0 :                                     TEST_FILE_SIZE == uFileSize );
    3084           0 :         }
    3085           0 :         CPPUNIT_TEST_SUITE( getFileSize );
    3086           0 :         CPPUNIT_TEST( getFileSize_001 );
    3087           0 :         CPPUNIT_TEST( getFileSize_002 );
    3088           0 :         CPPUNIT_TEST_SUITE_END();
    3089             :     };// class getFileSize
    3090             : 
    3091             :     //---------------------------------------------------------------------
    3092             :     //  testing the method
    3093             :     //  inline ::rtl::OUString getFileName() const
    3094             :     //---------------------------------------------------------------------
    3095           0 :     class  getFileName : public CppUnit::TestFixture
    3096             :     {
    3097             :         ::rtl::OUString         aTypeURL;
    3098             :         ::osl::FileBase::RC     nError;
    3099             :         ::osl::DirectoryItem    rItem;
    3100             : 
    3101             :         public:
    3102           0 :         getFileName() :nError(FileBase::E_None) {}
    3103             :         // initialization
    3104           0 :         void setUp()
    3105             :         {
    3106           0 :             aTypeURL = aUserDirectoryURL.copy( 0 );
    3107           0 :             concatURL( aTypeURL, aTmpName2 );
    3108           0 :             createTestFile( aTypeURL );
    3109           0 :             nError = ::osl::DirectoryItem::get( aTypeURL, rItem );
    3110           0 :             CPPUNIT_ASSERT( nError == FileBase::E_None );
    3111           0 :         }
    3112             : 
    3113           0 :         void tearDown()
    3114             :         {
    3115           0 :             deleteTestFile( aTypeURL );
    3116           0 :         }
    3117             : 
    3118             :         // test code.
    3119           0 :         void getFileName_001()
    3120             :         {
    3121           0 :               ::osl::FileStatus   rFileStatus( osl_FileStatus_Mask_FileName );
    3122           0 :             nError = rItem.getFileStatus( rFileStatus );
    3123           0 :             CPPUNIT_ASSERT( nError == FileBase::E_None );
    3124             : 
    3125           0 :             ::rtl::OUString aFileName = rFileStatus.getFileName();
    3126             : 
    3127           0 :             CPPUNIT_ASSERT_MESSAGE( "test for getFileName function: name compare with specify",
    3128           0 :                                     sal_True == compareFileName( aFileName, aTmpName2 ) );
    3129           0 :         }
    3130             : 
    3131           0 :         CPPUNIT_TEST_SUITE( getFileName );
    3132           0 :         CPPUNIT_TEST( getFileName_001 );
    3133           0 :         CPPUNIT_TEST_SUITE_END();
    3134             :     };// class getFileName
    3135             : 
    3136             :     //---------------------------------------------------------------------
    3137             :     //  testing the method
    3138             :     //  inline ::rtl::OUString getFileURL() const
    3139             :     //---------------------------------------------------------------------
    3140           0 :     class  getFileURL : public CppUnit::TestFixture
    3141             :     {
    3142             :         ::rtl::OUString         aTypeURL;
    3143             :         ::osl::FileBase::RC     nError;
    3144             :         ::osl::DirectoryItem    rItem;
    3145             : 
    3146             :         public:
    3147           0 :         getFileURL() :nError(FileBase::E_None) {}
    3148             : 
    3149             :         // initialization
    3150           0 :         void setUp()
    3151             :         {
    3152           0 :             createTestFile( aTmpName6 );
    3153           0 :             nError = ::osl::DirectoryItem::get( aTmpName6, rItem );
    3154           0 :             CPPUNIT_ASSERT( nError == FileBase::E_None );
    3155           0 :         }
    3156             : 
    3157           0 :         void tearDown()
    3158             :         {
    3159           0 :             deleteTestFile( aTmpName6 );
    3160           0 :         }
    3161             : 
    3162             :         // test code.
    3163           0 :         void getFileURL_001()
    3164             :         {
    3165           0 :               ::osl::FileStatus   rFileStatus( osl_FileStatus_Mask_FileURL );
    3166           0 :             nError = rItem.getFileStatus( rFileStatus );
    3167           0 :             CPPUNIT_ASSERT( nError == FileBase::E_None );
    3168             : 
    3169           0 :             ::rtl::OUString aFileURL = rFileStatus.getFileURL();
    3170             : 
    3171           0 :             CPPUNIT_ASSERT_MESSAGE( "test for getFileURL function: ",
    3172           0 :                                     sal_True == compareFileName( aFileURL, aTmpName6 ) );
    3173           0 :         }
    3174             : 
    3175           0 :         CPPUNIT_TEST_SUITE( getFileURL );
    3176           0 :         CPPUNIT_TEST( getFileURL_001 );
    3177           0 :         CPPUNIT_TEST_SUITE_END();
    3178             :     };// class getFileURL
    3179             : 
    3180             :     //---------------------------------------------------------------------
    3181             :     //  testing the method
    3182             :     //  inline ::rtl::OUString getLinkTargetURL() const
    3183             :     //---------------------------------------------------------------------
    3184           0 :     class  getLinkTargetURL : public CppUnit::TestFixture
    3185             :     {
    3186             :         ::rtl::OUString         aTypeURL;
    3187             :         ::osl::FileBase::RC     nError;
    3188             :         ::osl::DirectoryItem    rItem;
    3189             : 
    3190             :         public:
    3191             : 
    3192           0 :         getLinkTargetURL() :nError(FileBase::E_None) {}
    3193             :         // test code.
    3194             :         // initialization
    3195           0 :         void setUp()
    3196             :         {
    3197           0 :             aTypeURL = aUserDirectoryURL.copy( 0 );
    3198           0 :             concatURL( aTypeURL, aTmpName2 );
    3199           0 :             createTestFile( aTypeURL );
    3200           0 :         }
    3201             : 
    3202           0 :         void tearDown()
    3203             :         {
    3204           0 :             deleteTestFile( aTypeURL );
    3205           0 :         }
    3206             : 
    3207             : #if ( defined UNX )            //Link file is not define in Windows
    3208           0 :         void getLinkTargetURL_001()
    3209             :         {
    3210             :             //create a link file;
    3211           0 :             ::rtl::OUString aUStr_LnkFileSys( aTempDirectorySys ), aUStr_SrcFileSys( aTempDirectorySys );
    3212           0 :             ( ( aUStr_LnkFileSys += aSlashURL ) += getCurrentPID() ) += ::rtl::OUString("/link.file");
    3213           0 :             ( ( aUStr_SrcFileSys += aSlashURL ) += getCurrentPID() ) += ::rtl::OUString("/tmpname");
    3214             : 
    3215           0 :                 rtl::OString strLinkFileName, strSrcFileName;
    3216           0 :                 strLinkFileName = OUStringToOString( aUStr_LnkFileSys, RTL_TEXTENCODING_ASCII_US );
    3217           0 :                 strSrcFileName  = OUStringToOString( aUStr_SrcFileSys, RTL_TEXTENCODING_ASCII_US );
    3218             : 
    3219             :             sal_Int32 fd;
    3220           0 :                 fd = symlink( strSrcFileName.getStr(), strLinkFileName.getStr() );
    3221           0 :             CPPUNIT_ASSERT_MESSAGE( "in creating link file",  fd == 0 );
    3222             : 
    3223             :             //get linkTarget URL
    3224           0 :             nError = ::osl::DirectoryItem::get( aLnkURL1, rItem );
    3225           0 :             CPPUNIT_ASSERT_MESSAGE( "in getting link file item", nError == FileBase::E_None );
    3226             : 
    3227           0 :               ::osl::FileStatus   rFileStatus( osl_FileStatus_Mask_LinkTargetURL );
    3228           0 :             nError = rItem.getFileStatus( rFileStatus );
    3229           0 :             CPPUNIT_ASSERT_MESSAGE( "in getting link file status", nError == FileBase::E_None );
    3230           0 :             ::rtl::OUString aFileURL = rFileStatus.getLinkTargetURL();
    3231             : 
    3232             :             //remove link file
    3233           0 :                 fd = remove( strLinkFileName.getStr() );
    3234           0 :             CPPUNIT_ASSERT_MESSAGE( "in deleting link file",  fd == 0 );
    3235             : 
    3236           0 :             CPPUNIT_ASSERT_MESSAGE( "test for getLinkTargetURL function: Solaris version, creat a file, and a link file link to it, get its LinkTargetURL and compare",
    3237           0 :                                     sal_True == compareFileName( aFileURL, aTypeURL ) );
    3238           0 :         }
    3239             : #else
    3240             :         void getLinkTargetURL_001()
    3241             :         {
    3242             :             CPPUNIT_ASSERT_MESSAGE( "test for getLinkTargetURL function: Windows version, not tested",
    3243             :                                     1 );
    3244             :         }
    3245             : #endif
    3246             : 
    3247           0 :         CPPUNIT_TEST_SUITE( getLinkTargetURL );
    3248           0 :         CPPUNIT_TEST( getLinkTargetURL_001 );
    3249           0 :         CPPUNIT_TEST_SUITE_END();
    3250             :     };// class getLinkTargetURL
    3251             : 
    3252             :     // -----------------------------------------------------------------------------
    3253           1 :     CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileStatus::ctors, "osl_FileStatus" );
    3254           1 :     CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileStatus::isValid, "osl_FileStatus" );
    3255           1 :     CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileStatus::getFileType, "osl_FileStatus" );
    3256           1 :     CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileStatus::getAttributes, "osl_FileStatus" );
    3257           1 :     CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileStatus::getAccessTime, "osl_FileStatus" );
    3258           1 :     CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileStatus::getModifyTime, "osl_FileStatus" );
    3259           1 :     CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileStatus::getFileSize, "osl_FileStatus" );
    3260           1 :     CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileStatus::getFileName, "osl_FileStatus" );
    3261           1 :     CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileStatus::getFileURL, "osl_FileStatus" );
    3262           1 :     CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileStatus::getLinkTargetURL, "osl_FileStatus" );
    3263             : }// namespace osl_FileStatus
    3264             : 
    3265             : 
    3266             : 
    3267             : //------------------------------------------------------------------------
    3268             : // Beginning of the test cases for File class
    3269             : //------------------------------------------------------------------------
    3270             : namespace osl_File
    3271             : {
    3272             :     //---------------------------------------------------------------------
    3273             :     //  testing the method
    3274             :     //  File( const ::rtl::OUString& ustrFileURL )
    3275             :     //---------------------------------------------------------------------
    3276           0 :     class  ctors : public CppUnit::TestFixture
    3277             :     {
    3278             :         // ::osl::FileBase::RC     nError1;
    3279             : 
    3280             :         public:
    3281             :         // initialization
    3282           0 :         void setUp()
    3283             :         {
    3284             :             // create a tempfile in $TEMP/tmpdir/tmpname.
    3285           0 :             createTestDirectory( aTmpName3 );
    3286           0 :             createTestFile( aTmpName4 );
    3287           0 :         }
    3288             : 
    3289           0 :         void tearDown()
    3290             :         {
    3291             :             // remove the tempfile in $TEMP/tmpdir/tmpname.
    3292           0 :             deleteTestFile( aTmpName4 );
    3293           0 :             deleteTestDirectory( aTmpName3 );
    3294           0 :         }
    3295             : 
    3296             :         // test code.
    3297           0 :         void ctors_001()
    3298             :         {
    3299           0 :             ::osl::File testFile( aTmpName4 );
    3300             : 
    3301           0 :             ::osl::FileBase::RC nError1 = testFile.open( osl_File_OpenFlag_Read | osl_File_OpenFlag_Write );
    3302           0 :             ::osl::FileBase::RC nError2 = testFile.close();
    3303           0 :             CPPUNIT_ASSERT_MESSAGE( "test for ctors function: initialize a File and test its open and close",
    3304           0 :                                      ( ::osl::FileBase::E_None == nError1 ) && ( ::osl::FileBase::E_None == nError2 ) );
    3305           0 :         }
    3306             : 
    3307           0 :         void ctors_002()
    3308             :         {
    3309           0 :             ::osl::File testFile( aTmpName5 );
    3310           0 :             sal_Char buffer[30] = "Test for File constructor";
    3311             :             sal_uInt64 nCount;
    3312             : 
    3313           0 :                 ::osl::FileBase::RC nError1 = testFile.open( osl_File_OpenFlag_Read | osl_File_OpenFlag_Write );
    3314           0 :                 ::osl::FileBase::RC nError2 = testFile.write( buffer, 30, nCount );
    3315           0 :             testFile.close();
    3316             : 
    3317           0 :             CPPUNIT_ASSERT_MESSAGE( "test for ctors function: test relative file URL, this test show that relative file URL is also acceptable",
    3318           0 :                                      ( ::osl::FileBase::E_None == nError1 ) && ( ::osl::FileBase::E_None == nError2 )  );
    3319           0 :         }
    3320             : 
    3321           0 :         CPPUNIT_TEST_SUITE( ctors );
    3322           0 :         CPPUNIT_TEST( ctors_001 );
    3323           0 :         CPPUNIT_TEST( ctors_002 );
    3324           0 :         CPPUNIT_TEST_SUITE_END();
    3325             :     };// class ctors
    3326             : 
    3327             :     //---------------------------------------------------------------------
    3328             :     //  testing the method
    3329             :     //  inline RC open( sal_uInt32 uFlags )
    3330             :     //---------------------------------------------------------------------
    3331           0 :     class  open : public CppUnit::TestFixture
    3332             :     {
    3333             :         ::osl::FileBase::RC     nError1, nError2, nError3;
    3334             : 
    3335             :         public:
    3336           0 :         open()
    3337             :             : nError1(FileBase::E_None)
    3338             :             , nError2(FileBase::E_None)
    3339           0 :             , nError3(FileBase::E_None) {}
    3340             :         // initialization
    3341           0 :         void setUp()
    3342             :         {
    3343             :             // create a tempfile in $TEMP/tmpdir/tmpname.
    3344           0 :             createTestDirectory( aTmpName3 );
    3345           0 :             createTestFile( aTmpName4 );
    3346           0 :         }
    3347             : 
    3348           0 :         void tearDown()
    3349             :         {
    3350             :             // remove the tempfile in $TEMP/tmpdir/tmpname.
    3351           0 :             deleteTestFile( aTmpName4 );
    3352           0 :             deleteTestDirectory( aTmpName3 );
    3353           0 :         }
    3354             : 
    3355             :         // test code.
    3356           0 :         void open_001()
    3357             :         {
    3358           0 :             ::osl::File testFile( aTmpName4 );
    3359             : 
    3360           0 :             nError1 = testFile.open( osl_File_OpenFlag_Read | osl_File_OpenFlag_Write );
    3361           0 :             nError2 = testFile.close();
    3362           0 :             CPPUNIT_ASSERT_MESSAGE("close error", ::osl::FileBase::E_None == nError2 );
    3363             : 
    3364           0 :             CPPUNIT_ASSERT_MESSAGE( "test for open function: open a regular file",
    3365           0 :                                      ::osl::FileBase::E_None == nError1 );
    3366           0 :         }
    3367             : 
    3368           0 :         void open_002()
    3369             :         {
    3370           0 :             ::osl::File testFile( aTmpName3 );
    3371             : 
    3372           0 :             nError1 = testFile.open( osl_File_OpenFlag_Read );
    3373             : 
    3374           0 :             CPPUNIT_ASSERT_MESSAGE( "test for open function: open a directory",
    3375           0 :                                      ( File::E_INVAL == nError1 ) || ( File::E_ACCES == nError1 ) );
    3376           0 :         }
    3377             : 
    3378           0 :         void open_003()
    3379             :         {
    3380           0 :             ::osl::File testFile( aCanURL1 );
    3381             : 
    3382           0 :             nError1 = testFile.open( osl_File_OpenFlag_Read | osl_File_OpenFlag_Write );
    3383             : 
    3384           0 :             CPPUNIT_ASSERT_MESSAGE( "test for open function: open a non-exist file",
    3385           0 :                                      File::E_NOENT == nError1 );
    3386           0 :         }
    3387             : 
    3388           0 :         void open_004()
    3389             :         {
    3390           0 :             ::rtl::OUString  aTestFile( aRootURL );
    3391           0 :             concatURL( aTestFile, aTmpName2 );
    3392           0 :             ::osl::File testFile( aTestFile );
    3393             : 
    3394           0 :             nError1 = testFile.open( osl_File_OpenFlag_Create );
    3395           0 :             sal_Bool bOK = ( File::E_ACCES == nError1 );
    3396             : #if defined (WNT )
    3397             :             bOK = sal_True;  /// in Windows, you can create file in c:/ any way.
    3398             :             testFile.close();
    3399             :             deleteTestFile( aTestFile);
    3400             : #endif
    3401             : 
    3402           0 :             CPPUNIT_ASSERT_MESSAGE( "test for open function: create an illegal file",
    3403           0 :                                       bOK == sal_True );
    3404           0 :         }
    3405             : 
    3406           0 :         void open_005()
    3407             :         {
    3408           0 :             ::osl::File testFile( aTmpName4 );
    3409             : 
    3410           0 :             nError1 = testFile.open( osl_File_OpenFlag_Create );
    3411             : 
    3412           0 :             CPPUNIT_ASSERT_MESSAGE( "test for open function: create an exist file",
    3413           0 :                                      File::E_EXIST == nError1 );
    3414           0 :         }
    3415             : 
    3416           0 :         void open_006()
    3417             :         {
    3418           0 :             ::osl::File testFile( aCanURL1 );
    3419           0 :             sal_Char buffer_write[30] = "Test for File open";
    3420             :             sal_Char buffer_read[30];
    3421             :             sal_uInt64 nCount_write, nCount_read;
    3422             : 
    3423           0 :             nError1 = testFile.open( osl_File_OpenFlag_Read | osl_File_OpenFlag_Write | osl_File_OpenFlag_Create );
    3424           0 :             nError2 = testFile.write( buffer_write, 30, nCount_write );
    3425           0 :              ::osl::FileBase::RC nError4 = testFile.setPos( osl_Pos_Absolut, 0 );
    3426           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError4 );
    3427           0 :             nError3 = testFile.read( buffer_read, 10, nCount_read );
    3428             : 
    3429           0 :              ::osl::FileBase::RC nError5 = testFile.close();
    3430           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError5 );
    3431           0 :             ::osl::FileBase::RC nError6 = testFile.remove( aCanURL1 );
    3432           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError6 );
    3433             : 
    3434           0 :             CPPUNIT_ASSERT_MESSAGE( "test for open function: test for osl_File_OpenFlag_Read, osl_File_OpenFlag_Write and osl_File_OpenFlag_Create",
    3435             :                                     ( ::osl::FileBase::E_None == nError1 ) &&
    3436             :                                     ( ::osl::FileBase::E_None == nError2 ) &&
    3437             :                                     ( ::osl::FileBase::E_None == nError3 ) &&
    3438             :                                     ( 30 == nCount_write ) &&
    3439           0 :                                     ( 10 == nCount_read ) );
    3440           0 :         }
    3441             : 
    3442           0 :         CPPUNIT_TEST_SUITE( open );
    3443           0 :         CPPUNIT_TEST( open_001 );
    3444           0 :         CPPUNIT_TEST( open_002 );
    3445           0 :         CPPUNIT_TEST( open_003 );
    3446           0 :         CPPUNIT_TEST( open_004 );
    3447           0 :         CPPUNIT_TEST( open_005 );
    3448           0 :         CPPUNIT_TEST( open_006 );
    3449           0 :         CPPUNIT_TEST_SUITE_END();
    3450             :     };// class open
    3451             : 
    3452             :     //---------------------------------------------------------------------
    3453             :     //  testing the method
    3454             :     //  inline RC close()
    3455             :     //---------------------------------------------------------------------
    3456           0 :     class  close : public CppUnit::TestFixture
    3457             :     {
    3458             :         ::osl::FileBase::RC     nError1, nError2, nError3;
    3459             : 
    3460             :         public:
    3461           0 :         close()
    3462             :             : nError1(FileBase::E_None)
    3463             :             , nError2(FileBase::E_None)
    3464           0 :             , nError3(FileBase::E_None) {}
    3465             :         // initialization
    3466           0 :         void setUp()
    3467             :         {
    3468             :             // create a tempfile in $TEMP/tmpdir/tmpname.
    3469           0 :             createTestDirectory( aTmpName3 );
    3470           0 :             createTestFile( aTmpName4 );
    3471           0 :         }
    3472             : 
    3473           0 :         void tearDown()
    3474             :         {
    3475             :             // remove the tempfile in $TEMP/tmpdir/tmpname.
    3476           0 :             deleteTestFile( aTmpName4 );
    3477           0 :             deleteTestDirectory( aTmpName3 );
    3478           0 :         }
    3479             : 
    3480             :         // test code.
    3481           0 :         void close_001()
    3482             :         {
    3483           0 :             ::osl::File testFile( aTmpName4 );
    3484             : 
    3485           0 :             nError1 = testFile.open( osl_File_OpenFlag_Read | osl_File_OpenFlag_Write );
    3486           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3487             : 
    3488           0 :             nError2 = testFile.close();
    3489             : 
    3490           0 :             CPPUNIT_ASSERT_MESSAGE( "test for close function: close a regular file",
    3491           0 :                                      ::osl::FileBase::E_None == nError2 );
    3492           0 :         }
    3493             : 
    3494           0 :         void close_002()
    3495             :         {
    3496           0 :             ::osl::File testFile( aTmpName4 );
    3497             : 
    3498           0 :             nError1 = testFile.open( osl_File_OpenFlag_Read | osl_File_OpenFlag_Write );
    3499           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3500             : 
    3501           0 :             nError2 = testFile.close();
    3502             : 
    3503           0 :              nError3 = testFile.setPos( osl_Pos_Absolut, 0 );
    3504             : 
    3505           0 :             CPPUNIT_ASSERT_MESSAGE( "test for close function: manipulate a file after it has been closed",
    3506             :                                      ( ::osl::FileBase::E_None == nError2 ) &&
    3507           0 :                                     ( ::osl::FileBase::E_None != nError3 ) );
    3508           0 :         }
    3509             : 
    3510           0 :         CPPUNIT_TEST_SUITE( close );
    3511           0 :         CPPUNIT_TEST( close_001 );
    3512           0 :         CPPUNIT_TEST( close_002 );
    3513           0 :         CPPUNIT_TEST_SUITE_END();
    3514             :     };// class close
    3515             : 
    3516             : 
    3517             :     //---------------------------------------------------------------------
    3518             :     //  testing the method
    3519             :     //  inline RC setPos( sal_uInt32 uHow, sal_Int64 uPos )
    3520             :     //---------------------------------------------------------------------
    3521           0 :     class  setPos : public CppUnit::TestFixture
    3522             :     {
    3523             :         ::osl::FileBase::RC     nError1;
    3524             :         sal_uInt64 nCount_write, nCount_read;
    3525             : 
    3526             :         public:
    3527           0 :         setPos() :nError1(FileBase::E_None) {}
    3528             : 
    3529             :         // initialization
    3530           0 :         void setUp()
    3531             :         {
    3532             :             // create a tempfile in $TEMP/tmpdir/tmpname.
    3533           0 :             createTestDirectory( aTmpName3 );
    3534           0 :             createTestFile( aTmpName4 );
    3535             : 
    3536             :             //write chars into the file.
    3537           0 :             ::osl::File testFile( aTmpName4 );
    3538             : 
    3539           0 :             nError1 = testFile.open( osl_File_OpenFlag_Write );
    3540           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3541           0 :             nError1 = testFile.write( pBuffer_Char, sizeof( pBuffer_Char ), nCount_write );
    3542           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3543           0 :              nError1 = testFile.close();
    3544           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3545           0 :         }
    3546             : 
    3547           0 :         void tearDown()
    3548             :         {
    3549             :             // remove the tempfile in $TEMP/tmpdir/tmpname.
    3550           0 :             deleteTestFile( aTmpName4 );
    3551           0 :             deleteTestDirectory( aTmpName3 );
    3552           0 :         }
    3553             : 
    3554             :         // test code.
    3555           0 :         void setPos_001()
    3556             :         {
    3557           0 :             ::osl::File testFile( aTmpName4 );
    3558             :             sal_Char buffer_read[2];
    3559             : 
    3560           0 :             nError1 = testFile.open( osl_File_OpenFlag_Read | osl_File_OpenFlag_Write );
    3561           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3562           0 :              nError1 = testFile.setPos( osl_Pos_Absolut, 26 );
    3563           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3564           0 :             nError1 = testFile.read( buffer_read, 1, nCount_read );
    3565           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3566           0 :             nError1 = testFile.close();
    3567           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3568             : 
    3569           0 :             CPPUNIT_ASSERT_MESSAGE( "test for setPos function: test for osl_Pos_Absolut, set the position to 26, test if the 26th char in file is correct",
    3570           0 :                                      buffer_read[0] == pBuffer_Char[26] );
    3571           0 :         }
    3572             : 
    3573           0 :         void setPos_002()
    3574             :         {
    3575           0 :             ::osl::File testFile( aTmpName4 );
    3576             :             sal_Char buffer_read[2];
    3577             : 
    3578           0 :             nError1 = testFile.open( osl_File_OpenFlag_Read | osl_File_OpenFlag_Write );
    3579           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3580           0 :              nError1 = testFile.setPos( osl_Pos_Absolut, sizeof( pBuffer_Char ) - 2 );
    3581           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3582           0 :              nError1 = testFile.setPos( osl_Pos_Current, 0);
    3583           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3584           0 :             nError1 = testFile.read( buffer_read, 1, nCount_read );
    3585           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3586           0 :             nError1 = testFile.close();
    3587           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3588             : 
    3589           0 :             CPPUNIT_ASSERT_MESSAGE( "test for setPos function: test for osl_Pos_Current, set the position to end, test if the ( end -1 ) char in file is correct",
    3590           0 :                                      buffer_read[0] == pBuffer_Char[sizeof( pBuffer_Char ) - 2] );
    3591           0 :         }
    3592             : 
    3593           0 :         void setPos_003()
    3594             :         {
    3595           0 :             ::osl::File testFile( aTmpName4 );
    3596             :             sal_Char buffer_read[2];
    3597             : 
    3598           0 :             nError1 = testFile.open( osl_File_OpenFlag_Read | osl_File_OpenFlag_Write );
    3599           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3600             :             //the file size is smaller than 100
    3601           0 :             nError1 = testFile.setPos( osl_Pos_End,  -100 );
    3602           0 :             CPPUNIT_ASSERT_MESSAGE( "should return error", ::osl::FileBase::E_INVAL == nError1 );
    3603             : 
    3604           0 :              nError1 = testFile.setPos( osl_Pos_End, -53 );
    3605           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3606           0 :             nError1 = testFile.read( buffer_read, 1, nCount_read );
    3607           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3608           0 :             nError1 = testFile.close();
    3609           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3610             : 
    3611           0 :             CPPUNIT_ASSERT_MESSAGE( "test for setPos function: test for osl_Pos_End, set the position to end, test if the first char in file is correct",
    3612           0 :                                      buffer_read[0] == pBuffer_Char[0] );
    3613           0 :         }
    3614             : 
    3615           0 :         CPPUNIT_TEST_SUITE( setPos );
    3616           0 :         CPPUNIT_TEST( setPos_001 );
    3617           0 :         CPPUNIT_TEST( setPos_002 );
    3618           0 :         CPPUNIT_TEST( setPos_003 );
    3619           0 :         CPPUNIT_TEST_SUITE_END();
    3620             :     };// class setPos
    3621             : 
    3622             :     //---------------------------------------------------------------------
    3623             :     //  testing the method
    3624             :     //  inline RC getPos( sal_uInt64& uPos )
    3625             :     //---------------------------------------------------------------------
    3626           0 :     class  getPos : public CppUnit::TestFixture
    3627             :     {
    3628             :         ::osl::FileBase::RC      nError1;
    3629             :         sal_uInt64 nCount_write;
    3630             : 
    3631             :         public:
    3632           0 :         getPos() :nError1(FileBase::E_None) {}
    3633             :         // initialization
    3634           0 :         void setUp()
    3635             :         {
    3636             :             // create a tempfile in $TEMP/tmpdir/tmpname.
    3637           0 :             createTestDirectory( aTmpName3 );
    3638           0 :             createTestFile( aTmpName4 );
    3639             : 
    3640             :             //write chars into the file.
    3641           0 :             ::osl::File testFile( aTmpName4 );
    3642             : 
    3643           0 :             nError1 = testFile.open( osl_File_OpenFlag_Write );
    3644           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3645           0 :             nError1 = testFile.write( pBuffer_Char, sizeof( pBuffer_Char ), nCount_write );
    3646           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3647           0 :              nError1 = testFile.close();
    3648           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3649           0 :         }
    3650             : 
    3651           0 :         void tearDown()
    3652             :         {
    3653             :             // remove the tempfile in $TEMP/tmpdir/tmpname.
    3654           0 :             deleteTestFile( aTmpName4 );
    3655           0 :             deleteTestDirectory( aTmpName3 );
    3656           0 :         }
    3657             : 
    3658             :         // test code.
    3659           0 :         void getPos_001()
    3660             :         {
    3661           0 :             ::osl::File testFile( aTmpName4 );
    3662             :             sal_uInt64 nFilePointer;
    3663             : 
    3664           0 :             nError1 = testFile.getPos( nFilePointer );
    3665           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_INVAL == nError1 );
    3666             : 
    3667           0 :             nError1 = testFile.open( osl_File_OpenFlag_Read | osl_File_OpenFlag_Write );
    3668           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3669             : 
    3670           0 :              nError1 = testFile.setPos( osl_Pos_Absolut, 26 );
    3671           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3672           0 :              nError1 = testFile.getPos( nFilePointer );
    3673           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3674             : 
    3675           0 :             nError1 = testFile.close();
    3676           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3677             : 
    3678           0 :             CPPUNIT_ASSERT_MESSAGE( "test for getPos function: set the position to 26, get position and check if it is right",
    3679           0 :                                      26 == nFilePointer );
    3680           0 :         }
    3681             : 
    3682           0 :         CPPUNIT_TEST_SUITE( getPos );
    3683           0 :         CPPUNIT_TEST( getPos_001 );
    3684           0 :         CPPUNIT_TEST_SUITE_END();
    3685             :     };// class getPos
    3686             : 
    3687             : 
    3688             :     //---------------------------------------------------------------------
    3689             :     //  testing the method
    3690             :     //  inline RC isEndOfFile( sal_Bool *pIsEOF )
    3691             :     //---------------------------------------------------------------------
    3692           0 :     class  isEndOfFile : public CppUnit::TestFixture
    3693             :     {
    3694             :         ::osl::FileBase::RC      nError1;
    3695             :         sal_uInt64 nCount_write;
    3696             : 
    3697             :         public:
    3698           0 :         isEndOfFile() :nError1(FileBase::E_None) {}
    3699             :         // initialization
    3700           0 :         void setUp()
    3701             :         {
    3702             :             // create a tempfile in $TEMP/tmpdir/tmpname.
    3703           0 :             createTestDirectory( aTmpName3 );
    3704           0 :             createTestFile( aTmpName4 );
    3705             : 
    3706             :             //write chars into the file.
    3707           0 :             ::osl::File testFile( aTmpName4 );
    3708             : 
    3709           0 :             nError1 = testFile.open( osl_File_OpenFlag_Write );
    3710           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3711           0 :             nError1 = testFile.write( pBuffer_Char, sizeof( pBuffer_Char ), nCount_write );
    3712           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3713           0 :              nError1 = testFile.close();
    3714           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3715           0 :         }
    3716             : 
    3717           0 :         void tearDown()
    3718             :         {
    3719             :             // remove the tempfile in $TEMP/tmpdir/tmpname.
    3720           0 :             deleteTestFile( aTmpName4 );
    3721           0 :             deleteTestDirectory( aTmpName3 );
    3722           0 :         }
    3723             : 
    3724             :         // test code.
    3725           0 :         void isEndOfFile_001()
    3726             :         {
    3727           0 :             ::osl::File   testFile( aTmpName4 );
    3728           0 :             sal_Bool      bEOF  = sal_False;
    3729           0 :             sal_Bool      *pEOF = &bEOF;
    3730             : 
    3731             : 
    3732           0 :             nError1 = testFile.open( osl_File_OpenFlag_Read | osl_File_OpenFlag_Write );
    3733           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3734             : 
    3735           0 :              nError1 = testFile.setPos( osl_Pos_End, 0 );
    3736           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3737           0 :             nError1 = testFile.isEndOfFile( pEOF );
    3738           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3739             : 
    3740           0 :             nError1 = testFile.close();
    3741           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3742             : 
    3743           0 :             CPPUNIT_ASSERT_MESSAGE( "test for isEndOfFile function: set the position to end, check if reach end",
    3744           0 :                                      sal_True == *pEOF );
    3745           0 :         }
    3746             : 
    3747           0 :         void isEndOfFile_002()
    3748             :         {
    3749           0 :              ::osl::File   testFile( aTmpName4 );
    3750           0 :             sal_Bool      bEOF  = sal_False;
    3751           0 :             sal_Bool      *pEOF = &bEOF;
    3752           0 :             sal_uInt64    nFilePointer = 0;
    3753             : 
    3754           0 :             nError1 = testFile.open( osl_File_OpenFlag_Read | osl_File_OpenFlag_Write );
    3755           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3756             : 
    3757           0 :              nError1 = testFile.setPos( osl_Pos_Absolut, 0 );
    3758           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3759           0 :             *pEOF = sal_False;
    3760           0 :              while ( !( *pEOF ) )
    3761             :             {
    3762           0 :                 nError1 = testFile.isEndOfFile( pEOF );
    3763           0 :                 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3764           0 :                 nError1 = testFile.setPos( osl_Pos_Current, 1 );
    3765           0 :                 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3766             :             }
    3767           0 :              nError1 = testFile.getPos( nFilePointer );
    3768           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3769             : 
    3770           0 :             nError1 = testFile.close();
    3771           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3772             : 
    3773           0 :             CPPUNIT_ASSERT_MESSAGE( "test for isEndOfFile function: use isEndOfFile to move pointer step by step",
    3774           0 :                                       sizeof( pBuffer_Char ) + 1 == nFilePointer  );
    3775           0 :         }
    3776           0 :         CPPUNIT_TEST_SUITE( isEndOfFile );
    3777           0 :         CPPUNIT_TEST( isEndOfFile_001 );
    3778           0 :         CPPUNIT_TEST( isEndOfFile_002 );
    3779           0 :         CPPUNIT_TEST_SUITE_END();
    3780             :     };// class isEndOfFile
    3781             : 
    3782             : 
    3783             :     //---------------------------------------------------------------------
    3784             :     //  testing the method
    3785             :     //  inline RC setSize( sal_uInt64 uSize )
    3786             :     //---------------------------------------------------------------------
    3787           0 :     class  setSize : public CppUnit::TestFixture
    3788             :     {
    3789             :         ::osl::FileBase::RC      nError1;
    3790             :         sal_uInt64 nCount_write;
    3791             : 
    3792             :         public:
    3793           0 :         setSize() :nError1(FileBase::E_None) {}
    3794             :         // initialization
    3795           0 :         void setUp()
    3796             :         {
    3797             :             // create a tempfile in $TEMP/tmpdir/tmpname.
    3798           0 :             createTestDirectory( aTmpName3 );
    3799           0 :             createTestFile( aTmpName4 );
    3800             : 
    3801             :             //write chars into the file.
    3802           0 :             ::osl::File testFile( aTmpName4 );
    3803             : 
    3804           0 :             nError1 = testFile.open( osl_File_OpenFlag_Write );
    3805           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3806           0 :             nError1 = testFile.write( pBuffer_Char, sizeof( pBuffer_Char ), nCount_write );
    3807           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3808           0 :              nError1 = testFile.close();
    3809           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3810           0 :         }
    3811             : 
    3812           0 :         void tearDown()
    3813             :         {
    3814             :             // remove the tempfile in $TEMP/tmpdir/tmpname.
    3815           0 :             deleteTestFile( aTmpName4 );
    3816           0 :             deleteTestDirectory( aTmpName3 );
    3817           0 :         }
    3818             : 
    3819             :         // test code.
    3820           0 :         void setSize_001()
    3821             :         {
    3822           0 :             ::osl::File   testFile( aTmpName4 );
    3823             :             // sal_Bool      bEOF  = sal_False;
    3824             :             // sal_Bool      *pEOF = &bEOF;
    3825             :             sal_uInt64     nFilePointer;
    3826             : 
    3827             : 
    3828           0 :             nError1 = testFile.open( osl_File_OpenFlag_Read | osl_File_OpenFlag_Write );
    3829           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3830             : 
    3831             :             //enlarge the file to size of 100;
    3832           0 :              nError1 = testFile.setSize( 100 );
    3833           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3834             : 
    3835             :             //get the file size;
    3836           0 :              nError1 = testFile.setPos( osl_Pos_End, 0 );
    3837           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3838           0 :              nError1 = testFile.getPos( nFilePointer );
    3839           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3840             : 
    3841           0 :             nError1 = testFile.close();
    3842           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3843             : 
    3844           0 :             CPPUNIT_ASSERT_MESSAGE( "test for setSize function: enlarge the file ",
    3845           0 :                                      100 == nFilePointer );
    3846           0 :         }
    3847             : 
    3848           0 :         void setSize_002()
    3849             :         {
    3850           0 :             ::osl::File   testFile( aTmpName4 );
    3851             :             // sal_Bool      bEOF  = sal_False;
    3852             :             // sal_Bool      *pEOF = &bEOF;
    3853             :             sal_uInt64     nFilePointer;
    3854             : 
    3855             : 
    3856           0 :             nError1 = testFile.open( osl_File_OpenFlag_Read | osl_File_OpenFlag_Write );
    3857           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3858             : 
    3859             :             //enlarge the file to size of 100;
    3860           0 :              nError1 = testFile.setSize( 10 );
    3861           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3862             : 
    3863             :             //get the file size;
    3864           0 :              nError1 = testFile.setPos( osl_Pos_End, 0 );
    3865           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3866           0 :              nError1 = testFile.getPos( nFilePointer );
    3867           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3868             : 
    3869           0 :             nError1 = testFile.close();
    3870           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3871             : 
    3872           0 :             CPPUNIT_ASSERT_MESSAGE( "test for setSize function: truncate the file ",
    3873           0 :                                      10 == nFilePointer );
    3874           0 :         }
    3875             : 
    3876           0 :         CPPUNIT_TEST_SUITE( setSize );
    3877           0 :         CPPUNIT_TEST( setSize_001 );
    3878           0 :         CPPUNIT_TEST( setSize_002 );
    3879           0 :         CPPUNIT_TEST_SUITE_END();
    3880             :     };// class setSize
    3881             : 
    3882             : 
    3883             :     //---------------------------------------------------------------------
    3884             :     //  testing the method
    3885             :     //  inline RC read( void *pBuffer, sal_uInt64 uBytesRequested, sal_uInt64& rBytesRead )
    3886             :     //---------------------------------------------------------------------
    3887           0 :     class  read : public CppUnit::TestFixture
    3888             :     {
    3889             :         ::osl::FileBase::RC      nError1;
    3890             :         sal_uInt64 nCount_write, nCount_read;
    3891             : 
    3892             :         public:
    3893           0 :         read() :nError1(FileBase::E_None) {}
    3894             :         // initialization
    3895           0 :         void setUp()
    3896             :         {
    3897             :             // create a tempfile in $TEMP/tmpdir/tmpname.
    3898           0 :             createTestDirectory( aTmpName3 );
    3899           0 :             createTestFile( aTmpName4 );
    3900             : 
    3901             :             //write chars into the file.
    3902           0 :             ::osl::File testFile( aTmpName4 );
    3903             : 
    3904           0 :             nError1 = testFile.open( osl_File_OpenFlag_Write );
    3905           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3906           0 :             nError1 = testFile.write( pBuffer_Char, sizeof( pBuffer_Char ), nCount_write );
    3907           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3908           0 :              nError1 = testFile.close();
    3909           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3910           0 :         }
    3911             : 
    3912           0 :         void tearDown()
    3913             :         {
    3914             :             // remove the tempfile in $TEMP/tmpdir/tmpname.
    3915           0 :             deleteTestFile( aTmpName4 );
    3916           0 :             deleteTestDirectory( aTmpName3 );
    3917           0 :         }
    3918             : 
    3919             :         // test code.
    3920           0 :         void read_001()
    3921             :         {
    3922           0 :             ::osl::File    testFile( aTmpName4 );
    3923             :             sal_uInt64     nFilePointer;
    3924             :             sal_Char       buffer_read[10];
    3925             : 
    3926             : 
    3927           0 :             nError1 = testFile.open( osl_File_OpenFlag_Read | osl_File_OpenFlag_Write );
    3928           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3929             : 
    3930           0 :             nError1 = testFile.read( buffer_read, 10, nCount_read );
    3931           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3932           0 :              nError1 = testFile.getPos( nFilePointer );
    3933           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3934             : 
    3935           0 :             nError1 = testFile.close();
    3936           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3937             : 
    3938           0 :             CPPUNIT_ASSERT_MESSAGE( "test for read function: read whole content in the file to a buffer",
    3939           0 :                                      ( 10 == nFilePointer ) && ( 0 == strncmp( buffer_read, pBuffer_Char, 10 ) ) );
    3940           0 :         }
    3941             : 
    3942           0 :         void read_002()
    3943             :         {
    3944           0 :             ::osl::File    testFile( aTmpName4 );
    3945             :             sal_uInt64     nFilePointer;
    3946             :             sal_Char       buffer_read[26];
    3947             : 
    3948             : 
    3949           0 :             nError1 = testFile.open( osl_File_OpenFlag_Read | osl_File_OpenFlag_Write );
    3950           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3951             : 
    3952           0 :              nError1 = testFile.setPos( osl_Pos_Absolut, 26 );
    3953           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3954           0 :             nError1 = testFile.read( buffer_read, 26, nCount_read );
    3955           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3956           0 :              nError1 = testFile.getPos( nFilePointer );
    3957           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3958             : 
    3959           0 :             nError1 = testFile.close();
    3960           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    3961             : 
    3962           0 :             CPPUNIT_ASSERT_MESSAGE( "test for read function: read from a special position in the file",
    3963           0 :                                      ( 52 == nFilePointer ) && ( 26 == nCount_read ) && ( 0 == strncmp( buffer_read, &pBuffer_Char[26], 26 ) ) );
    3964           0 :         }
    3965             : 
    3966           0 :         CPPUNIT_TEST_SUITE( read );
    3967           0 :         CPPUNIT_TEST( read_001 );
    3968           0 :         CPPUNIT_TEST( read_002 );
    3969           0 :         CPPUNIT_TEST_SUITE_END();
    3970             :     };// class read
    3971             : 
    3972             :     //---------------------------------------------------------------------
    3973             :     //  testing the method
    3974             :     //  inline RC write(const void *pBuffer, sal_uInt64 uBytesToWrite, sal_uInt64& rBytesWritten)
    3975             :     //---------------------------------------------------------------------
    3976           0 :     class  write : public CppUnit::TestFixture
    3977             :     {
    3978             :         ::osl::FileBase::RC      nError1;
    3979             :         sal_uInt64 nCount_write, nCount_read;
    3980             : 
    3981             :         public:
    3982           0 :         write() :nError1(FileBase::E_None) {}
    3983             :         // initialization
    3984           0 :         void setUp()
    3985             :         {
    3986             :             // create a tempfile in $TEMP/tmpname.
    3987           0 :             createTestFile( aTmpName6 );
    3988           0 :         }
    3989             : 
    3990           0 :         void tearDown()
    3991             :         {
    3992             :             // remove the tempfile in $TEMP/tmpname.
    3993           0 :             deleteTestFile( aTmpName6 );
    3994           0 :         }
    3995             : 
    3996             :         // test code.
    3997           0 :         void write_001()
    3998             :         {
    3999           0 :             ::osl::File    testFile( aTmpName6 );
    4000             :             sal_uInt64     nFilePointer;
    4001             :             sal_Char       buffer_read[10];
    4002             : 
    4003           0 :             nError1 = testFile.open( osl_File_OpenFlag_Read | osl_File_OpenFlag_Write );
    4004           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    4005             : 
    4006             :             //write chars into the file.
    4007           0 :             nError1 = testFile.write( pBuffer_Char, 10, nCount_write );
    4008           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    4009             :             //get the current pointer;
    4010           0 :              nError1 = testFile.getPos( nFilePointer );
    4011           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    4012             :             //reset pointer to the beginning;
    4013           0 :              nError1 = testFile.setPos( osl_Pos_Absolut, 0 );
    4014           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    4015           0 :             nError1 = testFile.read( buffer_read, 10, nCount_read );
    4016           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    4017             : 
    4018           0 :             nError1 = testFile.close();
    4019           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    4020             : 
    4021           0 :             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",
    4022             :                                      ( 10 == nFilePointer ) &&
    4023             :                                     ( 0 == strncmp( buffer_read, pBuffer_Char, 10 ) ) &&
    4024           0 :                                     ( 10 == nCount_write ) );
    4025           0 :         }
    4026             : 
    4027           0 :         CPPUNIT_TEST_SUITE( write );
    4028           0 :         CPPUNIT_TEST( write_001 );
    4029           0 :         CPPUNIT_TEST_SUITE_END();
    4030             :     };// class write
    4031             : 
    4032             :     //---------------------------------------------------------------------
    4033             :     //  testing the method
    4034             :     //  inline RC readLine( ::rtl::ByteSequence& aSeq )
    4035             :     //---------------------------------------------------------------------
    4036           0 :     class  readLine : public CppUnit::TestFixture
    4037             :     {
    4038             :         ::osl::FileBase::RC      nError1;
    4039             :         sal_uInt64 nCount_write;
    4040             :         ::rtl::ByteSequence      aSequence;
    4041             : 
    4042             :         public:
    4043           0 :         readLine() :nError1(FileBase::E_None) {}
    4044             :         // initialization
    4045           0 :         void setUp()
    4046             :         {
    4047             :             // create a tempfile in $TEMP/tmpname.
    4048           0 :             createTestFile( aTmpName6 );
    4049             : 
    4050             :             //write some strings into the file.
    4051           0 :             ::osl::File testFile( aTmpName6 );
    4052             :             sal_Char ppStrSeq[3][27]  =  { "abcde\n",
    4053             :                                         "1234567890\n",
    4054             :                                         "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    4055           0 :                                       };
    4056             : 
    4057           0 :             nError1 = testFile.open( osl_File_OpenFlag_Write );
    4058           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    4059             : 
    4060           0 :             for ( int nCount = 0; nCount < 3; nCount++ )
    4061             :             {
    4062           0 :                 nError1 = testFile.write( ppStrSeq[nCount], strlen( ppStrSeq[nCount] ), nCount_write );
    4063           0 :                 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    4064             :             }
    4065             : 
    4066           0 :              nError1 = testFile.close();
    4067           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    4068           0 :         }
    4069             : 
    4070           0 :         void tearDown()
    4071             :         {
    4072             :             // remove the tempfile in $TEMP/tmpname.
    4073           0 :             deleteTestFile( aTmpName6 );
    4074           0 :         }
    4075             : 
    4076             :         // test code.
    4077           0 :         void readLine_001()
    4078             :         {
    4079           0 :              ::osl::File    testFile( aTmpName6 );
    4080             : 
    4081           0 :             nError1 = testFile.open( osl_File_OpenFlag_Read | osl_File_OpenFlag_Write );
    4082           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    4083           0 :             nError1 = testFile.readLine( aSequence );
    4084           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    4085           0 :             CPPUNIT_ASSERT_MESSAGE( "test for readLine function: read the first line of the file.",
    4086             :                                     ( ::osl::FileBase::E_None == nError1 ) &&
    4087           0 :                                     ( 0 == strncmp( ( const char * )aSequence.getArray(), pBuffer_Char, 5 ) ) );
    4088           0 :         }
    4089             : 
    4090           0 :         void readLine_002()
    4091             :         {
    4092           0 :             ::osl::File testFile( aTmpName6 );
    4093           0 :             sal_Bool bEOF  = sal_False;
    4094           0 :             sal_Bool *pEOF = &bEOF;
    4095             : 
    4096           0 :             nError1 = testFile.open( osl_File_OpenFlag_Read | osl_File_OpenFlag_Write );
    4097           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    4098           0 :             for ( int nCount = 0; nCount < 3; nCount++ )
    4099             :             {
    4100           0 :                 nError1 = testFile.readLine( aSequence );
    4101           0 :                 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    4102             :             }
    4103           0 :              nError1 = testFile.isEndOfFile( pEOF );
    4104           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    4105             : 
    4106           0 :             CPPUNIT_ASSERT_MESSAGE( "test for readLine function: read three lines of the file and check the file pointer moving.",
    4107             :                                      *pEOF &&
    4108           0 :                                     ( 0 == strncmp( ( const char * )aSequence.getArray(), &pBuffer_Char[26], 26 ) ) );
    4109           0 :         }
    4110             : #ifdef UNX
    4111           0 :         void readLine_android()
    4112             :         {
    4113             :             static const char buffer[] =
    4114             :                 "Hello\n\r\n\a\n"
    4115             :                 "Fun=Badness\n"
    4116             :                 "Some=Somethingelse\n\r";
    4117           0 :             sal_Int32 aHash = rtl_str_hashCode( buffer );
    4118           0 :             for (size_t i = 0; i < sizeof (buffer); i += 7)
    4119             :             {
    4120           0 :                 oslFileHandle pFile( 0 );
    4121           0 :                 CPPUNIT_ASSERT( osl_openMemoryAsFile( (void *)buffer,
    4122             :                                                       sizeof( buffer ) - i, &pFile )
    4123           0 :                                 == osl_File_E_None );
    4124             :                 for (;;)
    4125             :                 {
    4126           0 :                     sal_Sequence *pSequence( 0 );
    4127           0 :                     if (osl_readLine( pFile, &pSequence ) != osl_File_E_None)
    4128           0 :                         break;
    4129           0 :                     rtl_byte_sequence_release (pSequence);
    4130           0 :                 }
    4131           0 :                 CPPUNIT_ASSERT( osl_closeFile( pFile ) == osl_File_E_None );
    4132             :             }
    4133           0 :             CPPUNIT_ASSERT( aHash == rtl_str_hashCode( buffer ) );
    4134           0 :         }
    4135             : #endif
    4136           0 :         CPPUNIT_TEST_SUITE( readLine );
    4137           0 :         CPPUNIT_TEST( readLine_001 );
    4138           0 :         CPPUNIT_TEST( readLine_002 );
    4139             : #ifdef UNX
    4140           0 :         CPPUNIT_TEST( readLine_android );
    4141             : #endif
    4142           0 :         CPPUNIT_TEST_SUITE_END();
    4143             :     };// class readLine
    4144             : 
    4145             :     //---------------------------------------------------------------------
    4146             :     //  testing the method
    4147             :     //  inline static RC copy( const ::rtl::OUString& ustrSourceFileURL, const ::rtl::OUString& ustrDestFileURL )
    4148             :     //---------------------------------------------------------------------
    4149           0 :     class  copy : public CppUnit::TestFixture
    4150             :     {
    4151             :         ::osl::FileBase::RC      nError1;
    4152             :         sal_uInt64 nCount_write;
    4153             : 
    4154             :         public:
    4155           0 :         copy() :nError1(FileBase::E_None) {}
    4156             :         // initialization
    4157           0 :         void setUp()
    4158             :         {
    4159             :             // create a tempfile in $TEMP/tmpdir/tmpname.
    4160           0 :             createTestDirectory( aTmpName3 );
    4161           0 :             createTestFile( aTmpName4 );
    4162             : 
    4163             :             //write chars into the file.
    4164           0 :             ::osl::File testFile( aTmpName4 );
    4165             : 
    4166           0 :             nError1 = testFile.open( osl_File_OpenFlag_Write );
    4167           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    4168           0 :             nError1 = testFile.write( pBuffer_Char, sizeof( pBuffer_Char ), nCount_write );
    4169           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    4170           0 :              nError1 = testFile.close();
    4171           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    4172           0 :         }
    4173             : 
    4174           0 :         void tearDown()
    4175             :         {
    4176             :             // remove the tempfile in $TEMP/tmpdir/tmpname.
    4177           0 :             deleteTestFile( aTmpName4 );
    4178           0 :             deleteTestDirectory( aTmpName3 );
    4179           0 :         }
    4180             : 
    4181             :         // test code.
    4182           0 :         void copy_001()
    4183             :         {
    4184           0 :              ::osl::File    testFile( aTmpName6 );
    4185             : 
    4186             :             //copy $TEMP/tmpdir/tmpname to $TEMP/tmpname.
    4187           0 :             nError1 = ::osl::File::copy( aTmpName4, aTmpName6 );
    4188           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    4189             :             //check
    4190           0 :             nError1 = testFile.open( osl_File_OpenFlag_Create );
    4191           0 :             deleteTestFile( aTmpName6 );
    4192             : 
    4193           0 :             CPPUNIT_ASSERT_MESSAGE( "test for copy function: copy file to upper directory",
    4194           0 :                                      ::osl::FileBase::E_EXIST == nError1 );
    4195           0 :         }
    4196             : 
    4197           0 :         void copy_002()
    4198             :         {
    4199             :             //copy $TEMP/tmpdir/tmpname to $TEMP/tmpdir.
    4200           0 :             nError1 = ::osl::File::copy( aTmpName4, aTmpName3 );
    4201             : 
    4202           0 :             CPPUNIT_ASSERT_MESSAGE( "test for copy function: use directory as destination",
    4203           0 :                                      ( ::osl::FileBase::E_ISDIR == nError1 ) ||( ::osl::FileBase::E_ACCES == nError1 )  );
    4204           0 :         }
    4205             : 
    4206           0 :         void copy_003()
    4207             :         {
    4208             :             //copy $TEMP/tmpdir/tmpname to $ROOT/tmpname.
    4209           0 :             nError1 = ::osl::File::copy( aTmpName4, aTmpName7 );
    4210             : #if defined (WNT )
    4211             :             nError1 = ::osl::FileBase::E_ACCES;  /// for Windows, c:/ is writtenable any way.
    4212             :             deleteTestFile( aTmpName7);
    4213             : #endif
    4214           0 :             CPPUNIT_ASSERT_MESSAGE( "test for copy function: copy to an illigal place",
    4215           0 :                                      ::osl::FileBase::E_ACCES == nError1 );
    4216           0 :         }
    4217             : 
    4218           0 :         void copy_004()
    4219             :         {
    4220             :             //copy $TEMP/tmpname to $TEMP/tmpdir/tmpname.
    4221           0 :             nError1 = ::osl::File::copy( aTmpName6, aTmpName4 );
    4222             : 
    4223           0 :             CPPUNIT_ASSERT_MESSAGE( "test for copy function: copy a not exist file",
    4224           0 :                                      ::osl::FileBase::E_NOENT == nError1 );
    4225           0 :         }
    4226             : 
    4227           0 :         void copy_005()
    4228             :         {
    4229             :             //copy $TEMP/tmpname to $TEMP/system.path using system path.
    4230           0 :             nError1 = ::osl::File::copy( aTmpName6, aSysPath1 );
    4231             : 
    4232           0 :             CPPUNIT_ASSERT_MESSAGE( "test for copy function: copy a file using system file path",
    4233           0 :                                      ::osl::FileBase::E_INVAL == nError1 );
    4234           0 :         }
    4235           0 :       void copy_006()
    4236             :       {
    4237           0 :         createTestFile( aTmpName6 );
    4238           0 :         File tmpFile( aTmpName6 );
    4239           0 :         FileBase::RC err = tmpFile.open( osl_File_OpenFlag_Write | osl_File_OpenFlag_Read );
    4240             :         (void)err;
    4241           0 :         tmpFile.setSize( 200 );
    4242           0 :         tmpFile.close();
    4243             :         //copy to new path
    4244           0 :         nError1 = ::osl::File::copy( aTmpName6, aTmpName4 );
    4245           0 :         CPPUNIT_ASSERT( nError1 == FileBase::E_None );
    4246             : 
    4247             :         //check if is the new file
    4248           0 :         File newFile( aTmpName4 );
    4249           0 :         newFile.open( osl_File_OpenFlag_Write | osl_File_OpenFlag_Read );
    4250           0 :         nError1 = newFile.setPos( osl_Pos_End, 0 );
    4251           0 :         CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    4252             :         sal_uInt64     nFilePointer;
    4253           0 :         nError1 = newFile.getPos( nFilePointer );
    4254           0 :         CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    4255           0 :         newFile.close();
    4256           0 :         deleteTestFile( aTmpName6 );
    4257           0 :         CPPUNIT_ASSERT_MESSAGE( "test for copy function: the dest file exist",
    4258           0 :                     nFilePointer == 200 );
    4259           0 :       }
    4260             :       //copyLink has not been impletmented yet
    4261             :       void copy_007()
    4262             :       {
    4263             : #if ( defined UNX )
    4264             : 
    4265             :         CPPUNIT_ASSERT_MESSAGE( "test for copy function: source file is link file",
    4266             :                                      ::osl::FileBase::E_INVAL == nError1 );
    4267             : #endif
    4268             :       }
    4269             : 
    4270           0 :         CPPUNIT_TEST_SUITE( copy );
    4271           0 :         CPPUNIT_TEST( copy_001 );
    4272           0 :         CPPUNIT_TEST( copy_002 );
    4273           0 :         CPPUNIT_TEST( copy_003 );
    4274           0 :         CPPUNIT_TEST( copy_004 );
    4275           0 :         CPPUNIT_TEST( copy_005 );
    4276           0 :         CPPUNIT_TEST( copy_006 );
    4277           0 :         CPPUNIT_TEST_SUITE_END();
    4278             :     };// class copy
    4279             : 
    4280             :     //---------------------------------------------------------------------
    4281             :     //  testing the method
    4282             :     //  inline static RC move( const ::rtl::OUString& ustrSourceFileURL, const ::rtl::OUString& ustrDestFileURL )
    4283             :     //---------------------------------------------------------------------
    4284           0 :     class  move : public CppUnit::TestFixture
    4285             :     {
    4286             :         ::osl::FileBase::RC      nError1, nError2;
    4287             :         sal_uInt64 nCount_write;
    4288             : 
    4289             :         public:
    4290           0 :         move() :nError1(FileBase::E_None),nError2(FileBase::E_None) {}
    4291             :         // initialization
    4292           0 :         void setUp()
    4293             :         {
    4294             :             // create a tempfile in $TEMP/tmpdir/tmpname.
    4295           0 :             createTestDirectory( aTmpName3 );
    4296           0 :             createTestFile( aTmpName4 );
    4297             : 
    4298             :             //write chars into the file.
    4299           0 :             ::osl::File testFile( aTmpName4 );
    4300             : 
    4301           0 :             nError1 = testFile.open( osl_File_OpenFlag_Write );
    4302           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    4303           0 :             nError1 = testFile.write( pBuffer_Char, sizeof( pBuffer_Char ), nCount_write );
    4304           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    4305           0 :              nError1 = testFile.close();
    4306           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    4307           0 :         }
    4308             : 
    4309           0 :         void tearDown()
    4310             :         {
    4311             :             // remove the tempfile in $TEMP/tmpdir/tmpname.
    4312           0 :             deleteTestFile( aTmpName4 );
    4313           0 :             deleteTestDirectory( aTmpName3 );
    4314           0 :         }
    4315             : 
    4316             :         // test code.
    4317           0 :         void move_001()
    4318             :         {
    4319             :             //rename $TEMP/tmpdir/tmpname to $TEMP/canonical.name.
    4320           0 :             nError1 = ::osl::File::move( aTmpName4, aCanURL1 );
    4321           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    4322             :             //check
    4323           0 :              ::osl::File    testFile( aCanURL1 );
    4324           0 :             nError2 = testFile.open( osl_File_OpenFlag_Create );
    4325           0 :             deleteTestFile( aCanURL1 );
    4326             : 
    4327           0 :             CPPUNIT_ASSERT_MESSAGE( "test for move function: rename file to another directory",
    4328           0 :                                      ::osl::FileBase::E_EXIST == nError2 );
    4329           0 :         }
    4330             : 
    4331           0 :         void move_002()
    4332             :         {
    4333             :             //move $TEMP/tmpdir/tmpname to $TEMP/tmpdir.
    4334           0 :             nError1 = ::osl::File::move( aTmpName4, aTmpName3 );
    4335             :             //returned ::osl::FileBase::E_ACCES on WNT
    4336           0 :             CPPUNIT_ASSERT_MESSAGE( "test for move function: use directory as destination",
    4337           0 :                  ( ::osl::FileBase::E_ACCES == nError1 || ::osl::FileBase::E_ISDIR == nError1 ) ||( ::osl::FileBase::E_EXIST == nError1 )  );
    4338           0 :         }
    4339             : 
    4340           0 :         void move_003()
    4341             :         {
    4342             :             //move $TEMP/tmpdir/tmpname to $ROOT/tmpname.
    4343           0 :             nError1 = ::osl::File::move( aTmpName4, aTmpName7 );
    4344             : #if defined (WNT )
    4345             :             nError1 = ::osl::FileBase::E_ACCES;  /// for Windows, c:/ is writtenable any way.
    4346             :             deleteTestFile( aTmpName7);
    4347             : #endif
    4348             : 
    4349           0 :             CPPUNIT_ASSERT_MESSAGE( "test for move function: move to an illigal place",
    4350           0 :                                      ::osl::FileBase::E_ACCES == nError1 );
    4351           0 :         }
    4352             : 
    4353           0 :         void move_004()
    4354             :         {
    4355             :             //move $TEMP/tmpname to $TEMP/tmpdir/tmpname.
    4356           0 :             nError1 = ::osl::File::move( aTmpName6, aTmpName4 );
    4357             : 
    4358           0 :             CPPUNIT_ASSERT_MESSAGE( "test for move function: move a not exist file",
    4359           0 :                                      ::osl::FileBase::E_NOENT == nError1 );
    4360           0 :         }
    4361             : 
    4362           0 :         void move_005()
    4363             :         {
    4364             :             //move $TEMP/tmpname to $TEMP/system.path using system path.
    4365           0 :             nError1 = ::osl::File::move( aTmpName6, aSysPath1 );
    4366             : 
    4367           0 :             CPPUNIT_ASSERT_MESSAGE( "test for move function: move a file using system file",
    4368           0 :                                      ::osl::FileBase::E_INVAL == nError1 );
    4369           0 :         }
    4370             : 
    4371           0 :         void move_006()
    4372             :         {
    4373             :             //move directory $TEMP/tmpname to $TEMP/tmpdir/tmpname.
    4374           0 :             createTestDirectory( aTmpName6 );
    4375           0 :             nError1 = ::osl::File::move( aTmpName6, aTmpName4 );
    4376             :             //move file $TEMP/tmpdir/tmpname to $TEMP/tmpname
    4377           0 :             nError2 = ::osl::File::move( aTmpName4, aTmpName6 );
    4378           0 :             deleteTestDirectory( aTmpName6 );
    4379             : #if defined ( WNT )
    4380             :             deleteTestDirectory( aTmpName4 );// in Windows, it can be moved!!!!! this is only for not influence the following test.
    4381             :             deleteTestFile( aTmpName6 );
    4382             :             nError1 = ::osl::FileBase::E_NOTDIR;
    4383             :             nError2 = ::osl::FileBase::E_ISDIR;
    4384             : #endif
    4385           0 :             CPPUNIT_ASSERT_MESSAGE( "test for move function: move a directory to an exist file with same name, did not pass in (W32)",
    4386           0 :                                      ::osl::FileBase::E_NOTDIR == nError1 && ::osl::FileBase::E_ISDIR == nError2 );
    4387           0 :         }
    4388             : 
    4389           0 :         void move_007()
    4390             :         {
    4391             :             //create directory $TEMP/tmpname.
    4392           0 :             createTestDirectory( aTmpName6 );
    4393             :             //move directory $TEMP/tmpdir to $TEMP/tmpname/tmpdir
    4394           0 :             nError1 = ::osl::File::move( aTmpName3, aTmpName8 );
    4395             :             //check
    4396           0 :             nError2 = ::osl::Directory::create( aTmpName8 );
    4397           0 :             ::osl::File::move( aTmpName8, aTmpName3 );
    4398           0 :             deleteTestDirectory( aTmpName6 );
    4399             : 
    4400           0 :             CPPUNIT_ASSERT_MESSAGE( "test for move function: move a directory to an exist file with same name",
    4401             :                                      (::osl::FileBase::E_None == nError1 ) &&
    4402           0 :                                     (::osl::FileBase::E_EXIST == nError2 ) );
    4403           0 :         }
    4404             :       // oldpath and newpath are not on the same filesystem.EXDEV,no such error no on Solaris, only on linux
    4405             :       void move_008()
    4406             :       {
    4407             :         CPPUNIT_ASSERT_MESSAGE( "oldpath and newpath are not on the same filesystem, should error returns",
    4408             :                                      ::osl::FileBase::E_None == nError1  );
    4409             :       }
    4410             :       //bugid# 115420, after the bug fix, add the case
    4411             :       void move_009()
    4412             :       {
    4413             :         //create directory $TEMP/tmpname.
    4414             :         createTestDirectory( aTmpName6 );
    4415             :         //create directory $TEMP/tmpname/tmpdir
    4416             :         createTestDirectory( aTmpName8 );
    4417             :         //move directory $TEMP/tmpname to $TEMP/tmpname/tmpdir/tmpname
    4418             :         rtl::OUString newName = aTmpName8 + OUString("/tmpname");
    4419             :         nError1 = ::osl::File::move( aTmpName3, newName );
    4420             :         //deleteTestDirectory( newName + OUString("/tmpname") );
    4421             :         //deleteTestDirectory( newName );
    4422             :         deleteTestDirectory( aTmpName8 );
    4423             :         deleteTestDirectory( aTmpName6 );
    4424             :         CPPUNIT_ASSERT_MESSAGE( "test for move function: move a directory to it's subdirectory",
    4425             :                                  ::osl::FileBase::E_None != nError1 );
    4426             :       }
    4427             : 
    4428           0 :         CPPUNIT_TEST_SUITE( move );
    4429           0 :         CPPUNIT_TEST( move_001 );
    4430           0 :         CPPUNIT_TEST( move_002 );
    4431           0 :         CPPUNIT_TEST( move_003 );
    4432           0 :         CPPUNIT_TEST( move_004 );
    4433           0 :         CPPUNIT_TEST( move_005 );
    4434           0 :         CPPUNIT_TEST( move_006 );
    4435           0 :         CPPUNIT_TEST( move_007 );
    4436             :       //      CPPUNIT_TEST( move_008 );
    4437             :       //CPPUNIT_TEST( move_009 );
    4438           0 :         CPPUNIT_TEST_SUITE_END();
    4439             :     };// class move
    4440             : 
    4441             : 
    4442             :     //---------------------------------------------------------------------
    4443             :     //  testing the method
    4444             :     //  inline static RC remove( const ::rtl::OUString& ustrFileURL )
    4445             :     //---------------------------------------------------------------------
    4446           0 :     class  remove : public CppUnit::TestFixture
    4447             :     {
    4448             :         ::osl::FileBase::RC      nError1, nError2;
    4449             :         sal_uInt64 nCount_write;
    4450             : 
    4451             :         public:
    4452           0 :         remove() :nError1(FileBase::E_None),nError2(FileBase::E_None) {}
    4453             :         // initialization
    4454           0 :         void setUp()
    4455             :         {
    4456             :             // create a tempfile in $TEMP/tmpdir/tmpname.
    4457           0 :             createTestDirectory( aTmpName3 );
    4458           0 :             createTestFile( aTmpName4 );
    4459             : 
    4460             :             //write chars into the file.
    4461           0 :             ::osl::File testFile( aTmpName4 );
    4462             : 
    4463           0 :             nError1 = testFile.open( osl_File_OpenFlag_Write );
    4464           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    4465           0 :             nError1 = testFile.write( pBuffer_Char, sizeof( pBuffer_Char ), nCount_write );
    4466           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    4467           0 :              nError1 = testFile.close();
    4468           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    4469           0 :         }
    4470             : 
    4471           0 :         void tearDown()
    4472             :         {
    4473             :             // remove the tempfile in $TEMP/tmpdir/tmpname.
    4474           0 :             deleteTestFile( aTmpName4 );
    4475           0 :             deleteTestDirectory( aTmpName3 );
    4476           0 :         }
    4477             : 
    4478             :         // test code.
    4479           0 :         void remove_001()
    4480             :         {
    4481             :             //remove $TEMP/tmpdir/tmpname.
    4482           0 :             nError1 = ::osl::File::remove( aTmpName4 );
    4483             :             //check
    4484           0 :              ::osl::File    testFile( aTmpName4 );
    4485           0 :             nError2 = testFile.open( osl_File_OpenFlag_Create );
    4486             : 
    4487           0 :             CPPUNIT_ASSERT_MESSAGE( "test for remove function: remove a file",
    4488             :                                     ( ::osl::FileBase::E_None == nError1 ) &&
    4489           0 :                                      ( ::osl::FileBase::E_EXIST != nError2 ) );
    4490           0 :         }
    4491             : 
    4492           0 :         void remove_002()
    4493             :         {
    4494             :             //remove $TEMP/tmpname.
    4495           0 :             nError1 = ::osl::File::remove( aTmpName6 );
    4496             : 
    4497           0 :             CPPUNIT_ASSERT_MESSAGE( "test for remove function: remove a file not exist",
    4498           0 :                                     ( ::osl::FileBase::E_NOENT == nError1 ) );
    4499           0 :         }
    4500             : 
    4501           0 :         void remove_003()
    4502             :         {
    4503             :             //remove $TEMP/system/path.
    4504           0 :             nError1 = ::osl::File::remove( aSysPath2 );
    4505             : 
    4506           0 :             CPPUNIT_ASSERT_MESSAGE( "test for remove function: removing a file not using full qualified URL",
    4507           0 :                                     ( ::osl::FileBase::E_INVAL == nError1 ) );
    4508           0 :         }
    4509             : 
    4510           0 :         void remove_004()
    4511             :         {
    4512             :             //remove $TEMP/tmpdir.
    4513           0 :             nError1 = ::osl::File::remove( aTmpName3 );
    4514             : 
    4515           0 :             CPPUNIT_ASSERT_MESSAGE( "test for remove function: remove a directory",
    4516           0 :                                     ( ::osl::FileBase::E_ISDIR == nError1 ) || ( ::osl::FileBase::E_ACCES == nError1 ));
    4517           0 :         }
    4518             : 
    4519           0 :         CPPUNIT_TEST_SUITE( remove );
    4520           0 :         CPPUNIT_TEST( remove_001 );
    4521           0 :         CPPUNIT_TEST( remove_002 );
    4522           0 :         CPPUNIT_TEST( remove_003 );
    4523           0 :         CPPUNIT_TEST( remove_004 );
    4524           0 :         CPPUNIT_TEST_SUITE_END();
    4525             :     };// class remove
    4526             : 
    4527             : 
    4528             :     //---------------------------------------------------------------------
    4529             :     //  testing the method
    4530             :     //  inline static RC setAttributes( const ::rtl::OUString& ustrFileURL, sal_uInt64 uAttributes )
    4531             :     //---------------------------------------------------------------------
    4532           0 :     class  setAttributes : public CppUnit::TestFixture
    4533             :     {
    4534             :         ::osl::FileBase::RC      nError1, nError2;
    4535             :         ::osl::DirectoryItem    rItem, rItem_hidden;
    4536             : 
    4537             :         public:
    4538           0 :         setAttributes() :nError1(FileBase::E_None),nError2(FileBase::E_None) {}
    4539             :         // initialization
    4540           0 :         void setUp()
    4541             :         {
    4542             :             // create a tempfile in $TEMP/tmpdir/tmpname.
    4543           0 :             createTestFile( aTmpName6 );
    4544           0 :         }
    4545             : 
    4546           0 :         void tearDown()
    4547             :         {
    4548             :             // remove the tempfile in $TEMP/tmpdir/tmpname.
    4549           0 :             deleteTestFile( aTmpName6 );
    4550           0 :         }
    4551             : 
    4552             :         // test code.
    4553           0 :         void setAttributes_001()
    4554             :         {
    4555             :         //on windows, only can set 2 attributes: osl_File_Attribute_ReadOnly,  osl_File_Attribute_Hidden
    4556             : #ifdef UNX
    4557             :             //set the file to readonly
    4558           0 :             nError2 = ::osl::File::setAttributes( aTmpName6, osl_File_Attribute_ReadOnly | osl_File_Attribute_GrpRead | osl_File_Attribute_OwnRead | osl_File_Attribute_OthRead );
    4559           0 :             CPPUNIT_ASSERT( nError2 == FileBase::E_None);
    4560           0 :             nError1 = ::osl::DirectoryItem::get( aTmpName6, rItem );
    4561           0 :             CPPUNIT_ASSERT( nError1 == FileBase::E_None);
    4562             :             //get the file attributes
    4563           0 :               ::osl::FileStatus   rFileStatus( osl_FileStatus_Mask_Attributes );
    4564           0 :             nError1 = rItem.getFileStatus( rFileStatus );
    4565           0 :             CPPUNIT_ASSERT( nError1 == FileBase::E_None );
    4566             : 
    4567           0 :             CPPUNIT_ASSERT_MESSAGE( "test for setAttributes function: set file attributes and get it to verify.",
    4568             :                                     ( osl_File_Attribute_ReadOnly | osl_File_Attribute_GrpRead | osl_File_Attribute_OwnRead | osl_File_Attribute_OthRead ) ==
    4569           0 :                                     rFileStatus.getAttributes() );
    4570             : #else
    4571             :             //please see GetFileAttributes
    4572             :             nError2 = ::osl::File::setAttributes( aTmpName6, osl_File_Attribute_ReadOnly );
    4573             :             CPPUNIT_ASSERT( nError2 == FileBase::E_None);
    4574             :             nError1 = ::osl::DirectoryItem::get( aTmpName6, rItem );
    4575             :             CPPUNIT_ASSERT( nError1 == FileBase::E_None);
    4576             :             //get the file attributes
    4577             :               ::osl::FileStatus   rFileStatus( osl_FileStatus_Mask_Attributes );
    4578             :             nError1 = rItem.getFileStatus( rFileStatus );
    4579             :             CPPUNIT_ASSERT( nError1 == FileBase::E_None );
    4580             :             //here the file has 2 Attributes: FILE_ATTRIBUTE_READONLY and FILE_ATTRIBUTE_NORMAL,
    4581             :             // but FILE_ATTRIBUTE_NORMAL is valid only if used alone, so this is maybe a bug
    4582             :             /*::rtl::OString aString = ::rtl::OUStringToOString( aTmpName6, RTL_TEXTENCODING_ASCII_US );
    4583             :             DWORD dwFileAttributes = GetFileAttributes( aString.getStr() );
    4584             :             if (dwFileAttributes & FILE_ATTRIBUTE_NORMAL)
    4585             :                 printf("has normal attribute");
    4586             :             if (dwFileAttributes & FILE_ATTRIBUTE_READONLY)
    4587             :                 printf("has readonly attribute");
    4588             :             */
    4589             :             CPPUNIT_ASSERT_MESSAGE( "test for setAttributes function: set file attributes READONLY and get it to verify.",
    4590             :                                     (osl_File_Attribute_ReadOnly & rFileStatus.getAttributes()) != 0  );
    4591             : #endif
    4592           0 :     }
    4593           0 :         void setAttributes_002()
    4594             :         {
    4595             :         //on UNX, can not set hidden attribute to file, rename file can set the attribute
    4596             : #ifdef WNT
    4597             :             //set the file to hidden
    4598             :             nError2 = ::osl::File::setAttributes( aTmpName6, osl_File_Attribute_Hidden);
    4599             : 
    4600             :             CPPUNIT_ASSERT( nError2 == FileBase::E_None);
    4601             :             nError1 = ::osl::DirectoryItem::get( aTmpName6, rItem );
    4602             :             CPPUNIT_ASSERT( nError1 == FileBase::E_None);
    4603             :             //get the file attributes
    4604             :               ::osl::FileStatus rFileStatus( osl_FileStatus_Mask_Attributes );
    4605             :             nError1 = rItem.getFileStatus( rFileStatus );
    4606             :             CPPUNIT_ASSERT( nError1 == FileBase::E_None );
    4607             : 
    4608             :             CPPUNIT_ASSERT_MESSAGE( "test for setAttributes function: set file attributes and get it to verify.",
    4609             :                                     (osl_File_Attribute_Hidden & rFileStatus.getAttributes()) != 0 );
    4610             : #endif
    4611           0 :         }
    4612             : 
    4613           0 :         CPPUNIT_TEST_SUITE( setAttributes );
    4614           0 :         CPPUNIT_TEST( setAttributes_001 );
    4615           0 :         CPPUNIT_TEST( setAttributes_002 );
    4616           0 :         CPPUNIT_TEST_SUITE_END();
    4617             :     };// class setAttributes
    4618             : 
    4619             : 
    4620             :     //---------------------------------------------------------------------
    4621             :     //  testing the method
    4622             :     //  inline static RC setTime(
    4623             :     //         const ::rtl::OUString& ustrFileURL,
    4624             :     //         const TimeValue& rCreationTime,
    4625             :     //         const TimeValue& rLastAccessTime,
    4626             :     //         const TimeValue& rLastWriteTime )
    4627             :     //---------------------------------------------------------------------
    4628           0 :     class  setTime : public CppUnit::TestFixture
    4629             :     {
    4630             :         ::osl::FileBase::RC     nError1, nError2;
    4631             :         ::osl::DirectoryItem    rItem;
    4632             : 
    4633             :         public:
    4634           0 :         setTime() :nError1(FileBase::E_None),nError2(FileBase::E_None) {}
    4635             :         // initialization
    4636           0 :         void setUp()
    4637             :         {
    4638             :             // create a tempfile in $TEMP/tmpdir/tmpname.
    4639           0 :             createTestFile( aTmpName6 );
    4640           0 :         }
    4641             : 
    4642           0 :         void tearDown()
    4643             :         {
    4644             :             // remove the tempfile in $TEMP/tmpdir/tmpname.
    4645           0 :             deleteTestFile( aTmpName6 );
    4646           0 :         }
    4647             : 
    4648             :         // test code.
    4649           0 :         void setTime_001()
    4650             :         {
    4651           0 :              TimeValue *pTV_current  = NULL;
    4652           0 :             CPPUNIT_ASSERT( ( pTV_current = ( TimeValue* )malloc( sizeof( TimeValue ) ) ) != NULL );
    4653           0 :             TimeValue *pTV_creation = NULL;
    4654           0 :             CPPUNIT_ASSERT( ( pTV_creation = ( TimeValue* )malloc( sizeof( TimeValue ) ) ) != NULL );
    4655           0 :             TimeValue *pTV_access   = NULL;
    4656           0 :             CPPUNIT_ASSERT( ( pTV_access = ( TimeValue* )malloc( sizeof( TimeValue ) ) ) != NULL );
    4657           0 :             TimeValue *pTV_modify   = NULL;
    4658           0 :             CPPUNIT_ASSERT( ( pTV_modify = ( TimeValue* )malloc( sizeof( TimeValue ) ) ) != NULL );
    4659             : 
    4660             :             //get current time
    4661           0 :             sal_Bool bOk = osl_getSystemTime( pTV_current );
    4662           0 :             CPPUNIT_ASSERT( sal_True == bOk );
    4663             : 
    4664             :             //set the file time
    4665           0 :             nError2 = ::osl::File::setTime( aTmpName6, *pTV_current, *pTV_current, *pTV_current );
    4666           0 :             CPPUNIT_ASSERT_MESSAGE( errorToStr( nError2 ).getStr(), nError2 == FileBase::E_None);
    4667             : 
    4668             :              //get the file access time, creation time, modify time
    4669           0 :             nError1 = ::osl::DirectoryItem::get( aTmpName6, rItem );
    4670           0 :             CPPUNIT_ASSERT_MESSAGE( errorToStr( nError1 ).getStr(), nError1 == FileBase::E_None);
    4671             : 
    4672           0 :               ::osl::FileStatus   rFileStatus( osl_FileStatus_Mask_AccessTime );
    4673           0 :             nError1 = rItem.getFileStatus( rFileStatus );
    4674           0 :             CPPUNIT_ASSERT_MESSAGE( errorToStr( nError1 ).getStr(),nError1 == FileBase::E_None );
    4675           0 :             *pTV_access = rFileStatus.getAccessTime();
    4676             : 
    4677           0 :               ::osl::FileStatus   rFileStatus1( osl_FileStatus_Mask_CreationTime );
    4678           0 :             nError1 = rItem.getFileStatus( rFileStatus1 );
    4679           0 :             CPPUNIT_ASSERT_MESSAGE( errorToStr( nError1 ).getStr(), nError1 == FileBase::E_None );
    4680           0 :             *pTV_creation = rFileStatus1.getCreationTime();
    4681             : 
    4682           0 :               ::osl::FileStatus   rFileStatus2( osl_FileStatus_Mask_ModifyTime );
    4683           0 :             nError1 = rItem.getFileStatus( rFileStatus2 );
    4684           0 :             CPPUNIT_ASSERT_MESSAGE( errorToStr( nError1 ).getStr(), nError1 == FileBase::E_None );
    4685           0 :             *pTV_modify = rFileStatus2.getModifyTime();
    4686             : 
    4687           0 :             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.",
    4688           0 :                 sal_True == t_compareTime( pTV_access, pTV_current, delta ) );
    4689             : #if defined ( WNT )
    4690             :             //Unfortunately there is no way to get the creation time of a file under Unix (its a Windows only feature).
    4691             :             //That means the flag osl_FileStatus_Mask_CreationTime should be deprecated under Unix.
    4692             :             CPPUNIT_ASSERT_MESSAGE( "test for setTime function: set creation time then get it. ",
    4693             :                 sal_True == t_compareTime( pTV_creation, pTV_current, delta ) ) ;
    4694             : #endif
    4695           0 :             CPPUNIT_ASSERT_MESSAGE( "test for setTime function: set modify time then get it. ",
    4696           0 :                 sal_True == t_compareTime( pTV_modify, pTV_current, delta ) );
    4697           0 :             free( pTV_current );
    4698           0 :             free( pTV_creation );
    4699           0 :             free( pTV_access );
    4700           0 :             free( pTV_modify );
    4701           0 :         }
    4702             : 
    4703           0 :         CPPUNIT_TEST_SUITE( setTime );
    4704           0 :         CPPUNIT_TEST( setTime_001 );
    4705           0 :         CPPUNIT_TEST_SUITE_END();
    4706             :     };// class setTime
    4707             : 
    4708             :     //---------------------------------------------------------------------
    4709             :     //  testing the method
    4710             :     //  inline static RC sync()
    4711             :     //---------------------------------------------------------------------
    4712           0 :         class  sync : public CppUnit::TestFixture
    4713             :     {
    4714             :         ::osl::FileBase::RC     nError1, nError2;
    4715             :         ::osl::DirectoryItem    rItem;
    4716             : 
    4717             :         public:
    4718           0 :         sync() :nError1(FileBase::E_None),nError2(FileBase::E_None) {}
    4719             :         // initialization
    4720           0 :         void setUp()
    4721             :         {
    4722             :             // create a tempfile in $TEMP/tmpdir/tmpname.
    4723           0 :             createTestFile( aTmpName6 );
    4724             : 
    4725           0 :         }
    4726             : 
    4727           0 :         void tearDown()
    4728             :         {
    4729             :             // remove the tempfile in $TEMP/tmpdir/tmpname.
    4730           0 :             deleteTestFile( aTmpName6 );
    4731           0 :         }
    4732             : 
    4733             :         // test case: if The file is located on a read only file system.
    4734           0 :         void sync_001()
    4735             :         {
    4736             : #ifdef UNX
    4737           0 :             nError1 = ::osl::DirectoryItem::get( aTmpName6, rItem );
    4738           0 :             CPPUNIT_ASSERT( nError1 == FileBase::E_None);
    4739             : 
    4740           0 :             File tmp_file( aTmpName6 );
    4741           0 :             FileBase::RC err = tmp_file.open(osl_File_OpenFlag_Write );
    4742             : 
    4743           0 :             CPPUNIT_ASSERT_MESSAGE("File open failed", err == FileBase::E_None);
    4744             : 
    4745             :             char buffer[50000];
    4746           0 :             sal_uInt64 written = 0;
    4747           0 :             nError1 = tmp_file.write((void*)buffer, sizeof(buffer), written);
    4748           0 :             CPPUNIT_ASSERT_MESSAGE("write failed!", nError1 == FileBase::E_None);
    4749             : 
    4750             :             //set the file to readonly
    4751           0 :             nError2 = ::osl::File::setAttributes( aTmpName6, osl_File_Attribute_ReadOnly | osl_File_Attribute_GrpRead | osl_File_Attribute_OwnRead | osl_File_Attribute_OthRead );
    4752           0 :             CPPUNIT_ASSERT( nError2 == FileBase::E_None);
    4753             : 
    4754           0 :             nError2 = tmp_file.sync();
    4755             : 
    4756           0 :                 CPPUNIT_ASSERT_MESSAGE("can not sync to readonly file!", nError2 == FileBase::E_None);
    4757             : 
    4758           0 :             tmp_file.close();
    4759             : #endif
    4760           0 :         }
    4761             :       //test case:no enough space, how to create such case???see test_cpy_wrt_file.cxx::test_osl_writeFile
    4762             : 
    4763             : 
    4764             : 
    4765           0 :         CPPUNIT_TEST_SUITE( sync );
    4766           0 :         CPPUNIT_TEST( sync_001 );
    4767           0 :         CPPUNIT_TEST_SUITE_END();
    4768             :     };// class setTime
    4769             : 
    4770             :     // -----------------------------------------------------------------------------
    4771           1 :     CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::ctors, "osl_File" );
    4772           1 :     CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::open, "osl_File" );
    4773           1 :     CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::close, "osl_File" );
    4774           1 :     CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::setPos, "osl_File" );
    4775           1 :     CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::getPos, "osl_File" );
    4776           1 :     CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::isEndOfFile, "osl_File" );
    4777           1 :     CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::setSize, "osl_File" );
    4778           1 :     CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::read, "osl_File" );
    4779           1 :     CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::write, "osl_File" );
    4780           1 :     CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::readLine, "osl_File" );
    4781           1 :     CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::copy, "osl_File" );
    4782           1 :     CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::move, "osl_File" );
    4783           1 :     CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::remove, "osl_File" );
    4784           1 :     CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::setAttributes, "osl_File" );
    4785           1 :     CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::setTime, "osl_File" );
    4786           1 :     CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::sync, "osl_File" );
    4787             : // FIXME: to enable these tests (when they work cross-platform) we need to add the below:
    4788             : //    CPPUNIT_REGISTRY_ADD_TO_DEFAULT( "osl_File" );
    4789             : 
    4790             : }// namespace osl_File
    4791             : 
    4792             : 
    4793             : //------------------------------------------------------------------------
    4794             : // Beginning of the test cases for DirectoryItem class
    4795             : //------------------------------------------------------------------------
    4796             : namespace osl_DirectoryItem
    4797             : {
    4798             :     //---------------------------------------------------------------------
    4799             :     //  testing the method
    4800             :     //  DirectoryItem(): _pData( NULL )
    4801             :     //---------------------------------------------------------------------
    4802           0 :     class  ctors : public CppUnit::TestFixture
    4803             :     {
    4804             :         ::osl::FileBase::RC     nError1;
    4805             : 
    4806             :         public:
    4807           0 :         ctors() :nError1(FileBase::E_None) {}
    4808             :         // initialization
    4809           0 :         void setUp()
    4810             :         {
    4811             :             // create a tempfile in $TEMP/tmpname.
    4812           0 :             createTestFile( aTmpName6 );
    4813           0 :         }
    4814             : 
    4815           0 :         void tearDown()
    4816             :         {
    4817             :             // remove the tempfile in $TEMP/tmpname.
    4818           0 :             deleteTestFile( aTmpName6 );
    4819           0 :         }
    4820             : 
    4821             :         // test code.
    4822           0 :         void ctors_001()
    4823             :         {
    4824           0 :             ::osl::File testFile( aTmpName6 );
    4825           0 :             ::osl::DirectoryItem    rItem;  //constructor
    4826             : 
    4827             :              //get the DirectoryItem.
    4828           0 :             nError1 = ::osl::DirectoryItem::get( aTmpName6, rItem );
    4829           0 :             CPPUNIT_ASSERT( FileBase::E_None == nError1 );
    4830             : 
    4831           0 :             CPPUNIT_ASSERT_MESSAGE( "test for ctors function: initialize a new instance of DirectoryItem and get an item to check.",
    4832           0 :                                       ::osl::FileBase::E_None == nError1  );
    4833           0 :         }
    4834             : 
    4835           0 :         CPPUNIT_TEST_SUITE( ctors );
    4836           0 :         CPPUNIT_TEST( ctors_001 );
    4837           0 :         CPPUNIT_TEST_SUITE_END();
    4838             :     };// class ctors
    4839             : 
    4840             :     //---------------------------------------------------------------------
    4841             :     //  testing the method
    4842             :     //  DirectoryItem( const DirectoryItem& rItem ): _pData( rItem._pData)
    4843             :     //---------------------------------------------------------------------
    4844           0 :     class  copy_assin_Ctors : public CppUnit::TestFixture
    4845             :     {
    4846             :         ::osl::FileBase::RC     nError1;
    4847             : 
    4848             :         public:
    4849           0 :         copy_assin_Ctors() :nError1(FileBase::E_None) {}
    4850             :         // initialization
    4851           0 :         void setUp()
    4852             :         {
    4853             :             // create a tempfile in $TEMP/tmpname.
    4854           0 :             createTestFile( aTmpName6 );
    4855           0 :         }
    4856             : 
    4857           0 :         void tearDown()
    4858             :         {
    4859             :             // remove the tempfile in $TEMP/tmpname.
    4860           0 :             deleteTestFile( aTmpName6 );
    4861           0 :         }
    4862             : 
    4863             :         // test code.
    4864           0 :         void copy_assin_Ctors_001()
    4865             :         {
    4866           0 :             ::osl::DirectoryItem    rItem;  //constructor
    4867             :              //get the DirectoryItem.
    4868           0 :             nError1 = ::osl::DirectoryItem::get( aTmpName6, rItem );
    4869           0 :             CPPUNIT_ASSERT( FileBase::E_None == nError1 );
    4870             : 
    4871           0 :             ::osl::DirectoryItem    copyItem( rItem ); //copy constructor
    4872           0 :               ::osl::FileStatus   rFileStatus( osl_FileStatus_Mask_FileName );
    4873           0 :             nError1 = copyItem.getFileStatus( rFileStatus );
    4874           0 :             CPPUNIT_ASSERT( nError1 == FileBase::E_None );
    4875             : 
    4876           0 :             CPPUNIT_ASSERT_MESSAGE( "test for copy_assin_Ctors function: use copy constructor to get an item and check filename.",
    4877           0 :                                     ( sal_True == compareFileName( rFileStatus.getFileName(), aTmpName2 ) ) );
    4878           0 :         }
    4879             : 
    4880           0 :         void copy_assin_Ctors_002()
    4881             :         {
    4882           0 :             ::osl::DirectoryItem    rItem;  //constructor
    4883             :              //get the DirectoryItem.
    4884           0 :             nError1 = ::osl::DirectoryItem::get( aTmpName6, rItem );
    4885           0 :             CPPUNIT_ASSERT( FileBase::E_None == nError1 );
    4886             : 
    4887           0 :             ::osl::DirectoryItem    copyItem;
    4888           0 :             copyItem = rItem;               //assinment operator
    4889           0 :               ::osl::FileStatus   rFileStatus( osl_FileStatus_Mask_FileName );
    4890           0 :             nError1 = copyItem.getFileStatus( rFileStatus );
    4891           0 :             CPPUNIT_ASSERT( nError1 == FileBase::E_None );
    4892             : 
    4893           0 :             CPPUNIT_ASSERT_MESSAGE( "test for copy_assin_Ctors function: test assinment operator here since it is same as copy constructor in test way.",
    4894           0 :                                     ( sal_True == compareFileName( rFileStatus.getFileName(), aTmpName2 ) ) );
    4895           0 :         }
    4896             : 
    4897           0 :         CPPUNIT_TEST_SUITE( copy_assin_Ctors );
    4898           0 :         CPPUNIT_TEST( copy_assin_Ctors_001 );
    4899           0 :         CPPUNIT_TEST( copy_assin_Ctors_002 );
    4900           0 :         CPPUNIT_TEST_SUITE_END();
    4901             :     };// class copy_assin_Ctors
    4902             : 
    4903             :     //---------------------------------------------------------------------
    4904             :     //  testing the method
    4905             :     //  inline sal_Bool is()
    4906             :     //---------------------------------------------------------------------
    4907           0 :     class  is : public CppUnit::TestFixture
    4908             :     {
    4909             :         ::osl::FileBase::RC     nError1;
    4910             : 
    4911             :         public:
    4912           0 :         is() :nError1(FileBase::E_None) {}
    4913             :         // initialization
    4914           0 :         void setUp()
    4915             :         {
    4916             :             // create a tempfile in $TEMP/tmpname.
    4917           0 :             createTestFile( aTmpName6 );
    4918           0 :         }
    4919             : 
    4920           0 :         void tearDown()
    4921             :         {
    4922             :             // remove the tempfile in $TEMP/tmpname.
    4923           0 :             deleteTestFile( aTmpName6 );
    4924           0 :         }
    4925             : 
    4926             :         // test code.
    4927           0 :         void is_001()
    4928             :         {
    4929           0 :             ::osl::DirectoryItem    rItem;  //constructor
    4930             : 
    4931           0 :             CPPUNIT_ASSERT_MESSAGE( "test for is function: use an uninitialized instance.",
    4932           0 :                                     !rItem.is() );
    4933           0 :         }
    4934             : 
    4935           0 :         void is_002()
    4936             :         {
    4937           0 :             ::osl::DirectoryItem    rItem;  //constructor
    4938             :              //get the DirectoryItem.
    4939           0 :             nError1 = ::osl::DirectoryItem::get( aTmpName6, rItem );
    4940           0 :             CPPUNIT_ASSERT( FileBase::E_None == nError1 );
    4941             : 
    4942           0 :             CPPUNIT_ASSERT_MESSAGE( "test for is function: use an uninitialized instance.",
    4943           0 :                                     ( sal_True == rItem.is() ) );
    4944           0 :         }
    4945             : 
    4946           0 :         CPPUNIT_TEST_SUITE( is );
    4947           0 :         CPPUNIT_TEST( is_001 );
    4948           0 :         CPPUNIT_TEST( is_002 );
    4949           0 :         CPPUNIT_TEST_SUITE_END();
    4950             :     };// class is
    4951             : 
    4952             :     //---------------------------------------------------------------------
    4953             :     //  testing the method
    4954             :     //  static inline RC get( const ::rtl::OUString& ustrFileURL, DirectoryItem& rItem )
    4955             :     //---------------------------------------------------------------------
    4956           0 :     class  get : public CppUnit::TestFixture
    4957             :     {
    4958             :         ::osl::FileBase::RC     nError1, nError2;
    4959             : 
    4960             :         public:
    4961           0 :         get() :nError1(FileBase::E_None),nError2(FileBase::E_None) {}
    4962             :         // initialization
    4963           0 :         void setUp()
    4964             :         {
    4965             :             // create a tempfile in $TEMP/tmpname.
    4966           0 :             createTestFile( aTmpName6 );
    4967           0 :         }
    4968             : 
    4969           0 :         void tearDown()
    4970             :         {
    4971             :             // remove the tempfile in $TEMP/tmpname.
    4972           0 :             deleteTestFile( aTmpName6 );
    4973           0 :         }
    4974             : 
    4975             :         // test code.
    4976           0 :         void get_001()
    4977             :         {
    4978           0 :             ::osl::DirectoryItem    rItem;  //constructor
    4979             :              //get the DirectoryItem.
    4980           0 :             nError2 = ::osl::DirectoryItem::get( aTmpName6, rItem );
    4981             : 
    4982             :             //check the file name
    4983           0 :               ::osl::FileStatus   rFileStatus( osl_FileStatus_Mask_FileName );
    4984           0 :             nError1 = rItem.getFileStatus( rFileStatus );
    4985           0 :             CPPUNIT_ASSERT( nError1 == FileBase::E_None );
    4986             : 
    4987           0 :             CPPUNIT_ASSERT_MESSAGE( "test for get function: use copy constructor to get an item and check filename.",
    4988             :                                     ( ::osl::FileBase::E_None == nError2 ) &&
    4989           0 :                                     ( sal_True == compareFileName( rFileStatus.getFileName(), aTmpName2 ) ) );
    4990           0 :         }
    4991             : 
    4992           0 :         void get_002()
    4993             :         {
    4994           0 :             ::osl::DirectoryItem    rItem;
    4995             :              //get the DirectoryItem.
    4996           0 :             nError1 = ::osl::DirectoryItem::get( aSysPath1, rItem );
    4997             : 
    4998           0 :             CPPUNIT_ASSERT_MESSAGE( "test for get function: use a system name instead of a URL.",
    4999           0 :                                     FileBase::E_INVAL == nError1 );
    5000           0 :         }
    5001             : 
    5002           0 :         void get_003()
    5003             :         {
    5004           0 :             ::osl::DirectoryItem    rItem;
    5005             :              //get the DirectoryItem.
    5006           0 :             nError1 = ::osl::DirectoryItem::get( aTmpName3, rItem );
    5007             : 
    5008           0 :             CPPUNIT_ASSERT_MESSAGE( "test for get function: use a non existed file URL.",
    5009           0 :                                     FileBase::E_NOENT == nError1 );
    5010           0 :         }
    5011             : 
    5012           0 :         CPPUNIT_TEST_SUITE( get );
    5013           0 :         CPPUNIT_TEST( get_001 );
    5014           0 :         CPPUNIT_TEST( get_002 );
    5015           0 :         CPPUNIT_TEST( get_003 );
    5016           0 :         CPPUNIT_TEST_SUITE_END();
    5017             :     };// class get
    5018             : 
    5019             :     //---------------------------------------------------------------------
    5020             :     //  testing the method
    5021             :     //  inline RC getFileStatus( FileStatus& rStatus )
    5022             :     //---------------------------------------------------------------------
    5023           0 :     class  getFileStatus : public CppUnit::TestFixture
    5024             :     {
    5025             :         ::osl::FileBase::RC     nError1, nError2;
    5026             : 
    5027             :         public:
    5028           0 :         getFileStatus() :nError1(FileBase::E_None),nError2(FileBase::E_None) {}
    5029             :         // initialization
    5030           0 :         void setUp()
    5031             :         {
    5032             :             // create a tempfile in $TEMP/tmpdir/tmpname.
    5033           0 :             createTestDirectory( aTmpName3 );
    5034           0 :             createTestFile( aTmpName4 );
    5035           0 :         }
    5036             : 
    5037           0 :         void tearDown()
    5038             :         {
    5039             :             // remove the tempfile in $TEMP/tmpdir/tmpname.
    5040           0 :             deleteTestFile( aTmpName4 );
    5041           0 :             deleteTestDirectory( aTmpName3 );
    5042           0 :         }
    5043             : 
    5044             :         // test code.
    5045           0 :         void getFileStatus_001()
    5046             :         {
    5047           0 :             ::osl::DirectoryItem    rItem;  //constructor
    5048             :              //get the DirectoryItem.
    5049           0 :             nError1 = ::osl::DirectoryItem::get( aTmpName4, rItem );
    5050           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    5051             : 
    5052             :             //check the file name
    5053           0 :               ::osl::FileStatus   rFileStatus( osl_FileStatus_Mask_FileName );
    5054           0 :             nError2 = rItem.getFileStatus( rFileStatus );
    5055             : 
    5056           0 :             CPPUNIT_ASSERT_MESSAGE( "test for getFileStatus function: get file status and check filename",
    5057             :                                     ( ::osl::FileBase::E_None == nError2 ) &&
    5058           0 :                                     ( sal_True == compareFileName( rFileStatus.getFileName(), aTmpName2 ) ) );
    5059           0 :         }
    5060             : 
    5061           0 :         void getFileStatus_002()
    5062             :         {
    5063           0 :             ::osl::DirectoryItem    rItem;  //constructor
    5064             :              //get the DirectoryItem.
    5065           0 :             nError1 = ::osl::DirectoryItem::get( aTmpName6, rItem );
    5066             : 
    5067             :             //check the file name
    5068           0 :               ::osl::FileStatus   rFileStatus( osl_FileStatus_Mask_FileName );
    5069           0 :             nError2 = rItem.getFileStatus( rFileStatus );
    5070             : 
    5071           0 :             CPPUNIT_ASSERT_MESSAGE( "test for getFileStatus function: file not existed",
    5072           0 :                                     ( ::osl::FileBase::E_INVAL == nError2 )  );
    5073           0 :         }
    5074             : 
    5075           0 :         void getFileStatus_003()
    5076             :         {
    5077           0 :             ::osl::DirectoryItem    rItem;  //constructor
    5078             :              //get the DirectoryItem.
    5079           0 :             nError1 = ::osl::DirectoryItem::get( aTmpName3, rItem );
    5080           0 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    5081             : 
    5082             :             //check the file name
    5083           0 :               ::osl::FileStatus   rFileStatus( osl_FileStatus_Mask_FileName );
    5084           0 :             nError2 = rItem.getFileStatus( rFileStatus );
    5085             : 
    5086           0 :             CPPUNIT_ASSERT_MESSAGE( "test for getFileStatus function: get directory information",
    5087             :                                     ( ::osl::FileBase::E_None == nError2 ) &&
    5088           0 :                                     ( sal_True == compareFileName( rFileStatus.getFileName(), aTmpName1 ) ) );
    5089           0 :         }
    5090             : 
    5091             : 
    5092           0 :         CPPUNIT_TEST_SUITE( getFileStatus );
    5093           0 :         CPPUNIT_TEST( getFileStatus_001 );
    5094           0 :         CPPUNIT_TEST( getFileStatus_002 );
    5095           0 :         CPPUNIT_TEST( getFileStatus_003 );
    5096           0 :         CPPUNIT_TEST_SUITE_END();
    5097             :     };// class getFileStatus
    5098             : 
    5099             : 
    5100             : 
    5101           1 :      CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_DirectoryItem::ctors, "osl_DirectoryItem" );
    5102           1 :     CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_DirectoryItem::copy_assin_Ctors, "osl_DirectoryItem" );
    5103           1 :     CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_DirectoryItem::is, "osl_DirectoryItem" );
    5104           1 :     CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_DirectoryItem::get, "osl_DirectoryItem" );
    5105           1 :     CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_DirectoryItem::getFileStatus, "osl_DirectoryItem" );
    5106             : }// namespace osl_DirectoryItem
    5107             : 
    5108             : //------------------------------------------------------------------------
    5109             : // Beginning of the test cases for Directory class
    5110             : //------------------------------------------------------------------------
    5111             : namespace osl_Directory
    5112             : {
    5113             :     //---------------------------------------------------------------------
    5114             :     //  testing the method
    5115             :     //  Directory( const ::rtl::OUString& strPath ): _pData( 0 ), _aPath( strPath )
    5116             :     //---------------------------------------------------------------------
    5117           4 :     class  ctors : public CppUnit::TestFixture
    5118             :     {
    5119             :         ::osl::FileBase::RC     nError1, nError2;
    5120             : 
    5121             :         public:
    5122           2 :         ctors() :nError1(FileBase::E_None),nError2(FileBase::E_None) {}
    5123             :         // initialization
    5124           2 :         void setUp()
    5125             :         {
    5126             :             // create a tempfile in $TEMP/tmpdir/tmpname.
    5127           2 :             createTestDirectory( aTmpName3 );
    5128           2 :             createTestFile( aTmpName4 );
    5129           2 :         }
    5130             : 
    5131           2 :         void tearDown()
    5132             :         {
    5133             :             // remove the tempfile in $TEMP/tmpdir/tmpname.
    5134           2 :             deleteTestFile( aTmpName4 );
    5135           2 :             deleteTestDirectory( aTmpName3 );
    5136             :             // LLA: t_print("tearDown done.\n");
    5137           2 :         }
    5138             : 
    5139             :         // test code.
    5140           1 :         void ctors_001()
    5141             :         {
    5142           1 :             ::osl::Directory testDirectory( aTmpName3 ); //constructor
    5143             : 
    5144             :             //open a directory
    5145           1 :             nError1 = testDirectory.open();
    5146           1 :              CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    5147             :             //close a directory
    5148           1 :             nError2 = testDirectory.close();
    5149           1 :              CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError2 );
    5150             : 
    5151           2 :             CPPUNIT_ASSERT_MESSAGE( "test for ctors function: create an instance and check open and close",
    5152             :                                      ( ::osl::FileBase::E_None == nError1 ) &&
    5153           2 :                                     ( ::osl::FileBase::E_None == nError2 ) );
    5154           1 :         }
    5155             : 
    5156           1 :         void ctors_002()
    5157             :         {
    5158           1 :             ::osl::Directory testDirectory( aTmpName9 ); //constructor
    5159             : 
    5160             :             //open a directory
    5161           1 :             nError1 = testDirectory.open();
    5162           1 :              CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    5163             :             //close a directory
    5164           1 :             nError2 = testDirectory.close();
    5165           1 :              CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError2 );
    5166             : 
    5167           2 :             CPPUNIT_ASSERT_MESSAGE( "test for ctors function: relative URL, :-), it is also worked",
    5168             :                                      ( ::osl::FileBase::E_None == nError1 ) &&
    5169           2 :                                     ( ::osl::FileBase::E_None == nError2 ) );
    5170           1 :         }
    5171             : 
    5172           2 :         CPPUNIT_TEST_SUITE( ctors );
    5173           1 :         CPPUNIT_TEST( ctors_001 );
    5174           1 :         CPPUNIT_TEST( ctors_002 );
    5175           2 :         CPPUNIT_TEST_SUITE_END();
    5176             :     };// class ctors
    5177             : 
    5178             :     //---------------------------------------------------------------------
    5179             :     //  testing the method
    5180             :     //  inline RC open()
    5181             :     //---------------------------------------------------------------------
    5182           8 :     class  open : public CppUnit::TestFixture
    5183             :     {
    5184             :         ::osl::FileBase::RC     nError1, nError2;
    5185             : 
    5186             :         public:
    5187           4 :         open() :nError1(FileBase::E_None),nError2(FileBase::E_None) {}
    5188             :         // initialization
    5189           4 :         void setUp()
    5190             :         {
    5191             :             // create a tempfile in $TEMP/tmpdir/tmpname.
    5192           4 :             createTestDirectory( aTmpName3 );
    5193           4 :             createTestFile( aTmpName4 );
    5194           4 :         }
    5195             : 
    5196           4 :         void tearDown()
    5197             :         {
    5198             :             // remove the tempfile in $TEMP/tmpdir/tmpname.
    5199           4 :             deleteTestFile( aTmpName4 );
    5200           4 :             deleteTestDirectory( aTmpName3 );
    5201           4 :         }
    5202             : 
    5203             :         // test code.
    5204           1 :         void open_001()
    5205             :         {
    5206           1 :             ::osl::Directory testDirectory( aTmpName3 ); //constructor
    5207             : 
    5208             :             //open a directory
    5209           1 :             nError1 = testDirectory.open();
    5210             :             //check if directory is opened.
    5211           1 :             sal_Bool bOk = testDirectory.isOpen();
    5212             :             //close a directory
    5213           1 :             nError2 = testDirectory.close();
    5214             : 
    5215           2 :             CPPUNIT_ASSERT_MESSAGE( "test for open function: open a directory and check for open",
    5216             :                                     ( sal_True == bOk ) &&
    5217             :                                      ( ::osl::FileBase::E_None == nError1 ) &&
    5218           2 :                                     ( ::osl::FileBase::E_None == nError2 ) );
    5219           1 :         }
    5220             : 
    5221           1 :         void open_002()
    5222             :         {
    5223           1 :             ::osl::Directory testDirectory( aTmpName6 ); //constructor
    5224             : 
    5225             :             //open a directory
    5226           1 :             nError1 = testDirectory.open();
    5227           1 :              if ( ::osl::FileBase::E_None == nError1 )
    5228             :             {
    5229           0 :                 nError2 = testDirectory.close();
    5230           0 :                 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError2 );
    5231             :             }
    5232             : 
    5233           2 :             CPPUNIT_ASSERT_MESSAGE( "test for open function: open a file that is not existed",
    5234           2 :                                      ( ::osl::FileBase::E_NOENT == nError1 ) );
    5235           1 :         }
    5236             : 
    5237           1 :         void open_003()
    5238             :         {
    5239           1 :             ::osl::Directory testDirectory( aUserDirectorySys ); //constructor
    5240             : 
    5241             :             //open a directory
    5242           1 :             nError1 = testDirectory.open();
    5243           1 :              if ( ::osl::FileBase::E_None == nError1 )
    5244             :             {
    5245           0 :                 nError2 = testDirectory.close();
    5246           0 :                 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError2 );
    5247             :             }
    5248             : 
    5249           2 :             CPPUNIT_ASSERT_MESSAGE( "test for open function: using system path",
    5250           2 :                                      ( ::osl::FileBase::E_INVAL == nError1 ) );
    5251           1 :         }
    5252             : 
    5253           1 :         void open_004()
    5254             :         {
    5255           1 :             ::osl::Directory testDirectory( aTmpName4 ); //constructor
    5256             : 
    5257             :             //open a directory
    5258           1 :             nError1 = testDirectory.open();
    5259           1 :              if ( ::osl::FileBase::E_None == nError1 )
    5260             :             {
    5261           0 :                 nError2 = testDirectory.close();
    5262           0 :                 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError2 );
    5263             :             }
    5264             : 
    5265           2 :             CPPUNIT_ASSERT_MESSAGE( "test for open function: open a file instead of a directory",
    5266           2 :                                      ( ::osl::FileBase::E_NOTDIR == nError1 ) || ( ::osl::FileBase::E_ACCES ) );
    5267           1 :         }
    5268             : 
    5269           2 :         CPPUNIT_TEST_SUITE( open );
    5270           1 :         CPPUNIT_TEST( open_001 );
    5271           1 :         CPPUNIT_TEST( open_002 );
    5272           1 :         CPPUNIT_TEST( open_003 );
    5273           1 :         CPPUNIT_TEST( open_004 );
    5274           2 :         CPPUNIT_TEST_SUITE_END();
    5275             :     };// class open
    5276             : 
    5277             :     //---------------------------------------------------------------------
    5278             :     //  testing the method
    5279             :     //  inline sal_Bool isOpen() { return _pData != NULL; };
    5280             :     //---------------------------------------------------------------------
    5281           4 :     class  isOpen : public CppUnit::TestFixture
    5282             :     {
    5283             :         ::osl::FileBase::RC     nError1, nError2;
    5284             : 
    5285             :         public:
    5286           2 :         isOpen() :nError1(FileBase::E_None),nError2(FileBase::E_None) {}
    5287             :         // initialization
    5288           2 :         void setUp()
    5289             :         {
    5290             :             // create a tempfile in $TEMP/tmpdir/tmpname.
    5291           2 :             createTestDirectory( aTmpName3 );
    5292           2 :             createTestFile( aTmpName4 );
    5293           2 :         }
    5294             : 
    5295           2 :         void tearDown()
    5296             :         {
    5297             :             // remove the tempfile in $TEMP/tmpdir/tmpname.
    5298           2 :             deleteTestFile( aTmpName4 );
    5299           2 :             deleteTestDirectory( aTmpName3 );
    5300           2 :         }
    5301             : 
    5302             :         // test code.
    5303           1 :         void isOpen_001()
    5304             :         {
    5305           1 :             ::osl::Directory testDirectory( aTmpName3 ); //constructor
    5306             : 
    5307             :             //open a directory
    5308           1 :             nError1 = testDirectory.open();
    5309             :             //check if directory is opened.
    5310           1 :             sal_Bool bOk = testDirectory.isOpen();
    5311             :             //close a directory
    5312           1 :             nError2 = testDirectory.close();
    5313             : 
    5314           2 :             CPPUNIT_ASSERT_MESSAGE( "test for isOpen function: open a directory and check for open",
    5315           2 :                                     ( sal_True == bOk ) );
    5316           1 :         }
    5317             : 
    5318           1 :         void isOpen_002()
    5319             :         {
    5320           1 :             ::osl::Directory testDirectory( aTmpName3 ); //constructor
    5321             : 
    5322             :             //check if directory is opened.
    5323           1 :             sal_Bool bOk = testDirectory.isOpen();
    5324             : 
    5325           2 :             CPPUNIT_ASSERT_MESSAGE( "test for isOpen function: do not open a directory and check for open",
    5326           2 :                                     !( sal_True == bOk ) );
    5327           1 :         }
    5328             : 
    5329           2 :         CPPUNIT_TEST_SUITE( isOpen );
    5330           1 :         CPPUNIT_TEST( isOpen_001 );
    5331           1 :         CPPUNIT_TEST( isOpen_002 );
    5332           2 :         CPPUNIT_TEST_SUITE_END();
    5333             :     };// class isOpen
    5334             : 
    5335             :     //---------------------------------------------------------------------
    5336             :     //  testing the method
    5337             :     //  inline RC close()
    5338             :     //---------------------------------------------------------------------
    5339           4 :     class  close : public CppUnit::TestFixture
    5340             :     {
    5341             :         ::osl::FileBase::RC     nError1, nError2;
    5342             : 
    5343             :         public:
    5344           2 :         close() :nError1(FileBase::E_None),nError2(FileBase::E_None) {}
    5345             :         // initialization
    5346           2 :         void setUp()
    5347             :         {
    5348             :             // create a tempdirectory : $TEMP/tmpdir.
    5349           2 :             createTestDirectory( aTmpName3 );
    5350           2 :         }
    5351             : 
    5352           2 :         void tearDown()
    5353             :         {
    5354             :             // remove a tempdirectory : $TEMP/tmpdir.
    5355           2 :             deleteTestDirectory( aTmpName3 );
    5356           2 :         }
    5357             : 
    5358             :         // test code.
    5359           1 :         void close_001()
    5360             :         {
    5361           1 :             ::osl::Directory testDirectory( aTmpName3 ); //constructor
    5362             : 
    5363             :             //open a directory
    5364           1 :             nError1 = testDirectory.open();
    5365             :             //close a directory
    5366           1 :             nError2 = testDirectory.close();
    5367             :             //check if directory is opened.
    5368           1 :             sal_Bool bOk = testDirectory.isOpen();
    5369             : 
    5370           2 :             CPPUNIT_ASSERT_MESSAGE( "test for isOpen function: close a directory and check for open",
    5371           2 :                                     !( sal_True == bOk ) );
    5372           1 :         }
    5373             : 
    5374           1 :         void close_002()
    5375             :         {
    5376           1 :             ::osl::Directory testDirectory( aTmpName3 ); //constructor
    5377             : 
    5378             :             //close a directory
    5379           1 :             nError1 = testDirectory.close();
    5380             : 
    5381           2 :             CPPUNIT_ASSERT_MESSAGE( "test for isOpen function: close a not opened directory",
    5382           2 :                                     ( ::osl::FileBase::E_BADF == nError1 ) );
    5383           1 :         }
    5384             : 
    5385             : 
    5386           2 :         CPPUNIT_TEST_SUITE( close );
    5387           1 :         CPPUNIT_TEST( close_001 );
    5388           1 :         CPPUNIT_TEST( close_002 );
    5389           2 :         CPPUNIT_TEST_SUITE_END();
    5390             :     };// class close
    5391             : 
    5392             :     //---------------------------------------------------------------------
    5393             :     //  testing the method
    5394             :     //  inline RC reset()
    5395             :     //---------------------------------------------------------------------
    5396           8 :     class  reset : public CppUnit::TestFixture
    5397             :     {
    5398             :         ::osl::FileBase::RC     nError1, nError2;
    5399             :         ::osl::DirectoryItem    rItem;
    5400             : 
    5401             :         public:
    5402           4 :         reset() :nError1(FileBase::E_None),nError2(FileBase::E_None) {}
    5403             :         // initialization
    5404           4 :         void setUp()
    5405             :         {
    5406             :             // create a tempdirectory : $TEMP/tmpdir.
    5407           4 :             createTestDirectory( aTmpName3 );
    5408             :             // create three files : $TEMP/tmpdir/tmpname, $TEMP/tmpdir/tmpdir, $TEMP/tmpdir/hiddenfile,
    5409           4 :             createTestFile( aTmpName3, aTmpName2);
    5410           4 :             createTestFile( aTmpName3, aTmpName1);
    5411           4 :             createTestFile( aTmpName3, aHidURL1);
    5412           4 :         }
    5413             : 
    5414           4 :         void tearDown()
    5415             :         {
    5416             :             // remove three files : $TEMP/tmpdir/tmpname, $TEMP/tmpdir/tmpdir, $TEMP/tmpdir/hiddenfile,
    5417           4 :             deleteTestFile( aTmpName3, aHidURL1);
    5418           4 :             deleteTestFile( aTmpName3, aTmpName1);
    5419           4 :             deleteTestFile( aTmpName3, aTmpName2);
    5420             :             // remove a tempdirectory : $TEMP/tmpdir.
    5421           4 :             deleteTestDirectory( aTmpName3 );
    5422           4 :         }
    5423             : 
    5424             :         // test code.
    5425           1 :         void reset_001()
    5426             :         {
    5427           1 :             ::osl::Directory testDirectory( aTmpName3 ); //constructor
    5428             : 
    5429             :             //open a directory
    5430           1 :             nError1 = testDirectory.open();
    5431           1 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    5432             :             //get first Item
    5433           1 :             nError1 = testDirectory.getNextItem( rItem, 1 );
    5434           1 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    5435             :             //check the file name of first Item
    5436           2 :               ::osl::FileStatus   rFileStatusFirst( osl_FileStatus_Mask_FileName );
    5437           1 :             nError1 = rItem.getFileStatus( rFileStatusFirst );
    5438             : 
    5439             :             //get second Item
    5440             :             //mindy: nError1 = testDirectory.getNextItem( rItem, 0 );
    5441             :             //mindy: CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    5442             : 
    5443             :             //reset enumeration
    5444           1 :             nError2 = testDirectory.reset();
    5445           1 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError2 );
    5446             :             //get reseted Item, if reset does not work, getNextItem() should return the second Item (aTmpName1)
    5447           1 :             nError1 = testDirectory.getNextItem( rItem, 0 );
    5448           1 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    5449             : 
    5450             :             //check the file name again
    5451           2 :               ::osl::FileStatus   rFileStatus( osl_FileStatus_Mask_FileName );
    5452           1 :             nError1 = rItem.getFileStatus( rFileStatus );
    5453             :             //close a directory
    5454           1 :             nError1 = testDirectory.close();
    5455           1 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    5456             : 
    5457             :             sal_Bool bOK1,bOK2,bOK3;
    5458           1 :             bOK1 = compareFileName( rFileStatus.getFileName(), aTmpName2 );
    5459           1 :             bOK2 = compareFileName( rFileStatus.getFileName(), aHidURL1 );
    5460           1 :             bOK3 = compareFileName( rFileStatus.getFileName(), rFileStatusFirst.getFileName() );
    5461           2 :             CPPUNIT_ASSERT_MESSAGE( "test for reset function: get two directory item, reset it, then get again, check the filename",
    5462             :                                     ( ::osl::FileBase::E_None == nError2 ) &&
    5463           2 :                                     ( sal_True == bOK1 || bOK2 || bOK3 ) );
    5464           1 :         }
    5465             : 
    5466           1 :         void reset_002()
    5467             :         {
    5468           1 :             ::osl::Directory testDirectory( aTmpName6 ); //constructor
    5469             : 
    5470             :             //close a directory
    5471           1 :             nError1 = testDirectory.reset();
    5472             : 
    5473           2 :             CPPUNIT_ASSERT_MESSAGE( "test for reset function: reset a non existed directory",
    5474           2 :                                     ( ::osl::FileBase::E_NOENT == nError1 ) );
    5475           1 :         }
    5476             : 
    5477             : 
    5478           1 :         void reset_003()
    5479             :         {
    5480           1 :             ::osl::Directory testDirectory( aTmpName4 ); //constructor
    5481             : 
    5482             :             //close a directory
    5483           1 :             nError1 = testDirectory.reset();
    5484             : 
    5485           2 :             CPPUNIT_ASSERT_MESSAGE( "test for reset function: reset a file instead of a directory",
    5486           2 :                                     ( ::osl::FileBase::E_NOTDIR == nError1 ) || ( ::osl::FileBase::E_NOENT == nError1 ) );
    5487           1 :         }
    5488             : 
    5489           1 :         void reset_004()
    5490             :         {
    5491           1 :             ::osl::Directory testDirectory( aUserDirectorySys ); //constructor
    5492             : 
    5493             :             //close a directory
    5494           1 :             nError1 = testDirectory.reset();
    5495             : 
    5496           2 :             CPPUNIT_ASSERT_MESSAGE( "test for reset function: use a system path",
    5497           2 :                                     ( ::osl::FileBase::E_INVAL == nError1 ) );
    5498           1 :         }
    5499             : 
    5500           2 :         CPPUNIT_TEST_SUITE( reset );
    5501           1 :         CPPUNIT_TEST( reset_001 );
    5502           1 :         CPPUNIT_TEST( reset_002 );
    5503           1 :         CPPUNIT_TEST( reset_003 );
    5504           1 :         CPPUNIT_TEST( reset_004 );
    5505           2 :         CPPUNIT_TEST_SUITE_END();
    5506             :     };// class reset
    5507             : 
    5508             :     //---------------------------------------------------------------------
    5509             :     //  testing the method
    5510             :     //  inline RC getNextItem( DirectoryItem& rItem, sal_uInt32 nHint = 0 )
    5511             :     //---------------------------------------------------------------------
    5512           8 :     class  getNextItem : public CppUnit::TestFixture
    5513             :     {
    5514             :         ::osl::FileBase::RC     nError1, nError2;
    5515             :         ::osl::DirectoryItem    rItem;
    5516             : 
    5517             :         public:
    5518           4 :         getNextItem() :nError1(FileBase::E_None),nError2(FileBase::E_None) {}
    5519             :         // initialization
    5520           4 :         void setUp()
    5521             :         {
    5522             :             // create a tempdirectory : $TEMP/tmpdir.
    5523           4 :             createTestDirectory( aTmpName3 );
    5524             :             // create three files : $TEMP/tmpdir/tmpname, $TEMP/tmpdir/tmpdir, $TEMP/tmpdir/hiddenfile,
    5525           4 :             createTestFile( aTmpName3, aTmpName2 );
    5526           4 :             createTestFile( aTmpName3, aTmpName1 );
    5527           4 :             createTestFile( aTmpName3, aHidURL1 );
    5528             : 
    5529           4 :         }
    5530             : 
    5531           4 :         void tearDown()
    5532             :         {
    5533             :             // remove three files : $TEMP/tmpdir/tmpname, $TEMP/tmpdir/tmpdir, $TEMP/tmpdir/hiddenfile,
    5534           4 :             deleteTestFile( aTmpName3, aHidURL1 );
    5535           4 :             deleteTestFile( aTmpName3, aTmpName1 );
    5536           4 :             deleteTestFile( aTmpName3, aTmpName2 );
    5537             :             // remove a tempdirectory : $TEMP/tmpdir.
    5538           4 :             deleteTestDirectory( aTmpName3 );
    5539           4 :         }
    5540             : 
    5541             :         // test code.
    5542           1 :         void getNextItem_001()
    5543             :         {
    5544           1 :              ::osl::Directory testDirectory( aTmpName3 ); //constructor
    5545             : 
    5546             :             //open a directory
    5547           1 :             nError1 = testDirectory.open();
    5548           1 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    5549             : 
    5550             :             //check the file name
    5551           1 :             sal_Bool            bOk1 = sal_False;
    5552           1 :             sal_Bool bOk2 = sal_False;
    5553           1 :             sal_Bool bOk3 = sal_False;
    5554           2 :               ::osl::FileStatus   rFileStatus( osl_FileStatus_Mask_FileName );
    5555           4 :             for ( int nCount = 0; nCount < 3; nCount++ )
    5556             :             {
    5557             :                 //get three Items
    5558           3 :                 nError1 = testDirectory.getNextItem( rItem, 2 );
    5559           3 :                 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    5560           3 :                 nError1 = rItem.getFileStatus( rFileStatus );
    5561           3 :                 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    5562             : 
    5563             :                 // a special order is not guaranteed. So any file may occur on any time.
    5564             :                 // But every file name should occur only once.
    5565           3 :                 if ( bOk1 == sal_False && compareFileName( rFileStatus.getFileName(), aTmpName1 ) )
    5566             :                 {
    5567           1 :                     bOk1 = sal_True;
    5568             :                 }
    5569             : 
    5570           3 :                 if ( bOk2 == sal_False && compareFileName( rFileStatus.getFileName(), aTmpName2 ) )
    5571             :                 {
    5572           1 :                     bOk2 = sal_True;
    5573             :                 }
    5574             : 
    5575           3 :                 if ( bOk3 == sal_False && compareFileName( rFileStatus.getFileName(), aHidURL1 ) )
    5576             :                 {
    5577           1 :                     bOk3 = sal_True;
    5578             :                 }
    5579             :            }
    5580             : 
    5581             :             //close a directory
    5582           1 :             nError1 = testDirectory.close();
    5583           1 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    5584             : 
    5585           2 :             CPPUNIT_ASSERT_MESSAGE( "test for getNextItem function: retrive three items and check their names.",
    5586           2 :                                     ( sal_True == bOk1 ) && ( sal_True == bOk2 ) && ( sal_True == bOk3 ) );
    5587           1 :         }
    5588             : 
    5589           1 :         void getNextItem_002()
    5590             :         {
    5591           1 :              ::osl::Directory testDirectory( aTmpName3 ); //constructor
    5592           1 :             nError1 = testDirectory.getNextItem( rItem );
    5593             : 
    5594           2 :             CPPUNIT_ASSERT_MESSAGE( "test for getNextItem function: retrive an item in a directory which is not opened, also test for nHint's default value.",
    5595           2 :                                     ( ::osl::FileBase::E_INVAL == nError1 ) );
    5596           1 :         }
    5597             : 
    5598           1 :         void getNextItem_003()
    5599             :         {
    5600           1 :              ::osl::Directory testDirectory( aTmpName3 ); //constructor
    5601             : 
    5602             :             //open a directory
    5603           1 :             nError1 = testDirectory.open();
    5604           1 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    5605             : 
    5606           5 :             for ( int nCount = 0; nCount < 4; nCount++ )
    5607             :             {
    5608           4 :                 nError2 = testDirectory.getNextItem( rItem, 3 );
    5609             :             }
    5610             : 
    5611             :             //close a directory
    5612           1 :             nError1 = testDirectory.close();
    5613           1 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    5614             : 
    5615           2 :             CPPUNIT_ASSERT_MESSAGE( "test for getNextItem function: retrive 4 times in a directory which contain only 3 files.",
    5616           2 :                                     ( ::osl::FileBase::E_NOENT == nError2 ) );
    5617           1 :         }
    5618             : 
    5619           1 :         void getNextItem_004()
    5620             :         {
    5621             :         //create a link file(can not on Windows), then check if getNextItem can get it.
    5622             : #ifdef UNX
    5623           1 :             sal_Bool bLnkOK = sal_False;
    5624           1 :             sal_Bool bFoundOK = sal_False;
    5625             : 
    5626           2 :             ::rtl::OUString aUStr_LnkFileSys( aTempDirectorySys ), aUStr_SrcFileSys( aTempDirectorySys );
    5627           1 :             ( aUStr_LnkFileSys += aSlashURL ) += ::rtl::OUString("/tmpdir/link.file");
    5628           1 :             ( aUStr_SrcFileSys += aSlashURL ) += ::rtl::OUString("/tmpdir/tmpname");
    5629             : 
    5630           2 :             ::rtl::OString strLinkFileName, strSrcFileName;
    5631           1 :             strLinkFileName = OUStringToOString( aUStr_LnkFileSys, RTL_TEXTENCODING_ASCII_US );
    5632           1 :             strSrcFileName  = OUStringToOString( aUStr_SrcFileSys, RTL_TEXTENCODING_ASCII_US );
    5633             : 
    5634             :             // create a link file and link it to file "/tmp/PID/tmpdir/tmpname"
    5635           1 :             sal_Int32 fd = symlink( strSrcFileName.getStr(), strLinkFileName.getStr() );
    5636           1 :             CPPUNIT_ASSERT( fd == 0 );
    5637           2 :             ::osl::Directory testDirectory( aTmpName3 );
    5638             : 
    5639             :             //open a directory
    5640           1 :             nError1 = testDirectory.open();
    5641           1 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    5642           2 :             ::rtl::OUString aFileName ("link.file");
    5643             : 
    5644             :             while (1) {
    5645           1 :                 nError1 = testDirectory.getNextItem( rItem, 4 );
    5646           1 :                 if (::osl::FileBase::E_None == nError1) {
    5647           1 :                     ::osl::FileStatus   rFileStatus( osl_FileStatus_Mask_FileName | osl_FileStatus_Mask_Type );
    5648           1 :                     rItem.getFileStatus( rFileStatus );
    5649           1 :                     if ( compareFileName( rFileStatus.getFileName(), aFileName) == sal_True )
    5650             :                     {
    5651           1 :                         bFoundOK = sal_True;
    5652           1 :                         if ( FileStatus::Link == rFileStatus.getFileType())
    5653             :                         {
    5654           1 :                             bLnkOK = sal_True;
    5655           1 :                             break;
    5656             :                         }
    5657           0 :                     }
    5658             :                 }
    5659             :                 else
    5660           0 :                     break;
    5661             :             };
    5662           1 :                 fd = std::remove( strLinkFileName.getStr() );
    5663           1 :             CPPUNIT_ASSERT_MESSAGE( "remove link file failed", fd == 0 );
    5664           2 :             CPPUNIT_ASSERT_MESSAGE( "test for getNextItem function: check if can retrieve the link file name",
    5665           1 :                                     ( bFoundOK == sal_True ) );
    5666           2 :             CPPUNIT_ASSERT_MESSAGE( "test for getNextItem function: check if link file has file type link",
    5667           2 :                                     ( bLnkOK == sal_True ) );
    5668             : #endif
    5669           1 :         }
    5670             : 
    5671           2 :         CPPUNIT_TEST_SUITE( getNextItem );
    5672           1 :         CPPUNIT_TEST( getNextItem_001 );
    5673           1 :         CPPUNIT_TEST( getNextItem_002 );
    5674           1 :         CPPUNIT_TEST( getNextItem_003 );
    5675           1 :         CPPUNIT_TEST( getNextItem_004 );
    5676           2 :         CPPUNIT_TEST_SUITE_END();
    5677             :     };// class getNextItem
    5678             : 
    5679             :     //---------------------------------------------------------------------
    5680             :     //  testing the method
    5681             :     //  inline static RC getVolumeInfo( const ::rtl::OUString& ustrDirectoryURL, VolumeInfo& rInfo )
    5682             :     //---------------------------------------------------------------------
    5683          20 :     class  getVolumeInfo : public CppUnit::TestFixture
    5684             :     {
    5685             :         ::osl::FileBase::RC     nError1;
    5686             : 
    5687             :         public:
    5688             : 
    5689          10 :         getVolumeInfo() :nError1(FileBase::E_None) {}
    5690             :         // test code.
    5691           6 :         void checkValidMask(osl::VolumeInfo const& _aVolumeInfo, sal_Int32 _nMask)
    5692             :             {
    5693           6 :                 if (_nMask == osl_VolumeInfo_Mask_FileSystemName)
    5694             :         {
    5695             :             //get file system name
    5696           0 :             ::rtl::OUString aFileSysName( aNullURL );
    5697           0 :                     aFileSysName = _aVolumeInfo.getFileSystemName();
    5698             : 
    5699           0 :                     sal_Bool bRes2 = compareFileName( aFileSysName, aNullURL );
    5700           0 :             CPPUNIT_ASSERT_MESSAGE( "test for getVolumeInfo function: getVolumeInfo of root directory.",
    5701             :                                     ( osl::FileBase::E_None == nError1 ) &&
    5702           0 :                                             ( sal_False == bRes2 ) );
    5703             :                 }
    5704           6 :                 if (_nMask == osl_VolumeInfo_Mask_Attributes)
    5705             :                 {
    5706           1 :                     sal_Bool b1 = _aVolumeInfo.getRemoteFlag();
    5707           1 :                     sal_Bool b2 = _aVolumeInfo.getRemoveableFlag();
    5708           1 :                     sal_Bool b3 = _aVolumeInfo.getCompactDiscFlag();
    5709           1 :                     sal_Bool b4 = _aVolumeInfo.getFloppyDiskFlag();
    5710           1 :                     sal_Bool b5 = _aVolumeInfo.getFixedDiskFlag();
    5711           1 :                     sal_Bool b6 = _aVolumeInfo.getRAMDiskFlag();
    5712             : 
    5713           1 :                     rtl::OString sAttr;
    5714           1 :                     if (b1) sAttr =  "Remote";
    5715           1 :                     if (b2) sAttr += " Removeable";
    5716           1 :                     if (b3) sAttr += " CDROM";
    5717           1 :                     if (b4) sAttr += " Floppy";
    5718           1 :                     if (b5) sAttr += " FixedDisk";
    5719           1 :                     if (b6) sAttr += " RAMDisk";
    5720             : 
    5721           1 :                     printf("Attributes: %s\n", sAttr.getStr() );
    5722             :                 }
    5723           6 :                 if (_nMask == osl_VolumeInfo_Mask_TotalSpace)
    5724             :                 {
    5725             :                     // within Linux, df / * 1024 bytes is the result
    5726           1 :                     sal_uInt64 nSize = _aVolumeInfo.getTotalSpace();
    5727           1 :                     printf("Total space: %" SAL_PRIuUINT64 "\n", nSize);
    5728             :                 }
    5729           6 :                 if (_nMask == osl_VolumeInfo_Mask_UsedSpace)
    5730             :                 {
    5731           1 :                     sal_uInt64 nSize = _aVolumeInfo.getUsedSpace();
    5732           1 :                     printf(" Used space: %" SAL_PRIuUINT64 "\n", nSize);
    5733             :                 }
    5734           6 :                 if (_nMask == osl_VolumeInfo_Mask_FreeSpace)
    5735             :                 {
    5736           1 :                     sal_uInt64 nSize = _aVolumeInfo.getFreeSpace();
    5737           1 :                     printf(" Free space: %" SAL_PRIuUINT64 "\n", nSize);
    5738             :                 }
    5739           6 :                 if (_nMask == osl_VolumeInfo_Mask_MaxNameLength)
    5740             :                 {
    5741           1 :                     sal_uInt32 nLength = _aVolumeInfo.getMaxNameLength();
    5742           1 :                     printf("max name length: %" SAL_PRIuUINT32 "\n", nLength);
    5743             :                 }
    5744           6 :                 if (_nMask == osl_VolumeInfo_Mask_MaxPathLength)
    5745             :                 {
    5746           1 :                     sal_uInt32 nLength = _aVolumeInfo.getMaxPathLength();
    5747           1 :                     printf("max path length: %" SAL_PRIuUINT32 "\n", nLength);
    5748             :                 }
    5749           6 :                 if (_nMask == osl_VolumeInfo_Mask_FileSystemCaseHandling)
    5750             :                 {
    5751           0 :                     bool bIsCase = _aVolumeInfo.isCaseSensitiveFileSystem();
    5752           0 :                     printf("filesystem case sensitive: %s\n", bIsCase ? "yes" : "no");
    5753             :                 }
    5754           6 :             }
    5755             : 
    5756           8 :         void checkVolumeInfo(sal_Int32 _nMask)
    5757             :             {
    5758           8 :                 ::osl::VolumeInfo aVolumeInfo( _nMask );
    5759             :                 //call getVolumeInfo here
    5760           8 :                 nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
    5761             :                 // LLA: IMHO it's not a bug, if VolumeInfo is not valid, it's a feature
    5762             :                 // LLA: CPPUNIT_ASSERT_MESSAGE("mask is not valid", sal_True == aVolumeInfo.isValid( _nMask ) );
    5763           8 :                 if (aVolumeInfo.isValid( _nMask))
    5764             :                 {
    5765           6 :                     checkValidMask(aVolumeInfo, _nMask);
    5766           8 :                 }
    5767           8 :             }
    5768             : 
    5769             : 
    5770           1 :         void getVolumeInfo_001_1()
    5771             :         {
    5772           1 :             sal_Int32 mask = osl_VolumeInfo_Mask_FileSystemName;
    5773           1 :             checkVolumeInfo(mask);
    5774           1 :         }
    5775           1 :         void getVolumeInfo_001_2()
    5776             :         {
    5777           1 :             sal_Int32 mask = osl_VolumeInfo_Mask_Attributes;
    5778           1 :             checkVolumeInfo(mask);
    5779           1 :         }
    5780           1 :         void getVolumeInfo_001_3()
    5781             :         {
    5782           1 :             sal_Int32 mask = osl_VolumeInfo_Mask_TotalSpace;
    5783           1 :             checkVolumeInfo(mask);
    5784           1 :         }
    5785           1 :         void getVolumeInfo_001_4()
    5786             :         {
    5787           1 :             sal_Int32 mask = osl_VolumeInfo_Mask_UsedSpace;
    5788           1 :             checkVolumeInfo(mask);
    5789           1 :         }
    5790           1 :         void getVolumeInfo_001_5()
    5791             :         {
    5792           1 :             sal_Int32 mask = osl_VolumeInfo_Mask_FreeSpace;
    5793           1 :             checkVolumeInfo(mask);
    5794           1 :         }
    5795           1 :         void getVolumeInfo_001_6()
    5796             :         {
    5797           1 :             sal_Int32 mask = osl_VolumeInfo_Mask_MaxNameLength;
    5798           1 :             checkVolumeInfo(mask);
    5799           1 :         }
    5800           1 :         void getVolumeInfo_001_7()
    5801             :         {
    5802           1 :             sal_Int32 mask = osl_VolumeInfo_Mask_MaxPathLength;
    5803           1 :             checkVolumeInfo(mask);
    5804           1 :         }
    5805           1 :         void getVolumeInfo_001_8()
    5806             :         {
    5807           1 :             sal_Int32 mask = osl_VolumeInfo_Mask_FileSystemCaseHandling;
    5808           1 :             checkVolumeInfo(mask);
    5809           1 :         }
    5810             : 
    5811           1 :         void getVolumeInfo_002()
    5812             :         {
    5813           1 :             sal_Int32 mask = osl_VolumeInfo_Mask_FileSystemName;
    5814           1 :             ::osl::VolumeInfo aVolumeInfo( mask );
    5815             :             //call getVolumeInfo here
    5816             : 
    5817             :             // LLA: rtl::OUString aRootSysURL;
    5818             :             // LLA: nError1 = osl::File::getFileURLFromSystemPath(aRootSys, aRootSysURL);
    5819             :             // LLA:
    5820             :             // LLA: CPPUNIT_ASSERT_MESSAGE( "can't convert root path to file url",
    5821             :             // LLA:                         ( osl::FileBase::E_NONE == nError1 ) );
    5822             : 
    5823           1 :             nError1 = ::osl::Directory::getVolumeInfo( aRootSys, aVolumeInfo );
    5824             : 
    5825           2 :             CPPUNIT_ASSERT_MESSAGE( "test for getVolumeInfo function: use system path as parameter.",
    5826           2 :                                     ( osl::FileBase::E_INVAL == nError1 ) );
    5827           1 :         }
    5828             : 
    5829           1 :         void getVolumeInfo_003()
    5830             :         {
    5831           1 :             sal_Int32 mask = osl_VolumeInfo_Mask_FileSystemName;
    5832           1 :             ::osl::VolumeInfo aVolumeInfo( mask );
    5833             :             //call getVolumeInfo here
    5834           1 :             nError1 = ::osl::Directory::getVolumeInfo( aTmpName3, aVolumeInfo );
    5835             : 
    5836             : // LLA: in Windows, it reply no error, it did not pass in (W32).
    5837             : #if defined(UNX) && !defined(IOS)
    5838           2 :             CPPUNIT_ASSERT_MESSAGE( "test for getVolumeInfo function: non-existence test. ",
    5839           2 :                                     ( osl::FileBase::E_NOENT == nError1 ) );
    5840             : #endif
    5841           1 :         }
    5842             : 
    5843           2 :         CPPUNIT_TEST_SUITE( getVolumeInfo );
    5844           1 :         CPPUNIT_TEST( getVolumeInfo_001_1 );
    5845           1 :         CPPUNIT_TEST( getVolumeInfo_001_2 );
    5846           1 :         CPPUNIT_TEST( getVolumeInfo_001_3 );
    5847           1 :         CPPUNIT_TEST( getVolumeInfo_001_4 );
    5848           1 :         CPPUNIT_TEST( getVolumeInfo_001_5 );
    5849           1 :         CPPUNIT_TEST( getVolumeInfo_001_6 );
    5850           1 :         CPPUNIT_TEST( getVolumeInfo_001_7 );
    5851           1 :         CPPUNIT_TEST( getVolumeInfo_001_8 );
    5852           1 :         CPPUNIT_TEST( getVolumeInfo_002 );
    5853           1 :         CPPUNIT_TEST( getVolumeInfo_003 );
    5854           2 :         CPPUNIT_TEST_SUITE_END();
    5855             :     };// class getVolumeInfo
    5856             : 
    5857             : 
    5858             :     //---------------------------------------------------------------------
    5859             :     //  testing the method
    5860             :     //  inline static RC create( const ::rtl::OUString& ustrDirectoryURL )
    5861             :     //---------------------------------------------------------------------
    5862           6 :     class  create : public CppUnit::TestFixture
    5863             :     {
    5864             :         ::osl::FileBase::RC     nError1, nError2;
    5865             : 
    5866             :         public:
    5867             : 
    5868             :         // test code.
    5869           3 :         create() :nError1(FileBase::E_None),nError2(FileBase::E_None) {}
    5870           1 :         void create_001()
    5871             :         {
    5872             :             //create directory in $TEMP/tmpdir
    5873           1 :             nError1 = ::osl::Directory::create( aTmpName3 );
    5874             :             //check for existence
    5875           1 :             nError2 = ::osl::Directory::create( aTmpName3 );
    5876             :             //remove it
    5877           1 :             deleteTestDirectory( aTmpName3 );
    5878             : 
    5879           2 :             CPPUNIT_ASSERT_MESSAGE( "test for create function: create a directory and check its existence.",
    5880             :                                     ( osl::FileBase::E_None == nError1 ) &&
    5881           1 :                                     ( osl::FileBase::E_EXIST== nError2 ) );
    5882           1 :         }
    5883             : 
    5884           1 :         void create_002()
    5885             :         {
    5886             : #if !defined (WNT) && !defined (MACOSX) && defined (SAL_UNX)
    5887           1 :             if (geteuid() == 0) //don't test if building as root
    5888           2 :                 return;
    5889             : 
    5890           0 :             rtl::OUString aTmpDir;
    5891           0 :             nError1 = FileBase::createTempFile(NULL, NULL, &aTmpDir);
    5892           0 :             CPPUNIT_ASSERT_MESSAGE("temp File creation failed", osl::FileBase::E_None == nError1);
    5893             : 
    5894           0 :             nError1 = ::osl::File::remove(aTmpDir);
    5895           0 :             CPPUNIT_ASSERT_MESSAGE("temp File removal failed", osl::FileBase::E_None == nError1);
    5896             : 
    5897           0 :             nError1 = ::osl::Directory::create(aTmpDir);
    5898           0 :             ::rtl::OString sError("test for create function: create a directory '");
    5899           0 :             sError += ::rtl::OUStringToOString(aTmpDir, RTL_TEXTENCODING_ASCII_US);
    5900           0 :             sError += "' and check its existence.";
    5901           0 :             CPPUNIT_ASSERT_MESSAGE(sError.getStr(), osl::FileBase::E_None == nError1);
    5902           0 :             osl_setFileAttributes(aTmpDir.pData, 0); //no access allowed now
    5903             : 
    5904             :             //Shouldn't be possible now to create a dir underneath it
    5905           0 :             rtl::OUString aTmpSubLevel = aTmpDir + OUString("/notallowedhere");
    5906           0 :             nError1 = ::osl::Directory::create(aTmpSubLevel);
    5907             : 
    5908             :             //allow removal
    5909             :             osl_setFileAttributes(aTmpDir.pData,
    5910             :                 osl_File_Attribute_OwnRead |
    5911             :                 osl_File_Attribute_OwnWrite |
    5912           0 :                 osl_File_Attribute_OwnExe);
    5913           0 :             deleteTestDirectory(aTmpDir);
    5914           0 :             sError = ::rtl::OString("test for create function: create a directory under '");
    5915           0 :             sError += ::rtl::OUStringToOString(aTmpDir, RTL_TEXTENCODING_ASCII_US);
    5916           0 :             sError += "' for access test.";
    5917           0 :             CPPUNIT_ASSERT_MESSAGE(sError.getStr(), osl::FileBase::E_ACCES == nError1);
    5918             : #endif
    5919             :         }
    5920             : 
    5921           1 :         void create_003()
    5922             :         {
    5923             :             //create directory in /tmpname
    5924           1 :             nError1 = ::osl::Directory::create( aSysPath1 );
    5925             : 
    5926           2 :             CPPUNIT_ASSERT_MESSAGE( "test for create function: create a directory using system path.",
    5927           1 :                                     ( osl::FileBase::E_INVAL == nError1 ) );
    5928           1 :         }
    5929             : 
    5930           2 :         CPPUNIT_TEST_SUITE( create );
    5931           1 :         CPPUNIT_TEST( create_001 );
    5932           1 :         CPPUNIT_TEST( create_002 );
    5933           1 :         CPPUNIT_TEST( create_003 );
    5934           2 :         CPPUNIT_TEST_SUITE_END();
    5935             :     };// class create
    5936             : 
    5937             :     //---------------------------------------------------------------------
    5938             :     //  testing the method
    5939             :     //  inline static RC remove( const ::rtl::OUString& ustrDirectoryURL )
    5940             :     //---------------------------------------------------------------------
    5941          10 :     class  remove : public CppUnit::TestFixture
    5942             :     {
    5943             :         ::osl::FileBase::RC     nError1, nError2;
    5944             : 
    5945             :         public:
    5946             : 
    5947           5 :         remove() :nError1(FileBase::E_None),nError2(FileBase::E_None) {}
    5948             :         // test code.
    5949           1 :         void remove_001()
    5950             :         {
    5951             :             //create directory in $TEMP/tmpdir
    5952           1 :             nError1 = ::osl::Directory::create( aTmpName3 );
    5953           1 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    5954             :             //remove it
    5955           1 :             nError1 = ::osl::Directory::remove( aTmpName3 );
    5956             :             //check for existence
    5957           1 :             ::osl::Directory rDirectory( aTmpName3 );
    5958           1 :             nError2 = rDirectory.open();
    5959             : 
    5960           2 :             CPPUNIT_ASSERT_MESSAGE( "test for remove function: remove a directory and check its existence.",
    5961             :                                     ( osl::FileBase::E_None == nError1 ) &&
    5962           2 :                                     ( osl::FileBase::E_NOENT == nError2 ) );
    5963           1 :         }
    5964             : 
    5965           1 :         void remove_002()
    5966             :         {
    5967             :             //create directory in $TEMP/tmpdir
    5968           1 :             nError1 = ::osl::Directory::create( aTmpName3 );
    5969           1 :             CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
    5970             :             //try to remove it by system path
    5971           1 :             nError1 = ::osl::Directory::remove( aSysPath3 );
    5972             :              //check for existence
    5973           1 :             ::osl::Directory rDirectory( aTmpName3 );
    5974           1 :             nError2 = rDirectory.open();
    5975           1 :             if ( osl::FileBase::E_NOENT != nError2 )
    5976           1 :                 ::osl::Directory::remove( aTmpName3 );
    5977             : 
    5978           2 :             CPPUNIT_ASSERT_MESSAGE( "test for remove function: remove a directory by its system path, and check its existence.",
    5979           2 :                                     ( osl::FileBase::E_INVAL == nError1 ) );
    5980           1 :         }
    5981             : 
    5982           1 :         void remove_003()
    5983             :         {
    5984             :             //try to remove a non-existed directory
    5985           1 :             nError1 = ::osl::Directory::remove( aTmpName6 );
    5986             : 
    5987           2 :             CPPUNIT_ASSERT_MESSAGE( "test for remove function: try to remove a non-existed directory.",
    5988           1 :                                     ( osl::FileBase::E_NOENT == nError1 ) );
    5989           1 :         }
    5990             : 
    5991           1 :         void remove_004()
    5992             :         {
    5993           1 :             createTestFile( aTmpName6 );
    5994           1 :             sal_Bool bExist = ifFileExist( aTmpName6 );
    5995             :             //try to remove file.
    5996           1 :             nError1 = ::osl::Directory::remove( aTmpName6 );
    5997           1 :             deleteTestFile( aTmpName6 );
    5998             : 
    5999           2 :             CPPUNIT_ASSERT_MESSAGE( "test for remove function: try to remove a file but not directory.",
    6000           1 :                                     bExist == sal_True &&(( osl::FileBase::E_NOTDIR == nError1 ) || ( osl::FileBase::E_NOENT == nError1 )) );
    6001           1 :         }
    6002             : 
    6003           1 :         void remove_005()
    6004             :         {
    6005           1 :             createTestDirectory( aTmpName3 );
    6006           1 :             createTestFile( aTmpName4 );
    6007           1 :             nError1 = ::osl::Directory::remove( aTmpName3 );
    6008           1 :             deleteTestFile( aTmpName4 );
    6009           1 :             deleteTestDirectory( aTmpName3 );
    6010           1 :             ::rtl::OString sError = "test for remove function: try to remove a directory that is not empty.";
    6011           1 :             sError += errorToStr( nError1 ).getStr();
    6012             : #if defined ( SOLARIS )
    6013             :             //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.
    6014             :             //EEXIST The directory contains entries other than those for "." and "..".
    6015             :             printf("#Solaris test\n");
    6016             :             CPPUNIT_ASSERT_MESSAGE( sError.getStr(), ( osl::FileBase::E_EXIST == nError1 ) );
    6017             : #else
    6018           1 :             CPPUNIT_ASSERT_MESSAGE( sError.getStr(), ( osl::FileBase::E_NOTEMPTY == nError1 ) );
    6019             : #endif
    6020           1 :         }
    6021             : 
    6022           2 :         CPPUNIT_TEST_SUITE( remove );
    6023           1 :         CPPUNIT_TEST( remove_001 );
    6024           1 :         CPPUNIT_TEST( remove_002 );
    6025           1 :         CPPUNIT_TEST( remove_003 );
    6026           1 :         CPPUNIT_TEST( remove_004 );
    6027           1 :         CPPUNIT_TEST( remove_005 );
    6028           2 :         CPPUNIT_TEST_SUITE_END();
    6029             :     };// class remove
    6030             : 
    6031             :     //########################################
    6032             :     // TEST Directory::createPath
    6033             :     //########################################
    6034             : 
    6035             :     #ifdef WNT
    6036             :     #   define PATH_BUFFER_SIZE MAX_PATH
    6037             :     #else
    6038             :     #   define PATH_BUFFER_SIZE PATH_MAX
    6039             :     #endif
    6040             : 
    6041             : #define TEST_PATH_POSTFIX "hello/world"
    6042             : 
    6043             :     //########################################
    6044           2 :     OUString get_test_path()
    6045             :     {
    6046           2 :         static OUString test_path;
    6047           2 :         if (test_path.isEmpty())
    6048             :         {
    6049           1 :             OUString tmp;
    6050           1 :             FileBase::RC rc = FileBase::getTempDirURL(tmp);
    6051             : 
    6052           2 :             CPPUNIT_ASSERT_MESSAGE
    6053             :             (
    6054             :              "Getting the location of TMP dir failed",
    6055             :              rc == FileBase::E_None
    6056           1 :             );
    6057             : 
    6058           2 :             OUString system_path;
    6059           1 :             rc = FileBase::getSystemPathFromFileURL(tmp, system_path);
    6060             : 
    6061           2 :             CPPUNIT_ASSERT_MESSAGE
    6062             :             (
    6063             :              "Cannot convert the TMP dir to system path",
    6064             :              rc == FileBase::E_None
    6065           1 :             );
    6066             : 
    6067           2 :             OString tmp_x(rtl::OUStringToOString(system_path, RTL_TEXTENCODING_UTF8 ));
    6068           1 :             if (tmp_x.lastIndexOf('/') != (tmp_x.getLength() - 1))
    6069           1 :                 tmp_x += rtl::OString('/');
    6070             : 
    6071             : #if !defined(WNT) && !defined(ANDROID) && !defined(AIX)
    6072             :             // FIXME would be nice to create unique dir even on Windows
    6073           1 :             tmp_x += rtl::OString("XXXXXX");
    6074           1 :             char *out = mkdtemp(const_cast<char*>(tmp_x.getStr()));
    6075             : 
    6076           2 :             CPPUNIT_ASSERT_MESSAGE
    6077             :             (
    6078             :              "mkdtemp call failed",
    6079             :              out != NULL
    6080           1 :             );
    6081             : 
    6082           1 :             tmp_x += rtl::OString('/');
    6083             : #endif
    6084           1 :             tmp_x += rtl::OString(TEST_PATH_POSTFIX);
    6085             : 
    6086           1 :             rc = FileBase::getFileURLFromSystemPath(rtl::OStringToOUString(tmp_x, RTL_TEXTENCODING_UTF8), test_path);
    6087             : 
    6088           2 :             CPPUNIT_ASSERT_MESSAGE
    6089             :             (
    6090             :              "Cannot convert the system path back to an URL",
    6091             :              rc == FileBase::E_None
    6092           2 :             );
    6093             :         }
    6094           2 :         return test_path;
    6095             :     }
    6096             : 
    6097             :     //########################################
    6098           4 :     void rm_test_path(const OUString& path)
    6099             :     {
    6100             :         sal_Unicode buffer[PATH_BUFFER_SIZE];
    6101           4 :         memcpy(buffer, path.getStr(), (path.getLength() + 1) * sizeof(sal_Unicode));
    6102             : 
    6103           4 :         sal_Int32 i = rtl_ustr_lastIndexOfChar(buffer, '/');
    6104           4 :         if (i == path.getLength())
    6105           0 :             buffer[i] = 0;
    6106             : 
    6107           4 :         Directory::remove(buffer);
    6108             : 
    6109           4 :         i = rtl_ustr_lastIndexOfChar(buffer, '/');
    6110           4 :         buffer[i] = 0;
    6111           4 :         Directory::remove(buffer);
    6112           4 :     }
    6113             : 
    6114             :     //########################################
    6115           2 :     class DirCreatedObserver : public DirectoryCreationObserver
    6116             :     {
    6117             :     public:
    6118           1 :         DirCreatedObserver() : i(0)
    6119             :         {
    6120           1 :         }
    6121             : 
    6122           2 :         virtual void DirectoryCreated(const rtl::OUString& /*aDirectoryUrl*/)
    6123             :         {
    6124           2 :             i++;
    6125           2 :         };
    6126             : 
    6127           1 :         int number_of_dirs_created() const
    6128             :         {
    6129           1 :             return i;
    6130             :         }
    6131             : 
    6132             :     private:
    6133             :             int i;
    6134             :     };
    6135             : 
    6136             : 
    6137             :     //########################################
    6138           6 :     class createPath : public CppUnit::TestFixture
    6139             :     {
    6140             :     public:
    6141             :         //##########################################
    6142           3 :         createPath()
    6143           3 :         {}
    6144             : 
    6145             :         //##########################################
    6146           1 :         void with_relative_path()
    6147             :         {
    6148           1 :             FileBase::RC rc = Directory::createPath( OUString(TEST_PATH_POSTFIX));
    6149             : 
    6150             : 
    6151           2 :             CPPUNIT_ASSERT_MESSAGE
    6152             :             (
    6153             :                 "osl_createDirectoryPath contract broken",
    6154             :                 rc == FileBase::E_INVAL
    6155           1 :             );
    6156           1 :         }
    6157             : 
    6158             :         //##########################################
    6159           1 :         void without_callback()
    6160             :         {
    6161           1 :             OUString tp_url = get_test_path();
    6162             : 
    6163           1 :             rm_test_path(tp_url);
    6164             : 
    6165           1 :             FileBase::RC rc = Directory::createPath(tp_url);
    6166             : 
    6167           1 :             rm_test_path(tp_url);
    6168             : 
    6169           2 :             CPPUNIT_ASSERT_MESSAGE
    6170             :             (
    6171             :                 "osl_createDirectoryPath failed",
    6172             :                 rc == FileBase::E_None
    6173           2 :             );
    6174           1 :         }
    6175             : 
    6176             :         //##########################################
    6177           1 :         void with_callback()
    6178             :         {
    6179           1 :             OUString tp_url = get_test_path();
    6180             : 
    6181           1 :             rm_test_path(tp_url);
    6182             : 
    6183           1 :             DirCreatedObserver* observer = new DirCreatedObserver;
    6184           1 :             FileBase::RC rc = Directory::createPath(tp_url, observer);
    6185           1 :             int nDirs = observer->number_of_dirs_created();
    6186           1 :             delete observer;
    6187             : 
    6188           1 :             rm_test_path(tp_url);
    6189             : 
    6190           2 :             CPPUNIT_ASSERT_MESSAGE
    6191             :             (
    6192             :                 "osl_createDirectoryPath failed",
    6193             :                 (rc == FileBase::E_None) && (nDirs > 0)
    6194           2 :             );
    6195             : 
    6196           1 :         }
    6197             : 
    6198             : #ifdef WNT
    6199             : 
    6200             :         //##########################################
    6201             :         char* get_unused_drive_letter()
    6202             :         {
    6203             :             static char m_aBuff[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    6204             : 
    6205             :             DWORD ld = GetLogicalDrives();
    6206             :             DWORD i = 4;
    6207             :             DWORD j = 2;
    6208             : 
    6209             :             while ((ld & i) && (i > 1))
    6210             :             { i = i << 1; j++; }
    6211             : 
    6212             :             if (i > 2)
    6213             :                 return m_aBuff + j;
    6214             : 
    6215             :             return NULL;
    6216             :         }
    6217             : 
    6218             :         //##########################################
    6219             :         void at_invalid_logical_drive()
    6220             :         {
    6221             :             char* drv = get_unused_drive_letter();
    6222             :             char buff[PATH_BUFFER_SIZE];
    6223             :             memset(buff, 0, sizeof(buff));
    6224             : 
    6225             :             strncpy(buff, drv, 1);
    6226             :             strcat(buff, ":\\");
    6227             :             strcat(buff, TEST_PATH_POSTFIX);
    6228             : 
    6229             :             OUString path = OUString::createFromAscii(buff);
    6230             :             OUString tp_url;
    6231             :             FileBase::getFileURLFromSystemPath(path, tp_url);
    6232             : 
    6233             :             FileBase::RC rc = Directory::createPath(tp_url);
    6234             : 
    6235             :             CPPUNIT_ASSERT_MESSAGE
    6236             :             (
    6237             :                 "osl_createDirectoryPath doesn't fail on unused logical drive letters",
    6238             :                 rc != FileBase::E_None
    6239             :             );
    6240             :         }
    6241             : #endif /* WNT */
    6242             : 
    6243           2 :     CPPUNIT_TEST_SUITE(createPath);
    6244           1 :     CPPUNIT_TEST(with_relative_path);
    6245           1 :     CPPUNIT_TEST(without_callback);
    6246           1 :     CPPUNIT_TEST(with_callback);
    6247             : #ifdef WNT
    6248             :     CPPUNIT_TEST(at_invalid_logical_drive);
    6249             : #endif
    6250           2 :     CPPUNIT_TEST_SUITE_END();
    6251             : 
    6252             :     }; // class createPath
    6253             : 
    6254             :     // -----------------------------------------------------------------------------
    6255           1 :     CPPUNIT_TEST_SUITE_REGISTRATION( osl_Directory::ctors );
    6256           1 :     CPPUNIT_TEST_SUITE_REGISTRATION( osl_Directory::open );
    6257           1 :     CPPUNIT_TEST_SUITE_REGISTRATION( osl_Directory::isOpen );
    6258           1 :     CPPUNIT_TEST_SUITE_REGISTRATION( osl_Directory::close );
    6259           1 :     CPPUNIT_TEST_SUITE_REGISTRATION( osl_Directory::reset );
    6260           1 :     CPPUNIT_TEST_SUITE_REGISTRATION( osl_Directory::getNextItem );
    6261           1 :     CPPUNIT_TEST_SUITE_REGISTRATION( osl_Directory::getVolumeInfo );
    6262           1 :     CPPUNIT_TEST_SUITE_REGISTRATION( osl_Directory::create );
    6263           1 :     CPPUNIT_TEST_SUITE_REGISTRATION( osl_Directory::remove );
    6264           1 :     CPPUNIT_TEST_SUITE_REGISTRATION( osl_Directory::createPath );
    6265             : }// namespace osl_Directory
    6266             : 
    6267             : 
    6268             : 
    6269           1 : CPPUNIT_PLUGIN_IMPLEMENT();
    6270             : 
    6271             : 
    6272             : 
    6273             : /** get Current PID.
    6274             : */
    6275           0 : inline ::rtl::OUString getCurrentPID(  )
    6276             : {
    6277             :     //~ Get current PID and turn it into OUString;
    6278           0 :     int nPID = 0;
    6279             : #ifdef WNT
    6280             :     nPID = GetCurrentProcessId();
    6281             : #else
    6282           0 :     nPID = getpid();
    6283             : #endif
    6284           0 :     return ( ::rtl::OUString::valueOf( ( long )nPID ) );
    6285             : }
    6286             : 
    6287             : 
    6288             : //~ do some clean up work after all test completed.
    6289             : class GlobalObject
    6290             : {
    6291             :     public:
    6292           0 :     ~GlobalObject()
    6293             :     {
    6294             :         try
    6295             :         {
    6296             :             //~ special clean up task in Windows and Unix separately;
    6297             : #if ( defined UNX )
    6298             :             //~ some clean up task  for UNIX OS
    6299             :             ;
    6300             : #else
    6301             :             //~ some clean up task  for Windows OS
    6302             :             //~ check if some files are in the way, remove them if necessary.
    6303             :             if ( ifFileExist( aTmpName6 )  == sal_True )
    6304             :                 deleteTestFile( aTmpName6 );
    6305             :             if ( ifFileExist( aTmpName4 )  == sal_True )
    6306             :                 deleteTestFile( aTmpName4 );
    6307             :             if ( checkDirectory( aTmpName4, osl_Check_Mode_Exist )  == sal_True )
    6308             :                 deleteTestDirectory( aTmpName4 );
    6309             :             if ( ifFileExist( aTmpName3 )  == sal_True )
    6310             :                 deleteTestFile( aTmpName3 );
    6311             :             if ( checkDirectory( aTmpName3, osl_Check_Mode_Exist )  == sal_True )
    6312             :                 deleteTestDirectory( aTmpName3 );
    6313             : 
    6314             :             ::rtl::OUString aUStr( aUserDirectoryURL );
    6315             :             concatURL( aUStr, aHidURL1 );
    6316             :             if ( ifFileExist( aUStr )  == sal_True )
    6317             :                 deleteTestFile( aUStr );
    6318             : 
    6319             :             ::rtl::OUString aUStr1( aRootURL );
    6320             :             concatURL( aUStr1, aTmpName2 );
    6321             :             if ( ifFileExist( aUStr1 )  == sal_True )
    6322             :                 deleteTestFile( aUStr1 );
    6323             : #endif
    6324             :         }
    6325             :         catch (const CppUnit::Exception &e)
    6326             :         {
    6327             :             printf("Exception caught in GlobalObject dtor(). Exception message: '%s'. Source line: %d\n", e.what(), e.sourceLine().lineNumber());
    6328             :         }
    6329             :         catch (...)
    6330             :         {
    6331             :             printf("Exception caught (...) in GlobalObject dtor()\n");
    6332             :         }
    6333           0 :     }
    6334             : };
    6335             : 
    6336           3 : GlobalObject theGlobalObject;
    6337             : 
    6338             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10