merge the formfield patch from ooo-build
[ooovba.git] / sal / qa / osl / file / osl_old_test_file.cxx
blobe5f34da701ca954665f64499c1f4c5e34af66b18
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: osl_old_test_file.cxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sal.hxx"
34 // LLA:
35 // this file is converted to use with testshl2
36 // original was placed in sal/test/textenc.cxx
38 #include <stdio.h>
40 #include <osl/file.h>
41 #include <osl/process.h>
42 #include <rtl/ustring.hxx>
43 #ifdef SAL_UNX
44 #include <unistd.h>
45 #include <limits.h>
46 #include <string.h>
47 #include <sys/stat.h>
48 #define TEST_VOLUME ""
49 #else
50 // WINDOWS
51 #define TEST_VOLUME "c:/"
52 #endif
54 #include <cppunit/simpleheader.hxx>
56 namespace osl_test_file
59 // -----------------------------------------------------------------------------
61 class oldtestfile : public CppUnit::TestFixture
63 public:
64 void test_file_001();
65 void test_file_002();
66 void test_file_003();
67 void test_file_004();
69 CPPUNIT_TEST_SUITE( oldtestfile );
70 CPPUNIT_TEST( test_file_001 );
71 CPPUNIT_TEST( test_file_002 );
72 CPPUNIT_TEST( test_file_003 );
73 CPPUNIT_TEST( test_file_004 );
74 CPPUNIT_TEST_SUITE_END( );
77 char *aSource1[] =
79 "a" , "file:///" TEST_VOLUME "bla/a",
80 "a/" , "file:///" TEST_VOLUME "bla/a",
81 "../a" , "file:///" TEST_VOLUME "a" ,
82 "a/.." , "file:///" TEST_VOLUME "bla",
83 "a/../b" , "file:///" TEST_VOLUME "bla/b",
84 ".." , "file:///" TEST_VOLUME "",
85 "a/b/c/d/" , "file:///" TEST_VOLUME "bla/a/b/c/d",
86 "a/./c" , "file:///" TEST_VOLUME "bla/a/c",
87 "file:///bla/blub", "file:///" TEST_VOLUME "bla/blub",
88 0 , 0
91 char *aSource2[ ] =
93 "a" , "file:///" TEST_VOLUME "bla/blubs/schnubbel/a",
94 "a/", "file:///" TEST_VOLUME "bla/blubs/schnubbel/a",
95 "../a", "file:///" TEST_VOLUME "bla/blubs/a",
96 "../../a", "file:///" TEST_VOLUME "bla/a",
97 "../../../a", "file:///" TEST_VOLUME "a",
98 "../../../a/b/c/d", "file:///" TEST_VOLUME "a/b/c/d",
99 0,0
102 char *aSource3[ ] =
104 ".." , "/a",
105 "../a" , "/a/a",
106 "e/f" , "/c/e/f",
107 "../..", "",
111 using namespace rtl;
113 void oldtestfile::test_file_001()
115 #ifdef WIN32
116 return;
117 #endif
119 OUString base1( RTL_CONSTASCII_USTRINGPARAM( "file:///" TEST_VOLUME "bla" ) );
120 int i;
121 for( i = 0 ; aSource1[i] ; i +=2 )
123 OUString target;
124 OUString rel = OUString::createFromAscii( aSource1[i] );
125 oslFileError e = osl_getAbsoluteFileURL( base1.pData, rel.pData , &target.pData );
126 CPPUNIT_ASSERT_MESSAGE("failure #1", osl_File_E_None == e );
127 if( osl_File_E_None == e )
129 CPPUNIT_ASSERT_MESSAGE("failure #1.1", target.equalsAscii( aSource1[i+1] ) );
131 OString o = OUStringToOString( target , RTL_TEXTENCODING_ASCII_US );
132 OString obase = OUStringToOString( base1 , RTL_TEXTENCODING_ASCII_US );
133 fprintf( stderr, "%d %s + %s = %s\n" ,e, obase.getStr(), aSource1[i], o.pData->buffer );
136 OUString err1( RTL_CONSTASCII_USTRINGPARAM( "../.." ) );
137 OUString target;
138 CPPUNIT_ASSERT_MESSAGE("failure #11", osl_File_E_None != osl_getAbsoluteFileURL( base1.pData , err1.pData , &target.pData ) );
142 void oldtestfile::test_file_002()
144 #ifdef WIN32
145 return;
146 #endif
148 OUString base2( RTL_CONSTASCII_USTRINGPARAM( "file:///" TEST_VOLUME "bla/blubs/schnubbel" ) );
149 int i;
150 for( i = 0 ; aSource2[i] ; i +=2 )
152 OUString target;
153 OUString rel = OUString::createFromAscii( aSource2[i] );
154 oslFileError e = osl_getAbsoluteFileURL( base2.pData, rel.pData , &target.pData );
155 CPPUNIT_ASSERT_MESSAGE("failure #2", osl_File_E_None == e );
156 if( osl_File_E_None == e )
158 CPPUNIT_ASSERT_MESSAGE("failure #2.1", target.equalsAscii( aSource2[i+1] ) );
160 OString o = OUStringToOString( target , RTL_TEXTENCODING_ASCII_US );
161 OString obase = OUStringToOString( base2 , RTL_TEXTENCODING_ASCII_US );
162 // fprintf( stderr, "%d %s + %s = %s\n" ,e, obase.getStr(), aSource2[i], o.pData->buffer );
166 void oldtestfile::test_file_003()
168 #ifdef WIN32
169 return;
170 #endif
172 // links !
173 #ifdef UNX
174 int i;
175 char buf[PATH_MAX];
176 if( getcwd( buf, PATH_MAX ) )
178 char buf2[PATH_MAX];
179 strcpy( buf2 , buf );
180 strcat( buf2, "/a" );
182 if( 0 == mkdir( buf2 , S_IRWXG | S_IRWXO | S_IRWXU ) )
184 strcat( buf2, "/b" );
185 if( 0 == mkdir( buf2, S_IRWXU | S_IRWXO | S_IRWXU ) )
187 if( 0 == symlink( buf2 , "c" ) )
189 OUString dir;
190 osl_getProcessWorkingDir( &(dir.pData) );
192 OUString base3 = dir;
193 base3 += OUString( RTL_CONSTASCII_USTRINGPARAM( "/c" ) );
194 for( i = 0 ; aSource3[i] ; i +=2 )
196 OUString target;
197 OUString rel = OUString::createFromAscii( aSource3[i] );
198 oslFileError e = osl_getAbsoluteFileURL( base3.pData, rel.pData , &target.pData );
199 CPPUNIT_ASSERT_MESSAGE("failure #3", osl_File_E_None == e );
200 if( osl_File_E_None == e )
202 CPPUNIT_ASSERT_MESSAGE("failure #4", target.getLength() >= dir.getLength() );
203 if( target.getLength() >= dir.getLength() )
205 int j;
206 for( j = dir.getLength() ;
207 j < target.getLength() &&
208 aSource3[i+1][j-dir.getLength()] == target[j] ; j++ );
209 CPPUNIT_ASSERT_MESSAGE("failure #5", j == target.getLength() );
212 OString o = OUStringToOString( target , RTL_TEXTENCODING_ASCII_US );
213 OString obase = OUStringToOString( base3 , RTL_TEXTENCODING_ASCII_US );
214 fprintf( stderr, "%d %s + %s = %s\n" ,e, obase.getStr(), aSource3[i], o.pData->buffer );
216 unlink( "c" );
218 else
220 CPPUNIT_ASSERT_MESSAGE("failure #6", 0 );
222 rmdir( "a/b" );
224 else
226 CPPUNIT_ASSERT_MESSAGE("failure #7", 0 );
228 rmdir( "a" );
230 else
232 CPPUNIT_ASSERT_MESSAGE("failure #8", 0 );
235 else
237 CPPUNIT_ASSERT_MESSAGE("failure #9", 0 );
239 #endif
242 void oldtestfile::test_file_004()
244 #ifdef WIN32
245 return;
246 #endif
248 OUString base4( RTL_CONSTASCII_USTRINGPARAM( "file:///" TEST_VOLUME "bla/" ) );
249 int i;
250 for( i = 0 ; aSource1[i] ; i +=2 )
252 OUString target;
253 OUString rel = OUString::createFromAscii( aSource1[i] );
254 oslFileError e = osl_getAbsoluteFileURL( base4.pData, rel.pData , &target.pData );
255 CPPUNIT_ASSERT_MESSAGE("failure #10", osl_File_E_None == e );
256 if( osl_File_E_None == e )
258 CPPUNIT_ASSERT_MESSAGE("failure #10.1", target.equalsAscii( aSource1[i+1] ) );
260 OString o = OUStringToOString( target , RTL_TEXTENCODING_ASCII_US );
261 OString obase = OUStringToOString( base4 , RTL_TEXTENCODING_ASCII_US );
262 fprintf( stderr, "%d %s + %s = %s\n" ,e, obase.getStr(), aSource1[i], o.pData->buffer );
266 // fprintf( stderr, "test_file done\n" );
269 } // namespace osl_test_file
271 // -----------------------------------------------------------------------------
272 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( osl_test_file::oldtestfile, "osl_File" );
274 // -----------------------------------------------------------------------------
275 NOADDITIONAL;