xref: /trunk/main/stoc/test/uriproc/test_uriproc.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_stoc.hxx"
30 
31 #include "com/sun/star/lang/XComponent.hpp"
32 #include "com/sun/star/lang/XMultiComponentFactory.hpp"
33 #include "com/sun/star/uno/Reference.hxx"
34 #include "com/sun/star/uno/XComponentContext.hpp"
35 #include "com/sun/star/uri/ExternalUriReferenceTranslator.hpp"
36 #include "com/sun/star/uri/UriReferenceFactory.hpp"
37 #include "com/sun/star/uri/VndSunStarPkgUrlReferenceFactory.hpp"
38 #include "com/sun/star/uri/XExternalUriReferenceTranslator.hpp"
39 #include "com/sun/star/uri/XUriReference.hpp"
40 #include "com/sun/star/uri/XUriReferenceFactory.hpp"
41 #include "com/sun/star/uri/XVndSunStarExpandUrlReference.hpp"
42 #include "com/sun/star/uri/XVndSunStarPkgUrlReferenceFactory.hpp"
43 #include "com/sun/star/uri/XVndSunStarScriptUrlReference.hpp"
44 #include "com/sun/star/util/XMacroExpander.hpp"
45 #include "cppuhelper/bootstrap.hxx"
46 #include "cppunit/TestAssert.h"
47 #include "cppunit/TestFixture.h"
48 #include "cppunit/extensions/HelperMacros.h"
49 #include "cppunit/plugin/TestPlugIn.h"
50 #include "osl/diagnose.h"
51 #include "rtl/string.h"
52 #include "rtl/string.hxx"
53 #include "rtl/textenc.h"
54 #include "rtl/ustrbuf.hxx"
55 #include "rtl/ustring.hxx"
56 #include "sal/types.h"
57 
58 #include <cstdlib>
59 
60 namespace css = com::sun::star;
61 
62 namespace {
63 
64 #define TEST_ASSERT_EQUAL(token1, token2, token3, expected, actual) \
65     CPPUNIT_ASSERT_MESSAGE( \
66         createTestAssertEqualMessage( \
67             token1, token2, token3, #expected, #actual, expected, actual). \
68             getStr(), \
69         (actual) == (expected))
70 
71 template< typename T > void append(
72     rtl::OUStringBuffer & buffer, T const & value)
73 {
74     buffer.append(value);
75 }
76 
77 template<> void append(rtl::OUStringBuffer & buffer, bool const & value) {
78     buffer.append(static_cast< sal_Bool >(value));
79 }
80 
81 template<> void append(rtl::OUStringBuffer & buffer, std::size_t const & value)
82 {
83     buffer.append(static_cast< sal_Int32 >(value));
84 }
85 
86 template<> void append(rtl::OUStringBuffer & buffer, char const * const & value)
87 {
88     buffer.appendAscii(value);
89 }
90 
91 template< typename T1, typename T2, typename T3, typename T4 >
92 rtl::OString createTestAssertEqualMessage(
93     char const * token1, T1 const & token2, T2 const & token3,
94     char const * expectedExpr, char const * actualExpr, T3 const & expected,
95     T4 const & actual)
96 {
97     rtl::OUStringBuffer buf;
98     buf.appendAscii(token1);
99     buf.append(static_cast< sal_Unicode >('|'));
100     append(buf, token2);
101     buf.append(static_cast< sal_Unicode >('|'));
102     append(buf, token3);
103     buf.appendAscii(RTL_CONSTASCII_STRINGPARAM(": TEST_ASSERT_EQUAL("));
104     buf.appendAscii(expectedExpr);
105     buf.appendAscii(RTL_CONSTASCII_STRINGPARAM(", "));
106     buf.appendAscii(actualExpr);
107     buf.appendAscii(RTL_CONSTASCII_STRINGPARAM("): <"));
108     append(buf, expected);
109     buf.appendAscii(RTL_CONSTASCII_STRINGPARAM("> != <"));
110     append(buf, actual);
111     buf.append(static_cast< sal_Unicode >('>'));
112     return rtl::OUStringToOString(
113         buf.makeStringAndClear(), RTL_TEXTENCODING_ASCII_US);
114 }
115 
116 class Test: public CppUnit::TestFixture {
117 public:
118     virtual void setUp();
119 
120     virtual void tearDown();
121 
122     void testParse();
123 
124     void testMakeAbsolute();
125 
126     void testMakeRelative();
127 
128     void testVndSunStarExpand();
129 
130     void testVndSunStarScript();
131 
132     void testTranslator();
133 
134     void testPkgUrlFactory();
135 
136     CPPUNIT_TEST_SUITE(Test);
137     CPPUNIT_TEST(testParse);
138     CPPUNIT_TEST(testMakeAbsolute);
139     CPPUNIT_TEST(testMakeRelative);
140     CPPUNIT_TEST(testVndSunStarExpand);
141     CPPUNIT_TEST(testVndSunStarScript);
142     CPPUNIT_TEST(testTranslator);
143     CPPUNIT_TEST(testPkgUrlFactory);
144     CPPUNIT_TEST_SUITE_END();
145 
146 private:
147     css::uno::Reference< css::uno::XComponentContext > m_context;
148     css::uno::Reference< css::uri::XUriReferenceFactory > m_uriFactory;
149 };
150 
151 void Test::setUp() {
152     m_context = cppu::defaultBootstrap_InitialComponentContext();
153     m_uriFactory = css::uri::UriReferenceFactory::create(m_context);
154 }
155 
156 void Test::tearDown() {
157     m_uriFactory.clear();
158     css::uno::Reference< css::lang::XComponent >(
159         m_context, css::uno::UNO_QUERY_THROW)->dispose();
160 }
161 
162 void Test::testParse() {
163     struct Data {
164         char const * uriReference;
165         char const * scheme;
166         char const * schemeSpecificPart;
167         bool isHierarchical;
168         char const * authority;
169         char const * path;
170         bool hasRelativePath;
171         sal_Int32 pathSegmentCount;
172         char const * pathSegment0;
173         char const * pathSegment1;
174         char const * pathSegment2;
175         char const * pathSegment3;
176         char const * pathSegment4;
177         char const * query;
178         char const * fragment;
179     };
180     Data data[] = {
181         { "", 0, "", true, 0,
182           "", true, 0, "", "", "", "", "", 0, 0 },
183         { "scheme:", 0, 0, false, 0,
184           0, false, 0, 0, 0, 0, 0, 0, 0, 0 },
185         { "scheme:/", "scheme", "/", true, 0,
186           "/", false, 1, "", "", "", "", "", 0, 0 },
187         { "scheme://", "scheme", "//", true, "",
188           "", false, 0, "", "", "", "", "", 0, 0 },
189         { "scheme:///", "scheme", "///", true, "",
190           "/", false, 1, "", "", "", "", "", 0, 0 },
191         { "scheme:////", "scheme", "////", true, "",
192           "//", false, 2, "", "", "", "", "", 0, 0 },
193         { "scheme:////", "scheme", "////", true, "",
194           "//", false, 2, "", "", "", "", "", 0, 0 },
195         { "scheme:#", 0, 0, false, 0,
196           0, false, 0, 0, 0, 0, 0, 0, 0, 0 },
197         { "scheme:?", "scheme", "?", false, 0,
198           "?", false, 0, "", "", "", "", "", 0, 0 },
199         { "/", 0, "/", true, 0,
200           "/", false, 1, "", "", "", "", "", 0, 0 },
201         { "//", 0, "//", true, "",
202           "", false, 0, "", "", "", "", "", 0, 0 },
203         { "///", 0, "///", true, "",
204           "/", false, 1, "", "", "", "", "", 0, 0 },
205         { "////", 0, "////", true, "",
206           "//", false, 2, "", "", "", "", "", 0, 0 } };
207     for (std::size_t i = 0; i < sizeof data / sizeof data[0]; ++i) {
208         css::uno::Reference< css::uri::XUriReference > uriRef(
209             m_uriFactory->parse(
210                 rtl::OUString::createFromAscii(data[i].uriReference)));
211         CPPUNIT_ASSERT(uriRef.is() == (data[i].schemeSpecificPart != 0));
212         if (uriRef.is()) {
213             TEST_ASSERT_EQUAL(
214                 "testParse", i, data[i].uriReference,
215                 rtl::OUString::createFromAscii(data[i].uriReference),
216                 uriRef->getUriReference());
217             TEST_ASSERT_EQUAL(
218                 "testParse", i, data[i].uriReference,
219                 data[i].scheme != 0, uriRef->isAbsolute());
220             TEST_ASSERT_EQUAL(
221                 "testParse", i, data[i].uriReference,
222                 rtl::OUString::createFromAscii(
223                     data[i].scheme == 0 ? "" : data[i].scheme),
224                 uriRef->getScheme());
225             TEST_ASSERT_EQUAL(
226                 "testParse", i, data[i].uriReference,
227                 rtl::OUString::createFromAscii(data[i].schemeSpecificPart),
228                 uriRef->getSchemeSpecificPart());
229             TEST_ASSERT_EQUAL(
230                 "testParse", i, data[i].uriReference,
231                 data[i].isHierarchical,
232                 static_cast< bool >(uriRef->isHierarchical()));
233             TEST_ASSERT_EQUAL(
234                 "testParse", i, data[i].uriReference,
235                 data[i].authority != 0, uriRef->hasAuthority());
236             TEST_ASSERT_EQUAL(
237                 "testParse", i, data[i].uriReference,
238                 rtl::OUString::createFromAscii(
239                     data[i].authority == 0 ? "" : data[i].authority),
240                 uriRef->getAuthority());
241             TEST_ASSERT_EQUAL(
242                 "testParse", i, data[i].uriReference,
243                 rtl::OUString::createFromAscii(data[i].path),
244                 uriRef->getPath());
245             TEST_ASSERT_EQUAL(
246                 "testParse", i, data[i].uriReference,
247                 data[i].hasRelativePath,
248                 static_cast< bool >(uriRef->hasRelativePath()));
249             TEST_ASSERT_EQUAL(
250                 "testParse", i, data[i].uriReference,
251                 data[i].pathSegmentCount, uriRef->getPathSegmentCount());
252             TEST_ASSERT_EQUAL(
253                 "testParse", i, data[i].uriReference,
254                 rtl::OUString::createFromAscii(""), uriRef->getPathSegment(-1));
255             TEST_ASSERT_EQUAL(
256                 "testParse", i, data[i].uriReference,
257                 rtl::OUString::createFromAscii(data[i].pathSegment0),
258                 uriRef->getPathSegment(0));
259             TEST_ASSERT_EQUAL(
260                 "testParse", i, data[i].uriReference,
261                 rtl::OUString::createFromAscii(data[i].pathSegment1),
262                 uriRef->getPathSegment(1));
263             TEST_ASSERT_EQUAL(
264                 "testParse", i, data[i].uriReference,
265                 rtl::OUString::createFromAscii(data[i].pathSegment2),
266                 uriRef->getPathSegment(2));
267             TEST_ASSERT_EQUAL(
268                 "testParse", i, data[i].uriReference,
269                 rtl::OUString::createFromAscii(data[i].pathSegment3),
270                 uriRef->getPathSegment(3));
271             TEST_ASSERT_EQUAL(
272                 "testParse", i, data[i].uriReference,
273                 rtl::OUString::createFromAscii(data[i].pathSegment4),
274                 uriRef->getPathSegment(4));
275             TEST_ASSERT_EQUAL(
276                 "testParse", i, data[i].uriReference,
277                 rtl::OUString::createFromAscii(""), uriRef->getPathSegment(5));
278             TEST_ASSERT_EQUAL(
279                 "testParse", i, data[i].uriReference,
280                 data[i].query != 0, uriRef->hasQuery());
281             TEST_ASSERT_EQUAL(
282                 "testParse", i, data[i].uriReference,
283                 rtl::OUString::createFromAscii(
284                     data[i].query == 0 ? "" : data[i].query),
285                 uriRef->getQuery());
286             TEST_ASSERT_EQUAL(
287                 "testParse", i, data[i].uriReference,
288                 data[i].fragment != 0, uriRef->hasFragment());
289             TEST_ASSERT_EQUAL(
290                 "testParse", i, data[i].uriReference,
291                 rtl::OUString::createFromAscii(
292                     data[i].fragment == 0 ? "" : data[i].fragment),
293                 uriRef->getFragment());
294         }
295     }
296 }
297 
298 void Test::testMakeAbsolute() {
299     struct Data {
300         char const * baseUriReference;
301         char const * uriReference;
302         bool processSpecialBaseSegments;
303         css::uri::RelativeUriExcessParentSegments excessParentSegments;
304         char const * absolute;
305     };
306     Data data[] = {
307         // The following tests are taken from RFC 2396, Appendix C:
308         { "http://a/b/c/d;p?q", "g:h", true,
309           css::uri::RelativeUriExcessParentSegments_ERROR, "g:h" },
310         { "http://a/b/c/d;p?q", "g", true,
311           css::uri::RelativeUriExcessParentSegments_ERROR, "http://a/b/c/g" },
312         { "http://a/b/c/d;p?q", "./g", true,
313           css::uri::RelativeUriExcessParentSegments_ERROR, "http://a/b/c/g" },
314         { "http://a/b/c/d;p?q", "g/", true,
315           css::uri::RelativeUriExcessParentSegments_ERROR, "http://a/b/c/g/" },
316         { "http://a/b/c/d;p?q", "//g", true,
317           css::uri::RelativeUriExcessParentSegments_ERROR, "http://g" },
318         { "http://a/b/c/d;p?q", "?y", true,
319           css::uri::RelativeUriExcessParentSegments_ERROR, "http://a/b/c/?y" },
320         { "http://a/b/c/d;p?q", "g?y", true,
321           css::uri::RelativeUriExcessParentSegments_ERROR,
322           "http://a/b/c/g?y" },
323         { "http://a/b/c/d;p?q", "#s", true,
324           css::uri::RelativeUriExcessParentSegments_ERROR,
325           "http://a/b/c/d;p?q#s" },
326         { "http://a/b/c/d;p?q", "g#s", true,
327           css::uri::RelativeUriExcessParentSegments_ERROR,
328           "http://a/b/c/g#s" },
329         { "http://a/b/c/d;p?q", "g?y#s", true,
330           css::uri::RelativeUriExcessParentSegments_ERROR,
331           "http://a/b/c/g?y#s" },
332         { "http://a/b/c/d;p?q", ";x", true,
333           css::uri::RelativeUriExcessParentSegments_ERROR, "http://a/b/c/;x" },
334         { "http://a/b/c/d;p?q", "g;x", true,
335           css::uri::RelativeUriExcessParentSegments_ERROR,
336           "http://a/b/c/g;x" },
337         { "http://a/b/c/d;p?q", "g;x?y#s", true,
338           css::uri::RelativeUriExcessParentSegments_ERROR,
339           "http://a/b/c/g;x?y#s" },
340         { "http://a/b/c/d;p?q", ".", true,
341           css::uri::RelativeUriExcessParentSegments_ERROR, "http://a/b/c/" },
342         { "http://a/b/c/d;p?q", "./", true,
343           css::uri::RelativeUriExcessParentSegments_ERROR, "http://a/b/c/" },
344         { "http://a/b/c/d;p?q", "..", true,
345           css::uri::RelativeUriExcessParentSegments_ERROR, "http://a/b/" },
346         { "http://a/b/c/d;p?q", "../", true,
347           css::uri::RelativeUriExcessParentSegments_ERROR, "http://a/b/" },
348         { "http://a/b/c/d;p?q", "../g", true,
349           css::uri::RelativeUriExcessParentSegments_ERROR, "http://a/b/g" },
350         { "http://a/b/c/d;p?q", "../..", true,
351           css::uri::RelativeUriExcessParentSegments_ERROR, "http://a/" },
352         { "http://a/b/c/d;p?q", "../../", true,
353           css::uri::RelativeUriExcessParentSegments_ERROR, "http://a/" },
354         { "http://a/b/c/d;p?q", "../../g", true,
355           css::uri::RelativeUriExcessParentSegments_ERROR, "http://a/g" },
356         { "http://a/b/c/d;p?q", "", true,
357           css::uri::RelativeUriExcessParentSegments_ERROR,
358           "http://a/b/c/d;p?q" },
359         { "http://a/b/c/d;p?q", "../../../g", true,
360           css::uri::RelativeUriExcessParentSegments_ERROR, 0 },
361         { "http://a/b/c/d;p?q", "../../../g", true,
362           css::uri::RelativeUriExcessParentSegments_RETAIN, "http://a/../g" },
363         { "http://a/b/c/d;p?q", "../../../g", true,
364           css::uri::RelativeUriExcessParentSegments_REMOVE, "http://a/g" },
365         { "http://a/b/c/d;p?q", "../../../../g", true,
366           css::uri::RelativeUriExcessParentSegments_ERROR, 0 },
367         { "http://a/b/c/d;p?q", "../../../../g", true,
368           css::uri::RelativeUriExcessParentSegments_RETAIN,
369           "http://a/../../g" },
370         { "http://a/b/c/d;p?q", "../../../../g", true,
371           css::uri::RelativeUriExcessParentSegments_REMOVE, "http://a/g" },
372         { "http://a/b/c/d;p?q", "/./g", true,
373           css::uri::RelativeUriExcessParentSegments_ERROR, "http://a/./g" },
374         { "http://a/b/c/d;p?q", "/../g", true,
375           css::uri::RelativeUriExcessParentSegments_ERROR, "http://a/../g" },
376         { "http://a/b/c/d;p?q", "g.", true,
377           css::uri::RelativeUriExcessParentSegments_ERROR, "http://a/b/c/g." },
378         { "http://a/b/c/d;p?q", ".g", true,
379           css::uri::RelativeUriExcessParentSegments_ERROR, "http://a/b/c/.g" },
380         { "http://a/b/c/d;p?q", "g..", true,
381           css::uri::RelativeUriExcessParentSegments_ERROR,
382           "http://a/b/c/g.." },
383         { "http://a/b/c/d;p?q", "..g", true,
384           css::uri::RelativeUriExcessParentSegments_ERROR,
385           "http://a/b/c/..g" },
386         { "http://a/b/c/d;p?q", "./../g", true,
387           css::uri::RelativeUriExcessParentSegments_ERROR, "http://a/b/g" },
388         { "http://a/b/c/d;p?q", "./g/.", true,
389           css::uri::RelativeUriExcessParentSegments_ERROR, "http://a/b/c/g/" },
390         { "http://a/b/c/d;p?q", "g/./h", true,
391           css::uri::RelativeUriExcessParentSegments_ERROR,
392           "http://a/b/c/g/h" },
393         { "http://a/b/c/d;p?q", "g/../h", true,
394           css::uri::RelativeUriExcessParentSegments_ERROR, "http://a/b/c/h" },
395         { "http://a/b/c/d;p?q", "g;x=1/./y", true,
396           css::uri::RelativeUriExcessParentSegments_ERROR,
397           "http://a/b/c/g;x=1/y" },
398         { "http://a/b/c/d;p?q", "g;x=1/../y", true,
399           css::uri::RelativeUriExcessParentSegments_ERROR, "http://a/b/c/y" },
400         { "http://a/b/c/d;p?q", "g?y/./x", true,
401           css::uri::RelativeUriExcessParentSegments_ERROR,
402           "http://a/b/c/g?y/./x" },
403         { "http://a/b/c/d;p?q", "g?y/../x", true,
404           css::uri::RelativeUriExcessParentSegments_ERROR,
405           "http://a/b/c/g?y/../x" },
406         { "http://a/b/c/d;p?q", "g#s/./x", true,
407           css::uri::RelativeUriExcessParentSegments_ERROR,
408           "http://a/b/c/g#s/./x" },
409         { "http://a/b/c/d;p?q", "g#s/../x", true,
410           css::uri::RelativeUriExcessParentSegments_ERROR,
411           "http://a/b/c/g#s/../x" },
412         { "http.://a/b/c/d;p?q", "http.:g", true,
413           css::uri::RelativeUriExcessParentSegments_ERROR, "http.:g" },
414 
415         { "scheme://a", "", true,
416           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a" },
417         { "scheme://a", ".", true,
418           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a" },
419         { "scheme://a", "./", true,
420           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a" },
421         { "scheme://a", "./.", true,
422           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a" },
423         { "scheme://a", "././", true,
424           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a" },
425         { "scheme://a", "././.", true,
426           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a" },
427         { "scheme://a", "x/..", true,
428           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a" },
429         { "scheme://a", "x/../", true,
430           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a" },
431         { "scheme://a", "x/../.", true,
432           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a" },
433         { "scheme://a", "x/.././", true,
434           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a" },
435         { "scheme://a", "x/.././.", true,
436           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a" },
437         { "scheme://a", "x/../././", true,
438           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a" },
439         { "scheme://a", "x/../././.", true,
440           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a" },
441         { "scheme://a", "./x/..", true,
442           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a" },
443         { "scheme://a", "././x/..", true,
444           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a" },
445         { "scheme://a", "./././x/..", true,
446           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a" },
447         { "scheme://a", "./x/../.", true,
448           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a" },
449         { "scheme://a", "./x/.././", true,
450           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a" },
451         { "scheme://a", "././x/.././.", true,
452           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a" },
453         { "scheme://a", "././x/../././", true,
454           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a" },
455         { "scheme://a", "./././x/../././.", true,
456           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a" },
457 
458         { "scheme://a/", "", true,
459           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/" },
460         { "scheme://a/", ".", true,
461           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/" },
462         { "scheme://a/", "./", true,
463           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/" },
464         { "scheme://a/", "./.", true,
465           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/" },
466         { "scheme://a/", "././", true,
467           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/" },
468         { "scheme://a/", "././.", true,
469           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/" },
470         { "scheme://a/", "x/..", true,
471           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/" },
472         { "scheme://a/", "x/../", true,
473           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/" },
474         { "scheme://a/", "x/../.", true,
475           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/" },
476         { "scheme://a/", "x/.././", true,
477           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/" },
478         { "scheme://a/", "x/.././.", true,
479           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/" },
480         { "scheme://a/", "x/../././", true,
481           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/" },
482         { "scheme://a/", "x/../././.", true,
483           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/" },
484         { "scheme://a/", "./x/..", true,
485           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/" },
486         { "scheme://a/", "././x/..", true,
487           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/" },
488         { "scheme://a/", "./././x/..", true,
489           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/" },
490         { "scheme://a/", "./x/../.", true,
491           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/" },
492         { "scheme://a/", "./x/.././", true,
493           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/" },
494         { "scheme://a/", "././x/.././.", true,
495           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/" },
496         { "scheme://a/", "././x/../././", true,
497           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/" },
498         { "scheme://a/", "./././x/../././.", true,
499           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/" },
500 
501         { "scheme://a/b", "", true,
502           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/b" },
503         { "scheme://a/b", ".", true,
504           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/" },
505         { "scheme://a/b", "./", true,
506           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/" },
507         { "scheme://a/b", "./.", true,
508           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/" },
509         { "scheme://a/b", "././", true,
510           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/" },
511         { "scheme://a/b", "././.", true,
512           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/" },
513         { "scheme://a/b", "x/..", true,
514           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/" },
515         { "scheme://a/b", "x/../", true,
516           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/" },
517         { "scheme://a/b", "x/../.", true,
518           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/" },
519         { "scheme://a/b", "x/.././", true,
520           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/" },
521         { "scheme://a/b", "x/.././.", true,
522           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/" },
523         { "scheme://a/b", "x/../././", true,
524           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/" },
525         { "scheme://a/b", "x/../././.", true,
526           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/" },
527         { "scheme://a/b", "./x/..", true,
528           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/" },
529         { "scheme://a/b", "././x/..", true,
530           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/" },
531         { "scheme://a/b", "./././x/..", true,
532           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/" },
533         { "scheme://a/b", "./x/../.", true,
534           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/" },
535         { "scheme://a/b", "./x/.././", true,
536           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/" },
537         { "scheme://a/b", "././x/.././.", true,
538           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/" },
539         { "scheme://a/b", "././x/../././", true,
540           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/" },
541         { "scheme://a/b", "./././x/../././.", true,
542           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/" },
543 
544         { "scheme://a/b/", "", true,
545           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/b/" },
546         { "scheme://a/b/", ".", true,
547           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/b/" },
548         { "scheme://a/b/", "./", true,
549           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/b/" },
550         { "scheme://a/b/", "./.", true,
551           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/b/" },
552         { "scheme://a/b/", "././", true,
553           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/b/" },
554         { "scheme://a/b/", "././.", true,
555           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/b/" },
556         { "scheme://a/b/", "x/..", true,
557           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/b/" },
558         { "scheme://a/b/", "x/../", true,
559           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/b/" },
560         { "scheme://a/b/", "x/../.", true,
561           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/b/" },
562         { "scheme://a/b/", "x/.././", true,
563           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/b/" },
564         { "scheme://a/b/", "x/.././.", true,
565           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/b/" },
566         { "scheme://a/b/", "x/../././", true,
567           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/b/" },
568         { "scheme://a/b/", "x/../././.", true,
569           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/b/" },
570         { "scheme://a/b/", "./x/..", true,
571           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/b/" },
572         { "scheme://a/b/", "././x/..", true,
573           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/b/" },
574         { "scheme://a/b/", "./././x/..", true,
575           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/b/" },
576         { "scheme://a/b/", "./x/../.", true,
577           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/b/" },
578         { "scheme://a/b/", "./x/.././", true,
579           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/b/" },
580         { "scheme://a/b/", "././x/.././.", true,
581           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/b/" },
582         { "scheme://a/b/", "././x/../././", true,
583           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/b/" },
584         { "scheme://a/b/", "./././x/../././.", true,
585           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/b/" },
586 
587         { "scheme://a#s", "", true,
588           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a" },
589         { "scheme://a", "?q", true,
590           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a?q" },
591         { "scheme://a#s", "?q", true,
592           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a?q" },
593         { "scheme://a", "#s", true,
594           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a#s" },
595         { "scheme://a#s1", "#s2", true,
596           css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a#s2" } };
597     for (std::size_t i = 0; i < sizeof data / sizeof data[0]; ++i) {
598         css::uno::Reference< css::uri::XUriReference > baseUriRef(
599             m_uriFactory->parse(
600                 rtl::OUString::createFromAscii(data[i].baseUriReference)));
601         CPPUNIT_ASSERT(baseUriRef.is());
602         css::uno::Reference< css::uri::XUriReference > uriRef(
603             m_uriFactory->parse(
604                 rtl::OUString::createFromAscii(data[i].uriReference)));
605         CPPUNIT_ASSERT(uriRef.is());
606         css::uno::Reference< css::uri::XUriReference > absolute(
607             m_uriFactory->makeAbsolute(
608                 baseUriRef, uriRef, data[i].processSpecialBaseSegments,
609                 data[i].excessParentSegments));
610         TEST_ASSERT_EQUAL(
611             "testMakeAbsolute", i, data[i].uriReference,
612             data[i].absolute != 0, absolute.is());
613         if (absolute.is()) {
614             TEST_ASSERT_EQUAL(
615                 "testMakeAbsolute", i, data[i].uriReference,
616                 rtl::OUString::createFromAscii(data[i].absolute),
617                 absolute->getUriReference());
618         }
619     }
620 }
621 
622 void Test::testMakeRelative() {
623     struct Data {
624         char const * baseUriReference;
625         char const * uriReference;
626         bool preferAuthorityOverRelativePath;
627         bool preferAbsoluteOverRelativePath;
628         bool encodeRetainedSpecialSegments;
629         char const * relative;
630         char const * absolute;
631     };
632     Data data[] = {
633         { "scheme1://a/b/c", "scheme2://a/b/c?q#s", true, true, false,
634           "scheme2://a/b/c?q#s", 0 },
635         { "scheme://a/b/c", "scheme:a/b/c?q#s", true, true, false,
636           "scheme:a/b/c?q#s", 0 },
637         { "scheme://a/b/c", "", true, true, false, "", "scheme://a/b/c" },
638         { "scheme://a/b/c", "//d/e/f", true, true, false, "//d/e/f",
639           "scheme://d/e/f" },
640         { "scheme://a/b/c", "./e?q#s", true, true, false, "./e?q#s",
641           "scheme://a/b/e?q#s" },
642         { "scheme://a/b", "scheme://a?q", true, true, false, "/?q",
643           "scheme://a/?q" },
644         { "scheme://a/b", "scheme://a?q", true, false, false, "?q",
645           "scheme://a/?q" },
646         { "scheme://a", "scheme://a?q", true, true, false, "?q", 0 },
647         { "scheme://a/", "scheme://a?q", true, true, false, "?q",
648           "scheme://a/?q" },
649         { "scheme://a", "scheme://a/?q", true, true, false, "?q",
650           "scheme://a?q" },
651         { "scheme://a/", "scheme://a/?q", true, true, false, "?q",
652           "scheme://a/?q" },
653         { "scheme://a?q", "scheme://a?q", true, true, false, "", 0 },
654         { "scheme://a/?q", "scheme://a?q", true, true, false, "",
655           "scheme://a/?q" },
656         { "scheme://a?q", "scheme://a/?q", true, true, false, "",
657           "scheme://a?q" },
658         { "scheme://a/?q", "scheme://a/?q", true, true, false, "", 0 },
659         { "scheme://a/b/c/d", "scheme://a//", true, true, false, "//a//", 0 },
660         { "scheme://a/b/c/d", "scheme://a//", false, true, false, "../..//",
661           0 },
662         { "scheme://a/b/c/d", "scheme://a//", true, false, false, "../..//",
663           0 },
664         { "scheme://a/b/c/d", "scheme://a//", false, false, false, "../..//",
665           0 },
666         { "scheme://a/b/c/d", "scheme://a/e", true, true, false, "/e", 0 },
667         { "scheme://a/b/c/d", "scheme://a/e", true, false, false, "../../e",
668           0 },
669         { "scheme://a/b/c/d/e", "scheme://a/b/f", true, true, false, "../../f",
670           0 },
671         { "scheme://a/b/c/d/e", "scheme://a/b", true, true, false, "/b", 0 },
672         { "scheme://a/b/c/d/e", "scheme://a/b", true, false, false,
673           "../../../b", 0 },
674         { "scheme://a/b/c/d/e", "scheme://a/b/", true, true, false, "../..",
675           0 },
676         { "scheme://a/b/c/d/e", "scheme://a/b/c", true, true, false, "../../c",
677           0 },
678         { "scheme://a/b/c/d/e", "scheme://a/b/c/", true, true, false, "..", 0 },
679         { "scheme://a/b/", "scheme://a/b/c/d", true, true, false, "c/d", 0 },
680         { "scheme://a/b/", "scheme://a/b/c/d/", true, true, false, "c/d/", 0 },
681         { "scheme://a/b/c", "scheme://a/b//", true, true, false, ".//", 0 },
682         { "scheme://a/b/c", "scheme://a/b//d", true, true, false, ".//d", 0 },
683         { "scheme://a/b/c", "scheme://a/b//d//", true, true, false, ".//d//",
684           0 },
685         { "scheme://a/b/c", "scheme://a/b/d+:", true, true, false, "./d+:", 0 },
686         { "scheme://a/b/c", "scheme://a/b/+d:", true, true, false, "+d:", 0 },
687         { "scheme://a/b/c", "scheme://a/b/d#e:f", true, true, false, "d#e:f",
688           0 },
689         { "scheme://a/b/c/", "scheme://a/b/../d/.e/.", true, true, false,
690           "../../d/.e/.",
691           "scheme://a/d/.e/" },
692         { "scheme://a/b/c/", "scheme://a/b/../d/.e/.", true, true, true,
693           "../%2E%2E/d/.e/%2E", "scheme://a/b/%2E%2E/d/.e/%2E" },
694         { "scheme://auth/a/b", "scheme://auth//c/d", true, true, false,
695           "//auth//c/d", 0 },
696         { "scheme://auth/a/b", "scheme://auth//c/d", false, true, false,
697           "..//c/d", 0 },
698         { "scheme://auth/a/b", "scheme://auth/c/d", true, true, false, "/c/d",
699           0 },
700         { "scheme://auth/a/b", "scheme://auth/c/d", true, false, false,
701           "../c/d", 0 } };
702     for (std::size_t i = 0; i < sizeof data / sizeof data[0]; ++i) {
703         css::uno::Reference< css::uri::XUriReference > baseUriRef(
704             m_uriFactory->parse(
705                 rtl::OUString::createFromAscii(data[i].baseUriReference)));
706         CPPUNIT_ASSERT(baseUriRef.is());
707         css::uno::Reference< css::uri::XUriReference > uriRef(
708             m_uriFactory->parse(
709                 rtl::OUString::createFromAscii(data[i].uriReference)));
710         CPPUNIT_ASSERT(uriRef.is());
711         css::uno::Reference< css::uri::XUriReference > relative(
712             m_uriFactory->makeRelative(
713                 baseUriRef, uriRef, data[i].preferAuthorityOverRelativePath,
714                 data[i].preferAbsoluteOverRelativePath,
715                 data[i].encodeRetainedSpecialSegments));
716         TEST_ASSERT_EQUAL(
717             "testMakeRelative", i, data[i].uriReference,
718             data[i].relative != 0, relative.is());
719         if (relative.is()) {
720             TEST_ASSERT_EQUAL(
721                 "testMakeRelative", i, data[i].uriReference,
722                 rtl::OUString::createFromAscii(data[i].relative),
723                 relative->getUriReference());
724             css::uno::Reference< css::uri::XUriReference > absolute(
725                 m_uriFactory->makeAbsolute(
726                     baseUriRef, relative, true,
727                     css::uri::RelativeUriExcessParentSegments_ERROR));
728             CPPUNIT_ASSERT(absolute.is());
729             TEST_ASSERT_EQUAL(
730                 "testMakeRelative", i, data[i].uriReference,
731                 rtl::OUString::createFromAscii(
732                     data[i].absolute == 0
733                     ? data[i].uriReference : data[i].absolute),
734                 absolute->getUriReference());
735         }
736     }
737 }
738 
739 void Test::testVndSunStarExpand() {
740     struct Data {
741         char const * uriReference;
742         char const * expanded;
743     };
744     Data data[] = {
745         { "vnd.sun.star.expand:", "" }, // liberally accepted
746         { "vnd.sun.star.expand:/", "/" }, // liberally accepted
747         { "vnd.sun.star.expand:%80", 0 },
748         { "vnd.sun.star.expand:%5C$%5C%24%5C%5C", "$$\\" } };
749     css::uno::Reference< css::util::XMacroExpander > expander(
750         m_context->getValueByName(
751               rtl::OUString(
752                   RTL_CONSTASCII_USTRINGPARAM(
753                       "/singletons/com.sun.star.util.theMacroExpander"))),
754         css::uno::UNO_QUERY_THROW);
755     for (std::size_t i = 0; i < sizeof data / sizeof data[0]; ++i) {
756         css::uno::Reference< css::uri::XUriReference > uriRef(
757             m_uriFactory->parse(
758                 rtl::OUString::createFromAscii(data[i].uriReference)));
759         TEST_ASSERT_EQUAL(
760             "testVndSunStarExpand", i, data[i].uriReference,
761             data[i].expanded != 0, uriRef.is());
762         if (uriRef.is()) {
763             css::uno::Reference< css::uri::XVndSunStarExpandUrlReference >
764                 expandUrl(uriRef, css::uno::UNO_QUERY_THROW);
765             TEST_ASSERT_EQUAL(
766                 "testVndSunStarExpand", i, data[i].uriReference,
767                 rtl::OUString::createFromAscii(data[i].expanded),
768                 expandUrl->expand(expander));
769         }
770     }
771 }
772 
773 void Test::testVndSunStarScript() {
774     struct Parameter {
775         char const * key;
776         char const * value;
777     };
778     std::size_t const parameterCount = 3;
779     struct Data {
780         char const * uriReference;
781         char const * name;
782         const bool   normalized;
783         Parameter parameters[parameterCount];
784     };
785     Data data[] = {
786         { "vnd.sun.star.script:", 0, false, {} },
787         { "vnd.sun.star.script:/", 0, false, {} },
788         { "vnd.sun.star.script:/abc/def?ghi=jkl&mno=pqr", 0, false, {} },
789         { "vnd.sun.star.script:abc%3fdef/ghi", "abc?def/ghi", false, {} },
790         { "vnd.sun.star.script:name?a", 0, false, {} },
791         { "vnd.sun.star.script:name?a=", "name", true, { { "a", "" }, { "A", 0 } } },
792         { "vnd.sun.star.script:name?a=&", 0, true, {} },
793         { "vnd.sun.star.script:name?key1=&%26=%3D&key1=hello", "name", true,
794           { { "key1", "" }, { "key2", 0 }, { "&", "=" } } } };
795     for (std::size_t i = 0; i < sizeof data / sizeof data[0]; ++i) {
796         css::uno::Reference< css::uri::XUriReference > uriRef(
797             m_uriFactory->parse(
798                 rtl::OUString::createFromAscii(data[i].uriReference)));
799         TEST_ASSERT_EQUAL(
800             "testVndSunStarScript", i, data[i].uriReference, data[i].name != 0,
801             uriRef.is());
802         if (uriRef.is()) {
803             css::uno::Reference< css::uri::XVndSunStarScriptUrlReference >
804                 scriptUrl(uriRef, css::uno::UNO_QUERY_THROW);
805             TEST_ASSERT_EQUAL(
806                 "testVndSunStarScript", i, data[i].uriReference,
807                 rtl::OUString::createFromAscii(data[i].uriReference),
808                 scriptUrl->getUriReference());
809             TEST_ASSERT_EQUAL(
810                 "testVndSunStarScript", i, data[i].uriReference,
811                 rtl::OUString::createFromAscii(data[i].name),
812                 scriptUrl->getName());
813             rtl::OUString originalReference(uriRef->getUriReference());
814             for (std::size_t j = 0; j < parameterCount; ++j) {
815                 if (data[i].parameters[j].key != 0) {
816                     TEST_ASSERT_EQUAL(
817                         "testVndSunStarScript",
818                         static_cast< double >(i)
819                         + static_cast< double >(j) / 10.0,
820                         data[i].uriReference,
821                         data[i].parameters[j].value != 0,
822                         scriptUrl->hasParameter(
823                             rtl::OUString::createFromAscii(
824                                 data[i].parameters[j].key)));
825                     TEST_ASSERT_EQUAL(
826                         "testVndSunStarScript",
827                         static_cast< double >(i)
828                         + static_cast< double >(j) / 10.0,
829                         data[i].uriReference,
830                         rtl::OUString::createFromAscii(
831                             data[i].parameters[j].value),
832                         scriptUrl->getParameter(
833                             rtl::OUString::createFromAscii(
834                                 data[i].parameters[j].key)));
835 
836                     // setting the parameter to its original value should not change
837                     // the overall uri reference (provided it was normalized before)
838                     if ( data[i].normalized ) {
839                         if ( scriptUrl->hasParameter(rtl::OUString::createFromAscii(
840                             data[i].parameters[j].key)) ) {
841                             scriptUrl->setParameter(
842                                 rtl::OUString::createFromAscii(
843                                     data[i].parameters[j].key),
844                                 scriptUrl->getParameter(
845                                     rtl::OUString::createFromAscii(
846                                         data[i].parameters[j].key)));
847                             TEST_ASSERT_EQUAL(
848                                 "testVndSunStarScript",
849                                 static_cast< double >(i)
850                                 + static_cast< double >(j) / 10.0,
851                                 ::rtl::OUString::createFromAscii("setParameter"),
852                                 originalReference,
853                                 uriRef->getUriReference());
854                         }
855                     }
856                 }
857             }
858             if ( data[i].normalized ) {
859                 scriptUrl->setName(scriptUrl->getName());
860                 TEST_ASSERT_EQUAL(
861                     "testVndSunStarScript",
862                     i,
863                     ::rtl::OUString::createFromAscii("setName"),
864                     originalReference,
865                     uriRef->getUriReference());
866             }
867         }
868     }
869 
870     css::uno::Reference< css::uri::XUriReference > uriRef(
871         m_uriFactory->parse(
872             rtl::OUString(
873                 RTL_CONSTASCII_USTRINGPARAM(
874                     "vnd.sun.star.script:Hello?location=Library.Module"))),
875         css::uno::UNO_SET_THROW);
876     css::uno::Reference< css::uri::XVndSunStarScriptUrlReference >
877         scriptUrl(uriRef, css::uno::UNO_QUERY_THROW);
878 
879     scriptUrl->setParameter(
880         ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "location")),
881         ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "foo")));
882     TEST_ASSERT_EQUAL(
883         "testVndSunStarScript", (sal_Int32)10, (sal_Int32)1,
884         uriRef->getUriReference(),
885         ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "vnd.sun.star.script:Hello?location=foo")));
886 
887     scriptUrl->setParameter(
888         ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "language")),
889         ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "StarBasic")));
890     TEST_ASSERT_EQUAL(
891         "testVndSunStarScript", (sal_Int32)10, (sal_Int32)2,
892         uriRef->getUriReference(),
893         ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "vnd.sun.star.script:Hello?location=foo&language=StarBasic")));
894 
895 
896     bool caughtExpected = false;
897     try {
898         scriptUrl->setName(::rtl::OUString());
899     }
900     catch( const css::lang::IllegalArgumentException& ) {
901         caughtExpected = true;
902     }
903     TEST_ASSERT_EQUAL(
904         "testVndSunStarScript",
905         ::rtl::OUString::createFromAscii("illegal arguments"),
906         ::rtl::OUString::createFromAscii("name"),
907         caughtExpected,
908         true);
909 
910     caughtExpected = false;
911     try {
912         scriptUrl->setParameter(
913             ::rtl::OUString(),
914             ::rtl::OUString::createFromAscii("non-empty"));
915     }
916     catch( const css::lang::IllegalArgumentException& ) {
917         caughtExpected = true;
918     }
919     TEST_ASSERT_EQUAL(
920         "testVndSunStarScript",
921         ::rtl::OUString::createFromAscii("illegal arguments"),
922         ::rtl::OUString::createFromAscii("parameter"),
923         caughtExpected,
924         true);
925 }
926 
927 void Test::testTranslator() {
928     struct Data {
929         char const * externalUriReference;
930         char const * internalUriReference;
931         bool toInternal;
932     };
933     Data data[] = {
934         { "", "", true },
935         { "#fragment", "#fragment", true },
936         { "segment/segment?query#fragment", "segment/segment?query#fragment",
937           true },
938         { "/segment/segment?query#fragment", "/segment/segment?query#fragment",
939           true },
940         { "//authority/segment?query#fragment",
941           "//authority/segment?query#fragment", true },
942         { "foo:bar#fragment", "foo:bar#fragment", true },
943         { "file:///abc/def", "file:///abc/def", true },
944         { "file:///abc/%FEef", "file:///abc/%feef", false },
945         { "file:///abc/%80%80ef", "file:///abc/%80%80ef", false },
946         { "file:///abc/%ED%A0%80%ED%B0%80ef",
947           "file:///abc/%ED%A0%80%ED%B0%80ef", false },
948         { "file:///abc/%25.ef", "file:///abc/%.ef", false },
949         { "file:///abc/%25ef", "file:///abc/%25ef", true } };
950     css::uno::Reference< css::uri::XExternalUriReferenceTranslator >
951         translator(css::uri::ExternalUriReferenceTranslator::create(m_context));
952     for (std::size_t i = 0; i < sizeof data / sizeof data[0]; ++i) {
953         if (data[i].toInternal) {
954             TEST_ASSERT_EQUAL(
955                 "testTranslator, translateToInternal", i,
956                 data[i].externalUriReference,
957                 rtl::OUString::createFromAscii(data[i].internalUriReference),
958                 translator->translateToInternal(
959                     rtl::OUString::createFromAscii(
960                         data[i].externalUriReference)));
961         }
962         TEST_ASSERT_EQUAL(
963             "testTranslator, translateToExternal", i,
964             data[i].internalUriReference,
965             rtl::OUString::createFromAscii(data[i].externalUriReference),
966             translator->translateToExternal(
967                 rtl::OUString::createFromAscii(data[i].internalUriReference)));
968     }
969 }
970 
971 void Test::testPkgUrlFactory() {
972     struct Data {
973         char const * authority;
974         char const * result;
975     };
976     Data data[] = {
977         { "a/b/c", 0 },
978         { "file:///#foo", 0 },
979         { "file:///a%25b%2fc/d~e&f@g?h",
980           "vnd.sun.star.pkg://file:%2F%2F%2Fa%2525b%252fc%2Fd~e&f@g%3Fh" } };
981     css::uno::Reference< css::uri::XVndSunStarPkgUrlReferenceFactory > factory(
982         css::uri::VndSunStarPkgUrlReferenceFactory::create(m_context));
983     for (std::size_t i = 0; i < sizeof data / sizeof data[0]; ++i) {
984         css::uno::Reference< css::uri::XUriReference > url(
985             factory->createVndSunStarPkgUrlReference(
986                 m_uriFactory->parse(
987                     rtl::OUString::createFromAscii(data[i].authority))));
988         TEST_ASSERT_EQUAL(
989             "testVndSunStarPkgFactory", i, data[i].authority,
990             data[i].result != 0, static_cast< bool >(url.is()));
991         if (data[i].result != 0) {
992             TEST_ASSERT_EQUAL(
993                 "testVndSunStarPkgFactory", i, data[i].authority,
994                 rtl::OUString::createFromAscii(data[i].result),
995                 url->getUriReference());
996         }
997     }
998 }
999 
1000 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
1001 
1002 }
1003 
1004 CPPUNIT_PLUGIN_IMPLEMENT();
1005