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 "cppunit/TestAssert.h" 43 #include "cppunit/TestFixture.h" 44 #include "cppunit/extensions/HelperMacros.h" 45 #include "cppunit/plugin/TestPlugIn.h" 46 #include "osl/diagnose.h" 47 #include "rtl/string.h" 48 #include "rtl/string.hxx" 49 #include "rtl/textenc.h" 50 #include "rtl/ustrbuf.hxx" 51 #include "rtl/ustring.hxx" 52 #include "sal/types.h" 53 54 #include <cstdlib> 55 56 namespace css = com::sun::star; 57 58 namespace { 59 60 #define TEST_ASSERT_EQUAL(token1, token2, token3, expected, actual) \ 61 CPPUNIT_ASSERT_MESSAGE( \ 62 createTestAssertEqualMessage( \ 63 token1, token2, token3, #expected, #actual, expected, actual). \ 64 getStr(), \ 65 (actual) == (expected)) 66 67 template< typename T > void append( 68 rtl::OUStringBuffer & buffer, T const & value) 69 { 70 buffer.append(value); 71 } 72 73 template<> void append(rtl::OUStringBuffer & buffer, bool const & value) { 74 buffer.append(static_cast< sal_Bool >(value)); 75 } 76 77 template<> void append(rtl::OUStringBuffer & buffer, std::size_t const & value) 78 { 79 buffer.append(static_cast< sal_Int32 >(value)); 80 } 81 82 template<> void append(rtl::OUStringBuffer & buffer, char const * const & value) 83 { 84 buffer.appendAscii(value); 85 } 86 87 template< typename T1, typename T2, typename T3, typename T4 > 88 rtl::OString createTestAssertEqualMessage( 89 char const * token1, T1 const & token2, T2 const & token3, 90 char const * expectedExpr, char const * actualExpr, T3 const & expected, 91 T4 const & actual) 92 { 93 rtl::OUStringBuffer buf; 94 buf.appendAscii(token1); 95 buf.append(static_cast< sal_Unicode >('|')); 96 append(buf, token2); 97 buf.append(static_cast< sal_Unicode >('|')); 98 append(buf, token3); 99 buf.appendAscii(RTL_CONSTASCII_STRINGPARAM(": TEST_ASSERT_EQUAL(")); 100 buf.appendAscii(expectedExpr); 101 buf.appendAscii(RTL_CONSTASCII_STRINGPARAM(", ")); 102 buf.appendAscii(actualExpr); 103 buf.appendAscii(RTL_CONSTASCII_STRINGPARAM("): <")); 104 append(buf, expected); 105 buf.appendAscii(RTL_CONSTASCII_STRINGPARAM("> != <")); 106 append(buf, actual); 107 buf.append(static_cast< sal_Unicode >('>')); 108 return rtl::OUStringToOString( 109 buf.makeStringAndClear(), RTL_TEXTENCODING_ASCII_US); 110 } 111 112 class Test: public CppUnit::TestFixture { 113 public: 114 virtual void setUp(); 115 116 virtual void tearDown(); 117 118 void testParse(); 119 120 void testMakeAbsolute(); 121 122 void testMakeRelative(); 123 124 void testVndSunStarExpand(); 125 126 void testVndSunStarScript(); 127 128 void testTranslator(); 129 130 void testPkgUrlFactory(); 131 132 CPPUNIT_TEST_SUITE(Test); 133 CPPUNIT_TEST(testParse); 134 CPPUNIT_TEST(testMakeAbsolute); 135 CPPUNIT_TEST(testMakeRelative); 136 CPPUNIT_TEST(testVndSunStarExpand); 137 CPPUNIT_TEST(testVndSunStarScript); 138 CPPUNIT_TEST(testTranslator); 139 CPPUNIT_TEST(testPkgUrlFactory); 140 CPPUNIT_TEST_SUITE_END(); 141 142 private: 143 css::uno::Reference< css::uno::XComponentContext > m_context; 144 css::uno::Reference< css::uri::XUriReferenceFactory > m_uriFactory; 145 }; 146 147 void Test::setUp() { 148 m_context = cppu::defaultBootstrap_InitialComponentContext(); 149 m_uriFactory = css::uri::UriReferenceFactory::create(m_context); 150 } 151 152 void Test::tearDown() { 153 m_uriFactory.clear(); 154 css::uno::Reference< css::lang::XComponent >( 155 m_context, css::uno::UNO_QUERY_THROW)->dispose(); 156 } 157 158 void Test::testParse() { 159 struct Data { 160 char const * uriReference; 161 char const * scheme; 162 char const * schemeSpecificPart; 163 bool isHierarchical; 164 char const * authority; 165 char const * path; 166 bool hasRelativePath; 167 sal_Int32 pathSegmentCount; 168 char const * pathSegment0; 169 char const * pathSegment1; 170 char const * pathSegment2; 171 char const * pathSegment3; 172 char const * pathSegment4; 173 char const * query; 174 char const * fragment; 175 }; 176 Data data[] = { 177 { "", 0, "", true, 0, 178 "", true, 0, "", "", "", "", "", 0, 0 }, 179 { "scheme:", 0, 0, false, 0, 180 0, false, 0, 0, 0, 0, 0, 0, 0, 0 }, 181 { "scheme:/", "scheme", "/", true, 0, 182 "/", false, 1, "", "", "", "", "", 0, 0 }, 183 { "scheme://", "scheme", "//", true, "", 184 "", false, 0, "", "", "", "", "", 0, 0 }, 185 { "scheme:///", "scheme", "///", true, "", 186 "/", false, 1, "", "", "", "", "", 0, 0 }, 187 { "scheme:////", "scheme", "////", true, "", 188 "//", false, 2, "", "", "", "", "", 0, 0 }, 189 { "scheme:////", "scheme", "////", true, "", 190 "//", false, 2, "", "", "", "", "", 0, 0 }, 191 { "scheme:#", 0, 0, false, 0, 192 0, false, 0, 0, 0, 0, 0, 0, 0, 0 }, 193 { "scheme:?", "scheme", "?", false, 0, 194 "?", false, 0, "", "", "", "", "", 0, 0 }, 195 { "/", 0, "/", true, 0, 196 "/", false, 1, "", "", "", "", "", 0, 0 }, 197 { "//", 0, "//", true, "", 198 "", false, 0, "", "", "", "", "", 0, 0 }, 199 { "///", 0, "///", true, "", 200 "/", false, 1, "", "", "", "", "", 0, 0 }, 201 { "////", 0, "////", true, "", 202 "//", false, 2, "", "", "", "", "", 0, 0 } }; 203 for (std::size_t i = 0; i < sizeof data / sizeof data[0]; ++i) { 204 css::uno::Reference< css::uri::XUriReference > uriRef( 205 m_uriFactory->parse( 206 rtl::OUString::createFromAscii(data[i].uriReference))); 207 CPPUNIT_ASSERT(uriRef.is() == (data[i].schemeSpecificPart != 0)); 208 if (uriRef.is()) { 209 TEST_ASSERT_EQUAL( 210 "testParse", i, data[i].uriReference, 211 rtl::OUString::createFromAscii(data[i].uriReference), 212 uriRef->getUriReference()); 213 TEST_ASSERT_EQUAL( 214 "testParse", i, data[i].uriReference, 215 data[i].scheme != 0, uriRef->isAbsolute()); 216 TEST_ASSERT_EQUAL( 217 "testParse", i, data[i].uriReference, 218 rtl::OUString::createFromAscii( 219 data[i].scheme == 0 ? "" : data[i].scheme), 220 uriRef->getScheme()); 221 TEST_ASSERT_EQUAL( 222 "testParse", i, data[i].uriReference, 223 rtl::OUString::createFromAscii(data[i].schemeSpecificPart), 224 uriRef->getSchemeSpecificPart()); 225 TEST_ASSERT_EQUAL( 226 "testParse", i, data[i].uriReference, 227 data[i].isHierarchical, 228 static_cast< bool >(uriRef->isHierarchical())); 229 TEST_ASSERT_EQUAL( 230 "testParse", i, data[i].uriReference, 231 data[i].authority != 0, uriRef->hasAuthority()); 232 TEST_ASSERT_EQUAL( 233 "testParse", i, data[i].uriReference, 234 rtl::OUString::createFromAscii( 235 data[i].authority == 0 ? "" : data[i].authority), 236 uriRef->getAuthority()); 237 TEST_ASSERT_EQUAL( 238 "testParse", i, data[i].uriReference, 239 rtl::OUString::createFromAscii(data[i].path), 240 uriRef->getPath()); 241 TEST_ASSERT_EQUAL( 242 "testParse", i, data[i].uriReference, 243 data[i].hasRelativePath, 244 static_cast< bool >(uriRef->hasRelativePath())); 245 TEST_ASSERT_EQUAL( 246 "testParse", i, data[i].uriReference, 247 data[i].pathSegmentCount, uriRef->getPathSegmentCount()); 248 TEST_ASSERT_EQUAL( 249 "testParse", i, data[i].uriReference, 250 rtl::OUString::createFromAscii(""), uriRef->getPathSegment(-1)); 251 TEST_ASSERT_EQUAL( 252 "testParse", i, data[i].uriReference, 253 rtl::OUString::createFromAscii(data[i].pathSegment0), 254 uriRef->getPathSegment(0)); 255 TEST_ASSERT_EQUAL( 256 "testParse", i, data[i].uriReference, 257 rtl::OUString::createFromAscii(data[i].pathSegment1), 258 uriRef->getPathSegment(1)); 259 TEST_ASSERT_EQUAL( 260 "testParse", i, data[i].uriReference, 261 rtl::OUString::createFromAscii(data[i].pathSegment2), 262 uriRef->getPathSegment(2)); 263 TEST_ASSERT_EQUAL( 264 "testParse", i, data[i].uriReference, 265 rtl::OUString::createFromAscii(data[i].pathSegment3), 266 uriRef->getPathSegment(3)); 267 TEST_ASSERT_EQUAL( 268 "testParse", i, data[i].uriReference, 269 rtl::OUString::createFromAscii(data[i].pathSegment4), 270 uriRef->getPathSegment(4)); 271 TEST_ASSERT_EQUAL( 272 "testParse", i, data[i].uriReference, 273 rtl::OUString::createFromAscii(""), uriRef->getPathSegment(5)); 274 TEST_ASSERT_EQUAL( 275 "testParse", i, data[i].uriReference, 276 data[i].query != 0, uriRef->hasQuery()); 277 TEST_ASSERT_EQUAL( 278 "testParse", i, data[i].uriReference, 279 rtl::OUString::createFromAscii( 280 data[i].query == 0 ? "" : data[i].query), 281 uriRef->getQuery()); 282 TEST_ASSERT_EQUAL( 283 "testParse", i, data[i].uriReference, 284 data[i].fragment != 0, uriRef->hasFragment()); 285 TEST_ASSERT_EQUAL( 286 "testParse", i, data[i].uriReference, 287 rtl::OUString::createFromAscii( 288 data[i].fragment == 0 ? "" : data[i].fragment), 289 uriRef->getFragment()); 290 } 291 } 292 } 293 294 void Test::testMakeAbsolute() { 295 struct Data { 296 char const * baseUriReference; 297 char const * uriReference; 298 bool processSpecialBaseSegments; 299 css::uri::RelativeUriExcessParentSegments excessParentSegments; 300 char const * absolute; 301 }; 302 Data data[] = { 303 // The following tests are taken from RFC 2396, Appendix C: 304 { "http://a/b/c/d;p?q", "g:h", true, 305 css::uri::RelativeUriExcessParentSegments_ERROR, "g:h" }, 306 { "http://a/b/c/d;p?q", "g", true, 307 css::uri::RelativeUriExcessParentSegments_ERROR, "http://a/b/c/g" }, 308 { "http://a/b/c/d;p?q", "./g", true, 309 css::uri::RelativeUriExcessParentSegments_ERROR, "http://a/b/c/g" }, 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://g" }, 314 { "http://a/b/c/d;p?q", "?y", true, 315 css::uri::RelativeUriExcessParentSegments_ERROR, "http://a/b/c/?y" }, 316 { "http://a/b/c/d;p?q", "g?y", true, 317 css::uri::RelativeUriExcessParentSegments_ERROR, 318 "http://a/b/c/g?y" }, 319 { "http://a/b/c/d;p?q", "#s", true, 320 css::uri::RelativeUriExcessParentSegments_ERROR, 321 "http://a/b/c/d;p?q#s" }, 322 { "http://a/b/c/d;p?q", "g#s", true, 323 css::uri::RelativeUriExcessParentSegments_ERROR, 324 "http://a/b/c/g#s" }, 325 { "http://a/b/c/d;p?q", "g?y#s", true, 326 css::uri::RelativeUriExcessParentSegments_ERROR, 327 "http://a/b/c/g?y#s" }, 328 { "http://a/b/c/d;p?q", ";x", true, 329 css::uri::RelativeUriExcessParentSegments_ERROR, "http://a/b/c/;x" }, 330 { "http://a/b/c/d;p?q", "g;x", true, 331 css::uri::RelativeUriExcessParentSegments_ERROR, 332 "http://a/b/c/g;x" }, 333 { "http://a/b/c/d;p?q", "g;x?y#s", true, 334 css::uri::RelativeUriExcessParentSegments_ERROR, 335 "http://a/b/c/g;x?y#s" }, 336 { "http://a/b/c/d;p?q", ".", true, 337 css::uri::RelativeUriExcessParentSegments_ERROR, "http://a/b/c/" }, 338 { "http://a/b/c/d;p?q", "./", true, 339 css::uri::RelativeUriExcessParentSegments_ERROR, "http://a/b/c/" }, 340 { "http://a/b/c/d;p?q", "..", true, 341 css::uri::RelativeUriExcessParentSegments_ERROR, "http://a/b/" }, 342 { "http://a/b/c/d;p?q", "../", true, 343 css::uri::RelativeUriExcessParentSegments_ERROR, "http://a/b/" }, 344 { "http://a/b/c/d;p?q", "../g", true, 345 css::uri::RelativeUriExcessParentSegments_ERROR, "http://a/b/g" }, 346 { "http://a/b/c/d;p?q", "../..", true, 347 css::uri::RelativeUriExcessParentSegments_ERROR, "http://a/" }, 348 { "http://a/b/c/d;p?q", "../../", true, 349 css::uri::RelativeUriExcessParentSegments_ERROR, "http://a/" }, 350 { "http://a/b/c/d;p?q", "../../g", true, 351 css::uri::RelativeUriExcessParentSegments_ERROR, "http://a/g" }, 352 { "http://a/b/c/d;p?q", "", true, 353 css::uri::RelativeUriExcessParentSegments_ERROR, 354 "http://a/b/c/d;p?q" }, 355 { "http://a/b/c/d;p?q", "../../../g", true, 356 css::uri::RelativeUriExcessParentSegments_ERROR, 0 }, 357 { "http://a/b/c/d;p?q", "../../../g", true, 358 css::uri::RelativeUriExcessParentSegments_RETAIN, "http://a/../g" }, 359 { "http://a/b/c/d;p?q", "../../../g", true, 360 css::uri::RelativeUriExcessParentSegments_REMOVE, "http://a/g" }, 361 { "http://a/b/c/d;p?q", "../../../../g", true, 362 css::uri::RelativeUriExcessParentSegments_ERROR, 0 }, 363 { "http://a/b/c/d;p?q", "../../../../g", true, 364 css::uri::RelativeUriExcessParentSegments_RETAIN, 365 "http://a/../../g" }, 366 { "http://a/b/c/d;p?q", "../../../../g", true, 367 css::uri::RelativeUriExcessParentSegments_REMOVE, "http://a/g" }, 368 { "http://a/b/c/d;p?q", "/./g", true, 369 css::uri::RelativeUriExcessParentSegments_ERROR, "http://a/./g" }, 370 { "http://a/b/c/d;p?q", "/../g", true, 371 css::uri::RelativeUriExcessParentSegments_ERROR, "http://a/../g" }, 372 { "http://a/b/c/d;p?q", "g.", true, 373 css::uri::RelativeUriExcessParentSegments_ERROR, "http://a/b/c/g." }, 374 { "http://a/b/c/d;p?q", ".g", true, 375 css::uri::RelativeUriExcessParentSegments_ERROR, "http://a/b/c/.g" }, 376 { "http://a/b/c/d;p?q", "g..", true, 377 css::uri::RelativeUriExcessParentSegments_ERROR, 378 "http://a/b/c/g.." }, 379 { "http://a/b/c/d;p?q", "..g", true, 380 css::uri::RelativeUriExcessParentSegments_ERROR, 381 "http://a/b/c/..g" }, 382 { "http://a/b/c/d;p?q", "./../g", true, 383 css::uri::RelativeUriExcessParentSegments_ERROR, "http://a/b/g" }, 384 { "http://a/b/c/d;p?q", "./g/.", true, 385 css::uri::RelativeUriExcessParentSegments_ERROR, "http://a/b/c/g/" }, 386 { "http://a/b/c/d;p?q", "g/./h", true, 387 css::uri::RelativeUriExcessParentSegments_ERROR, 388 "http://a/b/c/g/h" }, 389 { "http://a/b/c/d;p?q", "g/../h", true, 390 css::uri::RelativeUriExcessParentSegments_ERROR, "http://a/b/c/h" }, 391 { "http://a/b/c/d;p?q", "g;x=1/./y", true, 392 css::uri::RelativeUriExcessParentSegments_ERROR, 393 "http://a/b/c/g;x=1/y" }, 394 { "http://a/b/c/d;p?q", "g;x=1/../y", true, 395 css::uri::RelativeUriExcessParentSegments_ERROR, "http://a/b/c/y" }, 396 { "http://a/b/c/d;p?q", "g?y/./x", true, 397 css::uri::RelativeUriExcessParentSegments_ERROR, 398 "http://a/b/c/g?y/./x" }, 399 { "http://a/b/c/d;p?q", "g?y/../x", true, 400 css::uri::RelativeUriExcessParentSegments_ERROR, 401 "http://a/b/c/g?y/../x" }, 402 { "http://a/b/c/d;p?q", "g#s/./x", true, 403 css::uri::RelativeUriExcessParentSegments_ERROR, 404 "http://a/b/c/g#s/./x" }, 405 { "http://a/b/c/d;p?q", "g#s/../x", true, 406 css::uri::RelativeUriExcessParentSegments_ERROR, 407 "http://a/b/c/g#s/../x" }, 408 { "http.://a/b/c/d;p?q", "http.:g", true, 409 css::uri::RelativeUriExcessParentSegments_ERROR, "http.:g" }, 410 411 { "scheme://a", "", true, 412 css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a" }, 413 { "scheme://a", ".", true, 414 css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a" }, 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", "x/..", true, 424 css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a" }, 425 { "scheme://a", "x/../", 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 454 { "scheme://a/", "", true, 455 css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/" }, 456 { "scheme://a/", ".", true, 457 css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/" }, 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/", "x/..", true, 467 css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/" }, 468 { "scheme://a/", "x/../", 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 497 { "scheme://a/b", "", true, 498 css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/b" }, 499 { "scheme://a/b", ".", true, 500 css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/" }, 501 { "scheme://a/b", "./", true, 502 css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/" }, 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", "x/..", true, 510 css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/" }, 511 { "scheme://a/b", "x/../", 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 540 { "scheme://a/b/", "", true, 541 css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/b/" }, 542 { "scheme://a/b/", ".", true, 543 css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a/b/" }, 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/", "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 { "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 583 { "scheme://a#s", "", true, 584 css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a" }, 585 { "scheme://a", "?q", true, 586 css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a?q" }, 587 { "scheme://a#s", "?q", true, 588 css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a?q" }, 589 { "scheme://a", "#s", true, 590 css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a#s" }, 591 { "scheme://a#s1", "#s2", true, 592 css::uri::RelativeUriExcessParentSegments_ERROR, "scheme://a#s2" } }; 593 for (std::size_t i = 0; i < sizeof data / sizeof data[0]; ++i) { 594 css::uno::Reference< css::uri::XUriReference > baseUriRef( 595 m_uriFactory->parse( 596 rtl::OUString::createFromAscii(data[i].baseUriReference))); 597 CPPUNIT_ASSERT(baseUriRef.is()); 598 css::uno::Reference< css::uri::XUriReference > uriRef( 599 m_uriFactory->parse( 600 rtl::OUString::createFromAscii(data[i].uriReference))); 601 CPPUNIT_ASSERT(uriRef.is()); 602 css::uno::Reference< css::uri::XUriReference > absolute( 603 m_uriFactory->makeAbsolute( 604 baseUriRef, uriRef, data[i].processSpecialBaseSegments, 605 data[i].excessParentSegments)); 606 TEST_ASSERT_EQUAL( 607 "testMakeAbsolute", i, data[i].uriReference, 608 data[i].absolute != 0, absolute.is()); 609 if (absolute.is()) { 610 TEST_ASSERT_EQUAL( 611 "testMakeAbsolute", i, data[i].uriReference, 612 rtl::OUString::createFromAscii(data[i].absolute), 613 absolute->getUriReference()); 614 } 615 } 616 } 617 618 void Test::testMakeRelative() { 619 struct Data { 620 char const * baseUriReference; 621 char const * uriReference; 622 bool preferAuthorityOverRelativePath; 623 bool preferAbsoluteOverRelativePath; 624 bool encodeRetainedSpecialSegments; 625 char const * relative; 626 char const * absolute; 627 }; 628 Data data[] = { 629 { "scheme1://a/b/c", "scheme2://a/b/c?q#s", true, true, false, 630 "scheme2://a/b/c?q#s", 0 }, 631 { "scheme://a/b/c", "scheme:a/b/c?q#s", true, true, false, 632 "scheme:a/b/c?q#s", 0 }, 633 { "scheme://a/b/c", "", true, true, false, "", "scheme://a/b/c" }, 634 { "scheme://a/b/c", "//d/e/f", true, true, false, "//d/e/f", 635 "scheme://d/e/f" }, 636 { "scheme://a/b/c", "./e?q#s", true, true, false, "./e?q#s", 637 "scheme://a/b/e?q#s" }, 638 { "scheme://a/b", "scheme://a?q", true, true, false, "/?q", 639 "scheme://a/?q" }, 640 { "scheme://a/b", "scheme://a?q", true, false, false, "?q", 641 "scheme://a/?q" }, 642 { "scheme://a", "scheme://a?q", true, true, false, "?q", 0 }, 643 { "scheme://a/", "scheme://a?q", true, true, false, "?q", 644 "scheme://a/?q" }, 645 { "scheme://a", "scheme://a/?q", true, true, false, "?q", 646 "scheme://a?q" }, 647 { "scheme://a/", "scheme://a/?q", true, true, false, "?q", 648 "scheme://a/?q" }, 649 { "scheme://a?q", "scheme://a?q", true, true, false, "", 0 }, 650 { "scheme://a/?q", "scheme://a?q", true, true, false, "", 651 "scheme://a/?q" }, 652 { "scheme://a?q", "scheme://a/?q", true, true, false, "", 653 "scheme://a?q" }, 654 { "scheme://a/?q", "scheme://a/?q", true, true, false, "", 0 }, 655 { "scheme://a/b/c/d", "scheme://a//", true, true, false, "//a//", 0 }, 656 { "scheme://a/b/c/d", "scheme://a//", false, true, false, "../..//", 657 0 }, 658 { "scheme://a/b/c/d", "scheme://a//", true, false, false, "../..//", 659 0 }, 660 { "scheme://a/b/c/d", "scheme://a//", false, false, false, "../..//", 661 0 }, 662 { "scheme://a/b/c/d", "scheme://a/e", true, true, false, "/e", 0 }, 663 { "scheme://a/b/c/d", "scheme://a/e", true, false, false, "../../e", 664 0 }, 665 { "scheme://a/b/c/d/e", "scheme://a/b/f", true, true, false, "../../f", 666 0 }, 667 { "scheme://a/b/c/d/e", "scheme://a/b", true, true, false, "/b", 0 }, 668 { "scheme://a/b/c/d/e", "scheme://a/b", true, false, false, 669 "../../../b", 0 }, 670 { "scheme://a/b/c/d/e", "scheme://a/b/", true, true, false, "../..", 671 0 }, 672 { "scheme://a/b/c/d/e", "scheme://a/b/c", true, true, false, "../../c", 673 0 }, 674 { "scheme://a/b/c/d/e", "scheme://a/b/c/", true, true, false, "..", 0 }, 675 { "scheme://a/b/", "scheme://a/b/c/d", true, true, false, "c/d", 0 }, 676 { "scheme://a/b/", "scheme://a/b/c/d/", true, true, false, "c/d/", 0 }, 677 { "scheme://a/b/c", "scheme://a/b//", true, true, false, ".//", 0 }, 678 { "scheme://a/b/c", "scheme://a/b//d", true, true, false, ".//d", 0 }, 679 { "scheme://a/b/c", "scheme://a/b//d//", true, true, false, ".//d//", 680 0 }, 681 { "scheme://a/b/c", "scheme://a/b/d+:", true, true, false, "./d+:", 0 }, 682 { "scheme://a/b/c", "scheme://a/b/+d:", true, true, false, "+d:", 0 }, 683 { "scheme://a/b/c", "scheme://a/b/d#e:f", true, true, false, "d#e:f", 684 0 }, 685 { "scheme://a/b/c/", "scheme://a/b/../d/.e/.", true, true, false, 686 "../../d/.e/.", 687 "scheme://a/d/.e/" }, 688 { "scheme://a/b/c/", "scheme://a/b/../d/.e/.", true, true, true, 689 "../%2E%2E/d/.e/%2E", "scheme://a/b/%2E%2E/d/.e/%2E" }, 690 { "scheme://auth/a/b", "scheme://auth//c/d", true, true, false, 691 "//auth//c/d", 0 }, 692 { "scheme://auth/a/b", "scheme://auth//c/d", false, true, false, 693 "..//c/d", 0 }, 694 { "scheme://auth/a/b", "scheme://auth/c/d", true, true, false, "/c/d", 695 0 }, 696 { "scheme://auth/a/b", "scheme://auth/c/d", true, false, false, 697 "../c/d", 0 } }; 698 for (std::size_t i = 0; i < sizeof data / sizeof data[0]; ++i) { 699 css::uno::Reference< css::uri::XUriReference > baseUriRef( 700 m_uriFactory->parse( 701 rtl::OUString::createFromAscii(data[i].baseUriReference))); 702 CPPUNIT_ASSERT(baseUriRef.is()); 703 css::uno::Reference< css::uri::XUriReference > uriRef( 704 m_uriFactory->parse( 705 rtl::OUString::createFromAscii(data[i].uriReference))); 706 CPPUNIT_ASSERT(uriRef.is()); 707 css::uno::Reference< css::uri::XUriReference > relative( 708 m_uriFactory->makeRelative( 709 baseUriRef, uriRef, data[i].preferAuthorityOverRelativePath, 710 data[i].preferAbsoluteOverRelativePath, 711 data[i].encodeRetainedSpecialSegments)); 712 TEST_ASSERT_EQUAL( 713 "testMakeRelative", i, data[i].uriReference, 714 data[i].relative != 0, relative.is()); 715 if (relative.is()) { 716 TEST_ASSERT_EQUAL( 717 "testMakeRelative", i, data[i].uriReference, 718 rtl::OUString::createFromAscii(data[i].relative), 719 relative->getUriReference()); 720 css::uno::Reference< css::uri::XUriReference > absolute( 721 m_uriFactory->makeAbsolute( 722 baseUriRef, relative, true, 723 css::uri::RelativeUriExcessParentSegments_ERROR)); 724 CPPUNIT_ASSERT(absolute.is()); 725 TEST_ASSERT_EQUAL( 726 "testMakeRelative", i, data[i].uriReference, 727 rtl::OUString::createFromAscii( 728 data[i].absolute == 0 729 ? data[i].uriReference : data[i].absolute), 730 absolute->getUriReference()); 731 } 732 } 733 } 734 735 void Test::testVndSunStarExpand() { 736 struct Data { 737 char const * uriReference; 738 char const * expanded; 739 }; 740 Data data[] = { 741 { "vnd.sun.star.expand:", "" }, // liberally accepted 742 { "vnd.sun.star.expand:/", "/" }, // liberally accepted 743 { "vnd.sun.star.expand:%80", 0 }, 744 { "vnd.sun.star.expand:%5C$%5C%24%5C%5C", "$$\\" } }; 745 css::uno::Reference< css::util::XMacroExpander > expander( 746 m_context->getValueByName( 747 rtl::OUString( 748 RTL_CONSTASCII_USTRINGPARAM( 749 "/singletons/com.sun.star.util.theMacroExpander"))), 750 css::uno::UNO_QUERY_THROW); 751 for (std::size_t i = 0; i < sizeof data / sizeof data[0]; ++i) { 752 css::uno::Reference< css::uri::XUriReference > uriRef( 753 m_uriFactory->parse( 754 rtl::OUString::createFromAscii(data[i].uriReference))); 755 TEST_ASSERT_EQUAL( 756 "testVndSunStarExpand", i, data[i].uriReference, 757 data[i].expanded != 0, uriRef.is()); 758 if (uriRef.is()) { 759 css::uno::Reference< css::uri::XVndSunStarExpandUrlReference > 760 expandUrl(uriRef, css::uno::UNO_QUERY_THROW); 761 TEST_ASSERT_EQUAL( 762 "testVndSunStarExpand", i, data[i].uriReference, 763 rtl::OUString::createFromAscii(data[i].expanded), 764 expandUrl->expand(expander)); 765 } 766 } 767 } 768 769 void Test::testVndSunStarScript() { 770 struct Parameter { 771 char const * key; 772 char const * value; 773 }; 774 std::size_t const parameterCount = 3; 775 struct Data { 776 char const * uriReference; 777 char const * name; 778 const bool normalized; 779 Parameter parameters[parameterCount]; 780 }; 781 Data data[] = { 782 { "vnd.sun.star.script:", 0, false, {} }, 783 { "vnd.sun.star.script:/", 0, false, {} }, 784 { "vnd.sun.star.script:/abc/def?ghi=jkl&mno=pqr", 0, false, {} }, 785 { "vnd.sun.star.script:abc%3fdef/ghi", "abc?def/ghi", false, {} }, 786 { "vnd.sun.star.script:name?a", 0, false, {} }, 787 { "vnd.sun.star.script:name?a=", "name", true, { { "a", "" }, { "A", 0 } } }, 788 { "vnd.sun.star.script:name?a=&", 0, true, {} }, 789 { "vnd.sun.star.script:name?key1=&%26=%3D&key1=hello", "name", true, 790 { { "key1", "" }, { "key2", 0 }, { "&", "=" } } } }; 791 for (std::size_t i = 0; i < sizeof data / sizeof data[0]; ++i) { 792 css::uno::Reference< css::uri::XUriReference > uriRef( 793 m_uriFactory->parse( 794 rtl::OUString::createFromAscii(data[i].uriReference))); 795 TEST_ASSERT_EQUAL( 796 "testVndSunStarScript", i, data[i].uriReference, data[i].name != 0, 797 uriRef.is()); 798 if (uriRef.is()) { 799 css::uno::Reference< css::uri::XVndSunStarScriptUrlReference > 800 scriptUrl(uriRef, css::uno::UNO_QUERY_THROW); 801 TEST_ASSERT_EQUAL( 802 "testVndSunStarScript", i, data[i].uriReference, 803 rtl::OUString::createFromAscii(data[i].uriReference), 804 scriptUrl->getUriReference()); 805 TEST_ASSERT_EQUAL( 806 "testVndSunStarScript", i, data[i].uriReference, 807 rtl::OUString::createFromAscii(data[i].name), 808 scriptUrl->getName()); 809 rtl::OUString originalReference(uriRef->getUriReference()); 810 for (std::size_t j = 0; j < parameterCount; ++j) { 811 if (data[i].parameters[j].key != 0) { 812 TEST_ASSERT_EQUAL( 813 "testVndSunStarScript", 814 static_cast< double >(i) 815 + static_cast< double >(j) / 10.0, 816 data[i].uriReference, 817 data[i].parameters[j].value != 0, 818 scriptUrl->hasParameter( 819 rtl::OUString::createFromAscii( 820 data[i].parameters[j].key))); 821 TEST_ASSERT_EQUAL( 822 "testVndSunStarScript", 823 static_cast< double >(i) 824 + static_cast< double >(j) / 10.0, 825 data[i].uriReference, 826 rtl::OUString::createFromAscii( 827 data[i].parameters[j].value), 828 scriptUrl->getParameter( 829 rtl::OUString::createFromAscii( 830 data[i].parameters[j].key))); 831 832 // setting the parameter to its original value should not change 833 // the overall uri reference (provided it was normalized before) 834 if ( data[i].normalized ) { 835 if ( scriptUrl->hasParameter(rtl::OUString::createFromAscii( 836 data[i].parameters[j].key)) ) { 837 scriptUrl->setParameter( 838 rtl::OUString::createFromAscii( 839 data[i].parameters[j].key), 840 scriptUrl->getParameter( 841 rtl::OUString::createFromAscii( 842 data[i].parameters[j].key))); 843 TEST_ASSERT_EQUAL( 844 "testVndSunStarScript", 845 static_cast< double >(i) 846 + static_cast< double >(j) / 10.0, 847 ::rtl::OUString::createFromAscii("setParameter"), 848 originalReference, 849 uriRef->getUriReference()); 850 } 851 } 852 } 853 } 854 if ( data[i].normalized ) { 855 scriptUrl->setName(scriptUrl->getName()); 856 TEST_ASSERT_EQUAL( 857 "testVndSunStarScript", 858 i, 859 ::rtl::OUString::createFromAscii("setName"), 860 originalReference, 861 uriRef->getUriReference()); 862 } 863 } 864 } 865 866 css::uno::Reference< css::uri::XUriReference > uriRef( 867 m_uriFactory->parse( 868 rtl::OUString( 869 RTL_CONSTASCII_USTRINGPARAM( 870 "vnd.sun.star.script:Hello?location=Library.Module"))), 871 css::uno::UNO_SET_THROW); 872 css::uno::Reference< css::uri::XVndSunStarScriptUrlReference > 873 scriptUrl(uriRef, css::uno::UNO_QUERY_THROW); 874 875 scriptUrl->setParameter( 876 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "location")), 877 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "foo"))); 878 TEST_ASSERT_EQUAL( 879 "testVndSunStarScript", (sal_Int32)10, (sal_Int32)1, 880 uriRef->getUriReference(), 881 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "vnd.sun.star.script:Hello?location=foo"))); 882 883 scriptUrl->setParameter( 884 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "language")), 885 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "StarBasic"))); 886 TEST_ASSERT_EQUAL( 887 "testVndSunStarScript", (sal_Int32)10, (sal_Int32)2, 888 uriRef->getUriReference(), 889 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "vnd.sun.star.script:Hello?location=foo&language=StarBasic"))); 890 891 892 bool caughtExpected = false; 893 try { 894 scriptUrl->setName(::rtl::OUString()); 895 } 896 catch( const css::lang::IllegalArgumentException& ) { 897 caughtExpected = true; 898 } 899 TEST_ASSERT_EQUAL( 900 "testVndSunStarScript", 901 ::rtl::OUString::createFromAscii("illegal arguments"), 902 ::rtl::OUString::createFromAscii("name"), 903 caughtExpected, 904 true); 905 906 caughtExpected = false; 907 try { 908 scriptUrl->setParameter( 909 ::rtl::OUString(), 910 ::rtl::OUString::createFromAscii("non-empty")); 911 } 912 catch( const css::lang::IllegalArgumentException& ) { 913 caughtExpected = true; 914 } 915 TEST_ASSERT_EQUAL( 916 "testVndSunStarScript", 917 ::rtl::OUString::createFromAscii("illegal arguments"), 918 ::rtl::OUString::createFromAscii("parameter"), 919 caughtExpected, 920 true); 921 } 922 923 void Test::testTranslator() { 924 struct Data { 925 char const * externalUriReference; 926 char const * internalUriReference; 927 bool toInternal; 928 }; 929 Data data[] = { 930 { "", "", true }, 931 { "#fragment", "#fragment", true }, 932 { "segment/segment?query#fragment", "segment/segment?query#fragment", 933 true }, 934 { "/segment/segment?query#fragment", "/segment/segment?query#fragment", 935 true }, 936 { "//authority/segment?query#fragment", 937 "//authority/segment?query#fragment", true }, 938 { "foo:bar#fragment", "foo:bar#fragment", true }, 939 { "file:///abc/def", "file:///abc/def", true }, 940 { "file:///abc/%FEef", "file:///abc/%feef", false }, 941 { "file:///abc/%80%80ef", "file:///abc/%80%80ef", false }, 942 { "file:///abc/%ED%A0%80%ED%B0%80ef", 943 "file:///abc/%ED%A0%80%ED%B0%80ef", false }, 944 { "file:///abc/%25.ef", "file:///abc/%.ef", false }, 945 { "file:///abc/%25ef", "file:///abc/%25ef", true } }; 946 css::uno::Reference< css::uri::XExternalUriReferenceTranslator > 947 translator(css::uri::ExternalUriReferenceTranslator::create(m_context)); 948 for (std::size_t i = 0; i < sizeof data / sizeof data[0]; ++i) { 949 if (data[i].toInternal) { 950 TEST_ASSERT_EQUAL( 951 "testTranslator, translateToInternal", i, 952 data[i].externalUriReference, 953 rtl::OUString::createFromAscii(data[i].internalUriReference), 954 translator->translateToInternal( 955 rtl::OUString::createFromAscii( 956 data[i].externalUriReference))); 957 } 958 TEST_ASSERT_EQUAL( 959 "testTranslator, translateToExternal", i, 960 data[i].internalUriReference, 961 rtl::OUString::createFromAscii(data[i].externalUriReference), 962 translator->translateToExternal( 963 rtl::OUString::createFromAscii(data[i].internalUriReference))); 964 } 965 } 966 967 void Test::testPkgUrlFactory() { 968 struct Data { 969 char const * authority; 970 char const * result; 971 }; 972 Data data[] = { 973 { "a/b/c", 0 }, 974 { "file:///#foo", 0 }, 975 { "file:///a%25b%2fc/d~e&f@g?h", 976 "vnd.sun.star.pkg://file:%2F%2F%2Fa%2525b%252fc%2Fd~e&f@g%3Fh" } }; 977 css::uno::Reference< css::uri::XVndSunStarPkgUrlReferenceFactory > factory( 978 css::uri::VndSunStarPkgUrlReferenceFactory::create(m_context)); 979 for (std::size_t i = 0; i < sizeof data / sizeof data[0]; ++i) { 980 css::uno::Reference< css::uri::XUriReference > url( 981 factory->createVndSunStarPkgUrlReference( 982 m_uriFactory->parse( 983 rtl::OUString::createFromAscii(data[i].authority)))); 984 TEST_ASSERT_EQUAL( 985 "testVndSunStarPkgFactory", i, data[i].authority, 986 data[i].result != 0, static_cast< bool >(url.is())); 987 if (data[i].result != 0) { 988 TEST_ASSERT_EQUAL( 989 "testVndSunStarPkgFactory", i, data[i].authority, 990 rtl::OUString::createFromAscii(data[i].result), 991 url->getUriReference()); 992 } 993 } 994 } 995 996 CPPUNIT_TEST_SUITE_REGISTRATION(Test); 997 998 } 999 1000 CPPUNIT_PLUGIN_IMPLEMENT(); 1001