merge the formfield patch from ooo-build
[ooovba.git] / sal / workben / testfile.cxx
blob2cf4d8c9b527d4b32e615795ae7bb64b0d5fc00e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: testfile.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sal.hxx"
34 #define UNICODE
37 #include <osl/file.hxx>
38 #include <osl/process.h>
39 #include <osl/time.h>
40 #include <rtl/alloc.h>
41 #include <rtl/ustring.hxx>
42 #include <stdio.h>
43 #include <string.h>
44 #include <time.h>
47 #ifdef UNX
48 #include <wchar.h>
49 #endif
51 #ifdef WNT
52 #include <windows.h>
53 #endif
55 using namespace osl;
56 using namespace rtl;
58 #define MAXIMPATH 256
60 rtl::OUString root;
62 rtl::OUString dir1;
63 rtl::OUString dir2;
64 rtl::OUString dir_on_server;
65 rtl::OUString dir_not_exist;
66 rtl::OUString dir_not_exist_on_server;
67 rtl::OUString dir_wrong_semantic;
69 rtl::OUString file1;
70 rtl::OUString file2;
71 rtl::OUString file3;
72 rtl::OUString file_on_server;
73 rtl::OUString file_not_exist;
77 void print_error(::rtl::OString& str, FileBase::RC rc);
79 void PressKey()
81 printf("\nPress Return !\n");
82 int i=getchar();
85 void printFileName(::rtl::OUString& str)
87 rtl::OString aString;
89 aString = rtl::OUStringToOString( str, RTL_TEXTENCODING_ASCII_US );
91 printf( "%s", aString.getStr() );
93 return;
96 //--------------------------------------------------
97 // Initialization
98 //--------------------------------------------------
100 sal_Bool testLineBreak( sal_Char *pCount , sal_uInt64 nLen , sal_uInt32 *cLineBreak )
102 sal_Bool fSuccess=sal_False;
103 *cLineBreak=0;
105 if (nLen==0)
106 return fSuccess;
108 if ( *pCount==13 )
110 if (nLen>=1 && *(pCount+1)==10)
111 *cLineBreak=2;
112 else
113 *cLineBreak=1;
115 if (nLen>=2 && *(pCount+2)==10)
116 (*cLineBreak)++;
118 fSuccess=sal_True;
120 else if ( *pCount==10 )
122 *cLineBreak=1;
123 fSuccess=sal_True;
126 return fSuccess;
129 // Initialization
131 sal_Bool Initialize( void )
133 DirectoryItem aItem;
134 FileStatus aStatus( FileStatusMask_All );
135 rtl_uString *strExeFileURL=NULL;
136 oslProcessError ProcessError;
138 rtl::OUString iniFileURL;
139 File *pFile;
140 sal_Unicode *pExeFileCount;
142 FileBase::RC rc;
144 sal_uInt64 uBytesRequested;
145 sal_uInt64 uBytesRead;
146 sal_Char *pBuffer;
147 sal_Char *pBegin;
148 sal_Char *pCount;
150 rtl::OUString dir[12];
152 // Open to the ini-file
154 ProcessError=osl_getExecutableFile(&strExeFileURL);
156 if ( ProcessError == osl_Process_E_None)
158 pExeFileCount=rtl_uString_getStr(strExeFileURL)+rtl_uString_getLength(strExeFileURL);
160 // Search for the last slash in the Path
161 while (*pExeFileCount!=L'/' && pExeFileCount>rtl_uString_getStr(strExeFileURL))
162 pExeFileCount--;
164 // iniFileURL = strExeFileURL without the filename of the exe-File
165 iniFileURL=rtl::OUString( rtl_uString_getStr(strExeFileURL) ,(int) (pExeFileCount-rtl_uString_getStr(strExeFileURL)) );
167 // add "/testfile.ini" to iniFileURL
168 iniFileURL+=rtl::OUString::createFromAscii("/testfile.ini");
170 // Open the ini-File
171 pFile=new File( iniFileURL );
172 rc=pFile->open( OpenFlag_Read | OpenFlag_Write );
173 if ( rc!=FileBase::E_None )
175 rtl_uString_release(strExeFileURL);
176 return sal_False;
179 else
181 rtl_uString_release(strExeFileURL);
182 return sal_False;
185 // Get filesize of the ini-File
187 rc=DirectoryItem::get( iniFileURL, aItem );
188 if ( rc!=FileBase::E_None )
189 return sal_False;
191 rc=aItem.getFileStatus( aStatus );
192 if ( rc!=FileBase::E_None )
193 return sal_False;
195 uBytesRequested=aStatus.getFileSize();
197 // read ini-File
198 rc=pFile->setPos( Pos_Absolut, 0 );
199 pBuffer=(sal_Char*) rtl_allocateMemory( (sal_uInt32) (uBytesRequested+1)*sizeof(sal_Char) );
200 rtl_zeroMemory( pBuffer, (sal_uInt32)(uBytesRequested+1)*sizeof(sal_Char) );
202 rc=pFile->read( pBuffer , uBytesRequested , uBytesRead );
203 if ( rc!=FileBase::E_None )
204 return sal_False;
207 pBegin=pBuffer;
208 pCount=pBegin;
210 for ( int i=0 ; i<12 ; i++ )
212 sal_uInt32 cLineBrake=0;
213 while ( (pCount-pBuffer < uBytesRead) && *pCount!='=')
214 pCount++;
216 pCount++;
217 pBegin=pCount;
219 while ( (pCount-pBuffer < uBytesRead) && !testLineBreak(pCount,uBytesRead-(pCount-pBuffer), &cLineBrake))
220 pCount++;
222 dir[i]=rtl::OUString(pBegin, pCount-pBegin, RTL_TEXTENCODING_ASCII_US);
224 pCount+=cLineBrake;
225 pBegin=pCount;
228 root=rtl::OUString(dir[0]);
229 dir1=rtl::OUString(dir[1]);
230 dir2=rtl::OUString(dir[2]);
231 dir_on_server=rtl::OUString(dir[3]);
232 dir_not_exist=rtl::OUString(dir[4]);
233 dir_not_exist_on_server=rtl::OUString(dir[5]);
234 dir_wrong_semantic=rtl::OUString(dir[6]);
236 file1=rtl::OUString(dir[7]);
237 file2=rtl::OUString(dir[8]);
238 file3=rtl::OUString(dir[9]);
239 file_on_server=rtl::OUString(dir[10]);
240 file_not_exist=rtl::OUString(dir[11]);
242 // close the ini-file
243 rc=pFile->close();
245 rtl_freeMemory( pBuffer );
248 // Create directories
249 rc=Directory::create( dir1 );
250 if ( rc!=FileBase::E_None )
251 return sal_False;
253 rc=Directory::create( dir2 );
254 if ( rc!=FileBase::E_None )
255 return sal_False;
257 rc=Directory::create( dir_on_server );
258 if ( rc!=FileBase::E_None )
259 return sal_False;
261 pFile=new File( file1 );
262 rc=pFile->open( OpenFlag_Write | OpenFlag_Create );
263 if ( rc!=FileBase::E_None )
264 return sal_False;
265 rc=pFile->close();
266 delete pFile;
268 pFile=new File( file2 );
269 rc=pFile->open( OpenFlag_Write | OpenFlag_Create );
270 if ( rc!=FileBase::E_None )
271 return sal_False;
272 rc=pFile->close();
273 delete pFile;
275 pFile=new File( file_on_server );
276 rc=pFile->open( OpenFlag_Write | OpenFlag_Create );
277 if ( rc!=FileBase::E_None )
278 return sal_False;
279 rc=pFile->close();
280 delete pFile;
282 return sal_True;
285 //--------------------------------------------------
286 // Shutdown
287 //--------------------------------------------------
289 sal_Bool Shutdown( void )
291 sal_Bool fSuccess=sal_True;
292 FileBase::RC rc;
293 File *pFile;
295 // remove created files
297 pFile=new File( file1 );
298 rc=pFile->remove( file1 );
299 if ( rc!=FileBase::E_None )
300 fSuccess=sal_False;
301 delete pFile;
303 pFile=new File( file2 );
304 rc=pFile->remove( file2 );
305 if ( rc!=FileBase::E_None )
306 fSuccess=sal_False;
307 delete pFile;
309 // remove created directories
311 rc=Directory::remove( dir1 );
312 if ( rc!=FileBase::E_None )
313 fSuccess=sal_False;
315 rc=Directory::remove( dir2 );
316 if ( rc!=FileBase::E_None )
317 fSuccess=sal_False;
319 // remove created file on the server
321 pFile=new File( file_on_server );
322 rc=pFile->remove( file_on_server );
323 if ( rc!=FileBase::E_None )
324 fSuccess=sal_False;
325 delete pFile;
327 // remove created directory on the server
329 rc=Directory::remove( dir_on_server );
330 if ( rc!=FileBase::E_None )
331 fSuccess=sal_False;
333 return fSuccess;
336 //--------------------------------------------------
337 // helper functions
338 //--------------------------------------------------
340 // Show FileType
341 void showFileType( FileStatus::Type aType )
343 if ( aType==FileStatus::Directory )
344 printf( "FileType: Directory \n" );
345 else if ( aType==FileStatus::Volume )
346 printf( "FileType: Volume \n" );
347 else if ( aType==FileStatus::Regular )
348 printf( "FileType: Regular \n" );
349 else if ( aType==FileStatus::Unknown )
350 printf( "FileType: Unknown \n" );
354 // Show Attributes
355 void showAttributes( sal_uInt64 uAttributes )
357 if ( uAttributes==0 )
358 printf( "No Attributes \n" );
359 if ( uAttributes & Attribute_ReadOnly )
360 printf( "Attribute: ReadOnly \n" );
361 if ( uAttributes & Attribute_Hidden )
362 printf( "Attribute: Hidden \n" );
363 if ( uAttributes & Attribute_Executable )
364 printf( "Attribute: Executable \n");
365 if ( uAttributes & Attribute_GrpWrite )
366 printf( "Attribute: GrpWrite \n");
367 if ( uAttributes & Attribute_GrpRead )
368 printf( "Attribute: GrpRead \n" );
369 if ( uAttributes & Attribute_GrpExe )
370 printf( "Attribute: GrpExe \n" );
371 if ( uAttributes & Attribute_OwnWrite )
372 printf( "Attribute: OwnWrite \n");
373 if ( uAttributes & Attribute_OwnRead )
374 printf( "Attribute: OwnRead \n" );
375 if ( uAttributes & Attribute_OwnExe )
376 printf( "Attribute: OwnExe \n" );
377 if ( uAttributes & Attribute_OthWrite )
378 printf( "Attribute: OthWrite \n" );
379 if ( uAttributes & Attribute_OthRead )
380 printf( "Attribute: OthRead \n");
381 if ( uAttributes & Attribute_OthExe )
382 printf( "Attribute: OthExe \n" );
384 return;
387 // Show Time
388 void showTime( TimeValue aTime )
390 TimeValue aLocalTimeVal, aSystemTimeVal , aSysTimeVal;
391 oslDateTime aDateTime, aSystemTime;
393 if ( osl_getLocalTimeFromSystemTime( &aTime, &aLocalTimeVal ) )
395 if ( osl_getDateTimeFromTimeValue( &aLocalTimeVal, &aDateTime ) )
397 printf("\t%02i.%02i.%4i , %02i.%02i.%02i Uhr\n", aDateTime.Day, aDateTime.Month, aDateTime.Year, aDateTime.Hours, aDateTime.Minutes, aDateTime.Seconds);
399 else
400 printf("Error !\n");
403 if ( osl_getDateTimeFromTimeValue( &aTime, &aSystemTime ) )
405 printf("SystemTime: \t\t%02i.%02i.%4i , %02i.%02i.%02i Uhr\n", aSystemTime.Day, aSystemTime.Month, aSystemTime.Year, aSystemTime.Hours, aSystemTime.Minutes, aSystemTime.Seconds);
407 else
408 printf("Error !\n");
410 //Verify
412 if ( osl_getTimeValueFromDateTime( &aSystemTime, &aSystemTimeVal ) )
414 if ( ( aSystemTimeVal.Seconds == aTime.Seconds ) && ( aSystemTimeVal.Nanosec == aTime.Nanosec ))
415 printf ("Verify : TimeValue : ok! \n");
416 else
418 printf ("Verify : TimeValue : Error! \n");
419 printf ("aTime : %u \n", aTime.Seconds);
420 printf ("aSystemTimeVal : %u \n", aSystemTimeVal.Seconds);
423 else
424 printf ("Verify : TimeValue : Error! \n");
427 if ( osl_getSystemTimeFromLocalTime( &aLocalTimeVal , &aSysTimeVal ) )
429 if ( ( aSysTimeVal.Seconds == aTime.Seconds ) && ( aSysTimeVal.Nanosec == aTime.Nanosec ))
430 printf ("Verify : SystemTime : ok! \n");
431 else
433 printf ("Verify : SystemTime : Error! \n");
434 printf ("aTime : %u\n", aTime.Seconds);
435 printf ("aSystemTimeVal : %u\n", aSysTimeVal.Seconds);
438 else
439 printf ("Verify : SystemTime : Error! \n");
441 return;
444 TimeValue getSystemTime()
446 TimeValue aTime;
447 time_t ltime;
449 time( &ltime );
451 aTime.Seconds = ltime;
452 aTime.Nanosec = 0;
454 return aTime;
458 //--------------------------------------------------
459 // DirectoryOpenAndCloseTest
460 //--------------------------------------------------
462 void DirectoryOpenAndCloseTest( void )
464 FileBase::RC rc;
465 int i=0;
466 Directory *pDir;
468 printf( "--------------------------------------------\n");
469 printf( "Directory-Open-And-Close-Test\n");
470 printf( "--------------------------------------------\n\n");
472 //--------------------------------------------------
473 // open an existing directory
474 //--------------------------------------------------
476 pDir=new Directory( dir1 );
477 printf( "Open an existing directory: ");
478 printFileName( dir1 );
479 printf( "\n" );
481 rc= pDir->open();
482 print_error( rtl::OString( "Open Directory" ), rc );
484 if ( pDir->isOpen() )
486 print_error( rtl::OString( "Directory is Open" ), rc );
489 // Close Directory
490 rc=pDir->close();
491 print_error( rtl::OString( "Close Directory" ), rc );
493 delete pDir;
494 printf( "\n" );
496 //--------------------------------------------------
497 // open a not existing directory
498 //--------------------------------------------------
500 pDir=new Directory( dir_not_exist );
502 printf( "Open a not existing directory: ");
503 printFileName( dir_not_exist );
504 printf( "\n" );
506 rc= pDir->open();
508 print_error( rtl::OString( "Open Directory" ), rc );
510 delete pDir;
512 printf( "\n" );
514 //--------------------------------------------------
515 // open a directory with a wrong semantic
516 //--------------------------------------------------
517 pDir=new Directory( dir_wrong_semantic );
519 printf( "Open a directory with a wrong semantic: ");
520 printFileName( dir_wrong_semantic );
521 printf( "\n" );
523 rc= pDir->open();
524 print_error( rtl::OString( "Open Directory" ), rc );
526 delete pDir;
528 printf( "\n" );
530 //--------------------------------------------------
531 // open an existing directory on a server
532 //--------------------------------------------------
534 pDir=new Directory( dir_on_server );
536 printf( "Open an existing directory on a server: ");
537 printFileName( dir_on_server );
538 printf( "\n" );
540 rc= pDir->open();
541 print_error( rtl::OString( "Open Directory" ), rc );
543 // Close Directory
544 rc=pDir->close();
545 print_error( rtl::OString( "Close Directory" ), rc );
547 delete pDir;
548 printf( "\n" );
550 //--------------------------------------------------
551 // open a not existing directory on a server
552 //--------------------------------------------------
554 pDir=new Directory( dir_not_exist_on_server );
556 printf( "Open a not existing directory on a server: ");
557 printFileName( dir_not_exist_on_server );
558 printf( "\n" );
560 rc= pDir->open();
561 print_error( rtl::OString( "Open Directory" ), rc );
563 delete pDir;
564 printf( "\n" );
566 //--------------------------------------------------
567 // Close a not existing directory
568 //--------------------------------------------------
570 pDir=new Directory( dir_not_exist );
571 printf( "Close a not existing directory: ");
572 printFileName( dir_not_exist );
573 printf( "\n" );
575 rc=pDir->close();
576 print_error( rtl::OString( "Close Directory" ), rc );
578 PressKey();
579 return;
583 //--------------------------------------------------
584 // DirectoryCreateAndRemoveTest
585 //--------------------------------------------------
587 void DirectoryCreateAndRemoveTest( void )
589 FileBase::RC rc,rc1;
590 int i=0;
591 Directory *pDir;
593 printf( "--------------------------------------------\n" );
594 printf( "Directory-Create-And-Remove-Test\n" );
595 printf( "--------------------------------------------\n\n" );
597 //--------------------------------------------------
598 // Create directory
599 //--------------------------------------------------
600 printf( "Create a not existing directory: ");
601 printFileName( dir_not_exist );
602 printf( "\n" );
604 rc=Directory::create( dir_not_exist) ;
605 print_error( rtl::OString( "Create Directory" ), rc );
607 // Verify
608 pDir=new Directory( dir_not_exist );
610 rc= pDir->open();
611 print_error( rtl::OString( "Verify" ), rc );
612 pDir->close();
613 delete pDir;
615 printf( "\n" );
617 //--------------------------------------------------
618 // Create a directory on a server
619 //--------------------------------------------------
621 printf( "Create a not existing directory on a server: ");
622 printFileName( dir_not_exist_on_server );
623 printf( "\n" );
625 rc=Directory::create( dir_not_exist_on_server );
626 print_error( rtl::OString( "Create Directory" ), rc );
628 // Verify
629 pDir=new Directory( dir_not_exist_on_server );
630 rc= pDir->open();
631 print_error( rtl::OString( "Verify" ), rc );
632 pDir->close();
633 delete pDir;
635 printf( "\n" );
637 //--------------------------------------------------
638 // Remove Directories
639 //--------------------------------------------------
641 printf( "Remove the created directories: \n" );
643 rc=Directory::remove( dir_not_exist );
645 rc1=Directory::remove( dir_not_exist_on_server );
647 if ( rc==FileBase::E_None && rc1==FileBase::E_None )
648 print_error( rtl::OString( "Remove Directories" ), FileBase::E_None );
649 else if ( rc!=FileBase::E_None )
650 print_error( rtl::OString( "Remove local Directory" ),rc );
651 else
652 print_error( rtl::OString( "Remove Directory on a server" ),rc1 );
654 printf( "\n" );
656 //--------------------------------------------------
657 // Remove a not existing directory
658 //--------------------------------------------------
660 printf( "Remove a not existing directory: ");
661 printFileName( dir_not_exist );
662 printf( "\n" );
664 rc=Directory::remove( dir_not_exist );
665 print_error( rtl::OString( "Remove" ),rc );
667 PressKey();
668 return;
671 //--------------------------------------------------
672 // FileOpenAndCloseTest
673 //--------------------------------------------------
675 static void FileOpenAndCloseTest( void )
677 FileBase::RC rc;
678 int i=0;
680 printf( "--------------------------------------------\n" );
681 printf( "File-Open-And-Close-Test\n" );
682 printf( "--------------------------------------------\n\n" );
684 File *pFile;
686 pFile=new File( file1 );
688 printf( "Open an existing file: ");
689 printFileName( file1 );
690 printf( "\n" );
692 //--------------------------------------------------
693 // open an existing file (Read)
694 //--------------------------------------------------
696 rc=pFile->open( OpenFlag_Read );
697 print_error( rtl::OString( "Open File (Read)" ), rc );
699 //--------------------------------------------------
700 // close the file
701 //--------------------------------------------------
703 rc=pFile->close();
704 print_error( rtl::OString( "Close File" ), rc );
706 printf( "\n" );
708 //--------------------------------------------------
709 // open an existing file (Write)
710 //--------------------------------------------------
712 rc=pFile->open( OpenFlag_Write );
713 print_error( rtl::OString( "Open File (Write)" ), rc );
715 //--------------------------------------------------
716 // close the file
717 //--------------------------------------------------
719 rc=pFile->close();
720 print_error( rtl::OString( "Close File" ), rc );
722 printf( "\n" );
724 //--------------------------------------------------
725 // close the file a second time
726 //--------------------------------------------------
728 rc=pFile->close();
729 print_error( rtl::OString( "Close the file a second time" ), rc );
731 delete pFile;
732 PressKey();
735 //--------------------------------------------------
736 // FileCreateAndRemoveTest
737 //--------------------------------------------------
739 void FileCreateAndRemoveTest()
741 FileBase::RC rc;
742 File *pFile;
744 printf( "--------------------------------------------\n" );
745 printf( "File-Create-And-Remove-Test\n" );
746 printf( "--------------------------------------------\n\n" );
748 pFile=new File( file_not_exist );
750 printf( "Create File: ");
751 printFileName( file_not_exist );
752 printf( "\n" );
754 //----------------------------------------------------
755 // open (create) a not existing file (Read and write)
756 //----------------------------------------------------
758 rc = pFile->open( OpenFlag_Read | OpenFlag_Write | osl_File_OpenFlag_Create );
760 print_error( rtl::OString( "Create and Open File (Read & Write)" ), rc );
762 //----------------------------------------------------
763 // close the file
764 //----------------------------------------------------
766 rc=pFile->close();
767 print_error( rtl::OString( "Close File" ), rc );
769 //----------------------------------------------------
770 // remove the file
771 //----------------------------------------------------
773 rc=pFile->remove( file_not_exist );
774 print_error( rtl::OString(" Remove File" ), rc );
776 printf( "\n" );
778 //----------------------------------------------------
779 // remove the same file a second time
780 //----------------------------------------------------
781 rc=pFile->remove( file_not_exist );
782 print_error( rtl::OString( "Remove a not existing File" ), rc );
784 //----------------------------------------------------
785 // remove an open file
786 //----------------------------------------------------
788 pFile->open( OpenFlag_Read | OpenFlag_Write | osl_File_OpenFlag_Create );
790 rc=pFile->remove( file_not_exist );
791 print_error( rtl::OString( "Remove an open File" ), rc );
793 pFile->close();
794 pFile->remove( file_not_exist );
796 PressKey();
798 return;
801 //--------------------------------------------------
802 // FileWriteAndReadTest
803 //--------------------------------------------------
805 void FileWriteAndReadTest( void )
807 FileBase::RC rc;
809 sal_uInt64 uWritten;
810 sal_uInt64 uRead;
811 sal_Char *pWriteBuffer="Hier kommt der Osterhase !";
812 sal_uInt64 nLen=strlen( pWriteBuffer );
813 sal_Char *pReadBuffer;
815 printf( "--------------------------------------------\n" );
816 printf( "File-Write-And-Read-Test\n" );
817 printf( "--------------------------------------------\n\n" );
819 File *pFile;
821 pFile=new File( file_not_exist );
823 printf( "Create File: ");
824 printFileName( file_not_exist );
825 printf("\n");
827 //----------------------------------------------------
828 // open (create) a not existing file (Read and write)
829 //----------------------------------------------------
831 rc = pFile->open( OpenFlag_Read | OpenFlag_Write | osl_File_OpenFlag_Create );
833 print_error( rtl::OString( "Create and Open File (Read & Write)" ), rc );
835 printf( "\n" );
837 //----------------------------------------------------
838 // write a string to the file
839 //----------------------------------------------------
840 rc=pFile->write( pWriteBuffer , nLen , uWritten );
841 print_error( rtl::OString( "Write File" ), rc );
843 if(uWritten==nLen)
844 printf( "Verify: OK! \n" );
845 else
846 printf( "Verify: Error\n" );
848 printf( "\n" );
850 //----------------------------------------------------
851 // move the filepointer to the beginning
852 //----------------------------------------------------
854 rc=pFile->setPos( Pos_Absolut , 0 );
855 print_error( rtl::OString( "Set FilePointer to the beginning of the file" ), rc );
857 printf( "\n" );
859 //----------------------------------------------------
860 // read the string
861 //----------------------------------------------------
863 pReadBuffer=(sal_Char*) rtl_allocateMemory( (sal_uInt32)(nLen+1)*sizeof(sal_Char) );
864 rtl_zeroMemory( pReadBuffer, (sal_uInt32)(nLen+1)*sizeof(sal_Char) );
865 rc=pFile->read( pReadBuffer , nLen,uRead );
866 print_error( rtl::OString( "Read File" ), rc );
868 if (strcmp(pWriteBuffer, pReadBuffer)==0)
870 printf( "Verify: OK !\n" );
871 printf( "Text: %s\n",pReadBuffer );
873 else
874 printf( "Verify: Error\n" );
876 rtl_freeMemory( pReadBuffer );
878 printf( "\n" );
880 // close the file
881 rc=pFile->close();
882 print_error( rtl::OString( "Close File" ), rc );
884 // remove the file
885 rc=pFile->remove( file_not_exist );
886 print_error( rtl::OString( "Remove File" ), rc );
888 PressKey();
890 return;
894 //--------------------------------------------------
895 // FileCopyMoveTest
896 //--------------------------------------------------
898 void FileCopyAndMoveTest( void )
900 FileBase::RC rc;
902 printf( "--------------------------------------------\n" );
903 printf( "File-Copy-Move-Test\n" );
904 printf( "--------------------------------------------\n\n" );
907 File *pFile;
908 rtl::OUString destPath(dir2);
910 //--------------------------------------------------
911 // FileCopyTest
912 //--------------------------------------------------
914 destPath+=rtl::OUString::createFromAscii("/");
915 destPath+=file3;
917 printf( "Copy the file ");
918 printFileName( file1 );
919 printf( " to ");
920 printFileName( destPath );
921 printf( "\n" );
924 rc=File::copy( file1 , destPath );
925 print_error( rtl::OString( "FileCopy" ), rc );
927 pFile=new File( destPath );
929 rc=pFile->open( OpenFlag_Read );
930 if ( rc == FileBase::E_None)
932 printf( "Verify: OK!\n" );
933 pFile->close();
934 File::remove( destPath );
936 else
937 printf( "Verify: Error!\n" );
939 delete pFile;
941 printf( "\n" );
943 //--------------------------------------------------
944 // Copy a file to a not existing directory
945 //--------------------------------------------------
947 destPath=rtl::OUString( dir_not_exist );
948 destPath+=rtl::OUString::createFromAscii("/");
949 destPath+=file3;
951 printf( "Copy a file to a not existing directory \n");
952 printf( "Copy the file %s to %s\n", file1.getStr(), destPath.getStr() );
954 rc=File::copy( file1, destPath );
955 print_error( rtl::OString( "FileCopy" ), rc );
957 printf( "\n" );
959 //--------------------------------------------------
960 // Copy a directory
961 //--------------------------------------------------
963 printf( "Copy the directory: ");
964 printFileName( dir1 );
965 printf( " to ");
966 printFileName( dir2 );
967 printf( "\n" );
969 rc=File::copy( dir1 , dir2 );
970 print_error( rtl::OString( "FileCopy" ), rc );
972 printf( "\n" );
974 //--------------------------------------------------
975 // FileMoveTest
976 //--------------------------------------------------
978 destPath=rtl::OUString( dir2 );
979 destPath+=rtl::OUString::createFromAscii("/");
980 destPath+=file3;
982 printf( "Move the file ");
983 printFileName( file1 );
984 printf( " to ");
985 printFileName( destPath );
986 printf( "\n" );
988 rc=File::move( file1, destPath );
989 print_error( rtl::OString( "FileMove" ), rc );
991 pFile=new File( destPath );
993 rc=pFile->open( OpenFlag_Read );
994 if ( rc==FileBase::E_None )
996 pFile->close();
998 delete pFile;
999 pFile=new File( file1 );
1001 rc=pFile->open( OpenFlag_Read );
1003 if ( rc!=FileBase::E_None )
1005 printf( "Verify: OK!\n" );
1006 File::move( destPath, file1 );
1008 else
1010 printf( "Verify: Error!\n" );
1011 pFile->close();
1012 File::remove( destPath );
1015 else
1016 printf( "Verify: Error!\n" );
1018 delete pFile;
1020 printf( "\n" );
1023 //--------------------------------------------------
1024 // Move a file to a not existing directory
1025 //--------------------------------------------------
1027 destPath=rtl::OUString( dir_not_exist );
1028 destPath+=rtl::OUString::createFromAscii("/");
1029 destPath+=file3;
1031 printf( "Move a file to a not existing directory: \n");
1032 printf( "Move the file ");
1033 printFileName( file1 );
1034 printf( " to ");
1035 printFileName( destPath );
1036 printf( "\n" );
1038 rc=File::move( file1 , destPath );
1039 print_error( rtl::OString( "FileMove" ), rc );
1041 printf( "\n" );
1043 //--------------------------------------------------
1044 // Move a directory
1045 //--------------------------------------------------
1047 printf( "Move a directory: \n");
1049 printf( "Move the directory ");
1050 printFileName( dir1 );
1051 printf( " to ");
1052 printFileName( dir_not_exist );
1053 printf( "\n" );
1056 rc=File::move( dir1 , dir_not_exist);
1057 print_error( rtl::OString( "FileMove" ), rc );
1059 if ( rc == FileBase::E_None )
1060 File::move( dir_not_exist , dir1);
1062 printf( "\n" );
1065 PressKey();
1066 return;
1069 //----------------------------------------------------
1070 // FileSizeTest
1071 //----------------------------------------------------
1073 void FileSizeTest( void )
1075 FileBase::RC rc;
1076 sal_uInt64 filesize;
1077 DirectoryItem aItem;
1079 printf( "--------------------------------------------\n" );
1080 printf( "File-Size-Test\n" );
1081 printf( "--------------------------------------------\n\n" );
1084 File aFile( file_not_exist );
1086 printf( "Create File: ");
1087 printFileName( file_not_exist );
1088 printf( "\n\n");
1090 rc = aFile.open( OpenFlag_Read | OpenFlag_Write | osl_File_OpenFlag_Create );
1091 print_error( rtl::OString( "Create and Open File (Read & Write)" ), rc );
1092 printf( "\n" );
1094 if ( rc == FileBase::E_None )
1096 //----------------------------------------------------
1097 // Set Filesize to 5000
1098 //----------------------------------------------------
1100 printf( "Set FileSize to 5000\n" );
1101 rc=aFile.setSize( 5000 );
1102 print_error( rtl::OString( "Set FileSize" ), rc );
1104 printf( "\n" );
1105 printf( "Verify:\n" );
1107 //----------------------------------------------------
1108 // Check whether Filesize is set to 5000
1109 //----------------------------------------------------
1111 rc=DirectoryItem::get( file_not_exist, aItem );
1112 print_error( rtl::OString( "Get DirectoryItem" ), rc );
1114 if ( rc == FileBase::E_None )
1116 FileStatus rStatus( FileStatusMask_FileSize );
1117 rc=aItem.getFileStatus( rStatus );
1118 print_error( rtl::OString( "Get FileStatus" ), rc );
1120 if ( rc == FileBase::E_None )
1122 filesize=rStatus.getFileSize();
1124 if ( filesize == 5000 )
1125 printf( "\nOK : FileSize: %i\n", filesize );
1126 else
1127 printf( "\nError : FileSize: %i\n", filesize );
1131 printf( "\n" );
1133 //----------------------------------------------------
1134 // Set Filesize to -1
1135 //----------------------------------------------------
1137 printf( "Set FileSize to -1\n" );
1138 rc=aFile.setSize( -1 );
1139 print_error( rtl::OString( "Set FileSize" ), rc );
1141 printf( "\n" );
1143 // close the file
1144 rc=aFile.close();
1145 print_error( rtl::OString( "Close File" ), rc );
1147 // remove the file
1148 rc=File::remove( file_not_exist );
1149 print_error( rtl::OString( "Remove File" ), rc );
1152 PressKey();
1154 return;
1158 //----------------------------------------------------
1159 // FilePointerTest
1160 //----------------------------------------------------
1162 void FilePointerTest( void )
1164 FileBase::RC rc;
1165 sal_uInt64 filepointer;
1167 printf( "--------------------------------------------\n" );
1168 printf( "File-Pointer-Test\n" );
1169 printf( "--------------------------------------------\n\n" );
1172 File rFile( file_not_exist );
1174 printf( "Create File: ");
1175 printFileName( file_not_exist );
1176 printf( "\n\n");
1178 rc = rFile.open( OpenFlag_Read | OpenFlag_Write | osl_File_OpenFlag_Create );
1179 print_error( rtl::OString( "Create and Open File (Read & Write) "), rc );
1180 printf( "\n" );
1182 if ( rc==FileBase::E_None )
1185 //----------------------------------------------------
1186 // get the position of the filepointer
1187 //----------------------------------------------------
1189 rc =rFile.getPos( filepointer );
1190 print_error( rtl::OString( "GetPos" ), rc );
1191 printf( "Position of the FilePointer: %i\n", filepointer );
1193 printf( "\n" );
1195 //----------------------------------------------------
1196 // set the filepointer at the end of a file
1197 //----------------------------------------------------
1199 printf( "Set FileSize to 5000\n" );
1200 rFile.setSize( 5000 );
1202 printf( "Set the FilePointer at the end of the file (5000)\n" );
1203 rc=rFile.setPos( Pos_End,0 );
1204 print_error( rtl::OString( "SetPos" ), rc );
1206 rc=rFile.getPos( filepointer );
1208 if ( filepointer==5000 )
1210 print_error( rtl::OString( "GetPos" ), rc );
1211 printf( "\nVerify: OK !\n" );
1212 printf( "Filepointer-Position: %llu\n",filepointer );
1214 else
1216 print_error( rtl::OString( "GetPos" ), rc );
1217 printf( "\nFilePointer-Test: Error\n" );
1218 printf( "Filepointer-Position: %i != 5000 \n",filepointer );
1221 printf( "\n" );
1223 // close the file
1224 rc=rFile.close();
1225 print_error( rtl::OString( "Close File" ), rc );
1227 // remove the file
1228 rc=File::remove( file_not_exist );
1229 print_error( rtl::OString( "Remove File" ), rc );
1232 PressKey();
1234 return;
1237 //--------------------------------------------------
1238 // FileAttributesTest
1239 //--------------------------------------------------
1241 void verifyFileAttributes( void )
1243 FileBase::RC rc;
1244 DirectoryItem aItem;
1245 FileStatus rStatus( FileStatusMask_Attributes );
1247 printf( "\nVerify:\n" );
1249 rc=DirectoryItem::get( file1, aItem );
1251 if ( rc==FileBase::E_None )
1253 rc=aItem.getFileStatus( rStatus );
1255 if ( rc==FileBase::E_None )
1257 sal_uInt64 uAttributes=rStatus.getAttributes();
1258 showAttributes(uAttributes);
1259 printf( "\n" );
1261 else
1262 print_error( rtl::OString( "Get FileStatus" ), rc );
1264 else
1265 print_error( rtl::OString( "Get DirectoryItem" ), rc );
1267 return;
1270 #ifdef UNX
1271 void FileAttributesTest( void )
1273 FileBase::RC rc;
1275 printf( "--------------------------------------------\n" );
1276 printf( "File-Attributes-Test\n" );
1277 printf( "--------------------------------------------\n\n" );
1279 printf( "File: ");
1280 printFileName( file1 );
1281 printf( "\n\n" );
1284 rc=File::setAttributes( file1, Attribute_GrpWrite );
1285 print_error( rtl::OString( "Set Attribute: GrpWrite" ), rc );
1287 verifyFileAttributes();
1289 rc=File::setAttributes( file1, 0 );
1290 if ( rc!=FileBase::E_None )
1291 print_error( rtl::OString( "Reset Attributes" ), rc );
1293 rc=File::setAttributes( file1, Attribute_GrpRead );
1294 print_error( rtl::OString( "Set Attribute: GrpRead" ), rc );
1296 verifyFileAttributes();
1298 rc=File::setAttributes( file1, 0 );
1299 if ( rc!=FileBase::E_None )
1300 print_error( rtl::OString( "Reset Attributes" ), rc );
1302 rc=File::setAttributes( file1, Attribute_GrpExe );
1303 print_error( rtl::OString( "Set Attribute: GrpExe" ), rc );
1305 verifyFileAttributes();
1307 rc=File::setAttributes( file1, 0 );
1308 if ( rc!=FileBase::E_None )
1309 print_error( rtl::OString( "Reset Attributes" ), rc );
1311 rc=File::setAttributes( file1, Attribute_OwnWrite );
1312 print_error( rtl::OString( "Set Attribute: OwnWrite" ), rc );
1314 verifyFileAttributes();
1316 rc=File::setAttributes( file1, 0 );
1317 if ( rc!=FileBase::E_None )
1318 print_error( rtl::OString( "Reset Attributes" ), rc );
1320 rc=File::setAttributes( file1, Attribute_OwnRead );
1321 print_error( rtl::OString( "Set Attribute: OwnRead" ), rc );
1323 verifyFileAttributes();
1325 rc=File::setAttributes( file1, 0 );
1326 if ( rc!=FileBase::E_None )
1327 print_error( rtl::OString( "Reset Attributes" ), rc );
1329 rc=File::setAttributes( file1, Attribute_OwnExe );
1330 print_error( rtl::OString( "Set Attribute: OwnExe" ), rc );
1332 verifyFileAttributes();
1334 rc=File::setAttributes( file1, 0 );
1335 if ( rc!=FileBase::E_None )
1336 print_error( rtl::OString( "Reset Attributes" ), rc );
1338 rc=File::setAttributes( file1, Attribute_OthWrite );
1339 print_error( rtl::OString( "Set Attribute: OthWrite" ), rc );
1341 verifyFileAttributes();
1343 rc=File::setAttributes( file1, 0 );
1344 if ( rc!=FileBase::E_None )
1345 print_error( rtl::OString( "Reset Attributes" ), rc );
1347 rc=File::setAttributes( file1, Attribute_OthRead );
1348 print_error( rtl::OString( "Set Attribute: OthRead" ), rc );
1350 verifyFileAttributes();
1352 rc=File::setAttributes( file1, 0 );
1353 if ( rc!=FileBase::E_None )
1354 print_error( rtl::OString( "Reset Attributes" ), rc );
1356 rc=File::setAttributes( file1, Attribute_OthExe );
1357 print_error( rtl::OString( "Set Attribute: OthExe" ), rc );
1359 verifyFileAttributes();
1361 rc=File::setAttributes( file1, 0 );
1362 if ( rc!=FileBase::E_None )
1363 print_error( rtl::OString( "Reset Attributes" ), rc );
1366 rc=File::setAttributes( file1, Attribute_GrpWrite | Attribute_GrpRead | Attribute_GrpExe | Attribute_OwnWrite | Attribute_OwnRead | Attribute_OwnExe | Attribute_OthWrite | Attribute_OthRead | Attribute_OthExe );
1367 print_error( rtl::OString( "Set all Attributes" ), rc );
1369 verifyFileAttributes();
1371 PressKey();
1373 return;
1375 #endif
1377 #ifdef WNT
1378 void FileAttributesTest( void )
1380 FileBase::RC rc;
1382 printf( "--------------------------------------------\n" );
1383 printf( "File-Attributes-Test\n" );
1384 printf( "--------------------------------------------\n\n" );
1386 printf( "File: ");
1387 printFileName( file1 );
1388 printf( "\n\n" );
1391 rc=File::setAttributes( file1, Attribute_ReadOnly );
1392 print_error( rtl::OString( "Set Attribute: ReadOnly" ), rc );
1394 verifyFileAttributes();
1396 rc=File::setAttributes( file1, 0 );
1397 print_error( rtl::OString( "Reset Attributes" ), rc );
1399 verifyFileAttributes();
1401 rc=File::setAttributes( file1, Attribute_Hidden );
1402 print_error( rtl::OString( "Set Attribute: Hidden" ), rc );
1404 verifyFileAttributes();
1406 rc=File::setAttributes( file1, 0 );
1407 print_error( rtl::OString( "Reset Attributes" ), rc );
1409 verifyFileAttributes();
1411 rc=File::setAttributes( file1, Attribute_Hidden | Attribute_ReadOnly );
1412 print_error( rtl::OString( "Set Attribute: Hidden & ReadOnly" ), rc );
1414 verifyFileAttributes();
1416 rc=File::setAttributes( file1, 0 );
1417 print_error( rtl::OString( "Reset Attributes") , rc );
1419 verifyFileAttributes();
1421 PressKey();
1423 return;
1425 #endif
1427 //--------------------------------------------------
1428 // FileTimeTest
1429 //--------------------------------------------------
1431 void FileTimeTest( void )
1433 FileBase::RC rc;
1435 DirectoryItem aItem;
1437 struct tm sSysCreationTime = { 0, 20, 12, 4, 9, 100 };
1438 struct tm sSysAccessTime = { 0, 40, 1, 6, 5, 98 };
1439 struct tm sSysModifyTime = { 0, 1, 24, 13, 11, 95 };
1441 time_t aSysCreationTime = mktime( &sSysCreationTime );
1442 time_t aSysAccessTime = mktime( &sSysAccessTime );
1443 time_t aSysModifyTime = mktime( &sSysModifyTime );
1445 TimeValue aCreationTime = { aSysCreationTime, 0};
1446 TimeValue aAccessTime = { aSysAccessTime, 0};
1447 TimeValue aModifyTime = { aSysModifyTime, 0};
1449 TimeValue aCreationTimeRead;
1450 TimeValue aAccessTimeRead;
1451 TimeValue aModifyTimeRead;
1454 printf( "--------------------------------------------\n" );
1455 printf( "File-Time-Test\n" );
1456 printf( "--------------------------------------------\n\n" );
1458 printf( "File: ");
1459 printFileName( file1 );
1460 printf( "\n\n" );
1462 printf( "CreationTime \t : ");
1463 showTime( aCreationTime );
1465 printf( "\nAccessTime \t : ");
1466 showTime( aAccessTime );
1468 printf( "\nModifyTime \t : ");
1469 showTime( aModifyTime );
1471 //--------------------------------------------------
1472 // setTime
1473 //--------------------------------------------------
1475 printf( "\n" );
1476 rc=File::setTime( file1 , aCreationTime , aAccessTime , aModifyTime );
1477 print_error( rtl::OString( "SetTime" ), rc );
1479 //--------------------------------------------------
1480 // Verify
1481 //--------------------------------------------------
1483 FileStatus rStatus( FileStatusMask_CreationTime | FileStatusMask_AccessTime | FileStatusMask_ModifyTime);
1485 printf( "\nVerify:\n" );
1487 rc=DirectoryItem::get( file1, aItem );
1488 print_error( rtl::OString( "Get DirectoryItem" ), rc );
1490 if ( rc==FileBase::E_None )
1492 rc=aItem.getFileStatus( rStatus );
1493 print_error( rtl::OString( "Get FileStatus" ), rc );
1494 printf( "\n" );
1496 if ( rc==FileBase::E_None )
1498 //--------------------------------------------------
1499 // GetCreationTime
1500 //--------------------------------------------------
1502 aCreationTimeRead=rStatus.getCreationTime();
1503 #ifdef WNT
1504 if ( aCreationTime.Seconds == aCreationTimeRead.Seconds && aCreationTime.Nanosec == aCreationTimeRead.Nanosec )
1505 printf( "GetCreationTime: ok : " );
1506 else
1507 printf( "GetCreationTime: Error : " );
1509 showTime( aCreationTimeRead );
1510 printf( "\n" );
1511 #endif
1512 //--------------------------------------------------
1513 // GetAccessTime
1514 //--------------------------------------------------
1516 aAccessTimeRead=rStatus.getAccessTime();
1518 if ( aAccessTime.Seconds == aAccessTimeRead.Seconds && aAccessTime.Nanosec == aAccessTimeRead.Nanosec )
1519 printf( "GetAccessTime: ok : " );
1520 else
1521 printf( "GetAccessTime: Error : " );
1523 showTime( aAccessTimeRead );
1524 printf( "\n" );
1526 //--------------------------------------------------
1527 // GetModifyTime
1528 //--------------------------------------------------
1530 aModifyTimeRead=rStatus.getModifyTime();
1532 if ( aModifyTime.Seconds == aModifyTimeRead.Seconds && aModifyTime.Nanosec == aModifyTimeRead.Nanosec )
1533 printf( "GetModifyTime: ok : " );
1534 else
1535 printf( "GetModifyTime: Error : " );
1537 showTime( aModifyTimeRead );
1538 printf( "\n" );
1542 PressKey();
1543 return;
1547 //--------------------------------------------------
1548 // DirectoryItemTest
1549 //--------------------------------------------------
1551 void DirectoryItemTest( void )
1553 FileBase::RC rc;
1554 Directory *pDir;
1555 DirectoryItem aItem;
1556 FileStatus *pStatus;
1557 File *pFile;
1559 printf( "--------------------------------------------\n" );
1560 printf( "Directory-Item-Test\n" );
1561 printf( "--------------------------------------------\n\n" );
1563 //--------------------------------------------------
1564 // get DirectoryItem from an existing directory
1565 //--------------------------------------------------
1567 printf( "Get DirectoryItem from an existing Directory: ");
1568 printFileName( dir1 );
1569 printf( "\n");
1571 rc=DirectoryItem::get( dir1 , aItem );
1572 print_error( rtl::OString( "GetDirectoryItem" ), rc );
1574 pStatus=new FileStatus( FileStatusMask_All );
1575 rc=aItem.getFileStatus( *pStatus );
1577 if ( rc==FileBase::E_None )
1579 printf( "GetFileStatus: FileURL: ");
1580 printFileName(pStatus->getFileURL() );
1581 printf( "\n" );
1584 delete pStatus;
1586 printf( "\n" );
1588 //--------------------------------------------------
1589 // get DirectoryItem from a not existing directory
1590 //--------------------------------------------------
1592 printf( "Get DirectoryItem from a not existing Directory: ");
1593 printFileName( dir_not_exist );
1594 printf( "\n" );
1596 rc=DirectoryItem::get( dir_not_exist , aItem );
1597 print_error( rtl::OString( "Get DirectoryItem" ), rc );
1599 printf( "\n" );
1601 //--------------------------------------------------
1602 // get DirectoryItem from an existing file
1603 //--------------------------------------------------
1605 printf( "Get DirectoryItem from an existing File: ");
1606 printFileName( file1 );
1607 printf( "\n" );
1609 rc=DirectoryItem::get( file1 , aItem );
1610 print_error( rtl::OString( "GetDirectoryItem" ), rc );
1612 pStatus=new FileStatus( FileStatusMask_All );
1613 rc=aItem.getFileStatus( *pStatus );
1615 if ( rc==FileBase::E_None )
1617 printf( "GetFileStatus: FileURL: ");
1618 printFileName( pStatus->getFileURL() );
1619 printf( "\n" );
1622 delete pStatus;
1624 printf( "\n" );
1626 //--------------------------------------------------
1627 // get DirectoryItem from a not existing file
1628 //--------------------------------------------------
1630 printf( "Get DirectoryItem from a not existing File: ");
1631 printFileName( file_not_exist );
1632 printf( "\n" );
1634 rc=DirectoryItem::get( file_not_exist , aItem );
1635 print_error( rtl::OString( "Get DirectoryItem" ), rc );
1637 printf( "\n" );
1639 //----------------------------------------------------------
1640 // get DirectoryItem from a directory with a wrong semantic
1641 //----------------------------------------------------------
1643 printf( "Get DirectoryItem from a Directory with a wrong semantic: ");
1644 printFileName( dir_not_exist );
1645 printf( "\n" );
1647 rc=DirectoryItem::get( dir_wrong_semantic, aItem );
1648 print_error( rtl::OString( "Get DirectoryItem" ),rc );
1650 printf( "\n" );
1652 //---------------------------------------------------
1653 // get DirectoryItem from a file-handle
1654 //--------------------------------------------------
1656 pFile=new File( file1 );
1658 rc=pFile->open( OpenFlag_Read );
1659 if ( rc==FileBase::E_None )
1661 printf( "Get DirectoryItem from a File-Handle: ");
1662 printFileName( file1 );
1663 printf( "\n" );
1665 rc=DirectoryItem::get( *pFile , aItem );
1666 print_error( rtl::OString( "GetDirectoryItem" ), rc );
1668 pStatus=new FileStatus( FileStatusMask_All );
1669 rc=aItem.getFileStatus( *pStatus );
1671 if ( rc==FileBase::E_None )
1673 printf( "GetFileStatus: FileURL: ");
1674 printFileName( pStatus->getFileURL() );
1675 printf( "\n");
1678 delete pStatus;
1680 pFile->close();
1683 delete pFile;
1685 printf( "\n" );
1687 //---------------------------------------------------
1688 // get DirectoryItem from an empty file-handle
1689 //--------------------------------------------------
1691 pFile=new File( file1 );
1693 printf( "Get DirectoryItem from an empty File-Handle\n" );
1694 rc=DirectoryItem::get( *pFile , aItem );
1695 print_error( rtl::OString( "GetDirectoryItem" ), rc );
1697 delete pFile;
1699 printf( "\n" );
1701 //--------------------------------------------------
1702 // GetNextItem from a directory
1703 //--------------------------------------------------
1705 pDir=new Directory( dir1 );
1706 printf( "Get next DirectoryItem from a directory: ");
1707 printFileName( dir1);
1708 printf( "\n" );
1710 rc= pDir->open();
1711 print_error( rtl::OString( "Open Directory" ), rc );
1713 printf( "\n" );
1715 if ( pDir->isOpen() )
1717 //--------------------------------------------------
1718 // get all files from the directory
1719 //--------------------------------------------------
1721 rtl::OUString str;
1722 rtl::OUString str1[2];
1724 aItem=DirectoryItem();
1725 rc=pDir->getNextItem( aItem );
1726 print_error( rtl::OString( "GetNextItem" ),rc );
1728 while( rc==FileBase::E_None )
1731 FileStatus rStatus( FileStatusMask_All );
1732 aItem.getFileStatus( rStatus );
1734 str=rStatus.getFileName();
1735 printf( "Filename: ");
1736 printFileName( str );
1737 printf( "\n");
1739 aItem=DirectoryItem();
1740 rc=pDir->getNextItem( aItem );
1741 print_error( rtl::OString( "GetNextItem" ),rc );
1744 printf( "\n" );
1746 //--------------------------------------------------
1747 // Reset-Test
1748 //--------------------------------------------------
1750 for (int i=0; i<2; i++)
1752 aItem=DirectoryItem();
1753 rc=pDir->reset();
1754 rc=pDir->getNextItem( aItem );
1756 FileStatus rStatus( FileStatusMask_All );
1757 aItem.getFileStatus( rStatus );
1759 str1[i]=rStatus.getFileName();
1763 if ( str1[0].compareTo(str1[1]) == 0 )
1764 print_error( rtl::OString( "Reset" ),FileBase::E_None );
1765 else
1766 print_error( rtl::OString( "Reset" ),FileBase::E_invalidError );
1768 printf( "\n" );
1770 // Close Directory
1771 rc=pDir->close();
1772 print_error( rtl::OString( "Close Directory" ), rc );
1775 printf( "\n");
1777 //--------------------------------------------------
1778 // GetNextItem from a closed directory
1779 //--------------------------------------------------
1781 printf( "Get next DirectoryItem from a closed directory: ");
1782 printFileName( dir1 );
1783 printf( "\n" );
1785 aItem=DirectoryItem();
1786 rc=pDir->getNextItem( aItem );
1787 print_error( rtl::OString( "GetNextItem" ),rc );
1789 delete pDir;
1791 PressKey();
1792 return;
1795 //--------------------------------------------------
1796 // FileStatusTest (for different types)
1797 //--------------------------------------------------
1799 void FileStatusTest( FileStatus *pStatus )
1801 //--------------------------------------------------
1802 // GetFileType of the directory
1803 //--------------------------------------------------
1805 FileStatus::Type aType;
1807 printf( "\ngetFileType:\n" );
1808 aType=pStatus->getFileType();
1809 showFileType( aType );
1811 //--------------------------------------------------
1812 // GetAttributes
1813 //--------------------------------------------------
1815 sal_uInt64 uAttributes;
1817 printf( "\ngetAttributes:\n" );
1818 uAttributes=pStatus->getAttributes();
1819 showAttributes( uAttributes );
1821 //--------------------------------------------------
1822 // GetCreationTime
1823 //--------------------------------------------------
1825 TimeValue aCreationTime;
1827 printf( "\ngetCreationTime:\n" );
1828 aCreationTime=pStatus->getCreationTime();
1830 printf( "CreationTime: " );
1831 showTime( aCreationTime );
1833 //--------------------------------------------------
1834 // GetAccessTime
1835 //--------------------------------------------------
1837 TimeValue aAccessTime;
1839 printf( "\ngetAccessTime:\n" );
1840 aAccessTime=pStatus->getAccessTime();
1842 printf( "AccessTime: " );
1843 showTime( aAccessTime );
1845 //--------------------------------------------------
1846 // GetModifyTime
1847 //--------------------------------------------------
1849 TimeValue aModifyTime;
1851 printf( "\ngetModifyTime:\n" );
1852 aModifyTime=pStatus->getModifyTime();
1854 printf( "ModifyTime: " );
1855 showTime( aModifyTime );
1857 //--------------------------------------------------
1858 // GetFileSize
1859 //--------------------------------------------------
1861 sal_uInt64 FileSize;
1863 printf( "\ngetFileSize:\n" );
1865 FileSize=pStatus->getFileSize();
1866 printf( "FileSize: %i\n", FileSize);
1868 //--------------------------------------------------
1869 // GetFileName
1870 //--------------------------------------------------
1872 rtl::OUString FileName;
1874 printf( "\ngetFileName:\n" );
1876 FileName=pStatus->getFileName();
1877 printf( "FileName: ");
1878 printFileName( FileName );
1879 printf( "\n" );
1881 //--------------------------------------------------
1882 // GetFileURL
1883 //--------------------------------------------------
1885 rtl::OUString FileURL;
1887 printf( "\ngetFileURL:\n" );
1889 FileURL=pStatus->getFileURL();
1890 printf( "FileURL: ");
1891 printFileName( FileURL );
1892 printf( "\n" );
1894 //--------------------------------------------------
1895 // GetLinkTargetURL
1896 //--------------------------------------------------
1898 rtl::OUString LinkTargetURL;
1900 printf( "\ngetLinkTargetURL:\n");
1902 LinkTargetURL=pStatus->getLinkTargetURL();
1903 printf( "LinkTargetURL: ");
1904 printFileName( LinkTargetURL );
1905 printf( "\n" );
1907 return;
1910 //--------------------------------------------------
1911 // DirectoryFileStatusTest
1912 //--------------------------------------------------
1914 void DirectoryFileStatusTest( void )
1916 FileBase::RC rc;
1917 DirectoryItem aItem;
1918 FileStatus *pStatus;
1920 printf( "--------------------------------------------\n" );
1921 printf( "Directory-FileStatus-Test\n" );
1922 printf( "--------------------------------------------\n\n" );
1924 printf( "FileStatus of the directory: ");
1925 printFileName( dir1 );
1926 printf( "\n" );
1928 aItem=DirectoryItem();
1930 rc=DirectoryItem::get( dir1, aItem );
1931 print_error( rtl::OString( "Get DirectoryItem" ), rc );
1933 if ( rc==FileBase::E_None )
1935 pStatus=new FileStatus( FileStatusMask_All );
1936 rc=aItem.getFileStatus( *pStatus );
1938 FileStatusTest( pStatus );
1940 delete pStatus;
1943 printf( "\n" );
1945 PressKey();
1946 return;
1949 //--------------------------------------------------
1950 // FileFileStatusTest
1951 //--------------------------------------------------
1953 void FileFileStatusTest( void )
1955 FileBase::RC rc;
1956 DirectoryItem aItem;
1957 FileStatus *pStatus;
1959 printf( "--------------------------------------------\n" );
1960 printf( "File-FileStatus-Test\n" );
1961 printf( "--------------------------------------------\n\n" );
1963 printf( "FileStatus of the file: ");
1964 printFileName( file1 );
1965 printf( "\n" );
1967 aItem=DirectoryItem();
1969 rc=DirectoryItem::get( file1 , aItem );
1970 print_error( rtl::OString( "Get DirectoryItem" ), rc );
1972 if ( rc==FileBase::E_None )
1974 pStatus=new FileStatus( FileStatusMask_All );
1975 rc=aItem.getFileStatus( *pStatus );
1977 FileStatusTest( pStatus );
1979 delete pStatus;
1982 printf( "\n" );
1984 PressKey();
1985 return;
1988 //--------------------------------------------------
1989 // VolumeFileStatusTest
1990 //--------------------------------------------------
1992 void VolumeFileStatusTest( void )
1994 FileBase::RC rc;
1995 DirectoryItem aItem;
1996 FileStatus *pStatus;
1998 printf( "--------------------------------------------\n" );
1999 printf( "Volume-FileStatus-Test\n" );
2000 printf( "--------------------------------------------\n\n" );
2002 printf( "FileStatus of the Volume: ");
2003 printFileName( root );
2004 printf( "\n" );
2006 aItem=DirectoryItem();
2008 rc=DirectoryItem::get( root , aItem );
2009 print_error( rtl::OString( "Get DirectoryItem" ), rc );
2011 if ( rc==FileBase::E_None )
2013 pStatus=new FileStatus( FileStatusMask_All) ;
2014 rc=aItem.getFileStatus( *pStatus );
2016 FileStatusTest( pStatus );
2018 delete pStatus;
2021 printf( "\n" );
2023 PressKey();
2024 return;
2028 //--------------------------------------------------
2029 // VolumeInfoTest
2030 //--------------------------------------------------
2032 void VolumeInfoTest( void )
2034 FileBase::RC rc;
2036 printf( "--------------------------------------------\n" );
2037 printf( "Volume-Info-Test\n" );
2038 printf( "--------------------------------------------\n\n" );
2040 printf( "VolumeInfo of the volume ");
2041 printFileName( root );
2043 printf( "\n" );
2045 VolumeInfo rInfo( VolumeInfoMask_FreeSpace );
2046 rc=Directory::getVolumeInfo( root , rInfo );
2047 print_error( rtl::OString( "GetVolumeInfo" ),rc );
2049 printf( "\n" );
2051 //--------------------------------------------------
2052 // getRemoteFlag
2053 //--------------------------------------------------
2055 if ( rInfo.getRemoteFlag() )
2056 printf( "RemoteFlag: Yes\n" );
2057 else
2058 printf( "RemoteFlag: No\n" );
2060 //--------------------------------------------------
2061 // getRemoveableFlag
2062 //--------------------------------------------------
2064 if ( rInfo.getRemoveableFlag() )
2065 printf( "RemoveableFlag: Yes\n" );
2066 else
2067 printf( "RemoveableFlag: No\n" );
2069 //--------------------------------------------------
2070 // getTotalSpace
2071 //--------------------------------------------------
2073 sal_uInt64 TotalSpace;
2074 TotalSpace=rInfo.getTotalSpace();
2075 printf( "Total Space: %i\n",TotalSpace );
2077 //--------------------------------------------------
2078 // getFreeSpace
2079 //--------------------------------------------------
2081 sal_uInt64 FreeSpace;
2082 FreeSpace=rInfo.getFreeSpace();
2083 printf( "Free Space: %i\n",FreeSpace );
2085 //--------------------------------------------------
2086 // getUsedSpace
2087 //--------------------------------------------------
2089 sal_uInt64 UsedSpace;
2090 UsedSpace=rInfo.getUsedSpace();
2091 printf( "Used Space: %i\n",UsedSpace );
2093 //--------------------------------------------------
2094 // getMaxNameLength
2095 //--------------------------------------------------
2097 sal_uInt32 MaxNameLength;
2098 MaxNameLength=rInfo.getMaxNameLength();
2099 printf( "MaxNameLength: %i\n",MaxNameLength );
2101 //--------------------------------------------------
2102 // getMaxPathLength
2103 //--------------------------------------------------
2105 sal_uInt32 MaxPathLength;
2106 MaxPathLength=rInfo.getMaxPathLength();
2107 printf( "MaxPathLength: %i\n",MaxPathLength );
2109 //--------------------------------------------------
2110 // getFileSystemName
2111 //--------------------------------------------------
2113 rtl::OUString FileSystemName;
2114 FileSystemName=rInfo.getFileSystemName();
2115 printf( "File-System-Name: ");
2116 printFileName( FileSystemName );
2117 printf( "\n" );
2119 PressKey();
2120 return;
2123 //--------------------------------------------------
2124 // FileBaseTest
2125 //--------------------------------------------------
2127 void ConvertPathTest(rtl::OUString& strPath)
2129 FileBase::RC rc;
2131 rtl::OUString strNormPath;
2132 rtl::OUString strFileURL;
2133 rtl::OUString strNormPathFromFileURL;
2134 rtl::OUString strSystemPath;
2136 //--------------------------------------------------
2137 // normalizePath
2138 //--------------------------------------------------
2140 rc=FileBase::getFileURLFromSystemPath( strPath, strNormPath );
2142 if ( rc == FileBase::E_None )
2144 printf( "Normalized Path: \t\t");
2145 printFileName( strNormPath );
2146 printf( "\n" );
2148 else
2149 printf( "normalizePath: Error \n" );
2151 //--------------------------------------------------
2152 // getFileURLFromSystemPath
2153 //--------------------------------------------------
2155 if ( strNormPath.getLength() != 0 )
2157 rc=FileBase::getFileURLFromSystemPath( strNormPath, strFileURL );
2159 if ( rc == FileBase::E_None )
2161 printf( "File-URL: \t\t\t");
2162 printFileName( strFileURL );
2163 printf( "\n" );
2165 else
2166 printf( "getFileURLFromSystemPath: Error \n" );
2168 else
2169 printf( "getFileURLFromSystemPath: not tested \n" );
2171 //--------------------------------------------------
2172 // getNormalizedPathFromFileURL
2173 //--------------------------------------------------
2175 if ( strFileURL.getLength() != 0 )
2177 rc=FileBase::getSystemPathFromFileURL( strFileURL, strNormPathFromFileURL );
2179 if ( rc == FileBase::E_None )
2181 printf( "Normalized Path from File-URL: \t");
2182 printFileName( strNormPathFromFileURL );
2183 printf( "\n" );
2185 else
2186 printf( "getNormalizedPathFromFileURL: Error \n" );
2188 else
2189 printf( "getNormalizedPathFromFileURL: not tested \n" );
2192 //--------------------------------------------------
2193 // getSystemPathFromFileURL
2194 //--------------------------------------------------
2196 if ( strNormPath.getLength() != 0 )
2198 rc=FileBase::getSystemPathFromFileURL( strNormPath, strSystemPath );
2200 if ( rc == FileBase::E_None )
2202 printf( "System-Path: \t\t\t");
2203 printFileName( strSystemPath );
2204 printf( "\n");
2206 else
2207 printf( "getSystemPathFromFileURL: Error \n" );
2209 else
2210 printf( "getSystemPathFromFileURL: not tested \n" );
2212 //--------------------------------------------------
2213 // Verify
2214 //--------------------------------------------------
2216 if ( strNormPathFromFileURL == strNormPath )
2217 printf( "\nVerify: OK ! ( Normalized-Path == Normalized-Path-From-File-URL )\n" );
2218 else
2219 printf( "\nVerify: Error ! ( Normalized-Path != Normalized-Path-From-File-URL )\n" );
2221 return;
2224 void FileBaseTest()
2226 printf( "--------------------------------------------\n" );
2227 printf( "FileBase-Test\n" );
2228 printf( "--------------------------------------------\n\n" );
2230 //--------------------------------------------------
2231 // ConvertPath-Test (Local File)
2232 //--------------------------------------------------
2234 printf( "- Local File: ");
2235 printFileName( file1 );
2236 printf( "\n\n" );
2238 ConvertPathTest(file1);
2240 //--------------------------------------------------
2241 // ConvertPath-Test (File on a server)
2242 //--------------------------------------------------
2244 printf( "\n- File on server: ");
2245 printFileName( file_on_server );
2246 printf( "\n\n" );
2247 ConvertPathTest(file_on_server);
2249 PressKey();
2251 return;
2255 //--------------------------------------------------
2256 // AbsolutePathTest
2257 //--------------------------------------------------
2258 void DoAbsolutePathTest(rtl::OUString strDirBase, rtl::OUString strRelative)
2260 FileBase::RC rc;
2262 rtl::OUString strAbsolute;
2264 printf( "Base-Directory: \t");
2265 printFileName( strDirBase );
2266 printf( "\n" );
2267 printf( "Relative-Path: \t\t");
2268 printFileName ( strRelative );
2269 printf( "\n" );
2271 rc=FileBase::getAbsoluteFileURL( strDirBase, strRelative, strAbsolute );
2273 if ( rc == FileBase::E_None )
2275 printf( "Absolute-Path: \t\t");
2276 printFileName ( strAbsolute );
2277 printf( "\n" );
2279 else
2280 printf( "Absolute-Path: Error \n" );
2282 printf( "\n" );
2283 return;
2286 void AbsolutePathTest(void)
2288 printf( "--------------------------------------------\n" );
2289 printf( "AbsolutePath-Test\n" );
2290 printf( "--------------------------------------------\n\n" );
2292 DoAbsolutePathTest(dir1, rtl::OUString::createFromAscii("."));
2293 DoAbsolutePathTest(dir1, rtl::OUString::createFromAscii(".."));
2294 DoAbsolutePathTest(dir1, rtl::OUString::createFromAscii("../.."));
2295 DoAbsolutePathTest(dir1, rtl::OUString::createFromAscii("../HUHU"));
2297 DoAbsolutePathTest(dir_on_server, rtl::OUString::createFromAscii("."));
2298 DoAbsolutePathTest(dir_on_server, rtl::OUString::createFromAscii(".."));
2299 DoAbsolutePathTest(dir_on_server, rtl::OUString::createFromAscii("../.."));
2300 DoAbsolutePathTest(dir_on_server, rtl::OUString::createFromAscii("../HUHU"));
2302 PressKey();
2303 return;
2307 //--------------------------------------------------
2308 // searchPathTest
2309 //--------------------------------------------------
2311 void SearchPathTest(void)
2313 FileBase::RC rc;
2315 rtl::OUString strNormPath(file1);
2316 rtl::OUString strFileURL;
2317 rtl::OUString strSystemPath;
2318 rtl::OUString strResultPath;
2320 printf( "--------------------------------------------\n" );
2321 printf( "SearchPath-Test\n" );
2322 printf( "--------------------------------------------\n\n" );
2325 rc=FileBase::getFileURLFromSystemPath( strNormPath, strFileURL );
2326 print_error( rtl::OString( "getFileURLFromSystemPath" ), rc );
2327 rc=FileBase::getSystemPathFromFileURL( strNormPath, strSystemPath );
2328 print_error( rtl::OString( "getSystemPathFromFileURL" ), rc );
2330 //--------------------------------------------------
2331 // searchFileURL (with a normalized path)
2332 //--------------------------------------------------
2334 if ( strNormPath.getLength() != 0 )
2336 printf( "\nSearch-Normalized-Path (with a normalized path) : ");
2337 printFileName ( strNormPath );
2338 printf( "\n" );
2340 rc=FileBase::searchFileURL( strNormPath , rtl::OUString() , strResultPath );
2342 if ( rc == FileBase::E_None )
2344 printf( "Result: \t\t\t");
2345 printFileName ( strResultPath );
2346 printf( "\n" );
2348 else
2349 printf( "searchFileURL (with a normalized path): Error\n" );
2351 else
2352 printf( "searchFileURL (with a normalized path): not tested\n" );
2354 //--------------------------------------------------
2355 // searchFileURL (with a File-URL)
2356 //--------------------------------------------------
2358 if ( strFileURL.getLength() != 0 )
2360 printf( "\nSearch-Normalized-Path (with a FileURL) : ");
2361 printFileName( strFileURL );
2362 printf( "\n" );
2364 rc=FileBase::searchFileURL( strFileURL , rtl::OUString() , strResultPath );
2366 if ( rc == FileBase::E_None )
2368 printf( "Result: \t\t\t");
2369 printFileName ( strResultPath );
2370 printf( "\n" );
2372 else
2373 printf( "searchFileURL (with a FileURL path): Error\n" );
2375 else
2376 printf( "searchFileURL (with a FileURL path): not tested\n" );
2378 //--------------------------------------------------
2379 // searchFileURL (with a systempath)
2380 //--------------------------------------------------
2382 if ( strSystemPath.getLength() != 0 )
2384 printf( "\nSearch-Normalized-Path (with a SystemPath) : ");
2385 printFileName( strSystemPath );
2386 printf( "\n" );
2388 rc=FileBase::searchFileURL( strSystemPath , rtl::OUString() , strResultPath );
2390 if ( rc == FileBase::E_None )
2392 printf( "Result: \t\t\t");
2393 printFileName( strResultPath );
2394 printf( "\n" );
2396 else
2397 printf( "searchFileURL (with a systempath): Error\n" );
2399 else
2400 printf( "searchFileURL (with a systempath): not tested\n" );
2402 //--------------------------------------------------
2403 // searchFileURL (File and no searchpath)
2404 //--------------------------------------------------
2406 printf( "\nsearchFileURL: File (no searchpath) : ");
2407 printFileName( file3 );
2408 printf( "\n" );
2410 rc=FileBase::searchFileURL( file3 , rtl::OUString::createFromAscii("") , strResultPath );
2412 if ( rc == FileBase::E_None )
2414 printf( "Result: \t\t\t");
2415 printFileName( strResultPath );
2416 printf( "\n" );
2418 else
2419 printf( "searchFileURL: File not found: OK ! \n" );
2421 //--------------------------------------------------
2422 // searchFileURL (File and Path)
2423 //--------------------------------------------------
2425 printf( "\nsearchFileURL: File : ");
2426 printFileName( file3 );
2427 printf( "\tSearchPath ");
2428 printFileName( dir1 );
2429 printf( "\n");
2431 rc=FileBase::searchFileURL( file3 , dir1 , strResultPath );
2433 if ( rc == FileBase::E_None )
2435 printf( "Result: \t\t\t");
2436 printFileName( strResultPath );
2437 printf( "\n");
2439 else
2440 printf( "searchFileURL: File not found: Error\n" );
2442 //------------------------------------------------------------
2443 // searchFileURL (File and searchpath with two entries)
2444 //------------------------------------------------------------
2446 rtl::OUString strSearchPath( dir_not_exist );
2447 strSearchPath+=rtl::OUString::createFromAscii(";");
2448 strSearchPath+=dir_on_server;
2450 printf( "\nsearchFileURL: File : ");
2451 printFileName( file3 );
2452 printf( "SearchPath ");
2453 printFileName( strSearchPath );
2454 printf( "\n");
2456 rc=FileBase::searchFileURL( file3 , strSearchPath , strResultPath );
2458 if ( rc == FileBase::E_None )
2460 printf( "Result: \t\t\t");
2461 printFileName( strResultPath );
2462 printf( "\n" );
2464 else
2465 printf( "searchFileURL: File not found: Error\n" );
2467 //-------------------------------------------------------------------
2468 // searchFileURL (File and searchpath (with a wrong semantic))
2469 //-------------------------------------------------------------------
2471 strSearchPath=rtl::OUString( dir_wrong_semantic );
2473 printf( "\nsearchFileURL: File : ");
2474 printFileName( file3 );
2475 printf( "SearchPath ");
2476 printFileName( strSearchPath );
2477 printf( "\n");
2479 rc=FileBase::searchFileURL( file3 , strSearchPath , strResultPath );
2481 if ( rc == FileBase::E_None )
2482 printf( "Error: Wrong Semantich but no error occurs !\n" );
2483 else
2484 printf( "searchFileURL: File not found: OK !\n" );
2486 return;
2489 //--------------------------------------------------
2490 // CanonicalNameTest
2491 //--------------------------------------------------
2493 void getCanonicalNameTest(rtl::OUString strPath)
2495 FileBase::RC rc;
2497 rtl::OUString strValid;
2499 printf( "Original-Name: \t\t");
2500 printFileName( strPath );
2501 printf( "\n" );
2503 rc=FileBase::getCanonicalName( strPath, strValid );
2505 if ( rc == FileBase::E_None)
2507 printf( "Canonical-Name: \t");
2508 printFileName( strValid );
2509 printf( "\n");
2512 else
2513 printf( "Canonical-Name: Error \n" );
2515 printf( "\n" );
2516 return;
2519 void CanonicalNameTest(void)
2521 printf( "--------------------------------------------\n" );
2522 printf( "CanonicalName-Test\n" );
2523 printf( "--------------------------------------------\n\n" );
2525 getCanonicalNameTest( dir1 );
2526 getCanonicalNameTest( dir_on_server );
2527 getCanonicalNameTest( file1 );
2528 getCanonicalNameTest( file_on_server );
2530 PressKey();
2531 return;
2534 //--------------------------------------------------
2535 // print_error
2536 //--------------------------------------------------
2538 void print_error( ::rtl::OString& str, FileBase::RC rc )
2541 printf( "%s : ",str.getStr() );
2542 switch(rc)
2544 case FileBase::E_None:
2545 printf("OK !\n");
2546 break;
2547 case FileBase::E_PERM:
2548 printf("E_PERM\n");
2549 break;
2550 case FileBase::E_NOENT:
2551 printf("E_NOENT\n");
2552 break;
2553 case FileBase::E_SRCH:
2554 printf("E_SRCH\n");
2555 break;
2556 case FileBase::E_INTR:
2557 printf("E_INTR\n");
2558 break;
2559 case FileBase::E_IO:
2560 printf("E_IO\n");
2561 break;
2562 case FileBase::E_NXIO:
2563 printf("E_NXIO\n");
2564 break;
2565 case FileBase::E_2BIG:
2566 printf("E_2BIG\n");
2567 break;
2568 case FileBase::E_NOEXEC:
2569 printf("E_NOEXEC\n");
2570 break;
2571 case FileBase::E_BADF:
2572 printf("E_BADF\n");
2573 break;
2574 case FileBase::E_CHILD:
2575 printf("E_CHILD\n");
2576 break;
2577 case FileBase::E_AGAIN:
2578 printf("E_AGAIN\n");
2579 break;
2580 case FileBase::E_NOMEM:
2581 printf("E_NOMEM\n");
2582 break;
2583 case FileBase::E_ACCES:
2584 printf("E_ACCES\n");
2585 break;
2586 case FileBase::E_FAULT:
2587 printf("E_FAULT\n");
2588 break;
2589 case FileBase::E_BUSY:
2590 printf("E_BUSY\n");
2591 break;
2592 case FileBase::E_EXIST:
2593 printf("E_EXIST\n");
2594 break;
2595 case FileBase::E_XDEV:
2596 printf("E_XDEV\n");
2597 break;
2598 case FileBase::E_NODEV:
2599 printf("E_NODEV\n");
2600 break;
2601 case FileBase::E_NOTDIR:
2602 printf("E_NOTDIR\n");
2603 break;
2604 case FileBase::E_ISDIR:
2605 printf("E_ISDIR\n");
2606 break;
2607 case FileBase::E_INVAL:
2608 printf("E_INVAL\n");
2609 break;
2610 case FileBase::E_NFILE:
2611 printf("E_NFILE\n");
2612 break;
2613 case FileBase::E_MFILE:
2614 printf("E_MFILE\n");
2615 break;
2616 case FileBase::E_NOTTY:
2617 printf("E_NOTTY\n");
2618 break;
2619 case FileBase::E_FBIG:
2620 printf("E_FBIG\n");
2621 break;
2622 case FileBase::E_NOSPC:
2623 printf("E_NOSPC\n");
2624 break;
2625 case FileBase::E_SPIPE:
2626 printf("E_SPIPE\n");
2627 break;
2628 case FileBase::E_ROFS:
2629 printf("E_ROFS\n");
2630 break;
2631 case FileBase::E_MLINK:
2632 printf("E_MLINK\n");
2633 break;
2634 case FileBase::E_PIPE:
2635 printf("E_PIPE\n");
2636 break;
2637 case FileBase::E_DOM:
2638 printf("E_DOM\n");
2639 break;
2640 case FileBase::E_RANGE:
2641 printf("E_RANGE\n");
2642 break;
2643 case FileBase::E_DEADLK:
2644 printf("E_DEADLK\n");
2645 break;
2646 case FileBase::E_NAMETOOLONG:
2647 printf("E_NAMETOOLONG\n");
2648 break;
2649 case FileBase::E_NOLCK:
2650 printf("E_NOLCK\n");
2651 break;
2652 case FileBase::E_NOSYS:
2653 printf("E_NOSYS\n");
2654 break;
2655 case FileBase::E_NOTEMPTY:
2656 printf("E_NOTEMPTY\n");
2657 break;
2658 case FileBase::E_LOOP:
2659 printf("E_LOOP\n");
2660 break;
2661 case FileBase::E_ILSEQ:
2662 printf("E_ILSEQ\n");
2663 break;
2664 case FileBase::E_NOLINK:
2665 printf("E_NOLINK\n");
2666 break;
2667 case FileBase::E_MULTIHOP:
2668 printf("E_MULTIHOP\n");
2669 break;
2670 case FileBase::E_USERS:
2671 printf("E_USERS\n");
2672 break;
2673 case FileBase::E_OVERFLOW:
2674 printf("E_OVERFLOW\n");
2675 break;
2676 default:
2677 printf("E_Unknown\n");
2678 break;
2680 return;
2683 //--------------------------------------------------
2684 // main
2685 //--------------------------------------------------
2686 #if defined WNT
2687 #define MAIN _cdecl main
2688 #else
2689 #define MAIN main
2690 #endif
2692 int MAIN( int argc, char* argv[] )
2694 sal_Bool fSuccess=sal_False;
2696 //Initialization
2697 fSuccess=Initialize();
2698 if ( !fSuccess )
2700 printf("Error during Initialization");
2701 return -1;
2705 if (argc==1)
2707 DirectoryOpenAndCloseTest();
2708 DirectoryCreateAndRemoveTest();
2710 FileOpenAndCloseTest();
2711 FileCreateAndRemoveTest();
2712 FileWriteAndReadTest();
2713 FileCopyAndMoveTest();
2714 FileSizeTest();
2715 FilePointerTest();
2716 FileAttributesTest();
2717 FileTimeTest();
2718 DirectoryItemTest();
2719 DirectoryFileStatusTest();
2720 VolumeFileStatusTest();
2721 FileFileStatusTest();
2722 VolumeInfoTest();
2723 FileBaseTest();
2724 SearchPathTest();
2725 AbsolutePathTest();
2726 CanonicalNameTest();
2728 // command line arguments ?
2729 else
2731 int i=1;
2733 while (i<argc)
2735 if (strcmp(argv[i], "doc")==0)
2736 DirectoryOpenAndCloseTest();
2737 else if (strcmp(argv[i], "dcr")==0)
2738 DirectoryCreateAndRemoveTest();
2739 else if (strcmp(argv[i], "foc")==0)
2740 FileOpenAndCloseTest();
2741 else if (strcmp(argv[i], "fcr")==0)
2742 FileCreateAndRemoveTest();
2743 else if (strcmp(argv[i], "fwr")==0)
2744 FileWriteAndReadTest();
2745 else if (strcmp(argv[i], "fcm")==0)
2746 FileCopyAndMoveTest();
2747 else if (strcmp(argv[i], "fs")==0)
2748 FileSizeTest();
2749 else if (strcmp(argv[i], "fp")==0)
2750 FilePointerTest();
2751 else if (strcmp(argv[i], "fa")==0)
2752 FileAttributesTest();
2753 else if (strcmp(argv[i], "ft")==0)
2754 FileTimeTest();
2755 else if (strcmp(argv[i], "di")==0)
2756 DirectoryItemTest();
2757 else if (strcmp(argv[i], "dfs")==0)
2758 DirectoryFileStatusTest();
2759 else if (strcmp(argv[i], "vfs")==0)
2760 VolumeFileStatusTest();
2761 else if (strcmp(argv[i], "ffs")==0)
2762 FileFileStatusTest();
2763 else if (strcmp(argv[i], "vi")==0)
2764 VolumeInfoTest();
2765 else if (strcmp(argv[i], "fb")==0)
2766 FileBaseTest();
2767 else if (strcmp(argv[i], "sp")==0)
2768 SearchPathTest();
2769 else if (strcmp(argv[i], "ap")==0)
2770 AbsolutePathTest();
2771 else if (strcmp(argv[i], "cn")==0)
2772 CanonicalNameTest();
2774 i++;
2778 // Shutdown
2779 fSuccess=Shutdown();
2780 if ( !fSuccess )
2782 printf("Error during Shutdown");
2783 return -1;
2786 return 0;