Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <osl/file.h>
21 : #include <osl/process.h>
22 : #include <rtl/ustring.hxx>
23 : #ifdef SAL_UNX
24 : #include <unistd.h>
25 : #include <limits.h>
26 : #include <string.h>
27 : #include <sys/stat.h>
28 : #define TEST_VOLUME ""
29 : #else
30 : // WINDOWS
31 : #define TEST_VOLUME "c:/"
32 : #endif
33 :
34 : #include <cppunit/TestFixture.h>
35 : #include <cppunit/extensions/HelperMacros.h>
36 : #include <cppunit/plugin/TestPlugIn.h>
37 :
38 : namespace osl_test_file
39 : {
40 :
41 : // -----------------------------------------------------------------------------
42 :
43 9 : class oldtestfile : public CppUnit::TestFixture
44 : {
45 : public:
46 : void test_file_001();
47 : void test_file_002();
48 : void test_file_004();
49 :
50 2 : CPPUNIT_TEST_SUITE( oldtestfile );
51 1 : CPPUNIT_TEST( test_file_001 );
52 1 : CPPUNIT_TEST( test_file_002 );
53 1 : CPPUNIT_TEST( test_file_004 );
54 2 : CPPUNIT_TEST_SUITE_END( );
55 : };
56 :
57 : const char * const aSource1[] =
58 : {
59 : "a" , "file:///" TEST_VOLUME "bla/a",
60 : ///TODO: check if last slash must be omitted in resolved path.
61 : // "a/" , "file:///" TEST_VOLUME "bla/a",
62 : "../a" , "file:///" TEST_VOLUME "a" ,
63 : "a/.." , "file:///" TEST_VOLUME "bla/",
64 : "a/../b" , "file:///" TEST_VOLUME "bla/b",
65 : ".." , "file:///" TEST_VOLUME "",
66 : "a/b/c/d" , "file:///" TEST_VOLUME "bla/a/b/c/d",
67 : "a/./c" , "file:///" TEST_VOLUME "bla/a/c",
68 : "file:///bla/blub", "file:///" "bla/blub",
69 : 0 , 0
70 : };
71 :
72 : const char * const aSource2[ ] =
73 : {
74 : "a" , "file:///" TEST_VOLUME "bla/blubs/schnubbel/a",
75 : ///TODO: check if last slash must be omitted in resolved path.
76 : // "a/", "file:///" TEST_VOLUME "bla/blubs/schnubbel/a",
77 : "../a", "file:///" TEST_VOLUME "bla/blubs/a",
78 : "../../a", "file:///" TEST_VOLUME "bla/a",
79 : "../../../a", "file:///" TEST_VOLUME "a",
80 : "../../../a/b/c/d", "file:///" TEST_VOLUME "a/b/c/d",
81 : 0,0
82 : };
83 :
84 : const char * const aSource3[ ] =
85 : {
86 : ".." , "/a",
87 : "../a" , "/a/a",
88 : "e/f" , "/c/e/f",
89 : "../..", "",
90 : 0,0
91 : };
92 :
93 : using ::rtl::OUString;
94 : using ::rtl::OUStringToOString;
95 : using ::rtl::OString;
96 :
97 1 : void oldtestfile::test_file_001()
98 : {
99 : #ifndef WIN32
100 1 : OUString base1( RTL_CONSTASCII_USTRINGPARAM( "file:///" TEST_VOLUME "bla" ) );
101 : int i;
102 9 : for( i = 0 ; aSource1[i] ; i +=2 )
103 : {
104 8 : OUString target;
105 8 : OUString rel = OUString::createFromAscii( aSource1[i] );
106 8 : oslFileError e = osl_getAbsoluteFileURL( base1.pData, rel.pData , &target.pData );
107 8 : CPPUNIT_ASSERT_MESSAGE("failure #1", osl_File_E_None == e );
108 8 : if( osl_File_E_None == e )
109 : {
110 8 : CPPUNIT_ASSERT_MESSAGE("failure #1.1", target.equalsAscii( aSource1[i+1] ) );
111 : }
112 9 : }
113 : #endif
114 1 : }
115 :
116 1 : void oldtestfile::test_file_002()
117 : {
118 : #ifndef WIN32
119 1 : OUString base2( RTL_CONSTASCII_USTRINGPARAM( "file:///" TEST_VOLUME "bla/blubs/schnubbel" ) );
120 : int i;
121 6 : for( i = 0 ; aSource2[i] ; i +=2 )
122 : {
123 5 : OUString target;
124 5 : OUString rel = OUString::createFromAscii( aSource2[i] );
125 5 : oslFileError e = osl_getAbsoluteFileURL( base2.pData, rel.pData , &target.pData );
126 5 : CPPUNIT_ASSERT_MESSAGE("failure #2", osl_File_E_None == e );
127 5 : if( osl_File_E_None == e )
128 : {
129 5 : CPPUNIT_ASSERT_MESSAGE("failure #2.1", target.equalsAscii( aSource2[i+1] ) );
130 : }
131 6 : }
132 : #endif
133 1 : }
134 :
135 1 : void oldtestfile::test_file_004()
136 : {
137 : #ifndef WIN32
138 1 : OUString base4( RTL_CONSTASCII_USTRINGPARAM( "file:///" TEST_VOLUME "bla/" ) );
139 : int i;
140 9 : for( i = 0 ; aSource1[i] ; i +=2 )
141 : {
142 8 : OUString target;
143 8 : OUString rel = OUString::createFromAscii( aSource1[i] );
144 8 : oslFileError e = osl_getAbsoluteFileURL( base4.pData, rel.pData , &target.pData );
145 8 : CPPUNIT_ASSERT_MESSAGE("failure #10", osl_File_E_None == e );
146 8 : if( osl_File_E_None == e )
147 : {
148 8 : CPPUNIT_ASSERT_MESSAGE("failure #10.1", target.equalsAscii( aSource1[i+1] ) );
149 : }
150 9 : }
151 : #endif
152 1 : }
153 :
154 : } // namespace osl_test_file
155 :
156 : // -----------------------------------------------------------------------------
157 1 : CPPUNIT_TEST_SUITE_REGISTRATION( osl_test_file::oldtestfile);
158 :
159 : // -----------------------------------------------------------------------------
160 4 : CPPUNIT_PLUGIN_IMPLEMENT();
161 :
162 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|