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 // LLA:
28cdf0e10cSrcweir // this file is converted to use with testshl2
29cdf0e10cSrcweir // original was placed in sal/test/textenc.cxx
30cdf0e10cSrcweir
31cdf0e10cSrcweir #include <stdio.h>
32cdf0e10cSrcweir
33cdf0e10cSrcweir #include <osl/file.h>
34cdf0e10cSrcweir #include <osl/process.h>
35cdf0e10cSrcweir #include <rtl/ustring.hxx>
36cdf0e10cSrcweir #ifdef SAL_UNX
37cdf0e10cSrcweir #include <unistd.h>
38cdf0e10cSrcweir #include <limits.h>
39cdf0e10cSrcweir #include <string.h>
40cdf0e10cSrcweir #include <sys/stat.h>
41cdf0e10cSrcweir #define TEST_VOLUME ""
42cdf0e10cSrcweir #else
43cdf0e10cSrcweir // WINDOWS
44cdf0e10cSrcweir #define TEST_VOLUME "c:/"
45cdf0e10cSrcweir #endif
46cdf0e10cSrcweir
47*bfbc7fbcSDamjan Jovanovic #include "gtest/gtest.h"
48cdf0e10cSrcweir
49cdf0e10cSrcweir namespace osl_test_file
50cdf0e10cSrcweir {
51cdf0e10cSrcweir
52cdf0e10cSrcweir // -----------------------------------------------------------------------------
53cdf0e10cSrcweir
54*bfbc7fbcSDamjan Jovanovic class oldtestfile : public ::testing::Test
55cdf0e10cSrcweir {
56cdf0e10cSrcweir public:
57cdf0e10cSrcweir };
58cdf0e10cSrcweir
59cdf0e10cSrcweir char *aSource1[] =
60cdf0e10cSrcweir {
61cdf0e10cSrcweir "a" , "file:///" TEST_VOLUME "bla/a",
62cdf0e10cSrcweir "a/" , "file:///" TEST_VOLUME "bla/a",
63cdf0e10cSrcweir "../a" , "file:///" TEST_VOLUME "a" ,
64cdf0e10cSrcweir "a/.." , "file:///" TEST_VOLUME "bla",
65cdf0e10cSrcweir "a/../b" , "file:///" TEST_VOLUME "bla/b",
66cdf0e10cSrcweir ".." , "file:///" TEST_VOLUME "",
67cdf0e10cSrcweir "a/b/c/d/" , "file:///" TEST_VOLUME "bla/a/b/c/d",
68cdf0e10cSrcweir "a/./c" , "file:///" TEST_VOLUME "bla/a/c",
69cdf0e10cSrcweir "file:///bla/blub", "file:///" TEST_VOLUME "bla/blub",
70cdf0e10cSrcweir 0 , 0
71cdf0e10cSrcweir };
72cdf0e10cSrcweir
73cdf0e10cSrcweir char *aSource2[ ] =
74cdf0e10cSrcweir {
75cdf0e10cSrcweir "a" , "file:///" TEST_VOLUME "bla/blubs/schnubbel/a",
76cdf0e10cSrcweir "a/", "file:///" TEST_VOLUME "bla/blubs/schnubbel/a",
77cdf0e10cSrcweir "../a", "file:///" TEST_VOLUME "bla/blubs/a",
78cdf0e10cSrcweir "../../a", "file:///" TEST_VOLUME "bla/a",
79cdf0e10cSrcweir "../../../a", "file:///" TEST_VOLUME "a",
80cdf0e10cSrcweir "../../../a/b/c/d", "file:///" TEST_VOLUME "a/b/c/d",
81cdf0e10cSrcweir 0,0
82cdf0e10cSrcweir };
83cdf0e10cSrcweir
84cdf0e10cSrcweir char *aSource3[ ] =
85cdf0e10cSrcweir {
86cdf0e10cSrcweir ".." , "/a",
87cdf0e10cSrcweir "../a" , "/a/a",
88cdf0e10cSrcweir "e/f" , "/c/e/f",
89cdf0e10cSrcweir "../..", "",
90cdf0e10cSrcweir 0,0
91cdf0e10cSrcweir };
92cdf0e10cSrcweir
93cdf0e10cSrcweir using namespace rtl;
94cdf0e10cSrcweir
TEST_F(oldtestfile,test_file_001)95*bfbc7fbcSDamjan Jovanovic TEST_F(oldtestfile, test_file_001)
96cdf0e10cSrcweir {
97cdf0e10cSrcweir #ifdef WIN32
98cdf0e10cSrcweir return;
99cdf0e10cSrcweir #endif
100cdf0e10cSrcweir
101cdf0e10cSrcweir OUString base1( RTL_CONSTASCII_USTRINGPARAM( "file:///" TEST_VOLUME "bla" ) );
102cdf0e10cSrcweir int i;
103cdf0e10cSrcweir for( i = 0 ; aSource1[i] ; i +=2 )
104cdf0e10cSrcweir {
105cdf0e10cSrcweir OUString target;
106cdf0e10cSrcweir OUString rel = OUString::createFromAscii( aSource1[i] );
107cdf0e10cSrcweir oslFileError e = osl_getAbsoluteFileURL( base1.pData, rel.pData , &target.pData );
108*bfbc7fbcSDamjan Jovanovic ASSERT_TRUE( osl_File_E_None == e ) << "failure #1";
109cdf0e10cSrcweir if( osl_File_E_None == e )
110cdf0e10cSrcweir {
111*bfbc7fbcSDamjan Jovanovic ASSERT_TRUE( target.equalsAscii( aSource1[i+1] ) ) << "failure #1.1";
112cdf0e10cSrcweir }
113cdf0e10cSrcweir OString o = OUStringToOString( target , RTL_TEXTENCODING_ASCII_US );
114cdf0e10cSrcweir OString obase = OUStringToOString( base1 , RTL_TEXTENCODING_ASCII_US );
115cdf0e10cSrcweir fprintf( stderr, "%d %s + %s = %s\n" ,e, obase.getStr(), aSource1[i], o.pData->buffer );
116cdf0e10cSrcweir }
117cdf0e10cSrcweir
118cdf0e10cSrcweir OUString err1( RTL_CONSTASCII_USTRINGPARAM( "../.." ) );
119cdf0e10cSrcweir OUString target;
120*bfbc7fbcSDamjan Jovanovic ASSERT_TRUE( osl_File_E_None != osl_getAbsoluteFileURL( base1.pData , err1.pData , &target.pData ) ) << "failure #11";
121cdf0e10cSrcweir
122cdf0e10cSrcweir }
123cdf0e10cSrcweir
TEST_F(oldtestfile,test_file_002)124*bfbc7fbcSDamjan Jovanovic TEST_F(oldtestfile, test_file_002)
125cdf0e10cSrcweir {
126cdf0e10cSrcweir #ifdef WIN32
127cdf0e10cSrcweir return;
128cdf0e10cSrcweir #endif
129cdf0e10cSrcweir
130cdf0e10cSrcweir OUString base2( RTL_CONSTASCII_USTRINGPARAM( "file:///" TEST_VOLUME "bla/blubs/schnubbel" ) );
131cdf0e10cSrcweir int i;
132cdf0e10cSrcweir for( i = 0 ; aSource2[i] ; i +=2 )
133cdf0e10cSrcweir {
134cdf0e10cSrcweir OUString target;
135cdf0e10cSrcweir OUString rel = OUString::createFromAscii( aSource2[i] );
136cdf0e10cSrcweir oslFileError e = osl_getAbsoluteFileURL( base2.pData, rel.pData , &target.pData );
137*bfbc7fbcSDamjan Jovanovic ASSERT_TRUE(osl_File_E_None == e) << "failure #2";
138cdf0e10cSrcweir if( osl_File_E_None == e )
139cdf0e10cSrcweir {
140*bfbc7fbcSDamjan Jovanovic ASSERT_TRUE(target.equalsAscii( aSource2[i+1] )) << "failure #2.1";
141cdf0e10cSrcweir }
142cdf0e10cSrcweir OString o = OUStringToOString( target , RTL_TEXTENCODING_ASCII_US );
143cdf0e10cSrcweir OString obase = OUStringToOString( base2 , RTL_TEXTENCODING_ASCII_US );
144cdf0e10cSrcweir // fprintf( stderr, "%d %s + %s = %s\n" ,e, obase.getStr(), aSource2[i], o.pData->buffer );
145cdf0e10cSrcweir }
146cdf0e10cSrcweir }
147cdf0e10cSrcweir
TEST_F(oldtestfile,test_file_003)148*bfbc7fbcSDamjan Jovanovic TEST_F(oldtestfile, test_file_003)
149cdf0e10cSrcweir {
150cdf0e10cSrcweir #ifdef WIN32
151cdf0e10cSrcweir return;
152cdf0e10cSrcweir #endif
153cdf0e10cSrcweir
154cdf0e10cSrcweir // links !
155cdf0e10cSrcweir #ifdef UNX
156cdf0e10cSrcweir int i;
157cdf0e10cSrcweir char buf[PATH_MAX];
158cdf0e10cSrcweir if( getcwd( buf, PATH_MAX ) )
159cdf0e10cSrcweir {
160cdf0e10cSrcweir char buf2[PATH_MAX];
161cdf0e10cSrcweir strcpy( buf2 , buf );
162cdf0e10cSrcweir strcat( buf2, "/a" );
163cdf0e10cSrcweir
164cdf0e10cSrcweir if( 0 == mkdir( buf2 , S_IRWXG | S_IRWXO | S_IRWXU ) )
165cdf0e10cSrcweir {
166cdf0e10cSrcweir strcat( buf2, "/b" );
167cdf0e10cSrcweir if( 0 == mkdir( buf2, S_IRWXU | S_IRWXO | S_IRWXU ) )
168cdf0e10cSrcweir {
169cdf0e10cSrcweir if( 0 == symlink( buf2 , "c" ) )
170cdf0e10cSrcweir {
171cdf0e10cSrcweir OUString dir;
172cdf0e10cSrcweir osl_getProcessWorkingDir( &(dir.pData) );
173cdf0e10cSrcweir
174cdf0e10cSrcweir OUString base3 = dir;
175cdf0e10cSrcweir base3 += OUString( RTL_CONSTASCII_USTRINGPARAM( "/c" ) );
176cdf0e10cSrcweir for( i = 0 ; aSource3[i] ; i +=2 )
177cdf0e10cSrcweir {
178cdf0e10cSrcweir OUString target;
179cdf0e10cSrcweir OUString rel = OUString::createFromAscii( aSource3[i] );
180cdf0e10cSrcweir oslFileError e = osl_getAbsoluteFileURL( base3.pData, rel.pData , &target.pData );
181*bfbc7fbcSDamjan Jovanovic ASSERT_TRUE(osl_File_E_None == e) << "failure #3";
182cdf0e10cSrcweir if( osl_File_E_None == e )
183cdf0e10cSrcweir {
184*bfbc7fbcSDamjan Jovanovic ASSERT_TRUE(target.getLength() >= dir.getLength()) << "failure #4";
185cdf0e10cSrcweir if( target.getLength() >= dir.getLength() )
186cdf0e10cSrcweir {
187cdf0e10cSrcweir int j;
188cdf0e10cSrcweir for( j = dir.getLength() ;
189cdf0e10cSrcweir j < target.getLength() &&
190cdf0e10cSrcweir aSource3[i+1][j-dir.getLength()] == target[j] ; j++ );
191*bfbc7fbcSDamjan Jovanovic ASSERT_TRUE(j == target.getLength()) << "failure #5";
192cdf0e10cSrcweir }
193cdf0e10cSrcweir }
194cdf0e10cSrcweir OString o = OUStringToOString( target , RTL_TEXTENCODING_ASCII_US );
195cdf0e10cSrcweir OString obase = OUStringToOString( base3 , RTL_TEXTENCODING_ASCII_US );
196cdf0e10cSrcweir fprintf( stderr, "%d %s + %s = %s\n" ,e, obase.getStr(), aSource3[i], o.pData->buffer );
197cdf0e10cSrcweir }
198cdf0e10cSrcweir unlink( "c" );
199cdf0e10cSrcweir }
200cdf0e10cSrcweir else
201cdf0e10cSrcweir {
202*bfbc7fbcSDamjan Jovanovic ASSERT_TRUE(0) << "failure #6";
203cdf0e10cSrcweir }
204cdf0e10cSrcweir rmdir( "a/b" );
205cdf0e10cSrcweir }
206cdf0e10cSrcweir else
207cdf0e10cSrcweir {
208*bfbc7fbcSDamjan Jovanovic ASSERT_TRUE(0) << "failure #7";
209cdf0e10cSrcweir }
210cdf0e10cSrcweir rmdir( "a" );
211cdf0e10cSrcweir }
212cdf0e10cSrcweir else
213cdf0e10cSrcweir {
214*bfbc7fbcSDamjan Jovanovic ASSERT_TRUE(0) << "failure #8";
215cdf0e10cSrcweir }
216cdf0e10cSrcweir }
217cdf0e10cSrcweir else
218cdf0e10cSrcweir {
219*bfbc7fbcSDamjan Jovanovic ASSERT_TRUE(0) << "failure #9";
220cdf0e10cSrcweir }
221cdf0e10cSrcweir #endif
222cdf0e10cSrcweir }
223cdf0e10cSrcweir
TEST_F(oldtestfile,test_file_004)224*bfbc7fbcSDamjan Jovanovic TEST_F(oldtestfile, test_file_004)
225cdf0e10cSrcweir {
226cdf0e10cSrcweir #ifdef WIN32
227cdf0e10cSrcweir return;
228cdf0e10cSrcweir #endif
229cdf0e10cSrcweir
230cdf0e10cSrcweir OUString base4( RTL_CONSTASCII_USTRINGPARAM( "file:///" TEST_VOLUME "bla/" ) );
231cdf0e10cSrcweir int i;
232cdf0e10cSrcweir for( i = 0 ; aSource1[i] ; i +=2 )
233cdf0e10cSrcweir {
234cdf0e10cSrcweir OUString target;
235cdf0e10cSrcweir OUString rel = OUString::createFromAscii( aSource1[i] );
236cdf0e10cSrcweir oslFileError e = osl_getAbsoluteFileURL( base4.pData, rel.pData , &target.pData );
237*bfbc7fbcSDamjan Jovanovic ASSERT_TRUE(osl_File_E_None == e) << "failure #10";
238cdf0e10cSrcweir if( osl_File_E_None == e )
239cdf0e10cSrcweir {
240*bfbc7fbcSDamjan Jovanovic ASSERT_TRUE(target.equalsAscii( aSource1[i+1] )) << "failure #10.1";
241cdf0e10cSrcweir }
242cdf0e10cSrcweir OString o = OUStringToOString( target , RTL_TEXTENCODING_ASCII_US );
243cdf0e10cSrcweir OString obase = OUStringToOString( base4 , RTL_TEXTENCODING_ASCII_US );
244cdf0e10cSrcweir fprintf( stderr, "%d %s + %s = %s\n" ,e, obase.getStr(), aSource1[i], o.pData->buffer );
245cdf0e10cSrcweir }
246cdf0e10cSrcweir
247cdf0e10cSrcweir
248cdf0e10cSrcweir // fprintf( stderr, "test_file done\n" );
249cdf0e10cSrcweir }
250cdf0e10cSrcweir
251cdf0e10cSrcweir } // namespace osl_test_file
252cdf0e10cSrcweir
253cdf0e10cSrcweir // -----------------------------------------------------------------------------
254cdf0e10cSrcweir
main(int argc,char ** argv)255*bfbc7fbcSDamjan Jovanovic int main(int argc, char **argv)
256*bfbc7fbcSDamjan Jovanovic {
257*bfbc7fbcSDamjan Jovanovic ::testing::InitGoogleTest(&argc, argv);
258*bfbc7fbcSDamjan Jovanovic return RUN_ALL_TESTS();
259*bfbc7fbcSDamjan Jovanovic }
260