1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: testfile.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sal.hxx"
37 #include <osl/file.hxx>
38 #include <osl/process.h>
40 #include <rtl/alloc.h>
41 #include <rtl/ustring.hxx>
64 rtl::OUString dir_on_server
;
65 rtl::OUString dir_not_exist
;
66 rtl::OUString dir_not_exist_on_server
;
67 rtl::OUString dir_wrong_semantic
;
72 rtl::OUString file_on_server
;
73 rtl::OUString file_not_exist
;
77 void print_error(::rtl::OString
& str
, FileBase::RC rc
);
81 printf("\nPress Return !\n");
85 void printFileName(::rtl::OUString
& str
)
89 aString
= rtl::OUStringToOString( str
, RTL_TEXTENCODING_ASCII_US
);
91 printf( "%s", aString
.getStr() );
96 //--------------------------------------------------
98 //--------------------------------------------------
100 sal_Bool
testLineBreak( sal_Char
*pCount
, sal_uInt64 nLen
, sal_uInt32
*cLineBreak
)
102 sal_Bool fSuccess
=sal_False
;
110 if (nLen
>=1 && *(pCount
+1)==10)
115 if (nLen
>=2 && *(pCount
+2)==10)
120 else if ( *pCount
==10 )
131 sal_Bool
Initialize( void )
134 FileStatus
aStatus( FileStatusMask_All
);
135 rtl_uString
*strExeFileURL
=NULL
;
136 oslProcessError ProcessError
;
138 rtl::OUString iniFileURL
;
140 sal_Unicode
*pExeFileCount
;
144 sal_uInt64 uBytesRequested
;
145 sal_uInt64 uBytesRead
;
150 rtl::OUString dir
[12];
152 // Open to the ini-file
154 ProcessError
=osl_getExecutableFile(&strExeFileURL
);
156 if ( ProcessError
== osl_Process_E_None
)
158 pExeFileCount
=rtl_uString_getStr(strExeFileURL
)+rtl_uString_getLength(strExeFileURL
);
160 // Search for the last slash in the Path
161 while (*pExeFileCount
!=L
'/' && pExeFileCount
>rtl_uString_getStr(strExeFileURL
))
164 // iniFileURL = strExeFileURL without the filename of the exe-File
165 iniFileURL
=rtl::OUString( rtl_uString_getStr(strExeFileURL
) ,(int) (pExeFileCount
-rtl_uString_getStr(strExeFileURL
)) );
167 // add "/testfile.ini" to iniFileURL
168 iniFileURL
+=rtl::OUString::createFromAscii("/testfile.ini");
171 pFile
=new File( iniFileURL
);
172 rc
=pFile
->open( OpenFlag_Read
| OpenFlag_Write
);
173 if ( rc
!=FileBase::E_None
)
175 rtl_uString_release(strExeFileURL
);
181 rtl_uString_release(strExeFileURL
);
185 // Get filesize of the ini-File
187 rc
=DirectoryItem::get( iniFileURL
, aItem
);
188 if ( rc
!=FileBase::E_None
)
191 rc
=aItem
.getFileStatus( aStatus
);
192 if ( rc
!=FileBase::E_None
)
195 uBytesRequested
=aStatus
.getFileSize();
198 rc
=pFile
->setPos( Pos_Absolut
, 0 );
199 pBuffer
=(sal_Char
*) rtl_allocateMemory( (sal_uInt32
) (uBytesRequested
+1)*sizeof(sal_Char
) );
200 rtl_zeroMemory( pBuffer
, (sal_uInt32
)(uBytesRequested
+1)*sizeof(sal_Char
) );
202 rc
=pFile
->read( pBuffer
, uBytesRequested
, uBytesRead
);
203 if ( rc
!=FileBase::E_None
)
210 for ( int i
=0 ; i
<12 ; i
++ )
212 sal_uInt32 cLineBrake
=0;
213 while ( (pCount
-pBuffer
< uBytesRead
) && *pCount
!='=')
219 while ( (pCount
-pBuffer
< uBytesRead
) && !testLineBreak(pCount
,uBytesRead
-(pCount
-pBuffer
), &cLineBrake
))
222 dir
[i
]=rtl::OUString(pBegin
, pCount
-pBegin
, RTL_TEXTENCODING_ASCII_US
);
228 root
=rtl::OUString(dir
[0]);
229 dir1
=rtl::OUString(dir
[1]);
230 dir2
=rtl::OUString(dir
[2]);
231 dir_on_server
=rtl::OUString(dir
[3]);
232 dir_not_exist
=rtl::OUString(dir
[4]);
233 dir_not_exist_on_server
=rtl::OUString(dir
[5]);
234 dir_wrong_semantic
=rtl::OUString(dir
[6]);
236 file1
=rtl::OUString(dir
[7]);
237 file2
=rtl::OUString(dir
[8]);
238 file3
=rtl::OUString(dir
[9]);
239 file_on_server
=rtl::OUString(dir
[10]);
240 file_not_exist
=rtl::OUString(dir
[11]);
242 // close the ini-file
245 rtl_freeMemory( pBuffer
);
248 // Create directories
249 rc
=Directory::create( dir1
);
250 if ( rc
!=FileBase::E_None
)
253 rc
=Directory::create( dir2
);
254 if ( rc
!=FileBase::E_None
)
257 rc
=Directory::create( dir_on_server
);
258 if ( rc
!=FileBase::E_None
)
261 pFile
=new File( file1
);
262 rc
=pFile
->open( OpenFlag_Write
| OpenFlag_Create
);
263 if ( rc
!=FileBase::E_None
)
268 pFile
=new File( file2
);
269 rc
=pFile
->open( OpenFlag_Write
| OpenFlag_Create
);
270 if ( rc
!=FileBase::E_None
)
275 pFile
=new File( file_on_server
);
276 rc
=pFile
->open( OpenFlag_Write
| OpenFlag_Create
);
277 if ( rc
!=FileBase::E_None
)
285 //--------------------------------------------------
287 //--------------------------------------------------
289 sal_Bool
Shutdown( void )
291 sal_Bool fSuccess
=sal_True
;
295 // remove created files
297 pFile
=new File( file1
);
298 rc
=pFile
->remove( file1
);
299 if ( rc
!=FileBase::E_None
)
303 pFile
=new File( file2
);
304 rc
=pFile
->remove( file2
);
305 if ( rc
!=FileBase::E_None
)
309 // remove created directories
311 rc
=Directory::remove( dir1
);
312 if ( rc
!=FileBase::E_None
)
315 rc
=Directory::remove( dir2
);
316 if ( rc
!=FileBase::E_None
)
319 // remove created file on the server
321 pFile
=new File( file_on_server
);
322 rc
=pFile
->remove( file_on_server
);
323 if ( rc
!=FileBase::E_None
)
327 // remove created directory on the server
329 rc
=Directory::remove( dir_on_server
);
330 if ( rc
!=FileBase::E_None
)
336 //--------------------------------------------------
338 //--------------------------------------------------
341 void showFileType( FileStatus::Type aType
)
343 if ( aType
==FileStatus::Directory
)
344 printf( "FileType: Directory \n" );
345 else if ( aType
==FileStatus::Volume
)
346 printf( "FileType: Volume \n" );
347 else if ( aType
==FileStatus::Regular
)
348 printf( "FileType: Regular \n" );
349 else if ( aType
==FileStatus::Unknown
)
350 printf( "FileType: Unknown \n" );
355 void showAttributes( sal_uInt64 uAttributes
)
357 if ( uAttributes
==0 )
358 printf( "No Attributes \n" );
359 if ( uAttributes
& Attribute_ReadOnly
)
360 printf( "Attribute: ReadOnly \n" );
361 if ( uAttributes
& Attribute_Hidden
)
362 printf( "Attribute: Hidden \n" );
363 if ( uAttributes
& Attribute_Executable
)
364 printf( "Attribute: Executable \n");
365 if ( uAttributes
& Attribute_GrpWrite
)
366 printf( "Attribute: GrpWrite \n");
367 if ( uAttributes
& Attribute_GrpRead
)
368 printf( "Attribute: GrpRead \n" );
369 if ( uAttributes
& Attribute_GrpExe
)
370 printf( "Attribute: GrpExe \n" );
371 if ( uAttributes
& Attribute_OwnWrite
)
372 printf( "Attribute: OwnWrite \n");
373 if ( uAttributes
& Attribute_OwnRead
)
374 printf( "Attribute: OwnRead \n" );
375 if ( uAttributes
& Attribute_OwnExe
)
376 printf( "Attribute: OwnExe \n" );
377 if ( uAttributes
& Attribute_OthWrite
)
378 printf( "Attribute: OthWrite \n" );
379 if ( uAttributes
& Attribute_OthRead
)
380 printf( "Attribute: OthRead \n");
381 if ( uAttributes
& Attribute_OthExe
)
382 printf( "Attribute: OthExe \n" );
388 void showTime( TimeValue aTime
)
390 TimeValue aLocalTimeVal
, aSystemTimeVal
, aSysTimeVal
;
391 oslDateTime aDateTime
, aSystemTime
;
393 if ( osl_getLocalTimeFromSystemTime( &aTime
, &aLocalTimeVal
) )
395 if ( osl_getDateTimeFromTimeValue( &aLocalTimeVal
, &aDateTime
) )
397 printf("\t%02i.%02i.%4i , %02i.%02i.%02i Uhr\n", aDateTime
.Day
, aDateTime
.Month
, aDateTime
.Year
, aDateTime
.Hours
, aDateTime
.Minutes
, aDateTime
.Seconds
);
403 if ( osl_getDateTimeFromTimeValue( &aTime
, &aSystemTime
) )
405 printf("SystemTime: \t\t%02i.%02i.%4i , %02i.%02i.%02i Uhr\n", aSystemTime
.Day
, aSystemTime
.Month
, aSystemTime
.Year
, aSystemTime
.Hours
, aSystemTime
.Minutes
, aSystemTime
.Seconds
);
412 if ( osl_getTimeValueFromDateTime( &aSystemTime
, &aSystemTimeVal
) )
414 if ( ( aSystemTimeVal
.Seconds
== aTime
.Seconds
) && ( aSystemTimeVal
.Nanosec
== aTime
.Nanosec
))
415 printf ("Verify : TimeValue : ok! \n");
418 printf ("Verify : TimeValue : Error! \n");
419 printf ("aTime : %u \n", aTime
.Seconds
);
420 printf ("aSystemTimeVal : %u \n", aSystemTimeVal
.Seconds
);
424 printf ("Verify : TimeValue : Error! \n");
427 if ( osl_getSystemTimeFromLocalTime( &aLocalTimeVal
, &aSysTimeVal
) )
429 if ( ( aSysTimeVal
.Seconds
== aTime
.Seconds
) && ( aSysTimeVal
.Nanosec
== aTime
.Nanosec
))
430 printf ("Verify : SystemTime : ok! \n");
433 printf ("Verify : SystemTime : Error! \n");
434 printf ("aTime : %u\n", aTime
.Seconds
);
435 printf ("aSystemTimeVal : %u\n", aSysTimeVal
.Seconds
);
439 printf ("Verify : SystemTime : Error! \n");
444 TimeValue
getSystemTime()
451 aTime
.Seconds
= ltime
;
458 //--------------------------------------------------
459 // DirectoryOpenAndCloseTest
460 //--------------------------------------------------
462 void DirectoryOpenAndCloseTest( void )
468 printf( "--------------------------------------------\n");
469 printf( "Directory-Open-And-Close-Test\n");
470 printf( "--------------------------------------------\n\n");
472 //--------------------------------------------------
473 // open an existing directory
474 //--------------------------------------------------
476 pDir
=new Directory( dir1
);
477 printf( "Open an existing directory: ");
478 printFileName( dir1
);
482 print_error( rtl::OString( "Open Directory" ), rc
);
484 if ( pDir
->isOpen() )
486 print_error( rtl::OString( "Directory is Open" ), rc
);
491 print_error( rtl::OString( "Close Directory" ), rc
);
496 //--------------------------------------------------
497 // open a not existing directory
498 //--------------------------------------------------
500 pDir
=new Directory( dir_not_exist
);
502 printf( "Open a not existing directory: ");
503 printFileName( dir_not_exist
);
508 print_error( rtl::OString( "Open Directory" ), rc
);
514 //--------------------------------------------------
515 // open a directory with a wrong semantic
516 //--------------------------------------------------
517 pDir
=new Directory( dir_wrong_semantic
);
519 printf( "Open a directory with a wrong semantic: ");
520 printFileName( dir_wrong_semantic
);
524 print_error( rtl::OString( "Open Directory" ), rc
);
530 //--------------------------------------------------
531 // open an existing directory on a server
532 //--------------------------------------------------
534 pDir
=new Directory( dir_on_server
);
536 printf( "Open an existing directory on a server: ");
537 printFileName( dir_on_server
);
541 print_error( rtl::OString( "Open Directory" ), rc
);
545 print_error( rtl::OString( "Close Directory" ), rc
);
550 //--------------------------------------------------
551 // open a not existing directory on a server
552 //--------------------------------------------------
554 pDir
=new Directory( dir_not_exist_on_server
);
556 printf( "Open a not existing directory on a server: ");
557 printFileName( dir_not_exist_on_server
);
561 print_error( rtl::OString( "Open Directory" ), rc
);
566 //--------------------------------------------------
567 // Close a not existing directory
568 //--------------------------------------------------
570 pDir
=new Directory( dir_not_exist
);
571 printf( "Close a not existing directory: ");
572 printFileName( dir_not_exist
);
576 print_error( rtl::OString( "Close Directory" ), rc
);
583 //--------------------------------------------------
584 // DirectoryCreateAndRemoveTest
585 //--------------------------------------------------
587 void DirectoryCreateAndRemoveTest( void )
593 printf( "--------------------------------------------\n" );
594 printf( "Directory-Create-And-Remove-Test\n" );
595 printf( "--------------------------------------------\n\n" );
597 //--------------------------------------------------
599 //--------------------------------------------------
600 printf( "Create a not existing directory: ");
601 printFileName( dir_not_exist
);
604 rc
=Directory::create( dir_not_exist
) ;
605 print_error( rtl::OString( "Create Directory" ), rc
);
608 pDir
=new Directory( dir_not_exist
);
611 print_error( rtl::OString( "Verify" ), rc
);
617 //--------------------------------------------------
618 // Create a directory on a server
619 //--------------------------------------------------
621 printf( "Create a not existing directory on a server: ");
622 printFileName( dir_not_exist_on_server
);
625 rc
=Directory::create( dir_not_exist_on_server
);
626 print_error( rtl::OString( "Create Directory" ), rc
);
629 pDir
=new Directory( dir_not_exist_on_server
);
631 print_error( rtl::OString( "Verify" ), rc
);
637 //--------------------------------------------------
638 // Remove Directories
639 //--------------------------------------------------
641 printf( "Remove the created directories: \n" );
643 rc
=Directory::remove( dir_not_exist
);
645 rc1
=Directory::remove( dir_not_exist_on_server
);
647 if ( rc
==FileBase::E_None
&& rc1
==FileBase::E_None
)
648 print_error( rtl::OString( "Remove Directories" ), FileBase::E_None
);
649 else if ( rc
!=FileBase::E_None
)
650 print_error( rtl::OString( "Remove local Directory" ),rc
);
652 print_error( rtl::OString( "Remove Directory on a server" ),rc1
);
656 //--------------------------------------------------
657 // Remove a not existing directory
658 //--------------------------------------------------
660 printf( "Remove a not existing directory: ");
661 printFileName( dir_not_exist
);
664 rc
=Directory::remove( dir_not_exist
);
665 print_error( rtl::OString( "Remove" ),rc
);
671 //--------------------------------------------------
672 // FileOpenAndCloseTest
673 //--------------------------------------------------
675 static void FileOpenAndCloseTest( void )
680 printf( "--------------------------------------------\n" );
681 printf( "File-Open-And-Close-Test\n" );
682 printf( "--------------------------------------------\n\n" );
686 pFile
=new File( file1
);
688 printf( "Open an existing file: ");
689 printFileName( file1
);
692 //--------------------------------------------------
693 // open an existing file (Read)
694 //--------------------------------------------------
696 rc
=pFile
->open( OpenFlag_Read
);
697 print_error( rtl::OString( "Open File (Read)" ), rc
);
699 //--------------------------------------------------
701 //--------------------------------------------------
704 print_error( rtl::OString( "Close File" ), rc
);
708 //--------------------------------------------------
709 // open an existing file (Write)
710 //--------------------------------------------------
712 rc
=pFile
->open( OpenFlag_Write
);
713 print_error( rtl::OString( "Open File (Write)" ), rc
);
715 //--------------------------------------------------
717 //--------------------------------------------------
720 print_error( rtl::OString( "Close File" ), rc
);
724 //--------------------------------------------------
725 // close the file a second time
726 //--------------------------------------------------
729 print_error( rtl::OString( "Close the file a second time" ), rc
);
735 //--------------------------------------------------
736 // FileCreateAndRemoveTest
737 //--------------------------------------------------
739 void FileCreateAndRemoveTest()
744 printf( "--------------------------------------------\n" );
745 printf( "File-Create-And-Remove-Test\n" );
746 printf( "--------------------------------------------\n\n" );
748 pFile
=new File( file_not_exist
);
750 printf( "Create File: ");
751 printFileName( file_not_exist
);
754 //----------------------------------------------------
755 // open (create) a not existing file (Read and write)
756 //----------------------------------------------------
758 rc
= pFile
->open( OpenFlag_Read
| OpenFlag_Write
| osl_File_OpenFlag_Create
);
760 print_error( rtl::OString( "Create and Open File (Read & Write)" ), rc
);
762 //----------------------------------------------------
764 //----------------------------------------------------
767 print_error( rtl::OString( "Close File" ), rc
);
769 //----------------------------------------------------
771 //----------------------------------------------------
773 rc
=pFile
->remove( file_not_exist
);
774 print_error( rtl::OString(" Remove File" ), rc
);
778 //----------------------------------------------------
779 // remove the same file a second time
780 //----------------------------------------------------
781 rc
=pFile
->remove( file_not_exist
);
782 print_error( rtl::OString( "Remove a not existing File" ), rc
);
784 //----------------------------------------------------
785 // remove an open file
786 //----------------------------------------------------
788 pFile
->open( OpenFlag_Read
| OpenFlag_Write
| osl_File_OpenFlag_Create
);
790 rc
=pFile
->remove( file_not_exist
);
791 print_error( rtl::OString( "Remove an open File" ), rc
);
794 pFile
->remove( file_not_exist
);
801 //--------------------------------------------------
802 // FileWriteAndReadTest
803 //--------------------------------------------------
805 void FileWriteAndReadTest( void )
811 sal_Char
*pWriteBuffer
="Hier kommt der Osterhase !";
812 sal_uInt64 nLen
=strlen( pWriteBuffer
);
813 sal_Char
*pReadBuffer
;
815 printf( "--------------------------------------------\n" );
816 printf( "File-Write-And-Read-Test\n" );
817 printf( "--------------------------------------------\n\n" );
821 pFile
=new File( file_not_exist
);
823 printf( "Create File: ");
824 printFileName( file_not_exist
);
827 //----------------------------------------------------
828 // open (create) a not existing file (Read and write)
829 //----------------------------------------------------
831 rc
= pFile
->open( OpenFlag_Read
| OpenFlag_Write
| osl_File_OpenFlag_Create
);
833 print_error( rtl::OString( "Create and Open File (Read & Write)" ), rc
);
837 //----------------------------------------------------
838 // write a string to the file
839 //----------------------------------------------------
840 rc
=pFile
->write( pWriteBuffer
, nLen
, uWritten
);
841 print_error( rtl::OString( "Write File" ), rc
);
844 printf( "Verify: OK! \n" );
846 printf( "Verify: Error\n" );
850 //----------------------------------------------------
851 // move the filepointer to the beginning
852 //----------------------------------------------------
854 rc
=pFile
->setPos( Pos_Absolut
, 0 );
855 print_error( rtl::OString( "Set FilePointer to the beginning of the file" ), rc
);
859 //----------------------------------------------------
861 //----------------------------------------------------
863 pReadBuffer
=(sal_Char
*) rtl_allocateMemory( (sal_uInt32
)(nLen
+1)*sizeof(sal_Char
) );
864 rtl_zeroMemory( pReadBuffer
, (sal_uInt32
)(nLen
+1)*sizeof(sal_Char
) );
865 rc
=pFile
->read( pReadBuffer
, nLen
,uRead
);
866 print_error( rtl::OString( "Read File" ), rc
);
868 if (strcmp(pWriteBuffer
, pReadBuffer
)==0)
870 printf( "Verify: OK !\n" );
871 printf( "Text: %s\n",pReadBuffer
);
874 printf( "Verify: Error\n" );
876 rtl_freeMemory( pReadBuffer
);
882 print_error( rtl::OString( "Close File" ), rc
);
885 rc
=pFile
->remove( file_not_exist
);
886 print_error( rtl::OString( "Remove File" ), rc
);
894 //--------------------------------------------------
896 //--------------------------------------------------
898 void FileCopyAndMoveTest( void )
902 printf( "--------------------------------------------\n" );
903 printf( "File-Copy-Move-Test\n" );
904 printf( "--------------------------------------------\n\n" );
908 rtl::OUString
destPath(dir2
);
910 //--------------------------------------------------
912 //--------------------------------------------------
914 destPath
+=rtl::OUString::createFromAscii("/");
917 printf( "Copy the file ");
918 printFileName( file1
);
920 printFileName( destPath
);
924 rc
=File::copy( file1
, destPath
);
925 print_error( rtl::OString( "FileCopy" ), rc
);
927 pFile
=new File( destPath
);
929 rc
=pFile
->open( OpenFlag_Read
);
930 if ( rc
== FileBase::E_None
)
932 printf( "Verify: OK!\n" );
934 File::remove( destPath
);
937 printf( "Verify: Error!\n" );
943 //--------------------------------------------------
944 // Copy a file to a not existing directory
945 //--------------------------------------------------
947 destPath
=rtl::OUString( dir_not_exist
);
948 destPath
+=rtl::OUString::createFromAscii("/");
951 printf( "Copy a file to a not existing directory \n");
952 printf( "Copy the file %s to %s\n", file1
.getStr(), destPath
.getStr() );
954 rc
=File::copy( file1
, destPath
);
955 print_error( rtl::OString( "FileCopy" ), rc
);
959 //--------------------------------------------------
961 //--------------------------------------------------
963 printf( "Copy the directory: ");
964 printFileName( dir1
);
966 printFileName( dir2
);
969 rc
=File::copy( dir1
, dir2
);
970 print_error( rtl::OString( "FileCopy" ), rc
);
974 //--------------------------------------------------
976 //--------------------------------------------------
978 destPath
=rtl::OUString( dir2
);
979 destPath
+=rtl::OUString::createFromAscii("/");
982 printf( "Move the file ");
983 printFileName( file1
);
985 printFileName( destPath
);
988 rc
=File::move( file1
, destPath
);
989 print_error( rtl::OString( "FileMove" ), rc
);
991 pFile
=new File( destPath
);
993 rc
=pFile
->open( OpenFlag_Read
);
994 if ( rc
==FileBase::E_None
)
999 pFile
=new File( file1
);
1001 rc
=pFile
->open( OpenFlag_Read
);
1003 if ( rc
!=FileBase::E_None
)
1005 printf( "Verify: OK!\n" );
1006 File::move( destPath
, file1
);
1010 printf( "Verify: Error!\n" );
1012 File::remove( destPath
);
1016 printf( "Verify: Error!\n" );
1023 //--------------------------------------------------
1024 // Move a file to a not existing directory
1025 //--------------------------------------------------
1027 destPath
=rtl::OUString( dir_not_exist
);
1028 destPath
+=rtl::OUString::createFromAscii("/");
1031 printf( "Move a file to a not existing directory: \n");
1032 printf( "Move the file ");
1033 printFileName( file1
);
1035 printFileName( destPath
);
1038 rc
=File::move( file1
, destPath
);
1039 print_error( rtl::OString( "FileMove" ), rc
);
1043 //--------------------------------------------------
1045 //--------------------------------------------------
1047 printf( "Move a directory: \n");
1049 printf( "Move the directory ");
1050 printFileName( dir1
);
1052 printFileName( dir_not_exist
);
1056 rc
=File::move( dir1
, dir_not_exist
);
1057 print_error( rtl::OString( "FileMove" ), rc
);
1059 if ( rc
== FileBase::E_None
)
1060 File::move( dir_not_exist
, dir1
);
1069 //----------------------------------------------------
1071 //----------------------------------------------------
1073 void FileSizeTest( void )
1076 sal_uInt64 filesize
;
1077 DirectoryItem aItem
;
1079 printf( "--------------------------------------------\n" );
1080 printf( "File-Size-Test\n" );
1081 printf( "--------------------------------------------\n\n" );
1084 File
aFile( file_not_exist
);
1086 printf( "Create File: ");
1087 printFileName( file_not_exist
);
1090 rc
= aFile
.open( OpenFlag_Read
| OpenFlag_Write
| osl_File_OpenFlag_Create
);
1091 print_error( rtl::OString( "Create and Open File (Read & Write)" ), rc
);
1094 if ( rc
== FileBase::E_None
)
1096 //----------------------------------------------------
1097 // Set Filesize to 5000
1098 //----------------------------------------------------
1100 printf( "Set FileSize to 5000\n" );
1101 rc
=aFile
.setSize( 5000 );
1102 print_error( rtl::OString( "Set FileSize" ), rc
);
1105 printf( "Verify:\n" );
1107 //----------------------------------------------------
1108 // Check whether Filesize is set to 5000
1109 //----------------------------------------------------
1111 rc
=DirectoryItem::get( file_not_exist
, aItem
);
1112 print_error( rtl::OString( "Get DirectoryItem" ), rc
);
1114 if ( rc
== FileBase::E_None
)
1116 FileStatus
rStatus( FileStatusMask_FileSize
);
1117 rc
=aItem
.getFileStatus( rStatus
);
1118 print_error( rtl::OString( "Get FileStatus" ), rc
);
1120 if ( rc
== FileBase::E_None
)
1122 filesize
=rStatus
.getFileSize();
1124 if ( filesize
== 5000 )
1125 printf( "\nOK : FileSize: %i\n", filesize
);
1127 printf( "\nError : FileSize: %i\n", filesize
);
1133 //----------------------------------------------------
1134 // Set Filesize to -1
1135 //----------------------------------------------------
1137 printf( "Set FileSize to -1\n" );
1138 rc
=aFile
.setSize( -1 );
1139 print_error( rtl::OString( "Set FileSize" ), rc
);
1145 print_error( rtl::OString( "Close File" ), rc
);
1148 rc
=File::remove( file_not_exist
);
1149 print_error( rtl::OString( "Remove File" ), rc
);
1158 //----------------------------------------------------
1160 //----------------------------------------------------
1162 void FilePointerTest( void )
1165 sal_uInt64 filepointer
;
1167 printf( "--------------------------------------------\n" );
1168 printf( "File-Pointer-Test\n" );
1169 printf( "--------------------------------------------\n\n" );
1172 File
rFile( file_not_exist
);
1174 printf( "Create File: ");
1175 printFileName( file_not_exist
);
1178 rc
= rFile
.open( OpenFlag_Read
| OpenFlag_Write
| osl_File_OpenFlag_Create
);
1179 print_error( rtl::OString( "Create and Open File (Read & Write) "), rc
);
1182 if ( rc
==FileBase::E_None
)
1185 //----------------------------------------------------
1186 // get the position of the filepointer
1187 //----------------------------------------------------
1189 rc
=rFile
.getPos( filepointer
);
1190 print_error( rtl::OString( "GetPos" ), rc
);
1191 printf( "Position of the FilePointer: %i\n", filepointer
);
1195 //----------------------------------------------------
1196 // set the filepointer at the end of a file
1197 //----------------------------------------------------
1199 printf( "Set FileSize to 5000\n" );
1200 rFile
.setSize( 5000 );
1202 printf( "Set the FilePointer at the end of the file (5000)\n" );
1203 rc
=rFile
.setPos( Pos_End
,0 );
1204 print_error( rtl::OString( "SetPos" ), rc
);
1206 rc
=rFile
.getPos( filepointer
);
1208 if ( filepointer
==5000 )
1210 print_error( rtl::OString( "GetPos" ), rc
);
1211 printf( "\nVerify: OK !\n" );
1212 printf( "Filepointer-Position: %llu\n",filepointer
);
1216 print_error( rtl::OString( "GetPos" ), rc
);
1217 printf( "\nFilePointer-Test: Error\n" );
1218 printf( "Filepointer-Position: %i != 5000 \n",filepointer
);
1225 print_error( rtl::OString( "Close File" ), rc
);
1228 rc
=File::remove( file_not_exist
);
1229 print_error( rtl::OString( "Remove File" ), rc
);
1237 //--------------------------------------------------
1238 // FileAttributesTest
1239 //--------------------------------------------------
1241 void verifyFileAttributes( void )
1244 DirectoryItem aItem
;
1245 FileStatus
rStatus( FileStatusMask_Attributes
);
1247 printf( "\nVerify:\n" );
1249 rc
=DirectoryItem::get( file1
, aItem
);
1251 if ( rc
==FileBase::E_None
)
1253 rc
=aItem
.getFileStatus( rStatus
);
1255 if ( rc
==FileBase::E_None
)
1257 sal_uInt64 uAttributes
=rStatus
.getAttributes();
1258 showAttributes(uAttributes
);
1262 print_error( rtl::OString( "Get FileStatus" ), rc
);
1265 print_error( rtl::OString( "Get DirectoryItem" ), rc
);
1271 void FileAttributesTest( void )
1275 printf( "--------------------------------------------\n" );
1276 printf( "File-Attributes-Test\n" );
1277 printf( "--------------------------------------------\n\n" );
1280 printFileName( file1
);
1284 rc
=File::setAttributes( file1
, Attribute_GrpWrite
);
1285 print_error( rtl::OString( "Set Attribute: GrpWrite" ), rc
);
1287 verifyFileAttributes();
1289 rc
=File::setAttributes( file1
, 0 );
1290 if ( rc
!=FileBase::E_None
)
1291 print_error( rtl::OString( "Reset Attributes" ), rc
);
1293 rc
=File::setAttributes( file1
, Attribute_GrpRead
);
1294 print_error( rtl::OString( "Set Attribute: GrpRead" ), rc
);
1296 verifyFileAttributes();
1298 rc
=File::setAttributes( file1
, 0 );
1299 if ( rc
!=FileBase::E_None
)
1300 print_error( rtl::OString( "Reset Attributes" ), rc
);
1302 rc
=File::setAttributes( file1
, Attribute_GrpExe
);
1303 print_error( rtl::OString( "Set Attribute: GrpExe" ), rc
);
1305 verifyFileAttributes();
1307 rc
=File::setAttributes( file1
, 0 );
1308 if ( rc
!=FileBase::E_None
)
1309 print_error( rtl::OString( "Reset Attributes" ), rc
);
1311 rc
=File::setAttributes( file1
, Attribute_OwnWrite
);
1312 print_error( rtl::OString( "Set Attribute: OwnWrite" ), rc
);
1314 verifyFileAttributes();
1316 rc
=File::setAttributes( file1
, 0 );
1317 if ( rc
!=FileBase::E_None
)
1318 print_error( rtl::OString( "Reset Attributes" ), rc
);
1320 rc
=File::setAttributes( file1
, Attribute_OwnRead
);
1321 print_error( rtl::OString( "Set Attribute: OwnRead" ), rc
);
1323 verifyFileAttributes();
1325 rc
=File::setAttributes( file1
, 0 );
1326 if ( rc
!=FileBase::E_None
)
1327 print_error( rtl::OString( "Reset Attributes" ), rc
);
1329 rc
=File::setAttributes( file1
, Attribute_OwnExe
);
1330 print_error( rtl::OString( "Set Attribute: OwnExe" ), rc
);
1332 verifyFileAttributes();
1334 rc
=File::setAttributes( file1
, 0 );
1335 if ( rc
!=FileBase::E_None
)
1336 print_error( rtl::OString( "Reset Attributes" ), rc
);
1338 rc
=File::setAttributes( file1
, Attribute_OthWrite
);
1339 print_error( rtl::OString( "Set Attribute: OthWrite" ), rc
);
1341 verifyFileAttributes();
1343 rc
=File::setAttributes( file1
, 0 );
1344 if ( rc
!=FileBase::E_None
)
1345 print_error( rtl::OString( "Reset Attributes" ), rc
);
1347 rc
=File::setAttributes( file1
, Attribute_OthRead
);
1348 print_error( rtl::OString( "Set Attribute: OthRead" ), rc
);
1350 verifyFileAttributes();
1352 rc
=File::setAttributes( file1
, 0 );
1353 if ( rc
!=FileBase::E_None
)
1354 print_error( rtl::OString( "Reset Attributes" ), rc
);
1356 rc
=File::setAttributes( file1
, Attribute_OthExe
);
1357 print_error( rtl::OString( "Set Attribute: OthExe" ), rc
);
1359 verifyFileAttributes();
1361 rc
=File::setAttributes( file1
, 0 );
1362 if ( rc
!=FileBase::E_None
)
1363 print_error( rtl::OString( "Reset Attributes" ), rc
);
1366 rc
=File::setAttributes( file1
, Attribute_GrpWrite
| Attribute_GrpRead
| Attribute_GrpExe
| Attribute_OwnWrite
| Attribute_OwnRead
| Attribute_OwnExe
| Attribute_OthWrite
| Attribute_OthRead
| Attribute_OthExe
);
1367 print_error( rtl::OString( "Set all Attributes" ), rc
);
1369 verifyFileAttributes();
1378 void FileAttributesTest( void )
1382 printf( "--------------------------------------------\n" );
1383 printf( "File-Attributes-Test\n" );
1384 printf( "--------------------------------------------\n\n" );
1387 printFileName( file1
);
1391 rc
=File::setAttributes( file1
, Attribute_ReadOnly
);
1392 print_error( rtl::OString( "Set Attribute: ReadOnly" ), rc
);
1394 verifyFileAttributes();
1396 rc
=File::setAttributes( file1
, 0 );
1397 print_error( rtl::OString( "Reset Attributes" ), rc
);
1399 verifyFileAttributes();
1401 rc
=File::setAttributes( file1
, Attribute_Hidden
);
1402 print_error( rtl::OString( "Set Attribute: Hidden" ), rc
);
1404 verifyFileAttributes();
1406 rc
=File::setAttributes( file1
, 0 );
1407 print_error( rtl::OString( "Reset Attributes" ), rc
);
1409 verifyFileAttributes();
1411 rc
=File::setAttributes( file1
, Attribute_Hidden
| Attribute_ReadOnly
);
1412 print_error( rtl::OString( "Set Attribute: Hidden & ReadOnly" ), rc
);
1414 verifyFileAttributes();
1416 rc
=File::setAttributes( file1
, 0 );
1417 print_error( rtl::OString( "Reset Attributes") , rc
);
1419 verifyFileAttributes();
1427 //--------------------------------------------------
1429 //--------------------------------------------------
1431 void FileTimeTest( void )
1435 DirectoryItem aItem
;
1437 struct tm sSysCreationTime
= { 0, 20, 12, 4, 9, 100 };
1438 struct tm sSysAccessTime
= { 0, 40, 1, 6, 5, 98 };
1439 struct tm sSysModifyTime
= { 0, 1, 24, 13, 11, 95 };
1441 time_t aSysCreationTime
= mktime( &sSysCreationTime
);
1442 time_t aSysAccessTime
= mktime( &sSysAccessTime
);
1443 time_t aSysModifyTime
= mktime( &sSysModifyTime
);
1445 TimeValue aCreationTime
= { aSysCreationTime
, 0};
1446 TimeValue aAccessTime
= { aSysAccessTime
, 0};
1447 TimeValue aModifyTime
= { aSysModifyTime
, 0};
1449 TimeValue aCreationTimeRead
;
1450 TimeValue aAccessTimeRead
;
1451 TimeValue aModifyTimeRead
;
1454 printf( "--------------------------------------------\n" );
1455 printf( "File-Time-Test\n" );
1456 printf( "--------------------------------------------\n\n" );
1459 printFileName( file1
);
1462 printf( "CreationTime \t : ");
1463 showTime( aCreationTime
);
1465 printf( "\nAccessTime \t : ");
1466 showTime( aAccessTime
);
1468 printf( "\nModifyTime \t : ");
1469 showTime( aModifyTime
);
1471 //--------------------------------------------------
1473 //--------------------------------------------------
1476 rc
=File::setTime( file1
, aCreationTime
, aAccessTime
, aModifyTime
);
1477 print_error( rtl::OString( "SetTime" ), rc
);
1479 //--------------------------------------------------
1481 //--------------------------------------------------
1483 FileStatus
rStatus( FileStatusMask_CreationTime
| FileStatusMask_AccessTime
| FileStatusMask_ModifyTime
);
1485 printf( "\nVerify:\n" );
1487 rc
=DirectoryItem::get( file1
, aItem
);
1488 print_error( rtl::OString( "Get DirectoryItem" ), rc
);
1490 if ( rc
==FileBase::E_None
)
1492 rc
=aItem
.getFileStatus( rStatus
);
1493 print_error( rtl::OString( "Get FileStatus" ), rc
);
1496 if ( rc
==FileBase::E_None
)
1498 //--------------------------------------------------
1500 //--------------------------------------------------
1502 aCreationTimeRead
=rStatus
.getCreationTime();
1504 if ( aCreationTime
.Seconds
== aCreationTimeRead
.Seconds
&& aCreationTime
.Nanosec
== aCreationTimeRead
.Nanosec
)
1505 printf( "GetCreationTime: ok : " );
1507 printf( "GetCreationTime: Error : " );
1509 showTime( aCreationTimeRead
);
1512 //--------------------------------------------------
1514 //--------------------------------------------------
1516 aAccessTimeRead
=rStatus
.getAccessTime();
1518 if ( aAccessTime
.Seconds
== aAccessTimeRead
.Seconds
&& aAccessTime
.Nanosec
== aAccessTimeRead
.Nanosec
)
1519 printf( "GetAccessTime: ok : " );
1521 printf( "GetAccessTime: Error : " );
1523 showTime( aAccessTimeRead
);
1526 //--------------------------------------------------
1528 //--------------------------------------------------
1530 aModifyTimeRead
=rStatus
.getModifyTime();
1532 if ( aModifyTime
.Seconds
== aModifyTimeRead
.Seconds
&& aModifyTime
.Nanosec
== aModifyTimeRead
.Nanosec
)
1533 printf( "GetModifyTime: ok : " );
1535 printf( "GetModifyTime: Error : " );
1537 showTime( aModifyTimeRead
);
1547 //--------------------------------------------------
1548 // DirectoryItemTest
1549 //--------------------------------------------------
1551 void DirectoryItemTest( void )
1555 DirectoryItem aItem
;
1556 FileStatus
*pStatus
;
1559 printf( "--------------------------------------------\n" );
1560 printf( "Directory-Item-Test\n" );
1561 printf( "--------------------------------------------\n\n" );
1563 //--------------------------------------------------
1564 // get DirectoryItem from an existing directory
1565 //--------------------------------------------------
1567 printf( "Get DirectoryItem from an existing Directory: ");
1568 printFileName( dir1
);
1571 rc
=DirectoryItem::get( dir1
, aItem
);
1572 print_error( rtl::OString( "GetDirectoryItem" ), rc
);
1574 pStatus
=new FileStatus( FileStatusMask_All
);
1575 rc
=aItem
.getFileStatus( *pStatus
);
1577 if ( rc
==FileBase::E_None
)
1579 printf( "GetFileStatus: FileURL: ");
1580 printFileName(pStatus
->getFileURL() );
1588 //--------------------------------------------------
1589 // get DirectoryItem from a not existing directory
1590 //--------------------------------------------------
1592 printf( "Get DirectoryItem from a not existing Directory: ");
1593 printFileName( dir_not_exist
);
1596 rc
=DirectoryItem::get( dir_not_exist
, aItem
);
1597 print_error( rtl::OString( "Get DirectoryItem" ), rc
);
1601 //--------------------------------------------------
1602 // get DirectoryItem from an existing file
1603 //--------------------------------------------------
1605 printf( "Get DirectoryItem from an existing File: ");
1606 printFileName( file1
);
1609 rc
=DirectoryItem::get( file1
, aItem
);
1610 print_error( rtl::OString( "GetDirectoryItem" ), rc
);
1612 pStatus
=new FileStatus( FileStatusMask_All
);
1613 rc
=aItem
.getFileStatus( *pStatus
);
1615 if ( rc
==FileBase::E_None
)
1617 printf( "GetFileStatus: FileURL: ");
1618 printFileName( pStatus
->getFileURL() );
1626 //--------------------------------------------------
1627 // get DirectoryItem from a not existing file
1628 //--------------------------------------------------
1630 printf( "Get DirectoryItem from a not existing File: ");
1631 printFileName( file_not_exist
);
1634 rc
=DirectoryItem::get( file_not_exist
, aItem
);
1635 print_error( rtl::OString( "Get DirectoryItem" ), rc
);
1639 //----------------------------------------------------------
1640 // get DirectoryItem from a directory with a wrong semantic
1641 //----------------------------------------------------------
1643 printf( "Get DirectoryItem from a Directory with a wrong semantic: ");
1644 printFileName( dir_not_exist
);
1647 rc
=DirectoryItem::get( dir_wrong_semantic
, aItem
);
1648 print_error( rtl::OString( "Get DirectoryItem" ),rc
);
1652 //---------------------------------------------------
1653 // get DirectoryItem from a file-handle
1654 //--------------------------------------------------
1656 pFile
=new File( file1
);
1658 rc
=pFile
->open( OpenFlag_Read
);
1659 if ( rc
==FileBase::E_None
)
1661 printf( "Get DirectoryItem from a File-Handle: ");
1662 printFileName( file1
);
1665 rc
=DirectoryItem::get( *pFile
, aItem
);
1666 print_error( rtl::OString( "GetDirectoryItem" ), rc
);
1668 pStatus
=new FileStatus( FileStatusMask_All
);
1669 rc
=aItem
.getFileStatus( *pStatus
);
1671 if ( rc
==FileBase::E_None
)
1673 printf( "GetFileStatus: FileURL: ");
1674 printFileName( pStatus
->getFileURL() );
1687 //---------------------------------------------------
1688 // get DirectoryItem from an empty file-handle
1689 //--------------------------------------------------
1691 pFile
=new File( file1
);
1693 printf( "Get DirectoryItem from an empty File-Handle\n" );
1694 rc
=DirectoryItem::get( *pFile
, aItem
);
1695 print_error( rtl::OString( "GetDirectoryItem" ), rc
);
1701 //--------------------------------------------------
1702 // GetNextItem from a directory
1703 //--------------------------------------------------
1705 pDir
=new Directory( dir1
);
1706 printf( "Get next DirectoryItem from a directory: ");
1707 printFileName( dir1
);
1711 print_error( rtl::OString( "Open Directory" ), rc
);
1715 if ( pDir
->isOpen() )
1717 //--------------------------------------------------
1718 // get all files from the directory
1719 //--------------------------------------------------
1722 rtl::OUString str1
[2];
1724 aItem
=DirectoryItem();
1725 rc
=pDir
->getNextItem( aItem
);
1726 print_error( rtl::OString( "GetNextItem" ),rc
);
1728 while( rc
==FileBase::E_None
)
1731 FileStatus
rStatus( FileStatusMask_All
);
1732 aItem
.getFileStatus( rStatus
);
1734 str
=rStatus
.getFileName();
1735 printf( "Filename: ");
1736 printFileName( str
);
1739 aItem
=DirectoryItem();
1740 rc
=pDir
->getNextItem( aItem
);
1741 print_error( rtl::OString( "GetNextItem" ),rc
);
1746 //--------------------------------------------------
1748 //--------------------------------------------------
1750 for (int i
=0; i
<2; i
++)
1752 aItem
=DirectoryItem();
1754 rc
=pDir
->getNextItem( aItem
);
1756 FileStatus
rStatus( FileStatusMask_All
);
1757 aItem
.getFileStatus( rStatus
);
1759 str1
[i
]=rStatus
.getFileName();
1763 if ( str1
[0].compareTo(str1
[1]) == 0 )
1764 print_error( rtl::OString( "Reset" ),FileBase::E_None
);
1766 print_error( rtl::OString( "Reset" ),FileBase::E_invalidError
);
1772 print_error( rtl::OString( "Close Directory" ), rc
);
1777 //--------------------------------------------------
1778 // GetNextItem from a closed directory
1779 //--------------------------------------------------
1781 printf( "Get next DirectoryItem from a closed directory: ");
1782 printFileName( dir1
);
1785 aItem
=DirectoryItem();
1786 rc
=pDir
->getNextItem( aItem
);
1787 print_error( rtl::OString( "GetNextItem" ),rc
);
1795 //--------------------------------------------------
1796 // FileStatusTest (for different types)
1797 //--------------------------------------------------
1799 void FileStatusTest( FileStatus
*pStatus
)
1801 //--------------------------------------------------
1802 // GetFileType of the directory
1803 //--------------------------------------------------
1805 FileStatus::Type aType
;
1807 printf( "\ngetFileType:\n" );
1808 aType
=pStatus
->getFileType();
1809 showFileType( aType
);
1811 //--------------------------------------------------
1813 //--------------------------------------------------
1815 sal_uInt64 uAttributes
;
1817 printf( "\ngetAttributes:\n" );
1818 uAttributes
=pStatus
->getAttributes();
1819 showAttributes( uAttributes
);
1821 //--------------------------------------------------
1823 //--------------------------------------------------
1825 TimeValue aCreationTime
;
1827 printf( "\ngetCreationTime:\n" );
1828 aCreationTime
=pStatus
->getCreationTime();
1830 printf( "CreationTime: " );
1831 showTime( aCreationTime
);
1833 //--------------------------------------------------
1835 //--------------------------------------------------
1837 TimeValue aAccessTime
;
1839 printf( "\ngetAccessTime:\n" );
1840 aAccessTime
=pStatus
->getAccessTime();
1842 printf( "AccessTime: " );
1843 showTime( aAccessTime
);
1845 //--------------------------------------------------
1847 //--------------------------------------------------
1849 TimeValue aModifyTime
;
1851 printf( "\ngetModifyTime:\n" );
1852 aModifyTime
=pStatus
->getModifyTime();
1854 printf( "ModifyTime: " );
1855 showTime( aModifyTime
);
1857 //--------------------------------------------------
1859 //--------------------------------------------------
1861 sal_uInt64 FileSize
;
1863 printf( "\ngetFileSize:\n" );
1865 FileSize
=pStatus
->getFileSize();
1866 printf( "FileSize: %i\n", FileSize
);
1868 //--------------------------------------------------
1870 //--------------------------------------------------
1872 rtl::OUString FileName
;
1874 printf( "\ngetFileName:\n" );
1876 FileName
=pStatus
->getFileName();
1877 printf( "FileName: ");
1878 printFileName( FileName
);
1881 //--------------------------------------------------
1883 //--------------------------------------------------
1885 rtl::OUString FileURL
;
1887 printf( "\ngetFileURL:\n" );
1889 FileURL
=pStatus
->getFileURL();
1890 printf( "FileURL: ");
1891 printFileName( FileURL
);
1894 //--------------------------------------------------
1896 //--------------------------------------------------
1898 rtl::OUString LinkTargetURL
;
1900 printf( "\ngetLinkTargetURL:\n");
1902 LinkTargetURL
=pStatus
->getLinkTargetURL();
1903 printf( "LinkTargetURL: ");
1904 printFileName( LinkTargetURL
);
1910 //--------------------------------------------------
1911 // DirectoryFileStatusTest
1912 //--------------------------------------------------
1914 void DirectoryFileStatusTest( void )
1917 DirectoryItem aItem
;
1918 FileStatus
*pStatus
;
1920 printf( "--------------------------------------------\n" );
1921 printf( "Directory-FileStatus-Test\n" );
1922 printf( "--------------------------------------------\n\n" );
1924 printf( "FileStatus of the directory: ");
1925 printFileName( dir1
);
1928 aItem
=DirectoryItem();
1930 rc
=DirectoryItem::get( dir1
, aItem
);
1931 print_error( rtl::OString( "Get DirectoryItem" ), rc
);
1933 if ( rc
==FileBase::E_None
)
1935 pStatus
=new FileStatus( FileStatusMask_All
);
1936 rc
=aItem
.getFileStatus( *pStatus
);
1938 FileStatusTest( pStatus
);
1949 //--------------------------------------------------
1950 // FileFileStatusTest
1951 //--------------------------------------------------
1953 void FileFileStatusTest( void )
1956 DirectoryItem aItem
;
1957 FileStatus
*pStatus
;
1959 printf( "--------------------------------------------\n" );
1960 printf( "File-FileStatus-Test\n" );
1961 printf( "--------------------------------------------\n\n" );
1963 printf( "FileStatus of the file: ");
1964 printFileName( file1
);
1967 aItem
=DirectoryItem();
1969 rc
=DirectoryItem::get( file1
, aItem
);
1970 print_error( rtl::OString( "Get DirectoryItem" ), rc
);
1972 if ( rc
==FileBase::E_None
)
1974 pStatus
=new FileStatus( FileStatusMask_All
);
1975 rc
=aItem
.getFileStatus( *pStatus
);
1977 FileStatusTest( pStatus
);
1988 //--------------------------------------------------
1989 // VolumeFileStatusTest
1990 //--------------------------------------------------
1992 void VolumeFileStatusTest( void )
1995 DirectoryItem aItem
;
1996 FileStatus
*pStatus
;
1998 printf( "--------------------------------------------\n" );
1999 printf( "Volume-FileStatus-Test\n" );
2000 printf( "--------------------------------------------\n\n" );
2002 printf( "FileStatus of the Volume: ");
2003 printFileName( root
);
2006 aItem
=DirectoryItem();
2008 rc
=DirectoryItem::get( root
, aItem
);
2009 print_error( rtl::OString( "Get DirectoryItem" ), rc
);
2011 if ( rc
==FileBase::E_None
)
2013 pStatus
=new FileStatus( FileStatusMask_All
) ;
2014 rc
=aItem
.getFileStatus( *pStatus
);
2016 FileStatusTest( pStatus
);
2028 //--------------------------------------------------
2030 //--------------------------------------------------
2032 void VolumeInfoTest( void )
2036 printf( "--------------------------------------------\n" );
2037 printf( "Volume-Info-Test\n" );
2038 printf( "--------------------------------------------\n\n" );
2040 printf( "VolumeInfo of the volume ");
2041 printFileName( root
);
2045 VolumeInfo
rInfo( VolumeInfoMask_FreeSpace
);
2046 rc
=Directory::getVolumeInfo( root
, rInfo
);
2047 print_error( rtl::OString( "GetVolumeInfo" ),rc
);
2051 //--------------------------------------------------
2053 //--------------------------------------------------
2055 if ( rInfo
.getRemoteFlag() )
2056 printf( "RemoteFlag: Yes\n" );
2058 printf( "RemoteFlag: No\n" );
2060 //--------------------------------------------------
2061 // getRemoveableFlag
2062 //--------------------------------------------------
2064 if ( rInfo
.getRemoveableFlag() )
2065 printf( "RemoveableFlag: Yes\n" );
2067 printf( "RemoveableFlag: No\n" );
2069 //--------------------------------------------------
2071 //--------------------------------------------------
2073 sal_uInt64 TotalSpace
;
2074 TotalSpace
=rInfo
.getTotalSpace();
2075 printf( "Total Space: %i\n",TotalSpace
);
2077 //--------------------------------------------------
2079 //--------------------------------------------------
2081 sal_uInt64 FreeSpace
;
2082 FreeSpace
=rInfo
.getFreeSpace();
2083 printf( "Free Space: %i\n",FreeSpace
);
2085 //--------------------------------------------------
2087 //--------------------------------------------------
2089 sal_uInt64 UsedSpace
;
2090 UsedSpace
=rInfo
.getUsedSpace();
2091 printf( "Used Space: %i\n",UsedSpace
);
2093 //--------------------------------------------------
2095 //--------------------------------------------------
2097 sal_uInt32 MaxNameLength
;
2098 MaxNameLength
=rInfo
.getMaxNameLength();
2099 printf( "MaxNameLength: %i\n",MaxNameLength
);
2101 //--------------------------------------------------
2103 //--------------------------------------------------
2105 sal_uInt32 MaxPathLength
;
2106 MaxPathLength
=rInfo
.getMaxPathLength();
2107 printf( "MaxPathLength: %i\n",MaxPathLength
);
2109 //--------------------------------------------------
2110 // getFileSystemName
2111 //--------------------------------------------------
2113 rtl::OUString FileSystemName
;
2114 FileSystemName
=rInfo
.getFileSystemName();
2115 printf( "File-System-Name: ");
2116 printFileName( FileSystemName
);
2123 //--------------------------------------------------
2125 //--------------------------------------------------
2127 void ConvertPathTest(rtl::OUString
& strPath
)
2131 rtl::OUString strNormPath
;
2132 rtl::OUString strFileURL
;
2133 rtl::OUString strNormPathFromFileURL
;
2134 rtl::OUString strSystemPath
;
2136 //--------------------------------------------------
2138 //--------------------------------------------------
2140 rc
=FileBase::getFileURLFromSystemPath( strPath
, strNormPath
);
2142 if ( rc
== FileBase::E_None
)
2144 printf( "Normalized Path: \t\t");
2145 printFileName( strNormPath
);
2149 printf( "normalizePath: Error \n" );
2151 //--------------------------------------------------
2152 // getFileURLFromSystemPath
2153 //--------------------------------------------------
2155 if ( strNormPath
.getLength() != 0 )
2157 rc
=FileBase::getFileURLFromSystemPath( strNormPath
, strFileURL
);
2159 if ( rc
== FileBase::E_None
)
2161 printf( "File-URL: \t\t\t");
2162 printFileName( strFileURL
);
2166 printf( "getFileURLFromSystemPath: Error \n" );
2169 printf( "getFileURLFromSystemPath: not tested \n" );
2171 //--------------------------------------------------
2172 // getNormalizedPathFromFileURL
2173 //--------------------------------------------------
2175 if ( strFileURL
.getLength() != 0 )
2177 rc
=FileBase::getSystemPathFromFileURL( strFileURL
, strNormPathFromFileURL
);
2179 if ( rc
== FileBase::E_None
)
2181 printf( "Normalized Path from File-URL: \t");
2182 printFileName( strNormPathFromFileURL
);
2186 printf( "getNormalizedPathFromFileURL: Error \n" );
2189 printf( "getNormalizedPathFromFileURL: not tested \n" );
2192 //--------------------------------------------------
2193 // getSystemPathFromFileURL
2194 //--------------------------------------------------
2196 if ( strNormPath
.getLength() != 0 )
2198 rc
=FileBase::getSystemPathFromFileURL( strNormPath
, strSystemPath
);
2200 if ( rc
== FileBase::E_None
)
2202 printf( "System-Path: \t\t\t");
2203 printFileName( strSystemPath
);
2207 printf( "getSystemPathFromFileURL: Error \n" );
2210 printf( "getSystemPathFromFileURL: not tested \n" );
2212 //--------------------------------------------------
2214 //--------------------------------------------------
2216 if ( strNormPathFromFileURL
== strNormPath
)
2217 printf( "\nVerify: OK ! ( Normalized-Path == Normalized-Path-From-File-URL )\n" );
2219 printf( "\nVerify: Error ! ( Normalized-Path != Normalized-Path-From-File-URL )\n" );
2226 printf( "--------------------------------------------\n" );
2227 printf( "FileBase-Test\n" );
2228 printf( "--------------------------------------------\n\n" );
2230 //--------------------------------------------------
2231 // ConvertPath-Test (Local File)
2232 //--------------------------------------------------
2234 printf( "- Local File: ");
2235 printFileName( file1
);
2238 ConvertPathTest(file1
);
2240 //--------------------------------------------------
2241 // ConvertPath-Test (File on a server)
2242 //--------------------------------------------------
2244 printf( "\n- File on server: ");
2245 printFileName( file_on_server
);
2247 ConvertPathTest(file_on_server
);
2255 //--------------------------------------------------
2257 //--------------------------------------------------
2258 void DoAbsolutePathTest(rtl::OUString strDirBase
, rtl::OUString strRelative
)
2262 rtl::OUString strAbsolute
;
2264 printf( "Base-Directory: \t");
2265 printFileName( strDirBase
);
2267 printf( "Relative-Path: \t\t");
2268 printFileName ( strRelative
);
2271 rc
=FileBase::getAbsoluteFileURL( strDirBase
, strRelative
, strAbsolute
);
2273 if ( rc
== FileBase::E_None
)
2275 printf( "Absolute-Path: \t\t");
2276 printFileName ( strAbsolute
);
2280 printf( "Absolute-Path: Error \n" );
2286 void AbsolutePathTest(void)
2288 printf( "--------------------------------------------\n" );
2289 printf( "AbsolutePath-Test\n" );
2290 printf( "--------------------------------------------\n\n" );
2292 DoAbsolutePathTest(dir1
, rtl::OUString::createFromAscii("."));
2293 DoAbsolutePathTest(dir1
, rtl::OUString::createFromAscii(".."));
2294 DoAbsolutePathTest(dir1
, rtl::OUString::createFromAscii("../.."));
2295 DoAbsolutePathTest(dir1
, rtl::OUString::createFromAscii("../HUHU"));
2297 DoAbsolutePathTest(dir_on_server
, rtl::OUString::createFromAscii("."));
2298 DoAbsolutePathTest(dir_on_server
, rtl::OUString::createFromAscii(".."));
2299 DoAbsolutePathTest(dir_on_server
, rtl::OUString::createFromAscii("../.."));
2300 DoAbsolutePathTest(dir_on_server
, rtl::OUString::createFromAscii("../HUHU"));
2307 //--------------------------------------------------
2309 //--------------------------------------------------
2311 void SearchPathTest(void)
2315 rtl::OUString
strNormPath(file1
);
2316 rtl::OUString strFileURL
;
2317 rtl::OUString strSystemPath
;
2318 rtl::OUString strResultPath
;
2320 printf( "--------------------------------------------\n" );
2321 printf( "SearchPath-Test\n" );
2322 printf( "--------------------------------------------\n\n" );
2325 rc
=FileBase::getFileURLFromSystemPath( strNormPath
, strFileURL
);
2326 print_error( rtl::OString( "getFileURLFromSystemPath" ), rc
);
2327 rc
=FileBase::getSystemPathFromFileURL( strNormPath
, strSystemPath
);
2328 print_error( rtl::OString( "getSystemPathFromFileURL" ), rc
);
2330 //--------------------------------------------------
2331 // searchFileURL (with a normalized path)
2332 //--------------------------------------------------
2334 if ( strNormPath
.getLength() != 0 )
2336 printf( "\nSearch-Normalized-Path (with a normalized path) : ");
2337 printFileName ( strNormPath
);
2340 rc
=FileBase::searchFileURL( strNormPath
, rtl::OUString() , strResultPath
);
2342 if ( rc
== FileBase::E_None
)
2344 printf( "Result: \t\t\t");
2345 printFileName ( strResultPath
);
2349 printf( "searchFileURL (with a normalized path): Error\n" );
2352 printf( "searchFileURL (with a normalized path): not tested\n" );
2354 //--------------------------------------------------
2355 // searchFileURL (with a File-URL)
2356 //--------------------------------------------------
2358 if ( strFileURL
.getLength() != 0 )
2360 printf( "\nSearch-Normalized-Path (with a FileURL) : ");
2361 printFileName( strFileURL
);
2364 rc
=FileBase::searchFileURL( strFileURL
, rtl::OUString() , strResultPath
);
2366 if ( rc
== FileBase::E_None
)
2368 printf( "Result: \t\t\t");
2369 printFileName ( strResultPath
);
2373 printf( "searchFileURL (with a FileURL path): Error\n" );
2376 printf( "searchFileURL (with a FileURL path): not tested\n" );
2378 //--------------------------------------------------
2379 // searchFileURL (with a systempath)
2380 //--------------------------------------------------
2382 if ( strSystemPath
.getLength() != 0 )
2384 printf( "\nSearch-Normalized-Path (with a SystemPath) : ");
2385 printFileName( strSystemPath
);
2388 rc
=FileBase::searchFileURL( strSystemPath
, rtl::OUString() , strResultPath
);
2390 if ( rc
== FileBase::E_None
)
2392 printf( "Result: \t\t\t");
2393 printFileName( strResultPath
);
2397 printf( "searchFileURL (with a systempath): Error\n" );
2400 printf( "searchFileURL (with a systempath): not tested\n" );
2402 //--------------------------------------------------
2403 // searchFileURL (File and no searchpath)
2404 //--------------------------------------------------
2406 printf( "\nsearchFileURL: File (no searchpath) : ");
2407 printFileName( file3
);
2410 rc
=FileBase::searchFileURL( file3
, rtl::OUString::createFromAscii("") , strResultPath
);
2412 if ( rc
== FileBase::E_None
)
2414 printf( "Result: \t\t\t");
2415 printFileName( strResultPath
);
2419 printf( "searchFileURL: File not found: OK ! \n" );
2421 //--------------------------------------------------
2422 // searchFileURL (File and Path)
2423 //--------------------------------------------------
2425 printf( "\nsearchFileURL: File : ");
2426 printFileName( file3
);
2427 printf( "\tSearchPath ");
2428 printFileName( dir1
);
2431 rc
=FileBase::searchFileURL( file3
, dir1
, strResultPath
);
2433 if ( rc
== FileBase::E_None
)
2435 printf( "Result: \t\t\t");
2436 printFileName( strResultPath
);
2440 printf( "searchFileURL: File not found: Error\n" );
2442 //------------------------------------------------------------
2443 // searchFileURL (File and searchpath with two entries)
2444 //------------------------------------------------------------
2446 rtl::OUString
strSearchPath( dir_not_exist
);
2447 strSearchPath
+=rtl::OUString::createFromAscii(";");
2448 strSearchPath
+=dir_on_server
;
2450 printf( "\nsearchFileURL: File : ");
2451 printFileName( file3
);
2452 printf( "SearchPath ");
2453 printFileName( strSearchPath
);
2456 rc
=FileBase::searchFileURL( file3
, strSearchPath
, strResultPath
);
2458 if ( rc
== FileBase::E_None
)
2460 printf( "Result: \t\t\t");
2461 printFileName( strResultPath
);
2465 printf( "searchFileURL: File not found: Error\n" );
2467 //-------------------------------------------------------------------
2468 // searchFileURL (File and searchpath (with a wrong semantic))
2469 //-------------------------------------------------------------------
2471 strSearchPath
=rtl::OUString( dir_wrong_semantic
);
2473 printf( "\nsearchFileURL: File : ");
2474 printFileName( file3
);
2475 printf( "SearchPath ");
2476 printFileName( strSearchPath
);
2479 rc
=FileBase::searchFileURL( file3
, strSearchPath
, strResultPath
);
2481 if ( rc
== FileBase::E_None
)
2482 printf( "Error: Wrong Semantich but no error occurs !\n" );
2484 printf( "searchFileURL: File not found: OK !\n" );
2489 //--------------------------------------------------
2490 // CanonicalNameTest
2491 //--------------------------------------------------
2493 void getCanonicalNameTest(rtl::OUString strPath
)
2497 rtl::OUString strValid
;
2499 printf( "Original-Name: \t\t");
2500 printFileName( strPath
);
2503 rc
=FileBase::getCanonicalName( strPath
, strValid
);
2505 if ( rc
== FileBase::E_None
)
2507 printf( "Canonical-Name: \t");
2508 printFileName( strValid
);
2513 printf( "Canonical-Name: Error \n" );
2519 void CanonicalNameTest(void)
2521 printf( "--------------------------------------------\n" );
2522 printf( "CanonicalName-Test\n" );
2523 printf( "--------------------------------------------\n\n" );
2525 getCanonicalNameTest( dir1
);
2526 getCanonicalNameTest( dir_on_server
);
2527 getCanonicalNameTest( file1
);
2528 getCanonicalNameTest( file_on_server
);
2534 //--------------------------------------------------
2536 //--------------------------------------------------
2538 void print_error( ::rtl::OString
& str
, FileBase::RC rc
)
2541 printf( "%s : ",str
.getStr() );
2544 case FileBase::E_None
:
2547 case FileBase::E_PERM
:
2550 case FileBase::E_NOENT
:
2551 printf("E_NOENT\n");
2553 case FileBase::E_SRCH
:
2556 case FileBase::E_INTR
:
2559 case FileBase::E_IO
:
2562 case FileBase::E_NXIO
:
2565 case FileBase::E_2BIG
:
2568 case FileBase::E_NOEXEC
:
2569 printf("E_NOEXEC\n");
2571 case FileBase::E_BADF
:
2574 case FileBase::E_CHILD
:
2575 printf("E_CHILD\n");
2577 case FileBase::E_AGAIN
:
2578 printf("E_AGAIN\n");
2580 case FileBase::E_NOMEM
:
2581 printf("E_NOMEM\n");
2583 case FileBase::E_ACCES
:
2584 printf("E_ACCES\n");
2586 case FileBase::E_FAULT
:
2587 printf("E_FAULT\n");
2589 case FileBase::E_BUSY
:
2592 case FileBase::E_EXIST
:
2593 printf("E_EXIST\n");
2595 case FileBase::E_XDEV
:
2598 case FileBase::E_NODEV
:
2599 printf("E_NODEV\n");
2601 case FileBase::E_NOTDIR
:
2602 printf("E_NOTDIR\n");
2604 case FileBase::E_ISDIR
:
2605 printf("E_ISDIR\n");
2607 case FileBase::E_INVAL
:
2608 printf("E_INVAL\n");
2610 case FileBase::E_NFILE
:
2611 printf("E_NFILE\n");
2613 case FileBase::E_MFILE
:
2614 printf("E_MFILE\n");
2616 case FileBase::E_NOTTY
:
2617 printf("E_NOTTY\n");
2619 case FileBase::E_FBIG
:
2622 case FileBase::E_NOSPC
:
2623 printf("E_NOSPC\n");
2625 case FileBase::E_SPIPE
:
2626 printf("E_SPIPE\n");
2628 case FileBase::E_ROFS
:
2631 case FileBase::E_MLINK
:
2632 printf("E_MLINK\n");
2634 case FileBase::E_PIPE
:
2637 case FileBase::E_DOM
:
2640 case FileBase::E_RANGE
:
2641 printf("E_RANGE\n");
2643 case FileBase::E_DEADLK
:
2644 printf("E_DEADLK\n");
2646 case FileBase::E_NAMETOOLONG
:
2647 printf("E_NAMETOOLONG\n");
2649 case FileBase::E_NOLCK
:
2650 printf("E_NOLCK\n");
2652 case FileBase::E_NOSYS
:
2653 printf("E_NOSYS\n");
2655 case FileBase::E_NOTEMPTY
:
2656 printf("E_NOTEMPTY\n");
2658 case FileBase::E_LOOP
:
2661 case FileBase::E_ILSEQ
:
2662 printf("E_ILSEQ\n");
2664 case FileBase::E_NOLINK
:
2665 printf("E_NOLINK\n");
2667 case FileBase::E_MULTIHOP
:
2668 printf("E_MULTIHOP\n");
2670 case FileBase::E_USERS
:
2671 printf("E_USERS\n");
2673 case FileBase::E_OVERFLOW
:
2674 printf("E_OVERFLOW\n");
2677 printf("E_Unknown\n");
2683 //--------------------------------------------------
2685 //--------------------------------------------------
2687 #define MAIN _cdecl main
2692 int MAIN( int argc
, char* argv
[] )
2694 sal_Bool fSuccess
=sal_False
;
2697 fSuccess
=Initialize();
2700 printf("Error during Initialization");
2707 DirectoryOpenAndCloseTest();
2708 DirectoryCreateAndRemoveTest();
2710 FileOpenAndCloseTest();
2711 FileCreateAndRemoveTest();
2712 FileWriteAndReadTest();
2713 FileCopyAndMoveTest();
2716 FileAttributesTest();
2718 DirectoryItemTest();
2719 DirectoryFileStatusTest();
2720 VolumeFileStatusTest();
2721 FileFileStatusTest();
2726 CanonicalNameTest();
2728 // command line arguments ?
2735 if (strcmp(argv
[i
], "doc")==0)
2736 DirectoryOpenAndCloseTest();
2737 else if (strcmp(argv
[i
], "dcr")==0)
2738 DirectoryCreateAndRemoveTest();
2739 else if (strcmp(argv
[i
], "foc")==0)
2740 FileOpenAndCloseTest();
2741 else if (strcmp(argv
[i
], "fcr")==0)
2742 FileCreateAndRemoveTest();
2743 else if (strcmp(argv
[i
], "fwr")==0)
2744 FileWriteAndReadTest();
2745 else if (strcmp(argv
[i
], "fcm")==0)
2746 FileCopyAndMoveTest();
2747 else if (strcmp(argv
[i
], "fs")==0)
2749 else if (strcmp(argv
[i
], "fp")==0)
2751 else if (strcmp(argv
[i
], "fa")==0)
2752 FileAttributesTest();
2753 else if (strcmp(argv
[i
], "ft")==0)
2755 else if (strcmp(argv
[i
], "di")==0)
2756 DirectoryItemTest();
2757 else if (strcmp(argv
[i
], "dfs")==0)
2758 DirectoryFileStatusTest();
2759 else if (strcmp(argv
[i
], "vfs")==0)
2760 VolumeFileStatusTest();
2761 else if (strcmp(argv
[i
], "ffs")==0)
2762 FileFileStatusTest();
2763 else if (strcmp(argv
[i
], "vi")==0)
2765 else if (strcmp(argv
[i
], "fb")==0)
2767 else if (strcmp(argv
[i
], "sp")==0)
2769 else if (strcmp(argv
[i
], "ap")==0)
2771 else if (strcmp(argv
[i
], "cn")==0)
2772 CanonicalNameTest();
2779 fSuccess
=Shutdown();
2782 printf("Error during Shutdown");