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