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