Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * Version: MPL 1.1 / GPLv3+ / LGPLv3+
4 : : *
5 : : * The contents of this file are subject to the Mozilla Public License Version
6 : : * 1.1 (the "License"); you may not use this file except in compliance with
7 : : * the License. You may obtain a copy of the License at
8 : : * http://www.mozilla.org/MPL/
9 : : *
10 : : * Software distributed under the License is distributed on an "AS IS" basis,
11 : : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : : * for the specific language governing rights and limitations under the
13 : : * License.
14 : : *
15 : : * The Initial Developer of the Original Code is
16 : : * [ insert your name / company etc. here eg. Jim Bob <jim@bob.org> ]
17 : : * Portions created by the Initial Developer are Copyright (C) 2010 the
18 : : * Initial Developer. All Rights Reserved.
19 : : *
20 : : * Contributor(s): Florian Reuter <freuter@novell.com>
21 : : *
22 : : * Alternatively, the contents of this file may be used under the terms of
23 : : * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
24 : : * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
25 : : * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
26 : : * instead of those above.
27 : : */
28 : :
29 : : #include <string>
30 : :
31 : : #include <sal/types.h>
32 : : #include "cppunit/TestFixture.h"
33 : : #include <cppunit/extensions/HelperMacros.h>
34 : : #include "tools/urlobj.hxx"
35 : :
36 : : #define OUSTR_TO_STDSTR( oustr ) std::string( rtl::OUStringToOString( oustr, RTL_TEXTENCODING_ASCII_US ).getStr() )
37 : :
38 : : CPPUNIT_NS_BEGIN
39 : :
40 : : template<> struct assertion_traits<INetProtocol>
41 : : {
42 : 10 : static bool equal( const INetProtocol& x, const INetProtocol& y )
43 : : {
44 : 10 : return x == y;
45 : : }
46 : :
47 : 0 : static std::string toString( const INetProtocol& x )
48 : : {
49 [ # # ]: 0 : OStringStream ost;
50 [ # # ]: 0 : ost << static_cast<unsigned int>(x);
51 [ # # ][ # # ]: 0 : return ost.str();
52 : : }
53 : : };
54 : :
55 : : CPPUNIT_NS_END
56 : :
57 : : namespace tools_urlobj
58 : : {
59 : :
60 [ - + ]: 105 : class urlobjTest:public CppUnit::TestFixture
61 : : {
62 : :
63 : : public:
64 : : // initialise your test code values here.
65 : 35 : void setUp( )
66 : : {
67 : 35 : }
68 : :
69 : 35 : void tearDown( )
70 : : {
71 : 35 : }
72 : :
73 : : // insert your test code here.
74 : : // this is only demonstration code
75 : 5 : void urlobjTest_001( )
76 : : {
77 : : INetURLObject aUrl( rtl::
78 : : OUString( RTL_CONSTASCII_USTRINGPARAM
79 [ + - ][ + - ]: 5 : ( "file://10.10.1.1/sampledir/sample.file" ) ) );
80 : : #ifdef LINUX
81 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT( aUrl.GetMainURL( INetURLObject::NO_DECODE ).
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
82 : : compareToAscii
83 : : ( "smb://10.10.1.1/sampledir/sample.file" ) ==
84 [ + - ]: 5 : 0 );
85 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT( aUrl.GetProtocol( ) == INET_PROT_SMB );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
86 : : #endif
87 : : #ifdef WIN
88 : : CPPUNIT_ASSERT( aUrl.GetMainURL( INetURLObject::NO_DECODE ).
89 : : compareToAscii
90 : : ( "file://10.10.1.1/sampledir/sample.file" ) ==
91 : : 0 );
92 : : CPPUNIT_ASSERT( aUrl.GetProtocol( ) == INET_PROT_FILE );
93 : : #endif
94 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT( aUrl.GetHost( INetURLObject::NO_DECODE ).
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
95 [ + - ]: 5 : compareToAscii( "10.10.1.1" ) == 0 );
96 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT( aUrl.GetURLPath( INetURLObject::NO_DECODE ).
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
97 [ + - ]: 5 : compareToAscii( "/sampledir/sample.file" ) == 0 );
98 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT( aUrl.getName( ).
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
99 [ + - ]: 5 : compareToAscii( "sample.file" ) == 0 );
100 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT( aUrl.getBase( ).compareToAscii( "sample" ) ==
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
101 [ + - ]: 5 : 0 );
102 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT( aUrl.getExtension( ).compareToAscii( "file" ) ==
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
103 [ + - + - ]: 10 : 0 );
104 : 5 : }
105 : :
106 : 5 : void urlobjTest_002( )
107 : : {
108 [ + - ]: 5 : INetURLObject aUrl;
109 : : aUrl.
110 : : setFSysPath( rtl::
111 : : OUString( RTL_CONSTASCII_USTRINGPARAM
112 : : ( "\\\\137.65.170.24\\c$\\Img0001.jpg" ) ),
113 [ + - ][ + - ]: 5 : INetURLObject::FSYS_DETECT );
114 : : #ifdef LINUX
115 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT( aUrl.GetMainURL( INetURLObject::NO_DECODE ).
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
116 : : compareToAscii
117 [ + - ]: 5 : ( "smb://137.65.170.24/c$/Img0001.jpg" ) == 0 );
118 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT( aUrl.GetProtocol( ) == INET_PROT_SMB );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
119 : : #endif
120 : : #ifdef WIN
121 : : CPPUNIT_ASSERT( aUrl.GetMainURL( INetURLObject::NO_DECODE ).
122 : : compareToAscii
123 : : ( "file://137.65.170.24/c$/Img0001.jpg" ) == 0 );
124 : : CPPUNIT_ASSERT( aUrl.GetProtocol( ) == INET_PROT_FILE );
125 : : #endif
126 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT( aUrl.GetHost( INetURLObject::NO_DECODE ).
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
127 [ + - ]: 5 : compareToAscii( "137.65.170.24" ) == 0 );
128 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT( aUrl.GetURLPath( INetURLObject::NO_DECODE ).
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
129 [ + - ]: 5 : compareToAscii( "/c$/Img0001.jpg" ) == 0 );
130 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT( aUrl.getName( ).
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
131 [ + - ]: 5 : compareToAscii( "Img0001.jpg" ) == 0 );
132 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT( aUrl.getBase( ).compareToAscii( "Img0001" ) ==
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
133 [ + - ]: 5 : 0 );
134 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT( aUrl.getExtension( ).compareToAscii( "jpg" ) ==
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
135 [ + - + - ]: 10 : 0 );
136 : 5 : }
137 : :
138 : :
139 : 5 : void urlobjTest_003( )
140 : : {
141 [ + - ]: 5 : INetURLObject aUrl;
142 : : aUrl.
143 : : setFSysPath( rtl::
144 : : OUString( RTL_CONSTASCII_USTRINGPARAM
145 : : ( "\\\\hive-winxp-x86\\pmladek\\test2.odt" ) ),
146 [ + - ][ + - ]: 5 : INetURLObject::FSYS_DETECT );
147 : : #ifdef LINUX
148 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT( aUrl.GetMainURL( INetURLObject::NO_DECODE ).
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
149 : : compareToAscii
150 : : ( "smb://hive-winxp-x86/pmladek/test2.odt" ) ==
151 [ + - ]: 5 : 0 );
152 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT( aUrl.GetProtocol( ) == INET_PROT_SMB );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
153 : : #endif
154 : : #ifdef WIN
155 : : CPPUNIT_ASSERT( aUrl.GetMainURL( INetURLObject::NO_DECODE ).
156 : : compareToAscii
157 : : ( "file://hive-winxp-x86/pmladek/test2.odt" ) ==
158 : : 0 );
159 : : CPPUNIT_ASSERT( aUrl.GetProtocol( ) == INET_PROT_FILE );
160 : : #endif
161 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT( aUrl.GetHost( INetURLObject::NO_DECODE ).
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
162 [ + - ]: 5 : compareToAscii( "hive-winxp-x86" ) == 0 );
163 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT( aUrl.GetURLPath( INetURLObject::NO_DECODE ).
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
164 [ + - + - ]: 10 : compareToAscii( "/pmladek/test2.odt" ) == 0 );
165 : 5 : }
166 : :
167 : 5 : void urlobjTest_004( )
168 : : {
169 : : INetURLObject aUrl( rtl::
170 : : OUString( RTL_CONSTASCII_USTRINGPARAM
171 [ + - ][ + - ]: 5 : ( "smb://10.10.1.1/sampledir/sample.file" ) ) );
172 : : #ifdef LINUX
173 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT( aUrl.GetMainURL( INetURLObject::NO_DECODE ).
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
174 : : compareToAscii
175 : : ( "smb://10.10.1.1/sampledir/sample.file" ) ==
176 [ + - ]: 5 : 0 );
177 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT( aUrl.GetProtocol( ) == INET_PROT_SMB );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
178 : : #endif
179 : : #ifdef WIN
180 : : CPPUNIT_ASSERT( aUrl.GetMainURL( INetURLObject::NO_DECODE ).
181 : : compareToAscii
182 : : ( "file://10.10.1.1/sampledir/sample.file" ) ==
183 : : 0 );
184 : : CPPUNIT_ASSERT( aUrl.GetProtocol( ) == INET_PROT_FILE );
185 : : #endif
186 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT( aUrl.GetHost( INetURLObject::NO_DECODE ).
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
187 [ + - ]: 5 : compareToAscii( "10.10.1.1" ) == 0 );
188 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT( aUrl.GetURLPath( INetURLObject::NO_DECODE ).
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
189 [ + - ]: 5 : compareToAscii( "/sampledir/sample.file" ) == 0 );
190 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT( aUrl.getName( ).
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
191 [ + - ]: 5 : compareToAscii( "sample.file" ) == 0 );
192 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT( aUrl.getBase( ).compareToAscii( "sample" ) ==
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
193 [ + - ]: 5 : 0 );
194 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT( aUrl.getExtension( ).compareToAscii( "file" ) ==
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
195 [ + - + - ]: 10 : 0 );
196 : 5 : }
197 : :
198 : 5 : void urlobjTest_005( )
199 : : {
200 [ + - ]: 5 : INetURLObject aUrl;
201 : : aUrl.setFSysPath( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "//137.65.170.24/c$/Img0001.jpg" ) ),
202 [ + - ][ + - ]: 5 : INetURLObject::FSYS_DETECT );
203 : : #ifdef LINUX
204 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT( aUrl.GetMainURL( INetURLObject::NO_DECODE ).
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
205 [ + - ]: 5 : compareToAscii( "smb://137.65.170.24/c$/Img0001.jpg" ) == 0 );
206 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT( aUrl.GetProtocol( ) == INET_PROT_SMB );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
207 : : #endif
208 : : #ifdef WIN
209 : : CPPUNIT_ASSERT( aUrl.GetMainURL( INetURLObject::NO_DECODE ).
210 : : compareToAscii( "file://137.65.170.24/c$/Img0001.jpg" ) == 0 );
211 : : CPPUNIT_ASSERT( aUrl.GetProtocol( ) == INET_PROT_FILE );
212 : : #endif
213 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT( aUrl.GetHost( INetURLObject::NO_DECODE ).
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
214 [ + - ]: 5 : compareToAscii( "137.65.170.24" ) == 0 );
215 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT( aUrl.GetURLPath( INetURLObject::NO_DECODE ).
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
216 [ + - ]: 5 : compareToAscii( "/c$/Img0001.jpg" ) == 0 );
217 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT( aUrl.getName( ).compareToAscii( "Img0001.jpg" ) == 0 );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
218 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT( aUrl.getBase( ).compareToAscii( "Img0001" ) == 0 );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
219 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT( aUrl.getExtension( ).compareToAscii( "jpg" ) == 0 );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
220 : 5 : }
221 : :
222 : :
223 : 5 : void urlobjTest_006( )
224 : : {
225 [ + - ]: 5 : INetURLObject aUrl;
226 : : aUrl.setFSysPath( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "//hive-winxp-x86/pmladek/test2.odt" ) ),
227 [ + - ][ + - ]: 5 : INetURLObject::FSYS_DETECT );
228 : : #ifdef LINUX
229 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT( aUrl.GetMainURL( INetURLObject::NO_DECODE ).
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
230 [ + - ]: 5 : compareToAscii( "smb://hive-winxp-x86/pmladek/test2.odt" ) == 0 );
231 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT( aUrl.GetProtocol( ) == INET_PROT_SMB );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
232 : : #endif
233 : : #ifdef WIN
234 : : CPPUNIT_ASSERT( aUrl.GetMainURL( INetURLObject::NO_DECODE ).
235 : : compareToAscii( "file://hive-winxp-x86/pmladek/test2.odt" ) == 0 );
236 : : CPPUNIT_ASSERT( aUrl.GetProtocol( ) == INET_PROT_FILE );
237 : : #endif
238 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT( aUrl.GetHost( INetURLObject::NO_DECODE ).
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
239 [ + - ]: 5 : compareToAscii( "hive-winxp-x86" ) == 0 );
240 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT( aUrl.GetURLPath( INetURLObject::NO_DECODE ).
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
241 [ + - + - ]: 10 : compareToAscii( "/pmladek/test2.odt" ) == 0 );
242 : 5 : }
243 : :
244 : 5 : void urlobjCmisTest( )
245 : : {
246 : : // Test with a username part
247 : : {
248 : : INetURLObject aUrl( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
249 [ + - ][ + - ]: 5 : "vnd.libreoffice.cmis+atom://username@http:%2F%2Ffoo.bar.com:8080%2Fmy%2Fcmis%2Fatom%23repo-id-encoded/path/to/content" ) ) );
250 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT_EQUAL( std::string( "http://foo.bar.com:8080/my/cmis/atom#repo-id-encoded" ),
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
251 [ + - ]: 5 : OUSTR_TO_STDSTR( aUrl.GetHost( INetURLObject::DECODE_WITH_CHARSET ) ) );
252 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_EQUAL( std::string( "username" ), OUSTR_TO_STDSTR( aUrl.GetUser( ) ) );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
253 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT_EQUAL( std::string( "/path/to/content" ),
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
254 [ + - ]: 5 : OUSTR_TO_STDSTR( aUrl.GetURLPath( INetURLObject::NO_DECODE ) ) );
255 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_EQUAL_MESSAGE( "Wrong protocol found", INET_PROT_CMIS_ATOM, aUrl.GetProtocol( ) );
[ + - ][ + - ]
[ + - ][ + - ]
256 : : }
257 : :
258 : : // Test without a username part
259 : : {
260 : : INetURLObject aUrl( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
261 [ + - ][ + - ]: 5 : "vnd.libreoffice.cmis+atom://http:%2F%2Ffoo.bar.com:8080%2Fmy%2Fcmis%2Fatom%23repo-id-encoded/path/to/content" ) ) );
262 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT_EQUAL( std::string( "http://foo.bar.com:8080/my/cmis/atom#repo-id-encoded" ),
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
263 [ + - ]: 5 : OUSTR_TO_STDSTR( aUrl.GetHost( INetURLObject::DECODE_WITH_CHARSET ) ) );
264 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT( !aUrl.HasUserData() );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
265 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT_EQUAL( std::string( "/path/to/content" ),
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
266 [ + - ]: 5 : OUSTR_TO_STDSTR( aUrl.GetURLPath( INetURLObject::NO_DECODE ) ) );
267 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_EQUAL_MESSAGE( "Wrong protocol found", INET_PROT_CMIS_ATOM, aUrl.GetProtocol( ) );
[ + - ][ + - ]
[ + - ][ + - ]
268 : : }
269 : 5 : }
270 : :
271 : : // Change the following lines only, if you add, remove or rename
272 : : // member functions of the current class,
273 : : // because these macros are need by auto register mechanism.
274 : :
275 [ + - ][ + - ]: 10 : CPPUNIT_TEST_SUITE( urlobjTest );
[ + - ][ + - ]
[ # # ]
276 [ + - ][ + - ]: 5 : CPPUNIT_TEST( urlobjTest_001 );
[ + - ][ + - ]
[ + - ][ + - ]
277 [ + - ][ + - ]: 5 : CPPUNIT_TEST( urlobjTest_002 );
[ + - ][ + - ]
[ + - ][ + - ]
278 [ + - ][ + - ]: 5 : CPPUNIT_TEST( urlobjTest_003 );
[ + - ][ + - ]
[ + - ][ + - ]
279 [ + - ][ + - ]: 5 : CPPUNIT_TEST( urlobjTest_004 );
[ + - ][ + - ]
[ + - ][ + - ]
280 [ + - ][ + - ]: 5 : CPPUNIT_TEST( urlobjTest_005 );
[ + - ][ + - ]
[ + - ][ + - ]
281 [ + - ][ + - ]: 5 : CPPUNIT_TEST( urlobjTest_006 );
[ + - ][ + - ]
[ + - ][ + - ]
282 [ + - ][ + - ]: 5 : CPPUNIT_TEST( urlobjCmisTest );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
283 [ + - ][ + - ]: 10 : CPPUNIT_TEST_SUITE_END( );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
284 : : }; // class createPool
285 : :
286 : :
287 : 5 : CPPUNIT_TEST_SUITE_REGISTRATION( urlobjTest );
288 [ + - ][ + - ]: 15 : } // namespace rtl_random
289 : :
290 : :
291 : : // -----------------------------------------------------------------------------
292 : :
293 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|