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