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 //------------------------------------------------------------------------
28 // include files
29 //------------------------------------------------------------------------
30 #include <sal/types.h>
31 #include <rtl/ustring.hxx>
32 #include <rtl/ustrbuf.hxx>
33
34 #include "osl/thread.h"
35
36 #include "rtl/ustrbuf.hxx"
37 #include <osl/file.hxx>
38 #include <osl_File_Const.h>
39
40 #include <testshl/simpleheader.hxx>
41
42 // #ifdef WNT
43 // # define UNICODE
44 // # define WIN32_LEAN_AND_MEAN
45 // # include <windows.h>
46 // # include <tchar.h>
47 // #endif
48
49
50 using namespace osl;
51 using namespace rtl;
52
53 //------------------------------------------------------------------------
54 // helper functions
55 //------------------------------------------------------------------------
56
57 /** detailed wrong message.
58 */
errorToString(const::osl::FileBase::RC _nError)59 inline ::rtl::OString errorToString( const ::osl::FileBase::RC _nError )
60 {
61 ::rtl::OString sResult;
62 switch ( _nError ) {
63 case ::osl::FileBase::E_None:
64 sResult = "Success";
65 break;
66 case ::osl::FileBase::E_PERM:
67 sResult = "Operation not permitted";
68 break;
69 case ::osl::FileBase::E_NOENT:
70 sResult = "No such file or directory";
71 break;
72 case ::osl::FileBase::E_EXIST:
73 sResult = "Already Exist";
74 break;
75 case ::osl::FileBase::E_ACCES:
76 sResult = "Permission denied";
77 break;
78 case ::osl::FileBase::E_INVAL:
79 sResult = "The format of the parameters was not valid";
80 break;
81 case ::osl::FileBase::E_NOTDIR:
82 sResult = "Not a directory";
83 break;
84 case ::osl::FileBase::E_ISDIR:
85 sResult = "Is a directory";
86 break;
87 case ::osl::FileBase::E_BADF:
88 sResult = "Bad file";
89 break;
90 case ::osl::FileBase::E_NOTEMPTY:
91 sResult = "The directory is not empty";
92 break;
93 default:
94 sResult = "Unknown Error";
95 break;
96 }
97 return sResult;
98 }
99
errorToStr(::osl::FileBase::RC const & nError)100 rtl::OUString errorToStr( ::osl::FileBase::RC const& nError)
101 {
102 rtl::OUStringBuffer suBuf;
103 suBuf.append( rtl::OUString::createFromAscii("The returned error is: ") );
104 suBuf.append( rtl::OStringToOUString(errorToString(nError), RTL_TEXTENCODING_ASCII_US) );
105 suBuf.append( rtl::OUString::createFromAscii("!\n") );
106 return suBuf.makeStringAndClear();
107 }
108
109 /** print a file type name.
110 */
printFileType(const::osl::FileStatus::Type nType)111 inline void printFileType( const ::osl::FileStatus::Type nType )
112 {
113 t_print( "#printFileType# " );
114 switch ( nType ) {
115 case ::osl::FileStatus::Directory:
116 t_print( "This file is a: Directory.\n" );
117 break;
118 case ::osl::FileStatus::Volume:
119 t_print( "This file is a: volume device.\n" );
120 break;
121 case ::osl::FileStatus::Regular:
122 t_print( "This file is a: regular file.\n" );
123 break;
124 case ::osl::FileStatus::Fifo:
125 t_print( "This file is a: fifo.\n" );
126 break;
127 case ::osl::FileStatus::Socket:
128 t_print( "This file is a: socket.\n" );
129 break;
130 case ::osl::FileStatus::Link:
131 t_print( "This file is a: link file.\n" );
132 break;
133 case ::osl::FileStatus::Special:
134 t_print( "This file is a: special.\n" );
135 break;
136 case ::osl::FileStatus::Unknown:
137 t_print( "The file type is unknown %d \n", nType );
138 break;
139 }
140 }
141
142 /** print a file attributes.
143 */
printFileAttributes(const sal_Int64 nAttributes)144 inline void printFileAttributes( const sal_Int64 nAttributes )
145 {
146 t_print( "#printFileAttributes# This file is a: (" );
147 if ( ( nAttributes | Attribute_ReadOnly ) == nAttributes )
148 t_print( " ReadOnly " );
149 if ( ( nAttributes | Attribute_Hidden ) == nAttributes )
150 t_print( " Hidden " );
151 if ( ( nAttributes | Attribute_Executable ) == nAttributes )
152 t_print( " Executable " );
153 if ( ( nAttributes | Attribute_GrpWrite ) == nAttributes )
154 t_print( " GrpWrite " );
155 if ( ( nAttributes | Attribute_GrpRead ) == nAttributes )
156 t_print( " GrpRead " );
157 if ( ( nAttributes | Attribute_GrpExe ) == nAttributes )
158 t_print( " GrpExe " );
159 if ( ( nAttributes | Attribute_OwnWrite ) == nAttributes )
160 t_print( " OwnWrite " );
161 if ( ( nAttributes | Attribute_OwnRead ) == nAttributes )
162 t_print( " OwnRead " );
163 if ( ( nAttributes | Attribute_OwnExe ) == nAttributes )
164 t_print( " OwnExe " );
165 if ( ( nAttributes | Attribute_OthWrite ) == nAttributes )
166 t_print( " OthWrite " );
167 if ( ( nAttributes | Attribute_OthRead ) == nAttributes )
168 t_print( " OthRead " );
169 if ( ( nAttributes | Attribute_OthExe ) == nAttributes )
170 t_print( " OthExe " );
171 t_print( ") file!\n" );
172 }
173
174 /** print a UNI_CODE file name.
175 */
printFileName(const::rtl::OUString & str)176 inline void printFileName( const ::rtl::OUString & str )
177 {
178 rtl::OString aString;
179
180 t_print( "#printFileName_u# " );
181 aString = ::rtl::OUStringToOString( str, RTL_TEXTENCODING_ASCII_US );
182 t_print( "%s\n", aString.getStr( ) );
183 }
184
185 /** print a ASCII_CODE file name.
186 */
printFileName(const sal_Char * str)187 inline void printFileName( const sal_Char * str )
188 {
189 t_print( "#printFileName_a# " );
190 t_print( "%s\n", str );
191 }
192
193 /** print an output wrong message.
194 */
printError(const::osl::FileBase::RC nError)195 inline void printError( const ::osl::FileBase::RC nError )
196 {
197 t_print( "#printError# " );
198 printFileName( errorToStr(nError) );
199 }
200
201 /** print an signed Integer Number.
202 */
printInt(sal_Int64 i)203 inline void printInt( sal_Int64 i )
204 {
205 t_print( "#printInt_i64# " );
206 t_print( "The Integer64 is %lld\n", i);
207 }
208
209 /** print an unsigned Integer Number.
210 */
printInt(sal_uInt64 i)211 inline void printInt( sal_uInt64 i )
212 {
213 t_print( "#printInt_u64# " );
214 t_print( "The unsigned Integer64 is %llu\n", i);
215 }
216
217 /** print Boolean value.
218 */
printBool(sal_Bool bOk)219 inline void printBool( sal_Bool bOk )
220 {
221 t_print( "#printBool# " );
222 ( sal_True == bOk ) ? t_print( "YES!\n" ): t_print( "NO!\n" );
223 }
224
225 /** print struct TimeValue in local time format.
226 */
printTime(TimeValue * tv)227 inline void printTime( TimeValue *tv )
228 {
229 oslDateTime *pDateTime = ( oslDateTime* )malloc( sizeof( oslDateTime ) ) ;
230 CPPUNIT_ASSERT_MESSAGE( "Error in printTime() function,malloc ", pDateTime != NULL );
231 TimeValue *pLocalTV = ( TimeValue* )malloc( sizeof( TimeValue ) );
232 CPPUNIT_ASSERT_MESSAGE( "Error in printTime() function,malloc ", pLocalTV != NULL );
233
234 CPPUNIT_ASSERT_MESSAGE( "Error in printTime() function,osl_getLocalTimeFromSystemTime ",sal_True == osl_getLocalTimeFromSystemTime( tv, pLocalTV ) );
235 CPPUNIT_ASSERT_MESSAGE( "Error in printTime() function,osl_gepDateTimeFromTimeValue ",sal_True == osl_getDateTimeFromTimeValue( pLocalTV, pDateTime ) );
236
237 t_print( "#printTime# " );
238 t_print( " Time is: %d/%d/%d ", pDateTime->Month, pDateTime->Day, pDateTime->Year);
239 switch ( pDateTime->DayOfWeek )
240 {
241 case 0: t_print("Sun. "); break;
242 case 1: t_print("Mon. "); break;
243 case 2: t_print("Tue. "); break;
244 case 3: t_print("Thr. "); break;
245 case 4: t_print("Wen. "); break;
246 case 5: t_print("Fri. "); break;
247 case 6: t_print("Sat. "); break;
248 }
249 t_print( " %d:%d:%d %d nsecs\n", pDateTime->Hours, pDateTime->Minutes, pDateTime->Seconds, pDateTime->NanoSeconds);
250
251 free( pDateTime );
252 free( pLocalTV );
253 }
254
255 /** compare two TimeValue, unit is "ms", since Windows time precision is better than UNX.
256 */
257
258 #if ( defined UNX ) || ( defined OS2 ) //precision of time in Windows is better than UNX
259 # define delta 2000 //time precision, 2000ms
260 #else
261 # define delta 1800 //time precision, 1.8s
262 #endif
263
t_abs64(sal_Int64 _nValue)264 inline sal_Int64 t_abs64(sal_Int64 _nValue)
265 {
266 // std::abs() seems to have some ambiguity problems (so-texas)
267 // return abs(_nValue);
268 t_print("t_abs64(%ld)\n", _nValue);
269 // CPPUNIT_ASSERT(_nValue < 2147483647);
270
271 if (_nValue < 0)
272 {
273 _nValue = -_nValue;
274 }
275 return _nValue;
276 }
277
t_compareTime(TimeValue * m_aEndTime,TimeValue * m_aStartTime,sal_Int32 nDelta)278 inline sal_Bool t_compareTime( TimeValue *m_aEndTime, TimeValue *m_aStartTime, sal_Int32 nDelta)
279 {
280 // sal_uInt64 uTimeValue;
281 // sal_Int64 iTimeValue;
282 //
283 // iTimeValue = t_abs64(( tv1->Seconds - tv2->Seconds) * 1000000000 + tv1->Nanosec - tv2->Nanosec);
284 // uTimeValue = ( iTimeValue / 1000000 );
285
286 sal_Int32 nDeltaSeconds = m_aEndTime->Seconds - m_aStartTime->Seconds;
287 sal_Int32 nDeltaNanoSec = sal_Int32(m_aEndTime->Nanosec) - sal_Int32(m_aStartTime->Nanosec);
288 if (nDeltaNanoSec < 0)
289 {
290 nDeltaNanoSec = 1000000000 + nDeltaNanoSec;
291 nDeltaSeconds--;
292 }
293
294 sal_Int32 nDeltaMilliSec = (nDeltaSeconds * 1000) + (nDeltaNanoSec / 1000000);
295 return ( nDeltaMilliSec < nDelta );
296 }
297
298 /** compare two OUString file name.
299 */
compareFileName(const::rtl::OUString & ustr1,const::rtl::OUString & ustr2)300 inline sal_Bool compareFileName( const ::rtl::OUString & ustr1, const ::rtl::OUString & ustr2 )
301 {
302 sal_Bool bOk;
303 //on Windows, the seperatar is '\', so here change to '/', then compare
304 #if defined (WNT )
305 ::rtl::OUString ustr1new,ustr2new;
306 sal_Unicode reverseSlash = (sal_Unicode)'\\';
307
308 if (ustr1.lastIndexOf(reverseSlash) != -1)
309 ustr1new = ustr1.replace(reverseSlash,(sal_Unicode)'/');
310 else
311 ustr1new = ustr1;
312 if (ustr2.lastIndexOf(reverseSlash) != -1)
313 ustr2new = ustr2.replace(reverseSlash,(sal_Unicode)'/');
314 else
315 ustr2new = ustr2;
316 bOk = ustr1new.equalsIgnoreAsciiCase( ustr2new ) ;
317 #else
318 bOk = ustr1.equalsIgnoreAsciiCase( ustr2 );
319 #endif
320 return bOk;
321 }
322
323 /** compare a OUString and an ASCII file name.
324 */
compareFileName(const::rtl::OUString & ustr,const sal_Char * astr)325 inline sal_Bool compareFileName( const ::rtl::OUString & ustr, const sal_Char *astr )
326 {
327 (void)ustr;
328 ::rtl::OUString ustr1 = rtl::OUString::createFromAscii( astr );
329 sal_Bool bOk = ustr1.equalsIgnoreAsciiCase( ustr1 );
330
331 return bOk;
332 }
333
334 /** simple version to judge if a file name or directory name is a URL or a system path, just to see if it
335 is start with "file:///";.
336 */
isURL(const sal_Char * pathname)337 inline sal_Bool isURL( const sal_Char *pathname )
338 {
339 return ( 0 == strncmp( pathname, FILE_PREFIX, sizeof( FILE_PREFIX ) - 1 ) );
340 }
341
342 /** simple version to judge if a file name or directory name is a URL or a system path, just to see if it
343 is start with "file:///";.
344 */
isURL(const::rtl::OUString pathname)345 inline sal_Bool isURL( const ::rtl::OUString pathname )
346 {
347 return ( ( pathname.indexOf( aPreURL ) == 0 ) ? sal_True : sal_False );
348 }
349
350 /** concat two part to form a URL or system path, add PATH_SEPERATOR between them if necessary, add "file:///" to begining if necessary.
351 */
concatURL(::rtl::OUString & pathname1,const::rtl::OUString & pathname2)352 inline void concatURL( ::rtl::OUString & pathname1, const ::rtl::OUString & pathname2 )
353 {
354 //check if pathname1 is full qualified URL;
355 if ( !isURL( pathname1 ) )
356 {
357 ::rtl::OUString aPathName = pathname1.copy( 0 );
358 ::osl::FileBase::getFileURLFromSystemPath( pathname1, aPathName ); //convert if not full qualified URL
359 pathname1 = aPathName.copy( 0 );
360 }
361
362 sal_Int32 index = 0;
363 //check if '/' is in the end of pathname1 or at the begin of pathname2;
364 if ( ( ( index = pathname1.lastIndexOf( aSlashURL ) ) != ( pathname1.getLength( ) - 1 ) ) &&
365 ( ( index = pathname2.indexOf( aSlashURL ) ) != 0 ) )
366 pathname1 += aSlashURL;
367 pathname1 += pathname2;
368 }
369
370 /** create a temp test file using OUString name of full qualified URL or system path.
371 */
createTestFile(const::rtl::OUString filename)372 inline void createTestFile( const ::rtl::OUString filename )
373 {
374 ::rtl::OUString aPathURL = filename.copy( 0 );
375 ::osl::FileBase::RC nError;
376
377 if ( !isURL( filename ) )
378 ::osl::FileBase::getFileURLFromSystemPath( filename, aPathURL ); //convert if not full qualified URL
379
380 //::std::auto_ptr<File> pFile( new File( aPathURL ) );
381 File aFile(aPathURL);
382 //nError = pFile->open( OpenFlag_Read | OpenFlag_Write | OpenFlag_Create );
383 nError = aFile.open( OpenFlag_Read | OpenFlag_Write | OpenFlag_Create );
384 //CPPUNIT_ASSERT_MESSAGE( "In createTestFile Function: creation ", ( ::osl::FileBase::E_None == nError ) || ( nError == ::osl::FileBase::E_EXIST ) );
385 if ( ( ::osl::FileBase::E_None != nError ) && ( nError != ::osl::FileBase::E_EXIST ))
386 {
387 t_print("createTestFile failed!\n");
388 }
389 aFile.close();
390
391 }
392
393 /** create a temp test file using OUString name of full qualified URL or system path in a base directory.
394 */
createTestFile(const::rtl::OUString basename,const::rtl::OUString filename)395 inline void createTestFile( const ::rtl::OUString basename, const ::rtl::OUString filename )
396 {
397 ::rtl::OUString aBaseURL = basename.copy( 0 );
398
399 concatURL( aBaseURL, filename );
400 createTestFile( aBaseURL );
401 }
402
403 /** detete a temp test file using OUString name.
404 */
deleteTestFile(const::rtl::OUString filename)405 inline void deleteTestFile( const ::rtl::OUString filename )
406 {
407 // LLA: t_print("deleteTestFile\n");
408 ::rtl::OUString aPathURL = filename.copy( 0 );
409 ::osl::FileBase::RC nError;
410
411 if ( !isURL( filename ) )
412 ::osl::FileBase::getFileURLFromSystemPath( filename, aPathURL ); //convert if not full qualified URL
413
414 nError = ::osl::File::setAttributes( aPathURL, Attribute_GrpWrite| Attribute_OwnWrite| Attribute_OthWrite ); // if readonly, make writtenable.
415 CPPUNIT_ASSERT_MESSAGE( "In deleteTestFile Function: set writtenable ", ( ::osl::FileBase::E_None == nError ) || ( ::osl::FileBase::E_NOENT == nError ) );
416
417 nError = ::osl::File::remove( aPathURL );
418 CPPUNIT_ASSERT_MESSAGE( "In deleteTestFile Function: remove ", ( ::osl::FileBase::E_None == nError ) || ( nError == ::osl::FileBase::E_NOENT ) );
419 }
420
421 /** delete a temp test file using OUString name of full qualified URL or system path in a base directory.
422 */
deleteTestFile(const::rtl::OUString basename,const::rtl::OUString filename)423 inline void deleteTestFile( const ::rtl::OUString basename, const ::rtl::OUString filename )
424 {
425 ::rtl::OUString aBaseURL = basename.copy( 0 );
426
427 concatURL( aBaseURL, filename );
428 deleteTestFile( aBaseURL );
429 }
430
431 /** create a temp test directory using OUString name of full qualified URL or system path.
432 */
createTestDirectory(const::rtl::OUString dirname)433 inline void createTestDirectory( const ::rtl::OUString dirname )
434 {
435 ::rtl::OUString aPathURL = dirname.copy( 0 );
436 ::osl::FileBase::RC nError;
437
438 if ( !isURL( dirname ) )
439 ::osl::FileBase::getFileURLFromSystemPath( dirname, aPathURL ); //convert if not full qualified URL
440 nError = ::osl::Directory::create( aPathURL );
441 //CPPUNIT_ASSERT_MESSAGE( "In createTestDirectory Function: creation: ", ( ::osl::FileBase::E_None == nError ) || ( nError == ::osl::FileBase::E_EXIST ) );
442 if ( ( ::osl::FileBase::E_None != nError ) && ( nError != ::osl::FileBase::E_EXIST ))
443 t_print("createTestDirectory failed!\n");
444 }
445
446 /** create a temp test directory using OUString name of full qualified URL or system path in a base directory.
447 */
createTestDirectory(const::rtl::OUString basename,const::rtl::OUString dirname)448 inline void createTestDirectory( const ::rtl::OUString basename, const ::rtl::OUString dirname )
449 {
450 ::rtl::OUString aBaseURL = basename.copy( 0 );
451 ::rtl::OString aString;
452
453 concatURL( aBaseURL, dirname );
454 createTestDirectory( aBaseURL );
455 }
456
457 /** delete a temp test directory using OUString name of full qualified URL or system path.
458 */
deleteTestDirectory(const::rtl::OUString dirname)459 inline void deleteTestDirectory( const ::rtl::OUString dirname )
460 {
461 // LLA: t_print("deleteTestDirectory\n");
462 ::rtl::OUString aPathURL = dirname.copy( 0 );
463 ::osl::FileBase::RC nError;
464 // LLA: printFileName(aPathURL);
465 if ( !isURL( dirname ) )
466 ::osl::FileBase::getFileURLFromSystemPath( dirname, aPathURL ); //convert if not full qualified URL
467
468 ::osl::Directory testDir( aPathURL );
469 if ( testDir.isOpen( ) == sal_True )
470 {
471 // LLA: t_print("#close Dir\n");
472 testDir.close( ); //close if still open.
473 }
474
475 nError = ::osl::Directory::remove( aPathURL );
476 // LLA: printError(nError);
477 // LLA: if (( ::osl::FileBase::E_None == nError ))
478 // LLA: {
479 // LLA: t_print("nError == E_None\n");
480 // LLA: }
481 // LLA: else if ( ( nError == ::osl::FileBase::E_NOENT ))
482 // LLA: {
483 // LLA: t_print("nError == E_NOENT\n");
484 // LLA: }
485 // LLA: else
486 // LLA: {
487 // LLA: // t_print("nError == %d\n", nError);
488 // LLA: }
489 rtl::OUString strError = rtl::OUString::createFromAscii( "In deleteTestDirectory function: remove Directory ");
490 strError += aPathURL;
491 CPPUNIT_ASSERT_MESSAGE( strError, ( ::osl::FileBase::E_None == nError ) || ( nError == ::osl::FileBase::E_NOENT ) );
492 // LLA: if (! ( ::osl::FileBase::E_None == nError ) || ( nError == ::osl::FileBase::E_NOENT ))
493 // LLA: {
494 // LLA: t_print("In deleteTestDirectory function: remove\n");
495 // LLA: }
496 }
497
498 /** delete a temp test directory using OUString name of full qualified URL or system path in a base directory.
499 */
deleteTestDirectory(const::rtl::OUString basename,const::rtl::OUString dirname)500 inline void deleteTestDirectory( const ::rtl::OUString basename, const ::rtl::OUString dirname )
501 {
502 ::rtl::OUString aBaseURL = basename.copy( 0 );
503
504 concatURL( aBaseURL, dirname );
505 deleteTestDirectory( aBaseURL );
506 }
507
508
509 /** Check for the file and directory access right.
510 */
511 typedef enum {
512 osl_Check_Mode_Exist,
513 osl_Check_Mode_OpenAccess,
514 osl_Check_Mode_ReadAccess,
515 osl_Check_Mode_WriteAccess
516 } oslCheckMode;
517
518 // not used here
checkFile(const::rtl::OUString & str,oslCheckMode nCheckMode)519 inline sal_Bool checkFile( const ::rtl::OUString & str, oslCheckMode nCheckMode )
520 {
521 ::osl::FileBase::RC nError1, nError2;
522 ::osl::File testFile( str );
523 sal_Bool bCheckResult;
524
525 bCheckResult = sal_False;
526 nError1 = testFile.open ( OpenFlag_Read );
527 if ( ( ::osl::FileBase::E_NOENT != nError1 ) && ( ::osl::FileBase::E_ACCES != nError1 ) ){
528
529 switch ( nCheckMode ) {
530 case osl_Check_Mode_Exist:
531 /// check if the file is exist.
532 if ( ::osl::FileBase::E_None == nError1 )
533 bCheckResult = sal_True;
534 break;
535 case osl_Check_Mode_OpenAccess:
536 /// check if the file is openable.
537 if ( ::osl::FileBase::E_None == nError1 )
538 bCheckResult = sal_True;
539 break;
540 case osl_Check_Mode_WriteAccess:
541 /// check the file name and whether it can be write.
542 /// write chars into the file.
543 //testFile.close( );
544 //testFile.open( OpenFlag_Write );
545 sal_uInt64 nCount_write;
546 nError2 = testFile.write( pBuffer_Char, 10, nCount_write );
547 if ( ::osl::FileBase::E_None == nError2 )
548 bCheckResult = sal_True;
549 break;
550
551 default:
552 bCheckResult = sal_False;
553 }/// swith
554
555 nError2 = testFile.close( );
556 CPPUNIT_ASSERT_MESSAGE( " in CheckFile() function, close file ", nError2 == FileBase::E_None );
557
558 }
559
560 return bCheckResult;
561 }
562
563 //check if the file exist
ifFileExist(const::rtl::OUString & str)564 inline sal_Bool ifFileExist( const ::rtl::OUString & str )
565 {
566 sal_Bool bCheckResult = sal_False;
567
568 /*#ifdef WNT
569 ::rtl::OUString aUStr = str.copy( 0 );
570 if ( isURL( str ) )
571 ::osl::FileBase::getSystemPathFromFileURL( str, aUStr );
572
573 ::rtl::OString aString = ::rtl::OUStringToOString( aUStr, RTL_TEXTENCODING_ASCII_US );
574 const char *path = aString.getStr( );
575 if (( _access( path, 0 ) ) != -1 )
576 bCheckResult = sal_True;
577 #else*/
578 ::rtl::OString aString = ::rtl::OUStringToOString( str, RTL_TEXTENCODING_ASCII_US );
579 // const char *path = aString.getStr( );
580 ::osl::File testFile( str );
581 bCheckResult = ( osl::FileBase::E_None == testFile.open( OpenFlag_Read ) );
582 //if (bCheckResult)
583 //t_print("%s exist!\n", path);
584 //else
585 //t_print("%s not exist!\n", path);
586 //#endif
587 return bCheckResult;
588
589 }
590
591 //check if the file can be writen
ifFileCanWrite(const::rtl::OUString & str)592 inline sal_Bool ifFileCanWrite( const ::rtl::OUString & str )
593 {
594 sal_Bool bCheckResult = sal_False;
595 //on Windows, the file has no write right, but can be written
596 #ifdef WNT
597 ::rtl::OUString aUStr = str.copy( 0 );
598 if ( isURL( str ) )
599 ::osl::FileBase::getSystemPathFromFileURL( str, aUStr );
600
601 ::rtl::OString aString = ::rtl::OUStringToOString( aUStr, RTL_TEXTENCODING_ASCII_US );
602 const char *path = aString.getStr( );
603 if (( _access( path, 2 ) ) != -1 )
604 bCheckResult = sal_True;
605 //on UNX, just test if open success with OpenFlag_Write
606 #else
607 ::osl::File testFile( str );
608 bCheckResult = (osl::FileBase::E_None == testFile.open( OpenFlag_Write ));
609 #endif
610 return bCheckResult;
611 }
612
checkDirectory(const::rtl::OUString & str,oslCheckMode nCheckMode)613 inline sal_Bool checkDirectory( const ::rtl::OUString & str, oslCheckMode nCheckMode )
614 {
615 rtl::OUString aUString;
616 DirectoryItem rItem;
617 FileBase::RC rc;
618 sal_Bool bCheckResult= sal_False;
619
620 //::std::auto_ptr<Directory> pDir( new Directory( str ) );
621 Directory aDir( str );
622 rc = aDir.open( );
623
624 if ( ( ::osl::FileBase::E_NOENT != rc ) && ( ::osl::FileBase::E_ACCES != rc ) ){
625
626 switch ( nCheckMode ) {
627 case osl_Check_Mode_Exist:
628 if ( rc == ::osl::FileBase::E_None )
629 bCheckResult = sal_True;
630 break;
631 case osl_Check_Mode_OpenAccess:
632 if ( rc == ::osl::FileBase::E_None )
633 bCheckResult = sal_True;
634 break;
635 case osl_Check_Mode_ReadAccess:
636 //rc = pDir->getNextItem( rItem, 0 );
637 rc = aDir.getNextItem( rItem, 0 );
638 if ( ( rc == ::osl::FileBase::E_None ) || ( rc == ::osl::FileBase::E_NOENT ) )
639 bCheckResult = sal_True;
640 else
641 bCheckResult = sal_False;
642 break;
643 case osl_Check_Mode_WriteAccess:
644 ( ( aUString += str ) += aSlashURL ) += aTmpName2;
645 //if ( ( rc = pDir->create( aUString ) ) == ::osl::FileBase::E_None )
646 if ( ( rc = Directory::create( aUString ) ) == ::osl::FileBase::E_None )
647 {
648 bCheckResult = sal_True;
649 //rc = pDir->remove( aUString );
650 rc = Directory::remove( aUString );
651 CPPUNIT_ASSERT( rc == ::osl::FileBase::E_None );
652 }
653 else
654 bCheckResult = sal_False;
655 break;
656
657 default:
658 bCheckResult = sal_False;
659 }// switch
660
661 rc = aDir.close( );
662 CPPUNIT_ASSERT( rc == FileBase::E_None );
663
664 }//if
665
666 return bCheckResult;
667 }
668
669 /** construct error message
670 */
outputError(const::rtl::OUString & returnVal,const::rtl::OUString & rightVal,const sal_Char * msg="")671 inline ::rtl::OUString outputError( const ::rtl::OUString & returnVal, const ::rtl::OUString & rightVal, const sal_Char * msg = "")
672 {
673 ::rtl::OUString aUString;
674 if ( returnVal.equals( rightVal ) )
675 return aUString;
676 aUString += ::rtl::OUString::createFromAscii(msg);
677 aUString += ::rtl::OUString::createFromAscii(": the returned value is '");
678 aUString += returnVal;
679 aUString += ::rtl::OUString::createFromAscii("', but the value should be '");
680 aUString += rightVal;
681 aUString += ::rtl::OUString::createFromAscii("'.");
682 return aUString;
683 }
684
685 /** Change file mode, two version in UNIX and Windows;.
686 */
687 #if ( defined UNX ) || ( defined OS2 ) //chmod() method is differ in Windows
changeFileMode(::rtl::OUString & filepath,sal_Int32 mode)688 inline void changeFileMode( ::rtl::OUString & filepath, sal_Int32 mode )
689 {
690 rtl::OString aString;
691 rtl::OUString aUStr = filepath.copy( 0 );
692
693 if ( isURL( filepath ) )
694 ::osl::FileBase::getSystemPathFromFileURL( filepath, aUStr );
695 aString = ::rtl::OUStringToOString( aUStr, RTL_TEXTENCODING_ASCII_US );
696 chmod( aString.getStr( ), mode );
697 }
698 #else //Windows version
changeFileMode(::rtl::OUString & filepath,sal_Int32 mode)699 inline void changeFileMode( ::rtl::OUString & filepath, sal_Int32 mode )
700 {
701 (void)filepath;
702 (void)mode;
703 t_print("this method is not implemented yet");
704 }
705 #endif
706
707 inline ::rtl::OUString getCurrentPID( void );
708
709
710
711 //------------------------------------------------------------------------
712 // Beginning of the test cases for FileBase class
713 //------------------------------------------------------------------------
714 namespace osl_FileBase
715 {
716
717 #if 0 //~ this function has been deprecated
718 //---------------------------------------------------------------------
719 // testing the method
720 // static inline RC getCanonicalName( const ::rtl::OUString& ustrRequestedURL, ::rtl::OUString& ustrValidURL )
721 //
722 // The illegal characters are ;+=[]',\"*\\<>/?:|.
723 // because getCanonicalName method is not implemented yet and will be deprecated in the future, this test is not necessary.
724 //---------------------------------------------------------------------
725
726 class getCanonicalName:public CppUnit::TestFixture
727 {
728
729 public:
730 ::osl::FileBase::RC nError;
731
732 void getCanonicalName_001( )
733 {
734 ::rtl::OUString aUStr_ValidURL;
735 nError = ::osl::FileBase::getCanonicalName( aCanURL1, aUStr_ValidURL );
736
737 CPPUNIT_ASSERT_MESSAGE("test for getCanonicalName function: check valid and unused file name",
738 ( osl::FileBase::E_None == nError ) && aUStr_ValidURL.equalsIgnoreAsciiCase( aCanURL1 ) );
739 }
740
741 void getCanonicalName_002( )
742 {
743 ::rtl::OUString aUStr_ValidURL;
744
745 createTestFile( aCanURL1 );
746 nError = ::osl::FileBase::getCanonicalName( aCanURL1, aUStr_ValidURL );
747 deleteTestFile( aCanURL1 );
748
749 CPPUNIT_ASSERT_MESSAGE( " test for getCanonicalName function: an existed file name, should different from the request, it did not passed(W32)(UNX)",
750 ( osl::FileBase::E_None == nError ) && aUStr_ValidURL.equalsIgnoreAsciiCase( aCanURL1 ) );
751 }
752
753 void getCanonicalName_003( )
754 {
755 ::rtl::OUString aUStr_ValidURL;
756 nError = ::osl::FileBase::getCanonicalName ( aCanURL2, aUStr_ValidURL );
757
758 CPPUNIT_ASSERT_MESSAGE( " test for getCanonicalName function: invalid file name, should different from the request, it did not passed(W32)(UNX)",
759 ( osl::FileBase::E_None == nError ) && aUStr_ValidURL.equalsIgnoreAsciiCase( aCanURL2 ) );
760 }
761
762 CPPUNIT_TEST_SUITE( getCanonicalName );
763 CPPUNIT_TEST( getCanonicalName_001 );
764 CPPUNIT_TEST( getCanonicalName_002 );
765 CPPUNIT_TEST( getCanonicalName_003 );
766 CPPUNIT_TEST_SUITE_END( );
767 };// class getCanonicalName
768 #endif
769
770 //---------------------------------------------------------------------
771 // testing the method
772 // static inline RC getAbsoluteFileURL( const ::rtl::OUString& ustrBaseDirectoryURL,
773 // const ::rtl::OUString& ustrRelativeFileURL,
774 // ::rtl::OUString& ustrAbsoluteFileURL )
775 //---------------------------------------------------------------------
776
777 class getAbsoluteFileURL:public CppUnit::TestFixture
778 {
779 //::osl::FileBase aFileBase;
780 ::rtl::OUString aResultURL1, aResultURL2, aResultURL3, aResultURL4, aResultURL5, aResultURL6;
781 // ::osl::FileBase::RC nError;
782 sal_Bool bOk;
783
784 public:
785
786 void check_getAbsoluteFileURL( rtl::OUString const& _suBaseURL, rtl::OString const& _sRelativeURL, ::osl::FileBase::RC _nAssumeError, rtl::OUString const& _suAssumeResultStr );
787
788 void getAbsoluteFileURL_001_1();
789 void getAbsoluteFileURL_001_2();
790 void getAbsoluteFileURL_001_3();
791 void getAbsoluteFileURL_001_4();
792 void getAbsoluteFileURL_001_5();
793 void getAbsoluteFileURL_001_6();
794 void getAbsoluteFileURL_001_7();
795 void getAbsoluteFileURL_001_8();
796 void getAbsoluteFileURL_002();
797 void getAbsoluteFileURL_003();
798 void getAbsoluteFileURL_004();
799
800 CPPUNIT_TEST_SUITE( getAbsoluteFileURL );
801 CPPUNIT_TEST( getAbsoluteFileURL_001_1 );
802 CPPUNIT_TEST( getAbsoluteFileURL_001_2 );
803 CPPUNIT_TEST( getAbsoluteFileURL_001_3 );
804 CPPUNIT_TEST( getAbsoluteFileURL_001_4 );
805 CPPUNIT_TEST( getAbsoluteFileURL_001_5 );
806 CPPUNIT_TEST( getAbsoluteFileURL_001_6 );
807 CPPUNIT_TEST( getAbsoluteFileURL_001_7 );
808 CPPUNIT_TEST( getAbsoluteFileURL_001_8 );
809 CPPUNIT_TEST( getAbsoluteFileURL_002 );
810 CPPUNIT_TEST( getAbsoluteFileURL_003 );
811 CPPUNIT_TEST( getAbsoluteFileURL_004 );
812 CPPUNIT_TEST_SUITE_END( );
813
814 }; //class getAbsoluteFileURL
815
816 /* use coding format as same as getSystemPathFromFileURL
817 // initialization
818 void setUp( )
819 {
820 sal_Char pResultURL1[] = "/relative/file1";
821 sal_Char pResultURL2[] = "/relative/file2";
822 sal_Char pResultURL3[] = "/file3";
823 sal_Char pResultURL4[] = "/file4";
824 sal_Char pResultURL5[] = "/canonical.name";
825 sal_Char pResultURL6[] = "/relative/";
826 aResultURL1 = aUserDirectoryURL.concat( rtl::OUString::createFromAscii( pResultURL1 ) );
827 aResultURL2 = aUserDirectoryURL.concat( rtl::OUString::createFromAscii( pResultURL2 ) );
828 aResultURL3 = aUserDirectoryURL.concat( rtl::OUString::createFromAscii( pResultURL3 ) );
829 aResultURL4 = aUserDirectoryURL.concat( rtl::OUString::createFromAscii( pResultURL4 ) );
830 aResultURL5 = aUserDirectoryURL.concat( rtl::OUString::createFromAscii( pResultURL5 ) );
831 aResultURL6 = aUserDirectoryURL.concat( rtl::OUString::createFromAscii( pResultURL6 ) );
832 }
833
834 void tearDown( )
835 {
836 }
837
838 // test code
839 void getAbsoluteFileURL_001( )
840 {
841 ::rtl::OUString aUStr_AbsURL;
842
843 ::osl::FileBase::RC nError11 = aFileBase.getAbsoluteFileURL( aUserDirectoryURL, aRelURL1, aUStr_AbsURL );
844 ::rtl::OUString suError = ::rtl::OUString::createFromAscii("test for getAbsoluteFileURL(' ");
845 suError += aUserDirectoryURL;
846 suError += ::rtl::OUString::createFromAscii("', '");
847 suError += aRelURL1;
848 suError += ::rtl::OUString::createFromAscii("', '");
849 suError += aUStr_AbsURL;
850 suError += outputError( aUStr_AbsURL, aResultURL1, "' ),");
851
852 sal_Bool nError12 = aUStr_AbsURL.equals( aResultURL1 );
853 ::osl::FileBase::RC nError21 = aFileBase.getAbsoluteFileURL( aUserDirectoryURL, aRelURL2, aUStr_AbsURL );
854 sal_Bool nError22 = aUStr_AbsURL.equals( aResultURL2 );
855 ::osl::FileBase::RC nError31 = aFileBase.getAbsoluteFileURL( aUserDirectoryURL, aRelURL3, aUStr_AbsURL );
856 sal_Bool nError32 = aUStr_AbsURL.equals( aResultURL3 );
857 ::osl::FileBase::RC nError41 = aFileBase.getAbsoluteFileURL( aUserDirectoryURL, aRelURL4, aUStr_AbsURL );
858 sal_Bool nError42 = aUStr_AbsURL.equals( aResultURL4 );
859 ::osl::FileBase::RC nError61 = aFileBase.getAbsoluteFileURL( aUserDirectoryURL, aRelURL6, aUStr_AbsURL );
860 sal_Bool nError62 = aUStr_AbsURL.equals( aResultURL6 );
861 printFileName( aUStr_AbsURL );
862 printFileName( aResultURL6 );
863
864 CPPUNIT_ASSERT_MESSAGE("test for getAbsoluteFileURL function: valid file name with valid directory",
865 ( ::osl::FileBase::E_None == nError11 ) && ( sal_True == nError12 ) &&
866 ( ::osl::FileBase::E_None == nError21 ) && ( sal_True == nError22 ) &&
867 ( ::osl::FileBase::E_None == nError31 ) && ( sal_True == nError32 ) &&
868 ( ::osl::FileBase::E_None == nError41 ) && ( sal_True == nError42 ) &&
869 ( ::osl::FileBase::E_None == nError61 ) && ( sal_True == nError62 ) );
870 }
871
872
873 #if ( defined UNX ) || ( defined OS2 ) //Link is not defined in Windows
874 void getAbsoluteFileURL_002( )
875 {
876 ::rtl::OUString aUStr_AbsURL, aUStr_LnkFileSys( aTempDirectorySys ), aUStr_SrcFileSys( aTempDirectorySys );
877 ( ( aUStr_LnkFileSys += aSlashURL ) += getCurrentPID( ) ) += ::rtl::OUString::createFromAscii("/link.file");
878 ( ( aUStr_SrcFileSys += aSlashURL ) += getCurrentPID( ) ) += ::rtl::OUString::createFromAscii("/canonical.name");
879
880 rtl::OString strLinkFileName, strSrcFileName;
881 strLinkFileName = OUStringToOString( aUStr_LnkFileSys, RTL_TEXTENCODING_ASCII_US );
882 strSrcFileName = OUStringToOString( aUStr_SrcFileSys, RTL_TEXTENCODING_ASCII_US );
883
884 createTestFile( aCanURL1 );
885 sal_Int32 fd = symlink( strSrcFileName.getStr(), strLinkFileName.getStr() );
886 CPPUNIT_ASSERT( fd == 0 );
887
888 nError = aFileBase.getAbsoluteFileURL( aUserDirectoryURL, aLnkURL1, aUStr_AbsURL );
889 bOk = aUStr_AbsURL.equals( aResultURL5 );
890
891 ::rtl::OUString suError = ::rtl::OUString::createFromAscii("test for getAbsoluteFileURL(' ");
892 suError += aUserDirectoryURL;
893 suError += ::rtl::OUString::createFromAscii("', '");
894 suError += aLnkURL1;
895 suError += ::rtl::OUString::createFromAscii("', '");
896 suError += aUStr_AbsURL;
897 suError += outputError( aUStr_AbsURL, aResultURL5, "' ),");
898 //printFileName(suError);
899
900 deleteTestFile( aCanURL1 );
901 fd = remove( strLinkFileName.getStr() );
902 CPPUNIT_ASSERT( fd == 0 );
903
904 CPPUNIT_ASSERT_MESSAGE("test for getAbsoluteFileURL function: URL contain link( Solaris version )",
905 ( ::osl::FileBase::E_None == nError ) && ( sal_True == bOk ) );
906 }
907 #else //Windows version
908 void getAbsoluteFileURL_002( )
909 {
910 CPPUNIT_ASSERT_MESSAGE("test for getAbsoluteFileURL function: URL contain link( Windows version )",
911 1 );
912 }
913 #endif
914
915 void getAbsoluteFileURL_003( )
916 {
917 // LLA: may be a wrong test, aTmpName1 not a real URL
918 #if 0
919 ::rtl::OUString aUStr_AbsURL;
920
921 nError = aFileBase.getAbsoluteFileURL( aTmpName1, aRelURL1, aUStr_AbsURL ); //base dir invalid error
922 ::rtl::OUString suError = ::rtl::OUString::createFromAscii("test for getAbsoluteFileURL('");
923 suError += aTmpName1;
924 suError += ::rtl::OUString::createFromAscii("', '");
925 suError += aRelURL1;
926 suError += ::rtl::OUString::createFromAscii("', '");
927 suError += aUStr_AbsURL;
928 suError += ::rtl::OUString::createFromAscii("' ),Parameter is invalid. it ignore the invalid base in Windows, did not pass in (W32), the reason maybe caused by the similar bug with getSystemPathFromFileURL() ");
929
930 CPPUNIT_ASSERT_MESSAGE( suError, ( ::osl::FileBase::E_INVAL == nError ) );
931 #endif
932 }
933
934 //use ".." in relartive path, the BasePath must exist on the file system
935 void getAbsoluteFileURL_004( )
936 {
937 //create two level directories under $Temp/PID/
938 ::rtl::OUString aUStrUpBase = aUserDirectoryURL + ::rtl::OUString::createFromAscii("/test1");
939 createTestDirectory( aUStrUpBase );
940 ::rtl::OUString aUStrBase = aUserDirectoryURL + ::rtl::OUString::createFromAscii("/test1/dir1");
941 createTestDirectory( aUStrBase );
942
943 ::rtl::OUString aUStrRelar = ::rtl::OUString::createFromAscii("../../mytestfile");
944 ::rtl::OUString aUStr_AbsURL;
945 ::rtl::OUString aResultURL6 = aUserDirectoryURL + ::rtl::OUString::createFromAscii("/mytestfile");
946
947 nError = aFileBase.getAbsoluteFileURL( aUStrBase, aUStrRelar, aUStr_AbsURL );
948 bOk = aUStr_AbsURL.equals( aResultURL6 );
949 ::rtl::OUString suError = ::rtl::OUString::createFromAscii("test for getAbsoluteFileURL('");
950 suError += aUStrBase;
951 suError += ::rtl::OUString::createFromAscii("', '");
952 suError += aUStrRelar;
953 suError += ::rtl::OUString::createFromAscii("', '");
954 suError += aUStr_AbsURL;
955 suError += outputError( aUStr_AbsURL, aResultURL6, "' ), did not pass on Win32 ");
956
957 deleteTestDirectory( aUStrBase );
958 deleteTestDirectory( aUStrUpBase );
959
960 CPPUNIT_ASSERT_MESSAGE( suError, ( ::osl::FileBase::E_None == nError ) && ( sal_True == bOk ) );
961 }
962
963 CPPUNIT_TEST_SUITE( getAbsoluteFileURL );
964 CPPUNIT_TEST( getAbsoluteFileURL_001 );
965 CPPUNIT_TEST( getAbsoluteFileURL_002 );
966 CPPUNIT_TEST( getAbsoluteFileURL_003 );
967 CPPUNIT_TEST( getAbsoluteFileURL_004 );
968 CPPUNIT_TEST_SUITE_END( );
969 };// class getAbsoluteFileURL*/
970
check_getAbsoluteFileURL(rtl::OUString const & _suBaseURL,rtl::OString const & _sRelativeURL,::osl::FileBase::RC _nAssumeError,rtl::OUString const & _suAssumeResultStr)971 void getAbsoluteFileURL::check_getAbsoluteFileURL( rtl::OUString const& _suBaseURL, rtl::OString const& _sRelativeURL, ::osl::FileBase::RC _nAssumeError, rtl::OUString const& _suAssumeResultStr )
972 {
973 rtl::OUString suRelativeURL = rtl::OStringToOUString(_sRelativeURL, RTL_TEXTENCODING_UTF8);
974 rtl::OString sBaseURL = rtl::OUStringToOString(_suBaseURL, RTL_TEXTENCODING_UTF8);
975 rtl::OUString suResultURL;
976 osl::FileBase::RC nError = FileBase::getAbsoluteFileURL( _suBaseURL, suRelativeURL, suResultURL );
977 rtl::OString sResultURL = rtl::OUStringToOString( suResultURL, RTL_TEXTENCODING_UTF8);
978 rtl::OString sError = errorToString(nError);
979 t_print("getAbsoluteFileURL('%s','%s') deliver absolute URL: '%s', error '%s'\n", sBaseURL.getStr(), _sRelativeURL.getStr(),sResultURL.getStr(), sError.getStr() );
980 CPPUNIT_ASSERT_MESSAGE( "Assumption is wrong: error number is wrong", nError == _nAssumeError );
981 if ( nError == ::osl::FileBase::E_None )
982 {
983 sal_Bool bStrAreEqual = _suAssumeResultStr.equals( suResultURL );
984 CPPUNIT_ASSERT_MESSAGE( "Assumption is wrong: ResultURL is not equal to expected URL ", bStrAreEqual == sal_True );
985 }
986 }
987
getAbsoluteFileURL_001_1()988 void getAbsoluteFileURL::getAbsoluteFileURL_001_1()
989 {
990 rtl::OUString suAssume = aUserDirectoryURL.concat( rtl::OUString::createFromAscii("/relative/file1") );
991 check_getAbsoluteFileURL( aUserDirectoryURL, "relative/file1",::osl::FileBase::E_None, suAssume );
992 }
getAbsoluteFileURL_001_2()993 void getAbsoluteFileURL::getAbsoluteFileURL_001_2()
994 {
995 rtl::OUString suAssume = aUserDirectoryURL.concat( rtl::OUString::createFromAscii("/relative/file2") );
996 check_getAbsoluteFileURL( aUserDirectoryURL, "relative/./file2",::osl::FileBase::E_None, suAssume );
997 }
getAbsoluteFileURL_001_3()998 void getAbsoluteFileURL::getAbsoluteFileURL_001_3()
999 {
1000 rtl::OUString suAssume = aUserDirectoryURL.concat( rtl::OUString::createFromAscii("/file3") );
1001 check_getAbsoluteFileURL( aUserDirectoryURL, "relative/../file3",::osl::FileBase::E_None, suAssume );
1002 }
getAbsoluteFileURL_001_4()1003 void getAbsoluteFileURL::getAbsoluteFileURL_001_4()
1004 {
1005 rtl::OUString suAssume = aUserDirectoryURL.concat( rtl::OUString::createFromAscii("/file4") );
1006 check_getAbsoluteFileURL( aUserDirectoryURL, "././relative/../file4",::osl::FileBase::E_None, suAssume );
1007 }
getAbsoluteFileURL_001_5()1008 void getAbsoluteFileURL::getAbsoluteFileURL_001_5()
1009 {
1010 rtl::OUString suAssume;
1011 #if ( defined UNX )
1012 suAssume = aUserDirectoryURL.concat( rtl::OUString::createFromAscii("/relative/") );
1013 #else
1014 suAssume = aUserDirectoryURL.concat( rtl::OUString::createFromAscii("/relative") );
1015 #endif
1016 check_getAbsoluteFileURL( aUserDirectoryURL, "././relative/.",::osl::FileBase::E_None, suAssume );
1017 }
getAbsoluteFileURL_001_6()1018 void getAbsoluteFileURL::getAbsoluteFileURL_001_6()
1019 {
1020 rtl::OUString suAssume = aUserDirectoryURL.concat( rtl::OUString::createFromAscii("/.relative") );
1021 check_getAbsoluteFileURL( aUserDirectoryURL, "./.relative",::osl::FileBase::E_None, suAssume );
1022 }
getAbsoluteFileURL_001_7()1023 void getAbsoluteFileURL::getAbsoluteFileURL_001_7()
1024 {
1025 rtl::OUString suAssume;
1026 #if (defined UNX )
1027 suAssume = aUserDirectoryURL.concat( rtl::OUString::createFromAscii("/.a/") );
1028 #else //windows
1029 suAssume = aUserDirectoryURL.concat( rtl::OUString::createFromAscii("/.a") );
1030 #endif
1031 check_getAbsoluteFileURL( aUserDirectoryURL, "./.a/mydir/..",::osl::FileBase::E_None, suAssume );
1032 }
getAbsoluteFileURL_001_8()1033 void getAbsoluteFileURL::getAbsoluteFileURL_001_8()
1034 {
1035 rtl::OUString suAssume = aUserDirectoryURL.concat( rtl::OUString::createFromAscii("/tmp/ok") );
1036 #if ( defined UNX ) || ( defined OS2 )
1037 check_getAbsoluteFileURL( aUserDirectoryURL, "tmp//ok",::osl::FileBase::E_None, suAssume );
1038 #else
1039 check_getAbsoluteFileURL( aUserDirectoryURL, "tmp//ok",::osl::FileBase::E_INVAL, suAssume );
1040 #endif
1041 }
getAbsoluteFileURL_002()1042 void getAbsoluteFileURL::getAbsoluteFileURL_002()
1043 {
1044 #if ( defined UNX ) || ( defined OS2 ) //Link is not defined in Windows
1045 ::rtl::OUString aUStr_AbsURL, aUStr_LnkFileSys( aTempDirectorySys ), aUStr_SrcFileSys( aTempDirectorySys );
1046 ( ( aUStr_LnkFileSys += aSlashURL ) += getCurrentPID( ) ) += ::rtl::OUString::createFromAscii("/link.file");
1047 ( ( aUStr_SrcFileSys += aSlashURL ) += getCurrentPID( ) ) += ::rtl::OUString::createFromAscii("/canonical.name");
1048
1049 rtl::OString strLinkFileName, strSrcFileName;
1050 strLinkFileName = OUStringToOString( aUStr_LnkFileSys, RTL_TEXTENCODING_ASCII_US );
1051 strSrcFileName = OUStringToOString( aUStr_SrcFileSys, RTL_TEXTENCODING_ASCII_US );
1052
1053 createTestFile( aCanURL1 );
1054 sal_Int32 fd = symlink( strSrcFileName.getStr(), strLinkFileName.getStr() );
1055 CPPUNIT_ASSERT( fd == 0 );
1056 rtl::OString sLnkURL = OUStringToOString( aLnkURL1, RTL_TEXTENCODING_ASCII_US );
1057 rtl::OUString suAssume = aUserDirectoryURL.concat( rtl::OUString::createFromAscii("/canonical.name") );
1058 check_getAbsoluteFileURL( aUserDirectoryURL, sLnkURL, ::osl::FileBase::E_None, suAssume );
1059 deleteTestFile( aCanURL1 );
1060 fd = remove( strLinkFileName.getStr() );
1061 CPPUNIT_ASSERT( fd == 0 );
1062 #endif
1063 }
1064 //please see line# 930
getAbsoluteFileURL_003()1065 void getAbsoluteFileURL::getAbsoluteFileURL_003()
1066 {
1067 }
getAbsoluteFileURL_004()1068 void getAbsoluteFileURL::getAbsoluteFileURL_004()
1069 {
1070 //create two level directories under $Temp/PID/
1071 ::rtl::OUString aUStrUpBase = aUserDirectoryURL + ::rtl::OUString::createFromAscii("/test1");
1072 createTestDirectory( aUStrUpBase );
1073 ::rtl::OUString aUStrBase = aUserDirectoryURL + ::rtl::OUString::createFromAscii("/test1/dir1");
1074 createTestDirectory( aUStrBase );
1075
1076 ::rtl::OUString suAssume = aUserDirectoryURL.concat( ::rtl::OUString::createFromAscii("/mytestfile") );
1077 check_getAbsoluteFileURL( aUStrBase, "../../mytestfile" , ::osl::FileBase::E_None, suAssume );
1078 deleteTestDirectory( aUStrBase );
1079 deleteTestDirectory( aUStrUpBase );
1080 }
1081 //---------------------------------------------------------------------
1082 // testing two methods:
1083 // static inline RC getSystemPathFromFileURL( const ::rtl::OUString& ustrFileURL,
1084 // ::rtl::OUString& ustrSystemPath )
1085 // static RC getFileURLFromSystemPath( const ::rtl::OUString & ustrSystemPath,
1086 // ::rtl::OUString & ustrFileURL );
1087 //---------------------------------------------------------------------
1088 class SystemPath_FileURL:public CppUnit::TestFixture
1089 {
1090 //::osl::FileBase aFileBase;
1091 // ::rtl::OUString aUStr;
1092 // ::osl::FileBase::RC nError;
1093
1094 //void check_getSystemPathFromFileURL(rtl::OString const& _sURL, ::osl::FileBase::RC _nAssumeError, rtl::OString const& _sAssumeResultStr);
1095 void check_SystemPath_FileURL(rtl::OString const& _sSource, ::osl::FileBase::RC _nAssumeError, rtl::OString const& _sAssumeResultStr, sal_Bool bDirection = sal_True );
1096 void checkWNTBehaviour_getSystemPathFromFileURL(rtl::OString const& _sURL, ::osl::FileBase::RC _nAssumeError, rtl::OString const& _sWNTAssumeResultString );
1097 void checkUNXBehaviour_getSystemPathFromFileURL(rtl::OString const& _sURL, ::osl::FileBase::RC _nAssumeError, rtl::OString const& _sUnixAssumeResultString );
1098 void checkWNTBehaviour_getFileURLFromSystemPath(rtl::OString const& _sSysPath, ::osl::FileBase::RC _nAssumeError, rtl::OString const& _sWNTAssumeResultString);
1099 void checkUNXBehaviour_getFileURLFromSystemPath(rtl::OString const& _sSysPath, ::osl::FileBase::RC _nAssumeError, rtl::OString const& _sUnixAssumeResultString);
1100
1101 public:
1102 // test code.
1103 void getSystemPathFromFileURL_001_1( );
1104 void getSystemPathFromFileURL_001_2( );
1105 void getSystemPathFromFileURL_001_21( );
1106 void getSystemPathFromFileURL_001_22( );
1107 void getSystemPathFromFileURL_001_3( );
1108 void getSystemPathFromFileURL_001_31( );
1109 void getSystemPathFromFileURL_001_4( );
1110 void getSystemPathFromFileURL_001_41( );
1111 void getSystemPathFromFileURL_001_5( );
1112 void getSystemPathFromFileURL_001_51( );
1113 void getSystemPathFromFileURL_001_52( );
1114 void getSystemPathFromFileURL_001_53( );
1115 void getSystemPathFromFileURL_001_6( );
1116 void getSystemPathFromFileURL_001_61( );
1117 void getSystemPathFromFileURL_001_7( );
1118 void getSystemPathFromFileURL_001_71( );
1119 void getSystemPathFromFileURL_001_8( );
1120 void getSystemPathFromFileURL_001_81( );
1121 void getSystemPathFromFileURL_001_9( );
1122 void getSystemPathFromFileURL_001_91( );
1123 void getSystemPathFromFileURL_001_92( );
1124 void getSystemPathFromFileURL_004( );
1125 void getSystemPathFromFileURL_005( );
1126
1127 //test case fot getFileURLFromSystemPath
1128 void getFileURLFromSystemPath_001( );
1129 void getFileURLFromSystemPath_002( );
1130 void getFileURLFromSystemPath_003( );
1131 void getFileURLFromSystemPath_004( );
1132 void getFileURLFromSystemPath_005( );
1133
1134 CPPUNIT_TEST_SUITE( SystemPath_FileURL );
1135 CPPUNIT_TEST( getSystemPathFromFileURL_001_1 );
1136 CPPUNIT_TEST( getSystemPathFromFileURL_001_2 );
1137 CPPUNIT_TEST( getSystemPathFromFileURL_001_21 );
1138 CPPUNIT_TEST( getSystemPathFromFileURL_001_22 );
1139 CPPUNIT_TEST( getSystemPathFromFileURL_001_3 );
1140 CPPUNIT_TEST( getSystemPathFromFileURL_001_31 );
1141 CPPUNIT_TEST( getSystemPathFromFileURL_001_4 );
1142 CPPUNIT_TEST( getSystemPathFromFileURL_001_41 );
1143 CPPUNIT_TEST( getSystemPathFromFileURL_001_5 );
1144 CPPUNIT_TEST( getSystemPathFromFileURL_001_51 );
1145 CPPUNIT_TEST( getSystemPathFromFileURL_001_52 );
1146 CPPUNIT_TEST( getSystemPathFromFileURL_001_53 );
1147 CPPUNIT_TEST( getSystemPathFromFileURL_001_6 );
1148 CPPUNIT_TEST( getSystemPathFromFileURL_001_61 );
1149 CPPUNIT_TEST( getSystemPathFromFileURL_001_7 );
1150 CPPUNIT_TEST( getSystemPathFromFileURL_001_71 );
1151 CPPUNIT_TEST( getSystemPathFromFileURL_001_8 );
1152 CPPUNIT_TEST( getSystemPathFromFileURL_001_81 );
1153 CPPUNIT_TEST( getSystemPathFromFileURL_001_9 );
1154 CPPUNIT_TEST( getSystemPathFromFileURL_001_91 );
1155 CPPUNIT_TEST( getSystemPathFromFileURL_001_92 );
1156 CPPUNIT_TEST( getSystemPathFromFileURL_004 );
1157 CPPUNIT_TEST( getSystemPathFromFileURL_005 );
1158 CPPUNIT_TEST( getFileURLFromSystemPath_001 );
1159 CPPUNIT_TEST( getFileURLFromSystemPath_002 );
1160 CPPUNIT_TEST( getFileURLFromSystemPath_003 );
1161 CPPUNIT_TEST( getFileURLFromSystemPath_004 );
1162 CPPUNIT_TEST( getFileURLFromSystemPath_005 );
1163 CPPUNIT_TEST_SUITE_END( );
1164 };// class SystemPath_FileURL
1165
1166
1167 // test code.
1168
1169 /* void getSystemPathFromFileURL::check_getSystemPathFromFileURL(rtl::OString const& _sURL, ::osl::FileBase::RC _nAssumeError, rtl::OString const& _sAssumeResultStr)
1170 {
1171 // PRE: URL as String
1172 rtl::OUString suURL;
1173 rtl::OUString suStr;
1174 suURL = rtl::OStringToOUString(_sURL, RTL_TEXTENCODING_UTF8);
1175 ::osl::FileBase::RC nError = osl::FileBase::getSystemPathFromFileURL( suURL, suStr ); // start with /
1176
1177 // if the given string is gt length 0,
1178 // we check also this string
1179 rtl::OString sStr = rtl::OUStringToOString(suStr, RTL_TEXTENCODING_UTF8);
1180 rtl::OString sError = errorToString(nError);
1181 t_print("getSystemPathFromFileURL('%s') deliver system path: '%s', error '%s'\n", _sURL.getStr(), sStr.getStr(), sError.getStr() );
1182
1183 // rtl::OUString suStrEncode = rtl::Uri::encode(suStr, rtl_UriCharClassUnoParamValue, rtl_UriEncodeKeepEscapes, RTL_TEXTENCODING_UTF8);
1184 // sStr = rtl::OUStringToOString(suStr, RTL_TEXTENCODING_UTF8);
1185 // t_print("UTF8: %s\n", sStr.getStr() );
1186
1187 if (_sAssumeResultStr.getLength() > 0)
1188 {
1189 sal_Bool bStrAreEqual = _sAssumeResultStr.equals(sStr);
1190 CPPUNIT_ASSERT_MESSAGE( "Assumption is wrong",
1191 nError == _nAssumeError && bStrAreEqual == sal_True );
1192 }
1193 else
1194 {
1195 CPPUNIT_ASSERT_MESSAGE( "Assumption is wrong", nError == _nAssumeError );
1196 }
1197 }*/
1198
1199 // if bDirection==sal_True, check getSystemPathFromFileURL
1200 // if bDirection==sal_False, check getFileURLFromSystemPath
check_SystemPath_FileURL(rtl::OString const & _sSource,::osl::FileBase::RC _nAssumeError,rtl::OString const & _sAssumeResultStr,sal_Bool bDirection)1201 void SystemPath_FileURL::check_SystemPath_FileURL(rtl::OString const& _sSource, ::osl::FileBase::RC _nAssumeError, rtl::OString const& _sAssumeResultStr, sal_Bool bDirection)
1202 {
1203 // PRE: URL as String
1204 rtl::OUString suSource;
1205 rtl::OUString suStr;
1206 suSource = rtl::OStringToOUString(_sSource, RTL_TEXTENCODING_UTF8);
1207 ::osl::FileBase::RC nError;
1208 if ( bDirection == sal_True )
1209 nError = osl::FileBase::getSystemPathFromFileURL( suSource, suStr );
1210 else
1211 nError = osl::FileBase::getFileURLFromSystemPath( suSource, suStr );
1212
1213 // if the given string is gt length 0,
1214 // we check also this string
1215 rtl::OString sStr = rtl::OUStringToOString(suStr, RTL_TEXTENCODING_UTF8);
1216 rtl::OString sError = errorToString(nError);
1217 if ( bDirection == sal_True )
1218 t_print("getSystemPathFromFileURL('%s') deliver system path: '%s', error '%s'\n", _sSource.getStr(), sStr.getStr(), sError.getStr() );
1219 else
1220 t_print("getFileURLFromSystemPath('%s') deliver File URL: '%s', error '%s'\n", _sSource.getStr(), sStr.getStr(), sError.getStr() );
1221
1222 // rtl::OUString suStrEncode = rtl::Uri::encode(suStr, rtl_UriCharClassUnoParamValue, rtl_UriEncodeKeepEscapes, RTL_TEXTENCODING_UTF8);
1223 // sStr = rtl::OUStringToOString(suStr, RTL_TEXTENCODING_UTF8);
1224 // t_print("UTF8: %s\n", sStr.getStr() );
1225
1226 if (_sAssumeResultStr.getLength() > 0)
1227 {
1228 sal_Bool bStrAreEqual = _sAssumeResultStr.equals(sStr);
1229 CPPUNIT_ASSERT_MESSAGE( "Assumption is wrong",
1230 nError == _nAssumeError && bStrAreEqual == sal_True );
1231 }
1232 else
1233 {
1234 CPPUNIT_ASSERT_MESSAGE( "Assumption is wrong", nError == _nAssumeError );
1235 }
1236 }
checkWNTBehaviour_getSystemPathFromFileURL(rtl::OString const & _sURL,::osl::FileBase::RC _nAssumeError,rtl::OString const & _sWNTAssumeResultString)1237 void SystemPath_FileURL::checkWNTBehaviour_getSystemPathFromFileURL(rtl::OString const& _sURL, ::osl::FileBase::RC _nAssumeError, rtl::OString const& _sWNTAssumeResultString)
1238 {
1239 #if ( defined WNT )
1240 check_SystemPath_FileURL(_sURL, _nAssumeError, _sWNTAssumeResultString);
1241 #else
1242 (void)_sURL;
1243 (void)_nAssumeError;
1244 (void)_sWNTAssumeResultString;
1245 #endif
1246 }
1247
checkUNXBehaviour_getSystemPathFromFileURL(rtl::OString const & _sURL,::osl::FileBase::RC _nAssumeError,rtl::OString const & _sUnixAssumeResultString)1248 void SystemPath_FileURL::checkUNXBehaviour_getSystemPathFromFileURL(rtl::OString const& _sURL, ::osl::FileBase::RC _nAssumeError, rtl::OString const& _sUnixAssumeResultString)
1249 {
1250 #if ( defined UNX )
1251 check_SystemPath_FileURL(_sURL, _nAssumeError, _sUnixAssumeResultString);
1252 #else
1253 (void)_sURL;
1254 (void)_nAssumeError;
1255 (void)_sUnixAssumeResultString;
1256 #endif
1257 }
1258
checkWNTBehaviour_getFileURLFromSystemPath(rtl::OString const & _sSysPath,::osl::FileBase::RC _nAssumeError,rtl::OString const & _sWNTAssumeResultString)1259 void SystemPath_FileURL::checkWNTBehaviour_getFileURLFromSystemPath(rtl::OString const& _sSysPath, ::osl::FileBase::RC _nAssumeError, rtl::OString const& _sWNTAssumeResultString)
1260 {
1261 #if ( defined WNT )
1262 check_SystemPath_FileURL(_sSysPath, _nAssumeError, _sWNTAssumeResultString, sal_False );
1263 #else
1264 (void)_sSysPath;
1265 (void)_nAssumeError;
1266 (void)_sWNTAssumeResultString;
1267 #endif
1268 }
1269
checkUNXBehaviour_getFileURLFromSystemPath(rtl::OString const & _sSysPath,::osl::FileBase::RC _nAssumeError,rtl::OString const & _sUnixAssumeResultString)1270 void SystemPath_FileURL::checkUNXBehaviour_getFileURLFromSystemPath(rtl::OString const& _sSysPath, ::osl::FileBase::RC _nAssumeError, rtl::OString const& _sUnixAssumeResultString)
1271 {
1272 #if ( defined UNX )
1273 check_SystemPath_FileURL(_sSysPath, _nAssumeError, _sUnixAssumeResultString, sal_False );
1274 #else
1275 (void)_sSysPath;
1276 (void)_nAssumeError;
1277 (void)_sUnixAssumeResultString;
1278 #endif
1279 }
1280
1281 /** LLA: Test for getSystemPathFromFileURL()
1282 this test is splitted into 2 different OS tests,
1283 the first function checkUNXBehaviour... runs only on Unix based Systems,
1284 the second only on windows based systems
1285 the first parameter are a file URL where we want to get the system path of,
1286 the second parameter is the assumed error of the osl_getSystemPathFromFileURL() function,
1287 the thrid parameter is the assumed result string, the string will only test, if it's length is greater 0
1288 */
1289
getSystemPathFromFileURL_001_1()1290 void SystemPath_FileURL::getSystemPathFromFileURL_001_1()
1291 {
1292 rtl::OString sURL("");
1293 checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, "");
1294 checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, "");
1295 }
1296
getSystemPathFromFileURL_001_2()1297 void SystemPath_FileURL::getSystemPathFromFileURL_001_2()
1298 {
1299 rtl::OString sURL("/");
1300 checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, "");
1301 checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "\\");
1302 }
getSystemPathFromFileURL_001_21()1303 void SystemPath_FileURL::getSystemPathFromFileURL_001_21()
1304 {
1305 // rtl::OString sURL("%2f");
1306 rtl::OString sURL("%2F");
1307 checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "/"); // LLA: this is may be a BUG
1308 checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, "");
1309 }
getSystemPathFromFileURL_001_22()1310 void SystemPath_FileURL::getSystemPathFromFileURL_001_22()
1311 {
1312 rtl::OString sURL("file:///tmp%2Fmydir");
1313 checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, "");
1314 checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, "");
1315 }
getSystemPathFromFileURL_001_3()1316 void SystemPath_FileURL::getSystemPathFromFileURL_001_3()
1317 {
1318 rtl::OString sURL("a");
1319 checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "a");
1320 checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "a");
1321 }
getSystemPathFromFileURL_001_31()1322 void SystemPath_FileURL::getSystemPathFromFileURL_001_31()
1323 {
1324 rtl::OString sURL("tmpname");
1325 checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "tmpname");
1326 checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "tmpname");
1327 }
getSystemPathFromFileURL_001_4()1328 void SystemPath_FileURL::getSystemPathFromFileURL_001_4()
1329 {
1330 rtl::OString sURL("file://");
1331 checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "");
1332 checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, "");
1333 }
getSystemPathFromFileURL_001_41()1334 void SystemPath_FileURL::getSystemPathFromFileURL_001_41()
1335 {
1336 rtl::OString sURL("file://localhost/tmp");
1337 checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "");
1338 checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, "");
1339 }
getSystemPathFromFileURL_001_5()1340 void SystemPath_FileURL::getSystemPathFromFileURL_001_5()
1341 {
1342 rtl::OString sURL("file:///tmp");
1343 checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "/tmp");
1344 checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, "");
1345 }
getSystemPathFromFileURL_001_51()1346 void SystemPath_FileURL::getSystemPathFromFileURL_001_51()
1347 {
1348 rtl::OString sURL("file://c:/tmp");
1349 checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "c:/tmp"); // LLA: this is may be a BUG
1350 checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, "");
1351 }
getSystemPathFromFileURL_001_52()1352 void SystemPath_FileURL::getSystemPathFromFileURL_001_52()
1353 {
1354 rtl::OString sURL("file:///c:/tmp");
1355 checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "/c:/tmp");
1356 checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "c:\\tmp");
1357 }
getSystemPathFromFileURL_001_53()1358 void SystemPath_FileURL::getSystemPathFromFileURL_001_53()
1359 {
1360 // LLA: is this a legal file path?
1361 rtl::OString sURL("file:///c|/tmp");
1362 checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "/c|/tmp");
1363 checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "c:\\tmp");
1364 }
getSystemPathFromFileURL_001_6()1365 void SystemPath_FileURL::getSystemPathFromFileURL_001_6()
1366 {
1367 rtl::OString sURL("file:///tmp/first");
1368 checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "/tmp/first");
1369 checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, "");
1370 }
getSystemPathFromFileURL_001_61()1371 void SystemPath_FileURL::getSystemPathFromFileURL_001_61()
1372 {
1373 rtl::OString sURL("file:///c:/tmp/first");
1374 checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "/c:/tmp/first");
1375 checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "c:\\tmp\\first");
1376 }
getSystemPathFromFileURL_001_7()1377 void SystemPath_FileURL::getSystemPathFromFileURL_001_7()
1378 {
1379 rtl::OString sURL("file:///tmp/../second");
1380 checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "/tmp/../second"); // LLA: may be a BUG
1381 checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, "");
1382 }
getSystemPathFromFileURL_001_71()1383 void SystemPath_FileURL::getSystemPathFromFileURL_001_71()
1384 {
1385 rtl::OString sURL("file:///c:/tmp/../second");
1386 checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "/c:/tmp/../second");
1387 checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "c:\\tmp\\..\\second");
1388 }
getSystemPathFromFileURL_001_8()1389 void SystemPath_FileURL::getSystemPathFromFileURL_001_8()
1390 {
1391 rtl::OString sURL("../tmp");
1392 checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "../tmp");
1393 checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "..\\tmp");
1394 }
getSystemPathFromFileURL_001_81()1395 void SystemPath_FileURL::getSystemPathFromFileURL_001_81()
1396 {
1397 rtl::OString sURL("file://~/tmp");
1398 char* home_path;
1399 home_path = getenv("HOME");
1400 rtl::OString expResult(home_path);
1401 expResult += "/tmp";
1402 checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, expResult );
1403 // checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "\\tmp");
1404 }
getSystemPathFromFileURL_001_9()1405 void SystemPath_FileURL::getSystemPathFromFileURL_001_9()
1406 {
1407 rtl::OString sURL("file:///tmp/first%20second");
1408 checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "/tmp/first second");
1409 checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, "");
1410 }
getSystemPathFromFileURL_001_91()1411 void SystemPath_FileURL::getSystemPathFromFileURL_001_91()
1412 {
1413 rtl::OString sURL("file:///c:/tmp/first%20second");
1414 checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "/c:/tmp/first second");
1415 checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "c:\\tmp\\first second");
1416 }
1417
getSystemPathFromFileURL_001_92()1418 void SystemPath_FileURL::getSystemPathFromFileURL_001_92()
1419 {
1420 rtl::OString sURL("ca@#;+.,$///78no%01ni..name");
1421 checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "");
1422 checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, "");
1423 }
1424
1425 #if 0
1426 void SystemPath_FileURL::getSystemPathFromFileURL_003( )
1427 {
1428 // LLA: ???
1429 //!! seams to be, that the directories do not pass together
1430 ::rtl::OUString aUStr;
1431 ::rtl::OUString aRelativeURL = ::rtl::OUString::createFromAscii("../../relartive/file3");
1432 ::rtl::OUString aResultURL ( aSysPath4 );
1433 ::osl::FileBase::RC nError = osl::FileBase::getSystemPathFromFileURL( aRelativeURL, aUStr );
1434
1435 sal_Bool bOk = compareFileName( aUStr, aResultURL );
1436
1437 ::rtl::OUString suError = ::rtl::OUString::createFromAscii("test for getSystemPathFromFileURL(");
1438 suError += aRelativeURL;
1439 suError += ::rtl::OUString::createFromAscii(") function:use a relative file URL, did not pass in(W32), it did not specified in method declaration of relative path issue, ");
1440 suError += outputError(aUStr, aResultURL);
1441 CPPUNIT_ASSERT_MESSAGE( suError, ( osl::FileBase::E_None == nError ) && ( sal_True == bOk ) );
1442 }
1443 #endif
1444
1445 //normal legal case
getSystemPathFromFileURL_004()1446 void SystemPath_FileURL::getSystemPathFromFileURL_004( )
1447 {
1448 ::rtl::OUString aUStr;
1449 ::rtl::OUString aNormalURL( aTmpName6 );
1450 ::rtl::OUString aResultURL ( aSysPath4 );
1451 ::osl::FileBase::RC nError = osl::FileBase::getSystemPathFromFileURL( aNormalURL, aUStr );
1452
1453 sal_Bool bOk = compareFileName( aUStr, aResultURL );
1454
1455 ::rtl::OUString suError = ::rtl::OUString::createFromAscii("test for getSystemPathFromFileURL(' ");
1456 suError += aNormalURL;
1457 suError += ::rtl::OUString::createFromAscii(" ') function:use an absolute file URL, ");
1458 suError += outputError(aUStr, aResultURL);
1459
1460 CPPUNIT_ASSERT_MESSAGE( suError, ( osl::FileBase::E_None == nError ) && ( sal_True == bOk ) );
1461
1462 }
1463
1464 //CJK charactors case
getSystemPathFromFileURL_005()1465 void SystemPath_FileURL::getSystemPathFromFileURL_005( )
1466 {
1467 ::rtl::OUString aUStr;
1468 createTestDirectory( aTmpName10 );
1469 ::rtl::OUString aNormalURL( aTmpName10 );
1470 ::rtl::OUString aResultURL ( aSysPath5 );
1471
1472 ::osl::FileBase::RC nError = osl::FileBase::getSystemPathFromFileURL( aNormalURL, aUStr );
1473
1474 sal_Bool bOk = compareFileName( aUStr, aResultURL );
1475
1476 ::rtl::OUString suError = ::rtl::OUString::createFromAscii("test for getSystemPathFromFileURL(' ");
1477 suError += aNormalURL;
1478 suError += ::rtl::OUString::createFromAscii(" ') function:use a CJK coded absolute URL, ");
1479 suError += outputError(aUStr, aResultURL);
1480 deleteTestDirectory( aTmpName10 );
1481
1482 CPPUNIT_ASSERT_MESSAGE( suError, ( osl::FileBase::E_None == nError ) && ( sal_True == bOk ) );
1483 }
getFileURLFromSystemPath_001()1484 void SystemPath_FileURL::getFileURLFromSystemPath_001()
1485 {
1486 rtl::OString sSysPath("~/tmp");
1487 char* home_path;
1488 home_path = getenv("HOME");
1489 rtl::OString expResult(home_path);
1490 expResult = "file://"+ expResult + "/tmp";
1491 checkUNXBehaviour_getFileURLFromSystemPath(sSysPath, osl::FileBase::E_None, expResult );
1492 checkWNTBehaviour_getFileURLFromSystemPath(sSysPath, osl::FileBase::E_None, "~/tmp");
1493 }
getFileURLFromSystemPath_002()1494 void SystemPath_FileURL::getFileURLFromSystemPath_002()
1495 {
1496 rtl::OString sSysPath("c:/tmp");
1497 checkUNXBehaviour_getFileURLFromSystemPath(sSysPath, osl::FileBase::E_None, "c:/tmp");
1498 checkWNTBehaviour_getFileURLFromSystemPath(sSysPath, osl::FileBase::E_None, "file:///c:/tmp");
1499 }
getFileURLFromSystemPath_003()1500 void SystemPath_FileURL::getFileURLFromSystemPath_003()
1501 {
1502 rtl::OString sSysPath("file:///temp");
1503 checkUNXBehaviour_getFileURLFromSystemPath(sSysPath, osl::FileBase::E_INVAL, "");
1504 checkWNTBehaviour_getFileURLFromSystemPath(sSysPath, osl::FileBase::E_INVAL, "");
1505 }
getFileURLFromSystemPath_004()1506 void SystemPath_FileURL::getFileURLFromSystemPath_004()
1507 {
1508 rtl::OString sSysPath("//tmp//first start");
1509 checkUNXBehaviour_getFileURLFromSystemPath(sSysPath, osl::FileBase::E_None, "file:///tmp/first%20start");
1510 checkWNTBehaviour_getFileURLFromSystemPath(sSysPath, osl::FileBase::E_INVAL, "");
1511 }
getFileURLFromSystemPath_005()1512 void SystemPath_FileURL::getFileURLFromSystemPath_005()
1513 {
1514 rtl::OString sSysPath("");
1515 checkUNXBehaviour_getFileURLFromSystemPath(sSysPath, osl::FileBase::E_INVAL, "");
1516 checkWNTBehaviour_getFileURLFromSystemPath(sSysPath, osl::FileBase::E_INVAL, "");
1517 }
1518 // start with "~user", not impletment
1519 // void SystemPath_FileURL::getFileURLFromSystemPath_006()
1520
1521
1522
1523
1524 //---------------------------------------------------------------------
1525 // testing the method
1526 // static inline RC searchFileURL( const ::rtl::OUString& ustrFileName,
1527 // const ::rtl::OUString& ustrSearchPath,
1528 // ::rtl::OUString& ustrFileURL )
1529 //---------------------------------------------------------------------
1530 class searchFileURL:public CppUnit::TestFixture
1531 {
1532 //::osl::FileBase aFileBase;
1533 ::rtl::OUString aUStr;
1534 ::osl::FileBase::RC nError1, nError2, nError3,nError4;
1535
1536 public:
1537
1538 // test code.
searchFileURL_001()1539 void searchFileURL_001( )
1540 {
1541 /* search file is passed by system filename */
1542 nError1 = ::osl::FileBase::searchFileURL( aTmpName1, aUserDirectorySys, aUStr );
1543 /* search file is passed by full qualified file URL */
1544 nError2 = ::osl::FileBase::searchFileURL( aCanURL1, aUserDirectorySys, aUStr );
1545 /* search file is passed by relative file path */
1546 nError3 = ::osl::FileBase::searchFileURL( aRelURL4, aUserDirectorySys, aUStr );
1547
1548 CPPUNIT_ASSERT_MESSAGE( "test for searchFileURL function: system filename/URL filename/relative path, system directory, searched files that is not exist, but it reply invalid error, did not pass in (W32) ",
1549 ( osl::FileBase::E_NOENT == nError1 ) &&
1550 ( osl::FileBase::E_NOENT == nError2 ) &&
1551 ( osl::FileBase::E_NOENT == nError3 ));
1552 }
1553
searchFileURL_002()1554 void searchFileURL_002( )
1555 {
1556 /* search file is passed by system filename */
1557 nError1 = ::osl::FileBase::searchFileURL( aTempDirectorySys, aRootSys, aUStr );
1558 sal_Bool bOk1 = compareFileName( aUStr, aTempDirectoryURL );
1559 /* search file is passed by full qualified file URL */
1560 nError2 = ::osl::FileBase::searchFileURL( aTempDirectoryURL, aRootSys, aUStr );
1561 sal_Bool bOk2 = compareFileName( aUStr, aTempDirectoryURL );
1562 /* search file is passed by relative file path */
1563 nError3 = ::osl::FileBase::searchFileURL( aRelURL5, aRootSys, aUStr );
1564 sal_Bool bOk3 = compareFileName( aUStr, aTempDirectoryURL );
1565 /* search file is passed by an exist file */
1566 createTestFile( aCanURL1 );
1567 nError4 = ::osl::FileBase::searchFileURL( aCanURL4, aUserDirectorySys, aUStr );
1568 sal_Bool bOk4 = compareFileName( aUStr, aCanURL1 );
1569 deleteTestFile( aCanURL1 );
1570
1571 CPPUNIT_ASSERT_MESSAGE( "test for searchFileURL function: system filename/URL filename/relative path, system directory, searched file already exist.",
1572 ( osl::FileBase::E_None == nError1 ) &&
1573 ( osl::FileBase::E_None == nError2 ) &&
1574 ( osl::FileBase::E_None == nError3 ) &&
1575 ( osl::FileBase::E_None == nError4 ) &&
1576 ( sal_True == bOk1 ) &&
1577 ( sal_True == bOk2 ) &&
1578 ( sal_True == bOk3 ) &&
1579 ( sal_True == bOk4 ) );
1580 }
1581
1582
searchFileURL_003()1583 void searchFileURL_003( )
1584 {
1585 OSLTEST_DECLARE( SystemPathList, TEST_PLATFORM_ROOT":"TEST_PLATFORM_ROOT TEST_PLATFORM_TEMP":"TEST_PLATFORM_ROOT"system/path" );
1586 nError1 = ::osl::FileBase::searchFileURL( aUserDirectoryURL, aSystemPathList, aUStr );
1587 sal_Bool bOk = compareFileName( aUStr, aUserDirectoryURL );
1588 CPPUNIT_ASSERT_MESSAGE( "test for searchFileURL function: search directory is a list of system paths",
1589 ( osl::FileBase::E_None == nError1 ) &&
1590 ( sal_True == bOk ) );
1591 }
1592
searchFileURL_004()1593 void searchFileURL_004( )
1594 {
1595 OSLTEST_DECLARE( SystemPathList, TEST_PLATFORM_ROOT PATH_LIST_DELIMITER TEST_PLATFORM_ROOT TEST_PLATFORM_TEMP PATH_LIST_DELIMITER TEST_PLATFORM_ROOT "system/path/../name" );
1596 nError1 = ::osl::FileBase::searchFileURL( aUserDirectoryURL, aSystemPathList, aUStr );
1597 sal_Bool bOk = compareFileName( aUStr, aUserDirectoryURL );
1598 CPPUNIT_ASSERT_MESSAGE( "test for searchFileURL function: search directory is a list of system paths",
1599 ( osl::FileBase::E_None == nError1 ) &&
1600 ( sal_True == bOk ) );
1601 }
1602
searchFileURL_005()1603 void searchFileURL_005( )
1604 {
1605 nError1 = ::osl::FileBase::searchFileURL( aUserDirectoryURL, aNullURL, aUStr );
1606 sal_Bool bOk = compareFileName( aUStr, aUserDirectoryURL );
1607 CPPUNIT_ASSERT_MESSAGE( "test for searchFileURL function: search directory is NULL",
1608 ( osl::FileBase::E_None == nError1 ) &&
1609 ( sal_True == bOk ) );
1610 }
1611
1612 CPPUNIT_TEST_SUITE( searchFileURL );
1613 CPPUNIT_TEST( searchFileURL_001 );
1614 CPPUNIT_TEST( searchFileURL_002 );
1615 CPPUNIT_TEST( searchFileURL_003 );
1616 CPPUNIT_TEST( searchFileURL_004 );
1617 CPPUNIT_TEST( searchFileURL_005 );
1618 CPPUNIT_TEST_SUITE_END( );
1619 };// class searchFileURL
1620
1621
1622 //---------------------------------------------------------------------
1623 // testing the method
1624 // static inline RC getTempDirURL( ::rtl::OUString& ustrTempDirURL )
1625 //---------------------------------------------------------------------
1626 class getTempDirURL:public CppUnit::TestFixture
1627 {
1628 //::osl::FileBase aFileBase;
1629 ::rtl::OUString aUStr;
1630 ::osl::FileBase::RC nError;
1631
1632 public:
1633 // initialization
setUp()1634 void setUp( )
1635 {
1636 nError = FileBase::getTempDirURL( aUStr );
1637 }
1638
tearDown()1639 void tearDown( )
1640 {
1641 }
1642
1643 // test code.
getTempDirURL_001()1644 void getTempDirURL_001( )
1645 {
1646
1647 CPPUNIT_ASSERT_MESSAGE( "test for getTempDirURL function: excution",
1648 ( osl::FileBase::E_None == nError ) );
1649 }
1650
getTempDirURL_002()1651 void getTempDirURL_002( )
1652 {
1653 CPPUNIT_ASSERT_MESSAGE( "test for getTempDirURL function: test for open and write access rights",
1654 checkDirectory( aUStr, osl_Check_Mode_OpenAccess ) &&
1655 checkDirectory( aUStr, osl_Check_Mode_ReadAccess ) &&
1656 checkDirectory( aUStr,osl_Check_Mode_WriteAccess ) );
1657 }
1658
1659 CPPUNIT_TEST_SUITE( getTempDirURL );
1660 CPPUNIT_TEST( getTempDirURL_001 );
1661 CPPUNIT_TEST( getTempDirURL_002 );
1662 CPPUNIT_TEST_SUITE_END( );
1663 };// class getTempDirURL
1664
1665
1666 //---------------------------------------------------------------------
1667 // testing the method
1668 // static inline RC createTempFile( ::rtl::OUString* pustrDirectoryURL,
1669 // oslFileHandle* pHandle,
1670 // ::rtl::OUString* pustrTempFileURL)
1671 //---------------------------------------------------------------------
1672 class createTempFile:public CppUnit::TestFixture
1673 {
1674 //::osl::FileBase aFileBase;
1675 ::osl::FileBase::RC nError1, nError2;
1676 sal_Bool bOK;
1677
1678 oslFileHandle *pHandle;
1679 ::rtl::OUString *pUStr_DirURL;
1680 ::rtl::OUString *pUStr_FileURL;
1681
1682 public:
1683
1684 // initialization
setUp()1685 void setUp( )
1686 {
1687 pHandle = new oslFileHandle();
1688 pUStr_DirURL = new ::rtl::OUString( aUserDirectoryURL );
1689 pUStr_FileURL = new ::rtl::OUString();
1690 //*pUStr_DirURL = aUserDirectoryURL; /// create temp file in /tmp/PID or c:\temp\PID.*/
1691 }
1692
tearDown()1693 void tearDown( )
1694 {
1695 delete pUStr_DirURL;
1696 delete pUStr_FileURL;
1697 delete pHandle;
1698 }
1699
1700 // test code.
createTempFile_001()1701 void createTempFile_001( )
1702 {
1703 nError1 = FileBase::createTempFile( pUStr_DirURL, pHandle, pUStr_FileURL );
1704 ::osl::File testFile( *pUStr_FileURL );
1705 //printFileName(*pUStr_FileURL);
1706 nError2 = testFile.open( OpenFlag_Create );
1707 if ( osl::FileBase::E_EXIST == nError2 ) {
1708 osl_closeFile( *pHandle );
1709 deleteTestFile( *pUStr_FileURL );
1710 }
1711
1712 CPPUNIT_ASSERT_MESSAGE( "test for createTempFile function: create temp file and test the existence",
1713 ( osl::FileBase::E_None == nError1 ) && ( pHandle != NULL ) && ( osl::FileBase::E_EXIST== nError2 ) );
1714 }
1715
createTempFile_002()1716 void createTempFile_002( )
1717 {
1718 bOK = sal_False;
1719 nError1 = FileBase::createTempFile( pUStr_DirURL, pHandle, pUStr_FileURL );
1720 ::osl::File testFile( *pUStr_FileURL );
1721 nError2 = testFile.open( OpenFlag_Create );
1722
1723 CPPUNIT_ASSERT_MESSAGE( "createTempFile function: create a temp file, but it does not exist",
1724 ( osl::FileBase::E_None == nError1 ) && ( pHandle != NULL ) &&
1725 ( osl::FileBase::E_EXIST == nError2 ) );
1726
1727 //check file if have the write permission
1728 if ( osl::FileBase::E_EXIST == nError2 ) {
1729 bOK = ifFileCanWrite( *pUStr_FileURL );
1730 osl_closeFile( *pHandle );
1731 deleteTestFile( *pUStr_FileURL );
1732 }
1733
1734 CPPUNIT_ASSERT_MESSAGE( "test for open and write access rights, in (W32), it did not have write access right, but it should be writtenable.",
1735 ( sal_True == bOK ) );
1736 }
1737
createTempFile_003()1738 void createTempFile_003( )
1739 {
1740 nError1 = FileBase::createTempFile( pUStr_DirURL, pHandle, 0 );
1741 //the temp file will be removed when return from createTempFile
1742 bOK = ( pHandle != NULL && pHandle != 0);
1743 if ( sal_True == bOK )
1744 osl_closeFile( *pHandle );
1745
1746 CPPUNIT_ASSERT_MESSAGE( "test for createTempFile function: set pUStrFileURL to 0 to let it remove the file after call.",
1747 ( ::osl::FileBase::E_None == nError1 ) &&( sal_True == bOK ) );
1748 }
createTempFile_004()1749 void createTempFile_004( )
1750 {
1751 nError1 = FileBase::createTempFile( pUStr_DirURL, 0, pUStr_FileURL );
1752 bOK = ( pUStr_FileURL != 0);
1753 ::osl::File testFile( *pUStr_FileURL );
1754 nError2 = testFile.open( OpenFlag_Create );
1755 deleteTestFile( *pUStr_FileURL );
1756 CPPUNIT_ASSERT_MESSAGE( "createTempFile function: create a temp file, but it does not exist",
1757 ( osl::FileBase::E_None == nError1 ) && ( osl::FileBase::E_EXIST == nError2 ) &&( sal_True == bOK ) );
1758
1759 }
1760
1761 CPPUNIT_TEST_SUITE( createTempFile );
1762 CPPUNIT_TEST( createTempFile_001 );
1763 CPPUNIT_TEST( createTempFile_002 );
1764 CPPUNIT_TEST( createTempFile_003 );
1765 CPPUNIT_TEST( createTempFile_004 );
1766 CPPUNIT_TEST_SUITE_END( );
1767 };// class createTempFile
1768
1769 // -----------------------------------------------------------------------------
1770 #if 0 //~ this function has been deprecated.
1771 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileBase::getCanonicalName, "osl_FileBase" );
1772 #endif
1773 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileBase::getAbsoluteFileURL, "osl_FileBase" );
1774 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileBase::SystemPath_FileURL, "osl_FileBase" );
1775 // CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileBase::getFileURLFromSystemPath, "osl_FileBase" );
1776 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileBase::searchFileURL, "osl_FileBase" );
1777 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileBase::getTempDirURL, "osl_FileBase" );
1778 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileBase::createTempFile, "osl_FileBase" );
1779 }// namespace osl_FileBase
1780
1781
1782 //------------------------------------------------------------------------
1783 // Beginning of the test cases for VolumeDevice class
1784 //------------------------------------------------------------------------
1785
1786 #if 0 //~ this Class has been deprecated
1787 namespace osl_VolumeDevice
1788 {
1789
1790 //---------------------------------------------------------------------
1791 // testing the method
1792 // VolumeDevice() : _aHandle( NULL )
1793 //---------------------------------------------------------------------
1794 class ctors : public CppUnit::TestFixture
1795 {
1796 ::osl::VolumeDevice aVolumeDevice;
1797 ::rtl::OUString aUStr;
1798 ::osl::FileBase::RC nError1, nError2;
1799
1800 public:
1801 // initialization
1802 void setUp( )
1803 {
1804 }
1805
1806 void tearDown( )
1807 {
1808 }
1809
1810 // test code.
1811 void ctors_001( )
1812 {
1813 ::osl::VolumeDevice aVolumeDevice1;
1814
1815 CPPUNIT_ASSERT_MESSAGE( "test for ctors function: Constructor for VolumeDevice with no args.",
1816 ( osl::FileBase::E_None != aVolumeDevice1.automount( ) ) &&
1817 ( osl::FileBase::E_None != aVolumeDevice1.unmount( ) ) &&
1818 ( aNullURL.equals( aVolumeDevice1.getMountPath( ) ) ) );
1819 }
1820
1821 void ctors_002( )
1822 {
1823 ::osl::VolumeInfo aVolumeInfo( VolumeInfoMask_Attributes );
1824 nError1 = ::osl::Directory::getVolumeInfo( aRootURL, aVolumeInfo );
1825 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
1826
1827 ::osl::VolumeDevice aVolumeDevice1( aVolumeInfo.getDeviceHandle( ) );
1828 sal_Bool bOk = compareFileName( aNullURL, aVolumeDevice1.getMountPath( ) );
1829 CPPUNIT_ASSERT_MESSAGE( "test for ctors function: Copy constructor for VolumeDevice, the copied VolumeDevice should have a mount path file:///, but it returned an empty OUString, it also may be the error from getDeviceHandle(), it did not pass in (UNX), (W32).",
1830 sal_False == bOk );
1831 }
1832
1833 void ctors_003( )
1834 {
1835 ::osl::VolumeInfo aVolumeInfo( VolumeInfoMask_Attributes );
1836 nError1 = ::osl::Directory::getVolumeInfo( aRootURL, aVolumeInfo );
1837 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
1838
1839 ::osl::VolumeDevice aVolumeDevice1 = aVolumeInfo.getDeviceHandle( );
1840 sal_Bool bOk = compareFileName( aNullURL, aVolumeDevice1.getMountPath( ) );
1841 CPPUNIT_ASSERT_MESSAGE( "test for ctors function: Assigned operator for VolumeDevice, the assigned VolumeDevice should have a mount path file:///, but it returned an empty OUString, it also may be the error from getDeviceHandle(),it did not pass in (UNX), (W32).",
1842 sal_False == bOk );
1843 }
1844
1845 CPPUNIT_TEST_SUITE( ctors );
1846 CPPUNIT_TEST( ctors_001 );
1847 CPPUNIT_TEST( ctors_002 );
1848 CPPUNIT_TEST( ctors_003 );
1849 CPPUNIT_TEST_SUITE_END( );
1850 };// class ctors
1851
1852
1853 //---------------------------------------------------------------------
1854 // testing the method
1855 // inline RC automount()
1856 //---------------------------------------------------------------------
1857 class automount : public CppUnit::TestFixture
1858 {
1859 ::osl::VolumeDevice aVolumeDevice;
1860 ::rtl::OUString aUStr;
1861 ::osl::FileBase::RC nError1, nError2;
1862
1863 public:
1864 // initialization
1865 void setUp( )
1866 {
1867 }
1868
1869 void tearDown( )
1870 {
1871
1872 }
1873
1874 // test code.
1875 void automount_001( )
1876 {
1877 ::osl::VolumeDevice aVolumeDevice1;
1878 nError1 = aVolumeDevice1.automount( );
1879
1880 CPPUNIT_ASSERT_MESSAGE( "test for automount function: invalid parameter.",
1881 ( osl::FileBase::E_INVAL == nError1 ) );
1882 }
1883
1884 void automount_002( )
1885 {
1886 ::osl::VolumeInfo aVolumeInfo( VolumeInfoMask_Attributes );
1887 nError1 = ::osl::Directory::getVolumeInfo( aVolURL2, aVolumeInfo );
1888 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
1889
1890 ::osl::VolumeDevice aVolumeDevice1( aVolumeInfo.getDeviceHandle( ) );
1891 nError1 = aVolumeDevice1.unmount( );
1892 nError1 = aVolumeDevice1.automount( );
1893 CPPUNIT_ASSERT_MESSAGE( "test for automount function: this test is not implemented yet, it did not pass in (UNX), (W32).",
1894 ( osl::FileBase::E_None == nError1 ) );
1895 }
1896
1897 CPPUNIT_TEST_SUITE( automount );
1898 CPPUNIT_TEST( automount_001 );
1899 CPPUNIT_TEST( automount_002 );
1900 CPPUNIT_TEST_SUITE_END( );
1901 };// class automount
1902
1903
1904 // -----------------------------------------------------------------------------
1905 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeDevice::ctors, "osl_VolumeDevice" );
1906 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeDevice::automount, "osl_VolumeDevice" );
1907 }// namespace osl_VolumeDevice
1908 #endif
1909
1910
1911 //------------------------------------------------------------------------
1912 // Beginning of the test cases for VolumeInfo class
1913 //------------------------------------------------------------------------
1914 namespace osl_VolumeInfo
1915 {
1916
1917 //---------------------------------------------------------------------
1918 // testing the method
1919 // VolumeInfo( sal_uInt32 nMask ): _nMask( nMask )
1920 //---------------------------------------------------------------------
1921 class ctors : public CppUnit::TestFixture
1922 {
1923 ::rtl::OUString aUStr;
1924 ::osl::FileBase::RC nError1, nError2;
1925
1926 ::osl::VolumeDevice aVolumeDevice1;
1927
1928 public:
1929 // initialization
setUp()1930 void setUp( )
1931 {
1932 }
1933
tearDown()1934 void tearDown( )
1935 {
1936 }
1937
1938 // test code.
ctors_001()1939 void ctors_001( )
1940 {
1941 ::osl::VolumeInfo aVolumeInfo( 0 );
1942 nError1 = ::osl::Directory::getVolumeInfo( aRootURL, aVolumeInfo );
1943 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
1944 sal_uInt64 uiTotalSpace = aVolumeInfo.getTotalSpace( );
1945 sal_uInt32 uiMaxPathLength = aVolumeInfo.getMaxPathLength( );
1946 aUStr = aVolumeInfo.getFileSystemName( );
1947
1948 CPPUNIT_ASSERT_MESSAGE( "test for ctors function: mask is empty",
1949 ( 0 == uiTotalSpace ) &&
1950 ( 0 == uiMaxPathLength ) &&
1951 sal_True == compareFileName( aUStr, aNullURL ) );
1952 }
1953
1954 #if ( defined UNX ) || ( defined OS2 )
ctors_002()1955 void ctors_002( )
1956 {
1957 ::osl::VolumeInfo aVolumeInfo( VolumeInfoMask_TotalSpace |
1958 VolumeInfoMask_UsedSpace |
1959 VolumeInfoMask_FileSystemName );
1960 nError1 = ::osl::Directory::getVolumeInfo( aVolURL4, aVolumeInfo );
1961 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
1962 //CPPUNIT_ASSERT( aVolumeInfo.isValid( mask ) );
1963 sal_uInt64 uiTotalSpace = aVolumeInfo.getTotalSpace( );
1964 sal_uInt64 uiUsedSpace = aVolumeInfo.getUsedSpace( );
1965 aUStr = aVolumeInfo.getFileSystemName( );
1966
1967 CPPUNIT_ASSERT_MESSAGE( "test for ctors function: mask is specified as certain valid fields, and get the masked fields",
1968 ( 0 != uiTotalSpace ) &&
1969 ( 0 != uiUsedSpace ) &&
1970 sal_True == compareFileName( aUStr, "nfs" ) );
1971 }
1972 #else /// Windows version,here we can not determine whichvolume in Windows is serve as an nfs volume.
ctors_002()1973 void ctors_002( )
1974 {
1975 CPPUNIT_ASSERT_MESSAGE( "test for ctors function: mask is specified as certain valid fields, and get the masked fields( Windows version )",
1976 1 == 1 );
1977 }
1978 #endif
1979
ctors_003()1980 void ctors_003( )
1981 {
1982
1983 sal_Int32 mask1 = VolumeInfoMask_FreeSpace;
1984 ::osl::VolumeInfo aVolumeInfo1( mask1 );
1985 nError1 = ::osl::Directory::getVolumeInfo( aRootURL, aVolumeInfo1 );
1986 CPPUNIT_ASSERT( sal_True == aVolumeInfo1.isValid( mask1 ) );
1987 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
1988
1989 sal_uInt64 uiTotalSpace1 = aVolumeInfo1.getTotalSpace( );
1990 aUStr = aVolumeInfo1.getFileSystemName( );
1991
1992 sal_Int32 mask2 = VolumeInfoMask_TotalSpace;
1993 ::osl::VolumeInfo aVolumeInfo2( mask2 );
1994 nError2 = ::osl::Directory::getVolumeInfo( aRootURL, aVolumeInfo2 );
1995 CPPUNIT_ASSERT( sal_True == aVolumeInfo2.isValid( mask2 ) );
1996 CPPUNIT_ASSERT( osl::FileBase::E_None == nError2 );
1997
1998 sal_uInt64 uiTotalSpace2 = aVolumeInfo2.getTotalSpace( );
1999
2000 CPPUNIT_ASSERT_MESSAGE( "test for ctors function: mask is specified as certain valid fields, but get unmasked fields, use mask to FreeSpace, but I can get TotalSpace, did not pass in (UNX)(W32)",
2001 ( 0 == uiTotalSpace1 ) && ( 0 != uiTotalSpace2 ) &&
2002 sal_True == compareFileName( aUStr, aNullURL ) );
2003 }
2004
2005 CPPUNIT_TEST_SUITE( ctors );
2006 CPPUNIT_TEST( ctors_001 );
2007 CPPUNIT_TEST( ctors_002 );
2008 CPPUNIT_TEST( ctors_003 );
2009 CPPUNIT_TEST_SUITE_END( );
2010 };// class ctors
2011
2012
2013 //---------------------------------------------------------------------
2014 // testing the method
2015 // inline sal_Bool isValid( sal_uInt32 nMask ) const
2016 //---------------------------------------------------------------------
2017 class isValid : public CppUnit::TestFixture
2018 {
2019 ::osl::VolumeDevice aVolumeDevice;
2020 ::rtl::OUString aUStr;
2021 ::osl::FileBase::RC nError1, nError2;
2022
2023 public:
2024 // initialization
setUp()2025 void setUp( )
2026 {
2027 }
2028
tearDown()2029 void tearDown( )
2030 {
2031
2032 }
2033
2034 // test code.
isValid_001()2035 void isValid_001( )
2036 {
2037 sal_Int32 mask = 0;
2038 ::osl::VolumeInfo aVolumeInfo( mask );
2039 nError1 = ::osl::Directory::getVolumeInfo( aVolURL4, aVolumeInfo );
2040 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2041
2042 CPPUNIT_ASSERT_MESSAGE( "test for isValid function: no fields specified.",
2043 sal_True == aVolumeInfo.isValid( mask ) );
2044 }
2045
2046 #if ( defined UNX ) || ( defined OS2 )
isValid_002()2047 void isValid_002( )
2048 {
2049 sal_Int32 mask = VolumeInfoMask_Attributes | VolumeInfoMask_TotalSpace | osl_VolumeInfo_Mask_UsedSpace |
2050 osl_VolumeInfo_Mask_FreeSpace | osl_VolumeInfo_Mask_MaxNameLength |
2051 osl_VolumeInfo_Mask_MaxPathLength | osl_VolumeInfo_Mask_FileSystemName;
2052 ::osl::VolumeInfo aVolumeInfo( mask );
2053 nError1 = ::osl::Directory::getVolumeInfo( aVolURL4, aVolumeInfo );
2054 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2055
2056 CPPUNIT_ASSERT_MESSAGE( "test for isValid function: all valid fields specified for a nfs volume.",
2057 sal_True == aVolumeInfo.isValid( mask ) );
2058 }
2059 #else /// Windows version,here we can not determine whichvolume in Windows is serve as an nfs volume.
isValid_002()2060 void isValid_002( )
2061 {
2062 CPPUNIT_ASSERT_MESSAGE( "test for isValid function: all valid fields specified for a nfs volume.( Windows version )",
2063 1 == 1 );
2064 }
2065 #endif
2066
isValid_003()2067 void isValid_003( )
2068 {
2069 ::osl::VolumeDevice aVolumeDevice1;
2070 sal_Int32 mask = VolumeInfoMask_Attributes;
2071 ::osl::VolumeInfo aVolumeInfo( mask );
2072 nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
2073 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2074 sal_Bool bOk1 = aVolumeInfo.isValid( mask );
2075
2076 nError1 = ::osl::Directory::getVolumeInfo( aVolURL2, aVolumeInfo );
2077 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2078 sal_Bool bOk2 = aVolumeInfo.isValid( mask );
2079
2080 CPPUNIT_ASSERT_MESSAGE( "test for isValid function: VolumeInfoMask_Attributes, it should be valid for some volume such as /, floppy, cdrom, etc. but it did not pass",
2081 ( sal_True == bOk1 ) && ( sal_True == bOk2 ) );
2082 }
2083
2084 CPPUNIT_TEST_SUITE( isValid );
2085 CPPUNIT_TEST( isValid_001 );
2086 CPPUNIT_TEST( isValid_002 );
2087 CPPUNIT_TEST( isValid_003 );
2088 CPPUNIT_TEST_SUITE_END( );
2089 };// class isValid
2090
2091 //---------------------------------------------------------------------
2092 // testing the method
2093 // inline sal_Bool getRemoteFlag() const
2094 //---------------------------------------------------------------------
2095 class getRemoteFlag : public CppUnit::TestFixture
2096 {
2097 ::osl::VolumeDevice aVolumeDevice;
2098 ::rtl::OUString aUStr;
2099 ::osl::FileBase::RC nError1, nError2;
2100
2101 public:
2102 // test code.
getRemoteFlag_001()2103 void getRemoteFlag_001( )
2104 {
2105 sal_Int32 mask = VolumeInfoMask_Attributes;
2106 ::osl::VolumeInfo aVolumeInfo( mask );
2107 nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
2108 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2109 sal_Bool bOk = aVolumeInfo.getRemoteFlag( );
2110
2111 CPPUNIT_ASSERT_MESSAGE( "test for getRemoteFlag function: get a volume device which is not remote.",
2112 ( sal_False == bOk ) );
2113 }
2114
2115 #if ( defined UNX ) || ( defined OS2 ) //remote Volume is different in Solaris and Windows
getRemoteFlag_002()2116 void getRemoteFlag_002( )
2117 {
2118 sal_Int32 mask = VolumeInfoMask_Attributes;
2119 ::osl::VolumeInfo aVolumeInfo( mask );
2120 nError1 = ::osl::Directory::getVolumeInfo( aVolURL4, aVolumeInfo );
2121 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2122 sal_Bool bOk = aVolumeInfo.getRemoteFlag( );
2123
2124 CPPUNIT_ASSERT_MESSAGE( "test for getRemoteFlag function: get a volume device which is remote( Solaris version ).",
2125 ( sal_True == bOk ) );
2126 }
2127 #else //Windows version
getRemoteFlag_002()2128 void getRemoteFlag_002( )
2129 {
2130 CPPUNIT_ASSERT_MESSAGE( "test for getRemoteFlag function: get a volume device which is remote( Windows version )",
2131 1 == 1 );
2132 }
2133 #endif
2134
2135 CPPUNIT_TEST_SUITE( getRemoteFlag );
2136 CPPUNIT_TEST( getRemoteFlag_001 );
2137 CPPUNIT_TEST( getRemoteFlag_002 );
2138 CPPUNIT_TEST_SUITE_END( );
2139 };// class getRemoteFlag
2140
2141 //---------------------------------------------------------------------
2142 // testing the method
2143 // inline sal_Bool getRemoveableFlag() const
2144 //---------------------------------------------------------------------
2145 class getRemoveableFlag : public CppUnit::TestFixture
2146 {
2147 ::osl::FileBase::RC nError1, nError2;
2148
2149 public:
2150 // test code.
getRemoveableFlag_001()2151 void getRemoveableFlag_001( )
2152 {
2153 sal_Int32 mask = VolumeInfoMask_Attributes;
2154 ::osl::VolumeInfo aVolumeInfo( mask );
2155 nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
2156 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2157 sal_Bool bOk = aVolumeInfo.getRemoveableFlag( );
2158
2159 CPPUNIT_ASSERT_MESSAGE( "test for getRemoveableFlag function: get a volume device which is not removable.",
2160 sal_False == bOk );
2161 }
2162
getRemoveableFlag_002()2163 void getRemoveableFlag_002( )
2164 {
2165 sal_Int32 mask = VolumeInfoMask_Attributes;
2166 ::osl::VolumeInfo aVolumeInfo( mask );
2167 nError1 = ::osl::Directory::getVolumeInfo( aVolURL2, aVolumeInfo );
2168 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2169 sal_Bool bOk = aVolumeInfo.getRemoveableFlag( );
2170
2171 CPPUNIT_ASSERT_MESSAGE( "test for getRemoveableFlag function: get a volume device which is removable, not sure, here we use floppy disk, but it did not pass.",
2172 sal_True == bOk );
2173 }
2174 CPPUNIT_TEST_SUITE( getRemoveableFlag );
2175 CPPUNIT_TEST( getRemoveableFlag_001 );
2176 CPPUNIT_TEST( getRemoveableFlag_002 );
2177 CPPUNIT_TEST_SUITE_END( );
2178 };// class getRemoveableFlag
2179
2180
2181 //---------------------------------------------------------------------
2182 // testing the method
2183 // inline sal_Bool getCompactDiscFlag() const
2184 //---------------------------------------------------------------------
2185 class getCompactDiscFlag : public CppUnit::TestFixture
2186 {
2187 ::osl::FileBase::RC nError1;
2188
2189 public:
2190 // test code.
getCompactDiscFlag_001()2191 void getCompactDiscFlag_001( )
2192 {
2193 sal_Int32 mask = VolumeInfoMask_Attributes;
2194 ::osl::VolumeInfo aVolumeInfo( mask );
2195 nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
2196 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2197 sal_Bool bOk = aVolumeInfo.getCompactDiscFlag( );
2198
2199 CPPUNIT_ASSERT_MESSAGE( "test for getCompactDiscFlag function: get a volume device which is not a cdrom.",
2200 ( sal_False == bOk ) );
2201 }
2202
getCompactDiscFlag_002()2203 void getCompactDiscFlag_002( )
2204 {
2205 sal_Int32 mask = VolumeInfoMask_Attributes;
2206 ::osl::VolumeInfo aVolumeInfo( mask );
2207 nError1 = ::osl::Directory::getVolumeInfo( aVolURL6, aVolumeInfo );
2208 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2209 sal_Bool bOk = aVolumeInfo.getCompactDiscFlag( );
2210
2211 CPPUNIT_ASSERT_MESSAGE( "test for getCompactDiscFlag function: get a cdrom volume device flag, it did not pass.",
2212 ( sal_True == bOk ) );
2213 }
2214 CPPUNIT_TEST_SUITE( getCompactDiscFlag );
2215 CPPUNIT_TEST( getCompactDiscFlag_001 );
2216 CPPUNIT_TEST( getCompactDiscFlag_002 );
2217 CPPUNIT_TEST_SUITE_END( );
2218 };// class getCompactDiscFlag
2219
2220
2221 //---------------------------------------------------------------------
2222 // testing the method
2223 // inline sal_Bool getFloppyDiskFlag() const
2224 //---------------------------------------------------------------------
2225 class getFloppyDiskFlag : public CppUnit::TestFixture
2226 {
2227 ::osl::FileBase::RC nError1;
2228
2229 public:
2230 // test code.
getFloppyDiskFlag_001()2231 void getFloppyDiskFlag_001( )
2232 {
2233 sal_Int32 mask = VolumeInfoMask_Attributes;
2234 ::osl::VolumeInfo aVolumeInfo( mask );
2235 nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
2236 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2237 sal_Bool bOk = aVolumeInfo.getFloppyDiskFlag( );
2238
2239 CPPUNIT_ASSERT_MESSAGE( "test for getFloppyDiskFlag function: get a volume device which is not a floppy disk.",
2240 ( sal_False == bOk ) );
2241 }
2242
getFloppyDiskFlag_002()2243 void getFloppyDiskFlag_002( )
2244 {
2245 sal_Int32 mask = VolumeInfoMask_Attributes;
2246 ::osl::VolumeInfo aVolumeInfo( mask );
2247 nError1 = ::osl::Directory::getVolumeInfo( aVolURL2, aVolumeInfo );
2248 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2249 sal_Bool bOk = aVolumeInfo.getFloppyDiskFlag( );
2250
2251 CPPUNIT_ASSERT_MESSAGE( "test for getFloppyDiskFlag function: get a floppy volume device flag, it did not pass.",
2252 ( sal_True == bOk ) );
2253 }
2254 CPPUNIT_TEST_SUITE( getFloppyDiskFlag );
2255 CPPUNIT_TEST( getFloppyDiskFlag_001 );
2256 CPPUNIT_TEST( getFloppyDiskFlag_002 );
2257 CPPUNIT_TEST_SUITE_END( );
2258 };// class getFloppyDiskFlag
2259
2260
2261 //---------------------------------------------------------------------
2262 // testing the method
2263 // inline sal_Bool getFixedDiskFlag() const
2264 //---------------------------------------------------------------------
2265 class getFixedDiskFlag : public CppUnit::TestFixture
2266 {
2267 ::osl::FileBase::RC nError1;
2268
2269 public:
2270 // test code.
getFixedDiskFlag_001()2271 void getFixedDiskFlag_001( )
2272 {
2273 sal_Int32 mask = VolumeInfoMask_Attributes;
2274 ::osl::VolumeInfo aVolumeInfo( mask );
2275 nError1 = ::osl::Directory::getVolumeInfo( aVolURL2, aVolumeInfo );
2276 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2277 sal_Bool bOk = aVolumeInfo.getFixedDiskFlag( );
2278
2279 CPPUNIT_ASSERT_MESSAGE( "test for getFixedDiskFlag function: get a volume device which is not a fixed disk.",
2280 ( sal_False == bOk ) );
2281 }
2282
getFixedDiskFlag_002()2283 void getFixedDiskFlag_002( )
2284 {
2285 sal_Int32 mask = VolumeInfoMask_Attributes;
2286 ::osl::VolumeInfo aVolumeInfo( mask );
2287 nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
2288 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2289 sal_Bool bOk = aVolumeInfo.getFixedDiskFlag( );
2290
2291 CPPUNIT_ASSERT_MESSAGE( "test for getFixedDiskFlag function: get a fixed disk volume device flag, it did not pass.",
2292 ( sal_True == bOk ) );
2293 }
2294 CPPUNIT_TEST_SUITE( getFixedDiskFlag );
2295 CPPUNIT_TEST( getFixedDiskFlag_001 );
2296 CPPUNIT_TEST( getFixedDiskFlag_002 );
2297 CPPUNIT_TEST_SUITE_END( );
2298 };// class getFixedDiskFlag
2299
2300 //---------------------------------------------------------------------
2301 // testing the method
2302 // inline sal_Bool getRAMDiskFlag() const
2303 //---------------------------------------------------------------------
2304 class getRAMDiskFlag : public CppUnit::TestFixture
2305 {
2306 ::osl::FileBase::RC nError1;
2307
2308 public:
2309 // test code.
getRAMDiskFlag_001()2310 void getRAMDiskFlag_001( )
2311 {
2312 sal_Int32 mask = VolumeInfoMask_Attributes;
2313 ::osl::VolumeInfo aVolumeInfo( mask );
2314 nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
2315 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2316 sal_Bool bOk = aVolumeInfo.getRAMDiskFlag( );
2317
2318 CPPUNIT_ASSERT_MESSAGE( "test for getRAMDiskFlag function: get a volume device which is not a RAM disk.",
2319 ( sal_False == bOk ) );
2320 }
2321
getRAMDiskFlag_002()2322 void getRAMDiskFlag_002( )
2323 {
2324 sal_Int32 mask = VolumeInfoMask_Attributes;
2325 ::osl::VolumeInfo aVolumeInfo( mask );
2326 nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
2327 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2328 sal_Bool bOk = aVolumeInfo.getRAMDiskFlag( );
2329
2330 CPPUNIT_ASSERT_MESSAGE( "test for getRAMDiskFlag function: FIX ME, don't know how to get a RAM disk flag, perhaps Windows 98 boot disk can create a RAM disk, it did not pass in (UNX)(W32).",
2331 ( sal_True == bOk ) );
2332 }
2333 CPPUNIT_TEST_SUITE( getRAMDiskFlag );
2334 CPPUNIT_TEST( getRAMDiskFlag_001 );
2335 CPPUNIT_TEST( getRAMDiskFlag_002 );
2336 CPPUNIT_TEST_SUITE_END( );
2337 };// class getRAMDiskFlag
2338
2339
2340 //---------------------------------------------------------------------
2341 // testing the method
2342 // inline sal_uInt64 getTotalSpace() const
2343 //---------------------------------------------------------------------
2344 class getTotalSpace : public CppUnit::TestFixture
2345 {
2346 ::osl::FileBase::RC nError1;
2347
2348 public:
2349 // test code.
getTotalSpace_001()2350 void getTotalSpace_001( )
2351 {
2352 sal_Int32 mask = VolumeInfoMask_TotalSpace;
2353 ::osl::VolumeInfo aVolumeInfo( mask );
2354 nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
2355 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2356 CPPUNIT_ASSERT( sal_True == aVolumeInfo.isValid( mask ) );
2357 sal_uInt64 uiTotalSpace = aVolumeInfo.getTotalSpace( );
2358
2359 CPPUNIT_ASSERT_MESSAGE( "test for getTotalSpace function: get total space of Fixed disk volume mounted on /, it should not be 0",
2360 0 != uiTotalSpace );
2361 }
2362
2363 #if defined( UNX )
getTotalSpace_002()2364 void getTotalSpace_002( )
2365 {
2366 sal_Int32 mask = VolumeInfoMask_TotalSpace;
2367 ::osl::VolumeInfo aVolumeInfo( mask );
2368 nError1 = ::osl::Directory::getVolumeInfo( aVolURL3, aVolumeInfo );
2369 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2370 CPPUNIT_ASSERT( sal_True == aVolumeInfo.isValid( mask ) );
2371 sal_uInt64 uiTotalSpace = aVolumeInfo.getTotalSpace( );
2372
2373 CPPUNIT_ASSERT_MESSAGE( "test for getTotalSpace function: get total space of /proc, it should be 0",
2374 0 == uiTotalSpace );
2375 }
2376 #else /// Windows version, in Windows, there is no /proc directory
getTotalSpace_002()2377 void getTotalSpace_002( )
2378 {
2379 CPPUNIT_ASSERT_MESSAGE( "test for getTotalSpace function:not applicable for /proc( Windows version )",
2380 1 == 1 );
2381 }
2382 #endif
2383
2384
2385
2386 #if defined(SOLARIS)
getTotalSpace_003()2387 void getTotalSpace_003( )
2388 {
2389 struct statvfs aStatFS;
2390 static const sal_Char name[] = "/";
2391
2392 memset (&aStatFS, 0, sizeof(aStatFS));
2393 statvfs( name, &aStatFS);
2394 sal_uInt64 TotalSpace = aStatFS.f_frsize * aStatFS.f_blocks ;
2395
2396 sal_Int32 mask = VolumeInfoMask_TotalSpace;
2397 ::osl::VolumeInfo aVolumeInfo( mask );
2398 nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
2399 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2400 CPPUNIT_ASSERT( sal_True == aVolumeInfo.isValid( mask ) );
2401 sal_uInt64 uiTotalSpace = aVolumeInfo.getTotalSpace( );
2402
2403 CPPUNIT_ASSERT_MESSAGE( "test for getTotalSpace function: get total space by hand, then compare with getTotalSpace, it did not pass",
2404 uiTotalSpace == TotalSpace );
2405 }
2406 #else /// Windows version
getTotalSpace_003()2407 void getTotalSpace_003( )
2408 {
2409 CPPUNIT_ASSERT_MESSAGE( "test for getTotalSpace function:not implemented yet( Windows version )",
2410 1 == 1 );
2411 }
2412 #endif
2413
2414 CPPUNIT_TEST_SUITE( getTotalSpace );
2415 CPPUNIT_TEST( getTotalSpace_001 );
2416 CPPUNIT_TEST( getTotalSpace_002 );
2417 CPPUNIT_TEST( getTotalSpace_003 );
2418 CPPUNIT_TEST_SUITE_END( );
2419 };// class getTotalSpace
2420
2421 //---------------------------------------------------------------------
2422 // testing the method
2423 // inline sal_uInt64 getFreeSpace() const
2424 //---------------------------------------------------------------------
2425 class getFreeSpace : public CppUnit::TestFixture
2426 {
2427 ::osl::FileBase::RC nError1;
2428
2429 public:
2430 // test code.
getFreeSpace_001()2431 void getFreeSpace_001( )
2432 {
2433 sal_Int32 mask = VolumeInfoMask_FreeSpace;
2434 ::osl::VolumeInfo aVolumeInfo( mask );
2435 nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
2436 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2437 CPPUNIT_ASSERT( sal_True == aVolumeInfo.isValid( mask ) );
2438 sal_uInt64 uiFreeSpace = aVolumeInfo.getFreeSpace( );
2439
2440 CPPUNIT_ASSERT_MESSAGE( "test for getFreeSpace function: get free space of Fixed disk volume mounted on /, it should not be 0, suggestion: returned value, -1 is better, since some times the free space may be 0",
2441 0 != uiFreeSpace );
2442 }
2443
2444 #if defined( UNX )
getFreeSpace_002()2445 void getFreeSpace_002( )
2446 {
2447 sal_Int32 mask = VolumeInfoMask_FreeSpace;
2448 ::osl::VolumeInfo aVolumeInfo( mask );
2449 nError1 = ::osl::Directory::getVolumeInfo( aVolURL3, aVolumeInfo );
2450 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2451 CPPUNIT_ASSERT( sal_True == aVolumeInfo.isValid( mask ) );
2452 sal_uInt64 uiFreeSpace = aVolumeInfo.getFreeSpace( );
2453
2454 CPPUNIT_ASSERT_MESSAGE( "test for getFreeSpace function: get free space of /proc, it should be 0",
2455 0 == uiFreeSpace );
2456 }
2457 #else /// Windows version, in Windows, there is no /proc directory
getFreeSpace_002()2458 void getFreeSpace_002( )
2459 {
2460 CPPUNIT_ASSERT_MESSAGE( "test for getFreeSpace function: not applicable for /proc( Windows version )",
2461 1 == 1 );
2462 }
2463 #endif
2464
2465
2466 #if defined(SOLARIS)
getFreeSpace_003()2467 void getFreeSpace_003( )
2468 {
2469 struct statvfs aStatFS;
2470 static const sal_Char name[] = "/";
2471
2472 memset (&aStatFS, 0, sizeof(aStatFS));
2473 statvfs( name, &aStatFS);
2474 sal_uInt64 FreeSpace = aStatFS.f_bfree * aStatFS.f_frsize ;
2475
2476 sal_Int32 mask = VolumeInfoMask_FreeSpace;
2477 ::osl::VolumeInfo aVolumeInfo( mask );
2478 nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
2479 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2480 CPPUNIT_ASSERT( sal_True == aVolumeInfo.isValid( mask ) );
2481 sal_uInt64 uiFreeSpace = aVolumeInfo.getFreeSpace( );
2482
2483 CPPUNIT_ASSERT_MESSAGE( "test for getFreeSpace function: get free space by hand, then compare with getFreeSpace, it did not pass",
2484 uiFreeSpace == FreeSpace );
2485 }
2486 #else //Windows version
getFreeSpace_003()2487 void getFreeSpace_003( )
2488 {
2489 CPPUNIT_ASSERT_MESSAGE( "test for getFreeSpace function: not implemented yet( Windows version )",
2490 1 == 1 );
2491 }
2492 #endif
2493
2494
2495 CPPUNIT_TEST_SUITE( getFreeSpace );
2496 CPPUNIT_TEST( getFreeSpace_001 );
2497 CPPUNIT_TEST( getFreeSpace_002 );
2498 CPPUNIT_TEST( getFreeSpace_003 );
2499 CPPUNIT_TEST_SUITE_END( );
2500 };// class getFreeSpace
2501
2502 //---------------------------------------------------------------------
2503 // testing the method
2504 // inline sal_uInt64 getUsedSpace() const
2505 //---------------------------------------------------------------------
2506 class getUsedSpace : public CppUnit::TestFixture
2507 {
2508 ::osl::FileBase::RC nError1;
2509
2510 public:
2511 // test code.
getUsedSpace_001()2512 void getUsedSpace_001( )
2513 {
2514 sal_Int32 mask = VolumeInfoMask_UsedSpace;
2515 ::osl::VolumeInfo aVolumeInfo( mask );
2516 nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
2517 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2518 CPPUNIT_ASSERT( sal_True == aVolumeInfo.isValid( mask ) );
2519 sal_uInt64 uiUsedSpace = aVolumeInfo.getUsedSpace( );
2520
2521 CPPUNIT_ASSERT_MESSAGE( "test for getUsedSpace function: get used space of Fixed disk volume mounted on /, it should not be 0, suggestion: returned value, -1 is better, since some times the used space may be 0",
2522 0 != uiUsedSpace );
2523 }
2524
2525 #if defined( UNX )
getUsedSpace_002()2526 void getUsedSpace_002( )
2527 {
2528 sal_Int32 mask = VolumeInfoMask_UsedSpace;
2529 ::osl::VolumeInfo aVolumeInfo( mask );
2530 nError1 = ::osl::Directory::getVolumeInfo( aVolURL3, aVolumeInfo );
2531 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2532 CPPUNIT_ASSERT( sal_True == aVolumeInfo.isValid( mask ) );
2533 sal_uInt64 uiUsedSpace = aVolumeInfo.getUsedSpace( );
2534
2535 CPPUNIT_ASSERT_MESSAGE( "test for getUsedSpace function: get used space of /proc, it should be 0",
2536 0 == uiUsedSpace );
2537 }
2538 #else /// Windows version, in Windows, there is no /proc directory
getUsedSpace_002()2539 void getUsedSpace_002( )
2540 {
2541 CPPUNIT_ASSERT_MESSAGE( "test for getUsedSpace function: not applicable for /proc( Windows version )",
2542 1 == 1 );
2543 }
2544 #endif
2545
2546
2547 #if defined(SOLARIS)
getUsedSpace_003()2548 void getUsedSpace_003( )
2549 {
2550 struct statvfs aStatFS;
2551 static const sal_Char name[] = "/";
2552
2553 memset (&aStatFS, 0, sizeof(aStatFS));
2554 statvfs( name, &aStatFS);
2555 sal_uInt64 UsedSpace = ( aStatFS.f_blocks - aStatFS.f_bavail ) * aStatFS.f_frsize;
2556
2557
2558 sal_Int32 mask = VolumeInfoMask_UsedSpace;
2559 ::osl::VolumeInfo aVolumeInfo( mask );
2560 nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
2561 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2562 CPPUNIT_ASSERT( sal_True == aVolumeInfo.isValid( mask ) );
2563 sal_uInt64 uiUsedSpace = aVolumeInfo.getUsedSpace( );
2564
2565 CPPUNIT_ASSERT_MESSAGE( "test for getUsedSpace function: get used space by hand, then compare with getUsedSpace, it did not pass",
2566 uiUsedSpace == UsedSpace );
2567 }
2568 #else //Windows version
getUsedSpace_003()2569 void getUsedSpace_003( )
2570 {
2571 CPPUNIT_ASSERT_MESSAGE( "test for getUsedSpace function: not implemented yet( Windows version )",
2572 1 == 1 );
2573 }
2574 #endif
2575
2576
2577 CPPUNIT_TEST_SUITE( getUsedSpace );
2578 CPPUNIT_TEST( getUsedSpace_001 );
2579 CPPUNIT_TEST( getUsedSpace_002 );
2580 CPPUNIT_TEST( getUsedSpace_003 );
2581 CPPUNIT_TEST_SUITE_END( );
2582 };// class getUsedSpace
2583
2584
2585 //---------------------------------------------------------------------
2586 // testing the method
2587 // inline sal_uInt32 getMaxNameLength() const
2588 //---------------------------------------------------------------------
2589 class getMaxNameLength : public CppUnit::TestFixture
2590 {
2591 ::osl::FileBase::RC nError1;
2592
2593 public:
2594 // test code.
getMaxNameLength_001()2595 void getMaxNameLength_001( )
2596 {
2597 sal_Int32 mask = VolumeInfoMask_MaxNameLength;
2598 ::osl::VolumeInfo aVolumeInfo( mask );
2599 nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
2600 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2601 CPPUNIT_ASSERT( sal_True == aVolumeInfo.isValid( mask ) );
2602 sal_uInt32 uiMaxNameLength = aVolumeInfo.getMaxNameLength( );
2603
2604 CPPUNIT_ASSERT_MESSAGE( "test for getMaxNameLength function: get max name length of Fixed disk volume mounted on /, it should not be 0",
2605 0 != uiMaxNameLength );
2606 }
2607
2608
2609 #if ( defined UNX ) || ( defined OS2 )
getMaxNameLength_002()2610 void getMaxNameLength_002( )
2611 {
2612 struct statvfs aStatFS;
2613 static const sal_Char name[] = "/";
2614
2615 memset (&aStatFS, 0, sizeof(aStatFS));
2616 statvfs( name, &aStatFS);
2617 sal_uInt64 MaxNameLength = aStatFS.f_namemax;
2618
2619 sal_Int32 mask = VolumeInfoMask_MaxNameLength;
2620 ::osl::VolumeInfo aVolumeInfo( mask );
2621 nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
2622 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2623 CPPUNIT_ASSERT( sal_True == aVolumeInfo.isValid( mask ) );
2624 sal_uInt64 uiMaxNameLength = aVolumeInfo.getMaxNameLength( );
2625
2626 CPPUNIT_ASSERT_MESSAGE( "test for getMaxNameLength function: get max name length by hand, then compare with getMaxNameLength",
2627 uiMaxNameLength == MaxNameLength );
2628 }
2629 #else //Windows version
getMaxNameLength_002()2630 void getMaxNameLength_002( )
2631 {
2632 CPPUNIT_ASSERT_MESSAGE( "test for getMaxNameLength function: not implemented yet( Windows version )",
2633 1 == 1 );
2634 }
2635 #endif
2636
2637 CPPUNIT_TEST_SUITE( getMaxNameLength );
2638 CPPUNIT_TEST( getMaxNameLength_001 );
2639 CPPUNIT_TEST( getMaxNameLength_002 );
2640 CPPUNIT_TEST_SUITE_END( );
2641 };// class getMaxNameLength
2642
2643
2644 //---------------------------------------------------------------------
2645 // testing the method
2646 // inline sal_uInt32 getMaxPathLength() const
2647 //---------------------------------------------------------------------
2648 class getMaxPathLength : public CppUnit::TestFixture
2649 {
2650 ::osl::FileBase::RC nError1;
2651
2652 public:
2653 // test code.
getMaxPathLength_001()2654 void getMaxPathLength_001( )
2655 {
2656 sal_Int32 mask = VolumeInfoMask_MaxPathLength;
2657 ::osl::VolumeInfo aVolumeInfo( mask );
2658 nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
2659 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2660 CPPUNIT_ASSERT( sal_True == aVolumeInfo.isValid( mask ) );
2661 sal_uInt32 uiMaxPathLength = aVolumeInfo.getMaxPathLength( );
2662
2663 CPPUNIT_ASSERT_MESSAGE( "test for getMaxPathLength function: get max path length of Fixed disk volume mounted on /, it should not be 0",
2664 0 != uiMaxPathLength );
2665 }
2666
2667
2668 #if ( defined UNX ) || ( defined OS2 )
getMaxPathLength_002()2669 void getMaxPathLength_002( )
2670 {
2671 sal_Int32 mask = VolumeInfoMask_MaxPathLength;
2672 ::osl::VolumeInfo aVolumeInfo( mask );
2673 nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
2674 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2675 CPPUNIT_ASSERT( sal_True == aVolumeInfo.isValid( mask ) );
2676 sal_uInt64 uiMaxPathLength = aVolumeInfo.getMaxPathLength( );
2677
2678 CPPUNIT_ASSERT_MESSAGE( "test for getMaxPathLength function: get max path length by hand, then compare with getMaxPathLength",
2679 uiMaxPathLength == PATH_MAX );
2680 }
2681 #else //Windows version
getMaxPathLength_002()2682 void getMaxPathLength_002( )
2683 {
2684 CPPUNIT_ASSERT_MESSAGE( "test for getMaxPathLength function: not implemented yet( Windows version )",
2685 1 == 1 );
2686 }
2687 #endif
2688
2689
2690 CPPUNIT_TEST_SUITE( getMaxPathLength );
2691 CPPUNIT_TEST( getMaxPathLength_001 );
2692 CPPUNIT_TEST( getMaxPathLength_002 );
2693 CPPUNIT_TEST_SUITE_END( );
2694 };// class getMaxPathLength
2695
2696
2697 //---------------------------------------------------------------------
2698 // testing the method
2699 // inline ::rtl::OUString getFileSystemName() const
2700 //---------------------------------------------------------------------
2701 class getFileSystemName : public CppUnit::TestFixture
2702 {
2703 ::rtl::OUString aUStr;
2704 ::osl::FileBase::RC nError1;
2705
2706 public:
2707 // test code.
getFileSystemName_001()2708 void getFileSystemName_001( )
2709 {
2710 sal_Int32 mask = VolumeInfoMask_FileSystemName;
2711 ::osl::VolumeInfo aVolumeInfo( mask );
2712 nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
2713 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2714 CPPUNIT_ASSERT( sal_True == aVolumeInfo.isValid( mask ) );
2715 aUStr = aVolumeInfo.getFileSystemName( );
2716
2717 CPPUNIT_ASSERT_MESSAGE( "test for getFileSystemName function: get file system name of Fixed disk volume mounted on /, it should not be empty string",
2718 sal_False == compareFileName( aNullURL, aUStr ) );
2719 }
2720
2721
2722 #if defined(SOLARIS)
getFileSystemName_002()2723 void getFileSystemName_002( )
2724 {
2725 struct statvfs aStatFS;
2726 static const sal_Char name[] = "/";
2727
2728 memset (&aStatFS, 0, sizeof(aStatFS));
2729 statvfs( name, &aStatFS);
2730 sal_Char * astrFileSystemName = aStatFS.f_basetype;
2731
2732 sal_Int32 mask = VolumeInfoMask_FileSystemName;
2733 ::osl::VolumeInfo aVolumeInfo( mask );
2734 nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
2735 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2736 CPPUNIT_ASSERT( sal_True == aVolumeInfo.isValid( mask ) );
2737 aUStr = aVolumeInfo.getFileSystemName( );
2738
2739 CPPUNIT_ASSERT_MESSAGE( "test for getFileSystemName function: get file system name by hand, then compare with getFileSystemName",
2740 sal_True == compareFileName( aUStr, astrFileSystemName ) );
2741 }
2742 #else //Windows version
getFileSystemName_002()2743 void getFileSystemName_002( )
2744 {
2745 CPPUNIT_ASSERT_MESSAGE( "test for getFileSystemName function: not implemented yet( Windows version )",
2746 1 == 1 );
2747 }
2748 #endif
2749
2750
2751 CPPUNIT_TEST_SUITE( getFileSystemName );
2752 CPPUNIT_TEST( getFileSystemName_001 );
2753 CPPUNIT_TEST( getFileSystemName_002 );
2754 CPPUNIT_TEST_SUITE_END( );
2755 };// class getFileSystemName
2756
2757 //---------------------------------------------------------------------
2758 // testing the method
2759 // inline VolumeDevice getDeviceHandle() const
2760 //---------------------------------------------------------------------
2761 class getDeviceHandle : public CppUnit::TestFixture
2762 {
2763 ::rtl::OUString aUStr;
2764 ::osl::FileBase::RC nError1;
2765
2766 public:
2767 // test code.
getDeviceHandle_001()2768 void getDeviceHandle_001( )
2769 {
2770 ::osl::VolumeInfo aVolumeInfo( VolumeInfoMask_Attributes );
2771 nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
2772 CPPUNIT_ASSERT( osl::FileBase::E_None == nError1 );
2773
2774 ::osl::VolumeDevice aVolumeDevice1( aVolumeInfo.getDeviceHandle( ) );
2775 sal_Bool bOk = compareFileName( aNullURL, aVolumeDevice1.getMountPath( ) );
2776
2777 CPPUNIT_ASSERT_MESSAGE( "test for getDeviceHandle function: get device handle of Fixed disk volume mounted on /, it should not be NULL, it did not pass in (W32) (UNX).",
2778 ( sal_False == bOk ) );
2779 }
2780
2781 CPPUNIT_TEST_SUITE( getDeviceHandle );
2782 CPPUNIT_TEST( getDeviceHandle_001 );
2783 CPPUNIT_TEST_SUITE_END( );
2784 };// class getDeviceHandle
2785
2786
2787 // -----------------------------------------------------------------------------
2788 /*CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeInfo::ctors, "osl_VolumeInfo" );
2789 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeInfo::isValid, "osl_VolumeInfo" );
2790 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeInfo::getRemoteFlag, "osl_VolumeInfo" );
2791 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeInfo::getRemoveableFlag, "osl_VolumeInfo" );
2792 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeInfo::getCompactDiscFlag, "osl_VolumeInfo" );
2793 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeInfo::getFloppyDiskFlag, "osl_VolumeInfo" );
2794 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeInfo::getFixedDiskFlag, "osl_VolumeInfo" );
2795 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeInfo::getRAMDiskFlag, "osl_VolumeInfo" );
2796 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeInfo::getTotalSpace, "osl_VolumeInfo" );
2797 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeInfo::getFreeSpace, "osl_VolumeInfo" );
2798 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeInfo::getUsedSpace, "osl_VolumeInfo" );
2799 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeInfo::getMaxNameLength, "osl_VolumeInfo" );
2800 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeInfo::getMaxPathLength, "osl_VolumeInfo" );
2801 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeInfo::getFileSystemName, "osl_VolumeInfo" );
2802 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_VolumeInfo::getDeviceHandle, "osl_VolumeInfo" );*/
2803 }// namespace osl_VolumeInfo
2804
2805
2806
2807 //------------------------------------------------------------------------
2808 // Beginning of the test cases for VolumeDevice class
2809 //------------------------------------------------------------------------
2810 namespace osl_FileStatus
2811 {
2812
2813 //---------------------------------------------------------------------
2814 // testing the method
2815 // FileStatus( sal_uInt32 nMask ): _nMask( nMask )
2816 //---------------------------------------------------------------------
2817 class ctors : public CppUnit::TestFixture
2818 {
2819 ::rtl::OUString aUStr;
2820 ::osl::FileBase::RC nError1, nError2;
2821 ::osl::DirectoryItem rItem;
2822
2823 public:
2824 // initialization
setUp()2825 void setUp( )
2826 {
2827 // create a tempfile in $TEMP/tmpdir/tmpname.
2828 createTestDirectory( aTmpName3 );
2829 createTestFile( aTmpName4 );
2830
2831 ::std::auto_ptr<Directory> pDir( new Directory( aTmpName3 ) );
2832 nError1 = pDir->open( );
2833 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
2834 nError1 = pDir->getNextItem( rItem, 0 );
2835 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
2836 pDir->close();
2837 /*
2838 Directory aDir( aTmpName3 );
2839 nError1 = aDir.open();
2840 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
2841 nError1 = aDir.getNextItem( rItem, 0 );
2842 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
2843 aDir.close();
2844 */
2845 }
2846
tearDown()2847 void tearDown( )
2848 {
2849 // remove the tempfile in $TEMP/tmpdir/tmpname.
2850 deleteTestFile( aTmpName4 );
2851 deleteTestDirectory( aTmpName3 );
2852 }
2853
2854 // test code.
ctors_001()2855 void ctors_001( )
2856 {
2857 ::osl::FileStatus rFileStatus( FileStatusMask_All );
2858 nError1 = rItem.getFileStatus( rFileStatus );
2859 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
2860 aUStr = rFileStatus.getFileName( );
2861
2862 CPPUNIT_ASSERT_MESSAGE( "test for ctors function: mask all and see the file name",
2863 sal_True == compareFileName( aUStr, aTmpName2) );
2864 }
2865
ctors_002()2866 void ctors_002( )
2867 {
2868 ::osl::FileStatus rFileStatus( 0 );
2869 nError1 = rItem.getFileStatus( rFileStatus );
2870 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
2871 aUStr = rFileStatus.getFileName( );
2872
2873 CPPUNIT_ASSERT_MESSAGE( "test for ctors function: mask is empty",
2874 sal_True == compareFileName( aUStr, aNullURL) );
2875 }
2876
2877 CPPUNIT_TEST_SUITE( ctors );
2878 CPPUNIT_TEST( ctors_001 );
2879 CPPUNIT_TEST( ctors_002 );
2880 CPPUNIT_TEST_SUITE_END( );
2881 };// class ctors
2882
2883
2884 //---------------------------------------------------------------------
2885 // testing the method
2886 // inline sal_Bool isValid( sal_uInt32 nMask ) const
2887 //---------------------------------------------------------------------
2888 class isValid : public CppUnit::TestFixture
2889 {
2890 ::rtl::OUString aUStr;
2891 ::osl::Directory *pDir;
2892 ::osl::DirectoryItem rItem_file, rItem_link;
2893
2894 public:
2895 // initialization
setUp()2896 void setUp( )
2897 {
2898 // create a tempfile in $TEMP/tmpdir/tmpname.
2899 createTestDirectory( aTmpName3 );
2900 createTestFile( aTmpName4 );
2901
2902 pDir = new Directory( aTmpName3 );
2903 //::std::auto_ptr<Directory> pDir( new Directory( aTmpName3 ) );
2904 ::osl::FileBase::RC nError1 = pDir->open( );
2905 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
2906 nError1 = pDir->getNextItem( rItem_file, 1 );
2907 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
2908 }
2909
tearDown()2910 void tearDown( )
2911 {
2912 ::osl::FileBase::RC nError1 = pDir->close( );
2913 delete pDir;
2914 CPPUNIT_ASSERT_MESSAGE( errorToStr(nError1), ::osl::FileBase::E_None == nError1 );
2915
2916 // remove the tempfile in $TEMP/tmpdir/tmpname.
2917 deleteTestFile( aTmpName4 );
2918 deleteTestDirectory( aTmpName3 );
2919 }
2920
2921 // test code.
isValid_001()2922 void isValid_001( )
2923 {
2924 sal_uInt32 mask = 0;
2925 ::osl::FileStatus rFileStatus( mask );
2926 ::osl::FileBase::RC nError1 = rItem_file.getFileStatus( rFileStatus );
2927 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
2928 sal_Bool bOk = rFileStatus.isValid( mask );
2929
2930 CPPUNIT_ASSERT_MESSAGE( "test for isValid function: no fields specified",
2931 ( sal_True == bOk ) );
2932 }
2933
check_FileStatus(::osl::FileStatus const & _aStatus)2934 void check_FileStatus(::osl::FileStatus const& _aStatus)
2935 {
2936 rtl::OString sStat;
2937 if (_aStatus.isValid(FileStatusMask_Type))
2938 {
2939 sStat += "type ";
2940 }
2941 if (_aStatus.isValid(FileStatusMask_Attributes))
2942 {
2943 sStat += "attributes ";
2944 }
2945 if (_aStatus.isValid(FileStatusMask_CreationTime))
2946 {
2947 sStat += "ctime ";
2948 }
2949 if (_aStatus.isValid(FileStatusMask_AccessTime))
2950 {
2951 sStat += "atime ";
2952 }
2953 if (_aStatus.isValid(FileStatusMask_ModifyTime))
2954 {
2955 sStat += "mtime ";
2956 }
2957 if (_aStatus.isValid(FileStatusMask_FileSize))
2958 {
2959 sStat += "filesize ";
2960 }
2961 if (_aStatus.isValid(FileStatusMask_FileName))
2962 {
2963 sStat += "filename ";
2964 }
2965 if (_aStatus.isValid(FileStatusMask_FileURL))
2966 {
2967 sStat += "fileurl ";
2968 }
2969 t_print("mask: %s\n", sStat.getStr());
2970 }
2971
isValid_002()2972 void isValid_002( )
2973 {
2974 createTestFile( aTmpName6 );
2975 sal_uInt32 mask_file = ( FileStatusMask_Type | FileStatusMask_Attributes |
2976 FileStatusMask_CreationTime | FileStatusMask_AccessTime |
2977 FileStatusMask_ModifyTime | FileStatusMask_FileSize |
2978 FileStatusMask_FileName | FileStatusMask_FileURL) ;
2979 ::osl::FileStatus rFileStatus( mask_file );
2980 ::osl::FileBase::RC nError1 = ::osl::DirectoryItem::get( aTmpName6, rItem_file );
2981 nError1 = rItem_file.getFileStatus( rFileStatus );
2982
2983 CPPUNIT_ASSERT_MESSAGE( errorToStr(nError1), ::osl::FileBase::E_None == nError1 );
2984
2985 // LLA: this is wrong, we never should try to check on all masks
2986 // only on one.
2987 // Second, it's not a bug, if a value is not valid, it's an unhandled feature.
2988
2989 // sal_Bool bOk = rFileStatus.isValid( mask_file );
2990
2991 check_FileStatus(rFileStatus);
2992 deleteTestFile( aTmpName6 );
2993
2994 // CPPUNIT_ASSERT_MESSAGE( "test for isValid function: regular file mask fields test, #FileStatusMask_CreationTime# should be valid field for regular file, but feedback is invalid",
2995 // ( sal_True == bOk ) );
2996 }
2997
2998 //Link is not defined in Windows, and on Linux, we can not get the directory item of the link file
2999 // LLA: we have to differ to filesystems, normal filesystems support links (EXT2, ...)
3000 // castrated filesystems don't (FAT, FAT32)
3001 // Windows NT NTFS support links, but the windows api don't :-(
3002
isValid_003()3003 void isValid_003( )
3004 {
3005 #if defined ( UNX )
3006 // ::osl::FileBase::RC nError;
3007 sal_Int32 fd;
3008
3009 ::rtl::OUString aUStr_LnkFileSys( aTempDirectorySys ), aUStr_SrcFileSys( aTempDirectorySys );
3010 ( ( aUStr_LnkFileSys += aSlashURL ) += getCurrentPID( ) ) += ::rtl::OUString::createFromAscii("/tmpdir/link.file");
3011 ( ( aUStr_SrcFileSys += aSlashURL ) += getCurrentPID( ) ) += ::rtl::OUString::createFromAscii("/tmpdir/tmpname");
3012
3013 rtl::OString strLinkFileName;
3014 rtl::OString strSrcFileName;
3015 strLinkFileName = OUStringToOString( aUStr_LnkFileSys, RTL_TEXTENCODING_ASCII_US );
3016 strSrcFileName = OUStringToOString( aUStr_SrcFileSys, RTL_TEXTENCODING_ASCII_US );
3017
3018 //create a link file and link it to file "/tmp/PID/tmpdir/tmpname"
3019 fd = symlink( strSrcFileName.getStr(), strLinkFileName.getStr() );
3020 CPPUNIT_ASSERT( fd == 0 );
3021
3022 // testDirectory is "/tmp/PID/tmpdir/"
3023 ::osl::Directory testDirectory( aTmpName3 );
3024 ::osl::FileBase::RC nError1 = testDirectory.open( );
3025 ::rtl::OUString aFileName = ::rtl::OUString::createFromAscii("link.file");
3026 sal_Bool bOk = sal_False;
3027 while (1) {
3028 nError1 = testDirectory.getNextItem( rItem_link, 4 );
3029 if (::osl::FileBase::E_None == nError1) {
3030 sal_uInt32 mask_link = FileStatusMask_FileName | FileStatusMask_LinkTargetURL;
3031 ::osl::FileStatus rFileStatus( mask_link );
3032 rItem_link.getFileStatus( rFileStatus );
3033 //printFileName( rFileStatus.getFileName( ) );
3034 if ( compareFileName( rFileStatus.getFileName( ), aFileName) == sal_True )
3035 {
3036 //t_print("find the link file");
3037 if ( sal_True == rFileStatus.isValid( FileStatusMask_LinkTargetURL ) )
3038 {
3039 bOk = sal_True;
3040 break;
3041 }
3042 }
3043 }
3044 else
3045 break;
3046 };
3047
3048 fd = remove( strLinkFileName );
3049 CPPUNIT_ASSERT( fd == 0 );
3050
3051 CPPUNIT_ASSERT_MESSAGE("test for isValid function: link file, check for LinkTargetURL",
3052 ( sal_True == bOk ) );
3053 #endif
3054 }
3055
isValid_004()3056 void isValid_004( )
3057 {
3058 sal_uInt32 mask_file_all = FileStatusMask_All;
3059 ::osl::FileStatus rFileStatus_all( mask_file_all );
3060 ::osl::FileBase::RC nError1 = rItem_file.getFileStatus( rFileStatus_all );
3061 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
3062
3063 check_FileStatus(rFileStatus_all);
3064 // LLA: this is wrong
3065 // sal_Bool bOk1 = rFileStatus_all.isValid( mask_file_all );
3066
3067 sal_uInt32 mask_file_val = FileStatusMask_Validate;
3068 ::osl::FileStatus rFileStatus_val( mask_file_val );
3069 nError1 = rItem_file.getFileStatus( rFileStatus_val );
3070 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
3071 // sal_Bool bOk2 = rFileStatus_val.isValid( mask_file_val );
3072
3073 check_FileStatus(rFileStatus_val);
3074 // CPPUNIT_ASSERT_MESSAGE( "test for isValid function: check for Mask_All and Validate, really not sure what validate used for and how to use it, help me. did not pass (W32)(UNX).",
3075 // ( sal_False == bOk1 ) && ( sal_True == bOk2 ) );
3076 }
3077
3078
3079 CPPUNIT_TEST_SUITE( isValid );
3080 CPPUNIT_TEST( isValid_001 );
3081 CPPUNIT_TEST( isValid_002 );
3082 CPPUNIT_TEST( isValid_003 );
3083 CPPUNIT_TEST( isValid_004 );
3084 CPPUNIT_TEST_SUITE_END( );
3085 };// class ctors
3086
3087
3088 //---------------------------------------------------------------------
3089 // testing the method
3090 // inline Type getFileType() const
3091 //---------------------------------------------------------------------
3092 class getFileType : public CppUnit::TestFixture
3093 {
3094 ::rtl::OUString aUStr;
3095 ::osl::FileBase::RC nError1, nError2;
3096
3097 ::osl::DirectoryItem m_aItem_1, m_aItem_2, m_aVolumeItem, m_aFifoItem;
3098 ::osl::DirectoryItem m_aLinkItem, m_aSocketItem, m_aSpecialItem;
3099
3100 public:
3101 // initialization
setUp()3102 void setUp( )
3103 {
3104 // create a tempfile: $TEMP/tmpdir/tmpname.
3105 // a tempdirectory: $TEMP/tmpdir/tmpdir.
3106 // use $ROOT/staroffice as volume ---> use dev/fd as volume.
3107 // and get their directory item.
3108 createTestDirectory( aTmpName3 );
3109 //printFileName( aTmpName2);
3110 createTestFile( aTmpName3, aTmpName2 );
3111 createTestDirectory( aTmpName3, aTmpName1 );
3112
3113 ::std::auto_ptr<Directory> pDir( new Directory( aTmpName3 ) );
3114 nError1 = pDir->open( );
3115 CPPUNIT_ASSERT_MESSAGE("open aTmpName3 failed!", ::osl::FileBase::E_None == nError1 );
3116 //getNextItem can not assure which item retrieved
3117 nError1 = pDir->getNextItem( m_aItem_1, 1 );
3118 CPPUNIT_ASSERT_MESSAGE("get first item failed!", ::osl::FileBase::E_None == nError1 );
3119
3120 nError1 = pDir->getNextItem( m_aItem_2 );
3121 CPPUNIT_ASSERT_MESSAGE("get second item failed!", ::osl::FileBase::E_None == nError1 );
3122 pDir->close();
3123 //mindy: failed on my RH9,so removed temporaly
3124 //nError1 = ::osl::DirectoryItem::get( aVolURL2, m_aVolumeItem );
3125 //CPPUNIT_ASSERT_MESSAGE("get volume item failed!", ::osl::FileBase::E_None == nError1 );
3126
3127 }
3128
tearDown()3129 void tearDown( )
3130 {
3131 // remove all in $TEMP/tmpdir.
3132 deleteTestDirectory( aTmpName3, aTmpName1 );
3133 deleteTestFile( aTmpName3, aTmpName2 );
3134 deleteTestDirectory( aTmpName3 );
3135 }
3136
3137 // test code.
getFileType_001()3138 void getFileType_001( )
3139 {
3140 ::osl::FileStatus rFileStatus( FileStatusMask_Type | FileStatusMask_FileName );
3141 nError1 = m_aItem_1.getFileStatus( rFileStatus );
3142 CPPUNIT_ASSERT_MESSAGE("getFileStatus failed", ::osl::FileBase::E_None == nError1 );
3143
3144 check_FileType(rFileStatus);
3145 }
3146
check_FileType(osl::FileStatus const & _rFileStatus)3147 void check_FileType(osl::FileStatus const& _rFileStatus )
3148 {
3149 sal_Bool bOK = sal_False;
3150 if ( _rFileStatus.isValid(FileStatusMask_FileName))
3151 {
3152 rtl::OUString suFilename = _rFileStatus.getFileName();
3153
3154 if ( _rFileStatus.isValid(FileStatusMask_Type))
3155 {
3156 osl::FileStatus::Type eType = _rFileStatus.getFileType( );
3157
3158 if ( compareFileName( suFilename, aTmpName2) == sal_True )
3159 {
3160 // regular
3161 bOK = ( eType == osl::FileStatus::Regular );
3162 }
3163 if ( compareFileName( suFilename, aTmpName1) == sal_True )
3164 {
3165 // directory
3166 bOK = ( eType == ::osl::FileStatus::Directory );
3167 }
3168
3169 CPPUNIT_ASSERT_MESSAGE( "test for getFileType function: ",
3170 ( bOK == sal_True ) );
3171 }
3172 }
3173 // LLA: it's not a bug, if a FileStatus not exist, so no else
3174 }
3175
getFileType_002()3176 void getFileType_002( )
3177 {
3178 ::osl::FileStatus rFileStatus( FileStatusMask_Type | FileStatusMask_FileName );
3179 nError1 = m_aItem_2.getFileStatus( rFileStatus );
3180
3181 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
3182 check_FileType(rFileStatus);
3183 }
3184
getFileType_003()3185 void getFileType_003( )
3186 {
3187 #if 0
3188 // LLA: this have to be discussed.
3189 ::osl::FileStatus rFileStatus( FileStatusMask_Type );
3190 nError1 = m_aVolumeItem.getFileStatus( rFileStatus );
3191 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
3192
3193 if (rFileStatus.isValid(FileStatusMask_Type))
3194 {
3195 osl::FileStatus::Type eType = rFileStatus.getFileType( );
3196
3197 CPPUNIT_ASSERT_MESSAGE( "test for getFileType function: Volume, it seems the volume part of the field is not implemented, it did not pass in (W32)(UNX).",
3198 ( eType == ::osl::FileStatus::Volume ) );
3199 }
3200 #endif
3201 }
3202
3203
getFileType_004()3204 void getFileType_004( )
3205 {
3206 #if ( defined UNX ) || ( defined OS2 ) //Fifo creation is differ in Windows
3207
3208 //create a fifo in $ROOT/tmp/tmpdir, get its DirectoryItem.
3209 rtl::OString strFifoSys;
3210 strFifoSys = OUStringToOString( aFifoSys, RTL_TEXTENCODING_ASCII_US );
3211 ::rtl::OUString aFifoURL;
3212
3213 int fd = mkfifo( strFifoSys.getStr(), O_RDWR | O_CREAT );
3214 CPPUNIT_ASSERT_MESSAGE("mkfifo failed!", fd == 0 );
3215 ::osl::FileBase::getFileURLFromSystemPath( aFifoSys, aFifoURL );
3216
3217 nError1 = ::osl::DirectoryItem::get( aFifoURL, m_aFifoItem );
3218 CPPUNIT_ASSERT_MESSAGE("get item failed!", ::osl::FileBase::E_None == nError1 );
3219
3220 //check for File type
3221 ::osl::FileStatus rFileStatus( FileStatusMask_Type );
3222 nError1 = m_aFifoItem.getFileStatus( rFileStatus );
3223 CPPUNIT_ASSERT_MESSAGE("get Status failed!", ::osl::FileBase::E_None == nError1 );
3224
3225 //delete fifo
3226 nError1 = ::osl::File::remove( aFifoURL );
3227 CPPUNIT_ASSERT_MESSAGE("remove file failed!", ::osl::FileBase::E_None == nError1 );
3228
3229 if (rFileStatus.isValid(FileStatusMask_Type))
3230 {
3231 osl::FileStatus::Type eType = rFileStatus.getFileType( );
3232
3233 CPPUNIT_ASSERT_MESSAGE( "test for getFileType function: Fifo, Solaris version ",
3234 ( eType == ::osl::FileStatus::Fifo ) );
3235 }
3236 #endif
3237 }
3238
3239 /*
3240 * LLA: removed, m_aSocketItem is wrong initialised.
3241 */
3242
3243 // LLA: void getFileType_005( )
3244 // LLA: {
3245 // LLA: #if defined ( SOLARIS ) //Socket file may differ in Windows
3246 // LLA: // nError1 = ::osl::DirectoryItem::get( aTypeURL1, m_aSocketItem );
3247 // LLA: nError1 = ::osl::DirectoryItem::get( rtl::OUString::createFromAscii("/dev/null"), m_aSocketItem );
3248 // LLA: printError(nError1);
3249 // LLA: CPPUNIT_ASSERT_MESSAGE("get Socket type file failed", ::osl::FileBase::E_None == nError1 );
3250 // LLA:
3251 // LLA: //check for File type
3252 // LLA: ::osl::FileStatus rFileStatus( FileStatusMask_Type );
3253 // LLA:
3254 // LLA: nError1 = m_aSocketItem.getFileStatus( rFileStatus );
3255 // LLA: CPPUNIT_ASSERT_MESSAGE("getFileStatus failed", ::osl::FileBase::E_None == nError1 );
3256 // LLA:
3257 // LLA: if (rFileStatus.isValid( FileStatusMask_Type ))
3258 // LLA: {
3259 // LLA: osl::FileStatus::Type eType = rFileStatus.getFileType( );
3260 // LLA: printFileType(eType);
3261 // LLA: CPPUNIT_ASSERT_MESSAGE( "test for getFileType function: Socket, Solaris version ",
3262 // LLA: ( eType == ::osl::FileStatus::Socket ) );
3263 // LLA: }
3264 // LLA: #endif
3265 // LLA: }
3266
3267
3268 // deprecated since there is a same case Directory::getNextItem_004
3269 /*#if defined 0 //( UNX ) //( SOLARIS ) //Link file is not defined in Windows
3270 void getFileType_006( )
3271 {
3272 nError1 = ::osl::DirectoryItem::get( aTypeURL3, m_aLinkItem );
3273 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
3274
3275 //check for File type
3276 ::osl::FileStatus rFileStatus( FileStatusMask_Type );
3277 nError1 = m_aLinkItem.getFileStatus( rFileStatus );
3278 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
3279
3280 CPPUNIT_ASSERT_MESSAGE( "test for getFileType function: Link, UNX version ",
3281 ( ::osl::FileStatus::Link == rFileStatus.getFileType( ) ) );
3282 }
3283 #endif */
3284
getFileType_007()3285 void getFileType_007( )
3286 {
3287 #if defined ( SOLARIS ) //Special file is differ in Windows
3288 nError1 = ::osl::DirectoryItem::get( aTypeURL2, m_aSpecialItem );
3289 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
3290
3291 //check for File type
3292 ::osl::FileStatus rFileStatus( FileStatusMask_Type );
3293 nError1 = m_aSpecialItem.getFileStatus( rFileStatus );
3294 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
3295
3296 if (rFileStatus.isValid(FileStatusMask_Type))
3297 {
3298 osl::FileStatus::Type eType = rFileStatus.getFileType( );
3299
3300
3301 CPPUNIT_ASSERT_MESSAGE( "test for getFileType function: Special, Solaris version ",
3302 ( eType == ::osl::FileStatus::Special ) );
3303 }
3304 #endif
3305 }
3306
3307 CPPUNIT_TEST_SUITE( getFileType );
3308 CPPUNIT_TEST( getFileType_001 );
3309 CPPUNIT_TEST( getFileType_002 );
3310 CPPUNIT_TEST( getFileType_003 );
3311 CPPUNIT_TEST( getFileType_004 );
3312 // LLA: CPPUNIT_TEST( getFileType_005 );
3313 //CPPUNIT_TEST( getFileType_006 );
3314 CPPUNIT_TEST( getFileType_007 );
3315 CPPUNIT_TEST_SUITE_END( );
3316 };// class getFileType
3317
3318 //---------------------------------------------------------------------
3319 // testing the method
3320 // inline sal_uInt64 getAttributes() const
3321 //---------------------------------------------------------------------
3322 class getAttributes : public CppUnit::TestFixture
3323 {
3324 ::rtl::OUString aTypeURL, aTypeURL_Hid;
3325 ::osl::FileBase::RC nError;
3326 ::osl::DirectoryItem rItem, rItem_hidden;
3327
3328 public:
3329 // initialization
setUp()3330 void setUp( )
3331 {
3332 aTypeURL = aUserDirectoryURL.copy( 0 );
3333 concatURL( aTypeURL, aTmpName2 );
3334 createTestFile( aTypeURL );
3335 nError = ::osl::DirectoryItem::get( aTypeURL, rItem );
3336 CPPUNIT_ASSERT( nError == FileBase::E_None );
3337
3338 aTypeURL_Hid = aUserDirectoryURL.copy( 0 );
3339 concatURL( aTypeURL_Hid, aHidURL1 );
3340 createTestFile( aTypeURL_Hid );
3341 nError = ::osl::DirectoryItem::get( aTypeURL_Hid, rItem_hidden );
3342 CPPUNIT_ASSERT( nError == FileBase::E_None );
3343 }
3344
tearDown()3345 void tearDown( )
3346 {
3347 deleteTestFile( aTypeURL );
3348 deleteTestFile( aTypeURL_Hid );
3349 }
3350
3351 // test code.
3352 #if ( defined UNX ) || ( defined OS2 )
3353 //windows only 3 file attributes: normal, readonly, hidden
getAttributes_001()3354 void getAttributes_001( )
3355 {
3356 changeFileMode( aTypeURL, S_IRUSR | S_IRGRP | S_IROTH );
3357
3358 ::osl::FileStatus rFileStatus( FileStatusMask_Attributes );
3359 nError = rItem.getFileStatus( rFileStatus );
3360 CPPUNIT_ASSERT( nError == FileBase::E_None );
3361
3362 CPPUNIT_ASSERT_MESSAGE( "test for getAttributes function: ReadOnly, GrpRead, OwnRead, OthRead( UNX version ) ",
3363 ( Attribute_ReadOnly | Attribute_GrpRead | Attribute_OwnRead | Attribute_OthRead ) ==
3364 rFileStatus.getAttributes( ) );
3365 }
3366 #else //Windows version
getAttributes_001()3367 void getAttributes_001( )
3368 {
3369 CPPUNIT_ASSERT_MESSAGE( "test for getAttributes function: ReadOnly, GrpRead, OwnRead, OthRead( Windows version )",
3370 1 == 1 );
3371 }
3372 #endif
3373
3374
getAttributes_002()3375 void getAttributes_002( )
3376 {
3377 #if ( defined UNX ) || ( defined OS2 )
3378 changeFileMode( aTypeURL, S_IXUSR | S_IXGRP | S_IXOTH );
3379
3380 ::osl::FileStatus rFileStatus( FileStatusMask_Attributes );
3381 nError = rItem.getFileStatus( rFileStatus );
3382 CPPUNIT_ASSERT( nError == FileBase::E_None );
3383
3384 CPPUNIT_ASSERT_MESSAGE( "test for getAttributes function: Executable, GrpExe, OwnExe, OthExe, the result is Readonly, Executable, GrpExe, OwnExe, OthExe, it partly not pass( Solaris version )",
3385 ( Attribute_ReadOnly | Attribute_Executable | Attribute_GrpExe | Attribute_OwnExe | Attribute_OthExe ) ==
3386 rFileStatus.getAttributes( ) );
3387 #endif
3388 }
3389
3390
3391 #if ( defined UNX ) || ( defined OS2 )
getAttributes_003()3392 void getAttributes_003( )
3393 {
3394 changeFileMode( aTypeURL, S_IWUSR | S_IWGRP | S_IWOTH );
3395
3396 ::osl::FileStatus rFileStatus( FileStatusMask_Attributes );
3397 nError = rItem.getFileStatus( rFileStatus );
3398 CPPUNIT_ASSERT( nError == FileBase::E_None );
3399
3400 CPPUNIT_ASSERT_MESSAGE( "test for getAttributes function: GrpWrite, OwnWrite, OthWrite( Solaris version )",
3401 ( Attribute_GrpWrite | Attribute_OwnWrite | Attribute_OthWrite ) ==
3402 rFileStatus.getAttributes( ) );
3403 }
3404 #else //Windows version
getAttributes_003()3405 void getAttributes_003( )
3406 {
3407 CPPUNIT_ASSERT_MESSAGE( "test for getAttributes function: GrpWrite, OwnWrite, OthWrite( Windows version )",
3408 1 == 1 );
3409 }
3410 #endif
3411
3412 #if ( defined UNX ) || ( defined OS2 ) //hidden file definition may different in Windows
getAttributes_004()3413 void getAttributes_004( )
3414 {
3415 sal_Int32 test_Attributes = Attribute_Hidden;
3416 ::osl::FileStatus rFileStatus( FileStatusMask_Attributes );
3417 nError = rItem_hidden.getFileStatus( rFileStatus );
3418 CPPUNIT_ASSERT( nError == FileBase::E_None );
3419 test_Attributes &= rFileStatus.getAttributes( );
3420
3421 CPPUNIT_ASSERT_MESSAGE( "test for getAttributes function: Hidden files( Solaris version )",
3422 test_Attributes == Attribute_Hidden );
3423 }
3424 #else //Windows version
getAttributes_004()3425 void getAttributes_004( )
3426 {
3427 ::rtl::OUString aUserHiddenFileURL = ::rtl::OUString::createFromAscii("file:///c:/AUTOEXEC.BAT");
3428 nError = ::osl::DirectoryItem::get( aUserHiddenFileURL, rItem_hidden );
3429 //printFileName( aUserHiddenFileURL );
3430 CPPUNIT_ASSERT_MESSAGE("get item fail", nError == FileBase::E_None );
3431 ::osl::FileStatus rFileStatus( FileStatusMask_Attributes );
3432 nError = rItem_hidden.getFileStatus( rFileStatus );
3433 CPPUNIT_ASSERT( nError == FileBase::E_None );
3434
3435 CPPUNIT_ASSERT_MESSAGE( "Hidden files(Windows version), please check if hidden file c:/AUTOEXEC.BAT exists ",
3436 (rFileStatus.getAttributes( ) & Attribute_Hidden)!= 0 );
3437 }
3438 #endif
3439
3440 CPPUNIT_TEST_SUITE( getAttributes );
3441 CPPUNIT_TEST( getAttributes_001 );
3442 CPPUNIT_TEST( getAttributes_002 );
3443 CPPUNIT_TEST( getAttributes_003 );
3444 CPPUNIT_TEST( getAttributes_004 );
3445 CPPUNIT_TEST_SUITE_END( );
3446 };// class getAttributes
3447
3448 //---------------------------------------------------------------------
3449 // testing the method
3450 // inline TimeValue getAccessTime() const
3451 //---------------------------------------------------------------------
3452 class getAccessTime : public CppUnit::TestFixture
3453 {
3454 ::rtl::OUString aTypeURL;
3455 ::osl::FileBase::RC nError;
3456 ::osl::DirectoryItem rItem;
3457
3458 public:
3459 // initialization
setUp()3460 void setUp( )
3461 {
3462 aTypeURL = aUserDirectoryURL.copy( 0 );
3463 concatURL( aTypeURL, aTmpName2 );
3464 createTestFile( aTypeURL );
3465 nError = ::osl::DirectoryItem::get( aTypeURL, rItem );
3466 CPPUNIT_ASSERT( nError == FileBase::E_None );
3467
3468 }
3469
tearDown()3470 void tearDown( )
3471 {
3472 deleteTestFile( aTypeURL );
3473 }
3474
3475 // test code.
getAccessTime_001()3476 void getAccessTime_001( )
3477 {
3478 TimeValue *pTV_current = NULL;
3479 CPPUNIT_ASSERT( ( pTV_current = ( TimeValue* )malloc( sizeof( TimeValue ) ) ) != NULL );
3480 TimeValue *pTV_access = NULL;
3481 CPPUNIT_ASSERT( ( pTV_access = ( TimeValue* )malloc( sizeof( TimeValue ) ) ) != NULL );
3482
3483 ::osl::FileStatus rFileStatus( FileStatusMask_AccessTime );
3484 nError = rItem.getFileStatus( rFileStatus );
3485 sal_Bool bOk = osl_getSystemTime( pTV_current );
3486 CPPUNIT_ASSERT( sal_True == bOk && nError == FileBase::E_None );
3487
3488 *pTV_access = rFileStatus.getAccessTime( );
3489
3490 sal_Bool bOK = t_compareTime( pTV_access, pTV_current, delta );
3491 free( pTV_current );
3492 free( pTV_access );
3493
3494 CPPUNIT_ASSERT_MESSAGE( "test for getAccessTime function: This test turns out that UNX pricision is no more than 1 sec, don't know how to test this function, in Windows test, it lost hour min sec, only have date time. ",
3495 sal_True == bOK );
3496 }
3497
3498 CPPUNIT_TEST_SUITE( getAccessTime );
3499 CPPUNIT_TEST( getAccessTime_001 );
3500 CPPUNIT_TEST_SUITE_END( );
3501 };// class getAccessTime
3502
3503 //---------------------------------------------------------------------
3504 // testing the method
3505 // inline TimeValue getModifyTime() const
3506 //---------------------------------------------------------------------
3507 class getModifyTime : public CppUnit::TestFixture
3508 {
3509 ::rtl::OUString aTypeURL;
3510 ::osl::FileBase::RC nError;
3511 ::osl::DirectoryItem rItem;
3512
3513 public:
3514
3515 // test code.
getModifyTime_001()3516 void getModifyTime_001( )
3517 {
3518 TimeValue *pTV_current = NULL;
3519 CPPUNIT_ASSERT( ( pTV_current = ( TimeValue* )malloc( sizeof( TimeValue ) ) ) != NULL );
3520
3521 //create file
3522 aTypeURL = aUserDirectoryURL.copy( 0 );
3523 concatURL( aTypeURL, aTmpName2 );
3524 createTestFile( aTypeURL );
3525
3526 //get current time
3527 sal_Bool bOk = osl_getSystemTime( pTV_current );
3528 CPPUNIT_ASSERT( sal_True == bOk );
3529
3530 //get instance item and filestatus
3531 nError = ::osl::DirectoryItem::get( aTypeURL, rItem );
3532 CPPUNIT_ASSERT( nError == FileBase::E_None );
3533 ::osl::FileStatus rFileStatus( FileStatusMask_ModifyTime );
3534 nError = rItem.getFileStatus( rFileStatus );
3535 CPPUNIT_ASSERT( nError == FileBase::E_None );
3536
3537 //get modify time
3538 TimeValue *pTV_modify = NULL;
3539 CPPUNIT_ASSERT( ( pTV_modify = ( TimeValue* )malloc( sizeof( TimeValue ) ) ) != NULL );
3540 *pTV_modify = rFileStatus.getModifyTime( );
3541
3542 sal_Bool bOK = t_compareTime( pTV_modify, pTV_current, delta );
3543 //delete file
3544 deleteTestFile( aTypeURL );
3545 free( pTV_current );
3546
3547 CPPUNIT_ASSERT_MESSAGE( "test for getModifyTime function: This test turns out that UNX pricision is no more than 1 sec, don't know how to improve this function. ",
3548 sal_True == bOK );
3549 }
3550
3551 CPPUNIT_TEST_SUITE( getModifyTime );
3552 CPPUNIT_TEST( getModifyTime_001 );
3553 CPPUNIT_TEST_SUITE_END( );
3554 };// class getModifyTime
3555
3556
3557 //---------------------------------------------------------------------
3558 // testing the method
3559 // inline sal_uInt64 getFileSize() const
3560 //---------------------------------------------------------------------
3561 class getFileSize : public CppUnit::TestFixture
3562 {
3563 ::rtl::OUString aTypeURL;
3564 ::osl::FileBase::RC nError;
3565 ::osl::DirectoryItem rItem;
3566
3567 public:
3568 // initialization
setUp()3569 void setUp( )
3570 {
3571 aTypeURL = aUserDirectoryURL.copy( 0 );
3572 concatURL( aTypeURL, aTmpName2 );
3573 createTestFile( aTypeURL );
3574 nError = ::osl::DirectoryItem::get( aTypeURL, rItem );
3575 CPPUNIT_ASSERT( nError == FileBase::E_None );
3576 }
3577
tearDown()3578 void tearDown( )
3579 {
3580 deleteTestFile( aTypeURL );
3581 }
3582
3583 // test code.
getFileSize_001()3584 void getFileSize_001( )
3585 {
3586 ::osl::FileStatus rFileStatus( FileStatusMask_FileSize );
3587 nError = rItem.getFileStatus( rFileStatus );
3588 CPPUNIT_ASSERT( nError == FileBase::E_None );
3589
3590 sal_uInt64 uFileSize = rFileStatus.getFileSize( );
3591
3592 CPPUNIT_ASSERT_MESSAGE( "test for getFileSize function: empty file ",
3593 0 == uFileSize );
3594 }
3595
getFileSize_002()3596 void getFileSize_002( )
3597 {
3598 ::osl::File testfile( aTypeURL );
3599 nError = testfile.open( OpenFlag_Write | OpenFlag_Read );
3600 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError );
3601 nError = testfile.setSize( TEST_FILE_SIZE );
3602 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError );
3603
3604 nError = ::osl::DirectoryItem::get( aTypeURL, rItem );
3605 CPPUNIT_ASSERT( nError == FileBase::E_None );
3606 ::osl::FileStatus rFileStatus( FileStatusMask_FileSize );
3607 nError = rItem.getFileStatus( rFileStatus );
3608 CPPUNIT_ASSERT( nError == FileBase::E_None );
3609 sal_uInt64 uFileSize = rFileStatus.getFileSize( );
3610
3611 CPPUNIT_ASSERT_MESSAGE( "test for getFileSize function: file with size of TEST_FILE_SIZE, did not pass in (W32). ",
3612 TEST_FILE_SIZE == uFileSize );
3613 }
3614 CPPUNIT_TEST_SUITE( getFileSize );
3615 CPPUNIT_TEST( getFileSize_001 );
3616 CPPUNIT_TEST( getFileSize_002 );
3617 CPPUNIT_TEST_SUITE_END( );
3618 };// class getFileSize
3619
3620 //---------------------------------------------------------------------
3621 // testing the method
3622 // inline ::rtl::OUString getFileName() const
3623 //---------------------------------------------------------------------
3624 class getFileName : public CppUnit::TestFixture
3625 {
3626 ::rtl::OUString aTypeURL;
3627 ::osl::FileBase::RC nError;
3628 ::osl::DirectoryItem rItem;
3629
3630 public:
3631 // initialization
setUp()3632 void setUp( )
3633 {
3634 aTypeURL = aUserDirectoryURL.copy( 0 );
3635 concatURL( aTypeURL, aTmpName2 );
3636 createTestFile( aTypeURL );
3637 nError = ::osl::DirectoryItem::get( aTypeURL, rItem );
3638 CPPUNIT_ASSERT( nError == FileBase::E_None );
3639 }
3640
tearDown()3641 void tearDown( )
3642 {
3643 deleteTestFile( aTypeURL );
3644 }
3645
3646 // test code.
getFileName_001()3647 void getFileName_001( )
3648 {
3649 ::osl::FileStatus rFileStatus( FileStatusMask_FileName );
3650 nError = rItem.getFileStatus( rFileStatus );
3651 CPPUNIT_ASSERT( nError == FileBase::E_None );
3652
3653 ::rtl::OUString aFileName = rFileStatus.getFileName( );
3654
3655 CPPUNIT_ASSERT_MESSAGE( "test for getFileName function: name compare with specify",
3656 sal_True == compareFileName( aFileName, aTmpName2 ) );
3657 }
3658
3659 CPPUNIT_TEST_SUITE( getFileName );
3660 CPPUNIT_TEST( getFileName_001 );
3661 CPPUNIT_TEST_SUITE_END( );
3662 };// class getFileName
3663
3664 //---------------------------------------------------------------------
3665 // testing the method
3666 // inline ::rtl::OUString getFileURL() const
3667 //---------------------------------------------------------------------
3668 class getFileURL : public CppUnit::TestFixture
3669 {
3670 ::rtl::OUString aTypeURL;
3671 ::osl::FileBase::RC nError;
3672 ::osl::DirectoryItem rItem;
3673
3674 public:
3675 // initialization
setUp()3676 void setUp( )
3677 {
3678 createTestFile( aTmpName6 );
3679 nError = ::osl::DirectoryItem::get( aTmpName6, rItem );
3680 CPPUNIT_ASSERT( nError == FileBase::E_None );
3681 }
3682
tearDown()3683 void tearDown( )
3684 {
3685 deleteTestFile( aTmpName6 );
3686 }
3687
3688 // test code.
getFileURL_001()3689 void getFileURL_001( )
3690 {
3691 ::osl::FileStatus rFileStatus( FileStatusMask_FileURL );
3692 nError = rItem.getFileStatus( rFileStatus );
3693 CPPUNIT_ASSERT( nError == FileBase::E_None );
3694
3695 ::rtl::OUString aFileURL = rFileStatus.getFileURL( );
3696
3697 CPPUNIT_ASSERT_MESSAGE( "test for getFileURL function: ",
3698 sal_True == compareFileName( aFileURL, aTmpName6 ) );
3699 }
3700
3701 CPPUNIT_TEST_SUITE( getFileURL );
3702 CPPUNIT_TEST( getFileURL_001 );
3703 CPPUNIT_TEST_SUITE_END( );
3704 };// class getFileURL
3705
3706 //---------------------------------------------------------------------
3707 // testing the method
3708 // inline ::rtl::OUString getLinkTargetURL() const
3709 //---------------------------------------------------------------------
3710 class getLinkTargetURL : public CppUnit::TestFixture
3711 {
3712 ::rtl::OUString aTypeURL;
3713 ::osl::FileBase::RC nError;
3714 ::osl::DirectoryItem rItem;
3715
3716 public:
3717 // test code.
3718 // initialization
setUp()3719 void setUp( )
3720 {
3721 aTypeURL = aUserDirectoryURL.copy( 0 );
3722 concatURL( aTypeURL, aTmpName2 );
3723 createTestFile( aTypeURL );
3724 }
3725
tearDown()3726 void tearDown( )
3727 {
3728 deleteTestFile( aTypeURL );
3729 }
3730
3731 #if ( defined UNX ) || ( defined OS2 ) //Link file is not define in Windows
getLinkTargetURL_001()3732 void getLinkTargetURL_001( )
3733 {
3734 //create a link file;
3735 ::rtl::OUString aUStr_LnkFileSys( aTempDirectorySys ), aUStr_SrcFileSys( aTempDirectorySys );
3736 ( ( aUStr_LnkFileSys += aSlashURL ) += getCurrentPID( ) ) += ::rtl::OUString::createFromAscii("/link.file");
3737 ( ( aUStr_SrcFileSys += aSlashURL ) += getCurrentPID( ) ) += ::rtl::OUString::createFromAscii("/tmpname");
3738
3739 rtl::OString strLinkFileName, strSrcFileName;
3740 strLinkFileName = OUStringToOString( aUStr_LnkFileSys, RTL_TEXTENCODING_ASCII_US );
3741 strSrcFileName = OUStringToOString( aUStr_SrcFileSys, RTL_TEXTENCODING_ASCII_US );
3742
3743 sal_Int32 fd;
3744 fd = symlink( strSrcFileName.getStr(), strLinkFileName.getStr() );
3745 CPPUNIT_ASSERT_MESSAGE( "in creating link file", fd == 0 );
3746
3747 //get linkTarget URL
3748 nError = ::osl::DirectoryItem::get( aLnkURL1, rItem );
3749 CPPUNIT_ASSERT_MESSAGE( "in getting link file item", nError == FileBase::E_None );
3750
3751 ::osl::FileStatus rFileStatus( FileStatusMask_LinkTargetURL );
3752 nError = rItem.getFileStatus( rFileStatus );
3753 CPPUNIT_ASSERT_MESSAGE( "in getting link file status", nError == FileBase::E_None );
3754 ::rtl::OUString aFileURL = rFileStatus.getLinkTargetURL( );
3755
3756 //remove link file
3757 fd = remove( strLinkFileName.getStr() );
3758 CPPUNIT_ASSERT_MESSAGE( "in deleting link file", fd == 0 );
3759
3760 CPPUNIT_ASSERT_MESSAGE( "test for getLinkTargetURL function: Solaris version, creat a file, and a link file link to it, get its LinkTargetURL and compare",
3761 sal_True == compareFileName( aFileURL, aTypeURL ) );
3762 }
3763 #else
getLinkTargetURL_001()3764 void getLinkTargetURL_001( )
3765 {
3766 CPPUNIT_ASSERT_MESSAGE( "test for getLinkTargetURL function: Windows version, not tested",
3767 1 );
3768 }
3769 #endif
3770
3771 CPPUNIT_TEST_SUITE( getLinkTargetURL );
3772 CPPUNIT_TEST( getLinkTargetURL_001 );
3773 CPPUNIT_TEST_SUITE_END( );
3774 };// class getLinkTargetURL
3775
3776 // -----------------------------------------------------------------------------
3777 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileStatus::ctors, "osl_FileStatus" );
3778 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileStatus::isValid, "osl_FileStatus" );
3779 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileStatus::getFileType, "osl_FileStatus" );
3780 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileStatus::getAttributes, "osl_FileStatus" );
3781 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileStatus::getAccessTime, "osl_FileStatus" );
3782 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileStatus::getModifyTime, "osl_FileStatus" );
3783 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileStatus::getFileSize, "osl_FileStatus" );
3784 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileStatus::getFileName, "osl_FileStatus" );
3785 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileStatus::getFileURL, "osl_FileStatus" );
3786 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_FileStatus::getLinkTargetURL, "osl_FileStatus" );
3787 }// namespace osl_FileStatus
3788
3789
3790
3791 //------------------------------------------------------------------------
3792 // Beginning of the test cases for File class
3793 //------------------------------------------------------------------------
3794 namespace osl_File
3795 {
3796 //---------------------------------------------------------------------
3797 // testing the method
3798 // File( const ::rtl::OUString& ustrFileURL )
3799 //---------------------------------------------------------------------
3800 class ctors : public CppUnit::TestFixture
3801 {
3802 // ::osl::FileBase::RC nError1;
3803
3804 public:
3805 // initialization
setUp()3806 void setUp( )
3807 {
3808 // create a tempfile in $TEMP/tmpdir/tmpname.
3809 createTestDirectory( aTmpName3 );
3810 createTestFile( aTmpName4 );
3811 }
3812
tearDown()3813 void tearDown( )
3814 {
3815 // remove the tempfile in $TEMP/tmpdir/tmpname.
3816 deleteTestFile( aTmpName4 );
3817 deleteTestDirectory( aTmpName3 );
3818 }
3819
3820 // test code.
ctors_001()3821 void ctors_001( )
3822 {
3823 ::osl::File testFile( aTmpName4 );
3824
3825 ::osl::FileBase::RC nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write );
3826 ::osl::FileBase::RC nError2 = testFile.close( );
3827 CPPUNIT_ASSERT_MESSAGE( "test for ctors function: initialize a File and test its open and close",
3828 ( ::osl::FileBase::E_None == nError1 ) && ( ::osl::FileBase::E_None == nError2 ) );
3829 }
3830
ctors_002()3831 void ctors_002( )
3832 {
3833 ::osl::File testFile( aTmpName5 );
3834 sal_Char buffer[30] = "Test for File constructor";
3835 sal_uInt64 nCount;
3836
3837 ::osl::FileBase::RC nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write );
3838 ::osl::FileBase::RC nError2 = testFile.write( buffer, 30, nCount );
3839 testFile.close( );
3840
3841 CPPUNIT_ASSERT_MESSAGE( "test for ctors function: test relative file URL, this test show that relative file URL is also acceptable",
3842 ( ::osl::FileBase::E_None == nError1 ) && ( ::osl::FileBase::E_None == nError2 ) );
3843 }
3844
3845 CPPUNIT_TEST_SUITE( ctors );
3846 CPPUNIT_TEST( ctors_001 );
3847 CPPUNIT_TEST( ctors_002 );
3848 CPPUNIT_TEST_SUITE_END( );
3849 };// class ctors
3850
3851 //---------------------------------------------------------------------
3852 // testing the method
3853 // inline RC open( sal_uInt32 uFlags )
3854 //---------------------------------------------------------------------
3855 class open : public CppUnit::TestFixture
3856 {
3857 ::osl::FileBase::RC nError1, nError2, nError3;
3858
3859 public:
3860 // initialization
setUp()3861 void setUp( )
3862 {
3863 // create a tempfile in $TEMP/tmpdir/tmpname.
3864 createTestDirectory( aTmpName3 );
3865 createTestFile( aTmpName4 );
3866 }
3867
tearDown()3868 void tearDown( )
3869 {
3870 // remove the tempfile in $TEMP/tmpdir/tmpname.
3871 deleteTestFile( aTmpName4 );
3872 deleteTestDirectory( aTmpName3 );
3873 }
3874
3875 // test code.
open_001()3876 void open_001( )
3877 {
3878 ::osl::File testFile( aTmpName4 );
3879
3880 nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write );
3881 nError2 = testFile.close( );
3882 CPPUNIT_ASSERT_MESSAGE("close error", ::osl::FileBase::E_None == nError2 );
3883
3884 CPPUNIT_ASSERT_MESSAGE( "test for open function: open a regular file",
3885 ::osl::FileBase::E_None == nError1 );
3886 }
3887
open_002()3888 void open_002( )
3889 {
3890 ::osl::File testFile( aTmpName3 );
3891
3892 nError1 = testFile.open( OpenFlag_Read );
3893
3894 CPPUNIT_ASSERT_MESSAGE( "test for open function: open a directory",
3895 ( File::E_INVAL == nError1 ) || ( File::E_ACCES == nError1 ) );
3896 }
3897
open_003()3898 void open_003( )
3899 {
3900 ::osl::File testFile( aCanURL1 );
3901
3902 nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write );
3903
3904 CPPUNIT_ASSERT_MESSAGE( "test for open function: open a non-exist file",
3905 File::E_NOENT == nError1 );
3906 }
3907
open_004()3908 void open_004( )
3909 {
3910 ::rtl::OUString aTestFile( aRootURL );
3911 concatURL( aTestFile, aTmpName2 );
3912 ::osl::File testFile( aTestFile );
3913
3914 nError1 = testFile.open( OpenFlag_Create );
3915 sal_Bool bOK = ( File::E_ACCES == nError1 );
3916 #if defined (WNT )
3917 bOK = sal_True; /// in Windows, you can create file in c:/ any way.
3918 testFile.close( );
3919 deleteTestFile( aTestFile);
3920 #endif
3921
3922 CPPUNIT_ASSERT_MESSAGE( "test for open function: create an illegal file",
3923 bOK == sal_True );
3924 }
3925
open_005()3926 void open_005( )
3927 {
3928 ::osl::File testFile( aTmpName4 );
3929
3930 nError1 = testFile.open( OpenFlag_Create );
3931
3932 CPPUNIT_ASSERT_MESSAGE( "test for open function: create an exist file",
3933 File::E_EXIST == nError1 );
3934 }
3935
open_006()3936 void open_006( )
3937 {
3938 ::osl::File testFile( aCanURL1 );
3939 sal_Char buffer_write[30] = "Test for File open";
3940 sal_Char buffer_read[30];
3941 sal_uInt64 nCount_write, nCount_read;
3942
3943 nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write | OpenFlag_Create );
3944 nError2 = testFile.write( buffer_write, 30, nCount_write );
3945 ::osl::FileBase::RC nError4 = testFile.setPos( Pos_Absolut, 0 );
3946 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError4 );
3947 nError3 = testFile.read( buffer_read, 10, nCount_read );
3948
3949 ::osl::FileBase::RC nError5 = testFile.close( );
3950 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError5 );
3951 ::osl::FileBase::RC nError6 = testFile.remove( aCanURL1 );
3952 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError6 );
3953
3954 CPPUNIT_ASSERT_MESSAGE( "test for open function: test for OpenFlag_Read,OpenFlag_Write and OpenFlag_Create",
3955 ( ::osl::FileBase::E_None == nError1 ) &&
3956 ( ::osl::FileBase::E_None == nError2 ) &&
3957 ( ::osl::FileBase::E_None == nError3 ) &&
3958 ( 30 == nCount_write ) &&
3959 ( 10 == nCount_read ) );
3960 }
3961
3962 CPPUNIT_TEST_SUITE( open );
3963 CPPUNIT_TEST( open_001 );
3964 CPPUNIT_TEST( open_002 );
3965 CPPUNIT_TEST( open_003 );
3966 CPPUNIT_TEST( open_004 );
3967 CPPUNIT_TEST( open_005 );
3968 CPPUNIT_TEST( open_006 );
3969 CPPUNIT_TEST_SUITE_END( );
3970 };// class open
3971
3972 //---------------------------------------------------------------------
3973 // testing the method
3974 // inline RC close()
3975 //---------------------------------------------------------------------
3976 class close : public CppUnit::TestFixture
3977 {
3978 ::osl::FileBase::RC nError1, nError2, nError3;
3979
3980 public:
3981 // initialization
setUp()3982 void setUp( )
3983 {
3984 // create a tempfile in $TEMP/tmpdir/tmpname.
3985 createTestDirectory( aTmpName3 );
3986 createTestFile( aTmpName4 );
3987 }
3988
tearDown()3989 void tearDown( )
3990 {
3991 // remove the tempfile in $TEMP/tmpdir/tmpname.
3992 deleteTestFile( aTmpName4 );
3993 deleteTestDirectory( aTmpName3 );
3994 }
3995
3996 // test code.
close_001()3997 void close_001( )
3998 {
3999 ::osl::File testFile( aTmpName4 );
4000
4001 nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write );
4002 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4003
4004 nError2 = testFile.close( );
4005
4006 CPPUNIT_ASSERT_MESSAGE( "test for close function: close a regular file",
4007 ::osl::FileBase::E_None == nError2 );
4008 }
4009
close_002()4010 void close_002( )
4011 {
4012 ::osl::File testFile( aTmpName4 );
4013
4014 nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write );
4015 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4016
4017 nError2 = testFile.close( );
4018
4019 nError3 = testFile.setPos( Pos_Absolut, 0 );
4020
4021 CPPUNIT_ASSERT_MESSAGE( "test for close function: manipulate a file after it has been closed",
4022 ( ::osl::FileBase::E_None == nError2 ) &&
4023 ( ::osl::FileBase::E_None != nError3 ) );
4024 }
4025
4026 CPPUNIT_TEST_SUITE( close );
4027 CPPUNIT_TEST( close_001 );
4028 CPPUNIT_TEST( close_002 );
4029 CPPUNIT_TEST_SUITE_END( );
4030 };// class close
4031
4032
4033 //---------------------------------------------------------------------
4034 // testing the method
4035 // inline RC setPos( sal_uInt32 uHow, sal_Int64 uPos )
4036 //---------------------------------------------------------------------
4037 class setPos : public CppUnit::TestFixture
4038 {
4039 ::osl::FileBase::RC nError1;
4040 sal_uInt64 nCount_write, nCount_read;
4041
4042 public:
4043 // initialization
setUp()4044 void setUp( )
4045 {
4046 // create a tempfile in $TEMP/tmpdir/tmpname.
4047 createTestDirectory( aTmpName3 );
4048 createTestFile( aTmpName4 );
4049
4050 //write chars into the file.
4051 ::osl::File testFile( aTmpName4 );
4052
4053 nError1 = testFile.open( OpenFlag_Write );
4054 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4055 nError1 = testFile.write( pBuffer_Char, sizeof( pBuffer_Char ), nCount_write );
4056 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4057 nError1 = testFile.close( );
4058 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4059 }
4060
tearDown()4061 void tearDown( )
4062 {
4063 // remove the tempfile in $TEMP/tmpdir/tmpname.
4064 deleteTestFile( aTmpName4 );
4065 deleteTestDirectory( aTmpName3 );
4066 }
4067
4068 // test code.
setPos_001()4069 void setPos_001( )
4070 {
4071 ::osl::File testFile( aTmpName4 );
4072 sal_Char buffer_read[2];
4073
4074 nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write );
4075 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4076 nError1 = testFile.setPos( Pos_Absolut, 26 );
4077 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4078 nError1 = testFile.read( buffer_read, 1, nCount_read );
4079 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4080 nError1 = testFile.close( );
4081 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4082
4083 CPPUNIT_ASSERT_MESSAGE( "test for setPos function: test for Pos_Absolut, set the position to 26, test if the 26th char in file is correct",
4084 buffer_read[0] == pBuffer_Char[26] );
4085 }
4086
setPos_002()4087 void setPos_002( )
4088 {
4089 ::osl::File testFile( aTmpName4 );
4090 sal_Char buffer_read[2];
4091
4092 nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write );
4093 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4094 nError1 = testFile.setPos( Pos_Absolut, sizeof( pBuffer_Char ) - 2 );
4095 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4096 nError1 = testFile.setPos( Pos_Current, 0);
4097 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4098 nError1 = testFile.read( buffer_read, 1, nCount_read );
4099 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4100 nError1 = testFile.close( );
4101 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4102
4103 CPPUNIT_ASSERT_MESSAGE( "test for setPos function: test for Pos_Current, set the position to end, test if the ( end -1 ) char in file is correct",
4104 buffer_read[0] == pBuffer_Char[sizeof( pBuffer_Char ) - 2] );
4105 }
4106
setPos_003()4107 void setPos_003( )
4108 {
4109 ::osl::File testFile( aTmpName4 );
4110 sal_Char buffer_read[2];
4111
4112 nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write );
4113 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4114 //the file size is smaller than 100
4115 nError1 = testFile.setPos( Pos_End, -100 );
4116 CPPUNIT_ASSERT_MESSAGE( "should return error", ::osl::FileBase::E_INVAL == nError1 );
4117
4118 nError1 = testFile.setPos( Pos_End, -53 );
4119 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4120 nError1 = testFile.read( buffer_read, 1, nCount_read );
4121 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4122 nError1 = testFile.close( );
4123 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4124
4125 CPPUNIT_ASSERT_MESSAGE( "test for setPos function: test for Pos_End, set the position to end, test if the first char in file is correct",
4126 buffer_read[0] == pBuffer_Char[0] );
4127 }
4128
4129 CPPUNIT_TEST_SUITE( setPos );
4130 CPPUNIT_TEST( setPos_001 );
4131 CPPUNIT_TEST( setPos_002 );
4132 CPPUNIT_TEST( setPos_003 );
4133 CPPUNIT_TEST_SUITE_END( );
4134 };// class setPos
4135
4136 //---------------------------------------------------------------------
4137 // testing the method
4138 // inline RC getPos( sal_uInt64& uPos )
4139 //---------------------------------------------------------------------
4140 class getPos : public CppUnit::TestFixture
4141 {
4142 ::osl::FileBase::RC nError1;
4143 sal_uInt64 nCount_write, nCount_read;
4144
4145 public:
4146 // initialization
setUp()4147 void setUp( )
4148 {
4149 // create a tempfile in $TEMP/tmpdir/tmpname.
4150 createTestDirectory( aTmpName3 );
4151 createTestFile( aTmpName4 );
4152
4153 //write chars into the file.
4154 ::osl::File testFile( aTmpName4 );
4155
4156 nError1 = testFile.open( OpenFlag_Write );
4157 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4158 nError1 = testFile.write( pBuffer_Char, sizeof( pBuffer_Char ), nCount_write );
4159 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4160 nError1 = testFile.close( );
4161 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4162 }
4163
tearDown()4164 void tearDown( )
4165 {
4166 // remove the tempfile in $TEMP/tmpdir/tmpname.
4167 deleteTestFile( aTmpName4 );
4168 deleteTestDirectory( aTmpName3 );
4169 }
4170
4171 // test code.
getPos_001()4172 void getPos_001( )
4173 {
4174 ::osl::File testFile( aTmpName4 );
4175 sal_uInt64 nFilePointer;
4176
4177 nError1 = testFile.getPos( nFilePointer );
4178 CPPUNIT_ASSERT( ::osl::FileBase::E_INVAL == nError1 );
4179
4180 nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write );
4181 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4182
4183 nError1 = testFile.setPos( Pos_Absolut, 26 );
4184 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4185 nError1 = testFile.getPos( nFilePointer );
4186 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4187
4188 nError1 = testFile.close( );
4189 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4190
4191 CPPUNIT_ASSERT_MESSAGE( "test for getPos function: set the position to 26, get position and check if it is right",
4192 26 == nFilePointer );
4193 }
4194
4195 CPPUNIT_TEST_SUITE( getPos );
4196 CPPUNIT_TEST( getPos_001 );
4197 CPPUNIT_TEST_SUITE_END( );
4198 };// class getPos
4199
4200
4201 //---------------------------------------------------------------------
4202 // testing the method
4203 // inline RC isEndOfFile( sal_Bool *pIsEOF )
4204 //---------------------------------------------------------------------
4205 class isEndOfFile : public CppUnit::TestFixture
4206 {
4207 ::osl::FileBase::RC nError1;
4208 sal_uInt64 nCount_write, nCount_read;
4209
4210 public:
4211 // initialization
setUp()4212 void setUp( )
4213 {
4214 // create a tempfile in $TEMP/tmpdir/tmpname.
4215 createTestDirectory( aTmpName3 );
4216 createTestFile( aTmpName4 );
4217
4218 //write chars into the file.
4219 ::osl::File testFile( aTmpName4 );
4220
4221 nError1 = testFile.open( OpenFlag_Write );
4222 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4223 nError1 = testFile.write( pBuffer_Char, sizeof( pBuffer_Char ), nCount_write );
4224 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4225 nError1 = testFile.close( );
4226 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4227 }
4228
tearDown()4229 void tearDown( )
4230 {
4231 // remove the tempfile in $TEMP/tmpdir/tmpname.
4232 deleteTestFile( aTmpName4 );
4233 deleteTestDirectory( aTmpName3 );
4234 }
4235
4236 // test code.
isEndOfFile_001()4237 void isEndOfFile_001( )
4238 {
4239 ::osl::File testFile( aTmpName4 );
4240 sal_Bool bEOF = sal_False;
4241 sal_Bool *pEOF = &bEOF;
4242
4243
4244 nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write );
4245 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4246
4247 nError1 = testFile.setPos( Pos_End, 0 );
4248 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4249 nError1 = testFile.isEndOfFile( pEOF );
4250 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4251
4252 nError1 = testFile.close( );
4253 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4254
4255 CPPUNIT_ASSERT_MESSAGE( "test for isEndOfFile function: set the position to end, check if reach end",
4256 sal_True == *pEOF );
4257 }
4258
isEndOfFile_002()4259 void isEndOfFile_002( )
4260 {
4261 ::osl::File testFile( aTmpName4 );
4262 sal_Bool bEOF = sal_False;
4263 sal_Bool *pEOF = &bEOF;
4264 sal_uInt64 nFilePointer = 0;
4265
4266 nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write );
4267 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4268
4269 nError1 = testFile.setPos( Pos_Absolut, 0 );
4270 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4271 *pEOF = sal_False;
4272 while ( !( *pEOF ) )
4273 {
4274 nError1 = testFile.isEndOfFile( pEOF );
4275 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4276 nError1 = testFile.setPos( Pos_Current, 1 );
4277 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4278 }
4279 nError1 = testFile.getPos( nFilePointer );
4280 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4281
4282 nError1 = testFile.close( );
4283 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4284
4285 CPPUNIT_ASSERT_MESSAGE( "test for isEndOfFile function: use isEndOfFile to move pointer step by step",
4286 sizeof( pBuffer_Char ) + 1 == nFilePointer );
4287 }
4288 CPPUNIT_TEST_SUITE( isEndOfFile );
4289 CPPUNIT_TEST( isEndOfFile_001 );
4290 CPPUNIT_TEST( isEndOfFile_002 );
4291 CPPUNIT_TEST_SUITE_END( );
4292 };// class isEndOfFile
4293
4294
4295 //---------------------------------------------------------------------
4296 // testing the method
4297 // inline RC setSize( sal_uInt64 uSize )
4298 //---------------------------------------------------------------------
4299 class setSize : public CppUnit::TestFixture
4300 {
4301 ::osl::FileBase::RC nError1;
4302 sal_uInt64 nCount_write, nCount_read;
4303
4304 public:
4305 // initialization
setUp()4306 void setUp( )
4307 {
4308 // create a tempfile in $TEMP/tmpdir/tmpname.
4309 createTestDirectory( aTmpName3 );
4310 createTestFile( aTmpName4 );
4311
4312 //write chars into the file.
4313 ::osl::File testFile( aTmpName4 );
4314
4315 nError1 = testFile.open( OpenFlag_Write );
4316 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4317 nError1 = testFile.write( pBuffer_Char, sizeof( pBuffer_Char ), nCount_write );
4318 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4319 nError1 = testFile.close( );
4320 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4321 }
4322
tearDown()4323 void tearDown( )
4324 {
4325 // remove the tempfile in $TEMP/tmpdir/tmpname.
4326 deleteTestFile( aTmpName4 );
4327 deleteTestDirectory( aTmpName3 );
4328 }
4329
4330 // test code.
setSize_001()4331 void setSize_001( )
4332 {
4333 ::osl::File testFile( aTmpName4 );
4334 // sal_Bool bEOF = sal_False;
4335 // sal_Bool *pEOF = &bEOF;
4336 sal_uInt64 nFilePointer;
4337
4338
4339 nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write );
4340 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4341
4342 //enlarge the file to size of 100;
4343 nError1 = testFile.setSize( 100 );
4344 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4345
4346 //get the file size;
4347 nError1 = testFile.setPos( Pos_End, 0 );
4348 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4349 nError1 = testFile.getPos( nFilePointer );
4350 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4351
4352 nError1 = testFile.close( );
4353 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4354
4355 CPPUNIT_ASSERT_MESSAGE( "test for setSize function: enlarge the file ",
4356 100 == nFilePointer );
4357 }
4358
setSize_002()4359 void setSize_002( )
4360 {
4361 ::osl::File testFile( aTmpName4 );
4362 // sal_Bool bEOF = sal_False;
4363 // sal_Bool *pEOF = &bEOF;
4364 sal_uInt64 nFilePointer;
4365
4366
4367 nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write );
4368 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4369
4370 //enlarge the file to size of 100;
4371 nError1 = testFile.setSize( 10 );
4372 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4373
4374 //get the file size;
4375 nError1 = testFile.setPos( Pos_End, 0 );
4376 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4377 nError1 = testFile.getPos( nFilePointer );
4378 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4379
4380 nError1 = testFile.close( );
4381 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4382
4383 CPPUNIT_ASSERT_MESSAGE( "test for setSize function: truncate the file ",
4384 10 == nFilePointer );
4385 }
4386 /* void setSize_003( )
4387 {
4388 ::osl::File testFile( aTmpName4 );
4389 // sal_Bool bEOF = sal_False;
4390 // sal_Bool *pEOF = &bEOF;
4391 sal_uInt64 nFilePointer;
4392
4393
4394 nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write );
4395 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4396
4397 //enlarge the file to size of 100;
4398 nError1 = testFile.setSize( 10 );
4399 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4400
4401 //get the file size;
4402 nError1 = testFile.setPos( Pos_End, 0 );
4403 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4404 nError1 = testFile.getPos( nFilePointer );
4405 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4406
4407 nError1 = testFile.close( );
4408 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4409
4410 CPPUNIT_ASSERT_MESSAGE( "test for setSize function: truncate the file ",
4411 10 == nFilePointer );
4412 }
4413 */
4414
4415 CPPUNIT_TEST_SUITE( setSize );
4416 CPPUNIT_TEST( setSize_001 );
4417 CPPUNIT_TEST( setSize_002 );
4418 CPPUNIT_TEST_SUITE_END( );
4419 };// class setSize
4420
4421
4422 //---------------------------------------------------------------------
4423 // testing the method
4424 // inline RC read( void *pBuffer, sal_uInt64 uBytesRequested, sal_uInt64& rBytesRead )
4425 //---------------------------------------------------------------------
4426 class read : public CppUnit::TestFixture
4427 {
4428 ::osl::FileBase::RC nError1;
4429 sal_uInt64 nCount_write, nCount_read;
4430
4431 public:
4432 // initialization
setUp()4433 void setUp( )
4434 {
4435 // create a tempfile in $TEMP/tmpdir/tmpname.
4436 createTestDirectory( aTmpName3 );
4437 createTestFile( aTmpName4 );
4438
4439 //write chars into the file.
4440 ::osl::File testFile( aTmpName4 );
4441
4442 nError1 = testFile.open( OpenFlag_Write );
4443 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4444 nError1 = testFile.write( pBuffer_Char, sizeof( pBuffer_Char ), nCount_write );
4445 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4446 nError1 = testFile.close( );
4447 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4448 }
4449
tearDown()4450 void tearDown( )
4451 {
4452 // remove the tempfile in $TEMP/tmpdir/tmpname.
4453 deleteTestFile( aTmpName4 );
4454 deleteTestDirectory( aTmpName3 );
4455 }
4456
4457 // test code.
read_001()4458 void read_001( )
4459 {
4460 ::osl::File testFile( aTmpName4 );
4461 sal_uInt64 nFilePointer;
4462 sal_Char buffer_read[10];
4463
4464
4465 nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write );
4466 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4467
4468 nError1 = testFile.read( buffer_read, 10, nCount_read );
4469 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4470 nError1 = testFile.getPos( nFilePointer );
4471 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4472
4473 nError1 = testFile.close( );
4474 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4475
4476 CPPUNIT_ASSERT_MESSAGE( "test for read function: read whole content in the file to a buffer",
4477 ( 10 == nFilePointer ) && ( 0 == strncmp( buffer_read, pBuffer_Char, 10 ) ) );
4478 }
4479
read_002()4480 void read_002( )
4481 {
4482 ::osl::File testFile( aTmpName4 );
4483 sal_uInt64 nFilePointer;
4484 sal_Char buffer_read[26];
4485
4486
4487 nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write );
4488 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4489
4490 nError1 = testFile.setPos( Pos_Absolut, 26 );
4491 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4492 nError1 = testFile.read( buffer_read, 26, nCount_read );
4493 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4494 nError1 = testFile.getPos( nFilePointer );
4495 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4496
4497 nError1 = testFile.close( );
4498 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4499
4500 CPPUNIT_ASSERT_MESSAGE( "test for read function: read from a special positon in the file",
4501 ( 52 == nFilePointer ) && ( 26 == nCount_read ) && ( 0 == strncmp( buffer_read, &pBuffer_Char[26], 26 ) ) );
4502 }
4503
4504 CPPUNIT_TEST_SUITE( read );
4505 CPPUNIT_TEST( read_001 );
4506 CPPUNIT_TEST( read_002 );
4507 CPPUNIT_TEST_SUITE_END( );
4508 };// class read
4509
4510 //---------------------------------------------------------------------
4511 // testing the method
4512 // inline RC write(const void *pBuffer, sal_uInt64 uBytesToWrite, sal_uInt64& rBytesWritten)
4513 //---------------------------------------------------------------------
4514 class write : public CppUnit::TestFixture
4515 {
4516 ::osl::FileBase::RC nError1;
4517 sal_uInt64 nCount_write, nCount_read;
4518
4519 public:
4520 // initialization
setUp()4521 void setUp( )
4522 {
4523 // create a tempfile in $TEMP/tmpname.
4524 createTestFile( aTmpName6 );
4525 }
4526
tearDown()4527 void tearDown( )
4528 {
4529 // remove the tempfile in $TEMP/tmpname.
4530 deleteTestFile( aTmpName6 );
4531 }
4532
4533 // test code.
write_001()4534 void write_001( )
4535 {
4536 ::osl::File testFile( aTmpName6 );
4537 sal_uInt64 nFilePointer;
4538 sal_Char buffer_read[10];
4539
4540 nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write );
4541 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4542
4543 //write chars into the file.
4544 nError1 = testFile.write( pBuffer_Char, 10, nCount_write );
4545 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4546 //get the current pointer;
4547 nError1 = testFile.getPos( nFilePointer );
4548 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4549 //reset pointer to the begining;
4550 nError1 = testFile.setPos( Pos_Absolut, 0 );
4551 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4552 nError1 = testFile.read( buffer_read, 10, nCount_read );
4553 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4554
4555 nError1 = testFile.close( );
4556 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4557
4558 CPPUNIT_ASSERT_MESSAGE( "test for write function: read whole content in the file to a buffer. Note, buffer size can not smaller than the read size",
4559 ( 10 == nFilePointer ) &&
4560 ( 0 == strncmp( buffer_read, pBuffer_Char, 10 ) ) &&
4561 ( 10 == nCount_write ) );
4562 }
4563
4564 CPPUNIT_TEST_SUITE( write );
4565 CPPUNIT_TEST( write_001 );
4566 CPPUNIT_TEST_SUITE_END( );
4567 };// class write
4568
4569 //---------------------------------------------------------------------
4570 // testing the method
4571 // inline RC readLine( ::rtl::ByteSequence& aSeq )
4572 //---------------------------------------------------------------------
4573 class readLine : public CppUnit::TestFixture
4574 {
4575 ::osl::FileBase::RC nError1;
4576 sal_uInt64 nCount_write, nCount_read;
4577 ::rtl::ByteSequence aSequence;
4578
4579 public:
4580 // initialization
setUp()4581 void setUp( )
4582 {
4583 // create a tempfile in $TEMP/tmpname.
4584 createTestFile( aTmpName6 );
4585
4586 //write some strings into the file.
4587 ::osl::File testFile( aTmpName6 );
4588 sal_Char ppStrSeq[3][27] = { "abcde\n",
4589 "1234567890\n",
4590 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
4591 };
4592
4593 nError1 = testFile.open( OpenFlag_Write );
4594 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4595
4596 for ( int nCount = 0; nCount < 3; nCount++ )
4597 {
4598 nError1 = testFile.write( ppStrSeq[nCount], strlen( ppStrSeq[nCount] ), nCount_write );
4599 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4600 }
4601
4602 nError1 = testFile.close( );
4603 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4604 }
4605
tearDown()4606 void tearDown( )
4607 {
4608 // remove the tempfile in $TEMP/tmpname.
4609 deleteTestFile( aTmpName6 );
4610 }
4611
4612 // test code.
readLine_001()4613 void readLine_001( )
4614 {
4615 ::osl::File testFile( aTmpName6 );
4616
4617 nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write );
4618 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4619 nError1 = testFile.readLine( aSequence );
4620 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4621
4622 CPPUNIT_ASSERT_MESSAGE( "test for readLine function: read the first line of the file.",
4623 ( ::osl::FileBase::E_None == nError1 ) &&
4624 ( 0 == strncmp( ( const char * )aSequence.getArray( ), pBuffer_Char, 5 ) ) );
4625 }
4626
readLine_002()4627 void readLine_002( )
4628 {
4629 ::osl::File testFile( aTmpName6 );
4630 sal_Bool bEOF = sal_False;
4631 sal_Bool *pEOF = &bEOF;
4632
4633 nError1 = testFile.open( OpenFlag_Read | OpenFlag_Write );
4634 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4635 for ( int nCount = 0; nCount < 3; nCount++ )
4636 {
4637 nError1 = testFile.readLine( aSequence );
4638 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4639 }
4640 nError1 = testFile.isEndOfFile( pEOF );
4641 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4642
4643 CPPUNIT_ASSERT_MESSAGE( "test for readLine function: read three lines of the file and check the file pointer moving.",
4644 *pEOF &&
4645 ( 0 == strncmp( ( const char * )aSequence.getArray( ), &pBuffer_Char[26], 26 ) ) );
4646 }
4647 CPPUNIT_TEST_SUITE( readLine );
4648 CPPUNIT_TEST( readLine_001 );
4649 CPPUNIT_TEST( readLine_002 );
4650 CPPUNIT_TEST_SUITE_END( );
4651 };// class readLine
4652
4653 //---------------------------------------------------------------------
4654 // testing the method
4655 // inline static RC copy( const ::rtl::OUString& ustrSourceFileURL, const ::rtl::OUString& ustrDestFileURL )
4656 //---------------------------------------------------------------------
4657 class copy : public CppUnit::TestFixture
4658 {
4659 ::osl::FileBase::RC nError1;
4660 sal_uInt64 nCount_write, nCount_read;
4661
4662 public:
4663 // initialization
setUp()4664 void setUp( )
4665 {
4666 // create a tempfile in $TEMP/tmpdir/tmpname.
4667 createTestDirectory( aTmpName3 );
4668 createTestFile( aTmpName4 );
4669
4670 //write chars into the file.
4671 ::osl::File testFile( aTmpName4 );
4672
4673 nError1 = testFile.open( OpenFlag_Write );
4674 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4675 nError1 = testFile.write( pBuffer_Char, sizeof( pBuffer_Char ), nCount_write );
4676 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4677 nError1 = testFile.close( );
4678 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4679 }
4680
tearDown()4681 void tearDown( )
4682 {
4683 // remove the tempfile in $TEMP/tmpdir/tmpname.
4684 deleteTestFile( aTmpName4 );
4685 deleteTestDirectory( aTmpName3 );
4686 }
4687
4688 // test code.
copy_001()4689 void copy_001( )
4690 {
4691 ::osl::File testFile( aTmpName6 );
4692
4693 //copy $TEMP/tmpdir/tmpname to $TEMP/tmpname.
4694 nError1 = ::osl::File::copy( aTmpName4, aTmpName6 );
4695 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4696 //check
4697 nError1 = testFile.open( OpenFlag_Create );
4698 deleteTestFile( aTmpName6 );
4699
4700 CPPUNIT_ASSERT_MESSAGE( "test for copy function: copy file to upper directory",
4701 ::osl::FileBase::E_EXIST == nError1 );
4702 }
4703
copy_002()4704 void copy_002( )
4705 {
4706 //copy $TEMP/tmpdir/tmpname to $TEMP/tmpdir.
4707 nError1 = ::osl::File::copy( aTmpName4, aTmpName3 );
4708
4709 CPPUNIT_ASSERT_MESSAGE( "test for copy function: use directory as destination",
4710 ( ::osl::FileBase::E_ISDIR == nError1 ) ||( ::osl::FileBase::E_ACCES == nError1 ) );
4711 }
4712
copy_003()4713 void copy_003( )
4714 {
4715 //copy $TEMP/tmpdir/tmpname to $ROOT/tmpname.
4716 nError1 = ::osl::File::copy( aTmpName4, aTmpName7 );
4717 #if defined (WNT )
4718 nError1 = ::osl::FileBase::E_ACCES; /// for Windows, c:/ is writtenable any way.
4719 deleteTestFile( aTmpName7);
4720 #endif
4721 CPPUNIT_ASSERT_MESSAGE( "test for copy function: copy to an illigal place",
4722 ::osl::FileBase::E_ACCES == nError1 );
4723 }
4724
copy_004()4725 void copy_004( )
4726 {
4727 //copy $TEMP/tmpname to $TEMP/tmpdir/tmpname.
4728 nError1 = ::osl::File::copy( aTmpName6, aTmpName4 );
4729
4730 CPPUNIT_ASSERT_MESSAGE( "test for copy function: copy a not exist file",
4731 ::osl::FileBase::E_NOENT == nError1 );
4732 }
4733
copy_005()4734 void copy_005( )
4735 {
4736 //copy $TEMP/tmpname to $TEMP/system.path using system path.
4737 nError1 = ::osl::File::copy( aTmpName6, aSysPath1 );
4738
4739 CPPUNIT_ASSERT_MESSAGE( "test for copy function: copy a file using system file path",
4740 ::osl::FileBase::E_INVAL == nError1 );
4741 }
copy_006()4742 void copy_006( )
4743 {
4744 createTestFile( aTmpName6 );
4745 File tmpFile( aTmpName6 );
4746 FileBase::RC err = tmpFile.open( OpenFlag_Write | OpenFlag_Read );
4747 (void)err;
4748 tmpFile.setSize( 200 );
4749 tmpFile.close();
4750 //copy to new path
4751 nError1 = ::osl::File::copy( aTmpName6, aTmpName4 );
4752 CPPUNIT_ASSERT( nError1 == FileBase::E_None );
4753
4754 //check if is the new file
4755 File newFile( aTmpName4 );
4756 newFile.open( OpenFlag_Write | OpenFlag_Read );
4757 newFile.setPos( Pos_End, 0 );
4758 // CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4759 sal_uInt64 nFilePointer;
4760 nError1 = newFile.getPos( nFilePointer );
4761 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4762 newFile.close( );
4763 deleteTestFile( aTmpName6 );
4764 CPPUNIT_ASSERT_MESSAGE( "test for copy function: the dest file exist",
4765 nFilePointer == 200 );
4766 }
4767 //copyLink has not been impletmented yet
copy_007()4768 void copy_007( )
4769 {
4770 #if ( defined UNX )
4771
4772 CPPUNIT_ASSERT_MESSAGE( "test for copy function: source file is link file",
4773 ::osl::FileBase::E_INVAL == nError1 );
4774 #endif
4775 }
4776
4777 CPPUNIT_TEST_SUITE( copy );
4778 CPPUNIT_TEST( copy_001 );
4779 CPPUNIT_TEST( copy_002 );
4780 CPPUNIT_TEST( copy_003 );
4781 CPPUNIT_TEST( copy_004 );
4782 CPPUNIT_TEST( copy_005 );
4783 CPPUNIT_TEST( copy_006 );
4784 CPPUNIT_TEST_SUITE_END( );
4785 };// class copy
4786
4787 //---------------------------------------------------------------------
4788 // testing the method
4789 // inline static RC move( const ::rtl::OUString& ustrSourceFileURL, const ::rtl::OUString& ustrDestFileURL )
4790 //---------------------------------------------------------------------
4791 class move : public CppUnit::TestFixture
4792 {
4793 ::osl::FileBase::RC nError1, nError2;
4794 sal_uInt64 nCount_write, nCount_read;
4795
4796 public:
4797 // initialization
setUp()4798 void setUp( )
4799 {
4800 // create a tempfile in $TEMP/tmpdir/tmpname.
4801 createTestDirectory( aTmpName3 );
4802 createTestFile( aTmpName4 );
4803
4804 //write chars into the file.
4805 ::osl::File testFile( aTmpName4 );
4806
4807 nError1 = testFile.open( OpenFlag_Write );
4808 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4809 nError1 = testFile.write( pBuffer_Char, sizeof( pBuffer_Char ), nCount_write );
4810 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4811 nError1 = testFile.close( );
4812 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4813 }
4814
tearDown()4815 void tearDown( )
4816 {
4817 // remove the tempfile in $TEMP/tmpdir/tmpname.
4818 deleteTestFile( aTmpName4 );
4819 deleteTestDirectory( aTmpName3 );
4820 }
4821
4822 // test code.
move_001()4823 void move_001( )
4824 {
4825 //rename $TEMP/tmpdir/tmpname to $TEMP/canonical.name.
4826 nError1 = ::osl::File::move( aTmpName4, aCanURL1 );
4827 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4828 //check
4829 ::osl::File testFile( aCanURL1 );
4830 nError2 = testFile.open( OpenFlag_Create );
4831 deleteTestFile( aCanURL1 );
4832
4833 CPPUNIT_ASSERT_MESSAGE( "test for move function: rename file to another directory",
4834 ::osl::FileBase::E_EXIST == nError2 );
4835 }
4836
move_002()4837 void move_002( )
4838 {
4839 //move $TEMP/tmpdir/tmpname to $TEMP/tmpdir.
4840 nError1 = ::osl::File::move( aTmpName4, aTmpName3 );
4841 //returned ::osl::FileBase::E_ACCES on WNT
4842 CPPUNIT_ASSERT_MESSAGE( "test for move function: use directory as destination",
4843 ( ::osl::FileBase::E_ACCES == nError1 || ::osl::FileBase::E_ISDIR == nError1 ) ||( ::osl::FileBase::E_EXIST == nError1 ) );
4844 }
4845
move_003()4846 void move_003( )
4847 {
4848 //move $TEMP/tmpdir/tmpname to $ROOT/tmpname.
4849 nError1 = ::osl::File::move( aTmpName4, aTmpName7 );
4850 #if defined (WNT )
4851 nError1 = ::osl::FileBase::E_ACCES; /// for Windows, c:/ is writtenable any way.
4852 deleteTestFile( aTmpName7);
4853 #endif
4854
4855 CPPUNIT_ASSERT_MESSAGE( "test for move function: move to an illigal place",
4856 ::osl::FileBase::E_ACCES == nError1 );
4857 }
4858
move_004()4859 void move_004( )
4860 {
4861 //move $TEMP/tmpname to $TEMP/tmpdir/tmpname.
4862 nError1 = ::osl::File::move( aTmpName6, aTmpName4 );
4863
4864 CPPUNIT_ASSERT_MESSAGE( "test for move function: move a not exist file",
4865 ::osl::FileBase::E_NOENT == nError1 );
4866 }
4867
move_005()4868 void move_005( )
4869 {
4870 //move $TEMP/tmpname to $TEMP/system.path using system path.
4871 nError1 = ::osl::File::move( aTmpName6, aSysPath1 );
4872
4873 CPPUNIT_ASSERT_MESSAGE( "test for move function: move a file using system file",
4874 ::osl::FileBase::E_INVAL == nError1 );
4875 }
4876
move_006()4877 void move_006( )
4878 {
4879 //move directory $TEMP/tmpname to $TEMP/tmpdir/tmpname.
4880 createTestDirectory( aTmpName6 );
4881 nError1 = ::osl::File::move( aTmpName6, aTmpName4 );
4882 //move file $TEMP/tmpdir/tmpname to $TEMP/tmpname
4883 nError2 = ::osl::File::move( aTmpName4, aTmpName6 );
4884 deleteTestDirectory( aTmpName6 );
4885 #if defined ( WNT )
4886 deleteTestDirectory( aTmpName4 );// in Windows, it can be moved!!!!! this is only for not influence the following test.
4887 deleteTestFile( aTmpName6 );
4888 nError1 = ::osl::FileBase::E_NOTDIR;
4889 nError2 = ::osl::FileBase::E_ISDIR;
4890 #endif
4891 CPPUNIT_ASSERT_MESSAGE( "test for move function: move a directory to an exist file with same name, did not pass in (W32)",
4892 ::osl::FileBase::E_NOTDIR == nError1 && ::osl::FileBase::E_ISDIR == nError2 );
4893 }
4894
move_007()4895 void move_007( )
4896 {
4897 //create directory $TEMP/tmpname.
4898 createTestDirectory( aTmpName6 );
4899 //move directory $TEMP/tmpdir to $TEMP/tmpname/tmpdir
4900 nError1 = ::osl::File::move( aTmpName3, aTmpName8 );
4901 //check
4902 nError2 = ::osl::Directory::create( aTmpName8 );
4903 ::osl::File::move( aTmpName8, aTmpName3 );
4904 deleteTestDirectory( aTmpName6 );
4905
4906 CPPUNIT_ASSERT_MESSAGE( "test for move function: move a directory to an exist file with same name",
4907 (::osl::FileBase::E_None == nError1 ) &&
4908 (::osl::FileBase::E_EXIST == nError2 ) );
4909 }
4910 // oldpath and newpath are not on the same filesystem.EXDEV,no such error no on Solaris, only on linux
move_008()4911 void move_008( )
4912 {
4913 CPPUNIT_ASSERT_MESSAGE( "oldpath and newpath are not on the same filesystem, should error returns",
4914 ::osl::FileBase::E_None == nError1 );
4915 }
4916 //bugid# 115420, after the bug fix, add the case
move_009()4917 void move_009( )
4918 {
4919 //create directory $TEMP/tmpname.
4920 createTestDirectory( aTmpName6 );
4921 //create directory $TEMP/tmpname/tmpdir
4922 createTestDirectory( aTmpName8 );
4923 //move directory $TEMP/tmpname to $TEMP/tmpname/tmpdir/tmpname
4924 rtl::OUString newName = aTmpName8 + OUString::createFromAscii("/tmpname");
4925 //printFileName( newName );
4926 nError1 = ::osl::File::move( aTmpName3, newName );
4927 //deleteTestDirectory( newName + OUString::createFromAscii("/tmpname") );
4928 //deleteTestDirectory( newName );
4929 deleteTestDirectory( aTmpName8 );
4930 deleteTestDirectory( aTmpName6 );
4931 CPPUNIT_ASSERT_MESSAGE( "test for move function: move a directory to it's subdirectory",
4932 ::osl::FileBase::E_None != nError1 );
4933 }
4934
4935 CPPUNIT_TEST_SUITE( move );
4936 CPPUNIT_TEST( move_001 );
4937 CPPUNIT_TEST( move_002 );
4938 CPPUNIT_TEST( move_003 );
4939 CPPUNIT_TEST( move_004 );
4940 CPPUNIT_TEST( move_005 );
4941 CPPUNIT_TEST( move_006 );
4942 CPPUNIT_TEST( move_007 );
4943 // CPPUNIT_TEST( move_008 );
4944 //CPPUNIT_TEST( move_009 );
4945 CPPUNIT_TEST_SUITE_END( );
4946 };// class move
4947
4948
4949 //---------------------------------------------------------------------
4950 // testing the method
4951 // inline static RC remove( const ::rtl::OUString& ustrFileURL )
4952 //---------------------------------------------------------------------
4953 class remove : public CppUnit::TestFixture
4954 {
4955 ::osl::FileBase::RC nError1, nError2;
4956 sal_uInt64 nCount_write, nCount_read;
4957
4958 public:
4959 // initialization
setUp()4960 void setUp( )
4961 {
4962 // create a tempfile in $TEMP/tmpdir/tmpname.
4963 createTestDirectory( aTmpName3 );
4964 createTestFile( aTmpName4 );
4965
4966 //write chars into the file.
4967 ::osl::File testFile( aTmpName4 );
4968
4969 nError1 = testFile.open( OpenFlag_Write );
4970 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4971 nError1 = testFile.write( pBuffer_Char, sizeof( pBuffer_Char ), nCount_write );
4972 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4973 nError1 = testFile.close( );
4974 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
4975 }
4976
tearDown()4977 void tearDown( )
4978 {
4979 // remove the tempfile in $TEMP/tmpdir/tmpname.
4980 deleteTestFile( aTmpName4 );
4981 deleteTestDirectory( aTmpName3 );
4982 }
4983
4984 // test code.
remove_001()4985 void remove_001( )
4986 {
4987 //remove $TEMP/tmpdir/tmpname.
4988 nError1 = ::osl::File::remove( aTmpName4 );
4989 //check
4990 ::osl::File testFile( aTmpName4 );
4991 nError2 = testFile.open( OpenFlag_Create );
4992
4993 CPPUNIT_ASSERT_MESSAGE( "test for remove function: remove a file",
4994 ( ::osl::FileBase::E_None == nError1 ) &&
4995 ( ::osl::FileBase::E_EXIST != nError2 ) );
4996 }
4997
remove_002()4998 void remove_002( )
4999 {
5000 //remove $TEMP/tmpname.
5001 nError1 = ::osl::File::remove( aTmpName6 );
5002
5003 CPPUNIT_ASSERT_MESSAGE( "test for remove function: remove a file not exist",
5004 ( ::osl::FileBase::E_NOENT == nError1 ) );
5005 }
5006
remove_003()5007 void remove_003( )
5008 {
5009 //remove $TEMP/system/path.
5010 nError1 = ::osl::File::remove( aSysPath2 );
5011
5012 CPPUNIT_ASSERT_MESSAGE( "test for remove function: removing a file not using full qualified URL",
5013 ( ::osl::FileBase::E_INVAL == nError1 ) );
5014 }
5015
remove_004()5016 void remove_004( )
5017 {
5018 //remove $TEMP/tmpdir.
5019 nError1 = ::osl::File::remove( aTmpName3 );
5020
5021 CPPUNIT_ASSERT_MESSAGE( "test for remove function: remove a directory",
5022 ( ::osl::FileBase::E_ISDIR == nError1 ) || ( ::osl::FileBase::E_ACCES == nError1 ));
5023 }
5024
5025 CPPUNIT_TEST_SUITE( remove );
5026 CPPUNIT_TEST( remove_001 );
5027 CPPUNIT_TEST( remove_002 );
5028 CPPUNIT_TEST( remove_003 );
5029 CPPUNIT_TEST( remove_004 );
5030 CPPUNIT_TEST_SUITE_END( );
5031 };// class remove
5032
5033
5034 //---------------------------------------------------------------------
5035 // testing the method
5036 // inline static RC setAttributes( const ::rtl::OUString& ustrFileURL, sal_uInt64 uAttributes )
5037 //---------------------------------------------------------------------
5038 class setAttributes : public CppUnit::TestFixture
5039 {
5040 ::osl::FileBase::RC nError1, nError2;
5041 ::osl::DirectoryItem rItem, rItem_hidden;
5042
5043 public:
5044 // initialization
setUp()5045 void setUp( )
5046 {
5047 // create a tempfile in $TEMP/tmpdir/tmpname.
5048 createTestFile( aTmpName6 );
5049 }
5050
tearDown()5051 void tearDown( )
5052 {
5053 // remove the tempfile in $TEMP/tmpdir/tmpname.
5054 deleteTestFile( aTmpName6 );
5055 }
5056
5057 // test code.
setAttributes_001()5058 void setAttributes_001( )
5059 {
5060 //on windows, only can set 2 attributes: Attribute_ReadOnly, Attribute_HIDDEN
5061 #ifdef UNX
5062 //set the file to readonly
5063 nError2 = ::osl::File::setAttributes( aTmpName6, Attribute_ReadOnly | Attribute_GrpRead | Attribute_OwnRead | Attribute_OthRead );
5064 CPPUNIT_ASSERT( nError2 == FileBase::E_None);
5065 nError1 = ::osl::DirectoryItem::get( aTmpName6, rItem );
5066 CPPUNIT_ASSERT( nError1 == FileBase::E_None);
5067 //get the file attributes
5068 ::osl::FileStatus rFileStatus( FileStatusMask_Attributes );
5069 nError1 = rItem.getFileStatus( rFileStatus );
5070 CPPUNIT_ASSERT( nError1 == FileBase::E_None );
5071
5072 CPPUNIT_ASSERT_MESSAGE( "test for setAttributes function: set file attributes and get it to verify.",
5073 ( Attribute_ReadOnly | Attribute_GrpRead | Attribute_OwnRead | Attribute_OthRead ) ==
5074 rFileStatus.getAttributes( ) );
5075 #else
5076 //please see GetFileAttributes
5077 nError2 = ::osl::File::setAttributes( aTmpName6, Attribute_ReadOnly );
5078 CPPUNIT_ASSERT( nError2 == FileBase::E_None);
5079 nError1 = ::osl::DirectoryItem::get( aTmpName6, rItem );
5080 CPPUNIT_ASSERT( nError1 == FileBase::E_None);
5081 //get the file attributes
5082 ::osl::FileStatus rFileStatus( FileStatusMask_Attributes );
5083 nError1 = rItem.getFileStatus( rFileStatus );
5084 CPPUNIT_ASSERT( nError1 == FileBase::E_None );
5085 //here the file has 2 Attributes: FILE_ATTRIBUTE_READONLY and FILE_ATTRIBUTE_NORMAL,
5086 // but FILE_ATTRIBUTE_NORMAL is valid only if used alone, so this is maybe a bug
5087 /*::rtl::OString aString = ::rtl::OUStringToOString( aTmpName6, RTL_TEXTENCODING_ASCII_US );
5088 DWORD dwFileAttributes = GetFileAttributes( aString.getStr( ) );
5089 if (dwFileAttributes & FILE_ATTRIBUTE_NORMAL)
5090 t_print("has normal attribute");
5091 if (dwFileAttributes & FILE_ATTRIBUTE_READONLY)
5092 t_print("has readonly attribute");
5093 */
5094 CPPUNIT_ASSERT_MESSAGE( "test for setAttributes function: set file attributes READONLY and get it to verify.",
5095 (Attribute_ReadOnly & rFileStatus.getAttributes( )) != 0 );
5096 #endif
5097 }
setAttributes_002()5098 void setAttributes_002( )
5099 {
5100 //on UNX, can not set hidden attribute to file, rename file can set the attribute
5101 #ifdef WNT
5102 //set the file to hidden
5103 nError2 = ::osl::File::setAttributes( aTmpName6, Attribute_Hidden);
5104
5105 CPPUNIT_ASSERT( nError2 == FileBase::E_None);
5106 nError1 = ::osl::DirectoryItem::get( aTmpName6, rItem );
5107 CPPUNIT_ASSERT( nError1 == FileBase::E_None);
5108 //get the file attributes
5109 ::osl::FileStatus rFileStatus( FileStatusMask_Attributes );
5110 nError1 = rItem.getFileStatus( rFileStatus );
5111 CPPUNIT_ASSERT( nError1 == FileBase::E_None );
5112
5113 CPPUNIT_ASSERT_MESSAGE( "test for setAttributes function: set file attributes and get it to verify.",
5114 (Attribute_Hidden & rFileStatus.getAttributes( )) != 0 );
5115 #endif
5116 }
5117
5118 CPPUNIT_TEST_SUITE( setAttributes );
5119 CPPUNIT_TEST( setAttributes_001 );
5120 CPPUNIT_TEST( setAttributes_002 );
5121 CPPUNIT_TEST_SUITE_END( );
5122 };// class setAttributes
5123
5124
5125 //---------------------------------------------------------------------
5126 // testing the method
5127 // inline static RC setTime(
5128 // const ::rtl::OUString& ustrFileURL,
5129 // const TimeValue& rCreationTime,
5130 // const TimeValue& rLastAccessTime,
5131 // const TimeValue& rLastWriteTime )
5132 //---------------------------------------------------------------------
5133 class setTime : public CppUnit::TestFixture
5134 {
5135 ::osl::FileBase::RC nError1, nError2;
5136 ::osl::DirectoryItem rItem;
5137
5138 public:
5139 // initialization
setUp()5140 void setUp( )
5141 {
5142 // create a tempfile in $TEMP/tmpdir/tmpname.
5143 createTestFile( aTmpName6 );
5144 }
5145
tearDown()5146 void tearDown( )
5147 {
5148 // remove the tempfile in $TEMP/tmpdir/tmpname.
5149 deleteTestFile( aTmpName6 );
5150 }
5151
5152 // test code.
setTime_001()5153 void setTime_001( )
5154 {
5155 TimeValue *pTV_current = NULL;
5156 CPPUNIT_ASSERT( ( pTV_current = ( TimeValue* )malloc( sizeof( TimeValue ) ) ) != NULL );
5157 TimeValue *pTV_creation = NULL;
5158 CPPUNIT_ASSERT( ( pTV_creation = ( TimeValue* )malloc( sizeof( TimeValue ) ) ) != NULL );
5159 TimeValue *pTV_access = NULL;
5160 CPPUNIT_ASSERT( ( pTV_access = ( TimeValue* )malloc( sizeof( TimeValue ) ) ) != NULL );
5161 TimeValue *pTV_modify = NULL;
5162 CPPUNIT_ASSERT( ( pTV_modify = ( TimeValue* )malloc( sizeof( TimeValue ) ) ) != NULL );
5163
5164 //get current time
5165 sal_Bool bOk = osl_getSystemTime( pTV_current );
5166 CPPUNIT_ASSERT( sal_True == bOk );
5167
5168 //set the file time
5169 nError2 = ::osl::File::setTime( aTmpName6, *pTV_current, *pTV_current, *pTV_current );
5170 CPPUNIT_ASSERT_MESSAGE( errorToStr( nError2 ), nError2 == FileBase::E_None);
5171
5172 //get the file access time, creation time, modify time
5173 nError1 = ::osl::DirectoryItem::get( aTmpName6, rItem );
5174 CPPUNIT_ASSERT_MESSAGE( errorToStr( nError1 ), nError1 == FileBase::E_None);
5175
5176 ::osl::FileStatus rFileStatus( FileStatusMask_AccessTime );
5177 nError1 = rItem.getFileStatus( rFileStatus );
5178 CPPUNIT_ASSERT_MESSAGE( errorToStr( nError1 ),nError1 == FileBase::E_None );
5179 *pTV_access = rFileStatus.getAccessTime( );
5180
5181 ::osl::FileStatus rFileStatus1( FileStatusMask_CreationTime );
5182 nError1 = rItem.getFileStatus( rFileStatus1 );
5183 CPPUNIT_ASSERT_MESSAGE( errorToStr( nError1 ), nError1 == FileBase::E_None );
5184 *pTV_creation = rFileStatus1.getCreationTime( );
5185
5186 ::osl::FileStatus rFileStatus2( FileStatusMask_ModifyTime );
5187 nError1 = rItem.getFileStatus( rFileStatus2 );
5188 CPPUNIT_ASSERT_MESSAGE( errorToStr( nError1 ), nError1 == FileBase::E_None );
5189 *pTV_modify = rFileStatus2.getModifyTime( );
5190
5191 CPPUNIT_ASSERT_MESSAGE( "test for setTime function: set access time then get it. time precision is still a problem for it cut off the nanosec.",
5192 sal_True == t_compareTime( pTV_access, pTV_current, delta ) );
5193 #if defined ( WNT )
5194 //Unfortunately there is no way to get the creation time of a file under Unix (its a Windows only feature).
5195 //That means the flag osl_FileStatus_Mask_CreationTime should be deprecated under Unix.
5196 CPPUNIT_ASSERT_MESSAGE( "test for setTime function: set creation time then get it. ",
5197 sal_True == t_compareTime( pTV_creation, pTV_current, delta ) ) ;
5198 #endif
5199 CPPUNIT_ASSERT_MESSAGE( "test for setTime function: set modify time then get it. ",
5200 sal_True == t_compareTime( pTV_modify, pTV_current, delta ) );
5201 free( pTV_current );
5202 free( pTV_creation );
5203 free( pTV_access );
5204 free( pTV_modify );
5205 }
5206
5207 CPPUNIT_TEST_SUITE( setTime );
5208 CPPUNIT_TEST( setTime_001 );
5209 CPPUNIT_TEST_SUITE_END( );
5210 };// class setTime
5211
5212 //---------------------------------------------------------------------
5213 // testing the method
5214 // inline static RC sync()
5215 //---------------------------------------------------------------------
5216 class sync : public CppUnit::TestFixture
5217 {
5218 ::osl::FileBase::RC nError1, nError2;
5219 ::osl::DirectoryItem rItem;
5220
5221 public:
5222 // initialization
setUp()5223 void setUp( )
5224 {
5225 // create a tempfile in $TEMP/tmpdir/tmpname.
5226 createTestFile( aTmpName6 );
5227
5228 }
5229
tearDown()5230 void tearDown( )
5231 {
5232 // remove the tempfile in $TEMP/tmpdir/tmpname.
5233 deleteTestFile( aTmpName6 );
5234 }
5235
5236 // test case: if The file is located on a read only file system.
sync_001()5237 void sync_001( )
5238 {
5239 #ifdef UNX
5240 nError1 = ::osl::DirectoryItem::get( aTmpName6, rItem );
5241 CPPUNIT_ASSERT( nError1 == FileBase::E_None);
5242
5243 File tmp_file( aTmpName6 );
5244 FileBase::RC err = tmp_file.open(osl_File_OpenFlag_Write );
5245
5246 CPPUNIT_ASSERT_MESSAGE("File open failed", err == FileBase::E_None);
5247
5248 char buffer[50000];
5249 sal_uInt64 written = 0;
5250 nError1 = tmp_file.write((void*)buffer, sizeof(buffer), written);
5251 CPPUNIT_ASSERT_MESSAGE("write failed!", nError1 == FileBase::E_None);
5252
5253 //set the file to readonly
5254 nError2 = ::osl::File::setAttributes( aTmpName6, Attribute_ReadOnly | Attribute_GrpRead | Attribute_OwnRead | Attribute_OthRead );
5255 CPPUNIT_ASSERT( nError2 == FileBase::E_None);
5256
5257 nError2 = tmp_file.sync();
5258
5259 CPPUNIT_ASSERT_MESSAGE("can not sync to readonly file!", nError2 == FileBase::E_None);
5260
5261 tmp_file.close();
5262 #endif
5263 }
5264 //test case:no enough space, how to create such case???see test_cpy_wrt_file.cxx::test_osl_writeFile
5265
5266
5267
5268 CPPUNIT_TEST_SUITE( sync );
5269 CPPUNIT_TEST( sync_001 );
5270 CPPUNIT_TEST_SUITE_END( );
5271 };// class setTime
5272
5273 // -----------------------------------------------------------------------------
5274 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::ctors, "osl_File" );
5275 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::open, "osl_File" );
5276 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::close, "osl_File" );
5277 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::setPos, "osl_File" );
5278 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::getPos, "osl_File" );
5279 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::isEndOfFile, "osl_File" );
5280 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::setSize, "osl_File" );
5281 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::read, "osl_File" );
5282 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::write, "osl_File" );
5283 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::readLine, "osl_File" );
5284 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::copy, "osl_File" );
5285 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::move, "osl_File" );
5286 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::remove, "osl_File" );
5287 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::setAttributes, "osl_File" );
5288 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::setTime, "osl_File" );
5289 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_File::sync, "osl_File" );
5290
5291 }// namespace osl_File
5292
5293
5294 //------------------------------------------------------------------------
5295 // Beginning of the test cases for DirectoryItem class
5296 //------------------------------------------------------------------------
5297 namespace osl_DirectoryItem
5298 {
5299 //---------------------------------------------------------------------
5300 // testing the method
5301 // DirectoryItem(): _pData( NULL )
5302 //---------------------------------------------------------------------
5303 class ctors : public CppUnit::TestFixture
5304 {
5305 ::osl::FileBase::RC nError1, nError2;
5306
5307 public:
5308 // initialization
setUp()5309 void setUp( )
5310 {
5311 // create a tempfile in $TEMP/tmpname.
5312 createTestFile( aTmpName6 );
5313 }
5314
tearDown()5315 void tearDown( )
5316 {
5317 // remove the tempfile in $TEMP/tmpname.
5318 deleteTestFile( aTmpName6 );
5319 }
5320
5321 // test code.
ctors_001()5322 void ctors_001( )
5323 {
5324 ::osl::File testFile( aTmpName6 );
5325 ::osl::DirectoryItem rItem; //constructor
5326
5327 //get the DirectoryItem.
5328 nError1 = ::osl::DirectoryItem::get( aTmpName6, rItem );
5329 CPPUNIT_ASSERT( FileBase::E_None == nError1 );
5330
5331 CPPUNIT_ASSERT_MESSAGE( "test for ctors function: initialize a new instance of DirectoryItem and get an item to check.",
5332 ::osl::FileBase::E_None == nError1 );
5333 }
5334
5335 CPPUNIT_TEST_SUITE( ctors );
5336 CPPUNIT_TEST( ctors_001 );
5337 CPPUNIT_TEST_SUITE_END( );
5338 };// class ctors
5339
5340 //---------------------------------------------------------------------
5341 // testing the method
5342 // DirectoryItem( const DirectoryItem& rItem ): _pData( rItem._pData)
5343 //---------------------------------------------------------------------
5344 class copy_assin_Ctors : public CppUnit::TestFixture
5345 {
5346 ::osl::FileBase::RC nError1, nError2;
5347
5348 public:
5349 // initialization
setUp()5350 void setUp( )
5351 {
5352 // create a tempfile in $TEMP/tmpname.
5353 createTestFile( aTmpName6 );
5354 }
5355
tearDown()5356 void tearDown( )
5357 {
5358 // remove the tempfile in $TEMP/tmpname.
5359 deleteTestFile( aTmpName6 );
5360 }
5361
5362 // test code.
copy_assin_Ctors_001()5363 void copy_assin_Ctors_001( )
5364 {
5365 ::osl::DirectoryItem rItem; //constructor
5366 //get the DirectoryItem.
5367 nError1 = ::osl::DirectoryItem::get( aTmpName6, rItem );
5368 CPPUNIT_ASSERT( FileBase::E_None == nError1 );
5369
5370 ::osl::DirectoryItem copyItem( rItem ); //copy constructor
5371 ::osl::FileStatus rFileStatus( FileStatusMask_FileName );
5372 nError1 = copyItem.getFileStatus( rFileStatus );
5373 CPPUNIT_ASSERT( nError1 == FileBase::E_None );
5374
5375 CPPUNIT_ASSERT_MESSAGE( "test for copy_assin_Ctors function: use copy constructor to get an item and check filename.",
5376 ( sal_True == compareFileName( rFileStatus.getFileName( ), aTmpName2 ) ) );
5377 }
5378
copy_assin_Ctors_002()5379 void copy_assin_Ctors_002( )
5380 {
5381 ::osl::DirectoryItem rItem; //constructor
5382 //get the DirectoryItem.
5383 nError1 = ::osl::DirectoryItem::get( aTmpName6, rItem );
5384 CPPUNIT_ASSERT( FileBase::E_None == nError1 );
5385
5386 ::osl::DirectoryItem copyItem;
5387 copyItem = rItem; //assinment operator
5388 ::osl::FileStatus rFileStatus( FileStatusMask_FileName );
5389 nError1 = copyItem.getFileStatus( rFileStatus );
5390 CPPUNIT_ASSERT( nError1 == FileBase::E_None );
5391
5392 CPPUNIT_ASSERT_MESSAGE( "test for copy_assin_Ctors function: test assinment operator here since it is same as copy constructor in test way.",
5393 ( sal_True == compareFileName( rFileStatus.getFileName( ), aTmpName2 ) ) );
5394 }
5395
5396 CPPUNIT_TEST_SUITE( copy_assin_Ctors );
5397 CPPUNIT_TEST( copy_assin_Ctors_001 );
5398 CPPUNIT_TEST( copy_assin_Ctors_002 );
5399 CPPUNIT_TEST_SUITE_END( );
5400 };// class copy_assin_Ctors
5401
5402 //---------------------------------------------------------------------
5403 // testing the method
5404 // inline sal_Bool is()
5405 //---------------------------------------------------------------------
5406 class is : public CppUnit::TestFixture
5407 {
5408 ::osl::FileBase::RC nError1, nError2;
5409
5410 public:
5411 // initialization
setUp()5412 void setUp( )
5413 {
5414 // create a tempfile in $TEMP/tmpname.
5415 createTestFile( aTmpName6 );
5416 }
5417
tearDown()5418 void tearDown( )
5419 {
5420 // remove the tempfile in $TEMP/tmpname.
5421 deleteTestFile( aTmpName6 );
5422 }
5423
5424 // test code.
is_001()5425 void is_001( )
5426 {
5427 ::osl::DirectoryItem rItem; //constructor
5428
5429 CPPUNIT_ASSERT_MESSAGE( "test for is function: use an uninitialized instance.",
5430 !rItem.is( ) );
5431 }
5432
is_002()5433 void is_002( )
5434 {
5435 ::osl::DirectoryItem rItem; //constructor
5436 //get the DirectoryItem.
5437 nError1 = ::osl::DirectoryItem::get( aTmpName6, rItem );
5438 CPPUNIT_ASSERT( FileBase::E_None == nError1 );
5439
5440 CPPUNIT_ASSERT_MESSAGE( "test for is function: use an uninitialized instance.",
5441 ( sal_True == rItem.is( ) ) );
5442 }
5443
5444 CPPUNIT_TEST_SUITE( is );
5445 CPPUNIT_TEST( is_001 );
5446 CPPUNIT_TEST( is_002 );
5447 CPPUNIT_TEST_SUITE_END( );
5448 };// class is
5449
5450 //---------------------------------------------------------------------
5451 // testing the method
5452 // static inline RC get( const ::rtl::OUString& ustrFileURL, DirectoryItem& rItem )
5453 //---------------------------------------------------------------------
5454 class get : public CppUnit::TestFixture
5455 {
5456 ::osl::FileBase::RC nError1, nError2;
5457
5458 public:
5459 // initialization
setUp()5460 void setUp( )
5461 {
5462 // create a tempfile in $TEMP/tmpname.
5463 createTestFile( aTmpName6 );
5464 }
5465
tearDown()5466 void tearDown( )
5467 {
5468 // remove the tempfile in $TEMP/tmpname.
5469 deleteTestFile( aTmpName6 );
5470 }
5471
5472 // test code.
get_001()5473 void get_001( )
5474 {
5475 ::osl::DirectoryItem rItem; //constructor
5476 //get the DirectoryItem.
5477 nError2 = ::osl::DirectoryItem::get( aTmpName6, rItem );
5478
5479 //check the file name
5480 ::osl::FileStatus rFileStatus( FileStatusMask_FileName );
5481 nError1 = rItem.getFileStatus( rFileStatus );
5482 CPPUNIT_ASSERT( nError1 == FileBase::E_None );
5483
5484 CPPUNIT_ASSERT_MESSAGE( "test for get function: use copy constructor to get an item and check filename.",
5485 ( ::osl::FileBase::E_None == nError2 ) &&
5486 ( sal_True == compareFileName( rFileStatus.getFileName( ), aTmpName2 ) ) );
5487 }
5488
get_002()5489 void get_002( )
5490 {
5491 ::osl::DirectoryItem rItem;
5492 //get the DirectoryItem.
5493 nError1 = ::osl::DirectoryItem::get( aSysPath1, rItem );
5494
5495 CPPUNIT_ASSERT_MESSAGE( "test for get function: use a system name instead of a URL.",
5496 FileBase::E_INVAL == nError1 );
5497 }
5498
get_003()5499 void get_003( )
5500 {
5501 ::osl::DirectoryItem rItem;
5502 //get the DirectoryItem.
5503 nError1 = ::osl::DirectoryItem::get( aTmpName3, rItem );
5504
5505 CPPUNIT_ASSERT_MESSAGE( "test for get function: use a non existed file URL.",
5506 FileBase::E_NOENT == nError1 );
5507 }
5508
5509 CPPUNIT_TEST_SUITE( get );
5510 CPPUNIT_TEST( get_001 );
5511 CPPUNIT_TEST( get_002 );
5512 CPPUNIT_TEST( get_003 );
5513 CPPUNIT_TEST_SUITE_END( );
5514 };// class get
5515
5516 //---------------------------------------------------------------------
5517 // testing the method
5518 // inline RC getFileStatus( FileStatus& rStatus )
5519 //---------------------------------------------------------------------
5520 class getFileStatus : public CppUnit::TestFixture
5521 {
5522 ::osl::FileBase::RC nError1, nError2;
5523
5524 public:
5525 // initialization
setUp()5526 void setUp( )
5527 {
5528 // create a tempfile in $TEMP/tmpdir/tmpname.
5529 createTestDirectory( aTmpName3 );
5530 createTestFile( aTmpName4 );
5531 }
5532
tearDown()5533 void tearDown( )
5534 {
5535 // remove the tempfile in $TEMP/tmpdir/tmpname.
5536 deleteTestFile( aTmpName4 );
5537 deleteTestDirectory( aTmpName3 );
5538 }
5539
5540 // test code.
getFileStatus_001()5541 void getFileStatus_001( )
5542 {
5543 ::osl::DirectoryItem rItem; //constructor
5544 //get the DirectoryItem.
5545 nError1 = ::osl::DirectoryItem::get( aTmpName4, rItem );
5546 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
5547
5548 //check the file name
5549 ::osl::FileStatus rFileStatus( FileStatusMask_FileName );
5550 nError2 = rItem.getFileStatus( rFileStatus );
5551
5552 CPPUNIT_ASSERT_MESSAGE( "test for getFileStatus function: get file status and check filename",
5553 ( ::osl::FileBase::E_None == nError2 ) &&
5554 ( sal_True == compareFileName( rFileStatus.getFileName( ), aTmpName2 ) ) );
5555 }
5556
getFileStatus_002()5557 void getFileStatus_002( )
5558 {
5559 ::osl::DirectoryItem rItem; //constructor
5560 //get the DirectoryItem.
5561 nError1 = ::osl::DirectoryItem::get( aTmpName6, rItem );
5562
5563 //check the file name
5564 ::osl::FileStatus rFileStatus( FileStatusMask_FileName );
5565 nError2 = rItem.getFileStatus( rFileStatus );
5566
5567 CPPUNIT_ASSERT_MESSAGE( "test for getFileStatus function: file not existed",
5568 ( ::osl::FileBase::E_INVAL == nError2 ) );
5569 }
5570
getFileStatus_003()5571 void getFileStatus_003( )
5572 {
5573 ::osl::DirectoryItem rItem; //constructor
5574 //get the DirectoryItem.
5575 nError1 = ::osl::DirectoryItem::get( aTmpName3, rItem );
5576 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
5577
5578 //check the file name
5579 ::osl::FileStatus rFileStatus( FileStatusMask_FileName );
5580 nError2 = rItem.getFileStatus( rFileStatus );
5581
5582 CPPUNIT_ASSERT_MESSAGE( "test for getFileStatus function: get directory information",
5583 ( ::osl::FileBase::E_None == nError2 ) &&
5584 ( sal_True == compareFileName( rFileStatus.getFileName( ), aTmpName1 ) ) );
5585 }
5586
5587
5588 CPPUNIT_TEST_SUITE( getFileStatus );
5589 CPPUNIT_TEST( getFileStatus_001 );
5590 CPPUNIT_TEST( getFileStatus_002 );
5591 CPPUNIT_TEST( getFileStatus_003 );
5592 CPPUNIT_TEST_SUITE_END( );
5593 };// class getFileStatus
5594
5595
5596
5597 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_DirectoryItem::ctors, "osl_DirectoryItem" );
5598 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_DirectoryItem::copy_assin_Ctors, "osl_DirectoryItem" );
5599 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_DirectoryItem::is, "osl_DirectoryItem" );
5600 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_DirectoryItem::get, "osl_DirectoryItem" );
5601 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_DirectoryItem::getFileStatus, "osl_DirectoryItem" );
5602 }// namespace osl_DirectoryItem
5603
5604
5605 //------------------------------------------------------------------------
5606 // Beginning of the test cases for Directory class
5607 //------------------------------------------------------------------------
5608 namespace osl_Directory
5609 {
5610 //---------------------------------------------------------------------
5611 // testing the method
5612 // Directory( const ::rtl::OUString& strPath ): _pData( 0 ), _aPath( strPath )
5613 //---------------------------------------------------------------------
5614 class ctors : public CppUnit::TestFixture
5615 {
5616 ::osl::FileBase::RC nError1, nError2;
5617
5618 public:
5619 // initialization
setUp()5620 void setUp( )
5621 {
5622 // create a tempfile in $TEMP/tmpdir/tmpname.
5623 createTestDirectory( aTmpName3 );
5624 createTestFile( aTmpName4 );
5625 }
5626
tearDown()5627 void tearDown( )
5628 {
5629 // remove the tempfile in $TEMP/tmpdir/tmpname.
5630 deleteTestFile( aTmpName4 );
5631 deleteTestDirectory( aTmpName3 );
5632 // LLA: t_print("tearDown done.\n");
5633 }
5634
5635 // test code.
ctors_001()5636 void ctors_001( )
5637 {
5638 ::osl::Directory testDirectory( aTmpName3 ); //constructor
5639
5640 //open a directory
5641 nError1 = testDirectory.open( );
5642 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
5643 //close a directory
5644 nError2 = testDirectory.close( );
5645 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError2 );
5646
5647 CPPUNIT_ASSERT_MESSAGE( "test for ctors function: create an instance and check open and close",
5648 ( ::osl::FileBase::E_None == nError1 ) &&
5649 ( ::osl::FileBase::E_None == nError2 ) );
5650 }
5651
ctors_002()5652 void ctors_002( )
5653 {
5654 ::osl::Directory testDirectory( aTmpName9 ); //constructor
5655
5656 //open a directory
5657 nError1 = testDirectory.open( );
5658 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
5659 //close a directory
5660 nError2 = testDirectory.close( );
5661 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError2 );
5662
5663 CPPUNIT_ASSERT_MESSAGE( "test for ctors function: relative URL, :-), it is also worked",
5664 ( ::osl::FileBase::E_None == nError1 ) &&
5665 ( ::osl::FileBase::E_None == nError2 ) );
5666 }
5667
5668 CPPUNIT_TEST_SUITE( ctors );
5669 CPPUNIT_TEST( ctors_001 );
5670 CPPUNIT_TEST( ctors_002 );
5671 CPPUNIT_TEST_SUITE_END( );
5672 };// class ctors
5673
5674 //---------------------------------------------------------------------
5675 // testing the method
5676 // inline RC open()
5677 //---------------------------------------------------------------------
5678 class open : public CppUnit::TestFixture
5679 {
5680 ::osl::FileBase::RC nError1, nError2;
5681
5682 public:
5683 // initialization
setUp()5684 void setUp( )
5685 {
5686 // create a tempfile in $TEMP/tmpdir/tmpname.
5687 createTestDirectory( aTmpName3 );
5688 createTestFile( aTmpName4 );
5689 }
5690
tearDown()5691 void tearDown( )
5692 {
5693 // remove the tempfile in $TEMP/tmpdir/tmpname.
5694 deleteTestFile( aTmpName4 );
5695 deleteTestDirectory( aTmpName3 );
5696 }
5697
5698 // test code.
open_001()5699 void open_001( )
5700 {
5701 ::osl::Directory testDirectory( aTmpName3 ); //constructor
5702
5703 //open a directory
5704 nError1 = testDirectory.open( );
5705 //check if directory is opened.
5706 sal_Bool bOk = testDirectory.isOpen( );
5707 //close a directory
5708 nError2 = testDirectory.close( );
5709
5710 CPPUNIT_ASSERT_MESSAGE( "test for open function: open a directory and check for open",
5711 ( sal_True == bOk ) &&
5712 ( ::osl::FileBase::E_None == nError1 ) &&
5713 ( ::osl::FileBase::E_None == nError2 ) );
5714 }
5715
open_002()5716 void open_002( )
5717 {
5718 ::osl::Directory testDirectory( aTmpName6 ); //constructor
5719
5720 //open a directory
5721 nError1 = testDirectory.open( );
5722 if ( ::osl::FileBase::E_None == nError1 )
5723 {
5724 nError2 = testDirectory.close( );
5725 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError2 );
5726 }
5727
5728 CPPUNIT_ASSERT_MESSAGE( "test for open function: open a file that is not existed",
5729 ( ::osl::FileBase::E_NOENT == nError1 ) );
5730 }
5731
open_003()5732 void open_003( )
5733 {
5734 ::osl::Directory testDirectory( aUserDirectorySys ); //constructor
5735
5736 //open a directory
5737 nError1 = testDirectory.open( );
5738 if ( ::osl::FileBase::E_None == nError1 )
5739 {
5740 nError2 = testDirectory.close( );
5741 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError2 );
5742 }
5743
5744 CPPUNIT_ASSERT_MESSAGE( "test for open function: using system path",
5745 ( ::osl::FileBase::E_INVAL == nError1 ) );
5746 }
5747
open_004()5748 void open_004( )
5749 {
5750 ::osl::Directory testDirectory( aTmpName4 ); //constructor
5751
5752 //open a directory
5753 nError1 = testDirectory.open( );
5754 if ( ::osl::FileBase::E_None == nError1 )
5755 {
5756 nError2 = testDirectory.close( );
5757 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError2 );
5758 }
5759
5760 CPPUNIT_ASSERT_MESSAGE( "test for open function: open a file instead of a directory",
5761 ( ::osl::FileBase::E_NOTDIR == nError1 ) || ( ::osl::FileBase::E_ACCES ) );
5762 }
5763
5764 CPPUNIT_TEST_SUITE( open );
5765 CPPUNIT_TEST( open_001 );
5766 CPPUNIT_TEST( open_002 );
5767 CPPUNIT_TEST( open_003 );
5768 CPPUNIT_TEST( open_004 );
5769 CPPUNIT_TEST_SUITE_END( );
5770 };// class open
5771
5772 //---------------------------------------------------------------------
5773 // testing the method
5774 // inline sal_Bool isOpen() { return _pData != NULL; };
5775 //---------------------------------------------------------------------
5776 class isOpen : public CppUnit::TestFixture
5777 {
5778 ::osl::FileBase::RC nError1, nError2;
5779
5780 public:
5781 // initialization
setUp()5782 void setUp( )
5783 {
5784 // create a tempfile in $TEMP/tmpdir/tmpname.
5785 createTestDirectory( aTmpName3 );
5786 createTestFile( aTmpName4 );
5787 }
5788
tearDown()5789 void tearDown( )
5790 {
5791 // remove the tempfile in $TEMP/tmpdir/tmpname.
5792 deleteTestFile( aTmpName4 );
5793 deleteTestDirectory( aTmpName3 );
5794 }
5795
5796 // test code.
isOpen_001()5797 void isOpen_001( )
5798 {
5799 ::osl::Directory testDirectory( aTmpName3 ); //constructor
5800
5801 //open a directory
5802 nError1 = testDirectory.open( );
5803 //check if directory is opened.
5804 sal_Bool bOk = testDirectory.isOpen( );
5805 //close a directory
5806 nError2 = testDirectory.close( );
5807
5808 CPPUNIT_ASSERT_MESSAGE( "test for isOpen function: open a directory and check for open",
5809 ( sal_True == bOk ) );
5810 }
5811
isOpen_002()5812 void isOpen_002( )
5813 {
5814 ::osl::Directory testDirectory( aTmpName3 ); //constructor
5815
5816 //check if directory is opened.
5817 sal_Bool bOk = testDirectory.isOpen( );
5818
5819 CPPUNIT_ASSERT_MESSAGE( "test for isOpen function: do not open a directory and check for open",
5820 !( sal_True == bOk ) );
5821 }
5822
5823 CPPUNIT_TEST_SUITE( isOpen );
5824 CPPUNIT_TEST( isOpen_001 );
5825 CPPUNIT_TEST( isOpen_002 );
5826 CPPUNIT_TEST_SUITE_END( );
5827 };// class isOpen
5828
5829 //---------------------------------------------------------------------
5830 // testing the method
5831 // inline RC close()
5832 //---------------------------------------------------------------------
5833 class close : public CppUnit::TestFixture
5834 {
5835 ::osl::FileBase::RC nError1, nError2;
5836
5837 public:
5838 // initialization
setUp()5839 void setUp( )
5840 {
5841 // create a tempdirectory : $TEMP/tmpdir.
5842 createTestDirectory( aTmpName3 );
5843 }
5844
tearDown()5845 void tearDown( )
5846 {
5847 // remove a tempdirectory : $TEMP/tmpdir.
5848 deleteTestDirectory( aTmpName3 );
5849 }
5850
5851 // test code.
close_001()5852 void close_001( )
5853 {
5854 ::osl::Directory testDirectory( aTmpName3 ); //constructor
5855
5856 //open a directory
5857 nError1 = testDirectory.open( );
5858 //close a directory
5859 nError2 = testDirectory.close( );
5860 //check if directory is opened.
5861 sal_Bool bOk = testDirectory.isOpen( );
5862
5863 CPPUNIT_ASSERT_MESSAGE( "test for isOpen function: close a directory and check for open",
5864 !( sal_True == bOk ) );
5865 }
5866
close_002()5867 void close_002( )
5868 {
5869 ::osl::Directory testDirectory( aTmpName3 ); //constructor
5870
5871 //close a directory
5872 nError1 = testDirectory.close( );
5873
5874 CPPUNIT_ASSERT_MESSAGE( "test for isOpen function: close a not opened directory",
5875 ( ::osl::FileBase::E_BADF == nError1 ) );
5876 }
5877
5878
5879 CPPUNIT_TEST_SUITE( close );
5880 CPPUNIT_TEST( close_001 );
5881 CPPUNIT_TEST( close_002 );
5882 CPPUNIT_TEST_SUITE_END( );
5883 };// class close
5884
5885 //---------------------------------------------------------------------
5886 // testing the method
5887 // inline RC reset()
5888 //---------------------------------------------------------------------
5889 class reset : public CppUnit::TestFixture
5890 {
5891 ::osl::FileBase::RC nError1, nError2;
5892 ::osl::DirectoryItem rItem;
5893
5894 public:
5895 // initialization
setUp()5896 void setUp( )
5897 {
5898 // create a tempdirectory : $TEMP/tmpdir.
5899 createTestDirectory( aTmpName3 );
5900 // create three files : $TEMP/tmpdir/tmpname, $TEMP/tmpdir/tmpdir, $TEMP/tmpdir/hiddenfile,
5901 createTestFile( aTmpName3, aTmpName2);
5902 createTestFile( aTmpName3, aTmpName1);
5903 createTestFile( aTmpName3, aHidURL1);
5904 }
5905
tearDown()5906 void tearDown( )
5907 {
5908 // remove three files : $TEMP/tmpdir/tmpname, $TEMP/tmpdir/tmpdir, $TEMP/tmpdir/hiddenfile,
5909 deleteTestFile( aTmpName3, aHidURL1);
5910 deleteTestFile( aTmpName3, aTmpName1);
5911 deleteTestFile( aTmpName3, aTmpName2);
5912 // remove a tempdirectory : $TEMP/tmpdir.
5913 deleteTestDirectory( aTmpName3 );
5914 }
5915
5916 // test code.
reset_001()5917 void reset_001( )
5918 {
5919 ::osl::Directory testDirectory( aTmpName3 ); //constructor
5920
5921 //open a directory
5922 nError1 = testDirectory.open( );
5923 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
5924 //get first Item
5925 nError1 = testDirectory.getNextItem( rItem, 1 );
5926 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
5927 //get second Item
5928 //mindy: nError1 = testDirectory.getNextItem( rItem, 0 );
5929 //mindy: CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
5930
5931 //reset enumeration
5932 nError2 = testDirectory.reset( );
5933 //get reseted Item, if reset does not work, getNextItem() should return the second Item (aTmpName1)
5934 nError1 = testDirectory.getNextItem( rItem, 0 );
5935 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
5936
5937 //check the file name
5938 ::osl::FileStatus rFileStatus( FileStatusMask_FileName );
5939 nError1 = rItem.getFileStatus( rFileStatus );
5940 //close a directory
5941 nError1 = testDirectory.close( );
5942 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
5943
5944 sal_Bool bOK1,bOK2;
5945 bOK1 = compareFileName( rFileStatus.getFileName( ), aTmpName2 );
5946 bOK2 = compareFileName( rFileStatus.getFileName( ), aHidURL1 );
5947
5948 CPPUNIT_ASSERT_MESSAGE( "test for reset function: get two directory item, reset it, then get again, check the filename",
5949 ( ::osl::FileBase::E_None == nError2 ) &&
5950 ( sal_True == bOK1 || bOK2 ) );
5951 }
5952
reset_002()5953 void reset_002( )
5954 {
5955 ::osl::Directory testDirectory( aTmpName6 ); //constructor
5956
5957 //close a directory
5958 nError1 = testDirectory.reset( );
5959
5960 CPPUNIT_ASSERT_MESSAGE( "test for reset function: reset a non existed directory",
5961 ( ::osl::FileBase::E_NOENT == nError1 ) );
5962 }
5963
5964
reset_003()5965 void reset_003( )
5966 {
5967 ::osl::Directory testDirectory( aTmpName4 ); //constructor
5968
5969 //close a directory
5970 nError1 = testDirectory.reset( );
5971
5972 CPPUNIT_ASSERT_MESSAGE( "test for reset function: reset a file instead of a directory",
5973 ( ::osl::FileBase::E_NOTDIR == nError1 ) || ( ::osl::FileBase::E_NOENT == nError1 ) );
5974 }
5975
reset_004()5976 void reset_004( )
5977 {
5978 ::osl::Directory testDirectory( aUserDirectorySys ); //constructor
5979
5980 //close a directory
5981 nError1 = testDirectory.reset( );
5982
5983 CPPUNIT_ASSERT_MESSAGE( "test for reset function: use a system path",
5984 ( ::osl::FileBase::E_INVAL == nError1 ) );
5985 }
5986
5987 CPPUNIT_TEST_SUITE( reset );
5988 CPPUNIT_TEST( reset_001 );
5989 CPPUNIT_TEST( reset_002 );
5990 CPPUNIT_TEST( reset_003 );
5991 CPPUNIT_TEST( reset_004 );
5992 CPPUNIT_TEST_SUITE_END( );
5993 };// class reset
5994
5995 //---------------------------------------------------------------------
5996 // testing the method
5997 // inline RC getNextItem( DirectoryItem& rItem, sal_uInt32 nHint = 0 )
5998 //---------------------------------------------------------------------
5999 class getNextItem : public CppUnit::TestFixture
6000 {
6001 ::osl::FileBase::RC nError1, nError2;
6002 ::osl::DirectoryItem rItem;
6003
6004 public:
6005 // initialization
setUp()6006 void setUp( )
6007 {
6008 // create a tempdirectory : $TEMP/tmpdir.
6009 createTestDirectory( aTmpName3 );
6010 // create three files : $TEMP/tmpdir/tmpname, $TEMP/tmpdir/tmpdir, $TEMP/tmpdir/hiddenfile,
6011 createTestFile( aTmpName3, aTmpName2 );
6012 createTestFile( aTmpName3, aTmpName1 );
6013 createTestFile( aTmpName3, aHidURL1 );
6014
6015 }
6016
tearDown()6017 void tearDown( )
6018 {
6019 // remove three files : $TEMP/tmpdir/tmpname, $TEMP/tmpdir/tmpdir, $TEMP/tmpdir/hiddenfile,
6020 deleteTestFile( aTmpName3, aHidURL1 );
6021 deleteTestFile( aTmpName3, aTmpName1 );
6022 deleteTestFile( aTmpName3, aTmpName2 );
6023 // remove a tempdirectory : $TEMP/tmpdir.
6024 deleteTestDirectory( aTmpName3 );
6025 }
6026
6027 // test code.
getNextItem_001()6028 void getNextItem_001( )
6029 {
6030 ::osl::Directory testDirectory( aTmpName3 ); //constructor
6031
6032 //open a directory
6033 nError1 = testDirectory.open( );
6034 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
6035
6036 //check the file name
6037 ::rtl::OUString strFilename;
6038 sal_Bool bOk1 = sal_False;
6039 sal_Bool bOk2 = sal_False;
6040 sal_Bool bOk3 = sal_False;
6041 ::osl::FileStatus rFileStatus( FileStatusMask_FileName );
6042 for ( int nCount = 0; nCount < 3; nCount++ )
6043 {
6044 //get three Items
6045 nError1 = testDirectory.getNextItem( rItem, 2 );
6046 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
6047 nError1 = rItem.getFileStatus( rFileStatus );
6048 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
6049 switch ( nCount )
6050 {
6051 case 0: bOk1 = compareFileName( rFileStatus.getFileName( ), aTmpName2 ) || compareFileName( rFileStatus.getFileName( ), aHidURL1);
6052 break;
6053 case 1: bOk2 = compareFileName( rFileStatus.getFileName( ), aTmpName1 );
6054 break;
6055 case 2: bOk3 = compareFileName( rFileStatus.getFileName( ), aHidURL1) || compareFileName( rFileStatus.getFileName( ), aTmpName2 );
6056 }
6057 }
6058
6059 //close a directory
6060 nError1 = testDirectory.close( );
6061 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
6062
6063 CPPUNIT_ASSERT_MESSAGE( "test for getNextItem function: retrive three items and check their names.",
6064 ( sal_True == bOk1 ) && ( sal_True == bOk2 ) && ( sal_True == bOk3 ) );
6065 }
6066
getNextItem_002()6067 void getNextItem_002( )
6068 {
6069 ::osl::Directory testDirectory( aTmpName3 ); //constructor
6070 nError1 = testDirectory.getNextItem( rItem );
6071
6072 CPPUNIT_ASSERT_MESSAGE( "test for getNextItem function: retrive an item in a directory which is not opened, also test for nHint's default value.",
6073 ( ::osl::FileBase::E_INVAL == nError1 ) );
6074 }
6075
getNextItem_003()6076 void getNextItem_003( )
6077 {
6078 ::osl::Directory testDirectory( aTmpName3 ); //constructor
6079
6080 //open a directory
6081 nError1 = testDirectory.open( );
6082 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
6083
6084 for ( int nCount = 0; nCount < 4; nCount++ )
6085 {
6086 nError2 = testDirectory.getNextItem( rItem, 3 );
6087 }
6088
6089 //close a directory
6090 nError1 = testDirectory.close( );
6091 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
6092
6093 CPPUNIT_ASSERT_MESSAGE( "test for getNextItem function: retrive 4 times in a directory which contain only 3 files.",
6094 ( ::osl::FileBase::E_NOENT == nError2 ) );
6095 }
6096
getNextItem_004()6097 void getNextItem_004( )
6098 {
6099 //create a link file(can not on Windows), then check if getNextItem can get it.
6100 #ifdef UNX
6101 sal_Bool bOK = sal_False;
6102 ::rtl::OUString aUStr_LnkFileSys( aTempDirectorySys ), aUStr_SrcFileSys( aTempDirectorySys );
6103 ( ( aUStr_LnkFileSys += aSlashURL ) += getCurrentPID( ) ) += ::rtl::OUString::createFromAscii("/tmpdir/link.file");
6104 ( ( aUStr_SrcFileSys += aSlashURL ) += getCurrentPID( ) ) += ::rtl::OUString::createFromAscii("/tmpdir/tmpname");
6105 rtl::OString strLinkFileName, strSrcFileName;
6106 strLinkFileName = OUStringToOString( aUStr_LnkFileSys, RTL_TEXTENCODING_ASCII_US );
6107 strSrcFileName = OUStringToOString( aUStr_SrcFileSys, RTL_TEXTENCODING_ASCII_US );
6108
6109 //create a link file and link it to file "/tmp/PID/tmpdir/tmpname"
6110 sal_Int32 fd = symlink( strSrcFileName.getStr(), strLinkFileName.getStr() );
6111 CPPUNIT_ASSERT( fd == 0 );
6112 ::osl::Directory testDirectory( aTmpName3 );
6113
6114 //open a directory
6115 nError1 = testDirectory.open( );
6116 ::rtl::OUString aFileName = ::rtl::OUString::createFromAscii("link.file");
6117
6118 while (1) {
6119 nError1 = testDirectory.getNextItem( rItem, 4 );
6120 if (::osl::FileBase::E_None == nError1) {
6121 ::osl::FileStatus rFileStatus( FileStatusMask_FileName | FileStatusMask_Type );
6122 rItem.getFileStatus( rFileStatus );
6123 if ( compareFileName( rFileStatus.getFileName( ), aFileName) == sal_True )
6124 {
6125 if ( FileStatus::Link == rFileStatus.getFileType( ))
6126 {
6127 bOK = sal_True;
6128 break;
6129 }
6130 }
6131 }
6132 else
6133 break;
6134 };
6135 fd = std::remove( strLinkFileName.getStr() );
6136 CPPUNIT_ASSERT_MESSAGE( "remove link file failed", fd == 0 );
6137 CPPUNIT_ASSERT_MESSAGE( "test for getNextItem function: check if can retrieve the link file name",
6138 ( bOK == sal_True ) );
6139 #endif
6140 }
6141
6142 CPPUNIT_TEST_SUITE( getNextItem );
6143 CPPUNIT_TEST( getNextItem_001 );
6144 CPPUNIT_TEST( getNextItem_002 );
6145 CPPUNIT_TEST( getNextItem_003 );
6146 CPPUNIT_TEST( getNextItem_004 );
6147 CPPUNIT_TEST_SUITE_END( );
6148 };// class getNextItem
6149
6150 //---------------------------------------------------------------------
6151 // testing the method
6152 // inline static RC getVolumeInfo( const ::rtl::OUString& ustrDirectoryURL, VolumeInfo& rInfo )
6153 //---------------------------------------------------------------------
6154 class getVolumeInfo : public CppUnit::TestFixture
6155 {
6156 ::osl::FileBase::RC nError1, nError2;
6157
6158 public:
6159
6160 // test code.
checkValidMask(osl::VolumeInfo const & _aVolumeInfo,sal_Int32 _nMask)6161 void checkValidMask(osl::VolumeInfo const& _aVolumeInfo, sal_Int32 _nMask)
6162 {
6163 if (_nMask == VolumeInfoMask_FileSystemName)
6164 {
6165 //get file system name
6166 ::rtl::OUString aFileSysName( aNullURL );
6167 aFileSysName = _aVolumeInfo.getFileSystemName( );
6168
6169 sal_Bool bRes2 = compareFileName( aFileSysName, aNullURL );
6170 CPPUNIT_ASSERT_MESSAGE( "test for getVolumeInfo function: getVolumeInfo of root directory.",
6171 ( osl::FileBase::E_None == nError1 ) &&
6172 ( sal_False == bRes2 ) );
6173 }
6174 if (_nMask == VolumeInfoMask_Attributes)
6175 {
6176 sal_Bool b1 = _aVolumeInfo.getRemoteFlag();
6177 sal_Bool b2 = _aVolumeInfo.getRemoveableFlag();
6178 sal_Bool b3 = _aVolumeInfo.getCompactDiscFlag();
6179 sal_Bool b4 = _aVolumeInfo.getFloppyDiskFlag();
6180 sal_Bool b5 = _aVolumeInfo.getFixedDiskFlag();
6181 sal_Bool b6 = _aVolumeInfo.getRAMDiskFlag();
6182
6183 rtl::OString sAttr;
6184 if (b1) sAttr = "Remote";
6185 if (b2) sAttr += " Removeable";
6186 if (b3) sAttr += " CDROM";
6187 if (b4) sAttr += " Floppy";
6188 if (b5) sAttr += " FixedDisk";
6189 if (b6) sAttr += " RAMDisk";
6190
6191 t_print("Attributes: %s\n", sAttr.getStr() );
6192 }
6193 if (_nMask == VolumeInfoMask_TotalSpace)
6194 {
6195 // within Linux, df / * 1024 bytes is the result
6196 sal_uInt64 nSize = _aVolumeInfo.getTotalSpace();
6197 t_print("Total space: %lld\n", nSize);
6198 }
6199 if (_nMask == VolumeInfoMask_UsedSpace)
6200 {
6201 sal_uInt64 nSize = _aVolumeInfo.getUsedSpace();
6202 t_print(" Used space: %lld\n", nSize);
6203 }
6204 if (_nMask == VolumeInfoMask_FreeSpace)
6205 {
6206 sal_uInt64 nSize = _aVolumeInfo.getFreeSpace();
6207 t_print(" Free space: %lld\n", nSize);
6208 }
6209 if (_nMask == VolumeInfoMask_MaxNameLength)
6210 {
6211 sal_uInt32 nLength = _aVolumeInfo.getMaxNameLength();
6212 t_print("max name length: %ld\n", nLength);
6213 }
6214 if (_nMask == VolumeInfoMask_MaxPathLength)
6215 {
6216 sal_uInt32 nLength = _aVolumeInfo.getMaxPathLength();
6217 t_print("max path length: %ld\n", nLength);
6218 }
6219 if (_nMask == VolumeInfoMask_FileSystemCaseHandling)
6220 {
6221 bool bIsCase = _aVolumeInfo.isCaseSensitiveFileSystem();
6222 t_print("filesystem case sensitive: %s\n", bIsCase ? "yes" : "no");
6223 }
6224 }
6225
checkVolumeInfo(sal_Int32 _nMask)6226 void checkVolumeInfo(sal_Int32 _nMask)
6227 {
6228 ::osl::VolumeInfo aVolumeInfo( _nMask );
6229 //call getVolumeInfo here
6230 nError1 = ::osl::Directory::getVolumeInfo( aVolURL1, aVolumeInfo );
6231 // LLA: IMHO it's not a bug, if VolumeInfo is not valid, it's a feature
6232 // LLA: CPPUNIT_ASSERT_MESSAGE("mask is not valid", sal_True == aVolumeInfo.isValid( _nMask ) );
6233 if (aVolumeInfo.isValid( _nMask))
6234 {
6235 checkValidMask(aVolumeInfo, _nMask);
6236 }
6237 }
6238
6239
getVolumeInfo_001_1()6240 void getVolumeInfo_001_1( )
6241 {
6242 sal_Int32 mask = VolumeInfoMask_FileSystemName;
6243 checkVolumeInfo(mask);
6244 }
getVolumeInfo_001_2()6245 void getVolumeInfo_001_2( )
6246 {
6247 sal_Int32 mask = VolumeInfoMask_Attributes;
6248 checkVolumeInfo(mask);
6249 }
getVolumeInfo_001_3()6250 void getVolumeInfo_001_3( )
6251 {
6252 sal_Int32 mask = VolumeInfoMask_TotalSpace;
6253 checkVolumeInfo(mask);
6254 }
getVolumeInfo_001_4()6255 void getVolumeInfo_001_4( )
6256 {
6257 sal_Int32 mask = VolumeInfoMask_UsedSpace;
6258 checkVolumeInfo(mask);
6259 }
getVolumeInfo_001_5()6260 void getVolumeInfo_001_5( )
6261 {
6262 sal_Int32 mask = VolumeInfoMask_FreeSpace;
6263 checkVolumeInfo(mask);
6264 }
getVolumeInfo_001_6()6265 void getVolumeInfo_001_6( )
6266 {
6267 sal_Int32 mask = VolumeInfoMask_MaxNameLength;
6268 checkVolumeInfo(mask);
6269 }
getVolumeInfo_001_7()6270 void getVolumeInfo_001_7( )
6271 {
6272 sal_Int32 mask = VolumeInfoMask_MaxPathLength;
6273 checkVolumeInfo(mask);
6274 }
getVolumeInfo_001_8()6275 void getVolumeInfo_001_8( )
6276 {
6277 sal_Int32 mask = VolumeInfoMask_FileSystemCaseHandling;
6278 checkVolumeInfo(mask);
6279 }
6280
getVolumeInfo_002()6281 void getVolumeInfo_002( )
6282 {
6283 sal_Int32 mask = VolumeInfoMask_FileSystemName;
6284 ::osl::VolumeInfo aVolumeInfo( mask );
6285 //call getVolumeInfo here
6286
6287 // LLA: rtl::OUString aRootSysURL;
6288 // LLA: nError1 = osl::File::getFileURLFromSystemPath(aRootSys, aRootSysURL);
6289 // LLA:
6290 // LLA: CPPUNIT_ASSERT_MESSAGE( "can't convert root path to file url",
6291 // LLA: ( osl::FileBase::E_NONE == nError1 ) );
6292
6293 nError1 = ::osl::Directory::getVolumeInfo( aRootSys, aVolumeInfo );
6294
6295 CPPUNIT_ASSERT_MESSAGE( "test for getVolumeInfo function: use system path as parameter.",
6296 ( osl::FileBase::E_INVAL == nError1 ) );
6297 }
6298
getVolumeInfo_003()6299 void getVolumeInfo_003( )
6300 {
6301 sal_Int32 mask = VolumeInfoMask_FileSystemName;
6302 ::osl::VolumeInfo aVolumeInfo( mask );
6303 //call getVolumeInfo here
6304 nError1 = ::osl::Directory::getVolumeInfo( aTmpName3, aVolumeInfo );
6305
6306 // LLA: in Windows, it reply no error, it did not pass in (W32).
6307 #ifdef UNX
6308 CPPUNIT_ASSERT_MESSAGE( "test for getVolumeInfo function: non-existence test. ",
6309 ( osl::FileBase::E_NOENT == nError1 ) );
6310 #endif
6311 }
6312
6313 CPPUNIT_TEST_SUITE( getVolumeInfo );
6314 CPPUNIT_TEST( getVolumeInfo_001_1 );
6315 CPPUNIT_TEST( getVolumeInfo_001_2 );
6316 CPPUNIT_TEST( getVolumeInfo_001_3 );
6317 CPPUNIT_TEST( getVolumeInfo_001_4 );
6318 CPPUNIT_TEST( getVolumeInfo_001_5 );
6319 CPPUNIT_TEST( getVolumeInfo_001_6 );
6320 CPPUNIT_TEST( getVolumeInfo_001_7 );
6321 CPPUNIT_TEST( getVolumeInfo_001_8 );
6322 CPPUNIT_TEST( getVolumeInfo_002 );
6323 CPPUNIT_TEST( getVolumeInfo_003 );
6324 CPPUNIT_TEST_SUITE_END( );
6325 };// class getVolumeInfo
6326
6327
6328 //---------------------------------------------------------------------
6329 // testing the method
6330 // inline static RC create( const ::rtl::OUString& ustrDirectoryURL )
6331 //---------------------------------------------------------------------
6332 class create : public CppUnit::TestFixture
6333 {
6334 ::osl::FileBase::RC nError1, nError2;
6335
6336 public:
6337
6338 // test code.
create_001()6339 void create_001( )
6340 {
6341 //create directory in $TEMP/tmpdir
6342 nError1 = ::osl::Directory::create( aTmpName3 );
6343 //check for existence
6344 nError2 = ::osl::Directory::create( aTmpName3 );
6345 //remove it
6346 deleteTestDirectory( aTmpName3 );
6347
6348 CPPUNIT_ASSERT_MESSAGE( "test for create function: create a directory and check its existence.",
6349 ( osl::FileBase::E_None == nError1 ) &&
6350 ( osl::FileBase::E_EXIST== nError2 ) );
6351 }
6352
create_002()6353 void create_002( )
6354 {
6355 //create directory in /tmpname
6356 nError1 = ::osl::Directory::create( aTmpName7 );
6357 #if defined (WNT )
6358 nError1 = osl::FileBase::E_ACCES; /// in Windows, you can create directory in c:/ any way.
6359 deleteTestDirectory( aTmpName7 );
6360 #endif
6361
6362 CPPUNIT_ASSERT_MESSAGE( "test for create function: create a directory in root for access test.",
6363 ( osl::FileBase::E_ACCES == nError1 ) );
6364 }
6365
create_003()6366 void create_003( )
6367 {
6368 //create directory in /tmpname
6369 nError1 = ::osl::Directory::create( aSysPath1 );
6370
6371 CPPUNIT_ASSERT_MESSAGE( "test for create function: create a directory using system path.",
6372 ( osl::FileBase::E_INVAL == nError1 ) );
6373 }
6374
6375 CPPUNIT_TEST_SUITE( create );
6376 CPPUNIT_TEST( create_001 );
6377 CPPUNIT_TEST( create_002 );
6378 CPPUNIT_TEST( create_003 );
6379 CPPUNIT_TEST_SUITE_END( );
6380 };// class create
6381
6382 //---------------------------------------------------------------------
6383 // testing the method
6384 // inline static RC remove( const ::rtl::OUString& ustrDirectoryURL )
6385 //---------------------------------------------------------------------
6386 class remove : public CppUnit::TestFixture
6387 {
6388 ::osl::FileBase::RC nError1, nError2;
6389
6390 public:
6391
6392 // test code.
remove_001()6393 void remove_001( )
6394 {
6395 //create directory in $TEMP/tmpdir
6396 nError1 = ::osl::Directory::create( aTmpName3 );
6397 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
6398 //remove it
6399 nError1 = ::osl::Directory::remove( aTmpName3 );
6400 //check for existence
6401 ::osl::Directory rDirectory( aTmpName3 );
6402 nError2 = rDirectory.open( );
6403
6404 CPPUNIT_ASSERT_MESSAGE( "test for remove function: remove a directory and check its existence.",
6405 ( osl::FileBase::E_None == nError1 ) &&
6406 ( osl::FileBase::E_NOENT == nError2 ) );
6407 }
6408
remove_002()6409 void remove_002( )
6410 {
6411 //create directory in $TEMP/tmpdir
6412 nError1 = ::osl::Directory::create( aTmpName3 );
6413 CPPUNIT_ASSERT( ::osl::FileBase::E_None == nError1 );
6414 //try to remove it by system path
6415 nError1 = ::osl::Directory::remove( aSysPath3 );
6416 //check for existence
6417 ::osl::Directory rDirectory( aTmpName3 );
6418 nError2 = rDirectory.open( );
6419 if ( osl::FileBase::E_NOENT != nError2 )
6420 ::osl::Directory::remove( aTmpName3 );
6421
6422 CPPUNIT_ASSERT_MESSAGE( "test for remove function: remove a directory by its system path, and check its existence.",
6423 ( osl::FileBase::E_INVAL == nError1 ) );
6424 }
6425
remove_003()6426 void remove_003( )
6427 {
6428 //try to remove a non-existed directory
6429 nError1 = ::osl::Directory::remove( aTmpName6 );
6430
6431 CPPUNIT_ASSERT_MESSAGE( "test for remove function: try to remove a non-existed directory.",
6432 ( osl::FileBase::E_NOENT == nError1 ) );
6433 }
6434
remove_004()6435 void remove_004( )
6436 {
6437 createTestFile( aTmpName6 );
6438 sal_Bool bExist = ifFileExist( aTmpName6 );
6439 //try to remove file.
6440 nError1 = ::osl::Directory::remove( aTmpName6 );
6441 deleteTestFile( aTmpName6 );
6442
6443 CPPUNIT_ASSERT_MESSAGE( "test for remove function: try to remove a file but not directory.",
6444 bExist == sal_True &&(( osl::FileBase::E_NOTDIR == nError1 ) || ( osl::FileBase::E_NOENT == nError1 )) );
6445 }
6446
remove_005()6447 void remove_005( )
6448 {
6449 createTestDirectory( aTmpName3 );
6450 createTestFile( aTmpName4 );
6451 nError1 = ::osl::Directory::remove( aTmpName3 );
6452 deleteTestFile( aTmpName4 );
6453 deleteTestDirectory( aTmpName3 );
6454 ::rtl::OUString suError = ::rtl::OUString::createFromAscii("test for remove function: try to remove a directory that is not empty.") + errorToStr( nError1 );
6455 #if defined ( SOLARIS )
6456 //on UNX, the implementation uses rmdir(), which EEXIST is thrown on Solaris when the directory is not empty, refer to: 'man -s 2 rmdir', while on linux, ENOTEMPTY is thrown.
6457 //EEXIST The directory contains entries other than those for "." and "..".
6458 t_print("#Solaris test\n");
6459 CPPUNIT_ASSERT_MESSAGE( suError, ( osl::FileBase::E_EXIST == nError1 ) );
6460 #else
6461 CPPUNIT_ASSERT_MESSAGE( suError, ( osl::FileBase::E_NOTEMPTY == nError1 ) );
6462 #endif
6463 }
6464
6465 CPPUNIT_TEST_SUITE( remove );
6466 CPPUNIT_TEST( remove_001 );
6467 CPPUNIT_TEST( remove_002 );
6468 CPPUNIT_TEST( remove_003 );
6469 CPPUNIT_TEST( remove_004 );
6470 CPPUNIT_TEST( remove_005 );
6471 CPPUNIT_TEST_SUITE_END( );
6472 };// class remove
6473
6474 //########################################
6475 // TEST Directory::createPath
6476 //########################################
6477
6478 #ifdef WNT
6479 # define PATH_BUFFER_SIZE MAX_PATH
6480 #else
6481 # define PATH_BUFFER_SIZE PATH_MAX
6482 #endif
6483
6484 char TEST_PATH_POSTFIX[] = "hello/world";
6485
6486 //########################################
get_test_path()6487 OUString get_test_path()
6488 {
6489 OUString tmp;
6490 FileBase::RC rc = FileBase::getTempDirURL(tmp);
6491
6492 CPPUNIT_ASSERT_MESSAGE
6493 (
6494 "Test path creation failed",
6495 rc == FileBase::E_None
6496 );
6497
6498 OUStringBuffer b(tmp);
6499 if (tmp.lastIndexOf('/') != (tmp.getLength() - 1))
6500 b.appendAscii("/");
6501
6502 b.appendAscii(TEST_PATH_POSTFIX);
6503
6504 return b.makeStringAndClear();
6505 }
6506
6507 //########################################
rm_test_path(const OUString & path)6508 void rm_test_path(const OUString& path)
6509 {
6510 sal_Unicode buffer[PATH_BUFFER_SIZE];
6511 rtl_copyMemory(buffer, path.getStr(), (path.getLength() + 1) * sizeof(sal_Unicode));
6512
6513 sal_Int32 i = rtl_ustr_lastIndexOfChar(buffer, '/');
6514 if (i == path.getLength())
6515 buffer[i] = 0;
6516
6517 Directory::remove(buffer);
6518
6519 i = rtl_ustr_lastIndexOfChar(buffer, '/');
6520 buffer[i] = 0;
6521 Directory::remove(buffer);
6522 }
6523
6524 //########################################
6525 class DirCreatedObserver : public DirectoryCreationObserver
6526 {
6527 public:
DirCreatedObserver()6528 DirCreatedObserver() : i(0)
6529 {
6530 }
6531
DirectoryCreated(const rtl::OUString &)6532 virtual void DirectoryCreated(const rtl::OUString& /*aDirectoryUrl*/)
6533 {
6534 i++;
6535 };
6536
number_of_dirs_created() const6537 int number_of_dirs_created() const
6538 {
6539 return i;
6540 }
6541
6542 private:
6543 int i;
6544 };
6545
6546
6547 //########################################
6548 class createPath : public CppUnit::TestFixture
6549 {
6550 public:
6551 //##########################################
createPath()6552 createPath()
6553 {}
6554
6555 //##########################################
with_relative_path()6556 void with_relative_path()
6557 {
6558 FileBase::RC rc = Directory::createPath(
6559 OUString::createFromAscii(TEST_PATH_POSTFIX));
6560
6561 CPPUNIT_ASSERT_MESSAGE
6562 (
6563 "osl_createDirectoryPath contract broken",
6564 rc == FileBase::E_INVAL
6565 );
6566 }
6567
6568 //##########################################
without_callback()6569 void without_callback()
6570 {
6571 OUString tp_url = get_test_path();
6572
6573 rm_test_path(tp_url);
6574
6575 FileBase::RC rc = Directory::createPath(tp_url);
6576
6577 CPPUNIT_ASSERT_MESSAGE
6578 (
6579 "osl_createDirectoryPath failed",
6580 rc == FileBase::E_None
6581 );
6582 }
6583
6584 //##########################################
with_callback()6585 void with_callback()
6586 {
6587 OUString tp_url = get_test_path();
6588
6589 rm_test_path(tp_url);
6590
6591 DirCreatedObserver* observer = new DirCreatedObserver;
6592 FileBase::RC rc = Directory::createPath(tp_url, observer);
6593 int nDirs = observer->number_of_dirs_created();
6594 delete observer;
6595 CPPUNIT_ASSERT_MESSAGE
6596 (
6597 "osl_createDirectoryPath failed",
6598 (rc == FileBase::E_None) && (nDirs > 0)
6599 );
6600
6601 }
6602
6603 #ifdef WNT
6604
6605 //##########################################
get_unused_drive_letter()6606 char* get_unused_drive_letter()
6607 {
6608 static char m_aBuff[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
6609
6610 DWORD ld = GetLogicalDrives();
6611 DWORD i = 4;
6612 DWORD j = 2;
6613
6614 while ((ld & i) && (i > 1))
6615 { i = i << 1; j++; }
6616
6617 if (i > 2)
6618 return m_aBuff + j;
6619
6620 return NULL;
6621 }
6622
6623 //##########################################
at_invalid_logical_drive()6624 void at_invalid_logical_drive()
6625 {
6626 char* drv = get_unused_drive_letter();
6627 char buff[PATH_BUFFER_SIZE];
6628 rtl_zeroMemory(buff, sizeof(buff));
6629
6630 strncpy(buff, drv, 1);
6631 strcat(buff, ":\\");
6632 strcat(buff, TEST_PATH_POSTFIX);
6633
6634 OUString path = OUString::createFromAscii(buff);
6635 OUString tp_url;
6636 FileBase::getFileURLFromSystemPath(path, tp_url);
6637
6638 FileBase::RC rc = Directory::createPath(tp_url);
6639
6640 CPPUNIT_ASSERT_MESSAGE
6641 (
6642 "osl_createDirectoryPath doesn't fail on unused logical drive letters",
6643 rc != FileBase::E_None
6644 );
6645 }
6646
6647 //##########################################
with_UNC_path()6648 void with_UNC_path()
6649 {
6650
6651 OUString tp_unc = OUString::createFromAscii("\\\\Tra-1\\TRA_D\\hello\\world\\");
6652 OUString tp_url;
6653 FileBase::getFileURLFromSystemPath(tp_unc, tp_url);
6654
6655 FileBase::RC rc = Directory::createPath(tp_url);
6656
6657 CPPUNIT_ASSERT_MESSAGE
6658 (
6659 "osl_createDirectoryPath fails with UNC path",
6660 rc == FileBase::E_None
6661 );
6662 }
6663
6664 #endif /* WNT */
6665
6666 CPPUNIT_TEST_SUITE(createPath);
6667 CPPUNIT_TEST(with_relative_path);
6668 CPPUNIT_TEST(without_callback);
6669 CPPUNIT_TEST(with_callback);
6670 #ifdef WNT
6671 CPPUNIT_TEST(at_invalid_logical_drive);
6672
6673 // adapt the UNC path in method createDirectoryPath_with_UNC_path
6674 // in order to run this test successfully
6675 //CPPUNIT_TEST(with_UNC_path);
6676 #endif
6677 CPPUNIT_TEST_SUITE_END();
6678
6679 }; // class createPath
6680
6681 // -----------------------------------------------------------------------------
6682 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_Directory::ctors, "osl_Directory" );
6683 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_Directory::open, "osl_Directory" );
6684 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_Directory::isOpen, "osl_Directory" );
6685 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_Directory::close, "osl_Directory" );
6686 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_Directory::reset, "osl_Directory" );
6687 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_Directory::getNextItem, "osl_Directory" );
6688 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_Directory::getVolumeInfo, "osl_Directory" );
6689 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_Directory::create, "osl_Directory" );
6690 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_Directory::remove, "osl_Directory" );
6691 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_Directory::createPath, "osl_Directory" );
6692 }// namespace osl_Directory
6693
6694
6695 // -----------------------------------------------------------------------------
6696 // this macro creates an empty function, which will called by the RegisterAllFunctions()
6697 // to let the user the possibility to also register some functions by hand.
6698 // -----------------------------------------------------------------------------
6699
6700 /// NOADDITIONAL;
6701
6702
6703
6704 /** get Current PID.
6705 */
getCurrentPID()6706 inline ::rtl::OUString getCurrentPID( )
6707 {
6708 //~ Get current PID and turn it into OUString;
6709 int nPID = 0;
6710 #ifdef WNT
6711 nPID = GetCurrentProcessId();
6712 #else
6713 nPID = getpid();
6714 #endif
6715 return ( ::rtl::OUString::valueOf( ( long )nPID ) );
6716 }
6717
6718
6719 /** Insert Current PID to the URL to avoid access violation between multiuser execution.
6720 */
insertPID(::rtl::OUString & pathname)6721 inline void insertPID( ::rtl::OUString & pathname )
6722 {
6723 //~ check if the path contain the temp directory, do nothing changes if not;
6724 if ( pathname.indexOf( aTempDirectoryURL ) && pathname.indexOf( aTempDirectorySys ) )
6725 return;
6726
6727 //~ format pathname to TEMP/USERPID/URL style;
6728 if ( !pathname.indexOf( aTempDirectoryURL ) )
6729 {
6730 ::rtl::OUString strPID( getCurrentPID( ) );
6731 ::rtl::OUString pathLeft = aTempDirectoryURL.copy( 0 );
6732 ::rtl::OUString pathRight = pathname.copy( aTempDirectoryURL.getLength( ) );
6733 pathname = pathLeft.copy( 0 );
6734 ( ( pathname += aSlashURL ) += strPID ) += pathRight;
6735 }
6736 else
6737 {
6738 ::rtl::OUString strPID( getCurrentPID( ) );
6739 ::rtl::OUString pathLeft = aTempDirectorySys.copy( 0 );
6740 ::rtl::OUString pathRight = pathname.copy( aTempDirectorySys.getLength( ) );
6741 pathname = pathLeft.copy( 0 );
6742 ( ( pathname += aSlashURL ) += strPID ) += pathRight;
6743 }
6744
6745
6746 }
6747
6748 /** to do some initialized work, we replace the NOADDITIONAL macro with the initialize work which
6749 will check the file and directory existence. and set some variables for test use.
6750 to simplify the initialize work, we seperate it into UNIX section and Windows section, the main task
6751 of initialization is adapt all URL defined in osl_File_Const.h to TEMP/USERPID/URL style format,
6752 since there may be an instance that multiuser execute test at the same time, and the temp file
6753 may not be clean up in this case due to access right problem.
6754 */
RegisterAdditionalFunctions(FktRegFuncPtr _pFunc)6755 void RegisterAdditionalFunctions( FktRegFuncPtr _pFunc )
6756 {
6757 (void)_pFunc;
6758 t_print( "Initializing..." );
6759
6760 //~ make sure the c:\temp exist, if not, create it.
6761 #if ( defined WNT )
6762 if ( checkDirectory( aTempDirectoryURL, osl_Check_Mode_Exist ) != sal_True ) {
6763 t_print( "\n#C:\\temp is not exist, now creating\n" );
6764 createTestDirectory( aTempDirectoryURL );
6765 };
6766 #endif
6767
6768 //~ make sure the c:\temp\PID or /tmp/PID exist, if not, create it. initialize the user directory.
6769 ( aUserDirectoryURL += aSlashURL ) += getCurrentPID( );
6770 ( aUserDirectorySys += aSlashURL ) += getCurrentPID( );
6771
6772 if ( checkDirectory( aUserDirectoryURL, osl_Check_Mode_Exist ) != sal_True ) {
6773 createTestDirectory( aUserDirectoryURL );
6774 }
6775
6776 //~ adapt all URL to the TEMP/USERPID/URL format;
6777 insertPID( aCanURL1 );
6778 insertPID( aTmpName3 );
6779 insertPID( aTmpName4 );
6780 insertPID( aTmpName5 );
6781 insertPID( aTmpName6 );
6782 insertPID( aTmpName8 );
6783 insertPID( aTmpName9 );
6784 insertPID( aLnkURL1 );
6785 insertPID( aFifoSys );
6786 insertPID( aSysPath1 );
6787 insertPID( aSysPath2 );
6788 insertPID( aSysPath3 );
6789 insertPID( aSysPath4 );
6790
6791 t_print( "Done.\n" );
6792
6793 }
6794
6795
6796 //~ do some clean up work after all test completed.
6797 class GlobalObject
6798 {
6799 public:
~GlobalObject()6800 ~GlobalObject()
6801 {
6802 try
6803 {
6804 //~ make sure the c:\temp\PID or /tmp/PID exist, if yes, delete it.
6805 t_print( "\n#Do some clean-ups ...\n" );
6806 if ( checkDirectory( aUserDirectoryURL, osl_Check_Mode_Exist ) == sal_True ) {
6807 deleteTestDirectory( aUserDirectoryURL );
6808 }
6809
6810 // LLA: t_print("after deleteTestDirectory\n");
6811 //~ special clean up task in Windows and Unix seperately;
6812 #if ( defined UNX ) || ( defined OS2 )
6813 //~ some clean up task for UNIX OS
6814 ;
6815 #else
6816 //~ some clean up task for Windows OS
6817 //~ check if some files are in the way, remove them if necessary.
6818 if ( ifFileExist( aTmpName6 ) == sal_True )
6819 deleteTestFile( aTmpName6 );
6820 if ( ifFileExist( aTmpName4 ) == sal_True )
6821 deleteTestFile( aTmpName4 );
6822 if ( checkDirectory( aTmpName4, osl_Check_Mode_Exist ) == sal_True )
6823 deleteTestDirectory( aTmpName4 );
6824 if ( ifFileExist( aTmpName3 ) == sal_True )
6825 deleteTestFile( aTmpName3 );
6826 if ( checkDirectory( aTmpName3, osl_Check_Mode_Exist ) == sal_True )
6827 deleteTestDirectory( aTmpName3 );
6828
6829 ::rtl::OUString aUStr( aUserDirectoryURL );
6830 concatURL( aUStr, aHidURL1 );
6831 if ( ifFileExist( aUStr ) == sal_True )
6832 deleteTestFile( aUStr );
6833
6834 ::rtl::OUString aUStr1( aRootURL );
6835 concatURL( aUStr1, aTmpName2 );
6836 if ( ifFileExist( aUStr1 ) == sal_True )
6837 deleteTestFile( aUStr1 );
6838 #endif
6839
6840 }
6841 catch (CppUnit::Exception &e)
6842 {
6843 t_print("Exception caught in GlobalObject dtor(). Exception message: '%s'. Source line: %d\n", e.what(), e.sourceLine().lineNumber());
6844 }
6845 catch (...)
6846 {
6847 t_print("Exception caught (...) in GlobalObject dtor()\n");
6848 }
6849 }
6850 };
6851
6852 GlobalObject theGlobalObject;
6853