1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: osl_old_test_file.cxx,v $
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"
35 // this file is converted to use with testshl2
36 // original was placed in sal/test/textenc.cxx
41 #include <osl/process.h>
42 #include <rtl/ustring.hxx>
48 #define TEST_VOLUME ""
51 #define TEST_VOLUME "c:/"
54 #include <cppunit/simpleheader.hxx>
56 namespace osl_test_file
59 // -----------------------------------------------------------------------------
61 class oldtestfile
: public CppUnit::TestFixture
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( );
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",
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",
113 void oldtestfile::test_file_001()
119 OUString
base1( RTL_CONSTASCII_USTRINGPARAM( "file:///" TEST_VOLUME
"bla" ) );
121 for( i
= 0 ; aSource1
[i
] ; i
+=2 )
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( "../.." ) );
138 CPPUNIT_ASSERT_MESSAGE("failure #11", osl_File_E_None
!= osl_getAbsoluteFileURL( base1
.pData
, err1
.pData
, &target
.pData
) );
142 void oldtestfile::test_file_002()
148 OUString
base2( RTL_CONSTASCII_USTRINGPARAM( "file:///" TEST_VOLUME
"bla/blubs/schnubbel" ) );
150 for( i
= 0 ; aSource2
[i
] ; i
+=2 )
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()
176 if( getcwd( buf
, 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" ) )
190 osl_getProcessWorkingDir( &(dir
.pData
) );
192 OUString base3
= dir
;
193 base3
+= OUString( RTL_CONSTASCII_USTRINGPARAM( "/c" ) );
194 for( i
= 0 ; aSource3
[i
] ; i
+=2 )
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() )
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
);
220 CPPUNIT_ASSERT_MESSAGE("failure #6", 0 );
226 CPPUNIT_ASSERT_MESSAGE("failure #7", 0 );
232 CPPUNIT_ASSERT_MESSAGE("failure #8", 0 );
237 CPPUNIT_ASSERT_MESSAGE("failure #9", 0 );
242 void oldtestfile::test_file_004()
248 OUString
base4( RTL_CONSTASCII_USTRINGPARAM( "file:///" TEST_VOLUME
"bla/" ) );
250 for( i
= 0 ; aSource1
[i
] ; i
+=2 )
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 // -----------------------------------------------------------------------------