update dev300-m58
[ooovba.git] / tools / workben / urltest.cxx
blob08a9efce2fad8104a29d0b7a4af851be45db5fcf
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: urltest.cxx,v $
10 * $Revision: 1.39 $
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_tools.hxx"
33 #include <tools/inetmime.hxx>
34 #include <tools/urlobj.hxx>
35 #include "com/sun/star/util/XStringWidth.hpp"
36 #include "com/sun/star/uno/Reference.hxx"
37 #include "cppuhelper/implbase1.hxx"
38 #include "osl/thread.h"
39 #include "rtl/string.h"
40 #include "rtl/string.hxx"
41 #include "rtl/textenc.h"
42 #include "rtl/ustring.h"
43 #include "rtl/ustring.hxx"
45 #include <cstddef>
46 #include <cstdlib>
47 #include <iostream>
48 #include <ostream>
49 #include <stdio.h>
51 using namespace com::sun;
53 std::ostream & operator <<(std::ostream & out, rtl::OUString const & value) {
54 out << rtl::OUStringToOString(value, RTL_TEXTENCODING_ASCII_US).getStr();
55 return out;
58 namespace {
60 template< typename T1, typename T2 > bool assertEqual(
61 rtl::OUString const & message, T1 const & expected, T2 const & actual)
63 bool success = expected == actual;
64 if (!success) {
65 std::cout
66 << "FAILED " << message << ": " << expected << " != " << actual
67 << '\n';
69 return success;
74 //============================================================================
76 // testRelToAbs
78 //============================================================================
80 struct RelToAbsTest
82 sal_Char const * m_pBase;
83 sal_Char const * m_pRel;
84 sal_Char const * m_pAbs;
85 sal_Char const * m_pAlt;
88 //============================================================================
89 bool testRelToAbs(RelToAbsTest const * pTest, std::size_t nSize)
91 bool bSuccess = true;
92 INetURLObject aBase;
93 String aTest;
94 for (std::size_t i = 0; i < nSize; ++i)
96 if (pTest[i].m_pBase)
98 aBase.SetURL(pTest[i].m_pBase);
100 if (aBase.HasError())
102 printf(" BAD BASE %s\n",
103 pTest[i].m_pBase ? pTest[i].m_pBase : "");
104 bSuccess = false;
105 continue;
107 INetURLObject aAbs;
108 aBase.GetNewAbsURL(pTest[i].m_pRel, &aAbs);
109 ByteString aTheAbs(String(aAbs.GetMainURL(INetURLObject::NO_DECODE)),
110 RTL_TEXTENCODING_ISO_8859_1);
111 if (!(aTheAbs.Equals(pTest[i].m_pAbs)
112 || pTest[i].m_pAlt && aTheAbs.Equals(pTest[i].m_pAlt)))
114 printf(" BAD GetNewAbsURL %s -> %s (%s)\n", pTest[i].m_pRel,
115 aTheAbs.GetBuffer(), pTest[i].m_pAbs);
116 bSuccess = false;
118 aTheAbs = ByteString(
119 String(
120 INetURLObject::GetAbsURL(
121 aBase.GetMainURL(INetURLObject::NO_DECODE),
122 UniString(pTest[i].m_pRel, RTL_TEXTENCODING_ISO_8859_1))),
123 RTL_TEXTENCODING_ISO_8859_1);
124 if (!(aTheAbs.Equals(pTest[i].m_pAbs)
125 || pTest[i].m_pAlt && aTheAbs.Equals(pTest[i].m_pAlt)))
127 printf(" BAD GetAbsURL %s -> %s (%s)\n", pTest[i].m_pRel,
128 aTheAbs.GetBuffer(), pTest[i].m_pAbs);
129 bSuccess = false;
132 printf("\n");
133 return bSuccess;
136 //============================================================================
138 // testSetFSys
140 //============================================================================
142 struct SetFSysTest
144 sal_Char const * m_pPath;
145 INetURLObject::FSysStyle m_eStyle;
146 sal_Char const * m_pUrl;
149 //============================================================================
150 inline sal_Char const * toString(INetURLObject::FSysStyle eStyle)
152 static sal_Char aBuffer[5];
153 int i = 0;
154 if (eStyle & INetURLObject::FSYS_VOS)
155 aBuffer[i++] = 'V';
156 if (eStyle & INetURLObject::FSYS_UNX)
157 aBuffer[i++] = 'U';
158 if (eStyle & INetURLObject::FSYS_DOS)
159 aBuffer[i++] = 'D';
160 if (eStyle & INetURLObject::FSYS_MAC)
161 aBuffer[i++] = 'M';
162 if (i == 0)
163 aBuffer[i++] = '-';
164 aBuffer[i] = '\0';
165 return aBuffer;
168 //============================================================================
169 bool testSetFSys(SetFSysTest const * pTest, std::size_t nSize)
171 bool bSuccess = true;
172 String aPath;
173 for (std::size_t i = 0; i < nSize; ++i)
175 if (pTest[i].m_pPath)
176 aPath = String::CreateFromAscii(pTest[i].m_pPath);
177 if (aPath.Len() == 0)
179 printf(" NO PATH\n");
180 continue;
182 INetURLObject aUrl1(aPath, pTest[i].m_eStyle);
183 INetURLObject aUrl2;
184 aUrl2.setFSysPath(aPath, pTest[i].m_eStyle);
185 if (aUrl1.GetMainURL(INetURLObject::NO_DECODE).
186 equalsAscii(pTest[i].m_pUrl)
187 && aUrl2.GetMainURL(INetURLObject::NO_DECODE).
188 equalsAscii(pTest[i].m_pUrl))
189 printf(" ok %s %s -> %s\n",
190 ByteString(aPath, RTL_TEXTENCODING_ISO_8859_1).GetBuffer(),
191 toString(pTest[i].m_eStyle), pTest[i].m_pUrl);
192 else
194 String aTestA = aUrl1.GetMainURL(INetURLObject::NO_DECODE);
195 String aTestB = aUrl2.GetMainURL(INetURLObject::NO_DECODE);
197 printf(" BAD %s %s -> %s, %s (%s)\n",
198 ByteString(aPath, RTL_TEXTENCODING_ISO_8859_1).GetBuffer(),
199 toString(pTest[i].m_eStyle),
200 ByteString(aTestA, RTL_TEXTENCODING_ISO_8859_1).GetBuffer(),
201 ByteString(aTestB, RTL_TEXTENCODING_ISO_8859_1).GetBuffer(),
202 pTest[i].m_pUrl);
203 bSuccess = false;
206 printf("\n");
207 return bSuccess;
210 //============================================================================
212 // main
214 //============================================================================
216 namespace {
218 class StringWidth: public cppu::WeakImplHelper1< star::util::XStringWidth >
220 public:
221 virtual sal_Int32 SAL_CALL queryStringWidth(rtl::OUString const & rString)
222 throw (star::uno::RuntimeException)
224 return rString.getLength();
228 void abbreviate(INetURLObject aObj)
230 star::uno::Reference< star::util::XStringWidth > xWidth(new StringWidth);
231 sal_Int32 nMax = aObj.GetMainURL(INetURLObject::NO_DECODE).getLength() + 10;
232 for (sal_Int32 i = -10; i <= nMax; ++i)
234 rtl::OString
235 aAbbreviated(rtl::OUStringToOString(
236 aObj.getAbbreviated(xWidth,
238 INetURLObject::NO_DECODE),
239 RTL_TEXTENCODING_UTF8));
240 printf(
241 "%4ld: <%s", static_cast< long int >(i), aAbbreviated.getStr());
242 for (sal_Int32 j = aAbbreviated.getLength(); j < i; ++j)
243 printf(" ");
244 printf(">\n");
248 bool test_getSegmentCount(
249 char const * url, bool ignoreFinalSlash, sal_Int32 result)
251 return
252 assertEqual(
253 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("test_getSegmentCount")),
254 result,
255 INetURLObject(rtl::OUString::createFromAscii(url)).getSegmentCount(
256 ignoreFinalSlash));
259 bool test_insertName(
260 char const * url, char const * name, bool appendFinalSlash, sal_Int32 index,
261 bool ignoreFinalSlash, bool success, char const * result)
263 INetURLObject tmp(rtl::OUString::createFromAscii(url));
264 return
265 assertEqual(
266 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("test_insertName")),
267 success,
268 tmp.insertName(
269 rtl::OUString::createFromAscii(name), appendFinalSlash, index,
270 ignoreFinalSlash)) &
271 assertEqual(
272 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("test_insertName")),
273 rtl::OUString::createFromAscii(result),
274 tmp.GetMainURL(INetURLObject::NO_DECODE));
277 bool test_removeSegment(
278 char const * url, sal_Int32 index, bool ignoreFinalSlash, bool success,
279 char const * result)
281 INetURLObject tmp(rtl::OUString::createFromAscii(url));
282 return
283 assertEqual(
284 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("test_removeSegment")),
285 success, tmp.removeSegment(index, ignoreFinalSlash)) &
286 assertEqual(
287 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("test_removeSegment")),
288 rtl::OUString::createFromAscii(result),
289 tmp.GetMainURL(INetURLObject::NO_DECODE));
295 #if defined WNT
296 __cdecl
297 #endif // WNT
298 main()
300 bool bSuccess = true;
302 if (true)
304 // The data for this test is taken from the files
305 // <http://www.ics.uci.edu/~fielding/url/testN.html> with N = 1,
306 // ..., 3, as of August 28, 2000:
307 static RelToAbsTest const aTest[]
308 = { //{ "http://a/b/c/d;p?q", "g:h", "g:h", 0 },
309 { "http://a/b/c/d;p?q", "g", "http://a/b/c/g", 0 },
310 { 0, "./g", "http://a/b/c/g", 0 },
311 { 0, "g/", "http://a/b/c/g/", 0 },
312 { 0, "/g", "http://a/g", 0 },
313 { 0, "//g", "http://g", "http://g/" },
314 //{ 0, "?y", "http://a/b/c/d;p?y", 0 },
315 { 0, "g?y", "http://a/b/c/g?y", 0 },
316 //{ 0, "#s", "http://a/b/c/d;p?q#s", 0 },
317 { 0, "g#s", "http://a/b/c/g#s", 0 },
318 { 0, "g?y#s", "http://a/b/c/g?y#s", 0 },
319 { 0, ";x", "http://a/b/c/;x", 0 },
320 { 0, "g;x", "http://a/b/c/g;x", 0 },
321 { 0, "g;x?y#s", "http://a/b/c/g;x?y#s", 0 },
322 { 0, ".", "http://a/b/c/", 0 },
323 { 0, "./", "http://a/b/c/", 0 },
324 { 0, "..", "http://a/b/", 0 },
325 { 0, "../", "http://a/b/", 0 },
326 { 0, "../g", "http://a/b/g", 0 },
327 { 0, "../..", "http://a/", 0 },
328 { 0, "../../", "http://a/", 0 },
329 { 0, "../../g", "http://a/g", 0 },
330 //{ 0, "", "http://a/b/c/d;p?q", 0 },
331 { 0, "../../../g", "http://a/../g", "http://a/g" },
332 { 0, "../../../../g", "http://a/../../g", "http://a/g" },
333 { 0, "/./g", "http://a/./g", 0 },
334 { 0, "/../g", "http://a/../g", 0 },
335 { 0, "g.", "http://a/b/c/g.", 0 },
336 { 0, ".g", "http://a/b/c/.g", 0 },
337 { 0, "g..", "http://a/b/c/g..", 0 },
338 { 0, "..g", "http://a/b/c/..g", 0 },
339 { 0, "./../g", "http://a/b/g", 0 },
340 { 0, "./g/.", "http://a/b/c/g/", 0 },
341 { 0, "g/./h", "http://a/b/c/g/h", 0 },
342 { 0, "g/../h", "http://a/b/c/h", 0 },
343 { 0, "g;x=1/./y", "http://a/b/c/g;x=1/y", 0 },
344 { 0, "g;x=1/../y", "http://a/b/c/y", 0 },
345 { 0, "g?y/./x", "http://a/b/c/g?y/./x", 0 },
346 { 0, "g?y/../x", "http://a/b/c/g?y/../x", 0 },
347 { 0, "g#s/./x", "http://a/b/c/g#s/./x", 0 },
348 { 0, "g#s/../x", "http://a/b/c/g#s/../x", 0 },
349 { 0, "http:g", "http:g", "http://a/b/c/g" },
350 //{ 0, "http:", "http:", 0 },
351 { "http://a/b/c/d;p?q=1/2", "g", "http://a/b/c/g", 0 },
352 { 0, "./g", "http://a/b/c/g", 0 },
353 { 0, "g/", "http://a/b/c/g/", 0 },
354 { 0, "/g", "http://a/g", 0 },
355 { 0, "//g", "http://g", "http://g/" },
356 { 0, "g?y", "http://a/b/c/g?y", 0 },
357 { 0, "g?y/./x", "http://a/b/c/g?y/./x", 0 },
358 { 0, "g?y/../x", "http://a/b/c/g?y/../x", 0 },
359 { 0, "g#s", "http://a/b/c/g#s", 0 },
360 { 0, "g#s/./x", "http://a/b/c/g#s/./x", 0 },
361 { 0, "g#s/../x", "http://a/b/c/g#s/../x", 0 },
362 { 0, "./", "http://a/b/c/", 0 },
363 { 0, "../", "http://a/b/", 0 },
364 { 0, "../g", "http://a/b/g", 0 },
365 { 0, "../../", "http://a/", 0 },
366 { 0, "../../g", "http://a/g", 0 },
367 { "http://a/b/c/d;p=1/2?q", "g", "http://a/b/c/d;p=1/g", 0 },
368 { 0, "./g", "http://a/b/c/d;p=1/g", 0 },
369 { 0, "g/", "http://a/b/c/d;p=1/g/", 0 },
370 { 0, "g?y", "http://a/b/c/d;p=1/g?y", 0 },
371 { 0, ";x", "http://a/b/c/d;p=1/;x", 0 },
372 { 0, "g;x", "http://a/b/c/d;p=1/g;x", 0 },
373 { 0, "g;x=1/./y", "http://a/b/c/d;p=1/g;x=1/y", 0 },
374 { 0, "g;x=1/../y", "http://a/b/c/d;p=1/y", 0 },
375 { 0, "./", "http://a/b/c/d;p=1/", 0 },
376 { 0, "../", "http://a/b/c/", 0 },
377 { 0, "../g", "http://a/b/c/g", 0 },
378 { 0, "../../", "http://a/b/", 0 },
379 { 0, "../../g", "http://a/b/g", 0 },
380 { "file:///", "generic:", "file:///generic:", 0 },
381 { 0, "generic:#fragment", "file:///generic:#fragment", 0 },
382 { 0, "generic:something", "generic:something", 0 },
383 { 0, "c:/foo/bar", "file:///c:/foo/bar", 0 },
384 { 0, "c:\\foo\\bar", "file:///c:%5Cfoo%5Cbar", 0 } };
385 if (!testRelToAbs(aTest, sizeof aTest / sizeof (RelToAbsTest)))
386 bSuccess = false;
389 if (false)
391 static SetFSysTest const aTest[]
392 = { { "//.", INetURLObject::FSysStyle(0), "" },
393 { 0, INetURLObject::FSysStyle(1), "file:///" },
394 { 0, INetURLObject::FSysStyle(2), "file:////." },
395 { 0, INetURLObject::FSysStyle(3), "file:///" },
396 { 0, INetURLObject::FSysStyle(4), "file:///%2F%2F." },
397 { 0, INetURLObject::FSysStyle(5), "file:///" },
398 { 0, INetURLObject::FSysStyle(6), "file:////." },
399 { 0, INetURLObject::FSysStyle(7), "file:///" },
400 { 0, INetURLObject::FSysStyle(8), "file:///%2F%2F." },
401 { 0, INetURLObject::FSysStyle(9), "file:///" },
402 { 0, INetURLObject::FSysStyle(10), "file:////." },
403 { 0, INetURLObject::FSysStyle(11), "file:///" },
404 { 0, INetURLObject::FSysStyle(12), "file:///%2F%2F." },
405 { 0, INetURLObject::FSysStyle(13), "file:///" },
406 { 0, INetURLObject::FSysStyle(14), "file:////." },
407 { 0, INetURLObject::FSysStyle(15), "file:///" },
408 { "//./", INetURLObject::FSysStyle(0), "" },
409 { 0, INetURLObject::FSysStyle(1), "file:///" },
410 { 0, INetURLObject::FSysStyle(2), "file:////./" },
411 { 0, INetURLObject::FSysStyle(3), "file:///" },
412 { 0, INetURLObject::FSysStyle(4), "file:///%2F%2F.%2F" },
413 { 0, INetURLObject::FSysStyle(5), "file:///" },
414 { 0, INetURLObject::FSysStyle(6), "file:////./" },
415 { 0, INetURLObject::FSysStyle(7), "file:///" },
416 { 0, INetURLObject::FSysStyle(8), "file:///%2F%2F.%2F" },
417 { 0, INetURLObject::FSysStyle(9), "file:///" },
418 { 0, INetURLObject::FSysStyle(10), "file:////./" },
419 { 0, INetURLObject::FSysStyle(11), "file:///" },
420 { 0, INetURLObject::FSysStyle(12), "file:///%2F%2F.%2F" },
421 { 0, INetURLObject::FSysStyle(13), "file:///" },
422 { 0, INetURLObject::FSysStyle(14), "file:////./" },
423 { 0, INetURLObject::FSysStyle(15), "file:///" },
424 { "//./a/b\\c:d", INetURLObject::FSysStyle(0), "" },
425 { 0, INetURLObject::FSysStyle(1), "file:///a/b%5Cc:d" },
426 { 0, INetURLObject::FSysStyle(2), "file:////./a/b%5Cc:d" },
427 { 0, INetURLObject::FSysStyle(3), "file:///a/b%5Cc:d" },
428 { 0, INetURLObject::FSysStyle(4), "file:///%2F%2F.%2Fa%2Fb/c:d" },
429 { 0, INetURLObject::FSysStyle(5), "file:///a/b%5Cc:d" },
430 { 0, INetURLObject::FSysStyle(6), "file:////./a/b%5Cc:d" },
431 { 0, INetURLObject::FSysStyle(7), "file:///a/b%5Cc:d" },
432 { 0, INetURLObject::FSysStyle(8), "file:///%2F%2F.%2Fa%2Fb%5Cc/d" },
433 { 0, INetURLObject::FSysStyle(9), "file:///a/b%5Cc:d" },
434 { 0, INetURLObject::FSysStyle(10), "file:////./a/b%5Cc:d" },
435 { 0, INetURLObject::FSysStyle(11), "file:///a/b%5Cc:d" },
436 { 0, INetURLObject::FSysStyle(12), "file:///%2F%2F.%2Fa%2Fb/c:d" },
437 { 0, INetURLObject::FSysStyle(13), "file:///a/b%5Cc:d" },
438 { 0, INetURLObject::FSysStyle(14), "file:////./a/b%5Cc:d" },
439 { 0, INetURLObject::FSysStyle(15), "file:///a/b%5Cc:d" } };
440 if (!testSetFSys(aTest, sizeof aTest / sizeof (SetFSysTest)))
441 bSuccess = false;
445 if (false)
447 bool bAbs = false;
448 INetURLObject aUrl1(INetURLObject().smartRel2Abs(L"/export/home/mba/Office/user/Basic/soffice.sbl", bAbs));
450 INetURLObject aUrl2a(L"/export/home/mba/Office/user/Basic/soffice.sbl", INET_PROT_FILE);
452 INetURLObject aUrl2b(L"file:///export/home/mba/Office/user/Basic/soffice.sbl", INET_PROT_FILE);
454 INetURLObject aUrl3a(L"/export/home/mba/Office/user/Basic/soffice.sbl", INetURLObject::FSYS_DETECT);
456 INetURLObject aUrl3b(L"file:///export/home/mba/Office/user/Basic/soffice.sbl", INetURLObject::FSYS_DETECT);
460 if (true)
462 INetURLObject aUrl1("http://host:1234/xy/~zw?xxx=yyy");
463 if (aUrl1.HasError())
465 printf("BAD http\n");
466 bSuccess = false;
468 INetURLObject aUrl2("vnd.sun.star.webdav://host:1234/xy/~zw?xxx=yyy");
469 if (aUrl2.HasError())
471 printf("BAD vnd.sun.star.webdav\n");
472 bSuccess = false;
476 if (true)
478 struct Test { char const * in; char const * out; };
479 static Test const aTest[]
480 = { { "vnd.sun.star.help://", "vnd.sun.star.help:///" },
481 { "vnd.sun.star.help:///", 0 },
482 { "vnd.sun.star.help://swriter",
483 "vnd.sun.star.help://swriter/" },
484 { "vnd.sun.star.help://swriter/", 0 },
485 { "vnd.sun.star.help://swriter/12345", 0 },
486 { "vnd.sun.star.help://swriter/1234X", 0 },
487 { "vnd.sun.star.help://swriter/?a=b?c=d", 0 },
488 { "vnd.sun.star.help://swriter/12345?a=b?c=d", 0 },
489 { "vnd.sun.star.help://swriter/12345???", 0 },
490 { "vnd.sun.star.help://swriter/#xxx", 0 },
491 { "vnd.sun.star.help://swriter/12345#xxx", 0 },
492 { "vnd.sun.star.help://swriter/1234X#xxx", 0 },
493 { "vnd.sun.star.help://swriter/?a=b?c=d#xxx", 0 },
494 { "vnd.sun.star.help://swriter/12345?a=b?c=d#xxx", 0 },
495 { "vnd.sun.star.help://swriter/12345???#xxx", 0 },
496 { "vnd.sun.star.help://swriter/start", 0 },
497 { "vnd.sun.star.help://swriter/s/t/a/r/t", 0 },
498 { "vnd.sun.star.help://swriter/a%2Fb%3Fc%2534d/e?f", 0 },
499 { "vnd.sun.star.help://swriter?foo",
500 "vnd.sun.star.help://swriter/?foo" },
501 { "vnd.sun.star.help://swriter/?foo", 0 } };
502 for (std::size_t i = 0; i < sizeof aTest / sizeof aTest[0]; ++i)
504 INetURLObject aUrl(aTest[i].in);
505 if (aUrl.HasError())
506 printf("BAD %s\n", aTest[i].in);
507 else if (aUrl.GetMainURL(INetURLObject::DECODE_TO_IURI).
508 equalsAscii(
509 aTest[i].out == 0 ? aTest[i].in : aTest[i].out)
510 != sal_True)
512 String sTest(aUrl.GetMainURL(INetURLObject::DECODE_TO_IURI));
513 printf("BAD %s -> %s\n",
514 aTest[i].in,
515 ByteString(sTest, RTL_TEXTENCODING_ASCII_US).
516 GetBuffer());
521 if (true)
523 static sal_Char const * const aTest[]
524 = { /*TODO "vnd.sun.star.wfs://",*/
525 /*TODO "vnd.sun.star.wfs://LocalHost",*/
526 /*TODO "vnd.sun.star.wfs:///c|/xyz/",*/
527 /*TODO "vnd.sun.star.wfs://xxx/yyy?zzz",*/
528 "vnd.sun.star.wfs:///x/y/z",
529 /*TODO "wfs://",*/
530 /*TODO "wfs://LocalHost",*/
531 /*TODO "wfs:///c|/xyz/",*/
532 /*TODO "wfs://xxx/yyy?zzz",*/
533 /*TODO "wfs:///x/y/z"*/ };
534 for (std::size_t i = 0; i < sizeof aTest / sizeof aTest[0]; ++i)
536 INetURLObject aUrl(aTest[i]);
537 if (aUrl.HasError())
538 printf("BAD %s\n", aTest[i]);
539 else if (aUrl.GetMainURL(INetURLObject::DECODE_TO_IURI).
540 equalsAscii(aTest[i]) != sal_True)
542 String sTest(aUrl.GetMainURL(INetURLObject::DECODE_TO_IURI));
543 printf("BAD %s -> %s\n",
544 aTest[i],
545 ByteString(sTest, RTL_TEXTENCODING_ASCII_US).GetBuffer());
550 if (true)
552 static sal_Char const * const aTest[]
553 = { /*TODO "vnd.sun.star.pkg:",*/
554 /*TODO "vnd.sun.star.pkg:/",*/
555 /*TODO "vnd.sun.star.pkg://abc",*/
556 /*TODO "vnd.sun.star.pkg://file:%2F%2F%2Fa:%2Fb%20c",*/
557 "vnd.sun.star.pkg://file:%2F%2F%2Fa:%2Fb%20c/",
558 "vnd.sun.star.pkg://file:%2F%2F%2Fa:%2Fb%20c/xx",
559 /*TODO "vnd.sun.star.pkg://file:%2F%2F%2Fa:%2Fb%20c/xx;yy",*/
560 "vnd.sun.star.pkg://file:%2F%2F%2Fa:%2Fb%20c/xx//yy" };
561 for (std::size_t i = 0; i < sizeof aTest / sizeof aTest[0]; ++i)
563 INetURLObject aUrl(aTest[i]);
564 if (aUrl.HasError())
565 printf("BAD %s\n", aTest[i]);
566 else if (aUrl.GetMainURL(INetURLObject::DECODE_TO_IURI).
567 equalsAscii(aTest[i]) != sal_True)
569 String sTest(aUrl.GetMainURL(INetURLObject::DECODE_TO_IURI));
570 printf("BAD %s -> %s\n",
571 aTest[i],
572 ByteString(sTest, RTL_TEXTENCODING_ASCII_US).GetBuffer());
577 if (true)
579 static sal_Char const * const aTest[]
580 = { /*TODO "vnd.sun.star.cmd:",*/
581 /*TODO "vnd.sun.star.cmd:/",*/
582 "vnd.sun.star.cmd:logout",
583 "vnd.sun.star.cmd:log/out",
584 /*TODO "vnd.sun.star.cmd:[logout]",*/
585 "vnd.sun.star.cmd:log[out]" };
586 for (std::size_t i = 0; i < sizeof aTest / sizeof aTest[0]; ++i)
588 INetURLObject aUrl(aTest[i]);
589 if (aUrl.HasError())
590 printf("BAD %s\n", aTest[i]);
591 else if (aUrl.GetMainURL(INetURLObject::DECODE_TO_IURI).
592 equalsAscii(aTest[i]) != sal_True)
594 String sTest(aUrl.GetMainURL(INetURLObject::DECODE_TO_IURI));
595 printf("BAD %s -> %s\n",
596 aTest[i],
597 ByteString(sTest, RTL_TEXTENCODING_ASCII_US).GetBuffer());
602 if (true)
604 rtl::OUString
605 aParameters(rtl::OUString::createFromAscii("; CharSet=UTF-8 ; Blubber=Blob"));
606 sal_Unicode const * pBegin = aParameters.getStr();
607 sal_Unicode const * pEnd = pBegin + aParameters.getLength();
608 INetContentTypeParameterList aList;
609 if (INetMIME::scanParameters(pBegin, pEnd, &aList) == pEnd)
611 ULONG nCount = aList.Count();
612 for (ULONG i = 0; i < nCount; ++i)
614 INetContentTypeParameter const * p = aList.GetObject(i);
615 if (p)
618 printf("attribute: '%s'\n charset: '%s'\n language: '%s'\n value: '%s'\n converted: %s\n",
619 p->m_sAttribute.GetBuffer(),
620 p->m_sCharset.GetBuffer(),
621 p->m_sLanguage.GetBuffer(),
622 rtl::OUStringToOString(p->m_sValue,RTL_TEXTENCODING_UTF8).getStr(),
623 p->m_bConverted ? "true" : "false");
626 else
627 printf("BAD INetContentTypeParameter\n");
630 else
632 printf("BAD INetMIME::scanParameters()\n");
633 bSuccess = false;
637 if (true)
640 INetURLObject aObj;
641 aObj.setFSysPath(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("a:")),
642 INetURLObject::FSYS_DETECT);
643 if (!rtl::OUString(aObj.GetMainURL(INetURLObject::NO_DECODE)).
644 equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("file:///a:")))
646 printf("BAD setFSysPath(\"a:\")\n");
647 bSuccess = false;
651 INetURLObject aObj;
652 aObj.setFSysPath(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
653 "a:/")),
654 INetURLObject::FSYS_DETECT);
655 if (!rtl::OUString(aObj.GetMainURL(INetURLObject::NO_DECODE)).
656 equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("file:///a:/")))
658 printf("BAD setFSysPath(\"a:/\")\n");
659 bSuccess = false;
663 INetURLObject aObj;
664 aObj.setFSysPath(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
665 "a:\\")),
666 INetURLObject::FSYS_DETECT);
667 if (!rtl::OUString(aObj.GetMainURL(INetURLObject::NO_DECODE)).
668 equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("file:///a:/")))
670 printf("BAD setFSysPath(\"a:\\\")\n");
671 bSuccess = false;
675 if (!rtl::OUString(INetURLObject("file:///a:").
676 getFSysPath(INetURLObject::FSYS_DETECT)).
677 equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("a:")))
679 printf("BAD getFSysPath(\"file:///a:\")\n");
680 bSuccess = false;
682 if (!rtl::OUString(INetURLObject("file:///a:/").
683 getFSysPath(INetURLObject::FSYS_DETECT)).
684 equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("a:\\")))
686 printf("BAD getFSysPath(\"file:///a:/\")\n");
687 bSuccess = false;
691 bool bWasAbsolute;
692 if (!rtl::OUString(INetURLObject(rtl::OUString(
693 RTL_CONSTASCII_USTRINGPARAM(
694 "file:///"))).
695 smartRel2Abs(
696 rtl::OUString(
697 RTL_CONSTASCII_USTRINGPARAM(
698 "a:")),
699 bWasAbsolute).
700 GetMainURL(INetURLObject::NO_DECODE)).
701 equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("file:///a:"))
702 || !bWasAbsolute)
704 printf("BAD smartRel2Abs(\"a:\")\n");
705 bSuccess = false;
709 bool bWasAbsolute;
710 if (!rtl::OUString(INetURLObject(rtl::OUString(
711 RTL_CONSTASCII_USTRINGPARAM(
712 "file:///"))).
713 smartRel2Abs(
714 rtl::OUString(
715 RTL_CONSTASCII_USTRINGPARAM(
716 "a:/")),
717 bWasAbsolute).
718 GetMainURL(INetURLObject::NO_DECODE)).
719 equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("file:///a:/"))
720 || !bWasAbsolute)
722 printf("BAD smartRel2Abs(\"a:/\")\n");
723 bSuccess = false;
727 bool bWasAbsolute;
728 if (!rtl::OUString(INetURLObject(rtl::OUString(
729 RTL_CONSTASCII_USTRINGPARAM(
730 "file:///"))).
731 smartRel2Abs(
732 rtl::OUString(
733 RTL_CONSTASCII_USTRINGPARAM(
734 "a:\\")),
735 bWasAbsolute).
736 GetMainURL(INetURLObject::NO_DECODE)).
737 equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("file:///a:/"))
738 || !bWasAbsolute)
740 printf("BAD smartRel2Abs(\"a:\\\")\n");
741 bSuccess = false;
745 bool bWasAbsolute;
746 if (!rtl::OUString(INetURLObject(rtl::OUString(
747 RTL_CONSTASCII_USTRINGPARAM(
748 "file:///"))).
749 smartRel2Abs(
750 rtl::OUString(
751 RTL_CONSTASCII_USTRINGPARAM(
752 "generic:")),
753 bWasAbsolute).
754 GetMainURL(INetURLObject::NO_DECODE)).
755 equalsAsciiL(
756 RTL_CONSTASCII_STRINGPARAM("file:///generic:"))
757 || bWasAbsolute)
759 printf("BAD smartRel2Abs(\"generic:\")\n");
760 bSuccess = false;
764 bool bWasAbsolute;
765 if (!rtl::OUString(INetURLObject(rtl::OUString(
766 RTL_CONSTASCII_USTRINGPARAM(
767 "file:///"))).
768 smartRel2Abs(
769 rtl::OUString(
770 RTL_CONSTASCII_USTRINGPARAM(
771 "generic:#fragment")),
772 bWasAbsolute).
773 GetMainURL(INetURLObject::NO_DECODE)).
774 equalsAsciiL(
775 RTL_CONSTASCII_STRINGPARAM(
776 "file:///generic:#fragment"))
777 || bWasAbsolute)
779 printf("BAD smartRel2Abs(\"generic:#fragment\")\n");
780 bSuccess = false;
784 bool bWasAbsolute;
785 if (!rtl::OUString(INetURLObject(rtl::OUString(
786 RTL_CONSTASCII_USTRINGPARAM(
787 "file:///"))).
788 smartRel2Abs(
789 rtl::OUString(
790 RTL_CONSTASCII_USTRINGPARAM(
791 "generic:something")),
792 bWasAbsolute).
793 GetMainURL(INetURLObject::NO_DECODE)).
794 equalsAsciiL(
795 RTL_CONSTASCII_STRINGPARAM("generic:something"))
796 || !bWasAbsolute)
798 printf("BAD smartRel2Abs(\"generic:something\")\n");
799 bSuccess = false;
803 bool bWasAbsolute;
804 if (!rtl::OUString(INetURLObject(rtl::OUString(
805 RTL_CONSTASCII_USTRINGPARAM(
806 "file:///"))).
807 smartRel2Abs(
808 rtl::OUString(
809 RTL_CONSTASCII_USTRINGPARAM(
810 "\\\\unc_host\\path")),
811 bWasAbsolute).
812 GetMainURL(INetURLObject::NO_DECODE)).
813 equalsAsciiL(
814 RTL_CONSTASCII_STRINGPARAM("file://unc_host/path"))
815 || !bWasAbsolute)
817 printf("BAD smartRel2Abs(\"\\\\unc_host\\path\")\n");
818 bSuccess = false;
823 if (true)
825 /*TODO
827 INetURLObject aObj(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("http://xxx/yyy?abc/def~")));
828 if (!rtl::OUString(aObj.GetMainURL(INetURLObject::NO_DECODE)).
829 equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("http://xxx/yyy?abc%2Fdef%7E")))
831 printf("BAD http query 1\n");
832 bSuccess = false;
837 INetURLObject aObj(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("https://xxx/yyy?abc/def~")));
838 if (!rtl::OUString(aObj.GetMainURL(INetURLObject::NO_DECODE)).
839 equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("https://xxx/yyy?abc/def~")))
841 printf("BAD https query 1\n");
842 bSuccess = false;
845 /*TODO
847 INetURLObject aObj(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("http://xxx/yyy")));
848 aObj.SetParam("abc/def~");
849 if (!rtl::OUString(aObj.GetMainURL(INetURLObject::NO_DECODE)).
850 equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("http://xxx/yyy?abc%2Fdef%7E")))
852 printf("BAD http query 2\n");
853 bSuccess = false;
858 INetURLObject aObj(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("https://xxx/yyy")));
859 aObj.SetParam("abc/def~");
860 if (!rtl::OUString(aObj.GetMainURL(INetURLObject::NO_DECODE)).
861 equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("https://xxx/yyy?abc/def~")))
863 printf("BAD https query 2\n");
864 bSuccess = false;
869 if (true)
871 if (INetURLObject(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("vnd.sun.star.hier:"))).HasError())
873 printf("BAD vnd.sun.star.hier test 1\n");
874 bSuccess = false;
876 if (!INetURLObject(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("vnd.sun.star.hier://"))).HasError())
878 printf("BAD vnd.sun.star.hier test 2\n");
879 bSuccess = false;
881 if (!INetURLObject(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("vnd.sun.star.hier:///"))).HasError())
883 printf("BAD vnd.sun.star.hier test 3\n");
884 bSuccess = false;
886 if (!INetURLObject(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("vnd.sun.star.hier:///abc"))).HasError())
888 printf("BAD vnd.sun.star.hier test 4\n");
889 bSuccess = false;
891 if (INetURLObject(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("vnd.sun.star.hier://abc"))).HasError())
893 printf("BAD vnd.sun.star.hier test 5\n");
894 bSuccess = false;
896 if (INetURLObject(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("vnd.sun.star.hier://abc/def"))).HasError())
898 printf("BAD vnd.sun.star.hier test 6\n");
899 bSuccess = false;
903 if (false)
905 abbreviate(INetURLObject(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
906 "file:///"))));
907 abbreviate(INetURLObject(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
908 "file:///a"))));
909 abbreviate(INetURLObject(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
910 "file:///a/def/"))));
911 abbreviate(INetURLObject(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
912 "file:///ab/def/"))));
913 abbreviate(INetURLObject(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
914 "file:///abc/def/"))));
915 abbreviate(INetURLObject(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
916 "file:///a/def"))));
917 abbreviate(INetURLObject(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
918 "file:///ab/def"))));
919 abbreviate(INetURLObject(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
920 "file:///abc/def"))));
921 abbreviate(INetURLObject(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
922 "file:///abcdef/d"))));
923 abbreviate(INetURLObject(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
924 "file:///abcdef/de"))));
925 abbreviate(INetURLObject(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
926 "file:///abcdef/def"))));
927 abbreviate(INetURLObject(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
928 "file://some.host/"))));
929 abbreviate(INetURLObject(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
930 "file://some.host/a"))));
931 abbreviate(INetURLObject(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
932 "file://some.host/a/def/"))));
933 abbreviate(INetURLObject(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
934 "file://some.host/ab/def/"))));
935 abbreviate(INetURLObject(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
936 "file://some.host/abc/def/"))));
937 abbreviate(INetURLObject(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
938 "file://some.host/a/def"))));
939 abbreviate(INetURLObject(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
940 "file://some.host/ab/def"))));
941 abbreviate(INetURLObject(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
942 "file://some.host/abc/def"))));
943 abbreviate(INetURLObject(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
944 "file://some.host/abcdef/d"))));
945 abbreviate(INetURLObject(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
946 "file://some.host/abcdef/de"))));
947 abbreviate(INetURLObject(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
948 "file://some.host/abcdef/def"))));
949 abbreviate(INetURLObject(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
950 "http://foo/aa/bb//cc/d/eee////ff/ggggggg/hhhhhh/iii/j/"
951 "kkkkkkkkkkkkk/ll/mm/nn/oo/p"))));
954 if (true)
957 rtl::OUString
958 aBase(RTL_CONSTASCII_USTRINGPARAM("file:///a:/b/c"));
959 rtl::OUString aAbs(RTL_CONSTASCII_USTRINGPARAM("file:///a:/d/e"));
960 rtl::OUString aRel(INetURLObject::GetRelURL(aBase, aAbs));
961 if (!aRel.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("../d/e")))
963 printf("BAD GetRelURL(%s, %s) = %s\n",
964 rtl::OUStringToOString(aBase, RTL_TEXTENCODING_UTF8).
965 getStr(),
966 rtl::OUStringToOString(aAbs, RTL_TEXTENCODING_UTF8).
967 getStr(),
968 rtl::OUStringToOString(aRel, RTL_TEXTENCODING_UTF8).
969 getStr());
970 bSuccess = false;
974 rtl::OUString
975 aBase(RTL_CONSTASCII_USTRINGPARAM("file:///a:/b/c"));
976 rtl::OUString aAbs(RTL_CONSTASCII_USTRINGPARAM("file:///d:/e/f"));
977 rtl::OUString aRel(INetURLObject::GetRelURL(aBase, aAbs));
978 if (aRel != aAbs)
980 printf("BAD GetRelURL(%s, %s) = %s\n",
981 rtl::OUStringToOString(aBase, RTL_TEXTENCODING_UTF8).
982 getStr(),
983 rtl::OUStringToOString(aAbs, RTL_TEXTENCODING_UTF8).
984 getStr(),
985 rtl::OUStringToOString(aRel, RTL_TEXTENCODING_UTF8).
986 getStr());
987 bSuccess = false;
991 rtl::OUString
992 aBase(RTL_CONSTASCII_USTRINGPARAM("file:///a:/b/c"));
993 rtl::OUString aAbs(RTL_CONSTASCII_USTRINGPARAM("file:///d/e/f"));
994 rtl::OUString aRel(INetURLObject::GetRelURL(aBase, aAbs));
995 if (!aRel.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("../../d/e/f")))
997 printf("BAD GetRelURL(%s, %s) = %s\n",
998 rtl::OUStringToOString(aBase, RTL_TEXTENCODING_UTF8).
999 getStr(),
1000 rtl::OUStringToOString(aAbs, RTL_TEXTENCODING_UTF8).
1001 getStr(),
1002 rtl::OUStringToOString(aRel, RTL_TEXTENCODING_UTF8).
1003 getStr());
1004 bSuccess = false;
1008 rtl::OUString
1009 aBase(RTL_CONSTASCII_USTRINGPARAM("file:///a:/b/c"));
1010 rtl::OUString aAbs(RTL_CONSTASCII_USTRINGPARAM("file:///d:/e/f"));
1011 rtl::OUString
1012 aRel(INetURLObject::GetRelURL(aBase,
1013 aAbs,
1014 INetURLObject::WAS_ENCODED,
1015 INetURLObject::DECODE_TO_IURI,
1016 RTL_TEXTENCODING_UTF8,
1017 INetURLObject::FSYS_UNX));
1018 if (!aRel.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(
1019 "../../d:/e/f")))
1021 printf("BAD GetRelURL(%s, %s) = %s\n",
1022 rtl::OUStringToOString(aBase, RTL_TEXTENCODING_UTF8).
1023 getStr(),
1024 rtl::OUStringToOString(aAbs, RTL_TEXTENCODING_UTF8).
1025 getStr(),
1026 rtl::OUStringToOString(aRel, RTL_TEXTENCODING_UTF8).
1027 getStr());
1028 bSuccess = false;
1031 /*TODO
1033 rtl::OUString
1034 aBase(RTL_CONSTASCII_USTRINGPARAM("file:///test.html"));
1035 rtl::OUString
1036 aAbs(RTL_CONSTASCII_USTRINGPARAM("/images/myimage.gif"));
1037 rtl::OUString aRel(INetURLObject::GetRelURL(aBase, aAbs));
1038 if (aRel != aAbs)
1040 printf("BAD GetRelURL(%s, %s) = %s\n",
1041 rtl::OUStringToOString(aBase, RTL_TEXTENCODING_UTF8).
1042 getStr(),
1043 rtl::OUStringToOString(aAbs, RTL_TEXTENCODING_UTF8).
1044 getStr(),
1045 rtl::OUStringToOString(aRel, RTL_TEXTENCODING_UTF8).
1046 getStr());
1047 bSuccess = false;
1053 if (true)
1055 INetURLObject aUrl(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1056 "file://host/dir/file")));
1057 rtl::OUString aPath;
1058 aPath = aUrl.getFSysPath(INetURLObject::FSYS_DETECT);
1059 if (!aPath.
1060 equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("//host/dir/file")))
1062 printf("BAD getFSysPath(VOS|UNX|DOS|MAC) = %s\n",
1063 rtl::OUStringToOString(aPath, RTL_TEXTENCODING_UTF8).
1064 getStr());
1065 bSuccess = false;
1067 aPath = aUrl.getFSysPath(INetURLObject::FSysStyle(
1068 INetURLObject::FSYS_UNX
1069 | INetURLObject::FSYS_DOS
1070 | INetURLObject::FSYS_MAC));
1071 if (!aPath.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(
1072 "\\\\host\\dir\\file")))
1074 printf("BAD getFSysPath(UNX|DOS|MAC) = %s\n",
1075 rtl::OUStringToOString(aPath, RTL_TEXTENCODING_UTF8).
1076 getStr());
1077 bSuccess = false;
1079 aPath = aUrl.getFSysPath(INetURLObject::FSysStyle(
1080 INetURLObject::FSYS_UNX
1081 | INetURLObject::FSYS_MAC));
1082 if (aPath.getLength() != 0)
1084 printf("BAD getFSysPath(UNX|MAC) = %s\n",
1085 rtl::OUStringToOString(aPath, RTL_TEXTENCODING_UTF8).
1086 getStr());
1087 bSuccess = false;
1091 if (true)
1094 INetURLObject aUrl1(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("vnd.sun.star.odma:")));
1095 rtl::OUString aUrl2(aUrl1.GetMainURL(
1096 INetURLObject::DECODE_TO_IURI));
1097 if (!aUrl2.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("vnd.sun.star.odma:/")))
1099 printf("BAD vnd.sun.star.odma: != %s\n",
1100 rtl::OUStringToOString(aUrl2, RTL_TEXTENCODING_UTF8).
1101 getStr());
1102 bSuccess = false;
1106 INetURLObject aUrl1(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("vnd.sun.star.odma:/")));
1107 rtl::OUString aUrl2(aUrl1.GetMainURL(
1108 INetURLObject::DECODE_TO_IURI));
1109 if (!aUrl2.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("vnd.sun.star.odma:/")))
1111 printf("BAD vnd.sun.star.odma:/ != %s\n",
1112 rtl::OUStringToOString(aUrl2, RTL_TEXTENCODING_UTF8).
1113 getStr());
1114 bSuccess = false;
1118 INetURLObject aUrl1(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("vnd.sun.star.odma:/bla/bla")));
1119 rtl::OUString aUrl2(aUrl1.GetMainURL(
1120 INetURLObject::DECODE_TO_IURI));
1121 if (!aUrl2.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("vnd.sun.star.odma:/bla%2Fbla")))
1123 printf("BAD vnd.sun.star.odma:/bla/bla != %s\n",
1124 rtl::OUStringToOString(aUrl2, RTL_TEXTENCODING_UTF8).
1125 getStr());
1126 bSuccess = false;
1131 if (true)
1133 struct Test
1135 char const * m_pInput;
1136 char const * m_pOutput;
1138 static Test const aTest[]
1139 = { { "file:///abc", "file:///abc" },
1140 { "file://localhost/abc", "file:///abc" },
1141 { "file://LocalHost/abc", "file:///abc" },
1142 { "file://LOCALHOST/abc", "file:///abc" },
1143 { "file://127.0.0.1/abc", "file://127.0.0.1/abc" },
1144 { "file://xxx.yyy-zzz/abc", "file://xxx.yyy-zzz/abc" },
1145 { "file://xxx_yyy/abc", "file://xxx_yyy/abc" },
1146 { "file://!%23$%&'()-.@^_{}~/abc",
1147 "file://!%23$%25&'()-.@%5E_%7B%7D~/abc" },
1148 { "file://d:\\dir1\\file1", 0 },
1149 { "http://as@alaska:8000/test/test.sxw", 0 },
1150 { "telnet:", 0 },
1151 { "telnet://", 0 },
1152 { "telnet://ab:cd@ef:", "telnet://ab:cd@ef:/" },
1153 { "telnet://ab:cd@ef:123", "telnet://ab:cd@ef:123/" },
1154 { "TELNET://abc.def.ghi/", "telnet://abc.def.ghi/" },
1155 { "telnet://abc.def.ghi/jkl", 0 },
1156 { "telnet://abc.def.ghi?jkl", 0 },
1157 { "telnet://abc.def.ghi/?jkl", 0 },
1158 { "file:", 0 },
1159 { "file:/", "file:///" },
1160 { "file:/abc", "file:///abc" },
1161 { "file:/abc/def", "file:///abc/def" },
1162 { "file:/localhost", "file:///localhost" },
1163 { "file://", "file:///" },
1164 { "file:///", "file:///" },
1165 { "http:", 0 },
1166 { "http:/abc", 0 },
1167 { "news:", 0 },
1168 { "news:*", "news:*" },
1169 { "news:**", 0 },
1170 { "news:%2A", 0 },
1171 { "news:a", "news:a" },
1172 { "news:A", "news:A" },
1173 { "news:+-._", 0 },
1174 { "news:A0+-._", "news:A0+-._" },
1175 { "news:0", 0 },
1176 { "news:AB,", 0 },
1177 { "news:abc@def", "news:abc@def" },
1178 { "news:abc@def:33", 0 },
1179 { "news:abc@123.456.789.0", "news:abc@123.456.789.0" },
1180 { "news:abc@def.", "news:abc@def." },
1181 { "news:abc@def.ghi", "news:abc@def.ghi" },
1182 { "news:abc@def.-ghi", 0 },
1183 { "news:abc@def.ghi@", 0 },
1184 { "news:%21%22%23@def", "news:%21%22%23@def" },
1185 { "news:!%22%23@def", "news:!%22%23@def" },
1186 { "news: @def", "news:%20@def" },
1187 { "vnd.sun.star.tdoc:", 0 },
1188 { "vnd.sun.star.tdoc:a/b/c", 0 },
1189 { "vnd.sun.star.tdoc:/", "vnd.sun.star.tdoc:/" },
1190 { "vnd.sun.star.tdoc:/a;b/", "vnd.sun.star.tdoc:/a%3Bb/" },
1191 { "vnd.sun.star.tdoc:/a?b", "vnd.sun.star.tdoc:/a%3Fb" },
1192 { "http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/x",
1193 "http://[fedc:ba98:7654:3210:fedc:ba98:7654:3210]:80/x" },
1194 { "http://[1080:0:0:0:8:800:200C:417A]/index.html",
1195 "http://[1080:0:0:0:8:800:200c:417a]/index.html" },
1196 { "http://[3ffe:2a00:100:7031::1]",
1197 "http://[3ffe:2a00:100:7031::1]/" },
1198 { "http://[1080::8:800:200c:417a]/foo",
1199 "http://[1080::8:800:200c:417a]/foo" },
1200 { "http://[::192.9.5.5]/ipng", "http://[::192.9.5.5]/ipng" },
1201 { "http://[:::192.9.5.5]/ipng", "http://[:::192.9.5.5]/ipng" },
1202 { "http://[::FFFF:129.144.52.38]:80/index.html",
1203 "http://[::ffff:129.144.52.38]:80/index.html" },
1204 { "http://[2010:836B:4179::836B:4179]",
1205 "http://[2010:836b:4179::836b:4179]/" },
1206 { "http://[::1]", "http://[::1]/" },
1207 { "http://[0:0:0:0:0:0:13.1.68.3]/",
1208 "http://[0:0:0:0:0:0:13.1.68.3]/" },
1209 { "http://[0:0:0:0:0:FFFF:129.144.52.38]/",
1210 "http://[0:0:0:0:0:ffff:129.144.52.38]/" },
1211 { "smb://", "smb:///" },
1212 { "smb://foo", "smb://foo/" },
1213 { "smb://x;foo:bar@baz.xyz:12345/ab?cd",
1214 "smb://x;foo:bar@baz.xyz:12345/ab?cd" } };
1215 for (std::size_t i = 0; i < sizeof aTest / sizeof aTest[0]; ++i)
1217 INetURLObject aUrl(aTest[i].m_pInput);
1218 if (aTest[i].m_pOutput == 0
1219 ? !aUrl.HasError()
1220 : (aUrl.HasError()
1221 || (aUrl.GetMainURL(INetURLObject::DECODE_TO_IURI).
1222 equalsAscii(aTest[i].m_pOutput)
1223 != sal_True)))
1225 String sTest(aUrl.GetMainURL(INetURLObject::DECODE_TO_IURI));
1226 printf("BAD %s -> %s != %s\n",
1227 aTest[i].m_pInput,
1228 aUrl.HasError() ? "<none>"
1229 : ByteString(sTest, RTL_TEXTENCODING_ASCII_US).GetBuffer(),
1230 aTest[i].m_pOutput == 0 ? "<none>" : aTest[i].m_pOutput);
1235 if (true)
1237 struct Test
1239 char const * m_pInput;
1240 char const * m_pOutput;
1242 static Test const aTest[]
1243 = { { "file://d:\\dir1\\file1", "file:///d:/dir1/file1" },
1244 { "http://as@alaska:8000/test/test.sxw", 0 } };
1245 for (std::size_t i = 0; i < sizeof aTest / sizeof aTest[0]; ++i)
1247 INetURLObject aUrl = INetURLObject(
1248 String(aTest[i].m_pInput, RTL_TEXTENCODING_UTF8),
1249 INET_PROT_HTTP);
1250 if (aTest[i].m_pOutput == 0
1251 ? !aUrl.HasError()
1252 : (aUrl.HasError()
1253 || (aUrl.GetMainURL(INetURLObject::DECODE_TO_IURI).
1254 equalsAscii(aTest[i].m_pOutput)
1255 != sal_True)))
1257 String sTest(aUrl.GetMainURL(INetURLObject::DECODE_TO_IURI));
1258 printf("BAD %s -> %s != %s\n",
1259 aTest[i].m_pInput,
1260 aUrl.HasError() ? "<none>"
1261 : ByteString(sTest, RTL_TEXTENCODING_ASCII_US).GetBuffer(),
1262 aTest[i].m_pOutput == 0 ? "<none>" : aTest[i].m_pOutput);
1267 if (true)
1269 INetURLObject aUrl;
1270 rtl::OUString aUser;
1271 aUrl = INetURLObject(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1272 "ftp://test")));
1273 aUser = aUrl.GetUser();
1274 if (aUser.getLength() != 0)
1275 printf(
1276 "BAD <ftp://test> user: \"%s\" != \"\"",
1277 rtl::OUStringToOString(aUser, RTL_TEXTENCODING_UTF8).getStr());
1278 aUrl = INetURLObject(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1279 "ftp://user@test")));
1280 aUser = aUrl.GetUser();
1281 if (!aUser.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("user")))
1282 printf(
1283 "BAD <ftp://user@test> user: \"%s\" != \"user\"",
1284 rtl::OUStringToOString(aUser, RTL_TEXTENCODING_UTF8).getStr());
1287 if (true)
1289 INetURLObject aUrl;
1291 aUrl = INetURLObject("vnd.sun.star.pkg://foo.bar/a/b/c?abc/def?");
1292 if (aUrl.GetProtocol() != INET_PROT_VND_SUN_STAR_PKG)
1293 printf("BAD <vnd.sun.star.pkg://foo.bar/a/b/c?abc/def?>:"
1294 " scheme = %d\n",
1295 static_cast< int >(aUrl.GetProtocol()));
1296 else
1298 if (!rtl::OUString(aUrl.GetMainURL(INetURLObject::NO_DECODE)).
1299 equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(
1300 "vnd.sun.star.pkg://foo.bar/a/b/c?abc/def?")))
1301 printf("BAD <vnd.sun.star.pkg://foo.bar/a/b/c?abc/def?>:"
1302 " URL = %s\n",
1303 rtl::OUStringToOString(
1304 aUrl.GetMainURL(INetURLObject::NO_DECODE),
1305 RTL_TEXTENCODING_UTF8).getStr());
1306 if (!rtl::OUString(aUrl.GetParam(INetURLObject::NO_DECODE)).
1307 equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("abc/def?")))
1308 printf("BAD <vnd.sun.star.pkg://foo.bar/a/b/c?abc/def?>:"
1309 " query = %s\n",
1310 rtl::OUStringToOString(
1311 aUrl.GetParam(INetURLObject::NO_DECODE),
1312 RTL_TEXTENCODING_UTF8).getStr());
1315 aUrl = INetURLObject("vnd.sun.star.pkg://foo.bar/a/b/c%3Fabc/def%3F");
1316 if (aUrl.GetProtocol() != INET_PROT_VND_SUN_STAR_PKG)
1317 printf("BAD <vnd.sun.star.pkg://foo.bar/a/b/c%%3Fabc/def%%3F>:"
1318 " scheme = %d\n",
1319 static_cast< int >(aUrl.GetProtocol()));
1320 else
1322 if (!rtl::OUString(aUrl.GetMainURL(INetURLObject::NO_DECODE)).
1323 equalsAsciiL(
1324 RTL_CONSTASCII_STRINGPARAM(
1325 "vnd.sun.star.pkg://foo.bar/a/b/c%3Fabc/def%3F")))
1326 printf("BAD <vnd.sun.star.pkg://foo.bar/a/b/c?abc/def?>:"
1327 " URL = %s\n",
1328 rtl::OUStringToOString(
1329 aUrl.GetMainURL(INetURLObject::NO_DECODE),
1330 RTL_TEXTENCODING_UTF8).getStr());
1331 if (!rtl::OUString(aUrl.GetParam(INetURLObject::NO_DECODE)).
1332 equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("")))
1333 printf("BAD <vnd.sun.star.pkg://foo.bar/a/b/c%%3Fabc/def%%3F>:"
1334 " query = %s\n",
1335 rtl::OUStringToOString(
1336 aUrl.GetParam(INetURLObject::NO_DECODE),
1337 RTL_TEXTENCODING_UTF8).getStr());
1341 if (true)
1343 struct Test
1345 INetProtocol eScheme;
1346 char const * pPath;
1347 char const * pUri;
1349 static Test const aTest[]
1350 = { { INET_PROT_FILE, "", "file:///" },
1351 { INET_PROT_FILE, "/", "file:///" },
1352 { INET_PROT_FILE, "abc", 0 },
1353 { INET_PROT_FILE, "/abc/", "file:///abc/" },
1354 { INET_PROT_NEWS, "", 0 },
1355 { INET_PROT_NEWS, "*", "news:*" },
1356 { INET_PROT_NEWS, "**", 0 },
1357 { INET_PROT_NEWS, "%2A", 0 },
1358 { INET_PROT_NEWS, "a", "news:a" },
1359 { INET_PROT_NEWS, "A", "news:A" },
1360 { INET_PROT_NEWS, "+-._", 0 },
1361 { INET_PROT_NEWS, "A0+-._", "news:A0+-._" },
1362 { INET_PROT_NEWS, "0", 0 },
1363 { INET_PROT_NEWS, "AB,", 0 },
1364 { INET_PROT_NEWS, "abc@def", "news:abc@def" },
1365 { INET_PROT_NEWS, "abc@def:33", 0 },
1366 { INET_PROT_NEWS, "abc@123.456.789.0",
1367 "news:abc@123.456.789.0" },
1368 { INET_PROT_NEWS, "abc@def.", "news:abc@def." },
1369 { INET_PROT_NEWS, "abc@def.ghi", "news:abc@def.ghi" },
1370 { INET_PROT_NEWS, "abc@def.-ghi", 0 },
1371 { INET_PROT_NEWS, "abc@def.ghi@", 0 },
1372 { INET_PROT_NEWS, "!\"#@def", "news:!%22%23@def" },
1373 { INET_PROT_NEWS, " @def", "news:%20@def" } };
1374 for (std::size_t i = 0; i < sizeof aTest / sizeof aTest[0]; ++i)
1376 INetURLObject aUri;
1377 bool bOk = aUri.ConcatData(aTest[i].eScheme, String(), String(),
1378 String(), 0,
1379 String(aTest[i].pPath,
1380 RTL_TEXTENCODING_ASCII_US),
1381 INetURLObject::ENCODE_ALL);
1382 if (bOk == aUri.HasError())
1383 printf(
1384 "BAD ConcatData(%d, ..., %s) = %d, HasError() = %d\n",
1385 static_cast< int >(aTest[i].eScheme), aTest[i].pPath,
1386 static_cast< int >(bOk),
1387 static_cast< int >(aUri.HasError()));
1388 else if (aTest[i].pUri == 0
1389 ? !aUri.HasError()
1390 : (aUri.HasError()
1391 || (aUri.GetMainURL(INetURLObject::DECODE_TO_IURI).
1392 equalsAscii(aTest[i].pUri)
1393 != sal_True)))
1395 String sTest(aUri.GetMainURL(INetURLObject::DECODE_TO_IURI));
1396 printf("BAD ConcatData(%d, ..., %s) -> %s != %s\n",
1397 static_cast< int >(aTest[i].eScheme), aTest[i].pPath,
1398 aUri.HasError() ? "<none>"
1399 : ByteString(sTest, RTL_TEXTENCODING_ASCII_US).GetBuffer(),
1400 aTest[i].pUri == 0 ? "<none>" : aTest[i].pUri);
1405 if (true)
1407 // #i13760#
1409 // Test for unrelated URLs.
1410 const rtl::OUString aBaseURL(RTL_CONSTASCII_USTRINGPARAM(
1411 "http://www.openoffice.org"));
1412 rtl::OUString aRelURL (RTL_CONSTASCII_USTRINGPARAM(
1413 "http://www.sun.com"));
1415 rtl::OUString aRelURLToTest(
1416 INetURLObject::GetRelURL(aBaseURL, aRelURL));
1418 if (INetURLObject(aRelURLToTest) != INetURLObject(aRelURL))
1419 printf("BAD GetRelURL(%s, %s), ret = %s\n",
1420 ByteString(aBaseURL.getStr(),
1421 RTL_TEXTENCODING_ASCII_US).GetBuffer(),
1422 ByteString(aRelURL.getStr(),
1423 RTL_TEXTENCODING_ASCII_US).GetBuffer(),
1424 ByteString(aRelURLToTest.getStr(),
1425 RTL_TEXTENCODING_ASCII_US).GetBuffer());
1427 // Test for related URLs.
1428 aRelURL = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1429 "http://www.openoffice.org/api/test.html"));
1430 aRelURLToTest = rtl::OUString(
1431 INetURLObject::GetRelURL(aBaseURL, aRelURL));
1433 if (!aRelURLToTest.equalsAsciiL(
1434 RTL_CONSTASCII_STRINGPARAM("api/test.html")))
1435 printf("BAD GetRelURL(%s, %s), ret = %s\n",
1436 ByteString(aBaseURL.getStr(),
1437 RTL_TEXTENCODING_ASCII_US).GetBuffer(),
1438 ByteString(aRelURL.getStr(),
1439 RTL_TEXTENCODING_ASCII_US).GetBuffer(),
1440 ByteString(aRelURLToTest.getStr(),
1441 RTL_TEXTENCODING_ASCII_US).GetBuffer());
1444 if (true) { // #112130#
1445 INetURLObject url1(rtl::OUString::createFromAscii(".uno:abc%3Fdef"));
1446 if (url1.GetProtocol() != INET_PROT_UNO) {
1447 printf("BAD .uno:abc%%3Fdef\n");
1448 bSuccess = false;
1450 if (!rtl::OUString(url1.GetURLPath(INetURLObject::NO_DECODE)).
1451 equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("abc%3Fdef"))) {
1452 printf(
1453 "BAD GetURLPath(.uno:abc%%3Fdef): %s\n",
1454 rtl::OUStringToOString(
1455 url1.GetURLPath(INetURLObject::NO_DECODE),
1456 osl_getThreadTextEncoding()).getStr());
1457 bSuccess = false;
1459 if (url1.HasParam()) {
1460 printf("BAD HasParam(.uno:abc%%3Fdef)\n");
1461 bSuccess = false;
1463 INetURLObject url2(rtl::OUString::createFromAscii(".uno:abc?def?ghi"));
1464 if (url2.GetProtocol() != INET_PROT_UNO) {
1465 printf("BAD .uno:abc?def?ghi\n");
1466 bSuccess = false;
1468 if (!rtl::OUString(url2.GetURLPath(INetURLObject::NO_DECODE)).
1469 equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("abc"))) {
1470 printf(
1471 "BAD GetURLPath(.uno:abc?def?ghi): %s\n",
1472 rtl::OUStringToOString(
1473 url2.GetURLPath(INetURLObject::NO_DECODE),
1474 osl_getThreadTextEncoding()).getStr());
1475 bSuccess = false;
1477 if (!url2.HasParam()) {
1478 printf("BAD HasParam(.uno:abc?def?ghi)\n");
1479 bSuccess = false;
1481 if (!rtl::OUString(url2.GetParam(INetURLObject::NO_DECODE)).
1482 equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("def?ghi"))) {
1483 printf(
1484 "BAD GetURLPath(.uno:abc?def?ghi): %s\n",
1485 rtl::OUStringToOString(
1486 url2.GetParam(INetURLObject::NO_DECODE),
1487 osl_getThreadTextEncoding()).getStr());
1488 bSuccess = false;
1492 if (true) { // #116269#
1493 rtl::OUString url;
1494 INetURLObject urlobj;
1496 url = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("A-b.3:/%2f?x#y"));
1497 urlobj = INetURLObject(url);
1498 bSuccess &= assertEqual(url, INET_PROT_GENERIC_HIERARCHICAL, urlobj.GetProtocol());
1499 bSuccess &= assertEqual(
1500 url, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("a-b.3:/%2F?x#y")),
1501 rtl::OUString(urlobj.GetMainURL(INetURLObject::NO_DECODE)));
1502 bSuccess &= assertEqual(url, false, urlobj.HasUserData());
1503 bSuccess &= assertEqual(url, false, urlobj.hasPassword());
1504 bSuccess &= assertEqual(url, false, urlobj.HasPort());
1505 bSuccess &= assertEqual(
1506 url, rtl::OUString(), rtl::OUString(urlobj.GetHost()));
1507 bSuccess &= assertEqual(
1508 url, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/%2F?x")),
1509 rtl::OUString(urlobj.GetURLPath()));
1510 bSuccess &= assertEqual(url, false, urlobj.HasParam());
1511 bSuccess &= assertEqual(url, true, urlobj.HasMark());
1512 bSuccess &= assertEqual(
1513 url, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("y")),
1514 rtl::OUString(urlobj.GetMark()));
1516 url = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foo:"));
1517 urlobj = INetURLObject(url);
1518 bSuccess &= assertEqual(url, true, urlobj.HasError());
1520 url = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foo:#"));
1521 urlobj = INetURLObject(url);
1522 bSuccess &= assertEqual(url, true, urlobj.HasError());
1524 url = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foo:/"));
1525 urlobj = INetURLObject(url);
1526 bSuccess &= assertEqual(url, INET_PROT_GENERIC_HIERARCHICAL, urlobj.GetProtocol());
1527 bSuccess &= assertEqual(
1528 url, url,
1529 rtl::OUString(urlobj.GetMainURL(INetURLObject::NO_DECODE)));
1531 url = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".foo:/"));
1532 urlobj = INetURLObject(url);
1533 bSuccess &= assertEqual(url, true, urlobj.HasError());
1535 url = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("C:\\bla"));
1536 urlobj = INetURLObject(url);
1537 bSuccess &= assertEqual(url, true, urlobj.HasError());
1539 url = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("C:\\bla"));
1540 urlobj = INetURLObject(url, INET_PROT_FILE);
1541 bSuccess &= assertEqual(url, INET_PROT_FILE, urlobj.GetProtocol());
1542 bSuccess &= assertEqual(
1543 url, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("file:///C:/bla")),
1544 rtl::OUString(urlobj.GetMainURL(INetURLObject::NO_DECODE)));
1546 url = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("LPR:\\bla"));
1547 urlobj = INetURLObject(url);
1548 bSuccess &= assertEqual(url, INET_PROT_GENERIC, urlobj.GetProtocol());
1549 bSuccess &= assertEqual(
1550 url, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("lpr:%5Cbla")),
1551 rtl::OUString(urlobj.GetMainURL(INetURLObject::NO_DECODE)));
1553 url = rtl::OUString(
1554 RTL_CONSTASCII_USTRINGPARAM("private:factory/swriter"));
1555 urlobj = INetURLObject(url);
1556 bSuccess &= assertEqual(
1557 url, INET_PROT_PRIV_SOFFICE, urlobj.GetProtocol());
1558 bSuccess &= assertEqual(
1559 url, url,
1560 rtl::OUString(urlobj.GetMainURL(INetURLObject::NO_DECODE)));
1562 url = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("A-b.3:/%2f?x#y"));
1563 urlobj = INetURLObject(url, INET_PROT_CID);
1564 bSuccess &= assertEqual(url, INET_PROT_GENERIC_HIERARCHICAL, urlobj.GetProtocol());
1565 bSuccess &= assertEqual(
1566 url, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("a-b.3:/%2F?x#y")),
1567 rtl::OUString(urlobj.GetMainURL(INetURLObject::NO_DECODE)));
1569 url = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foo:"));
1570 urlobj = INetURLObject(url, INET_PROT_CID);
1571 bSuccess &= assertEqual(url, INET_PROT_CID, urlobj.GetProtocol());
1572 bSuccess &= assertEqual(
1573 url, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("cid:foo:")),
1574 rtl::OUString(urlobj.GetMainURL(INetURLObject::NO_DECODE)));
1576 url = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foo:#"));
1577 urlobj = INetURLObject(url, INET_PROT_CID);
1578 bSuccess &= assertEqual(url, INET_PROT_CID, urlobj.GetProtocol());
1579 bSuccess &= assertEqual(
1580 url, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("cid:foo:#")),
1581 rtl::OUString(urlobj.GetMainURL(INetURLObject::NO_DECODE)));
1583 url = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foo:/"));
1584 urlobj = INetURLObject(url, INET_PROT_CID);
1585 bSuccess &= assertEqual(url, INET_PROT_GENERIC_HIERARCHICAL, urlobj.GetProtocol());
1586 bSuccess &= assertEqual(
1587 url, url,
1588 rtl::OUString(urlobj.GetMainURL(INetURLObject::NO_DECODE)));
1590 url = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".foo:/"));
1591 urlobj = INetURLObject(url, INET_PROT_CID);
1592 bSuccess &= assertEqual(url, INET_PROT_CID, urlobj.GetProtocol());
1593 bSuccess &= assertEqual(
1594 url, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("cid:.foo:/")),
1595 rtl::OUString(urlobj.GetMainURL(INetURLObject::NO_DECODE)));
1597 url = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("C:\\bla"));
1598 urlobj = INetURLObject(url, INET_PROT_CID);
1599 bSuccess &= assertEqual(url, INET_PROT_FILE, urlobj.GetProtocol());
1600 bSuccess &= assertEqual(
1601 url, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("file:///C:/bla")),
1602 rtl::OUString(urlobj.GetMainURL(INetURLObject::NO_DECODE)));
1604 url = rtl::OUString(
1605 RTL_CONSTASCII_USTRINGPARAM("private:factory/swriter"));
1606 urlobj = INetURLObject(url, INET_PROT_CID);
1607 bSuccess &= assertEqual(
1608 url, INET_PROT_PRIV_SOFFICE, urlobj.GetProtocol());
1609 bSuccess &= assertEqual(
1610 url, url,
1611 rtl::OUString(urlobj.GetMainURL(INetURLObject::NO_DECODE)));
1613 // #i80134#:
1614 url = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\\\\foobar\\%20#"));
1615 urlobj = INetURLObject(url, INET_PROT_FILE);
1616 bSuccess &= assertEqual(url, INET_PROT_FILE, urlobj.GetProtocol());
1617 bSuccess &= assertEqual(
1618 url,
1619 rtl::OUString(
1620 RTL_CONSTASCII_USTRINGPARAM("file://foobar/%2520%23")),
1621 rtl::OUString(urlobj.GetMainURL(INetURLObject::NO_DECODE)));
1622 url = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\\\\foo_bar\\%20#"));
1623 urlobj = INetURLObject(url, INET_PROT_FILE);
1624 bSuccess &= assertEqual(url, INET_PROT_FILE, urlobj.GetProtocol());
1625 bSuccess &= assertEqual(
1626 url,
1627 rtl::OUString(
1628 RTL_CONSTASCII_USTRINGPARAM("file://foo_bar/%2520%23")),
1629 rtl::OUString(urlobj.GetMainURL(INetURLObject::NO_DECODE)));
1632 if (true) {
1633 rtl::OUString path;
1634 path = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/a/b/c"));
1635 bSuccess &= assertEqual(
1636 path,
1637 rtl::OUString(
1638 INetURLObject(path, INetURLObject::FSYS_DETECT).GetMainURL(
1639 INetURLObject::NO_DECODE)),
1640 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("file:///a/b/c")));
1641 path = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("a\\b\\c"));
1642 bSuccess &= assertEqual(
1643 path,
1644 rtl::OUString(
1645 INetURLObject(path, INetURLObject::FSYS_DETECT).GetMainURL(
1646 INetURLObject::NO_DECODE)),
1647 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("file:///a/b/c")));
1648 path = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("a:b:c"));
1649 bSuccess &= assertEqual(
1650 path, INetURLObject(path, INetURLObject::FSYS_DETECT).HasError(),
1651 true);
1652 bSuccess &= assertEqual(
1653 path,
1654 rtl::OUString(
1655 INetURLObject(
1656 path,
1657 INetURLObject::FSysStyle(
1658 INetURLObject::FSYS_DETECT | INetURLObject::FSYS_MAC)).
1659 GetMainURL(INetURLObject::NO_DECODE)),
1660 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("file:///a/b/c")));
1661 rtl::OUString url;
1662 url = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/a/b/c"));
1663 bSuccess &= assertEqual(
1664 url,
1665 rtl::OUString(
1666 INetURLObject(url, INET_PROT_HTTP).GetMainURL(
1667 INetURLObject::NO_DECODE)),
1668 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("file:///a/b/c")));
1669 url = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("a:\\b\\c"));
1670 bSuccess &= assertEqual(
1671 url,
1672 rtl::OUString(
1673 INetURLObject(url, INET_PROT_HTTP).GetMainURL(
1674 INetURLObject::NO_DECODE)),
1675 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("file:///a:/b/c")));
1676 url = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("a:b:c"));
1677 bSuccess &= assertEqual(
1678 url, INetURLObject(url, INET_PROT_HTTP).HasError(), true);
1679 bSuccess &= assertEqual(
1680 url,
1681 (INetURLObject(
1682 url, INET_PROT_HTTP, INetURLObject::WAS_ENCODED,
1683 RTL_TEXTENCODING_UTF8,
1684 INetURLObject::FSysStyle(
1685 INetURLObject::FSYS_DETECT | INetURLObject::FSYS_MAC)).
1686 HasError()),
1687 true);
1690 bSuccess &= test_getSegmentCount("mailto:a@b", false, 0);
1691 bSuccess &= test_getSegmentCount("vnd.sun.star.expand:$PREFIX", false, 1);
1692 bSuccess &= test_getSegmentCount("vnd.sun.star.expand:$PREFIX", true, 1);
1693 bSuccess &= test_getSegmentCount("vnd.sun.star.expand:$PREFIX/", false, 2);
1694 bSuccess &= test_getSegmentCount("vnd.sun.star.expand:$PREFIX/", true, 1);
1695 bSuccess &= test_getSegmentCount(
1696 "vnd.sun.star.expand:$PREFIX/foo", false, 2);
1697 bSuccess &= test_getSegmentCount(
1698 "vnd.sun.star.expand:$PREFIX/foo", true, 2);
1699 bSuccess &= test_getSegmentCount("file:///", false, 1);
1700 bSuccess &= test_getSegmentCount("file:///", true, 0);
1701 bSuccess &= test_getSegmentCount("file:///foo", false, 1);
1702 bSuccess &= test_getSegmentCount("file:///foo", true, 1);
1704 bSuccess &= test_insertName(
1705 "mailto:a@b", "foo", false, 0, false, false, "mailto:a@b");
1706 bSuccess &= test_insertName(
1707 "vnd.sun.star.expand:$PREFIX", "foo", false, 0, false, true,
1708 "vnd.sun.star.expand:%2Ffoo/$PREFIX");
1709 bSuccess &= test_insertName(
1710 "vnd.sun.star.expand:$PREFIX", "foo", false, 0, true, true,
1711 "vnd.sun.star.expand:%2Ffoo/$PREFIX");
1712 bSuccess &= test_insertName(
1713 "vnd.sun.star.expand:$PREFIX", "foo", true, 0, false, true,
1714 "vnd.sun.star.expand:%2Ffoo/$PREFIX");
1715 bSuccess &= test_insertName(
1716 "vnd.sun.star.expand:$PREFIX", "foo", true, 0, true, true,
1717 "vnd.sun.star.expand:%2Ffoo/$PREFIX");
1718 bSuccess &= test_insertName(
1719 "vnd.sun.star.expand:$PREFIX", "foo", false, 1, false, true,
1720 "vnd.sun.star.expand:$PREFIX/foo");
1721 bSuccess &= test_insertName(
1722 "vnd.sun.star.expand:$PREFIX", "foo", false, 1, true, true,
1723 "vnd.sun.star.expand:$PREFIX/foo");
1724 bSuccess &= test_insertName(
1725 "vnd.sun.star.expand:$PREFIX", "foo", true, 1, false, true,
1726 "vnd.sun.star.expand:$PREFIX/foo/");
1727 bSuccess &= test_insertName(
1728 "vnd.sun.star.expand:$PREFIX", "foo", true, 1, true, true,
1729 "vnd.sun.star.expand:$PREFIX/foo/");
1730 bSuccess &= test_insertName(
1731 "vnd.sun.star.expand:$PREFIX", "foo", false,
1732 INetURLObject::LAST_SEGMENT, false, true,
1733 "vnd.sun.star.expand:$PREFIX/foo");
1734 bSuccess &= test_insertName(
1735 "vnd.sun.star.expand:$PREFIX", "foo", false,
1736 INetURLObject::LAST_SEGMENT, true, true,
1737 "vnd.sun.star.expand:$PREFIX/foo");
1738 bSuccess &= test_insertName(
1739 "vnd.sun.star.expand:$PREFIX", "foo", true,
1740 INetURLObject::LAST_SEGMENT, false, true,
1741 "vnd.sun.star.expand:$PREFIX/foo/");
1742 bSuccess &= test_insertName(
1743 "vnd.sun.star.expand:$PREFIX", "foo", true,
1744 INetURLObject::LAST_SEGMENT, true, true,
1745 "vnd.sun.star.expand:$PREFIX/foo/");
1746 bSuccess &= test_insertName(
1747 "vnd.sun.star.expand:$PREFIX/", "foo", false,
1748 1, false, true,
1749 "vnd.sun.star.expand:$PREFIX/foo/");
1750 bSuccess &= test_insertName(
1751 "vnd.sun.star.expand:$PREFIX/", "foo", false,
1752 1, true, true,
1753 "vnd.sun.star.expand:$PREFIX/foo");
1754 bSuccess &= test_insertName(
1755 "vnd.sun.star.expand:$PREFIX/", "foo", true,
1756 1, false, true,
1757 "vnd.sun.star.expand:$PREFIX/foo/");
1758 bSuccess &= test_insertName(
1759 "vnd.sun.star.expand:$PREFIX/", "foo", true,
1760 1, true, true,
1761 "vnd.sun.star.expand:$PREFIX/foo/");
1762 bSuccess &= test_insertName(
1763 "vnd.sun.star.expand:$PREFIX/", "foo", false,
1764 INetURLObject::LAST_SEGMENT, false, true,
1765 "vnd.sun.star.expand:$PREFIX//foo");
1766 bSuccess &= test_insertName(
1767 "vnd.sun.star.expand:$PREFIX/", "foo", false,
1768 INetURLObject::LAST_SEGMENT, true, true,
1769 "vnd.sun.star.expand:$PREFIX/foo");
1770 bSuccess &= test_insertName(
1771 "vnd.sun.star.expand:$PREFIX/", "foo", true,
1772 INetURLObject::LAST_SEGMENT, false, true,
1773 "vnd.sun.star.expand:$PREFIX//foo/");
1774 bSuccess &= test_insertName(
1775 "vnd.sun.star.expand:$PREFIX/", "foo", true,
1776 INetURLObject::LAST_SEGMENT, true, true,
1777 "vnd.sun.star.expand:$PREFIX/foo/");
1778 bSuccess &= test_insertName(
1779 "file:///", "foo", false, 0, false, true, "file:///foo/");
1780 bSuccess &= test_insertName(
1781 "file:///", "foo", false, 0, true, true, "file:///foo");
1782 bSuccess &= test_insertName(
1783 "file:///", "foo", true, 0, false, true, "file:///foo/");
1784 bSuccess &= test_insertName(
1785 "file:///", "foo", true, 0, true, true, "file:///foo/");
1786 bSuccess &= test_insertName(
1787 "file:///bar", "foo", false, 0, false, true, "file:///foo/bar");
1788 bSuccess &= test_insertName(
1789 "file:///bar", "foo", false, 0, true, true, "file:///foo/bar");
1790 bSuccess &= test_insertName(
1791 "file:///bar", "foo", true, 0, false, true, "file:///foo/bar");
1792 bSuccess &= test_insertName(
1793 "file:///bar", "foo", true, 0, true, true, "file:///foo/bar");
1795 bSuccess &= test_removeSegment("mailto:a@b", 0, false, false, "mailto:a@b");
1796 bSuccess &= test_removeSegment(
1797 "vnd.sun.star.expand:$PREFIX", 0, false, false,
1798 "vnd.sun.star.expand:$PREFIX");
1799 bSuccess &= test_removeSegment(
1800 "vnd.sun.star.expand:$PREFIX", 0, true, true,
1801 "vnd.sun.star.expand:%2F");
1802 bSuccess &= test_removeSegment(
1803 "vnd.sun.star.expand:$PREFIX", 1, false, false,
1804 "vnd.sun.star.expand:$PREFIX");
1805 bSuccess &= test_removeSegment(
1806 "vnd.sun.star.expand:$PREFIX", 1, true, false,
1807 "vnd.sun.star.expand:$PREFIX");
1808 bSuccess &= test_removeSegment(
1809 "vnd.sun.star.expand:$PREFIX", 2, false, false,
1810 "vnd.sun.star.expand:$PREFIX");
1811 bSuccess &= test_removeSegment(
1812 "vnd.sun.star.expand:$PREFIX", 2, true, false,
1813 "vnd.sun.star.expand:$PREFIX");
1814 bSuccess &= test_removeSegment(
1815 "vnd.sun.star.expand:$PREFIX", INetURLObject::LAST_SEGMENT, false,
1816 false, "vnd.sun.star.expand:$PREFIX");
1817 bSuccess &= test_removeSegment(
1818 "vnd.sun.star.expand:$PREFIX", INetURLObject::LAST_SEGMENT, true, true,
1819 "vnd.sun.star.expand:%2F");
1820 bSuccess &= test_removeSegment(
1821 "vnd.sun.star.expand:$PREFIX/", 0, false, true,
1822 "vnd.sun.star.expand:%2F");
1823 bSuccess &= test_removeSegment(
1824 "vnd.sun.star.expand:$PREFIX/", 0, true, true,
1825 "vnd.sun.star.expand:%2F");
1826 bSuccess &= test_removeSegment(
1827 "vnd.sun.star.expand:$PREFIX/", 1, false, true,
1828 "vnd.sun.star.expand:$PREFIX");
1829 bSuccess &= test_removeSegment(
1830 "vnd.sun.star.expand:$PREFIX/", 1, true, true,
1831 "vnd.sun.star.expand:$PREFIX/");
1832 bSuccess &= test_removeSegment(
1833 "vnd.sun.star.expand:$PREFIX/", 2, false, false,
1834 "vnd.sun.star.expand:$PREFIX/");
1835 bSuccess &= test_removeSegment(
1836 "vnd.sun.star.expand:$PREFIX/", 2, true, false,
1837 "vnd.sun.star.expand:$PREFIX/");
1838 bSuccess &= test_removeSegment(
1839 "vnd.sun.star.expand:$PREFIX/", INetURLObject::LAST_SEGMENT, false,
1840 true, "vnd.sun.star.expand:$PREFIX");
1841 bSuccess &= test_removeSegment(
1842 "vnd.sun.star.expand:$PREFIX/", INetURLObject::LAST_SEGMENT, true,
1843 true, "vnd.sun.star.expand:%2F");
1844 bSuccess &= test_removeSegment("file:///", 0, false, true, "file:///");
1845 bSuccess &= test_removeSegment("file:///", 0, true, true, "file:///");
1846 bSuccess &= test_removeSegment("file:///", 1, false, false, "file:///");
1847 bSuccess &= test_removeSegment("file:///", 1, true, false, "file:///");
1848 bSuccess &= test_removeSegment("file:///", 2, false, false, "file:///");
1849 bSuccess &= test_removeSegment("file:///", 2, true, false, "file:///");
1850 bSuccess &= test_removeSegment(
1851 "file:///", INetURLObject::LAST_SEGMENT, false, true, "file:///");
1852 bSuccess &= test_removeSegment(
1853 "file:///", INetURLObject::LAST_SEGMENT, true, false, "file:///");
1854 bSuccess &= test_removeSegment("file:///foo", 0, false, true, "file:///");
1855 bSuccess &= test_removeSegment("file:///foo", 0, true, true, "file:///");
1856 bSuccess &= test_removeSegment(
1857 "file:///foo", 1, false, false, "file:///foo");
1858 bSuccess &= test_removeSegment(
1859 "file:///foo", 1, true, false, "file:///foo");
1860 bSuccess &= test_removeSegment(
1861 "file:///foo", 2, false, false, "file:///foo");
1862 bSuccess &= test_removeSegment(
1863 "file:///foo", 2, true, false, "file:///foo");
1864 bSuccess &= test_removeSegment(
1865 "file:///foo", INetURLObject::LAST_SEGMENT, false, true, "file:///");
1866 bSuccess &= test_removeSegment(
1867 "file:///foo", INetURLObject::LAST_SEGMENT, true, true, "file:///");
1868 bSuccess &= test_removeSegment("file:///foo/", 0, false, true, "file:///");
1869 bSuccess &= test_removeSegment("file:///foo/", 0, true, true, "file:///");
1870 bSuccess &= test_removeSegment(
1871 "file:///foo/", 1, false, true, "file:///foo");
1872 bSuccess &= test_removeSegment(
1873 "file:///foo/", 1, true, true, "file:///foo/");
1874 bSuccess &= test_removeSegment(
1875 "file:///foo/", 2, false, false, "file:///foo/");
1876 bSuccess &= test_removeSegment(
1877 "file:///foo/", 2, true, false, "file:///foo/");
1878 bSuccess &= test_removeSegment(
1879 "file:///foo/", INetURLObject::LAST_SEGMENT, false, true,
1880 "file:///foo");
1881 bSuccess &= test_removeSegment(
1882 "file:///foo/", INetURLObject::LAST_SEGMENT, true, true, "file:///");
1884 return bSuccess ? EXIT_SUCCESS : EXIT_FAILURE;