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