merged tag ooo/DEV300_m102
[LibreOffice.git] / sal / workben / testfile.cxx
blob8e3296a5aab531a8e0e5b5a8f562e62b71d351f9
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sal.hxx"
31 #define UNICODE
34 #include <osl/file.hxx>
35 #include <osl/process.h>
36 #include <osl/time.h>
37 #include <rtl/alloc.h>
38 #include <rtl/ustring.hxx>
39 #include <stdio.h>
40 #include <string.h>
41 #include <time.h>
44 #ifdef UNX
45 #include <wchar.h>
46 #endif
48 #ifdef WNT
49 #include <windows.h>
50 #endif
52 using namespace osl;
53 using namespace rtl;
55 #define MAXIMPATH 256
57 rtl::OUString root;
59 rtl::OUString dir1;
60 rtl::OUString dir2;
61 rtl::OUString dir_on_server;
62 rtl::OUString dir_not_exist;
63 rtl::OUString dir_not_exist_on_server;
64 rtl::OUString dir_wrong_semantic;
66 rtl::OUString file1;
67 rtl::OUString file2;
68 rtl::OUString file3;
69 rtl::OUString file_on_server;
70 rtl::OUString file_not_exist;
74 void print_error(::rtl::OString& str, FileBase::RC rc);
76 void PressKey()
78 printf("\nPress Return !\n");
79 int i=getchar();
82 void printFileName(::rtl::OUString& str)
84 rtl::OString aString;
86 aString = rtl::OUStringToOString( str, RTL_TEXTENCODING_ASCII_US );
88 printf( "%s", aString.getStr() );
90 return;
93 //--------------------------------------------------
94 // Initialization
95 //--------------------------------------------------
97 sal_Bool testLineBreak( sal_Char *pCount , sal_uInt64 nLen , sal_uInt32 *cLineBreak )
99 sal_Bool fSuccess=sal_False;
100 *cLineBreak=0;
102 if (nLen==0)
103 return fSuccess;
105 if ( *pCount==13 )
107 if (nLen>=1 && *(pCount+1)==10)
108 *cLineBreak=2;
109 else
110 *cLineBreak=1;
112 if (nLen>=2 && *(pCount+2)==10)
113 (*cLineBreak)++;
115 fSuccess=sal_True;
117 else if ( *pCount==10 )
119 *cLineBreak=1;
120 fSuccess=sal_True;
123 return fSuccess;
126 // Initialization
128 sal_Bool Initialize( void )
130 DirectoryItem aItem;
131 FileStatus aStatus( FileStatusMask_All );
132 rtl_uString *strExeFileURL=NULL;
133 oslProcessError ProcessError;
135 rtl::OUString iniFileURL;
136 File *pFile;
137 sal_Unicode *pExeFileCount;
139 FileBase::RC rc;
141 sal_uInt64 uBytesRequested;
142 sal_uInt64 uBytesRead;
143 sal_Char *pBuffer;
144 sal_Char *pBegin;
145 sal_Char *pCount;
147 rtl::OUString dir[12];
149 // Open to the ini-file
151 ProcessError=osl_getExecutableFile(&strExeFileURL);
153 if ( ProcessError == osl_Process_E_None)
155 pExeFileCount=rtl_uString_getStr(strExeFileURL)+rtl_uString_getLength(strExeFileURL);
157 // Search for the last slash in the Path
158 while (*pExeFileCount!=L'/' && pExeFileCount>rtl_uString_getStr(strExeFileURL))
159 pExeFileCount--;
161 // iniFileURL = strExeFileURL without the filename of the exe-File
162 iniFileURL=rtl::OUString( rtl_uString_getStr(strExeFileURL) ,(int) (pExeFileCount-rtl_uString_getStr(strExeFileURL)) );
164 // add "/testfile.ini" to iniFileURL
165 iniFileURL+=rtl::OUString::createFromAscii("/testfile.ini");
167 // Open the ini-File
168 pFile=new File( iniFileURL );
169 rc=pFile->open( OpenFlag_Read | OpenFlag_Write );
170 if ( rc!=FileBase::E_None )
172 rtl_uString_release(strExeFileURL);
173 return sal_False;
176 else
178 rtl_uString_release(strExeFileURL);
179 return sal_False;
182 // Get filesize of the ini-File
184 rc=DirectoryItem::get( iniFileURL, aItem );
185 if ( rc!=FileBase::E_None )
186 return sal_False;
188 rc=aItem.getFileStatus( aStatus );
189 if ( rc!=FileBase::E_None )
190 return sal_False;
192 uBytesRequested=aStatus.getFileSize();
194 // read ini-File
195 rc=pFile->setPos( Pos_Absolut, 0 );
196 pBuffer=(sal_Char*) rtl_allocateMemory( (sal_uInt32) (uBytesRequested+1)*sizeof(sal_Char) );
197 rtl_zeroMemory( pBuffer, (sal_uInt32)(uBytesRequested+1)*sizeof(sal_Char) );
199 rc=pFile->read( pBuffer , uBytesRequested , uBytesRead );
200 if ( rc!=FileBase::E_None )
201 return sal_False;
204 pBegin=pBuffer;
205 pCount=pBegin;
207 for ( int i=0 ; i<12 ; i++ )
209 sal_uInt32 cLineBrake=0;
210 while ( (pCount-pBuffer < uBytesRead) && *pCount!='=')
211 pCount++;
213 pCount++;
214 pBegin=pCount;
216 while ( (pCount-pBuffer < uBytesRead) && !testLineBreak(pCount,uBytesRead-(pCount-pBuffer), &cLineBrake))
217 pCount++;
219 dir[i]=rtl::OUString(pBegin, pCount-pBegin, RTL_TEXTENCODING_ASCII_US);
221 pCount+=cLineBrake;
222 pBegin=pCount;
225 root=rtl::OUString(dir[0]);
226 dir1=rtl::OUString(dir[1]);
227 dir2=rtl::OUString(dir[2]);
228 dir_on_server=rtl::OUString(dir[3]);
229 dir_not_exist=rtl::OUString(dir[4]);
230 dir_not_exist_on_server=rtl::OUString(dir[5]);
231 dir_wrong_semantic=rtl::OUString(dir[6]);
233 file1=rtl::OUString(dir[7]);
234 file2=rtl::OUString(dir[8]);
235 file3=rtl::OUString(dir[9]);
236 file_on_server=rtl::OUString(dir[10]);
237 file_not_exist=rtl::OUString(dir[11]);
239 // close the ini-file
240 rc=pFile->close();
242 rtl_freeMemory( pBuffer );
245 // Create directories
246 rc=Directory::create( dir1 );
247 if ( rc!=FileBase::E_None )
248 return sal_False;
250 rc=Directory::create( dir2 );
251 if ( rc!=FileBase::E_None )
252 return sal_False;
254 rc=Directory::create( dir_on_server );
255 if ( rc!=FileBase::E_None )
256 return sal_False;
258 pFile=new File( file1 );
259 rc=pFile->open( OpenFlag_Write | OpenFlag_Create );
260 if ( rc!=FileBase::E_None )
261 return sal_False;
262 rc=pFile->close();
263 delete pFile;
265 pFile=new File( file2 );
266 rc=pFile->open( OpenFlag_Write | OpenFlag_Create );
267 if ( rc!=FileBase::E_None )
268 return sal_False;
269 rc=pFile->close();
270 delete pFile;
272 pFile=new File( file_on_server );
273 rc=pFile->open( OpenFlag_Write | OpenFlag_Create );
274 if ( rc!=FileBase::E_None )
275 return sal_False;
276 rc=pFile->close();
277 delete pFile;
279 return sal_True;
282 //--------------------------------------------------
283 // Shutdown
284 //--------------------------------------------------
286 sal_Bool Shutdown( void )
288 sal_Bool fSuccess=sal_True;
289 FileBase::RC rc;
290 File *pFile;
292 // remove created files
294 pFile=new File( file1 );
295 rc=pFile->remove( file1 );
296 if ( rc!=FileBase::E_None )
297 fSuccess=sal_False;
298 delete pFile;
300 pFile=new File( file2 );
301 rc=pFile->remove( file2 );
302 if ( rc!=FileBase::E_None )
303 fSuccess=sal_False;
304 delete pFile;
306 // remove created directories
308 rc=Directory::remove( dir1 );
309 if ( rc!=FileBase::E_None )
310 fSuccess=sal_False;
312 rc=Directory::remove( dir2 );
313 if ( rc!=FileBase::E_None )
314 fSuccess=sal_False;
316 // remove created file on the server
318 pFile=new File( file_on_server );
319 rc=pFile->remove( file_on_server );
320 if ( rc!=FileBase::E_None )
321 fSuccess=sal_False;
322 delete pFile;
324 // remove created directory on the server
326 rc=Directory::remove( dir_on_server );
327 if ( rc!=FileBase::E_None )
328 fSuccess=sal_False;
330 return fSuccess;
333 //--------------------------------------------------
334 // helper functions
335 //--------------------------------------------------
337 // Show FileType
338 void showFileType( FileStatus::Type aType )
340 if ( aType==FileStatus::Directory )
341 printf( "FileType: Directory \n" );
342 else if ( aType==FileStatus::Volume )
343 printf( "FileType: Volume \n" );
344 else if ( aType==FileStatus::Regular )
345 printf( "FileType: Regular \n" );
346 else if ( aType==FileStatus::Unknown )
347 printf( "FileType: Unknown \n" );
351 // Show Attributes
352 void showAttributes( sal_uInt64 uAttributes )
354 if ( uAttributes==0 )
355 printf( "No Attributes \n" );
356 if ( uAttributes & Attribute_ReadOnly )
357 printf( "Attribute: ReadOnly \n" );
358 if ( uAttributes & Attribute_Hidden )
359 printf( "Attribute: Hidden \n" );
360 if ( uAttributes & Attribute_Executable )
361 printf( "Attribute: Executable \n");
362 if ( uAttributes & Attribute_GrpWrite )
363 printf( "Attribute: GrpWrite \n");
364 if ( uAttributes & Attribute_GrpRead )
365 printf( "Attribute: GrpRead \n" );
366 if ( uAttributes & Attribute_GrpExe )
367 printf( "Attribute: GrpExe \n" );
368 if ( uAttributes & Attribute_OwnWrite )
369 printf( "Attribute: OwnWrite \n");
370 if ( uAttributes & Attribute_OwnRead )
371 printf( "Attribute: OwnRead \n" );
372 if ( uAttributes & Attribute_OwnExe )
373 printf( "Attribute: OwnExe \n" );
374 if ( uAttributes & Attribute_OthWrite )
375 printf( "Attribute: OthWrite \n" );
376 if ( uAttributes & Attribute_OthRead )
377 printf( "Attribute: OthRead \n");
378 if ( uAttributes & Attribute_OthExe )
379 printf( "Attribute: OthExe \n" );
381 return;
384 // Show Time
385 void showTime( TimeValue aTime )
387 TimeValue aLocalTimeVal, aSystemTimeVal , aSysTimeVal;
388 oslDateTime aDateTime, aSystemTime;
390 if ( osl_getLocalTimeFromSystemTime( &aTime, &aLocalTimeVal ) )
392 if ( osl_getDateTimeFromTimeValue( &aLocalTimeVal, &aDateTime ) )
394 printf("\t%02i.%02i.%4i , %02i.%02i.%02i Uhr\n", aDateTime.Day, aDateTime.Month, aDateTime.Year, aDateTime.Hours, aDateTime.Minutes, aDateTime.Seconds);
396 else
397 printf("Error !\n");
400 if ( osl_getDateTimeFromTimeValue( &aTime, &aSystemTime ) )
402 printf("SystemTime: \t\t%02i.%02i.%4i , %02i.%02i.%02i Uhr\n", aSystemTime.Day, aSystemTime.Month, aSystemTime.Year, aSystemTime.Hours, aSystemTime.Minutes, aSystemTime.Seconds);
404 else
405 printf("Error !\n");
407 //Verify
409 if ( osl_getTimeValueFromDateTime( &aSystemTime, &aSystemTimeVal ) )
411 if ( ( aSystemTimeVal.Seconds == aTime.Seconds ) && ( aSystemTimeVal.Nanosec == aTime.Nanosec ))
412 printf ("Verify : TimeValue : ok! \n");
413 else
415 printf ("Verify : TimeValue : Error! \n");
416 printf ("aTime : %u \n", aTime.Seconds);
417 printf ("aSystemTimeVal : %u \n", aSystemTimeVal.Seconds);
420 else
421 printf ("Verify : TimeValue : Error! \n");
424 if ( osl_getSystemTimeFromLocalTime( &aLocalTimeVal , &aSysTimeVal ) )
426 if ( ( aSysTimeVal.Seconds == aTime.Seconds ) && ( aSysTimeVal.Nanosec == aTime.Nanosec ))
427 printf ("Verify : SystemTime : ok! \n");
428 else
430 printf ("Verify : SystemTime : Error! \n");
431 printf ("aTime : %u\n", aTime.Seconds);
432 printf ("aSystemTimeVal : %u\n", aSysTimeVal.Seconds);
435 else
436 printf ("Verify : SystemTime : Error! \n");
438 return;
441 TimeValue getSystemTime()
443 TimeValue aTime;
444 time_t ltime;
446 time( &ltime );
448 aTime.Seconds = ltime;
449 aTime.Nanosec = 0;
451 return aTime;
455 //--------------------------------------------------
456 // DirectoryOpenAndCloseTest
457 //--------------------------------------------------
459 void DirectoryOpenAndCloseTest( void )
461 FileBase::RC rc;
462 int i=0;
463 Directory *pDir;
465 printf( "--------------------------------------------\n");
466 printf( "Directory-Open-And-Close-Test\n");
467 printf( "--------------------------------------------\n\n");
469 //--------------------------------------------------
470 // open an existing directory
471 //--------------------------------------------------
473 pDir=new Directory( dir1 );
474 printf( "Open an existing directory: ");
475 printFileName( dir1 );
476 printf( "\n" );
478 rc= pDir->open();
479 print_error( rtl::OString( "Open Directory" ), rc );
481 if ( pDir->isOpen() )
483 print_error( rtl::OString( "Directory is Open" ), rc );
486 // Close Directory
487 rc=pDir->close();
488 print_error( rtl::OString( "Close Directory" ), rc );
490 delete pDir;
491 printf( "\n" );
493 //--------------------------------------------------
494 // open a not existing directory
495 //--------------------------------------------------
497 pDir=new Directory( dir_not_exist );
499 printf( "Open a not existing directory: ");
500 printFileName( dir_not_exist );
501 printf( "\n" );
503 rc= pDir->open();
505 print_error( rtl::OString( "Open Directory" ), rc );
507 delete pDir;
509 printf( "\n" );
511 //--------------------------------------------------
512 // open a directory with a wrong semantic
513 //--------------------------------------------------
514 pDir=new Directory( dir_wrong_semantic );
516 printf( "Open a directory with a wrong semantic: ");
517 printFileName( dir_wrong_semantic );
518 printf( "\n" );
520 rc= pDir->open();
521 print_error( rtl::OString( "Open Directory" ), rc );
523 delete pDir;
525 printf( "\n" );
527 //--------------------------------------------------
528 // open an existing directory on a server
529 //--------------------------------------------------
531 pDir=new Directory( dir_on_server );
533 printf( "Open an existing directory on a server: ");
534 printFileName( dir_on_server );
535 printf( "\n" );
537 rc= pDir->open();
538 print_error( rtl::OString( "Open Directory" ), rc );
540 // Close Directory
541 rc=pDir->close();
542 print_error( rtl::OString( "Close Directory" ), rc );
544 delete pDir;
545 printf( "\n" );
547 //--------------------------------------------------
548 // open a not existing directory on a server
549 //--------------------------------------------------
551 pDir=new Directory( dir_not_exist_on_server );
553 printf( "Open a not existing directory on a server: ");
554 printFileName( dir_not_exist_on_server );
555 printf( "\n" );
557 rc= pDir->open();
558 print_error( rtl::OString( "Open Directory" ), rc );
560 delete pDir;
561 printf( "\n" );
563 //--------------------------------------------------
564 // Close a not existing directory
565 //--------------------------------------------------
567 pDir=new Directory( dir_not_exist );
568 printf( "Close a not existing directory: ");
569 printFileName( dir_not_exist );
570 printf( "\n" );
572 rc=pDir->close();
573 print_error( rtl::OString( "Close Directory" ), rc );
575 PressKey();
576 return;
580 //--------------------------------------------------
581 // DirectoryCreateAndRemoveTest
582 //--------------------------------------------------
584 void DirectoryCreateAndRemoveTest( void )
586 FileBase::RC rc,rc1;
587 int i=0;
588 Directory *pDir;
590 printf( "--------------------------------------------\n" );
591 printf( "Directory-Create-And-Remove-Test\n" );
592 printf( "--------------------------------------------\n\n" );
594 //--------------------------------------------------
595 // Create directory
596 //--------------------------------------------------
597 printf( "Create a not existing directory: ");
598 printFileName( dir_not_exist );
599 printf( "\n" );
601 rc=Directory::create( dir_not_exist) ;
602 print_error( rtl::OString( "Create Directory" ), rc );
604 // Verify
605 pDir=new Directory( dir_not_exist );
607 rc= pDir->open();
608 print_error( rtl::OString( "Verify" ), rc );
609 pDir->close();
610 delete pDir;
612 printf( "\n" );
614 //--------------------------------------------------
615 // Create a directory on a server
616 //--------------------------------------------------
618 printf( "Create a not existing directory on a server: ");
619 printFileName( dir_not_exist_on_server );
620 printf( "\n" );
622 rc=Directory::create( dir_not_exist_on_server );
623 print_error( rtl::OString( "Create Directory" ), rc );
625 // Verify
626 pDir=new Directory( dir_not_exist_on_server );
627 rc= pDir->open();
628 print_error( rtl::OString( "Verify" ), rc );
629 pDir->close();
630 delete pDir;
632 printf( "\n" );
634 //--------------------------------------------------
635 // Remove Directories
636 //--------------------------------------------------
638 printf( "Remove the created directories: \n" );
640 rc=Directory::remove( dir_not_exist );
642 rc1=Directory::remove( dir_not_exist_on_server );
644 if ( rc==FileBase::E_None && rc1==FileBase::E_None )
645 print_error( rtl::OString( "Remove Directories" ), FileBase::E_None );
646 else if ( rc!=FileBase::E_None )
647 print_error( rtl::OString( "Remove local Directory" ),rc );
648 else
649 print_error( rtl::OString( "Remove Directory on a server" ),rc1 );
651 printf( "\n" );
653 //--------------------------------------------------
654 // Remove a not existing directory
655 //--------------------------------------------------
657 printf( "Remove a not existing directory: ");
658 printFileName( dir_not_exist );
659 printf( "\n" );
661 rc=Directory::remove( dir_not_exist );
662 print_error( rtl::OString( "Remove" ),rc );
664 PressKey();
665 return;
668 //--------------------------------------------------
669 // FileOpenAndCloseTest
670 //--------------------------------------------------
672 static void FileOpenAndCloseTest( void )
674 FileBase::RC rc;
675 int i=0;
677 printf( "--------------------------------------------\n" );
678 printf( "File-Open-And-Close-Test\n" );
679 printf( "--------------------------------------------\n\n" );
681 File *pFile;
683 pFile=new File( file1 );
685 printf( "Open an existing file: ");
686 printFileName( file1 );
687 printf( "\n" );
689 //--------------------------------------------------
690 // open an existing file (Read)
691 //--------------------------------------------------
693 rc=pFile->open( OpenFlag_Read );
694 print_error( rtl::OString( "Open File (Read)" ), rc );
696 //--------------------------------------------------
697 // close the file
698 //--------------------------------------------------
700 rc=pFile->close();
701 print_error( rtl::OString( "Close File" ), rc );
703 printf( "\n" );
705 //--------------------------------------------------
706 // open an existing file (Write)
707 //--------------------------------------------------
709 rc=pFile->open( OpenFlag_Write );
710 print_error( rtl::OString( "Open File (Write)" ), rc );
712 //--------------------------------------------------
713 // close the file
714 //--------------------------------------------------
716 rc=pFile->close();
717 print_error( rtl::OString( "Close File" ), rc );
719 printf( "\n" );
721 //--------------------------------------------------
722 // close the file a second time
723 //--------------------------------------------------
725 rc=pFile->close();
726 print_error( rtl::OString( "Close the file a second time" ), rc );
728 delete pFile;
729 PressKey();
732 //--------------------------------------------------
733 // FileCreateAndRemoveTest
734 //--------------------------------------------------
736 void FileCreateAndRemoveTest()
738 FileBase::RC rc;
739 File *pFile;
741 printf( "--------------------------------------------\n" );
742 printf( "File-Create-And-Remove-Test\n" );
743 printf( "--------------------------------------------\n\n" );
745 pFile=new File( file_not_exist );
747 printf( "Create File: ");
748 printFileName( file_not_exist );
749 printf( "\n" );
751 //----------------------------------------------------
752 // open (create) a not existing file (Read and write)
753 //----------------------------------------------------
755 rc = pFile->open( OpenFlag_Read | OpenFlag_Write | osl_File_OpenFlag_Create );
757 print_error( rtl::OString( "Create and Open File (Read & Write)" ), rc );
759 //----------------------------------------------------
760 // close the file
761 //----------------------------------------------------
763 rc=pFile->close();
764 print_error( rtl::OString( "Close File" ), rc );
766 //----------------------------------------------------
767 // remove the file
768 //----------------------------------------------------
770 rc=pFile->remove( file_not_exist );
771 print_error( rtl::OString(" Remove File" ), rc );
773 printf( "\n" );
775 //----------------------------------------------------
776 // remove the same file a second time
777 //----------------------------------------------------
778 rc=pFile->remove( file_not_exist );
779 print_error( rtl::OString( "Remove a not existing File" ), rc );
781 //----------------------------------------------------
782 // remove an open file
783 //----------------------------------------------------
785 pFile->open( OpenFlag_Read | OpenFlag_Write | osl_File_OpenFlag_Create );
787 rc=pFile->remove( file_not_exist );
788 print_error( rtl::OString( "Remove an open File" ), rc );
790 pFile->close();
791 pFile->remove( file_not_exist );
793 PressKey();
795 return;
798 //--------------------------------------------------
799 // FileWriteAndReadTest
800 //--------------------------------------------------
802 void FileWriteAndReadTest( void )
804 FileBase::RC rc;
806 sal_uInt64 uWritten;
807 sal_uInt64 uRead;
808 sal_Char *pWriteBuffer="Hier kommt der Osterhase !";
809 sal_uInt64 nLen=strlen( pWriteBuffer );
810 sal_Char *pReadBuffer;
812 printf( "--------------------------------------------\n" );
813 printf( "File-Write-And-Read-Test\n" );
814 printf( "--------------------------------------------\n\n" );
816 File *pFile;
818 pFile=new File( file_not_exist );
820 printf( "Create File: ");
821 printFileName( file_not_exist );
822 printf("\n");
824 //----------------------------------------------------
825 // open (create) a not existing file (Read and write)
826 //----------------------------------------------------
828 rc = pFile->open( OpenFlag_Read | OpenFlag_Write | osl_File_OpenFlag_Create );
830 print_error( rtl::OString( "Create and Open File (Read & Write)" ), rc );
832 printf( "\n" );
834 //----------------------------------------------------
835 // write a string to the file
836 //----------------------------------------------------
837 rc=pFile->write( pWriteBuffer , nLen , uWritten );
838 print_error( rtl::OString( "Write File" ), rc );
840 if(uWritten==nLen)
841 printf( "Verify: OK! \n" );
842 else
843 printf( "Verify: Error\n" );
845 printf( "\n" );
847 //----------------------------------------------------
848 // move the filepointer to the beginning
849 //----------------------------------------------------
851 rc=pFile->setPos( Pos_Absolut , 0 );
852 print_error( rtl::OString( "Set FilePointer to the beginning of the file" ), rc );
854 printf( "\n" );
856 //----------------------------------------------------
857 // read the string
858 //----------------------------------------------------
860 pReadBuffer=(sal_Char*) rtl_allocateMemory( (sal_uInt32)(nLen+1)*sizeof(sal_Char) );
861 rtl_zeroMemory( pReadBuffer, (sal_uInt32)(nLen+1)*sizeof(sal_Char) );
862 rc=pFile->read( pReadBuffer , nLen,uRead );
863 print_error( rtl::OString( "Read File" ), rc );
865 if (strcmp(pWriteBuffer, pReadBuffer)==0)
867 printf( "Verify: OK !\n" );
868 printf( "Text: %s\n",pReadBuffer );
870 else
871 printf( "Verify: Error\n" );
873 rtl_freeMemory( pReadBuffer );
875 printf( "\n" );
877 // close the file
878 rc=pFile->close();
879 print_error( rtl::OString( "Close File" ), rc );
881 // remove the file
882 rc=pFile->remove( file_not_exist );
883 print_error( rtl::OString( "Remove File" ), rc );
885 PressKey();
887 return;
891 //--------------------------------------------------
892 // FileCopyMoveTest
893 //--------------------------------------------------
895 void FileCopyAndMoveTest( void )
897 FileBase::RC rc;
899 printf( "--------------------------------------------\n" );
900 printf( "File-Copy-Move-Test\n" );
901 printf( "--------------------------------------------\n\n" );
904 File *pFile;
905 rtl::OUString destPath(dir2);
907 //--------------------------------------------------
908 // FileCopyTest
909 //--------------------------------------------------
911 destPath+=rtl::OUString::createFromAscii("/");
912 destPath+=file3;
914 printf( "Copy the file ");
915 printFileName( file1 );
916 printf( " to ");
917 printFileName( destPath );
918 printf( "\n" );
921 rc=File::copy( file1 , destPath );
922 print_error( rtl::OString( "FileCopy" ), rc );
924 pFile=new File( destPath );
926 rc=pFile->open( OpenFlag_Read );
927 if ( rc == FileBase::E_None)
929 printf( "Verify: OK!\n" );
930 pFile->close();
931 File::remove( destPath );
933 else
934 printf( "Verify: Error!\n" );
936 delete pFile;
938 printf( "\n" );
940 //--------------------------------------------------
941 // Copy a file to a not existing directory
942 //--------------------------------------------------
944 destPath=rtl::OUString( dir_not_exist );
945 destPath+=rtl::OUString::createFromAscii("/");
946 destPath+=file3;
948 printf( "Copy a file to a not existing directory \n");
949 printf( "Copy the file %s to %s\n", file1.getStr(), destPath.getStr() );
951 rc=File::copy( file1, destPath );
952 print_error( rtl::OString( "FileCopy" ), rc );
954 printf( "\n" );
956 //--------------------------------------------------
957 // Copy a directory
958 //--------------------------------------------------
960 printf( "Copy the directory: ");
961 printFileName( dir1 );
962 printf( " to ");
963 printFileName( dir2 );
964 printf( "\n" );
966 rc=File::copy( dir1 , dir2 );
967 print_error( rtl::OString( "FileCopy" ), rc );
969 printf( "\n" );
971 //--------------------------------------------------
972 // FileMoveTest
973 //--------------------------------------------------
975 destPath=rtl::OUString( dir2 );
976 destPath+=rtl::OUString::createFromAscii("/");
977 destPath+=file3;
979 printf( "Move the file ");
980 printFileName( file1 );
981 printf( " to ");
982 printFileName( destPath );
983 printf( "\n" );
985 rc=File::move( file1, destPath );
986 print_error( rtl::OString( "FileMove" ), rc );
988 pFile=new File( destPath );
990 rc=pFile->open( OpenFlag_Read );
991 if ( rc==FileBase::E_None )
993 pFile->close();
995 delete pFile;
996 pFile=new File( file1 );
998 rc=pFile->open( OpenFlag_Read );
1000 if ( rc!=FileBase::E_None )
1002 printf( "Verify: OK!\n" );
1003 File::move( destPath, file1 );
1005 else
1007 printf( "Verify: Error!\n" );
1008 pFile->close();
1009 File::remove( destPath );
1012 else
1013 printf( "Verify: Error!\n" );
1015 delete pFile;
1017 printf( "\n" );
1020 //--------------------------------------------------
1021 // Move a file to a not existing directory
1022 //--------------------------------------------------
1024 destPath=rtl::OUString( dir_not_exist );
1025 destPath+=rtl::OUString::createFromAscii("/");
1026 destPath+=file3;
1028 printf( "Move a file to a not existing directory: \n");
1029 printf( "Move the file ");
1030 printFileName( file1 );
1031 printf( " to ");
1032 printFileName( destPath );
1033 printf( "\n" );
1035 rc=File::move( file1 , destPath );
1036 print_error( rtl::OString( "FileMove" ), rc );
1038 printf( "\n" );
1040 //--------------------------------------------------
1041 // Move a directory
1042 //--------------------------------------------------
1044 printf( "Move a directory: \n");
1046 printf( "Move the directory ");
1047 printFileName( dir1 );
1048 printf( " to ");
1049 printFileName( dir_not_exist );
1050 printf( "\n" );
1053 rc=File::move( dir1 , dir_not_exist);
1054 print_error( rtl::OString( "FileMove" ), rc );
1056 if ( rc == FileBase::E_None )
1057 File::move( dir_not_exist , dir1);
1059 printf( "\n" );
1062 PressKey();
1063 return;
1066 //----------------------------------------------------
1067 // FileSizeTest
1068 //----------------------------------------------------
1070 void FileSizeTest( void )
1072 FileBase::RC rc;
1073 sal_uInt64 filesize;
1074 DirectoryItem aItem;
1076 printf( "--------------------------------------------\n" );
1077 printf( "File-Size-Test\n" );
1078 printf( "--------------------------------------------\n\n" );
1081 File aFile( file_not_exist );
1083 printf( "Create File: ");
1084 printFileName( file_not_exist );
1085 printf( "\n\n");
1087 rc = aFile.open( OpenFlag_Read | OpenFlag_Write | osl_File_OpenFlag_Create );
1088 print_error( rtl::OString( "Create and Open File (Read & Write)" ), rc );
1089 printf( "\n" );
1091 if ( rc == FileBase::E_None )
1093 //----------------------------------------------------
1094 // Set Filesize to 5000
1095 //----------------------------------------------------
1097 printf( "Set FileSize to 5000\n" );
1098 rc=aFile.setSize( 5000 );
1099 print_error( rtl::OString( "Set FileSize" ), rc );
1101 printf( "\n" );
1102 printf( "Verify:\n" );
1104 //----------------------------------------------------
1105 // Check whether Filesize is set to 5000
1106 //----------------------------------------------------
1108 rc=DirectoryItem::get( file_not_exist, aItem );
1109 print_error( rtl::OString( "Get DirectoryItem" ), rc );
1111 if ( rc == FileBase::E_None )
1113 FileStatus rStatus( FileStatusMask_FileSize );
1114 rc=aItem.getFileStatus( rStatus );
1115 print_error( rtl::OString( "Get FileStatus" ), rc );
1117 if ( rc == FileBase::E_None )
1119 filesize=rStatus.getFileSize();
1121 if ( filesize == 5000 )
1122 printf( "\nOK : FileSize: %i\n", filesize );
1123 else
1124 printf( "\nError : FileSize: %i\n", filesize );
1128 printf( "\n" );
1130 //----------------------------------------------------
1131 // Set Filesize to -1
1132 //----------------------------------------------------
1134 printf( "Set FileSize to -1\n" );
1135 rc=aFile.setSize( -1 );
1136 print_error( rtl::OString( "Set FileSize" ), rc );
1138 printf( "\n" );
1140 // close the file
1141 rc=aFile.close();
1142 print_error( rtl::OString( "Close File" ), rc );
1144 // remove the file
1145 rc=File::remove( file_not_exist );
1146 print_error( rtl::OString( "Remove File" ), rc );
1149 PressKey();
1151 return;
1155 //----------------------------------------------------
1156 // FilePointerTest
1157 //----------------------------------------------------
1159 void FilePointerTest( void )
1161 FileBase::RC rc;
1162 sal_uInt64 filepointer;
1164 printf( "--------------------------------------------\n" );
1165 printf( "File-Pointer-Test\n" );
1166 printf( "--------------------------------------------\n\n" );
1169 File rFile( file_not_exist );
1171 printf( "Create File: ");
1172 printFileName( file_not_exist );
1173 printf( "\n\n");
1175 rc = rFile.open( OpenFlag_Read | OpenFlag_Write | osl_File_OpenFlag_Create );
1176 print_error( rtl::OString( "Create and Open File (Read & Write) "), rc );
1177 printf( "\n" );
1179 if ( rc==FileBase::E_None )
1182 //----------------------------------------------------
1183 // get the position of the filepointer
1184 //----------------------------------------------------
1186 rc =rFile.getPos( filepointer );
1187 print_error( rtl::OString( "GetPos" ), rc );
1188 printf( "Position of the FilePointer: %i\n", filepointer );
1190 printf( "\n" );
1192 //----------------------------------------------------
1193 // set the filepointer at the end of a file
1194 //----------------------------------------------------
1196 printf( "Set FileSize to 5000\n" );
1197 rFile.setSize( 5000 );
1199 printf( "Set the FilePointer at the end of the file (5000)\n" );
1200 rc=rFile.setPos( Pos_End,0 );
1201 print_error( rtl::OString( "SetPos" ), rc );
1203 rc=rFile.getPos( filepointer );
1205 if ( filepointer==5000 )
1207 print_error( rtl::OString( "GetPos" ), rc );
1208 printf( "\nVerify: OK !\n" );
1209 printf( "Filepointer-Position: %llu\n",filepointer );
1211 else
1213 print_error( rtl::OString( "GetPos" ), rc );
1214 printf( "\nFilePointer-Test: Error\n" );
1215 printf( "Filepointer-Position: %i != 5000 \n",filepointer );
1218 printf( "\n" );
1220 // close the file
1221 rc=rFile.close();
1222 print_error( rtl::OString( "Close File" ), rc );
1224 // remove the file
1225 rc=File::remove( file_not_exist );
1226 print_error( rtl::OString( "Remove File" ), rc );
1229 PressKey();
1231 return;
1234 //--------------------------------------------------
1235 // FileAttributesTest
1236 //--------------------------------------------------
1238 void verifyFileAttributes( void )
1240 FileBase::RC rc;
1241 DirectoryItem aItem;
1242 FileStatus rStatus( FileStatusMask_Attributes );
1244 printf( "\nVerify:\n" );
1246 rc=DirectoryItem::get( file1, aItem );
1248 if ( rc==FileBase::E_None )
1250 rc=aItem.getFileStatus( rStatus );
1252 if ( rc==FileBase::E_None )
1254 sal_uInt64 uAttributes=rStatus.getAttributes();
1255 showAttributes(uAttributes);
1256 printf( "\n" );
1258 else
1259 print_error( rtl::OString( "Get FileStatus" ), rc );
1261 else
1262 print_error( rtl::OString( "Get DirectoryItem" ), rc );
1264 return;
1267 #ifdef UNX
1268 void FileAttributesTest( void )
1270 FileBase::RC rc;
1272 printf( "--------------------------------------------\n" );
1273 printf( "File-Attributes-Test\n" );
1274 printf( "--------------------------------------------\n\n" );
1276 printf( "File: ");
1277 printFileName( file1 );
1278 printf( "\n\n" );
1281 rc=File::setAttributes( file1, Attribute_GrpWrite );
1282 print_error( rtl::OString( "Set Attribute: GrpWrite" ), rc );
1284 verifyFileAttributes();
1286 rc=File::setAttributes( file1, 0 );
1287 if ( rc!=FileBase::E_None )
1288 print_error( rtl::OString( "Reset Attributes" ), rc );
1290 rc=File::setAttributes( file1, Attribute_GrpRead );
1291 print_error( rtl::OString( "Set Attribute: GrpRead" ), rc );
1293 verifyFileAttributes();
1295 rc=File::setAttributes( file1, 0 );
1296 if ( rc!=FileBase::E_None )
1297 print_error( rtl::OString( "Reset Attributes" ), rc );
1299 rc=File::setAttributes( file1, Attribute_GrpExe );
1300 print_error( rtl::OString( "Set Attribute: GrpExe" ), rc );
1302 verifyFileAttributes();
1304 rc=File::setAttributes( file1, 0 );
1305 if ( rc!=FileBase::E_None )
1306 print_error( rtl::OString( "Reset Attributes" ), rc );
1308 rc=File::setAttributes( file1, Attribute_OwnWrite );
1309 print_error( rtl::OString( "Set Attribute: OwnWrite" ), rc );
1311 verifyFileAttributes();
1313 rc=File::setAttributes( file1, 0 );
1314 if ( rc!=FileBase::E_None )
1315 print_error( rtl::OString( "Reset Attributes" ), rc );
1317 rc=File::setAttributes( file1, Attribute_OwnRead );
1318 print_error( rtl::OString( "Set Attribute: OwnRead" ), rc );
1320 verifyFileAttributes();
1322 rc=File::setAttributes( file1, 0 );
1323 if ( rc!=FileBase::E_None )
1324 print_error( rtl::OString( "Reset Attributes" ), rc );
1326 rc=File::setAttributes( file1, Attribute_OwnExe );
1327 print_error( rtl::OString( "Set Attribute: OwnExe" ), rc );
1329 verifyFileAttributes();
1331 rc=File::setAttributes( file1, 0 );
1332 if ( rc!=FileBase::E_None )
1333 print_error( rtl::OString( "Reset Attributes" ), rc );
1335 rc=File::setAttributes( file1, Attribute_OthWrite );
1336 print_error( rtl::OString( "Set Attribute: OthWrite" ), rc );
1338 verifyFileAttributes();
1340 rc=File::setAttributes( file1, 0 );
1341 if ( rc!=FileBase::E_None )
1342 print_error( rtl::OString( "Reset Attributes" ), rc );
1344 rc=File::setAttributes( file1, Attribute_OthRead );
1345 print_error( rtl::OString( "Set Attribute: OthRead" ), rc );
1347 verifyFileAttributes();
1349 rc=File::setAttributes( file1, 0 );
1350 if ( rc!=FileBase::E_None )
1351 print_error( rtl::OString( "Reset Attributes" ), rc );
1353 rc=File::setAttributes( file1, Attribute_OthExe );
1354 print_error( rtl::OString( "Set Attribute: OthExe" ), rc );
1356 verifyFileAttributes();
1358 rc=File::setAttributes( file1, 0 );
1359 if ( rc!=FileBase::E_None )
1360 print_error( rtl::OString( "Reset Attributes" ), rc );
1363 rc=File::setAttributes( file1, Attribute_GrpWrite | Attribute_GrpRead | Attribute_GrpExe | Attribute_OwnWrite | Attribute_OwnRead | Attribute_OwnExe | Attribute_OthWrite | Attribute_OthRead | Attribute_OthExe );
1364 print_error( rtl::OString( "Set all Attributes" ), rc );
1366 verifyFileAttributes();
1368 PressKey();
1370 return;
1372 #endif
1374 #ifdef WNT
1375 void FileAttributesTest( void )
1377 FileBase::RC rc;
1379 printf( "--------------------------------------------\n" );
1380 printf( "File-Attributes-Test\n" );
1381 printf( "--------------------------------------------\n\n" );
1383 printf( "File: ");
1384 printFileName( file1 );
1385 printf( "\n\n" );
1388 rc=File::setAttributes( file1, Attribute_ReadOnly );
1389 print_error( rtl::OString( "Set Attribute: ReadOnly" ), rc );
1391 verifyFileAttributes();
1393 rc=File::setAttributes( file1, 0 );
1394 print_error( rtl::OString( "Reset Attributes" ), rc );
1396 verifyFileAttributes();
1398 rc=File::setAttributes( file1, Attribute_Hidden );
1399 print_error( rtl::OString( "Set Attribute: Hidden" ), rc );
1401 verifyFileAttributes();
1403 rc=File::setAttributes( file1, 0 );
1404 print_error( rtl::OString( "Reset Attributes" ), rc );
1406 verifyFileAttributes();
1408 rc=File::setAttributes( file1, Attribute_Hidden | Attribute_ReadOnly );
1409 print_error( rtl::OString( "Set Attribute: Hidden & ReadOnly" ), rc );
1411 verifyFileAttributes();
1413 rc=File::setAttributes( file1, 0 );
1414 print_error( rtl::OString( "Reset Attributes") , rc );
1416 verifyFileAttributes();
1418 PressKey();
1420 return;
1422 #endif
1424 //--------------------------------------------------
1425 // FileTimeTest
1426 //--------------------------------------------------
1428 void FileTimeTest( void )
1430 FileBase::RC rc;
1432 DirectoryItem aItem;
1434 struct tm sSysCreationTime = { 0, 20, 12, 4, 9, 100 };
1435 struct tm sSysAccessTime = { 0, 40, 1, 6, 5, 98 };
1436 struct tm sSysModifyTime = { 0, 1, 24, 13, 11, 95 };
1438 time_t aSysCreationTime = mktime( &sSysCreationTime );
1439 time_t aSysAccessTime = mktime( &sSysAccessTime );
1440 time_t aSysModifyTime = mktime( &sSysModifyTime );
1442 TimeValue aCreationTime = { aSysCreationTime, 0};
1443 TimeValue aAccessTime = { aSysAccessTime, 0};
1444 TimeValue aModifyTime = { aSysModifyTime, 0};
1446 TimeValue aCreationTimeRead;
1447 TimeValue aAccessTimeRead;
1448 TimeValue aModifyTimeRead;
1451 printf( "--------------------------------------------\n" );
1452 printf( "File-Time-Test\n" );
1453 printf( "--------------------------------------------\n\n" );
1455 printf( "File: ");
1456 printFileName( file1 );
1457 printf( "\n\n" );
1459 printf( "CreationTime \t : ");
1460 showTime( aCreationTime );
1462 printf( "\nAccessTime \t : ");
1463 showTime( aAccessTime );
1465 printf( "\nModifyTime \t : ");
1466 showTime( aModifyTime );
1468 //--------------------------------------------------
1469 // setTime
1470 //--------------------------------------------------
1472 printf( "\n" );
1473 rc=File::setTime( file1 , aCreationTime , aAccessTime , aModifyTime );
1474 print_error( rtl::OString( "SetTime" ), rc );
1476 //--------------------------------------------------
1477 // Verify
1478 //--------------------------------------------------
1480 FileStatus rStatus( FileStatusMask_CreationTime | FileStatusMask_AccessTime | FileStatusMask_ModifyTime);
1482 printf( "\nVerify:\n" );
1484 rc=DirectoryItem::get( file1, aItem );
1485 print_error( rtl::OString( "Get DirectoryItem" ), rc );
1487 if ( rc==FileBase::E_None )
1489 rc=aItem.getFileStatus( rStatus );
1490 print_error( rtl::OString( "Get FileStatus" ), rc );
1491 printf( "\n" );
1493 if ( rc==FileBase::E_None )
1495 //--------------------------------------------------
1496 // GetCreationTime
1497 //--------------------------------------------------
1499 aCreationTimeRead=rStatus.getCreationTime();
1500 #ifdef WNT
1501 if ( aCreationTime.Seconds == aCreationTimeRead.Seconds && aCreationTime.Nanosec == aCreationTimeRead.Nanosec )
1502 printf( "GetCreationTime: ok : " );
1503 else
1504 printf( "GetCreationTime: Error : " );
1506 showTime( aCreationTimeRead );
1507 printf( "\n" );
1508 #endif
1509 //--------------------------------------------------
1510 // GetAccessTime
1511 //--------------------------------------------------
1513 aAccessTimeRead=rStatus.getAccessTime();
1515 if ( aAccessTime.Seconds == aAccessTimeRead.Seconds && aAccessTime.Nanosec == aAccessTimeRead.Nanosec )
1516 printf( "GetAccessTime: ok : " );
1517 else
1518 printf( "GetAccessTime: Error : " );
1520 showTime( aAccessTimeRead );
1521 printf( "\n" );
1523 //--------------------------------------------------
1524 // GetModifyTime
1525 //--------------------------------------------------
1527 aModifyTimeRead=rStatus.getModifyTime();
1529 if ( aModifyTime.Seconds == aModifyTimeRead.Seconds && aModifyTime.Nanosec == aModifyTimeRead.Nanosec )
1530 printf( "GetModifyTime: ok : " );
1531 else
1532 printf( "GetModifyTime: Error : " );
1534 showTime( aModifyTimeRead );
1535 printf( "\n" );
1539 PressKey();
1540 return;
1544 //--------------------------------------------------
1545 // DirectoryItemTest
1546 //--------------------------------------------------
1548 void DirectoryItemTest( void )
1550 FileBase::RC rc;
1551 Directory *pDir;
1552 DirectoryItem aItem;
1553 FileStatus *pStatus;
1554 File *pFile;
1556 printf( "--------------------------------------------\n" );
1557 printf( "Directory-Item-Test\n" );
1558 printf( "--------------------------------------------\n\n" );
1560 //--------------------------------------------------
1561 // get DirectoryItem from an existing directory
1562 //--------------------------------------------------
1564 printf( "Get DirectoryItem from an existing Directory: ");
1565 printFileName( dir1 );
1566 printf( "\n");
1568 rc=DirectoryItem::get( dir1 , aItem );
1569 print_error( rtl::OString( "GetDirectoryItem" ), rc );
1571 pStatus=new FileStatus( FileStatusMask_All );
1572 rc=aItem.getFileStatus( *pStatus );
1574 if ( rc==FileBase::E_None )
1576 printf( "GetFileStatus: FileURL: ");
1577 printFileName(pStatus->getFileURL() );
1578 printf( "\n" );
1581 delete pStatus;
1583 printf( "\n" );
1585 //--------------------------------------------------
1586 // get DirectoryItem from a not existing directory
1587 //--------------------------------------------------
1589 printf( "Get DirectoryItem from a not existing Directory: ");
1590 printFileName( dir_not_exist );
1591 printf( "\n" );
1593 rc=DirectoryItem::get( dir_not_exist , aItem );
1594 print_error( rtl::OString( "Get DirectoryItem" ), rc );
1596 printf( "\n" );
1598 //--------------------------------------------------
1599 // get DirectoryItem from an existing file
1600 //--------------------------------------------------
1602 printf( "Get DirectoryItem from an existing File: ");
1603 printFileName( file1 );
1604 printf( "\n" );
1606 rc=DirectoryItem::get( file1 , aItem );
1607 print_error( rtl::OString( "GetDirectoryItem" ), rc );
1609 pStatus=new FileStatus( FileStatusMask_All );
1610 rc=aItem.getFileStatus( *pStatus );
1612 if ( rc==FileBase::E_None )
1614 printf( "GetFileStatus: FileURL: ");
1615 printFileName( pStatus->getFileURL() );
1616 printf( "\n" );
1619 delete pStatus;
1621 printf( "\n" );
1623 //--------------------------------------------------
1624 // get DirectoryItem from a not existing file
1625 //--------------------------------------------------
1627 printf( "Get DirectoryItem from a not existing File: ");
1628 printFileName( file_not_exist );
1629 printf( "\n" );
1631 rc=DirectoryItem::get( file_not_exist , aItem );
1632 print_error( rtl::OString( "Get DirectoryItem" ), rc );
1634 printf( "\n" );
1636 //----------------------------------------------------------
1637 // get DirectoryItem from a directory with a wrong semantic
1638 //----------------------------------------------------------
1640 printf( "Get DirectoryItem from a Directory with a wrong semantic: ");
1641 printFileName( dir_not_exist );
1642 printf( "\n" );
1644 rc=DirectoryItem::get( dir_wrong_semantic, aItem );
1645 print_error( rtl::OString( "Get DirectoryItem" ),rc );
1647 printf( "\n" );
1649 //---------------------------------------------------
1650 // get DirectoryItem from a file-handle
1651 //--------------------------------------------------
1653 pFile=new File( file1 );
1655 rc=pFile->open( OpenFlag_Read );
1656 if ( rc==FileBase::E_None )
1658 printf( "Get DirectoryItem from a File-Handle: ");
1659 printFileName( file1 );
1660 printf( "\n" );
1662 rc=DirectoryItem::get( *pFile , aItem );
1663 print_error( rtl::OString( "GetDirectoryItem" ), rc );
1665 pStatus=new FileStatus( FileStatusMask_All );
1666 rc=aItem.getFileStatus( *pStatus );
1668 if ( rc==FileBase::E_None )
1670 printf( "GetFileStatus: FileURL: ");
1671 printFileName( pStatus->getFileURL() );
1672 printf( "\n");
1675 delete pStatus;
1677 pFile->close();
1680 delete pFile;
1682 printf( "\n" );
1684 //---------------------------------------------------
1685 // get DirectoryItem from an empty file-handle
1686 //--------------------------------------------------
1688 pFile=new File( file1 );
1690 printf( "Get DirectoryItem from an empty File-Handle\n" );
1691 rc=DirectoryItem::get( *pFile , aItem );
1692 print_error( rtl::OString( "GetDirectoryItem" ), rc );
1694 delete pFile;
1696 printf( "\n" );
1698 //--------------------------------------------------
1699 // GetNextItem from a directory
1700 //--------------------------------------------------
1702 pDir=new Directory( dir1 );
1703 printf( "Get next DirectoryItem from a directory: ");
1704 printFileName( dir1);
1705 printf( "\n" );
1707 rc= pDir->open();
1708 print_error( rtl::OString( "Open Directory" ), rc );
1710 printf( "\n" );
1712 if ( pDir->isOpen() )
1714 //--------------------------------------------------
1715 // get all files from the directory
1716 //--------------------------------------------------
1718 rtl::OUString str;
1719 rtl::OUString str1[2];
1721 aItem=DirectoryItem();
1722 rc=pDir->getNextItem( aItem );
1723 print_error( rtl::OString( "GetNextItem" ),rc );
1725 while( rc==FileBase::E_None )
1728 FileStatus rStatus( FileStatusMask_All );
1729 aItem.getFileStatus( rStatus );
1731 str=rStatus.getFileName();
1732 printf( "Filename: ");
1733 printFileName( str );
1734 printf( "\n");
1736 aItem=DirectoryItem();
1737 rc=pDir->getNextItem( aItem );
1738 print_error( rtl::OString( "GetNextItem" ),rc );
1741 printf( "\n" );
1743 //--------------------------------------------------
1744 // Reset-Test
1745 //--------------------------------------------------
1747 for (int i=0; i<2; i++)
1749 aItem=DirectoryItem();
1750 rc=pDir->reset();
1751 rc=pDir->getNextItem( aItem );
1753 FileStatus rStatus( FileStatusMask_All );
1754 aItem.getFileStatus( rStatus );
1756 str1[i]=rStatus.getFileName();
1760 if ( str1[0].compareTo(str1[1]) == 0 )
1761 print_error( rtl::OString( "Reset" ),FileBase::E_None );
1762 else
1763 print_error( rtl::OString( "Reset" ),FileBase::E_invalidError );
1765 printf( "\n" );
1767 // Close Directory
1768 rc=pDir->close();
1769 print_error( rtl::OString( "Close Directory" ), rc );
1772 printf( "\n");
1774 //--------------------------------------------------
1775 // GetNextItem from a closed directory
1776 //--------------------------------------------------
1778 printf( "Get next DirectoryItem from a closed directory: ");
1779 printFileName( dir1 );
1780 printf( "\n" );
1782 aItem=DirectoryItem();
1783 rc=pDir->getNextItem( aItem );
1784 print_error( rtl::OString( "GetNextItem" ),rc );
1786 delete pDir;
1788 PressKey();
1789 return;
1792 //--------------------------------------------------
1793 // FileStatusTest (for different types)
1794 //--------------------------------------------------
1796 void FileStatusTest( FileStatus *pStatus )
1798 //--------------------------------------------------
1799 // GetFileType of the directory
1800 //--------------------------------------------------
1802 FileStatus::Type aType;
1804 printf( "\ngetFileType:\n" );
1805 aType=pStatus->getFileType();
1806 showFileType( aType );
1808 //--------------------------------------------------
1809 // GetAttributes
1810 //--------------------------------------------------
1812 sal_uInt64 uAttributes;
1814 printf( "\ngetAttributes:\n" );
1815 uAttributes=pStatus->getAttributes();
1816 showAttributes( uAttributes );
1818 //--------------------------------------------------
1819 // GetCreationTime
1820 //--------------------------------------------------
1822 TimeValue aCreationTime;
1824 printf( "\ngetCreationTime:\n" );
1825 aCreationTime=pStatus->getCreationTime();
1827 printf( "CreationTime: " );
1828 showTime( aCreationTime );
1830 //--------------------------------------------------
1831 // GetAccessTime
1832 //--------------------------------------------------
1834 TimeValue aAccessTime;
1836 printf( "\ngetAccessTime:\n" );
1837 aAccessTime=pStatus->getAccessTime();
1839 printf( "AccessTime: " );
1840 showTime( aAccessTime );
1842 //--------------------------------------------------
1843 // GetModifyTime
1844 //--------------------------------------------------
1846 TimeValue aModifyTime;
1848 printf( "\ngetModifyTime:\n" );
1849 aModifyTime=pStatus->getModifyTime();
1851 printf( "ModifyTime: " );
1852 showTime( aModifyTime );
1854 //--------------------------------------------------
1855 // GetFileSize
1856 //--------------------------------------------------
1858 sal_uInt64 FileSize;
1860 printf( "\ngetFileSize:\n" );
1862 FileSize=pStatus->getFileSize();
1863 printf( "FileSize: %i\n", FileSize);
1865 //--------------------------------------------------
1866 // GetFileName
1867 //--------------------------------------------------
1869 rtl::OUString FileName;
1871 printf( "\ngetFileName:\n" );
1873 FileName=pStatus->getFileName();
1874 printf( "FileName: ");
1875 printFileName( FileName );
1876 printf( "\n" );
1878 //--------------------------------------------------
1879 // GetFileURL
1880 //--------------------------------------------------
1882 rtl::OUString FileURL;
1884 printf( "\ngetFileURL:\n" );
1886 FileURL=pStatus->getFileURL();
1887 printf( "FileURL: ");
1888 printFileName( FileURL );
1889 printf( "\n" );
1891 //--------------------------------------------------
1892 // GetLinkTargetURL
1893 //--------------------------------------------------
1895 rtl::OUString LinkTargetURL;
1897 printf( "\ngetLinkTargetURL:\n");
1899 LinkTargetURL=pStatus->getLinkTargetURL();
1900 printf( "LinkTargetURL: ");
1901 printFileName( LinkTargetURL );
1902 printf( "\n" );
1904 return;
1907 //--------------------------------------------------
1908 // DirectoryFileStatusTest
1909 //--------------------------------------------------
1911 void DirectoryFileStatusTest( void )
1913 FileBase::RC rc;
1914 DirectoryItem aItem;
1915 FileStatus *pStatus;
1917 printf( "--------------------------------------------\n" );
1918 printf( "Directory-FileStatus-Test\n" );
1919 printf( "--------------------------------------------\n\n" );
1921 printf( "FileStatus of the directory: ");
1922 printFileName( dir1 );
1923 printf( "\n" );
1925 aItem=DirectoryItem();
1927 rc=DirectoryItem::get( dir1, aItem );
1928 print_error( rtl::OString( "Get DirectoryItem" ), rc );
1930 if ( rc==FileBase::E_None )
1932 pStatus=new FileStatus( FileStatusMask_All );
1933 rc=aItem.getFileStatus( *pStatus );
1935 FileStatusTest( pStatus );
1937 delete pStatus;
1940 printf( "\n" );
1942 PressKey();
1943 return;
1946 //--------------------------------------------------
1947 // FileFileStatusTest
1948 //--------------------------------------------------
1950 void FileFileStatusTest( void )
1952 FileBase::RC rc;
1953 DirectoryItem aItem;
1954 FileStatus *pStatus;
1956 printf( "--------------------------------------------\n" );
1957 printf( "File-FileStatus-Test\n" );
1958 printf( "--------------------------------------------\n\n" );
1960 printf( "FileStatus of the file: ");
1961 printFileName( file1 );
1962 printf( "\n" );
1964 aItem=DirectoryItem();
1966 rc=DirectoryItem::get( file1 , aItem );
1967 print_error( rtl::OString( "Get DirectoryItem" ), rc );
1969 if ( rc==FileBase::E_None )
1971 pStatus=new FileStatus( FileStatusMask_All );
1972 rc=aItem.getFileStatus( *pStatus );
1974 FileStatusTest( pStatus );
1976 delete pStatus;
1979 printf( "\n" );
1981 PressKey();
1982 return;
1985 //--------------------------------------------------
1986 // VolumeFileStatusTest
1987 //--------------------------------------------------
1989 void VolumeFileStatusTest( void )
1991 FileBase::RC rc;
1992 DirectoryItem aItem;
1993 FileStatus *pStatus;
1995 printf( "--------------------------------------------\n" );
1996 printf( "Volume-FileStatus-Test\n" );
1997 printf( "--------------------------------------------\n\n" );
1999 printf( "FileStatus of the Volume: ");
2000 printFileName( root );
2001 printf( "\n" );
2003 aItem=DirectoryItem();
2005 rc=DirectoryItem::get( root , aItem );
2006 print_error( rtl::OString( "Get DirectoryItem" ), rc );
2008 if ( rc==FileBase::E_None )
2010 pStatus=new FileStatus( FileStatusMask_All) ;
2011 rc=aItem.getFileStatus( *pStatus );
2013 FileStatusTest( pStatus );
2015 delete pStatus;
2018 printf( "\n" );
2020 PressKey();
2021 return;
2025 //--------------------------------------------------
2026 // VolumeInfoTest
2027 //--------------------------------------------------
2029 void VolumeInfoTest( void )
2031 FileBase::RC rc;
2033 printf( "--------------------------------------------\n" );
2034 printf( "Volume-Info-Test\n" );
2035 printf( "--------------------------------------------\n\n" );
2037 printf( "VolumeInfo of the volume ");
2038 printFileName( root );
2040 printf( "\n" );
2042 VolumeInfo rInfo( VolumeInfoMask_FreeSpace );
2043 rc=Directory::getVolumeInfo( root , rInfo );
2044 print_error( rtl::OString( "GetVolumeInfo" ),rc );
2046 printf( "\n" );
2048 //--------------------------------------------------
2049 // getRemoteFlag
2050 //--------------------------------------------------
2052 if ( rInfo.getRemoteFlag() )
2053 printf( "RemoteFlag: Yes\n" );
2054 else
2055 printf( "RemoteFlag: No\n" );
2057 //--------------------------------------------------
2058 // getRemoveableFlag
2059 //--------------------------------------------------
2061 if ( rInfo.getRemoveableFlag() )
2062 printf( "RemoveableFlag: Yes\n" );
2063 else
2064 printf( "RemoveableFlag: No\n" );
2066 //--------------------------------------------------
2067 // getTotalSpace
2068 //--------------------------------------------------
2070 sal_uInt64 TotalSpace;
2071 TotalSpace=rInfo.getTotalSpace();
2072 printf( "Total Space: %i\n",TotalSpace );
2074 //--------------------------------------------------
2075 // getFreeSpace
2076 //--------------------------------------------------
2078 sal_uInt64 FreeSpace;
2079 FreeSpace=rInfo.getFreeSpace();
2080 printf( "Free Space: %i\n",FreeSpace );
2082 //--------------------------------------------------
2083 // getUsedSpace
2084 //--------------------------------------------------
2086 sal_uInt64 UsedSpace;
2087 UsedSpace=rInfo.getUsedSpace();
2088 printf( "Used Space: %i\n",UsedSpace );
2090 //--------------------------------------------------
2091 // getMaxNameLength
2092 //--------------------------------------------------
2094 sal_uInt32 MaxNameLength;
2095 MaxNameLength=rInfo.getMaxNameLength();
2096 printf( "MaxNameLength: %i\n",MaxNameLength );
2098 //--------------------------------------------------
2099 // getMaxPathLength
2100 //--------------------------------------------------
2102 sal_uInt32 MaxPathLength;
2103 MaxPathLength=rInfo.getMaxPathLength();
2104 printf( "MaxPathLength: %i\n",MaxPathLength );
2106 //--------------------------------------------------
2107 // getFileSystemName
2108 //--------------------------------------------------
2110 rtl::OUString FileSystemName;
2111 FileSystemName=rInfo.getFileSystemName();
2112 printf( "File-System-Name: ");
2113 printFileName( FileSystemName );
2114 printf( "\n" );
2116 PressKey();
2117 return;
2120 //--------------------------------------------------
2121 // FileBaseTest
2122 //--------------------------------------------------
2124 void ConvertPathTest(rtl::OUString& strPath)
2126 FileBase::RC rc;
2128 rtl::OUString strNormPath;
2129 rtl::OUString strFileURL;
2130 rtl::OUString strNormPathFromFileURL;
2131 rtl::OUString strSystemPath;
2133 //--------------------------------------------------
2134 // normalizePath
2135 //--------------------------------------------------
2137 rc=FileBase::getFileURLFromSystemPath( strPath, strNormPath );
2139 if ( rc == FileBase::E_None )
2141 printf( "Normalized Path: \t\t");
2142 printFileName( strNormPath );
2143 printf( "\n" );
2145 else
2146 printf( "normalizePath: Error \n" );
2148 //--------------------------------------------------
2149 // getFileURLFromSystemPath
2150 //--------------------------------------------------
2152 if ( strNormPath.getLength() != 0 )
2154 rc=FileBase::getFileURLFromSystemPath( strNormPath, strFileURL );
2156 if ( rc == FileBase::E_None )
2158 printf( "File-URL: \t\t\t");
2159 printFileName( strFileURL );
2160 printf( "\n" );
2162 else
2163 printf( "getFileURLFromSystemPath: Error \n" );
2165 else
2166 printf( "getFileURLFromSystemPath: not tested \n" );
2168 //--------------------------------------------------
2169 // getNormalizedPathFromFileURL
2170 //--------------------------------------------------
2172 if ( strFileURL.getLength() != 0 )
2174 rc=FileBase::getSystemPathFromFileURL( strFileURL, strNormPathFromFileURL );
2176 if ( rc == FileBase::E_None )
2178 printf( "Normalized Path from File-URL: \t");
2179 printFileName( strNormPathFromFileURL );
2180 printf( "\n" );
2182 else
2183 printf( "getNormalizedPathFromFileURL: Error \n" );
2185 else
2186 printf( "getNormalizedPathFromFileURL: not tested \n" );
2189 //--------------------------------------------------
2190 // getSystemPathFromFileURL
2191 //--------------------------------------------------
2193 if ( strNormPath.getLength() != 0 )
2195 rc=FileBase::getSystemPathFromFileURL( strNormPath, strSystemPath );
2197 if ( rc == FileBase::E_None )
2199 printf( "System-Path: \t\t\t");
2200 printFileName( strSystemPath );
2201 printf( "\n");
2203 else
2204 printf( "getSystemPathFromFileURL: Error \n" );
2206 else
2207 printf( "getSystemPathFromFileURL: not tested \n" );
2209 //--------------------------------------------------
2210 // Verify
2211 //--------------------------------------------------
2213 if ( strNormPathFromFileURL == strNormPath )
2214 printf( "\nVerify: OK ! ( Normalized-Path == Normalized-Path-From-File-URL )\n" );
2215 else
2216 printf( "\nVerify: Error ! ( Normalized-Path != Normalized-Path-From-File-URL )\n" );
2218 return;
2221 void FileBaseTest()
2223 printf( "--------------------------------------------\n" );
2224 printf( "FileBase-Test\n" );
2225 printf( "--------------------------------------------\n\n" );
2227 //--------------------------------------------------
2228 // ConvertPath-Test (Local File)
2229 //--------------------------------------------------
2231 printf( "- Local File: ");
2232 printFileName( file1 );
2233 printf( "\n\n" );
2235 ConvertPathTest(file1);
2237 //--------------------------------------------------
2238 // ConvertPath-Test (File on a server)
2239 //--------------------------------------------------
2241 printf( "\n- File on server: ");
2242 printFileName( file_on_server );
2243 printf( "\n\n" );
2244 ConvertPathTest(file_on_server);
2246 PressKey();
2248 return;
2252 //--------------------------------------------------
2253 // AbsolutePathTest
2254 //--------------------------------------------------
2255 void DoAbsolutePathTest(rtl::OUString strDirBase, rtl::OUString strRelative)
2257 FileBase::RC rc;
2259 rtl::OUString strAbsolute;
2261 printf( "Base-Directory: \t");
2262 printFileName( strDirBase );
2263 printf( "\n" );
2264 printf( "Relative-Path: \t\t");
2265 printFileName ( strRelative );
2266 printf( "\n" );
2268 rc=FileBase::getAbsoluteFileURL( strDirBase, strRelative, strAbsolute );
2270 if ( rc == FileBase::E_None )
2272 printf( "Absolute-Path: \t\t");
2273 printFileName ( strAbsolute );
2274 printf( "\n" );
2276 else
2277 printf( "Absolute-Path: Error \n" );
2279 printf( "\n" );
2280 return;
2283 void AbsolutePathTest(void)
2285 printf( "--------------------------------------------\n" );
2286 printf( "AbsolutePath-Test\n" );
2287 printf( "--------------------------------------------\n\n" );
2289 DoAbsolutePathTest(dir1, rtl::OUString::createFromAscii("."));
2290 DoAbsolutePathTest(dir1, rtl::OUString::createFromAscii(".."));
2291 DoAbsolutePathTest(dir1, rtl::OUString::createFromAscii("../.."));
2292 DoAbsolutePathTest(dir1, rtl::OUString::createFromAscii("../HUHU"));
2294 DoAbsolutePathTest(dir_on_server, rtl::OUString::createFromAscii("."));
2295 DoAbsolutePathTest(dir_on_server, rtl::OUString::createFromAscii(".."));
2296 DoAbsolutePathTest(dir_on_server, rtl::OUString::createFromAscii("../.."));
2297 DoAbsolutePathTest(dir_on_server, rtl::OUString::createFromAscii("../HUHU"));
2299 PressKey();
2300 return;
2304 //--------------------------------------------------
2305 // searchPathTest
2306 //--------------------------------------------------
2308 void SearchPathTest(void)
2310 FileBase::RC rc;
2312 rtl::OUString strNormPath(file1);
2313 rtl::OUString strFileURL;
2314 rtl::OUString strSystemPath;
2315 rtl::OUString strResultPath;
2317 printf( "--------------------------------------------\n" );
2318 printf( "SearchPath-Test\n" );
2319 printf( "--------------------------------------------\n\n" );
2322 rc=FileBase::getFileURLFromSystemPath( strNormPath, strFileURL );
2323 print_error( rtl::OString( "getFileURLFromSystemPath" ), rc );
2324 rc=FileBase::getSystemPathFromFileURL( strNormPath, strSystemPath );
2325 print_error( rtl::OString( "getSystemPathFromFileURL" ), rc );
2327 //--------------------------------------------------
2328 // searchFileURL (with a normalized path)
2329 //--------------------------------------------------
2331 if ( strNormPath.getLength() != 0 )
2333 printf( "\nSearch-Normalized-Path (with a normalized path) : ");
2334 printFileName ( strNormPath );
2335 printf( "\n" );
2337 rc=FileBase::searchFileURL( strNormPath , rtl::OUString() , strResultPath );
2339 if ( rc == FileBase::E_None )
2341 printf( "Result: \t\t\t");
2342 printFileName ( strResultPath );
2343 printf( "\n" );
2345 else
2346 printf( "searchFileURL (with a normalized path): Error\n" );
2348 else
2349 printf( "searchFileURL (with a normalized path): not tested\n" );
2351 //--------------------------------------------------
2352 // searchFileURL (with a File-URL)
2353 //--------------------------------------------------
2355 if ( strFileURL.getLength() != 0 )
2357 printf( "\nSearch-Normalized-Path (with a FileURL) : ");
2358 printFileName( strFileURL );
2359 printf( "\n" );
2361 rc=FileBase::searchFileURL( strFileURL , rtl::OUString() , strResultPath );
2363 if ( rc == FileBase::E_None )
2365 printf( "Result: \t\t\t");
2366 printFileName ( strResultPath );
2367 printf( "\n" );
2369 else
2370 printf( "searchFileURL (with a FileURL path): Error\n" );
2372 else
2373 printf( "searchFileURL (with a FileURL path): not tested\n" );
2375 //--------------------------------------------------
2376 // searchFileURL (with a systempath)
2377 //--------------------------------------------------
2379 if ( strSystemPath.getLength() != 0 )
2381 printf( "\nSearch-Normalized-Path (with a SystemPath) : ");
2382 printFileName( strSystemPath );
2383 printf( "\n" );
2385 rc=FileBase::searchFileURL( strSystemPath , rtl::OUString() , strResultPath );
2387 if ( rc == FileBase::E_None )
2389 printf( "Result: \t\t\t");
2390 printFileName( strResultPath );
2391 printf( "\n" );
2393 else
2394 printf( "searchFileURL (with a systempath): Error\n" );
2396 else
2397 printf( "searchFileURL (with a systempath): not tested\n" );
2399 //--------------------------------------------------
2400 // searchFileURL (File and no searchpath)
2401 //--------------------------------------------------
2403 printf( "\nsearchFileURL: File (no searchpath) : ");
2404 printFileName( file3 );
2405 printf( "\n" );
2407 rc=FileBase::searchFileURL( file3 , rtl::OUString::createFromAscii("") , strResultPath );
2409 if ( rc == FileBase::E_None )
2411 printf( "Result: \t\t\t");
2412 printFileName( strResultPath );
2413 printf( "\n" );
2415 else
2416 printf( "searchFileURL: File not found: OK ! \n" );
2418 //--------------------------------------------------
2419 // searchFileURL (File and Path)
2420 //--------------------------------------------------
2422 printf( "\nsearchFileURL: File : ");
2423 printFileName( file3 );
2424 printf( "\tSearchPath ");
2425 printFileName( dir1 );
2426 printf( "\n");
2428 rc=FileBase::searchFileURL( file3 , dir1 , strResultPath );
2430 if ( rc == FileBase::E_None )
2432 printf( "Result: \t\t\t");
2433 printFileName( strResultPath );
2434 printf( "\n");
2436 else
2437 printf( "searchFileURL: File not found: Error\n" );
2439 //------------------------------------------------------------
2440 // searchFileURL (File and searchpath with two entries)
2441 //------------------------------------------------------------
2443 rtl::OUString strSearchPath( dir_not_exist );
2444 strSearchPath+=rtl::OUString::createFromAscii(";");
2445 strSearchPath+=dir_on_server;
2447 printf( "\nsearchFileURL: File : ");
2448 printFileName( file3 );
2449 printf( "SearchPath ");
2450 printFileName( strSearchPath );
2451 printf( "\n");
2453 rc=FileBase::searchFileURL( file3 , strSearchPath , strResultPath );
2455 if ( rc == FileBase::E_None )
2457 printf( "Result: \t\t\t");
2458 printFileName( strResultPath );
2459 printf( "\n" );
2461 else
2462 printf( "searchFileURL: File not found: Error\n" );
2464 //-------------------------------------------------------------------
2465 // searchFileURL (File and searchpath (with a wrong semantic))
2466 //-------------------------------------------------------------------
2468 strSearchPath=rtl::OUString( dir_wrong_semantic );
2470 printf( "\nsearchFileURL: File : ");
2471 printFileName( file3 );
2472 printf( "SearchPath ");
2473 printFileName( strSearchPath );
2474 printf( "\n");
2476 rc=FileBase::searchFileURL( file3 , strSearchPath , strResultPath );
2478 if ( rc == FileBase::E_None )
2479 printf( "Error: Wrong Semantich but no error occurs !\n" );
2480 else
2481 printf( "searchFileURL: File not found: OK !\n" );
2483 return;
2486 //--------------------------------------------------
2487 // CanonicalNameTest
2488 //--------------------------------------------------
2490 void getCanonicalNameTest(rtl::OUString strPath)
2492 FileBase::RC rc;
2494 rtl::OUString strValid;
2496 printf( "Original-Name: \t\t");
2497 printFileName( strPath );
2498 printf( "\n" );
2500 rc=FileBase::getCanonicalName( strPath, strValid );
2502 if ( rc == FileBase::E_None)
2504 printf( "Canonical-Name: \t");
2505 printFileName( strValid );
2506 printf( "\n");
2509 else
2510 printf( "Canonical-Name: Error \n" );
2512 printf( "\n" );
2513 return;
2516 void CanonicalNameTest(void)
2518 printf( "--------------------------------------------\n" );
2519 printf( "CanonicalName-Test\n" );
2520 printf( "--------------------------------------------\n\n" );
2522 getCanonicalNameTest( dir1 );
2523 getCanonicalNameTest( dir_on_server );
2524 getCanonicalNameTest( file1 );
2525 getCanonicalNameTest( file_on_server );
2527 PressKey();
2528 return;
2531 //--------------------------------------------------
2532 // print_error
2533 //--------------------------------------------------
2535 void print_error( ::rtl::OString& str, FileBase::RC rc )
2538 printf( "%s : ",str.getStr() );
2539 switch(rc)
2541 case FileBase::E_None:
2542 printf("OK !\n");
2543 break;
2544 case FileBase::E_PERM:
2545 printf("E_PERM\n");
2546 break;
2547 case FileBase::E_NOENT:
2548 printf("E_NOENT\n");
2549 break;
2550 case FileBase::E_SRCH:
2551 printf("E_SRCH\n");
2552 break;
2553 case FileBase::E_INTR:
2554 printf("E_INTR\n");
2555 break;
2556 case FileBase::E_IO:
2557 printf("E_IO\n");
2558 break;
2559 case FileBase::E_NXIO:
2560 printf("E_NXIO\n");
2561 break;
2562 case FileBase::E_2BIG:
2563 printf("E_2BIG\n");
2564 break;
2565 case FileBase::E_NOEXEC:
2566 printf("E_NOEXEC\n");
2567 break;
2568 case FileBase::E_BADF:
2569 printf("E_BADF\n");
2570 break;
2571 case FileBase::E_CHILD:
2572 printf("E_CHILD\n");
2573 break;
2574 case FileBase::E_AGAIN:
2575 printf("E_AGAIN\n");
2576 break;
2577 case FileBase::E_NOMEM:
2578 printf("E_NOMEM\n");
2579 break;
2580 case FileBase::E_ACCES:
2581 printf("E_ACCES\n");
2582 break;
2583 case FileBase::E_FAULT:
2584 printf("E_FAULT\n");
2585 break;
2586 case FileBase::E_BUSY:
2587 printf("E_BUSY\n");
2588 break;
2589 case FileBase::E_EXIST:
2590 printf("E_EXIST\n");
2591 break;
2592 case FileBase::E_XDEV:
2593 printf("E_XDEV\n");
2594 break;
2595 case FileBase::E_NODEV:
2596 printf("E_NODEV\n");
2597 break;
2598 case FileBase::E_NOTDIR:
2599 printf("E_NOTDIR\n");
2600 break;
2601 case FileBase::E_ISDIR:
2602 printf("E_ISDIR\n");
2603 break;
2604 case FileBase::E_INVAL:
2605 printf("E_INVAL\n");
2606 break;
2607 case FileBase::E_NFILE:
2608 printf("E_NFILE\n");
2609 break;
2610 case FileBase::E_MFILE:
2611 printf("E_MFILE\n");
2612 break;
2613 case FileBase::E_NOTTY:
2614 printf("E_NOTTY\n");
2615 break;
2616 case FileBase::E_FBIG:
2617 printf("E_FBIG\n");
2618 break;
2619 case FileBase::E_NOSPC:
2620 printf("E_NOSPC\n");
2621 break;
2622 case FileBase::E_SPIPE:
2623 printf("E_SPIPE\n");
2624 break;
2625 case FileBase::E_ROFS:
2626 printf("E_ROFS\n");
2627 break;
2628 case FileBase::E_MLINK:
2629 printf("E_MLINK\n");
2630 break;
2631 case FileBase::E_PIPE:
2632 printf("E_PIPE\n");
2633 break;
2634 case FileBase::E_DOM:
2635 printf("E_DOM\n");
2636 break;
2637 case FileBase::E_RANGE:
2638 printf("E_RANGE\n");
2639 break;
2640 case FileBase::E_DEADLK:
2641 printf("E_DEADLK\n");
2642 break;
2643 case FileBase::E_NAMETOOLONG:
2644 printf("E_NAMETOOLONG\n");
2645 break;
2646 case FileBase::E_NOLCK:
2647 printf("E_NOLCK\n");
2648 break;
2649 case FileBase::E_NOSYS:
2650 printf("E_NOSYS\n");
2651 break;
2652 case FileBase::E_NOTEMPTY:
2653 printf("E_NOTEMPTY\n");
2654 break;
2655 case FileBase::E_LOOP:
2656 printf("E_LOOP\n");
2657 break;
2658 case FileBase::E_ILSEQ:
2659 printf("E_ILSEQ\n");
2660 break;
2661 case FileBase::E_NOLINK:
2662 printf("E_NOLINK\n");
2663 break;
2664 case FileBase::E_MULTIHOP:
2665 printf("E_MULTIHOP\n");
2666 break;
2667 case FileBase::E_USERS:
2668 printf("E_USERS\n");
2669 break;
2670 case FileBase::E_OVERFLOW:
2671 printf("E_OVERFLOW\n");
2672 break;
2673 default:
2674 printf("E_Unknown\n");
2675 break;
2677 return;
2680 //--------------------------------------------------
2681 // main
2682 //--------------------------------------------------
2683 #if defined WNT
2684 #define MAIN _cdecl main
2685 #else
2686 #define MAIN main
2687 #endif
2689 int MAIN( int argc, char* argv[] )
2691 sal_Bool fSuccess=sal_False;
2693 //Initialization
2694 fSuccess=Initialize();
2695 if ( !fSuccess )
2697 printf("Error during Initialization");
2698 return -1;
2702 if (argc==1)
2704 DirectoryOpenAndCloseTest();
2705 DirectoryCreateAndRemoveTest();
2707 FileOpenAndCloseTest();
2708 FileCreateAndRemoveTest();
2709 FileWriteAndReadTest();
2710 FileCopyAndMoveTest();
2711 FileSizeTest();
2712 FilePointerTest();
2713 FileAttributesTest();
2714 FileTimeTest();
2715 DirectoryItemTest();
2716 DirectoryFileStatusTest();
2717 VolumeFileStatusTest();
2718 FileFileStatusTest();
2719 VolumeInfoTest();
2720 FileBaseTest();
2721 SearchPathTest();
2722 AbsolutePathTest();
2723 CanonicalNameTest();
2725 // command line arguments ?
2726 else
2728 int i=1;
2730 while (i<argc)
2732 if (strcmp(argv[i], "doc")==0)
2733 DirectoryOpenAndCloseTest();
2734 else if (strcmp(argv[i], "dcr")==0)
2735 DirectoryCreateAndRemoveTest();
2736 else if (strcmp(argv[i], "foc")==0)
2737 FileOpenAndCloseTest();
2738 else if (strcmp(argv[i], "fcr")==0)
2739 FileCreateAndRemoveTest();
2740 else if (strcmp(argv[i], "fwr")==0)
2741 FileWriteAndReadTest();
2742 else if (strcmp(argv[i], "fcm")==0)
2743 FileCopyAndMoveTest();
2744 else if (strcmp(argv[i], "fs")==0)
2745 FileSizeTest();
2746 else if (strcmp(argv[i], "fp")==0)
2747 FilePointerTest();
2748 else if (strcmp(argv[i], "fa")==0)
2749 FileAttributesTest();
2750 else if (strcmp(argv[i], "ft")==0)
2751 FileTimeTest();
2752 else if (strcmp(argv[i], "di")==0)
2753 DirectoryItemTest();
2754 else if (strcmp(argv[i], "dfs")==0)
2755 DirectoryFileStatusTest();
2756 else if (strcmp(argv[i], "vfs")==0)
2757 VolumeFileStatusTest();
2758 else if (strcmp(argv[i], "ffs")==0)
2759 FileFileStatusTest();
2760 else if (strcmp(argv[i], "vi")==0)
2761 VolumeInfoTest();
2762 else if (strcmp(argv[i], "fb")==0)
2763 FileBaseTest();
2764 else if (strcmp(argv[i], "sp")==0)
2765 SearchPathTest();
2766 else if (strcmp(argv[i], "ap")==0)
2767 AbsolutePathTest();
2768 else if (strcmp(argv[i], "cn")==0)
2769 CanonicalNameTest();
2771 i++;
2775 // Shutdown
2776 fSuccess=Shutdown();
2777 if ( !fSuccess )
2779 printf("Error during Shutdown");
2780 return -1;
2783 return 0;