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