LCOV - code coverage report
Current view: top level - sal/qa/rtl/uri - rtl_testuri.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 164 168 97.6 %
Date: 2014-11-03 Functions: 9 9 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <config_locales.h>
      21             : 
      22             : #include "rtl/strbuf.hxx"
      23             : #include "rtl/uri.hxx"
      24             : #include "rtl/ustrbuf.hxx"
      25             : 
      26             : #include <cppunit/TestFixture.h>
      27             : #include <cppunit/extensions/HelperMacros.h>
      28             : #include <cppunit/plugin/TestPlugIn.h>
      29             : 
      30             : #include <cstddef>
      31             : #include <stdio.h>
      32             : 
      33             : namespace {
      34             : 
      35           6 : struct Test: public CppUnit::TestFixture {
      36             :     void test_Uri();
      37             : 
      38           4 :     CPPUNIT_TEST_SUITE(Test);
      39           2 :     CPPUNIT_TEST(test_Uri);
      40           4 :     CPPUNIT_TEST_SUITE_END();
      41             : };
      42             : 
      43           2 : void Test::test_Uri() {
      44           2 :     rtl_UriCharClass const eFirstCharClass = rtl_UriCharClassNone;
      45           2 :     rtl_UriCharClass const eLastCharClass = rtl_UriCharClassUnoParamValue;
      46             : 
      47           2 :     rtl::OUStringBuffer aBuffer;
      48           4 :     rtl::OUString aText1;
      49           4 :     rtl::OUString aText2;
      50             : 
      51             :     // Check that all characters map back to themselves when encoded/decoded:
      52             : 
      53           4 :     aText1 = rtl::OUString(
      54             :         RTL_CONSTASCII_USTRINGPARAM(
      55             :             "\x00\x01\x02\x03\x04\x05\x06\x07"
      56             :             "\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F"
      57             :             "\x10\x11\x12\x13\x14\x15\x16\x17"
      58             :             "\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"
      59             :             "\x20\x21\x22\x23\x24\x25\x26\x27"
      60             :             "\x28\x29\x2A\x2B\x2C\x2D\x2E\x2F"
      61             :             "\x30\x31\x32\x33\x34\x35\x36\x37"
      62             :             "\x38\x39\x3A\x3B\x3C\x3D\x3E\x3F"
      63             :             "\x40\x41\x42\x43\x44\x45\x46\x47"
      64             :             "\x48\x49\x4A\x4B\x4C\x4D\x4E\x4F"
      65             :             "\x50\x51\x52\x53\x54\x55\x56\x57"
      66             :             "\x58\x59\x5A\x5B\x5C\x5D\x5E\x5F"
      67             :             "\x60\x61\x62\x63\x64\x65\x66\x67"
      68             :             "\x68\x69\x6A\x6B\x6C\x6D\x6E\x6F"
      69             :             "\x70\x71\x72\x73\x74\x75\x76\x77"
      70           2 :             "\x78\x79\x7A\x7B\x7C\x7D\x7E\x7F"));
      71           2 :     aText2 = aText1;
      72          36 :     for (rtl_UriCharClass eCharClass = eFirstCharClass;
      73          18 :          eCharClass <= eLastCharClass;
      74          16 :          eCharClass = static_cast< rtl_UriCharClass >(eCharClass + 1))
      75             :     {
      76          32 :         CPPUNIT_ASSERT_MESSAGE(
      77             :             "failure 1",
      78             :             (rtl::Uri::decode(
      79             :                 rtl::Uri::encode(
      80             :                     aText1, eCharClass, rtl_UriEncodeKeepEscapes,
      81             :                     RTL_TEXTENCODING_ISO_8859_1),
      82             :                 rtl_UriDecodeWithCharset, RTL_TEXTENCODING_ASCII_US)
      83          16 :              == aText2));
      84          32 :         CPPUNIT_ASSERT_MESSAGE(
      85             :             "failure 2",
      86             :             (rtl::Uri::decode(
      87             :                 rtl::Uri::encode(
      88             :                     aText1, eCharClass, rtl_UriEncodeCheckEscapes,
      89             :                     RTL_TEXTENCODING_ISO_8859_1),
      90             :                 rtl_UriDecodeWithCharset, RTL_TEXTENCODING_ASCII_US)
      91          16 :              == aText2));
      92          32 :         CPPUNIT_ASSERT_MESSAGE(
      93             :             "failure 3",
      94             :             (rtl::Uri::decode(
      95             :                 rtl::Uri::encode(
      96             :                     aText1, eCharClass, rtl_UriEncodeKeepEscapes,
      97             :                     RTL_TEXTENCODING_ISO_8859_1),
      98             :                 rtl_UriDecodeWithCharset, RTL_TEXTENCODING_ISO_8859_1)
      99          16 :              == aText2));
     100          32 :         CPPUNIT_ASSERT_MESSAGE(
     101             :             "failure 4",
     102             :             (rtl::Uri::decode(
     103             :                 rtl::Uri::encode(
     104             :                     aText1, eCharClass, rtl_UriEncodeCheckEscapes,
     105             :                     RTL_TEXTENCODING_ISO_8859_1),
     106             :                 rtl_UriDecodeWithCharset, RTL_TEXTENCODING_ISO_8859_1)
     107          16 :              == aText2));
     108          32 :         CPPUNIT_ASSERT_MESSAGE(
     109             :             "failure 5",
     110             :             (rtl::Uri::decode(
     111             :                 rtl::Uri::encode(
     112             :                     aText1, eCharClass, rtl_UriEncodeKeepEscapes,
     113             :                     RTL_TEXTENCODING_ISO_8859_1),
     114             :                 rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8)
     115          16 :              == aText2));
     116          32 :         CPPUNIT_ASSERT_MESSAGE(
     117             :             "failure 6",
     118             :             (rtl::Uri::decode(
     119             :                 rtl::Uri::encode(
     120             :                     aText1, eCharClass, rtl_UriEncodeCheckEscapes,
     121             :                     RTL_TEXTENCODING_ISO_8859_1),
     122             :                 rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8)
     123          16 :              == aText2));
     124             :     }
     125             : 
     126           4 :     aText1 = rtl::OUString(
     127             :         ("\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F"
     128             :          "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"
     129             :          "\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2A\x2B\x2C\x2D\x2E\x2F"
     130             :          "\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3A\x3B\x3C\x3D\x3E\x3F"
     131             :          "\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4A\x4B\x4C\x4D\x4E\x4F"
     132             :          "\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5A\x5B\x5C\x5D\x5E\x5F"
     133             :          "\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6A\x6B\x6C\x6D\x6E\x6F"
     134             :          "\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7A\x7B\x7C\x7D\x7E\x7F"
     135             :          "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x8D\x8E\x8F"
     136             :          "\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9D\x9E\x9F"
     137             :          "\xA0\xA1\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xAA\xAB\xAC\xAD\xAE\xAF"
     138             :          "\xB0\xB1\xB2\xB3\xB4\xB5\xB6\xB7\xB8\xB9\xBA\xBB\xBC\xBD\xBE\xBF"
     139             :          "\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF"
     140             :          "\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD7\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF"
     141             :          "\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF"
     142             :          "\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xFF"),
     143           2 :         256, RTL_TEXTENCODING_ISO_8859_1);
     144           2 :     aText2 = aText1;
     145          36 :     for (rtl_UriCharClass eCharClass = eFirstCharClass;
     146          18 :          eCharClass <= eLastCharClass;
     147          16 :          eCharClass = static_cast< rtl_UriCharClass >(eCharClass + 1))
     148             :     {
     149          32 :         CPPUNIT_ASSERT_MESSAGE(
     150             :             "failure 7",
     151             :             (rtl::Uri::decode(
     152             :                 rtl::Uri::encode(
     153             :                     aText1, eCharClass, rtl_UriEncodeKeepEscapes,
     154             :                     RTL_TEXTENCODING_ISO_8859_1),
     155             :                 rtl_UriDecodeWithCharset, RTL_TEXTENCODING_ISO_8859_1)
     156          16 :              == aText2));
     157          32 :         CPPUNIT_ASSERT_MESSAGE(
     158             :             "failure 8",
     159             :             (rtl::Uri::decode(
     160             :                 rtl::Uri::encode(
     161             :                     aText1, eCharClass, rtl_UriEncodeCheckEscapes,
     162             :                     RTL_TEXTENCODING_ISO_8859_1),
     163             :                 rtl_UriDecodeWithCharset, RTL_TEXTENCODING_ISO_8859_1)
     164          16 :              == aText2));
     165          32 :         CPPUNIT_ASSERT_MESSAGE(
     166             :             "failure 9",
     167             :             (rtl::Uri::decode(
     168             :                 rtl::Uri::encode(
     169             :                     aText1, eCharClass, rtl_UriEncodeKeepEscapes,
     170             :                     RTL_TEXTENCODING_UTF8),
     171             :                 rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8)
     172          16 :              == aText2));
     173          32 :         CPPUNIT_ASSERT_MESSAGE(
     174             :             "failure 10",
     175             :             (rtl::Uri::decode(
     176             :                 rtl::Uri::encode(
     177             :                     aText1, eCharClass, rtl_UriEncodeCheckEscapes,
     178             :                     RTL_TEXTENCODING_UTF8),
     179             :                 rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8)
     180          16 :              == aText2));
     181             :     }
     182             : 
     183             :     // Check surrogate handling:
     184             : 
     185           2 :     aBuffer.append(static_cast< sal_Unicode >(0xD800)); // %ED%A0%80
     186           2 :     aBuffer.append(static_cast< sal_Unicode >(0xD800)); // %F0%90%8F%BF
     187           2 :     aBuffer.append(static_cast< sal_Unicode >(0xDFFF));
     188           2 :     aBuffer.append(static_cast< sal_Unicode >(0xDFFF)); // %ED%BF%BF
     189           2 :     aBuffer.append('A'); // A
     190           2 :     aText1 = aBuffer.makeStringAndClear();
     191           4 :     aText2 = rtl::OUString(
     192           2 :             "%ED%A0%80" "%F0%90%8F%BF" "%ED%BF%BF" "A");
     193           4 :     CPPUNIT_ASSERT_MESSAGE(
     194             :         "failure 11",
     195             :         (rtl::Uri::encode(
     196             :             aText1, rtl_UriCharClassUric, rtl_UriEncodeIgnoreEscapes,
     197             :             RTL_TEXTENCODING_UTF8)
     198           2 :          == aText2));
     199           4 :     CPPUNIT_ASSERT_MESSAGE(
     200             :         "failure 12",
     201             :         (rtl::Uri::encode(
     202             :             aText1, rtl_UriCharClassUric, rtl_UriEncodeKeepEscapes,
     203             :             RTL_TEXTENCODING_UTF8)
     204           2 :          == aText2));
     205           4 :     CPPUNIT_ASSERT_MESSAGE(
     206             :         "failure 13",
     207             :         (rtl::Uri::encode(
     208             :             aText1, rtl_UriCharClassUric, rtl_UriEncodeCheckEscapes,
     209             :             RTL_TEXTENCODING_UTF8)
     210           2 :          == aText2));
     211             : 
     212           4 :     aText1 = rtl::OUString(
     213           2 :             "%ed%a0%80" "%f0%90%8f%bf" "%ed%bf%bf" "A");
     214           2 :     aBuffer.append("%ED%A0%80");
     215           2 :     aBuffer.append(static_cast< sal_Unicode >(0xD800));
     216           2 :     aBuffer.append(static_cast< sal_Unicode >(0xDFFF));
     217           2 :     aBuffer.append("%ED%BF%BF");
     218           2 :     aBuffer.append('A');
     219           2 :     aText2 = aBuffer.makeStringAndClear();
     220           4 :     CPPUNIT_ASSERT_MESSAGE(
     221             :         "failure 14",
     222             :         (rtl::Uri::decode(aText1, rtl_UriDecodeToIuri, RTL_TEXTENCODING_UTF8)
     223           2 :          == aText2));
     224           4 :     CPPUNIT_ASSERT_MESSAGE(
     225             :         "failure 15",
     226             :         (rtl::Uri::decode(
     227             :             aText1, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8)
     228           2 :          == aText2));
     229             : 
     230             :     // Check UTF-8 handling:
     231             : 
     232           2 :     aText1 = rtl::OUString("%E0%83%BF");
     233             :         // \U+00FF encoded with three instead of two bytes
     234           2 :     aText2 = aText1;
     235           4 :     CPPUNIT_ASSERT_MESSAGE(
     236             :         "failure 16",
     237             :         (rtl::Uri::encode(
     238             :             aText1, rtl_UriCharClassUric, rtl_UriEncodeCheckEscapes,
     239             :             RTL_TEXTENCODING_UTF8)
     240           2 :          == aText2));
     241             : 
     242           2 :     aText1 = rtl::OUString("%EF%BF%BF");
     243             :         // \U+FFFF is no legal character
     244           2 :     aText2 = aText1;
     245           4 :     CPPUNIT_ASSERT_MESSAGE(
     246             :         "failure 17",
     247             :         (rtl::Uri::encode(
     248             :             aText1, rtl_UriCharClassUric, rtl_UriEncodeCheckEscapes,
     249             :             RTL_TEXTENCODING_UTF8)
     250           2 :          == aText2));
     251             : 
     252             :     // Check IURI handling:
     253             : 
     254           2 :     aText1 = rtl::OUString("%30%C3%BF");
     255           2 :     aBuffer.append("%30");
     256           2 :     aBuffer.append(static_cast< sal_Unicode >(0x00FF));
     257           2 :     aText2 = aBuffer.makeStringAndClear();
     258           4 :     CPPUNIT_ASSERT_MESSAGE(
     259             :         "failure 18",
     260             :         (rtl::Uri::decode(aText1, rtl_UriDecodeToIuri, RTL_TEXTENCODING_UTF8)
     261           2 :          == aText2));
     262             : 
     263             :     // Check modified rtl_UriCharClassUnoParamValue (removed '[' and ']'):
     264             : 
     265           2 :     aText1 = rtl::OUString("[]%5B%5D");
     266           2 :     aText2 = rtl::OUString("%5B%5D%5B%5D");
     267           4 :     CPPUNIT_ASSERT_MESSAGE(
     268             :         "failure 19",
     269             :         (rtl::Uri::encode(
     270             :             aText1, rtl_UriCharClassUnoParamValue, rtl_UriEncodeCheckEscapes,
     271             :             RTL_TEXTENCODING_ASCII_US)
     272           2 :          == aText2));
     273             : 
     274             :     // Check Uri::convertRelToAbs:
     275             : 
     276             :     struct RelToAbsTest
     277             :     {
     278             :         char const * pBase;
     279             :         char const * pRel;
     280             :         char const * pAbs;
     281             :     };
     282             :     static RelToAbsTest const aRelToAbsTest[]
     283             :         = { // The following tests are taken from RFC 3986:
     284             :             { "http://a/b/c/d;p?q", "g:h", "g:h" },
     285             :             { "http://a/b/c/d;p?q", "g", "http://a/b/c/g" },
     286             :             { "http://a/b/c/d;p?q", "./g", "http://a/b/c/g" },
     287             :             { "http://a/b/c/d;p?q", "g/", "http://a/b/c/g/" },
     288             :             { "http://a/b/c/d;p?q", "/g", "http://a/g" },
     289             :             { "http://a/b/c/d;p?q", "//g", "http://g" },
     290             :             { "http://a/b/c/d;p?q", "?y", "http://a/b/c/d;p?y" },
     291             :             { "http://a/b/c/d;p?q", "g?y", "http://a/b/c/g?y" },
     292             :             { "http://a/b/c/d;p?q", "#s", "http://a/b/c/d;p?q#s" },
     293             :             { "http://a/b/c/d;p?q", "g#s", "http://a/b/c/g#s" },
     294             :             { "http://a/b/c/d;p?q", "g?y#s", "http://a/b/c/g?y#s" },
     295             :             { "http://a/b/c/d;p?q", ";x", "http://a/b/c/;x" },
     296             :             { "http://a/b/c/d;p?q", "g;x", "http://a/b/c/g;x" },
     297             :             { "http://a/b/c/d;p?q", "g;x?y#s", "http://a/b/c/g;x?y#s" },
     298             :             { "http://a/b/c/d;p?q", "", "http://a/b/c/d;p?q" },
     299             :             { "http://a/b/c/d;p?q", ".", "http://a/b/c/" },
     300             :             { "http://a/b/c/d;p?q", "./", "http://a/b/c/" },
     301             :             { "http://a/b/c/d;p?q", "..", "http://a/b/" },
     302             :             { "http://a/b/c/d;p?q", "../", "http://a/b/" },
     303             :             { "http://a/b/c/d;p?q", "../g", "http://a/b/g" },
     304             :             { "http://a/b/c/d;p?q", "../..", "http://a/" },
     305             :             { "http://a/b/c/d;p?q", "../../", "http://a/" },
     306             :             { "http://a/b/c/d;p?q", "../../g", "http://a/g" },
     307             :             { "http://a/b/c/d;p?q", "../../../g", "http://a/g" },
     308             :             { "http://a/b/c/d;p?q", "../../../../g", "http://a/g" },
     309             :             { "http://a/b/c/d;p?q", "/./g", "http://a/g" },
     310             :             { "http://a/b/c/d;p?q", "/../g", "http://a/g" },
     311             :             { "http://a/b/c/d;p?q", "g.", "http://a/b/c/g." },
     312             :             { "http://a/b/c/d;p?q", ".g", "http://a/b/c/.g" },
     313             :             { "http://a/b/c/d;p?q", "g..", "http://a/b/c/g.." },
     314             :             { "http://a/b/c/d;p?q", "..g", "http://a/b/c/..g" },
     315             :             { "http://a/b/c/d;p?q", "./../g", "http://a/b/g" },
     316             :             { "http://a/b/c/d;p?q", "./g/.", "http://a/b/c/g/" },
     317             :             { "http://a/b/c/d;p?q", "g/./h", "http://a/b/c/g/h" },
     318             :             { "http://a/b/c/d;p?q", "g/../h", "http://a/b/c/h" },
     319             :             { "http://a/b/c/d;p?q", "g;x=1/./y", "http://a/b/c/g;x=1/y" },
     320             :             { "http://a/b/c/d;p?q", "g;x=1/../y", "http://a/b/c/y" },
     321             :             { "http://a/b/c/d;p?q", "g?y/./x", "http://a/b/c/g?y/./x" },
     322             :             { "http://a/b/c/d;p?q", "g?y/../x", "http://a/b/c/g?y/../x" },
     323             :             { "http://a/b/c/d;p?q", "g#s/./x", "http://a/b/c/g#s/./x" },
     324             :             { "http://a/b/c/d;p?q", "g#s/../x", "http://a/b/c/g#s/../x" },
     325             :             { "http://a/b/c/d;p?q", "http:g", "http:g" },
     326             : 
     327             :             { "http!://a/b/c/d;p?q", "g:h", "g:h" },
     328             :             { "http!://a/b/c/d;p?q", "g", 0 },
     329             :             { "http:b/c/d;p?q", "g:h", "g:h" },
     330             :             { "http:b/c/d;p?q", "g", "http:b/c/g" },
     331             :             { "http://a/b/../", "../c", "http://a/c" },
     332             :             { "http://a/b/..", "../c", "http://a/c" },
     333             :             { "http://a/./b/", ".././.././../c", "http://a/c" },
     334             :             { "http://a", "b", "http://a/b" },
     335             :             { "", "http://a/b/../c", "http://a/c" } };
     336         104 :     for (std::size_t i = 0; i < sizeof aRelToAbsTest / sizeof (RelToAbsTest); ++i)
     337             :     {
     338         102 :         rtl::OUString aAbs;
     339         102 :         bool bMalformed = false;
     340             :         try {
     341         204 :             aAbs = rtl::Uri::convertRelToAbs(
     342             :                 rtl::OUString::createFromAscii(aRelToAbsTest[i].pBase),
     343         100 :                 rtl::OUString::createFromAscii(aRelToAbsTest[i].pRel));
     344           4 :         } catch (const rtl::MalformedUriException &) {
     345           2 :             bMalformed = true;
     346             :         }
     347         204 :         if (bMalformed
     348           2 :             ? aRelToAbsTest[i].pAbs != 0
     349         100 :             : (aRelToAbsTest[i].pAbs == 0
     350         100 :                || !aAbs.equalsAscii(aRelToAbsTest[i].pAbs)))
     351             :         {
     352             :             printf(
     353             :                 "FAILED convertRelToAbs(%s, %s) -> %s != %s\n",
     354             :                 aRelToAbsTest[i].pBase, aRelToAbsTest[i].pRel,
     355             :                 (bMalformed
     356             :                  ? "<MALFORMED>"
     357             :                  : rtl::OUStringToOString(
     358           0 :                      aAbs, RTL_TEXTENCODING_UTF8).getStr()),
     359           0 :                 (aRelToAbsTest[i].pAbs == 0
     360           0 :                  ? "<MALFORMED>" : aRelToAbsTest[i].pAbs));
     361           0 :             CPPUNIT_ASSERT(false);
     362             :         }
     363         102 :     }
     364             : 
     365             :     // Check encode with unusual text encodings:
     366             : 
     367             :     {
     368           2 :         sal_Unicode const aText1U[] = { ' ', '!', 0x0401, 0x045F, 0 };
     369           2 :         aText1 = rtl::OUString(aText1U);
     370           2 :         aText2 = rtl::OUString("%20!%A1%FF");
     371           4 :         CPPUNIT_ASSERT_MESSAGE(
     372             :             "failure 20",
     373             :             (rtl::Uri::encode(
     374             :                 aText1, rtl_UriCharClassUric, rtl_UriEncodeIgnoreEscapes,
     375             :                 RTL_TEXTENCODING_ISO_8859_5)
     376           2 :              == aText2));
     377           4 :         CPPUNIT_ASSERT_MESSAGE(
     378             :             "failure 20a",
     379             :             (rtl::Uri::decode(
     380             :                 aText2, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_ISO_8859_5)
     381           2 :              == aText1));
     382             :     }
     383             :     {
     384           2 :         sal_Unicode const aText1U[] = { ' ', '!', 0x0401, 0x0700, 0x045F, 0 };
     385           2 :         aText1 = rtl::OUString(aText1U);
     386             :         sal_Unicode const aText2U[] = {
     387           2 :             '%', '2', '0', '!', '%', 'A', '1', 0x0700, '%', 'F', 'F', 0 };
     388           2 :         aText2 = rtl::OUString(aText2U);
     389           4 :         CPPUNIT_ASSERT_MESSAGE(
     390             :             "failure 21",
     391             :             (rtl::Uri::encode(
     392             :                 aText1, rtl_UriCharClassUric, rtl_UriEncodeIgnoreEscapes,
     393             :                 RTL_TEXTENCODING_ISO_8859_5)
     394           2 :              == aText2));
     395           4 :         CPPUNIT_ASSERT_MESSAGE(
     396             :             "failure 21a",
     397             :             (rtl::Uri::decode(
     398             :                 aText2, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_ISO_8859_5)
     399           2 :              == aText1));
     400             :     }
     401             : #if WITH_LOCALE_ALL || WITH_LOCALE_zh
     402             :     {
     403           2 :         sal_Unicode const aText1U[] = { ' ', '!', 0x028A, 0xD849, 0xDD13, 0 };
     404           2 :         aText1 = rtl::OUString(aText1U);
     405           2 :         aText2 = rtl::OUString("%20!%81%30%B1%33%95%39%C5%37");
     406           4 :         CPPUNIT_ASSERT_MESSAGE(
     407             :             "failure 22",
     408             :             (rtl::Uri::encode(
     409             :                 aText1, rtl_UriCharClassUric, rtl_UriEncodeIgnoreEscapes,
     410             :                 RTL_TEXTENCODING_GB_18030)
     411           2 :              == aText2));
     412           4 :         CPPUNIT_ASSERT_MESSAGE(
     413             :             "failure 22a",
     414             :             (rtl::Uri::decode(
     415             :                 aText2, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_GB_18030)
     416           2 :              == aText1));
     417             :     }
     418             : #endif
     419             :     // Check strict mode:
     420             : 
     421             :     {
     422           2 :         sal_Unicode const aText1U[] = { ' ', '!', 0x0401, 0x0700, 0x045F, 0 };
     423           2 :         aText1 = rtl::OUString(aText1U);
     424           2 :         aText2 = rtl::OUString();
     425           4 :         CPPUNIT_ASSERT_MESSAGE(
     426             :             "failure 23",
     427             :             (rtl::Uri::encode(
     428             :                 aText1, rtl_UriCharClassUric, rtl_UriEncodeStrict,
     429             :                 RTL_TEXTENCODING_ISO_8859_5)
     430           2 :              == aText2));
     431             :     }
     432             :     {
     433           2 :         aText1 = rtl::OUString("%20%C4%80%FF");
     434           2 :         aText2 = rtl::OUString();
     435           4 :         CPPUNIT_ASSERT_MESSAGE(
     436             :             "failure 24",
     437             :             (rtl::Uri::decode(
     438             :                 aText1, rtl_UriDecodeStrict, RTL_TEXTENCODING_UTF8)
     439           2 :              == aText2));
     440             :     }
     441             : #if WITH_LOCALE_ALL || WITH_LOCALE_zh
     442             :     {
     443           2 :         aText1 = rtl::OUString("%81 ");
     444           2 :         aText2 = rtl::OUString();
     445           4 :         CPPUNIT_ASSERT_MESSAGE(
     446             :             "failure 25",
     447             :             (rtl::Uri::decode(
     448             :                 aText1, rtl_UriDecodeStrict, RTL_TEXTENCODING_GB_18030)
     449           2 :              == aText2));
     450             :     }
     451             :     {
     452           2 :         aText1 = rtl::OUString("%81%20");
     453           2 :         aText2 = rtl::OUString();
     454           4 :         CPPUNIT_ASSERT_MESSAGE(
     455             :             "failure 26",
     456             :             (rtl::Uri::decode(
     457             :                 aText1, rtl_UriDecodeStrict, RTL_TEXTENCODING_GB_18030)
     458           2 :              == aText2));
     459             :     }
     460             :     {
     461           2 :         aText1 = rtl::OUString("%81%30%B1%33");
     462           2 :         sal_Unicode const aText2U[] = { 0x028A, 0 };
     463           2 :         aText2 = rtl::OUString(aText2U);
     464           4 :         CPPUNIT_ASSERT_MESSAGE(
     465             :             "failure 27",
     466             :             (rtl::Uri::decode(
     467             :                 aText1, rtl_UriDecodeStrict, RTL_TEXTENCODING_GB_18030)
     468           2 :              == aText2));
     469             :     }
     470             :     {
     471           2 :         aText1 = rtl::OUString("%810%B13");
     472           2 :         sal_Unicode const aText2U[] = { 0x028A, 0 };
     473           2 :         aText2 = rtl::OUString(aText2U);
     474           4 :         CPPUNIT_ASSERT_MESSAGE(
     475             :             "failure 28",
     476             :             (rtl::Uri::decode(
     477             :                 aText1, rtl_UriDecodeStrict, RTL_TEXTENCODING_GB_18030)
     478           2 :              == aText2));
     479             :     }
     480             : #endif
     481             :     // Check rtl_UriEncodeStrictKeepEscapes mode:
     482             : 
     483             :     {
     484           2 :         aText1 = rtl::OUString("%%ea%c3%aa");
     485           2 :         aText2 = rtl::OUString("%25%EA%C3%AA");
     486           4 :         CPPUNIT_ASSERT_MESSAGE(
     487             :             "failure 29",
     488             :             (rtl::Uri::encode(
     489             :                 aText1, rtl_UriCharClassUric, rtl_UriEncodeStrictKeepEscapes,
     490             :                 RTL_TEXTENCODING_UTF8)
     491           2 :              == aText2));
     492             :     }
     493             :     {
     494           2 :         sal_Unicode const aText1U[] = { 0x00EA, 0 };
     495           2 :         aText1 = rtl::OUString(aText1U);
     496           2 :         aText2 = rtl::OUString("%C3%AA");
     497           4 :         CPPUNIT_ASSERT_MESSAGE(
     498             :             "failure 30",
     499             :             (rtl::Uri::encode(
     500             :                 aText1, rtl_UriCharClassUric, rtl_UriEncodeStrictKeepEscapes,
     501             :                 RTL_TEXTENCODING_UTF8)
     502           2 :              == aText2));
     503             :     }
     504             :     {
     505           2 :         sal_Unicode const aText1U[] = { ' ', '!', 0x0401, 0x0700, 0x045F, 0 };
     506           2 :         aText1 = rtl::OUString(aText1U);
     507           2 :         aText2 = rtl::OUString();
     508           4 :         CPPUNIT_ASSERT_MESSAGE(
     509             :             "failure 23",
     510             :             (rtl::Uri::encode(
     511             :                 aText1, rtl_UriCharClassUric, rtl_UriEncodeStrictKeepEscapes,
     512             :                 RTL_TEXTENCODING_ISO_8859_5)
     513           2 :              == aText2));
     514           2 :     }
     515           2 : }
     516             : 
     517             : }
     518             : 
     519           6 : CPPUNIT_TEST_SUITE_REGISTRATION(Test);
     520             : // NOADDITIONAL;
     521             : 
     522             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10