1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
33 #include <osl/file.hxx>
34 #include <osl/process.h>
36 #include <rtl/alloc.h>
37 #include <rtl/ustring.hxx>
60 rtl::OUString dir_on_server
;
61 rtl::OUString dir_not_exist
;
62 rtl::OUString dir_not_exist_on_server
;
63 rtl::OUString dir_wrong_semantic
;
68 rtl::OUString file_on_server
;
69 rtl::OUString file_not_exist
;
73 void print_error(const ::rtl::OString
& str
, FileBase::RC rc
);
77 printf("\nPress Return !\n");
81 void printFileName(const ::rtl::OUString
& str
)
85 aString
= rtl::OUStringToOString( str
, RTL_TEXTENCODING_ASCII_US
);
87 printf( "%s", aString
.getStr() );
92 //--------------------------------------------------
94 //--------------------------------------------------
96 sal_Bool
testLineBreak( sal_Char
*pCount
, sal_uInt64 nLen
, sal_uInt32
*cLineBreak
)
98 sal_Bool fSuccess
=sal_False
;
106 if (nLen
>=1 && *(pCount
+1)==10)
111 if (nLen
>=2 && *(pCount
+2)==10)
116 else if ( *pCount
==10 )
127 sal_Bool
Initialize( void )
130 FileStatus
aStatus( osl_FileStatus_Mask_All
);
131 rtl_uString
*strExeFileURL
=NULL
;
132 oslProcessError ProcessError
;
134 rtl::OUString iniFileURL
;
136 sal_Unicode
*pExeFileCount
;
140 sal_uInt64 uBytesRequested
;
141 sal_uInt64 uBytesRead
;
146 rtl::OUString dir
[12];
148 // Open to the ini-file
150 ProcessError
=osl_getExecutableFile(&strExeFileURL
);
152 if ( ProcessError
== osl_Process_E_None
)
154 pExeFileCount
=rtl_uString_getStr(strExeFileURL
)+rtl_uString_getLength(strExeFileURL
);
156 // Search for the last slash in the Path
157 while (*pExeFileCount
!=L
'/' && pExeFileCount
>rtl_uString_getStr(strExeFileURL
))
160 // iniFileURL = strExeFileURL without the filename of the exe-File
161 iniFileURL
=rtl::OUString( rtl_uString_getStr(strExeFileURL
) ,(int) (pExeFileCount
-rtl_uString_getStr(strExeFileURL
)) );
163 // add "/testfile.ini" to iniFileURL
164 iniFileURL
+=rtl::OUString("/testfile.ini");
167 pFile
=new File( iniFileURL
);
168 rc
=pFile
->open( osl_File_OpenFlag_Read
| osl_File_OpenFlag_Write
);
169 if ( rc
!=FileBase::E_None
)
171 rtl_uString_release(strExeFileURL
);
177 rtl_uString_release(strExeFileURL
);
181 // Get filesize of the ini-File
183 rc
=DirectoryItem::get( iniFileURL
, aItem
);
184 if ( rc
!=FileBase::E_None
)
187 rc
=aItem
.getFileStatus( aStatus
);
188 if ( rc
!=FileBase::E_None
)
191 uBytesRequested
=aStatus
.getFileSize();
194 rc
=pFile
->setPos( osl_Pos_Absolut
, 0 );
195 pBuffer
=(sal_Char
*) rtl_allocateMemory( (sal_uInt32
) (uBytesRequested
+1)*sizeof(sal_Char
) );
196 rtl_zeroMemory( pBuffer
, (sal_uInt32
)(uBytesRequested
+1)*sizeof(sal_Char
) );
198 rc
=pFile
->read( pBuffer
, uBytesRequested
, uBytesRead
);
199 if ( rc
!=FileBase::E_None
)
206 for ( int i
=0 ; i
<12 ; i
++ )
208 sal_uInt32 cLineBrake
=0;
209 while ( (static_cast<sal_uInt64
>(pCount
-pBuffer
) < uBytesRead
) && *pCount
!='=')
215 while ( (static_cast<sal_uInt64
>(pCount
-pBuffer
) < uBytesRead
) && !testLineBreak(pCount
,uBytesRead
-(pCount
-pBuffer
), &cLineBrake
))
218 dir
[i
]=rtl::OUString(pBegin
, pCount
-pBegin
, RTL_TEXTENCODING_ASCII_US
);
224 root
=rtl::OUString(dir
[0]);
225 dir1
=rtl::OUString(dir
[1]);
226 dir2
=rtl::OUString(dir
[2]);
227 dir_on_server
=rtl::OUString(dir
[3]);
228 dir_not_exist
=rtl::OUString(dir
[4]);
229 dir_not_exist_on_server
=rtl::OUString(dir
[5]);
230 dir_wrong_semantic
=rtl::OUString(dir
[6]);
232 file1
=rtl::OUString(dir
[7]);
233 file2
=rtl::OUString(dir
[8]);
234 file3
=rtl::OUString(dir
[9]);
235 file_on_server
=rtl::OUString(dir
[10]);
236 file_not_exist
=rtl::OUString(dir
[11]);
238 // close the ini-file
241 rtl_freeMemory( pBuffer
);
244 // Create directories
245 rc
=Directory::create( dir1
);
246 if ( rc
!=FileBase::E_None
)
249 rc
=Directory::create( dir2
);
250 if ( rc
!=FileBase::E_None
)
253 rc
=Directory::create( dir_on_server
);
254 if ( rc
!=FileBase::E_None
)
257 pFile
=new File( file1
);
258 rc
=pFile
->open( osl_File_OpenFlag_Write
| osl_File_OpenFlag_Create
);
259 if ( rc
!=FileBase::E_None
)
264 pFile
=new File( file2
);
265 rc
=pFile
->open( osl_File_OpenFlag_Write
| osl_File_OpenFlag_Create
);
266 if ( rc
!=FileBase::E_None
)
271 pFile
=new File( file_on_server
);
272 rc
=pFile
->open( osl_File_OpenFlag_Write
| osl_File_OpenFlag_Create
);
273 if ( rc
!=FileBase::E_None
)
281 //--------------------------------------------------
283 //--------------------------------------------------
285 sal_Bool
Shutdown( void )
287 sal_Bool fSuccess
=sal_True
;
291 // remove created files
293 pFile
=new File( file1
);
294 rc
=pFile
->remove( file1
);
295 if ( rc
!=FileBase::E_None
)
299 pFile
=new File( file2
);
300 rc
=pFile
->remove( file2
);
301 if ( rc
!=FileBase::E_None
)
305 // remove created directories
307 rc
=Directory::remove( dir1
);
308 if ( rc
!=FileBase::E_None
)
311 rc
=Directory::remove( dir2
);
312 if ( rc
!=FileBase::E_None
)
315 // remove created file on the server
317 pFile
=new File( file_on_server
);
318 rc
=pFile
->remove( file_on_server
);
319 if ( rc
!=FileBase::E_None
)
323 // remove created directory on the server
325 rc
=Directory::remove( dir_on_server
);
326 if ( rc
!=FileBase::E_None
)
332 //--------------------------------------------------
334 //--------------------------------------------------
337 void showFileType( FileStatus::Type aType
)
339 if ( aType
==FileStatus::Directory
)
340 printf( "FileType: Directory \n" );
341 else if ( aType
==FileStatus::Volume
)
342 printf( "FileType: Volume \n" );
343 else if ( aType
==FileStatus::Regular
)
344 printf( "FileType: Regular \n" );
345 else if ( aType
==FileStatus::Unknown
)
346 printf( "FileType: Unknown \n" );
351 void showAttributes( sal_uInt64 uAttributes
)
353 if ( uAttributes
==0 )
354 printf( "No Attributes \n" );
355 if ( uAttributes
& osl_File_Attribute_ReadOnly
)
356 printf( "Attribute: ReadOnly \n" );
357 if ( uAttributes
& osl_File_Attribute_Hidden
)
358 printf( "Attribute: Hidden \n" );
359 if ( uAttributes
& osl_File_Attribute_Executable
)
360 printf( "Attribute: Executable \n");
361 if ( uAttributes
& osl_File_Attribute_GrpWrite
)
362 printf( "Attribute: GrpWrite \n");
363 if ( uAttributes
& osl_File_Attribute_GrpRead
)
364 printf( "Attribute: GrpRead \n" );
365 if ( uAttributes
& osl_File_Attribute_GrpExe
)
366 printf( "Attribute: GrpExe \n" );
367 if ( uAttributes
& osl_File_Attribute_OwnWrite
)
368 printf( "Attribute: OwnWrite \n");
369 if ( uAttributes
& osl_File_Attribute_OwnRead
)
370 printf( "Attribute: OwnRead \n" );
371 if ( uAttributes
& osl_File_Attribute_OwnExe
)
372 printf( "Attribute: OwnExe \n" );
373 if ( uAttributes
& osl_File_Attribute_OthWrite
)
374 printf( "Attribute: OthWrite \n" );
375 if ( uAttributes
& osl_File_Attribute_OthRead
)
376 printf( "Attribute: OthRead \n");
377 if ( uAttributes
& osl_File_Attribute_OthExe
)
378 printf( "Attribute: OthExe \n" );
384 void showTime( TimeValue aTime
)
386 TimeValue aLocalTimeVal
, aSystemTimeVal
, aSysTimeVal
;
387 oslDateTime aDateTime
, aSystemTime
;
389 if ( osl_getLocalTimeFromSystemTime( &aTime
, &aLocalTimeVal
) )
391 if ( osl_getDateTimeFromTimeValue( &aLocalTimeVal
, &aDateTime
) )
393 printf("\t%02i.%02i.%4i , %02i.%02i.%02i Uhr\n", aDateTime
.Day
, aDateTime
.Month
, aDateTime
.Year
, aDateTime
.Hours
, aDateTime
.Minutes
, aDateTime
.Seconds
);
399 if ( osl_getDateTimeFromTimeValue( &aTime
, &aSystemTime
) )
401 printf("SystemTime: \t\t%02i.%02i.%4i , %02i.%02i.%02i Uhr\n", aSystemTime
.Day
, aSystemTime
.Month
, aSystemTime
.Year
, aSystemTime
.Hours
, aSystemTime
.Minutes
, aSystemTime
.Seconds
);
408 if ( osl_getTimeValueFromDateTime( &aSystemTime
, &aSystemTimeVal
) )
410 if ( ( aSystemTimeVal
.Seconds
== aTime
.Seconds
) && ( aSystemTimeVal
.Nanosec
== aTime
.Nanosec
))
411 printf ("Verify : TimeValue : ok! \n");
414 printf ("Verify : TimeValue : Error! \n");
415 printf ("aTime : %u \n", aTime
.Seconds
);
416 printf ("aSystemTimeVal : %u \n", aSystemTimeVal
.Seconds
);
420 printf ("Verify : TimeValue : Error! \n");
423 if ( osl_getSystemTimeFromLocalTime( &aLocalTimeVal
, &aSysTimeVal
) )
425 if ( ( aSysTimeVal
.Seconds
== aTime
.Seconds
) && ( aSysTimeVal
.Nanosec
== aTime
.Nanosec
))
426 printf ("Verify : SystemTime : ok! \n");
429 printf ("Verify : SystemTime : Error! \n");
430 printf ("aTime : %u\n", aTime
.Seconds
);
431 printf ("aSystemTimeVal : %u\n", aSysTimeVal
.Seconds
);
435 printf ("Verify : SystemTime : Error! \n");
440 TimeValue
getSystemTime()
447 aTime
.Seconds
= ltime
;
454 //--------------------------------------------------
455 // DirectoryOpenAndCloseTest
456 //--------------------------------------------------
458 void DirectoryOpenAndCloseTest( void )
463 printf( "--------------------------------------------\n");
464 printf( "Directory-Open-And-Close-Test\n");
465 printf( "--------------------------------------------\n\n");
467 //--------------------------------------------------
468 // open an existing directory
469 //--------------------------------------------------
471 pDir
=new Directory( dir1
);
472 printf( "Open an existing directory: ");
473 printFileName( dir1
);
477 print_error( rtl::OString( "Open Directory" ), rc
);
479 if ( pDir
->isOpen() )
481 print_error( rtl::OString( "Directory is Open" ), rc
);
486 print_error( rtl::OString( "Close Directory" ), rc
);
491 //--------------------------------------------------
492 // open a not existing directory
493 //--------------------------------------------------
495 pDir
=new Directory( dir_not_exist
);
497 printf( "Open a not existing directory: ");
498 printFileName( dir_not_exist
);
503 print_error( rtl::OString( "Open Directory" ), rc
);
509 //--------------------------------------------------
510 // open a directory with a wrong semantic
511 //--------------------------------------------------
512 pDir
=new Directory( dir_wrong_semantic
);
514 printf( "Open a directory with a wrong semantic: ");
515 printFileName( dir_wrong_semantic
);
519 print_error( rtl::OString( "Open Directory" ), rc
);
525 //--------------------------------------------------
526 // open an existing directory on a server
527 //--------------------------------------------------
529 pDir
=new Directory( dir_on_server
);
531 printf( "Open an existing directory on a server: ");
532 printFileName( dir_on_server
);
536 print_error( rtl::OString( "Open Directory" ), rc
);
540 print_error( rtl::OString( "Close Directory" ), rc
);
545 //--------------------------------------------------
546 // open a not existing directory on a server
547 //--------------------------------------------------
549 pDir
=new Directory( dir_not_exist_on_server
);
551 printf( "Open a not existing directory on a server: ");
552 printFileName( dir_not_exist_on_server
);
556 print_error( rtl::OString( "Open Directory" ), rc
);
561 //--------------------------------------------------
562 // Close a not existing directory
563 //--------------------------------------------------
565 pDir
=new Directory( dir_not_exist
);
566 printf( "Close a not existing directory: ");
567 printFileName( dir_not_exist
);
571 print_error( rtl::OString( "Close Directory" ), rc
);
578 //--------------------------------------------------
579 // DirectoryCreateAndRemoveTest
580 //--------------------------------------------------
582 void DirectoryCreateAndRemoveTest( void )
587 printf( "--------------------------------------------\n" );
588 printf( "Directory-Create-And-Remove-Test\n" );
589 printf( "--------------------------------------------\n\n" );
591 //--------------------------------------------------
593 //--------------------------------------------------
594 printf( "Create a not existing directory: ");
595 printFileName( dir_not_exist
);
598 rc
=Directory::create( dir_not_exist
) ;
599 print_error( rtl::OString( "Create Directory" ), rc
);
602 pDir
=new Directory( dir_not_exist
);
605 print_error( rtl::OString( "Verify" ), rc
);
611 //--------------------------------------------------
612 // Create a directory on a server
613 //--------------------------------------------------
615 printf( "Create a not existing directory on a server: ");
616 printFileName( dir_not_exist_on_server
);
619 rc
=Directory::create( dir_not_exist_on_server
);
620 print_error( rtl::OString( "Create Directory" ), rc
);
623 pDir
=new Directory( dir_not_exist_on_server
);
625 print_error( rtl::OString( "Verify" ), rc
);
631 //--------------------------------------------------
632 // Remove Directories
633 //--------------------------------------------------
635 printf( "Remove the created directories: \n" );
637 rc
=Directory::remove( dir_not_exist
);
639 rc1
=Directory::remove( dir_not_exist_on_server
);
641 if ( rc
==FileBase::E_None
&& rc1
==FileBase::E_None
)
642 print_error( rtl::OString( "Remove Directories" ), FileBase::E_None
);
643 else if ( rc
!=FileBase::E_None
)
644 print_error( rtl::OString( "Remove local Directory" ),rc
);
646 print_error( rtl::OString( "Remove Directory on a server" ),rc1
);
650 //--------------------------------------------------
651 // Remove a not existing directory
652 //--------------------------------------------------
654 printf( "Remove a not existing directory: ");
655 printFileName( dir_not_exist
);
658 rc
=Directory::remove( dir_not_exist
);
659 print_error( rtl::OString( "Remove" ),rc
);
665 //--------------------------------------------------
666 // FileOpenAndCloseTest
667 //--------------------------------------------------
669 static void FileOpenAndCloseTest( void )
673 printf( "--------------------------------------------\n" );
674 printf( "File-Open-And-Close-Test\n" );
675 printf( "--------------------------------------------\n\n" );
679 pFile
=new File( file1
);
681 printf( "Open an existing file: ");
682 printFileName( file1
);
685 //--------------------------------------------------
686 // open an existing file (Read)
687 //--------------------------------------------------
689 rc
=pFile
->open( osl_File_OpenFlag_Read
);
690 print_error( rtl::OString( "Open File (Read)" ), rc
);
692 //--------------------------------------------------
694 //--------------------------------------------------
697 print_error( rtl::OString( "Close File" ), rc
);
701 //--------------------------------------------------
702 // open an existing file (Write)
703 //--------------------------------------------------
705 rc
=pFile
->open( osl_File_OpenFlag_Write
);
706 print_error( rtl::OString( "Open File (Write)" ), rc
);
708 //--------------------------------------------------
710 //--------------------------------------------------
713 print_error( rtl::OString( "Close File" ), rc
);
717 //--------------------------------------------------
718 // close the file a second time
719 //--------------------------------------------------
722 print_error( rtl::OString( "Close the file a second time" ), rc
);
728 //--------------------------------------------------
729 // FileCreateAndRemoveTest
730 //--------------------------------------------------
732 void FileCreateAndRemoveTest()
737 printf( "--------------------------------------------\n" );
738 printf( "File-Create-And-Remove-Test\n" );
739 printf( "--------------------------------------------\n\n" );
741 pFile
=new File( file_not_exist
);
743 printf( "Create File: ");
744 printFileName( file_not_exist
);
747 //----------------------------------------------------
748 // open (create) a not existing file (Read and write)
749 //----------------------------------------------------
751 rc
= pFile
->open( osl_File_OpenFlag_Read
| osl_File_OpenFlag_Write
| osl_File_OpenFlag_Create
);
753 print_error( rtl::OString( "Create and Open File (Read & Write)" ), rc
);
755 //----------------------------------------------------
757 //----------------------------------------------------
760 print_error( rtl::OString( "Close File" ), rc
);
762 //----------------------------------------------------
764 //----------------------------------------------------
766 rc
=pFile
->remove( file_not_exist
);
767 print_error( rtl::OString(" Remove File" ), rc
);
771 //----------------------------------------------------
772 // remove the same file a second time
773 //----------------------------------------------------
774 rc
=pFile
->remove( file_not_exist
);
775 print_error( rtl::OString( "Remove a not existing File" ), rc
);
777 //----------------------------------------------------
778 // remove an open file
779 //----------------------------------------------------
781 pFile
->open( osl_File_OpenFlag_Read
| osl_File_OpenFlag_Write
| osl_File_OpenFlag_Create
);
783 rc
=pFile
->remove( file_not_exist
);
784 print_error( rtl::OString( "Remove an open File" ), rc
);
787 pFile
->remove( file_not_exist
);
794 //--------------------------------------------------
795 // FileWriteAndReadTest
796 //--------------------------------------------------
798 void FileWriteAndReadTest( void )
804 const sal_Char
*pWriteBuffer
="Hier kommt der Osterhase !";
805 sal_uInt64 nLen
=strlen( pWriteBuffer
);
806 sal_Char
*pReadBuffer
;
808 printf( "--------------------------------------------\n" );
809 printf( "File-Write-And-Read-Test\n" );
810 printf( "--------------------------------------------\n\n" );
814 pFile
=new File( file_not_exist
);
816 printf( "Create File: ");
817 printFileName( file_not_exist
);
820 //----------------------------------------------------
821 // open (create) a not existing file (Read and write)
822 //----------------------------------------------------
824 rc
= pFile
->open( osl_File_OpenFlag_Read
| osl_File_OpenFlag_Write
| osl_File_OpenFlag_Create
);
826 print_error( rtl::OString( "Create and Open File (Read & Write)" ), rc
);
830 //----------------------------------------------------
831 // write a string to the file
832 //----------------------------------------------------
833 rc
=pFile
->write( pWriteBuffer
, nLen
, uWritten
);
834 print_error( rtl::OString( "Write File" ), rc
);
837 printf( "Verify: OK! \n" );
839 printf( "Verify: Error\n" );
843 //----------------------------------------------------
844 // move the filepointer to the beginning
845 //----------------------------------------------------
847 rc
=pFile
->setPos( osl_Pos_Absolut
, 0 );
848 print_error( rtl::OString( "Set FilePointer to the beginning of the file" ), rc
);
852 //----------------------------------------------------
854 //----------------------------------------------------
856 pReadBuffer
=(sal_Char
*) rtl_allocateMemory( (sal_uInt32
)(nLen
+1)*sizeof(sal_Char
) );
857 rtl_zeroMemory( pReadBuffer
, (sal_uInt32
)(nLen
+1)*sizeof(sal_Char
) );
858 rc
=pFile
->read( pReadBuffer
, nLen
,uRead
);
859 print_error( rtl::OString( "Read File" ), rc
);
861 if (strcmp(pWriteBuffer
, pReadBuffer
)==0)
863 printf( "Verify: OK !\n" );
864 printf( "Text: %s\n",pReadBuffer
);
867 printf( "Verify: Error\n" );
869 rtl_freeMemory( pReadBuffer
);
875 print_error( rtl::OString( "Close File" ), rc
);
878 rc
=pFile
->remove( file_not_exist
);
879 print_error( rtl::OString( "Remove File" ), rc
);
887 //--------------------------------------------------
889 //--------------------------------------------------
891 void FileCopyAndMoveTest( void )
895 printf( "--------------------------------------------\n" );
896 printf( "File-Copy-Move-Test\n" );
897 printf( "--------------------------------------------\n\n" );
901 rtl::OUString
destPath(dir2
);
903 //--------------------------------------------------
905 //--------------------------------------------------
907 destPath
+=rtl::OUString("/");
910 printf( "Copy the file ");
911 printFileName( file1
);
913 printFileName( destPath
);
917 rc
=File::copy( file1
, destPath
);
918 print_error( rtl::OString( "FileCopy" ), rc
);
920 pFile
=new File( destPath
);
922 rc
=pFile
->open( osl_File_OpenFlag_Read
);
923 if ( rc
== FileBase::E_None
)
925 printf( "Verify: OK!\n" );
927 File::remove( destPath
);
930 printf( "Verify: Error!\n" );
936 //--------------------------------------------------
937 // Copy a file to a not existing directory
938 //--------------------------------------------------
940 destPath
=rtl::OUString( dir_not_exist
);
941 destPath
+=rtl::OUString("/");
944 printf( "Copy a file to a not existing directory \n");
945 printf( "Copy the file %s to %s\n",
946 rtl::OUStringToOString( file1
, RTL_TEXTENCODING_ASCII_US
).getStr(),
947 rtl::OUStringToOString( destPath
, RTL_TEXTENCODING_ASCII_US
).getStr() );
949 rc
=File::copy( file1
, destPath
);
950 print_error( rtl::OString( "FileCopy" ), rc
);
954 //--------------------------------------------------
956 //--------------------------------------------------
958 printf( "Copy the directory: ");
959 printFileName( dir1
);
961 printFileName( dir2
);
964 rc
=File::copy( dir1
, dir2
);
965 print_error( rtl::OString( "FileCopy" ), rc
);
969 //--------------------------------------------------
971 //--------------------------------------------------
973 destPath
=rtl::OUString( dir2
);
974 destPath
+=rtl::OUString("/");
977 printf( "Move the file ");
978 printFileName( file1
);
980 printFileName( destPath
);
983 rc
=File::move( file1
, destPath
);
984 print_error( rtl::OString( "FileMove" ), rc
);
986 pFile
=new File( destPath
);
988 rc
=pFile
->open( osl_File_OpenFlag_Read
);
989 if ( rc
==FileBase::E_None
)
994 pFile
=new File( file1
);
996 rc
=pFile
->open( osl_File_OpenFlag_Read
);
998 if ( rc
!=FileBase::E_None
)
1000 printf( "Verify: OK!\n" );
1001 File::move( destPath
, file1
);
1005 printf( "Verify: Error!\n" );
1007 File::remove( destPath
);
1011 printf( "Verify: Error!\n" );
1018 //--------------------------------------------------
1019 // Move a file to a not existing directory
1020 //--------------------------------------------------
1022 destPath
=rtl::OUString( dir_not_exist
);
1023 destPath
+=rtl::OUString("/");
1026 printf( "Move a file to a not existing directory: \n");
1027 printf( "Move the file ");
1028 printFileName( file1
);
1030 printFileName( destPath
);
1033 rc
=File::move( file1
, destPath
);
1034 print_error( rtl::OString( "FileMove" ), rc
);
1038 //--------------------------------------------------
1040 //--------------------------------------------------
1042 printf( "Move a directory: \n");
1044 printf( "Move the directory ");
1045 printFileName( dir1
);
1047 printFileName( dir_not_exist
);
1051 rc
=File::move( dir1
, dir_not_exist
);
1052 print_error( rtl::OString( "FileMove" ), rc
);
1054 if ( rc
== FileBase::E_None
)
1055 File::move( dir_not_exist
, dir1
);
1064 //----------------------------------------------------
1066 //----------------------------------------------------
1068 void FileSizeTest( void )
1071 sal_uInt64 filesize
;
1072 DirectoryItem aItem
;
1074 printf( "--------------------------------------------\n" );
1075 printf( "File-Size-Test\n" );
1076 printf( "--------------------------------------------\n\n" );
1079 File
aFile( file_not_exist
);
1081 printf( "Create File: ");
1082 printFileName( file_not_exist
);
1085 rc
= aFile
.open( osl_File_OpenFlag_Read
| osl_File_OpenFlag_Write
| osl_File_OpenFlag_Create
);
1086 print_error( rtl::OString( "Create and Open File (Read & Write)" ), rc
);
1089 if ( rc
== FileBase::E_None
)
1091 //----------------------------------------------------
1092 // Set Filesize to 5000
1093 //----------------------------------------------------
1095 printf( "Set FileSize to 5000\n" );
1096 rc
=aFile
.setSize( 5000 );
1097 print_error( rtl::OString( "Set FileSize" ), rc
);
1100 printf( "Verify:\n" );
1102 //----------------------------------------------------
1103 // Check whether Filesize is set to 5000
1104 //----------------------------------------------------
1106 rc
=DirectoryItem::get( file_not_exist
, aItem
);
1107 print_error( rtl::OString( "Get DirectoryItem" ), rc
);
1109 if ( rc
== FileBase::E_None
)
1111 FileStatus
rStatus( osl_FileStatus_Mask_FileSize
);
1112 rc
=aItem
.getFileStatus( rStatus
);
1113 print_error( rtl::OString( "Get FileStatus" ), rc
);
1115 if ( rc
== FileBase::E_None
)
1117 filesize
=rStatus
.getFileSize();
1119 if ( filesize
== 5000 )
1120 printf( "\nOK : FileSize: %" SAL_PRIuUINT64
"\n", filesize
);
1122 printf( "\nError : FileSize: %" SAL_PRIuUINT64
"\n", filesize
);
1128 //----------------------------------------------------
1129 // Set Filesize to -1
1130 //----------------------------------------------------
1132 printf( "Set FileSize to -1\n" );
1133 rc
=aFile
.setSize( -1 );
1134 print_error( rtl::OString( "Set FileSize" ), rc
);
1140 print_error( rtl::OString( "Close File" ), rc
);
1143 rc
=File::remove( file_not_exist
);
1144 print_error( rtl::OString( "Remove File" ), rc
);
1153 //----------------------------------------------------
1155 //----------------------------------------------------
1157 void FilePointerTest( void )
1160 sal_uInt64 filepointer
;
1162 printf( "--------------------------------------------\n" );
1163 printf( "File-Pointer-Test\n" );
1164 printf( "--------------------------------------------\n\n" );
1167 File
rFile( file_not_exist
);
1169 printf( "Create File: ");
1170 printFileName( file_not_exist
);
1173 rc
= rFile
.open( osl_File_OpenFlag_Read
| osl_File_OpenFlag_Write
| osl_File_OpenFlag_Create
);
1174 print_error( rtl::OString( "Create and Open File (Read & Write) "), rc
);
1177 if ( rc
==FileBase::E_None
)
1180 //----------------------------------------------------
1181 // get the position of the filepointer
1182 //----------------------------------------------------
1184 rc
=rFile
.getPos( filepointer
);
1185 print_error( rtl::OString( "GetPos" ), rc
);
1186 printf( "Position of the FilePointer: %" SAL_PRIuUINT64
"\n", filepointer
);
1190 //----------------------------------------------------
1191 // set the filepointer at the end of a file
1192 //----------------------------------------------------
1194 printf( "Set FileSize to 5000\n" );
1195 rFile
.setSize( 5000 );
1197 printf( "Set the FilePointer at the end of the file (5000)\n" );
1198 rc
=rFile
.setPos( osl_Pos_End
,0 );
1199 print_error( rtl::OString( "SetPos" ), rc
);
1201 rc
=rFile
.getPos( filepointer
);
1203 if ( filepointer
==5000 )
1205 print_error( rtl::OString( "GetPos" ), rc
);
1206 printf( "\nVerify: OK !\n" );
1207 printf( "Filepointer-Position: %" SAL_PRIuUINT64
"\n",filepointer
);
1211 print_error( rtl::OString( "GetPos" ), rc
);
1212 printf( "\nFilePointer-Test: Error\n" );
1213 printf( "Filepointer-Position: %" SAL_PRIuUINT64
" != 5000 \n",filepointer
);
1220 print_error( rtl::OString( "Close File" ), rc
);
1223 rc
=File::remove( file_not_exist
);
1224 print_error( rtl::OString( "Remove File" ), rc
);
1232 //--------------------------------------------------
1233 // FileAttributesTest
1234 //--------------------------------------------------
1236 void verifyFileAttributes( void )
1239 DirectoryItem aItem
;
1240 FileStatus
rStatus( osl_FileStatus_Mask_Attributes
);
1242 printf( "\nVerify:\n" );
1244 rc
=DirectoryItem::get( file1
, aItem
);
1246 if ( rc
==FileBase::E_None
)
1248 rc
=aItem
.getFileStatus( rStatus
);
1250 if ( rc
==FileBase::E_None
)
1252 sal_uInt64 uAttributes
=rStatus
.getAttributes();
1253 showAttributes(uAttributes
);
1257 print_error( rtl::OString( "Get FileStatus" ), rc
);
1260 print_error( rtl::OString( "Get DirectoryItem" ), rc
);
1266 void FileAttributesTest( void )
1270 printf( "--------------------------------------------\n" );
1271 printf( "File-Attributes-Test\n" );
1272 printf( "--------------------------------------------\n\n" );
1275 printFileName( file1
);
1279 rc
=File::setAttributes( file1
, osl_File_Attribute_GrpWrite
);
1280 print_error( rtl::OString( "Set Attribute: GrpWrite" ), rc
);
1282 verifyFileAttributes();
1284 rc
=File::setAttributes( file1
, 0 );
1285 if ( rc
!=FileBase::E_None
)
1286 print_error( rtl::OString( "Reset Attributes" ), rc
);
1288 rc
=File::setAttributes( file1
, osl_File_Attribute_GrpRead
);
1289 print_error( rtl::OString( "Set Attribute: GrpRead" ), rc
);
1291 verifyFileAttributes();
1293 rc
=File::setAttributes( file1
, 0 );
1294 if ( rc
!=FileBase::E_None
)
1295 print_error( rtl::OString( "Reset Attributes" ), rc
);
1297 rc
=File::setAttributes( file1
, osl_File_Attribute_GrpExe
);
1298 print_error( rtl::OString( "Set Attribute: GrpExe" ), rc
);
1300 verifyFileAttributes();
1302 rc
=File::setAttributes( file1
, 0 );
1303 if ( rc
!=FileBase::E_None
)
1304 print_error( rtl::OString( "Reset Attributes" ), rc
);
1306 rc
=File::setAttributes( file1
, osl_File_Attribute_OwnWrite
);
1307 print_error( rtl::OString( "Set Attribute: OwnWrite" ), rc
);
1309 verifyFileAttributes();
1311 rc
=File::setAttributes( file1
, 0 );
1312 if ( rc
!=FileBase::E_None
)
1313 print_error( rtl::OString( "Reset Attributes" ), rc
);
1315 rc
=File::setAttributes( file1
, osl_File_Attribute_OwnRead
);
1316 print_error( rtl::OString( "Set Attribute: OwnRead" ), rc
);
1318 verifyFileAttributes();
1320 rc
=File::setAttributes( file1
, 0 );
1321 if ( rc
!=FileBase::E_None
)
1322 print_error( rtl::OString( "Reset Attributes" ), rc
);
1324 rc
=File::setAttributes( file1
, osl_File_Attribute_OwnExe
);
1325 print_error( rtl::OString( "Set Attribute: OwnExe" ), rc
);
1327 verifyFileAttributes();
1329 rc
=File::setAttributes( file1
, 0 );
1330 if ( rc
!=FileBase::E_None
)
1331 print_error( rtl::OString( "Reset Attributes" ), rc
);
1333 rc
=File::setAttributes( file1
, osl_File_Attribute_OthWrite
);
1334 print_error( rtl::OString( "Set Attribute: OthWrite" ), rc
);
1336 verifyFileAttributes();
1338 rc
=File::setAttributes( file1
, 0 );
1339 if ( rc
!=FileBase::E_None
)
1340 print_error( rtl::OString( "Reset Attributes" ), rc
);
1342 rc
=File::setAttributes( file1
, osl_File_Attribute_OthRead
);
1343 print_error( rtl::OString( "Set Attribute: OthRead" ), rc
);
1345 verifyFileAttributes();
1347 rc
=File::setAttributes( file1
, 0 );
1348 if ( rc
!=FileBase::E_None
)
1349 print_error( rtl::OString( "Reset Attributes" ), rc
);
1351 rc
=File::setAttributes( file1
, osl_File_Attribute_OthExe
);
1352 print_error( rtl::OString( "Set Attribute: OthExe" ), rc
);
1354 verifyFileAttributes();
1356 rc
=File::setAttributes( file1
, 0 );
1357 if ( rc
!=FileBase::E_None
)
1358 print_error( rtl::OString( "Reset Attributes" ), rc
);
1361 rc
=File::setAttributes( file1
, osl_File_Attribute_GrpWrite
| osl_File_Attribute_GrpRead
| osl_File_Attribute_GrpExe
| osl_File_Attribute_OwnWrite
| osl_File_Attribute_OwnRead
| osl_File_Attribute_OwnExe
| osl_File_Attribute_OthWrite
| osl_File_Attribute_OthRead
| osl_File_Attribute_OthExe
);
1362 print_error( rtl::OString( "Set all Attributes" ), rc
);
1364 verifyFileAttributes();
1373 void FileAttributesTest( void )
1377 printf( "--------------------------------------------\n" );
1378 printf( "File-Attributes-Test\n" );
1379 printf( "--------------------------------------------\n\n" );
1382 printFileName( file1
);
1386 rc
=File::setAttributes( file1
, osl_File_Attribute_ReadOnly
);
1387 print_error( rtl::OString( "Set Attribute: ReadOnly" ), rc
);
1389 verifyFileAttributes();
1391 rc
=File::setAttributes( file1
, 0 );
1392 print_error( rtl::OString( "Reset Attributes" ), rc
);
1394 verifyFileAttributes();
1396 rc
=File::setAttributes( file1
, osl_File_Attribute_Hidden
);
1397 print_error( rtl::OString( "Set Attribute: Hidden" ), rc
);
1399 verifyFileAttributes();
1401 rc
=File::setAttributes( file1
, 0 );
1402 print_error( rtl::OString( "Reset Attributes" ), rc
);
1404 verifyFileAttributes();
1406 rc
=File::setAttributes( file1
, osl_File_Attribute_Hidden
| osl_File_Attribute_ReadOnly
);
1407 print_error( rtl::OString( "Set Attribute: Hidden & ReadOnly" ), rc
);
1409 verifyFileAttributes();
1411 rc
=File::setAttributes( file1
, 0 );
1412 print_error( rtl::OString( "Reset Attributes") , rc
);
1414 verifyFileAttributes();
1422 //--------------------------------------------------
1424 //--------------------------------------------------
1426 void FileTimeTest( void )
1430 DirectoryItem aItem
;
1432 struct tm sSysCreationTime
;
1433 sSysCreationTime
.tm_sec
= 0;
1434 sSysCreationTime
.tm_min
= 20;
1435 sSysCreationTime
.tm_hour
= 12;
1436 sSysCreationTime
.tm_mday
= 4;
1437 sSysCreationTime
.tm_mon
= 9;
1438 sSysCreationTime
.tm_year
= 99;
1440 struct tm sSysAccessTime
;
1441 sSysAccessTime
.tm_sec
= 0;
1442 sSysAccessTime
.tm_min
= 40;
1443 sSysAccessTime
.tm_hour
= 1;
1444 sSysAccessTime
.tm_mday
= 6;
1445 sSysAccessTime
.tm_mon
= 5;
1446 sSysAccessTime
.tm_year
= 98;
1448 struct tm sSysModifyTime
;
1449 sSysModifyTime
.tm_sec
= 0;
1450 sSysModifyTime
.tm_min
= 1;
1451 sSysModifyTime
.tm_hour
= 24;
1452 sSysModifyTime
.tm_mday
= 13;
1453 sSysModifyTime
.tm_mon
= 11;
1454 sSysModifyTime
.tm_year
= 95;
1456 sal_uInt32 aSysCreationTime
= mktime( &sSysCreationTime
);
1457 sal_uInt32 aSysAccessTime
= mktime( &sSysAccessTime
);
1458 sal_uInt32 aSysModifyTime
= mktime( &sSysModifyTime
);
1460 TimeValue aCreationTime
= { aSysCreationTime
, 0};
1461 TimeValue aAccessTime
= { aSysAccessTime
, 0};
1462 TimeValue aModifyTime
= { aSysModifyTime
, 0};
1464 TimeValue aCreationTimeRead
;
1465 TimeValue aAccessTimeRead
;
1466 TimeValue aModifyTimeRead
;
1469 printf( "--------------------------------------------\n" );
1470 printf( "File-Time-Test\n" );
1471 printf( "--------------------------------------------\n\n" );
1474 printFileName( file1
);
1477 printf( "CreationTime \t : ");
1478 showTime( aCreationTime
);
1480 printf( "\nAccessTime \t : ");
1481 showTime( aAccessTime
);
1483 printf( "\nModifyTime \t : ");
1484 showTime( aModifyTime
);
1486 //--------------------------------------------------
1488 //--------------------------------------------------
1491 rc
=File::setTime( file1
, aCreationTime
, aAccessTime
, aModifyTime
);
1492 print_error( rtl::OString( "SetTime" ), rc
);
1494 //--------------------------------------------------
1496 //--------------------------------------------------
1498 FileStatus
rStatus( osl_FileStatus_Mask_CreationTime
| osl_FileStatus_Mask_AccessTime
| osl_FileStatus_Mask_ModifyTime
);
1500 printf( "\nVerify:\n" );
1502 rc
=DirectoryItem::get( file1
, aItem
);
1503 print_error( rtl::OString( "Get DirectoryItem" ), rc
);
1505 if ( rc
==FileBase::E_None
)
1507 rc
=aItem
.getFileStatus( rStatus
);
1508 print_error( rtl::OString( "Get FileStatus" ), rc
);
1511 if ( rc
==FileBase::E_None
)
1513 //--------------------------------------------------
1515 //--------------------------------------------------
1517 aCreationTimeRead
=rStatus
.getCreationTime();
1519 if ( aCreationTime
.Seconds
== aCreationTimeRead
.Seconds
&& aCreationTime
.Nanosec
== aCreationTimeRead
.Nanosec
)
1520 printf( "GetCreationTime: ok : " );
1522 printf( "GetCreationTime: Error : " );
1524 showTime( aCreationTimeRead
);
1527 //--------------------------------------------------
1529 //--------------------------------------------------
1531 aAccessTimeRead
=rStatus
.getAccessTime();
1533 if ( aAccessTime
.Seconds
== aAccessTimeRead
.Seconds
&& aAccessTime
.Nanosec
== aAccessTimeRead
.Nanosec
)
1534 printf( "GetAccessTime: ok : " );
1536 printf( "GetAccessTime: Error : " );
1538 showTime( aAccessTimeRead
);
1541 //--------------------------------------------------
1543 //--------------------------------------------------
1545 aModifyTimeRead
=rStatus
.getModifyTime();
1547 if ( aModifyTime
.Seconds
== aModifyTimeRead
.Seconds
&& aModifyTime
.Nanosec
== aModifyTimeRead
.Nanosec
)
1548 printf( "GetModifyTime: ok : " );
1550 printf( "GetModifyTime: Error : " );
1552 showTime( aModifyTimeRead
);
1562 //--------------------------------------------------
1563 // DirectoryItemTest
1564 //--------------------------------------------------
1566 void DirectoryItemTest( void )
1570 DirectoryItem aItem
;
1571 FileStatus
*pStatus
;
1574 printf( "--------------------------------------------\n" );
1575 printf( "Directory-Item-Test\n" );
1576 printf( "--------------------------------------------\n\n" );
1578 //--------------------------------------------------
1579 // get DirectoryItem from an existing directory
1580 //--------------------------------------------------
1582 printf( "Get DirectoryItem from an existing Directory: ");
1583 printFileName( dir1
);
1586 rc
=DirectoryItem::get( dir1
, aItem
);
1587 print_error( rtl::OString( "GetDirectoryItem" ), rc
);
1589 pStatus
=new FileStatus( osl_FileStatus_Mask_All
);
1590 rc
=aItem
.getFileStatus( *pStatus
);
1592 if ( rc
==FileBase::E_None
)
1594 printf( "GetFileStatus: FileURL: ");
1595 printFileName(pStatus
->getFileURL() );
1603 //--------------------------------------------------
1604 // get DirectoryItem from a not existing directory
1605 //--------------------------------------------------
1607 printf( "Get DirectoryItem from a not existing Directory: ");
1608 printFileName( dir_not_exist
);
1611 rc
=DirectoryItem::get( dir_not_exist
, aItem
);
1612 print_error( rtl::OString( "Get DirectoryItem" ), rc
);
1616 //--------------------------------------------------
1617 // get DirectoryItem from an existing file
1618 //--------------------------------------------------
1620 printf( "Get DirectoryItem from an existing File: ");
1621 printFileName( file1
);
1624 rc
=DirectoryItem::get( file1
, aItem
);
1625 print_error( rtl::OString( "GetDirectoryItem" ), rc
);
1627 pStatus
=new FileStatus( osl_FileStatus_Mask_All
);
1628 rc
=aItem
.getFileStatus( *pStatus
);
1630 if ( rc
==FileBase::E_None
)
1632 printf( "GetFileStatus: FileURL: ");
1633 printFileName( pStatus
->getFileURL() );
1641 //--------------------------------------------------
1642 // get DirectoryItem from a not existing file
1643 //--------------------------------------------------
1645 printf( "Get DirectoryItem from a not existing File: ");
1646 printFileName( file_not_exist
);
1649 rc
=DirectoryItem::get( file_not_exist
, aItem
);
1650 print_error( rtl::OString( "Get DirectoryItem" ), rc
);
1654 //----------------------------------------------------------
1655 // get DirectoryItem from a directory with a wrong semantic
1656 //----------------------------------------------------------
1658 printf( "Get DirectoryItem from a Directory with a wrong semantic: ");
1659 printFileName( dir_not_exist
);
1662 rc
=DirectoryItem::get( dir_wrong_semantic
, aItem
);
1663 print_error( rtl::OString( "Get DirectoryItem" ),rc
);
1667 //---------------------------------------------------
1668 // get DirectoryItem from a file-handle
1669 //--------------------------------------------------
1671 pFile
=new File( file1
);
1673 rc
=pFile
->open( osl_File_OpenFlag_Read
);
1674 if ( rc
==FileBase::E_None
)
1676 printf( "Get DirectoryItem from a File-Handle: ");
1677 printFileName( file1
);
1680 rc
=DirectoryItem::get( file1
, aItem
);
1681 print_error( rtl::OString( "GetDirectoryItem" ), rc
);
1683 pStatus
=new FileStatus( osl_FileStatus_Mask_All
);
1684 rc
=aItem
.getFileStatus( *pStatus
);
1686 if ( rc
==FileBase::E_None
)
1688 printf( "GetFileStatus: FileURL: ");
1689 printFileName( pStatus
->getFileURL() );
1702 //---------------------------------------------------
1703 // get DirectoryItem
1704 //--------------------------------------------------
1706 printf( "Get DirectoryItem from an empty File-Handle\n" );
1707 rc
=DirectoryItem::get( file1
, aItem
);
1708 print_error( rtl::OString( "GetDirectoryItem" ), rc
);
1712 //--------------------------------------------------
1713 // GetNextItem from a directory
1714 //--------------------------------------------------
1716 pDir
=new Directory( dir1
);
1717 printf( "Get next DirectoryItem from a directory: ");
1718 printFileName( dir1
);
1722 print_error( rtl::OString( "Open Directory" ), rc
);
1726 if ( pDir
->isOpen() )
1728 //--------------------------------------------------
1729 // get all files from the directory
1730 //--------------------------------------------------
1733 rtl::OUString str1
[2];
1735 aItem
=DirectoryItem();
1736 rc
=pDir
->getNextItem( aItem
);
1737 print_error( rtl::OString( "GetNextItem" ),rc
);
1739 while( rc
==FileBase::E_None
)
1742 FileStatus
rStatus( osl_FileStatus_Mask_All
);
1743 aItem
.getFileStatus( rStatus
);
1745 str
=rStatus
.getFileName();
1746 printf( "Filename: ");
1747 printFileName( str
);
1750 aItem
=DirectoryItem();
1751 rc
=pDir
->getNextItem( aItem
);
1752 print_error( rtl::OString( "GetNextItem" ),rc
);
1757 //--------------------------------------------------
1759 //--------------------------------------------------
1761 for (int i
=0; i
<2; i
++)
1763 aItem
=DirectoryItem();
1765 rc
=pDir
->getNextItem( aItem
);
1767 FileStatus
rStatus( osl_FileStatus_Mask_All
);
1768 aItem
.getFileStatus( rStatus
);
1770 str1
[i
]=rStatus
.getFileName();
1774 if ( str1
[0].compareTo(str1
[1]) == 0 )
1775 print_error( rtl::OString( "Reset" ),FileBase::E_None
);
1777 print_error( rtl::OString( "Reset" ),FileBase::E_invalidError
);
1783 print_error( rtl::OString( "Close Directory" ), rc
);
1788 //--------------------------------------------------
1789 // GetNextItem from a closed directory
1790 //--------------------------------------------------
1792 printf( "Get next DirectoryItem from a closed directory: ");
1793 printFileName( dir1
);
1796 aItem
=DirectoryItem();
1797 rc
=pDir
->getNextItem( aItem
);
1798 print_error( rtl::OString( "GetNextItem" ),rc
);
1806 //--------------------------------------------------
1807 // FileStatusTest (for different types)
1808 //--------------------------------------------------
1810 void FileStatusTest( FileStatus
*pStatus
)
1812 //--------------------------------------------------
1813 // GetFileType of the directory
1814 //--------------------------------------------------
1816 FileStatus::Type aType
;
1818 printf( "\ngetFileType:\n" );
1819 aType
=pStatus
->getFileType();
1820 showFileType( aType
);
1822 //--------------------------------------------------
1824 //--------------------------------------------------
1826 sal_uInt64 uAttributes
;
1828 printf( "\ngetAttributes:\n" );
1829 uAttributes
=pStatus
->getAttributes();
1830 showAttributes( uAttributes
);
1832 //--------------------------------------------------
1834 //--------------------------------------------------
1836 TimeValue aCreationTime
;
1838 printf( "\ngetCreationTime:\n" );
1839 aCreationTime
=pStatus
->getCreationTime();
1841 printf( "CreationTime: " );
1842 showTime( aCreationTime
);
1844 //--------------------------------------------------
1846 //--------------------------------------------------
1848 TimeValue aAccessTime
;
1850 printf( "\ngetAccessTime:\n" );
1851 aAccessTime
=pStatus
->getAccessTime();
1853 printf( "AccessTime: " );
1854 showTime( aAccessTime
);
1856 //--------------------------------------------------
1858 //--------------------------------------------------
1860 TimeValue aModifyTime
;
1862 printf( "\ngetModifyTime:\n" );
1863 aModifyTime
=pStatus
->getModifyTime();
1865 printf( "ModifyTime: " );
1866 showTime( aModifyTime
);
1868 //--------------------------------------------------
1870 //--------------------------------------------------
1872 sal_uInt64 FileSize
;
1874 printf( "\ngetFileSize:\n" );
1876 FileSize
=pStatus
->getFileSize();
1877 printf( "FileSize: %" SAL_PRIuUINT64
"\n", FileSize
);
1879 //--------------------------------------------------
1881 //--------------------------------------------------
1883 rtl::OUString FileName
;
1885 printf( "\ngetFileName:\n" );
1887 FileName
=pStatus
->getFileName();
1888 printf( "FileName: ");
1889 printFileName( FileName
);
1892 //--------------------------------------------------
1894 //--------------------------------------------------
1896 rtl::OUString FileURL
;
1898 printf( "\ngetFileURL:\n" );
1900 FileURL
=pStatus
->getFileURL();
1901 printf( "FileURL: ");
1902 printFileName( FileURL
);
1905 //--------------------------------------------------
1907 //--------------------------------------------------
1909 rtl::OUString LinkTargetURL
;
1911 printf( "\ngetLinkTargetURL:\n");
1913 LinkTargetURL
=pStatus
->getLinkTargetURL();
1914 printf( "LinkTargetURL: ");
1915 printFileName( LinkTargetURL
);
1921 //--------------------------------------------------
1922 // DirectoryFileStatusTest
1923 //--------------------------------------------------
1925 void DirectoryFileStatusTest( void )
1928 DirectoryItem aItem
;
1929 FileStatus
*pStatus
;
1931 printf( "--------------------------------------------\n" );
1932 printf( "Directory-FileStatus-Test\n" );
1933 printf( "--------------------------------------------\n\n" );
1935 printf( "FileStatus of the directory: ");
1936 printFileName( dir1
);
1939 aItem
=DirectoryItem();
1941 rc
=DirectoryItem::get( dir1
, aItem
);
1942 print_error( rtl::OString( "Get DirectoryItem" ), rc
);
1944 if ( rc
==FileBase::E_None
)
1946 pStatus
=new FileStatus( osl_FileStatus_Mask_All
);
1947 rc
=aItem
.getFileStatus( *pStatus
);
1949 FileStatusTest( pStatus
);
1960 //--------------------------------------------------
1961 // FileFileStatusTest
1962 //--------------------------------------------------
1964 void FileFileStatusTest( void )
1967 DirectoryItem aItem
;
1968 FileStatus
*pStatus
;
1970 printf( "--------------------------------------------\n" );
1971 printf( "File-FileStatus-Test\n" );
1972 printf( "--------------------------------------------\n\n" );
1974 printf( "FileStatus of the file: ");
1975 printFileName( file1
);
1978 aItem
=DirectoryItem();
1980 rc
=DirectoryItem::get( file1
, aItem
);
1981 print_error( rtl::OString( "Get DirectoryItem" ), rc
);
1983 if ( rc
==FileBase::E_None
)
1985 pStatus
=new FileStatus( osl_FileStatus_Mask_All
);
1986 rc
=aItem
.getFileStatus( *pStatus
);
1988 FileStatusTest( pStatus
);
1999 //--------------------------------------------------
2000 // VolumeFileStatusTest
2001 //--------------------------------------------------
2003 void VolumeFileStatusTest( void )
2006 DirectoryItem aItem
;
2007 FileStatus
*pStatus
;
2009 printf( "--------------------------------------------\n" );
2010 printf( "Volume-FileStatus-Test\n" );
2011 printf( "--------------------------------------------\n\n" );
2013 printf( "FileStatus of the Volume: ");
2014 printFileName( root
);
2017 aItem
=DirectoryItem();
2019 rc
=DirectoryItem::get( root
, aItem
);
2020 print_error( rtl::OString( "Get DirectoryItem" ), rc
);
2022 if ( rc
==FileBase::E_None
)
2024 pStatus
=new FileStatus( osl_FileStatus_Mask_All
) ;
2025 rc
=aItem
.getFileStatus( *pStatus
);
2027 FileStatusTest( pStatus
);
2039 //--------------------------------------------------
2041 //--------------------------------------------------
2043 void VolumeInfoTest( void )
2047 printf( "--------------------------------------------\n" );
2048 printf( "Volume-Info-Test\n" );
2049 printf( "--------------------------------------------\n\n" );
2051 printf( "VolumeInfo of the volume ");
2052 printFileName( root
);
2056 VolumeInfo
rInfo( osl_VolumeInfo_Mask_FreeSpace
);
2057 rc
=Directory::getVolumeInfo( root
, rInfo
);
2058 print_error( rtl::OString( "GetVolumeInfo" ),rc
);
2062 //--------------------------------------------------
2064 //--------------------------------------------------
2066 if ( rInfo
.getRemoteFlag() )
2067 printf( "RemoteFlag: Yes\n" );
2069 printf( "RemoteFlag: No\n" );
2071 //--------------------------------------------------
2072 // getRemoveableFlag
2073 //--------------------------------------------------
2075 if ( rInfo
.getRemoveableFlag() )
2076 printf( "RemoveableFlag: Yes\n" );
2078 printf( "RemoveableFlag: No\n" );
2080 //--------------------------------------------------
2082 //--------------------------------------------------
2084 sal_uInt64 TotalSpace
;
2085 TotalSpace
=rInfo
.getTotalSpace();
2086 printf( "Total Space: %" SAL_PRIuUINT64
"\n",TotalSpace
);
2088 //--------------------------------------------------
2090 //--------------------------------------------------
2092 sal_uInt64 FreeSpace
;
2093 FreeSpace
=rInfo
.getFreeSpace();
2094 printf( "Free Space: %" SAL_PRIuUINT64
"\n",FreeSpace
);
2096 //--------------------------------------------------
2098 //--------------------------------------------------
2100 sal_uInt64 UsedSpace
;
2101 UsedSpace
=rInfo
.getUsedSpace();
2102 printf( "Used Space: %" SAL_PRIuUINT64
"\n",UsedSpace
);
2104 //--------------------------------------------------
2106 //--------------------------------------------------
2108 sal_uInt32 MaxNameLength
;
2109 MaxNameLength
=rInfo
.getMaxNameLength();
2110 printf( "MaxNameLength: %" SAL_PRIuUINT32
"\n",MaxNameLength
);
2112 //--------------------------------------------------
2114 //--------------------------------------------------
2116 sal_uInt32 MaxPathLength
;
2117 MaxPathLength
=rInfo
.getMaxPathLength();
2118 printf( "MaxPathLength: %" SAL_PRIuUINT32
"\n",MaxPathLength
);
2120 //--------------------------------------------------
2121 // getFileSystemName
2122 //--------------------------------------------------
2124 rtl::OUString FileSystemName
;
2125 FileSystemName
=rInfo
.getFileSystemName();
2126 printf( "File-System-Name: ");
2127 printFileName( FileSystemName
);
2134 //--------------------------------------------------
2136 //--------------------------------------------------
2138 void ConvertPathTest(rtl::OUString
& strPath
)
2142 rtl::OUString strNormPath
;
2143 rtl::OUString strFileURL
;
2144 rtl::OUString strNormPathFromFileURL
;
2145 rtl::OUString strSystemPath
;
2147 //--------------------------------------------------
2149 //--------------------------------------------------
2151 rc
=FileBase::getFileURLFromSystemPath( strPath
, strNormPath
);
2153 if ( rc
== FileBase::E_None
)
2155 printf( "Normalized Path: \t\t");
2156 printFileName( strNormPath
);
2160 printf( "normalizePath: Error \n" );
2162 //--------------------------------------------------
2163 // getFileURLFromSystemPath
2164 //--------------------------------------------------
2166 if ( strNormPath
.getLength() != 0 )
2168 rc
=FileBase::getFileURLFromSystemPath( strNormPath
, strFileURL
);
2170 if ( rc
== FileBase::E_None
)
2172 printf( "File-URL: \t\t\t");
2173 printFileName( strFileURL
);
2177 printf( "getFileURLFromSystemPath: Error \n" );
2180 printf( "getFileURLFromSystemPath: not tested \n" );
2182 //--------------------------------------------------
2183 // getNormalizedPathFromFileURL
2184 //--------------------------------------------------
2186 if ( strFileURL
.getLength() != 0 )
2188 rc
=FileBase::getSystemPathFromFileURL( strFileURL
, strNormPathFromFileURL
);
2190 if ( rc
== FileBase::E_None
)
2192 printf( "Normalized Path from File-URL: \t");
2193 printFileName( strNormPathFromFileURL
);
2197 printf( "getNormalizedPathFromFileURL: Error \n" );
2200 printf( "getNormalizedPathFromFileURL: not tested \n" );
2203 //--------------------------------------------------
2204 // getSystemPathFromFileURL
2205 //--------------------------------------------------
2207 if ( strNormPath
.getLength() != 0 )
2209 rc
=FileBase::getSystemPathFromFileURL( strNormPath
, strSystemPath
);
2211 if ( rc
== FileBase::E_None
)
2213 printf( "System-Path: \t\t\t");
2214 printFileName( strSystemPath
);
2218 printf( "getSystemPathFromFileURL: Error \n" );
2221 printf( "getSystemPathFromFileURL: not tested \n" );
2223 //--------------------------------------------------
2225 //--------------------------------------------------
2227 if ( strNormPathFromFileURL
== strNormPath
)
2228 printf( "\nVerify: OK ! ( Normalized-Path == Normalized-Path-From-File-URL )\n" );
2230 printf( "\nVerify: Error ! ( Normalized-Path != Normalized-Path-From-File-URL )\n" );
2237 printf( "--------------------------------------------\n" );
2238 printf( "FileBase-Test\n" );
2239 printf( "--------------------------------------------\n\n" );
2241 //--------------------------------------------------
2242 // ConvertPath-Test (Local File)
2243 //--------------------------------------------------
2245 printf( "- Local File: ");
2246 printFileName( file1
);
2249 ConvertPathTest(file1
);
2251 //--------------------------------------------------
2252 // ConvertPath-Test (File on a server)
2253 //--------------------------------------------------
2255 printf( "\n- File on server: ");
2256 printFileName( file_on_server
);
2258 ConvertPathTest(file_on_server
);
2266 //--------------------------------------------------
2268 //--------------------------------------------------
2269 void DoAbsolutePathTest(rtl::OUString strDirBase
, rtl::OUString strRelative
)
2273 rtl::OUString strAbsolute
;
2275 printf( "Base-Directory: \t");
2276 printFileName( strDirBase
);
2278 printf( "Relative-Path: \t\t");
2279 printFileName ( strRelative
);
2282 rc
=FileBase::getAbsoluteFileURL( strDirBase
, strRelative
, strAbsolute
);
2284 if ( rc
== FileBase::E_None
)
2286 printf( "Absolute-Path: \t\t");
2287 printFileName ( strAbsolute
);
2291 printf( "Absolute-Path: Error \n" );
2297 void AbsolutePathTest(void)
2299 printf( "--------------------------------------------\n" );
2300 printf( "AbsolutePath-Test\n" );
2301 printf( "--------------------------------------------\n\n" );
2303 DoAbsolutePathTest(dir1
, rtl::OUString("."));
2304 DoAbsolutePathTest(dir1
, rtl::OUString(".."));
2305 DoAbsolutePathTest(dir1
, rtl::OUString("../.."));
2306 DoAbsolutePathTest(dir1
, rtl::OUString("../HUHU"));
2308 DoAbsolutePathTest(dir_on_server
, rtl::OUString("."));
2309 DoAbsolutePathTest(dir_on_server
, rtl::OUString(".."));
2310 DoAbsolutePathTest(dir_on_server
, rtl::OUString("../.."));
2311 DoAbsolutePathTest(dir_on_server
, rtl::OUString("../HUHU"));
2318 //--------------------------------------------------
2320 //--------------------------------------------------
2322 void SearchPathTest(void)
2326 rtl::OUString
strNormPath(file1
);
2327 rtl::OUString strFileURL
;
2328 rtl::OUString strSystemPath
;
2329 rtl::OUString strResultPath
;
2331 printf( "--------------------------------------------\n" );
2332 printf( "SearchPath-Test\n" );
2333 printf( "--------------------------------------------\n\n" );
2336 rc
=FileBase::getFileURLFromSystemPath( strNormPath
, strFileURL
);
2337 print_error( rtl::OString( "getFileURLFromSystemPath" ), rc
);
2338 rc
=FileBase::getSystemPathFromFileURL( strNormPath
, strSystemPath
);
2339 print_error( rtl::OString( "getSystemPathFromFileURL" ), rc
);
2341 //--------------------------------------------------
2342 // searchFileURL (with a normalized path)
2343 //--------------------------------------------------
2345 if ( strNormPath
.getLength() != 0 )
2347 printf( "\nSearch-Normalized-Path (with a normalized path) : ");
2348 printFileName ( strNormPath
);
2351 rc
=FileBase::searchFileURL( strNormPath
, rtl::OUString() , strResultPath
);
2353 if ( rc
== FileBase::E_None
)
2355 printf( "Result: \t\t\t");
2356 printFileName ( strResultPath
);
2360 printf( "searchFileURL (with a normalized path): Error\n" );
2363 printf( "searchFileURL (with a normalized path): not tested\n" );
2365 //--------------------------------------------------
2366 // searchFileURL (with a File-URL)
2367 //--------------------------------------------------
2369 if ( strFileURL
.getLength() != 0 )
2371 printf( "\nSearch-Normalized-Path (with a FileURL) : ");
2372 printFileName( strFileURL
);
2375 rc
=FileBase::searchFileURL( strFileURL
, rtl::OUString() , strResultPath
);
2377 if ( rc
== FileBase::E_None
)
2379 printf( "Result: \t\t\t");
2380 printFileName ( strResultPath
);
2384 printf( "searchFileURL (with a FileURL path): Error\n" );
2387 printf( "searchFileURL (with a FileURL path): not tested\n" );
2389 //--------------------------------------------------
2390 // searchFileURL (with a systempath)
2391 //--------------------------------------------------
2393 if ( strSystemPath
.getLength() != 0 )
2395 printf( "\nSearch-Normalized-Path (with a SystemPath) : ");
2396 printFileName( strSystemPath
);
2399 rc
=FileBase::searchFileURL( strSystemPath
, rtl::OUString() , strResultPath
);
2401 if ( rc
== FileBase::E_None
)
2403 printf( "Result: \t\t\t");
2404 printFileName( strResultPath
);
2408 printf( "searchFileURL (with a systempath): Error\n" );
2411 printf( "searchFileURL (with a systempath): not tested\n" );
2413 //--------------------------------------------------
2414 // searchFileURL (File and no searchpath)
2415 //--------------------------------------------------
2417 printf( "\nsearchFileURL: File (no searchpath) : ");
2418 printFileName( file3
);
2421 rc
=FileBase::searchFileURL( file3
, rtl::OUString("") , strResultPath
);
2423 if ( rc
== FileBase::E_None
)
2425 printf( "Result: \t\t\t");
2426 printFileName( strResultPath
);
2430 printf( "searchFileURL: File not found: OK ! \n" );
2432 //--------------------------------------------------
2433 // searchFileURL (File and Path)
2434 //--------------------------------------------------
2436 printf( "\nsearchFileURL: File : ");
2437 printFileName( file3
);
2438 printf( "\tSearchPath ");
2439 printFileName( dir1
);
2442 rc
=FileBase::searchFileURL( file3
, dir1
, strResultPath
);
2444 if ( rc
== FileBase::E_None
)
2446 printf( "Result: \t\t\t");
2447 printFileName( strResultPath
);
2451 printf( "searchFileURL: File not found: Error\n" );
2453 //------------------------------------------------------------
2454 // searchFileURL (File and searchpath with two entries)
2455 //------------------------------------------------------------
2457 rtl::OUString
strSearchPath( dir_not_exist
);
2458 strSearchPath
+=rtl::OUString(";");
2459 strSearchPath
+=dir_on_server
;
2461 printf( "\nsearchFileURL: File : ");
2462 printFileName( file3
);
2463 printf( "SearchPath ");
2464 printFileName( strSearchPath
);
2467 rc
=FileBase::searchFileURL( file3
, strSearchPath
, strResultPath
);
2469 if ( rc
== FileBase::E_None
)
2471 printf( "Result: \t\t\t");
2472 printFileName( strResultPath
);
2476 printf( "searchFileURL: File not found: Error\n" );
2478 //-------------------------------------------------------------------
2479 // searchFileURL (File and searchpath (with a wrong semantic))
2480 //-------------------------------------------------------------------
2482 strSearchPath
=rtl::OUString( dir_wrong_semantic
);
2484 printf( "\nsearchFileURL: File : ");
2485 printFileName( file3
);
2486 printf( "SearchPath ");
2487 printFileName( strSearchPath
);
2490 rc
=FileBase::searchFileURL( file3
, strSearchPath
, strResultPath
);
2492 if ( rc
== FileBase::E_None
)
2493 printf( "Error: Wrong Semantich but no error occurs !\n" );
2495 printf( "searchFileURL: File not found: OK !\n" );
2500 //--------------------------------------------------
2501 // CanonicalNameTest
2502 //--------------------------------------------------
2504 void getCanonicalNameTest(rtl::OUString strPath
)
2508 rtl::OUString strValid
;
2510 printf( "Original-Name: \t\t");
2511 printFileName( strPath
);
2514 rc
=FileBase::getCanonicalName( strPath
, strValid
);
2516 if ( rc
== FileBase::E_None
)
2518 printf( "Canonical-Name: \t");
2519 printFileName( strValid
);
2524 printf( "Canonical-Name: Error \n" );
2530 void CanonicalNameTest(void)
2532 printf( "--------------------------------------------\n" );
2533 printf( "CanonicalName-Test\n" );
2534 printf( "--------------------------------------------\n\n" );
2536 getCanonicalNameTest( dir1
);
2537 getCanonicalNameTest( dir_on_server
);
2538 getCanonicalNameTest( file1
);
2539 getCanonicalNameTest( file_on_server
);
2545 //--------------------------------------------------
2547 //--------------------------------------------------
2549 void print_error( const ::rtl::OString
& str
, FileBase::RC rc
)
2552 printf( "%s : ", str
.getStr() );
2555 case FileBase::E_None
:
2558 case FileBase::E_PERM
:
2561 case FileBase::E_NOENT
:
2562 printf("E_NOENT\n");
2564 case FileBase::E_SRCH
:
2567 case FileBase::E_INTR
:
2570 case FileBase::E_IO
:
2573 case FileBase::E_NXIO
:
2576 case FileBase::E_2BIG
:
2579 case FileBase::E_NOEXEC
:
2580 printf("E_NOEXEC\n");
2582 case FileBase::E_BADF
:
2585 case FileBase::E_CHILD
:
2586 printf("E_CHILD\n");
2588 case FileBase::E_AGAIN
:
2589 printf("E_AGAIN\n");
2591 case FileBase::E_NOMEM
:
2592 printf("E_NOMEM\n");
2594 case FileBase::E_ACCES
:
2595 printf("E_ACCES\n");
2597 case FileBase::E_FAULT
:
2598 printf("E_FAULT\n");
2600 case FileBase::E_BUSY
:
2603 case FileBase::E_EXIST
:
2604 printf("E_EXIST\n");
2606 case FileBase::E_XDEV
:
2609 case FileBase::E_NODEV
:
2610 printf("E_NODEV\n");
2612 case FileBase::E_NOTDIR
:
2613 printf("E_NOTDIR\n");
2615 case FileBase::E_ISDIR
:
2616 printf("E_ISDIR\n");
2618 case FileBase::E_INVAL
:
2619 printf("E_INVAL\n");
2621 case FileBase::E_NFILE
:
2622 printf("E_NFILE\n");
2624 case FileBase::E_MFILE
:
2625 printf("E_MFILE\n");
2627 case FileBase::E_NOTTY
:
2628 printf("E_NOTTY\n");
2630 case FileBase::E_FBIG
:
2633 case FileBase::E_NOSPC
:
2634 printf("E_NOSPC\n");
2636 case FileBase::E_SPIPE
:
2637 printf("E_SPIPE\n");
2639 case FileBase::E_ROFS
:
2642 case FileBase::E_MLINK
:
2643 printf("E_MLINK\n");
2645 case FileBase::E_PIPE
:
2648 case FileBase::E_DOM
:
2651 case FileBase::E_RANGE
:
2652 printf("E_RANGE\n");
2654 case FileBase::E_DEADLK
:
2655 printf("E_DEADLK\n");
2657 case FileBase::E_NAMETOOLONG
:
2658 printf("E_NAMETOOLONG\n");
2660 case FileBase::E_NOLCK
:
2661 printf("E_NOLCK\n");
2663 case FileBase::E_NOSYS
:
2664 printf("E_NOSYS\n");
2666 case FileBase::E_NOTEMPTY
:
2667 printf("E_NOTEMPTY\n");
2669 case FileBase::E_LOOP
:
2672 case FileBase::E_ILSEQ
:
2673 printf("E_ILSEQ\n");
2675 case FileBase::E_NOLINK
:
2676 printf("E_NOLINK\n");
2678 case FileBase::E_MULTIHOP
:
2679 printf("E_MULTIHOP\n");
2681 case FileBase::E_USERS
:
2682 printf("E_USERS\n");
2684 case FileBase::E_OVERFLOW
:
2685 printf("E_OVERFLOW\n");
2688 printf("E_Unknown\n");
2694 //--------------------------------------------------
2696 //--------------------------------------------------
2698 #define MAIN _cdecl main
2703 int MAIN( int argc
, char* argv
[] )
2705 sal_Bool fSuccess
=sal_False
;
2708 fSuccess
=Initialize();
2711 printf("Error during Initialization");
2718 DirectoryOpenAndCloseTest();
2719 DirectoryCreateAndRemoveTest();
2721 FileOpenAndCloseTest();
2722 FileCreateAndRemoveTest();
2723 FileWriteAndReadTest();
2724 FileCopyAndMoveTest();
2727 FileAttributesTest();
2729 DirectoryItemTest();
2730 DirectoryFileStatusTest();
2731 VolumeFileStatusTest();
2732 FileFileStatusTest();
2737 CanonicalNameTest();
2739 // command line arguments ?
2746 if (strcmp(argv
[i
], "doc")==0)
2747 DirectoryOpenAndCloseTest();
2748 else if (strcmp(argv
[i
], "dcr")==0)
2749 DirectoryCreateAndRemoveTest();
2750 else if (strcmp(argv
[i
], "foc")==0)
2751 FileOpenAndCloseTest();
2752 else if (strcmp(argv
[i
], "fcr")==0)
2753 FileCreateAndRemoveTest();
2754 else if (strcmp(argv
[i
], "fwr")==0)
2755 FileWriteAndReadTest();
2756 else if (strcmp(argv
[i
], "fcm")==0)
2757 FileCopyAndMoveTest();
2758 else if (strcmp(argv
[i
], "fs")==0)
2760 else if (strcmp(argv
[i
], "fp")==0)
2762 else if (strcmp(argv
[i
], "fa")==0)
2763 FileAttributesTest();
2764 else if (strcmp(argv
[i
], "ft")==0)
2766 else if (strcmp(argv
[i
], "di")==0)
2767 DirectoryItemTest();
2768 else if (strcmp(argv
[i
], "dfs")==0)
2769 DirectoryFileStatusTest();
2770 else if (strcmp(argv
[i
], "vfs")==0)
2771 VolumeFileStatusTest();
2772 else if (strcmp(argv
[i
], "ffs")==0)
2773 FileFileStatusTest();
2774 else if (strcmp(argv
[i
], "vi")==0)
2776 else if (strcmp(argv
[i
], "fb")==0)
2778 else if (strcmp(argv
[i
], "sp")==0)
2780 else if (strcmp(argv
[i
], "ap")==0)
2782 else if (strcmp(argv
[i
], "cn")==0)
2783 CanonicalNameTest();
2790 fSuccess
=Shutdown();
2793 printf("Error during Shutdown");
2801 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */