1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
22 #include <osl/file.hxx>
23 #include <osl/process.h>
25 #include <rtl/alloc.h>
26 #include <rtl/ustring.hxx>
45 rtl::OUString dir_on_server
;
46 rtl::OUString dir_not_exist
;
47 rtl::OUString dir_not_exist_on_server
;
48 rtl::OUString dir_wrong_semantic
;
53 rtl::OUString file_on_server
;
54 rtl::OUString file_not_exist
;
56 void print_error(const ::rtl::OString
& str
, FileBase::RC rc
);
60 printf("\nPress Return !\n");
64 void printFileName(const ::rtl::OUString
& str
)
68 aString
= rtl::OUStringToOString( str
, RTL_TEXTENCODING_ASCII_US
);
70 printf( "%s", aString
.getStr() );
77 sal_Bool
testLineBreak( sal_Char
*pCount
, sal_uInt64 nLen
, sal_uInt32
*cLineBreak
)
79 sal_Bool fSuccess
=sal_False
;
87 if (nLen
>=1 && *(pCount
+1)==10)
92 if (nLen
>=2 && *(pCount
+2)==10)
97 else if ( *pCount
==10 )
108 sal_Bool
Initialize()
111 FileStatus
aStatus( osl_FileStatus_Mask_All
);
112 rtl_uString
*strExeFileURL
=NULL
;
113 oslProcessError ProcessError
;
115 rtl::OUString iniFileURL
;
120 sal_uInt64 uBytesRequested
;
121 sal_uInt64 uBytesRead
;
126 rtl::OUString dir
[12];
128 // Open to the ini-file
130 ProcessError
=osl_getExecutableFile(&strExeFileURL
);
132 if ( ProcessError
== osl_Process_E_None
)
134 sal_Unicode
*pExeFileCount
=rtl_uString_getStr(strExeFileURL
)+rtl_uString_getLength(strExeFileURL
);
136 // Search for the last slash in the Path
137 while (*pExeFileCount
!=L
'/' && pExeFileCount
>rtl_uString_getStr(strExeFileURL
))
140 // iniFileURL = strExeFileURL without the filename of the exe-File
141 iniFileURL
=rtl::OUString( rtl_uString_getStr(strExeFileURL
) ,(int) (pExeFileCount
-rtl_uString_getStr(strExeFileURL
)) );
143 // add "/testfile.ini" to iniFileURL
144 iniFileURL
+=rtl::OUString("/testfile.ini");
147 pFile
=new File( iniFileURL
);
148 rc
=pFile
->open( osl_File_OpenFlag_Read
| osl_File_OpenFlag_Write
);
149 if ( rc
!=FileBase::E_None
)
151 rtl_uString_release(strExeFileURL
);
157 rtl_uString_release(strExeFileURL
);
161 // Get filesize of the ini-File
163 rc
=DirectoryItem::get( iniFileURL
, aItem
);
164 if ( rc
!=FileBase::E_None
)
167 rc
=aItem
.getFileStatus( aStatus
);
168 if ( rc
!=FileBase::E_None
)
171 uBytesRequested
=aStatus
.getFileSize();
174 rc
=pFile
->setPos( osl_Pos_Absolut
, 0 );
175 pBuffer
=(sal_Char
*) rtl_allocateMemory( (sal_uInt32
) (uBytesRequested
+1)*sizeof(sal_Char
) );
176 memset( pBuffer
, 0, (sal_uInt32
)(uBytesRequested
+1)*sizeof(sal_Char
) );
178 rc
=pFile
->read( pBuffer
, uBytesRequested
, uBytesRead
);
179 if ( rc
!=FileBase::E_None
)
185 for ( int i
=0 ; i
<12 ; i
++ )
187 sal_uInt32 cLineBrake
=0;
188 while ( (static_cast<sal_uInt64
>(pCount
-pBuffer
) < uBytesRead
) && *pCount
!='=')
194 while ( (static_cast<sal_uInt64
>(pCount
-pBuffer
) < uBytesRead
) && !testLineBreak(pCount
,uBytesRead
-(pCount
-pBuffer
), &cLineBrake
))
197 dir
[i
]=rtl::OUString(pBegin
, pCount
-pBegin
, RTL_TEXTENCODING_ASCII_US
);
203 root
=rtl::OUString(dir
[0]);
204 dir1
=rtl::OUString(dir
[1]);
205 dir2
=rtl::OUString(dir
[2]);
206 dir_on_server
=rtl::OUString(dir
[3]);
207 dir_not_exist
=rtl::OUString(dir
[4]);
208 dir_not_exist_on_server
=rtl::OUString(dir
[5]);
209 dir_wrong_semantic
=rtl::OUString(dir
[6]);
211 file1
=rtl::OUString(dir
[7]);
212 file2
=rtl::OUString(dir
[8]);
213 file3
=rtl::OUString(dir
[9]);
214 file_on_server
=rtl::OUString(dir
[10]);
215 file_not_exist
=rtl::OUString(dir
[11]);
217 // close the ini-file
220 rtl_freeMemory( pBuffer
);
222 // Create directories
223 rc
=Directory::create( dir1
);
224 if ( rc
!=FileBase::E_None
)
227 rc
=Directory::create( dir2
);
228 if ( rc
!=FileBase::E_None
)
231 rc
=Directory::create( dir_on_server
);
232 if ( rc
!=FileBase::E_None
)
235 pFile
=new File( file1
);
236 rc
=pFile
->open( osl_File_OpenFlag_Write
| osl_File_OpenFlag_Create
);
237 if ( rc
!=FileBase::E_None
)
242 pFile
=new File( file2
);
243 rc
=pFile
->open( osl_File_OpenFlag_Write
| osl_File_OpenFlag_Create
);
244 if ( rc
!=FileBase::E_None
)
249 pFile
=new File( file_on_server
);
250 rc
=pFile
->open( osl_File_OpenFlag_Write
| osl_File_OpenFlag_Create
);
251 if ( rc
!=FileBase::E_None
)
263 sal_Bool fSuccess
=sal_True
;
267 // remove created files
269 pFile
=new File( file1
);
270 rc
=pFile
->remove( file1
);
271 if ( rc
!=FileBase::E_None
)
275 pFile
=new File( file2
);
276 rc
=pFile
->remove( file2
);
277 if ( rc
!=FileBase::E_None
)
281 // remove created directories
283 rc
=Directory::remove( dir1
);
284 if ( rc
!=FileBase::E_None
)
287 rc
=Directory::remove( dir2
);
288 if ( rc
!=FileBase::E_None
)
291 // remove created file on the server
293 pFile
=new File( file_on_server
);
294 rc
=pFile
->remove( file_on_server
);
295 if ( rc
!=FileBase::E_None
)
299 // remove created directory on the server
301 rc
=Directory::remove( dir_on_server
);
302 if ( rc
!=FileBase::E_None
)
311 void showFileType( FileStatus::Type aType
)
313 if ( aType
==FileStatus::Directory
)
314 printf( "FileType: Directory \n" );
315 else if ( aType
==FileStatus::Volume
)
316 printf( "FileType: Volume \n" );
317 else if ( aType
==FileStatus::Regular
)
318 printf( "FileType: Regular \n" );
319 else if ( aType
==FileStatus::Unknown
)
320 printf( "FileType: Unknown \n" );
325 void showAttributes( sal_uInt64 uAttributes
)
327 if ( uAttributes
==0 )
328 printf( "No Attributes \n" );
329 if ( uAttributes
& osl_File_Attribute_ReadOnly
)
330 printf( "Attribute: ReadOnly \n" );
331 if ( uAttributes
& osl_File_Attribute_Hidden
)
332 printf( "Attribute: Hidden \n" );
333 if ( uAttributes
& osl_File_Attribute_Executable
)
334 printf( "Attribute: Executable \n");
335 if ( uAttributes
& osl_File_Attribute_GrpWrite
)
336 printf( "Attribute: GrpWrite \n");
337 if ( uAttributes
& osl_File_Attribute_GrpRead
)
338 printf( "Attribute: GrpRead \n" );
339 if ( uAttributes
& osl_File_Attribute_GrpExe
)
340 printf( "Attribute: GrpExe \n" );
341 if ( uAttributes
& osl_File_Attribute_OwnWrite
)
342 printf( "Attribute: OwnWrite \n");
343 if ( uAttributes
& osl_File_Attribute_OwnRead
)
344 printf( "Attribute: OwnRead \n" );
345 if ( uAttributes
& osl_File_Attribute_OwnExe
)
346 printf( "Attribute: OwnExe \n" );
347 if ( uAttributes
& osl_File_Attribute_OthWrite
)
348 printf( "Attribute: OthWrite \n" );
349 if ( uAttributes
& osl_File_Attribute_OthRead
)
350 printf( "Attribute: OthRead \n");
351 if ( uAttributes
& osl_File_Attribute_OthExe
)
352 printf( "Attribute: OthExe \n" );
358 void showTime( TimeValue aTime
)
360 TimeValue aLocalTimeVal
, aSystemTimeVal
, aSysTimeVal
;
361 oslDateTime aDateTime
, aSystemTime
;
363 if ( osl_getLocalTimeFromSystemTime( &aTime
, &aLocalTimeVal
) )
365 if ( osl_getDateTimeFromTimeValue( &aLocalTimeVal
, &aDateTime
) )
367 printf("\t%02i.%02i.%4i , %02i.%02i.%02i Uhr\n", aDateTime
.Day
, aDateTime
.Month
, aDateTime
.Year
, aDateTime
.Hours
, aDateTime
.Minutes
, aDateTime
.Seconds
);
373 if ( osl_getDateTimeFromTimeValue( &aTime
, &aSystemTime
) )
375 printf("SystemTime: \t\t%02i.%02i.%4i , %02i.%02i.%02i Uhr\n", aSystemTime
.Day
, aSystemTime
.Month
, aSystemTime
.Year
, aSystemTime
.Hours
, aSystemTime
.Minutes
, aSystemTime
.Seconds
);
382 if ( osl_getTimeValueFromDateTime( &aSystemTime
, &aSystemTimeVal
) )
384 if ( ( aSystemTimeVal
.Seconds
== aTime
.Seconds
) && ( aSystemTimeVal
.Nanosec
== aTime
.Nanosec
))
385 printf ("Verify : TimeValue : ok! \n");
388 printf ("Verify : TimeValue : Error! \n");
389 printf ("aTime : %u \n", aTime
.Seconds
);
390 printf ("aSystemTimeVal : %u \n", aSystemTimeVal
.Seconds
);
394 printf ("Verify : TimeValue : Error! \n");
396 if ( osl_getSystemTimeFromLocalTime( &aLocalTimeVal
, &aSysTimeVal
) )
398 if ( ( aSysTimeVal
.Seconds
== aTime
.Seconds
) && ( aSysTimeVal
.Nanosec
== aTime
.Nanosec
))
399 printf ("Verify : SystemTime : ok! \n");
402 printf ("Verify : SystemTime : Error! \n");
403 printf ("aTime : %u\n", aTime
.Seconds
);
404 printf ("aSystemTimeVal : %u\n", aSysTimeVal
.Seconds
);
408 printf ("Verify : SystemTime : Error! \n");
413 TimeValue
getSystemTime()
420 aTime
.Seconds
= ltime
;
426 // DirectoryOpenAndCloseTest
428 void DirectoryOpenAndCloseTest()
433 printf( "--------------------------------------------\n");
434 printf( "Directory-Open-And-Close-Test\n");
435 printf( "--------------------------------------------\n\n");
437 // open an existing directory
439 pDir
=new Directory( dir1
);
440 printf( "Open an existing directory: ");
441 printFileName( dir1
);
445 print_error( rtl::OString( "Open Directory" ), rc
);
447 if ( pDir
->isOpen() )
449 print_error( rtl::OString( "Directory is Open" ), rc
);
454 print_error( rtl::OString( "Close Directory" ), rc
);
459 // open a not existing directory
461 pDir
=new Directory( dir_not_exist
);
463 printf( "Open a not existing directory: ");
464 printFileName( dir_not_exist
);
469 print_error( rtl::OString( "Open Directory" ), rc
);
475 // open a directory with a wrong semantic
477 pDir
=new Directory( dir_wrong_semantic
);
479 printf( "Open a directory with a wrong semantic: ");
480 printFileName( dir_wrong_semantic
);
484 print_error( rtl::OString( "Open Directory" ), rc
);
490 // open an existing directory on a server
492 pDir
=new Directory( dir_on_server
);
494 printf( "Open an existing directory on a server: ");
495 printFileName( dir_on_server
);
499 print_error( rtl::OString( "Open Directory" ), rc
);
503 print_error( rtl::OString( "Close Directory" ), rc
);
508 // open a not existing directory on a server
510 pDir
=new Directory( dir_not_exist_on_server
);
512 printf( "Open a not existing directory on a server: ");
513 printFileName( dir_not_exist_on_server
);
517 print_error( rtl::OString( "Open Directory" ), rc
);
522 // Close a not existing directory
524 pDir
=new Directory( dir_not_exist
);
525 printf( "Close a not existing directory: ");
526 printFileName( dir_not_exist
);
530 print_error( rtl::OString( "Close Directory" ), rc
);
537 // DirectoryCreateAndRemoveTest
539 void DirectoryCreateAndRemoveTest()
544 printf( "--------------------------------------------\n" );
545 printf( "Directory-Create-And-Remove-Test\n" );
546 printf( "--------------------------------------------\n\n" );
550 printf( "Create a not existing directory: ");
551 printFileName( dir_not_exist
);
554 rc
=Directory::create( dir_not_exist
) ;
555 print_error( rtl::OString( "Create Directory" ), rc
);
558 pDir
=new Directory( dir_not_exist
);
561 print_error( rtl::OString( "Verify" ), rc
);
567 // Create a directory on a server
569 printf( "Create a not existing directory on a server: ");
570 printFileName( dir_not_exist_on_server
);
573 rc
=Directory::create( dir_not_exist_on_server
);
574 print_error( rtl::OString( "Create Directory" ), rc
);
577 pDir
=new Directory( dir_not_exist_on_server
);
579 print_error( rtl::OString( "Verify" ), rc
);
585 // Remove Directories
587 printf( "Remove the created directories: \n" );
589 rc
=Directory::remove( dir_not_exist
);
591 rc1
=Directory::remove( dir_not_exist_on_server
);
593 if ( rc
==FileBase::E_None
&& rc1
==FileBase::E_None
)
594 print_error( rtl::OString( "Remove Directories" ), FileBase::E_None
);
595 else if ( rc
!=FileBase::E_None
)
596 print_error( rtl::OString( "Remove local Directory" ),rc
);
598 print_error( rtl::OString( "Remove Directory on a server" ),rc1
);
602 // Remove a not existing directory
604 printf( "Remove a not existing directory: ");
605 printFileName( dir_not_exist
);
608 rc
=Directory::remove( dir_not_exist
);
609 print_error( rtl::OString( "Remove" ),rc
);
615 // FileOpenAndCloseTest
617 static void FileOpenAndCloseTest()
621 printf( "--------------------------------------------\n" );
622 printf( "File-Open-And-Close-Test\n" );
623 printf( "--------------------------------------------\n\n" );
627 pFile
=new File( file1
);
629 printf( "Open an existing file: ");
630 printFileName( file1
);
633 // open an existing file (Read)
635 rc
=pFile
->open( osl_File_OpenFlag_Read
);
636 print_error( rtl::OString( "Open File (Read)" ), rc
);
641 print_error( rtl::OString( "Close File" ), rc
);
645 // open an existing file (Write)
647 rc
=pFile
->open( osl_File_OpenFlag_Write
);
648 print_error( rtl::OString( "Open File (Write)" ), rc
);
653 print_error( rtl::OString( "Close File" ), rc
);
657 // close the file a second time
660 print_error( rtl::OString( "Close the file a second time" ), rc
);
666 // FileCreateAndRemoveTest
668 void FileCreateAndRemoveTest()
673 printf( "--------------------------------------------\n" );
674 printf( "File-Create-And-Remove-Test\n" );
675 printf( "--------------------------------------------\n\n" );
677 pFile
=new File( file_not_exist
);
679 printf( "Create File: ");
680 printFileName( file_not_exist
);
683 // open (create) a not existing file (Read and write)
685 rc
= pFile
->open( osl_File_OpenFlag_Read
| osl_File_OpenFlag_Write
| osl_File_OpenFlag_Create
);
687 print_error( rtl::OString( "Create and Open File (Read & Write)" ), rc
);
692 print_error( rtl::OString( "Close File" ), rc
);
696 rc
=pFile
->remove( file_not_exist
);
697 print_error( rtl::OString(" Remove File" ), rc
);
701 // remove the same file a second time
703 rc
=pFile
->remove( file_not_exist
);
704 print_error( rtl::OString( "Remove a not existing File" ), rc
);
706 // remove an open file
708 pFile
->open( osl_File_OpenFlag_Read
| osl_File_OpenFlag_Write
| osl_File_OpenFlag_Create
);
710 rc
=pFile
->remove( file_not_exist
);
711 print_error( rtl::OString( "Remove an open File" ), rc
);
714 pFile
->remove( file_not_exist
);
721 // FileWriteAndReadTest
723 void FileWriteAndReadTest()
729 const sal_Char
*pWriteBuffer
="Hier kommt der Osterhase !";
730 sal_uInt64 nLen
=strlen( pWriteBuffer
);
731 sal_Char
*pReadBuffer
;
733 printf( "--------------------------------------------\n" );
734 printf( "File-Write-And-Read-Test\n" );
735 printf( "--------------------------------------------\n\n" );
739 pFile
=new File( file_not_exist
);
741 printf( "Create File: ");
742 printFileName( file_not_exist
);
745 // open (create) a not existing file (Read and write)
747 rc
= pFile
->open( osl_File_OpenFlag_Read
| osl_File_OpenFlag_Write
| osl_File_OpenFlag_Create
);
749 print_error( rtl::OString( "Create and Open File (Read & Write)" ), rc
);
753 // write a string to the file
755 rc
=pFile
->write( pWriteBuffer
, nLen
, uWritten
);
756 print_error( rtl::OString( "Write File" ), rc
);
759 printf( "Verify: OK! \n" );
761 printf( "Verify: Error\n" );
765 // move the filepointer to the beginning
767 rc
=pFile
->setPos( osl_Pos_Absolut
, 0 );
768 print_error( rtl::OString( "Set FilePointer to the beginning of the file" ), rc
);
774 pReadBuffer
=(sal_Char
*) rtl_allocateMemory( (sal_uInt32
)(nLen
+1)*sizeof(sal_Char
) );
775 memset( pReadBuffer
, 0, (sal_uInt32
)(nLen
+1)*sizeof(sal_Char
) );
776 rc
=pFile
->read( pReadBuffer
, nLen
,uRead
);
777 print_error( rtl::OString( "Read File" ), rc
);
779 if (strcmp(pWriteBuffer
, pReadBuffer
)==0)
781 printf( "Verify: OK !\n" );
782 printf( "Text: %s\n",pReadBuffer
);
785 printf( "Verify: Error\n" );
787 rtl_freeMemory( pReadBuffer
);
793 print_error( rtl::OString( "Close File" ), rc
);
796 rc
=pFile
->remove( file_not_exist
);
797 print_error( rtl::OString( "Remove File" ), rc
);
807 void FileCopyAndMoveTest()
811 printf( "--------------------------------------------\n" );
812 printf( "File-Copy-Move-Test\n" );
813 printf( "--------------------------------------------\n\n" );
816 rtl::OUString
destPath(dir2
);
820 destPath
+=rtl::OUString("/");
823 printf( "Copy the file ");
824 printFileName( file1
);
826 printFileName( destPath
);
829 rc
=File::copy( file1
, destPath
);
830 print_error( rtl::OString( "FileCopy" ), rc
);
832 pFile
=new File( destPath
);
834 rc
=pFile
->open( osl_File_OpenFlag_Read
);
835 if ( rc
== FileBase::E_None
)
837 printf( "Verify: OK!\n" );
839 File::remove( destPath
);
842 printf( "Verify: Error!\n" );
848 // Copy a file to a not existing directory
850 destPath
=rtl::OUString( dir_not_exist
);
851 destPath
+=rtl::OUString("/");
854 printf( "Copy a file to a not existing directory \n");
855 printf( "Copy the file %s to %s\n",
856 rtl::OUStringToOString( file1
, RTL_TEXTENCODING_ASCII_US
).getStr(),
857 rtl::OUStringToOString( destPath
, RTL_TEXTENCODING_ASCII_US
).getStr() );
859 rc
=File::copy( file1
, destPath
);
860 print_error( rtl::OString( "FileCopy" ), rc
);
866 printf( "Copy the directory: ");
867 printFileName( dir1
);
869 printFileName( dir2
);
872 rc
=File::copy( dir1
, dir2
);
873 print_error( rtl::OString( "FileCopy" ), rc
);
879 destPath
=rtl::OUString( dir2
);
880 destPath
+=rtl::OUString("/");
883 printf( "Move the file ");
884 printFileName( file1
);
886 printFileName( destPath
);
889 rc
=File::move( file1
, destPath
);
890 print_error( rtl::OString( "FileMove" ), rc
);
892 pFile
=new File( destPath
);
894 rc
=pFile
->open( osl_File_OpenFlag_Read
);
895 if ( rc
==FileBase::E_None
)
900 pFile
=new File( file1
);
902 rc
=pFile
->open( osl_File_OpenFlag_Read
);
904 if ( rc
!=FileBase::E_None
)
906 printf( "Verify: OK!\n" );
907 File::move( destPath
, file1
);
911 printf( "Verify: Error!\n" );
913 File::remove( destPath
);
917 printf( "Verify: Error!\n" );
923 // Move a file to a not existing directory
925 destPath
=rtl::OUString( dir_not_exist
);
926 destPath
+=rtl::OUString("/");
929 printf( "Move a file to a not existing directory: \n");
930 printf( "Move the file ");
931 printFileName( file1
);
933 printFileName( destPath
);
936 rc
=File::move( file1
, destPath
);
937 print_error( rtl::OString( "FileMove" ), rc
);
943 printf( "Move a directory: \n");
945 printf( "Move the directory ");
946 printFileName( dir1
);
948 printFileName( dir_not_exist
);
951 rc
=File::move( dir1
, dir_not_exist
);
952 print_error( rtl::OString( "FileMove" ), rc
);
954 if ( rc
== FileBase::E_None
)
955 File::move( dir_not_exist
, dir1
);
971 printf( "--------------------------------------------\n" );
972 printf( "File-Size-Test\n" );
973 printf( "--------------------------------------------\n\n" );
975 File
aFile( file_not_exist
);
977 printf( "Create File: ");
978 printFileName( file_not_exist
);
981 rc
= aFile
.open( osl_File_OpenFlag_Read
| osl_File_OpenFlag_Write
| osl_File_OpenFlag_Create
);
982 print_error( rtl::OString( "Create and Open File (Read & Write)" ), rc
);
985 if ( rc
== FileBase::E_None
)
988 // Set Filesize to 5000
990 printf( "Set FileSize to 5000\n" );
991 rc
=aFile
.setSize( 5000 );
992 print_error( rtl::OString( "Set FileSize" ), rc
);
995 printf( "Verify:\n" );
997 // Check whether Filesize is set to 5000
999 rc
=DirectoryItem::get( file_not_exist
, aItem
);
1000 print_error( rtl::OString( "Get DirectoryItem" ), rc
);
1002 if ( rc
== FileBase::E_None
)
1004 FileStatus
rStatus( osl_FileStatus_Mask_FileSize
);
1005 rc
=aItem
.getFileStatus( rStatus
);
1006 print_error( rtl::OString( "Get FileStatus" ), rc
);
1008 if ( rc
== FileBase::E_None
)
1010 filesize
=rStatus
.getFileSize();
1012 if ( filesize
== 5000 )
1013 printf( "\nOK : FileSize: %" SAL_PRIuUINT64
"\n", filesize
);
1015 printf( "\nError : FileSize: %" SAL_PRIuUINT64
"\n", filesize
);
1021 // Set Filesize to -1
1023 printf( "Set FileSize to -1\n" );
1024 rc
=aFile
.setSize( -1 );
1025 print_error( rtl::OString( "Set FileSize" ), rc
);
1031 print_error( rtl::OString( "Close File" ), rc
);
1034 rc
=File::remove( file_not_exist
);
1035 print_error( rtl::OString( "Remove File" ), rc
);
1045 void FilePointerTest()
1048 sal_uInt64 filepointer
;
1050 printf( "--------------------------------------------\n" );
1051 printf( "File-Pointer-Test\n" );
1052 printf( "--------------------------------------------\n\n" );
1054 File
rFile( file_not_exist
);
1056 printf( "Create File: ");
1057 printFileName( file_not_exist
);
1060 rc
= rFile
.open( osl_File_OpenFlag_Read
| osl_File_OpenFlag_Write
| osl_File_OpenFlag_Create
);
1061 print_error( rtl::OString( "Create and Open File (Read & Write) "), rc
);
1064 if ( rc
==FileBase::E_None
)
1067 // get the position of the filepointer
1069 rc
=rFile
.getPos( filepointer
);
1070 print_error( rtl::OString( "GetPos" ), rc
);
1071 printf( "Position of the FilePointer: %" SAL_PRIuUINT64
"\n", filepointer
);
1075 // set the filepointer at the end of a file
1077 printf( "Set FileSize to 5000\n" );
1078 rFile
.setSize( 5000 );
1080 printf( "Set the FilePointer at the end of the file (5000)\n" );
1081 rc
=rFile
.setPos( osl_Pos_End
,0 );
1082 print_error( rtl::OString( "SetPos" ), rc
);
1084 rc
=rFile
.getPos( filepointer
);
1086 if ( filepointer
==5000 )
1088 print_error( rtl::OString( "GetPos" ), rc
);
1089 printf( "\nVerify: OK !\n" );
1090 printf( "Filepointer-Position: %" SAL_PRIuUINT64
"\n",filepointer
);
1094 print_error( rtl::OString( "GetPos" ), rc
);
1095 printf( "\nFilePointer-Test: Error\n" );
1096 printf( "Filepointer-Position: %" SAL_PRIuUINT64
" != 5000 \n",filepointer
);
1103 print_error( rtl::OString( "Close File" ), rc
);
1106 rc
=File::remove( file_not_exist
);
1107 print_error( rtl::OString( "Remove File" ), rc
);
1115 // FileAttributesTest
1117 void verifyFileAttributes()
1120 DirectoryItem aItem
;
1121 FileStatus
rStatus( osl_FileStatus_Mask_Attributes
);
1123 printf( "\nVerify:\n" );
1125 rc
=DirectoryItem::get( file1
, aItem
);
1127 if ( rc
==FileBase::E_None
)
1129 rc
=aItem
.getFileStatus( rStatus
);
1131 if ( rc
==FileBase::E_None
)
1133 sal_uInt64 uAttributes
=rStatus
.getAttributes();
1134 showAttributes(uAttributes
);
1138 print_error( rtl::OString( "Get FileStatus" ), rc
);
1141 print_error( rtl::OString( "Get DirectoryItem" ), rc
);
1147 void FileAttributesTest()
1151 printf( "--------------------------------------------\n" );
1152 printf( "File-Attributes-Test\n" );
1153 printf( "--------------------------------------------\n\n" );
1156 printFileName( file1
);
1159 rc
=File::setAttributes( file1
, osl_File_Attribute_GrpWrite
);
1160 print_error( rtl::OString( "Set Attribute: GrpWrite" ), rc
);
1162 verifyFileAttributes();
1164 rc
=File::setAttributes( file1
, 0 );
1165 if ( rc
!=FileBase::E_None
)
1166 print_error( rtl::OString( "Reset Attributes" ), rc
);
1168 rc
=File::setAttributes( file1
, osl_File_Attribute_GrpRead
);
1169 print_error( rtl::OString( "Set Attribute: GrpRead" ), rc
);
1171 verifyFileAttributes();
1173 rc
=File::setAttributes( file1
, 0 );
1174 if ( rc
!=FileBase::E_None
)
1175 print_error( rtl::OString( "Reset Attributes" ), rc
);
1177 rc
=File::setAttributes( file1
, osl_File_Attribute_GrpExe
);
1178 print_error( rtl::OString( "Set Attribute: GrpExe" ), rc
);
1180 verifyFileAttributes();
1182 rc
=File::setAttributes( file1
, 0 );
1183 if ( rc
!=FileBase::E_None
)
1184 print_error( rtl::OString( "Reset Attributes" ), rc
);
1186 rc
=File::setAttributes( file1
, osl_File_Attribute_OwnWrite
);
1187 print_error( rtl::OString( "Set Attribute: OwnWrite" ), rc
);
1189 verifyFileAttributes();
1191 rc
=File::setAttributes( file1
, 0 );
1192 if ( rc
!=FileBase::E_None
)
1193 print_error( rtl::OString( "Reset Attributes" ), rc
);
1195 rc
=File::setAttributes( file1
, osl_File_Attribute_OwnRead
);
1196 print_error( rtl::OString( "Set Attribute: OwnRead" ), rc
);
1198 verifyFileAttributes();
1200 rc
=File::setAttributes( file1
, 0 );
1201 if ( rc
!=FileBase::E_None
)
1202 print_error( rtl::OString( "Reset Attributes" ), rc
);
1204 rc
=File::setAttributes( file1
, osl_File_Attribute_OwnExe
);
1205 print_error( rtl::OString( "Set Attribute: OwnExe" ), rc
);
1207 verifyFileAttributes();
1209 rc
=File::setAttributes( file1
, 0 );
1210 if ( rc
!=FileBase::E_None
)
1211 print_error( rtl::OString( "Reset Attributes" ), rc
);
1213 rc
=File::setAttributes( file1
, osl_File_Attribute_OthWrite
);
1214 print_error( rtl::OString( "Set Attribute: OthWrite" ), rc
);
1216 verifyFileAttributes();
1218 rc
=File::setAttributes( file1
, 0 );
1219 if ( rc
!=FileBase::E_None
)
1220 print_error( rtl::OString( "Reset Attributes" ), rc
);
1222 rc
=File::setAttributes( file1
, osl_File_Attribute_OthRead
);
1223 print_error( rtl::OString( "Set Attribute: OthRead" ), rc
);
1225 verifyFileAttributes();
1227 rc
=File::setAttributes( file1
, 0 );
1228 if ( rc
!=FileBase::E_None
)
1229 print_error( rtl::OString( "Reset Attributes" ), rc
);
1231 rc
=File::setAttributes( file1
, osl_File_Attribute_OthExe
);
1232 print_error( rtl::OString( "Set Attribute: OthExe" ), rc
);
1234 verifyFileAttributes();
1236 rc
=File::setAttributes( file1
, 0 );
1237 if ( rc
!=FileBase::E_None
)
1238 print_error( rtl::OString( "Reset Attributes" ), rc
);
1240 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
);
1241 print_error( rtl::OString( "Set all Attributes" ), rc
);
1243 verifyFileAttributes();
1252 void FileAttributesTest()
1256 printf( "--------------------------------------------\n" );
1257 printf( "File-Attributes-Test\n" );
1258 printf( "--------------------------------------------\n\n" );
1261 printFileName( file1
);
1264 rc
=File::setAttributes( file1
, osl_File_Attribute_ReadOnly
);
1265 print_error( rtl::OString( "Set Attribute: ReadOnly" ), rc
);
1267 verifyFileAttributes();
1269 rc
=File::setAttributes( file1
, 0 );
1270 print_error( rtl::OString( "Reset Attributes" ), rc
);
1272 verifyFileAttributes();
1274 rc
=File::setAttributes( file1
, osl_File_Attribute_Hidden
);
1275 print_error( rtl::OString( "Set Attribute: Hidden" ), rc
);
1277 verifyFileAttributes();
1279 rc
=File::setAttributes( file1
, 0 );
1280 print_error( rtl::OString( "Reset Attributes" ), rc
);
1282 verifyFileAttributes();
1284 rc
=File::setAttributes( file1
, osl_File_Attribute_Hidden
| osl_File_Attribute_ReadOnly
);
1285 print_error( rtl::OString( "Set Attribute: Hidden & ReadOnly" ), rc
);
1287 verifyFileAttributes();
1289 rc
=File::setAttributes( file1
, 0 );
1290 print_error( rtl::OString( "Reset Attributes") , rc
);
1292 verifyFileAttributes();
1306 DirectoryItem aItem
;
1308 struct tm sSysCreationTime
;
1309 sSysCreationTime
.tm_sec
= 0;
1310 sSysCreationTime
.tm_min
= 20;
1311 sSysCreationTime
.tm_hour
= 12;
1312 sSysCreationTime
.tm_mday
= 4;
1313 sSysCreationTime
.tm_mon
= 9;
1314 sSysCreationTime
.tm_year
= 99;
1316 struct tm sSysAccessTime
;
1317 sSysAccessTime
.tm_sec
= 0;
1318 sSysAccessTime
.tm_min
= 40;
1319 sSysAccessTime
.tm_hour
= 1;
1320 sSysAccessTime
.tm_mday
= 6;
1321 sSysAccessTime
.tm_mon
= 5;
1322 sSysAccessTime
.tm_year
= 98;
1324 struct tm sSysModifyTime
;
1325 sSysModifyTime
.tm_sec
= 0;
1326 sSysModifyTime
.tm_min
= 1;
1327 sSysModifyTime
.tm_hour
= 24;
1328 sSysModifyTime
.tm_mday
= 13;
1329 sSysModifyTime
.tm_mon
= 11;
1330 sSysModifyTime
.tm_year
= 95;
1332 sal_uInt32 aSysCreationTime
= mktime( &sSysCreationTime
);
1333 sal_uInt32 aSysAccessTime
= mktime( &sSysAccessTime
);
1334 sal_uInt32 aSysModifyTime
= mktime( &sSysModifyTime
);
1336 TimeValue aCreationTime
= { aSysCreationTime
, 0};
1337 TimeValue aAccessTime
= { aSysAccessTime
, 0};
1338 TimeValue aModifyTime
= { aSysModifyTime
, 0};
1340 TimeValue aCreationTimeRead
;
1341 TimeValue aAccessTimeRead
;
1342 TimeValue aModifyTimeRead
;
1344 printf( "--------------------------------------------\n" );
1345 printf( "File-Time-Test\n" );
1346 printf( "--------------------------------------------\n\n" );
1349 printFileName( file1
);
1352 printf( "CreationTime \t : ");
1353 showTime( aCreationTime
);
1355 printf( "\nAccessTime \t : ");
1356 showTime( aAccessTime
);
1358 printf( "\nModifyTime \t : ");
1359 showTime( aModifyTime
);
1364 rc
=File::setTime( file1
, aCreationTime
, aAccessTime
, aModifyTime
);
1365 print_error( rtl::OString( "SetTime" ), rc
);
1369 FileStatus
rStatus( osl_FileStatus_Mask_CreationTime
| osl_FileStatus_Mask_AccessTime
| osl_FileStatus_Mask_ModifyTime
);
1371 printf( "\nVerify:\n" );
1373 rc
=DirectoryItem::get( file1
, aItem
);
1374 print_error( rtl::OString( "Get DirectoryItem" ), rc
);
1376 if ( rc
==FileBase::E_None
)
1378 rc
=aItem
.getFileStatus( rStatus
);
1379 print_error( rtl::OString( "Get FileStatus" ), rc
);
1382 if ( rc
==FileBase::E_None
)
1387 aCreationTimeRead
=rStatus
.getCreationTime();
1389 if ( aCreationTime
.Seconds
== aCreationTimeRead
.Seconds
&& aCreationTime
.Nanosec
== aCreationTimeRead
.Nanosec
)
1390 printf( "GetCreationTime: ok : " );
1392 printf( "GetCreationTime: Error : " );
1394 showTime( aCreationTimeRead
);
1400 aAccessTimeRead
=rStatus
.getAccessTime();
1402 if ( aAccessTime
.Seconds
== aAccessTimeRead
.Seconds
&& aAccessTime
.Nanosec
== aAccessTimeRead
.Nanosec
)
1403 printf( "GetAccessTime: ok : " );
1405 printf( "GetAccessTime: Error : " );
1407 showTime( aAccessTimeRead
);
1412 aModifyTimeRead
=rStatus
.getModifyTime();
1414 if ( aModifyTime
.Seconds
== aModifyTimeRead
.Seconds
&& aModifyTime
.Nanosec
== aModifyTimeRead
.Nanosec
)
1415 printf( "GetModifyTime: ok : " );
1417 printf( "GetModifyTime: Error : " );
1419 showTime( aModifyTimeRead
);
1428 // DirectoryItemTest
1430 void DirectoryItemTest()
1434 DirectoryItem aItem
;
1435 FileStatus
*pStatus
;
1438 printf( "--------------------------------------------\n" );
1439 printf( "Directory-Item-Test\n" );
1440 printf( "--------------------------------------------\n\n" );
1442 // get DirectoryItem from an existing directory
1444 printf( "Get DirectoryItem from an existing Directory: ");
1445 printFileName( dir1
);
1448 rc
=DirectoryItem::get( dir1
, aItem
);
1449 print_error( rtl::OString( "GetDirectoryItem" ), rc
);
1451 pStatus
=new FileStatus( osl_FileStatus_Mask_All
);
1452 rc
=aItem
.getFileStatus( *pStatus
);
1454 if ( rc
==FileBase::E_None
)
1456 printf( "GetFileStatus: FileURL: ");
1457 printFileName(pStatus
->getFileURL() );
1465 // get DirectoryItem from a not existing directory
1467 printf( "Get DirectoryItem from a not existing Directory: ");
1468 printFileName( dir_not_exist
);
1471 rc
=DirectoryItem::get( dir_not_exist
, aItem
);
1472 print_error( rtl::OString( "Get DirectoryItem" ), rc
);
1476 // get DirectoryItem from an existing file
1478 printf( "Get DirectoryItem from an existing File: ");
1479 printFileName( file1
);
1482 rc
=DirectoryItem::get( file1
, aItem
);
1483 print_error( rtl::OString( "GetDirectoryItem" ), rc
);
1485 pStatus
=new FileStatus( osl_FileStatus_Mask_All
);
1486 rc
=aItem
.getFileStatus( *pStatus
);
1488 if ( rc
==FileBase::E_None
)
1490 printf( "GetFileStatus: FileURL: ");
1491 printFileName( pStatus
->getFileURL() );
1499 // get DirectoryItem from a not existing file
1501 printf( "Get DirectoryItem from a not existing File: ");
1502 printFileName( file_not_exist
);
1505 rc
=DirectoryItem::get( file_not_exist
, aItem
);
1506 print_error( rtl::OString( "Get DirectoryItem" ), rc
);
1510 // get DirectoryItem from a directory with a wrong semantic
1512 printf( "Get DirectoryItem from a Directory with a wrong semantic: ");
1513 printFileName( dir_not_exist
);
1516 rc
=DirectoryItem::get( dir_wrong_semantic
, aItem
);
1517 print_error( rtl::OString( "Get DirectoryItem" ),rc
);
1521 // get DirectoryItem from a file-handle
1523 pFile
=new File( file1
);
1525 rc
=pFile
->open( osl_File_OpenFlag_Read
);
1526 if ( rc
==FileBase::E_None
)
1528 printf( "Get DirectoryItem from a File-Handle: ");
1529 printFileName( file1
);
1532 rc
=DirectoryItem::get( file1
, aItem
);
1533 print_error( rtl::OString( "GetDirectoryItem" ), rc
);
1535 pStatus
=new FileStatus( osl_FileStatus_Mask_All
);
1536 rc
=aItem
.getFileStatus( *pStatus
);
1538 if ( rc
==FileBase::E_None
)
1540 printf( "GetFileStatus: FileURL: ");
1541 printFileName( pStatus
->getFileURL() );
1554 // get DirectoryItem
1556 printf( "Get DirectoryItem from an empty File-Handle\n" );
1557 rc
=DirectoryItem::get( file1
, aItem
);
1558 print_error( rtl::OString( "GetDirectoryItem" ), rc
);
1562 // GetNextItem from a directory
1564 pDir
=new Directory( dir1
);
1565 printf( "Get next DirectoryItem from a directory: ");
1566 printFileName( dir1
);
1570 print_error( rtl::OString( "Open Directory" ), rc
);
1574 if ( pDir
->isOpen() )
1577 // get all files from the directory
1580 rtl::OUString str1
[2];
1582 aItem
=DirectoryItem();
1583 rc
=pDir
->getNextItem( aItem
);
1584 print_error( rtl::OString( "GetNextItem" ),rc
);
1586 while( rc
==FileBase::E_None
)
1589 FileStatus
rStatus( osl_FileStatus_Mask_All
);
1590 aItem
.getFileStatus( rStatus
);
1592 str
=rStatus
.getFileName();
1593 printf( "Filename: ");
1594 printFileName( str
);
1597 aItem
=DirectoryItem();
1598 rc
=pDir
->getNextItem( aItem
);
1599 print_error( rtl::OString( "GetNextItem" ),rc
);
1606 for (int i
=0; i
<2; i
++)
1608 aItem
=DirectoryItem();
1610 rc
=pDir
->getNextItem( aItem
);
1612 FileStatus
rStatus( osl_FileStatus_Mask_All
);
1613 aItem
.getFileStatus( rStatus
);
1615 str1
[i
]=rStatus
.getFileName();
1618 if ( str1
[0] == str1
[1] )
1619 print_error( rtl::OString( "Reset" ),FileBase::E_None
);
1621 print_error( rtl::OString( "Reset" ),FileBase::E_invalidError
);
1627 print_error( rtl::OString( "Close Directory" ), rc
);
1632 // GetNextItem from a closed directory
1634 printf( "Get next DirectoryItem from a closed directory: ");
1635 printFileName( dir1
);
1638 aItem
=DirectoryItem();
1639 rc
=pDir
->getNextItem( aItem
);
1640 print_error( rtl::OString( "GetNextItem" ),rc
);
1648 // FileStatusTest (for different types)
1650 void FileStatusTest( FileStatus
*pStatus
)
1653 // GetFileType of the directory
1655 FileStatus::Type aType
;
1657 printf( "\ngetFileType:\n" );
1658 aType
=pStatus
->getFileType();
1659 showFileType( aType
);
1663 sal_uInt64 uAttributes
;
1665 printf( "\ngetAttributes:\n" );
1666 uAttributes
=pStatus
->getAttributes();
1667 showAttributes( uAttributes
);
1671 TimeValue aCreationTime
;
1673 printf( "\ngetCreationTime:\n" );
1674 aCreationTime
=pStatus
->getCreationTime();
1676 printf( "CreationTime: " );
1677 showTime( aCreationTime
);
1681 TimeValue aAccessTime
;
1683 printf( "\ngetAccessTime:\n" );
1684 aAccessTime
=pStatus
->getAccessTime();
1686 printf( "AccessTime: " );
1687 showTime( aAccessTime
);
1691 TimeValue aModifyTime
;
1693 printf( "\ngetModifyTime:\n" );
1694 aModifyTime
=pStatus
->getModifyTime();
1696 printf( "ModifyTime: " );
1697 showTime( aModifyTime
);
1701 sal_uInt64 FileSize
;
1703 printf( "\ngetFileSize:\n" );
1705 FileSize
=pStatus
->getFileSize();
1706 printf( "FileSize: %" SAL_PRIuUINT64
"\n", FileSize
);
1710 rtl::OUString FileName
;
1712 printf( "\ngetFileName:\n" );
1714 FileName
=pStatus
->getFileName();
1715 printf( "FileName: ");
1716 printFileName( FileName
);
1721 rtl::OUString FileURL
;
1723 printf( "\ngetFileURL:\n" );
1725 FileURL
=pStatus
->getFileURL();
1726 printf( "FileURL: ");
1727 printFileName( FileURL
);
1732 rtl::OUString LinkTargetURL
;
1734 printf( "\ngetLinkTargetURL:\n");
1736 LinkTargetURL
=pStatus
->getLinkTargetURL();
1737 printf( "LinkTargetURL: ");
1738 printFileName( LinkTargetURL
);
1744 // DirectoryFileStatusTest
1746 void DirectoryFileStatusTest()
1749 DirectoryItem aItem
;
1751 printf( "--------------------------------------------\n" );
1752 printf( "Directory-FileStatus-Test\n" );
1753 printf( "--------------------------------------------\n\n" );
1755 printf( "FileStatus of the directory: ");
1756 printFileName( dir1
);
1759 aItem
=DirectoryItem();
1761 rc
=DirectoryItem::get( dir1
, aItem
);
1762 print_error( rtl::OString( "Get DirectoryItem" ), rc
);
1764 if ( rc
==FileBase::E_None
)
1766 FileStatus
*pStatus
=new FileStatus( osl_FileStatus_Mask_All
);
1767 rc
=aItem
.getFileStatus( *pStatus
);
1769 FileStatusTest( pStatus
);
1780 // FileFileStatusTest
1782 void FileFileStatusTest()
1785 DirectoryItem aItem
;
1787 printf( "--------------------------------------------\n" );
1788 printf( "File-FileStatus-Test\n" );
1789 printf( "--------------------------------------------\n\n" );
1791 printf( "FileStatus of the file: ");
1792 printFileName( file1
);
1795 aItem
=DirectoryItem();
1797 rc
=DirectoryItem::get( file1
, aItem
);
1798 print_error( rtl::OString( "Get DirectoryItem" ), rc
);
1800 if ( rc
==FileBase::E_None
)
1802 FileStatus
*pStatus
=new FileStatus( osl_FileStatus_Mask_All
);
1803 rc
=aItem
.getFileStatus( *pStatus
);
1805 FileStatusTest( pStatus
);
1816 // VolumeFileStatusTest
1818 void VolumeFileStatusTest()
1821 DirectoryItem aItem
;
1823 printf( "--------------------------------------------\n" );
1824 printf( "Volume-FileStatus-Test\n" );
1825 printf( "--------------------------------------------\n\n" );
1827 printf( "FileStatus of the Volume: ");
1828 printFileName( root
);
1831 aItem
=DirectoryItem();
1833 rc
=DirectoryItem::get( root
, aItem
);
1834 print_error( rtl::OString( "Get DirectoryItem" ), rc
);
1836 if ( rc
==FileBase::E_None
)
1838 FileStatus
*pStatus
=new FileStatus( osl_FileStatus_Mask_All
) ;
1839 rc
=aItem
.getFileStatus( *pStatus
);
1841 FileStatusTest( pStatus
);
1854 void VolumeInfoTest()
1858 printf( "--------------------------------------------\n" );
1859 printf( "Volume-Info-Test\n" );
1860 printf( "--------------------------------------------\n\n" );
1862 printf( "VolumeInfo of the volume ");
1863 printFileName( root
);
1867 VolumeInfo
rInfo( osl_VolumeInfo_Mask_FreeSpace
);
1868 rc
=Directory::getVolumeInfo( root
, rInfo
);
1869 print_error( rtl::OString( "GetVolumeInfo" ),rc
);
1875 if ( rInfo
.getRemoteFlag() )
1876 printf( "RemoteFlag: Yes\n" );
1878 printf( "RemoteFlag: No\n" );
1880 // getRemoveableFlag
1882 if ( rInfo
.getRemoveableFlag() )
1883 printf( "RemoveableFlag: Yes\n" );
1885 printf( "RemoveableFlag: No\n" );
1889 sal_uInt64 TotalSpace
;
1890 TotalSpace
=rInfo
.getTotalSpace();
1891 printf( "Total Space: %" SAL_PRIuUINT64
"\n",TotalSpace
);
1895 sal_uInt64 FreeSpace
;
1896 FreeSpace
=rInfo
.getFreeSpace();
1897 printf( "Free Space: %" SAL_PRIuUINT64
"\n",FreeSpace
);
1901 sal_uInt64 UsedSpace
;
1902 UsedSpace
=rInfo
.getUsedSpace();
1903 printf( "Used Space: %" SAL_PRIuUINT64
"\n",UsedSpace
);
1907 sal_uInt32 MaxNameLength
;
1908 MaxNameLength
=rInfo
.getMaxNameLength();
1909 printf( "MaxNameLength: %" SAL_PRIuUINT32
"\n",MaxNameLength
);
1913 sal_uInt32 MaxPathLength
;
1914 MaxPathLength
=rInfo
.getMaxPathLength();
1915 printf( "MaxPathLength: %" SAL_PRIuUINT32
"\n",MaxPathLength
);
1917 // getFileSystemName
1919 rtl::OUString FileSystemName
;
1920 FileSystemName
=rInfo
.getFileSystemName();
1921 printf( "File-System-Name: ");
1922 printFileName( FileSystemName
);
1931 void ConvertPathTest(rtl::OUString
& strPath
)
1935 rtl::OUString strNormPath
;
1936 rtl::OUString strFileURL
;
1937 rtl::OUString strNormPathFromFileURL
;
1938 rtl::OUString strSystemPath
;
1942 rc
=FileBase::getFileURLFromSystemPath( strPath
, strNormPath
);
1944 if ( rc
== FileBase::E_None
)
1946 printf( "Normalized Path: \t\t");
1947 printFileName( strNormPath
);
1951 printf( "normalizePath: Error \n" );
1953 // getFileURLFromSystemPath
1955 if ( !strNormPath
.isEmpty() )
1957 rc
=FileBase::getFileURLFromSystemPath( strNormPath
, strFileURL
);
1959 if ( rc
== FileBase::E_None
)
1961 printf( "File-URL: \t\t\t");
1962 printFileName( strFileURL
);
1966 printf( "getFileURLFromSystemPath: Error \n" );
1969 printf( "getFileURLFromSystemPath: not tested \n" );
1971 // getNormalizedPathFromFileURL
1973 if ( !strFileURL
.isEmpty() )
1975 rc
=FileBase::getSystemPathFromFileURL( strFileURL
, strNormPathFromFileURL
);
1977 if ( rc
== FileBase::E_None
)
1979 printf( "Normalized Path from File-URL: \t");
1980 printFileName( strNormPathFromFileURL
);
1984 printf( "getNormalizedPathFromFileURL: Error \n" );
1987 printf( "getNormalizedPathFromFileURL: not tested \n" );
1989 // getSystemPathFromFileURL
1991 if ( !strNormPath
.isEmpty() )
1993 rc
=FileBase::getSystemPathFromFileURL( strNormPath
, strSystemPath
);
1995 if ( rc
== FileBase::E_None
)
1997 printf( "System-Path: \t\t\t");
1998 printFileName( strSystemPath
);
2002 printf( "getSystemPathFromFileURL: Error \n" );
2005 printf( "getSystemPathFromFileURL: not tested \n" );
2009 if ( strNormPathFromFileURL
== strNormPath
)
2010 printf( "\nVerify: OK ! ( Normalized-Path == Normalized-Path-From-File-URL )\n" );
2012 printf( "\nVerify: Error ! ( Normalized-Path != Normalized-Path-From-File-URL )\n" );
2019 printf( "--------------------------------------------\n" );
2020 printf( "FileBase-Test\n" );
2021 printf( "--------------------------------------------\n\n" );
2023 // ConvertPath-Test (Local File)
2025 printf( "- Local File: ");
2026 printFileName( file1
);
2029 ConvertPathTest(file1
);
2031 // ConvertPath-Test (File on a server)
2033 printf( "\n- File on server: ");
2034 printFileName( file_on_server
);
2036 ConvertPathTest(file_on_server
);
2045 void DoAbsolutePathTest(rtl::OUString strDirBase
, rtl::OUString strRelative
)
2049 rtl::OUString strAbsolute
;
2051 printf( "Base-Directory: \t");
2052 printFileName( strDirBase
);
2054 printf( "Relative-Path: \t\t");
2055 printFileName ( strRelative
);
2058 rc
=FileBase::getAbsoluteFileURL( strDirBase
, strRelative
, strAbsolute
);
2060 if ( rc
== FileBase::E_None
)
2062 printf( "Absolute-Path: \t\t");
2063 printFileName ( strAbsolute
);
2067 printf( "Absolute-Path: Error \n" );
2073 void AbsolutePathTest()
2075 printf( "--------------------------------------------\n" );
2076 printf( "AbsolutePath-Test\n" );
2077 printf( "--------------------------------------------\n\n" );
2079 DoAbsolutePathTest(dir1
, rtl::OUString("."));
2080 DoAbsolutePathTest(dir1
, rtl::OUString(".."));
2081 DoAbsolutePathTest(dir1
, rtl::OUString("../.."));
2082 DoAbsolutePathTest(dir1
, rtl::OUString("../HUHU"));
2084 DoAbsolutePathTest(dir_on_server
, rtl::OUString("."));
2085 DoAbsolutePathTest(dir_on_server
, rtl::OUString(".."));
2086 DoAbsolutePathTest(dir_on_server
, rtl::OUString("../.."));
2087 DoAbsolutePathTest(dir_on_server
, rtl::OUString("../HUHU"));
2095 void SearchPathTest()
2099 rtl::OUString
strNormPath(file1
);
2100 rtl::OUString strFileURL
;
2101 rtl::OUString strSystemPath
;
2102 rtl::OUString strResultPath
;
2104 printf( "--------------------------------------------\n" );
2105 printf( "SearchPath-Test\n" );
2106 printf( "--------------------------------------------\n\n" );
2108 rc
=FileBase::getFileURLFromSystemPath( strNormPath
, strFileURL
);
2109 print_error( rtl::OString( "getFileURLFromSystemPath" ), rc
);
2110 rc
=FileBase::getSystemPathFromFileURL( strNormPath
, strSystemPath
);
2111 print_error( rtl::OString( "getSystemPathFromFileURL" ), rc
);
2113 // searchFileURL (with a normalized path)
2115 if ( !strNormPath
.isEmpty() )
2117 printf( "\nSearch-Normalized-Path (with a normalized path) : ");
2118 printFileName ( strNormPath
);
2121 rc
=FileBase::searchFileURL( strNormPath
, rtl::OUString() , strResultPath
);
2123 if ( rc
== FileBase::E_None
)
2125 printf( "Result: \t\t\t");
2126 printFileName ( strResultPath
);
2130 printf( "searchFileURL (with a normalized path): Error\n" );
2133 printf( "searchFileURL (with a normalized path): not tested\n" );
2135 // searchFileURL (with a File-URL)
2137 if ( !strFileURL
.isEmpty() )
2139 printf( "\nSearch-Normalized-Path (with a FileURL) : ");
2140 printFileName( strFileURL
);
2143 rc
=FileBase::searchFileURL( strFileURL
, rtl::OUString() , strResultPath
);
2145 if ( rc
== FileBase::E_None
)
2147 printf( "Result: \t\t\t");
2148 printFileName ( strResultPath
);
2152 printf( "searchFileURL (with a FileURL path): Error\n" );
2155 printf( "searchFileURL (with a FileURL path): not tested\n" );
2157 // searchFileURL (with a systempath)
2159 if ( !strSystemPath
.isEmpty() )
2161 printf( "\nSearch-Normalized-Path (with a SystemPath) : ");
2162 printFileName( strSystemPath
);
2165 rc
=FileBase::searchFileURL( strSystemPath
, rtl::OUString() , strResultPath
);
2167 if ( rc
== FileBase::E_None
)
2169 printf( "Result: \t\t\t");
2170 printFileName( strResultPath
);
2174 printf( "searchFileURL (with a systempath): Error\n" );
2177 printf( "searchFileURL (with a systempath): not tested\n" );
2179 // searchFileURL (File and no searchpath)
2181 printf( "\nsearchFileURL: File (no searchpath) : ");
2182 printFileName( file3
);
2185 rc
=FileBase::searchFileURL( file3
, rtl::OUString("") , strResultPath
);
2187 if ( rc
== FileBase::E_None
)
2189 printf( "Result: \t\t\t");
2190 printFileName( strResultPath
);
2194 printf( "searchFileURL: File not found: OK ! \n" );
2196 // searchFileURL (File and Path)
2198 printf( "\nsearchFileURL: File : ");
2199 printFileName( file3
);
2200 printf( "\tSearchPath ");
2201 printFileName( dir1
);
2204 rc
=FileBase::searchFileURL( file3
, dir1
, strResultPath
);
2206 if ( rc
== FileBase::E_None
)
2208 printf( "Result: \t\t\t");
2209 printFileName( strResultPath
);
2213 printf( "searchFileURL: File not found: Error\n" );
2215 // searchFileURL (File and searchpath with two entries)
2217 rtl::OUString
strSearchPath( dir_not_exist
);
2218 strSearchPath
+=rtl::OUString(";");
2219 strSearchPath
+=dir_on_server
;
2221 printf( "\nsearchFileURL: File : ");
2222 printFileName( file3
);
2223 printf( "SearchPath ");
2224 printFileName( strSearchPath
);
2227 rc
=FileBase::searchFileURL( file3
, strSearchPath
, strResultPath
);
2229 if ( rc
== FileBase::E_None
)
2231 printf( "Result: \t\t\t");
2232 printFileName( strResultPath
);
2236 printf( "searchFileURL: File not found: Error\n" );
2238 // searchFileURL (File and searchpath (with a wrong semantic))
2240 strSearchPath
=rtl::OUString( dir_wrong_semantic
);
2242 printf( "\nsearchFileURL: File : ");
2243 printFileName( file3
);
2244 printf( "SearchPath ");
2245 printFileName( strSearchPath
);
2248 rc
=FileBase::searchFileURL( file3
, strSearchPath
, strResultPath
);
2250 if ( rc
== FileBase::E_None
)
2251 printf( "Error: Wrong Semantich but no error occurs !\n" );
2253 printf( "searchFileURL: File not found: OK !\n" );
2258 // CanonicalNameTest
2260 void getCanonicalNameTest(rtl::OUString strPath
)
2264 rtl::OUString strValid
;
2266 printf( "Original-Name: \t\t");
2267 printFileName( strPath
);
2270 rc
=FileBase::getCanonicalName( strPath
, strValid
);
2272 if ( rc
== FileBase::E_None
)
2274 printf( "Canonical-Name: \t");
2275 printFileName( strValid
);
2280 printf( "Canonical-Name: Error \n" );
2286 void CanonicalNameTest()
2288 printf( "--------------------------------------------\n" );
2289 printf( "CanonicalName-Test\n" );
2290 printf( "--------------------------------------------\n\n" );
2292 getCanonicalNameTest( dir1
);
2293 getCanonicalNameTest( dir_on_server
);
2294 getCanonicalNameTest( file1
);
2295 getCanonicalNameTest( file_on_server
);
2303 void print_error( const ::rtl::OString
& str
, FileBase::RC rc
)
2306 printf( "%s : ", str
.getStr() );
2309 case FileBase::E_None
:
2312 case FileBase::E_PERM
:
2315 case FileBase::E_NOENT
:
2316 printf("E_NOENT\n");
2318 case FileBase::E_SRCH
:
2321 case FileBase::E_INTR
:
2324 case FileBase::E_IO
:
2327 case FileBase::E_NXIO
:
2330 case FileBase::E_2BIG
:
2333 case FileBase::E_NOEXEC
:
2334 printf("E_NOEXEC\n");
2336 case FileBase::E_BADF
:
2339 case FileBase::E_CHILD
:
2340 printf("E_CHILD\n");
2342 case FileBase::E_AGAIN
:
2343 printf("E_AGAIN\n");
2345 case FileBase::E_NOMEM
:
2346 printf("E_NOMEM\n");
2348 case FileBase::E_ACCES
:
2349 printf("E_ACCES\n");
2351 case FileBase::E_FAULT
:
2352 printf("E_FAULT\n");
2354 case FileBase::E_BUSY
:
2357 case FileBase::E_EXIST
:
2358 printf("E_EXIST\n");
2360 case FileBase::E_XDEV
:
2363 case FileBase::E_NODEV
:
2364 printf("E_NODEV\n");
2366 case FileBase::E_NOTDIR
:
2367 printf("E_NOTDIR\n");
2369 case FileBase::E_ISDIR
:
2370 printf("E_ISDIR\n");
2372 case FileBase::E_INVAL
:
2373 printf("E_INVAL\n");
2375 case FileBase::E_NFILE
:
2376 printf("E_NFILE\n");
2378 case FileBase::E_MFILE
:
2379 printf("E_MFILE\n");
2381 case FileBase::E_NOTTY
:
2382 printf("E_NOTTY\n");
2384 case FileBase::E_FBIG
:
2387 case FileBase::E_NOSPC
:
2388 printf("E_NOSPC\n");
2390 case FileBase::E_SPIPE
:
2391 printf("E_SPIPE\n");
2393 case FileBase::E_ROFS
:
2396 case FileBase::E_MLINK
:
2397 printf("E_MLINK\n");
2399 case FileBase::E_PIPE
:
2402 case FileBase::E_DOM
:
2405 case FileBase::E_RANGE
:
2406 printf("E_RANGE\n");
2408 case FileBase::E_DEADLK
:
2409 printf("E_DEADLK\n");
2411 case FileBase::E_NAMETOOLONG
:
2412 printf("E_NAMETOOLONG\n");
2414 case FileBase::E_NOLCK
:
2415 printf("E_NOLCK\n");
2417 case FileBase::E_NOSYS
:
2418 printf("E_NOSYS\n");
2420 case FileBase::E_NOTEMPTY
:
2421 printf("E_NOTEMPTY\n");
2423 case FileBase::E_LOOP
:
2426 case FileBase::E_ILSEQ
:
2427 printf("E_ILSEQ\n");
2429 case FileBase::E_NOLINK
:
2430 printf("E_NOLINK\n");
2432 case FileBase::E_MULTIHOP
:
2433 printf("E_MULTIHOP\n");
2435 case FileBase::E_USERS
:
2436 printf("E_USERS\n");
2438 case FileBase::E_OVERFLOW
:
2439 printf("E_OVERFLOW\n");
2442 printf("E_Unknown\n");
2451 #define MAIN _cdecl main
2456 int MAIN( int argc
, char* argv
[] )
2458 sal_Bool fSuccess
=sal_False
;
2461 fSuccess
=Initialize();
2464 printf("Error during Initialization");
2470 DirectoryOpenAndCloseTest();
2471 DirectoryCreateAndRemoveTest();
2473 FileOpenAndCloseTest();
2474 FileCreateAndRemoveTest();
2475 FileWriteAndReadTest();
2476 FileCopyAndMoveTest();
2479 FileAttributesTest();
2481 DirectoryItemTest();
2482 DirectoryFileStatusTest();
2483 VolumeFileStatusTest();
2484 FileFileStatusTest();
2489 CanonicalNameTest();
2491 // command line arguments ?
2498 if (strcmp(argv
[i
], "doc")==0)
2499 DirectoryOpenAndCloseTest();
2500 else if (strcmp(argv
[i
], "dcr")==0)
2501 DirectoryCreateAndRemoveTest();
2502 else if (strcmp(argv
[i
], "foc")==0)
2503 FileOpenAndCloseTest();
2504 else if (strcmp(argv
[i
], "fcr")==0)
2505 FileCreateAndRemoveTest();
2506 else if (strcmp(argv
[i
], "fwr")==0)
2507 FileWriteAndReadTest();
2508 else if (strcmp(argv
[i
], "fcm")==0)
2509 FileCopyAndMoveTest();
2510 else if (strcmp(argv
[i
], "fs")==0)
2512 else if (strcmp(argv
[i
], "fp")==0)
2514 else if (strcmp(argv
[i
], "fa")==0)
2515 FileAttributesTest();
2516 else if (strcmp(argv
[i
], "ft")==0)
2518 else if (strcmp(argv
[i
], "di")==0)
2519 DirectoryItemTest();
2520 else if (strcmp(argv
[i
], "dfs")==0)
2521 DirectoryFileStatusTest();
2522 else if (strcmp(argv
[i
], "vfs")==0)
2523 VolumeFileStatusTest();
2524 else if (strcmp(argv
[i
], "ffs")==0)
2525 FileFileStatusTest();
2526 else if (strcmp(argv
[i
], "vi")==0)
2528 else if (strcmp(argv
[i
], "fb")==0)
2530 else if (strcmp(argv
[i
], "sp")==0)
2532 else if (strcmp(argv
[i
], "ap")==0)
2534 else if (strcmp(argv
[i
], "cn")==0)
2535 CanonicalNameTest();
2542 fSuccess
=Shutdown();
2545 printf("Error during Shutdown");
2552 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */