Bump for 3.6-28
[LibreOffice.git] / sal / workben / testfile.cxx
blob0ec2fe9600c3128d053f58ba9585a1b589c59577
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #define UNICODE
33 #include <osl/file.hxx>
34 #include <osl/process.h>
35 #include <osl/time.h>
36 #include <rtl/alloc.h>
37 #include <rtl/ustring.hxx>
38 #include <stdio.h>
39 #include <string.h>
40 #include <time.h>
43 #ifdef UNX
44 #include <wchar.h>
45 #endif
47 #ifdef WNT
48 #include <windows.h>
49 #endif
51 using namespace osl;
52 using namespace rtl;
54 #define MAXIMPATH 256
56 rtl::OUString root;
58 rtl::OUString dir1;
59 rtl::OUString dir2;
60 rtl::OUString dir_on_server;
61 rtl::OUString dir_not_exist;
62 rtl::OUString dir_not_exist_on_server;
63 rtl::OUString dir_wrong_semantic;
65 rtl::OUString file1;
66 rtl::OUString file2;
67 rtl::OUString file3;
68 rtl::OUString file_on_server;
69 rtl::OUString file_not_exist;
73 void print_error(const ::rtl::OString& str, FileBase::RC rc);
75 void PressKey()
77 printf("\nPress Return !\n");
78 getchar();
81 void printFileName(const ::rtl::OUString& str)
83 rtl::OString aString;
85 aString = rtl::OUStringToOString( str, RTL_TEXTENCODING_ASCII_US );
87 printf( "%s", aString.getStr() );
89 return;
92 //--------------------------------------------------
93 // Initialization
94 //--------------------------------------------------
96 sal_Bool testLineBreak( sal_Char *pCount , sal_uInt64 nLen , sal_uInt32 *cLineBreak )
98 sal_Bool fSuccess=sal_False;
99 *cLineBreak=0;
101 if (nLen==0)
102 return fSuccess;
104 if ( *pCount==13 )
106 if (nLen>=1 && *(pCount+1)==10)
107 *cLineBreak=2;
108 else
109 *cLineBreak=1;
111 if (nLen>=2 && *(pCount+2)==10)
112 (*cLineBreak)++;
114 fSuccess=sal_True;
116 else if ( *pCount==10 )
118 *cLineBreak=1;
119 fSuccess=sal_True;
122 return fSuccess;
125 // Initialization
127 sal_Bool Initialize( void )
129 DirectoryItem aItem;
130 FileStatus aStatus( osl_FileStatus_Mask_All );
131 rtl_uString *strExeFileURL=NULL;
132 oslProcessError ProcessError;
134 rtl::OUString iniFileURL;
135 File *pFile;
136 sal_Unicode *pExeFileCount;
138 FileBase::RC rc;
140 sal_uInt64 uBytesRequested;
141 sal_uInt64 uBytesRead;
142 sal_Char *pBuffer;
143 sal_Char *pBegin;
144 sal_Char *pCount;
146 rtl::OUString dir[12];
148 // Open to the ini-file
150 ProcessError=osl_getExecutableFile(&strExeFileURL);
152 if ( ProcessError == osl_Process_E_None)
154 pExeFileCount=rtl_uString_getStr(strExeFileURL)+rtl_uString_getLength(strExeFileURL);
156 // Search for the last slash in the Path
157 while (*pExeFileCount!=L'/' && pExeFileCount>rtl_uString_getStr(strExeFileURL))
158 pExeFileCount--;
160 // iniFileURL = strExeFileURL without the filename of the exe-File
161 iniFileURL=rtl::OUString( rtl_uString_getStr(strExeFileURL) ,(int) (pExeFileCount-rtl_uString_getStr(strExeFileURL)) );
163 // add "/testfile.ini" to iniFileURL
164 iniFileURL+=rtl::OUString("/testfile.ini");
166 // Open the ini-File
167 pFile=new File( iniFileURL );
168 rc=pFile->open( osl_File_OpenFlag_Read | osl_File_OpenFlag_Write );
169 if ( rc!=FileBase::E_None )
171 rtl_uString_release(strExeFileURL);
172 return sal_False;
175 else
177 rtl_uString_release(strExeFileURL);
178 return sal_False;
181 // Get filesize of the ini-File
183 rc=DirectoryItem::get( iniFileURL, aItem );
184 if ( rc!=FileBase::E_None )
185 return sal_False;
187 rc=aItem.getFileStatus( aStatus );
188 if ( rc!=FileBase::E_None )
189 return sal_False;
191 uBytesRequested=aStatus.getFileSize();
193 // read ini-File
194 rc=pFile->setPos( osl_Pos_Absolut, 0 );
195 pBuffer=(sal_Char*) rtl_allocateMemory( (sal_uInt32) (uBytesRequested+1)*sizeof(sal_Char) );
196 rtl_zeroMemory( pBuffer, (sal_uInt32)(uBytesRequested+1)*sizeof(sal_Char) );
198 rc=pFile->read( pBuffer , uBytesRequested , uBytesRead );
199 if ( rc!=FileBase::E_None )
200 return sal_False;
203 pBegin=pBuffer;
204 pCount=pBegin;
206 for ( int i=0 ; i<12 ; i++ )
208 sal_uInt32 cLineBrake=0;
209 while ( (static_cast<sal_uInt64>(pCount-pBuffer) < uBytesRead) && *pCount!='=')
210 pCount++;
212 pCount++;
213 pBegin=pCount;
215 while ( (static_cast<sal_uInt64>(pCount-pBuffer) < uBytesRead) && !testLineBreak(pCount,uBytesRead-(pCount-pBuffer), &cLineBrake))
216 pCount++;
218 dir[i]=rtl::OUString(pBegin, pCount-pBegin, RTL_TEXTENCODING_ASCII_US);
220 pCount+=cLineBrake;
221 pBegin=pCount;
224 root=rtl::OUString(dir[0]);
225 dir1=rtl::OUString(dir[1]);
226 dir2=rtl::OUString(dir[2]);
227 dir_on_server=rtl::OUString(dir[3]);
228 dir_not_exist=rtl::OUString(dir[4]);
229 dir_not_exist_on_server=rtl::OUString(dir[5]);
230 dir_wrong_semantic=rtl::OUString(dir[6]);
232 file1=rtl::OUString(dir[7]);
233 file2=rtl::OUString(dir[8]);
234 file3=rtl::OUString(dir[9]);
235 file_on_server=rtl::OUString(dir[10]);
236 file_not_exist=rtl::OUString(dir[11]);
238 // close the ini-file
239 rc=pFile->close();
241 rtl_freeMemory( pBuffer );
244 // Create directories
245 rc=Directory::create( dir1 );
246 if ( rc!=FileBase::E_None )
247 return sal_False;
249 rc=Directory::create( dir2 );
250 if ( rc!=FileBase::E_None )
251 return sal_False;
253 rc=Directory::create( dir_on_server );
254 if ( rc!=FileBase::E_None )
255 return sal_False;
257 pFile=new File( file1 );
258 rc=pFile->open( osl_File_OpenFlag_Write | osl_File_OpenFlag_Create );
259 if ( rc!=FileBase::E_None )
260 return sal_False;
261 rc=pFile->close();
262 delete pFile;
264 pFile=new File( file2 );
265 rc=pFile->open( osl_File_OpenFlag_Write | osl_File_OpenFlag_Create );
266 if ( rc!=FileBase::E_None )
267 return sal_False;
268 rc=pFile->close();
269 delete pFile;
271 pFile=new File( file_on_server );
272 rc=pFile->open( osl_File_OpenFlag_Write | osl_File_OpenFlag_Create );
273 if ( rc!=FileBase::E_None )
274 return sal_False;
275 rc=pFile->close();
276 delete pFile;
278 return sal_True;
281 //--------------------------------------------------
282 // Shutdown
283 //--------------------------------------------------
285 sal_Bool Shutdown( void )
287 sal_Bool fSuccess=sal_True;
288 FileBase::RC rc;
289 File *pFile;
291 // remove created files
293 pFile=new File( file1 );
294 rc=pFile->remove( file1 );
295 if ( rc!=FileBase::E_None )
296 fSuccess=sal_False;
297 delete pFile;
299 pFile=new File( file2 );
300 rc=pFile->remove( file2 );
301 if ( rc!=FileBase::E_None )
302 fSuccess=sal_False;
303 delete pFile;
305 // remove created directories
307 rc=Directory::remove( dir1 );
308 if ( rc!=FileBase::E_None )
309 fSuccess=sal_False;
311 rc=Directory::remove( dir2 );
312 if ( rc!=FileBase::E_None )
313 fSuccess=sal_False;
315 // remove created file on the server
317 pFile=new File( file_on_server );
318 rc=pFile->remove( file_on_server );
319 if ( rc!=FileBase::E_None )
320 fSuccess=sal_False;
321 delete pFile;
323 // remove created directory on the server
325 rc=Directory::remove( dir_on_server );
326 if ( rc!=FileBase::E_None )
327 fSuccess=sal_False;
329 return fSuccess;
332 //--------------------------------------------------
333 // helper functions
334 //--------------------------------------------------
336 // Show FileType
337 void showFileType( FileStatus::Type aType )
339 if ( aType==FileStatus::Directory )
340 printf( "FileType: Directory \n" );
341 else if ( aType==FileStatus::Volume )
342 printf( "FileType: Volume \n" );
343 else if ( aType==FileStatus::Regular )
344 printf( "FileType: Regular \n" );
345 else if ( aType==FileStatus::Unknown )
346 printf( "FileType: Unknown \n" );
350 // Show Attributes
351 void showAttributes( sal_uInt64 uAttributes )
353 if ( uAttributes==0 )
354 printf( "No Attributes \n" );
355 if ( uAttributes & osl_File_Attribute_ReadOnly )
356 printf( "Attribute: ReadOnly \n" );
357 if ( uAttributes & osl_File_Attribute_Hidden )
358 printf( "Attribute: Hidden \n" );
359 if ( uAttributes & osl_File_Attribute_Executable )
360 printf( "Attribute: Executable \n");
361 if ( uAttributes & osl_File_Attribute_GrpWrite )
362 printf( "Attribute: GrpWrite \n");
363 if ( uAttributes & osl_File_Attribute_GrpRead )
364 printf( "Attribute: GrpRead \n" );
365 if ( uAttributes & osl_File_Attribute_GrpExe )
366 printf( "Attribute: GrpExe \n" );
367 if ( uAttributes & osl_File_Attribute_OwnWrite )
368 printf( "Attribute: OwnWrite \n");
369 if ( uAttributes & osl_File_Attribute_OwnRead )
370 printf( "Attribute: OwnRead \n" );
371 if ( uAttributes & osl_File_Attribute_OwnExe )
372 printf( "Attribute: OwnExe \n" );
373 if ( uAttributes & osl_File_Attribute_OthWrite )
374 printf( "Attribute: OthWrite \n" );
375 if ( uAttributes & osl_File_Attribute_OthRead )
376 printf( "Attribute: OthRead \n");
377 if ( uAttributes & osl_File_Attribute_OthExe )
378 printf( "Attribute: OthExe \n" );
380 return;
383 // Show Time
384 void showTime( TimeValue aTime )
386 TimeValue aLocalTimeVal, aSystemTimeVal , aSysTimeVal;
387 oslDateTime aDateTime, aSystemTime;
389 if ( osl_getLocalTimeFromSystemTime( &aTime, &aLocalTimeVal ) )
391 if ( osl_getDateTimeFromTimeValue( &aLocalTimeVal, &aDateTime ) )
393 printf("\t%02i.%02i.%4i , %02i.%02i.%02i Uhr\n", aDateTime.Day, aDateTime.Month, aDateTime.Year, aDateTime.Hours, aDateTime.Minutes, aDateTime.Seconds);
395 else
396 printf("Error !\n");
399 if ( osl_getDateTimeFromTimeValue( &aTime, &aSystemTime ) )
401 printf("SystemTime: \t\t%02i.%02i.%4i , %02i.%02i.%02i Uhr\n", aSystemTime.Day, aSystemTime.Month, aSystemTime.Year, aSystemTime.Hours, aSystemTime.Minutes, aSystemTime.Seconds);
403 else
404 printf("Error !\n");
406 //Verify
408 if ( osl_getTimeValueFromDateTime( &aSystemTime, &aSystemTimeVal ) )
410 if ( ( aSystemTimeVal.Seconds == aTime.Seconds ) && ( aSystemTimeVal.Nanosec == aTime.Nanosec ))
411 printf ("Verify : TimeValue : ok! \n");
412 else
414 printf ("Verify : TimeValue : Error! \n");
415 printf ("aTime : %u \n", aTime.Seconds);
416 printf ("aSystemTimeVal : %u \n", aSystemTimeVal.Seconds);
419 else
420 printf ("Verify : TimeValue : Error! \n");
423 if ( osl_getSystemTimeFromLocalTime( &aLocalTimeVal , &aSysTimeVal ) )
425 if ( ( aSysTimeVal.Seconds == aTime.Seconds ) && ( aSysTimeVal.Nanosec == aTime.Nanosec ))
426 printf ("Verify : SystemTime : ok! \n");
427 else
429 printf ("Verify : SystemTime : Error! \n");
430 printf ("aTime : %u\n", aTime.Seconds);
431 printf ("aSystemTimeVal : %u\n", aSysTimeVal.Seconds);
434 else
435 printf ("Verify : SystemTime : Error! \n");
437 return;
440 TimeValue getSystemTime()
442 TimeValue aTime;
443 time_t ltime;
445 time( &ltime );
447 aTime.Seconds = ltime;
448 aTime.Nanosec = 0;
450 return aTime;
454 //--------------------------------------------------
455 // DirectoryOpenAndCloseTest
456 //--------------------------------------------------
458 void DirectoryOpenAndCloseTest( void )
460 FileBase::RC rc;
461 Directory *pDir;
463 printf( "--------------------------------------------\n");
464 printf( "Directory-Open-And-Close-Test\n");
465 printf( "--------------------------------------------\n\n");
467 //--------------------------------------------------
468 // open an existing directory
469 //--------------------------------------------------
471 pDir=new Directory( dir1 );
472 printf( "Open an existing directory: ");
473 printFileName( dir1 );
474 printf( "\n" );
476 rc= pDir->open();
477 print_error( rtl::OString( "Open Directory" ), rc );
479 if ( pDir->isOpen() )
481 print_error( rtl::OString( "Directory is Open" ), rc );
484 // Close Directory
485 rc=pDir->close();
486 print_error( rtl::OString( "Close Directory" ), rc );
488 delete pDir;
489 printf( "\n" );
491 //--------------------------------------------------
492 // open a not existing directory
493 //--------------------------------------------------
495 pDir=new Directory( dir_not_exist );
497 printf( "Open a not existing directory: ");
498 printFileName( dir_not_exist );
499 printf( "\n" );
501 rc= pDir->open();
503 print_error( rtl::OString( "Open Directory" ), rc );
505 delete pDir;
507 printf( "\n" );
509 //--------------------------------------------------
510 // open a directory with a wrong semantic
511 //--------------------------------------------------
512 pDir=new Directory( dir_wrong_semantic );
514 printf( "Open a directory with a wrong semantic: ");
515 printFileName( dir_wrong_semantic );
516 printf( "\n" );
518 rc= pDir->open();
519 print_error( rtl::OString( "Open Directory" ), rc );
521 delete pDir;
523 printf( "\n" );
525 //--------------------------------------------------
526 // open an existing directory on a server
527 //--------------------------------------------------
529 pDir=new Directory( dir_on_server );
531 printf( "Open an existing directory on a server: ");
532 printFileName( dir_on_server );
533 printf( "\n" );
535 rc= pDir->open();
536 print_error( rtl::OString( "Open Directory" ), rc );
538 // Close Directory
539 rc=pDir->close();
540 print_error( rtl::OString( "Close Directory" ), rc );
542 delete pDir;
543 printf( "\n" );
545 //--------------------------------------------------
546 // open a not existing directory on a server
547 //--------------------------------------------------
549 pDir=new Directory( dir_not_exist_on_server );
551 printf( "Open a not existing directory on a server: ");
552 printFileName( dir_not_exist_on_server );
553 printf( "\n" );
555 rc= pDir->open();
556 print_error( rtl::OString( "Open Directory" ), rc );
558 delete pDir;
559 printf( "\n" );
561 //--------------------------------------------------
562 // Close a not existing directory
563 //--------------------------------------------------
565 pDir=new Directory( dir_not_exist );
566 printf( "Close a not existing directory: ");
567 printFileName( dir_not_exist );
568 printf( "\n" );
570 rc=pDir->close();
571 print_error( rtl::OString( "Close Directory" ), rc );
573 PressKey();
574 return;
578 //--------------------------------------------------
579 // DirectoryCreateAndRemoveTest
580 //--------------------------------------------------
582 void DirectoryCreateAndRemoveTest( void )
584 FileBase::RC rc,rc1;
585 Directory *pDir;
587 printf( "--------------------------------------------\n" );
588 printf( "Directory-Create-And-Remove-Test\n" );
589 printf( "--------------------------------------------\n\n" );
591 //--------------------------------------------------
592 // Create directory
593 //--------------------------------------------------
594 printf( "Create a not existing directory: ");
595 printFileName( dir_not_exist );
596 printf( "\n" );
598 rc=Directory::create( dir_not_exist) ;
599 print_error( rtl::OString( "Create Directory" ), rc );
601 // Verify
602 pDir=new Directory( dir_not_exist );
604 rc= pDir->open();
605 print_error( rtl::OString( "Verify" ), rc );
606 pDir->close();
607 delete pDir;
609 printf( "\n" );
611 //--------------------------------------------------
612 // Create a directory on a server
613 //--------------------------------------------------
615 printf( "Create a not existing directory on a server: ");
616 printFileName( dir_not_exist_on_server );
617 printf( "\n" );
619 rc=Directory::create( dir_not_exist_on_server );
620 print_error( rtl::OString( "Create Directory" ), rc );
622 // Verify
623 pDir=new Directory( dir_not_exist_on_server );
624 rc= pDir->open();
625 print_error( rtl::OString( "Verify" ), rc );
626 pDir->close();
627 delete pDir;
629 printf( "\n" );
631 //--------------------------------------------------
632 // Remove Directories
633 //--------------------------------------------------
635 printf( "Remove the created directories: \n" );
637 rc=Directory::remove( dir_not_exist );
639 rc1=Directory::remove( dir_not_exist_on_server );
641 if ( rc==FileBase::E_None && rc1==FileBase::E_None )
642 print_error( rtl::OString( "Remove Directories" ), FileBase::E_None );
643 else if ( rc!=FileBase::E_None )
644 print_error( rtl::OString( "Remove local Directory" ),rc );
645 else
646 print_error( rtl::OString( "Remove Directory on a server" ),rc1 );
648 printf( "\n" );
650 //--------------------------------------------------
651 // Remove a not existing directory
652 //--------------------------------------------------
654 printf( "Remove a not existing directory: ");
655 printFileName( dir_not_exist );
656 printf( "\n" );
658 rc=Directory::remove( dir_not_exist );
659 print_error( rtl::OString( "Remove" ),rc );
661 PressKey();
662 return;
665 //--------------------------------------------------
666 // FileOpenAndCloseTest
667 //--------------------------------------------------
669 static void FileOpenAndCloseTest( void )
671 FileBase::RC rc;
673 printf( "--------------------------------------------\n" );
674 printf( "File-Open-And-Close-Test\n" );
675 printf( "--------------------------------------------\n\n" );
677 File *pFile;
679 pFile=new File( file1 );
681 printf( "Open an existing file: ");
682 printFileName( file1 );
683 printf( "\n" );
685 //--------------------------------------------------
686 // open an existing file (Read)
687 //--------------------------------------------------
689 rc=pFile->open( osl_File_OpenFlag_Read );
690 print_error( rtl::OString( "Open File (Read)" ), rc );
692 //--------------------------------------------------
693 // close the file
694 //--------------------------------------------------
696 rc=pFile->close();
697 print_error( rtl::OString( "Close File" ), rc );
699 printf( "\n" );
701 //--------------------------------------------------
702 // open an existing file (Write)
703 //--------------------------------------------------
705 rc=pFile->open( osl_File_OpenFlag_Write );
706 print_error( rtl::OString( "Open File (Write)" ), rc );
708 //--------------------------------------------------
709 // close the file
710 //--------------------------------------------------
712 rc=pFile->close();
713 print_error( rtl::OString( "Close File" ), rc );
715 printf( "\n" );
717 //--------------------------------------------------
718 // close the file a second time
719 //--------------------------------------------------
721 rc=pFile->close();
722 print_error( rtl::OString( "Close the file a second time" ), rc );
724 delete pFile;
725 PressKey();
728 //--------------------------------------------------
729 // FileCreateAndRemoveTest
730 //--------------------------------------------------
732 void FileCreateAndRemoveTest()
734 FileBase::RC rc;
735 File *pFile;
737 printf( "--------------------------------------------\n" );
738 printf( "File-Create-And-Remove-Test\n" );
739 printf( "--------------------------------------------\n\n" );
741 pFile=new File( file_not_exist );
743 printf( "Create File: ");
744 printFileName( file_not_exist );
745 printf( "\n" );
747 //----------------------------------------------------
748 // open (create) a not existing file (Read and write)
749 //----------------------------------------------------
751 rc = pFile->open( osl_File_OpenFlag_Read | osl_File_OpenFlag_Write | osl_File_OpenFlag_Create );
753 print_error( rtl::OString( "Create and Open File (Read & Write)" ), rc );
755 //----------------------------------------------------
756 // close the file
757 //----------------------------------------------------
759 rc=pFile->close();
760 print_error( rtl::OString( "Close File" ), rc );
762 //----------------------------------------------------
763 // remove the file
764 //----------------------------------------------------
766 rc=pFile->remove( file_not_exist );
767 print_error( rtl::OString(" Remove File" ), rc );
769 printf( "\n" );
771 //----------------------------------------------------
772 // remove the same file a second time
773 //----------------------------------------------------
774 rc=pFile->remove( file_not_exist );
775 print_error( rtl::OString( "Remove a not existing File" ), rc );
777 //----------------------------------------------------
778 // remove an open file
779 //----------------------------------------------------
781 pFile->open( osl_File_OpenFlag_Read | osl_File_OpenFlag_Write | osl_File_OpenFlag_Create );
783 rc=pFile->remove( file_not_exist );
784 print_error( rtl::OString( "Remove an open File" ), rc );
786 pFile->close();
787 pFile->remove( file_not_exist );
789 PressKey();
791 return;
794 //--------------------------------------------------
795 // FileWriteAndReadTest
796 //--------------------------------------------------
798 void FileWriteAndReadTest( void )
800 FileBase::RC rc;
802 sal_uInt64 uWritten;
803 sal_uInt64 uRead;
804 const sal_Char *pWriteBuffer="Hier kommt der Osterhase !";
805 sal_uInt64 nLen=strlen( pWriteBuffer );
806 sal_Char *pReadBuffer;
808 printf( "--------------------------------------------\n" );
809 printf( "File-Write-And-Read-Test\n" );
810 printf( "--------------------------------------------\n\n" );
812 File *pFile;
814 pFile=new File( file_not_exist );
816 printf( "Create File: ");
817 printFileName( file_not_exist );
818 printf("\n");
820 //----------------------------------------------------
821 // open (create) a not existing file (Read and write)
822 //----------------------------------------------------
824 rc = pFile->open( osl_File_OpenFlag_Read | osl_File_OpenFlag_Write | osl_File_OpenFlag_Create );
826 print_error( rtl::OString( "Create and Open File (Read & Write)" ), rc );
828 printf( "\n" );
830 //----------------------------------------------------
831 // write a string to the file
832 //----------------------------------------------------
833 rc=pFile->write( pWriteBuffer , nLen , uWritten );
834 print_error( rtl::OString( "Write File" ), rc );
836 if(uWritten==nLen)
837 printf( "Verify: OK! \n" );
838 else
839 printf( "Verify: Error\n" );
841 printf( "\n" );
843 //----------------------------------------------------
844 // move the filepointer to the beginning
845 //----------------------------------------------------
847 rc=pFile->setPos( osl_Pos_Absolut , 0 );
848 print_error( rtl::OString( "Set FilePointer to the beginning of the file" ), rc );
850 printf( "\n" );
852 //----------------------------------------------------
853 // read the string
854 //----------------------------------------------------
856 pReadBuffer=(sal_Char*) rtl_allocateMemory( (sal_uInt32)(nLen+1)*sizeof(sal_Char) );
857 rtl_zeroMemory( pReadBuffer, (sal_uInt32)(nLen+1)*sizeof(sal_Char) );
858 rc=pFile->read( pReadBuffer , nLen,uRead );
859 print_error( rtl::OString( "Read File" ), rc );
861 if (strcmp(pWriteBuffer, pReadBuffer)==0)
863 printf( "Verify: OK !\n" );
864 printf( "Text: %s\n",pReadBuffer );
866 else
867 printf( "Verify: Error\n" );
869 rtl_freeMemory( pReadBuffer );
871 printf( "\n" );
873 // close the file
874 rc=pFile->close();
875 print_error( rtl::OString( "Close File" ), rc );
877 // remove the file
878 rc=pFile->remove( file_not_exist );
879 print_error( rtl::OString( "Remove File" ), rc );
881 PressKey();
883 return;
887 //--------------------------------------------------
888 // FileCopyMoveTest
889 //--------------------------------------------------
891 void FileCopyAndMoveTest( void )
893 FileBase::RC rc;
895 printf( "--------------------------------------------\n" );
896 printf( "File-Copy-Move-Test\n" );
897 printf( "--------------------------------------------\n\n" );
900 File *pFile;
901 rtl::OUString destPath(dir2);
903 //--------------------------------------------------
904 // FileCopyTest
905 //--------------------------------------------------
907 destPath+=rtl::OUString("/");
908 destPath+=file3;
910 printf( "Copy the file ");
911 printFileName( file1 );
912 printf( " to ");
913 printFileName( destPath );
914 printf( "\n" );
917 rc=File::copy( file1 , destPath );
918 print_error( rtl::OString( "FileCopy" ), rc );
920 pFile=new File( destPath );
922 rc=pFile->open( osl_File_OpenFlag_Read );
923 if ( rc == FileBase::E_None)
925 printf( "Verify: OK!\n" );
926 pFile->close();
927 File::remove( destPath );
929 else
930 printf( "Verify: Error!\n" );
932 delete pFile;
934 printf( "\n" );
936 //--------------------------------------------------
937 // Copy a file to a not existing directory
938 //--------------------------------------------------
940 destPath=rtl::OUString( dir_not_exist );
941 destPath+=rtl::OUString("/");
942 destPath+=file3;
944 printf( "Copy a file to a not existing directory \n");
945 printf( "Copy the file %s to %s\n",
946 rtl::OUStringToOString( file1, RTL_TEXTENCODING_ASCII_US ).getStr(),
947 rtl::OUStringToOString( destPath, RTL_TEXTENCODING_ASCII_US ).getStr() );
949 rc=File::copy( file1, destPath );
950 print_error( rtl::OString( "FileCopy" ), rc );
952 printf( "\n" );
954 //--------------------------------------------------
955 // Copy a directory
956 //--------------------------------------------------
958 printf( "Copy the directory: ");
959 printFileName( dir1 );
960 printf( " to ");
961 printFileName( dir2 );
962 printf( "\n" );
964 rc=File::copy( dir1 , dir2 );
965 print_error( rtl::OString( "FileCopy" ), rc );
967 printf( "\n" );
969 //--------------------------------------------------
970 // FileMoveTest
971 //--------------------------------------------------
973 destPath=rtl::OUString( dir2 );
974 destPath+=rtl::OUString("/");
975 destPath+=file3;
977 printf( "Move the file ");
978 printFileName( file1 );
979 printf( " to ");
980 printFileName( destPath );
981 printf( "\n" );
983 rc=File::move( file1, destPath );
984 print_error( rtl::OString( "FileMove" ), rc );
986 pFile=new File( destPath );
988 rc=pFile->open( osl_File_OpenFlag_Read );
989 if ( rc==FileBase::E_None )
991 pFile->close();
993 delete pFile;
994 pFile=new File( file1 );
996 rc=pFile->open( osl_File_OpenFlag_Read );
998 if ( rc!=FileBase::E_None )
1000 printf( "Verify: OK!\n" );
1001 File::move( destPath, file1 );
1003 else
1005 printf( "Verify: Error!\n" );
1006 pFile->close();
1007 File::remove( destPath );
1010 else
1011 printf( "Verify: Error!\n" );
1013 delete pFile;
1015 printf( "\n" );
1018 //--------------------------------------------------
1019 // Move a file to a not existing directory
1020 //--------------------------------------------------
1022 destPath=rtl::OUString( dir_not_exist );
1023 destPath+=rtl::OUString("/");
1024 destPath+=file3;
1026 printf( "Move a file to a not existing directory: \n");
1027 printf( "Move the file ");
1028 printFileName( file1 );
1029 printf( " to ");
1030 printFileName( destPath );
1031 printf( "\n" );
1033 rc=File::move( file1 , destPath );
1034 print_error( rtl::OString( "FileMove" ), rc );
1036 printf( "\n" );
1038 //--------------------------------------------------
1039 // Move a directory
1040 //--------------------------------------------------
1042 printf( "Move a directory: \n");
1044 printf( "Move the directory ");
1045 printFileName( dir1 );
1046 printf( " to ");
1047 printFileName( dir_not_exist );
1048 printf( "\n" );
1051 rc=File::move( dir1 , dir_not_exist);
1052 print_error( rtl::OString( "FileMove" ), rc );
1054 if ( rc == FileBase::E_None )
1055 File::move( dir_not_exist , dir1);
1057 printf( "\n" );
1060 PressKey();
1061 return;
1064 //----------------------------------------------------
1065 // FileSizeTest
1066 //----------------------------------------------------
1068 void FileSizeTest( void )
1070 FileBase::RC rc;
1071 sal_uInt64 filesize;
1072 DirectoryItem aItem;
1074 printf( "--------------------------------------------\n" );
1075 printf( "File-Size-Test\n" );
1076 printf( "--------------------------------------------\n\n" );
1079 File aFile( file_not_exist );
1081 printf( "Create File: ");
1082 printFileName( file_not_exist );
1083 printf( "\n\n");
1085 rc = aFile.open( osl_File_OpenFlag_Read | osl_File_OpenFlag_Write | osl_File_OpenFlag_Create );
1086 print_error( rtl::OString( "Create and Open File (Read & Write)" ), rc );
1087 printf( "\n" );
1089 if ( rc == FileBase::E_None )
1091 //----------------------------------------------------
1092 // Set Filesize to 5000
1093 //----------------------------------------------------
1095 printf( "Set FileSize to 5000\n" );
1096 rc=aFile.setSize( 5000 );
1097 print_error( rtl::OString( "Set FileSize" ), rc );
1099 printf( "\n" );
1100 printf( "Verify:\n" );
1102 //----------------------------------------------------
1103 // Check whether Filesize is set to 5000
1104 //----------------------------------------------------
1106 rc=DirectoryItem::get( file_not_exist, aItem );
1107 print_error( rtl::OString( "Get DirectoryItem" ), rc );
1109 if ( rc == FileBase::E_None )
1111 FileStatus rStatus( osl_FileStatus_Mask_FileSize );
1112 rc=aItem.getFileStatus( rStatus );
1113 print_error( rtl::OString( "Get FileStatus" ), rc );
1115 if ( rc == FileBase::E_None )
1117 filesize=rStatus.getFileSize();
1119 if ( filesize == 5000 )
1120 printf( "\nOK : FileSize: %" SAL_PRIuUINT64 "\n", filesize );
1121 else
1122 printf( "\nError : FileSize: %" SAL_PRIuUINT64 "\n", filesize );
1126 printf( "\n" );
1128 //----------------------------------------------------
1129 // Set Filesize to -1
1130 //----------------------------------------------------
1132 printf( "Set FileSize to -1\n" );
1133 rc=aFile.setSize( -1 );
1134 print_error( rtl::OString( "Set FileSize" ), rc );
1136 printf( "\n" );
1138 // close the file
1139 rc=aFile.close();
1140 print_error( rtl::OString( "Close File" ), rc );
1142 // remove the file
1143 rc=File::remove( file_not_exist );
1144 print_error( rtl::OString( "Remove File" ), rc );
1147 PressKey();
1149 return;
1153 //----------------------------------------------------
1154 // FilePointerTest
1155 //----------------------------------------------------
1157 void FilePointerTest( void )
1159 FileBase::RC rc;
1160 sal_uInt64 filepointer;
1162 printf( "--------------------------------------------\n" );
1163 printf( "File-Pointer-Test\n" );
1164 printf( "--------------------------------------------\n\n" );
1167 File rFile( file_not_exist );
1169 printf( "Create File: ");
1170 printFileName( file_not_exist );
1171 printf( "\n\n");
1173 rc = rFile.open( osl_File_OpenFlag_Read | osl_File_OpenFlag_Write | osl_File_OpenFlag_Create );
1174 print_error( rtl::OString( "Create and Open File (Read & Write) "), rc );
1175 printf( "\n" );
1177 if ( rc==FileBase::E_None )
1180 //----------------------------------------------------
1181 // get the position of the filepointer
1182 //----------------------------------------------------
1184 rc =rFile.getPos( filepointer );
1185 print_error( rtl::OString( "GetPos" ), rc );
1186 printf( "Position of the FilePointer: %" SAL_PRIuUINT64 "\n", filepointer );
1188 printf( "\n" );
1190 //----------------------------------------------------
1191 // set the filepointer at the end of a file
1192 //----------------------------------------------------
1194 printf( "Set FileSize to 5000\n" );
1195 rFile.setSize( 5000 );
1197 printf( "Set the FilePointer at the end of the file (5000)\n" );
1198 rc=rFile.setPos( osl_Pos_End,0 );
1199 print_error( rtl::OString( "SetPos" ), rc );
1201 rc=rFile.getPos( filepointer );
1203 if ( filepointer==5000 )
1205 print_error( rtl::OString( "GetPos" ), rc );
1206 printf( "\nVerify: OK !\n" );
1207 printf( "Filepointer-Position: %" SAL_PRIuUINT64 "\n",filepointer );
1209 else
1211 print_error( rtl::OString( "GetPos" ), rc );
1212 printf( "\nFilePointer-Test: Error\n" );
1213 printf( "Filepointer-Position: %" SAL_PRIuUINT64 " != 5000 \n",filepointer );
1216 printf( "\n" );
1218 // close the file
1219 rc=rFile.close();
1220 print_error( rtl::OString( "Close File" ), rc );
1222 // remove the file
1223 rc=File::remove( file_not_exist );
1224 print_error( rtl::OString( "Remove File" ), rc );
1227 PressKey();
1229 return;
1232 //--------------------------------------------------
1233 // FileAttributesTest
1234 //--------------------------------------------------
1236 void verifyFileAttributes( void )
1238 FileBase::RC rc;
1239 DirectoryItem aItem;
1240 FileStatus rStatus( osl_FileStatus_Mask_Attributes );
1242 printf( "\nVerify:\n" );
1244 rc=DirectoryItem::get( file1, aItem );
1246 if ( rc==FileBase::E_None )
1248 rc=aItem.getFileStatus( rStatus );
1250 if ( rc==FileBase::E_None )
1252 sal_uInt64 uAttributes=rStatus.getAttributes();
1253 showAttributes(uAttributes);
1254 printf( "\n" );
1256 else
1257 print_error( rtl::OString( "Get FileStatus" ), rc );
1259 else
1260 print_error( rtl::OString( "Get DirectoryItem" ), rc );
1262 return;
1265 #ifdef UNX
1266 void FileAttributesTest( void )
1268 FileBase::RC rc;
1270 printf( "--------------------------------------------\n" );
1271 printf( "File-Attributes-Test\n" );
1272 printf( "--------------------------------------------\n\n" );
1274 printf( "File: ");
1275 printFileName( file1 );
1276 printf( "\n\n" );
1279 rc=File::setAttributes( file1, osl_File_Attribute_GrpWrite );
1280 print_error( rtl::OString( "Set Attribute: GrpWrite" ), rc );
1282 verifyFileAttributes();
1284 rc=File::setAttributes( file1, 0 );
1285 if ( rc!=FileBase::E_None )
1286 print_error( rtl::OString( "Reset Attributes" ), rc );
1288 rc=File::setAttributes( file1, osl_File_Attribute_GrpRead );
1289 print_error( rtl::OString( "Set Attribute: GrpRead" ), rc );
1291 verifyFileAttributes();
1293 rc=File::setAttributes( file1, 0 );
1294 if ( rc!=FileBase::E_None )
1295 print_error( rtl::OString( "Reset Attributes" ), rc );
1297 rc=File::setAttributes( file1, osl_File_Attribute_GrpExe );
1298 print_error( rtl::OString( "Set Attribute: GrpExe" ), rc );
1300 verifyFileAttributes();
1302 rc=File::setAttributes( file1, 0 );
1303 if ( rc!=FileBase::E_None )
1304 print_error( rtl::OString( "Reset Attributes" ), rc );
1306 rc=File::setAttributes( file1, osl_File_Attribute_OwnWrite );
1307 print_error( rtl::OString( "Set Attribute: OwnWrite" ), rc );
1309 verifyFileAttributes();
1311 rc=File::setAttributes( file1, 0 );
1312 if ( rc!=FileBase::E_None )
1313 print_error( rtl::OString( "Reset Attributes" ), rc );
1315 rc=File::setAttributes( file1, osl_File_Attribute_OwnRead );
1316 print_error( rtl::OString( "Set Attribute: OwnRead" ), rc );
1318 verifyFileAttributes();
1320 rc=File::setAttributes( file1, 0 );
1321 if ( rc!=FileBase::E_None )
1322 print_error( rtl::OString( "Reset Attributes" ), rc );
1324 rc=File::setAttributes( file1, osl_File_Attribute_OwnExe );
1325 print_error( rtl::OString( "Set Attribute: OwnExe" ), rc );
1327 verifyFileAttributes();
1329 rc=File::setAttributes( file1, 0 );
1330 if ( rc!=FileBase::E_None )
1331 print_error( rtl::OString( "Reset Attributes" ), rc );
1333 rc=File::setAttributes( file1, osl_File_Attribute_OthWrite );
1334 print_error( rtl::OString( "Set Attribute: OthWrite" ), rc );
1336 verifyFileAttributes();
1338 rc=File::setAttributes( file1, 0 );
1339 if ( rc!=FileBase::E_None )
1340 print_error( rtl::OString( "Reset Attributes" ), rc );
1342 rc=File::setAttributes( file1, osl_File_Attribute_OthRead );
1343 print_error( rtl::OString( "Set Attribute: OthRead" ), rc );
1345 verifyFileAttributes();
1347 rc=File::setAttributes( file1, 0 );
1348 if ( rc!=FileBase::E_None )
1349 print_error( rtl::OString( "Reset Attributes" ), rc );
1351 rc=File::setAttributes( file1, osl_File_Attribute_OthExe );
1352 print_error( rtl::OString( "Set Attribute: OthExe" ), rc );
1354 verifyFileAttributes();
1356 rc=File::setAttributes( file1, 0 );
1357 if ( rc!=FileBase::E_None )
1358 print_error( rtl::OString( "Reset Attributes" ), rc );
1361 rc=File::setAttributes( file1, osl_File_Attribute_GrpWrite | osl_File_Attribute_GrpRead | osl_File_Attribute_GrpExe | osl_File_Attribute_OwnWrite | osl_File_Attribute_OwnRead | osl_File_Attribute_OwnExe | osl_File_Attribute_OthWrite | osl_File_Attribute_OthRead | osl_File_Attribute_OthExe );
1362 print_error( rtl::OString( "Set all Attributes" ), rc );
1364 verifyFileAttributes();
1366 PressKey();
1368 return;
1370 #endif
1372 #ifdef WNT
1373 void FileAttributesTest( void )
1375 FileBase::RC rc;
1377 printf( "--------------------------------------------\n" );
1378 printf( "File-Attributes-Test\n" );
1379 printf( "--------------------------------------------\n\n" );
1381 printf( "File: ");
1382 printFileName( file1 );
1383 printf( "\n\n" );
1386 rc=File::setAttributes( file1, osl_File_Attribute_ReadOnly );
1387 print_error( rtl::OString( "Set Attribute: ReadOnly" ), rc );
1389 verifyFileAttributes();
1391 rc=File::setAttributes( file1, 0 );
1392 print_error( rtl::OString( "Reset Attributes" ), rc );
1394 verifyFileAttributes();
1396 rc=File::setAttributes( file1, osl_File_Attribute_Hidden );
1397 print_error( rtl::OString( "Set Attribute: Hidden" ), rc );
1399 verifyFileAttributes();
1401 rc=File::setAttributes( file1, 0 );
1402 print_error( rtl::OString( "Reset Attributes" ), rc );
1404 verifyFileAttributes();
1406 rc=File::setAttributes( file1, osl_File_Attribute_Hidden | osl_File_Attribute_ReadOnly );
1407 print_error( rtl::OString( "Set Attribute: Hidden & ReadOnly" ), rc );
1409 verifyFileAttributes();
1411 rc=File::setAttributes( file1, 0 );
1412 print_error( rtl::OString( "Reset Attributes") , rc );
1414 verifyFileAttributes();
1416 PressKey();
1418 return;
1420 #endif
1422 //--------------------------------------------------
1423 // FileTimeTest
1424 //--------------------------------------------------
1426 void FileTimeTest( void )
1428 FileBase::RC rc;
1430 DirectoryItem aItem;
1432 struct tm sSysCreationTime;
1433 sSysCreationTime.tm_sec = 0;
1434 sSysCreationTime.tm_min = 20;
1435 sSysCreationTime.tm_hour = 12;
1436 sSysCreationTime.tm_mday = 4;
1437 sSysCreationTime.tm_mon = 9;
1438 sSysCreationTime.tm_year = 99;
1440 struct tm sSysAccessTime;
1441 sSysAccessTime.tm_sec = 0;
1442 sSysAccessTime.tm_min = 40;
1443 sSysAccessTime.tm_hour = 1;
1444 sSysAccessTime.tm_mday = 6;
1445 sSysAccessTime.tm_mon = 5;
1446 sSysAccessTime.tm_year = 98;
1448 struct tm sSysModifyTime;
1449 sSysModifyTime.tm_sec = 0;
1450 sSysModifyTime.tm_min = 1;
1451 sSysModifyTime.tm_hour = 24;
1452 sSysModifyTime.tm_mday = 13;
1453 sSysModifyTime.tm_mon = 11;
1454 sSysModifyTime.tm_year = 95;
1456 sal_uInt32 aSysCreationTime = mktime( &sSysCreationTime );
1457 sal_uInt32 aSysAccessTime = mktime( &sSysAccessTime );
1458 sal_uInt32 aSysModifyTime = mktime( &sSysModifyTime );
1460 TimeValue aCreationTime = { aSysCreationTime, 0};
1461 TimeValue aAccessTime = { aSysAccessTime, 0};
1462 TimeValue aModifyTime = { aSysModifyTime, 0};
1464 TimeValue aCreationTimeRead;
1465 TimeValue aAccessTimeRead;
1466 TimeValue aModifyTimeRead;
1469 printf( "--------------------------------------------\n" );
1470 printf( "File-Time-Test\n" );
1471 printf( "--------------------------------------------\n\n" );
1473 printf( "File: ");
1474 printFileName( file1 );
1475 printf( "\n\n" );
1477 printf( "CreationTime \t : ");
1478 showTime( aCreationTime );
1480 printf( "\nAccessTime \t : ");
1481 showTime( aAccessTime );
1483 printf( "\nModifyTime \t : ");
1484 showTime( aModifyTime );
1486 //--------------------------------------------------
1487 // setTime
1488 //--------------------------------------------------
1490 printf( "\n" );
1491 rc=File::setTime( file1 , aCreationTime , aAccessTime , aModifyTime );
1492 print_error( rtl::OString( "SetTime" ), rc );
1494 //--------------------------------------------------
1495 // Verify
1496 //--------------------------------------------------
1498 FileStatus rStatus( osl_FileStatus_Mask_CreationTime | osl_FileStatus_Mask_AccessTime | osl_FileStatus_Mask_ModifyTime);
1500 printf( "\nVerify:\n" );
1502 rc=DirectoryItem::get( file1, aItem );
1503 print_error( rtl::OString( "Get DirectoryItem" ), rc );
1505 if ( rc==FileBase::E_None )
1507 rc=aItem.getFileStatus( rStatus );
1508 print_error( rtl::OString( "Get FileStatus" ), rc );
1509 printf( "\n" );
1511 if ( rc==FileBase::E_None )
1513 //--------------------------------------------------
1514 // GetCreationTime
1515 //--------------------------------------------------
1517 aCreationTimeRead=rStatus.getCreationTime();
1518 #ifdef WNT
1519 if ( aCreationTime.Seconds == aCreationTimeRead.Seconds && aCreationTime.Nanosec == aCreationTimeRead.Nanosec )
1520 printf( "GetCreationTime: ok : " );
1521 else
1522 printf( "GetCreationTime: Error : " );
1524 showTime( aCreationTimeRead );
1525 printf( "\n" );
1526 #endif
1527 //--------------------------------------------------
1528 // GetAccessTime
1529 //--------------------------------------------------
1531 aAccessTimeRead=rStatus.getAccessTime();
1533 if ( aAccessTime.Seconds == aAccessTimeRead.Seconds && aAccessTime.Nanosec == aAccessTimeRead.Nanosec )
1534 printf( "GetAccessTime: ok : " );
1535 else
1536 printf( "GetAccessTime: Error : " );
1538 showTime( aAccessTimeRead );
1539 printf( "\n" );
1541 //--------------------------------------------------
1542 // GetModifyTime
1543 //--------------------------------------------------
1545 aModifyTimeRead=rStatus.getModifyTime();
1547 if ( aModifyTime.Seconds == aModifyTimeRead.Seconds && aModifyTime.Nanosec == aModifyTimeRead.Nanosec )
1548 printf( "GetModifyTime: ok : " );
1549 else
1550 printf( "GetModifyTime: Error : " );
1552 showTime( aModifyTimeRead );
1553 printf( "\n" );
1557 PressKey();
1558 return;
1562 //--------------------------------------------------
1563 // DirectoryItemTest
1564 //--------------------------------------------------
1566 void DirectoryItemTest( void )
1568 FileBase::RC rc;
1569 Directory *pDir;
1570 DirectoryItem aItem;
1571 FileStatus *pStatus;
1572 File *pFile;
1574 printf( "--------------------------------------------\n" );
1575 printf( "Directory-Item-Test\n" );
1576 printf( "--------------------------------------------\n\n" );
1578 //--------------------------------------------------
1579 // get DirectoryItem from an existing directory
1580 //--------------------------------------------------
1582 printf( "Get DirectoryItem from an existing Directory: ");
1583 printFileName( dir1 );
1584 printf( "\n");
1586 rc=DirectoryItem::get( dir1 , aItem );
1587 print_error( rtl::OString( "GetDirectoryItem" ), rc );
1589 pStatus=new FileStatus( osl_FileStatus_Mask_All );
1590 rc=aItem.getFileStatus( *pStatus );
1592 if ( rc==FileBase::E_None )
1594 printf( "GetFileStatus: FileURL: ");
1595 printFileName(pStatus->getFileURL() );
1596 printf( "\n" );
1599 delete pStatus;
1601 printf( "\n" );
1603 //--------------------------------------------------
1604 // get DirectoryItem from a not existing directory
1605 //--------------------------------------------------
1607 printf( "Get DirectoryItem from a not existing Directory: ");
1608 printFileName( dir_not_exist );
1609 printf( "\n" );
1611 rc=DirectoryItem::get( dir_not_exist , aItem );
1612 print_error( rtl::OString( "Get DirectoryItem" ), rc );
1614 printf( "\n" );
1616 //--------------------------------------------------
1617 // get DirectoryItem from an existing file
1618 //--------------------------------------------------
1620 printf( "Get DirectoryItem from an existing File: ");
1621 printFileName( file1 );
1622 printf( "\n" );
1624 rc=DirectoryItem::get( file1 , aItem );
1625 print_error( rtl::OString( "GetDirectoryItem" ), rc );
1627 pStatus=new FileStatus( osl_FileStatus_Mask_All );
1628 rc=aItem.getFileStatus( *pStatus );
1630 if ( rc==FileBase::E_None )
1632 printf( "GetFileStatus: FileURL: ");
1633 printFileName( pStatus->getFileURL() );
1634 printf( "\n" );
1637 delete pStatus;
1639 printf( "\n" );
1641 //--------------------------------------------------
1642 // get DirectoryItem from a not existing file
1643 //--------------------------------------------------
1645 printf( "Get DirectoryItem from a not existing File: ");
1646 printFileName( file_not_exist );
1647 printf( "\n" );
1649 rc=DirectoryItem::get( file_not_exist , aItem );
1650 print_error( rtl::OString( "Get DirectoryItem" ), rc );
1652 printf( "\n" );
1654 //----------------------------------------------------------
1655 // get DirectoryItem from a directory with a wrong semantic
1656 //----------------------------------------------------------
1658 printf( "Get DirectoryItem from a Directory with a wrong semantic: ");
1659 printFileName( dir_not_exist );
1660 printf( "\n" );
1662 rc=DirectoryItem::get( dir_wrong_semantic, aItem );
1663 print_error( rtl::OString( "Get DirectoryItem" ),rc );
1665 printf( "\n" );
1667 //---------------------------------------------------
1668 // get DirectoryItem from a file-handle
1669 //--------------------------------------------------
1671 pFile=new File( file1 );
1673 rc=pFile->open( osl_File_OpenFlag_Read );
1674 if ( rc==FileBase::E_None )
1676 printf( "Get DirectoryItem from a File-Handle: ");
1677 printFileName( file1 );
1678 printf( "\n" );
1680 rc=DirectoryItem::get( file1 , aItem );
1681 print_error( rtl::OString( "GetDirectoryItem" ), rc );
1683 pStatus=new FileStatus( osl_FileStatus_Mask_All );
1684 rc=aItem.getFileStatus( *pStatus );
1686 if ( rc==FileBase::E_None )
1688 printf( "GetFileStatus: FileURL: ");
1689 printFileName( pStatus->getFileURL() );
1690 printf( "\n");
1693 delete pStatus;
1695 pFile->close();
1698 delete pFile;
1700 printf( "\n" );
1702 //---------------------------------------------------
1703 // get DirectoryItem
1704 //--------------------------------------------------
1706 printf( "Get DirectoryItem from an empty File-Handle\n" );
1707 rc=DirectoryItem::get( file1 , aItem );
1708 print_error( rtl::OString( "GetDirectoryItem" ), rc );
1710 printf( "\n" );
1712 //--------------------------------------------------
1713 // GetNextItem from a directory
1714 //--------------------------------------------------
1716 pDir=new Directory( dir1 );
1717 printf( "Get next DirectoryItem from a directory: ");
1718 printFileName( dir1);
1719 printf( "\n" );
1721 rc= pDir->open();
1722 print_error( rtl::OString( "Open Directory" ), rc );
1724 printf( "\n" );
1726 if ( pDir->isOpen() )
1728 //--------------------------------------------------
1729 // get all files from the directory
1730 //--------------------------------------------------
1732 rtl::OUString str;
1733 rtl::OUString str1[2];
1735 aItem=DirectoryItem();
1736 rc=pDir->getNextItem( aItem );
1737 print_error( rtl::OString( "GetNextItem" ),rc );
1739 while( rc==FileBase::E_None )
1742 FileStatus rStatus( osl_FileStatus_Mask_All );
1743 aItem.getFileStatus( rStatus );
1745 str=rStatus.getFileName();
1746 printf( "Filename: ");
1747 printFileName( str );
1748 printf( "\n");
1750 aItem=DirectoryItem();
1751 rc=pDir->getNextItem( aItem );
1752 print_error( rtl::OString( "GetNextItem" ),rc );
1755 printf( "\n" );
1757 //--------------------------------------------------
1758 // Reset-Test
1759 //--------------------------------------------------
1761 for (int i=0; i<2; i++)
1763 aItem=DirectoryItem();
1764 rc=pDir->reset();
1765 rc=pDir->getNextItem( aItem );
1767 FileStatus rStatus( osl_FileStatus_Mask_All );
1768 aItem.getFileStatus( rStatus );
1770 str1[i]=rStatus.getFileName();
1774 if ( str1[0].compareTo(str1[1]) == 0 )
1775 print_error( rtl::OString( "Reset" ),FileBase::E_None );
1776 else
1777 print_error( rtl::OString( "Reset" ),FileBase::E_invalidError );
1779 printf( "\n" );
1781 // Close Directory
1782 rc=pDir->close();
1783 print_error( rtl::OString( "Close Directory" ), rc );
1786 printf( "\n");
1788 //--------------------------------------------------
1789 // GetNextItem from a closed directory
1790 //--------------------------------------------------
1792 printf( "Get next DirectoryItem from a closed directory: ");
1793 printFileName( dir1 );
1794 printf( "\n" );
1796 aItem=DirectoryItem();
1797 rc=pDir->getNextItem( aItem );
1798 print_error( rtl::OString( "GetNextItem" ),rc );
1800 delete pDir;
1802 PressKey();
1803 return;
1806 //--------------------------------------------------
1807 // FileStatusTest (for different types)
1808 //--------------------------------------------------
1810 void FileStatusTest( FileStatus *pStatus )
1812 //--------------------------------------------------
1813 // GetFileType of the directory
1814 //--------------------------------------------------
1816 FileStatus::Type aType;
1818 printf( "\ngetFileType:\n" );
1819 aType=pStatus->getFileType();
1820 showFileType( aType );
1822 //--------------------------------------------------
1823 // GetAttributes
1824 //--------------------------------------------------
1826 sal_uInt64 uAttributes;
1828 printf( "\ngetAttributes:\n" );
1829 uAttributes=pStatus->getAttributes();
1830 showAttributes( uAttributes );
1832 //--------------------------------------------------
1833 // GetCreationTime
1834 //--------------------------------------------------
1836 TimeValue aCreationTime;
1838 printf( "\ngetCreationTime:\n" );
1839 aCreationTime=pStatus->getCreationTime();
1841 printf( "CreationTime: " );
1842 showTime( aCreationTime );
1844 //--------------------------------------------------
1845 // GetAccessTime
1846 //--------------------------------------------------
1848 TimeValue aAccessTime;
1850 printf( "\ngetAccessTime:\n" );
1851 aAccessTime=pStatus->getAccessTime();
1853 printf( "AccessTime: " );
1854 showTime( aAccessTime );
1856 //--------------------------------------------------
1857 // GetModifyTime
1858 //--------------------------------------------------
1860 TimeValue aModifyTime;
1862 printf( "\ngetModifyTime:\n" );
1863 aModifyTime=pStatus->getModifyTime();
1865 printf( "ModifyTime: " );
1866 showTime( aModifyTime );
1868 //--------------------------------------------------
1869 // GetFileSize
1870 //--------------------------------------------------
1872 sal_uInt64 FileSize;
1874 printf( "\ngetFileSize:\n" );
1876 FileSize=pStatus->getFileSize();
1877 printf( "FileSize: %" SAL_PRIuUINT64 "\n", FileSize);
1879 //--------------------------------------------------
1880 // GetFileName
1881 //--------------------------------------------------
1883 rtl::OUString FileName;
1885 printf( "\ngetFileName:\n" );
1887 FileName=pStatus->getFileName();
1888 printf( "FileName: ");
1889 printFileName( FileName );
1890 printf( "\n" );
1892 //--------------------------------------------------
1893 // GetFileURL
1894 //--------------------------------------------------
1896 rtl::OUString FileURL;
1898 printf( "\ngetFileURL:\n" );
1900 FileURL=pStatus->getFileURL();
1901 printf( "FileURL: ");
1902 printFileName( FileURL );
1903 printf( "\n" );
1905 //--------------------------------------------------
1906 // GetLinkTargetURL
1907 //--------------------------------------------------
1909 rtl::OUString LinkTargetURL;
1911 printf( "\ngetLinkTargetURL:\n");
1913 LinkTargetURL=pStatus->getLinkTargetURL();
1914 printf( "LinkTargetURL: ");
1915 printFileName( LinkTargetURL );
1916 printf( "\n" );
1918 return;
1921 //--------------------------------------------------
1922 // DirectoryFileStatusTest
1923 //--------------------------------------------------
1925 void DirectoryFileStatusTest( void )
1927 FileBase::RC rc;
1928 DirectoryItem aItem;
1929 FileStatus *pStatus;
1931 printf( "--------------------------------------------\n" );
1932 printf( "Directory-FileStatus-Test\n" );
1933 printf( "--------------------------------------------\n\n" );
1935 printf( "FileStatus of the directory: ");
1936 printFileName( dir1 );
1937 printf( "\n" );
1939 aItem=DirectoryItem();
1941 rc=DirectoryItem::get( dir1, aItem );
1942 print_error( rtl::OString( "Get DirectoryItem" ), rc );
1944 if ( rc==FileBase::E_None )
1946 pStatus=new FileStatus( osl_FileStatus_Mask_All );
1947 rc=aItem.getFileStatus( *pStatus );
1949 FileStatusTest( pStatus );
1951 delete pStatus;
1954 printf( "\n" );
1956 PressKey();
1957 return;
1960 //--------------------------------------------------
1961 // FileFileStatusTest
1962 //--------------------------------------------------
1964 void FileFileStatusTest( void )
1966 FileBase::RC rc;
1967 DirectoryItem aItem;
1968 FileStatus *pStatus;
1970 printf( "--------------------------------------------\n" );
1971 printf( "File-FileStatus-Test\n" );
1972 printf( "--------------------------------------------\n\n" );
1974 printf( "FileStatus of the file: ");
1975 printFileName( file1 );
1976 printf( "\n" );
1978 aItem=DirectoryItem();
1980 rc=DirectoryItem::get( file1 , aItem );
1981 print_error( rtl::OString( "Get DirectoryItem" ), rc );
1983 if ( rc==FileBase::E_None )
1985 pStatus=new FileStatus( osl_FileStatus_Mask_All );
1986 rc=aItem.getFileStatus( *pStatus );
1988 FileStatusTest( pStatus );
1990 delete pStatus;
1993 printf( "\n" );
1995 PressKey();
1996 return;
1999 //--------------------------------------------------
2000 // VolumeFileStatusTest
2001 //--------------------------------------------------
2003 void VolumeFileStatusTest( void )
2005 FileBase::RC rc;
2006 DirectoryItem aItem;
2007 FileStatus *pStatus;
2009 printf( "--------------------------------------------\n" );
2010 printf( "Volume-FileStatus-Test\n" );
2011 printf( "--------------------------------------------\n\n" );
2013 printf( "FileStatus of the Volume: ");
2014 printFileName( root );
2015 printf( "\n" );
2017 aItem=DirectoryItem();
2019 rc=DirectoryItem::get( root , aItem );
2020 print_error( rtl::OString( "Get DirectoryItem" ), rc );
2022 if ( rc==FileBase::E_None )
2024 pStatus=new FileStatus( osl_FileStatus_Mask_All) ;
2025 rc=aItem.getFileStatus( *pStatus );
2027 FileStatusTest( pStatus );
2029 delete pStatus;
2032 printf( "\n" );
2034 PressKey();
2035 return;
2039 //--------------------------------------------------
2040 // VolumeInfoTest
2041 //--------------------------------------------------
2043 void VolumeInfoTest( void )
2045 FileBase::RC rc;
2047 printf( "--------------------------------------------\n" );
2048 printf( "Volume-Info-Test\n" );
2049 printf( "--------------------------------------------\n\n" );
2051 printf( "VolumeInfo of the volume ");
2052 printFileName( root );
2054 printf( "\n" );
2056 VolumeInfo rInfo( osl_VolumeInfo_Mask_FreeSpace );
2057 rc=Directory::getVolumeInfo( root , rInfo );
2058 print_error( rtl::OString( "GetVolumeInfo" ),rc );
2060 printf( "\n" );
2062 //--------------------------------------------------
2063 // getRemoteFlag
2064 //--------------------------------------------------
2066 if ( rInfo.getRemoteFlag() )
2067 printf( "RemoteFlag: Yes\n" );
2068 else
2069 printf( "RemoteFlag: No\n" );
2071 //--------------------------------------------------
2072 // getRemoveableFlag
2073 //--------------------------------------------------
2075 if ( rInfo.getRemoveableFlag() )
2076 printf( "RemoveableFlag: Yes\n" );
2077 else
2078 printf( "RemoveableFlag: No\n" );
2080 //--------------------------------------------------
2081 // getTotalSpace
2082 //--------------------------------------------------
2084 sal_uInt64 TotalSpace;
2085 TotalSpace=rInfo.getTotalSpace();
2086 printf( "Total Space: %" SAL_PRIuUINT64 "\n",TotalSpace );
2088 //--------------------------------------------------
2089 // getFreeSpace
2090 //--------------------------------------------------
2092 sal_uInt64 FreeSpace;
2093 FreeSpace=rInfo.getFreeSpace();
2094 printf( "Free Space: %" SAL_PRIuUINT64 "\n",FreeSpace );
2096 //--------------------------------------------------
2097 // getUsedSpace
2098 //--------------------------------------------------
2100 sal_uInt64 UsedSpace;
2101 UsedSpace=rInfo.getUsedSpace();
2102 printf( "Used Space: %" SAL_PRIuUINT64 "\n",UsedSpace );
2104 //--------------------------------------------------
2105 // getMaxNameLength
2106 //--------------------------------------------------
2108 sal_uInt32 MaxNameLength;
2109 MaxNameLength=rInfo.getMaxNameLength();
2110 printf( "MaxNameLength: %" SAL_PRIuUINT32 "\n",MaxNameLength );
2112 //--------------------------------------------------
2113 // getMaxPathLength
2114 //--------------------------------------------------
2116 sal_uInt32 MaxPathLength;
2117 MaxPathLength=rInfo.getMaxPathLength();
2118 printf( "MaxPathLength: %" SAL_PRIuUINT32 "\n",MaxPathLength );
2120 //--------------------------------------------------
2121 // getFileSystemName
2122 //--------------------------------------------------
2124 rtl::OUString FileSystemName;
2125 FileSystemName=rInfo.getFileSystemName();
2126 printf( "File-System-Name: ");
2127 printFileName( FileSystemName );
2128 printf( "\n" );
2130 PressKey();
2131 return;
2134 //--------------------------------------------------
2135 // FileBaseTest
2136 //--------------------------------------------------
2138 void ConvertPathTest(rtl::OUString& strPath)
2140 FileBase::RC rc;
2142 rtl::OUString strNormPath;
2143 rtl::OUString strFileURL;
2144 rtl::OUString strNormPathFromFileURL;
2145 rtl::OUString strSystemPath;
2147 //--------------------------------------------------
2148 // normalizePath
2149 //--------------------------------------------------
2151 rc=FileBase::getFileURLFromSystemPath( strPath, strNormPath );
2153 if ( rc == FileBase::E_None )
2155 printf( "Normalized Path: \t\t");
2156 printFileName( strNormPath );
2157 printf( "\n" );
2159 else
2160 printf( "normalizePath: Error \n" );
2162 //--------------------------------------------------
2163 // getFileURLFromSystemPath
2164 //--------------------------------------------------
2166 if ( strNormPath.getLength() != 0 )
2168 rc=FileBase::getFileURLFromSystemPath( strNormPath, strFileURL );
2170 if ( rc == FileBase::E_None )
2172 printf( "File-URL: \t\t\t");
2173 printFileName( strFileURL );
2174 printf( "\n" );
2176 else
2177 printf( "getFileURLFromSystemPath: Error \n" );
2179 else
2180 printf( "getFileURLFromSystemPath: not tested \n" );
2182 //--------------------------------------------------
2183 // getNormalizedPathFromFileURL
2184 //--------------------------------------------------
2186 if ( strFileURL.getLength() != 0 )
2188 rc=FileBase::getSystemPathFromFileURL( strFileURL, strNormPathFromFileURL );
2190 if ( rc == FileBase::E_None )
2192 printf( "Normalized Path from File-URL: \t");
2193 printFileName( strNormPathFromFileURL );
2194 printf( "\n" );
2196 else
2197 printf( "getNormalizedPathFromFileURL: Error \n" );
2199 else
2200 printf( "getNormalizedPathFromFileURL: not tested \n" );
2203 //--------------------------------------------------
2204 // getSystemPathFromFileURL
2205 //--------------------------------------------------
2207 if ( strNormPath.getLength() != 0 )
2209 rc=FileBase::getSystemPathFromFileURL( strNormPath, strSystemPath );
2211 if ( rc == FileBase::E_None )
2213 printf( "System-Path: \t\t\t");
2214 printFileName( strSystemPath );
2215 printf( "\n");
2217 else
2218 printf( "getSystemPathFromFileURL: Error \n" );
2220 else
2221 printf( "getSystemPathFromFileURL: not tested \n" );
2223 //--------------------------------------------------
2224 // Verify
2225 //--------------------------------------------------
2227 if ( strNormPathFromFileURL == strNormPath )
2228 printf( "\nVerify: OK ! ( Normalized-Path == Normalized-Path-From-File-URL )\n" );
2229 else
2230 printf( "\nVerify: Error ! ( Normalized-Path != Normalized-Path-From-File-URL )\n" );
2232 return;
2235 void FileBaseTest()
2237 printf( "--------------------------------------------\n" );
2238 printf( "FileBase-Test\n" );
2239 printf( "--------------------------------------------\n\n" );
2241 //--------------------------------------------------
2242 // ConvertPath-Test (Local File)
2243 //--------------------------------------------------
2245 printf( "- Local File: ");
2246 printFileName( file1 );
2247 printf( "\n\n" );
2249 ConvertPathTest(file1);
2251 //--------------------------------------------------
2252 // ConvertPath-Test (File on a server)
2253 //--------------------------------------------------
2255 printf( "\n- File on server: ");
2256 printFileName( file_on_server );
2257 printf( "\n\n" );
2258 ConvertPathTest(file_on_server);
2260 PressKey();
2262 return;
2266 //--------------------------------------------------
2267 // AbsolutePathTest
2268 //--------------------------------------------------
2269 void DoAbsolutePathTest(rtl::OUString strDirBase, rtl::OUString strRelative)
2271 FileBase::RC rc;
2273 rtl::OUString strAbsolute;
2275 printf( "Base-Directory: \t");
2276 printFileName( strDirBase );
2277 printf( "\n" );
2278 printf( "Relative-Path: \t\t");
2279 printFileName ( strRelative );
2280 printf( "\n" );
2282 rc=FileBase::getAbsoluteFileURL( strDirBase, strRelative, strAbsolute );
2284 if ( rc == FileBase::E_None )
2286 printf( "Absolute-Path: \t\t");
2287 printFileName ( strAbsolute );
2288 printf( "\n" );
2290 else
2291 printf( "Absolute-Path: Error \n" );
2293 printf( "\n" );
2294 return;
2297 void AbsolutePathTest(void)
2299 printf( "--------------------------------------------\n" );
2300 printf( "AbsolutePath-Test\n" );
2301 printf( "--------------------------------------------\n\n" );
2303 DoAbsolutePathTest(dir1, rtl::OUString("."));
2304 DoAbsolutePathTest(dir1, rtl::OUString(".."));
2305 DoAbsolutePathTest(dir1, rtl::OUString("../.."));
2306 DoAbsolutePathTest(dir1, rtl::OUString("../HUHU"));
2308 DoAbsolutePathTest(dir_on_server, rtl::OUString("."));
2309 DoAbsolutePathTest(dir_on_server, rtl::OUString(".."));
2310 DoAbsolutePathTest(dir_on_server, rtl::OUString("../.."));
2311 DoAbsolutePathTest(dir_on_server, rtl::OUString("../HUHU"));
2313 PressKey();
2314 return;
2318 //--------------------------------------------------
2319 // searchPathTest
2320 //--------------------------------------------------
2322 void SearchPathTest(void)
2324 FileBase::RC rc;
2326 rtl::OUString strNormPath(file1);
2327 rtl::OUString strFileURL;
2328 rtl::OUString strSystemPath;
2329 rtl::OUString strResultPath;
2331 printf( "--------------------------------------------\n" );
2332 printf( "SearchPath-Test\n" );
2333 printf( "--------------------------------------------\n\n" );
2336 rc=FileBase::getFileURLFromSystemPath( strNormPath, strFileURL );
2337 print_error( rtl::OString( "getFileURLFromSystemPath" ), rc );
2338 rc=FileBase::getSystemPathFromFileURL( strNormPath, strSystemPath );
2339 print_error( rtl::OString( "getSystemPathFromFileURL" ), rc );
2341 //--------------------------------------------------
2342 // searchFileURL (with a normalized path)
2343 //--------------------------------------------------
2345 if ( strNormPath.getLength() != 0 )
2347 printf( "\nSearch-Normalized-Path (with a normalized path) : ");
2348 printFileName ( strNormPath );
2349 printf( "\n" );
2351 rc=FileBase::searchFileURL( strNormPath , rtl::OUString() , strResultPath );
2353 if ( rc == FileBase::E_None )
2355 printf( "Result: \t\t\t");
2356 printFileName ( strResultPath );
2357 printf( "\n" );
2359 else
2360 printf( "searchFileURL (with a normalized path): Error\n" );
2362 else
2363 printf( "searchFileURL (with a normalized path): not tested\n" );
2365 //--------------------------------------------------
2366 // searchFileURL (with a File-URL)
2367 //--------------------------------------------------
2369 if ( strFileURL.getLength() != 0 )
2371 printf( "\nSearch-Normalized-Path (with a FileURL) : ");
2372 printFileName( strFileURL );
2373 printf( "\n" );
2375 rc=FileBase::searchFileURL( strFileURL , rtl::OUString() , strResultPath );
2377 if ( rc == FileBase::E_None )
2379 printf( "Result: \t\t\t");
2380 printFileName ( strResultPath );
2381 printf( "\n" );
2383 else
2384 printf( "searchFileURL (with a FileURL path): Error\n" );
2386 else
2387 printf( "searchFileURL (with a FileURL path): not tested\n" );
2389 //--------------------------------------------------
2390 // searchFileURL (with a systempath)
2391 //--------------------------------------------------
2393 if ( strSystemPath.getLength() != 0 )
2395 printf( "\nSearch-Normalized-Path (with a SystemPath) : ");
2396 printFileName( strSystemPath );
2397 printf( "\n" );
2399 rc=FileBase::searchFileURL( strSystemPath , rtl::OUString() , strResultPath );
2401 if ( rc == FileBase::E_None )
2403 printf( "Result: \t\t\t");
2404 printFileName( strResultPath );
2405 printf( "\n" );
2407 else
2408 printf( "searchFileURL (with a systempath): Error\n" );
2410 else
2411 printf( "searchFileURL (with a systempath): not tested\n" );
2413 //--------------------------------------------------
2414 // searchFileURL (File and no searchpath)
2415 //--------------------------------------------------
2417 printf( "\nsearchFileURL: File (no searchpath) : ");
2418 printFileName( file3 );
2419 printf( "\n" );
2421 rc=FileBase::searchFileURL( file3 , rtl::OUString("") , strResultPath );
2423 if ( rc == FileBase::E_None )
2425 printf( "Result: \t\t\t");
2426 printFileName( strResultPath );
2427 printf( "\n" );
2429 else
2430 printf( "searchFileURL: File not found: OK ! \n" );
2432 //--------------------------------------------------
2433 // searchFileURL (File and Path)
2434 //--------------------------------------------------
2436 printf( "\nsearchFileURL: File : ");
2437 printFileName( file3 );
2438 printf( "\tSearchPath ");
2439 printFileName( dir1 );
2440 printf( "\n");
2442 rc=FileBase::searchFileURL( file3 , dir1 , strResultPath );
2444 if ( rc == FileBase::E_None )
2446 printf( "Result: \t\t\t");
2447 printFileName( strResultPath );
2448 printf( "\n");
2450 else
2451 printf( "searchFileURL: File not found: Error\n" );
2453 //------------------------------------------------------------
2454 // searchFileURL (File and searchpath with two entries)
2455 //------------------------------------------------------------
2457 rtl::OUString strSearchPath( dir_not_exist );
2458 strSearchPath+=rtl::OUString(";");
2459 strSearchPath+=dir_on_server;
2461 printf( "\nsearchFileURL: File : ");
2462 printFileName( file3 );
2463 printf( "SearchPath ");
2464 printFileName( strSearchPath );
2465 printf( "\n");
2467 rc=FileBase::searchFileURL( file3 , strSearchPath , strResultPath );
2469 if ( rc == FileBase::E_None )
2471 printf( "Result: \t\t\t");
2472 printFileName( strResultPath );
2473 printf( "\n" );
2475 else
2476 printf( "searchFileURL: File not found: Error\n" );
2478 //-------------------------------------------------------------------
2479 // searchFileURL (File and searchpath (with a wrong semantic))
2480 //-------------------------------------------------------------------
2482 strSearchPath=rtl::OUString( dir_wrong_semantic );
2484 printf( "\nsearchFileURL: File : ");
2485 printFileName( file3 );
2486 printf( "SearchPath ");
2487 printFileName( strSearchPath );
2488 printf( "\n");
2490 rc=FileBase::searchFileURL( file3 , strSearchPath , strResultPath );
2492 if ( rc == FileBase::E_None )
2493 printf( "Error: Wrong Semantich but no error occurs !\n" );
2494 else
2495 printf( "searchFileURL: File not found: OK !\n" );
2497 return;
2500 //--------------------------------------------------
2501 // CanonicalNameTest
2502 //--------------------------------------------------
2504 void getCanonicalNameTest(rtl::OUString strPath)
2506 FileBase::RC rc;
2508 rtl::OUString strValid;
2510 printf( "Original-Name: \t\t");
2511 printFileName( strPath );
2512 printf( "\n" );
2514 rc=FileBase::getCanonicalName( strPath, strValid );
2516 if ( rc == FileBase::E_None)
2518 printf( "Canonical-Name: \t");
2519 printFileName( strValid );
2520 printf( "\n");
2523 else
2524 printf( "Canonical-Name: Error \n" );
2526 printf( "\n" );
2527 return;
2530 void CanonicalNameTest(void)
2532 printf( "--------------------------------------------\n" );
2533 printf( "CanonicalName-Test\n" );
2534 printf( "--------------------------------------------\n\n" );
2536 getCanonicalNameTest( dir1 );
2537 getCanonicalNameTest( dir_on_server );
2538 getCanonicalNameTest( file1 );
2539 getCanonicalNameTest( file_on_server );
2541 PressKey();
2542 return;
2545 //--------------------------------------------------
2546 // print_error
2547 //--------------------------------------------------
2549 void print_error( const ::rtl::OString& str, FileBase::RC rc )
2552 printf( "%s : ", str.getStr() );
2553 switch(rc)
2555 case FileBase::E_None:
2556 printf("OK !\n");
2557 break;
2558 case FileBase::E_PERM:
2559 printf("E_PERM\n");
2560 break;
2561 case FileBase::E_NOENT:
2562 printf("E_NOENT\n");
2563 break;
2564 case FileBase::E_SRCH:
2565 printf("E_SRCH\n");
2566 break;
2567 case FileBase::E_INTR:
2568 printf("E_INTR\n");
2569 break;
2570 case FileBase::E_IO:
2571 printf("E_IO\n");
2572 break;
2573 case FileBase::E_NXIO:
2574 printf("E_NXIO\n");
2575 break;
2576 case FileBase::E_2BIG:
2577 printf("E_2BIG\n");
2578 break;
2579 case FileBase::E_NOEXEC:
2580 printf("E_NOEXEC\n");
2581 break;
2582 case FileBase::E_BADF:
2583 printf("E_BADF\n");
2584 break;
2585 case FileBase::E_CHILD:
2586 printf("E_CHILD\n");
2587 break;
2588 case FileBase::E_AGAIN:
2589 printf("E_AGAIN\n");
2590 break;
2591 case FileBase::E_NOMEM:
2592 printf("E_NOMEM\n");
2593 break;
2594 case FileBase::E_ACCES:
2595 printf("E_ACCES\n");
2596 break;
2597 case FileBase::E_FAULT:
2598 printf("E_FAULT\n");
2599 break;
2600 case FileBase::E_BUSY:
2601 printf("E_BUSY\n");
2602 break;
2603 case FileBase::E_EXIST:
2604 printf("E_EXIST\n");
2605 break;
2606 case FileBase::E_XDEV:
2607 printf("E_XDEV\n");
2608 break;
2609 case FileBase::E_NODEV:
2610 printf("E_NODEV\n");
2611 break;
2612 case FileBase::E_NOTDIR:
2613 printf("E_NOTDIR\n");
2614 break;
2615 case FileBase::E_ISDIR:
2616 printf("E_ISDIR\n");
2617 break;
2618 case FileBase::E_INVAL:
2619 printf("E_INVAL\n");
2620 break;
2621 case FileBase::E_NFILE:
2622 printf("E_NFILE\n");
2623 break;
2624 case FileBase::E_MFILE:
2625 printf("E_MFILE\n");
2626 break;
2627 case FileBase::E_NOTTY:
2628 printf("E_NOTTY\n");
2629 break;
2630 case FileBase::E_FBIG:
2631 printf("E_FBIG\n");
2632 break;
2633 case FileBase::E_NOSPC:
2634 printf("E_NOSPC\n");
2635 break;
2636 case FileBase::E_SPIPE:
2637 printf("E_SPIPE\n");
2638 break;
2639 case FileBase::E_ROFS:
2640 printf("E_ROFS\n");
2641 break;
2642 case FileBase::E_MLINK:
2643 printf("E_MLINK\n");
2644 break;
2645 case FileBase::E_PIPE:
2646 printf("E_PIPE\n");
2647 break;
2648 case FileBase::E_DOM:
2649 printf("E_DOM\n");
2650 break;
2651 case FileBase::E_RANGE:
2652 printf("E_RANGE\n");
2653 break;
2654 case FileBase::E_DEADLK:
2655 printf("E_DEADLK\n");
2656 break;
2657 case FileBase::E_NAMETOOLONG:
2658 printf("E_NAMETOOLONG\n");
2659 break;
2660 case FileBase::E_NOLCK:
2661 printf("E_NOLCK\n");
2662 break;
2663 case FileBase::E_NOSYS:
2664 printf("E_NOSYS\n");
2665 break;
2666 case FileBase::E_NOTEMPTY:
2667 printf("E_NOTEMPTY\n");
2668 break;
2669 case FileBase::E_LOOP:
2670 printf("E_LOOP\n");
2671 break;
2672 case FileBase::E_ILSEQ:
2673 printf("E_ILSEQ\n");
2674 break;
2675 case FileBase::E_NOLINK:
2676 printf("E_NOLINK\n");
2677 break;
2678 case FileBase::E_MULTIHOP:
2679 printf("E_MULTIHOP\n");
2680 break;
2681 case FileBase::E_USERS:
2682 printf("E_USERS\n");
2683 break;
2684 case FileBase::E_OVERFLOW:
2685 printf("E_OVERFLOW\n");
2686 break;
2687 default:
2688 printf("E_Unknown\n");
2689 break;
2691 return;
2694 //--------------------------------------------------
2695 // main
2696 //--------------------------------------------------
2697 #if defined WNT
2698 #define MAIN _cdecl main
2699 #else
2700 #define MAIN main
2701 #endif
2703 int MAIN( int argc, char* argv[] )
2705 sal_Bool fSuccess=sal_False;
2707 //Initialization
2708 fSuccess=Initialize();
2709 if ( !fSuccess )
2711 printf("Error during Initialization");
2712 return -1;
2716 if (argc==1)
2718 DirectoryOpenAndCloseTest();
2719 DirectoryCreateAndRemoveTest();
2721 FileOpenAndCloseTest();
2722 FileCreateAndRemoveTest();
2723 FileWriteAndReadTest();
2724 FileCopyAndMoveTest();
2725 FileSizeTest();
2726 FilePointerTest();
2727 FileAttributesTest();
2728 FileTimeTest();
2729 DirectoryItemTest();
2730 DirectoryFileStatusTest();
2731 VolumeFileStatusTest();
2732 FileFileStatusTest();
2733 VolumeInfoTest();
2734 FileBaseTest();
2735 SearchPathTest();
2736 AbsolutePathTest();
2737 CanonicalNameTest();
2739 // command line arguments ?
2740 else
2742 int i=1;
2744 while (i<argc)
2746 if (strcmp(argv[i], "doc")==0)
2747 DirectoryOpenAndCloseTest();
2748 else if (strcmp(argv[i], "dcr")==0)
2749 DirectoryCreateAndRemoveTest();
2750 else if (strcmp(argv[i], "foc")==0)
2751 FileOpenAndCloseTest();
2752 else if (strcmp(argv[i], "fcr")==0)
2753 FileCreateAndRemoveTest();
2754 else if (strcmp(argv[i], "fwr")==0)
2755 FileWriteAndReadTest();
2756 else if (strcmp(argv[i], "fcm")==0)
2757 FileCopyAndMoveTest();
2758 else if (strcmp(argv[i], "fs")==0)
2759 FileSizeTest();
2760 else if (strcmp(argv[i], "fp")==0)
2761 FilePointerTest();
2762 else if (strcmp(argv[i], "fa")==0)
2763 FileAttributesTest();
2764 else if (strcmp(argv[i], "ft")==0)
2765 FileTimeTest();
2766 else if (strcmp(argv[i], "di")==0)
2767 DirectoryItemTest();
2768 else if (strcmp(argv[i], "dfs")==0)
2769 DirectoryFileStatusTest();
2770 else if (strcmp(argv[i], "vfs")==0)
2771 VolumeFileStatusTest();
2772 else if (strcmp(argv[i], "ffs")==0)
2773 FileFileStatusTest();
2774 else if (strcmp(argv[i], "vi")==0)
2775 VolumeInfoTest();
2776 else if (strcmp(argv[i], "fb")==0)
2777 FileBaseTest();
2778 else if (strcmp(argv[i], "sp")==0)
2779 SearchPathTest();
2780 else if (strcmp(argv[i], "ap")==0)
2781 AbsolutePathTest();
2782 else if (strcmp(argv[i], "cn")==0)
2783 CanonicalNameTest();
2785 i++;
2789 // Shutdown
2790 fSuccess=Shutdown();
2791 if ( !fSuccess )
2793 printf("Error during Shutdown");
2794 return -1;
2797 return 0;
2801 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */