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