1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sal.hxx"
34 #include <osl/file.hxx>
35 #include <osl/process.h>
37 #include <rtl/alloc.h>
38 #include <rtl/ustring.hxx>
61 rtl::OUString dir_on_server
;
62 rtl::OUString dir_not_exist
;
63 rtl::OUString dir_not_exist_on_server
;
64 rtl::OUString dir_wrong_semantic
;
69 rtl::OUString file_on_server
;
70 rtl::OUString file_not_exist
;
74 void print_error(::rtl::OString
& str
, FileBase::RC rc
);
78 printf("\nPress Return !\n");
82 void printFileName(::rtl::OUString
& str
)
86 aString
= rtl::OUStringToOString( str
, RTL_TEXTENCODING_ASCII_US
);
88 printf( "%s", aString
.getStr() );
93 //--------------------------------------------------
95 //--------------------------------------------------
97 sal_Bool
testLineBreak( sal_Char
*pCount
, sal_uInt64 nLen
, sal_uInt32
*cLineBreak
)
99 sal_Bool fSuccess
=sal_False
;
107 if (nLen
>=1 && *(pCount
+1)==10)
112 if (nLen
>=2 && *(pCount
+2)==10)
117 else if ( *pCount
==10 )
128 sal_Bool
Initialize( void )
131 FileStatus
aStatus( FileStatusMask_All
);
132 rtl_uString
*strExeFileURL
=NULL
;
133 oslProcessError ProcessError
;
135 rtl::OUString iniFileURL
;
137 sal_Unicode
*pExeFileCount
;
141 sal_uInt64 uBytesRequested
;
142 sal_uInt64 uBytesRead
;
147 rtl::OUString dir
[12];
149 // Open to the ini-file
151 ProcessError
=osl_getExecutableFile(&strExeFileURL
);
153 if ( ProcessError
== osl_Process_E_None
)
155 pExeFileCount
=rtl_uString_getStr(strExeFileURL
)+rtl_uString_getLength(strExeFileURL
);
157 // Search for the last slash in the Path
158 while (*pExeFileCount
!=L
'/' && pExeFileCount
>rtl_uString_getStr(strExeFileURL
))
161 // iniFileURL = strExeFileURL without the filename of the exe-File
162 iniFileURL
=rtl::OUString( rtl_uString_getStr(strExeFileURL
) ,(int) (pExeFileCount
-rtl_uString_getStr(strExeFileURL
)) );
164 // add "/testfile.ini" to iniFileURL
165 iniFileURL
+=rtl::OUString::createFromAscii("/testfile.ini");
168 pFile
=new File( iniFileURL
);
169 rc
=pFile
->open( OpenFlag_Read
| OpenFlag_Write
);
170 if ( rc
!=FileBase::E_None
)
172 rtl_uString_release(strExeFileURL
);
178 rtl_uString_release(strExeFileURL
);
182 // Get filesize of the ini-File
184 rc
=DirectoryItem::get( iniFileURL
, aItem
);
185 if ( rc
!=FileBase::E_None
)
188 rc
=aItem
.getFileStatus( aStatus
);
189 if ( rc
!=FileBase::E_None
)
192 uBytesRequested
=aStatus
.getFileSize();
195 rc
=pFile
->setPos( Pos_Absolut
, 0 );
196 pBuffer
=(sal_Char
*) rtl_allocateMemory( (sal_uInt32
) (uBytesRequested
+1)*sizeof(sal_Char
) );
197 rtl_zeroMemory( pBuffer
, (sal_uInt32
)(uBytesRequested
+1)*sizeof(sal_Char
) );
199 rc
=pFile
->read( pBuffer
, uBytesRequested
, uBytesRead
);
200 if ( rc
!=FileBase::E_None
)
207 for ( int i
=0 ; i
<12 ; i
++ )
209 sal_uInt32 cLineBrake
=0;
210 while ( (pCount
-pBuffer
< uBytesRead
) && *pCount
!='=')
216 while ( (pCount
-pBuffer
< uBytesRead
) && !testLineBreak(pCount
,uBytesRead
-(pCount
-pBuffer
), &cLineBrake
))
219 dir
[i
]=rtl::OUString(pBegin
, pCount
-pBegin
, RTL_TEXTENCODING_ASCII_US
);
225 root
=rtl::OUString(dir
[0]);
226 dir1
=rtl::OUString(dir
[1]);
227 dir2
=rtl::OUString(dir
[2]);
228 dir_on_server
=rtl::OUString(dir
[3]);
229 dir_not_exist
=rtl::OUString(dir
[4]);
230 dir_not_exist_on_server
=rtl::OUString(dir
[5]);
231 dir_wrong_semantic
=rtl::OUString(dir
[6]);
233 file1
=rtl::OUString(dir
[7]);
234 file2
=rtl::OUString(dir
[8]);
235 file3
=rtl::OUString(dir
[9]);
236 file_on_server
=rtl::OUString(dir
[10]);
237 file_not_exist
=rtl::OUString(dir
[11]);
239 // close the ini-file
242 rtl_freeMemory( pBuffer
);
245 // Create directories
246 rc
=Directory::create( dir1
);
247 if ( rc
!=FileBase::E_None
)
250 rc
=Directory::create( dir2
);
251 if ( rc
!=FileBase::E_None
)
254 rc
=Directory::create( dir_on_server
);
255 if ( rc
!=FileBase::E_None
)
258 pFile
=new File( file1
);
259 rc
=pFile
->open( OpenFlag_Write
| OpenFlag_Create
);
260 if ( rc
!=FileBase::E_None
)
265 pFile
=new File( file2
);
266 rc
=pFile
->open( OpenFlag_Write
| OpenFlag_Create
);
267 if ( rc
!=FileBase::E_None
)
272 pFile
=new File( file_on_server
);
273 rc
=pFile
->open( OpenFlag_Write
| OpenFlag_Create
);
274 if ( rc
!=FileBase::E_None
)
282 //--------------------------------------------------
284 //--------------------------------------------------
286 sal_Bool
Shutdown( void )
288 sal_Bool fSuccess
=sal_True
;
292 // remove created files
294 pFile
=new File( file1
);
295 rc
=pFile
->remove( file1
);
296 if ( rc
!=FileBase::E_None
)
300 pFile
=new File( file2
);
301 rc
=pFile
->remove( file2
);
302 if ( rc
!=FileBase::E_None
)
306 // remove created directories
308 rc
=Directory::remove( dir1
);
309 if ( rc
!=FileBase::E_None
)
312 rc
=Directory::remove( dir2
);
313 if ( rc
!=FileBase::E_None
)
316 // remove created file on the server
318 pFile
=new File( file_on_server
);
319 rc
=pFile
->remove( file_on_server
);
320 if ( rc
!=FileBase::E_None
)
324 // remove created directory on the server
326 rc
=Directory::remove( dir_on_server
);
327 if ( rc
!=FileBase::E_None
)
333 //--------------------------------------------------
335 //--------------------------------------------------
338 void showFileType( FileStatus::Type aType
)
340 if ( aType
==FileStatus::Directory
)
341 printf( "FileType: Directory \n" );
342 else if ( aType
==FileStatus::Volume
)
343 printf( "FileType: Volume \n" );
344 else if ( aType
==FileStatus::Regular
)
345 printf( "FileType: Regular \n" );
346 else if ( aType
==FileStatus::Unknown
)
347 printf( "FileType: Unknown \n" );
352 void showAttributes( sal_uInt64 uAttributes
)
354 if ( uAttributes
==0 )
355 printf( "No Attributes \n" );
356 if ( uAttributes
& Attribute_ReadOnly
)
357 printf( "Attribute: ReadOnly \n" );
358 if ( uAttributes
& Attribute_Hidden
)
359 printf( "Attribute: Hidden \n" );
360 if ( uAttributes
& Attribute_Executable
)
361 printf( "Attribute: Executable \n");
362 if ( uAttributes
& Attribute_GrpWrite
)
363 printf( "Attribute: GrpWrite \n");
364 if ( uAttributes
& Attribute_GrpRead
)
365 printf( "Attribute: GrpRead \n" );
366 if ( uAttributes
& Attribute_GrpExe
)
367 printf( "Attribute: GrpExe \n" );
368 if ( uAttributes
& Attribute_OwnWrite
)
369 printf( "Attribute: OwnWrite \n");
370 if ( uAttributes
& Attribute_OwnRead
)
371 printf( "Attribute: OwnRead \n" );
372 if ( uAttributes
& Attribute_OwnExe
)
373 printf( "Attribute: OwnExe \n" );
374 if ( uAttributes
& Attribute_OthWrite
)
375 printf( "Attribute: OthWrite \n" );
376 if ( uAttributes
& Attribute_OthRead
)
377 printf( "Attribute: OthRead \n");
378 if ( uAttributes
& Attribute_OthExe
)
379 printf( "Attribute: OthExe \n" );
385 void showTime( TimeValue aTime
)
387 TimeValue aLocalTimeVal
, aSystemTimeVal
, aSysTimeVal
;
388 oslDateTime aDateTime
, aSystemTime
;
390 if ( osl_getLocalTimeFromSystemTime( &aTime
, &aLocalTimeVal
) )
392 if ( osl_getDateTimeFromTimeValue( &aLocalTimeVal
, &aDateTime
) )
394 printf("\t%02i.%02i.%4i , %02i.%02i.%02i Uhr\n", aDateTime
.Day
, aDateTime
.Month
, aDateTime
.Year
, aDateTime
.Hours
, aDateTime
.Minutes
, aDateTime
.Seconds
);
400 if ( osl_getDateTimeFromTimeValue( &aTime
, &aSystemTime
) )
402 printf("SystemTime: \t\t%02i.%02i.%4i , %02i.%02i.%02i Uhr\n", aSystemTime
.Day
, aSystemTime
.Month
, aSystemTime
.Year
, aSystemTime
.Hours
, aSystemTime
.Minutes
, aSystemTime
.Seconds
);
409 if ( osl_getTimeValueFromDateTime( &aSystemTime
, &aSystemTimeVal
) )
411 if ( ( aSystemTimeVal
.Seconds
== aTime
.Seconds
) && ( aSystemTimeVal
.Nanosec
== aTime
.Nanosec
))
412 printf ("Verify : TimeValue : ok! \n");
415 printf ("Verify : TimeValue : Error! \n");
416 printf ("aTime : %u \n", aTime
.Seconds
);
417 printf ("aSystemTimeVal : %u \n", aSystemTimeVal
.Seconds
);
421 printf ("Verify : TimeValue : Error! \n");
424 if ( osl_getSystemTimeFromLocalTime( &aLocalTimeVal
, &aSysTimeVal
) )
426 if ( ( aSysTimeVal
.Seconds
== aTime
.Seconds
) && ( aSysTimeVal
.Nanosec
== aTime
.Nanosec
))
427 printf ("Verify : SystemTime : ok! \n");
430 printf ("Verify : SystemTime : Error! \n");
431 printf ("aTime : %u\n", aTime
.Seconds
);
432 printf ("aSystemTimeVal : %u\n", aSysTimeVal
.Seconds
);
436 printf ("Verify : SystemTime : Error! \n");
441 TimeValue
getSystemTime()
448 aTime
.Seconds
= ltime
;
455 //--------------------------------------------------
456 // DirectoryOpenAndCloseTest
457 //--------------------------------------------------
459 void DirectoryOpenAndCloseTest( void )
465 printf( "--------------------------------------------\n");
466 printf( "Directory-Open-And-Close-Test\n");
467 printf( "--------------------------------------------\n\n");
469 //--------------------------------------------------
470 // open an existing directory
471 //--------------------------------------------------
473 pDir
=new Directory( dir1
);
474 printf( "Open an existing directory: ");
475 printFileName( dir1
);
479 print_error( rtl::OString( "Open Directory" ), rc
);
481 if ( pDir
->isOpen() )
483 print_error( rtl::OString( "Directory is Open" ), rc
);
488 print_error( rtl::OString( "Close Directory" ), rc
);
493 //--------------------------------------------------
494 // open a not existing directory
495 //--------------------------------------------------
497 pDir
=new Directory( dir_not_exist
);
499 printf( "Open a not existing directory: ");
500 printFileName( dir_not_exist
);
505 print_error( rtl::OString( "Open Directory" ), rc
);
511 //--------------------------------------------------
512 // open a directory with a wrong semantic
513 //--------------------------------------------------
514 pDir
=new Directory( dir_wrong_semantic
);
516 printf( "Open a directory with a wrong semantic: ");
517 printFileName( dir_wrong_semantic
);
521 print_error( rtl::OString( "Open Directory" ), rc
);
527 //--------------------------------------------------
528 // open an existing directory on a server
529 //--------------------------------------------------
531 pDir
=new Directory( dir_on_server
);
533 printf( "Open an existing directory on a server: ");
534 printFileName( dir_on_server
);
538 print_error( rtl::OString( "Open Directory" ), rc
);
542 print_error( rtl::OString( "Close Directory" ), rc
);
547 //--------------------------------------------------
548 // open a not existing directory on a server
549 //--------------------------------------------------
551 pDir
=new Directory( dir_not_exist_on_server
);
553 printf( "Open a not existing directory on a server: ");
554 printFileName( dir_not_exist_on_server
);
558 print_error( rtl::OString( "Open Directory" ), rc
);
563 //--------------------------------------------------
564 // Close a not existing directory
565 //--------------------------------------------------
567 pDir
=new Directory( dir_not_exist
);
568 printf( "Close a not existing directory: ");
569 printFileName( dir_not_exist
);
573 print_error( rtl::OString( "Close Directory" ), rc
);
580 //--------------------------------------------------
581 // DirectoryCreateAndRemoveTest
582 //--------------------------------------------------
584 void DirectoryCreateAndRemoveTest( void )
590 printf( "--------------------------------------------\n" );
591 printf( "Directory-Create-And-Remove-Test\n" );
592 printf( "--------------------------------------------\n\n" );
594 //--------------------------------------------------
596 //--------------------------------------------------
597 printf( "Create a not existing directory: ");
598 printFileName( dir_not_exist
);
601 rc
=Directory::create( dir_not_exist
) ;
602 print_error( rtl::OString( "Create Directory" ), rc
);
605 pDir
=new Directory( dir_not_exist
);
608 print_error( rtl::OString( "Verify" ), rc
);
614 //--------------------------------------------------
615 // Create a directory on a server
616 //--------------------------------------------------
618 printf( "Create a not existing directory on a server: ");
619 printFileName( dir_not_exist_on_server
);
622 rc
=Directory::create( dir_not_exist_on_server
);
623 print_error( rtl::OString( "Create Directory" ), rc
);
626 pDir
=new Directory( dir_not_exist_on_server
);
628 print_error( rtl::OString( "Verify" ), rc
);
634 //--------------------------------------------------
635 // Remove Directories
636 //--------------------------------------------------
638 printf( "Remove the created directories: \n" );
640 rc
=Directory::remove( dir_not_exist
);
642 rc1
=Directory::remove( dir_not_exist_on_server
);
644 if ( rc
==FileBase::E_None
&& rc1
==FileBase::E_None
)
645 print_error( rtl::OString( "Remove Directories" ), FileBase::E_None
);
646 else if ( rc
!=FileBase::E_None
)
647 print_error( rtl::OString( "Remove local Directory" ),rc
);
649 print_error( rtl::OString( "Remove Directory on a server" ),rc1
);
653 //--------------------------------------------------
654 // Remove a not existing directory
655 //--------------------------------------------------
657 printf( "Remove a not existing directory: ");
658 printFileName( dir_not_exist
);
661 rc
=Directory::remove( dir_not_exist
);
662 print_error( rtl::OString( "Remove" ),rc
);
668 //--------------------------------------------------
669 // FileOpenAndCloseTest
670 //--------------------------------------------------
672 static void FileOpenAndCloseTest( void )
677 printf( "--------------------------------------------\n" );
678 printf( "File-Open-And-Close-Test\n" );
679 printf( "--------------------------------------------\n\n" );
683 pFile
=new File( file1
);
685 printf( "Open an existing file: ");
686 printFileName( file1
);
689 //--------------------------------------------------
690 // open an existing file (Read)
691 //--------------------------------------------------
693 rc
=pFile
->open( OpenFlag_Read
);
694 print_error( rtl::OString( "Open File (Read)" ), rc
);
696 //--------------------------------------------------
698 //--------------------------------------------------
701 print_error( rtl::OString( "Close File" ), rc
);
705 //--------------------------------------------------
706 // open an existing file (Write)
707 //--------------------------------------------------
709 rc
=pFile
->open( OpenFlag_Write
);
710 print_error( rtl::OString( "Open File (Write)" ), rc
);
712 //--------------------------------------------------
714 //--------------------------------------------------
717 print_error( rtl::OString( "Close File" ), rc
);
721 //--------------------------------------------------
722 // close the file a second time
723 //--------------------------------------------------
726 print_error( rtl::OString( "Close the file a second time" ), rc
);
732 //--------------------------------------------------
733 // FileCreateAndRemoveTest
734 //--------------------------------------------------
736 void FileCreateAndRemoveTest()
741 printf( "--------------------------------------------\n" );
742 printf( "File-Create-And-Remove-Test\n" );
743 printf( "--------------------------------------------\n\n" );
745 pFile
=new File( file_not_exist
);
747 printf( "Create File: ");
748 printFileName( file_not_exist
);
751 //----------------------------------------------------
752 // open (create) a not existing file (Read and write)
753 //----------------------------------------------------
755 rc
= pFile
->open( OpenFlag_Read
| OpenFlag_Write
| osl_File_OpenFlag_Create
);
757 print_error( rtl::OString( "Create and Open File (Read & Write)" ), rc
);
759 //----------------------------------------------------
761 //----------------------------------------------------
764 print_error( rtl::OString( "Close File" ), rc
);
766 //----------------------------------------------------
768 //----------------------------------------------------
770 rc
=pFile
->remove( file_not_exist
);
771 print_error( rtl::OString(" Remove File" ), rc
);
775 //----------------------------------------------------
776 // remove the same file a second time
777 //----------------------------------------------------
778 rc
=pFile
->remove( file_not_exist
);
779 print_error( rtl::OString( "Remove a not existing File" ), rc
);
781 //----------------------------------------------------
782 // remove an open file
783 //----------------------------------------------------
785 pFile
->open( OpenFlag_Read
| OpenFlag_Write
| osl_File_OpenFlag_Create
);
787 rc
=pFile
->remove( file_not_exist
);
788 print_error( rtl::OString( "Remove an open File" ), rc
);
791 pFile
->remove( file_not_exist
);
798 //--------------------------------------------------
799 // FileWriteAndReadTest
800 //--------------------------------------------------
802 void FileWriteAndReadTest( void )
808 sal_Char
*pWriteBuffer
="Hier kommt der Osterhase !";
809 sal_uInt64 nLen
=strlen( pWriteBuffer
);
810 sal_Char
*pReadBuffer
;
812 printf( "--------------------------------------------\n" );
813 printf( "File-Write-And-Read-Test\n" );
814 printf( "--------------------------------------------\n\n" );
818 pFile
=new File( file_not_exist
);
820 printf( "Create File: ");
821 printFileName( file_not_exist
);
824 //----------------------------------------------------
825 // open (create) a not existing file (Read and write)
826 //----------------------------------------------------
828 rc
= pFile
->open( OpenFlag_Read
| OpenFlag_Write
| osl_File_OpenFlag_Create
);
830 print_error( rtl::OString( "Create and Open File (Read & Write)" ), rc
);
834 //----------------------------------------------------
835 // write a string to the file
836 //----------------------------------------------------
837 rc
=pFile
->write( pWriteBuffer
, nLen
, uWritten
);
838 print_error( rtl::OString( "Write File" ), rc
);
841 printf( "Verify: OK! \n" );
843 printf( "Verify: Error\n" );
847 //----------------------------------------------------
848 // move the filepointer to the beginning
849 //----------------------------------------------------
851 rc
=pFile
->setPos( Pos_Absolut
, 0 );
852 print_error( rtl::OString( "Set FilePointer to the beginning of the file" ), rc
);
856 //----------------------------------------------------
858 //----------------------------------------------------
860 pReadBuffer
=(sal_Char
*) rtl_allocateMemory( (sal_uInt32
)(nLen
+1)*sizeof(sal_Char
) );
861 rtl_zeroMemory( pReadBuffer
, (sal_uInt32
)(nLen
+1)*sizeof(sal_Char
) );
862 rc
=pFile
->read( pReadBuffer
, nLen
,uRead
);
863 print_error( rtl::OString( "Read File" ), rc
);
865 if (strcmp(pWriteBuffer
, pReadBuffer
)==0)
867 printf( "Verify: OK !\n" );
868 printf( "Text: %s\n",pReadBuffer
);
871 printf( "Verify: Error\n" );
873 rtl_freeMemory( pReadBuffer
);
879 print_error( rtl::OString( "Close File" ), rc
);
882 rc
=pFile
->remove( file_not_exist
);
883 print_error( rtl::OString( "Remove File" ), rc
);
891 //--------------------------------------------------
893 //--------------------------------------------------
895 void FileCopyAndMoveTest( void )
899 printf( "--------------------------------------------\n" );
900 printf( "File-Copy-Move-Test\n" );
901 printf( "--------------------------------------------\n\n" );
905 rtl::OUString
destPath(dir2
);
907 //--------------------------------------------------
909 //--------------------------------------------------
911 destPath
+=rtl::OUString::createFromAscii("/");
914 printf( "Copy the file ");
915 printFileName( file1
);
917 printFileName( destPath
);
921 rc
=File::copy( file1
, destPath
);
922 print_error( rtl::OString( "FileCopy" ), rc
);
924 pFile
=new File( destPath
);
926 rc
=pFile
->open( OpenFlag_Read
);
927 if ( rc
== FileBase::E_None
)
929 printf( "Verify: OK!\n" );
931 File::remove( destPath
);
934 printf( "Verify: Error!\n" );
940 //--------------------------------------------------
941 // Copy a file to a not existing directory
942 //--------------------------------------------------
944 destPath
=rtl::OUString( dir_not_exist
);
945 destPath
+=rtl::OUString::createFromAscii("/");
948 printf( "Copy a file to a not existing directory \n");
949 printf( "Copy the file %s to %s\n", file1
.getStr(), destPath
.getStr() );
951 rc
=File::copy( file1
, destPath
);
952 print_error( rtl::OString( "FileCopy" ), rc
);
956 //--------------------------------------------------
958 //--------------------------------------------------
960 printf( "Copy the directory: ");
961 printFileName( dir1
);
963 printFileName( dir2
);
966 rc
=File::copy( dir1
, dir2
);
967 print_error( rtl::OString( "FileCopy" ), rc
);
971 //--------------------------------------------------
973 //--------------------------------------------------
975 destPath
=rtl::OUString( dir2
);
976 destPath
+=rtl::OUString::createFromAscii("/");
979 printf( "Move the file ");
980 printFileName( file1
);
982 printFileName( destPath
);
985 rc
=File::move( file1
, destPath
);
986 print_error( rtl::OString( "FileMove" ), rc
);
988 pFile
=new File( destPath
);
990 rc
=pFile
->open( OpenFlag_Read
);
991 if ( rc
==FileBase::E_None
)
996 pFile
=new File( file1
);
998 rc
=pFile
->open( OpenFlag_Read
);
1000 if ( rc
!=FileBase::E_None
)
1002 printf( "Verify: OK!\n" );
1003 File::move( destPath
, file1
);
1007 printf( "Verify: Error!\n" );
1009 File::remove( destPath
);
1013 printf( "Verify: Error!\n" );
1020 //--------------------------------------------------
1021 // Move a file to a not existing directory
1022 //--------------------------------------------------
1024 destPath
=rtl::OUString( dir_not_exist
);
1025 destPath
+=rtl::OUString::createFromAscii("/");
1028 printf( "Move a file to a not existing directory: \n");
1029 printf( "Move the file ");
1030 printFileName( file1
);
1032 printFileName( destPath
);
1035 rc
=File::move( file1
, destPath
);
1036 print_error( rtl::OString( "FileMove" ), rc
);
1040 //--------------------------------------------------
1042 //--------------------------------------------------
1044 printf( "Move a directory: \n");
1046 printf( "Move the directory ");
1047 printFileName( dir1
);
1049 printFileName( dir_not_exist
);
1053 rc
=File::move( dir1
, dir_not_exist
);
1054 print_error( rtl::OString( "FileMove" ), rc
);
1056 if ( rc
== FileBase::E_None
)
1057 File::move( dir_not_exist
, dir1
);
1066 //----------------------------------------------------
1068 //----------------------------------------------------
1070 void FileSizeTest( void )
1073 sal_uInt64 filesize
;
1074 DirectoryItem aItem
;
1076 printf( "--------------------------------------------\n" );
1077 printf( "File-Size-Test\n" );
1078 printf( "--------------------------------------------\n\n" );
1081 File
aFile( file_not_exist
);
1083 printf( "Create File: ");
1084 printFileName( file_not_exist
);
1087 rc
= aFile
.open( OpenFlag_Read
| OpenFlag_Write
| osl_File_OpenFlag_Create
);
1088 print_error( rtl::OString( "Create and Open File (Read & Write)" ), rc
);
1091 if ( rc
== FileBase::E_None
)
1093 //----------------------------------------------------
1094 // Set Filesize to 5000
1095 //----------------------------------------------------
1097 printf( "Set FileSize to 5000\n" );
1098 rc
=aFile
.setSize( 5000 );
1099 print_error( rtl::OString( "Set FileSize" ), rc
);
1102 printf( "Verify:\n" );
1104 //----------------------------------------------------
1105 // Check whether Filesize is set to 5000
1106 //----------------------------------------------------
1108 rc
=DirectoryItem::get( file_not_exist
, aItem
);
1109 print_error( rtl::OString( "Get DirectoryItem" ), rc
);
1111 if ( rc
== FileBase::E_None
)
1113 FileStatus
rStatus( FileStatusMask_FileSize
);
1114 rc
=aItem
.getFileStatus( rStatus
);
1115 print_error( rtl::OString( "Get FileStatus" ), rc
);
1117 if ( rc
== FileBase::E_None
)
1119 filesize
=rStatus
.getFileSize();
1121 if ( filesize
== 5000 )
1122 printf( "\nOK : FileSize: %i\n", filesize
);
1124 printf( "\nError : FileSize: %i\n", filesize
);
1130 //----------------------------------------------------
1131 // Set Filesize to -1
1132 //----------------------------------------------------
1134 printf( "Set FileSize to -1\n" );
1135 rc
=aFile
.setSize( -1 );
1136 print_error( rtl::OString( "Set FileSize" ), rc
);
1142 print_error( rtl::OString( "Close File" ), rc
);
1145 rc
=File::remove( file_not_exist
);
1146 print_error( rtl::OString( "Remove File" ), rc
);
1155 //----------------------------------------------------
1157 //----------------------------------------------------
1159 void FilePointerTest( void )
1162 sal_uInt64 filepointer
;
1164 printf( "--------------------------------------------\n" );
1165 printf( "File-Pointer-Test\n" );
1166 printf( "--------------------------------------------\n\n" );
1169 File
rFile( file_not_exist
);
1171 printf( "Create File: ");
1172 printFileName( file_not_exist
);
1175 rc
= rFile
.open( OpenFlag_Read
| OpenFlag_Write
| osl_File_OpenFlag_Create
);
1176 print_error( rtl::OString( "Create and Open File (Read & Write) "), rc
);
1179 if ( rc
==FileBase::E_None
)
1182 //----------------------------------------------------
1183 // get the position of the filepointer
1184 //----------------------------------------------------
1186 rc
=rFile
.getPos( filepointer
);
1187 print_error( rtl::OString( "GetPos" ), rc
);
1188 printf( "Position of the FilePointer: %i\n", filepointer
);
1192 //----------------------------------------------------
1193 // set the filepointer at the end of a file
1194 //----------------------------------------------------
1196 printf( "Set FileSize to 5000\n" );
1197 rFile
.setSize( 5000 );
1199 printf( "Set the FilePointer at the end of the file (5000)\n" );
1200 rc
=rFile
.setPos( Pos_End
,0 );
1201 print_error( rtl::OString( "SetPos" ), rc
);
1203 rc
=rFile
.getPos( filepointer
);
1205 if ( filepointer
==5000 )
1207 print_error( rtl::OString( "GetPos" ), rc
);
1208 printf( "\nVerify: OK !\n" );
1209 printf( "Filepointer-Position: %llu\n",filepointer
);
1213 print_error( rtl::OString( "GetPos" ), rc
);
1214 printf( "\nFilePointer-Test: Error\n" );
1215 printf( "Filepointer-Position: %i != 5000 \n",filepointer
);
1222 print_error( rtl::OString( "Close File" ), rc
);
1225 rc
=File::remove( file_not_exist
);
1226 print_error( rtl::OString( "Remove File" ), rc
);
1234 //--------------------------------------------------
1235 // FileAttributesTest
1236 //--------------------------------------------------
1238 void verifyFileAttributes( void )
1241 DirectoryItem aItem
;
1242 FileStatus
rStatus( FileStatusMask_Attributes
);
1244 printf( "\nVerify:\n" );
1246 rc
=DirectoryItem::get( file1
, aItem
);
1248 if ( rc
==FileBase::E_None
)
1250 rc
=aItem
.getFileStatus( rStatus
);
1252 if ( rc
==FileBase::E_None
)
1254 sal_uInt64 uAttributes
=rStatus
.getAttributes();
1255 showAttributes(uAttributes
);
1259 print_error( rtl::OString( "Get FileStatus" ), rc
);
1262 print_error( rtl::OString( "Get DirectoryItem" ), rc
);
1268 void FileAttributesTest( void )
1272 printf( "--------------------------------------------\n" );
1273 printf( "File-Attributes-Test\n" );
1274 printf( "--------------------------------------------\n\n" );
1277 printFileName( file1
);
1281 rc
=File::setAttributes( file1
, Attribute_GrpWrite
);
1282 print_error( rtl::OString( "Set Attribute: GrpWrite" ), rc
);
1284 verifyFileAttributes();
1286 rc
=File::setAttributes( file1
, 0 );
1287 if ( rc
!=FileBase::E_None
)
1288 print_error( rtl::OString( "Reset Attributes" ), rc
);
1290 rc
=File::setAttributes( file1
, Attribute_GrpRead
);
1291 print_error( rtl::OString( "Set Attribute: GrpRead" ), rc
);
1293 verifyFileAttributes();
1295 rc
=File::setAttributes( file1
, 0 );
1296 if ( rc
!=FileBase::E_None
)
1297 print_error( rtl::OString( "Reset Attributes" ), rc
);
1299 rc
=File::setAttributes( file1
, Attribute_GrpExe
);
1300 print_error( rtl::OString( "Set Attribute: GrpExe" ), rc
);
1302 verifyFileAttributes();
1304 rc
=File::setAttributes( file1
, 0 );
1305 if ( rc
!=FileBase::E_None
)
1306 print_error( rtl::OString( "Reset Attributes" ), rc
);
1308 rc
=File::setAttributes( file1
, Attribute_OwnWrite
);
1309 print_error( rtl::OString( "Set Attribute: OwnWrite" ), rc
);
1311 verifyFileAttributes();
1313 rc
=File::setAttributes( file1
, 0 );
1314 if ( rc
!=FileBase::E_None
)
1315 print_error( rtl::OString( "Reset Attributes" ), rc
);
1317 rc
=File::setAttributes( file1
, Attribute_OwnRead
);
1318 print_error( rtl::OString( "Set Attribute: OwnRead" ), rc
);
1320 verifyFileAttributes();
1322 rc
=File::setAttributes( file1
, 0 );
1323 if ( rc
!=FileBase::E_None
)
1324 print_error( rtl::OString( "Reset Attributes" ), rc
);
1326 rc
=File::setAttributes( file1
, Attribute_OwnExe
);
1327 print_error( rtl::OString( "Set Attribute: OwnExe" ), rc
);
1329 verifyFileAttributes();
1331 rc
=File::setAttributes( file1
, 0 );
1332 if ( rc
!=FileBase::E_None
)
1333 print_error( rtl::OString( "Reset Attributes" ), rc
);
1335 rc
=File::setAttributes( file1
, Attribute_OthWrite
);
1336 print_error( rtl::OString( "Set Attribute: OthWrite" ), rc
);
1338 verifyFileAttributes();
1340 rc
=File::setAttributes( file1
, 0 );
1341 if ( rc
!=FileBase::E_None
)
1342 print_error( rtl::OString( "Reset Attributes" ), rc
);
1344 rc
=File::setAttributes( file1
, Attribute_OthRead
);
1345 print_error( rtl::OString( "Set Attribute: OthRead" ), rc
);
1347 verifyFileAttributes();
1349 rc
=File::setAttributes( file1
, 0 );
1350 if ( rc
!=FileBase::E_None
)
1351 print_error( rtl::OString( "Reset Attributes" ), rc
);
1353 rc
=File::setAttributes( file1
, Attribute_OthExe
);
1354 print_error( rtl::OString( "Set Attribute: OthExe" ), rc
);
1356 verifyFileAttributes();
1358 rc
=File::setAttributes( file1
, 0 );
1359 if ( rc
!=FileBase::E_None
)
1360 print_error( rtl::OString( "Reset Attributes" ), rc
);
1363 rc
=File::setAttributes( file1
, Attribute_GrpWrite
| Attribute_GrpRead
| Attribute_GrpExe
| Attribute_OwnWrite
| Attribute_OwnRead
| Attribute_OwnExe
| Attribute_OthWrite
| Attribute_OthRead
| Attribute_OthExe
);
1364 print_error( rtl::OString( "Set all Attributes" ), rc
);
1366 verifyFileAttributes();
1375 void FileAttributesTest( void )
1379 printf( "--------------------------------------------\n" );
1380 printf( "File-Attributes-Test\n" );
1381 printf( "--------------------------------------------\n\n" );
1384 printFileName( file1
);
1388 rc
=File::setAttributes( file1
, Attribute_ReadOnly
);
1389 print_error( rtl::OString( "Set Attribute: ReadOnly" ), rc
);
1391 verifyFileAttributes();
1393 rc
=File::setAttributes( file1
, 0 );
1394 print_error( rtl::OString( "Reset Attributes" ), rc
);
1396 verifyFileAttributes();
1398 rc
=File::setAttributes( file1
, Attribute_Hidden
);
1399 print_error( rtl::OString( "Set Attribute: Hidden" ), rc
);
1401 verifyFileAttributes();
1403 rc
=File::setAttributes( file1
, 0 );
1404 print_error( rtl::OString( "Reset Attributes" ), rc
);
1406 verifyFileAttributes();
1408 rc
=File::setAttributes( file1
, Attribute_Hidden
| Attribute_ReadOnly
);
1409 print_error( rtl::OString( "Set Attribute: Hidden & ReadOnly" ), rc
);
1411 verifyFileAttributes();
1413 rc
=File::setAttributes( file1
, 0 );
1414 print_error( rtl::OString( "Reset Attributes") , rc
);
1416 verifyFileAttributes();
1424 //--------------------------------------------------
1426 //--------------------------------------------------
1428 void FileTimeTest( void )
1432 DirectoryItem aItem
;
1434 struct tm sSysCreationTime
= { 0, 20, 12, 4, 9, 100 };
1435 struct tm sSysAccessTime
= { 0, 40, 1, 6, 5, 98 };
1436 struct tm sSysModifyTime
= { 0, 1, 24, 13, 11, 95 };
1438 time_t aSysCreationTime
= mktime( &sSysCreationTime
);
1439 time_t aSysAccessTime
= mktime( &sSysAccessTime
);
1440 time_t aSysModifyTime
= mktime( &sSysModifyTime
);
1442 TimeValue aCreationTime
= { aSysCreationTime
, 0};
1443 TimeValue aAccessTime
= { aSysAccessTime
, 0};
1444 TimeValue aModifyTime
= { aSysModifyTime
, 0};
1446 TimeValue aCreationTimeRead
;
1447 TimeValue aAccessTimeRead
;
1448 TimeValue aModifyTimeRead
;
1451 printf( "--------------------------------------------\n" );
1452 printf( "File-Time-Test\n" );
1453 printf( "--------------------------------------------\n\n" );
1456 printFileName( file1
);
1459 printf( "CreationTime \t : ");
1460 showTime( aCreationTime
);
1462 printf( "\nAccessTime \t : ");
1463 showTime( aAccessTime
);
1465 printf( "\nModifyTime \t : ");
1466 showTime( aModifyTime
);
1468 //--------------------------------------------------
1470 //--------------------------------------------------
1473 rc
=File::setTime( file1
, aCreationTime
, aAccessTime
, aModifyTime
);
1474 print_error( rtl::OString( "SetTime" ), rc
);
1476 //--------------------------------------------------
1478 //--------------------------------------------------
1480 FileStatus
rStatus( FileStatusMask_CreationTime
| FileStatusMask_AccessTime
| FileStatusMask_ModifyTime
);
1482 printf( "\nVerify:\n" );
1484 rc
=DirectoryItem::get( file1
, aItem
);
1485 print_error( rtl::OString( "Get DirectoryItem" ), rc
);
1487 if ( rc
==FileBase::E_None
)
1489 rc
=aItem
.getFileStatus( rStatus
);
1490 print_error( rtl::OString( "Get FileStatus" ), rc
);
1493 if ( rc
==FileBase::E_None
)
1495 //--------------------------------------------------
1497 //--------------------------------------------------
1499 aCreationTimeRead
=rStatus
.getCreationTime();
1501 if ( aCreationTime
.Seconds
== aCreationTimeRead
.Seconds
&& aCreationTime
.Nanosec
== aCreationTimeRead
.Nanosec
)
1502 printf( "GetCreationTime: ok : " );
1504 printf( "GetCreationTime: Error : " );
1506 showTime( aCreationTimeRead
);
1509 //--------------------------------------------------
1511 //--------------------------------------------------
1513 aAccessTimeRead
=rStatus
.getAccessTime();
1515 if ( aAccessTime
.Seconds
== aAccessTimeRead
.Seconds
&& aAccessTime
.Nanosec
== aAccessTimeRead
.Nanosec
)
1516 printf( "GetAccessTime: ok : " );
1518 printf( "GetAccessTime: Error : " );
1520 showTime( aAccessTimeRead
);
1523 //--------------------------------------------------
1525 //--------------------------------------------------
1527 aModifyTimeRead
=rStatus
.getModifyTime();
1529 if ( aModifyTime
.Seconds
== aModifyTimeRead
.Seconds
&& aModifyTime
.Nanosec
== aModifyTimeRead
.Nanosec
)
1530 printf( "GetModifyTime: ok : " );
1532 printf( "GetModifyTime: Error : " );
1534 showTime( aModifyTimeRead
);
1544 //--------------------------------------------------
1545 // DirectoryItemTest
1546 //--------------------------------------------------
1548 void DirectoryItemTest( void )
1552 DirectoryItem aItem
;
1553 FileStatus
*pStatus
;
1556 printf( "--------------------------------------------\n" );
1557 printf( "Directory-Item-Test\n" );
1558 printf( "--------------------------------------------\n\n" );
1560 //--------------------------------------------------
1561 // get DirectoryItem from an existing directory
1562 //--------------------------------------------------
1564 printf( "Get DirectoryItem from an existing Directory: ");
1565 printFileName( dir1
);
1568 rc
=DirectoryItem::get( dir1
, aItem
);
1569 print_error( rtl::OString( "GetDirectoryItem" ), rc
);
1571 pStatus
=new FileStatus( FileStatusMask_All
);
1572 rc
=aItem
.getFileStatus( *pStatus
);
1574 if ( rc
==FileBase::E_None
)
1576 printf( "GetFileStatus: FileURL: ");
1577 printFileName(pStatus
->getFileURL() );
1585 //--------------------------------------------------
1586 // get DirectoryItem from a not existing directory
1587 //--------------------------------------------------
1589 printf( "Get DirectoryItem from a not existing Directory: ");
1590 printFileName( dir_not_exist
);
1593 rc
=DirectoryItem::get( dir_not_exist
, aItem
);
1594 print_error( rtl::OString( "Get DirectoryItem" ), rc
);
1598 //--------------------------------------------------
1599 // get DirectoryItem from an existing file
1600 //--------------------------------------------------
1602 printf( "Get DirectoryItem from an existing File: ");
1603 printFileName( file1
);
1606 rc
=DirectoryItem::get( file1
, aItem
);
1607 print_error( rtl::OString( "GetDirectoryItem" ), rc
);
1609 pStatus
=new FileStatus( FileStatusMask_All
);
1610 rc
=aItem
.getFileStatus( *pStatus
);
1612 if ( rc
==FileBase::E_None
)
1614 printf( "GetFileStatus: FileURL: ");
1615 printFileName( pStatus
->getFileURL() );
1623 //--------------------------------------------------
1624 // get DirectoryItem from a not existing file
1625 //--------------------------------------------------
1627 printf( "Get DirectoryItem from a not existing File: ");
1628 printFileName( file_not_exist
);
1631 rc
=DirectoryItem::get( file_not_exist
, aItem
);
1632 print_error( rtl::OString( "Get DirectoryItem" ), rc
);
1636 //----------------------------------------------------------
1637 // get DirectoryItem from a directory with a wrong semantic
1638 //----------------------------------------------------------
1640 printf( "Get DirectoryItem from a Directory with a wrong semantic: ");
1641 printFileName( dir_not_exist
);
1644 rc
=DirectoryItem::get( dir_wrong_semantic
, aItem
);
1645 print_error( rtl::OString( "Get DirectoryItem" ),rc
);
1649 //---------------------------------------------------
1650 // get DirectoryItem from a file-handle
1651 //--------------------------------------------------
1653 pFile
=new File( file1
);
1655 rc
=pFile
->open( OpenFlag_Read
);
1656 if ( rc
==FileBase::E_None
)
1658 printf( "Get DirectoryItem from a File-Handle: ");
1659 printFileName( file1
);
1662 rc
=DirectoryItem::get( *pFile
, aItem
);
1663 print_error( rtl::OString( "GetDirectoryItem" ), rc
);
1665 pStatus
=new FileStatus( FileStatusMask_All
);
1666 rc
=aItem
.getFileStatus( *pStatus
);
1668 if ( rc
==FileBase::E_None
)
1670 printf( "GetFileStatus: FileURL: ");
1671 printFileName( pStatus
->getFileURL() );
1684 //---------------------------------------------------
1685 // get DirectoryItem from an empty file-handle
1686 //--------------------------------------------------
1688 pFile
=new File( file1
);
1690 printf( "Get DirectoryItem from an empty File-Handle\n" );
1691 rc
=DirectoryItem::get( *pFile
, aItem
);
1692 print_error( rtl::OString( "GetDirectoryItem" ), rc
);
1698 //--------------------------------------------------
1699 // GetNextItem from a directory
1700 //--------------------------------------------------
1702 pDir
=new Directory( dir1
);
1703 printf( "Get next DirectoryItem from a directory: ");
1704 printFileName( dir1
);
1708 print_error( rtl::OString( "Open Directory" ), rc
);
1712 if ( pDir
->isOpen() )
1714 //--------------------------------------------------
1715 // get all files from the directory
1716 //--------------------------------------------------
1719 rtl::OUString str1
[2];
1721 aItem
=DirectoryItem();
1722 rc
=pDir
->getNextItem( aItem
);
1723 print_error( rtl::OString( "GetNextItem" ),rc
);
1725 while( rc
==FileBase::E_None
)
1728 FileStatus
rStatus( FileStatusMask_All
);
1729 aItem
.getFileStatus( rStatus
);
1731 str
=rStatus
.getFileName();
1732 printf( "Filename: ");
1733 printFileName( str
);
1736 aItem
=DirectoryItem();
1737 rc
=pDir
->getNextItem( aItem
);
1738 print_error( rtl::OString( "GetNextItem" ),rc
);
1743 //--------------------------------------------------
1745 //--------------------------------------------------
1747 for (int i
=0; i
<2; i
++)
1749 aItem
=DirectoryItem();
1751 rc
=pDir
->getNextItem( aItem
);
1753 FileStatus
rStatus( FileStatusMask_All
);
1754 aItem
.getFileStatus( rStatus
);
1756 str1
[i
]=rStatus
.getFileName();
1760 if ( str1
[0].compareTo(str1
[1]) == 0 )
1761 print_error( rtl::OString( "Reset" ),FileBase::E_None
);
1763 print_error( rtl::OString( "Reset" ),FileBase::E_invalidError
);
1769 print_error( rtl::OString( "Close Directory" ), rc
);
1774 //--------------------------------------------------
1775 // GetNextItem from a closed directory
1776 //--------------------------------------------------
1778 printf( "Get next DirectoryItem from a closed directory: ");
1779 printFileName( dir1
);
1782 aItem
=DirectoryItem();
1783 rc
=pDir
->getNextItem( aItem
);
1784 print_error( rtl::OString( "GetNextItem" ),rc
);
1792 //--------------------------------------------------
1793 // FileStatusTest (for different types)
1794 //--------------------------------------------------
1796 void FileStatusTest( FileStatus
*pStatus
)
1798 //--------------------------------------------------
1799 // GetFileType of the directory
1800 //--------------------------------------------------
1802 FileStatus::Type aType
;
1804 printf( "\ngetFileType:\n" );
1805 aType
=pStatus
->getFileType();
1806 showFileType( aType
);
1808 //--------------------------------------------------
1810 //--------------------------------------------------
1812 sal_uInt64 uAttributes
;
1814 printf( "\ngetAttributes:\n" );
1815 uAttributes
=pStatus
->getAttributes();
1816 showAttributes( uAttributes
);
1818 //--------------------------------------------------
1820 //--------------------------------------------------
1822 TimeValue aCreationTime
;
1824 printf( "\ngetCreationTime:\n" );
1825 aCreationTime
=pStatus
->getCreationTime();
1827 printf( "CreationTime: " );
1828 showTime( aCreationTime
);
1830 //--------------------------------------------------
1832 //--------------------------------------------------
1834 TimeValue aAccessTime
;
1836 printf( "\ngetAccessTime:\n" );
1837 aAccessTime
=pStatus
->getAccessTime();
1839 printf( "AccessTime: " );
1840 showTime( aAccessTime
);
1842 //--------------------------------------------------
1844 //--------------------------------------------------
1846 TimeValue aModifyTime
;
1848 printf( "\ngetModifyTime:\n" );
1849 aModifyTime
=pStatus
->getModifyTime();
1851 printf( "ModifyTime: " );
1852 showTime( aModifyTime
);
1854 //--------------------------------------------------
1856 //--------------------------------------------------
1858 sal_uInt64 FileSize
;
1860 printf( "\ngetFileSize:\n" );
1862 FileSize
=pStatus
->getFileSize();
1863 printf( "FileSize: %i\n", FileSize
);
1865 //--------------------------------------------------
1867 //--------------------------------------------------
1869 rtl::OUString FileName
;
1871 printf( "\ngetFileName:\n" );
1873 FileName
=pStatus
->getFileName();
1874 printf( "FileName: ");
1875 printFileName( FileName
);
1878 //--------------------------------------------------
1880 //--------------------------------------------------
1882 rtl::OUString FileURL
;
1884 printf( "\ngetFileURL:\n" );
1886 FileURL
=pStatus
->getFileURL();
1887 printf( "FileURL: ");
1888 printFileName( FileURL
);
1891 //--------------------------------------------------
1893 //--------------------------------------------------
1895 rtl::OUString LinkTargetURL
;
1897 printf( "\ngetLinkTargetURL:\n");
1899 LinkTargetURL
=pStatus
->getLinkTargetURL();
1900 printf( "LinkTargetURL: ");
1901 printFileName( LinkTargetURL
);
1907 //--------------------------------------------------
1908 // DirectoryFileStatusTest
1909 //--------------------------------------------------
1911 void DirectoryFileStatusTest( void )
1914 DirectoryItem aItem
;
1915 FileStatus
*pStatus
;
1917 printf( "--------------------------------------------\n" );
1918 printf( "Directory-FileStatus-Test\n" );
1919 printf( "--------------------------------------------\n\n" );
1921 printf( "FileStatus of the directory: ");
1922 printFileName( dir1
);
1925 aItem
=DirectoryItem();
1927 rc
=DirectoryItem::get( dir1
, aItem
);
1928 print_error( rtl::OString( "Get DirectoryItem" ), rc
);
1930 if ( rc
==FileBase::E_None
)
1932 pStatus
=new FileStatus( FileStatusMask_All
);
1933 rc
=aItem
.getFileStatus( *pStatus
);
1935 FileStatusTest( pStatus
);
1946 //--------------------------------------------------
1947 // FileFileStatusTest
1948 //--------------------------------------------------
1950 void FileFileStatusTest( void )
1953 DirectoryItem aItem
;
1954 FileStatus
*pStatus
;
1956 printf( "--------------------------------------------\n" );
1957 printf( "File-FileStatus-Test\n" );
1958 printf( "--------------------------------------------\n\n" );
1960 printf( "FileStatus of the file: ");
1961 printFileName( file1
);
1964 aItem
=DirectoryItem();
1966 rc
=DirectoryItem::get( file1
, aItem
);
1967 print_error( rtl::OString( "Get DirectoryItem" ), rc
);
1969 if ( rc
==FileBase::E_None
)
1971 pStatus
=new FileStatus( FileStatusMask_All
);
1972 rc
=aItem
.getFileStatus( *pStatus
);
1974 FileStatusTest( pStatus
);
1985 //--------------------------------------------------
1986 // VolumeFileStatusTest
1987 //--------------------------------------------------
1989 void VolumeFileStatusTest( void )
1992 DirectoryItem aItem
;
1993 FileStatus
*pStatus
;
1995 printf( "--------------------------------------------\n" );
1996 printf( "Volume-FileStatus-Test\n" );
1997 printf( "--------------------------------------------\n\n" );
1999 printf( "FileStatus of the Volume: ");
2000 printFileName( root
);
2003 aItem
=DirectoryItem();
2005 rc
=DirectoryItem::get( root
, aItem
);
2006 print_error( rtl::OString( "Get DirectoryItem" ), rc
);
2008 if ( rc
==FileBase::E_None
)
2010 pStatus
=new FileStatus( FileStatusMask_All
) ;
2011 rc
=aItem
.getFileStatus( *pStatus
);
2013 FileStatusTest( pStatus
);
2025 //--------------------------------------------------
2027 //--------------------------------------------------
2029 void VolumeInfoTest( void )
2033 printf( "--------------------------------------------\n" );
2034 printf( "Volume-Info-Test\n" );
2035 printf( "--------------------------------------------\n\n" );
2037 printf( "VolumeInfo of the volume ");
2038 printFileName( root
);
2042 VolumeInfo
rInfo( VolumeInfoMask_FreeSpace
);
2043 rc
=Directory::getVolumeInfo( root
, rInfo
);
2044 print_error( rtl::OString( "GetVolumeInfo" ),rc
);
2048 //--------------------------------------------------
2050 //--------------------------------------------------
2052 if ( rInfo
.getRemoteFlag() )
2053 printf( "RemoteFlag: Yes\n" );
2055 printf( "RemoteFlag: No\n" );
2057 //--------------------------------------------------
2058 // getRemoveableFlag
2059 //--------------------------------------------------
2061 if ( rInfo
.getRemoveableFlag() )
2062 printf( "RemoveableFlag: Yes\n" );
2064 printf( "RemoveableFlag: No\n" );
2066 //--------------------------------------------------
2068 //--------------------------------------------------
2070 sal_uInt64 TotalSpace
;
2071 TotalSpace
=rInfo
.getTotalSpace();
2072 printf( "Total Space: %i\n",TotalSpace
);
2074 //--------------------------------------------------
2076 //--------------------------------------------------
2078 sal_uInt64 FreeSpace
;
2079 FreeSpace
=rInfo
.getFreeSpace();
2080 printf( "Free Space: %i\n",FreeSpace
);
2082 //--------------------------------------------------
2084 //--------------------------------------------------
2086 sal_uInt64 UsedSpace
;
2087 UsedSpace
=rInfo
.getUsedSpace();
2088 printf( "Used Space: %i\n",UsedSpace
);
2090 //--------------------------------------------------
2092 //--------------------------------------------------
2094 sal_uInt32 MaxNameLength
;
2095 MaxNameLength
=rInfo
.getMaxNameLength();
2096 printf( "MaxNameLength: %i\n",MaxNameLength
);
2098 //--------------------------------------------------
2100 //--------------------------------------------------
2102 sal_uInt32 MaxPathLength
;
2103 MaxPathLength
=rInfo
.getMaxPathLength();
2104 printf( "MaxPathLength: %i\n",MaxPathLength
);
2106 //--------------------------------------------------
2107 // getFileSystemName
2108 //--------------------------------------------------
2110 rtl::OUString FileSystemName
;
2111 FileSystemName
=rInfo
.getFileSystemName();
2112 printf( "File-System-Name: ");
2113 printFileName( FileSystemName
);
2120 //--------------------------------------------------
2122 //--------------------------------------------------
2124 void ConvertPathTest(rtl::OUString
& strPath
)
2128 rtl::OUString strNormPath
;
2129 rtl::OUString strFileURL
;
2130 rtl::OUString strNormPathFromFileURL
;
2131 rtl::OUString strSystemPath
;
2133 //--------------------------------------------------
2135 //--------------------------------------------------
2137 rc
=FileBase::getFileURLFromSystemPath( strPath
, strNormPath
);
2139 if ( rc
== FileBase::E_None
)
2141 printf( "Normalized Path: \t\t");
2142 printFileName( strNormPath
);
2146 printf( "normalizePath: Error \n" );
2148 //--------------------------------------------------
2149 // getFileURLFromSystemPath
2150 //--------------------------------------------------
2152 if ( strNormPath
.getLength() != 0 )
2154 rc
=FileBase::getFileURLFromSystemPath( strNormPath
, strFileURL
);
2156 if ( rc
== FileBase::E_None
)
2158 printf( "File-URL: \t\t\t");
2159 printFileName( strFileURL
);
2163 printf( "getFileURLFromSystemPath: Error \n" );
2166 printf( "getFileURLFromSystemPath: not tested \n" );
2168 //--------------------------------------------------
2169 // getNormalizedPathFromFileURL
2170 //--------------------------------------------------
2172 if ( strFileURL
.getLength() != 0 )
2174 rc
=FileBase::getSystemPathFromFileURL( strFileURL
, strNormPathFromFileURL
);
2176 if ( rc
== FileBase::E_None
)
2178 printf( "Normalized Path from File-URL: \t");
2179 printFileName( strNormPathFromFileURL
);
2183 printf( "getNormalizedPathFromFileURL: Error \n" );
2186 printf( "getNormalizedPathFromFileURL: not tested \n" );
2189 //--------------------------------------------------
2190 // getSystemPathFromFileURL
2191 //--------------------------------------------------
2193 if ( strNormPath
.getLength() != 0 )
2195 rc
=FileBase::getSystemPathFromFileURL( strNormPath
, strSystemPath
);
2197 if ( rc
== FileBase::E_None
)
2199 printf( "System-Path: \t\t\t");
2200 printFileName( strSystemPath
);
2204 printf( "getSystemPathFromFileURL: Error \n" );
2207 printf( "getSystemPathFromFileURL: not tested \n" );
2209 //--------------------------------------------------
2211 //--------------------------------------------------
2213 if ( strNormPathFromFileURL
== strNormPath
)
2214 printf( "\nVerify: OK ! ( Normalized-Path == Normalized-Path-From-File-URL )\n" );
2216 printf( "\nVerify: Error ! ( Normalized-Path != Normalized-Path-From-File-URL )\n" );
2223 printf( "--------------------------------------------\n" );
2224 printf( "FileBase-Test\n" );
2225 printf( "--------------------------------------------\n\n" );
2227 //--------------------------------------------------
2228 // ConvertPath-Test (Local File)
2229 //--------------------------------------------------
2231 printf( "- Local File: ");
2232 printFileName( file1
);
2235 ConvertPathTest(file1
);
2237 //--------------------------------------------------
2238 // ConvertPath-Test (File on a server)
2239 //--------------------------------------------------
2241 printf( "\n- File on server: ");
2242 printFileName( file_on_server
);
2244 ConvertPathTest(file_on_server
);
2252 //--------------------------------------------------
2254 //--------------------------------------------------
2255 void DoAbsolutePathTest(rtl::OUString strDirBase
, rtl::OUString strRelative
)
2259 rtl::OUString strAbsolute
;
2261 printf( "Base-Directory: \t");
2262 printFileName( strDirBase
);
2264 printf( "Relative-Path: \t\t");
2265 printFileName ( strRelative
);
2268 rc
=FileBase::getAbsoluteFileURL( strDirBase
, strRelative
, strAbsolute
);
2270 if ( rc
== FileBase::E_None
)
2272 printf( "Absolute-Path: \t\t");
2273 printFileName ( strAbsolute
);
2277 printf( "Absolute-Path: Error \n" );
2283 void AbsolutePathTest(void)
2285 printf( "--------------------------------------------\n" );
2286 printf( "AbsolutePath-Test\n" );
2287 printf( "--------------------------------------------\n\n" );
2289 DoAbsolutePathTest(dir1
, rtl::OUString::createFromAscii("."));
2290 DoAbsolutePathTest(dir1
, rtl::OUString::createFromAscii(".."));
2291 DoAbsolutePathTest(dir1
, rtl::OUString::createFromAscii("../.."));
2292 DoAbsolutePathTest(dir1
, rtl::OUString::createFromAscii("../HUHU"));
2294 DoAbsolutePathTest(dir_on_server
, rtl::OUString::createFromAscii("."));
2295 DoAbsolutePathTest(dir_on_server
, rtl::OUString::createFromAscii(".."));
2296 DoAbsolutePathTest(dir_on_server
, rtl::OUString::createFromAscii("../.."));
2297 DoAbsolutePathTest(dir_on_server
, rtl::OUString::createFromAscii("../HUHU"));
2304 //--------------------------------------------------
2306 //--------------------------------------------------
2308 void SearchPathTest(void)
2312 rtl::OUString
strNormPath(file1
);
2313 rtl::OUString strFileURL
;
2314 rtl::OUString strSystemPath
;
2315 rtl::OUString strResultPath
;
2317 printf( "--------------------------------------------\n" );
2318 printf( "SearchPath-Test\n" );
2319 printf( "--------------------------------------------\n\n" );
2322 rc
=FileBase::getFileURLFromSystemPath( strNormPath
, strFileURL
);
2323 print_error( rtl::OString( "getFileURLFromSystemPath" ), rc
);
2324 rc
=FileBase::getSystemPathFromFileURL( strNormPath
, strSystemPath
);
2325 print_error( rtl::OString( "getSystemPathFromFileURL" ), rc
);
2327 //--------------------------------------------------
2328 // searchFileURL (with a normalized path)
2329 //--------------------------------------------------
2331 if ( strNormPath
.getLength() != 0 )
2333 printf( "\nSearch-Normalized-Path (with a normalized path) : ");
2334 printFileName ( strNormPath
);
2337 rc
=FileBase::searchFileURL( strNormPath
, rtl::OUString() , strResultPath
);
2339 if ( rc
== FileBase::E_None
)
2341 printf( "Result: \t\t\t");
2342 printFileName ( strResultPath
);
2346 printf( "searchFileURL (with a normalized path): Error\n" );
2349 printf( "searchFileURL (with a normalized path): not tested\n" );
2351 //--------------------------------------------------
2352 // searchFileURL (with a File-URL)
2353 //--------------------------------------------------
2355 if ( strFileURL
.getLength() != 0 )
2357 printf( "\nSearch-Normalized-Path (with a FileURL) : ");
2358 printFileName( strFileURL
);
2361 rc
=FileBase::searchFileURL( strFileURL
, rtl::OUString() , strResultPath
);
2363 if ( rc
== FileBase::E_None
)
2365 printf( "Result: \t\t\t");
2366 printFileName ( strResultPath
);
2370 printf( "searchFileURL (with a FileURL path): Error\n" );
2373 printf( "searchFileURL (with a FileURL path): not tested\n" );
2375 //--------------------------------------------------
2376 // searchFileURL (with a systempath)
2377 //--------------------------------------------------
2379 if ( strSystemPath
.getLength() != 0 )
2381 printf( "\nSearch-Normalized-Path (with a SystemPath) : ");
2382 printFileName( strSystemPath
);
2385 rc
=FileBase::searchFileURL( strSystemPath
, rtl::OUString() , strResultPath
);
2387 if ( rc
== FileBase::E_None
)
2389 printf( "Result: \t\t\t");
2390 printFileName( strResultPath
);
2394 printf( "searchFileURL (with a systempath): Error\n" );
2397 printf( "searchFileURL (with a systempath): not tested\n" );
2399 //--------------------------------------------------
2400 // searchFileURL (File and no searchpath)
2401 //--------------------------------------------------
2403 printf( "\nsearchFileURL: File (no searchpath) : ");
2404 printFileName( file3
);
2407 rc
=FileBase::searchFileURL( file3
, rtl::OUString::createFromAscii("") , strResultPath
);
2409 if ( rc
== FileBase::E_None
)
2411 printf( "Result: \t\t\t");
2412 printFileName( strResultPath
);
2416 printf( "searchFileURL: File not found: OK ! \n" );
2418 //--------------------------------------------------
2419 // searchFileURL (File and Path)
2420 //--------------------------------------------------
2422 printf( "\nsearchFileURL: File : ");
2423 printFileName( file3
);
2424 printf( "\tSearchPath ");
2425 printFileName( dir1
);
2428 rc
=FileBase::searchFileURL( file3
, dir1
, strResultPath
);
2430 if ( rc
== FileBase::E_None
)
2432 printf( "Result: \t\t\t");
2433 printFileName( strResultPath
);
2437 printf( "searchFileURL: File not found: Error\n" );
2439 //------------------------------------------------------------
2440 // searchFileURL (File and searchpath with two entries)
2441 //------------------------------------------------------------
2443 rtl::OUString
strSearchPath( dir_not_exist
);
2444 strSearchPath
+=rtl::OUString::createFromAscii(";");
2445 strSearchPath
+=dir_on_server
;
2447 printf( "\nsearchFileURL: File : ");
2448 printFileName( file3
);
2449 printf( "SearchPath ");
2450 printFileName( strSearchPath
);
2453 rc
=FileBase::searchFileURL( file3
, strSearchPath
, strResultPath
);
2455 if ( rc
== FileBase::E_None
)
2457 printf( "Result: \t\t\t");
2458 printFileName( strResultPath
);
2462 printf( "searchFileURL: File not found: Error\n" );
2464 //-------------------------------------------------------------------
2465 // searchFileURL (File and searchpath (with a wrong semantic))
2466 //-------------------------------------------------------------------
2468 strSearchPath
=rtl::OUString( dir_wrong_semantic
);
2470 printf( "\nsearchFileURL: File : ");
2471 printFileName( file3
);
2472 printf( "SearchPath ");
2473 printFileName( strSearchPath
);
2476 rc
=FileBase::searchFileURL( file3
, strSearchPath
, strResultPath
);
2478 if ( rc
== FileBase::E_None
)
2479 printf( "Error: Wrong Semantich but no error occurs !\n" );
2481 printf( "searchFileURL: File not found: OK !\n" );
2486 //--------------------------------------------------
2487 // CanonicalNameTest
2488 //--------------------------------------------------
2490 void getCanonicalNameTest(rtl::OUString strPath
)
2494 rtl::OUString strValid
;
2496 printf( "Original-Name: \t\t");
2497 printFileName( strPath
);
2500 rc
=FileBase::getCanonicalName( strPath
, strValid
);
2502 if ( rc
== FileBase::E_None
)
2504 printf( "Canonical-Name: \t");
2505 printFileName( strValid
);
2510 printf( "Canonical-Name: Error \n" );
2516 void CanonicalNameTest(void)
2518 printf( "--------------------------------------------\n" );
2519 printf( "CanonicalName-Test\n" );
2520 printf( "--------------------------------------------\n\n" );
2522 getCanonicalNameTest( dir1
);
2523 getCanonicalNameTest( dir_on_server
);
2524 getCanonicalNameTest( file1
);
2525 getCanonicalNameTest( file_on_server
);
2531 //--------------------------------------------------
2533 //--------------------------------------------------
2535 void print_error( ::rtl::OString
& str
, FileBase::RC rc
)
2538 printf( "%s : ",str
.getStr() );
2541 case FileBase::E_None
:
2544 case FileBase::E_PERM
:
2547 case FileBase::E_NOENT
:
2548 printf("E_NOENT\n");
2550 case FileBase::E_SRCH
:
2553 case FileBase::E_INTR
:
2556 case FileBase::E_IO
:
2559 case FileBase::E_NXIO
:
2562 case FileBase::E_2BIG
:
2565 case FileBase::E_NOEXEC
:
2566 printf("E_NOEXEC\n");
2568 case FileBase::E_BADF
:
2571 case FileBase::E_CHILD
:
2572 printf("E_CHILD\n");
2574 case FileBase::E_AGAIN
:
2575 printf("E_AGAIN\n");
2577 case FileBase::E_NOMEM
:
2578 printf("E_NOMEM\n");
2580 case FileBase::E_ACCES
:
2581 printf("E_ACCES\n");
2583 case FileBase::E_FAULT
:
2584 printf("E_FAULT\n");
2586 case FileBase::E_BUSY
:
2589 case FileBase::E_EXIST
:
2590 printf("E_EXIST\n");
2592 case FileBase::E_XDEV
:
2595 case FileBase::E_NODEV
:
2596 printf("E_NODEV\n");
2598 case FileBase::E_NOTDIR
:
2599 printf("E_NOTDIR\n");
2601 case FileBase::E_ISDIR
:
2602 printf("E_ISDIR\n");
2604 case FileBase::E_INVAL
:
2605 printf("E_INVAL\n");
2607 case FileBase::E_NFILE
:
2608 printf("E_NFILE\n");
2610 case FileBase::E_MFILE
:
2611 printf("E_MFILE\n");
2613 case FileBase::E_NOTTY
:
2614 printf("E_NOTTY\n");
2616 case FileBase::E_FBIG
:
2619 case FileBase::E_NOSPC
:
2620 printf("E_NOSPC\n");
2622 case FileBase::E_SPIPE
:
2623 printf("E_SPIPE\n");
2625 case FileBase::E_ROFS
:
2628 case FileBase::E_MLINK
:
2629 printf("E_MLINK\n");
2631 case FileBase::E_PIPE
:
2634 case FileBase::E_DOM
:
2637 case FileBase::E_RANGE
:
2638 printf("E_RANGE\n");
2640 case FileBase::E_DEADLK
:
2641 printf("E_DEADLK\n");
2643 case FileBase::E_NAMETOOLONG
:
2644 printf("E_NAMETOOLONG\n");
2646 case FileBase::E_NOLCK
:
2647 printf("E_NOLCK\n");
2649 case FileBase::E_NOSYS
:
2650 printf("E_NOSYS\n");
2652 case FileBase::E_NOTEMPTY
:
2653 printf("E_NOTEMPTY\n");
2655 case FileBase::E_LOOP
:
2658 case FileBase::E_ILSEQ
:
2659 printf("E_ILSEQ\n");
2661 case FileBase::E_NOLINK
:
2662 printf("E_NOLINK\n");
2664 case FileBase::E_MULTIHOP
:
2665 printf("E_MULTIHOP\n");
2667 case FileBase::E_USERS
:
2668 printf("E_USERS\n");
2670 case FileBase::E_OVERFLOW
:
2671 printf("E_OVERFLOW\n");
2674 printf("E_Unknown\n");
2680 //--------------------------------------------------
2682 //--------------------------------------------------
2684 #define MAIN _cdecl main
2689 int MAIN( int argc
, char* argv
[] )
2691 sal_Bool fSuccess
=sal_False
;
2694 fSuccess
=Initialize();
2697 printf("Error during Initialization");
2704 DirectoryOpenAndCloseTest();
2705 DirectoryCreateAndRemoveTest();
2707 FileOpenAndCloseTest();
2708 FileCreateAndRemoveTest();
2709 FileWriteAndReadTest();
2710 FileCopyAndMoveTest();
2713 FileAttributesTest();
2715 DirectoryItemTest();
2716 DirectoryFileStatusTest();
2717 VolumeFileStatusTest();
2718 FileFileStatusTest();
2723 CanonicalNameTest();
2725 // command line arguments ?
2732 if (strcmp(argv
[i
], "doc")==0)
2733 DirectoryOpenAndCloseTest();
2734 else if (strcmp(argv
[i
], "dcr")==0)
2735 DirectoryCreateAndRemoveTest();
2736 else if (strcmp(argv
[i
], "foc")==0)
2737 FileOpenAndCloseTest();
2738 else if (strcmp(argv
[i
], "fcr")==0)
2739 FileCreateAndRemoveTest();
2740 else if (strcmp(argv
[i
], "fwr")==0)
2741 FileWriteAndReadTest();
2742 else if (strcmp(argv
[i
], "fcm")==0)
2743 FileCopyAndMoveTest();
2744 else if (strcmp(argv
[i
], "fs")==0)
2746 else if (strcmp(argv
[i
], "fp")==0)
2748 else if (strcmp(argv
[i
], "fa")==0)
2749 FileAttributesTest();
2750 else if (strcmp(argv
[i
], "ft")==0)
2752 else if (strcmp(argv
[i
], "di")==0)
2753 DirectoryItemTest();
2754 else if (strcmp(argv
[i
], "dfs")==0)
2755 DirectoryFileStatusTest();
2756 else if (strcmp(argv
[i
], "vfs")==0)
2757 VolumeFileStatusTest();
2758 else if (strcmp(argv
[i
], "ffs")==0)
2759 FileFileStatusTest();
2760 else if (strcmp(argv
[i
], "vi")==0)
2762 else if (strcmp(argv
[i
], "fb")==0)
2764 else if (strcmp(argv
[i
], "sp")==0)
2766 else if (strcmp(argv
[i
], "ap")==0)
2768 else if (strcmp(argv
[i
], "cn")==0)
2769 CanonicalNameTest();
2776 fSuccess
=Shutdown();
2779 printf("Error during Shutdown");