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