1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
22 #include <sal/types.h>
23 #include <rtl/ustring.hxx>
24 #include <rtl/ustrbuf.hxx>
26 #include "osl/thread.h"
28 #include <osl/file.hxx>
29 #include <osl_File_Const.h>
31 #include <cppunit/TestFixture.h>
32 #include <cppunit/extensions/HelperMacros.h>
33 #include <cppunit/plugin/TestPlugIn.h>
43 using ::rtl::OUString
;
44 using ::rtl::OUStringToOString
;
46 using ::rtl::OStringToOUString
;
50 /** detailed wrong message.
52 inline ::rtl::OString
errorToString( const ::osl::FileBase::RC _nError
)
54 ::rtl::OString sResult
;
56 case ::osl::FileBase::E_None
:
59 case ::osl::FileBase::E_PERM
:
60 sResult
= "Operation not permitted";
62 case ::osl::FileBase::E_NOENT
:
63 sResult
= "No such file or directory";
65 case ::osl::FileBase::E_EXIST
:
66 sResult
= "Already Exist";
68 case ::osl::FileBase::E_ACCES
:
69 sResult
= "Permission denied";
71 case ::osl::FileBase::E_INVAL
:
72 sResult
= "The format of the parameters was not valid";
74 case ::osl::FileBase::E_NOTDIR
:
75 sResult
= "Not a directory";
77 case ::osl::FileBase::E_ISDIR
:
78 sResult
= "Is a directory";
80 case ::osl::FileBase::E_BADF
:
83 case ::osl::FileBase::E_NOTEMPTY
:
84 sResult
= "The directory is not empty";
87 sResult
= "Unknown Error";
93 rtl::OString
errorToStr( ::osl::FileBase::RC
const& nError
)
96 suBuf
+= "The returned error is: " ;
97 suBuf
+= errorToString(nError
);
102 /** compare two TimeValue, unit is "ms", since Windows time precision is better than UNX.
104 /* FIXME: the above assertion is bogus */
106 #if ( defined UNX ) //precision of time in Windows is better than UNX
107 # define delta 2000 //time precision, 2000ms
109 # define delta 1800 //time precision, 1.8s
112 inline bool t_compareTime( TimeValue
*m_aEndTime
, TimeValue
*m_aStartTime
, sal_Int32 nDelta
)
114 // sal_uInt64 uTimeValue;
115 // sal_Int64 iTimeValue;
117 // iTimeValue = t_abs64(( tv1->Seconds - tv2->Seconds) * 1000000000 + tv1->Nanosec - tv2->Nanosec);
118 // uTimeValue = ( iTimeValue / 1000000 );
120 sal_Int32 nDeltaSeconds
= m_aEndTime
->Seconds
- m_aStartTime
->Seconds
;
121 sal_Int32 nDeltaNanoSec
= sal_Int32(m_aEndTime
->Nanosec
) - sal_Int32(m_aStartTime
->Nanosec
);
122 if (nDeltaNanoSec
< 0)
124 nDeltaNanoSec
= 1000000000 + nDeltaNanoSec
;
128 sal_Int32 nDeltaMilliSec
= (nDeltaSeconds
* 1000) + (nDeltaNanoSec
/ 1000000);
129 return ( nDeltaMilliSec
< nDelta
);
132 /** compare two OUString file name.
134 inline bool compareFileName( const ::rtl::OUString
& ustr1
, const ::rtl::OUString
& ustr2
)
137 //on Windows, the separator is '\', so here change to '/', then compare
139 ::rtl::OUString ustr1new
,ustr2new
;
140 sal_Unicode reverseSlash
= (sal_Unicode
)'\\';
142 if (ustr1
.lastIndexOf(reverseSlash
) != -1)
143 ustr1new
= ustr1
.replace(reverseSlash
,(sal_Unicode
)'/');
146 if (ustr2
.lastIndexOf(reverseSlash
) != -1)
147 ustr2new
= ustr2
.replace(reverseSlash
,(sal_Unicode
)'/');
150 bOk
= ustr1new
.equalsIgnoreAsciiCase( ustr2new
) ;
152 bOk
= ustr1
.equalsIgnoreAsciiCase( ustr2
);
157 /** simple version to judge if a file name or directory name is a URL or a system path, just to see if it
158 is start with "file:///";.
160 inline bool isURL( const ::rtl::OUString
& pathname
)
162 return pathname
.startsWith( aPreURL
);
165 /** concat two part to form a URL or system path, add PATH_SEPARATOR between them if necessary, add "file:///" to beginning if necessary.
167 inline void concatURL( ::rtl::OUString
& pathname1
, const ::rtl::OUString
& pathname2
)
169 //check if pathname1 is full qualified URL;
170 if ( !isURL( pathname1
) )
172 ::rtl::OUString aPathName
= pathname1
.copy( 0 );
173 ::osl::FileBase::getFileURLFromSystemPath( pathname1
, aPathName
); //convert if not full qualified URL
174 pathname1
= aPathName
.copy( 0 );
177 //check if '/' is in the end of pathname1 or at the begin of pathname2;
178 if ( !pathname1
.endsWith( aSlashURL
) && !pathname2
.startsWith( aSlashURL
) )
179 pathname1
+= aSlashURL
;
180 pathname1
+= pathname2
;
183 /** create a temp test file using OUString name of full qualified URL or system path.
185 inline void createTestFile( const ::rtl::OUString
& filename
)
187 ::rtl::OUString aPathURL
= filename
.copy( 0 );
188 ::osl::FileBase::RC nError
;
190 if ( !isURL( filename
) )
191 ::osl::FileBase::getFileURLFromSystemPath( filename
, aPathURL
); //convert if not full qualified URL
193 File
aFile(aPathURL
);
194 nError
= aFile
.open( osl_File_OpenFlag_Read
| osl_File_OpenFlag_Write
| osl_File_OpenFlag_Create
);
195 //CPPUNIT_ASSERT_MESSAGE( "In createTestFile Function: creation ", ( ::osl::FileBase::E_None == nError ) || ( nError == ::osl::FileBase::E_EXIST ) );
196 if ( ( ::osl::FileBase::E_None
!= nError
) && ( nError
!= ::osl::FileBase::E_EXIST
))
198 printf("createTestFile failed!\n");
204 /** create a temp test file using OUString name of full qualified URL or system path in a base directory.
206 inline void createTestFile( const ::rtl::OUString
& basename
, const ::rtl::OUString
& filename
)
208 ::rtl::OUString aBaseURL
= basename
.copy( 0 );
210 concatURL( aBaseURL
, filename
);
211 createTestFile( aBaseURL
);
214 /** detete a temp test file using OUString name.
216 inline void deleteTestFile( const ::rtl::OUString
& filename
)
218 // LLA: printf("deleteTestFile\n");
219 ::rtl::OUString aPathURL
= filename
.copy( 0 );
220 ::osl::FileBase::RC nError
;
222 if ( !isURL( filename
) )
223 ::osl::FileBase::getFileURLFromSystemPath( filename
, aPathURL
); //convert if not full qualified URL
225 nError
= ::osl::File::setAttributes( aPathURL
, osl_File_Attribute_GrpWrite
| osl_File_Attribute_OwnWrite
| osl_File_Attribute_OthWrite
); // if readonly, make writtenable.
226 CPPUNIT_ASSERT_MESSAGE( "In deleteTestFile Function: set writtenable ", ( ::osl::FileBase::E_None
== nError
) || ( ::osl::FileBase::E_NOENT
== nError
) );
228 nError
= ::osl::File::remove( aPathURL
);
229 CPPUNIT_ASSERT_MESSAGE( "In deleteTestFile Function: remove ", ( ::osl::FileBase::E_None
== nError
) || ( nError
== ::osl::FileBase::E_NOENT
) );
232 /** delete a temp test file using OUString name of full qualified URL or system path in a base directory.
234 inline void deleteTestFile( const ::rtl::OUString
& basename
, const ::rtl::OUString
& filename
)
236 ::rtl::OUString aBaseURL
= basename
.copy( 0 );
238 concatURL( aBaseURL
, filename
);
239 deleteTestFile( aBaseURL
);
242 /** create a temp test directory using OUString name of full qualified URL or system path.
244 inline void createTestDirectory( const ::rtl::OUString
& dirname
)
246 ::rtl::OUString aPathURL
= dirname
.copy( 0 );
247 ::osl::FileBase::RC nError
;
249 if ( !isURL( dirname
) )
250 ::osl::FileBase::getFileURLFromSystemPath( dirname
, aPathURL
); //convert if not full qualified URL
251 nError
= ::osl::Directory::create( aPathURL
);
252 //CPPUNIT_ASSERT_MESSAGE( "In createTestDirectory Function: creation: ", ( ::osl::FileBase::E_None == nError ) || ( nError == ::osl::FileBase::E_EXIST ) );
253 if ( ( ::osl::FileBase::E_None
!= nError
) && ( nError
!= ::osl::FileBase::E_EXIST
))
254 printf("createTestDirectory failed!\n");
257 /** create a temp test directory using OUString name of full qualified URL or system path in a base directory.
259 inline void createTestDirectory( const ::rtl::OUString
& basename
, const ::rtl::OUString
& dirname
)
261 ::rtl::OUString aBaseURL
= basename
.copy( 0 );
263 concatURL( aBaseURL
, dirname
);
264 createTestDirectory( aBaseURL
);
267 /** delete a temp test directory using OUString name of full qualified URL or system path.
269 inline void deleteTestDirectory( const ::rtl::OUString
& dirname
)
271 ::rtl::OUString aPathURL
= dirname
.copy( 0 );
272 ::osl::FileBase::RC nError
;
273 if ( !isURL( dirname
) )
274 ::osl::FileBase::getFileURLFromSystemPath( dirname
, aPathURL
); //convert if not full qualified URL
276 ::osl::Directory
testDir( aPathURL
);
277 if ( testDir
.isOpen() )
278 testDir
.close(); //close if still open.
280 nError
= ::osl::Directory::remove( aPathURL
);
282 rtl::OString
strError ("In deleteTestDirectory function: remove Directory ");
283 strError
+= ::rtl::OUStringToOString( aPathURL
, RTL_TEXTENCODING_ASCII_US
);
284 CPPUNIT_ASSERT_MESSAGE( strError
.getStr(), ( ::osl::FileBase::E_None
== nError
) || ( nError
== ::osl::FileBase::E_NOENT
) );
287 /** delete a temp test directory using OUString name of full qualified URL or system path in a base directory.
289 inline void deleteTestDirectory( const ::rtl::OUString
& basename
, const ::rtl::OUString
& dirname
)
291 ::rtl::OUString aBaseURL
= basename
.copy( 0 );
293 concatURL( aBaseURL
, dirname
);
294 deleteTestDirectory( aBaseURL
);
297 /** Check for the file and directory access right.
300 osl_Check_Mode_Exist
,
301 osl_Check_Mode_OpenAccess
,
302 osl_Check_Mode_ReadAccess
,
303 osl_Check_Mode_WriteAccess
306 //check if the file exist
307 inline bool ifFileExist( const ::rtl::OUString
& str
)
309 ::osl::File
testFile( str
);
310 return ( osl::FileBase::E_None
== testFile
.open( osl_File_OpenFlag_Read
) );
313 //check if the file can be written
314 inline bool ifFileCanWrite( const ::rtl::OUString
& str
)
316 bool bCheckResult
= false;
317 //on Windows, the file has no write right, but can be written
319 ::rtl::OUString aUStr
= str
.copy( 0 );
321 ::osl::FileBase::getSystemPathFromFileURL( str
, aUStr
);
323 ::rtl::OString aString
= ::rtl::OUStringToOString( aUStr
, RTL_TEXTENCODING_ASCII_US
);
324 const char *path
= aString
.getStr();
325 if (( _access( path
, 2 ) ) != -1 )
326 bCheckResult
= sal_True
;
327 //on UNX, just test if open success with osl_File_OpenFlag_Write
329 ::osl::File
testFile( str
);
330 bCheckResult
= (osl::FileBase::E_None
== testFile
.open( osl_File_OpenFlag_Write
));
335 inline bool checkDirectory( const ::rtl::OUString
& str
, oslCheckMode nCheckMode
)
337 rtl::OUString aUString
;
340 bool bCheckResult
= false;
342 Directory
aDir( str
);
345 if ( ( ::osl::FileBase::E_NOENT
!= rc
) && ( ::osl::FileBase::E_ACCES
!= rc
) ){
347 switch ( nCheckMode
) {
348 case osl_Check_Mode_Exist
:
349 if ( rc
== ::osl::FileBase::E_None
)
352 case osl_Check_Mode_OpenAccess
:
353 if ( rc
== ::osl::FileBase::E_None
)
356 case osl_Check_Mode_ReadAccess
:
357 //rc = pDir->getNextItem( rItem, 0 );
358 rc
= aDir
.getNextItem( rItem
, 0 );
359 if ( ( rc
== ::osl::FileBase::E_None
) || ( rc
== ::osl::FileBase::E_NOENT
) )
362 bCheckResult
= false;
364 case osl_Check_Mode_WriteAccess
:
365 ( ( aUString
+= str
) += aSlashURL
) += aTmpName2
;
366 //if ( ( rc = pDir->create( aUString ) ) == ::osl::FileBase::E_None )
367 if ( ( rc
= Directory::create( aUString
) ) == ::osl::FileBase::E_None
)
370 //rc = pDir->remove( aUString );
371 rc
= Directory::remove( aUString
);
372 CPPUNIT_ASSERT( rc
== ::osl::FileBase::E_None
);
375 bCheckResult
= false;
379 bCheckResult
= false;
383 CPPUNIT_ASSERT( rc
== FileBase::E_None
);
390 /** construct error message
392 inline ::rtl::OString
outputError( const ::rtl::OString
& returnVal
, const ::rtl::OString
& rightVal
, const sal_Char
* msg
= "")
394 ::rtl::OString aString
;
395 if ( returnVal
.equals( rightVal
) )
398 aString
+= ": the returned value is '";
399 aString
+= returnVal
;
400 aString
+= "', but the value should be '";
406 /** Change file mode, two version in UNIX and Windows;.
408 #if ( defined UNX ) //chmod() method is differ in Windows
409 inline void changeFileMode( ::rtl::OUString
& filepath
, sal_Int32 mode
)
411 rtl::OString aString
;
412 rtl::OUString aUStr
= filepath
.copy( 0 );
414 if ( isURL( filepath
) )
415 ::osl::FileBase::getSystemPathFromFileURL( filepath
, aUStr
);
416 aString
= ::rtl::OUStringToOString( aUStr
, RTL_TEXTENCODING_ASCII_US
);
417 int ret
= chmod( aString
.getStr(), mode
);
418 CPPUNIT_ASSERT(ret
== 0);
420 #else //Windows version
421 inline void changeFileMode( ::rtl::OUString
& filepath
, sal_Int32 mode
)
425 printf("this method is not implemented yet");
429 inline ::rtl::OUString
getCurrentPID();
431 // Beginning of the test cases for FileBase class
433 namespace osl_FileBase
436 // testing the method
437 // static inline RC getAbsoluteFileURL( const ::rtl::OUString& ustrBaseDirectoryURL,
438 // const ::rtl::OUString& ustrRelativeFileURL,
439 // ::rtl::OUString& ustrAbsoluteFileURL )
441 class getAbsoluteFileURL
:public CppUnit::TestFixture
445 void check_getAbsoluteFileURL( rtl::OUString
const& _suBaseURL
, rtl::OString
const& _sRelativeURL
, ::osl::FileBase::RC _nAssumeError
, rtl::OUString
const& _suAssumeResultStr
);
447 void getAbsoluteFileURL_001_1();
448 void getAbsoluteFileURL_001_2();
449 void getAbsoluteFileURL_001_3();
450 void getAbsoluteFileURL_001_4();
451 void getAbsoluteFileURL_001_5();
452 void getAbsoluteFileURL_001_6();
453 void getAbsoluteFileURL_001_7();
454 void getAbsoluteFileURL_001_8();
455 void getAbsoluteFileURL_002();
456 void getAbsoluteFileURL_003();
457 void getAbsoluteFileURL_004();
459 CPPUNIT_TEST_SUITE( getAbsoluteFileURL
);
460 CPPUNIT_TEST( getAbsoluteFileURL_001_1
);
461 CPPUNIT_TEST( getAbsoluteFileURL_001_2
);
462 CPPUNIT_TEST( getAbsoluteFileURL_001_3
);
463 CPPUNIT_TEST( getAbsoluteFileURL_001_4
);
464 CPPUNIT_TEST( getAbsoluteFileURL_001_5
);
465 CPPUNIT_TEST( getAbsoluteFileURL_001_6
);
466 CPPUNIT_TEST( getAbsoluteFileURL_001_7
);
467 CPPUNIT_TEST( getAbsoluteFileURL_001_8
);
468 CPPUNIT_TEST( getAbsoluteFileURL_002
);
469 CPPUNIT_TEST( getAbsoluteFileURL_003
);
470 CPPUNIT_TEST( getAbsoluteFileURL_004
);
471 CPPUNIT_TEST_SUITE_END();
473 }; //class getAbsoluteFileURL
475 void getAbsoluteFileURL::check_getAbsoluteFileURL( rtl::OUString
const& _suBaseURL
, rtl::OString
const& _sRelativeURL
, ::osl::FileBase::RC _nAssumeError
, rtl::OUString
const& _suAssumeResultStr
)
477 rtl::OUString suRelativeURL
= rtl::OStringToOUString(_sRelativeURL
, RTL_TEXTENCODING_UTF8
);
478 rtl::OString sBaseURL
= rtl::OUStringToOString(_suBaseURL
, RTL_TEXTENCODING_UTF8
);
479 rtl::OUString suResultURL
;
480 osl::FileBase::RC nError
= FileBase::getAbsoluteFileURL( _suBaseURL
, suRelativeURL
, suResultURL
);
481 rtl::OString sResultURL
= rtl::OUStringToOString( suResultURL
, RTL_TEXTENCODING_UTF8
);
482 rtl::OString sError
= errorToString(nError
);
483 printf("getAbsoluteFileURL('%s','%s') deliver absolute URL: '%s', error '%s'\n", sBaseURL
.getStr(), _sRelativeURL
.getStr(),sResultURL
.getStr(), sError
.getStr() );
484 CPPUNIT_ASSERT_MESSAGE( "Assumption is wrong: error number is wrong", nError
== _nAssumeError
);
485 if ( nError
== ::osl::FileBase::E_None
)
487 bool bStrAreEqual
= _suAssumeResultStr
.equals( suResultURL
);
488 CPPUNIT_ASSERT_MESSAGE( "Assumption is wrong: ResultURL is not equal to expected URL ", bStrAreEqual
);
492 void getAbsoluteFileURL::getAbsoluteFileURL_001_1()
494 rtl::OUString suAssume
= aUserDirectoryURL
.concat( rtl::OUString("/relative/file1") );
495 check_getAbsoluteFileURL( aUserDirectoryURL
, "relative/file1",::osl::FileBase::E_None
, suAssume
);
497 void getAbsoluteFileURL::getAbsoluteFileURL_001_2()
499 rtl::OUString suAssume
= aUserDirectoryURL
.concat( rtl::OUString("/relative/file2") );
500 check_getAbsoluteFileURL( aUserDirectoryURL
, "relative/./file2",::osl::FileBase::E_None
, suAssume
);
502 void getAbsoluteFileURL::getAbsoluteFileURL_001_3()
504 rtl::OUString suAssume
= aUserDirectoryURL
.concat( rtl::OUString("/file3") );
505 check_getAbsoluteFileURL( aUserDirectoryURL
, "relative/../file3",::osl::FileBase::E_None
, suAssume
);
507 void getAbsoluteFileURL::getAbsoluteFileURL_001_4()
509 rtl::OUString suAssume
= aUserDirectoryURL
.concat( rtl::OUString("/file4") );
510 check_getAbsoluteFileURL( aUserDirectoryURL
, "././relative/../file4",::osl::FileBase::E_None
, suAssume
);
512 void getAbsoluteFileURL::getAbsoluteFileURL_001_5()
514 rtl::OUString suAssume
;
516 suAssume
= aUserDirectoryURL
.concat( rtl::OUString("/relative/") );
518 suAssume
= aUserDirectoryURL
.concat( rtl::OUString("/relative") );
520 check_getAbsoluteFileURL( aUserDirectoryURL
, "././relative/.",::osl::FileBase::E_None
, suAssume
);
522 void getAbsoluteFileURL::getAbsoluteFileURL_001_6()
524 rtl::OUString suAssume
= aUserDirectoryURL
.concat( rtl::OUString("/.relative") );
525 check_getAbsoluteFileURL( aUserDirectoryURL
, "./.relative",::osl::FileBase::E_None
, suAssume
);
527 void getAbsoluteFileURL::getAbsoluteFileURL_001_7()
529 rtl::OUString suAssume
;
531 suAssume
= aUserDirectoryURL
.concat( rtl::OUString("/.a/") );
533 suAssume
= aUserDirectoryURL
.concat( rtl::OUString("/.a") );
535 check_getAbsoluteFileURL( aUserDirectoryURL
, "./.a/mydir/..",::osl::FileBase::E_None
, suAssume
);
537 void getAbsoluteFileURL::getAbsoluteFileURL_001_8()
539 rtl::OUString suAssume
= aUserDirectoryURL
.concat( rtl::OUString("/tmp/ok") );
541 check_getAbsoluteFileURL( aUserDirectoryURL
, "tmp//ok",::osl::FileBase::E_None
, suAssume
);
543 check_getAbsoluteFileURL( aUserDirectoryURL
, "tmp//ok",::osl::FileBase::E_INVAL
, suAssume
);
546 void getAbsoluteFileURL::getAbsoluteFileURL_002()
548 #if ( defined UNX ) //Link is not defined in Windows
549 ::rtl::OUString
aUStr_LnkFileSys( aTempDirectorySys
), aUStr_SrcFileSys( aTempDirectorySys
);
550 ( ( aUStr_LnkFileSys
+= aSlashURL
) += getCurrentPID() ) += ::rtl::OUString("/link.file");
551 ( ( aUStr_SrcFileSys
+= aSlashURL
) += getCurrentPID() ) += ::rtl::OUString("/canonical.name");
553 rtl::OString strLinkFileName
, strSrcFileName
;
554 strLinkFileName
= OUStringToOString( aUStr_LnkFileSys
, RTL_TEXTENCODING_ASCII_US
);
555 strSrcFileName
= OUStringToOString( aUStr_SrcFileSys
, RTL_TEXTENCODING_ASCII_US
);
557 createTestFile( aCanURL1
);
558 sal_Int32 fd
= symlink( strSrcFileName
.getStr(), strLinkFileName
.getStr() );
559 CPPUNIT_ASSERT( fd
== 0 );
560 rtl::OString sLnkURL
= OUStringToOString( aLnkURL1
, RTL_TEXTENCODING_ASCII_US
);
561 rtl::OUString suAssume
= aUserDirectoryURL
.concat( rtl::OUString("/canonical.name") );
562 check_getAbsoluteFileURL( aUserDirectoryURL
, sLnkURL
, ::osl::FileBase::E_None
, suAssume
);
563 deleteTestFile( aCanURL1
);
564 fd
= remove( strLinkFileName
.getStr() );
565 CPPUNIT_ASSERT( fd
== 0 );
568 //please see line# 930
569 void getAbsoluteFileURL::getAbsoluteFileURL_003()
572 void getAbsoluteFileURL::getAbsoluteFileURL_004()
574 //create two level directories under $Temp/PID/
575 ::rtl::OUString aUStrUpBase
= aUserDirectoryURL
+ "/test1";
576 createTestDirectory( aUStrUpBase
);
577 ::rtl::OUString aUStrBase
= aUserDirectoryURL
+ "/test1/dir1";
578 createTestDirectory( aUStrBase
);
580 ::rtl::OUString suAssume
= aUserDirectoryURL
.concat( ::rtl::OUString("/mytestfile") );
581 check_getAbsoluteFileURL( aUStrBase
, "../../mytestfile" , ::osl::FileBase::E_None
, suAssume
);
582 deleteTestDirectory( aUStrBase
);
583 deleteTestDirectory( aUStrUpBase
);
586 // testing two methods:
587 // static inline RC getSystemPathFromFileURL( const ::rtl::OUString& ustrFileURL,
588 // ::rtl::OUString& ustrSystemPath )
589 // static RC getFileURLFromSystemPath( const ::rtl::OUString & ustrSystemPath,
590 // ::rtl::OUString & ustrFileURL );
592 class SystemPath_FileURL
:public CppUnit::TestFixture
594 //::osl::FileBase aFileBase;
595 // ::rtl::OUString aUStr;
596 // ::osl::FileBase::RC nError;
598 //void check_getSystemPathFromFileURL(rtl::OString const& _sURL, ::osl::FileBase::RC _nAssumeError, rtl::OString const& _sAssumeResultStr);
599 void check_SystemPath_FileURL(rtl::OString
const& _sSource
, ::osl::FileBase::RC _nAssumeError
, rtl::OString
const& _sAssumeResultStr
, bool bDirection
= true );
600 void checkWNTBehaviour_getSystemPathFromFileURL(rtl::OString
const& _sURL
, ::osl::FileBase::RC _nAssumeError
, rtl::OString
const& _sWNTAssumeResultString
);
601 void checkUNXBehaviour_getSystemPathFromFileURL(rtl::OString
const& _sURL
, ::osl::FileBase::RC _nAssumeError
, rtl::OString
const& _sUnixAssumeResultString
);
602 void checkWNTBehaviour_getFileURLFromSystemPath(rtl::OString
const& _sSysPath
, ::osl::FileBase::RC _nAssumeError
, rtl::OString
const& _sWNTAssumeResultString
);
603 void checkUNXBehaviour_getFileURLFromSystemPath(rtl::OString
const& _sSysPath
, ::osl::FileBase::RC _nAssumeError
, rtl::OString
const& _sUnixAssumeResultString
);
607 void getSystemPathFromFileURL_001_1();
608 void getSystemPathFromFileURL_001_2();
609 void getSystemPathFromFileURL_001_21();
610 void getSystemPathFromFileURL_001_22();
611 void getSystemPathFromFileURL_001_3();
612 void getSystemPathFromFileURL_001_31();
613 void getSystemPathFromFileURL_001_4();
614 void getSystemPathFromFileURL_001_41();
615 void getSystemPathFromFileURL_001_5();
616 void getSystemPathFromFileURL_001_51();
617 void getSystemPathFromFileURL_001_52();
618 void getSystemPathFromFileURL_001_53();
619 void getSystemPathFromFileURL_001_6();
620 void getSystemPathFromFileURL_001_61();
621 void getSystemPathFromFileURL_001_7();
622 void getSystemPathFromFileURL_001_71();
623 void getSystemPathFromFileURL_001_8();
624 void getSystemPathFromFileURL_001_81();
625 void getSystemPathFromFileURL_001_9();
626 void getSystemPathFromFileURL_001_91();
627 void getSystemPathFromFileURL_001_92();
628 void getSystemPathFromFileURL_004();
629 void getSystemPathFromFileURL_005();
631 //test case fot getFileURLFromSystemPath
632 void getFileURLFromSystemPath_001();
633 void getFileURLFromSystemPath_002();
634 void getFileURLFromSystemPath_003();
635 void getFileURLFromSystemPath_004();
636 void getFileURLFromSystemPath_005();
638 CPPUNIT_TEST_SUITE( SystemPath_FileURL
);
639 CPPUNIT_TEST( getSystemPathFromFileURL_001_1
);
640 CPPUNIT_TEST( getSystemPathFromFileURL_001_2
);
641 CPPUNIT_TEST( getSystemPathFromFileURL_001_21
);
642 CPPUNIT_TEST( getSystemPathFromFileURL_001_22
);
643 CPPUNIT_TEST( getSystemPathFromFileURL_001_3
);
644 CPPUNIT_TEST( getSystemPathFromFileURL_001_31
);
645 CPPUNIT_TEST( getSystemPathFromFileURL_001_4
);
646 CPPUNIT_TEST( getSystemPathFromFileURL_001_41
);
647 CPPUNIT_TEST( getSystemPathFromFileURL_001_5
);
648 CPPUNIT_TEST( getSystemPathFromFileURL_001_51
);
649 CPPUNIT_TEST( getSystemPathFromFileURL_001_52
);
650 CPPUNIT_TEST( getSystemPathFromFileURL_001_53
);
651 CPPUNIT_TEST( getSystemPathFromFileURL_001_6
);
652 CPPUNIT_TEST( getSystemPathFromFileURL_001_61
);
653 CPPUNIT_TEST( getSystemPathFromFileURL_001_7
);
654 CPPUNIT_TEST( getSystemPathFromFileURL_001_71
);
655 CPPUNIT_TEST( getSystemPathFromFileURL_001_8
);
656 CPPUNIT_TEST( getSystemPathFromFileURL_001_81
);
657 CPPUNIT_TEST( getSystemPathFromFileURL_001_9
);
658 CPPUNIT_TEST( getSystemPathFromFileURL_001_91
);
659 CPPUNIT_TEST( getSystemPathFromFileURL_001_92
);
660 CPPUNIT_TEST( getSystemPathFromFileURL_004
);
661 CPPUNIT_TEST( getSystemPathFromFileURL_005
);
662 CPPUNIT_TEST( getFileURLFromSystemPath_001
);
663 CPPUNIT_TEST( getFileURLFromSystemPath_002
);
664 CPPUNIT_TEST( getFileURLFromSystemPath_003
);
665 CPPUNIT_TEST( getFileURLFromSystemPath_004
);
666 CPPUNIT_TEST( getFileURLFromSystemPath_005
);
667 CPPUNIT_TEST_SUITE_END();
668 };// class SystemPath_FileURL
670 // if bDirection==sal_True, check getSystemPathFromFileURL
671 // if bDirection==sal_False, check getFileURLFromSystemPath
672 void SystemPath_FileURL::check_SystemPath_FileURL(rtl::OString
const& _sSource
, ::osl::FileBase::RC _nAssumeError
, rtl::OString
const& _sAssumeResultStr
, bool bDirection
)
674 // PRE: URL as String
675 rtl::OUString suSource
;
677 suSource
= rtl::OStringToOUString(_sSource
, RTL_TEXTENCODING_UTF8
);
678 ::osl::FileBase::RC nError
;
680 nError
= osl::FileBase::getSystemPathFromFileURL( suSource
, suStr
);
682 nError
= osl::FileBase::getFileURLFromSystemPath( suSource
, suStr
);
684 // if the given string is gt length 0,
685 // we check also this string
686 rtl::OString sStr
= rtl::OUStringToOString(suStr
, RTL_TEXTENCODING_UTF8
);
687 rtl::OString sError
= errorToString(nError
);
689 printf("getSystemPathFromFileURL('%s') deliver system path: '%s', error '%s'\n", _sSource
.getStr(), sStr
.getStr(), sError
.getStr() );
691 printf("getFileURLFromSystemPath('%s') deliver File URL: '%s', error '%s'\n", _sSource
.getStr(), sStr
.getStr(), sError
.getStr() );
693 // rtl::OUString suStrEncode = rtl::Uri::encode(suStr, rtl_UriCharClassUnoParamValue, rtl_UriEncodeKeepEscapes, RTL_TEXTENCODING_UTF8);
694 // sStr = rtl::OUStringToOString(suStr, RTL_TEXTENCODING_UTF8);
695 // printf("UTF8: %s\n", sStr.getStr() );
697 if (!_sAssumeResultStr
.isEmpty())
699 bool bStrAreEqual
= _sAssumeResultStr
.equals(sStr
);
700 CPPUNIT_ASSERT_MESSAGE( "Assumption is wrong",
701 nError
== _nAssumeError
&& bStrAreEqual
);
705 CPPUNIT_ASSERT_MESSAGE( "Assumption is wrong", nError
== _nAssumeError
);
708 void SystemPath_FileURL::checkWNTBehaviour_getSystemPathFromFileURL(rtl::OString
const& _sURL
, ::osl::FileBase::RC _nAssumeError
, rtl::OString
const& _sWNTAssumeResultString
)
711 check_SystemPath_FileURL(_sURL
, _nAssumeError
, _sWNTAssumeResultString
);
715 (void)_sWNTAssumeResultString
;
719 void SystemPath_FileURL::checkUNXBehaviour_getSystemPathFromFileURL(rtl::OString
const& _sURL
, ::osl::FileBase::RC _nAssumeError
, rtl::OString
const& _sUnixAssumeResultString
)
722 check_SystemPath_FileURL(_sURL
, _nAssumeError
, _sUnixAssumeResultString
);
726 (void)_sUnixAssumeResultString
;
730 void SystemPath_FileURL::checkWNTBehaviour_getFileURLFromSystemPath(rtl::OString
const& _sSysPath
, ::osl::FileBase::RC _nAssumeError
, rtl::OString
const& _sWNTAssumeResultString
)
733 check_SystemPath_FileURL(_sSysPath
, _nAssumeError
, _sWNTAssumeResultString
, sal_False
);
737 (void)_sWNTAssumeResultString
;
741 void SystemPath_FileURL::checkUNXBehaviour_getFileURLFromSystemPath(rtl::OString
const& _sSysPath
, ::osl::FileBase::RC _nAssumeError
, rtl::OString
const& _sUnixAssumeResultString
)
744 check_SystemPath_FileURL(_sSysPath
, _nAssumeError
, _sUnixAssumeResultString
, false );
748 (void)_sUnixAssumeResultString
;
752 /** LLA: Test for getSystemPathFromFileURL()
753 this test is splitted into 2 different OS tests,
754 the first function checkUNXBehaviour... runs only on Unix based Systems,
755 the second only on windows based systems
756 the first parameter are a file URL where we want to get the system path of,
757 the second parameter is the assumed error of the osl_getSystemPathFromFileURL() function,
758 the third parameter is the assumed result string, the string will only test, if its length is greater 0
761 void SystemPath_FileURL::getSystemPathFromFileURL_001_1()
763 rtl::OString
sURL("");
764 checkUNXBehaviour_getSystemPathFromFileURL(sURL
, osl::FileBase::E_INVAL
, "");
765 checkWNTBehaviour_getSystemPathFromFileURL(sURL
, osl::FileBase::E_INVAL
, "");
768 void SystemPath_FileURL::getSystemPathFromFileURL_001_2()
770 rtl::OString
sURL("/");
771 checkUNXBehaviour_getSystemPathFromFileURL(sURL
, osl::FileBase::E_INVAL
, "");
772 checkWNTBehaviour_getSystemPathFromFileURL(sURL
, osl::FileBase::E_None
, "\\");
774 void SystemPath_FileURL::getSystemPathFromFileURL_001_21()
776 // rtl::OString sURL("%2f");
777 rtl::OString
sURL("%2F");
778 checkUNXBehaviour_getSystemPathFromFileURL(sURL
, osl::FileBase::E_None
, "/"); // LLA: this is may be a BUG
779 checkWNTBehaviour_getSystemPathFromFileURL(sURL
, osl::FileBase::E_INVAL
, "");
781 void SystemPath_FileURL::getSystemPathFromFileURL_001_22()
783 rtl::OString
sURL("file:///tmp%2Fmydir");
784 checkUNXBehaviour_getSystemPathFromFileURL(sURL
, osl::FileBase::E_INVAL
, "");
785 checkWNTBehaviour_getSystemPathFromFileURL(sURL
, osl::FileBase::E_INVAL
, "");
787 void SystemPath_FileURL::getSystemPathFromFileURL_001_3()
789 rtl::OString
sURL("a");
790 checkUNXBehaviour_getSystemPathFromFileURL(sURL
, osl::FileBase::E_None
, "a");
791 checkWNTBehaviour_getSystemPathFromFileURL(sURL
, osl::FileBase::E_None
, "a");
793 void SystemPath_FileURL::getSystemPathFromFileURL_001_31()
795 rtl::OString
sURL("tmpname");
796 checkUNXBehaviour_getSystemPathFromFileURL(sURL
, osl::FileBase::E_None
, "tmpname");
797 checkWNTBehaviour_getSystemPathFromFileURL(sURL
, osl::FileBase::E_None
, "tmpname");
799 void SystemPath_FileURL::getSystemPathFromFileURL_001_4()
801 rtl::OString
sURL("file://");
802 checkUNXBehaviour_getSystemPathFromFileURL(sURL
, osl::FileBase::E_None
, "");
803 checkWNTBehaviour_getSystemPathFromFileURL(sURL
, osl::FileBase::E_INVAL
, "");
805 void SystemPath_FileURL::getSystemPathFromFileURL_001_41()
807 rtl::OString
sURL("file://localhost/tmp");
808 checkUNXBehaviour_getSystemPathFromFileURL(sURL
, osl::FileBase::E_None
, "");
809 checkWNTBehaviour_getSystemPathFromFileURL(sURL
, osl::FileBase::E_INVAL
, "");
811 void SystemPath_FileURL::getSystemPathFromFileURL_001_5()
813 rtl::OString
sURL("file:///tmp");
814 checkUNXBehaviour_getSystemPathFromFileURL(sURL
, osl::FileBase::E_None
, "/tmp");
815 checkWNTBehaviour_getSystemPathFromFileURL(sURL
, osl::FileBase::E_INVAL
, "");
817 void SystemPath_FileURL::getSystemPathFromFileURL_001_51()
819 rtl::OString
sURL("file://c:/tmp");
820 checkUNXBehaviour_getSystemPathFromFileURL(sURL
, osl::FileBase::E_None
, "c:/tmp"); // LLA: this is may be a BUG
821 checkWNTBehaviour_getSystemPathFromFileURL(sURL
, osl::FileBase::E_INVAL
, "");
823 void SystemPath_FileURL::getSystemPathFromFileURL_001_52()
825 rtl::OString
sURL("file:///c:/tmp");
826 checkUNXBehaviour_getSystemPathFromFileURL(sURL
, osl::FileBase::E_None
, "/c:/tmp");
827 checkWNTBehaviour_getSystemPathFromFileURL(sURL
, osl::FileBase::E_None
, "c:\\tmp");
829 void SystemPath_FileURL::getSystemPathFromFileURL_001_53()
831 // LLA: is this a legal file path?
832 rtl::OString
sURL("file:///c|/tmp");
833 checkUNXBehaviour_getSystemPathFromFileURL(sURL
, osl::FileBase::E_None
, "/c|/tmp");
834 checkWNTBehaviour_getSystemPathFromFileURL(sURL
, osl::FileBase::E_None
, "c:\\tmp");
836 void SystemPath_FileURL::getSystemPathFromFileURL_001_6()
838 rtl::OString
sURL("file:///tmp/first");
839 checkUNXBehaviour_getSystemPathFromFileURL(sURL
, osl::FileBase::E_None
, "/tmp/first");
840 checkWNTBehaviour_getSystemPathFromFileURL(sURL
, osl::FileBase::E_INVAL
, "");
842 void SystemPath_FileURL::getSystemPathFromFileURL_001_61()
844 rtl::OString
sURL("file:///c:/tmp/first");
845 checkUNXBehaviour_getSystemPathFromFileURL(sURL
, osl::FileBase::E_None
, "/c:/tmp/first");
846 checkWNTBehaviour_getSystemPathFromFileURL(sURL
, osl::FileBase::E_None
, "c:\\tmp\\first");
848 void SystemPath_FileURL::getSystemPathFromFileURL_001_7()
850 rtl::OString
sURL("file:///tmp/../second");
851 checkUNXBehaviour_getSystemPathFromFileURL(sURL
, osl::FileBase::E_None
, "/tmp/../second"); // LLA: may be a BUG
852 checkWNTBehaviour_getSystemPathFromFileURL(sURL
, osl::FileBase::E_INVAL
, "");
854 void SystemPath_FileURL::getSystemPathFromFileURL_001_71()
856 rtl::OString
sURL("file:///c:/tmp/../second");
857 checkUNXBehaviour_getSystemPathFromFileURL(sURL
, osl::FileBase::E_None
, "/c:/tmp/../second");
858 checkWNTBehaviour_getSystemPathFromFileURL(sURL
, osl::FileBase::E_None
, "c:\\tmp\\..\\second");
860 void SystemPath_FileURL::getSystemPathFromFileURL_001_8()
862 rtl::OString
sURL("../tmp");
863 checkUNXBehaviour_getSystemPathFromFileURL(sURL
, osl::FileBase::E_None
, "../tmp");
864 checkWNTBehaviour_getSystemPathFromFileURL(sURL
, osl::FileBase::E_None
, "..\\tmp");
866 void SystemPath_FileURL::getSystemPathFromFileURL_001_81()
868 rtl::OString
sURL("file://~/tmp");
870 home_path
= getenv("HOME");
871 rtl::OString
expResult(home_path
);
873 checkUNXBehaviour_getSystemPathFromFileURL(sURL
, osl::FileBase::E_None
, expResult
);
874 // checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "\\tmp");
876 void SystemPath_FileURL::getSystemPathFromFileURL_001_9()
878 rtl::OString
sURL("file:///tmp/first%20second");
879 checkUNXBehaviour_getSystemPathFromFileURL(sURL
, osl::FileBase::E_None
, "/tmp/first second");
880 checkWNTBehaviour_getSystemPathFromFileURL(sURL
, osl::FileBase::E_INVAL
, "");
882 void SystemPath_FileURL::getSystemPathFromFileURL_001_91()
884 rtl::OString
sURL("file:///c:/tmp/first%20second");
885 checkUNXBehaviour_getSystemPathFromFileURL(sURL
, osl::FileBase::E_None
, "/c:/tmp/first second");
886 checkWNTBehaviour_getSystemPathFromFileURL(sURL
, osl::FileBase::E_None
, "c:\\tmp\\first second");
889 void SystemPath_FileURL::getSystemPathFromFileURL_001_92()
891 rtl::OString
sURL("ca@#;+.,$///78no%01ni..name");
892 checkUNXBehaviour_getSystemPathFromFileURL(sURL
, osl::FileBase::E_None
, "");
893 checkWNTBehaviour_getSystemPathFromFileURL(sURL
, osl::FileBase::E_INVAL
, "");
897 void SystemPath_FileURL::getSystemPathFromFileURL_004()
899 ::rtl::OUString aUStr
;
900 ::rtl::OUString
aUNormalURL( aTmpName6
);
901 ::rtl::OUString
aUResultURL ( aSysPath4
);
902 ::osl::FileBase::RC nError
= osl::FileBase::getSystemPathFromFileURL( aUNormalURL
, aUStr
);
904 bool bOk
= compareFileName( aUStr
, aUResultURL
);
906 ::rtl::OString
sError("test for getSystemPathFromFileURL(' ");
907 sError
+= ::rtl::OUStringToOString( aUNormalURL
, RTL_TEXTENCODING_ASCII_US
);
908 sError
+= " ') function:use an absolute file URL, ";
909 sError
+= outputError(::rtl::OUStringToOString( aUStr
, RTL_TEXTENCODING_ASCII_US
),
910 ::rtl::OUStringToOString( aUResultURL
, RTL_TEXTENCODING_ASCII_US
));
912 CPPUNIT_ASSERT_MESSAGE(sError
.getStr(), ( osl::FileBase::E_None
== nError
) && bOk
);
916 //CJK characters case
917 void SystemPath_FileURL::getSystemPathFromFileURL_005()
919 ::rtl::OUString aUStr
;
920 createTestDirectory( aTmpName10
);
921 ::rtl::OUString
aUNormalURL( aTmpName10
);
922 ::rtl::OUString
aUResultURL ( aSysPath5
);
924 ::osl::FileBase::RC nError
= osl::FileBase::getSystemPathFromFileURL( aUNormalURL
, aUStr
);
926 bool bOk
= compareFileName( aUStr
, aUResultURL
);
928 ::rtl::OString
sError("test for getSystemPathFromFileURL(' ");
929 sError
+= ::rtl::OUStringToOString( aUNormalURL
, RTL_TEXTENCODING_ASCII_US
);
930 sError
+= " ') function:use a CJK coded absolute URL, ";
931 sError
+= outputError(::rtl::OUStringToOString( aUStr
, RTL_TEXTENCODING_ASCII_US
),
932 ::rtl::OUStringToOString( aUResultURL
, RTL_TEXTENCODING_ASCII_US
));
933 deleteTestDirectory( aTmpName10
);
935 CPPUNIT_ASSERT_MESSAGE( sError
.getStr(), ( osl::FileBase::E_None
== nError
) && bOk
);
938 void SystemPath_FileURL::getFileURLFromSystemPath_001()
940 rtl::OString
sSysPath("~/tmp");
942 home_path
= getenv("HOME");
943 rtl::OString
expResult(home_path
);
944 expResult
= "file://"+ expResult
+ "/tmp";
945 checkUNXBehaviour_getFileURLFromSystemPath(sSysPath
, osl::FileBase::E_None
, expResult
);
946 checkWNTBehaviour_getFileURLFromSystemPath(sSysPath
, osl::FileBase::E_None
, "~/tmp");
948 void SystemPath_FileURL::getFileURLFromSystemPath_002()
950 rtl::OString
sSysPath("c:/tmp");
951 checkUNXBehaviour_getFileURLFromSystemPath(sSysPath
, osl::FileBase::E_None
, "c:/tmp");
952 checkWNTBehaviour_getFileURLFromSystemPath(sSysPath
, osl::FileBase::E_None
, "file:///c:/tmp");
954 void SystemPath_FileURL::getFileURLFromSystemPath_003()
956 rtl::OString
sSysPath("file:///temp");
957 checkUNXBehaviour_getFileURLFromSystemPath(sSysPath
, osl::FileBase::E_INVAL
, "");
958 checkWNTBehaviour_getFileURLFromSystemPath(sSysPath
, osl::FileBase::E_INVAL
, "");
960 void SystemPath_FileURL::getFileURLFromSystemPath_004()
962 rtl::OString
sSysPath("//tmp//first start");
963 checkUNXBehaviour_getFileURLFromSystemPath(sSysPath
, osl::FileBase::E_None
, "file:///tmp/first%20start");
964 checkWNTBehaviour_getFileURLFromSystemPath(sSysPath
, osl::FileBase::E_INVAL
, "");
966 void SystemPath_FileURL::getFileURLFromSystemPath_005()
968 rtl::OString
sSysPath("");
969 checkUNXBehaviour_getFileURLFromSystemPath(sSysPath
, osl::FileBase::E_INVAL
, "");
970 checkWNTBehaviour_getFileURLFromSystemPath(sSysPath
, osl::FileBase::E_INVAL
, "");
972 // start with "~user", not impletment
973 // void SystemPath_FileURL::getFileURLFromSystemPath_006()
975 // testing the method
976 // static inline RC searchFileURL( const ::rtl::OUString& ustrFileName,
977 // const ::rtl::OUString& ustrSearchPath,
978 // ::rtl::OUString& ustrFileURL )
980 class searchFileURL
:public CppUnit::TestFixture
982 //::osl::FileBase aFileBase;
983 ::rtl::OUString aUStr
;
984 ::osl::FileBase::RC nError1
, nError2
, nError3
,nError4
;
989 : nError1(FileBase::E_None
)
990 , nError2(FileBase::E_None
)
991 , nError3(FileBase::E_None
)
992 , nError4(FileBase::E_None
) {}
994 void searchFileURL_001()
996 /* search file is passed by system filename */
997 nError1
= ::osl::FileBase::searchFileURL( aTmpName1
, aUserDirectorySys
, aUStr
);
998 /* search file is passed by full qualified file URL */
999 nError2
= ::osl::FileBase::searchFileURL( aCanURL1
, aUserDirectorySys
, aUStr
);
1000 /* search file is passed by relative file path */
1001 nError3
= ::osl::FileBase::searchFileURL( aRelURL4
, aUserDirectorySys
, aUStr
);
1003 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) ",
1004 ( osl::FileBase::E_NOENT
== nError1
) &&
1005 ( osl::FileBase::E_NOENT
== nError2
) &&
1006 ( osl::FileBase::E_NOENT
== nError3
));
1009 void searchFileURL_002()
1011 /* search file is passed by system filename */
1012 nError1
= ::osl::FileBase::searchFileURL( aTempDirectorySys
, aRootSys
, aUStr
);
1013 bool bOk1
= compareFileName( aUStr
, aTempDirectoryURL
);
1014 /* search file is passed by full qualified file URL */
1015 nError2
= ::osl::FileBase::searchFileURL( aTempDirectoryURL
, aRootSys
, aUStr
);
1016 bool bOk2
= compareFileName( aUStr
, aTempDirectoryURL
);
1017 /* search file is passed by relative file path */
1018 nError3
= ::osl::FileBase::searchFileURL( aRelURL5
, aRootSys
, aUStr
);
1019 bool bOk3
= compareFileName( aUStr
, aTempDirectoryURL
);
1020 /* search file is passed by an exist file */
1021 createTestFile( aCanURL1
);
1022 nError4
= ::osl::FileBase::searchFileURL( aCanURL4
, aUserDirectorySys
, aUStr
);
1023 bool bOk4
= compareFileName( aUStr
, aCanURL1
);
1024 deleteTestFile( aCanURL1
);
1026 CPPUNIT_ASSERT_MESSAGE( "test for searchFileURL function: system filename/URL filename/relative path, system directory, searched file already exist.",
1027 ( osl::FileBase::E_None
== nError1
) &&
1028 ( osl::FileBase::E_None
== nError2
) &&
1029 ( osl::FileBase::E_None
== nError3
) &&
1030 ( osl::FileBase::E_None
== nError4
) &&
1031 bOk1
&& bOk2
&& bOk3
&& bOk4
);
1034 void searchFileURL_003()
1036 OSLTEST_DECLARE( SystemPathList
, TEST_PLATFORM_ROOT
":" TEST_PLATFORM_ROOT TEST_PLATFORM_TEMP
":" TEST_PLATFORM_ROOT
"system/path" );
1037 nError1
= ::osl::FileBase::searchFileURL( aUserDirectoryURL
, aSystemPathList
, aUStr
);
1038 bool bOk
= compareFileName( aUStr
, aUserDirectoryURL
);
1039 CPPUNIT_ASSERT_MESSAGE( "test for searchFileURL function: search directory is a list of system paths",
1040 ( osl::FileBase::E_None
== nError1
) &&
1044 void searchFileURL_004()
1046 OSLTEST_DECLARE( SystemPathList
, TEST_PLATFORM_ROOT PATH_LIST_DELIMITER TEST_PLATFORM_ROOT TEST_PLATFORM_TEMP PATH_LIST_DELIMITER TEST_PLATFORM_ROOT
"system/path/../name" );
1047 nError1
= ::osl::FileBase::searchFileURL( aUserDirectoryURL
, aSystemPathList
, aUStr
);
1048 bool bOk
= compareFileName( aUStr
, aUserDirectoryURL
);
1049 CPPUNIT_ASSERT_MESSAGE( "test for searchFileURL function: search directory is a list of system paths",
1050 ( osl::FileBase::E_None
== nError1
) &&
1054 void searchFileURL_005()
1056 nError1
= ::osl::FileBase::searchFileURL( aUserDirectoryURL
, aNullURL
, aUStr
);
1057 bool bOk
= compareFileName( aUStr
, aUserDirectoryURL
);
1058 CPPUNIT_ASSERT_MESSAGE( "test for searchFileURL function: search directory is NULL",
1059 ( osl::FileBase::E_None
== nError1
) &&
1063 CPPUNIT_TEST_SUITE( searchFileURL
);
1064 CPPUNIT_TEST( searchFileURL_001
);
1065 CPPUNIT_TEST( searchFileURL_002
);
1066 CPPUNIT_TEST( searchFileURL_003
);
1067 CPPUNIT_TEST( searchFileURL_004
);
1068 CPPUNIT_TEST( searchFileURL_005
);
1069 CPPUNIT_TEST_SUITE_END();
1070 };// class searchFileURL
1072 // testing the method
1073 // static inline RC getTempDirURL( ::rtl::OUString& ustrTempDirURL )
1075 class getTempDirURL
:public CppUnit::TestFixture
1077 //::osl::FileBase aFileBase;
1078 ::rtl::OUString aUStr
;
1079 ::osl::FileBase::RC nError
;
1082 getTempDirURL() :nError(FileBase::E_None
) {}
1084 void setUp() SAL_OVERRIDE
1086 nError
= FileBase::getTempDirURL( aUStr
);
1089 void tearDown() SAL_OVERRIDE
1094 void getTempDirURL_001()
1097 CPPUNIT_ASSERT_MESSAGE( "test for getTempDirURL function: excution",
1098 ( osl::FileBase::E_None
== nError
) );
1101 void getTempDirURL_002()
1103 CPPUNIT_ASSERT_MESSAGE( "test for getTempDirURL function: test for open and write access rights",
1104 checkDirectory( aUStr
, osl_Check_Mode_OpenAccess
) &&
1105 checkDirectory( aUStr
, osl_Check_Mode_ReadAccess
) &&
1106 checkDirectory( aUStr
,osl_Check_Mode_WriteAccess
) );
1109 CPPUNIT_TEST_SUITE( getTempDirURL
);
1110 CPPUNIT_TEST( getTempDirURL_001
);
1111 CPPUNIT_TEST( getTempDirURL_002
);
1112 CPPUNIT_TEST_SUITE_END();
1113 };// class getTempDirURL
1115 // testing the method
1116 // static inline RC createTempFile( ::rtl::OUString* pustrDirectoryURL,
1117 // oslFileHandle* pHandle,
1118 // ::rtl::OUString* pustrTempFileURL)
1120 class createTempFile
:public CppUnit::TestFixture
1122 //::osl::FileBase aFileBase;
1123 ::osl::FileBase::RC nError1
, nError2
;
1126 oslFileHandle
*pHandle
;
1127 ::rtl::OUString
*pUStr_DirURL
;
1128 ::rtl::OUString
*pUStr_FileURL
;
1132 : nError1(FileBase::E_None
)
1133 , nError2(FileBase::E_None
)
1136 , pUStr_DirURL(NULL
)
1137 , pUStr_FileURL(NULL
)
1142 void setUp() SAL_OVERRIDE
1144 pHandle
= new oslFileHandle();
1145 pUStr_DirURL
= new ::rtl::OUString( aUserDirectoryURL
);
1146 pUStr_FileURL
= new ::rtl::OUString();
1147 //*pUStr_DirURL = aUserDirectoryURL; /// create temp file in /tmp/PID or c:\temp\PID.*/
1150 void tearDown() SAL_OVERRIDE
1152 delete pUStr_DirURL
;
1153 delete pUStr_FileURL
;
1158 void createTempFile_001()
1160 nError1
= FileBase::createTempFile( pUStr_DirURL
, pHandle
, pUStr_FileURL
);
1161 ::osl::File
testFile( *pUStr_FileURL
);
1162 nError2
= testFile
.open( osl_File_OpenFlag_Create
);
1163 if ( osl::FileBase::E_EXIST
== nError2
) {
1164 osl_closeFile( *pHandle
);
1165 deleteTestFile( *pUStr_FileURL
);
1168 CPPUNIT_ASSERT_MESSAGE( "test for createTempFile function: create temp file and test the existence",
1169 ( osl::FileBase::E_None
== nError1
) && ( pHandle
!= NULL
) && ( osl::FileBase::E_EXIST
== nError2
) );
1172 void createTempFile_002()
1175 nError1
= FileBase::createTempFile( pUStr_DirURL
, pHandle
, pUStr_FileURL
);
1176 ::osl::File
testFile( *pUStr_FileURL
);
1177 nError2
= testFile
.open( osl_File_OpenFlag_Create
);
1179 CPPUNIT_ASSERT_MESSAGE( "createTempFile function: create a temp file, but it does not exist",
1180 ( osl::FileBase::E_None
== nError1
) && ( pHandle
!= NULL
) &&
1181 ( osl::FileBase::E_EXIST
== nError2
) );
1183 //check file if have the write permission
1184 if ( osl::FileBase::E_EXIST
== nError2
) {
1185 bOK
= ifFileCanWrite( *pUStr_FileURL
);
1186 osl_closeFile( *pHandle
);
1187 deleteTestFile( *pUStr_FileURL
);
1190 CPPUNIT_ASSERT_MESSAGE( "test for open and write access rights, in (W32), it did not have write access right, but it should be writtenable.",
1194 void createTempFile_003()
1196 nError1
= FileBase::createTempFile( pUStr_DirURL
, pHandle
, 0 );
1197 //the temp file will be removed when return from createTempFile
1198 bOK
= (pHandle
!= NULL
&& nError1
== osl::FileBase::E_None
);
1200 osl_closeFile( *pHandle
);
1202 CPPUNIT_ASSERT_MESSAGE( "test for createTempFile function: set pUStrFileURL to 0 to let it remove the file after call.",
1203 ( ::osl::FileBase::E_None
== nError1
) && bOK
);
1205 void createTempFile_004()
1207 nError1
= FileBase::createTempFile( pUStr_DirURL
, 0, pUStr_FileURL
);
1208 bOK
= ( pUStr_FileURL
!= 0);
1209 CPPUNIT_ASSERT(bOK
);
1210 ::osl::File
testFile( *pUStr_FileURL
);
1211 nError2
= testFile
.open( osl_File_OpenFlag_Create
);
1212 deleteTestFile( *pUStr_FileURL
);
1213 CPPUNIT_ASSERT_MESSAGE( "createTempFile function: create a temp file, but it does not exist",
1214 ( osl::FileBase::E_None
== nError1
) && ( osl::FileBase::E_EXIST
== nError2
) && bOK
);
1218 CPPUNIT_TEST_SUITE( createTempFile
);
1219 CPPUNIT_TEST( createTempFile_001
);
1220 CPPUNIT_TEST( createTempFile_002
);
1221 CPPUNIT_TEST( createTempFile_003
);
1222 CPPUNIT_TEST( createTempFile_004
);
1223 CPPUNIT_TEST_SUITE_END();
1224 };// class createTempFile
1226 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileBase::getAbsoluteFileURL
, "osl_FileBase" );
1227 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileBase::SystemPath_FileURL
, "osl_FileBase" );
1228 // CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileBase::getFileURLFromSystemPath, "osl_FileBase" );
1229 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileBase::searchFileURL
, "osl_FileBase" );
1230 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileBase::getTempDirURL
, "osl_FileBase" );
1231 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileBase::createTempFile
, "osl_FileBase" );
1232 }// namespace osl_FileBase
1234 namespace osl_FileStatus
1237 // testing the method
1238 // FileStatus( sal_uInt32 nMask ): _nMask( nMask )
1240 class ctors
: public CppUnit::TestFixture
1242 ::rtl::OUString aUStr
;
1243 ::osl::FileBase::RC nError1
;
1244 ::osl::DirectoryItem rItem
;
1247 ctors() :nError1(FileBase::E_None
) {}
1249 void setUp() SAL_OVERRIDE
1251 // create a tempfile in $TEMP/tmpdir/tmpname.
1252 createTestDirectory( aTmpName3
);
1253 createTestFile( aTmpName4
);
1255 Directory
pDir( aTmpName3
);
1256 nError1
= pDir
.open();
1257 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
1258 nError1
= pDir
.getNextItem( rItem
, 0 );
1259 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
1262 Directory aDir( aTmpName3 );
1263 nError1 = aDir.open();
1264 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
1265 nError1 = aDir.getNextItem( rItem, 0 );
1266 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
1271 void tearDown() SAL_OVERRIDE
1273 // remove the tempfile in $TEMP/tmpdir/tmpname.
1274 deleteTestFile( aTmpName4
);
1275 deleteTestDirectory( aTmpName3
);
1281 ::osl::FileStatus
rFileStatus( osl_FileStatus_Mask_All
);
1282 nError1
= rItem
.getFileStatus( rFileStatus
);
1283 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
1284 aUStr
= rFileStatus
.getFileName();
1286 CPPUNIT_ASSERT_MESSAGE( "test for ctors function: mask all and see the file name",
1287 compareFileName( aUStr
, aTmpName2
) );
1292 ::osl::FileStatus
rFileStatus( 0 );
1293 nError1
= rItem
.getFileStatus( rFileStatus
);
1294 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
1295 aUStr
= rFileStatus
.getFileName();
1297 CPPUNIT_ASSERT_MESSAGE( "test for ctors function: mask is empty",
1298 compareFileName( aUStr
, aNullURL
) );
1301 CPPUNIT_TEST_SUITE( ctors
);
1302 CPPUNIT_TEST( ctors_001
);
1303 CPPUNIT_TEST( ctors_002
);
1304 CPPUNIT_TEST_SUITE_END();
1307 // testing the method
1308 // inline sal_Bool isValid( sal_uInt32 nMask ) const
1310 class isValid
: public CppUnit::TestFixture
1312 ::osl::Directory
*pDir
;
1313 ::osl::DirectoryItem rItem_file
, rItem_link
;
1322 void setUp() SAL_OVERRIDE
1324 // create a tempfile in $TEMP/tmpdir/tmpname.
1325 createTestDirectory( aTmpName3
);
1326 createTestFile( aTmpName4
);
1328 pDir
= new Directory( aTmpName3
);
1329 ::osl::FileBase::RC nError1
= pDir
->open();
1330 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
1331 nError1
= pDir
->getNextItem( rItem_file
, 1 );
1332 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
1335 void tearDown() SAL_OVERRIDE
1337 ::osl::FileBase::RC nError1
= pDir
->close();
1339 CPPUNIT_ASSERT_MESSAGE( errorToStr(nError1
).getStr(), ::osl::FileBase::E_None
== nError1
);
1341 // remove the tempfile in $TEMP/tmpdir/tmpname.
1342 deleteTestFile( aTmpName4
);
1343 deleteTestDirectory( aTmpName3
);
1349 sal_uInt32 mask
= 0;
1350 ::osl::FileStatus
rFileStatus( mask
);
1351 ::osl::FileBase::RC nError1
= rItem_file
.getFileStatus( rFileStatus
);
1352 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
1353 bool bOk
= rFileStatus
.isValid( mask
);
1355 CPPUNIT_ASSERT_MESSAGE( "test for isValid function: no fields specified",
1359 void check_FileStatus(::osl::FileStatus
const& _aStatus
)
1362 if (_aStatus
.isValid(osl_FileStatus_Mask_Type
))
1366 if (_aStatus
.isValid(osl_FileStatus_Mask_Attributes
))
1368 sStat
+= "attributes ";
1370 if (_aStatus
.isValid(osl_FileStatus_Mask_CreationTime
))
1374 if (_aStatus
.isValid(osl_FileStatus_Mask_AccessTime
))
1378 if (_aStatus
.isValid(osl_FileStatus_Mask_ModifyTime
))
1382 if (_aStatus
.isValid(osl_FileStatus_Mask_FileSize
))
1384 sStat
+= "filesize ";
1386 if (_aStatus
.isValid(osl_FileStatus_Mask_FileName
))
1388 sStat
+= "filename ";
1390 if (_aStatus
.isValid(osl_FileStatus_Mask_FileURL
))
1392 sStat
+= "fileurl ";
1394 printf("mask: %s\n", sStat
.getStr());
1399 createTestFile( aTmpName6
);
1400 sal_uInt32 mask_file
= ( osl_FileStatus_Mask_Type
| osl_FileStatus_Mask_Attributes
|
1401 osl_FileStatus_Mask_CreationTime
| osl_FileStatus_Mask_AccessTime
|
1402 osl_FileStatus_Mask_ModifyTime
| osl_FileStatus_Mask_FileSize
|
1403 osl_FileStatus_Mask_FileName
| osl_FileStatus_Mask_FileURL
) ;
1404 ::osl::FileStatus
rFileStatus( mask_file
);
1405 ::osl::FileBase::RC nError1
= ::osl::DirectoryItem::get( aTmpName6
, rItem_file
);
1406 nError1
= rItem_file
.getFileStatus( rFileStatus
);
1408 CPPUNIT_ASSERT_MESSAGE( errorToStr(nError1
).getStr(), ::osl::FileBase::E_None
== nError1
);
1410 // LLA: this is wrong, we never should try to check on all masks
1412 // Second, it's not a bug, if a value is not valid, it's an unhandled feature.
1414 // sal_Bool bOk = rFileStatus.isValid( mask_file );
1416 check_FileStatus(rFileStatus
);
1417 deleteTestFile( aTmpName6
);
1419 // 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",
1420 // ( sal_True == bOk ) );
1423 //Link is not defined in Windows, and on Linux, we can not get the directory item of the link file
1424 // LLA: we have to differ to filesystems, normal filesystems support links (EXT2, ...)
1425 // castrated filesystems don't (FAT, FAT32)
1426 // Windows NT NTFS support links, but the windows api don't :-(
1431 // ::osl::FileBase::RC nError;
1434 ::rtl::OUString
aUStr_LnkFileSys( aTempDirectorySys
), aUStr_SrcFileSys( aTempDirectorySys
);
1435 ( ( aUStr_LnkFileSys
+= aSlashURL
) += getCurrentPID() ) += ::rtl::OUString("/tmpdir/link.file");
1436 ( ( aUStr_SrcFileSys
+= aSlashURL
) += getCurrentPID() ) += ::rtl::OUString("/tmpdir/tmpname");
1438 rtl::OString strLinkFileName
;
1439 rtl::OString strSrcFileName
;
1440 strLinkFileName
= OUStringToOString( aUStr_LnkFileSys
, RTL_TEXTENCODING_ASCII_US
);
1441 strSrcFileName
= OUStringToOString( aUStr_SrcFileSys
, RTL_TEXTENCODING_ASCII_US
);
1443 //create a link file and link it to file "/tmp/PID/tmpdir/tmpname"
1444 fd
= symlink( strSrcFileName
.getStr(), strLinkFileName
.getStr() );
1445 CPPUNIT_ASSERT( fd
== 0 );
1447 // testDirectory is "/tmp/PID/tmpdir/"
1448 ::osl::Directory
testDirectory( aTmpName3
);
1449 ::osl::FileBase::RC nError1
= testDirectory
.open();
1450 ::rtl::OUString
aFileName ("link.file");
1453 nError1
= testDirectory
.getNextItem( rItem_link
, 4 );
1454 if (::osl::FileBase::E_None
== nError1
) {
1455 sal_uInt32 mask_link
= osl_FileStatus_Mask_FileName
| osl_FileStatus_Mask_LinkTargetURL
;
1456 ::osl::FileStatus
rFileStatus( mask_link
);
1457 rItem_link
.getFileStatus( rFileStatus
);
1458 if ( compareFileName( rFileStatus
.getFileName(), aFileName
) )
1460 //printf("find the link file");
1461 if ( rFileStatus
.isValid( osl_FileStatus_Mask_LinkTargetURL
) )
1472 fd
= remove( strLinkFileName
.getStr() );
1473 CPPUNIT_ASSERT( fd
== 0 );
1475 CPPUNIT_ASSERT_MESSAGE("test for isValid function: link file, check for LinkTargetURL",
1482 sal_uInt32 mask_file_all
= osl_FileStatus_Mask_All
;
1483 ::osl::FileStatus
rFileStatus_all( mask_file_all
);
1484 ::osl::FileBase::RC nError1
= rItem_file
.getFileStatus( rFileStatus_all
);
1485 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
1487 check_FileStatus(rFileStatus_all
);
1488 // LLA: this is wrong
1489 // sal_Bool bOk1 = rFileStatus_all.isValid( mask_file_all );
1491 sal_uInt32 mask_file_val
= osl_FileStatus_Mask_Validate
;
1492 ::osl::FileStatus
rFileStatus_val( mask_file_val
);
1493 nError1
= rItem_file
.getFileStatus( rFileStatus_val
);
1494 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
1495 // sal_Bool bOk2 = rFileStatus_val.isValid( mask_file_val );
1497 check_FileStatus(rFileStatus_val
);
1498 // 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).",
1499 // ( sal_False == bOk1 ) && ( sal_True == bOk2 ) );
1502 CPPUNIT_TEST_SUITE( isValid
);
1503 CPPUNIT_TEST( isValid_001
);
1504 CPPUNIT_TEST( isValid_002
);
1505 CPPUNIT_TEST( isValid_003
);
1506 CPPUNIT_TEST( isValid_004
);
1507 CPPUNIT_TEST_SUITE_END();
1510 // testing the method
1511 // inline Type getFileType() const
1513 class getFileType
: public CppUnit::TestFixture
1515 ::osl::FileBase::RC nError1
;
1517 ::osl::DirectoryItem m_aItem_1
, m_aItem_2
, m_aVolumeItem
, m_aFifoItem
;
1518 ::osl::DirectoryItem m_aLinkItem
, m_aSocketItem
, m_aSpecialItem
;
1521 getFileType() :nError1(FileBase::E_None
) {}
1523 void setUp() SAL_OVERRIDE
1525 // create a tempfile: $TEMP/tmpdir/tmpname.
1526 // a tempdirectory: $TEMP/tmpdir/tmpdir.
1527 // use $ROOT/staroffice as volume ---> use dev/fd as volume.
1528 // and get their directory item.
1529 createTestDirectory( aTmpName3
);
1530 createTestFile( aTmpName3
, aTmpName2
);
1531 createTestDirectory( aTmpName3
, aTmpName1
);
1533 std::unique_ptr
<Directory
> xDir( new Directory( aTmpName3
) );
1534 nError1
= xDir
->open();
1535 CPPUNIT_ASSERT_MESSAGE("open aTmpName3 failed!", ::osl::FileBase::E_None
== nError1
);
1536 //getNextItem can not assure which item retrieved
1537 nError1
= xDir
->getNextItem( m_aItem_1
, 1 );
1538 CPPUNIT_ASSERT_MESSAGE("get first item failed!", ::osl::FileBase::E_None
== nError1
);
1540 nError1
= xDir
->getNextItem( m_aItem_2
);
1541 CPPUNIT_ASSERT_MESSAGE("get second item failed!", ::osl::FileBase::E_None
== nError1
);
1543 //mindy: failed on my RH9,so removed temporaly
1544 //nError1 = ::osl::DirectoryItem::get( aVolURL2, m_aVolumeItem );
1545 //CPPUNIT_ASSERT_MESSAGE("get volume item failed!", ::osl::FileBase::E_None == nError1 );
1549 void tearDown() SAL_OVERRIDE
1551 // remove all in $TEMP/tmpdir.
1552 deleteTestDirectory( aTmpName3
, aTmpName1
);
1553 deleteTestFile( aTmpName3
, aTmpName2
);
1554 deleteTestDirectory( aTmpName3
);
1558 void getFileType_001()
1560 ::osl::FileStatus
rFileStatus( osl_FileStatus_Mask_Type
| osl_FileStatus_Mask_FileName
);
1561 nError1
= m_aItem_1
.getFileStatus( rFileStatus
);
1562 CPPUNIT_ASSERT_MESSAGE("getFileStatus failed", ::osl::FileBase::E_None
== nError1
);
1564 check_FileType(rFileStatus
);
1567 void check_FileType(osl::FileStatus
const& _rFileStatus
)
1570 if ( _rFileStatus
.isValid(osl_FileStatus_Mask_FileName
))
1572 rtl::OUString suFilename
= _rFileStatus
.getFileName();
1574 if ( _rFileStatus
.isValid(osl_FileStatus_Mask_Type
))
1576 osl::FileStatus::Type eType
= _rFileStatus
.getFileType();
1578 if ( compareFileName( suFilename
, aTmpName2
) )
1581 bOK
= ( eType
== osl::FileStatus::Regular
);
1583 if ( compareFileName( suFilename
, aTmpName1
) )
1586 bOK
= ( eType
== ::osl::FileStatus::Directory
);
1589 CPPUNIT_ASSERT_MESSAGE( "test for getFileType function: ",
1593 // LLA: it's not a bug, if a FileStatus not exist, so no else
1596 void getFileType_002()
1598 ::osl::FileStatus
rFileStatus( osl_FileStatus_Mask_Type
| osl_FileStatus_Mask_FileName
);
1599 nError1
= m_aItem_2
.getFileStatus( rFileStatus
);
1601 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
1602 check_FileType(rFileStatus
);
1605 void getFileType_003()
1609 void getFileType_007()
1611 #if defined ( SOLARIS ) //Special file is differ in Windows
1612 nError1
= ::osl::DirectoryItem::get( aTypeURL2
, m_aSpecialItem
);
1613 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
1615 //check for File type
1616 ::osl::FileStatus
rFileStatus( osl_FileStatus_Mask_Type
);
1617 nError1
= m_aSpecialItem
.getFileStatus( rFileStatus
);
1618 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
1620 if (rFileStatus
.isValid(osl_FileStatus_Mask_Type
))
1622 osl::FileStatus::Type eType
= rFileStatus
.getFileType();
1624 CPPUNIT_ASSERT_MESSAGE( "test for getFileType function: Special, Solaris version ",
1625 ( eType
== ::osl::FileStatus::Special
) );
1630 CPPUNIT_TEST_SUITE( getFileType
);
1631 CPPUNIT_TEST( getFileType_001
);
1632 CPPUNIT_TEST( getFileType_002
);
1633 CPPUNIT_TEST( getFileType_003
);
1634 CPPUNIT_TEST( getFileType_007
);
1635 CPPUNIT_TEST_SUITE_END();
1636 };// class getFileType
1638 // testing the method
1639 // inline sal_uInt64 getAttributes() const
1641 class getAttributes
: public CppUnit::TestFixture
1643 ::rtl::OUString aTypeURL
, aTypeURL_Hid
;
1644 ::osl::FileBase::RC nError
;
1645 ::osl::DirectoryItem rItem
, rItem_hidden
;
1648 getAttributes() :nError(FileBase::E_None
) {}
1650 void setUp() SAL_OVERRIDE
1652 aTypeURL
= aUserDirectoryURL
.copy( 0 );
1653 concatURL( aTypeURL
, aTmpName2
);
1654 createTestFile( aTypeURL
);
1655 nError
= ::osl::DirectoryItem::get( aTypeURL
, rItem
);
1656 CPPUNIT_ASSERT( nError
== FileBase::E_None
);
1658 aTypeURL_Hid
= aUserDirectoryURL
.copy( 0 );
1659 concatURL( aTypeURL_Hid
, aHidURL1
);
1660 createTestFile( aTypeURL_Hid
);
1661 nError
= ::osl::DirectoryItem::get( aTypeURL_Hid
, rItem_hidden
);
1662 CPPUNIT_ASSERT( nError
== FileBase::E_None
);
1665 void tearDown() SAL_OVERRIDE
1667 deleteTestFile( aTypeURL
);
1668 deleteTestFile( aTypeURL_Hid
);
1673 //windows only 3 file attributes: normal, readonly, hidden
1674 void getAttributes_001()
1676 changeFileMode( aTypeURL
, S_IRUSR
| S_IRGRP
| S_IROTH
);
1678 ::osl::FileStatus
rFileStatus( osl_FileStatus_Mask_Attributes
);
1679 nError
= rItem
.getFileStatus( rFileStatus
);
1680 CPPUNIT_ASSERT( nError
== FileBase::E_None
);
1682 CPPUNIT_ASSERT_MESSAGE( "test for getAttributes function: ReadOnly, GrpRead, OwnRead, OthRead( UNX version ) ",
1683 ( osl_File_Attribute_ReadOnly
| osl_File_Attribute_GrpRead
| osl_File_Attribute_OwnRead
| osl_File_Attribute_OthRead
) ==
1684 rFileStatus
.getAttributes() );
1686 #else //Windows version
1687 void getAttributes_001()
1689 CPPUNIT_ASSERT_MESSAGE( "test for getAttributes function: ReadOnly, GrpRead, OwnRead, OthRead( Windows version )",
1694 void getAttributes_002()
1697 changeFileMode( aTypeURL
, S_IXUSR
| S_IXGRP
| S_IXOTH
);
1699 ::osl::FileStatus
rFileStatus( osl_FileStatus_Mask_Attributes
);
1700 nError
= rItem
.getFileStatus( rFileStatus
);
1701 CPPUNIT_ASSERT( nError
== FileBase::E_None
);
1703 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 )",
1704 ( osl_File_Attribute_ReadOnly
| osl_File_Attribute_Executable
| osl_File_Attribute_GrpExe
| osl_File_Attribute_OwnExe
| osl_File_Attribute_OthExe
) ==
1705 rFileStatus
.getAttributes() );
1710 void getAttributes_003()
1712 changeFileMode( aTypeURL
, S_IWUSR
| S_IWGRP
| S_IWOTH
);
1714 ::osl::FileStatus
rFileStatus( osl_FileStatus_Mask_Attributes
);
1715 nError
= rItem
.getFileStatus( rFileStatus
);
1716 CPPUNIT_ASSERT( nError
== FileBase::E_None
);
1718 CPPUNIT_ASSERT_MESSAGE( "test for getAttributes function: GrpWrite, OwnWrite, OthWrite( Solaris version )",
1719 ( osl_File_Attribute_GrpWrite
| osl_File_Attribute_OwnWrite
| osl_File_Attribute_OthWrite
) ==
1720 rFileStatus
.getAttributes() );
1722 #else //Windows version
1723 void getAttributes_003()
1725 CPPUNIT_ASSERT_MESSAGE( "test for getAttributes function: GrpWrite, OwnWrite, OthWrite( Windows version )",
1730 #if ( defined UNX ) //hidden file definition may different in Windows
1731 void getAttributes_004()
1733 sal_Int32 test_Attributes
= osl_File_Attribute_Hidden
;
1734 ::osl::FileStatus
rFileStatus( osl_FileStatus_Mask_Attributes
);
1735 nError
= rItem_hidden
.getFileStatus( rFileStatus
);
1736 CPPUNIT_ASSERT( nError
== FileBase::E_None
);
1737 test_Attributes
&= rFileStatus
.getAttributes();
1739 CPPUNIT_ASSERT_MESSAGE( "test for getAttributes function: Hidden files( Solaris version )",
1740 test_Attributes
== osl_File_Attribute_Hidden
);
1742 #else //Windows version
1743 void getAttributes_004()
1745 ::rtl::OUString
aUserHiddenFileURL ("file:///c:/AUTOEXEC.BAT");
1746 nError
= ::osl::DirectoryItem::get( aUserHiddenFileURL
, rItem_hidden
);
1747 CPPUNIT_ASSERT_MESSAGE("get item fail", nError
== FileBase::E_None
);
1748 ::osl::FileStatus
rFileStatus( osl_FileStatus_Mask_Attributes
);
1749 nError
= rItem_hidden
.getFileStatus( rFileStatus
);
1750 CPPUNIT_ASSERT( nError
== FileBase::E_None
);
1752 CPPUNIT_ASSERT_MESSAGE( "Hidden files(Windows version), please check if hidden file c:/AUTOEXEC.BAT exists ",
1753 (rFileStatus
.getAttributes() & osl_File_Attribute_Hidden
)!= 0 );
1757 CPPUNIT_TEST_SUITE( getAttributes
);
1758 CPPUNIT_TEST( getAttributes_001
);
1759 CPPUNIT_TEST( getAttributes_002
);
1760 CPPUNIT_TEST( getAttributes_003
);
1761 CPPUNIT_TEST( getAttributes_004
);
1762 CPPUNIT_TEST_SUITE_END();
1763 };// class getAttributes
1765 // testing the method
1766 // inline TimeValue getAccessTime() const
1768 class getAccessTime
: public CppUnit::TestFixture
1770 ::rtl::OUString aTypeURL
;
1771 ::osl::FileBase::RC nError
;
1772 ::osl::DirectoryItem rItem
;
1775 getAccessTime() :nError(FileBase::E_None
) {}
1777 void setUp() SAL_OVERRIDE
1779 aTypeURL
= aUserDirectoryURL
.copy( 0 );
1780 concatURL( aTypeURL
, aTmpName2
);
1781 createTestFile( aTypeURL
);
1782 nError
= ::osl::DirectoryItem::get( aTypeURL
, rItem
);
1783 CPPUNIT_ASSERT( nError
== FileBase::E_None
);
1787 void tearDown() SAL_OVERRIDE
1789 deleteTestFile( aTypeURL
);
1793 void getAccessTime_001()
1795 TimeValue
*pTV_current
= NULL
;
1796 CPPUNIT_ASSERT( ( pTV_current
= static_cast<TimeValue
*>(malloc( sizeof( TimeValue
) )) ) != NULL
);
1797 TimeValue
*pTV_access
= NULL
;
1798 CPPUNIT_ASSERT( ( pTV_access
= static_cast<TimeValue
*>(malloc( sizeof( TimeValue
) )) ) != NULL
);
1800 ::osl::FileStatus
rFileStatus( osl_FileStatus_Mask_AccessTime
);
1801 nError
= rItem
.getFileStatus( rFileStatus
);
1802 bool bOk
= osl_getSystemTime( pTV_current
);
1803 CPPUNIT_ASSERT( bOk
&& nError
== FileBase::E_None
);
1805 *pTV_access
= rFileStatus
.getAccessTime();
1807 bool bOK
= t_compareTime( pTV_access
, pTV_current
, delta
);
1808 free( pTV_current
);
1811 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. ",
1815 CPPUNIT_TEST_SUITE( getAccessTime
);
1816 CPPUNIT_TEST( getAccessTime_001
);
1817 CPPUNIT_TEST_SUITE_END();
1818 };// class getAccessTime
1820 // testing the method
1821 // inline TimeValue getModifyTime() const
1823 class getModifyTime
: public CppUnit::TestFixture
1825 ::rtl::OUString aTypeURL
;
1826 ::osl::FileBase::RC nError
;
1827 ::osl::DirectoryItem rItem
;
1830 getModifyTime() :nError(FileBase::E_None
) {}
1833 void getModifyTime_001()
1835 TimeValue
*pTV_current
= NULL
;
1836 CPPUNIT_ASSERT( ( pTV_current
= static_cast<TimeValue
*>(malloc( sizeof( TimeValue
) )) ) != NULL
);
1839 aTypeURL
= aUserDirectoryURL
.copy( 0 );
1840 concatURL( aTypeURL
, aTmpName2
);
1841 createTestFile( aTypeURL
);
1844 bool bOk
= osl_getSystemTime( pTV_current
);
1845 CPPUNIT_ASSERT( bOk
);
1847 //get instance item and filestatus
1848 nError
= ::osl::DirectoryItem::get( aTypeURL
, rItem
);
1849 CPPUNIT_ASSERT( nError
== FileBase::E_None
);
1850 ::osl::FileStatus
rFileStatus( osl_FileStatus_Mask_ModifyTime
);
1851 nError
= rItem
.getFileStatus( rFileStatus
);
1852 CPPUNIT_ASSERT( nError
== FileBase::E_None
);
1855 TimeValue
* pTV_modify
= NULL
;
1856 CPPUNIT_ASSERT( ( pTV_modify
= static_cast<TimeValue
*>(malloc( sizeof( TimeValue
) )) ) != NULL
);
1857 *pTV_modify
= rFileStatus
.getModifyTime();
1859 bool bOK
= t_compareTime( pTV_modify
, pTV_current
, delta
);
1861 deleteTestFile( aTypeURL
);
1862 free( pTV_current
);
1865 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. ",
1869 CPPUNIT_TEST_SUITE( getModifyTime
);
1870 CPPUNIT_TEST( getModifyTime_001
);
1871 CPPUNIT_TEST_SUITE_END();
1872 };// class getModifyTime
1874 // testing the method
1875 // inline sal_uInt64 getFileSize() const
1877 class getFileSize
: public CppUnit::TestFixture
1879 ::rtl::OUString aTypeURL
;
1880 ::osl::FileBase::RC nError
;
1881 ::osl::DirectoryItem rItem
;
1885 getFileSize() :nError(FileBase::E_None
) {}
1888 void setUp() SAL_OVERRIDE
1890 aTypeURL
= aUserDirectoryURL
.copy( 0 );
1891 concatURL( aTypeURL
, aTmpName2
);
1892 createTestFile( aTypeURL
);
1893 nError
= ::osl::DirectoryItem::get( aTypeURL
, rItem
);
1894 CPPUNIT_ASSERT( nError
== FileBase::E_None
);
1897 void tearDown() SAL_OVERRIDE
1899 deleteTestFile( aTypeURL
);
1903 void getFileSize_001()
1905 ::osl::FileStatus
rFileStatus( osl_FileStatus_Mask_FileSize
);
1906 nError
= rItem
.getFileStatus( rFileStatus
);
1907 CPPUNIT_ASSERT( nError
== FileBase::E_None
);
1909 sal_uInt64 uFileSize
= rFileStatus
.getFileSize();
1911 CPPUNIT_ASSERT_MESSAGE( "test for getFileSize function: empty file ",
1915 void getFileSize_002()
1917 ::osl::File
testfile( aTypeURL
);
1918 nError
= testfile
.open( osl_File_OpenFlag_Write
| osl_File_OpenFlag_Read
);
1919 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError
);
1920 nError
= testfile
.setSize( TEST_FILE_SIZE
);
1921 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError
);
1923 nError
= ::osl::DirectoryItem::get( aTypeURL
, rItem
);
1924 CPPUNIT_ASSERT( nError
== FileBase::E_None
);
1925 ::osl::FileStatus
rFileStatus( osl_FileStatus_Mask_FileSize
);
1926 nError
= rItem
.getFileStatus( rFileStatus
);
1927 CPPUNIT_ASSERT( nError
== FileBase::E_None
);
1928 sal_uInt64 uFileSize
= rFileStatus
.getFileSize();
1930 CPPUNIT_ASSERT_MESSAGE( "test for getFileSize function: file with size of TEST_FILE_SIZE, did not pass in (W32). ",
1931 TEST_FILE_SIZE
== uFileSize
);
1933 CPPUNIT_TEST_SUITE( getFileSize
);
1934 CPPUNIT_TEST( getFileSize_001
);
1935 CPPUNIT_TEST( getFileSize_002
);
1936 CPPUNIT_TEST_SUITE_END();
1937 };// class getFileSize
1939 // testing the method
1940 // inline ::rtl::OUString getFileName() const
1942 class getFileName
: public CppUnit::TestFixture
1944 ::rtl::OUString aTypeURL
;
1945 ::osl::FileBase::RC nError
;
1946 ::osl::DirectoryItem rItem
;
1949 getFileName() :nError(FileBase::E_None
) {}
1951 void setUp() SAL_OVERRIDE
1953 aTypeURL
= aUserDirectoryURL
.copy( 0 );
1954 concatURL( aTypeURL
, aTmpName2
);
1955 createTestFile( aTypeURL
);
1956 nError
= ::osl::DirectoryItem::get( aTypeURL
, rItem
);
1957 CPPUNIT_ASSERT( nError
== FileBase::E_None
);
1960 void tearDown() SAL_OVERRIDE
1962 deleteTestFile( aTypeURL
);
1966 void getFileName_001()
1968 ::osl::FileStatus
rFileStatus( osl_FileStatus_Mask_FileName
);
1969 nError
= rItem
.getFileStatus( rFileStatus
);
1970 CPPUNIT_ASSERT( nError
== FileBase::E_None
);
1972 ::rtl::OUString aFileName
= rFileStatus
.getFileName();
1974 CPPUNIT_ASSERT_MESSAGE( "test for getFileName function: name compare with specify",
1975 compareFileName( aFileName
, aTmpName2
) );
1978 CPPUNIT_TEST_SUITE( getFileName
);
1979 CPPUNIT_TEST( getFileName_001
);
1980 CPPUNIT_TEST_SUITE_END();
1981 };// class getFileName
1983 // testing the method
1984 // inline ::rtl::OUString getFileURL() const
1986 class getFileURL
: public CppUnit::TestFixture
1988 ::osl::FileBase::RC nError
;
1989 ::osl::DirectoryItem rItem
;
1992 getFileURL() :nError(FileBase::E_None
) {}
1995 void setUp() SAL_OVERRIDE
1997 createTestFile( aTmpName6
);
1998 nError
= ::osl::DirectoryItem::get( aTmpName6
, rItem
);
1999 CPPUNIT_ASSERT( nError
== FileBase::E_None
);
2002 void tearDown() SAL_OVERRIDE
2004 deleteTestFile( aTmpName6
);
2008 void getFileURL_001()
2010 ::osl::FileStatus
rFileStatus( osl_FileStatus_Mask_FileURL
);
2011 nError
= rItem
.getFileStatus( rFileStatus
);
2012 CPPUNIT_ASSERT( nError
== FileBase::E_None
);
2014 ::rtl::OUString aFileURL
= rFileStatus
.getFileURL();
2016 CPPUNIT_ASSERT_MESSAGE( "test for getFileURL function: ",
2017 compareFileName( aFileURL
, aTmpName6
) );
2020 CPPUNIT_TEST_SUITE( getFileURL
);
2021 CPPUNIT_TEST( getFileURL_001
);
2022 CPPUNIT_TEST_SUITE_END();
2023 };// class getFileURL
2025 // testing the method
2026 // inline ::rtl::OUString getLinkTargetURL() const
2028 class getLinkTargetURL
: public CppUnit::TestFixture
2030 ::rtl::OUString aTypeURL
;
2031 ::osl::FileBase::RC nError
;
2032 ::osl::DirectoryItem rItem
;
2036 getLinkTargetURL() :nError(FileBase::E_None
) {}
2039 void setUp() SAL_OVERRIDE
2041 aTypeURL
= aUserDirectoryURL
.copy( 0 );
2042 concatURL( aTypeURL
, aTmpName2
);
2043 createTestFile( aTypeURL
);
2046 void tearDown() SAL_OVERRIDE
2048 deleteTestFile( aTypeURL
);
2051 #if ( defined UNX ) //Link file is not define in Windows
2052 void getLinkTargetURL_001()
2054 //create a link file;
2055 ::rtl::OUString
aUStr_LnkFileSys( aTempDirectorySys
), aUStr_SrcFileSys( aTempDirectorySys
);
2056 ( ( aUStr_LnkFileSys
+= aSlashURL
) += getCurrentPID() ) += ::rtl::OUString("/link.file");
2057 ( ( aUStr_SrcFileSys
+= aSlashURL
) += getCurrentPID() ) += ::rtl::OUString("/tmpname");
2059 rtl::OString strLinkFileName
, strSrcFileName
;
2060 strLinkFileName
= OUStringToOString( aUStr_LnkFileSys
, RTL_TEXTENCODING_ASCII_US
);
2061 strSrcFileName
= OUStringToOString( aUStr_SrcFileSys
, RTL_TEXTENCODING_ASCII_US
);
2064 fd
= symlink( strSrcFileName
.getStr(), strLinkFileName
.getStr() );
2065 CPPUNIT_ASSERT_MESSAGE( "in creating link file", fd
== 0 );
2067 //get linkTarget URL
2068 nError
= ::osl::DirectoryItem::get( aLnkURL1
, rItem
);
2069 CPPUNIT_ASSERT_MESSAGE( "in getting link file item", nError
== FileBase::E_None
);
2071 ::osl::FileStatus
rFileStatus( osl_FileStatus_Mask_LinkTargetURL
);
2072 nError
= rItem
.getFileStatus( rFileStatus
);
2073 CPPUNIT_ASSERT_MESSAGE( "in getting link file status", nError
== FileBase::E_None
);
2074 ::rtl::OUString aFileURL
= rFileStatus
.getLinkTargetURL();
2077 fd
= remove( strLinkFileName
.getStr() );
2078 CPPUNIT_ASSERT_MESSAGE( "in deleting link file", fd
== 0 );
2080 CPPUNIT_ASSERT_MESSAGE( "test for getLinkTargetURL function: Solaris version, create a file, and a link file link to it, get its LinkTargetURL and compare",
2081 compareFileName( aFileURL
, aTypeURL
) );
2084 void getLinkTargetURL_001()
2086 CPPUNIT_ASSERT_MESSAGE( "test for getLinkTargetURL function: Windows version, not tested",
2091 CPPUNIT_TEST_SUITE( getLinkTargetURL
);
2092 CPPUNIT_TEST( getLinkTargetURL_001
);
2093 CPPUNIT_TEST_SUITE_END();
2094 };// class getLinkTargetURL
2096 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileStatus::ctors
, "osl_FileStatus" );
2097 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileStatus::isValid
, "osl_FileStatus" );
2098 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileStatus::getFileType
, "osl_FileStatus" );
2099 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileStatus::getAttributes
, "osl_FileStatus" );
2100 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileStatus::getAccessTime
, "osl_FileStatus" );
2101 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileStatus::getModifyTime
, "osl_FileStatus" );
2102 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileStatus::getFileSize
, "osl_FileStatus" );
2103 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileStatus::getFileName
, "osl_FileStatus" );
2104 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileStatus::getFileURL
, "osl_FileStatus" );
2105 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileStatus::getLinkTargetURL
, "osl_FileStatus" );
2106 }// namespace osl_FileStatus
2108 // Beginning of the test cases for File class
2113 // testing the method
2114 // File( const ::rtl::OUString& ustrFileURL )
2116 class ctors
: public CppUnit::TestFixture
2118 // ::osl::FileBase::RC nError1;
2122 void setUp() SAL_OVERRIDE
2124 // create a tempfile in $TEMP/tmpdir/tmpname.
2125 createTestDirectory( aTmpName3
);
2126 createTestFile( aTmpName4
);
2129 void tearDown() SAL_OVERRIDE
2131 // remove the tempfile in $TEMP/tmpdir/tmpname.
2132 deleteTestFile( aTmpName4
);
2133 deleteTestDirectory( aTmpName3
);
2139 ::osl::File
testFile( aTmpName4
);
2141 ::osl::FileBase::RC nError1
= testFile
.open( osl_File_OpenFlag_Read
| osl_File_OpenFlag_Write
);
2142 ::osl::FileBase::RC nError2
= testFile
.close();
2143 CPPUNIT_ASSERT_MESSAGE( "test for ctors function: initialize a File and test its open and close",
2144 ( ::osl::FileBase::E_None
== nError1
) && ( ::osl::FileBase::E_None
== nError2
) );
2149 ::osl::File
testFile( aTmpName5
);
2150 sal_Char buffer
[30] = "Test for File constructor";
2153 ::osl::FileBase::RC nError1
= testFile
.open( osl_File_OpenFlag_Read
| osl_File_OpenFlag_Write
);
2154 ::osl::FileBase::RC nError2
= testFile
.write( buffer
, 30, nCount
);
2157 CPPUNIT_ASSERT_MESSAGE( "test for ctors function: test relative file URL, this test show that relative file URL is also acceptable",
2158 ( ::osl::FileBase::E_None
== nError1
) && ( ::osl::FileBase::E_None
== nError2
) );
2161 CPPUNIT_TEST_SUITE( ctors
);
2162 CPPUNIT_TEST( ctors_001
);
2163 CPPUNIT_TEST( ctors_002
);
2164 CPPUNIT_TEST_SUITE_END();
2167 // testing the method
2168 // inline RC open( sal_uInt32 uFlags )
2170 class open
: public CppUnit::TestFixture
2172 ::osl::FileBase::RC nError1
, nError2
, nError3
;
2176 : nError1(FileBase::E_None
)
2177 , nError2(FileBase::E_None
)
2178 , nError3(FileBase::E_None
) {}
2180 void setUp() SAL_OVERRIDE
2182 // create a tempfile in $TEMP/tmpdir/tmpname.
2183 createTestDirectory( aTmpName3
);
2184 createTestFile( aTmpName4
);
2187 void tearDown() SAL_OVERRIDE
2189 // remove the tempfile in $TEMP/tmpdir/tmpname.
2190 deleteTestFile( aTmpName4
);
2191 deleteTestDirectory( aTmpName3
);
2197 ::osl::File
testFile( aTmpName4
);
2199 nError1
= testFile
.open( osl_File_OpenFlag_Read
| osl_File_OpenFlag_Write
);
2200 nError2
= testFile
.close();
2201 CPPUNIT_ASSERT_MESSAGE("close error", ::osl::FileBase::E_None
== nError2
);
2203 CPPUNIT_ASSERT_MESSAGE( "test for open function: open a regular file",
2204 ::osl::FileBase::E_None
== nError1
);
2209 ::osl::File
testFile( aTmpName3
);
2211 nError1
= testFile
.open( osl_File_OpenFlag_Read
);
2213 CPPUNIT_ASSERT_MESSAGE( "test for open function: open a directory",
2214 ( File::E_INVAL
== nError1
) || ( File::E_ACCES
== nError1
) );
2219 ::osl::File
testFile( aCanURL1
);
2221 nError1
= testFile
.open( osl_File_OpenFlag_Read
| osl_File_OpenFlag_Write
);
2223 CPPUNIT_ASSERT_MESSAGE( "test for open function: open a non-exist file",
2224 File::E_NOENT
== nError1
);
2229 ::rtl::OUString
aTestFile( aRootURL
);
2230 concatURL( aTestFile
, aTmpName2
);
2231 ::osl::File
testFile( aTestFile
);
2233 nError1
= testFile
.open( osl_File_OpenFlag_Create
);
2234 bool bOK
= ( File::E_ACCES
== nError1
);
2236 bOK
= sal_True
; /// in Windows, you can create file in c:/ any way.
2238 deleteTestFile( aTestFile
);
2241 CPPUNIT_ASSERT_MESSAGE( "test for open function: create an illegal file",
2247 ::osl::File
testFile( aTmpName4
);
2249 nError1
= testFile
.open( osl_File_OpenFlag_Create
);
2251 CPPUNIT_ASSERT_MESSAGE( "test for open function: create an exist file",
2252 File::E_EXIST
== nError1
);
2257 ::osl::File
testFile( aCanURL1
);
2258 sal_Char buffer_write
[30] = "Test for File open";
2259 sal_Char buffer_read
[30];
2260 sal_uInt64 nCount_write
, nCount_read
;
2262 nError1
= testFile
.open( osl_File_OpenFlag_Read
| osl_File_OpenFlag_Write
| osl_File_OpenFlag_Create
);
2263 nError2
= testFile
.write( buffer_write
, 30, nCount_write
);
2264 ::osl::FileBase::RC nError4
= testFile
.setPos( osl_Pos_Absolut
, 0 );
2265 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError4
);
2266 nError3
= testFile
.read( buffer_read
, 10, nCount_read
);
2268 ::osl::FileBase::RC nError5
= testFile
.close();
2269 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError5
);
2270 ::osl::FileBase::RC nError6
= osl::File::remove( aCanURL1
);
2271 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError6
);
2273 CPPUNIT_ASSERT_MESSAGE( "test for open function: test for osl_File_OpenFlag_Read, osl_File_OpenFlag_Write and osl_File_OpenFlag_Create",
2274 ( ::osl::FileBase::E_None
== nError1
) &&
2275 ( ::osl::FileBase::E_None
== nError2
) &&
2276 ( ::osl::FileBase::E_None
== nError3
) &&
2277 ( 30 == nCount_write
) &&
2278 ( 10 == nCount_read
) );
2281 CPPUNIT_TEST_SUITE( open
);
2282 CPPUNIT_TEST( open_001
);
2283 CPPUNIT_TEST( open_002
);
2284 CPPUNIT_TEST( open_003
);
2285 CPPUNIT_TEST( open_004
);
2286 CPPUNIT_TEST( open_005
);
2287 CPPUNIT_TEST( open_006
);
2288 CPPUNIT_TEST_SUITE_END();
2291 // testing the method
2292 // inline RC close()
2294 class close
: public CppUnit::TestFixture
2296 ::osl::FileBase::RC nError1
, nError2
, nError3
;
2300 : nError1(FileBase::E_None
)
2301 , nError2(FileBase::E_None
)
2302 , nError3(FileBase::E_None
) {}
2304 void setUp() SAL_OVERRIDE
2306 // create a tempfile in $TEMP/tmpdir/tmpname.
2307 createTestDirectory( aTmpName3
);
2308 createTestFile( aTmpName4
);
2311 void tearDown() SAL_OVERRIDE
2313 // remove the tempfile in $TEMP/tmpdir/tmpname.
2314 deleteTestFile( aTmpName4
);
2315 deleteTestDirectory( aTmpName3
);
2321 ::osl::File
testFile( aTmpName4
);
2323 nError1
= testFile
.open( osl_File_OpenFlag_Read
| osl_File_OpenFlag_Write
);
2324 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2326 nError2
= testFile
.close();
2328 CPPUNIT_ASSERT_MESSAGE( "test for close function: close a regular file",
2329 ::osl::FileBase::E_None
== nError2
);
2334 ::osl::File
testFile( aTmpName4
);
2336 nError1
= testFile
.open( osl_File_OpenFlag_Read
| osl_File_OpenFlag_Write
);
2337 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2339 nError2
= testFile
.close();
2341 nError3
= testFile
.setPos( osl_Pos_Absolut
, 0 );
2343 CPPUNIT_ASSERT_MESSAGE( "test for close function: manipulate a file after it has been closed",
2344 ( ::osl::FileBase::E_None
== nError2
) &&
2345 ( ::osl::FileBase::E_None
!= nError3
) );
2348 CPPUNIT_TEST_SUITE( close
);
2349 CPPUNIT_TEST( close_001
);
2350 CPPUNIT_TEST( close_002
);
2351 CPPUNIT_TEST_SUITE_END();
2354 // testing the method
2355 // inline RC setPos( sal_uInt32 uHow, sal_Int64 uPos )
2357 class setPos
: public CppUnit::TestFixture
2359 ::osl::FileBase::RC nError1
;
2360 sal_uInt64 nCount_write
, nCount_read
;
2364 : nError1(FileBase::E_None
)
2371 void setUp() SAL_OVERRIDE
2373 // create a tempfile in $TEMP/tmpdir/tmpname.
2374 createTestDirectory( aTmpName3
);
2375 createTestFile( aTmpName4
);
2377 //write chars into the file.
2378 ::osl::File
testFile( aTmpName4
);
2380 nError1
= testFile
.open( osl_File_OpenFlag_Write
);
2381 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2382 nError1
= testFile
.write( pBuffer_Char
, sizeof( pBuffer_Char
), nCount_write
);
2383 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2384 nError1
= testFile
.close();
2385 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2388 void tearDown() SAL_OVERRIDE
2390 // remove the tempfile in $TEMP/tmpdir/tmpname.
2391 deleteTestFile( aTmpName4
);
2392 deleteTestDirectory( aTmpName3
);
2398 ::osl::File
testFile( aTmpName4
);
2399 sal_Char buffer_read
[2];
2401 nError1
= testFile
.open( osl_File_OpenFlag_Read
| osl_File_OpenFlag_Write
);
2402 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2403 nError1
= testFile
.setPos( osl_Pos_Absolut
, 26 );
2404 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2405 nError1
= testFile
.read( buffer_read
, 1, nCount_read
);
2406 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2407 nError1
= testFile
.close();
2408 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2410 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",
2411 buffer_read
[0] == pBuffer_Char
[26] );
2416 ::osl::File
testFile( aTmpName4
);
2417 sal_Char buffer_read
[2];
2419 nError1
= testFile
.open( osl_File_OpenFlag_Read
| osl_File_OpenFlag_Write
);
2420 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2421 nError1
= testFile
.setPos( osl_Pos_Absolut
, sizeof( pBuffer_Char
) - 2 );
2422 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2423 nError1
= testFile
.setPos( osl_Pos_Current
, 0);
2424 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2425 nError1
= testFile
.read( buffer_read
, 1, nCount_read
);
2426 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2427 nError1
= testFile
.close();
2428 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2430 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",
2431 buffer_read
[0] == pBuffer_Char
[sizeof( pBuffer_Char
) - 2] );
2436 ::osl::File
testFile( aTmpName4
);
2437 sal_Char buffer_read
[2];
2439 nError1
= testFile
.open( osl_File_OpenFlag_Read
| osl_File_OpenFlag_Write
);
2440 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2441 //the file size is smaller than 100
2442 nError1
= testFile
.setPos( osl_Pos_End
, -100 );
2443 CPPUNIT_ASSERT_MESSAGE( "should return error", ::osl::FileBase::E_INVAL
== nError1
);
2445 nError1
= testFile
.setPos( osl_Pos_End
, -53 );
2446 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2447 nError1
= testFile
.read( buffer_read
, 1, nCount_read
);
2448 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2449 nError1
= testFile
.close();
2450 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2452 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",
2453 buffer_read
[0] == pBuffer_Char
[0] );
2456 CPPUNIT_TEST_SUITE( setPos
);
2457 CPPUNIT_TEST( setPos_001
);
2458 CPPUNIT_TEST( setPos_002
);
2459 CPPUNIT_TEST( setPos_003
);
2460 CPPUNIT_TEST_SUITE_END();
2463 // testing the method
2464 // inline RC getPos( sal_uInt64& uPos )
2466 class getPos
: public CppUnit::TestFixture
2468 ::osl::FileBase::RC nError1
;
2469 sal_uInt64 nCount_write
;
2473 : nError1(FileBase::E_None
)
2479 void setUp() SAL_OVERRIDE
2481 // create a tempfile in $TEMP/tmpdir/tmpname.
2482 createTestDirectory( aTmpName3
);
2483 createTestFile( aTmpName4
);
2485 //write chars into the file.
2486 ::osl::File
testFile( aTmpName4
);
2488 nError1
= testFile
.open( osl_File_OpenFlag_Write
);
2489 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2490 nError1
= testFile
.write( pBuffer_Char
, sizeof( pBuffer_Char
), nCount_write
);
2491 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2492 nError1
= testFile
.close();
2493 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2496 void tearDown() SAL_OVERRIDE
2498 // remove the tempfile in $TEMP/tmpdir/tmpname.
2499 deleteTestFile( aTmpName4
);
2500 deleteTestDirectory( aTmpName3
);
2506 ::osl::File
testFile( aTmpName4
);
2507 sal_uInt64 nFilePointer
;
2509 nError1
= testFile
.getPos( nFilePointer
);
2510 CPPUNIT_ASSERT( ::osl::FileBase::E_INVAL
== nError1
);
2512 nError1
= testFile
.open( osl_File_OpenFlag_Read
| osl_File_OpenFlag_Write
);
2513 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2515 nError1
= testFile
.setPos( osl_Pos_Absolut
, 26 );
2516 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2517 nError1
= testFile
.getPos( nFilePointer
);
2518 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2520 nError1
= testFile
.close();
2521 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2523 CPPUNIT_ASSERT_MESSAGE( "test for getPos function: set the position to 26, get position and check if it is right",
2524 26 == nFilePointer
);
2527 CPPUNIT_TEST_SUITE( getPos
);
2528 CPPUNIT_TEST( getPos_001
);
2529 CPPUNIT_TEST_SUITE_END();
2532 // testing the method
2533 // inline RC isEndOfFile( sal_Bool *pIsEOF )
2535 class isEndOfFile
: public CppUnit::TestFixture
2537 ::osl::FileBase::RC nError1
;
2538 sal_uInt64 nCount_write
;
2542 : nError1(FileBase::E_None
)
2548 void setUp() SAL_OVERRIDE
2550 // create a tempfile in $TEMP/tmpdir/tmpname.
2551 createTestDirectory( aTmpName3
);
2552 createTestFile( aTmpName4
);
2554 //write chars into the file.
2555 ::osl::File
testFile( aTmpName4
);
2557 nError1
= testFile
.open( osl_File_OpenFlag_Write
);
2558 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2559 nError1
= testFile
.write( pBuffer_Char
, sizeof( pBuffer_Char
), nCount_write
);
2560 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2561 nError1
= testFile
.close();
2562 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2565 void tearDown() SAL_OVERRIDE
2567 // remove the tempfile in $TEMP/tmpdir/tmpname.
2568 deleteTestFile( aTmpName4
);
2569 deleteTestDirectory( aTmpName3
);
2573 void isEndOfFile_001()
2575 ::osl::File
testFile( aTmpName4
);
2576 sal_Bool bEOF
= sal_False
;
2577 sal_Bool
*pEOF
= &bEOF
;
2579 nError1
= testFile
.open( osl_File_OpenFlag_Read
| osl_File_OpenFlag_Write
);
2580 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2582 nError1
= testFile
.setPos( osl_Pos_End
, 0 );
2583 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2584 nError1
= testFile
.isEndOfFile( pEOF
);
2585 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2587 nError1
= testFile
.close();
2588 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2590 CPPUNIT_ASSERT_MESSAGE( "test for isEndOfFile function: set the position to end, check if reach end",
2591 sal_True
== *pEOF
);
2594 void isEndOfFile_002()
2596 ::osl::File
testFile( aTmpName4
);
2597 sal_Bool bEOF
= sal_False
;
2598 sal_Bool
*pEOF
= &bEOF
;
2599 sal_uInt64 nFilePointer
= 0;
2601 nError1
= testFile
.open( osl_File_OpenFlag_Read
| osl_File_OpenFlag_Write
);
2602 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2604 nError1
= testFile
.setPos( osl_Pos_Absolut
, 0 );
2605 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2607 while ( !( *pEOF
) )
2609 nError1
= testFile
.isEndOfFile( pEOF
);
2610 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2611 nError1
= testFile
.setPos( osl_Pos_Current
, 1 );
2612 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2614 nError1
= testFile
.getPos( nFilePointer
);
2615 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2617 nError1
= testFile
.close();
2618 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2620 CPPUNIT_ASSERT_MESSAGE( "test for isEndOfFile function: use isEndOfFile to move pointer step by step",
2621 sizeof( pBuffer_Char
) + 1 == nFilePointer
);
2623 CPPUNIT_TEST_SUITE( isEndOfFile
);
2624 CPPUNIT_TEST( isEndOfFile_001
);
2625 CPPUNIT_TEST( isEndOfFile_002
);
2626 CPPUNIT_TEST_SUITE_END();
2627 };// class isEndOfFile
2629 // testing the method
2630 // inline RC setSize( sal_uInt64 uSize )
2632 class setSize
: public CppUnit::TestFixture
2634 ::osl::FileBase::RC nError1
;
2635 sal_uInt64 nCount_write
;
2639 : nError1(FileBase::E_None
)
2645 void setUp() SAL_OVERRIDE
2647 // create a tempfile in $TEMP/tmpdir/tmpname.
2648 createTestDirectory( aTmpName3
);
2649 createTestFile( aTmpName4
);
2651 //write chars into the file.
2652 ::osl::File
testFile( aTmpName4
);
2654 nError1
= testFile
.open( osl_File_OpenFlag_Write
);
2655 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2656 nError1
= testFile
.write( pBuffer_Char
, sizeof( pBuffer_Char
), nCount_write
);
2657 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2658 nError1
= testFile
.close();
2659 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2662 void tearDown() SAL_OVERRIDE
2664 // remove the tempfile in $TEMP/tmpdir/tmpname.
2665 deleteTestFile( aTmpName4
);
2666 deleteTestDirectory( aTmpName3
);
2672 ::osl::File
testFile( aTmpName4
);
2673 // sal_Bool bEOF = sal_False;
2674 // sal_Bool *pEOF = &bEOF;
2675 sal_uInt64 nFilePointer
;
2677 nError1
= testFile
.open( osl_File_OpenFlag_Read
| osl_File_OpenFlag_Write
);
2678 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2680 //enlarge the file to size of 100;
2681 nError1
= testFile
.setSize( 100 );
2682 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2684 //get the file size;
2685 nError1
= testFile
.setPos( osl_Pos_End
, 0 );
2686 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2687 nError1
= testFile
.getPos( nFilePointer
);
2688 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2690 nError1
= testFile
.close();
2691 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2693 CPPUNIT_ASSERT_MESSAGE( "test for setSize function: enlarge the file ",
2694 100 == nFilePointer
);
2699 ::osl::File
testFile( aTmpName4
);
2700 // sal_Bool bEOF = sal_False;
2701 // sal_Bool *pEOF = &bEOF;
2702 sal_uInt64 nFilePointer
;
2704 nError1
= testFile
.open( osl_File_OpenFlag_Read
| osl_File_OpenFlag_Write
);
2705 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2707 //enlarge the file to size of 100;
2708 nError1
= testFile
.setSize( 10 );
2709 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2711 //get the file size;
2712 nError1
= testFile
.setPos( osl_Pos_End
, 0 );
2713 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2714 nError1
= testFile
.getPos( nFilePointer
);
2715 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2717 nError1
= testFile
.close();
2718 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2720 CPPUNIT_ASSERT_MESSAGE( "test for setSize function: truncate the file ",
2721 10 == nFilePointer
);
2724 CPPUNIT_TEST_SUITE( setSize
);
2725 CPPUNIT_TEST( setSize_001
);
2726 CPPUNIT_TEST( setSize_002
);
2727 CPPUNIT_TEST_SUITE_END();
2730 // testing the method
2731 // inline RC read( void *pBuffer, sal_uInt64 uBytesRequested, sal_uInt64& rBytesRead )
2733 class read
: public CppUnit::TestFixture
2735 ::osl::FileBase::RC nError1
;
2736 sal_uInt64 nCount_write
, nCount_read
;
2740 : nError1(FileBase::E_None
)
2746 void setUp() SAL_OVERRIDE
2748 // create a tempfile in $TEMP/tmpdir/tmpname.
2749 createTestDirectory( aTmpName3
);
2750 createTestFile( aTmpName4
);
2752 //write chars into the file.
2753 ::osl::File
testFile( aTmpName4
);
2755 nError1
= testFile
.open( osl_File_OpenFlag_Write
);
2756 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2757 nError1
= testFile
.write( pBuffer_Char
, sizeof( pBuffer_Char
), nCount_write
);
2758 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2759 nError1
= testFile
.close();
2760 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2763 void tearDown() SAL_OVERRIDE
2765 // remove the tempfile in $TEMP/tmpdir/tmpname.
2766 deleteTestFile( aTmpName4
);
2767 deleteTestDirectory( aTmpName3
);
2773 ::osl::File
testFile( aTmpName4
);
2774 sal_uInt64 nFilePointer
;
2775 sal_Char buffer_read
[10];
2777 nError1
= testFile
.open( osl_File_OpenFlag_Read
| osl_File_OpenFlag_Write
);
2778 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2780 nError1
= testFile
.read( buffer_read
, 10, nCount_read
);
2781 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2782 nError1
= testFile
.getPos( nFilePointer
);
2783 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2785 nError1
= testFile
.close();
2786 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2788 CPPUNIT_ASSERT_MESSAGE( "test for read function: read whole content in the file to a buffer",
2789 ( 10 == nFilePointer
) && ( 0 == strncmp( buffer_read
, pBuffer_Char
, 10 ) ) );
2794 ::osl::File
testFile( aTmpName4
);
2795 sal_uInt64 nFilePointer
;
2796 sal_Char buffer_read
[26];
2798 nError1
= testFile
.open( osl_File_OpenFlag_Read
| osl_File_OpenFlag_Write
);
2799 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2801 nError1
= testFile
.setPos( osl_Pos_Absolut
, 26 );
2802 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2803 nError1
= testFile
.read( buffer_read
, 26, nCount_read
);
2804 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2805 nError1
= testFile
.getPos( nFilePointer
);
2806 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2808 nError1
= testFile
.close();
2809 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2811 CPPUNIT_ASSERT_MESSAGE( "test for read function: read from a special position in the file",
2812 ( 52 == nFilePointer
) && ( 26 == nCount_read
) && ( 0 == strncmp( buffer_read
, &pBuffer_Char
[26], 26 ) ) );
2815 CPPUNIT_TEST_SUITE( read
);
2816 CPPUNIT_TEST( read_001
);
2817 CPPUNIT_TEST( read_002
);
2818 CPPUNIT_TEST_SUITE_END();
2821 // testing the method
2822 // inline RC write(const void *pBuffer, sal_uInt64 uBytesToWrite, sal_uInt64& rBytesWritten)
2824 class write
: public CppUnit::TestFixture
2826 ::osl::FileBase::RC nError1
;
2827 sal_uInt64 nCount_write
, nCount_read
;
2831 : nError1(FileBase::E_None
)
2838 void setUp() SAL_OVERRIDE
2840 // create a tempfile in $TEMP/tmpname.
2841 createTestFile( aTmpName6
);
2844 void tearDown() SAL_OVERRIDE
2846 // remove the tempfile in $TEMP/tmpname.
2847 deleteTestFile( aTmpName6
);
2853 ::osl::File
testFile( aTmpName6
);
2854 sal_uInt64 nFilePointer
;
2855 sal_Char buffer_read
[10];
2857 nError1
= testFile
.open( osl_File_OpenFlag_Read
| osl_File_OpenFlag_Write
);
2858 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2860 //write chars into the file.
2861 nError1
= testFile
.write( pBuffer_Char
, 10, nCount_write
);
2862 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2863 //get the current pointer;
2864 nError1
= testFile
.getPos( nFilePointer
);
2865 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2866 //reset pointer to the beginning;
2867 nError1
= testFile
.setPos( osl_Pos_Absolut
, 0 );
2868 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2869 nError1
= testFile
.read( buffer_read
, 10, nCount_read
);
2870 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2872 nError1
= testFile
.close();
2873 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2875 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",
2876 ( 10 == nFilePointer
) &&
2877 ( 0 == strncmp( buffer_read
, pBuffer_Char
, 10 ) ) &&
2878 ( 10 == nCount_write
) );
2881 CPPUNIT_TEST_SUITE( write
);
2882 CPPUNIT_TEST( write_001
);
2883 CPPUNIT_TEST_SUITE_END();
2886 // testing the method
2887 // inline RC readLine( ::rtl::ByteSequence& aSeq )
2889 class readLine
: public CppUnit::TestFixture
2891 ::osl::FileBase::RC nError1
;
2892 sal_uInt64 nCount_write
;
2893 ::rtl::ByteSequence aSequence
;
2897 : nError1(FileBase::E_None
)
2902 void setUp() SAL_OVERRIDE
2904 // create a tempfile in $TEMP/tmpname.
2905 createTestFile( aTmpName6
);
2907 //write some strings into the file.
2908 ::osl::File
testFile( aTmpName6
);
2909 sal_Char ppStrSeq
[3][27] = { "abcde\n",
2911 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
2914 nError1
= testFile
.open( osl_File_OpenFlag_Write
);
2915 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2917 for ( int nCount
= 0; nCount
< 3; nCount
++ )
2919 nError1
= testFile
.write( ppStrSeq
[nCount
], strlen( ppStrSeq
[nCount
] ), nCount_write
);
2920 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2923 nError1
= testFile
.close();
2924 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2927 void tearDown() SAL_OVERRIDE
2929 // remove the tempfile in $TEMP/tmpname.
2930 deleteTestFile( aTmpName6
);
2936 ::osl::File
testFile( aTmpName6
);
2938 nError1
= testFile
.open( osl_File_OpenFlag_Read
| osl_File_OpenFlag_Write
);
2939 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2940 nError1
= testFile
.readLine( aSequence
);
2941 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2942 CPPUNIT_ASSERT_MESSAGE( "test for readLine function: read the first line of the file.",
2943 ( ::osl::FileBase::E_None
== nError1
) &&
2944 ( 0 == strncmp( reinterpret_cast<char *>(aSequence
.getArray()), pBuffer_Char
, 5 ) ) );
2949 ::osl::File
testFile( aTmpName6
);
2950 sal_Bool bEOF
= sal_False
;
2951 sal_Bool
*pEOF
= &bEOF
;
2953 nError1
= testFile
.open( osl_File_OpenFlag_Read
| osl_File_OpenFlag_Write
);
2954 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2955 for ( int nCount
= 0; nCount
< 3; nCount
++ )
2957 nError1
= testFile
.readLine( aSequence
);
2958 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2960 nError1
= testFile
.isEndOfFile( pEOF
);
2961 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
2963 CPPUNIT_ASSERT_MESSAGE( "test for readLine function: read three lines of the file and check the file pointer moving.",
2965 ( 0 == strncmp( reinterpret_cast<char *>(aSequence
.getArray()), &pBuffer_Char
[26], 26 ) ) );
2967 CPPUNIT_TEST_SUITE( readLine
);
2968 CPPUNIT_TEST( readLine_001
);
2969 CPPUNIT_TEST( readLine_002
);
2970 CPPUNIT_TEST_SUITE_END();
2973 // testing the method
2974 // inline static RC copy( const ::rtl::OUString& ustrSourceFileURL, const ::rtl::OUString& ustrDestFileURL )
2976 class copy
: public CppUnit::TestFixture
2978 ::osl::FileBase::RC nError1
;
2979 sal_uInt64 nCount_write
;
2983 : nError1(FileBase::E_None
)
2989 void setUp() SAL_OVERRIDE
2991 // create a tempfile in $TEMP/tmpdir/tmpname.
2992 createTestDirectory( aTmpName3
);
2993 createTestFile( aTmpName4
);
2995 //write chars into the file.
2996 ::osl::File
testFile( aTmpName4
);
2998 nError1
= testFile
.open( osl_File_OpenFlag_Write
);
2999 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
3000 nError1
= testFile
.write( pBuffer_Char
, sizeof( pBuffer_Char
), nCount_write
);
3001 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
3002 nError1
= testFile
.close();
3003 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
3006 void tearDown() SAL_OVERRIDE
3008 // remove the tempfile in $TEMP/tmpdir/tmpname.
3009 deleteTestFile( aTmpName4
);
3010 deleteTestDirectory( aTmpName3
);
3016 ::osl::File
testFile( aTmpName6
);
3018 //copy $TEMP/tmpdir/tmpname to $TEMP/tmpname.
3019 nError1
= ::osl::File::copy( aTmpName4
, aTmpName6
);
3020 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
3022 nError1
= testFile
.open( osl_File_OpenFlag_Create
);
3023 deleteTestFile( aTmpName6
);
3025 CPPUNIT_ASSERT_MESSAGE( "test for copy function: copy file to upper directory",
3026 ::osl::FileBase::E_EXIST
== nError1
);
3031 //copy $TEMP/tmpdir/tmpname to $TEMP/tmpdir.
3032 nError1
= ::osl::File::copy( aTmpName4
, aTmpName3
);
3034 CPPUNIT_ASSERT_MESSAGE( "test for copy function: use directory as destination",
3035 ( ::osl::FileBase::E_ISDIR
== nError1
) ||( ::osl::FileBase::E_ACCES
== nError1
) );
3040 //copy $TEMP/tmpdir/tmpname to $ROOT/tmpname.
3041 nError1
= ::osl::File::copy( aTmpName4
, aTmpName7
);
3043 nError1
= ::osl::FileBase::E_ACCES
; /// for Windows, c:/ is writtenable any way.
3044 deleteTestFile( aTmpName7
);
3046 CPPUNIT_ASSERT_MESSAGE( "test for copy function: copy to an illigal place",
3047 ::osl::FileBase::E_ACCES
== nError1
);
3052 //copy $TEMP/tmpname to $TEMP/tmpdir/tmpname.
3053 nError1
= ::osl::File::copy( aTmpName6
, aTmpName4
);
3055 CPPUNIT_ASSERT_MESSAGE( "test for copy function: copy a not exist file",
3056 ::osl::FileBase::E_NOENT
== nError1
);
3061 //copy $TEMP/tmpname to $TEMP/system.path using system path.
3062 nError1
= ::osl::File::copy( aTmpName6
, aSysPath1
);
3064 CPPUNIT_ASSERT_MESSAGE( "test for copy function: copy a file using system file path",
3065 ::osl::FileBase::E_INVAL
== nError1
);
3069 createTestFile( aTmpName6
);
3070 File
tmpFile( aTmpName6
);
3071 FileBase::RC err
= tmpFile
.open( osl_File_OpenFlag_Write
| osl_File_OpenFlag_Read
);
3073 tmpFile
.setSize( 200 );
3076 nError1
= ::osl::File::copy( aTmpName6
, aTmpName4
);
3077 CPPUNIT_ASSERT( nError1
== FileBase::E_None
);
3079 //check if is the new file
3080 File
newFile( aTmpName4
);
3081 newFile
.open( osl_File_OpenFlag_Write
| osl_File_OpenFlag_Read
);
3082 nError1
= newFile
.setPos( osl_Pos_End
, 0 );
3083 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
3084 sal_uInt64 nFilePointer
;
3085 nError1
= newFile
.getPos( nFilePointer
);
3086 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
3088 deleteTestFile( aTmpName6
);
3089 CPPUNIT_ASSERT_MESSAGE( "test for copy function: the dest file exist",
3090 nFilePointer
== 200 );
3093 CPPUNIT_TEST_SUITE( copy
);
3094 CPPUNIT_TEST( copy_001
);
3095 CPPUNIT_TEST( copy_002
);
3096 CPPUNIT_TEST( copy_003
);
3097 CPPUNIT_TEST( copy_004
);
3098 CPPUNIT_TEST( copy_005
);
3099 CPPUNIT_TEST( copy_006
);
3100 CPPUNIT_TEST_SUITE_END();
3103 // testing the method
3104 // inline static RC move( const ::rtl::OUString& ustrSourceFileURL, const ::rtl::OUString& ustrDestFileURL )
3106 class move
: public CppUnit::TestFixture
3108 ::osl::FileBase::RC nError1
, nError2
;
3109 sal_uInt64 nCount_write
;
3113 : nError1(FileBase::E_None
)
3114 , nError2(FileBase::E_None
)
3120 void setUp() SAL_OVERRIDE
3122 // create a tempfile in $TEMP/tmpdir/tmpname.
3123 createTestDirectory( aTmpName3
);
3124 createTestFile( aTmpName4
);
3126 //write chars into the file.
3127 ::osl::File
testFile( aTmpName4
);
3129 nError1
= testFile
.open( osl_File_OpenFlag_Write
);
3130 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
3131 nError1
= testFile
.write( pBuffer_Char
, sizeof( pBuffer_Char
), nCount_write
);
3132 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
3133 nError1
= testFile
.close();
3134 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
3137 void tearDown() SAL_OVERRIDE
3139 // remove the tempfile in $TEMP/tmpdir/tmpname.
3140 deleteTestFile( aTmpName4
);
3141 deleteTestDirectory( aTmpName3
);
3147 //rename $TEMP/tmpdir/tmpname to $TEMP/canonical.name.
3148 nError1
= ::osl::File::move( aTmpName4
, aCanURL1
);
3149 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
3151 ::osl::File
testFile( aCanURL1
);
3152 nError2
= testFile
.open( osl_File_OpenFlag_Create
);
3153 deleteTestFile( aCanURL1
);
3155 CPPUNIT_ASSERT_MESSAGE( "test for move function: rename file to another directory",
3156 ::osl::FileBase::E_EXIST
== nError2
);
3161 //move $TEMP/tmpdir/tmpname to $TEMP/tmpdir.
3162 nError1
= ::osl::File::move( aTmpName4
, aTmpName3
);
3163 //returned ::osl::FileBase::E_ACCES on WNT
3164 CPPUNIT_ASSERT_MESSAGE( "test for move function: use directory as destination",
3165 ( ::osl::FileBase::E_ACCES
== nError1
|| ::osl::FileBase::E_ISDIR
== nError1
) ||( ::osl::FileBase::E_EXIST
== nError1
) );
3170 //move $TEMP/tmpdir/tmpname to $ROOT/tmpname.
3171 nError1
= ::osl::File::move( aTmpName4
, aTmpName7
);
3173 nError1
= ::osl::FileBase::E_ACCES
; /// for Windows, c:/ is writtenable any way.
3174 deleteTestFile( aTmpName7
);
3177 CPPUNIT_ASSERT_MESSAGE( "test for move function: move to an illigal place",
3178 ::osl::FileBase::E_ACCES
== nError1
);
3183 //move $TEMP/tmpname to $TEMP/tmpdir/tmpname.
3184 nError1
= ::osl::File::move( aTmpName6
, aTmpName4
);
3186 CPPUNIT_ASSERT_MESSAGE( "test for move function: move a not exist file",
3187 ::osl::FileBase::E_NOENT
== nError1
);
3192 //move $TEMP/tmpname to $TEMP/system.path using system path.
3193 nError1
= ::osl::File::move( aTmpName6
, aSysPath1
);
3195 CPPUNIT_ASSERT_MESSAGE( "test for move function: move a file using system file",
3196 ::osl::FileBase::E_INVAL
== nError1
);
3201 //move directory $TEMP/tmpname to $TEMP/tmpdir/tmpname.
3202 createTestDirectory( aTmpName6
);
3203 nError1
= ::osl::File::move( aTmpName6
, aTmpName4
);
3204 //move file $TEMP/tmpdir/tmpname to $TEMP/tmpname
3205 nError2
= ::osl::File::move( aTmpName4
, aTmpName6
);
3206 deleteTestDirectory( aTmpName6
);
3208 deleteTestDirectory( aTmpName4
);// in Windows, it can be moved!!!!! this is only for not influence the following test.
3209 deleteTestFile( aTmpName6
);
3210 nError1
= ::osl::FileBase::E_NOTDIR
;
3211 nError2
= ::osl::FileBase::E_ISDIR
;
3213 CPPUNIT_ASSERT_MESSAGE( "test for move function: move a directory to an exist file with same name, did not pass in (W32)",
3214 ::osl::FileBase::E_NOTDIR
== nError1
&& ::osl::FileBase::E_ISDIR
== nError2
);
3219 //create directory $TEMP/tmpname.
3220 createTestDirectory( aTmpName6
);
3221 //move directory $TEMP/tmpdir to $TEMP/tmpname/tmpdir
3222 nError1
= ::osl::File::move( aTmpName3
, aTmpName8
);
3224 nError2
= ::osl::Directory::create( aTmpName8
);
3225 ::osl::File::move( aTmpName8
, aTmpName3
);
3226 deleteTestDirectory( aTmpName6
);
3228 CPPUNIT_ASSERT_MESSAGE( "test for move function: move a directory to an exist file with same name",
3229 (::osl::FileBase::E_None
== nError1
) &&
3230 (::osl::FileBase::E_EXIST
== nError2
) );
3232 //bugid# 115420, after the bug fix, add the case
3233 CPPUNIT_TEST_SUITE( move
);
3234 CPPUNIT_TEST( move_001
);
3235 CPPUNIT_TEST( move_002
);
3236 CPPUNIT_TEST( move_003
);
3237 CPPUNIT_TEST( move_004
);
3238 CPPUNIT_TEST( move_005
);
3239 CPPUNIT_TEST( move_006
);
3240 CPPUNIT_TEST( move_007
);
3241 CPPUNIT_TEST_SUITE_END();
3244 // testing the method
3245 // inline static RC remove( const ::rtl::OUString& ustrFileURL )
3247 class remove
: public CppUnit::TestFixture
3249 ::osl::FileBase::RC nError1
, nError2
;
3250 sal_uInt64 nCount_write
;
3254 : nError1(FileBase::E_None
)
3255 , nError2(FileBase::E_None
)
3261 void setUp() SAL_OVERRIDE
3263 // create a tempfile in $TEMP/tmpdir/tmpname.
3264 createTestDirectory( aTmpName3
);
3265 createTestFile( aTmpName4
);
3267 //write chars into the file.
3268 ::osl::File
testFile( aTmpName4
);
3270 nError1
= testFile
.open( osl_File_OpenFlag_Write
);
3271 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
3272 nError1
= testFile
.write( pBuffer_Char
, sizeof( pBuffer_Char
), nCount_write
);
3273 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
3274 nError1
= testFile
.close();
3275 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
3278 void tearDown() SAL_OVERRIDE
3280 // remove the tempfile in $TEMP/tmpdir/tmpname.
3281 deleteTestFile( aTmpName4
);
3282 deleteTestDirectory( aTmpName3
);
3288 //remove $TEMP/tmpdir/tmpname.
3289 nError1
= ::osl::File::remove( aTmpName4
);
3291 ::osl::File
testFile( aTmpName4
);
3292 nError2
= testFile
.open( osl_File_OpenFlag_Create
);
3294 CPPUNIT_ASSERT_MESSAGE( "test for remove function: remove a file",
3295 ( ::osl::FileBase::E_None
== nError1
) &&
3296 ( ::osl::FileBase::E_EXIST
!= nError2
) );
3301 //remove $TEMP/tmpname.
3302 nError1
= ::osl::File::remove( aTmpName6
);
3304 CPPUNIT_ASSERT_MESSAGE( "test for remove function: remove a file not exist",
3305 ( ::osl::FileBase::E_NOENT
== nError1
) );
3310 //remove $TEMP/system/path.
3311 nError1
= ::osl::File::remove( aSysPath2
);
3313 CPPUNIT_ASSERT_MESSAGE( "test for remove function: removing a file not using full qualified URL",
3314 ( ::osl::FileBase::E_INVAL
== nError1
) );
3319 //remove $TEMP/tmpdir.
3320 nError1
= ::osl::File::remove( aTmpName3
);
3322 CPPUNIT_ASSERT_MESSAGE( "test for remove function: remove a directory",
3323 ( ::osl::FileBase::E_ISDIR
== nError1
) || ( ::osl::FileBase::E_ACCES
== nError1
));
3326 CPPUNIT_TEST_SUITE( remove
);
3327 CPPUNIT_TEST( remove_001
);
3328 CPPUNIT_TEST( remove_002
);
3329 CPPUNIT_TEST( remove_003
);
3330 CPPUNIT_TEST( remove_004
);
3331 CPPUNIT_TEST_SUITE_END();
3334 // testing the method
3335 // inline static RC setAttributes( const ::rtl::OUString& ustrFileURL, sal_uInt64 uAttributes )
3337 class setAttributes
: public CppUnit::TestFixture
3339 ::osl::FileBase::RC nError1
, nError2
;
3340 ::osl::DirectoryItem rItem
, rItem_hidden
;
3343 setAttributes() :nError1(FileBase::E_None
),nError2(FileBase::E_None
) {}
3345 void setUp() SAL_OVERRIDE
3347 // create a tempfile in $TEMP/tmpdir/tmpname.
3348 createTestFile( aTmpName6
);
3351 void tearDown() SAL_OVERRIDE
3353 // remove the tempfile in $TEMP/tmpdir/tmpname.
3354 deleteTestFile( aTmpName6
);
3358 void setAttributes_001()
3360 //on windows, only can set 2 attributes: osl_File_Attribute_ReadOnly, osl_File_Attribute_Hidden
3362 //set the file to readonly
3363 nError2
= ::osl::File::setAttributes( aTmpName6
, osl_File_Attribute_ReadOnly
| osl_File_Attribute_GrpRead
| osl_File_Attribute_OwnRead
| osl_File_Attribute_OthRead
);
3364 CPPUNIT_ASSERT( nError2
== FileBase::E_None
);
3365 nError1
= ::osl::DirectoryItem::get( aTmpName6
, rItem
);
3366 CPPUNIT_ASSERT( nError1
== FileBase::E_None
);
3367 //get the file attributes
3368 ::osl::FileStatus
rFileStatus( osl_FileStatus_Mask_Attributes
);
3369 nError1
= rItem
.getFileStatus( rFileStatus
);
3370 CPPUNIT_ASSERT( nError1
== FileBase::E_None
);
3372 CPPUNIT_ASSERT_MESSAGE( "test for setAttributes function: set file attributes and get it to verify.",
3373 ( osl_File_Attribute_ReadOnly
| osl_File_Attribute_GrpRead
| osl_File_Attribute_OwnRead
| osl_File_Attribute_OthRead
) ==
3374 rFileStatus
.getAttributes() );
3376 //please see GetFileAttributes
3377 nError2
= ::osl::File::setAttributes( aTmpName6
, osl_File_Attribute_ReadOnly
);
3378 CPPUNIT_ASSERT( nError2
== FileBase::E_None
);
3379 nError1
= ::osl::DirectoryItem::get( aTmpName6
, rItem
);
3380 CPPUNIT_ASSERT( nError1
== FileBase::E_None
);
3381 //get the file attributes
3382 ::osl::FileStatus
rFileStatus( osl_FileStatus_Mask_Attributes
);
3383 nError1
= rItem
.getFileStatus( rFileStatus
);
3384 CPPUNIT_ASSERT( nError1
== FileBase::E_None
);
3385 //here the file has 2 Attributes: FILE_ATTRIBUTE_READONLY and FILE_ATTRIBUTE_NORMAL,
3386 // but FILE_ATTRIBUTE_NORMAL is valid only if used alone, so this is maybe a bug
3387 /*::rtl::OString aString = ::rtl::OUStringToOString( aTmpName6, RTL_TEXTENCODING_ASCII_US );
3388 DWORD dwFileAttributes = GetFileAttributes( aString.getStr() );
3389 if (dwFileAttributes & FILE_ATTRIBUTE_NORMAL)
3390 printf("has normal attribute");
3391 if (dwFileAttributes & FILE_ATTRIBUTE_READONLY)
3392 printf("has readonly attribute");
3394 CPPUNIT_ASSERT_MESSAGE( "test for setAttributes function: set file attributes READONLY and get it to verify.",
3395 (osl_File_Attribute_ReadOnly
& rFileStatus
.getAttributes()) != 0 );
3398 void setAttributes_002()
3400 //on UNX, can not set hidden attribute to file, rename file can set the attribute
3402 //set the file to hidden
3403 nError2
= ::osl::File::setAttributes( aTmpName6
, osl_File_Attribute_Hidden
);
3405 CPPUNIT_ASSERT( nError2
== FileBase::E_None
);
3406 nError1
= ::osl::DirectoryItem::get( aTmpName6
, rItem
);
3407 CPPUNIT_ASSERT( nError1
== FileBase::E_None
);
3408 //get the file attributes
3409 ::osl::FileStatus
rFileStatus( osl_FileStatus_Mask_Attributes
);
3410 nError1
= rItem
.getFileStatus( rFileStatus
);
3411 CPPUNIT_ASSERT( nError1
== FileBase::E_None
);
3413 CPPUNIT_ASSERT_MESSAGE( "test for setAttributes function: set file attributes and get it to verify.",
3414 (osl_File_Attribute_Hidden
& rFileStatus
.getAttributes()) != 0 );
3418 CPPUNIT_TEST_SUITE( setAttributes
);
3419 CPPUNIT_TEST( setAttributes_001
);
3420 CPPUNIT_TEST( setAttributes_002
);
3421 CPPUNIT_TEST_SUITE_END();
3422 };// class setAttributes
3424 // testing the method
3425 // inline static RC setTime(
3426 // const ::rtl::OUString& ustrFileURL,
3427 // const TimeValue& rCreationTime,
3428 // const TimeValue& rLastAccessTime,
3429 // const TimeValue& rLastWriteTime )
3431 class setTime
: public CppUnit::TestFixture
3433 ::osl::FileBase::RC nError1
, nError2
;
3434 ::osl::DirectoryItem rItem
;
3437 setTime() :nError1(FileBase::E_None
),nError2(FileBase::E_None
) {}
3439 void setUp() SAL_OVERRIDE
3441 // create a tempfile in $TEMP/tmpdir/tmpname.
3442 createTestFile( aTmpName6
);
3445 void tearDown() SAL_OVERRIDE
3447 // remove the tempfile in $TEMP/tmpdir/tmpname.
3448 deleteTestFile( aTmpName6
);
3454 TimeValue
*pTV_current
= NULL
;
3455 CPPUNIT_ASSERT( ( pTV_current
= static_cast<TimeValue
*>(malloc( sizeof( TimeValue
) )) ) != NULL
);
3456 TimeValue
*pTV_creation
= NULL
;
3457 CPPUNIT_ASSERT( ( pTV_creation
= static_cast<TimeValue
*>(malloc( sizeof( TimeValue
) )) ) != NULL
);
3458 TimeValue
*pTV_access
= NULL
;
3459 CPPUNIT_ASSERT( ( pTV_access
= static_cast<TimeValue
*>(malloc( sizeof( TimeValue
) )) ) != NULL
);
3460 TimeValue
*pTV_modify
= NULL
;
3461 CPPUNIT_ASSERT( ( pTV_modify
= static_cast<TimeValue
*>(malloc( sizeof( TimeValue
) )) ) != NULL
);
3464 bool bOk
= osl_getSystemTime( pTV_current
);
3465 CPPUNIT_ASSERT( bOk
);
3468 nError2
= ::osl::File::setTime( aTmpName6
, *pTV_current
, *pTV_current
, *pTV_current
);
3469 CPPUNIT_ASSERT_MESSAGE( errorToStr( nError2
).getStr(), nError2
== FileBase::E_None
);
3471 //get the file access time, creation time, modify time
3472 nError1
= ::osl::DirectoryItem::get( aTmpName6
, rItem
);
3473 CPPUNIT_ASSERT_MESSAGE( errorToStr( nError1
).getStr(), nError1
== FileBase::E_None
);
3475 ::osl::FileStatus
rFileStatus( osl_FileStatus_Mask_AccessTime
);
3476 nError1
= rItem
.getFileStatus( rFileStatus
);
3477 CPPUNIT_ASSERT_MESSAGE( errorToStr( nError1
).getStr(),nError1
== FileBase::E_None
);
3478 *pTV_access
= rFileStatus
.getAccessTime();
3480 ::osl::FileStatus
rFileStatus1( osl_FileStatus_Mask_CreationTime
);
3481 nError1
= rItem
.getFileStatus( rFileStatus1
);
3482 CPPUNIT_ASSERT_MESSAGE( errorToStr( nError1
).getStr(), nError1
== FileBase::E_None
);
3483 *pTV_creation
= rFileStatus1
.getCreationTime();
3485 ::osl::FileStatus
rFileStatus2( osl_FileStatus_Mask_ModifyTime
);
3486 nError1
= rItem
.getFileStatus( rFileStatus2
);
3487 CPPUNIT_ASSERT_MESSAGE( errorToStr( nError1
).getStr(), nError1
== FileBase::E_None
);
3488 *pTV_modify
= rFileStatus2
.getModifyTime();
3490 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.",
3491 t_compareTime( pTV_access
, pTV_current
, delta
) );
3493 //Unfortunately there is no way to get the creation time of a file under Unix (its a Windows only feature).
3494 //That means the flag osl_FileStatus_Mask_CreationTime should be deprecated under Unix.
3495 CPPUNIT_ASSERT_MESSAGE( "test for setTime function: set creation time then get it. ",
3496 sal_True
== t_compareTime( pTV_creation
, pTV_current
, delta
) ) ;
3498 CPPUNIT_ASSERT_MESSAGE( "test for setTime function: set modify time then get it. ",
3499 t_compareTime( pTV_modify
, pTV_current
, delta
) );
3500 free( pTV_current
);
3501 free( pTV_creation
);
3506 CPPUNIT_TEST_SUITE( setTime
);
3507 CPPUNIT_TEST( setTime_001
);
3508 CPPUNIT_TEST_SUITE_END();
3511 // testing the method
3512 // inline static RC sync()
3514 class sync
: public CppUnit::TestFixture
3516 ::osl::FileBase::RC nError1
, nError2
;
3517 ::osl::DirectoryItem rItem
;
3520 sync() :nError1(FileBase::E_None
),nError2(FileBase::E_None
) {}
3522 void setUp() SAL_OVERRIDE
3524 // create a tempfile in $TEMP/tmpdir/tmpname.
3525 createTestFile( aTmpName6
);
3529 void tearDown() SAL_OVERRIDE
3531 // remove the tempfile in $TEMP/tmpdir/tmpname.
3532 deleteTestFile( aTmpName6
);
3535 // test case: if The file is located on a read only file system.
3539 nError1
= ::osl::DirectoryItem::get( aTmpName6
, rItem
);
3540 CPPUNIT_ASSERT( nError1
== FileBase::E_None
);
3542 File
tmp_file( aTmpName6
);
3543 FileBase::RC err
= tmp_file
.open(osl_File_OpenFlag_Write
);
3545 CPPUNIT_ASSERT_MESSAGE("File open failed", err
== FileBase::E_None
);
3548 sal_uInt64 written
= 0;
3549 nError1
= tmp_file
.write((void*)buffer
, sizeof(buffer
), written
);
3550 CPPUNIT_ASSERT_MESSAGE("write failed!", nError1
== FileBase::E_None
);
3552 //set the file to readonly
3553 nError2
= ::osl::File::setAttributes( aTmpName6
, osl_File_Attribute_ReadOnly
| osl_File_Attribute_GrpRead
| osl_File_Attribute_OwnRead
| osl_File_Attribute_OthRead
);
3554 CPPUNIT_ASSERT( nError2
== FileBase::E_None
);
3556 nError2
= tmp_file
.sync();
3558 CPPUNIT_ASSERT_MESSAGE("can not sync to readonly file!", nError2
== FileBase::E_None
);
3563 //test case:no enough space, how to create such case???see test_cpy_wrt_file.cxx::test_osl_writeFile
3565 CPPUNIT_TEST_SUITE( sync
);
3566 CPPUNIT_TEST( sync_001
);
3567 CPPUNIT_TEST_SUITE_END();
3570 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::ctors
, "osl_File" );
3571 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::open
, "osl_File" );
3572 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::close
, "osl_File" );
3573 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::setPos
, "osl_File" );
3574 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::getPos
, "osl_File" );
3575 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::isEndOfFile
, "osl_File" );
3576 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::setSize
, "osl_File" );
3577 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::read
, "osl_File" );
3578 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::write
, "osl_File" );
3579 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::readLine
, "osl_File" );
3580 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::copy
, "osl_File" );
3581 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::move
, "osl_File" );
3582 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::remove
, "osl_File" );
3583 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::setAttributes
, "osl_File" );
3584 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::setTime
, "osl_File" );
3585 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::sync
, "osl_File" );
3586 // FIXME: to enable these tests (when they work cross-platform) we need to add the below:
3587 // CPPUNIT_REGISTRY_ADD_TO_DEFAULT( "osl_File" );
3589 }// namespace osl_File
3591 // Beginning of the test cases for DirectoryItem class
3593 namespace osl_DirectoryItem
3596 // testing the method
3597 // DirectoryItem(): _pData( NULL )
3599 class ctors
: public CppUnit::TestFixture
3601 ::osl::FileBase::RC nError1
;
3604 ctors() :nError1(FileBase::E_None
) {}
3606 void setUp() SAL_OVERRIDE
3608 // create a tempfile in $TEMP/tmpname.
3609 createTestFile( aTmpName6
);
3612 void tearDown() SAL_OVERRIDE
3614 // remove the tempfile in $TEMP/tmpname.
3615 deleteTestFile( aTmpName6
);
3621 ::osl::File
testFile( aTmpName6
);
3622 ::osl::DirectoryItem rItem
; //constructor
3624 //get the DirectoryItem.
3625 nError1
= ::osl::DirectoryItem::get( aTmpName6
, rItem
);
3626 CPPUNIT_ASSERT( FileBase::E_None
== nError1
);
3628 CPPUNIT_ASSERT_MESSAGE( "test for ctors function: initialize a new instance of DirectoryItem and get an item to check.",
3629 ::osl::FileBase::E_None
== nError1
);
3632 CPPUNIT_TEST_SUITE( ctors
);
3633 CPPUNIT_TEST( ctors_001
);
3634 CPPUNIT_TEST_SUITE_END();
3637 // testing the method
3638 // DirectoryItem( const DirectoryItem& rItem ): _pData( rItem._pData)
3640 class copy_assin_Ctors
: public CppUnit::TestFixture
3642 ::osl::FileBase::RC nError1
;
3645 copy_assin_Ctors() :nError1(FileBase::E_None
) {}
3647 void setUp() SAL_OVERRIDE
3649 // create a tempfile in $TEMP/tmpname.
3650 createTestFile( aTmpName6
);
3653 void tearDown() SAL_OVERRIDE
3655 // remove the tempfile in $TEMP/tmpname.
3656 deleteTestFile( aTmpName6
);
3660 void copy_assin_Ctors_001()
3662 ::osl::DirectoryItem rItem
; //constructor
3663 //get the DirectoryItem.
3664 nError1
= ::osl::DirectoryItem::get( aTmpName6
, rItem
);
3665 CPPUNIT_ASSERT( FileBase::E_None
== nError1
);
3667 ::osl::DirectoryItem
copyItem( rItem
); //copy constructor
3668 ::osl::FileStatus
rFileStatus( osl_FileStatus_Mask_FileName
);
3669 nError1
= copyItem
.getFileStatus( rFileStatus
);
3670 CPPUNIT_ASSERT( nError1
== FileBase::E_None
);
3672 CPPUNIT_ASSERT_MESSAGE( "test for copy_assin_Ctors function: use copy constructor to get an item and check filename.",
3673 compareFileName( rFileStatus
.getFileName(), aTmpName2
) );
3676 void copy_assin_Ctors_002()
3678 ::osl::DirectoryItem rItem
; //constructor
3679 //get the DirectoryItem.
3680 nError1
= ::osl::DirectoryItem::get( aTmpName6
, rItem
);
3681 CPPUNIT_ASSERT( FileBase::E_None
== nError1
);
3683 ::osl::DirectoryItem copyItem
;
3684 copyItem
= rItem
; //assinment operator
3685 ::osl::FileStatus
rFileStatus( osl_FileStatus_Mask_FileName
);
3686 nError1
= copyItem
.getFileStatus( rFileStatus
);
3687 CPPUNIT_ASSERT( nError1
== FileBase::E_None
);
3689 CPPUNIT_ASSERT_MESSAGE( "test for copy_assin_Ctors function: test assinment operator here since it is same as copy constructor in test way.",
3690 compareFileName( rFileStatus
.getFileName(), aTmpName2
) );
3693 CPPUNIT_TEST_SUITE( copy_assin_Ctors
);
3694 CPPUNIT_TEST( copy_assin_Ctors_001
);
3695 CPPUNIT_TEST( copy_assin_Ctors_002
);
3696 CPPUNIT_TEST_SUITE_END();
3697 };// class copy_assin_Ctors
3699 // testing the method
3700 // inline sal_Bool is()
3702 class is
: public CppUnit::TestFixture
3704 ::osl::FileBase::RC nError1
;
3707 is() :nError1(FileBase::E_None
) {}
3709 void setUp() SAL_OVERRIDE
3711 // create a tempfile in $TEMP/tmpname.
3712 createTestFile( aTmpName6
);
3715 void tearDown() SAL_OVERRIDE
3717 // remove the tempfile in $TEMP/tmpname.
3718 deleteTestFile( aTmpName6
);
3724 ::osl::DirectoryItem rItem
; //constructor
3726 CPPUNIT_ASSERT_MESSAGE( "test for is function: use an uninitialized instance.",
3732 ::osl::DirectoryItem rItem
; //constructor
3733 //get the DirectoryItem.
3734 nError1
= ::osl::DirectoryItem::get( aTmpName6
, rItem
);
3735 CPPUNIT_ASSERT( FileBase::E_None
== nError1
);
3737 CPPUNIT_ASSERT_MESSAGE( "test for is function: use an uninitialized instance.",
3741 CPPUNIT_TEST_SUITE( is
);
3742 CPPUNIT_TEST( is_001
);
3743 CPPUNIT_TEST( is_002
);
3744 CPPUNIT_TEST_SUITE_END();
3747 // testing the method
3748 // static inline RC get( const ::rtl::OUString& ustrFileURL, DirectoryItem& rItem )
3750 class get
: public CppUnit::TestFixture
3752 ::osl::FileBase::RC nError1
, nError2
;
3755 get() :nError1(FileBase::E_None
),nError2(FileBase::E_None
) {}
3757 void setUp() SAL_OVERRIDE
3759 // create a tempfile in $TEMP/tmpname.
3760 createTestFile( aTmpName6
);
3763 void tearDown() SAL_OVERRIDE
3765 // remove the tempfile in $TEMP/tmpname.
3766 deleteTestFile( aTmpName6
);
3772 ::osl::DirectoryItem rItem
; //constructor
3773 //get the DirectoryItem.
3774 nError2
= ::osl::DirectoryItem::get( aTmpName6
, rItem
);
3776 //check the file name
3777 ::osl::FileStatus
rFileStatus( osl_FileStatus_Mask_FileName
);
3778 nError1
= rItem
.getFileStatus( rFileStatus
);
3779 CPPUNIT_ASSERT( nError1
== FileBase::E_None
);
3781 CPPUNIT_ASSERT_MESSAGE( "test for get function: use copy constructor to get an item and check filename.",
3782 ( ::osl::FileBase::E_None
== nError2
) &&
3783 compareFileName( rFileStatus
.getFileName(), aTmpName2
) );
3788 ::osl::DirectoryItem rItem
;
3789 //get the DirectoryItem.
3790 nError1
= ::osl::DirectoryItem::get( aSysPath1
, rItem
);
3792 CPPUNIT_ASSERT_MESSAGE( "test for get function: use a system name instead of a URL.",
3793 FileBase::E_INVAL
== nError1
);
3798 ::osl::DirectoryItem rItem
;
3799 //get the DirectoryItem.
3800 nError1
= ::osl::DirectoryItem::get( aTmpName3
, rItem
);
3802 CPPUNIT_ASSERT_MESSAGE( "test for get function: use a non existed file URL.",
3803 FileBase::E_NOENT
== nError1
);
3806 CPPUNIT_TEST_SUITE( get
);
3807 CPPUNIT_TEST( get_001
);
3808 CPPUNIT_TEST( get_002
);
3809 CPPUNIT_TEST( get_003
);
3810 CPPUNIT_TEST_SUITE_END();
3813 // testing the method
3814 // inline RC getFileStatus( FileStatus& rStatus )
3816 class getFileStatus
: public CppUnit::TestFixture
3818 ::osl::FileBase::RC nError1
, nError2
;
3821 getFileStatus() :nError1(FileBase::E_None
),nError2(FileBase::E_None
) {}
3823 void setUp() SAL_OVERRIDE
3825 // create a tempfile in $TEMP/tmpdir/tmpname.
3826 createTestDirectory( aTmpName3
);
3827 createTestFile( aTmpName4
);
3830 void tearDown() SAL_OVERRIDE
3832 // remove the tempfile in $TEMP/tmpdir/tmpname.
3833 deleteTestFile( aTmpName4
);
3834 deleteTestDirectory( aTmpName3
);
3838 void getFileStatus_001()
3840 ::osl::DirectoryItem rItem
; //constructor
3841 //get the DirectoryItem.
3842 nError1
= ::osl::DirectoryItem::get( aTmpName4
, rItem
);
3843 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
3845 //check the file name
3846 ::osl::FileStatus
rFileStatus( osl_FileStatus_Mask_FileName
);
3847 nError2
= rItem
.getFileStatus( rFileStatus
);
3849 CPPUNIT_ASSERT_MESSAGE( "test for getFileStatus function: get file status and check filename",
3850 ( ::osl::FileBase::E_None
== nError2
) &&
3851 compareFileName( rFileStatus
.getFileName(), aTmpName2
) );
3854 void getFileStatus_002()
3856 ::osl::DirectoryItem rItem
; //constructor
3857 //get the DirectoryItem.
3858 nError1
= ::osl::DirectoryItem::get( aTmpName6
, rItem
);
3860 //check the file name
3861 ::osl::FileStatus
rFileStatus( osl_FileStatus_Mask_FileName
);
3862 nError2
= rItem
.getFileStatus( rFileStatus
);
3864 CPPUNIT_ASSERT_MESSAGE( "test for getFileStatus function: file not existed",
3865 ( ::osl::FileBase::E_INVAL
== nError2
) );
3868 void getFileStatus_003()
3870 ::osl::DirectoryItem rItem
; //constructor
3871 //get the DirectoryItem.
3872 nError1
= ::osl::DirectoryItem::get( aTmpName3
, rItem
);
3873 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
3875 //check the file name
3876 ::osl::FileStatus
rFileStatus( osl_FileStatus_Mask_FileName
);
3877 nError2
= rItem
.getFileStatus( rFileStatus
);
3879 CPPUNIT_ASSERT_MESSAGE( "test for getFileStatus function: get directory information",
3880 ( ::osl::FileBase::E_None
== nError2
) &&
3881 compareFileName( rFileStatus
.getFileName(), aTmpName1
) );
3884 CPPUNIT_TEST_SUITE( getFileStatus
);
3885 CPPUNIT_TEST( getFileStatus_001
);
3886 CPPUNIT_TEST( getFileStatus_002
);
3887 CPPUNIT_TEST( getFileStatus_003
);
3888 CPPUNIT_TEST_SUITE_END();
3889 };// class getFileStatus
3891 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_DirectoryItem::ctors
, "osl_DirectoryItem" );
3892 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_DirectoryItem::copy_assin_Ctors
, "osl_DirectoryItem" );
3893 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_DirectoryItem::is
, "osl_DirectoryItem" );
3894 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_DirectoryItem::get
, "osl_DirectoryItem" );
3895 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_DirectoryItem::getFileStatus
, "osl_DirectoryItem" );
3896 }// namespace osl_DirectoryItem
3898 // Beginning of the test cases for Directory class
3900 namespace osl_Directory
3903 // testing the method
3904 // Directory( const ::rtl::OUString& strPath ): _pData( 0 ), _aPath( strPath )
3906 class ctors
: public CppUnit::TestFixture
3908 ::osl::FileBase::RC nError1
, nError2
;
3911 ctors() :nError1(FileBase::E_None
),nError2(FileBase::E_None
) {}
3913 void setUp() SAL_OVERRIDE
3915 // create a tempfile in $TEMP/tmpdir/tmpname.
3916 createTestDirectory( aTmpName3
);
3917 createTestFile( aTmpName4
);
3920 void tearDown() SAL_OVERRIDE
3922 // remove the tempfile in $TEMP/tmpdir/tmpname.
3923 deleteTestFile( aTmpName4
);
3924 deleteTestDirectory( aTmpName3
);
3925 // LLA: t_print("tearDown done.\n");
3931 ::osl::Directory
testDirectory( aTmpName3
); //constructor
3934 nError1
= testDirectory
.open();
3935 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
3937 nError2
= testDirectory
.close();
3938 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError2
);
3940 CPPUNIT_ASSERT_MESSAGE( "test for ctors function: create an instance and check open and close",
3941 ( ::osl::FileBase::E_None
== nError1
) &&
3942 ( ::osl::FileBase::E_None
== nError2
) );
3947 ::osl::Directory
testDirectory( aTmpName9
); //constructor
3950 nError1
= testDirectory
.open();
3951 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
3953 nError2
= testDirectory
.close();
3954 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError2
);
3956 CPPUNIT_ASSERT_MESSAGE( "test for ctors function: relative URL, :-), it is also worked",
3957 ( ::osl::FileBase::E_None
== nError1
) &&
3958 ( ::osl::FileBase::E_None
== nError2
) );
3961 CPPUNIT_TEST_SUITE( ctors
);
3962 CPPUNIT_TEST( ctors_001
);
3963 CPPUNIT_TEST( ctors_002
);
3964 CPPUNIT_TEST_SUITE_END();
3967 // testing the method
3970 class open
: public CppUnit::TestFixture
3972 ::osl::FileBase::RC nError1
, nError2
;
3975 open() :nError1(FileBase::E_None
),nError2(FileBase::E_None
) {}
3977 void setUp() SAL_OVERRIDE
3979 // create a tempfile in $TEMP/tmpdir/tmpname.
3980 createTestDirectory( aTmpName3
);
3981 createTestFile( aTmpName4
);
3984 void tearDown() SAL_OVERRIDE
3986 // remove the tempfile in $TEMP/tmpdir/tmpname.
3987 deleteTestFile( aTmpName4
);
3988 deleteTestDirectory( aTmpName3
);
3994 ::osl::Directory
testDirectory( aTmpName3
); //constructor
3997 nError1
= testDirectory
.open();
3998 //check if directory is opened.
3999 bool bOk
= testDirectory
.isOpen();
4001 nError2
= testDirectory
.close();
4003 CPPUNIT_ASSERT_MESSAGE( "test for open function: open a directory and check for open",
4005 ( ::osl::FileBase::E_None
== nError1
) &&
4006 ( ::osl::FileBase::E_None
== nError2
) );
4011 ::osl::Directory
testDirectory( aTmpName6
); //constructor
4014 nError1
= testDirectory
.open();
4015 if ( ::osl::FileBase::E_None
== nError1
)
4017 nError2
= testDirectory
.close();
4018 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError2
);
4021 CPPUNIT_ASSERT_MESSAGE( "test for open function: open a file that is not existed",
4022 ( ::osl::FileBase::E_NOENT
== nError1
) );
4027 ::osl::Directory
testDirectory( aUserDirectorySys
); //constructor
4030 nError1
= testDirectory
.open();
4031 if ( ::osl::FileBase::E_None
== nError1
)
4033 nError2
= testDirectory
.close();
4034 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError2
);
4037 CPPUNIT_ASSERT_MESSAGE( "test for open function: using system path",
4038 ( ::osl::FileBase::E_INVAL
== nError1
) );
4043 ::osl::Directory
testDirectory( aTmpName4
); //constructor
4046 nError1
= testDirectory
.open();
4047 if ( ::osl::FileBase::E_None
== nError1
)
4049 nError2
= testDirectory
.close();
4050 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError2
);
4053 CPPUNIT_ASSERT_MESSAGE( "test for open function: open a file instead of a directory",
4054 ( ::osl::FileBase::E_NOTDIR
== nError1
) || ( ::osl::FileBase::E_ACCES
== nError1
) );
4057 CPPUNIT_TEST_SUITE( open
);
4058 CPPUNIT_TEST( open_001
);
4059 CPPUNIT_TEST( open_002
);
4060 CPPUNIT_TEST( open_003
);
4061 CPPUNIT_TEST( open_004
);
4062 CPPUNIT_TEST_SUITE_END();
4065 // testing the method
4066 // inline sal_Bool isOpen() { return _pData != NULL; };
4068 class isOpen
: public CppUnit::TestFixture
4070 ::osl::FileBase::RC nError1
, nError2
;
4073 isOpen() :nError1(FileBase::E_None
),nError2(FileBase::E_None
) {}
4075 void setUp() SAL_OVERRIDE
4077 // create a tempfile in $TEMP/tmpdir/tmpname.
4078 createTestDirectory( aTmpName3
);
4079 createTestFile( aTmpName4
);
4082 void tearDown() SAL_OVERRIDE
4084 // remove the tempfile in $TEMP/tmpdir/tmpname.
4085 deleteTestFile( aTmpName4
);
4086 deleteTestDirectory( aTmpName3
);
4092 ::osl::Directory
testDirectory( aTmpName3
); //constructor
4095 nError1
= testDirectory
.open();
4096 //check if directory is opened.
4097 bool bOk
= testDirectory
.isOpen();
4099 nError2
= testDirectory
.close();
4101 CPPUNIT_ASSERT_MESSAGE( "test for isOpen function: open a directory and check for open",
4107 ::osl::Directory
testDirectory( aTmpName3
); //constructor
4109 //check if directory is opened.
4110 bool bOk
= testDirectory
.isOpen();
4112 CPPUNIT_ASSERT_MESSAGE( "test for isOpen function: do not open a directory and check for open",
4116 CPPUNIT_TEST_SUITE( isOpen
);
4117 CPPUNIT_TEST( isOpen_001
);
4118 CPPUNIT_TEST( isOpen_002
);
4119 CPPUNIT_TEST_SUITE_END();
4122 // testing the method
4123 // inline RC close()
4125 class close
: public CppUnit::TestFixture
4127 ::osl::FileBase::RC nError1
, nError2
;
4130 close() :nError1(FileBase::E_None
),nError2(FileBase::E_None
) {}
4132 void setUp() SAL_OVERRIDE
4134 // create a tempdirectory : $TEMP/tmpdir.
4135 createTestDirectory( aTmpName3
);
4138 void tearDown() SAL_OVERRIDE
4140 // remove a tempdirectory : $TEMP/tmpdir.
4141 deleteTestDirectory( aTmpName3
);
4147 ::osl::Directory
testDirectory( aTmpName3
); //constructor
4150 nError1
= testDirectory
.open();
4152 nError2
= testDirectory
.close();
4153 //check if directory is opened.
4154 bool bOk
= testDirectory
.isOpen();
4156 CPPUNIT_ASSERT_MESSAGE( "test for isOpen function: close a directory and check for open",
4162 ::osl::Directory
testDirectory( aTmpName3
); //constructor
4165 nError1
= testDirectory
.close();
4167 CPPUNIT_ASSERT_MESSAGE( "test for isOpen function: close a not opened directory",
4168 ( ::osl::FileBase::E_BADF
== nError1
) );
4171 CPPUNIT_TEST_SUITE( close
);
4172 CPPUNIT_TEST( close_001
);
4173 CPPUNIT_TEST( close_002
);
4174 CPPUNIT_TEST_SUITE_END();
4177 // testing the method
4178 // inline RC reset()
4180 class reset
: public CppUnit::TestFixture
4182 ::osl::FileBase::RC nError1
, nError2
;
4183 ::osl::DirectoryItem rItem
;
4186 reset() :nError1(FileBase::E_None
),nError2(FileBase::E_None
) {}
4188 void setUp() SAL_OVERRIDE
4190 // create a tempdirectory : $TEMP/tmpdir.
4191 createTestDirectory( aTmpName3
);
4192 // create three files : $TEMP/tmpdir/tmpname, $TEMP/tmpdir/tmpdir, $TEMP/tmpdir/hiddenfile,
4193 createTestFile( aTmpName3
, aTmpName2
);
4194 createTestFile( aTmpName3
, aTmpName1
);
4195 createTestFile( aTmpName3
, aHidURL1
);
4198 void tearDown() SAL_OVERRIDE
4200 // remove three files : $TEMP/tmpdir/tmpname, $TEMP/tmpdir/tmpdir, $TEMP/tmpdir/hiddenfile,
4201 deleteTestFile( aTmpName3
, aHidURL1
);
4202 deleteTestFile( aTmpName3
, aTmpName1
);
4203 deleteTestFile( aTmpName3
, aTmpName2
);
4204 // remove a tempdirectory : $TEMP/tmpdir.
4205 deleteTestDirectory( aTmpName3
);
4211 ::osl::Directory
testDirectory( aTmpName3
); //constructor
4214 nError1
= testDirectory
.open();
4215 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
4217 nError1
= testDirectory
.getNextItem( rItem
, 1 );
4218 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
4219 //check the file name of first Item
4220 ::osl::FileStatus
rFileStatusFirst( osl_FileStatus_Mask_FileName
);
4221 nError1
= rItem
.getFileStatus( rFileStatusFirst
);
4224 //mindy: nError1 = testDirectory.getNextItem( rItem, 0 );
4225 //mindy: CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4228 nError2
= testDirectory
.reset();
4229 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError2
);
4230 //get reseted Item, if reset does not work, getNextItem() should return the second Item (aTmpName1)
4231 nError1
= testDirectory
.getNextItem( rItem
, 0 );
4232 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
4234 //check the file name again
4235 ::osl::FileStatus
rFileStatus( osl_FileStatus_Mask_FileName
);
4236 nError1
= rItem
.getFileStatus( rFileStatus
);
4238 nError1
= testDirectory
.close();
4239 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
4241 bool bOK1
,bOK2
,bOK3
;
4242 bOK1
= compareFileName( rFileStatus
.getFileName(), aTmpName2
);
4243 bOK2
= compareFileName( rFileStatus
.getFileName(), aHidURL1
);
4244 bOK3
= compareFileName( rFileStatus
.getFileName(), rFileStatusFirst
.getFileName() );
4245 CPPUNIT_ASSERT_MESSAGE( "test for reset function: get two directory item, reset it, then get again, check the filename",
4246 ( ::osl::FileBase::E_None
== nError2
) &&
4247 ( bOK1
|| bOK2
|| bOK3
) );
4252 ::osl::Directory
testDirectory( aTmpName6
); //constructor
4255 nError1
= testDirectory
.reset();
4257 CPPUNIT_ASSERT_MESSAGE( "test for reset function: reset a non existed directory",
4258 ( ::osl::FileBase::E_NOENT
== nError1
) );
4263 ::osl::Directory
testDirectory( aTmpName4
); //constructor
4266 nError1
= testDirectory
.reset();
4268 CPPUNIT_ASSERT_MESSAGE( "test for reset function: reset a file instead of a directory",
4269 ( ::osl::FileBase::E_NOTDIR
== nError1
) || ( ::osl::FileBase::E_NOENT
== nError1
) );
4274 ::osl::Directory
testDirectory( aUserDirectorySys
); //constructor
4277 nError1
= testDirectory
.reset();
4279 CPPUNIT_ASSERT_MESSAGE( "test for reset function: use a system path",
4280 ( ::osl::FileBase::E_INVAL
== nError1
) );
4283 CPPUNIT_TEST_SUITE( reset
);
4284 CPPUNIT_TEST( reset_001
);
4285 CPPUNIT_TEST( reset_002
);
4286 CPPUNIT_TEST( reset_003
);
4287 CPPUNIT_TEST( reset_004
);
4288 CPPUNIT_TEST_SUITE_END();
4291 // testing the method
4292 // inline RC getNextItem( DirectoryItem& rItem, sal_uInt32 nHint = 0 )
4294 class getNextItem
: public CppUnit::TestFixture
4296 ::osl::FileBase::RC nError1
, nError2
;
4297 ::osl::DirectoryItem rItem
;
4300 getNextItem() :nError1(FileBase::E_None
),nError2(FileBase::E_None
) {}
4302 void setUp() SAL_OVERRIDE
4304 // create a tempdirectory : $TEMP/tmpdir.
4305 createTestDirectory( aTmpName3
);
4306 // create three files : $TEMP/tmpdir/tmpname, $TEMP/tmpdir/tmpdir, $TEMP/tmpdir/hiddenfile,
4307 createTestFile( aTmpName3
, aTmpName2
);
4308 createTestFile( aTmpName3
, aTmpName1
);
4309 createTestFile( aTmpName3
, aHidURL1
);
4313 void tearDown() SAL_OVERRIDE
4315 // remove three files : $TEMP/tmpdir/tmpname, $TEMP/tmpdir/tmpdir, $TEMP/tmpdir/hiddenfile,
4316 deleteTestFile( aTmpName3
, aHidURL1
);
4317 deleteTestFile( aTmpName3
, aTmpName1
);
4318 deleteTestFile( aTmpName3
, aTmpName2
);
4319 // remove a tempdirectory : $TEMP/tmpdir.
4320 deleteTestDirectory( aTmpName3
);
4324 void getNextItem_001()
4326 ::osl::Directory
testDirectory( aTmpName3
); //constructor
4329 nError1
= testDirectory
.open();
4330 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
4332 //check the file name
4336 ::osl::FileStatus
rFileStatus( osl_FileStatus_Mask_FileName
);
4337 for ( int nCount
= 0; nCount
< 3; nCount
++ )
4340 nError1
= testDirectory
.getNextItem( rItem
, 2 );
4341 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
4342 nError1
= rItem
.getFileStatus( rFileStatus
);
4343 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
4345 // a special order is not guaranteed. So any file may occur on any time.
4346 // But every file name should occur only once.
4347 if ( !bOk1
&& compareFileName( rFileStatus
.getFileName(), aTmpName1
) )
4352 if ( !bOk2
&& compareFileName( rFileStatus
.getFileName(), aTmpName2
) )
4357 if ( !bOk3
&& compareFileName( rFileStatus
.getFileName(), aHidURL1
) )
4364 nError1
= testDirectory
.close();
4365 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
4367 CPPUNIT_ASSERT_MESSAGE( "test for getNextItem function: retrieve three items and check their names.",
4368 bOk1
&& bOk2
&& bOk3
);
4371 void getNextItem_002()
4373 ::osl::Directory
testDirectory( aTmpName3
); //constructor
4374 nError1
= testDirectory
.getNextItem( rItem
);
4376 CPPUNIT_ASSERT_MESSAGE( "test for getNextItem function: retrieve an item in a directory which is not opened, also test for nHint's default value.",
4377 ( ::osl::FileBase::E_INVAL
== nError1
) );
4380 void getNextItem_003()
4382 ::osl::Directory
testDirectory( aTmpName3
); //constructor
4385 nError1
= testDirectory
.open();
4386 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
4388 for ( int nCount
= 0; nCount
< 4; nCount
++ )
4390 nError2
= testDirectory
.getNextItem( rItem
, 3 );
4394 nError1
= testDirectory
.close();
4395 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
4397 CPPUNIT_ASSERT_MESSAGE( "test for getNextItem function: retrieve 4 times in a directory which contain only 3 files.",
4398 ( ::osl::FileBase::E_NOENT
== nError2
) );
4401 void getNextItem_004()
4403 //create a link file(can not on Windows), then check if getNextItem can get it.
4405 bool bLnkOK
= false;
4406 bool bFoundOK
= false;
4408 ::rtl::OUString
aUStr_LnkFileSys( aTempDirectorySys
), aUStr_SrcFileSys( aTempDirectorySys
);
4409 ( aUStr_LnkFileSys
+= aSlashURL
) += ::rtl::OUString("/tmpdir/link.file");
4410 ( aUStr_SrcFileSys
+= aSlashURL
) += ::rtl::OUString("/tmpdir/tmpname");
4412 ::rtl::OString strLinkFileName
, strSrcFileName
;
4413 strLinkFileName
= OUStringToOString( aUStr_LnkFileSys
, RTL_TEXTENCODING_ASCII_US
);
4414 strSrcFileName
= OUStringToOString( aUStr_SrcFileSys
, RTL_TEXTENCODING_ASCII_US
);
4416 // create a link file and link it to file "/tmp/PID/tmpdir/tmpname"
4417 sal_Int32 fd
= symlink( strSrcFileName
.getStr(), strLinkFileName
.getStr() );
4418 CPPUNIT_ASSERT( fd
== 0 );
4419 ::osl::Directory
testDirectory( aTmpName3
);
4422 nError1
= testDirectory
.open();
4423 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
4424 ::rtl::OUString
aFileName ("link.file");
4427 nError1
= testDirectory
.getNextItem( rItem
, 4 );
4428 if (::osl::FileBase::E_None
== nError1
) {
4429 ::osl::FileStatus
rFileStatus( osl_FileStatus_Mask_FileName
| osl_FileStatus_Mask_Type
);
4430 rItem
.getFileStatus( rFileStatus
);
4431 if ( compareFileName( rFileStatus
.getFileName(), aFileName
) )
4434 if ( FileStatus::Link
== rFileStatus
.getFileType())
4444 fd
= std::remove( strLinkFileName
.getStr() );
4445 CPPUNIT_ASSERT_MESSAGE( "remove link file failed", fd
== 0 );
4446 CPPUNIT_ASSERT_MESSAGE( "test for getNextItem function: check if can retrieve the link file name",
4448 CPPUNIT_ASSERT_MESSAGE( "test for getNextItem function: check if link file has file type link",
4453 CPPUNIT_TEST_SUITE( getNextItem
);
4454 CPPUNIT_TEST( getNextItem_001
);
4455 CPPUNIT_TEST( getNextItem_002
);
4456 CPPUNIT_TEST( getNextItem_003
);
4457 CPPUNIT_TEST( getNextItem_004
);
4458 CPPUNIT_TEST_SUITE_END();
4459 };// class getNextItem
4461 // testing the method
4462 // inline static RC getVolumeInfo( const ::rtl::OUString& ustrDirectoryURL, VolumeInfo& rInfo )
4464 class getVolumeInfo
: public CppUnit::TestFixture
4466 ::osl::FileBase::RC nError1
;
4470 getVolumeInfo() :nError1(FileBase::E_None
) {}
4472 void checkValidMask(osl::VolumeInfo
const& _aVolumeInfo
, sal_Int32 _nMask
)
4474 if (_nMask
== osl_VolumeInfo_Mask_FileSystemName
)
4476 //get file system name
4477 ::rtl::OUString
aFileSysName( aNullURL
);
4478 aFileSysName
= _aVolumeInfo
.getFileSystemName();
4480 bool bRes2
= compareFileName( aFileSysName
, aNullURL
);
4481 CPPUNIT_ASSERT_MESSAGE( "test for getVolumeInfo function: getVolumeInfo of root directory.",
4482 ( osl::FileBase::E_None
== nError1
) &&
4485 if (_nMask
== osl_VolumeInfo_Mask_Attributes
)
4487 bool b1
= _aVolumeInfo
.getRemoteFlag();
4488 bool b2
= _aVolumeInfo
.getRemoveableFlag();
4489 bool b3
= _aVolumeInfo
.getCompactDiscFlag();
4490 bool b4
= _aVolumeInfo
.getFloppyDiskFlag();
4491 bool b5
= _aVolumeInfo
.getFixedDiskFlag();
4492 bool b6
= _aVolumeInfo
.getRAMDiskFlag();
4495 if (b1
) sAttr
= "Remote";
4496 if (b2
) sAttr
+= " Removeable";
4497 if (b3
) sAttr
+= " CDROM";
4498 if (b4
) sAttr
+= " Floppy";
4499 if (b5
) sAttr
+= " FixedDisk";
4500 if (b6
) sAttr
+= " RAMDisk";
4502 printf("Attributes: %s\n", sAttr
.getStr() );
4504 if (_nMask
== osl_VolumeInfo_Mask_TotalSpace
)
4506 // within Linux, df / * 1024 bytes is the result
4507 sal_uInt64 nSize
= _aVolumeInfo
.getTotalSpace();
4508 printf("Total space: %" SAL_PRIuUINT64
"\n", nSize
);
4510 if (_nMask
== osl_VolumeInfo_Mask_UsedSpace
)
4512 sal_uInt64 nSize
= _aVolumeInfo
.getUsedSpace();
4513 printf(" Used space: %" SAL_PRIuUINT64
"\n", nSize
);
4515 if (_nMask
== osl_VolumeInfo_Mask_FreeSpace
)
4517 sal_uInt64 nSize
= _aVolumeInfo
.getFreeSpace();
4518 printf(" Free space: %" SAL_PRIuUINT64
"\n", nSize
);
4520 if (_nMask
== osl_VolumeInfo_Mask_MaxNameLength
)
4522 sal_uInt32 nLength
= _aVolumeInfo
.getMaxNameLength();
4523 printf("max name length: %" SAL_PRIuUINT32
"\n", nLength
);
4525 if (_nMask
== osl_VolumeInfo_Mask_MaxPathLength
)
4527 sal_uInt32 nLength
= _aVolumeInfo
.getMaxPathLength();
4528 printf("max path length: %" SAL_PRIuUINT32
"\n", nLength
);
4530 if (_nMask
== osl_VolumeInfo_Mask_FileSystemCaseHandling
)
4532 bool bIsCase
= _aVolumeInfo
.isCaseSensitiveFileSystem();
4533 printf("filesystem case sensitive: %s\n", bIsCase
? "yes" : "no");
4537 void checkVolumeInfo(sal_Int32 _nMask
)
4539 ::osl::VolumeInfo
aVolumeInfo( _nMask
);
4540 //call getVolumeInfo here
4541 nError1
= ::osl::Directory::getVolumeInfo( aVolURL1
, aVolumeInfo
);
4542 // LLA: IMHO it's not a bug, if VolumeInfo is not valid, it's a feature
4543 // LLA: CPPUNIT_ASSERT_MESSAGE("mask is not valid", sal_True == aVolumeInfo.isValid( _nMask ) );
4544 if (aVolumeInfo
.isValid( _nMask
))
4546 checkValidMask(aVolumeInfo
, _nMask
);
4550 void getVolumeInfo_001_1()
4552 sal_Int32 mask
= osl_VolumeInfo_Mask_FileSystemName
;
4553 checkVolumeInfo(mask
);
4555 void getVolumeInfo_001_2()
4557 sal_Int32 mask
= osl_VolumeInfo_Mask_Attributes
;
4558 checkVolumeInfo(mask
);
4560 void getVolumeInfo_001_3()
4562 sal_Int32 mask
= osl_VolumeInfo_Mask_TotalSpace
;
4563 checkVolumeInfo(mask
);
4565 void getVolumeInfo_001_4()
4567 sal_Int32 mask
= osl_VolumeInfo_Mask_UsedSpace
;
4568 checkVolumeInfo(mask
);
4570 void getVolumeInfo_001_5()
4572 sal_Int32 mask
= osl_VolumeInfo_Mask_FreeSpace
;
4573 checkVolumeInfo(mask
);
4575 void getVolumeInfo_001_6()
4577 sal_Int32 mask
= osl_VolumeInfo_Mask_MaxNameLength
;
4578 checkVolumeInfo(mask
);
4580 void getVolumeInfo_001_7()
4582 sal_Int32 mask
= osl_VolumeInfo_Mask_MaxPathLength
;
4583 checkVolumeInfo(mask
);
4585 void getVolumeInfo_001_8()
4587 sal_Int32 mask
= osl_VolumeInfo_Mask_FileSystemCaseHandling
;
4588 checkVolumeInfo(mask
);
4591 void getVolumeInfo_002()
4593 sal_Int32 mask
= osl_VolumeInfo_Mask_FileSystemName
;
4594 ::osl::VolumeInfo
aVolumeInfo( mask
);
4595 //call getVolumeInfo here
4597 // LLA: rtl::OUString aRootSysURL;
4598 // LLA: nError1 = osl::File::getFileURLFromSystemPath(aRootSys, aRootSysURL);
4600 // LLA: CPPUNIT_ASSERT_MESSAGE( "can't convert root path to file url",
4601 // LLA: ( osl::FileBase::E_NONE == nError1 ) );
4603 nError1
= ::osl::Directory::getVolumeInfo( aRootSys
, aVolumeInfo
);
4605 CPPUNIT_ASSERT_MESSAGE( "test for getVolumeInfo function: use system path as parameter.",
4606 ( osl::FileBase::E_INVAL
== nError1
) );
4609 void getVolumeInfo_003()
4611 sal_Int32 mask
= osl_VolumeInfo_Mask_FileSystemName
;
4612 ::osl::VolumeInfo
aVolumeInfo( mask
);
4613 //call getVolumeInfo here
4614 nError1
= ::osl::Directory::getVolumeInfo( aTmpName3
, aVolumeInfo
);
4616 // LLA: in Windows, it reply no error, it did not pass in (W32).
4617 #if defined(UNX) && !defined(IOS)
4618 CPPUNIT_ASSERT_MESSAGE( "test for getVolumeInfo function: non-existence test. ",
4619 ( osl::FileBase::E_NOENT
== nError1
) );
4623 CPPUNIT_TEST_SUITE( getVolumeInfo
);
4624 CPPUNIT_TEST( getVolumeInfo_001_1
);
4625 CPPUNIT_TEST( getVolumeInfo_001_2
);
4626 CPPUNIT_TEST( getVolumeInfo_001_3
);
4627 CPPUNIT_TEST( getVolumeInfo_001_4
);
4628 CPPUNIT_TEST( getVolumeInfo_001_5
);
4629 CPPUNIT_TEST( getVolumeInfo_001_6
);
4630 CPPUNIT_TEST( getVolumeInfo_001_7
);
4631 CPPUNIT_TEST( getVolumeInfo_001_8
);
4632 CPPUNIT_TEST( getVolumeInfo_002
);
4633 CPPUNIT_TEST( getVolumeInfo_003
);
4634 CPPUNIT_TEST_SUITE_END();
4635 };// class getVolumeInfo
4637 // testing the method
4638 // inline static RC create( const ::rtl::OUString& ustrDirectoryURL )
4640 class create
: public CppUnit::TestFixture
4642 ::osl::FileBase::RC nError1
, nError2
;
4647 create() :nError1(FileBase::E_None
),nError2(FileBase::E_None
) {}
4650 //create directory in $TEMP/tmpdir
4651 nError1
= ::osl::Directory::create( aTmpName3
);
4652 //check for existence
4653 nError2
= ::osl::Directory::create( aTmpName3
);
4655 deleteTestDirectory( aTmpName3
);
4657 CPPUNIT_ASSERT_MESSAGE( "test for create function: create a directory and check its existence.",
4658 ( osl::FileBase::E_None
== nError1
) &&
4659 ( osl::FileBase::E_EXIST
== nError2
) );
4664 #if !defined (WNT) && !defined (MACOSX) && defined (SAL_UNX)
4665 if (geteuid() == 0) //don't test if building as root
4668 rtl::OUString aTmpDir
;
4669 nError1
= FileBase::createTempFile(NULL
, NULL
, &aTmpDir
);
4670 CPPUNIT_ASSERT_MESSAGE("temp File creation failed", osl::FileBase::E_None
== nError1
);
4672 nError1
= ::osl::File::remove(aTmpDir
);
4673 CPPUNIT_ASSERT_MESSAGE("temp File removal failed", osl::FileBase::E_None
== nError1
);
4675 nError1
= ::osl::Directory::create(aTmpDir
);
4676 ::rtl::OString
sError("test for create function: create a directory '");
4677 sError
+= ::rtl::OUStringToOString(aTmpDir
, RTL_TEXTENCODING_ASCII_US
);
4678 sError
+= "' and check its existence.";
4679 CPPUNIT_ASSERT_MESSAGE(sError
.getStr(), osl::FileBase::E_None
== nError1
);
4680 osl_setFileAttributes(aTmpDir
.pData
, 0); //no access allowed now
4682 //Shouldn't be possible now to create a dir underneath it
4683 rtl::OUString aTmpSubLevel
= aTmpDir
+ "/notallowedhere";
4684 nError1
= ::osl::Directory::create(aTmpSubLevel
);
4687 osl_setFileAttributes(aTmpDir
.pData
,
4688 osl_File_Attribute_OwnRead
|
4689 osl_File_Attribute_OwnWrite
|
4690 osl_File_Attribute_OwnExe
);
4691 deleteTestDirectory(aTmpDir
);
4692 sError
= ::rtl::OString("test for create function: create a directory under '");
4693 sError
+= ::rtl::OUStringToOString(aTmpDir
, RTL_TEXTENCODING_ASCII_US
);
4694 sError
+= "' for access test.";
4695 CPPUNIT_ASSERT_MESSAGE(sError
.getStr(), osl::FileBase::E_ACCES
== nError1
);
4701 //create directory in /tmpname
4702 nError1
= ::osl::Directory::create( aSysPath1
);
4704 CPPUNIT_ASSERT_MESSAGE( "test for create function: create a directory using system path.",
4705 ( osl::FileBase::E_INVAL
== nError1
) );
4708 CPPUNIT_TEST_SUITE( create
);
4709 CPPUNIT_TEST( create_001
);
4710 CPPUNIT_TEST( create_002
);
4711 CPPUNIT_TEST( create_003
);
4712 CPPUNIT_TEST_SUITE_END();
4715 // testing the method
4716 // inline static RC remove( const ::rtl::OUString& ustrDirectoryURL )
4718 class remove
: public CppUnit::TestFixture
4720 ::osl::FileBase::RC nError1
, nError2
;
4724 remove() :nError1(FileBase::E_None
),nError2(FileBase::E_None
) {}
4728 //create directory in $TEMP/tmpdir
4729 nError1
= ::osl::Directory::create( aTmpName3
);
4730 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
4732 nError1
= ::osl::Directory::remove( aTmpName3
);
4733 //check for existence
4734 ::osl::Directory
rDirectory( aTmpName3
);
4735 nError2
= rDirectory
.open();
4737 CPPUNIT_ASSERT_MESSAGE( "test for remove function: remove a directory and check its existence.",
4738 ( osl::FileBase::E_None
== nError1
) &&
4739 ( osl::FileBase::E_NOENT
== nError2
) );
4744 //create directory in $TEMP/tmpdir
4745 nError1
= ::osl::Directory::create( aTmpName3
);
4746 CPPUNIT_ASSERT( ::osl::FileBase::E_None
== nError1
);
4747 //try to remove it by system path
4748 nError1
= ::osl::Directory::remove( aSysPath3
);
4749 //check for existence
4750 ::osl::Directory
rDirectory( aTmpName3
);
4751 nError2
= rDirectory
.open();
4752 if ( osl::FileBase::E_NOENT
!= nError2
)
4753 ::osl::Directory::remove( aTmpName3
);
4755 CPPUNIT_ASSERT_MESSAGE( "test for remove function: remove a directory by its system path, and check its existence.",
4756 ( osl::FileBase::E_INVAL
== nError1
) );
4761 //try to remove a non-existed directory
4762 nError1
= ::osl::Directory::remove( aTmpName6
);
4764 CPPUNIT_ASSERT_MESSAGE( "test for remove function: try to remove a non-existed directory.",
4765 ( osl::FileBase::E_NOENT
== nError1
) );
4770 createTestFile( aTmpName6
);
4771 bool bExist
= ifFileExist( aTmpName6
);
4772 //try to remove file.
4773 nError1
= ::osl::Directory::remove( aTmpName6
);
4774 deleteTestFile( aTmpName6
);
4776 CPPUNIT_ASSERT_MESSAGE( "test for remove function: try to remove a file but not directory.",
4777 bExist
&&(( osl::FileBase::E_NOTDIR
== nError1
) || ( osl::FileBase::E_NOENT
== nError1
)) );
4782 createTestDirectory( aTmpName3
);
4783 createTestFile( aTmpName4
);
4784 nError1
= ::osl::Directory::remove( aTmpName3
);
4785 deleteTestFile( aTmpName4
);
4786 deleteTestDirectory( aTmpName3
);
4787 ::rtl::OString sError
= "test for remove function: try to remove a directory that is not empty.";
4788 sError
+= errorToStr( nError1
).getStr();
4789 #if defined ( SOLARIS )
4790 //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.
4791 //EEXIST The directory contains entries other than those for "." and "..".
4792 printf("#Solaris test\n");
4793 CPPUNIT_ASSERT_MESSAGE( sError
.getStr(), ( osl::FileBase::E_EXIST
== nError1
) );
4795 CPPUNIT_ASSERT_MESSAGE( sError
.getStr(), ( osl::FileBase::E_NOTEMPTY
== nError1
) );
4799 CPPUNIT_TEST_SUITE( remove
);
4800 CPPUNIT_TEST( remove_001
);
4801 CPPUNIT_TEST( remove_002
);
4802 CPPUNIT_TEST( remove_003
);
4803 CPPUNIT_TEST( remove_004
);
4804 CPPUNIT_TEST( remove_005
);
4805 CPPUNIT_TEST_SUITE_END();
4808 // TEST Directory::createPath
4811 # define PATH_BUFFER_SIZE MAX_PATH
4813 # define PATH_BUFFER_SIZE PATH_MAX
4816 #define TEST_PATH_POSTFIX "hello/world"
4818 OUString
get_test_path()
4820 static OUString test_path
;
4821 if (test_path
.isEmpty())
4824 FileBase::RC rc
= FileBase::getTempDirURL(tmp
);
4826 CPPUNIT_ASSERT_MESSAGE
4828 "Getting the location of TMP dir failed",
4829 rc
== FileBase::E_None
4832 OUString system_path
;
4833 rc
= FileBase::getSystemPathFromFileURL(tmp
, system_path
);
4835 CPPUNIT_ASSERT_MESSAGE
4837 "Cannot convert the TMP dir to system path",
4838 rc
== FileBase::E_None
4841 OString
tmp_x(rtl::OUStringToOString(system_path
, RTL_TEXTENCODING_UTF8
));
4842 if (tmp_x
.lastIndexOf('/') != (tmp_x
.getLength() - 1))
4843 tmp_x
+= rtl::OString('/');
4845 #if !defined(WNT) && !defined(ANDROID) && !defined(AIX)
4846 // FIXME would be nice to create unique dir even on Windows
4847 tmp_x
+= rtl::OString("XXXXXX");
4848 char *out
= mkdtemp(const_cast<char*>(tmp_x
.getStr()));
4850 CPPUNIT_ASSERT_MESSAGE
4852 "mkdtemp call failed",
4856 tmp_x
+= rtl::OString('/');
4858 tmp_x
+= rtl::OString(TEST_PATH_POSTFIX
);
4860 rc
= FileBase::getFileURLFromSystemPath(rtl::OStringToOUString(tmp_x
, RTL_TEXTENCODING_UTF8
), test_path
);
4862 CPPUNIT_ASSERT_MESSAGE
4864 "Cannot convert the system path back to an URL",
4865 rc
== FileBase::E_None
4871 void rm_test_path(const OUString
& path
)
4873 sal_Unicode buffer
[PATH_BUFFER_SIZE
];
4874 memcpy(buffer
, path
.getStr(), (path
.getLength() + 1) * sizeof(sal_Unicode
));
4876 sal_Int32 i
= rtl_ustr_lastIndexOfChar(buffer
, '/');
4877 if (i
== path
.getLength())
4880 Directory::remove(buffer
);
4882 i
= rtl_ustr_lastIndexOfChar(buffer
, '/');
4887 Directory::remove(buffer
);
4891 class DirCreatedObserver
: public DirectoryCreationObserver
4894 DirCreatedObserver() : i(0)
4898 virtual void DirectoryCreated(const rtl::OUString
& /*aDirectoryUrl*/) SAL_OVERRIDE
4903 int number_of_dirs_created() const
4912 class createPath
: public CppUnit::TestFixture
4919 void with_relative_path()
4921 FileBase::RC rc
= Directory::createPath( OUString(TEST_PATH_POSTFIX
));
4923 CPPUNIT_ASSERT_MESSAGE
4925 "osl_createDirectoryPath contract broken",
4926 rc
== FileBase::E_INVAL
4930 void without_callback()
4932 OUString tp_url
= get_test_path();
4934 rm_test_path(tp_url
);
4936 FileBase::RC rc
= Directory::createPath(tp_url
);
4938 rm_test_path(tp_url
);
4940 CPPUNIT_ASSERT_MESSAGE
4942 "osl_createDirectoryPath failed",
4943 rc
== FileBase::E_None
4947 void with_callback()
4949 OUString tp_url
= get_test_path();
4951 rm_test_path(tp_url
);
4953 DirCreatedObserver
* observer
= new DirCreatedObserver
;
4954 FileBase::RC rc
= Directory::createPath(tp_url
, observer
);
4955 int nDirs
= observer
->number_of_dirs_created();
4958 rm_test_path(tp_url
);
4960 CPPUNIT_ASSERT_MESSAGE
4962 "osl_createDirectoryPath failed",
4963 (rc
== FileBase::E_None
) && (nDirs
> 0)
4970 const char* get_unused_drive_letter()
4972 static const char m_aBuff
[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
4974 DWORD ld
= GetLogicalDrives();
4978 while ((ld
& i
) && (i
> 1))
4979 { i
= i
<< 1; j
++; }
4987 void at_invalid_logical_drive()
4989 const char* drv
= get_unused_drive_letter();
4990 char buff
[PATH_BUFFER_SIZE
];
4991 memset(buff
, 0, sizeof(buff
));
4993 strncpy(buff
, drv
, 1);
4994 strcat(buff
, ":\\");
4995 strcat(buff
, TEST_PATH_POSTFIX
);
4997 OUString path
= OUString::createFromAscii(buff
);
4999 FileBase::getFileURLFromSystemPath(path
, tp_url
);
5001 FileBase::RC rc
= Directory::createPath(tp_url
);
5003 CPPUNIT_ASSERT_MESSAGE
5005 "osl_createDirectoryPath doesn't fail on unused logical drive letters",
5006 rc
!= FileBase::E_None
5011 CPPUNIT_TEST_SUITE(createPath
);
5012 CPPUNIT_TEST(with_relative_path
);
5013 CPPUNIT_TEST(without_callback
);
5014 CPPUNIT_TEST(with_callback
);
5016 CPPUNIT_TEST(at_invalid_logical_drive
);
5018 CPPUNIT_TEST_SUITE_END();
5020 }; // class createPath
5022 CPPUNIT_TEST_SUITE_REGISTRATION( osl_Directory::ctors
);
5023 CPPUNIT_TEST_SUITE_REGISTRATION( osl_Directory::open
);
5024 CPPUNIT_TEST_SUITE_REGISTRATION( osl_Directory::isOpen
);
5025 CPPUNIT_TEST_SUITE_REGISTRATION( osl_Directory::close
);
5026 CPPUNIT_TEST_SUITE_REGISTRATION( osl_Directory::reset
);
5027 CPPUNIT_TEST_SUITE_REGISTRATION( osl_Directory::getNextItem
);
5028 CPPUNIT_TEST_SUITE_REGISTRATION( osl_Directory::getVolumeInfo
);
5029 CPPUNIT_TEST_SUITE_REGISTRATION( osl_Directory::create
);
5030 CPPUNIT_TEST_SUITE_REGISTRATION( osl_Directory::remove
);
5031 CPPUNIT_TEST_SUITE_REGISTRATION( osl_Directory::createPath
);
5032 }// namespace osl_Directory
5034 CPPUNIT_PLUGIN_IMPLEMENT();
5036 /** get Current PID.
5038 inline ::rtl::OUString
getCurrentPID( )
5040 //~ Get current PID and turn it into OUString;
5043 nPID
= GetCurrentProcessId();
5047 return ( OUString::number( nPID
) );
5050 //~ do some clean up work after all test completed.
5058 //~ special clean up task in Windows and Unix separately;
5060 //~ some clean up task for UNIX OS
5063 //~ some clean up task for Windows OS
5064 //~ check if some files are in the way, remove them if necessary.
5065 if ( ifFileExist( aTmpName6
) == sal_True
)
5066 deleteTestFile( aTmpName6
);
5067 if ( ifFileExist( aTmpName4
) == sal_True
)
5068 deleteTestFile( aTmpName4
);
5069 if ( checkDirectory( aTmpName4
, osl_Check_Mode_Exist
) == sal_True
)
5070 deleteTestDirectory( aTmpName4
);
5071 if ( ifFileExist( aTmpName3
) == sal_True
)
5072 deleteTestFile( aTmpName3
);
5073 if ( checkDirectory( aTmpName3
, osl_Check_Mode_Exist
) == sal_True
)
5074 deleteTestDirectory( aTmpName3
);
5076 ::rtl::OUString
aUStr( aUserDirectoryURL
);
5077 concatURL( aUStr
, aHidURL1
);
5078 if ( ifFileExist( aUStr
) == sal_True
)
5079 deleteTestFile( aUStr
);
5081 ::rtl::OUString
aUStr1( aRootURL
);
5082 concatURL( aUStr1
, aTmpName2
);
5083 if ( ifFileExist( aUStr1
) == sal_True
)
5084 deleteTestFile( aUStr1
);
5087 catch (const CppUnit::Exception
&e
)
5089 printf("Exception caught in GlobalObject dtor(). Exception message: '%s'. Source line: %d\n", e
.what(), e
.sourceLine().lineNumber());
5093 printf("Exception caught (...) in GlobalObject dtor()\n");
5098 GlobalObject theGlobalObject
;
5100 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */