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