1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
24 #include <osl/file.hxx>
25 #include <osl/process.h>
27 #include <rtl/alloc.h>
28 #include <rtl/ustring.hxx>
49 rtl::OUString dir_on_server
;
50 rtl::OUString dir_not_exist
;
51 rtl::OUString dir_not_exist_on_server
;
52 rtl::OUString dir_wrong_semantic
;
57 rtl::OUString file_on_server
;
58 rtl::OUString file_not_exist
;
62 void print_error(const ::rtl::OString
& str
, FileBase::RC rc
);
66 printf("\nPress Return !\n");
70 void printFileName(const ::rtl::OUString
& str
)
74 aString
= rtl::OUStringToOString( str
, RTL_TEXTENCODING_ASCII_US
);
76 printf( "%s", aString
.getStr() );
81 //--------------------------------------------------
83 //--------------------------------------------------
85 sal_Bool
testLineBreak( sal_Char
*pCount
, sal_uInt64 nLen
, sal_uInt32
*cLineBreak
)
87 sal_Bool fSuccess
=sal_False
;
95 if (nLen
>=1 && *(pCount
+1)==10)
100 if (nLen
>=2 && *(pCount
+2)==10)
105 else if ( *pCount
==10 )
116 sal_Bool
Initialize( void )
119 FileStatus
aStatus( osl_FileStatus_Mask_All
);
120 rtl_uString
*strExeFileURL
=NULL
;
121 oslProcessError ProcessError
;
123 rtl::OUString iniFileURL
;
125 sal_Unicode
*pExeFileCount
;
129 sal_uInt64 uBytesRequested
;
130 sal_uInt64 uBytesRead
;
135 rtl::OUString dir
[12];
137 // Open to the ini-file
139 ProcessError
=osl_getExecutableFile(&strExeFileURL
);
141 if ( ProcessError
== osl_Process_E_None
)
143 pExeFileCount
=rtl_uString_getStr(strExeFileURL
)+rtl_uString_getLength(strExeFileURL
);
145 // Search for the last slash in the Path
146 while (*pExeFileCount
!=L
'/' && pExeFileCount
>rtl_uString_getStr(strExeFileURL
))
149 // iniFileURL = strExeFileURL without the filename of the exe-File
150 iniFileURL
=rtl::OUString( rtl_uString_getStr(strExeFileURL
) ,(int) (pExeFileCount
-rtl_uString_getStr(strExeFileURL
)) );
152 // add "/testfile.ini" to iniFileURL
153 iniFileURL
+=rtl::OUString("/testfile.ini");
156 pFile
=new File( iniFileURL
);
157 rc
=pFile
->open( osl_File_OpenFlag_Read
| osl_File_OpenFlag_Write
);
158 if ( rc
!=FileBase::E_None
)
160 rtl_uString_release(strExeFileURL
);
166 rtl_uString_release(strExeFileURL
);
170 // Get filesize of the ini-File
172 rc
=DirectoryItem::get( iniFileURL
, aItem
);
173 if ( rc
!=FileBase::E_None
)
176 rc
=aItem
.getFileStatus( aStatus
);
177 if ( rc
!=FileBase::E_None
)
180 uBytesRequested
=aStatus
.getFileSize();
183 rc
=pFile
->setPos( osl_Pos_Absolut
, 0 );
184 pBuffer
=(sal_Char
*) rtl_allocateMemory( (sal_uInt32
) (uBytesRequested
+1)*sizeof(sal_Char
) );
185 memset( pBuffer
, 0, (sal_uInt32
)(uBytesRequested
+1)*sizeof(sal_Char
) );
187 rc
=pFile
->read( pBuffer
, uBytesRequested
, uBytesRead
);
188 if ( rc
!=FileBase::E_None
)
195 for ( int i
=0 ; i
<12 ; i
++ )
197 sal_uInt32 cLineBrake
=0;
198 while ( (static_cast<sal_uInt64
>(pCount
-pBuffer
) < uBytesRead
) && *pCount
!='=')
204 while ( (static_cast<sal_uInt64
>(pCount
-pBuffer
) < uBytesRead
) && !testLineBreak(pCount
,uBytesRead
-(pCount
-pBuffer
), &cLineBrake
))
207 dir
[i
]=rtl::OUString(pBegin
, pCount
-pBegin
, RTL_TEXTENCODING_ASCII_US
);
213 root
=rtl::OUString(dir
[0]);
214 dir1
=rtl::OUString(dir
[1]);
215 dir2
=rtl::OUString(dir
[2]);
216 dir_on_server
=rtl::OUString(dir
[3]);
217 dir_not_exist
=rtl::OUString(dir
[4]);
218 dir_not_exist_on_server
=rtl::OUString(dir
[5]);
219 dir_wrong_semantic
=rtl::OUString(dir
[6]);
221 file1
=rtl::OUString(dir
[7]);
222 file2
=rtl::OUString(dir
[8]);
223 file3
=rtl::OUString(dir
[9]);
224 file_on_server
=rtl::OUString(dir
[10]);
225 file_not_exist
=rtl::OUString(dir
[11]);
227 // close the ini-file
230 rtl_freeMemory( pBuffer
);
233 // Create directories
234 rc
=Directory::create( dir1
);
235 if ( rc
!=FileBase::E_None
)
238 rc
=Directory::create( dir2
);
239 if ( rc
!=FileBase::E_None
)
242 rc
=Directory::create( dir_on_server
);
243 if ( rc
!=FileBase::E_None
)
246 pFile
=new File( file1
);
247 rc
=pFile
->open( osl_File_OpenFlag_Write
| osl_File_OpenFlag_Create
);
248 if ( rc
!=FileBase::E_None
)
253 pFile
=new File( file2
);
254 rc
=pFile
->open( osl_File_OpenFlag_Write
| osl_File_OpenFlag_Create
);
255 if ( rc
!=FileBase::E_None
)
260 pFile
=new File( file_on_server
);
261 rc
=pFile
->open( osl_File_OpenFlag_Write
| osl_File_OpenFlag_Create
);
262 if ( rc
!=FileBase::E_None
)
270 //--------------------------------------------------
272 //--------------------------------------------------
274 sal_Bool
Shutdown( void )
276 sal_Bool fSuccess
=sal_True
;
280 // remove created files
282 pFile
=new File( file1
);
283 rc
=pFile
->remove( file1
);
284 if ( rc
!=FileBase::E_None
)
288 pFile
=new File( file2
);
289 rc
=pFile
->remove( file2
);
290 if ( rc
!=FileBase::E_None
)
294 // remove created directories
296 rc
=Directory::remove( dir1
);
297 if ( rc
!=FileBase::E_None
)
300 rc
=Directory::remove( dir2
);
301 if ( rc
!=FileBase::E_None
)
304 // remove created file on the server
306 pFile
=new File( file_on_server
);
307 rc
=pFile
->remove( file_on_server
);
308 if ( rc
!=FileBase::E_None
)
312 // remove created directory on the server
314 rc
=Directory::remove( dir_on_server
);
315 if ( rc
!=FileBase::E_None
)
321 //--------------------------------------------------
323 //--------------------------------------------------
326 void showFileType( FileStatus::Type aType
)
328 if ( aType
==FileStatus::Directory
)
329 printf( "FileType: Directory \n" );
330 else if ( aType
==FileStatus::Volume
)
331 printf( "FileType: Volume \n" );
332 else if ( aType
==FileStatus::Regular
)
333 printf( "FileType: Regular \n" );
334 else if ( aType
==FileStatus::Unknown
)
335 printf( "FileType: Unknown \n" );
340 void showAttributes( sal_uInt64 uAttributes
)
342 if ( uAttributes
==0 )
343 printf( "No Attributes \n" );
344 if ( uAttributes
& osl_File_Attribute_ReadOnly
)
345 printf( "Attribute: ReadOnly \n" );
346 if ( uAttributes
& osl_File_Attribute_Hidden
)
347 printf( "Attribute: Hidden \n" );
348 if ( uAttributes
& osl_File_Attribute_Executable
)
349 printf( "Attribute: Executable \n");
350 if ( uAttributes
& osl_File_Attribute_GrpWrite
)
351 printf( "Attribute: GrpWrite \n");
352 if ( uAttributes
& osl_File_Attribute_GrpRead
)
353 printf( "Attribute: GrpRead \n" );
354 if ( uAttributes
& osl_File_Attribute_GrpExe
)
355 printf( "Attribute: GrpExe \n" );
356 if ( uAttributes
& osl_File_Attribute_OwnWrite
)
357 printf( "Attribute: OwnWrite \n");
358 if ( uAttributes
& osl_File_Attribute_OwnRead
)
359 printf( "Attribute: OwnRead \n" );
360 if ( uAttributes
& osl_File_Attribute_OwnExe
)
361 printf( "Attribute: OwnExe \n" );
362 if ( uAttributes
& osl_File_Attribute_OthWrite
)
363 printf( "Attribute: OthWrite \n" );
364 if ( uAttributes
& osl_File_Attribute_OthRead
)
365 printf( "Attribute: OthRead \n");
366 if ( uAttributes
& osl_File_Attribute_OthExe
)
367 printf( "Attribute: OthExe \n" );
373 void showTime( TimeValue aTime
)
375 TimeValue aLocalTimeVal
, aSystemTimeVal
, aSysTimeVal
;
376 oslDateTime aDateTime
, aSystemTime
;
378 if ( osl_getLocalTimeFromSystemTime( &aTime
, &aLocalTimeVal
) )
380 if ( osl_getDateTimeFromTimeValue( &aLocalTimeVal
, &aDateTime
) )
382 printf("\t%02i.%02i.%4i , %02i.%02i.%02i Uhr\n", aDateTime
.Day
, aDateTime
.Month
, aDateTime
.Year
, aDateTime
.Hours
, aDateTime
.Minutes
, aDateTime
.Seconds
);
388 if ( osl_getDateTimeFromTimeValue( &aTime
, &aSystemTime
) )
390 printf("SystemTime: \t\t%02i.%02i.%4i , %02i.%02i.%02i Uhr\n", aSystemTime
.Day
, aSystemTime
.Month
, aSystemTime
.Year
, aSystemTime
.Hours
, aSystemTime
.Minutes
, aSystemTime
.Seconds
);
397 if ( osl_getTimeValueFromDateTime( &aSystemTime
, &aSystemTimeVal
) )
399 if ( ( aSystemTimeVal
.Seconds
== aTime
.Seconds
) && ( aSystemTimeVal
.Nanosec
== aTime
.Nanosec
))
400 printf ("Verify : TimeValue : ok! \n");
403 printf ("Verify : TimeValue : Error! \n");
404 printf ("aTime : %u \n", aTime
.Seconds
);
405 printf ("aSystemTimeVal : %u \n", aSystemTimeVal
.Seconds
);
409 printf ("Verify : TimeValue : Error! \n");
412 if ( osl_getSystemTimeFromLocalTime( &aLocalTimeVal
, &aSysTimeVal
) )
414 if ( ( aSysTimeVal
.Seconds
== aTime
.Seconds
) && ( aSysTimeVal
.Nanosec
== aTime
.Nanosec
))
415 printf ("Verify : SystemTime : ok! \n");
418 printf ("Verify : SystemTime : Error! \n");
419 printf ("aTime : %u\n", aTime
.Seconds
);
420 printf ("aSystemTimeVal : %u\n", aSysTimeVal
.Seconds
);
424 printf ("Verify : SystemTime : Error! \n");
429 TimeValue
getSystemTime()
436 aTime
.Seconds
= ltime
;
443 //--------------------------------------------------
444 // DirectoryOpenAndCloseTest
445 //--------------------------------------------------
447 void DirectoryOpenAndCloseTest( void )
452 printf( "--------------------------------------------\n");
453 printf( "Directory-Open-And-Close-Test\n");
454 printf( "--------------------------------------------\n\n");
456 //--------------------------------------------------
457 // open an existing directory
458 //--------------------------------------------------
460 pDir
=new Directory( dir1
);
461 printf( "Open an existing directory: ");
462 printFileName( dir1
);
466 print_error( rtl::OString( "Open Directory" ), rc
);
468 if ( pDir
->isOpen() )
470 print_error( rtl::OString( "Directory is Open" ), rc
);
475 print_error( rtl::OString( "Close Directory" ), rc
);
480 //--------------------------------------------------
481 // open a not existing directory
482 //--------------------------------------------------
484 pDir
=new Directory( dir_not_exist
);
486 printf( "Open a not existing directory: ");
487 printFileName( dir_not_exist
);
492 print_error( rtl::OString( "Open Directory" ), rc
);
498 //--------------------------------------------------
499 // open a directory with a wrong semantic
500 //--------------------------------------------------
501 pDir
=new Directory( dir_wrong_semantic
);
503 printf( "Open a directory with a wrong semantic: ");
504 printFileName( dir_wrong_semantic
);
508 print_error( rtl::OString( "Open Directory" ), rc
);
514 //--------------------------------------------------
515 // open an existing directory on a server
516 //--------------------------------------------------
518 pDir
=new Directory( dir_on_server
);
520 printf( "Open an existing directory on a server: ");
521 printFileName( dir_on_server
);
525 print_error( rtl::OString( "Open Directory" ), rc
);
529 print_error( rtl::OString( "Close Directory" ), rc
);
534 //--------------------------------------------------
535 // open a not existing directory on a server
536 //--------------------------------------------------
538 pDir
=new Directory( dir_not_exist_on_server
);
540 printf( "Open a not existing directory on a server: ");
541 printFileName( dir_not_exist_on_server
);
545 print_error( rtl::OString( "Open Directory" ), rc
);
550 //--------------------------------------------------
551 // Close a not existing directory
552 //--------------------------------------------------
554 pDir
=new Directory( dir_not_exist
);
555 printf( "Close a not existing directory: ");
556 printFileName( dir_not_exist
);
560 print_error( rtl::OString( "Close Directory" ), rc
);
567 //--------------------------------------------------
568 // DirectoryCreateAndRemoveTest
569 //--------------------------------------------------
571 void DirectoryCreateAndRemoveTest( void )
576 printf( "--------------------------------------------\n" );
577 printf( "Directory-Create-And-Remove-Test\n" );
578 printf( "--------------------------------------------\n\n" );
580 //--------------------------------------------------
582 //--------------------------------------------------
583 printf( "Create a not existing directory: ");
584 printFileName( dir_not_exist
);
587 rc
=Directory::create( dir_not_exist
) ;
588 print_error( rtl::OString( "Create Directory" ), rc
);
591 pDir
=new Directory( dir_not_exist
);
594 print_error( rtl::OString( "Verify" ), rc
);
600 //--------------------------------------------------
601 // Create a directory on a server
602 //--------------------------------------------------
604 printf( "Create a not existing directory on a server: ");
605 printFileName( dir_not_exist_on_server
);
608 rc
=Directory::create( dir_not_exist_on_server
);
609 print_error( rtl::OString( "Create Directory" ), rc
);
612 pDir
=new Directory( dir_not_exist_on_server
);
614 print_error( rtl::OString( "Verify" ), rc
);
620 //--------------------------------------------------
621 // Remove Directories
622 //--------------------------------------------------
624 printf( "Remove the created directories: \n" );
626 rc
=Directory::remove( dir_not_exist
);
628 rc1
=Directory::remove( dir_not_exist_on_server
);
630 if ( rc
==FileBase::E_None
&& rc1
==FileBase::E_None
)
631 print_error( rtl::OString( "Remove Directories" ), FileBase::E_None
);
632 else if ( rc
!=FileBase::E_None
)
633 print_error( rtl::OString( "Remove local Directory" ),rc
);
635 print_error( rtl::OString( "Remove Directory on a server" ),rc1
);
639 //--------------------------------------------------
640 // Remove a not existing directory
641 //--------------------------------------------------
643 printf( "Remove a not existing directory: ");
644 printFileName( dir_not_exist
);
647 rc
=Directory::remove( dir_not_exist
);
648 print_error( rtl::OString( "Remove" ),rc
);
654 //--------------------------------------------------
655 // FileOpenAndCloseTest
656 //--------------------------------------------------
658 static void FileOpenAndCloseTest( void )
662 printf( "--------------------------------------------\n" );
663 printf( "File-Open-And-Close-Test\n" );
664 printf( "--------------------------------------------\n\n" );
668 pFile
=new File( file1
);
670 printf( "Open an existing file: ");
671 printFileName( file1
);
674 //--------------------------------------------------
675 // open an existing file (Read)
676 //--------------------------------------------------
678 rc
=pFile
->open( osl_File_OpenFlag_Read
);
679 print_error( rtl::OString( "Open File (Read)" ), rc
);
681 //--------------------------------------------------
683 //--------------------------------------------------
686 print_error( rtl::OString( "Close File" ), rc
);
690 //--------------------------------------------------
691 // open an existing file (Write)
692 //--------------------------------------------------
694 rc
=pFile
->open( osl_File_OpenFlag_Write
);
695 print_error( rtl::OString( "Open File (Write)" ), rc
);
697 //--------------------------------------------------
699 //--------------------------------------------------
702 print_error( rtl::OString( "Close File" ), rc
);
706 //--------------------------------------------------
707 // close the file a second time
708 //--------------------------------------------------
711 print_error( rtl::OString( "Close the file a second time" ), rc
);
717 //--------------------------------------------------
718 // FileCreateAndRemoveTest
719 //--------------------------------------------------
721 void FileCreateAndRemoveTest()
726 printf( "--------------------------------------------\n" );
727 printf( "File-Create-And-Remove-Test\n" );
728 printf( "--------------------------------------------\n\n" );
730 pFile
=new File( file_not_exist
);
732 printf( "Create File: ");
733 printFileName( file_not_exist
);
736 //----------------------------------------------------
737 // open (create) a not existing file (Read and write)
738 //----------------------------------------------------
740 rc
= pFile
->open( osl_File_OpenFlag_Read
| osl_File_OpenFlag_Write
| osl_File_OpenFlag_Create
);
742 print_error( rtl::OString( "Create and Open File (Read & Write)" ), rc
);
744 //----------------------------------------------------
746 //----------------------------------------------------
749 print_error( rtl::OString( "Close File" ), rc
);
751 //----------------------------------------------------
753 //----------------------------------------------------
755 rc
=pFile
->remove( file_not_exist
);
756 print_error( rtl::OString(" Remove File" ), rc
);
760 //----------------------------------------------------
761 // remove the same file a second time
762 //----------------------------------------------------
763 rc
=pFile
->remove( file_not_exist
);
764 print_error( rtl::OString( "Remove a not existing File" ), rc
);
766 //----------------------------------------------------
767 // remove an open file
768 //----------------------------------------------------
770 pFile
->open( osl_File_OpenFlag_Read
| osl_File_OpenFlag_Write
| osl_File_OpenFlag_Create
);
772 rc
=pFile
->remove( file_not_exist
);
773 print_error( rtl::OString( "Remove an open File" ), rc
);
776 pFile
->remove( file_not_exist
);
783 //--------------------------------------------------
784 // FileWriteAndReadTest
785 //--------------------------------------------------
787 void FileWriteAndReadTest( void )
793 const sal_Char
*pWriteBuffer
="Hier kommt der Osterhase !";
794 sal_uInt64 nLen
=strlen( pWriteBuffer
);
795 sal_Char
*pReadBuffer
;
797 printf( "--------------------------------------------\n" );
798 printf( "File-Write-And-Read-Test\n" );
799 printf( "--------------------------------------------\n\n" );
803 pFile
=new File( file_not_exist
);
805 printf( "Create File: ");
806 printFileName( file_not_exist
);
809 //----------------------------------------------------
810 // open (create) a not existing file (Read and write)
811 //----------------------------------------------------
813 rc
= pFile
->open( osl_File_OpenFlag_Read
| osl_File_OpenFlag_Write
| osl_File_OpenFlag_Create
);
815 print_error( rtl::OString( "Create and Open File (Read & Write)" ), rc
);
819 //----------------------------------------------------
820 // write a string to the file
821 //----------------------------------------------------
822 rc
=pFile
->write( pWriteBuffer
, nLen
, uWritten
);
823 print_error( rtl::OString( "Write File" ), rc
);
826 printf( "Verify: OK! \n" );
828 printf( "Verify: Error\n" );
832 //----------------------------------------------------
833 // move the filepointer to the beginning
834 //----------------------------------------------------
836 rc
=pFile
->setPos( osl_Pos_Absolut
, 0 );
837 print_error( rtl::OString( "Set FilePointer to the beginning of the file" ), rc
);
841 //----------------------------------------------------
843 //----------------------------------------------------
845 pReadBuffer
=(sal_Char
*) rtl_allocateMemory( (sal_uInt32
)(nLen
+1)*sizeof(sal_Char
) );
846 memset( pReadBuffer
, 0, (sal_uInt32
)(nLen
+1)*sizeof(sal_Char
) );
847 rc
=pFile
->read( pReadBuffer
, nLen
,uRead
);
848 print_error( rtl::OString( "Read File" ), rc
);
850 if (strcmp(pWriteBuffer
, pReadBuffer
)==0)
852 printf( "Verify: OK !\n" );
853 printf( "Text: %s\n",pReadBuffer
);
856 printf( "Verify: Error\n" );
858 rtl_freeMemory( pReadBuffer
);
864 print_error( rtl::OString( "Close File" ), rc
);
867 rc
=pFile
->remove( file_not_exist
);
868 print_error( rtl::OString( "Remove File" ), rc
);
876 //--------------------------------------------------
878 //--------------------------------------------------
880 void FileCopyAndMoveTest( void )
884 printf( "--------------------------------------------\n" );
885 printf( "File-Copy-Move-Test\n" );
886 printf( "--------------------------------------------\n\n" );
890 rtl::OUString
destPath(dir2
);
892 //--------------------------------------------------
894 //--------------------------------------------------
896 destPath
+=rtl::OUString("/");
899 printf( "Copy the file ");
900 printFileName( file1
);
902 printFileName( destPath
);
906 rc
=File::copy( file1
, destPath
);
907 print_error( rtl::OString( "FileCopy" ), rc
);
909 pFile
=new File( destPath
);
911 rc
=pFile
->open( osl_File_OpenFlag_Read
);
912 if ( rc
== FileBase::E_None
)
914 printf( "Verify: OK!\n" );
916 File::remove( destPath
);
919 printf( "Verify: Error!\n" );
925 //--------------------------------------------------
926 // Copy a file to a not existing directory
927 //--------------------------------------------------
929 destPath
=rtl::OUString( dir_not_exist
);
930 destPath
+=rtl::OUString("/");
933 printf( "Copy a file to a not existing directory \n");
934 printf( "Copy the file %s to %s\n",
935 rtl::OUStringToOString( file1
, RTL_TEXTENCODING_ASCII_US
).getStr(),
936 rtl::OUStringToOString( destPath
, RTL_TEXTENCODING_ASCII_US
).getStr() );
938 rc
=File::copy( file1
, destPath
);
939 print_error( rtl::OString( "FileCopy" ), rc
);
943 //--------------------------------------------------
945 //--------------------------------------------------
947 printf( "Copy the directory: ");
948 printFileName( dir1
);
950 printFileName( dir2
);
953 rc
=File::copy( dir1
, dir2
);
954 print_error( rtl::OString( "FileCopy" ), rc
);
958 //--------------------------------------------------
960 //--------------------------------------------------
962 destPath
=rtl::OUString( dir2
);
963 destPath
+=rtl::OUString("/");
966 printf( "Move the file ");
967 printFileName( file1
);
969 printFileName( destPath
);
972 rc
=File::move( file1
, destPath
);
973 print_error( rtl::OString( "FileMove" ), rc
);
975 pFile
=new File( destPath
);
977 rc
=pFile
->open( osl_File_OpenFlag_Read
);
978 if ( rc
==FileBase::E_None
)
983 pFile
=new File( file1
);
985 rc
=pFile
->open( osl_File_OpenFlag_Read
);
987 if ( rc
!=FileBase::E_None
)
989 printf( "Verify: OK!\n" );
990 File::move( destPath
, file1
);
994 printf( "Verify: Error!\n" );
996 File::remove( destPath
);
1000 printf( "Verify: Error!\n" );
1007 //--------------------------------------------------
1008 // Move a file to a not existing directory
1009 //--------------------------------------------------
1011 destPath
=rtl::OUString( dir_not_exist
);
1012 destPath
+=rtl::OUString("/");
1015 printf( "Move a file to a not existing directory: \n");
1016 printf( "Move the file ");
1017 printFileName( file1
);
1019 printFileName( destPath
);
1022 rc
=File::move( file1
, destPath
);
1023 print_error( rtl::OString( "FileMove" ), rc
);
1027 //--------------------------------------------------
1029 //--------------------------------------------------
1031 printf( "Move a directory: \n");
1033 printf( "Move the directory ");
1034 printFileName( dir1
);
1036 printFileName( dir_not_exist
);
1040 rc
=File::move( dir1
, dir_not_exist
);
1041 print_error( rtl::OString( "FileMove" ), rc
);
1043 if ( rc
== FileBase::E_None
)
1044 File::move( dir_not_exist
, dir1
);
1053 //----------------------------------------------------
1055 //----------------------------------------------------
1057 void FileSizeTest( void )
1060 sal_uInt64 filesize
;
1061 DirectoryItem aItem
;
1063 printf( "--------------------------------------------\n" );
1064 printf( "File-Size-Test\n" );
1065 printf( "--------------------------------------------\n\n" );
1068 File
aFile( file_not_exist
);
1070 printf( "Create File: ");
1071 printFileName( file_not_exist
);
1074 rc
= aFile
.open( osl_File_OpenFlag_Read
| osl_File_OpenFlag_Write
| osl_File_OpenFlag_Create
);
1075 print_error( rtl::OString( "Create and Open File (Read & Write)" ), rc
);
1078 if ( rc
== FileBase::E_None
)
1080 //----------------------------------------------------
1081 // Set Filesize to 5000
1082 //----------------------------------------------------
1084 printf( "Set FileSize to 5000\n" );
1085 rc
=aFile
.setSize( 5000 );
1086 print_error( rtl::OString( "Set FileSize" ), rc
);
1089 printf( "Verify:\n" );
1091 //----------------------------------------------------
1092 // Check whether Filesize is set to 5000
1093 //----------------------------------------------------
1095 rc
=DirectoryItem::get( file_not_exist
, aItem
);
1096 print_error( rtl::OString( "Get DirectoryItem" ), rc
);
1098 if ( rc
== FileBase::E_None
)
1100 FileStatus
rStatus( osl_FileStatus_Mask_FileSize
);
1101 rc
=aItem
.getFileStatus( rStatus
);
1102 print_error( rtl::OString( "Get FileStatus" ), rc
);
1104 if ( rc
== FileBase::E_None
)
1106 filesize
=rStatus
.getFileSize();
1108 if ( filesize
== 5000 )
1109 printf( "\nOK : FileSize: %" SAL_PRIuUINT64
"\n", filesize
);
1111 printf( "\nError : FileSize: %" SAL_PRIuUINT64
"\n", filesize
);
1117 //----------------------------------------------------
1118 // Set Filesize to -1
1119 //----------------------------------------------------
1121 printf( "Set FileSize to -1\n" );
1122 rc
=aFile
.setSize( -1 );
1123 print_error( rtl::OString( "Set FileSize" ), rc
);
1129 print_error( rtl::OString( "Close File" ), rc
);
1132 rc
=File::remove( file_not_exist
);
1133 print_error( rtl::OString( "Remove File" ), rc
);
1142 //----------------------------------------------------
1144 //----------------------------------------------------
1146 void FilePointerTest( void )
1149 sal_uInt64 filepointer
;
1151 printf( "--------------------------------------------\n" );
1152 printf( "File-Pointer-Test\n" );
1153 printf( "--------------------------------------------\n\n" );
1156 File
rFile( file_not_exist
);
1158 printf( "Create File: ");
1159 printFileName( file_not_exist
);
1162 rc
= rFile
.open( osl_File_OpenFlag_Read
| osl_File_OpenFlag_Write
| osl_File_OpenFlag_Create
);
1163 print_error( rtl::OString( "Create and Open File (Read & Write) "), rc
);
1166 if ( rc
==FileBase::E_None
)
1169 //----------------------------------------------------
1170 // get the position of the filepointer
1171 //----------------------------------------------------
1173 rc
=rFile
.getPos( filepointer
);
1174 print_error( rtl::OString( "GetPos" ), rc
);
1175 printf( "Position of the FilePointer: %" SAL_PRIuUINT64
"\n", filepointer
);
1179 //----------------------------------------------------
1180 // set the filepointer at the end of a file
1181 //----------------------------------------------------
1183 printf( "Set FileSize to 5000\n" );
1184 rFile
.setSize( 5000 );
1186 printf( "Set the FilePointer at the end of the file (5000)\n" );
1187 rc
=rFile
.setPos( osl_Pos_End
,0 );
1188 print_error( rtl::OString( "SetPos" ), rc
);
1190 rc
=rFile
.getPos( filepointer
);
1192 if ( filepointer
==5000 )
1194 print_error( rtl::OString( "GetPos" ), rc
);
1195 printf( "\nVerify: OK !\n" );
1196 printf( "Filepointer-Position: %" SAL_PRIuUINT64
"\n",filepointer
);
1200 print_error( rtl::OString( "GetPos" ), rc
);
1201 printf( "\nFilePointer-Test: Error\n" );
1202 printf( "Filepointer-Position: %" SAL_PRIuUINT64
" != 5000 \n",filepointer
);
1209 print_error( rtl::OString( "Close File" ), rc
);
1212 rc
=File::remove( file_not_exist
);
1213 print_error( rtl::OString( "Remove File" ), rc
);
1221 //--------------------------------------------------
1222 // FileAttributesTest
1223 //--------------------------------------------------
1225 void verifyFileAttributes( void )
1228 DirectoryItem aItem
;
1229 FileStatus
rStatus( osl_FileStatus_Mask_Attributes
);
1231 printf( "\nVerify:\n" );
1233 rc
=DirectoryItem::get( file1
, aItem
);
1235 if ( rc
==FileBase::E_None
)
1237 rc
=aItem
.getFileStatus( rStatus
);
1239 if ( rc
==FileBase::E_None
)
1241 sal_uInt64 uAttributes
=rStatus
.getAttributes();
1242 showAttributes(uAttributes
);
1246 print_error( rtl::OString( "Get FileStatus" ), rc
);
1249 print_error( rtl::OString( "Get DirectoryItem" ), rc
);
1255 void FileAttributesTest( void )
1259 printf( "--------------------------------------------\n" );
1260 printf( "File-Attributes-Test\n" );
1261 printf( "--------------------------------------------\n\n" );
1264 printFileName( file1
);
1268 rc
=File::setAttributes( file1
, osl_File_Attribute_GrpWrite
);
1269 print_error( rtl::OString( "Set Attribute: GrpWrite" ), rc
);
1271 verifyFileAttributes();
1273 rc
=File::setAttributes( file1
, 0 );
1274 if ( rc
!=FileBase::E_None
)
1275 print_error( rtl::OString( "Reset Attributes" ), rc
);
1277 rc
=File::setAttributes( file1
, osl_File_Attribute_GrpRead
);
1278 print_error( rtl::OString( "Set Attribute: GrpRead" ), rc
);
1280 verifyFileAttributes();
1282 rc
=File::setAttributes( file1
, 0 );
1283 if ( rc
!=FileBase::E_None
)
1284 print_error( rtl::OString( "Reset Attributes" ), rc
);
1286 rc
=File::setAttributes( file1
, osl_File_Attribute_GrpExe
);
1287 print_error( rtl::OString( "Set Attribute: GrpExe" ), rc
);
1289 verifyFileAttributes();
1291 rc
=File::setAttributes( file1
, 0 );
1292 if ( rc
!=FileBase::E_None
)
1293 print_error( rtl::OString( "Reset Attributes" ), rc
);
1295 rc
=File::setAttributes( file1
, osl_File_Attribute_OwnWrite
);
1296 print_error( rtl::OString( "Set Attribute: OwnWrite" ), rc
);
1298 verifyFileAttributes();
1300 rc
=File::setAttributes( file1
, 0 );
1301 if ( rc
!=FileBase::E_None
)
1302 print_error( rtl::OString( "Reset Attributes" ), rc
);
1304 rc
=File::setAttributes( file1
, osl_File_Attribute_OwnRead
);
1305 print_error( rtl::OString( "Set Attribute: OwnRead" ), rc
);
1307 verifyFileAttributes();
1309 rc
=File::setAttributes( file1
, 0 );
1310 if ( rc
!=FileBase::E_None
)
1311 print_error( rtl::OString( "Reset Attributes" ), rc
);
1313 rc
=File::setAttributes( file1
, osl_File_Attribute_OwnExe
);
1314 print_error( rtl::OString( "Set Attribute: OwnExe" ), rc
);
1316 verifyFileAttributes();
1318 rc
=File::setAttributes( file1
, 0 );
1319 if ( rc
!=FileBase::E_None
)
1320 print_error( rtl::OString( "Reset Attributes" ), rc
);
1322 rc
=File::setAttributes( file1
, osl_File_Attribute_OthWrite
);
1323 print_error( rtl::OString( "Set Attribute: OthWrite" ), rc
);
1325 verifyFileAttributes();
1327 rc
=File::setAttributes( file1
, 0 );
1328 if ( rc
!=FileBase::E_None
)
1329 print_error( rtl::OString( "Reset Attributes" ), rc
);
1331 rc
=File::setAttributes( file1
, osl_File_Attribute_OthRead
);
1332 print_error( rtl::OString( "Set Attribute: OthRead" ), rc
);
1334 verifyFileAttributes();
1336 rc
=File::setAttributes( file1
, 0 );
1337 if ( rc
!=FileBase::E_None
)
1338 print_error( rtl::OString( "Reset Attributes" ), rc
);
1340 rc
=File::setAttributes( file1
, osl_File_Attribute_OthExe
);
1341 print_error( rtl::OString( "Set Attribute: OthExe" ), rc
);
1343 verifyFileAttributes();
1345 rc
=File::setAttributes( file1
, 0 );
1346 if ( rc
!=FileBase::E_None
)
1347 print_error( rtl::OString( "Reset Attributes" ), rc
);
1350 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
);
1351 print_error( rtl::OString( "Set all Attributes" ), rc
);
1353 verifyFileAttributes();
1362 void FileAttributesTest( void )
1366 printf( "--------------------------------------------\n" );
1367 printf( "File-Attributes-Test\n" );
1368 printf( "--------------------------------------------\n\n" );
1371 printFileName( file1
);
1375 rc
=File::setAttributes( file1
, osl_File_Attribute_ReadOnly
);
1376 print_error( rtl::OString( "Set Attribute: ReadOnly" ), rc
);
1378 verifyFileAttributes();
1380 rc
=File::setAttributes( file1
, 0 );
1381 print_error( rtl::OString( "Reset Attributes" ), rc
);
1383 verifyFileAttributes();
1385 rc
=File::setAttributes( file1
, osl_File_Attribute_Hidden
);
1386 print_error( rtl::OString( "Set Attribute: Hidden" ), rc
);
1388 verifyFileAttributes();
1390 rc
=File::setAttributes( file1
, 0 );
1391 print_error( rtl::OString( "Reset Attributes" ), rc
);
1393 verifyFileAttributes();
1395 rc
=File::setAttributes( file1
, osl_File_Attribute_Hidden
| osl_File_Attribute_ReadOnly
);
1396 print_error( rtl::OString( "Set Attribute: Hidden & ReadOnly" ), rc
);
1398 verifyFileAttributes();
1400 rc
=File::setAttributes( file1
, 0 );
1401 print_error( rtl::OString( "Reset Attributes") , rc
);
1403 verifyFileAttributes();
1411 //--------------------------------------------------
1413 //--------------------------------------------------
1415 void FileTimeTest( void )
1419 DirectoryItem aItem
;
1421 struct tm sSysCreationTime
;
1422 sSysCreationTime
.tm_sec
= 0;
1423 sSysCreationTime
.tm_min
= 20;
1424 sSysCreationTime
.tm_hour
= 12;
1425 sSysCreationTime
.tm_mday
= 4;
1426 sSysCreationTime
.tm_mon
= 9;
1427 sSysCreationTime
.tm_year
= 99;
1429 struct tm sSysAccessTime
;
1430 sSysAccessTime
.tm_sec
= 0;
1431 sSysAccessTime
.tm_min
= 40;
1432 sSysAccessTime
.tm_hour
= 1;
1433 sSysAccessTime
.tm_mday
= 6;
1434 sSysAccessTime
.tm_mon
= 5;
1435 sSysAccessTime
.tm_year
= 98;
1437 struct tm sSysModifyTime
;
1438 sSysModifyTime
.tm_sec
= 0;
1439 sSysModifyTime
.tm_min
= 1;
1440 sSysModifyTime
.tm_hour
= 24;
1441 sSysModifyTime
.tm_mday
= 13;
1442 sSysModifyTime
.tm_mon
= 11;
1443 sSysModifyTime
.tm_year
= 95;
1445 sal_uInt32 aSysCreationTime
= mktime( &sSysCreationTime
);
1446 sal_uInt32 aSysAccessTime
= mktime( &sSysAccessTime
);
1447 sal_uInt32 aSysModifyTime
= mktime( &sSysModifyTime
);
1449 TimeValue aCreationTime
= { aSysCreationTime
, 0};
1450 TimeValue aAccessTime
= { aSysAccessTime
, 0};
1451 TimeValue aModifyTime
= { aSysModifyTime
, 0};
1453 TimeValue aCreationTimeRead
;
1454 TimeValue aAccessTimeRead
;
1455 TimeValue aModifyTimeRead
;
1458 printf( "--------------------------------------------\n" );
1459 printf( "File-Time-Test\n" );
1460 printf( "--------------------------------------------\n\n" );
1463 printFileName( file1
);
1466 printf( "CreationTime \t : ");
1467 showTime( aCreationTime
);
1469 printf( "\nAccessTime \t : ");
1470 showTime( aAccessTime
);
1472 printf( "\nModifyTime \t : ");
1473 showTime( aModifyTime
);
1475 //--------------------------------------------------
1477 //--------------------------------------------------
1480 rc
=File::setTime( file1
, aCreationTime
, aAccessTime
, aModifyTime
);
1481 print_error( rtl::OString( "SetTime" ), rc
);
1483 //--------------------------------------------------
1485 //--------------------------------------------------
1487 FileStatus
rStatus( osl_FileStatus_Mask_CreationTime
| osl_FileStatus_Mask_AccessTime
| osl_FileStatus_Mask_ModifyTime
);
1489 printf( "\nVerify:\n" );
1491 rc
=DirectoryItem::get( file1
, aItem
);
1492 print_error( rtl::OString( "Get DirectoryItem" ), rc
);
1494 if ( rc
==FileBase::E_None
)
1496 rc
=aItem
.getFileStatus( rStatus
);
1497 print_error( rtl::OString( "Get FileStatus" ), rc
);
1500 if ( rc
==FileBase::E_None
)
1502 //--------------------------------------------------
1504 //--------------------------------------------------
1506 aCreationTimeRead
=rStatus
.getCreationTime();
1508 if ( aCreationTime
.Seconds
== aCreationTimeRead
.Seconds
&& aCreationTime
.Nanosec
== aCreationTimeRead
.Nanosec
)
1509 printf( "GetCreationTime: ok : " );
1511 printf( "GetCreationTime: Error : " );
1513 showTime( aCreationTimeRead
);
1516 //--------------------------------------------------
1518 //--------------------------------------------------
1520 aAccessTimeRead
=rStatus
.getAccessTime();
1522 if ( aAccessTime
.Seconds
== aAccessTimeRead
.Seconds
&& aAccessTime
.Nanosec
== aAccessTimeRead
.Nanosec
)
1523 printf( "GetAccessTime: ok : " );
1525 printf( "GetAccessTime: Error : " );
1527 showTime( aAccessTimeRead
);
1530 //--------------------------------------------------
1532 //--------------------------------------------------
1534 aModifyTimeRead
=rStatus
.getModifyTime();
1536 if ( aModifyTime
.Seconds
== aModifyTimeRead
.Seconds
&& aModifyTime
.Nanosec
== aModifyTimeRead
.Nanosec
)
1537 printf( "GetModifyTime: ok : " );
1539 printf( "GetModifyTime: Error : " );
1541 showTime( aModifyTimeRead
);
1551 //--------------------------------------------------
1552 // DirectoryItemTest
1553 //--------------------------------------------------
1555 void DirectoryItemTest( void )
1559 DirectoryItem aItem
;
1560 FileStatus
*pStatus
;
1563 printf( "--------------------------------------------\n" );
1564 printf( "Directory-Item-Test\n" );
1565 printf( "--------------------------------------------\n\n" );
1567 //--------------------------------------------------
1568 // get DirectoryItem from an existing directory
1569 //--------------------------------------------------
1571 printf( "Get DirectoryItem from an existing Directory: ");
1572 printFileName( dir1
);
1575 rc
=DirectoryItem::get( dir1
, aItem
);
1576 print_error( rtl::OString( "GetDirectoryItem" ), rc
);
1578 pStatus
=new FileStatus( osl_FileStatus_Mask_All
);
1579 rc
=aItem
.getFileStatus( *pStatus
);
1581 if ( rc
==FileBase::E_None
)
1583 printf( "GetFileStatus: FileURL: ");
1584 printFileName(pStatus
->getFileURL() );
1592 //--------------------------------------------------
1593 // get DirectoryItem from a not existing directory
1594 //--------------------------------------------------
1596 printf( "Get DirectoryItem from a not existing Directory: ");
1597 printFileName( dir_not_exist
);
1600 rc
=DirectoryItem::get( dir_not_exist
, aItem
);
1601 print_error( rtl::OString( "Get DirectoryItem" ), rc
);
1605 //--------------------------------------------------
1606 // get DirectoryItem from an existing file
1607 //--------------------------------------------------
1609 printf( "Get DirectoryItem from an existing File: ");
1610 printFileName( file1
);
1613 rc
=DirectoryItem::get( file1
, aItem
);
1614 print_error( rtl::OString( "GetDirectoryItem" ), rc
);
1616 pStatus
=new FileStatus( osl_FileStatus_Mask_All
);
1617 rc
=aItem
.getFileStatus( *pStatus
);
1619 if ( rc
==FileBase::E_None
)
1621 printf( "GetFileStatus: FileURL: ");
1622 printFileName( pStatus
->getFileURL() );
1630 //--------------------------------------------------
1631 // get DirectoryItem from a not existing file
1632 //--------------------------------------------------
1634 printf( "Get DirectoryItem from a not existing File: ");
1635 printFileName( file_not_exist
);
1638 rc
=DirectoryItem::get( file_not_exist
, aItem
);
1639 print_error( rtl::OString( "Get DirectoryItem" ), rc
);
1643 //----------------------------------------------------------
1644 // get DirectoryItem from a directory with a wrong semantic
1645 //----------------------------------------------------------
1647 printf( "Get DirectoryItem from a Directory with a wrong semantic: ");
1648 printFileName( dir_not_exist
);
1651 rc
=DirectoryItem::get( dir_wrong_semantic
, aItem
);
1652 print_error( rtl::OString( "Get DirectoryItem" ),rc
);
1656 //---------------------------------------------------
1657 // get DirectoryItem from a file-handle
1658 //--------------------------------------------------
1660 pFile
=new File( file1
);
1662 rc
=pFile
->open( osl_File_OpenFlag_Read
);
1663 if ( rc
==FileBase::E_None
)
1665 printf( "Get DirectoryItem from a File-Handle: ");
1666 printFileName( file1
);
1669 rc
=DirectoryItem::get( file1
, aItem
);
1670 print_error( rtl::OString( "GetDirectoryItem" ), rc
);
1672 pStatus
=new FileStatus( osl_FileStatus_Mask_All
);
1673 rc
=aItem
.getFileStatus( *pStatus
);
1675 if ( rc
==FileBase::E_None
)
1677 printf( "GetFileStatus: FileURL: ");
1678 printFileName( pStatus
->getFileURL() );
1691 //---------------------------------------------------
1692 // get DirectoryItem
1693 //--------------------------------------------------
1695 printf( "Get DirectoryItem from an empty File-Handle\n" );
1696 rc
=DirectoryItem::get( file1
, aItem
);
1697 print_error( rtl::OString( "GetDirectoryItem" ), rc
);
1701 //--------------------------------------------------
1702 // GetNextItem from a directory
1703 //--------------------------------------------------
1705 pDir
=new Directory( dir1
);
1706 printf( "Get next DirectoryItem from a directory: ");
1707 printFileName( dir1
);
1711 print_error( rtl::OString( "Open Directory" ), rc
);
1715 if ( pDir
->isOpen() )
1717 //--------------------------------------------------
1718 // get all files from the directory
1719 //--------------------------------------------------
1722 rtl::OUString str1
[2];
1724 aItem
=DirectoryItem();
1725 rc
=pDir
->getNextItem( aItem
);
1726 print_error( rtl::OString( "GetNextItem" ),rc
);
1728 while( rc
==FileBase::E_None
)
1731 FileStatus
rStatus( osl_FileStatus_Mask_All
);
1732 aItem
.getFileStatus( rStatus
);
1734 str
=rStatus
.getFileName();
1735 printf( "Filename: ");
1736 printFileName( str
);
1739 aItem
=DirectoryItem();
1740 rc
=pDir
->getNextItem( aItem
);
1741 print_error( rtl::OString( "GetNextItem" ),rc
);
1746 //--------------------------------------------------
1748 //--------------------------------------------------
1750 for (int i
=0; i
<2; i
++)
1752 aItem
=DirectoryItem();
1754 rc
=pDir
->getNextItem( aItem
);
1756 FileStatus
rStatus( osl_FileStatus_Mask_All
);
1757 aItem
.getFileStatus( rStatus
);
1759 str1
[i
]=rStatus
.getFileName();
1763 if ( str1
[0] == str1
[1] )
1764 print_error( rtl::OString( "Reset" ),FileBase::E_None
);
1766 print_error( rtl::OString( "Reset" ),FileBase::E_invalidError
);
1772 print_error( rtl::OString( "Close Directory" ), rc
);
1777 //--------------------------------------------------
1778 // GetNextItem from a closed directory
1779 //--------------------------------------------------
1781 printf( "Get next DirectoryItem from a closed directory: ");
1782 printFileName( dir1
);
1785 aItem
=DirectoryItem();
1786 rc
=pDir
->getNextItem( aItem
);
1787 print_error( rtl::OString( "GetNextItem" ),rc
);
1795 //--------------------------------------------------
1796 // FileStatusTest (for different types)
1797 //--------------------------------------------------
1799 void FileStatusTest( FileStatus
*pStatus
)
1801 //--------------------------------------------------
1802 // GetFileType of the directory
1803 //--------------------------------------------------
1805 FileStatus::Type aType
;
1807 printf( "\ngetFileType:\n" );
1808 aType
=pStatus
->getFileType();
1809 showFileType( aType
);
1811 //--------------------------------------------------
1813 //--------------------------------------------------
1815 sal_uInt64 uAttributes
;
1817 printf( "\ngetAttributes:\n" );
1818 uAttributes
=pStatus
->getAttributes();
1819 showAttributes( uAttributes
);
1821 //--------------------------------------------------
1823 //--------------------------------------------------
1825 TimeValue aCreationTime
;
1827 printf( "\ngetCreationTime:\n" );
1828 aCreationTime
=pStatus
->getCreationTime();
1830 printf( "CreationTime: " );
1831 showTime( aCreationTime
);
1833 //--------------------------------------------------
1835 //--------------------------------------------------
1837 TimeValue aAccessTime
;
1839 printf( "\ngetAccessTime:\n" );
1840 aAccessTime
=pStatus
->getAccessTime();
1842 printf( "AccessTime: " );
1843 showTime( aAccessTime
);
1845 //--------------------------------------------------
1847 //--------------------------------------------------
1849 TimeValue aModifyTime
;
1851 printf( "\ngetModifyTime:\n" );
1852 aModifyTime
=pStatus
->getModifyTime();
1854 printf( "ModifyTime: " );
1855 showTime( aModifyTime
);
1857 //--------------------------------------------------
1859 //--------------------------------------------------
1861 sal_uInt64 FileSize
;
1863 printf( "\ngetFileSize:\n" );
1865 FileSize
=pStatus
->getFileSize();
1866 printf( "FileSize: %" SAL_PRIuUINT64
"\n", FileSize
);
1868 //--------------------------------------------------
1870 //--------------------------------------------------
1872 rtl::OUString FileName
;
1874 printf( "\ngetFileName:\n" );
1876 FileName
=pStatus
->getFileName();
1877 printf( "FileName: ");
1878 printFileName( FileName
);
1881 //--------------------------------------------------
1883 //--------------------------------------------------
1885 rtl::OUString FileURL
;
1887 printf( "\ngetFileURL:\n" );
1889 FileURL
=pStatus
->getFileURL();
1890 printf( "FileURL: ");
1891 printFileName( FileURL
);
1894 //--------------------------------------------------
1896 //--------------------------------------------------
1898 rtl::OUString LinkTargetURL
;
1900 printf( "\ngetLinkTargetURL:\n");
1902 LinkTargetURL
=pStatus
->getLinkTargetURL();
1903 printf( "LinkTargetURL: ");
1904 printFileName( LinkTargetURL
);
1910 //--------------------------------------------------
1911 // DirectoryFileStatusTest
1912 //--------------------------------------------------
1914 void DirectoryFileStatusTest( void )
1917 DirectoryItem aItem
;
1918 FileStatus
*pStatus
;
1920 printf( "--------------------------------------------\n" );
1921 printf( "Directory-FileStatus-Test\n" );
1922 printf( "--------------------------------------------\n\n" );
1924 printf( "FileStatus of the directory: ");
1925 printFileName( dir1
);
1928 aItem
=DirectoryItem();
1930 rc
=DirectoryItem::get( dir1
, aItem
);
1931 print_error( rtl::OString( "Get DirectoryItem" ), rc
);
1933 if ( rc
==FileBase::E_None
)
1935 pStatus
=new FileStatus( osl_FileStatus_Mask_All
);
1936 rc
=aItem
.getFileStatus( *pStatus
);
1938 FileStatusTest( pStatus
);
1949 //--------------------------------------------------
1950 // FileFileStatusTest
1951 //--------------------------------------------------
1953 void FileFileStatusTest( void )
1956 DirectoryItem aItem
;
1957 FileStatus
*pStatus
;
1959 printf( "--------------------------------------------\n" );
1960 printf( "File-FileStatus-Test\n" );
1961 printf( "--------------------------------------------\n\n" );
1963 printf( "FileStatus of the file: ");
1964 printFileName( file1
);
1967 aItem
=DirectoryItem();
1969 rc
=DirectoryItem::get( file1
, aItem
);
1970 print_error( rtl::OString( "Get DirectoryItem" ), rc
);
1972 if ( rc
==FileBase::E_None
)
1974 pStatus
=new FileStatus( osl_FileStatus_Mask_All
);
1975 rc
=aItem
.getFileStatus( *pStatus
);
1977 FileStatusTest( pStatus
);
1988 //--------------------------------------------------
1989 // VolumeFileStatusTest
1990 //--------------------------------------------------
1992 void VolumeFileStatusTest( void )
1995 DirectoryItem aItem
;
1996 FileStatus
*pStatus
;
1998 printf( "--------------------------------------------\n" );
1999 printf( "Volume-FileStatus-Test\n" );
2000 printf( "--------------------------------------------\n\n" );
2002 printf( "FileStatus of the Volume: ");
2003 printFileName( root
);
2006 aItem
=DirectoryItem();
2008 rc
=DirectoryItem::get( root
, aItem
);
2009 print_error( rtl::OString( "Get DirectoryItem" ), rc
);
2011 if ( rc
==FileBase::E_None
)
2013 pStatus
=new FileStatus( osl_FileStatus_Mask_All
) ;
2014 rc
=aItem
.getFileStatus( *pStatus
);
2016 FileStatusTest( pStatus
);
2028 //--------------------------------------------------
2030 //--------------------------------------------------
2032 void VolumeInfoTest( void )
2036 printf( "--------------------------------------------\n" );
2037 printf( "Volume-Info-Test\n" );
2038 printf( "--------------------------------------------\n\n" );
2040 printf( "VolumeInfo of the volume ");
2041 printFileName( root
);
2045 VolumeInfo
rInfo( osl_VolumeInfo_Mask_FreeSpace
);
2046 rc
=Directory::getVolumeInfo( root
, rInfo
);
2047 print_error( rtl::OString( "GetVolumeInfo" ),rc
);
2051 //--------------------------------------------------
2053 //--------------------------------------------------
2055 if ( rInfo
.getRemoteFlag() )
2056 printf( "RemoteFlag: Yes\n" );
2058 printf( "RemoteFlag: No\n" );
2060 //--------------------------------------------------
2061 // getRemoveableFlag
2062 //--------------------------------------------------
2064 if ( rInfo
.getRemoveableFlag() )
2065 printf( "RemoveableFlag: Yes\n" );
2067 printf( "RemoveableFlag: No\n" );
2069 //--------------------------------------------------
2071 //--------------------------------------------------
2073 sal_uInt64 TotalSpace
;
2074 TotalSpace
=rInfo
.getTotalSpace();
2075 printf( "Total Space: %" SAL_PRIuUINT64
"\n",TotalSpace
);
2077 //--------------------------------------------------
2079 //--------------------------------------------------
2081 sal_uInt64 FreeSpace
;
2082 FreeSpace
=rInfo
.getFreeSpace();
2083 printf( "Free Space: %" SAL_PRIuUINT64
"\n",FreeSpace
);
2085 //--------------------------------------------------
2087 //--------------------------------------------------
2089 sal_uInt64 UsedSpace
;
2090 UsedSpace
=rInfo
.getUsedSpace();
2091 printf( "Used Space: %" SAL_PRIuUINT64
"\n",UsedSpace
);
2093 //--------------------------------------------------
2095 //--------------------------------------------------
2097 sal_uInt32 MaxNameLength
;
2098 MaxNameLength
=rInfo
.getMaxNameLength();
2099 printf( "MaxNameLength: %" SAL_PRIuUINT32
"\n",MaxNameLength
);
2101 //--------------------------------------------------
2103 //--------------------------------------------------
2105 sal_uInt32 MaxPathLength
;
2106 MaxPathLength
=rInfo
.getMaxPathLength();
2107 printf( "MaxPathLength: %" SAL_PRIuUINT32
"\n",MaxPathLength
);
2109 //--------------------------------------------------
2110 // getFileSystemName
2111 //--------------------------------------------------
2113 rtl::OUString FileSystemName
;
2114 FileSystemName
=rInfo
.getFileSystemName();
2115 printf( "File-System-Name: ");
2116 printFileName( FileSystemName
);
2123 //--------------------------------------------------
2125 //--------------------------------------------------
2127 void ConvertPathTest(rtl::OUString
& strPath
)
2131 rtl::OUString strNormPath
;
2132 rtl::OUString strFileURL
;
2133 rtl::OUString strNormPathFromFileURL
;
2134 rtl::OUString strSystemPath
;
2136 //--------------------------------------------------
2138 //--------------------------------------------------
2140 rc
=FileBase::getFileURLFromSystemPath( strPath
, strNormPath
);
2142 if ( rc
== FileBase::E_None
)
2144 printf( "Normalized Path: \t\t");
2145 printFileName( strNormPath
);
2149 printf( "normalizePath: Error \n" );
2151 //--------------------------------------------------
2152 // getFileURLFromSystemPath
2153 //--------------------------------------------------
2155 if ( !strNormPath
.isEmpty() )
2157 rc
=FileBase::getFileURLFromSystemPath( strNormPath
, strFileURL
);
2159 if ( rc
== FileBase::E_None
)
2161 printf( "File-URL: \t\t\t");
2162 printFileName( strFileURL
);
2166 printf( "getFileURLFromSystemPath: Error \n" );
2169 printf( "getFileURLFromSystemPath: not tested \n" );
2171 //--------------------------------------------------
2172 // getNormalizedPathFromFileURL
2173 //--------------------------------------------------
2175 if ( !strFileURL
.isEmpty() )
2177 rc
=FileBase::getSystemPathFromFileURL( strFileURL
, strNormPathFromFileURL
);
2179 if ( rc
== FileBase::E_None
)
2181 printf( "Normalized Path from File-URL: \t");
2182 printFileName( strNormPathFromFileURL
);
2186 printf( "getNormalizedPathFromFileURL: Error \n" );
2189 printf( "getNormalizedPathFromFileURL: not tested \n" );
2192 //--------------------------------------------------
2193 // getSystemPathFromFileURL
2194 //--------------------------------------------------
2196 if ( !strNormPath
.isEmpty() )
2198 rc
=FileBase::getSystemPathFromFileURL( strNormPath
, strSystemPath
);
2200 if ( rc
== FileBase::E_None
)
2202 printf( "System-Path: \t\t\t");
2203 printFileName( strSystemPath
);
2207 printf( "getSystemPathFromFileURL: Error \n" );
2210 printf( "getSystemPathFromFileURL: not tested \n" );
2212 //--------------------------------------------------
2214 //--------------------------------------------------
2216 if ( strNormPathFromFileURL
== strNormPath
)
2217 printf( "\nVerify: OK ! ( Normalized-Path == Normalized-Path-From-File-URL )\n" );
2219 printf( "\nVerify: Error ! ( Normalized-Path != Normalized-Path-From-File-URL )\n" );
2226 printf( "--------------------------------------------\n" );
2227 printf( "FileBase-Test\n" );
2228 printf( "--------------------------------------------\n\n" );
2230 //--------------------------------------------------
2231 // ConvertPath-Test (Local File)
2232 //--------------------------------------------------
2234 printf( "- Local File: ");
2235 printFileName( file1
);
2238 ConvertPathTest(file1
);
2240 //--------------------------------------------------
2241 // ConvertPath-Test (File on a server)
2242 //--------------------------------------------------
2244 printf( "\n- File on server: ");
2245 printFileName( file_on_server
);
2247 ConvertPathTest(file_on_server
);
2255 //--------------------------------------------------
2257 //--------------------------------------------------
2258 void DoAbsolutePathTest(rtl::OUString strDirBase
, rtl::OUString strRelative
)
2262 rtl::OUString strAbsolute
;
2264 printf( "Base-Directory: \t");
2265 printFileName( strDirBase
);
2267 printf( "Relative-Path: \t\t");
2268 printFileName ( strRelative
);
2271 rc
=FileBase::getAbsoluteFileURL( strDirBase
, strRelative
, strAbsolute
);
2273 if ( rc
== FileBase::E_None
)
2275 printf( "Absolute-Path: \t\t");
2276 printFileName ( strAbsolute
);
2280 printf( "Absolute-Path: Error \n" );
2286 void AbsolutePathTest(void)
2288 printf( "--------------------------------------------\n" );
2289 printf( "AbsolutePath-Test\n" );
2290 printf( "--------------------------------------------\n\n" );
2292 DoAbsolutePathTest(dir1
, rtl::OUString("."));
2293 DoAbsolutePathTest(dir1
, rtl::OUString(".."));
2294 DoAbsolutePathTest(dir1
, rtl::OUString("../.."));
2295 DoAbsolutePathTest(dir1
, rtl::OUString("../HUHU"));
2297 DoAbsolutePathTest(dir_on_server
, rtl::OUString("."));
2298 DoAbsolutePathTest(dir_on_server
, rtl::OUString(".."));
2299 DoAbsolutePathTest(dir_on_server
, rtl::OUString("../.."));
2300 DoAbsolutePathTest(dir_on_server
, rtl::OUString("../HUHU"));
2307 //--------------------------------------------------
2309 //--------------------------------------------------
2311 void SearchPathTest(void)
2315 rtl::OUString
strNormPath(file1
);
2316 rtl::OUString strFileURL
;
2317 rtl::OUString strSystemPath
;
2318 rtl::OUString strResultPath
;
2320 printf( "--------------------------------------------\n" );
2321 printf( "SearchPath-Test\n" );
2322 printf( "--------------------------------------------\n\n" );
2325 rc
=FileBase::getFileURLFromSystemPath( strNormPath
, strFileURL
);
2326 print_error( rtl::OString( "getFileURLFromSystemPath" ), rc
);
2327 rc
=FileBase::getSystemPathFromFileURL( strNormPath
, strSystemPath
);
2328 print_error( rtl::OString( "getSystemPathFromFileURL" ), rc
);
2330 //--------------------------------------------------
2331 // searchFileURL (with a normalized path)
2332 //--------------------------------------------------
2334 if ( !strNormPath
.isEmpty() )
2336 printf( "\nSearch-Normalized-Path (with a normalized path) : ");
2337 printFileName ( strNormPath
);
2340 rc
=FileBase::searchFileURL( strNormPath
, rtl::OUString() , strResultPath
);
2342 if ( rc
== FileBase::E_None
)
2344 printf( "Result: \t\t\t");
2345 printFileName ( strResultPath
);
2349 printf( "searchFileURL (with a normalized path): Error\n" );
2352 printf( "searchFileURL (with a normalized path): not tested\n" );
2354 //--------------------------------------------------
2355 // searchFileURL (with a File-URL)
2356 //--------------------------------------------------
2358 if ( !strFileURL
.isEmpty() )
2360 printf( "\nSearch-Normalized-Path (with a FileURL) : ");
2361 printFileName( strFileURL
);
2364 rc
=FileBase::searchFileURL( strFileURL
, rtl::OUString() , strResultPath
);
2366 if ( rc
== FileBase::E_None
)
2368 printf( "Result: \t\t\t");
2369 printFileName ( strResultPath
);
2373 printf( "searchFileURL (with a FileURL path): Error\n" );
2376 printf( "searchFileURL (with a FileURL path): not tested\n" );
2378 //--------------------------------------------------
2379 // searchFileURL (with a systempath)
2380 //--------------------------------------------------
2382 if ( !strSystemPath
.isEmpty() )
2384 printf( "\nSearch-Normalized-Path (with a SystemPath) : ");
2385 printFileName( strSystemPath
);
2388 rc
=FileBase::searchFileURL( strSystemPath
, rtl::OUString() , strResultPath
);
2390 if ( rc
== FileBase::E_None
)
2392 printf( "Result: \t\t\t");
2393 printFileName( strResultPath
);
2397 printf( "searchFileURL (with a systempath): Error\n" );
2400 printf( "searchFileURL (with a systempath): not tested\n" );
2402 //--------------------------------------------------
2403 // searchFileURL (File and no searchpath)
2404 //--------------------------------------------------
2406 printf( "\nsearchFileURL: File (no searchpath) : ");
2407 printFileName( file3
);
2410 rc
=FileBase::searchFileURL( file3
, rtl::OUString("") , strResultPath
);
2412 if ( rc
== FileBase::E_None
)
2414 printf( "Result: \t\t\t");
2415 printFileName( strResultPath
);
2419 printf( "searchFileURL: File not found: OK ! \n" );
2421 //--------------------------------------------------
2422 // searchFileURL (File and Path)
2423 //--------------------------------------------------
2425 printf( "\nsearchFileURL: File : ");
2426 printFileName( file3
);
2427 printf( "\tSearchPath ");
2428 printFileName( dir1
);
2431 rc
=FileBase::searchFileURL( file3
, dir1
, strResultPath
);
2433 if ( rc
== FileBase::E_None
)
2435 printf( "Result: \t\t\t");
2436 printFileName( strResultPath
);
2440 printf( "searchFileURL: File not found: Error\n" );
2442 //------------------------------------------------------------
2443 // searchFileURL (File and searchpath with two entries)
2444 //------------------------------------------------------------
2446 rtl::OUString
strSearchPath( dir_not_exist
);
2447 strSearchPath
+=rtl::OUString(";");
2448 strSearchPath
+=dir_on_server
;
2450 printf( "\nsearchFileURL: File : ");
2451 printFileName( file3
);
2452 printf( "SearchPath ");
2453 printFileName( strSearchPath
);
2456 rc
=FileBase::searchFileURL( file3
, strSearchPath
, strResultPath
);
2458 if ( rc
== FileBase::E_None
)
2460 printf( "Result: \t\t\t");
2461 printFileName( strResultPath
);
2465 printf( "searchFileURL: File not found: Error\n" );
2467 //-------------------------------------------------------------------
2468 // searchFileURL (File and searchpath (with a wrong semantic))
2469 //-------------------------------------------------------------------
2471 strSearchPath
=rtl::OUString( dir_wrong_semantic
);
2473 printf( "\nsearchFileURL: File : ");
2474 printFileName( file3
);
2475 printf( "SearchPath ");
2476 printFileName( strSearchPath
);
2479 rc
=FileBase::searchFileURL( file3
, strSearchPath
, strResultPath
);
2481 if ( rc
== FileBase::E_None
)
2482 printf( "Error: Wrong Semantich but no error occurs !\n" );
2484 printf( "searchFileURL: File not found: OK !\n" );
2489 //--------------------------------------------------
2490 // CanonicalNameTest
2491 //--------------------------------------------------
2493 void getCanonicalNameTest(rtl::OUString strPath
)
2497 rtl::OUString strValid
;
2499 printf( "Original-Name: \t\t");
2500 printFileName( strPath
);
2503 rc
=FileBase::getCanonicalName( strPath
, strValid
);
2505 if ( rc
== FileBase::E_None
)
2507 printf( "Canonical-Name: \t");
2508 printFileName( strValid
);
2513 printf( "Canonical-Name: Error \n" );
2519 void CanonicalNameTest(void)
2521 printf( "--------------------------------------------\n" );
2522 printf( "CanonicalName-Test\n" );
2523 printf( "--------------------------------------------\n\n" );
2525 getCanonicalNameTest( dir1
);
2526 getCanonicalNameTest( dir_on_server
);
2527 getCanonicalNameTest( file1
);
2528 getCanonicalNameTest( file_on_server
);
2534 //--------------------------------------------------
2536 //--------------------------------------------------
2538 void print_error( const ::rtl::OString
& str
, FileBase::RC rc
)
2541 printf( "%s : ", str
.getStr() );
2544 case FileBase::E_None
:
2547 case FileBase::E_PERM
:
2550 case FileBase::E_NOENT
:
2551 printf("E_NOENT\n");
2553 case FileBase::E_SRCH
:
2556 case FileBase::E_INTR
:
2559 case FileBase::E_IO
:
2562 case FileBase::E_NXIO
:
2565 case FileBase::E_2BIG
:
2568 case FileBase::E_NOEXEC
:
2569 printf("E_NOEXEC\n");
2571 case FileBase::E_BADF
:
2574 case FileBase::E_CHILD
:
2575 printf("E_CHILD\n");
2577 case FileBase::E_AGAIN
:
2578 printf("E_AGAIN\n");
2580 case FileBase::E_NOMEM
:
2581 printf("E_NOMEM\n");
2583 case FileBase::E_ACCES
:
2584 printf("E_ACCES\n");
2586 case FileBase::E_FAULT
:
2587 printf("E_FAULT\n");
2589 case FileBase::E_BUSY
:
2592 case FileBase::E_EXIST
:
2593 printf("E_EXIST\n");
2595 case FileBase::E_XDEV
:
2598 case FileBase::E_NODEV
:
2599 printf("E_NODEV\n");
2601 case FileBase::E_NOTDIR
:
2602 printf("E_NOTDIR\n");
2604 case FileBase::E_ISDIR
:
2605 printf("E_ISDIR\n");
2607 case FileBase::E_INVAL
:
2608 printf("E_INVAL\n");
2610 case FileBase::E_NFILE
:
2611 printf("E_NFILE\n");
2613 case FileBase::E_MFILE
:
2614 printf("E_MFILE\n");
2616 case FileBase::E_NOTTY
:
2617 printf("E_NOTTY\n");
2619 case FileBase::E_FBIG
:
2622 case FileBase::E_NOSPC
:
2623 printf("E_NOSPC\n");
2625 case FileBase::E_SPIPE
:
2626 printf("E_SPIPE\n");
2628 case FileBase::E_ROFS
:
2631 case FileBase::E_MLINK
:
2632 printf("E_MLINK\n");
2634 case FileBase::E_PIPE
:
2637 case FileBase::E_DOM
:
2640 case FileBase::E_RANGE
:
2641 printf("E_RANGE\n");
2643 case FileBase::E_DEADLK
:
2644 printf("E_DEADLK\n");
2646 case FileBase::E_NAMETOOLONG
:
2647 printf("E_NAMETOOLONG\n");
2649 case FileBase::E_NOLCK
:
2650 printf("E_NOLCK\n");
2652 case FileBase::E_NOSYS
:
2653 printf("E_NOSYS\n");
2655 case FileBase::E_NOTEMPTY
:
2656 printf("E_NOTEMPTY\n");
2658 case FileBase::E_LOOP
:
2661 case FileBase::E_ILSEQ
:
2662 printf("E_ILSEQ\n");
2664 case FileBase::E_NOLINK
:
2665 printf("E_NOLINK\n");
2667 case FileBase::E_MULTIHOP
:
2668 printf("E_MULTIHOP\n");
2670 case FileBase::E_USERS
:
2671 printf("E_USERS\n");
2673 case FileBase::E_OVERFLOW
:
2674 printf("E_OVERFLOW\n");
2677 printf("E_Unknown\n");
2683 //--------------------------------------------------
2685 //--------------------------------------------------
2687 #define MAIN _cdecl main
2692 int MAIN( int argc
, char* argv
[] )
2694 sal_Bool fSuccess
=sal_False
;
2697 fSuccess
=Initialize();
2700 printf("Error during Initialization");
2707 DirectoryOpenAndCloseTest();
2708 DirectoryCreateAndRemoveTest();
2710 FileOpenAndCloseTest();
2711 FileCreateAndRemoveTest();
2712 FileWriteAndReadTest();
2713 FileCopyAndMoveTest();
2716 FileAttributesTest();
2718 DirectoryItemTest();
2719 DirectoryFileStatusTest();
2720 VolumeFileStatusTest();
2721 FileFileStatusTest();
2726 CanonicalNameTest();
2728 // command line arguments ?
2735 if (strcmp(argv
[i
], "doc")==0)
2736 DirectoryOpenAndCloseTest();
2737 else if (strcmp(argv
[i
], "dcr")==0)
2738 DirectoryCreateAndRemoveTest();
2739 else if (strcmp(argv
[i
], "foc")==0)
2740 FileOpenAndCloseTest();
2741 else if (strcmp(argv
[i
], "fcr")==0)
2742 FileCreateAndRemoveTest();
2743 else if (strcmp(argv
[i
], "fwr")==0)
2744 FileWriteAndReadTest();
2745 else if (strcmp(argv
[i
], "fcm")==0)
2746 FileCopyAndMoveTest();
2747 else if (strcmp(argv
[i
], "fs")==0)
2749 else if (strcmp(argv
[i
], "fp")==0)
2751 else if (strcmp(argv
[i
], "fa")==0)
2752 FileAttributesTest();
2753 else if (strcmp(argv
[i
], "ft")==0)
2755 else if (strcmp(argv
[i
], "di")==0)
2756 DirectoryItemTest();
2757 else if (strcmp(argv
[i
], "dfs")==0)
2758 DirectoryFileStatusTest();
2759 else if (strcmp(argv
[i
], "vfs")==0)
2760 VolumeFileStatusTest();
2761 else if (strcmp(argv
[i
], "ffs")==0)
2762 FileFileStatusTest();
2763 else if (strcmp(argv
[i
], "vi")==0)
2765 else if (strcmp(argv
[i
], "fb")==0)
2767 else if (strcmp(argv
[i
], "sp")==0)
2769 else if (strcmp(argv
[i
], "ap")==0)
2771 else if (strcmp(argv
[i
], "cn")==0)
2772 CanonicalNameTest();
2779 fSuccess
=Shutdown();
2782 printf("Error during Shutdown");
2790 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */