Version 4.2.0.1, tag libreoffice-4.2.0.1
[LibreOffice.git] / sal / workben / testfile.cxx
blobf4b1df974112461c5e3b23e58f9488874ab3f494
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #define UNICODE
24 #include <osl/file.hxx>
25 #include <osl/process.h>
26 #include <osl/time.h>
27 #include <rtl/alloc.h>
28 #include <rtl/ustring.hxx>
29 #include <stdio.h>
30 #include <string.h>
31 #include <time.h>
34 #ifdef UNX
35 #include <wchar.h>
36 #endif
38 #ifdef WNT
39 #include <windows.h>
40 #endif
42 using namespace osl;
43 using namespace rtl;
45 rtl::OUString root;
47 rtl::OUString dir1;
48 rtl::OUString dir2;
49 rtl::OUString dir_on_server;
50 rtl::OUString dir_not_exist;
51 rtl::OUString dir_not_exist_on_server;
52 rtl::OUString dir_wrong_semantic;
54 rtl::OUString file1;
55 rtl::OUString file2;
56 rtl::OUString file3;
57 rtl::OUString file_on_server;
58 rtl::OUString file_not_exist;
62 void print_error(const ::rtl::OString& str, FileBase::RC rc);
64 void PressKey()
66 printf("\nPress Return !\n");
67 getchar();
70 void printFileName(const ::rtl::OUString& str)
72 rtl::OString aString;
74 aString = rtl::OUStringToOString( str, RTL_TEXTENCODING_ASCII_US );
76 printf( "%s", aString.getStr() );
78 return;
81 //--------------------------------------------------
82 // Initialization
83 //--------------------------------------------------
85 sal_Bool testLineBreak( sal_Char *pCount , sal_uInt64 nLen , sal_uInt32 *cLineBreak )
87 sal_Bool fSuccess=sal_False;
88 *cLineBreak=0;
90 if (nLen==0)
91 return fSuccess;
93 if ( *pCount==13 )
95 if (nLen>=1 && *(pCount+1)==10)
96 *cLineBreak=2;
97 else
98 *cLineBreak=1;
100 if (nLen>=2 && *(pCount+2)==10)
101 (*cLineBreak)++;
103 fSuccess=sal_True;
105 else if ( *pCount==10 )
107 *cLineBreak=1;
108 fSuccess=sal_True;
111 return fSuccess;
114 // Initialization
116 sal_Bool Initialize( void )
118 DirectoryItem aItem;
119 FileStatus aStatus( osl_FileStatus_Mask_All );
120 rtl_uString *strExeFileURL=NULL;
121 oslProcessError ProcessError;
123 rtl::OUString iniFileURL;
124 File *pFile;
125 sal_Unicode *pExeFileCount;
127 FileBase::RC rc;
129 sal_uInt64 uBytesRequested;
130 sal_uInt64 uBytesRead;
131 sal_Char *pBuffer;
132 sal_Char *pBegin;
133 sal_Char *pCount;
135 rtl::OUString dir[12];
137 // Open to the ini-file
139 ProcessError=osl_getExecutableFile(&strExeFileURL);
141 if ( ProcessError == osl_Process_E_None)
143 pExeFileCount=rtl_uString_getStr(strExeFileURL)+rtl_uString_getLength(strExeFileURL);
145 // Search for the last slash in the Path
146 while (*pExeFileCount!=L'/' && pExeFileCount>rtl_uString_getStr(strExeFileURL))
147 pExeFileCount--;
149 // iniFileURL = strExeFileURL without the filename of the exe-File
150 iniFileURL=rtl::OUString( rtl_uString_getStr(strExeFileURL) ,(int) (pExeFileCount-rtl_uString_getStr(strExeFileURL)) );
152 // add "/testfile.ini" to iniFileURL
153 iniFileURL+=rtl::OUString("/testfile.ini");
155 // Open the ini-File
156 pFile=new File( iniFileURL );
157 rc=pFile->open( osl_File_OpenFlag_Read | osl_File_OpenFlag_Write );
158 if ( rc!=FileBase::E_None )
160 rtl_uString_release(strExeFileURL);
161 return sal_False;
164 else
166 rtl_uString_release(strExeFileURL);
167 return sal_False;
170 // Get filesize of the ini-File
172 rc=DirectoryItem::get( iniFileURL, aItem );
173 if ( rc!=FileBase::E_None )
174 return sal_False;
176 rc=aItem.getFileStatus( aStatus );
177 if ( rc!=FileBase::E_None )
178 return sal_False;
180 uBytesRequested=aStatus.getFileSize();
182 // read ini-File
183 rc=pFile->setPos( osl_Pos_Absolut, 0 );
184 pBuffer=(sal_Char*) rtl_allocateMemory( (sal_uInt32) (uBytesRequested+1)*sizeof(sal_Char) );
185 memset( pBuffer, 0, (sal_uInt32)(uBytesRequested+1)*sizeof(sal_Char) );
187 rc=pFile->read( pBuffer , uBytesRequested , uBytesRead );
188 if ( rc!=FileBase::E_None )
189 return sal_False;
192 pBegin=pBuffer;
193 pCount=pBegin;
195 for ( int i=0 ; i<12 ; i++ )
197 sal_uInt32 cLineBrake=0;
198 while ( (static_cast<sal_uInt64>(pCount-pBuffer) < uBytesRead) && *pCount!='=')
199 pCount++;
201 pCount++;
202 pBegin=pCount;
204 while ( (static_cast<sal_uInt64>(pCount-pBuffer) < uBytesRead) && !testLineBreak(pCount,uBytesRead-(pCount-pBuffer), &cLineBrake))
205 pCount++;
207 dir[i]=rtl::OUString(pBegin, pCount-pBegin, RTL_TEXTENCODING_ASCII_US);
209 pCount+=cLineBrake;
210 pBegin=pCount;
213 root=rtl::OUString(dir[0]);
214 dir1=rtl::OUString(dir[1]);
215 dir2=rtl::OUString(dir[2]);
216 dir_on_server=rtl::OUString(dir[3]);
217 dir_not_exist=rtl::OUString(dir[4]);
218 dir_not_exist_on_server=rtl::OUString(dir[5]);
219 dir_wrong_semantic=rtl::OUString(dir[6]);
221 file1=rtl::OUString(dir[7]);
222 file2=rtl::OUString(dir[8]);
223 file3=rtl::OUString(dir[9]);
224 file_on_server=rtl::OUString(dir[10]);
225 file_not_exist=rtl::OUString(dir[11]);
227 // close the ini-file
228 rc=pFile->close();
230 rtl_freeMemory( pBuffer );
233 // Create directories
234 rc=Directory::create( dir1 );
235 if ( rc!=FileBase::E_None )
236 return sal_False;
238 rc=Directory::create( dir2 );
239 if ( rc!=FileBase::E_None )
240 return sal_False;
242 rc=Directory::create( dir_on_server );
243 if ( rc!=FileBase::E_None )
244 return sal_False;
246 pFile=new File( file1 );
247 rc=pFile->open( osl_File_OpenFlag_Write | osl_File_OpenFlag_Create );
248 if ( rc!=FileBase::E_None )
249 return sal_False;
250 rc=pFile->close();
251 delete pFile;
253 pFile=new File( file2 );
254 rc=pFile->open( osl_File_OpenFlag_Write | osl_File_OpenFlag_Create );
255 if ( rc!=FileBase::E_None )
256 return sal_False;
257 rc=pFile->close();
258 delete pFile;
260 pFile=new File( file_on_server );
261 rc=pFile->open( osl_File_OpenFlag_Write | osl_File_OpenFlag_Create );
262 if ( rc!=FileBase::E_None )
263 return sal_False;
264 rc=pFile->close();
265 delete pFile;
267 return sal_True;
270 //--------------------------------------------------
271 // Shutdown
272 //--------------------------------------------------
274 sal_Bool Shutdown( void )
276 sal_Bool fSuccess=sal_True;
277 FileBase::RC rc;
278 File *pFile;
280 // remove created files
282 pFile=new File( file1 );
283 rc=pFile->remove( file1 );
284 if ( rc!=FileBase::E_None )
285 fSuccess=sal_False;
286 delete pFile;
288 pFile=new File( file2 );
289 rc=pFile->remove( file2 );
290 if ( rc!=FileBase::E_None )
291 fSuccess=sal_False;
292 delete pFile;
294 // remove created directories
296 rc=Directory::remove( dir1 );
297 if ( rc!=FileBase::E_None )
298 fSuccess=sal_False;
300 rc=Directory::remove( dir2 );
301 if ( rc!=FileBase::E_None )
302 fSuccess=sal_False;
304 // remove created file on the server
306 pFile=new File( file_on_server );
307 rc=pFile->remove( file_on_server );
308 if ( rc!=FileBase::E_None )
309 fSuccess=sal_False;
310 delete pFile;
312 // remove created directory on the server
314 rc=Directory::remove( dir_on_server );
315 if ( rc!=FileBase::E_None )
316 fSuccess=sal_False;
318 return fSuccess;
321 //--------------------------------------------------
322 // helper functions
323 //--------------------------------------------------
325 // Show FileType
326 void showFileType( FileStatus::Type aType )
328 if ( aType==FileStatus::Directory )
329 printf( "FileType: Directory \n" );
330 else if ( aType==FileStatus::Volume )
331 printf( "FileType: Volume \n" );
332 else if ( aType==FileStatus::Regular )
333 printf( "FileType: Regular \n" );
334 else if ( aType==FileStatus::Unknown )
335 printf( "FileType: Unknown \n" );
339 // Show Attributes
340 void showAttributes( sal_uInt64 uAttributes )
342 if ( uAttributes==0 )
343 printf( "No Attributes \n" );
344 if ( uAttributes & osl_File_Attribute_ReadOnly )
345 printf( "Attribute: ReadOnly \n" );
346 if ( uAttributes & osl_File_Attribute_Hidden )
347 printf( "Attribute: Hidden \n" );
348 if ( uAttributes & osl_File_Attribute_Executable )
349 printf( "Attribute: Executable \n");
350 if ( uAttributes & osl_File_Attribute_GrpWrite )
351 printf( "Attribute: GrpWrite \n");
352 if ( uAttributes & osl_File_Attribute_GrpRead )
353 printf( "Attribute: GrpRead \n" );
354 if ( uAttributes & osl_File_Attribute_GrpExe )
355 printf( "Attribute: GrpExe \n" );
356 if ( uAttributes & osl_File_Attribute_OwnWrite )
357 printf( "Attribute: OwnWrite \n");
358 if ( uAttributes & osl_File_Attribute_OwnRead )
359 printf( "Attribute: OwnRead \n" );
360 if ( uAttributes & osl_File_Attribute_OwnExe )
361 printf( "Attribute: OwnExe \n" );
362 if ( uAttributes & osl_File_Attribute_OthWrite )
363 printf( "Attribute: OthWrite \n" );
364 if ( uAttributes & osl_File_Attribute_OthRead )
365 printf( "Attribute: OthRead \n");
366 if ( uAttributes & osl_File_Attribute_OthExe )
367 printf( "Attribute: OthExe \n" );
369 return;
372 // Show Time
373 void showTime( TimeValue aTime )
375 TimeValue aLocalTimeVal, aSystemTimeVal , aSysTimeVal;
376 oslDateTime aDateTime, aSystemTime;
378 if ( osl_getLocalTimeFromSystemTime( &aTime, &aLocalTimeVal ) )
380 if ( osl_getDateTimeFromTimeValue( &aLocalTimeVal, &aDateTime ) )
382 printf("\t%02i.%02i.%4i , %02i.%02i.%02i Uhr\n", aDateTime.Day, aDateTime.Month, aDateTime.Year, aDateTime.Hours, aDateTime.Minutes, aDateTime.Seconds);
384 else
385 printf("Error !\n");
388 if ( osl_getDateTimeFromTimeValue( &aTime, &aSystemTime ) )
390 printf("SystemTime: \t\t%02i.%02i.%4i , %02i.%02i.%02i Uhr\n", aSystemTime.Day, aSystemTime.Month, aSystemTime.Year, aSystemTime.Hours, aSystemTime.Minutes, aSystemTime.Seconds);
392 else
393 printf("Error !\n");
395 //Verify
397 if ( osl_getTimeValueFromDateTime( &aSystemTime, &aSystemTimeVal ) )
399 if ( ( aSystemTimeVal.Seconds == aTime.Seconds ) && ( aSystemTimeVal.Nanosec == aTime.Nanosec ))
400 printf ("Verify : TimeValue : ok! \n");
401 else
403 printf ("Verify : TimeValue : Error! \n");
404 printf ("aTime : %u \n", aTime.Seconds);
405 printf ("aSystemTimeVal : %u \n", aSystemTimeVal.Seconds);
408 else
409 printf ("Verify : TimeValue : Error! \n");
412 if ( osl_getSystemTimeFromLocalTime( &aLocalTimeVal , &aSysTimeVal ) )
414 if ( ( aSysTimeVal.Seconds == aTime.Seconds ) && ( aSysTimeVal.Nanosec == aTime.Nanosec ))
415 printf ("Verify : SystemTime : ok! \n");
416 else
418 printf ("Verify : SystemTime : Error! \n");
419 printf ("aTime : %u\n", aTime.Seconds);
420 printf ("aSystemTimeVal : %u\n", aSysTimeVal.Seconds);
423 else
424 printf ("Verify : SystemTime : Error! \n");
426 return;
429 TimeValue getSystemTime()
431 TimeValue aTime;
432 time_t ltime;
434 time( &ltime );
436 aTime.Seconds = ltime;
437 aTime.Nanosec = 0;
439 return aTime;
443 //--------------------------------------------------
444 // DirectoryOpenAndCloseTest
445 //--------------------------------------------------
447 void DirectoryOpenAndCloseTest( void )
449 FileBase::RC rc;
450 Directory *pDir;
452 printf( "--------------------------------------------\n");
453 printf( "Directory-Open-And-Close-Test\n");
454 printf( "--------------------------------------------\n\n");
456 //--------------------------------------------------
457 // open an existing directory
458 //--------------------------------------------------
460 pDir=new Directory( dir1 );
461 printf( "Open an existing directory: ");
462 printFileName( dir1 );
463 printf( "\n" );
465 rc= pDir->open();
466 print_error( rtl::OString( "Open Directory" ), rc );
468 if ( pDir->isOpen() )
470 print_error( rtl::OString( "Directory is Open" ), rc );
473 // Close Directory
474 rc=pDir->close();
475 print_error( rtl::OString( "Close Directory" ), rc );
477 delete pDir;
478 printf( "\n" );
480 //--------------------------------------------------
481 // open a not existing directory
482 //--------------------------------------------------
484 pDir=new Directory( dir_not_exist );
486 printf( "Open a not existing directory: ");
487 printFileName( dir_not_exist );
488 printf( "\n" );
490 rc= pDir->open();
492 print_error( rtl::OString( "Open Directory" ), rc );
494 delete pDir;
496 printf( "\n" );
498 //--------------------------------------------------
499 // open a directory with a wrong semantic
500 //--------------------------------------------------
501 pDir=new Directory( dir_wrong_semantic );
503 printf( "Open a directory with a wrong semantic: ");
504 printFileName( dir_wrong_semantic );
505 printf( "\n" );
507 rc= pDir->open();
508 print_error( rtl::OString( "Open Directory" ), rc );
510 delete pDir;
512 printf( "\n" );
514 //--------------------------------------------------
515 // open an existing directory on a server
516 //--------------------------------------------------
518 pDir=new Directory( dir_on_server );
520 printf( "Open an existing directory on a server: ");
521 printFileName( dir_on_server );
522 printf( "\n" );
524 rc= pDir->open();
525 print_error( rtl::OString( "Open Directory" ), rc );
527 // Close Directory
528 rc=pDir->close();
529 print_error( rtl::OString( "Close Directory" ), rc );
531 delete pDir;
532 printf( "\n" );
534 //--------------------------------------------------
535 // open a not existing directory on a server
536 //--------------------------------------------------
538 pDir=new Directory( dir_not_exist_on_server );
540 printf( "Open a not existing directory on a server: ");
541 printFileName( dir_not_exist_on_server );
542 printf( "\n" );
544 rc= pDir->open();
545 print_error( rtl::OString( "Open Directory" ), rc );
547 delete pDir;
548 printf( "\n" );
550 //--------------------------------------------------
551 // Close a not existing directory
552 //--------------------------------------------------
554 pDir=new Directory( dir_not_exist );
555 printf( "Close a not existing directory: ");
556 printFileName( dir_not_exist );
557 printf( "\n" );
559 rc=pDir->close();
560 print_error( rtl::OString( "Close Directory" ), rc );
562 PressKey();
563 return;
567 //--------------------------------------------------
568 // DirectoryCreateAndRemoveTest
569 //--------------------------------------------------
571 void DirectoryCreateAndRemoveTest( void )
573 FileBase::RC rc,rc1;
574 Directory *pDir;
576 printf( "--------------------------------------------\n" );
577 printf( "Directory-Create-And-Remove-Test\n" );
578 printf( "--------------------------------------------\n\n" );
580 //--------------------------------------------------
581 // Create directory
582 //--------------------------------------------------
583 printf( "Create a not existing directory: ");
584 printFileName( dir_not_exist );
585 printf( "\n" );
587 rc=Directory::create( dir_not_exist) ;
588 print_error( rtl::OString( "Create Directory" ), rc );
590 // Verify
591 pDir=new Directory( dir_not_exist );
593 rc= pDir->open();
594 print_error( rtl::OString( "Verify" ), rc );
595 pDir->close();
596 delete pDir;
598 printf( "\n" );
600 //--------------------------------------------------
601 // Create a directory on a server
602 //--------------------------------------------------
604 printf( "Create a not existing directory on a server: ");
605 printFileName( dir_not_exist_on_server );
606 printf( "\n" );
608 rc=Directory::create( dir_not_exist_on_server );
609 print_error( rtl::OString( "Create Directory" ), rc );
611 // Verify
612 pDir=new Directory( dir_not_exist_on_server );
613 rc= pDir->open();
614 print_error( rtl::OString( "Verify" ), rc );
615 pDir->close();
616 delete pDir;
618 printf( "\n" );
620 //--------------------------------------------------
621 // Remove Directories
622 //--------------------------------------------------
624 printf( "Remove the created directories: \n" );
626 rc=Directory::remove( dir_not_exist );
628 rc1=Directory::remove( dir_not_exist_on_server );
630 if ( rc==FileBase::E_None && rc1==FileBase::E_None )
631 print_error( rtl::OString( "Remove Directories" ), FileBase::E_None );
632 else if ( rc!=FileBase::E_None )
633 print_error( rtl::OString( "Remove local Directory" ),rc );
634 else
635 print_error( rtl::OString( "Remove Directory on a server" ),rc1 );
637 printf( "\n" );
639 //--------------------------------------------------
640 // Remove a not existing directory
641 //--------------------------------------------------
643 printf( "Remove a not existing directory: ");
644 printFileName( dir_not_exist );
645 printf( "\n" );
647 rc=Directory::remove( dir_not_exist );
648 print_error( rtl::OString( "Remove" ),rc );
650 PressKey();
651 return;
654 //--------------------------------------------------
655 // FileOpenAndCloseTest
656 //--------------------------------------------------
658 static void FileOpenAndCloseTest( void )
660 FileBase::RC rc;
662 printf( "--------------------------------------------\n" );
663 printf( "File-Open-And-Close-Test\n" );
664 printf( "--------------------------------------------\n\n" );
666 File *pFile;
668 pFile=new File( file1 );
670 printf( "Open an existing file: ");
671 printFileName( file1 );
672 printf( "\n" );
674 //--------------------------------------------------
675 // open an existing file (Read)
676 //--------------------------------------------------
678 rc=pFile->open( osl_File_OpenFlag_Read );
679 print_error( rtl::OString( "Open File (Read)" ), rc );
681 //--------------------------------------------------
682 // close the file
683 //--------------------------------------------------
685 rc=pFile->close();
686 print_error( rtl::OString( "Close File" ), rc );
688 printf( "\n" );
690 //--------------------------------------------------
691 // open an existing file (Write)
692 //--------------------------------------------------
694 rc=pFile->open( osl_File_OpenFlag_Write );
695 print_error( rtl::OString( "Open File (Write)" ), rc );
697 //--------------------------------------------------
698 // close the file
699 //--------------------------------------------------
701 rc=pFile->close();
702 print_error( rtl::OString( "Close File" ), rc );
704 printf( "\n" );
706 //--------------------------------------------------
707 // close the file a second time
708 //--------------------------------------------------
710 rc=pFile->close();
711 print_error( rtl::OString( "Close the file a second time" ), rc );
713 delete pFile;
714 PressKey();
717 //--------------------------------------------------
718 // FileCreateAndRemoveTest
719 //--------------------------------------------------
721 void FileCreateAndRemoveTest()
723 FileBase::RC rc;
724 File *pFile;
726 printf( "--------------------------------------------\n" );
727 printf( "File-Create-And-Remove-Test\n" );
728 printf( "--------------------------------------------\n\n" );
730 pFile=new File( file_not_exist );
732 printf( "Create File: ");
733 printFileName( file_not_exist );
734 printf( "\n" );
736 //----------------------------------------------------
737 // open (create) a not existing file (Read and write)
738 //----------------------------------------------------
740 rc = pFile->open( osl_File_OpenFlag_Read | osl_File_OpenFlag_Write | osl_File_OpenFlag_Create );
742 print_error( rtl::OString( "Create and Open File (Read & Write)" ), rc );
744 //----------------------------------------------------
745 // close the file
746 //----------------------------------------------------
748 rc=pFile->close();
749 print_error( rtl::OString( "Close File" ), rc );
751 //----------------------------------------------------
752 // remove the file
753 //----------------------------------------------------
755 rc=pFile->remove( file_not_exist );
756 print_error( rtl::OString(" Remove File" ), rc );
758 printf( "\n" );
760 //----------------------------------------------------
761 // remove the same file a second time
762 //----------------------------------------------------
763 rc=pFile->remove( file_not_exist );
764 print_error( rtl::OString( "Remove a not existing File" ), rc );
766 //----------------------------------------------------
767 // remove an open file
768 //----------------------------------------------------
770 pFile->open( osl_File_OpenFlag_Read | osl_File_OpenFlag_Write | osl_File_OpenFlag_Create );
772 rc=pFile->remove( file_not_exist );
773 print_error( rtl::OString( "Remove an open File" ), rc );
775 pFile->close();
776 pFile->remove( file_not_exist );
778 PressKey();
780 return;
783 //--------------------------------------------------
784 // FileWriteAndReadTest
785 //--------------------------------------------------
787 void FileWriteAndReadTest( void )
789 FileBase::RC rc;
791 sal_uInt64 uWritten;
792 sal_uInt64 uRead;
793 const sal_Char *pWriteBuffer="Hier kommt der Osterhase !";
794 sal_uInt64 nLen=strlen( pWriteBuffer );
795 sal_Char *pReadBuffer;
797 printf( "--------------------------------------------\n" );
798 printf( "File-Write-And-Read-Test\n" );
799 printf( "--------------------------------------------\n\n" );
801 File *pFile;
803 pFile=new File( file_not_exist );
805 printf( "Create File: ");
806 printFileName( file_not_exist );
807 printf("\n");
809 //----------------------------------------------------
810 // open (create) a not existing file (Read and write)
811 //----------------------------------------------------
813 rc = pFile->open( osl_File_OpenFlag_Read | osl_File_OpenFlag_Write | osl_File_OpenFlag_Create );
815 print_error( rtl::OString( "Create and Open File (Read & Write)" ), rc );
817 printf( "\n" );
819 //----------------------------------------------------
820 // write a string to the file
821 //----------------------------------------------------
822 rc=pFile->write( pWriteBuffer , nLen , uWritten );
823 print_error( rtl::OString( "Write File" ), rc );
825 if(uWritten==nLen)
826 printf( "Verify: OK! \n" );
827 else
828 printf( "Verify: Error\n" );
830 printf( "\n" );
832 //----------------------------------------------------
833 // move the filepointer to the beginning
834 //----------------------------------------------------
836 rc=pFile->setPos( osl_Pos_Absolut , 0 );
837 print_error( rtl::OString( "Set FilePointer to the beginning of the file" ), rc );
839 printf( "\n" );
841 //----------------------------------------------------
842 // read the string
843 //----------------------------------------------------
845 pReadBuffer=(sal_Char*) rtl_allocateMemory( (sal_uInt32)(nLen+1)*sizeof(sal_Char) );
846 memset( pReadBuffer, 0, (sal_uInt32)(nLen+1)*sizeof(sal_Char) );
847 rc=pFile->read( pReadBuffer , nLen,uRead );
848 print_error( rtl::OString( "Read File" ), rc );
850 if (strcmp(pWriteBuffer, pReadBuffer)==0)
852 printf( "Verify: OK !\n" );
853 printf( "Text: %s\n",pReadBuffer );
855 else
856 printf( "Verify: Error\n" );
858 rtl_freeMemory( pReadBuffer );
860 printf( "\n" );
862 // close the file
863 rc=pFile->close();
864 print_error( rtl::OString( "Close File" ), rc );
866 // remove the file
867 rc=pFile->remove( file_not_exist );
868 print_error( rtl::OString( "Remove File" ), rc );
870 PressKey();
872 return;
876 //--------------------------------------------------
877 // FileCopyMoveTest
878 //--------------------------------------------------
880 void FileCopyAndMoveTest( void )
882 FileBase::RC rc;
884 printf( "--------------------------------------------\n" );
885 printf( "File-Copy-Move-Test\n" );
886 printf( "--------------------------------------------\n\n" );
889 File *pFile;
890 rtl::OUString destPath(dir2);
892 //--------------------------------------------------
893 // FileCopyTest
894 //--------------------------------------------------
896 destPath+=rtl::OUString("/");
897 destPath+=file3;
899 printf( "Copy the file ");
900 printFileName( file1 );
901 printf( " to ");
902 printFileName( destPath );
903 printf( "\n" );
906 rc=File::copy( file1 , destPath );
907 print_error( rtl::OString( "FileCopy" ), rc );
909 pFile=new File( destPath );
911 rc=pFile->open( osl_File_OpenFlag_Read );
912 if ( rc == FileBase::E_None)
914 printf( "Verify: OK!\n" );
915 pFile->close();
916 File::remove( destPath );
918 else
919 printf( "Verify: Error!\n" );
921 delete pFile;
923 printf( "\n" );
925 //--------------------------------------------------
926 // Copy a file to a not existing directory
927 //--------------------------------------------------
929 destPath=rtl::OUString( dir_not_exist );
930 destPath+=rtl::OUString("/");
931 destPath+=file3;
933 printf( "Copy a file to a not existing directory \n");
934 printf( "Copy the file %s to %s\n",
935 rtl::OUStringToOString( file1, RTL_TEXTENCODING_ASCII_US ).getStr(),
936 rtl::OUStringToOString( destPath, RTL_TEXTENCODING_ASCII_US ).getStr() );
938 rc=File::copy( file1, destPath );
939 print_error( rtl::OString( "FileCopy" ), rc );
941 printf( "\n" );
943 //--------------------------------------------------
944 // Copy a directory
945 //--------------------------------------------------
947 printf( "Copy the directory: ");
948 printFileName( dir1 );
949 printf( " to ");
950 printFileName( dir2 );
951 printf( "\n" );
953 rc=File::copy( dir1 , dir2 );
954 print_error( rtl::OString( "FileCopy" ), rc );
956 printf( "\n" );
958 //--------------------------------------------------
959 // FileMoveTest
960 //--------------------------------------------------
962 destPath=rtl::OUString( dir2 );
963 destPath+=rtl::OUString("/");
964 destPath+=file3;
966 printf( "Move the file ");
967 printFileName( file1 );
968 printf( " to ");
969 printFileName( destPath );
970 printf( "\n" );
972 rc=File::move( file1, destPath );
973 print_error( rtl::OString( "FileMove" ), rc );
975 pFile=new File( destPath );
977 rc=pFile->open( osl_File_OpenFlag_Read );
978 if ( rc==FileBase::E_None )
980 pFile->close();
982 delete pFile;
983 pFile=new File( file1 );
985 rc=pFile->open( osl_File_OpenFlag_Read );
987 if ( rc!=FileBase::E_None )
989 printf( "Verify: OK!\n" );
990 File::move( destPath, file1 );
992 else
994 printf( "Verify: Error!\n" );
995 pFile->close();
996 File::remove( destPath );
999 else
1000 printf( "Verify: Error!\n" );
1002 delete pFile;
1004 printf( "\n" );
1007 //--------------------------------------------------
1008 // Move a file to a not existing directory
1009 //--------------------------------------------------
1011 destPath=rtl::OUString( dir_not_exist );
1012 destPath+=rtl::OUString("/");
1013 destPath+=file3;
1015 printf( "Move a file to a not existing directory: \n");
1016 printf( "Move the file ");
1017 printFileName( file1 );
1018 printf( " to ");
1019 printFileName( destPath );
1020 printf( "\n" );
1022 rc=File::move( file1 , destPath );
1023 print_error( rtl::OString( "FileMove" ), rc );
1025 printf( "\n" );
1027 //--------------------------------------------------
1028 // Move a directory
1029 //--------------------------------------------------
1031 printf( "Move a directory: \n");
1033 printf( "Move the directory ");
1034 printFileName( dir1 );
1035 printf( " to ");
1036 printFileName( dir_not_exist );
1037 printf( "\n" );
1040 rc=File::move( dir1 , dir_not_exist);
1041 print_error( rtl::OString( "FileMove" ), rc );
1043 if ( rc == FileBase::E_None )
1044 File::move( dir_not_exist , dir1);
1046 printf( "\n" );
1049 PressKey();
1050 return;
1053 //----------------------------------------------------
1054 // FileSizeTest
1055 //----------------------------------------------------
1057 void FileSizeTest( void )
1059 FileBase::RC rc;
1060 sal_uInt64 filesize;
1061 DirectoryItem aItem;
1063 printf( "--------------------------------------------\n" );
1064 printf( "File-Size-Test\n" );
1065 printf( "--------------------------------------------\n\n" );
1068 File aFile( file_not_exist );
1070 printf( "Create File: ");
1071 printFileName( file_not_exist );
1072 printf( "\n\n");
1074 rc = aFile.open( osl_File_OpenFlag_Read | osl_File_OpenFlag_Write | osl_File_OpenFlag_Create );
1075 print_error( rtl::OString( "Create and Open File (Read & Write)" ), rc );
1076 printf( "\n" );
1078 if ( rc == FileBase::E_None )
1080 //----------------------------------------------------
1081 // Set Filesize to 5000
1082 //----------------------------------------------------
1084 printf( "Set FileSize to 5000\n" );
1085 rc=aFile.setSize( 5000 );
1086 print_error( rtl::OString( "Set FileSize" ), rc );
1088 printf( "\n" );
1089 printf( "Verify:\n" );
1091 //----------------------------------------------------
1092 // Check whether Filesize is set to 5000
1093 //----------------------------------------------------
1095 rc=DirectoryItem::get( file_not_exist, aItem );
1096 print_error( rtl::OString( "Get DirectoryItem" ), rc );
1098 if ( rc == FileBase::E_None )
1100 FileStatus rStatus( osl_FileStatus_Mask_FileSize );
1101 rc=aItem.getFileStatus( rStatus );
1102 print_error( rtl::OString( "Get FileStatus" ), rc );
1104 if ( rc == FileBase::E_None )
1106 filesize=rStatus.getFileSize();
1108 if ( filesize == 5000 )
1109 printf( "\nOK : FileSize: %" SAL_PRIuUINT64 "\n", filesize );
1110 else
1111 printf( "\nError : FileSize: %" SAL_PRIuUINT64 "\n", filesize );
1115 printf( "\n" );
1117 //----------------------------------------------------
1118 // Set Filesize to -1
1119 //----------------------------------------------------
1121 printf( "Set FileSize to -1\n" );
1122 rc=aFile.setSize( -1 );
1123 print_error( rtl::OString( "Set FileSize" ), rc );
1125 printf( "\n" );
1127 // close the file
1128 rc=aFile.close();
1129 print_error( rtl::OString( "Close File" ), rc );
1131 // remove the file
1132 rc=File::remove( file_not_exist );
1133 print_error( rtl::OString( "Remove File" ), rc );
1136 PressKey();
1138 return;
1142 //----------------------------------------------------
1143 // FilePointerTest
1144 //----------------------------------------------------
1146 void FilePointerTest( void )
1148 FileBase::RC rc;
1149 sal_uInt64 filepointer;
1151 printf( "--------------------------------------------\n" );
1152 printf( "File-Pointer-Test\n" );
1153 printf( "--------------------------------------------\n\n" );
1156 File rFile( file_not_exist );
1158 printf( "Create File: ");
1159 printFileName( file_not_exist );
1160 printf( "\n\n");
1162 rc = rFile.open( osl_File_OpenFlag_Read | osl_File_OpenFlag_Write | osl_File_OpenFlag_Create );
1163 print_error( rtl::OString( "Create and Open File (Read & Write) "), rc );
1164 printf( "\n" );
1166 if ( rc==FileBase::E_None )
1169 //----------------------------------------------------
1170 // get the position of the filepointer
1171 //----------------------------------------------------
1173 rc =rFile.getPos( filepointer );
1174 print_error( rtl::OString( "GetPos" ), rc );
1175 printf( "Position of the FilePointer: %" SAL_PRIuUINT64 "\n", filepointer );
1177 printf( "\n" );
1179 //----------------------------------------------------
1180 // set the filepointer at the end of a file
1181 //----------------------------------------------------
1183 printf( "Set FileSize to 5000\n" );
1184 rFile.setSize( 5000 );
1186 printf( "Set the FilePointer at the end of the file (5000)\n" );
1187 rc=rFile.setPos( osl_Pos_End,0 );
1188 print_error( rtl::OString( "SetPos" ), rc );
1190 rc=rFile.getPos( filepointer );
1192 if ( filepointer==5000 )
1194 print_error( rtl::OString( "GetPos" ), rc );
1195 printf( "\nVerify: OK !\n" );
1196 printf( "Filepointer-Position: %" SAL_PRIuUINT64 "\n",filepointer );
1198 else
1200 print_error( rtl::OString( "GetPos" ), rc );
1201 printf( "\nFilePointer-Test: Error\n" );
1202 printf( "Filepointer-Position: %" SAL_PRIuUINT64 " != 5000 \n",filepointer );
1205 printf( "\n" );
1207 // close the file
1208 rc=rFile.close();
1209 print_error( rtl::OString( "Close File" ), rc );
1211 // remove the file
1212 rc=File::remove( file_not_exist );
1213 print_error( rtl::OString( "Remove File" ), rc );
1216 PressKey();
1218 return;
1221 //--------------------------------------------------
1222 // FileAttributesTest
1223 //--------------------------------------------------
1225 void verifyFileAttributes( void )
1227 FileBase::RC rc;
1228 DirectoryItem aItem;
1229 FileStatus rStatus( osl_FileStatus_Mask_Attributes );
1231 printf( "\nVerify:\n" );
1233 rc=DirectoryItem::get( file1, aItem );
1235 if ( rc==FileBase::E_None )
1237 rc=aItem.getFileStatus( rStatus );
1239 if ( rc==FileBase::E_None )
1241 sal_uInt64 uAttributes=rStatus.getAttributes();
1242 showAttributes(uAttributes);
1243 printf( "\n" );
1245 else
1246 print_error( rtl::OString( "Get FileStatus" ), rc );
1248 else
1249 print_error( rtl::OString( "Get DirectoryItem" ), rc );
1251 return;
1254 #ifdef UNX
1255 void FileAttributesTest( void )
1257 FileBase::RC rc;
1259 printf( "--------------------------------------------\n" );
1260 printf( "File-Attributes-Test\n" );
1261 printf( "--------------------------------------------\n\n" );
1263 printf( "File: ");
1264 printFileName( file1 );
1265 printf( "\n\n" );
1268 rc=File::setAttributes( file1, osl_File_Attribute_GrpWrite );
1269 print_error( rtl::OString( "Set Attribute: GrpWrite" ), rc );
1271 verifyFileAttributes();
1273 rc=File::setAttributes( file1, 0 );
1274 if ( rc!=FileBase::E_None )
1275 print_error( rtl::OString( "Reset Attributes" ), rc );
1277 rc=File::setAttributes( file1, osl_File_Attribute_GrpRead );
1278 print_error( rtl::OString( "Set Attribute: GrpRead" ), rc );
1280 verifyFileAttributes();
1282 rc=File::setAttributes( file1, 0 );
1283 if ( rc!=FileBase::E_None )
1284 print_error( rtl::OString( "Reset Attributes" ), rc );
1286 rc=File::setAttributes( file1, osl_File_Attribute_GrpExe );
1287 print_error( rtl::OString( "Set Attribute: GrpExe" ), rc );
1289 verifyFileAttributes();
1291 rc=File::setAttributes( file1, 0 );
1292 if ( rc!=FileBase::E_None )
1293 print_error( rtl::OString( "Reset Attributes" ), rc );
1295 rc=File::setAttributes( file1, osl_File_Attribute_OwnWrite );
1296 print_error( rtl::OString( "Set Attribute: OwnWrite" ), rc );
1298 verifyFileAttributes();
1300 rc=File::setAttributes( file1, 0 );
1301 if ( rc!=FileBase::E_None )
1302 print_error( rtl::OString( "Reset Attributes" ), rc );
1304 rc=File::setAttributes( file1, osl_File_Attribute_OwnRead );
1305 print_error( rtl::OString( "Set Attribute: OwnRead" ), rc );
1307 verifyFileAttributes();
1309 rc=File::setAttributes( file1, 0 );
1310 if ( rc!=FileBase::E_None )
1311 print_error( rtl::OString( "Reset Attributes" ), rc );
1313 rc=File::setAttributes( file1, osl_File_Attribute_OwnExe );
1314 print_error( rtl::OString( "Set Attribute: OwnExe" ), rc );
1316 verifyFileAttributes();
1318 rc=File::setAttributes( file1, 0 );
1319 if ( rc!=FileBase::E_None )
1320 print_error( rtl::OString( "Reset Attributes" ), rc );
1322 rc=File::setAttributes( file1, osl_File_Attribute_OthWrite );
1323 print_error( rtl::OString( "Set Attribute: OthWrite" ), rc );
1325 verifyFileAttributes();
1327 rc=File::setAttributes( file1, 0 );
1328 if ( rc!=FileBase::E_None )
1329 print_error( rtl::OString( "Reset Attributes" ), rc );
1331 rc=File::setAttributes( file1, osl_File_Attribute_OthRead );
1332 print_error( rtl::OString( "Set Attribute: OthRead" ), rc );
1334 verifyFileAttributes();
1336 rc=File::setAttributes( file1, 0 );
1337 if ( rc!=FileBase::E_None )
1338 print_error( rtl::OString( "Reset Attributes" ), rc );
1340 rc=File::setAttributes( file1, osl_File_Attribute_OthExe );
1341 print_error( rtl::OString( "Set Attribute: OthExe" ), rc );
1343 verifyFileAttributes();
1345 rc=File::setAttributes( file1, 0 );
1346 if ( rc!=FileBase::E_None )
1347 print_error( rtl::OString( "Reset Attributes" ), rc );
1350 rc=File::setAttributes( file1, osl_File_Attribute_GrpWrite | osl_File_Attribute_GrpRead | osl_File_Attribute_GrpExe | osl_File_Attribute_OwnWrite | osl_File_Attribute_OwnRead | osl_File_Attribute_OwnExe | osl_File_Attribute_OthWrite | osl_File_Attribute_OthRead | osl_File_Attribute_OthExe );
1351 print_error( rtl::OString( "Set all Attributes" ), rc );
1353 verifyFileAttributes();
1355 PressKey();
1357 return;
1359 #endif
1361 #ifdef WNT
1362 void FileAttributesTest( void )
1364 FileBase::RC rc;
1366 printf( "--------------------------------------------\n" );
1367 printf( "File-Attributes-Test\n" );
1368 printf( "--------------------------------------------\n\n" );
1370 printf( "File: ");
1371 printFileName( file1 );
1372 printf( "\n\n" );
1375 rc=File::setAttributes( file1, osl_File_Attribute_ReadOnly );
1376 print_error( rtl::OString( "Set Attribute: ReadOnly" ), rc );
1378 verifyFileAttributes();
1380 rc=File::setAttributes( file1, 0 );
1381 print_error( rtl::OString( "Reset Attributes" ), rc );
1383 verifyFileAttributes();
1385 rc=File::setAttributes( file1, osl_File_Attribute_Hidden );
1386 print_error( rtl::OString( "Set Attribute: Hidden" ), rc );
1388 verifyFileAttributes();
1390 rc=File::setAttributes( file1, 0 );
1391 print_error( rtl::OString( "Reset Attributes" ), rc );
1393 verifyFileAttributes();
1395 rc=File::setAttributes( file1, osl_File_Attribute_Hidden | osl_File_Attribute_ReadOnly );
1396 print_error( rtl::OString( "Set Attribute: Hidden & ReadOnly" ), rc );
1398 verifyFileAttributes();
1400 rc=File::setAttributes( file1, 0 );
1401 print_error( rtl::OString( "Reset Attributes") , rc );
1403 verifyFileAttributes();
1405 PressKey();
1407 return;
1409 #endif
1411 //--------------------------------------------------
1412 // FileTimeTest
1413 //--------------------------------------------------
1415 void FileTimeTest( void )
1417 FileBase::RC rc;
1419 DirectoryItem aItem;
1421 struct tm sSysCreationTime;
1422 sSysCreationTime.tm_sec = 0;
1423 sSysCreationTime.tm_min = 20;
1424 sSysCreationTime.tm_hour = 12;
1425 sSysCreationTime.tm_mday = 4;
1426 sSysCreationTime.tm_mon = 9;
1427 sSysCreationTime.tm_year = 99;
1429 struct tm sSysAccessTime;
1430 sSysAccessTime.tm_sec = 0;
1431 sSysAccessTime.tm_min = 40;
1432 sSysAccessTime.tm_hour = 1;
1433 sSysAccessTime.tm_mday = 6;
1434 sSysAccessTime.tm_mon = 5;
1435 sSysAccessTime.tm_year = 98;
1437 struct tm sSysModifyTime;
1438 sSysModifyTime.tm_sec = 0;
1439 sSysModifyTime.tm_min = 1;
1440 sSysModifyTime.tm_hour = 24;
1441 sSysModifyTime.tm_mday = 13;
1442 sSysModifyTime.tm_mon = 11;
1443 sSysModifyTime.tm_year = 95;
1445 sal_uInt32 aSysCreationTime = mktime( &sSysCreationTime );
1446 sal_uInt32 aSysAccessTime = mktime( &sSysAccessTime );
1447 sal_uInt32 aSysModifyTime = mktime( &sSysModifyTime );
1449 TimeValue aCreationTime = { aSysCreationTime, 0};
1450 TimeValue aAccessTime = { aSysAccessTime, 0};
1451 TimeValue aModifyTime = { aSysModifyTime, 0};
1453 TimeValue aCreationTimeRead;
1454 TimeValue aAccessTimeRead;
1455 TimeValue aModifyTimeRead;
1458 printf( "--------------------------------------------\n" );
1459 printf( "File-Time-Test\n" );
1460 printf( "--------------------------------------------\n\n" );
1462 printf( "File: ");
1463 printFileName( file1 );
1464 printf( "\n\n" );
1466 printf( "CreationTime \t : ");
1467 showTime( aCreationTime );
1469 printf( "\nAccessTime \t : ");
1470 showTime( aAccessTime );
1472 printf( "\nModifyTime \t : ");
1473 showTime( aModifyTime );
1475 //--------------------------------------------------
1476 // setTime
1477 //--------------------------------------------------
1479 printf( "\n" );
1480 rc=File::setTime( file1 , aCreationTime , aAccessTime , aModifyTime );
1481 print_error( rtl::OString( "SetTime" ), rc );
1483 //--------------------------------------------------
1484 // Verify
1485 //--------------------------------------------------
1487 FileStatus rStatus( osl_FileStatus_Mask_CreationTime | osl_FileStatus_Mask_AccessTime | osl_FileStatus_Mask_ModifyTime);
1489 printf( "\nVerify:\n" );
1491 rc=DirectoryItem::get( file1, aItem );
1492 print_error( rtl::OString( "Get DirectoryItem" ), rc );
1494 if ( rc==FileBase::E_None )
1496 rc=aItem.getFileStatus( rStatus );
1497 print_error( rtl::OString( "Get FileStatus" ), rc );
1498 printf( "\n" );
1500 if ( rc==FileBase::E_None )
1502 //--------------------------------------------------
1503 // GetCreationTime
1504 //--------------------------------------------------
1506 aCreationTimeRead=rStatus.getCreationTime();
1507 #ifdef WNT
1508 if ( aCreationTime.Seconds == aCreationTimeRead.Seconds && aCreationTime.Nanosec == aCreationTimeRead.Nanosec )
1509 printf( "GetCreationTime: ok : " );
1510 else
1511 printf( "GetCreationTime: Error : " );
1513 showTime( aCreationTimeRead );
1514 printf( "\n" );
1515 #endif
1516 //--------------------------------------------------
1517 // GetAccessTime
1518 //--------------------------------------------------
1520 aAccessTimeRead=rStatus.getAccessTime();
1522 if ( aAccessTime.Seconds == aAccessTimeRead.Seconds && aAccessTime.Nanosec == aAccessTimeRead.Nanosec )
1523 printf( "GetAccessTime: ok : " );
1524 else
1525 printf( "GetAccessTime: Error : " );
1527 showTime( aAccessTimeRead );
1528 printf( "\n" );
1530 //--------------------------------------------------
1531 // GetModifyTime
1532 //--------------------------------------------------
1534 aModifyTimeRead=rStatus.getModifyTime();
1536 if ( aModifyTime.Seconds == aModifyTimeRead.Seconds && aModifyTime.Nanosec == aModifyTimeRead.Nanosec )
1537 printf( "GetModifyTime: ok : " );
1538 else
1539 printf( "GetModifyTime: Error : " );
1541 showTime( aModifyTimeRead );
1542 printf( "\n" );
1546 PressKey();
1547 return;
1551 //--------------------------------------------------
1552 // DirectoryItemTest
1553 //--------------------------------------------------
1555 void DirectoryItemTest( void )
1557 FileBase::RC rc;
1558 Directory *pDir;
1559 DirectoryItem aItem;
1560 FileStatus *pStatus;
1561 File *pFile;
1563 printf( "--------------------------------------------\n" );
1564 printf( "Directory-Item-Test\n" );
1565 printf( "--------------------------------------------\n\n" );
1567 //--------------------------------------------------
1568 // get DirectoryItem from an existing directory
1569 //--------------------------------------------------
1571 printf( "Get DirectoryItem from an existing Directory: ");
1572 printFileName( dir1 );
1573 printf( "\n");
1575 rc=DirectoryItem::get( dir1 , aItem );
1576 print_error( rtl::OString( "GetDirectoryItem" ), rc );
1578 pStatus=new FileStatus( osl_FileStatus_Mask_All );
1579 rc=aItem.getFileStatus( *pStatus );
1581 if ( rc==FileBase::E_None )
1583 printf( "GetFileStatus: FileURL: ");
1584 printFileName(pStatus->getFileURL() );
1585 printf( "\n" );
1588 delete pStatus;
1590 printf( "\n" );
1592 //--------------------------------------------------
1593 // get DirectoryItem from a not existing directory
1594 //--------------------------------------------------
1596 printf( "Get DirectoryItem from a not existing Directory: ");
1597 printFileName( dir_not_exist );
1598 printf( "\n" );
1600 rc=DirectoryItem::get( dir_not_exist , aItem );
1601 print_error( rtl::OString( "Get DirectoryItem" ), rc );
1603 printf( "\n" );
1605 //--------------------------------------------------
1606 // get DirectoryItem from an existing file
1607 //--------------------------------------------------
1609 printf( "Get DirectoryItem from an existing File: ");
1610 printFileName( file1 );
1611 printf( "\n" );
1613 rc=DirectoryItem::get( file1 , aItem );
1614 print_error( rtl::OString( "GetDirectoryItem" ), rc );
1616 pStatus=new FileStatus( osl_FileStatus_Mask_All );
1617 rc=aItem.getFileStatus( *pStatus );
1619 if ( rc==FileBase::E_None )
1621 printf( "GetFileStatus: FileURL: ");
1622 printFileName( pStatus->getFileURL() );
1623 printf( "\n" );
1626 delete pStatus;
1628 printf( "\n" );
1630 //--------------------------------------------------
1631 // get DirectoryItem from a not existing file
1632 //--------------------------------------------------
1634 printf( "Get DirectoryItem from a not existing File: ");
1635 printFileName( file_not_exist );
1636 printf( "\n" );
1638 rc=DirectoryItem::get( file_not_exist , aItem );
1639 print_error( rtl::OString( "Get DirectoryItem" ), rc );
1641 printf( "\n" );
1643 //----------------------------------------------------------
1644 // get DirectoryItem from a directory with a wrong semantic
1645 //----------------------------------------------------------
1647 printf( "Get DirectoryItem from a Directory with a wrong semantic: ");
1648 printFileName( dir_not_exist );
1649 printf( "\n" );
1651 rc=DirectoryItem::get( dir_wrong_semantic, aItem );
1652 print_error( rtl::OString( "Get DirectoryItem" ),rc );
1654 printf( "\n" );
1656 //---------------------------------------------------
1657 // get DirectoryItem from a file-handle
1658 //--------------------------------------------------
1660 pFile=new File( file1 );
1662 rc=pFile->open( osl_File_OpenFlag_Read );
1663 if ( rc==FileBase::E_None )
1665 printf( "Get DirectoryItem from a File-Handle: ");
1666 printFileName( file1 );
1667 printf( "\n" );
1669 rc=DirectoryItem::get( file1 , aItem );
1670 print_error( rtl::OString( "GetDirectoryItem" ), rc );
1672 pStatus=new FileStatus( osl_FileStatus_Mask_All );
1673 rc=aItem.getFileStatus( *pStatus );
1675 if ( rc==FileBase::E_None )
1677 printf( "GetFileStatus: FileURL: ");
1678 printFileName( pStatus->getFileURL() );
1679 printf( "\n");
1682 delete pStatus;
1684 pFile->close();
1687 delete pFile;
1689 printf( "\n" );
1691 //---------------------------------------------------
1692 // get DirectoryItem
1693 //--------------------------------------------------
1695 printf( "Get DirectoryItem from an empty File-Handle\n" );
1696 rc=DirectoryItem::get( file1 , aItem );
1697 print_error( rtl::OString( "GetDirectoryItem" ), rc );
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( osl_FileStatus_Mask_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( osl_FileStatus_Mask_All );
1757 aItem.getFileStatus( rStatus );
1759 str1[i]=rStatus.getFileName();
1763 if ( str1[0] == str1[1] )
1764 print_error( rtl::OString( "Reset" ),FileBase::E_None );
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: %" SAL_PRIuUINT64 "\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( osl_FileStatus_Mask_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( osl_FileStatus_Mask_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( osl_FileStatus_Mask_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( osl_VolumeInfo_Mask_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: %" SAL_PRIuUINT64 "\n",TotalSpace );
2077 //--------------------------------------------------
2078 // getFreeSpace
2079 //--------------------------------------------------
2081 sal_uInt64 FreeSpace;
2082 FreeSpace=rInfo.getFreeSpace();
2083 printf( "Free Space: %" SAL_PRIuUINT64 "\n",FreeSpace );
2085 //--------------------------------------------------
2086 // getUsedSpace
2087 //--------------------------------------------------
2089 sal_uInt64 UsedSpace;
2090 UsedSpace=rInfo.getUsedSpace();
2091 printf( "Used Space: %" SAL_PRIuUINT64 "\n",UsedSpace );
2093 //--------------------------------------------------
2094 // getMaxNameLength
2095 //--------------------------------------------------
2097 sal_uInt32 MaxNameLength;
2098 MaxNameLength=rInfo.getMaxNameLength();
2099 printf( "MaxNameLength: %" SAL_PRIuUINT32 "\n",MaxNameLength );
2101 //--------------------------------------------------
2102 // getMaxPathLength
2103 //--------------------------------------------------
2105 sal_uInt32 MaxPathLength;
2106 MaxPathLength=rInfo.getMaxPathLength();
2107 printf( "MaxPathLength: %" SAL_PRIuUINT32 "\n",MaxPathLength );
2109 //--------------------------------------------------
2110 // getFileSystemName
2111 //--------------------------------------------------
2113 rtl::OUString FileSystemName;
2114 FileSystemName=rInfo.getFileSystemName();
2115 printf( "File-System-Name: ");
2116 printFileName( FileSystemName );
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.isEmpty() )
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.isEmpty() )
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.isEmpty() )
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("."));
2293 DoAbsolutePathTest(dir1, rtl::OUString(".."));
2294 DoAbsolutePathTest(dir1, rtl::OUString("../.."));
2295 DoAbsolutePathTest(dir1, rtl::OUString("../HUHU"));
2297 DoAbsolutePathTest(dir_on_server, rtl::OUString("."));
2298 DoAbsolutePathTest(dir_on_server, rtl::OUString(".."));
2299 DoAbsolutePathTest(dir_on_server, rtl::OUString("../.."));
2300 DoAbsolutePathTest(dir_on_server, rtl::OUString("../HUHU"));
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.isEmpty() )
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.isEmpty() )
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.isEmpty() )
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("") , 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(";");
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( const ::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;
2790 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */