xref: /AOO41X/main/sal/workben/testfile.cxx (revision 87d2adbc9cadf14644c3679b041b9226f7630199)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sal.hxx"
26 
27 #define UNICODE
28 
29 
30 #include <osl/file.hxx>
31 #include <osl/process.h>
32 #include <osl/time.h>
33 #include <rtl/alloc.h>
34 #include <rtl/ustring.hxx>
35 #include <stdio.h>
36 #include <string.h>
37 #include <time.h>
38 
39 
40 #ifdef UNX
41 #include <wchar.h>
42 #endif
43 
44 #ifdef WNT
45 #include <windows.h>
46 #endif
47 
48 using namespace osl;
49 using namespace rtl;
50 
51 #define MAXIMPATH   256
52 
53 rtl::OUString   root;
54 
55 rtl::OUString   dir1;
56 rtl::OUString   dir2;
57 rtl::OUString   dir_on_server;
58 rtl::OUString   dir_not_exist;
59 rtl::OUString   dir_not_exist_on_server;
60 rtl::OUString   dir_wrong_semantic;
61 
62 rtl::OUString   file1;
63 rtl::OUString   file2;
64 rtl::OUString   file3;
65 rtl::OUString   file_on_server;
66 rtl::OUString   file_not_exist;
67 
68 
69 
70 void print_error(::rtl::OString& str, FileBase::RC rc);
71 
PressKey()72 void PressKey()
73 {
74     printf("\nPress Return !\n");
75     int i=getchar();
76 }
77 
printFileName(::rtl::OUString & str)78 void printFileName(::rtl::OUString& str)
79 {
80     rtl::OString        aString;
81 
82     aString = rtl::OUStringToOString( str, RTL_TEXTENCODING_ASCII_US );
83 
84     printf( "%s", aString.getStr() );
85 
86     return;
87 }
88 
89 //--------------------------------------------------
90 // Initialization
91 //--------------------------------------------------
92 
testLineBreak(sal_Char * pCount,sal_uInt64 nLen,sal_uInt32 * cLineBreak)93 sal_Bool testLineBreak( sal_Char *pCount , sal_uInt64 nLen , sal_uInt32 *cLineBreak )
94 {
95     sal_Bool fSuccess=sal_False;
96     *cLineBreak=0;
97 
98     if (nLen==0)
99         return fSuccess;
100 
101     if ( *pCount==13 )
102     {
103         if (nLen>=1 && *(pCount+1)==10)
104             *cLineBreak=2;
105         else
106             *cLineBreak=1;
107 
108         if (nLen>=2 && *(pCount+2)==10)
109             (*cLineBreak)++;
110 
111         fSuccess=sal_True;
112     }
113     else if ( *pCount==10 )
114     {
115         *cLineBreak=1;
116         fSuccess=sal_True;
117     }
118 
119     return fSuccess;
120 }
121 
122 // Initialization
123 
Initialize(void)124 sal_Bool Initialize( void )
125 {
126     DirectoryItem   aItem;
127     FileStatus      aStatus( FileStatusMask_All );
128     rtl_uString     *strExeFileURL=NULL;
129     oslProcessError ProcessError;
130 
131     rtl::OUString   iniFileURL;
132     File            *pFile;
133     sal_Unicode     *pExeFileCount;
134 
135     FileBase::RC    rc;
136 
137     sal_uInt64      uBytesRequested;
138     sal_uInt64      uBytesRead;
139     sal_Char        *pBuffer;
140     sal_Char        *pBegin;
141     sal_Char        *pCount;
142 
143     rtl::OUString   dir[12];
144 
145     // Open to the ini-file
146 
147     ProcessError=osl_getExecutableFile(&strExeFileURL);
148 
149     if ( ProcessError == osl_Process_E_None)
150     {
151         pExeFileCount=rtl_uString_getStr(strExeFileURL)+rtl_uString_getLength(strExeFileURL);
152 
153         // Search for the last slash in the Path
154         while (*pExeFileCount!=L'/' && pExeFileCount>rtl_uString_getStr(strExeFileURL))
155             pExeFileCount--;
156 
157         // iniFileURL = strExeFileURL without the filename of the exe-File
158         iniFileURL=rtl::OUString( rtl_uString_getStr(strExeFileURL) ,(int) (pExeFileCount-rtl_uString_getStr(strExeFileURL)) );
159 
160         // add "/testfile.ini" to iniFileURL
161         iniFileURL+=rtl::OUString::createFromAscii("/testfile.ini");
162 
163         // Open the ini-File
164         pFile=new File( iniFileURL );
165         rc=pFile->open( OpenFlag_Read | OpenFlag_Write );
166         if ( rc!=FileBase::E_None )
167         {
168             rtl_uString_release(strExeFileURL);
169             return sal_False;
170         }
171     }
172     else
173     {
174         rtl_uString_release(strExeFileURL);
175         return sal_False;
176     }
177 
178     // Get filesize of the ini-File
179 
180     rc=DirectoryItem::get( iniFileURL, aItem );
181     if ( rc!=FileBase::E_None )
182         return sal_False;
183 
184     rc=aItem.getFileStatus( aStatus );
185     if ( rc!=FileBase::E_None )
186         return sal_False;
187 
188     uBytesRequested=aStatus.getFileSize();
189 
190     // read ini-File
191     rc=pFile->setPos( Pos_Absolut, 0 );
192     pBuffer=(sal_Char*) rtl_allocateMemory( (sal_uInt32) (uBytesRequested+1)*sizeof(sal_Char) );
193     rtl_zeroMemory( pBuffer, (sal_uInt32)(uBytesRequested+1)*sizeof(sal_Char) );
194 
195     rc=pFile->read( pBuffer , uBytesRequested , uBytesRead );
196     if ( rc!=FileBase::E_None )
197         return sal_False;
198 
199 
200     pBegin=pBuffer;
201     pCount=pBegin;
202 
203     for ( int i=0 ; i<12 ; i++ )
204     {
205         sal_uInt32      cLineBrake=0;
206         while ( (pCount-pBuffer < uBytesRead) && *pCount!='=')
207             pCount++;
208 
209         pCount++;
210         pBegin=pCount;
211 
212         while ( (pCount-pBuffer < uBytesRead) && !testLineBreak(pCount,uBytesRead-(pCount-pBuffer), &cLineBrake))
213             pCount++;
214 
215         dir[i]=rtl::OUString(pBegin, pCount-pBegin, RTL_TEXTENCODING_ASCII_US);
216 
217         pCount+=cLineBrake;
218         pBegin=pCount;
219     }
220 
221     root=rtl::OUString(dir[0]);
222     dir1=rtl::OUString(dir[1]);
223     dir2=rtl::OUString(dir[2]);
224     dir_on_server=rtl::OUString(dir[3]);
225     dir_not_exist=rtl::OUString(dir[4]);
226     dir_not_exist_on_server=rtl::OUString(dir[5]);
227     dir_wrong_semantic=rtl::OUString(dir[6]);
228 
229     file1=rtl::OUString(dir[7]);
230     file2=rtl::OUString(dir[8]);
231     file3=rtl::OUString(dir[9]);
232     file_on_server=rtl::OUString(dir[10]);
233     file_not_exist=rtl::OUString(dir[11]);
234 
235     // close the ini-file
236     rc=pFile->close();
237 
238     rtl_freeMemory( pBuffer );
239 
240 
241     // Create directories
242     rc=Directory::create( dir1 );
243     if ( rc!=FileBase::E_None )
244         return sal_False;
245 
246     rc=Directory::create( dir2 );
247     if ( rc!=FileBase::E_None )
248         return sal_False;
249 
250     rc=Directory::create( dir_on_server );
251     if ( rc!=FileBase::E_None )
252         return sal_False;
253 
254     pFile=new File( file1 );
255     rc=pFile->open( OpenFlag_Write | OpenFlag_Create );
256     if ( rc!=FileBase::E_None )
257         return sal_False;
258     rc=pFile->close();
259     delete pFile;
260 
261     pFile=new File( file2 );
262     rc=pFile->open( OpenFlag_Write | OpenFlag_Create );
263     if ( rc!=FileBase::E_None )
264         return sal_False;
265     rc=pFile->close();
266     delete pFile;
267 
268     pFile=new File( file_on_server );
269     rc=pFile->open( OpenFlag_Write | OpenFlag_Create );
270     if ( rc!=FileBase::E_None )
271         return sal_False;
272     rc=pFile->close();
273     delete pFile;
274 
275     return sal_True;
276 }
277 
278 //--------------------------------------------------
279 // Shutdown
280 //--------------------------------------------------
281 
Shutdown(void)282 sal_Bool Shutdown( void )
283 {
284     sal_Bool        fSuccess=sal_True;
285     FileBase::RC    rc;
286     File            *pFile;
287 
288     // remove created files
289 
290     pFile=new File( file1 );
291     rc=pFile->remove( file1 );
292     if ( rc!=FileBase::E_None )
293         fSuccess=sal_False;
294     delete pFile;
295 
296     pFile=new File( file2 );
297     rc=pFile->remove( file2 );
298     if ( rc!=FileBase::E_None )
299         fSuccess=sal_False;
300     delete pFile;
301 
302     // remove created directories
303 
304     rc=Directory::remove( dir1 );
305     if ( rc!=FileBase::E_None )
306         fSuccess=sal_False;
307 
308     rc=Directory::remove( dir2 );
309     if ( rc!=FileBase::E_None )
310         fSuccess=sal_False;
311 
312     // remove created file on the server
313 
314     pFile=new File( file_on_server );
315     rc=pFile->remove( file_on_server );
316     if ( rc!=FileBase::E_None )
317         fSuccess=sal_False;
318     delete pFile;
319 
320     // remove created directory on the server
321 
322     rc=Directory::remove( dir_on_server );
323     if ( rc!=FileBase::E_None )
324         fSuccess=sal_False;
325 
326     return fSuccess;
327 }
328 
329 //--------------------------------------------------
330 // helper functions
331 //--------------------------------------------------
332 
333 // Show FileType
showFileType(FileStatus::Type aType)334 void showFileType( FileStatus::Type aType )
335 {
336     if ( aType==FileStatus::Directory )
337         printf( "FileType: Directory \n" );
338     else if ( aType==FileStatus::Volume )
339         printf( "FileType: Volume \n" );
340     else if ( aType==FileStatus::Regular )
341         printf( "FileType: Regular \n" );
342     else if ( aType==FileStatus::Unknown )
343         printf( "FileType: Unknown \n" );
344 
345 }
346 
347 // Show Attributes
showAttributes(sal_uInt64 uAttributes)348 void showAttributes( sal_uInt64 uAttributes )
349 {
350     if ( uAttributes==0 )
351         printf( "No Attributes \n" );
352     if ( uAttributes & Attribute_ReadOnly )
353         printf( "Attribute: ReadOnly \n" );
354     if ( uAttributes & Attribute_Hidden )
355         printf( "Attribute: Hidden \n" );
356     if ( uAttributes & Attribute_Executable )
357         printf( "Attribute: Executable \n");
358     if ( uAttributes & Attribute_GrpWrite )
359         printf( "Attribute: GrpWrite \n");
360     if ( uAttributes & Attribute_GrpRead )
361         printf( "Attribute: GrpRead \n" );
362     if ( uAttributes & Attribute_GrpExe )
363         printf( "Attribute: GrpExe \n" );
364     if ( uAttributes & Attribute_OwnWrite )
365         printf( "Attribute: OwnWrite \n");
366     if ( uAttributes & Attribute_OwnRead )
367         printf( "Attribute: OwnRead \n" );
368     if ( uAttributes & Attribute_OwnExe )
369         printf( "Attribute: OwnExe \n" );
370     if ( uAttributes & Attribute_OthWrite )
371         printf( "Attribute: OthWrite \n" );
372     if ( uAttributes & Attribute_OthRead )
373         printf( "Attribute: OthRead \n");
374     if ( uAttributes & Attribute_OthExe )
375         printf( "Attribute: OthExe \n" );
376 
377     return;
378 }
379 
380 // Show Time
showTime(TimeValue aTime)381 void showTime( TimeValue aTime )
382 {
383     TimeValue   aLocalTimeVal, aSystemTimeVal , aSysTimeVal;
384     oslDateTime aDateTime, aSystemTime;
385 
386     if ( osl_getLocalTimeFromSystemTime( &aTime, &aLocalTimeVal ) )
387     {
388         if ( osl_getDateTimeFromTimeValue( &aLocalTimeVal, &aDateTime ) )
389         {
390             printf("\t%02i.%02i.%4i , %02i.%02i.%02i Uhr\n", aDateTime.Day, aDateTime.Month, aDateTime.Year, aDateTime.Hours, aDateTime.Minutes, aDateTime.Seconds);
391         }
392         else
393             printf("Error !\n");
394     }
395 
396     if ( osl_getDateTimeFromTimeValue( &aTime, &aSystemTime ) )
397     {
398         printf("SystemTime: \t\t%02i.%02i.%4i , %02i.%02i.%02i Uhr\n", aSystemTime.Day, aSystemTime.Month, aSystemTime.Year, aSystemTime.Hours, aSystemTime.Minutes, aSystemTime.Seconds);
399     }
400     else
401         printf("Error !\n");
402 
403     //Verify
404 
405     if ( osl_getTimeValueFromDateTime( &aSystemTime, &aSystemTimeVal ) )
406     {
407         if ( ( aSystemTimeVal.Seconds == aTime.Seconds ) && ( aSystemTimeVal.Nanosec == aTime.Nanosec ))
408             printf ("Verify : TimeValue : ok! \n");
409         else
410         {
411             printf ("Verify : TimeValue : Error! \n");
412             printf ("aTime : %u \n", aTime.Seconds);
413             printf ("aSystemTimeVal : %u \n", aSystemTimeVal.Seconds);
414         }
415     }
416     else
417         printf ("Verify : TimeValue : Error! \n");
418 
419 
420     if ( osl_getSystemTimeFromLocalTime( &aLocalTimeVal , &aSysTimeVal ) )
421     {
422         if ( ( aSysTimeVal.Seconds == aTime.Seconds ) && ( aSysTimeVal.Nanosec == aTime.Nanosec ))
423             printf ("Verify : SystemTime : ok! \n");
424         else
425         {
426             printf ("Verify : SystemTime : Error! \n");
427             printf ("aTime : %u\n", aTime.Seconds);
428             printf ("aSystemTimeVal : %u\n", aSysTimeVal.Seconds);
429         }
430     }
431     else
432         printf ("Verify : SystemTime : Error! \n");
433 
434     return;
435 }
436 
getSystemTime()437 TimeValue getSystemTime()
438 {
439     TimeValue   aTime;
440     time_t ltime;
441 
442     time( &ltime );
443 
444     aTime.Seconds = ltime;
445     aTime.Nanosec = 0;
446 
447     return aTime;
448 }
449 
450 
451 //--------------------------------------------------
452 // DirectoryOpenAndCloseTest
453 //--------------------------------------------------
454 
DirectoryOpenAndCloseTest(void)455 void DirectoryOpenAndCloseTest( void )
456 {
457     FileBase::RC    rc;
458     int i=0;
459     Directory   *pDir;
460 
461     printf( "--------------------------------------------\n");
462     printf( "Directory-Open-And-Close-Test\n");
463     printf( "--------------------------------------------\n\n");
464 
465     //--------------------------------------------------
466     // open an existing directory
467     //--------------------------------------------------
468 
469     pDir=new Directory( dir1 );
470     printf( "Open an existing directory: ");
471     printFileName( dir1 );
472     printf( "\n" );
473 
474     rc= pDir->open();
475     print_error( rtl::OString( "Open Directory" ), rc );
476 
477     if ( pDir->isOpen() )
478     {
479         print_error( rtl::OString( "Directory is Open" ), rc );
480     }
481 
482     // Close Directory
483     rc=pDir->close();
484     print_error( rtl::OString( "Close Directory" ), rc );
485 
486     delete pDir;
487     printf( "\n" );
488 
489     //--------------------------------------------------
490     // open a not existing directory
491     //--------------------------------------------------
492 
493     pDir=new Directory( dir_not_exist );
494 
495     printf( "Open a not existing directory: ");
496     printFileName( dir_not_exist );
497     printf( "\n" );
498 
499     rc= pDir->open();
500 
501     print_error( rtl::OString( "Open Directory" ), rc );
502 
503     delete pDir;
504 
505     printf( "\n" );
506 
507     //--------------------------------------------------
508     // open a directory with a wrong semantic
509     //--------------------------------------------------
510     pDir=new Directory( dir_wrong_semantic );
511 
512     printf( "Open a directory with a wrong semantic: ");
513     printFileName( dir_wrong_semantic );
514     printf( "\n" );
515 
516     rc= pDir->open();
517     print_error( rtl::OString( "Open Directory" ), rc );
518 
519     delete pDir;
520 
521     printf( "\n" );
522 
523     //--------------------------------------------------
524     // open an existing directory on a server
525     //--------------------------------------------------
526 
527     pDir=new Directory( dir_on_server );
528 
529     printf( "Open an existing directory on a server: ");
530     printFileName( dir_on_server );
531     printf( "\n" );
532 
533     rc= pDir->open();
534     print_error( rtl::OString( "Open Directory" ), rc );
535 
536     // Close Directory
537     rc=pDir->close();
538     print_error( rtl::OString( "Close Directory" ), rc );
539 
540     delete pDir;
541     printf( "\n" );
542 
543     //--------------------------------------------------
544     // open a not existing directory on a server
545     //--------------------------------------------------
546 
547     pDir=new Directory( dir_not_exist_on_server );
548 
549     printf( "Open a not existing directory on a server: ");
550     printFileName( dir_not_exist_on_server );
551     printf( "\n" );
552 
553     rc= pDir->open();
554     print_error( rtl::OString( "Open Directory" ), rc );
555 
556     delete pDir;
557     printf( "\n" );
558 
559     //--------------------------------------------------
560     // Close a not existing directory
561     //--------------------------------------------------
562 
563     pDir=new Directory( dir_not_exist );
564     printf( "Close a not existing directory: ");
565     printFileName( dir_not_exist );
566     printf( "\n" );
567 
568     rc=pDir->close();
569     print_error( rtl::OString( "Close Directory" ), rc );
570 
571     PressKey();
572     return;
573 
574 }
575 
576 //--------------------------------------------------
577 // DirectoryCreateAndRemoveTest
578 //--------------------------------------------------
579 
DirectoryCreateAndRemoveTest(void)580 void DirectoryCreateAndRemoveTest( void )
581 {
582     FileBase::RC    rc,rc1;
583     int i=0;
584     Directory   *pDir;
585 
586     printf( "--------------------------------------------\n" );
587     printf( "Directory-Create-And-Remove-Test\n" );
588     printf( "--------------------------------------------\n\n" );
589 
590     //--------------------------------------------------
591     // Create directory
592     //--------------------------------------------------
593     printf( "Create a not existing directory: ");
594     printFileName( dir_not_exist );
595     printf( "\n" );
596 
597     rc=Directory::create( dir_not_exist) ;
598     print_error( rtl::OString( "Create Directory" ), rc );
599 
600     // Verify
601     pDir=new Directory( dir_not_exist );
602 
603     rc= pDir->open();
604     print_error( rtl::OString( "Verify" ), rc );
605     pDir->close();
606     delete pDir;
607 
608     printf( "\n" );
609 
610     //--------------------------------------------------
611     // Create a directory on a server
612     //--------------------------------------------------
613 
614     printf( "Create a not existing directory on a server: ");
615     printFileName( dir_not_exist_on_server );
616     printf( "\n" );
617 
618     rc=Directory::create( dir_not_exist_on_server );
619     print_error( rtl::OString( "Create Directory" ), rc );
620 
621     // Verify
622     pDir=new Directory( dir_not_exist_on_server );
623     rc= pDir->open();
624     print_error( rtl::OString( "Verify" ), rc );
625     pDir->close();
626     delete pDir;
627 
628     printf( "\n" );
629 
630     //--------------------------------------------------
631     // Remove Directories
632     //--------------------------------------------------
633 
634     printf( "Remove the created directories: \n" );
635 
636     rc=Directory::remove( dir_not_exist );
637 
638     rc1=Directory::remove( dir_not_exist_on_server );
639 
640     if ( rc==FileBase::E_None && rc1==FileBase::E_None )
641         print_error( rtl::OString( "Remove Directories" ), FileBase::E_None );
642     else if ( rc!=FileBase::E_None )
643         print_error( rtl::OString( "Remove local Directory" ),rc );
644     else
645         print_error( rtl::OString( "Remove Directory on a server" ),rc1 );
646 
647     printf( "\n" );
648 
649     //--------------------------------------------------
650     // Remove a not existing directory
651     //--------------------------------------------------
652 
653     printf( "Remove a not existing directory: ");
654     printFileName( dir_not_exist );
655     printf( "\n" );
656 
657     rc=Directory::remove( dir_not_exist );
658     print_error( rtl::OString( "Remove" ),rc );
659 
660     PressKey();
661     return;
662 }
663 
664 //--------------------------------------------------
665 // FileOpenAndCloseTest
666 //--------------------------------------------------
667 
FileOpenAndCloseTest(void)668 static void FileOpenAndCloseTest( void )
669 {
670     FileBase::RC    rc;
671     int i=0;
672 
673     printf( "--------------------------------------------\n" );
674     printf( "File-Open-And-Close-Test\n" );
675     printf( "--------------------------------------------\n\n" );
676 
677     File    *pFile;
678 
679     pFile=new File( file1 );
680 
681     printf( "Open an existing file: ");
682     printFileName( file1 );
683     printf( "\n" );
684 
685     //--------------------------------------------------
686     // open an existing file (Read)
687     //--------------------------------------------------
688 
689     rc=pFile->open( OpenFlag_Read );
690     print_error( rtl::OString( "Open File (Read)" ), rc );
691 
692     //--------------------------------------------------
693     // close the file
694     //--------------------------------------------------
695 
696     rc=pFile->close();
697     print_error( rtl::OString( "Close File" ), rc );
698 
699     printf( "\n" );
700 
701     //--------------------------------------------------
702     // open an existing file (Write)
703     //--------------------------------------------------
704 
705     rc=pFile->open( OpenFlag_Write );
706     print_error( rtl::OString( "Open File (Write)" ), rc );
707 
708     //--------------------------------------------------
709     // close the file
710     //--------------------------------------------------
711 
712     rc=pFile->close();
713     print_error( rtl::OString( "Close File" ), rc );
714 
715     printf( "\n" );
716 
717     //--------------------------------------------------
718     // close the file a second time
719     //--------------------------------------------------
720 
721     rc=pFile->close();
722     print_error( rtl::OString( "Close the file a second time" ), rc );
723 
724     delete pFile;
725     PressKey();
726 }
727 
728 //--------------------------------------------------
729 // FileCreateAndRemoveTest
730 //--------------------------------------------------
731 
FileCreateAndRemoveTest()732 void FileCreateAndRemoveTest()
733 {
734     FileBase::RC    rc;
735     File    *pFile;
736 
737     printf( "--------------------------------------------\n" );
738     printf( "File-Create-And-Remove-Test\n" );
739     printf( "--------------------------------------------\n\n" );
740 
741     pFile=new File( file_not_exist );
742 
743     printf( "Create File: ");
744     printFileName( file_not_exist );
745     printf( "\n" );
746 
747     //----------------------------------------------------
748     // open (create) a not existing file (Read and write)
749     //----------------------------------------------------
750 
751     rc = pFile->open( OpenFlag_Read | OpenFlag_Write | osl_File_OpenFlag_Create );
752 
753     print_error( rtl::OString( "Create and Open File (Read & Write)" ), rc );
754 
755     //----------------------------------------------------
756     // close the file
757     //----------------------------------------------------
758 
759     rc=pFile->close();
760     print_error( rtl::OString( "Close File" ), rc );
761 
762     //----------------------------------------------------
763     // remove the file
764     //----------------------------------------------------
765 
766     rc=pFile->remove( file_not_exist );
767     print_error( rtl::OString(" Remove File" ), rc );
768 
769     printf( "\n" );
770 
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 );
776 
777     //----------------------------------------------------
778     // remove an open file
779     //----------------------------------------------------
780 
781     pFile->open( OpenFlag_Read | OpenFlag_Write | osl_File_OpenFlag_Create );
782 
783     rc=pFile->remove( file_not_exist );
784     print_error( rtl::OString( "Remove an open File" ), rc );
785 
786     pFile->close();
787     pFile->remove( file_not_exist );
788 
789     PressKey();
790 
791     return;
792 }
793 
794 //--------------------------------------------------
795 // FileWriteAndReadTest
796 //--------------------------------------------------
797 
FileWriteAndReadTest(void)798 void FileWriteAndReadTest( void )
799 {
800     FileBase::RC    rc;
801 
802     sal_uInt64 uWritten;
803     sal_uInt64 uRead;
804     sal_Char    *pWriteBuffer="Hier kommt der Osterhase !";
805     sal_uInt64  nLen=strlen( pWriteBuffer );
806     sal_Char *pReadBuffer;
807 
808     printf( "--------------------------------------------\n" );
809     printf( "File-Write-And-Read-Test\n" );
810     printf( "--------------------------------------------\n\n" );
811 
812     File    *pFile;
813 
814     pFile=new File( file_not_exist );
815 
816     printf( "Create File: ");
817     printFileName( file_not_exist );
818     printf("\n");
819 
820     //----------------------------------------------------
821     // open (create) a not existing file (Read and write)
822     //----------------------------------------------------
823 
824     rc = pFile->open( OpenFlag_Read | OpenFlag_Write | osl_File_OpenFlag_Create );
825 
826     print_error( rtl::OString( "Create and Open File (Read & Write)" ), rc );
827 
828     printf( "\n" );
829 
830     //----------------------------------------------------
831     // write a string to the file
832     //----------------------------------------------------
833     rc=pFile->write( pWriteBuffer , nLen , uWritten );
834     print_error( rtl::OString( "Write File" ), rc );
835 
836     if(uWritten==nLen)
837         printf( "Verify: OK! \n" );
838     else
839         printf( "Verify: Error\n" );
840 
841     printf( "\n" );
842 
843     //----------------------------------------------------
844     // move the filepointer to the beginning
845     //----------------------------------------------------
846 
847     rc=pFile->setPos( Pos_Absolut , 0 );
848     print_error( rtl::OString( "Set FilePointer to the beginning of the file" ), rc );
849 
850     printf( "\n" );
851 
852     //----------------------------------------------------
853     // read the string
854     //----------------------------------------------------
855 
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 );
860 
861     if (strcmp(pWriteBuffer, pReadBuffer)==0)
862     {
863         printf( "Verify: OK !\n" );
864         printf( "Text: %s\n",pReadBuffer );
865     }
866     else
867         printf( "Verify: Error\n" );
868 
869     rtl_freeMemory( pReadBuffer );
870 
871     printf( "\n" );
872 
873     // close the file
874     rc=pFile->close();
875     print_error( rtl::OString( "Close File" ), rc );
876 
877     // remove the file
878     rc=pFile->remove( file_not_exist );
879     print_error( rtl::OString( "Remove File" ), rc );
880 
881     PressKey();
882 
883     return;
884 
885 }
886 
887 //--------------------------------------------------
888 // FileCopyMoveTest
889 //--------------------------------------------------
890 
FileCopyAndMoveTest(void)891 void FileCopyAndMoveTest( void )
892 {
893     FileBase::RC    rc;
894 
895     printf( "--------------------------------------------\n" );
896     printf( "File-Copy-Move-Test\n" );
897     printf( "--------------------------------------------\n\n" );
898 
899 
900     File    *pFile;
901     rtl::OUString   destPath(dir2);
902 
903     //--------------------------------------------------
904     // FileCopyTest
905     //--------------------------------------------------
906 
907     destPath+=rtl::OUString::createFromAscii("/");
908     destPath+=file3;
909 
910     printf( "Copy the file ");
911     printFileName( file1 );
912     printf( " to ");
913     printFileName( destPath );
914     printf( "\n" );
915 
916 
917     rc=File::copy( file1 , destPath );
918     print_error( rtl::OString( "FileCopy" ), rc );
919 
920     pFile=new File( destPath );
921 
922     rc=pFile->open( OpenFlag_Read );
923     if ( rc == FileBase::E_None)
924     {
925         printf( "Verify: OK!\n" );
926         pFile->close();
927         File::remove( destPath );
928     }
929     else
930         printf( "Verify: Error!\n" );
931 
932     delete pFile;
933 
934     printf( "\n" );
935 
936     //--------------------------------------------------
937     // Copy a file to a not existing directory
938     //--------------------------------------------------
939 
940     destPath=rtl::OUString( dir_not_exist );
941     destPath+=rtl::OUString::createFromAscii("/");
942     destPath+=file3;
943 
944     printf( "Copy a file to a not existing directory \n");
945     printf( "Copy the file  %s to %s\n", file1.getStr(), destPath.getStr() );
946 
947     rc=File::copy( file1, destPath );
948     print_error( rtl::OString( "FileCopy" ), rc );
949 
950     printf( "\n" );
951 
952     //--------------------------------------------------
953     // Copy a directory
954     //--------------------------------------------------
955 
956     printf( "Copy the directory: ");
957     printFileName( dir1 );
958     printf( " to ");
959     printFileName( dir2 );
960     printf( "\n" );
961 
962     rc=File::copy( dir1 , dir2 );
963     print_error( rtl::OString( "FileCopy" ), rc );
964 
965     printf( "\n" );
966 
967     //--------------------------------------------------
968     // FileMoveTest
969     //--------------------------------------------------
970 
971     destPath=rtl::OUString( dir2 );
972     destPath+=rtl::OUString::createFromAscii("/");
973     destPath+=file3;
974 
975     printf( "Move the file ");
976     printFileName( file1 );
977     printf( " to ");
978     printFileName( destPath );
979     printf( "\n" );
980 
981     rc=File::move( file1, destPath );
982     print_error( rtl::OString( "FileMove" ), rc );
983 
984     pFile=new File( destPath );
985 
986     rc=pFile->open( OpenFlag_Read );
987     if ( rc==FileBase::E_None )
988     {
989         pFile->close();
990 
991         delete pFile;
992         pFile=new File( file1 );
993 
994         rc=pFile->open( OpenFlag_Read );
995 
996         if ( rc!=FileBase::E_None )
997         {
998             printf( "Verify: OK!\n" );
999             File::move( destPath, file1 );
1000         }
1001         else
1002         {
1003             printf( "Verify: Error!\n" );
1004             pFile->close();
1005             File::remove( destPath );
1006         }
1007     }
1008     else
1009         printf( "Verify: Error!\n" );
1010 
1011     delete pFile;
1012 
1013     printf( "\n" );
1014 
1015 
1016     //--------------------------------------------------
1017     // Move a file to a not existing directory
1018     //--------------------------------------------------
1019 
1020     destPath=rtl::OUString( dir_not_exist );
1021     destPath+=rtl::OUString::createFromAscii("/");
1022     destPath+=file3;
1023 
1024     printf( "Move a file to a not existing directory: \n");
1025     printf( "Move the file ");
1026     printFileName( file1 );
1027     printf( " to ");
1028     printFileName( destPath );
1029     printf( "\n" );
1030 
1031     rc=File::move( file1 , destPath );
1032     print_error( rtl::OString( "FileMove" ), rc );
1033 
1034     printf( "\n" );
1035 
1036     //--------------------------------------------------
1037     // Move a directory
1038     //--------------------------------------------------
1039 
1040     printf( "Move a directory: \n");
1041 
1042     printf( "Move the directory ");
1043     printFileName( dir1 );
1044     printf( " to ");
1045     printFileName( dir_not_exist );
1046     printf( "\n" );
1047 
1048 
1049     rc=File::move( dir1 , dir_not_exist);
1050     print_error( rtl::OString( "FileMove" ), rc );
1051 
1052     if ( rc == FileBase::E_None )
1053         File::move( dir_not_exist , dir1);
1054 
1055     printf( "\n" );
1056 
1057 
1058     PressKey();
1059     return;
1060 }
1061 
1062 //----------------------------------------------------
1063 // FileSizeTest
1064 //----------------------------------------------------
1065 
FileSizeTest(void)1066 void FileSizeTest( void )
1067 {
1068     FileBase::RC    rc;
1069     sal_uInt64      filesize;
1070     DirectoryItem   aItem;
1071 
1072     printf( "--------------------------------------------\n" );
1073     printf( "File-Size-Test\n" );
1074     printf( "--------------------------------------------\n\n" );
1075 
1076 
1077     File    aFile( file_not_exist );
1078 
1079     printf( "Create File: ");
1080     printFileName( file_not_exist );
1081     printf( "\n\n");
1082 
1083     rc = aFile.open( OpenFlag_Read | OpenFlag_Write | osl_File_OpenFlag_Create );
1084     print_error( rtl::OString( "Create and Open File (Read & Write)" ), rc );
1085     printf( "\n" );
1086 
1087     if ( rc == FileBase::E_None )
1088     {
1089         //----------------------------------------------------
1090         // Set Filesize to 5000
1091         //----------------------------------------------------
1092 
1093         printf( "Set FileSize to 5000\n" );
1094         rc=aFile.setSize( 5000 );
1095         print_error( rtl::OString( "Set FileSize" ), rc );
1096 
1097         printf( "\n" );
1098         printf( "Verify:\n" );
1099 
1100         //----------------------------------------------------
1101         // Check whether Filesize is set to 5000
1102         //----------------------------------------------------
1103 
1104         rc=DirectoryItem::get( file_not_exist, aItem );
1105         print_error( rtl::OString( "Get DirectoryItem" ), rc );
1106 
1107         if ( rc == FileBase::E_None )
1108         {
1109             FileStatus rStatus( FileStatusMask_FileSize  );
1110             rc=aItem.getFileStatus( rStatus );
1111             print_error( rtl::OString( "Get FileStatus" ), rc );
1112 
1113             if ( rc == FileBase::E_None )
1114             {
1115                 filesize=rStatus.getFileSize();
1116 
1117                 if ( filesize == 5000 )
1118                     printf( "\nOK : FileSize: %i\n", filesize );
1119                 else
1120                     printf( "\nError : FileSize: %i\n", filesize );
1121             }
1122         }
1123 
1124         printf( "\n" );
1125 
1126         //----------------------------------------------------
1127         // Set Filesize to -1
1128         //----------------------------------------------------
1129 
1130         printf( "Set FileSize to -1\n" );
1131         rc=aFile.setSize( -1 );
1132         print_error( rtl::OString( "Set FileSize" ), rc );
1133 
1134         printf( "\n" );
1135 
1136         // close the file
1137         rc=aFile.close();
1138         print_error( rtl::OString( "Close File" ), rc );
1139 
1140         // remove the file
1141         rc=File::remove( file_not_exist );
1142         print_error( rtl::OString( "Remove File" ), rc );
1143     }
1144 
1145     PressKey();
1146 
1147     return;
1148 }
1149 
1150 
1151 //----------------------------------------------------
1152 // FilePointerTest
1153 //----------------------------------------------------
1154 
FilePointerTest(void)1155 void FilePointerTest( void )
1156 {
1157     FileBase::RC    rc;
1158     sal_uInt64 filepointer;
1159 
1160     printf( "--------------------------------------------\n" );
1161     printf( "File-Pointer-Test\n" );
1162     printf( "--------------------------------------------\n\n" );
1163 
1164 
1165     File    rFile( file_not_exist );
1166 
1167     printf( "Create File: ");
1168     printFileName( file_not_exist );
1169     printf( "\n\n");
1170 
1171     rc = rFile.open( OpenFlag_Read | OpenFlag_Write | osl_File_OpenFlag_Create );
1172     print_error( rtl::OString( "Create and Open File (Read & Write) "), rc );
1173     printf( "\n" );
1174 
1175     if ( rc==FileBase::E_None )
1176     {
1177 
1178         //----------------------------------------------------
1179         // get the position of the filepointer
1180         //----------------------------------------------------
1181 
1182         rc =rFile.getPos( filepointer );
1183         print_error( rtl::OString( "GetPos" ), rc );
1184         printf( "Position of the FilePointer: %i\n", filepointer );
1185 
1186         printf( "\n" );
1187 
1188         //----------------------------------------------------
1189         // set the filepointer at the end of a file
1190         //----------------------------------------------------
1191 
1192         printf( "Set FileSize to 5000\n" );
1193         rFile.setSize( 5000 );
1194 
1195         printf( "Set the FilePointer at the end of the file (5000)\n" );
1196         rc=rFile.setPos( Pos_End,0 );
1197         print_error( rtl::OString( "SetPos" ), rc );
1198 
1199         rc=rFile.getPos( filepointer );
1200 
1201         if ( filepointer==5000 )
1202         {
1203             print_error( rtl::OString( "GetPos" ), rc );
1204             printf( "\nVerify: OK !\n" );
1205             printf( "Filepointer-Position: %llu\n",filepointer );
1206         }
1207         else
1208         {
1209             print_error( rtl::OString( "GetPos" ), rc );
1210             printf( "\nFilePointer-Test: Error\n" );
1211             printf( "Filepointer-Position: %i != 5000 \n",filepointer );
1212         }
1213 
1214         printf( "\n" );
1215 
1216         // close the file
1217         rc=rFile.close();
1218         print_error( rtl::OString( "Close File" ), rc );
1219 
1220         // remove the file
1221         rc=File::remove( file_not_exist );
1222         print_error( rtl::OString( "Remove File" ), rc );
1223     }
1224 
1225     PressKey();
1226 
1227     return;
1228 }
1229 
1230 //--------------------------------------------------
1231 // FileAttributesTest
1232 //--------------------------------------------------
1233 
verifyFileAttributes(void)1234 void verifyFileAttributes( void )
1235 {
1236     FileBase::RC    rc;
1237     DirectoryItem   aItem;
1238     FileStatus rStatus( FileStatusMask_Attributes  );
1239 
1240     printf( "\nVerify:\n" );
1241 
1242     rc=DirectoryItem::get( file1, aItem );
1243 
1244     if ( rc==FileBase::E_None )
1245     {
1246         rc=aItem.getFileStatus( rStatus );
1247 
1248         if ( rc==FileBase::E_None )
1249         {
1250             sal_uInt64 uAttributes=rStatus.getAttributes();
1251             showAttributes(uAttributes);
1252             printf( "\n" );
1253         }
1254         else
1255             print_error( rtl::OString( "Get FileStatus" ), rc );
1256     }
1257     else
1258         print_error( rtl::OString( "Get DirectoryItem" ), rc );
1259 
1260     return;
1261 }
1262 
1263 #ifdef UNX
FileAttributesTest(void)1264 void FileAttributesTest( void )
1265 {
1266     FileBase::RC    rc;
1267 
1268     printf( "--------------------------------------------\n" );
1269     printf( "File-Attributes-Test\n" );
1270     printf( "--------------------------------------------\n\n" );
1271 
1272     printf( "File: ");
1273     printFileName( file1 );
1274     printf( "\n\n" );
1275 
1276 
1277     rc=File::setAttributes( file1, Attribute_GrpWrite );
1278     print_error( rtl::OString( "Set Attribute: GrpWrite" ), rc );
1279 
1280     verifyFileAttributes();
1281 
1282     rc=File::setAttributes( file1, 0 );
1283     if ( rc!=FileBase::E_None )
1284         print_error( rtl::OString( "Reset Attributes" ), rc );
1285 
1286     rc=File::setAttributes( file1, Attribute_GrpRead );
1287     print_error( rtl::OString( "Set Attribute: GrpRead" ), rc );
1288 
1289     verifyFileAttributes();
1290 
1291     rc=File::setAttributes( file1, 0 );
1292     if ( rc!=FileBase::E_None )
1293         print_error( rtl::OString( "Reset Attributes" ), rc );
1294 
1295     rc=File::setAttributes( file1, Attribute_GrpExe );
1296     print_error( rtl::OString( "Set Attribute: GrpExe" ), rc );
1297 
1298     verifyFileAttributes();
1299 
1300     rc=File::setAttributes( file1, 0 );
1301     if ( rc!=FileBase::E_None )
1302         print_error( rtl::OString( "Reset Attributes" ), rc );
1303 
1304     rc=File::setAttributes( file1, Attribute_OwnWrite );
1305     print_error( rtl::OString( "Set Attribute: OwnWrite" ), rc );
1306 
1307     verifyFileAttributes();
1308 
1309     rc=File::setAttributes( file1, 0 );
1310     if ( rc!=FileBase::E_None )
1311         print_error( rtl::OString( "Reset Attributes" ), rc );
1312 
1313     rc=File::setAttributes( file1, Attribute_OwnRead );
1314     print_error( rtl::OString( "Set Attribute: OwnRead" ), rc );
1315 
1316     verifyFileAttributes();
1317 
1318     rc=File::setAttributes( file1, 0 );
1319     if ( rc!=FileBase::E_None )
1320         print_error( rtl::OString( "Reset Attributes" ), rc );
1321 
1322     rc=File::setAttributes( file1, Attribute_OwnExe );
1323     print_error( rtl::OString( "Set Attribute: OwnExe" ), rc );
1324 
1325     verifyFileAttributes();
1326 
1327     rc=File::setAttributes( file1, 0 );
1328     if ( rc!=FileBase::E_None )
1329         print_error( rtl::OString( "Reset Attributes" ), rc );
1330 
1331     rc=File::setAttributes( file1, Attribute_OthWrite );
1332     print_error( rtl::OString( "Set Attribute: OthWrite" ), rc );
1333 
1334     verifyFileAttributes();
1335 
1336     rc=File::setAttributes( file1, 0 );
1337     if ( rc!=FileBase::E_None )
1338         print_error( rtl::OString( "Reset Attributes" ), rc );
1339 
1340     rc=File::setAttributes( file1, Attribute_OthRead );
1341     print_error( rtl::OString( "Set Attribute: OthRead" ), rc );
1342 
1343     verifyFileAttributes();
1344 
1345     rc=File::setAttributes( file1, 0 );
1346     if ( rc!=FileBase::E_None )
1347         print_error( rtl::OString( "Reset Attributes" ), rc );
1348 
1349     rc=File::setAttributes( file1, Attribute_OthExe );
1350     print_error( rtl::OString( "Set Attribute: OthExe" ), rc );
1351 
1352     verifyFileAttributes();
1353 
1354     rc=File::setAttributes( file1, 0 );
1355     if ( rc!=FileBase::E_None )
1356         print_error( rtl::OString( "Reset Attributes" ), rc );
1357 
1358 
1359     rc=File::setAttributes( file1, Attribute_GrpWrite | Attribute_GrpRead | Attribute_GrpExe | Attribute_OwnWrite | Attribute_OwnRead | Attribute_OwnExe | Attribute_OthWrite | Attribute_OthRead | Attribute_OthExe );
1360     print_error( rtl::OString( "Set all Attributes" ), rc );
1361 
1362     verifyFileAttributes();
1363 
1364     PressKey();
1365 
1366     return;
1367 }
1368 #endif
1369 
1370 #ifdef WNT
FileAttributesTest(void)1371 void FileAttributesTest( void )
1372 {
1373     FileBase::RC    rc;
1374 
1375     printf( "--------------------------------------------\n" );
1376     printf( "File-Attributes-Test\n" );
1377     printf( "--------------------------------------------\n\n" );
1378 
1379     printf( "File: ");
1380     printFileName( file1 );
1381     printf( "\n\n" );
1382 
1383 
1384     rc=File::setAttributes( file1, Attribute_ReadOnly );
1385     print_error( rtl::OString( "Set Attribute: ReadOnly" ), rc );
1386 
1387     verifyFileAttributes();
1388 
1389     rc=File::setAttributes( file1, 0 );
1390     print_error( rtl::OString( "Reset Attributes" ), rc );
1391 
1392     verifyFileAttributes();
1393 
1394     rc=File::setAttributes( file1, Attribute_Hidden );
1395     print_error( rtl::OString( "Set Attribute: Hidden" ), rc );
1396 
1397     verifyFileAttributes();
1398 
1399     rc=File::setAttributes( file1, 0 );
1400     print_error( rtl::OString( "Reset Attributes" ), rc );
1401 
1402     verifyFileAttributes();
1403 
1404     rc=File::setAttributes( file1, Attribute_Hidden | Attribute_ReadOnly );
1405     print_error( rtl::OString( "Set Attribute: Hidden & ReadOnly" ), rc );
1406 
1407     verifyFileAttributes();
1408 
1409     rc=File::setAttributes( file1, 0 );
1410     print_error( rtl::OString( "Reset Attributes") , rc );
1411 
1412     verifyFileAttributes();
1413 
1414     PressKey();
1415 
1416     return;
1417 }
1418 #endif
1419 
1420 //--------------------------------------------------
1421 // FileTimeTest
1422 //--------------------------------------------------
1423 
FileTimeTest(void)1424 void FileTimeTest( void )
1425 {
1426     FileBase::RC    rc;
1427 
1428     DirectoryItem   aItem;
1429 
1430     struct tm sSysCreationTime = { 0, 20, 12, 4, 9, 100 };
1431     struct tm sSysAccessTime = { 0, 40, 1, 6, 5, 98 };
1432     struct tm sSysModifyTime = { 0, 1, 24, 13, 11, 95 };
1433 
1434     time_t aSysCreationTime =  mktime( &sSysCreationTime );
1435     time_t aSysAccessTime =  mktime( &sSysAccessTime );
1436     time_t aSysModifyTime =  mktime( &sSysModifyTime );
1437 
1438     TimeValue       aCreationTime   = { aSysCreationTime, 0};
1439     TimeValue       aAccessTime     = { aSysAccessTime, 0};
1440     TimeValue       aModifyTime     = { aSysModifyTime, 0};
1441 
1442     TimeValue       aCreationTimeRead;
1443     TimeValue       aAccessTimeRead;
1444     TimeValue       aModifyTimeRead;
1445 
1446 
1447     printf( "--------------------------------------------\n" );
1448     printf( "File-Time-Test\n" );
1449     printf( "--------------------------------------------\n\n" );
1450 
1451     printf( "File: ");
1452     printFileName( file1 );
1453     printf( "\n\n" );
1454 
1455     printf( "CreationTime \t : ");
1456     showTime( aCreationTime );
1457 
1458     printf( "\nAccessTime \t : ");
1459     showTime( aAccessTime );
1460 
1461     printf( "\nModifyTime \t : ");
1462     showTime( aModifyTime );
1463 
1464     //--------------------------------------------------
1465     // setTime
1466     //--------------------------------------------------
1467 
1468     printf( "\n" );
1469     rc=File::setTime( file1 , aCreationTime , aAccessTime , aModifyTime );
1470     print_error( rtl::OString( "SetTime" ), rc );
1471 
1472     //--------------------------------------------------
1473     // Verify
1474     //--------------------------------------------------
1475 
1476     FileStatus rStatus( FileStatusMask_CreationTime | FileStatusMask_AccessTime | FileStatusMask_ModifyTime);
1477 
1478     printf( "\nVerify:\n" );
1479 
1480     rc=DirectoryItem::get( file1, aItem );
1481     print_error( rtl::OString( "Get DirectoryItem" ), rc );
1482 
1483     if ( rc==FileBase::E_None )
1484     {
1485         rc=aItem.getFileStatus( rStatus );
1486         print_error( rtl::OString( "Get FileStatus" ), rc );
1487         printf( "\n" );
1488 
1489         if ( rc==FileBase::E_None )
1490         {
1491             //--------------------------------------------------
1492             // GetCreationTime
1493             //--------------------------------------------------
1494 
1495             aCreationTimeRead=rStatus.getCreationTime();
1496 #ifdef WNT
1497             if ( aCreationTime.Seconds == aCreationTimeRead.Seconds && aCreationTime.Nanosec == aCreationTimeRead.Nanosec )
1498                 printf( "GetCreationTime: ok : " );
1499             else
1500                 printf( "GetCreationTime: Error : " );
1501 
1502             showTime( aCreationTimeRead );
1503             printf( "\n" );
1504 #endif
1505             //--------------------------------------------------
1506             // GetAccessTime
1507             //--------------------------------------------------
1508 
1509             aAccessTimeRead=rStatus.getAccessTime();
1510 
1511             if ( aAccessTime.Seconds == aAccessTimeRead.Seconds && aAccessTime.Nanosec == aAccessTimeRead.Nanosec )
1512                 printf( "GetAccessTime: ok : " );
1513             else
1514                 printf( "GetAccessTime: Error : " );
1515 
1516             showTime( aAccessTimeRead );
1517             printf( "\n" );
1518 
1519             //--------------------------------------------------
1520             // GetModifyTime
1521             //--------------------------------------------------
1522 
1523             aModifyTimeRead=rStatus.getModifyTime();
1524 
1525             if ( aModifyTime.Seconds == aModifyTimeRead.Seconds && aModifyTime.Nanosec == aModifyTimeRead.Nanosec )
1526                 printf( "GetModifyTime: ok : " );
1527             else
1528                 printf( "GetModifyTime: Error : " );
1529 
1530             showTime( aModifyTimeRead );
1531             printf( "\n" );
1532         }
1533     }
1534 
1535     PressKey();
1536     return;
1537 }
1538 
1539 
1540 //--------------------------------------------------
1541 // DirectoryItemTest
1542 //--------------------------------------------------
1543 
DirectoryItemTest(void)1544 void DirectoryItemTest( void )
1545 {
1546     FileBase::RC    rc;
1547     Directory       *pDir;
1548     DirectoryItem   aItem;
1549     FileStatus      *pStatus;
1550     File            *pFile;
1551 
1552     printf( "--------------------------------------------\n" );
1553     printf( "Directory-Item-Test\n" );
1554     printf( "--------------------------------------------\n\n" );
1555 
1556     //--------------------------------------------------
1557     // get DirectoryItem from an existing directory
1558     //--------------------------------------------------
1559 
1560     printf( "Get DirectoryItem from an existing Directory: ");
1561     printFileName( dir1 );
1562     printf( "\n");
1563 
1564     rc=DirectoryItem::get( dir1 , aItem );
1565     print_error( rtl::OString( "GetDirectoryItem" ), rc );
1566 
1567     pStatus=new FileStatus( FileStatusMask_All );
1568     rc=aItem.getFileStatus( *pStatus );
1569 
1570     if ( rc==FileBase::E_None )
1571     {
1572         printf( "GetFileStatus: FileURL: ");
1573         printFileName(pStatus->getFileURL() );
1574         printf( "\n" );
1575     }
1576 
1577     delete pStatus;
1578 
1579     printf( "\n" );
1580 
1581     //--------------------------------------------------
1582     // get DirectoryItem from a not existing directory
1583     //--------------------------------------------------
1584 
1585     printf( "Get DirectoryItem from a not existing Directory: ");
1586     printFileName( dir_not_exist );
1587     printf( "\n" );
1588 
1589     rc=DirectoryItem::get( dir_not_exist , aItem );
1590     print_error( rtl::OString( "Get DirectoryItem" ), rc );
1591 
1592     printf( "\n" );
1593 
1594     //--------------------------------------------------
1595     // get DirectoryItem from an existing file
1596     //--------------------------------------------------
1597 
1598     printf( "Get DirectoryItem from an existing File: ");
1599     printFileName( file1 );
1600     printf( "\n" );
1601 
1602     rc=DirectoryItem::get( file1 , aItem );
1603     print_error( rtl::OString( "GetDirectoryItem" ), rc );
1604 
1605     pStatus=new FileStatus( FileStatusMask_All );
1606     rc=aItem.getFileStatus( *pStatus );
1607 
1608     if ( rc==FileBase::E_None )
1609     {
1610         printf( "GetFileStatus: FileURL: ");
1611         printFileName( pStatus->getFileURL() );
1612         printf( "\n" );
1613     }
1614 
1615     delete pStatus;
1616 
1617     printf( "\n" );
1618 
1619     //--------------------------------------------------
1620     // get DirectoryItem from a not existing file
1621     //--------------------------------------------------
1622 
1623     printf( "Get DirectoryItem from a not existing File: ");
1624     printFileName( file_not_exist );
1625     printf( "\n" );
1626 
1627     rc=DirectoryItem::get( file_not_exist , aItem );
1628     print_error( rtl::OString( "Get DirectoryItem" ), rc );
1629 
1630     printf( "\n" );
1631 
1632     //----------------------------------------------------------
1633     // get DirectoryItem from a directory with a wrong semantic
1634     //----------------------------------------------------------
1635 
1636     printf( "Get DirectoryItem from a Directory with a wrong semantic: ");
1637     printFileName( dir_not_exist );
1638     printf( "\n" );
1639 
1640     rc=DirectoryItem::get( dir_wrong_semantic, aItem );
1641     print_error( rtl::OString( "Get DirectoryItem" ),rc );
1642 
1643     printf( "\n" );
1644 
1645     //---------------------------------------------------
1646     // get DirectoryItem from a file-handle
1647     //--------------------------------------------------
1648 
1649     pFile=new File( file1 );
1650 
1651     rc=pFile->open( OpenFlag_Read );
1652     if ( rc==FileBase::E_None )
1653     {
1654         printf( "Get DirectoryItem from a File-Handle: ");
1655         printFileName( file1 );
1656         printf( "\n" );
1657 
1658         rc=DirectoryItem::get( *pFile , aItem );
1659         print_error( rtl::OString( "GetDirectoryItem" ), rc );
1660 
1661         pStatus=new FileStatus( FileStatusMask_All );
1662         rc=aItem.getFileStatus( *pStatus );
1663 
1664         if ( rc==FileBase::E_None )
1665         {
1666             printf( "GetFileStatus: FileURL:  ");
1667             printFileName( pStatus->getFileURL() );
1668             printf( "\n");
1669         }
1670 
1671         delete pStatus;
1672 
1673         pFile->close();
1674     }
1675 
1676     delete pFile;
1677 
1678     printf( "\n" );
1679 
1680     //---------------------------------------------------
1681     // get DirectoryItem from an empty file-handle
1682     //--------------------------------------------------
1683 
1684     pFile=new File( file1 );
1685 
1686     printf( "Get DirectoryItem from an empty File-Handle\n" );
1687     rc=DirectoryItem::get( *pFile , aItem );
1688     print_error( rtl::OString( "GetDirectoryItem" ), rc );
1689 
1690     delete pFile;
1691 
1692     printf( "\n" );
1693 
1694     //--------------------------------------------------
1695     // GetNextItem from a directory
1696     //--------------------------------------------------
1697 
1698     pDir=new Directory( dir1 );
1699     printf( "Get next DirectoryItem from a directory: ");
1700     printFileName( dir1);
1701     printf( "\n" );
1702 
1703     rc= pDir->open();
1704     print_error( rtl::OString( "Open Directory" ), rc );
1705 
1706     printf( "\n" );
1707 
1708     if ( pDir->isOpen() )
1709     {
1710         //--------------------------------------------------
1711         // get all files from the directory
1712         //--------------------------------------------------
1713 
1714         rtl::OUString   str;
1715         rtl::OUString   str1[2];
1716 
1717         aItem=DirectoryItem();
1718         rc=pDir->getNextItem( aItem );
1719         print_error( rtl::OString( "GetNextItem" ),rc );
1720 
1721         while( rc==FileBase::E_None )
1722         {
1723 
1724             FileStatus rStatus( FileStatusMask_All );
1725             aItem.getFileStatus( rStatus );
1726 
1727             str=rStatus.getFileName();
1728             printf( "Filename: ");
1729             printFileName( str );
1730             printf( "\n");
1731 
1732             aItem=DirectoryItem();
1733             rc=pDir->getNextItem( aItem );
1734             print_error( rtl::OString( "GetNextItem" ),rc );
1735         }
1736 
1737         printf( "\n" );
1738 
1739         //--------------------------------------------------
1740         // Reset-Test
1741         //--------------------------------------------------
1742 
1743         for (int i=0; i<2; i++)
1744         {
1745             aItem=DirectoryItem();
1746             rc=pDir->reset();
1747             rc=pDir->getNextItem( aItem );
1748 
1749             FileStatus rStatus( FileStatusMask_All );
1750             aItem.getFileStatus( rStatus );
1751 
1752             str1[i]=rStatus.getFileName();
1753         }
1754 
1755 
1756         if ( str1[0].compareTo(str1[1]) == 0 )
1757             print_error( rtl::OString( "Reset" ),FileBase::E_None );
1758         else
1759             print_error( rtl::OString( "Reset" ),FileBase::E_invalidError );
1760 
1761         printf( "\n" );
1762 
1763         // Close Directory
1764         rc=pDir->close();
1765         print_error( rtl::OString( "Close Directory" ), rc );
1766     }
1767 
1768     printf( "\n");
1769 
1770     //--------------------------------------------------
1771     // GetNextItem from a closed directory
1772     //--------------------------------------------------
1773 
1774     printf( "Get next DirectoryItem from a closed directory: ");
1775     printFileName( dir1 );
1776     printf( "\n" );
1777 
1778     aItem=DirectoryItem();
1779     rc=pDir->getNextItem( aItem );
1780     print_error( rtl::OString( "GetNextItem" ),rc );
1781 
1782     delete pDir;
1783 
1784     PressKey();
1785     return;
1786 }
1787 
1788 //--------------------------------------------------
1789 // FileStatusTest (for different types)
1790 //--------------------------------------------------
1791 
FileStatusTest(FileStatus * pStatus)1792 void FileStatusTest( FileStatus *pStatus )
1793 {
1794     //--------------------------------------------------
1795     // GetFileType of the directory
1796     //--------------------------------------------------
1797 
1798     FileStatus::Type    aType;
1799 
1800     printf( "\ngetFileType:\n" );
1801     aType=pStatus->getFileType();
1802     showFileType( aType );
1803 
1804     //--------------------------------------------------
1805     // GetAttributes
1806     //--------------------------------------------------
1807 
1808     sal_uInt64          uAttributes;
1809 
1810     printf( "\ngetAttributes:\n" );
1811     uAttributes=pStatus->getAttributes();
1812     showAttributes( uAttributes );
1813 
1814     //--------------------------------------------------
1815     // GetCreationTime
1816     //--------------------------------------------------
1817 
1818     TimeValue   aCreationTime;
1819 
1820     printf( "\ngetCreationTime:\n" );
1821     aCreationTime=pStatus->getCreationTime();
1822 
1823     printf( "CreationTime: " );
1824     showTime( aCreationTime );
1825 
1826     //--------------------------------------------------
1827     // GetAccessTime
1828     //--------------------------------------------------
1829 
1830     TimeValue   aAccessTime;
1831 
1832     printf( "\ngetAccessTime:\n" );
1833     aAccessTime=pStatus->getAccessTime();
1834 
1835     printf( "AccessTime: " );
1836     showTime( aAccessTime );
1837 
1838     //--------------------------------------------------
1839     // GetModifyTime
1840     //--------------------------------------------------
1841 
1842     TimeValue   aModifyTime;
1843 
1844     printf( "\ngetModifyTime:\n" );
1845     aModifyTime=pStatus->getModifyTime();
1846 
1847     printf( "ModifyTime: " );
1848     showTime( aModifyTime );
1849 
1850     //--------------------------------------------------
1851     // GetFileSize
1852     //--------------------------------------------------
1853 
1854     sal_uInt64          FileSize;
1855 
1856     printf( "\ngetFileSize:\n" );
1857 
1858     FileSize=pStatus->getFileSize();
1859     printf( "FileSize: %i\n", FileSize);
1860 
1861     //--------------------------------------------------
1862     // GetFileName
1863     //--------------------------------------------------
1864 
1865     rtl::OUString           FileName;
1866 
1867     printf( "\ngetFileName:\n" );
1868 
1869     FileName=pStatus->getFileName();
1870     printf( "FileName: ");
1871     printFileName( FileName );
1872     printf( "\n" );
1873 
1874     //--------------------------------------------------
1875     // GetFileURL
1876     //--------------------------------------------------
1877 
1878     rtl::OUString           FileURL;
1879 
1880     printf( "\ngetFileURL:\n" );
1881 
1882     FileURL=pStatus->getFileURL();
1883     printf( "FileURL: ");
1884     printFileName( FileURL );
1885     printf( "\n" );
1886 
1887     //--------------------------------------------------
1888     // GetLinkTargetURL
1889     //--------------------------------------------------
1890 
1891     rtl::OUString           LinkTargetURL;
1892 
1893     printf( "\ngetLinkTargetURL:\n");
1894 
1895     LinkTargetURL=pStatus->getLinkTargetURL();
1896     printf( "LinkTargetURL: ");
1897     printFileName( LinkTargetURL );
1898     printf( "\n" );
1899 
1900     return;
1901 }
1902 
1903 //--------------------------------------------------
1904 // DirectoryFileStatusTest
1905 //--------------------------------------------------
1906 
DirectoryFileStatusTest(void)1907 void DirectoryFileStatusTest( void )
1908 {
1909     FileBase::RC    rc;
1910     DirectoryItem   aItem;
1911     FileStatus      *pStatus;
1912 
1913     printf( "--------------------------------------------\n" );
1914     printf( "Directory-FileStatus-Test\n" );
1915     printf( "--------------------------------------------\n\n" );
1916 
1917     printf( "FileStatus of the directory: ");
1918     printFileName( dir1 );
1919     printf( "\n" );
1920 
1921     aItem=DirectoryItem();
1922 
1923     rc=DirectoryItem::get( dir1, aItem );
1924     print_error( rtl::OString( "Get DirectoryItem" ), rc );
1925 
1926     if ( rc==FileBase::E_None )
1927     {
1928         pStatus=new FileStatus( FileStatusMask_All );
1929         rc=aItem.getFileStatus( *pStatus );
1930 
1931         FileStatusTest( pStatus );
1932 
1933         delete pStatus;
1934     }
1935 
1936     printf( "\n" );
1937 
1938     PressKey();
1939     return;
1940 }
1941 
1942 //--------------------------------------------------
1943 // FileFileStatusTest
1944 //--------------------------------------------------
1945 
FileFileStatusTest(void)1946 void FileFileStatusTest( void )
1947 {
1948     FileBase::RC    rc;
1949     DirectoryItem   aItem;
1950     FileStatus      *pStatus;
1951 
1952     printf( "--------------------------------------------\n" );
1953     printf( "File-FileStatus-Test\n" );
1954     printf( "--------------------------------------------\n\n" );
1955 
1956     printf( "FileStatus of the file: ");
1957     printFileName( file1 );
1958     printf( "\n" );
1959 
1960     aItem=DirectoryItem();
1961 
1962     rc=DirectoryItem::get( file1 , aItem );
1963     print_error( rtl::OString( "Get DirectoryItem" ), rc );
1964 
1965     if ( rc==FileBase::E_None )
1966     {
1967         pStatus=new FileStatus( FileStatusMask_All );
1968         rc=aItem.getFileStatus( *pStatus );
1969 
1970         FileStatusTest( pStatus );
1971 
1972         delete pStatus;
1973     }
1974 
1975     printf( "\n" );
1976 
1977     PressKey();
1978     return;
1979 }
1980 
1981 //--------------------------------------------------
1982 // VolumeFileStatusTest
1983 //--------------------------------------------------
1984 
VolumeFileStatusTest(void)1985 void VolumeFileStatusTest( void )
1986 {
1987     FileBase::RC    rc;
1988     DirectoryItem   aItem;
1989     FileStatus      *pStatus;
1990 
1991     printf( "--------------------------------------------\n" );
1992     printf( "Volume-FileStatus-Test\n" );
1993     printf( "--------------------------------------------\n\n" );
1994 
1995     printf( "FileStatus of the Volume: ");
1996     printFileName( root );
1997     printf( "\n" );
1998 
1999     aItem=DirectoryItem();
2000 
2001     rc=DirectoryItem::get( root , aItem );
2002     print_error( rtl::OString( "Get DirectoryItem" ), rc );
2003 
2004     if ( rc==FileBase::E_None )
2005     {
2006         pStatus=new FileStatus( FileStatusMask_All) ;
2007         rc=aItem.getFileStatus( *pStatus );
2008 
2009         FileStatusTest( pStatus );
2010 
2011         delete pStatus;
2012     }
2013 
2014     printf( "\n" );
2015 
2016     PressKey();
2017     return;
2018 }
2019 
2020 
2021 //--------------------------------------------------
2022 // VolumeInfoTest
2023 //--------------------------------------------------
2024 
VolumeInfoTest(void)2025 void VolumeInfoTest( void )
2026 {
2027     FileBase::RC    rc;
2028 
2029     printf( "--------------------------------------------\n" );
2030     printf( "Volume-Info-Test\n" );
2031     printf( "--------------------------------------------\n\n" );
2032 
2033     printf( "VolumeInfo of the volume ");
2034     printFileName( root );
2035 
2036     printf( "\n" );
2037 
2038     VolumeInfo rInfo( VolumeInfoMask_FreeSpace );
2039     rc=Directory::getVolumeInfo( root , rInfo );
2040     print_error( rtl::OString( "GetVolumeInfo" ),rc );
2041 
2042     printf( "\n" );
2043 
2044     //--------------------------------------------------
2045     // getRemoteFlag
2046     //--------------------------------------------------
2047 
2048     if ( rInfo.getRemoteFlag() )
2049         printf( "RemoteFlag: Yes\n" );
2050     else
2051         printf( "RemoteFlag: No\n" );
2052 
2053     //--------------------------------------------------
2054     // getRemoveableFlag
2055     //--------------------------------------------------
2056 
2057     if ( rInfo.getRemoveableFlag() )
2058         printf( "RemoveableFlag: Yes\n" );
2059     else
2060         printf( "RemoveableFlag: No\n" );
2061 
2062     //--------------------------------------------------
2063     // getTotalSpace
2064     //--------------------------------------------------
2065 
2066     sal_uInt64  TotalSpace;
2067     TotalSpace=rInfo.getTotalSpace();
2068     printf( "Total Space: %i\n",TotalSpace );
2069 
2070     //--------------------------------------------------
2071     // getFreeSpace
2072     //--------------------------------------------------
2073 
2074     sal_uInt64  FreeSpace;
2075     FreeSpace=rInfo.getFreeSpace();
2076     printf( "Free Space: %i\n",FreeSpace );
2077 
2078     //--------------------------------------------------
2079     // getUsedSpace
2080     //--------------------------------------------------
2081 
2082     sal_uInt64  UsedSpace;
2083     UsedSpace=rInfo.getUsedSpace();
2084     printf( "Used Space: %i\n",UsedSpace );
2085 
2086     //--------------------------------------------------
2087     // getMaxNameLength
2088     //--------------------------------------------------
2089 
2090     sal_uInt32  MaxNameLength;
2091     MaxNameLength=rInfo.getMaxNameLength();
2092     printf( "MaxNameLength: %i\n",MaxNameLength );
2093 
2094     //--------------------------------------------------
2095     // getMaxPathLength
2096     //--------------------------------------------------
2097 
2098     sal_uInt32  MaxPathLength;
2099     MaxPathLength=rInfo.getMaxPathLength();
2100     printf( "MaxPathLength: %i\n",MaxPathLength );
2101 
2102     //--------------------------------------------------
2103     // getFileSystemName
2104     //--------------------------------------------------
2105 
2106     rtl::OUString   FileSystemName;
2107     FileSystemName=rInfo.getFileSystemName();
2108     printf( "File-System-Name: ");
2109     printFileName( FileSystemName );
2110     printf( "\n" );
2111 
2112     PressKey();
2113     return;
2114 }
2115 
2116 //--------------------------------------------------
2117 // FileBaseTest
2118 //--------------------------------------------------
2119 
ConvertPathTest(rtl::OUString & strPath)2120 void ConvertPathTest(rtl::OUString& strPath)
2121 {
2122     FileBase::RC    rc;
2123 
2124     rtl::OUString       strNormPath;
2125     rtl::OUString       strFileURL;
2126     rtl::OUString       strNormPathFromFileURL;
2127     rtl::OUString       strSystemPath;
2128 
2129     //--------------------------------------------------
2130     // normalizePath
2131     //--------------------------------------------------
2132 
2133     rc=FileBase::getFileURLFromSystemPath( strPath, strNormPath );
2134 
2135     if ( rc == FileBase::E_None )
2136     {
2137         printf( "Normalized Path: \t\t");
2138         printFileName( strNormPath );
2139         printf( "\n" );
2140     }
2141     else
2142         printf( "normalizePath: Error \n" );
2143 
2144     //--------------------------------------------------
2145     // getFileURLFromSystemPath
2146     //--------------------------------------------------
2147 
2148     if ( strNormPath.getLength() != 0 )
2149     {
2150         rc=FileBase::getFileURLFromSystemPath( strNormPath, strFileURL );
2151 
2152         if ( rc == FileBase::E_None )
2153         {
2154             printf( "File-URL: \t\t\t");
2155             printFileName( strFileURL );
2156             printf( "\n" );
2157         }
2158         else
2159             printf( "getFileURLFromSystemPath: Error \n" );
2160     }
2161     else
2162         printf( "getFileURLFromSystemPath: not tested \n" );
2163 
2164     //--------------------------------------------------
2165     // getNormalizedPathFromFileURL
2166     //--------------------------------------------------
2167 
2168     if ( strFileURL.getLength() != 0 )
2169     {
2170         rc=FileBase::getSystemPathFromFileURL( strFileURL, strNormPathFromFileURL );
2171 
2172         if ( rc == FileBase::E_None )
2173         {
2174             printf( "Normalized Path from File-URL: \t");
2175             printFileName( strNormPathFromFileURL );
2176             printf( "\n" );
2177         }
2178         else
2179             printf( "getNormalizedPathFromFileURL: Error \n" );
2180     }
2181     else
2182         printf( "getNormalizedPathFromFileURL: not tested \n" );
2183 
2184 
2185     //--------------------------------------------------
2186     // getSystemPathFromFileURL
2187     //--------------------------------------------------
2188 
2189     if ( strNormPath.getLength() != 0 )
2190     {
2191         rc=FileBase::getSystemPathFromFileURL( strNormPath, strSystemPath );
2192 
2193         if ( rc == FileBase::E_None )
2194         {
2195             printf( "System-Path: \t\t\t");
2196             printFileName( strSystemPath );
2197             printf( "\n");
2198         }
2199         else
2200             printf( "getSystemPathFromFileURL: Error \n" );
2201     }
2202     else
2203         printf( "getSystemPathFromFileURL: not tested \n" );
2204 
2205     //--------------------------------------------------
2206     // Verify
2207     //--------------------------------------------------
2208 
2209     if ( strNormPathFromFileURL == strNormPath )
2210         printf( "\nVerify: OK ! ( Normalized-Path == Normalized-Path-From-File-URL )\n" );
2211     else
2212         printf( "\nVerify: Error ! ( Normalized-Path != Normalized-Path-From-File-URL )\n" );
2213 
2214     return;
2215 }
2216 
FileBaseTest()2217 void FileBaseTest()
2218 {
2219     printf( "--------------------------------------------\n" );
2220     printf( "FileBase-Test\n" );
2221     printf( "--------------------------------------------\n\n" );
2222 
2223     //--------------------------------------------------
2224     // ConvertPath-Test (Local File)
2225     //--------------------------------------------------
2226 
2227     printf( "- Local File: ");
2228     printFileName( file1 );
2229     printf( "\n\n" );
2230 
2231     ConvertPathTest(file1);
2232 
2233     //--------------------------------------------------
2234     // ConvertPath-Test (File on a server)
2235     //--------------------------------------------------
2236 
2237     printf( "\n- File on server: ");
2238     printFileName( file_on_server );
2239     printf( "\n\n" );
2240     ConvertPathTest(file_on_server);
2241 
2242     PressKey();
2243 
2244     return;
2245 }
2246 
2247 
2248 //--------------------------------------------------
2249 // AbsolutePathTest
2250 //--------------------------------------------------
DoAbsolutePathTest(rtl::OUString strDirBase,rtl::OUString strRelative)2251 void DoAbsolutePathTest(rtl::OUString strDirBase, rtl::OUString strRelative)
2252 {
2253     FileBase::RC    rc;
2254 
2255     rtl::OUString       strAbsolute;
2256 
2257     printf( "Base-Directory: \t");
2258     printFileName( strDirBase );
2259     printf( "\n" );
2260     printf( "Relative-Path: \t\t");
2261     printFileName ( strRelative );
2262     printf( "\n" );
2263 
2264     rc=FileBase::getAbsoluteFileURL( strDirBase, strRelative, strAbsolute );
2265 
2266     if ( rc == FileBase::E_None )
2267     {
2268         printf( "Absolute-Path: \t\t");
2269         printFileName ( strAbsolute );
2270         printf( "\n" );
2271     }
2272     else
2273         printf( "Absolute-Path: Error \n" );
2274 
2275     printf( "\n" );
2276     return;
2277 }
2278 
AbsolutePathTest(void)2279 void AbsolutePathTest(void)
2280 {
2281     printf( "--------------------------------------------\n" );
2282     printf( "AbsolutePath-Test\n" );
2283     printf( "--------------------------------------------\n\n" );
2284 
2285     DoAbsolutePathTest(dir1, rtl::OUString::createFromAscii("."));
2286     DoAbsolutePathTest(dir1, rtl::OUString::createFromAscii(".."));
2287     DoAbsolutePathTest(dir1, rtl::OUString::createFromAscii("../.."));
2288     DoAbsolutePathTest(dir1, rtl::OUString::createFromAscii("../HUHU"));
2289 
2290     DoAbsolutePathTest(dir_on_server, rtl::OUString::createFromAscii("."));
2291     DoAbsolutePathTest(dir_on_server, rtl::OUString::createFromAscii(".."));
2292     DoAbsolutePathTest(dir_on_server, rtl::OUString::createFromAscii("../.."));
2293     DoAbsolutePathTest(dir_on_server, rtl::OUString::createFromAscii("../HUHU"));
2294 
2295     PressKey();
2296     return;
2297 }
2298 
2299 
2300 //--------------------------------------------------
2301 // searchPathTest
2302 //--------------------------------------------------
2303 
SearchPathTest(void)2304 void SearchPathTest(void)
2305 {
2306     FileBase::RC    rc;
2307 
2308     rtl::OUString       strNormPath(file1);
2309     rtl::OUString       strFileURL;
2310     rtl::OUString       strSystemPath;
2311     rtl::OUString       strResultPath;
2312 
2313     printf( "--------------------------------------------\n" );
2314     printf( "SearchPath-Test\n" );
2315     printf( "--------------------------------------------\n\n" );
2316 
2317 
2318     rc=FileBase::getFileURLFromSystemPath( strNormPath, strFileURL );
2319     print_error( rtl::OString( "getFileURLFromSystemPath" ), rc );
2320     rc=FileBase::getSystemPathFromFileURL( strNormPath, strSystemPath );
2321     print_error( rtl::OString( "getSystemPathFromFileURL" ), rc );
2322 
2323     //--------------------------------------------------
2324     // searchFileURL (with a normalized path)
2325     //--------------------------------------------------
2326 
2327     if ( strNormPath.getLength() != 0 )
2328     {
2329         printf( "\nSearch-Normalized-Path (with a normalized path) : ");
2330         printFileName ( strNormPath );
2331         printf( "\n" );
2332 
2333         rc=FileBase::searchFileURL( strNormPath , rtl::OUString() , strResultPath );
2334 
2335         if ( rc == FileBase::E_None )
2336         {
2337             printf( "Result: \t\t\t");
2338             printFileName ( strResultPath );
2339             printf( "\n" );
2340         }
2341         else
2342             printf( "searchFileURL (with a normalized path): Error\n" );
2343     }
2344     else
2345         printf( "searchFileURL (with a normalized path): not tested\n" );
2346 
2347     //--------------------------------------------------
2348     // searchFileURL (with a File-URL)
2349     //--------------------------------------------------
2350 
2351     if ( strFileURL.getLength() != 0 )
2352     {
2353         printf( "\nSearch-Normalized-Path (with a FileURL) : ");
2354         printFileName( strFileURL );
2355         printf( "\n" );
2356 
2357         rc=FileBase::searchFileURL( strFileURL , rtl::OUString() , strResultPath );
2358 
2359         if ( rc == FileBase::E_None )
2360         {
2361             printf( "Result: \t\t\t");
2362             printFileName ( strResultPath );
2363             printf( "\n" );
2364         }
2365         else
2366             printf( "searchFileURL (with a FileURL path): Error\n" );
2367     }
2368     else
2369         printf( "searchFileURL (with a FileURL path): not tested\n" );
2370 
2371     //--------------------------------------------------
2372     // searchFileURL (with a systempath)
2373     //--------------------------------------------------
2374 
2375     if ( strSystemPath.getLength() != 0 )
2376     {
2377         printf( "\nSearch-Normalized-Path (with a SystemPath) : ");
2378         printFileName( strSystemPath );
2379         printf( "\n" );
2380 
2381         rc=FileBase::searchFileURL( strSystemPath , rtl::OUString() , strResultPath );
2382 
2383         if ( rc == FileBase::E_None )
2384         {
2385             printf( "Result: \t\t\t");
2386             printFileName( strResultPath );
2387             printf( "\n" );
2388         }
2389         else
2390             printf( "searchFileURL (with a systempath): Error\n" );
2391     }
2392     else
2393         printf( "searchFileURL (with a systempath): not tested\n" );
2394 
2395     //--------------------------------------------------
2396     // searchFileURL (File and no searchpath)
2397     //--------------------------------------------------
2398 
2399     printf( "\nsearchFileURL:  File (no searchpath) : ");
2400     printFileName( file3 );
2401     printf( "\n" );
2402 
2403     rc=FileBase::searchFileURL( file3 , rtl::OUString::createFromAscii("") , strResultPath );
2404 
2405     if ( rc == FileBase::E_None )
2406     {
2407         printf( "Result: \t\t\t");
2408         printFileName( strResultPath );
2409         printf( "\n" );
2410     }
2411     else
2412         printf( "searchFileURL:  File not found: OK ! \n" );
2413 
2414     //--------------------------------------------------
2415     // searchFileURL (File and Path)
2416     //--------------------------------------------------
2417 
2418     printf( "\nsearchFileURL:  File : ");
2419     printFileName( file3 );
2420     printf( "\tSearchPath ");
2421     printFileName( dir1 );
2422     printf( "\n");
2423 
2424     rc=FileBase::searchFileURL( file3 , dir1 , strResultPath );
2425 
2426     if ( rc == FileBase::E_None )
2427     {
2428         printf( "Result: \t\t\t");
2429         printFileName( strResultPath );
2430         printf( "\n");
2431     }
2432     else
2433         printf( "searchFileURL:  File not found: Error\n" );
2434 
2435     //------------------------------------------------------------
2436     // searchFileURL (File and searchpath with two entries)
2437     //------------------------------------------------------------
2438 
2439     rtl::OUString       strSearchPath( dir_not_exist );
2440     strSearchPath+=rtl::OUString::createFromAscii(";");
2441     strSearchPath+=dir_on_server;
2442 
2443     printf( "\nsearchFileURL:  File : ");
2444     printFileName( file3 );
2445     printf( "SearchPath ");
2446     printFileName( strSearchPath );
2447     printf( "\n");
2448 
2449     rc=FileBase::searchFileURL( file3 , strSearchPath , strResultPath );
2450 
2451     if ( rc == FileBase::E_None )
2452     {
2453         printf( "Result: \t\t\t");
2454         printFileName( strResultPath );
2455         printf( "\n" );
2456     }
2457     else
2458         printf( "searchFileURL:  File not found: Error\n" );
2459 
2460     //-------------------------------------------------------------------
2461     // searchFileURL (File and searchpath (with a wrong semantic))
2462     //-------------------------------------------------------------------
2463 
2464     strSearchPath=rtl::OUString( dir_wrong_semantic );
2465 
2466     printf( "\nsearchFileURL:  File : ");
2467     printFileName( file3 );
2468     printf( "SearchPath ");
2469     printFileName( strSearchPath );
2470     printf( "\n");
2471 
2472     rc=FileBase::searchFileURL( file3 , strSearchPath , strResultPath );
2473 
2474     if ( rc == FileBase::E_None )
2475         printf( "Error: Wrong Semantich but no error occurs !\n" );
2476     else
2477         printf( "searchFileURL:  File not found: OK !\n" );
2478 
2479     return;
2480 }
2481 
2482 //--------------------------------------------------
2483 // CanonicalNameTest
2484 //--------------------------------------------------
2485 
getCanonicalNameTest(rtl::OUString strPath)2486 void getCanonicalNameTest(rtl::OUString strPath)
2487 {
2488     FileBase::RC    rc;
2489 
2490     rtl::OUString   strValid;
2491 
2492     printf( "Original-Name: \t\t");
2493     printFileName( strPath );
2494     printf( "\n" );
2495 
2496     rc=FileBase::getCanonicalName( strPath, strValid );
2497 
2498     if ( rc == FileBase::E_None)
2499     {
2500         printf( "Canonical-Name: \t");
2501         printFileName( strValid );
2502         printf( "\n");
2503 
2504     }
2505     else
2506         printf( "Canonical-Name: Error \n" );
2507 
2508     printf( "\n" );
2509     return;
2510 }
2511 
CanonicalNameTest(void)2512 void CanonicalNameTest(void)
2513 {
2514     printf( "--------------------------------------------\n" );
2515     printf( "CanonicalName-Test\n" );
2516     printf( "--------------------------------------------\n\n" );
2517 
2518     getCanonicalNameTest( dir1 );
2519     getCanonicalNameTest( dir_on_server );
2520     getCanonicalNameTest( file1 );
2521     getCanonicalNameTest( file_on_server );
2522 
2523     PressKey();
2524     return;
2525 }
2526 
2527 //--------------------------------------------------
2528 // print_error
2529 //--------------------------------------------------
2530 
print_error(::rtl::OString & str,FileBase::RC rc)2531 void print_error( ::rtl::OString& str, FileBase::RC rc )
2532 {
2533 
2534     printf( "%s : ",str.getStr() );
2535     switch(rc)
2536     {
2537     case FileBase::E_None:
2538         printf("OK !\n");
2539         break;
2540     case FileBase::E_PERM:
2541         printf("E_PERM\n");
2542         break;
2543     case FileBase::E_NOENT:
2544         printf("E_NOENT\n");
2545         break;
2546     case FileBase::E_SRCH:
2547         printf("E_SRCH\n");
2548         break;
2549     case FileBase::E_INTR:
2550         printf("E_INTR\n");
2551         break;
2552     case FileBase::E_IO:
2553         printf("E_IO\n");
2554         break;
2555     case FileBase::E_NXIO:
2556         printf("E_NXIO\n");
2557         break;
2558     case FileBase::E_2BIG:
2559         printf("E_2BIG\n");
2560         break;
2561     case FileBase::E_NOEXEC:
2562         printf("E_NOEXEC\n");
2563         break;
2564     case FileBase::E_BADF:
2565         printf("E_BADF\n");
2566         break;
2567     case FileBase::E_CHILD:
2568         printf("E_CHILD\n");
2569         break;
2570     case FileBase::E_AGAIN:
2571         printf("E_AGAIN\n");
2572         break;
2573     case FileBase::E_NOMEM:
2574         printf("E_NOMEM\n");
2575         break;
2576     case FileBase::E_ACCES:
2577         printf("E_ACCES\n");
2578         break;
2579     case FileBase::E_FAULT:
2580         printf("E_FAULT\n");
2581         break;
2582     case FileBase::E_BUSY:
2583         printf("E_BUSY\n");
2584         break;
2585     case FileBase::E_EXIST:
2586         printf("E_EXIST\n");
2587         break;
2588     case FileBase::E_XDEV:
2589         printf("E_XDEV\n");
2590         break;
2591     case FileBase::E_NODEV:
2592         printf("E_NODEV\n");
2593         break;
2594     case FileBase::E_NOTDIR:
2595         printf("E_NOTDIR\n");
2596         break;
2597     case FileBase::E_ISDIR:
2598         printf("E_ISDIR\n");
2599         break;
2600     case FileBase::E_INVAL:
2601         printf("E_INVAL\n");
2602         break;
2603     case FileBase::E_NFILE:
2604         printf("E_NFILE\n");
2605         break;
2606     case FileBase::E_MFILE:
2607         printf("E_MFILE\n");
2608         break;
2609     case FileBase::E_NOTTY:
2610         printf("E_NOTTY\n");
2611         break;
2612     case FileBase::E_FBIG:
2613         printf("E_FBIG\n");
2614         break;
2615     case FileBase::E_NOSPC:
2616         printf("E_NOSPC\n");
2617         break;
2618     case FileBase::E_SPIPE:
2619         printf("E_SPIPE\n");
2620         break;
2621     case FileBase::E_ROFS:
2622         printf("E_ROFS\n");
2623         break;
2624     case FileBase::E_MLINK:
2625         printf("E_MLINK\n");
2626         break;
2627     case FileBase::E_PIPE:
2628         printf("E_PIPE\n");
2629         break;
2630     case FileBase::E_DOM:
2631         printf("E_DOM\n");
2632         break;
2633     case FileBase::E_RANGE:
2634         printf("E_RANGE\n");
2635         break;
2636     case FileBase::E_DEADLK:
2637         printf("E_DEADLK\n");
2638         break;
2639     case FileBase::E_NAMETOOLONG:
2640         printf("E_NAMETOOLONG\n");
2641         break;
2642     case FileBase::E_NOLCK:
2643         printf("E_NOLCK\n");
2644         break;
2645     case FileBase::E_NOSYS:
2646         printf("E_NOSYS\n");
2647         break;
2648     case FileBase::E_NOTEMPTY:
2649         printf("E_NOTEMPTY\n");
2650         break;
2651     case FileBase::E_LOOP:
2652         printf("E_LOOP\n");
2653         break;
2654     case FileBase::E_ILSEQ:
2655         printf("E_ILSEQ\n");
2656         break;
2657     case FileBase::E_NOLINK:
2658         printf("E_NOLINK\n");
2659         break;
2660     case FileBase::E_MULTIHOP:
2661         printf("E_MULTIHOP\n");
2662         break;
2663     case FileBase::E_USERS:
2664         printf("E_USERS\n");
2665         break;
2666     case FileBase::E_OVERFLOW:
2667         printf("E_OVERFLOW\n");
2668         break;
2669     default:
2670         printf("E_Unknown\n");
2671         break;
2672     }
2673     return;
2674 }
2675 
2676 //--------------------------------------------------
2677 // main
2678 //--------------------------------------------------
2679 #if defined WNT
2680         #define MAIN _cdecl main
2681 #else
2682         #define MAIN main
2683 #endif
2684 
MAIN(int argc,char * argv[])2685 int MAIN( int argc, char* argv[] )
2686 {
2687     sal_Bool fSuccess=sal_False;
2688 
2689     //Initialization
2690     fSuccess=Initialize();
2691     if ( !fSuccess )
2692     {
2693         printf("Error during Initialization");
2694         return -1;
2695     }
2696 
2697 
2698     if (argc==1)
2699     {
2700         DirectoryOpenAndCloseTest();
2701         DirectoryCreateAndRemoveTest();
2702 
2703         FileOpenAndCloseTest();
2704         FileCreateAndRemoveTest();
2705         FileWriteAndReadTest();
2706         FileCopyAndMoveTest();
2707         FileSizeTest();
2708         FilePointerTest();
2709         FileAttributesTest();
2710         FileTimeTest();
2711         DirectoryItemTest();
2712         DirectoryFileStatusTest();
2713         VolumeFileStatusTest();
2714         FileFileStatusTest();
2715         VolumeInfoTest();
2716         FileBaseTest();
2717         SearchPathTest();
2718         AbsolutePathTest();
2719         CanonicalNameTest();
2720     }
2721     // command line arguments ?
2722     else
2723     {
2724         int i=1;
2725 
2726         while (i<argc)
2727         {
2728             if (strcmp(argv[i], "doc")==0)
2729                 DirectoryOpenAndCloseTest();
2730             else if (strcmp(argv[i], "dcr")==0)
2731                 DirectoryCreateAndRemoveTest();
2732             else if (strcmp(argv[i], "foc")==0)
2733                 FileOpenAndCloseTest();
2734             else if (strcmp(argv[i], "fcr")==0)
2735                 FileCreateAndRemoveTest();
2736             else if (strcmp(argv[i], "fwr")==0)
2737                 FileWriteAndReadTest();
2738             else if (strcmp(argv[i], "fcm")==0)
2739                 FileCopyAndMoveTest();
2740             else if (strcmp(argv[i], "fs")==0)
2741                 FileSizeTest();
2742             else if (strcmp(argv[i], "fp")==0)
2743                 FilePointerTest();
2744             else if (strcmp(argv[i], "fa")==0)
2745                 FileAttributesTest();
2746             else if (strcmp(argv[i], "ft")==0)
2747                 FileTimeTest();
2748             else if (strcmp(argv[i], "di")==0)
2749                 DirectoryItemTest();
2750             else if (strcmp(argv[i], "dfs")==0)
2751                 DirectoryFileStatusTest();
2752             else if (strcmp(argv[i], "vfs")==0)
2753                 VolumeFileStatusTest();
2754             else if (strcmp(argv[i], "ffs")==0)
2755                 FileFileStatusTest();
2756             else if (strcmp(argv[i], "vi")==0)
2757                 VolumeInfoTest();
2758             else if (strcmp(argv[i], "fb")==0)
2759                 FileBaseTest();
2760             else if (strcmp(argv[i], "sp")==0)
2761                 SearchPathTest();
2762             else if (strcmp(argv[i], "ap")==0)
2763                 AbsolutePathTest();
2764             else if (strcmp(argv[i], "cn")==0)
2765                 CanonicalNameTest();
2766 
2767             i++;
2768         }
2769     }
2770 
2771     // Shutdown
2772     fSuccess=Shutdown();
2773     if ( !fSuccess )
2774     {
2775         printf("Error during Shutdown");
2776         return -1;
2777     }
2778 
2779     return 0;
2780 }
2781 
2782 
2783