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

Generated by: LCOV version 1.10