LCOV - code coverage report
Current view: top level - sal/qa/rtl/uri - rtl_testuri.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 162 166 97.6 %
Date: 2015-06-13 12:38:46 Functions: 12 12 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           3 : struct Test: public CppUnit::TestFixture {
      36             :     void test_Uri();
      37             : 
      38           2 :     CPPUNIT_TEST_SUITE(Test);
      39           1 :     CPPUNIT_TEST(test_Uri);
      40           5 :     CPPUNIT_TEST_SUITE_END();
      41             : };
      42             : 
      43           1 : void Test::test_Uri() {
      44           1 :     rtl_UriCharClass const eFirstCharClass = rtl_UriCharClassNone;
      45           1 :     rtl_UriCharClass const eLastCharClass = rtl_UriCharClassUnoParamValue;
      46             : 
      47           1 :     rtl::OUStringBuffer aBuffer;
      48           2 :     rtl::OUString aText1;
      49           2 :     rtl::OUString aText2;
      50             : 
      51             :     // Check that all characters map back to themselves when encoded/decoded:
      52             : 
      53           2 :     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           1 :             "\x78\x79\x7A\x7B\x7C\x7D\x7E\x7F"));
      71           1 :     aText2 = aText1;
      72          18 :     for (rtl_UriCharClass eCharClass = eFirstCharClass;
      73           9 :          eCharClass <= eLastCharClass;
      74           8 :          eCharClass = static_cast< rtl_UriCharClass >(eCharClass + 1))
      75             :     {
      76          16 :         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           8 :              == aText2));
      84          16 :         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           8 :              == aText2));
      92          16 :         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           8 :              == aText2));
     100          16 :         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           8 :              == aText2));
     108          16 :         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           8 :              == aText2));
     116          16 :         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           8 :              == aText2));
     124             :     }
     125             : 
     126           2 :     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           1 :         256, RTL_TEXTENCODING_ISO_8859_1);
     144           1 :     aText2 = aText1;
     145          18 :     for (rtl_UriCharClass eCharClass = eFirstCharClass;
     146           9 :          eCharClass <= eLastCharClass;
     147           8 :          eCharClass = static_cast< rtl_UriCharClass >(eCharClass + 1))
     148             :     {
     149          16 :         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           8 :              == aText2));
     157          16 :         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           8 :              == aText2));
     165          16 :         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           8 :              == aText2));
     173          16 :         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           8 :              == aText2));
     181             :     }
     182             : 
     183             :     // Check surrogate handling:
     184             : 
     185           1 :     aBuffer.append(static_cast< sal_Unicode >(0xD800)); // %ED%A0%80
     186           1 :     aBuffer.append(static_cast< sal_Unicode >(0xD800)); // %F0%90%8F%BF
     187           1 :     aBuffer.append(static_cast< sal_Unicode >(0xDFFF));
     188           1 :     aBuffer.append(static_cast< sal_Unicode >(0xDFFF)); // %ED%BF%BF
     189           1 :     aBuffer.append('A'); // A
     190           1 :     aText1 = aBuffer.makeStringAndClear();
     191           1 :     aText2 = "%ED%A0%80" "%F0%90%8F%BF" "%ED%BF%BF" "A";
     192           2 :     CPPUNIT_ASSERT_MESSAGE(
     193             :         "failure 11",
     194             :         (rtl::Uri::encode(
     195             :             aText1, rtl_UriCharClassUric, rtl_UriEncodeIgnoreEscapes,
     196             :             RTL_TEXTENCODING_UTF8)
     197           1 :          == aText2));
     198           2 :     CPPUNIT_ASSERT_MESSAGE(
     199             :         "failure 12",
     200             :         (rtl::Uri::encode(
     201             :             aText1, rtl_UriCharClassUric, rtl_UriEncodeKeepEscapes,
     202             :             RTL_TEXTENCODING_UTF8)
     203           1 :          == aText2));
     204           2 :     CPPUNIT_ASSERT_MESSAGE(
     205             :         "failure 13",
     206             :         (rtl::Uri::encode(
     207             :             aText1, rtl_UriCharClassUric, rtl_UriEncodeCheckEscapes,
     208             :             RTL_TEXTENCODING_UTF8)
     209           1 :          == aText2));
     210             : 
     211           1 :     aText1 = "%ed%a0%80" "%f0%90%8f%bf" "%ed%bf%bf" "A";
     212           1 :     aBuffer.append("%ED%A0%80");
     213           1 :     aBuffer.append(static_cast< sal_Unicode >(0xD800));
     214           1 :     aBuffer.append(static_cast< sal_Unicode >(0xDFFF));
     215           1 :     aBuffer.append("%ED%BF%BF");
     216           1 :     aBuffer.append('A');
     217           1 :     aText2 = aBuffer.makeStringAndClear();
     218           2 :     CPPUNIT_ASSERT_MESSAGE(
     219             :         "failure 14",
     220             :         (rtl::Uri::decode(aText1, rtl_UriDecodeToIuri, RTL_TEXTENCODING_UTF8)
     221           1 :          == aText2));
     222           2 :     CPPUNIT_ASSERT_MESSAGE(
     223             :         "failure 15",
     224             :         (rtl::Uri::decode(
     225             :             aText1, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8)
     226           1 :          == aText2));
     227             : 
     228             :     // Check UTF-8 handling:
     229             : 
     230           1 :     aText1 = "%E0%83%BF";
     231             :         // \U+00FF encoded with three instead of two bytes
     232           1 :     aText2 = aText1;
     233           2 :     CPPUNIT_ASSERT_MESSAGE(
     234             :         "failure 16",
     235             :         (rtl::Uri::encode(
     236             :             aText1, rtl_UriCharClassUric, rtl_UriEncodeCheckEscapes,
     237             :             RTL_TEXTENCODING_UTF8)
     238           1 :          == aText2));
     239             : 
     240           1 :     aText1 = "%EF%BF%BF";
     241             :         // \U+FFFF is no legal character
     242           1 :     aText2 = aText1;
     243           2 :     CPPUNIT_ASSERT_MESSAGE(
     244             :         "failure 17",
     245             :         (rtl::Uri::encode(
     246             :             aText1, rtl_UriCharClassUric, rtl_UriEncodeCheckEscapes,
     247             :             RTL_TEXTENCODING_UTF8)
     248           1 :          == aText2));
     249             : 
     250             :     // Check IURI handling:
     251             : 
     252           1 :     aText1 = "%30%C3%BF";
     253           1 :     aBuffer.append("%30");
     254           1 :     aBuffer.append(static_cast< sal_Unicode >(0x00FF));
     255           1 :     aText2 = aBuffer.makeStringAndClear();
     256           2 :     CPPUNIT_ASSERT_MESSAGE(
     257             :         "failure 18",
     258             :         (rtl::Uri::decode(aText1, rtl_UriDecodeToIuri, RTL_TEXTENCODING_UTF8)
     259           1 :          == aText2));
     260             : 
     261             :     // Check modified rtl_UriCharClassUnoParamValue (removed '[' and ']'):
     262             : 
     263           1 :     aText1 = "[]%5B%5D";
     264           1 :     aText2 = "%5B%5D%5B%5D";
     265           2 :     CPPUNIT_ASSERT_MESSAGE(
     266             :         "failure 19",
     267             :         (rtl::Uri::encode(
     268             :             aText1, rtl_UriCharClassUnoParamValue, rtl_UriEncodeCheckEscapes,
     269             :             RTL_TEXTENCODING_ASCII_US)
     270           1 :          == aText2));
     271             : 
     272             :     // Check Uri::convertRelToAbs:
     273             : 
     274             :     struct RelToAbsTest
     275             :     {
     276             :         char const * pBase;
     277             :         char const * pRel;
     278             :         char const * pAbs;
     279             :     };
     280             :     static RelToAbsTest const aRelToAbsTest[]
     281             :         = { // The following tests are taken from RFC 3986:
     282             :             { "http://a/b/c/d;p?q", "g:h", "g:h" },
     283             :             { "http://a/b/c/d;p?q", "g", "http://a/b/c/g" },
     284             :             { "http://a/b/c/d;p?q", "./g", "http://a/b/c/g" },
     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/g" },
     287             :             { "http://a/b/c/d;p?q", "//g", "http://g" },
     288             :             { "http://a/b/c/d;p?q", "?y", "http://a/b/c/d;p?y" },
     289             :             { "http://a/b/c/d;p?q", "g?y", "http://a/b/c/g?y" },
     290             :             { "http://a/b/c/d;p?q", "#s", "http://a/b/c/d;p?q#s" },
     291             :             { "http://a/b/c/d;p?q", "g#s", "http://a/b/c/g#s" },
     292             :             { "http://a/b/c/d;p?q", "g?y#s", "http://a/b/c/g?y#s" },
     293             :             { "http://a/b/c/d;p?q", ";x", "http://a/b/c/;x" },
     294             :             { "http://a/b/c/d;p?q", "g;x", "http://a/b/c/g;x" },
     295             :             { "http://a/b/c/d;p?q", "g;x?y#s", "http://a/b/c/g;x?y#s" },
     296             :             { "http://a/b/c/d;p?q", "", "http://a/b/c/d;p?q" },
     297             :             { "http://a/b/c/d;p?q", ".", "http://a/b/c/" },
     298             :             { "http://a/b/c/d;p?q", "./", "http://a/b/c/" },
     299             :             { "http://a/b/c/d;p?q", "..", "http://a/b/" },
     300             :             { "http://a/b/c/d;p?q", "../", "http://a/b/" },
     301             :             { "http://a/b/c/d;p?q", "../g", "http://a/b/g" },
     302             :             { "http://a/b/c/d;p?q", "../..", "http://a/" },
     303             :             { "http://a/b/c/d;p?q", "../../", "http://a/" },
     304             :             { "http://a/b/c/d;p?q", "../../g", "http://a/g" },
     305             :             { "http://a/b/c/d;p?q", "../../../g", "http://a/g" },
     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/b/c/g." },
     310             :             { "http://a/b/c/d;p?q", ".g", "http://a/b/c/.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/g" },
     314             :             { "http://a/b/c/d;p?q", "./g/.", "http://a/b/c/g/" },
     315             :             { "http://a/b/c/d;p?q", "g/./h", "http://a/b/c/g/h" },
     316             :             { "http://a/b/c/d;p?q", "g/../h", "http://a/b/c/h" },
     317             :             { "http://a/b/c/d;p?q", "g;x=1/./y", "http://a/b/c/g;x=1/y" },
     318             :             { "http://a/b/c/d;p?q", "g;x=1/../y", "http://a/b/c/y" },
     319             :             { "http://a/b/c/d;p?q", "g?y/./x", "http://a/b/c/g?y/./x" },
     320             :             { "http://a/b/c/d;p?q", "g?y/../x", "http://a/b/c/g?y/../x" },
     321             :             { "http://a/b/c/d;p?q", "g#s/./x", "http://a/b/c/g#s/./x" },
     322             :             { "http://a/b/c/d;p?q", "g#s/../x", "http://a/b/c/g#s/../x" },
     323             :             { "http://a/b/c/d;p?q", "http:g", "http:g" },
     324             : 
     325             :             { "http!://a/b/c/d;p?q", "g:h", "g:h" },
     326             :             { "http!://a/b/c/d;p?q", "g", 0 },
     327             :             { "http:b/c/d;p?q", "g:h", "g:h" },
     328             :             { "http:b/c/d;p?q", "g", "http:b/c/g" },
     329             :             { "http://a/b/../", "../c", "http://a/c" },
     330             :             { "http://a/b/..", "../c", "http://a/c" },
     331             :             { "http://a/./b/", ".././.././../c", "http://a/c" },
     332             :             { "http://a", "b", "http://a/b" },
     333             :             { "", "http://a/b/../c", "http://a/c" } };
     334          52 :     for (std::size_t i = 0; i < sizeof aRelToAbsTest / sizeof (RelToAbsTest); ++i)
     335             :     {
     336          51 :         rtl::OUString aAbs;
     337          51 :         bool bMalformed = false;
     338             :         try {
     339         102 :             aAbs = rtl::Uri::convertRelToAbs(
     340             :                 rtl::OUString::createFromAscii(aRelToAbsTest[i].pBase),
     341          50 :                 rtl::OUString::createFromAscii(aRelToAbsTest[i].pRel));
     342           2 :         } catch (const rtl::MalformedUriException &) {
     343           1 :             bMalformed = true;
     344             :         }
     345         102 :         if (bMalformed
     346           1 :             ? aRelToAbsTest[i].pAbs != 0
     347          50 :             : (aRelToAbsTest[i].pAbs == 0
     348          50 :                || !aAbs.equalsAscii(aRelToAbsTest[i].pAbs)))
     349             :         {
     350             :             printf(
     351             :                 "FAILED convertRelToAbs(%s, %s) -> %s != %s\n",
     352             :                 aRelToAbsTest[i].pBase, aRelToAbsTest[i].pRel,
     353             :                 (bMalformed
     354             :                  ? "<MALFORMED>"
     355             :                  : rtl::OUStringToOString(
     356           0 :                      aAbs, RTL_TEXTENCODING_UTF8).getStr()),
     357           0 :                 (aRelToAbsTest[i].pAbs == 0
     358           0 :                  ? "<MALFORMED>" : aRelToAbsTest[i].pAbs));
     359           0 :             CPPUNIT_ASSERT(false);
     360             :         }
     361          51 :     }
     362             : 
     363             :     // Check encode with unusual text encodings:
     364             : 
     365             :     {
     366           1 :         sal_Unicode const aText1U[] = { ' ', '!', 0x0401, 0x045F, 0 };
     367           1 :         aText1 = rtl::OUString(aText1U);
     368           1 :         aText2 = "%20!%A1%FF";
     369           2 :         CPPUNIT_ASSERT_MESSAGE(
     370             :             "failure 20",
     371             :             (rtl::Uri::encode(
     372             :                 aText1, rtl_UriCharClassUric, rtl_UriEncodeIgnoreEscapes,
     373             :                 RTL_TEXTENCODING_ISO_8859_5)
     374           1 :              == aText2));
     375           2 :         CPPUNIT_ASSERT_MESSAGE(
     376             :             "failure 20a",
     377             :             (rtl::Uri::decode(
     378             :                 aText2, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_ISO_8859_5)
     379           1 :              == aText1));
     380             :     }
     381             :     {
     382           1 :         sal_Unicode const aText1U[] = { ' ', '!', 0x0401, 0x0700, 0x045F, 0 };
     383           1 :         aText1 = rtl::OUString(aText1U);
     384             :         sal_Unicode const aText2U[] = {
     385           1 :             '%', '2', '0', '!', '%', 'A', '1', 0x0700, '%', 'F', 'F', 0 };
     386           1 :         aText2 = rtl::OUString(aText2U);
     387           2 :         CPPUNIT_ASSERT_MESSAGE(
     388             :             "failure 21",
     389             :             (rtl::Uri::encode(
     390             :                 aText1, rtl_UriCharClassUric, rtl_UriEncodeIgnoreEscapes,
     391             :                 RTL_TEXTENCODING_ISO_8859_5)
     392           1 :              == aText2));
     393           2 :         CPPUNIT_ASSERT_MESSAGE(
     394             :             "failure 21a",
     395             :             (rtl::Uri::decode(
     396             :                 aText2, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_ISO_8859_5)
     397           1 :              == aText1));
     398             :     }
     399             : #if WITH_LOCALE_ALL || WITH_LOCALE_zh
     400             :     {
     401           1 :         sal_Unicode const aText1U[] = { ' ', '!', 0x028A, 0xD849, 0xDD13, 0 };
     402           1 :         aText1 = rtl::OUString(aText1U);
     403           1 :         aText2 = "%20!%81%30%B1%33%95%39%C5%37";
     404           2 :         CPPUNIT_ASSERT_MESSAGE(
     405             :             "failure 22",
     406             :             (rtl::Uri::encode(
     407             :                 aText1, rtl_UriCharClassUric, rtl_UriEncodeIgnoreEscapes,
     408             :                 RTL_TEXTENCODING_GB_18030)
     409           1 :              == aText2));
     410           2 :         CPPUNIT_ASSERT_MESSAGE(
     411             :             "failure 22a",
     412             :             (rtl::Uri::decode(
     413             :                 aText2, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_GB_18030)
     414           1 :              == aText1));
     415             :     }
     416             : #endif
     417             :     // Check strict mode:
     418             : 
     419             :     {
     420           1 :         sal_Unicode const aText1U[] = { ' ', '!', 0x0401, 0x0700, 0x045F, 0 };
     421           1 :         aText1 = rtl::OUString(aText1U);
     422           1 :         aText2 = rtl::OUString();
     423           2 :         CPPUNIT_ASSERT_MESSAGE(
     424             :             "failure 23",
     425             :             (rtl::Uri::encode(
     426             :                 aText1, rtl_UriCharClassUric, rtl_UriEncodeStrict,
     427             :                 RTL_TEXTENCODING_ISO_8859_5)
     428           1 :              == aText2));
     429             :     }
     430             :     {
     431           1 :         aText1 = "%20%C4%80%FF";
     432           1 :         aText2 = rtl::OUString();
     433           2 :         CPPUNIT_ASSERT_MESSAGE(
     434             :             "failure 24",
     435             :             (rtl::Uri::decode(
     436             :                 aText1, rtl_UriDecodeStrict, RTL_TEXTENCODING_UTF8)
     437           1 :              == aText2));
     438             :     }
     439             : #if WITH_LOCALE_ALL || WITH_LOCALE_zh
     440             :     {
     441           1 :         aText1 = "%81 ";
     442           1 :         aText2 = rtl::OUString();
     443           2 :         CPPUNIT_ASSERT_MESSAGE(
     444             :             "failure 25",
     445             :             (rtl::Uri::decode(
     446             :                 aText1, rtl_UriDecodeStrict, RTL_TEXTENCODING_GB_18030)
     447           1 :              == aText2));
     448             :     }
     449             :     {
     450           1 :         aText1 = "%81%20";
     451           1 :         aText2 = rtl::OUString();
     452           2 :         CPPUNIT_ASSERT_MESSAGE(
     453             :             "failure 26",
     454             :             (rtl::Uri::decode(
     455             :                 aText1, rtl_UriDecodeStrict, RTL_TEXTENCODING_GB_18030)
     456           1 :              == aText2));
     457             :     }
     458             :     {
     459           1 :         aText1 = "%81%30%B1%33";
     460           1 :         sal_Unicode const aText2U[] = { 0x028A, 0 };
     461           1 :         aText2 = rtl::OUString(aText2U);
     462           2 :         CPPUNIT_ASSERT_MESSAGE(
     463             :             "failure 27",
     464             :             (rtl::Uri::decode(
     465             :                 aText1, rtl_UriDecodeStrict, RTL_TEXTENCODING_GB_18030)
     466           1 :              == aText2));
     467             :     }
     468             :     {
     469           1 :         aText1 = "%810%B13";
     470           1 :         sal_Unicode const aText2U[] = { 0x028A, 0 };
     471           1 :         aText2 = rtl::OUString(aText2U);
     472           2 :         CPPUNIT_ASSERT_MESSAGE(
     473             :             "failure 28",
     474             :             (rtl::Uri::decode(
     475             :                 aText1, rtl_UriDecodeStrict, RTL_TEXTENCODING_GB_18030)
     476           1 :              == aText2));
     477             :     }
     478             : #endif
     479             :     // Check rtl_UriEncodeStrictKeepEscapes mode:
     480             : 
     481             :     {
     482           1 :         aText1 = "%%ea%c3%aa";
     483           1 :         aText2 = "%25%EA%C3%AA";
     484           2 :         CPPUNIT_ASSERT_MESSAGE(
     485             :             "failure 29",
     486             :             (rtl::Uri::encode(
     487             :                 aText1, rtl_UriCharClassUric, rtl_UriEncodeStrictKeepEscapes,
     488             :                 RTL_TEXTENCODING_UTF8)
     489           1 :              == aText2));
     490             :     }
     491             :     {
     492           1 :         sal_Unicode const aText1U[] = { 0x00EA, 0 };
     493           1 :         aText1 = rtl::OUString(aText1U);
     494           1 :         aText2 = "%C3%AA";
     495           2 :         CPPUNIT_ASSERT_MESSAGE(
     496             :             "failure 30",
     497             :             (rtl::Uri::encode(
     498             :                 aText1, rtl_UriCharClassUric, rtl_UriEncodeStrictKeepEscapes,
     499             :                 RTL_TEXTENCODING_UTF8)
     500           1 :              == aText2));
     501             :     }
     502             :     {
     503           1 :         sal_Unicode const aText1U[] = { ' ', '!', 0x0401, 0x0700, 0x045F, 0 };
     504           1 :         aText1 = rtl::OUString(aText1U);
     505           1 :         aText2 = rtl::OUString();
     506           2 :         CPPUNIT_ASSERT_MESSAGE(
     507             :             "failure 23",
     508             :             (rtl::Uri::encode(
     509             :                 aText1, rtl_UriCharClassUric, rtl_UriEncodeStrictKeepEscapes,
     510             :                 RTL_TEXTENCODING_ISO_8859_5)
     511           1 :              == aText2));
     512           1 :     }
     513           1 : }
     514             : 
     515             : }
     516             : 
     517           3 : CPPUNIT_TEST_SUITE_REGISTRATION(Test);
     518             : // NOADDITIONAL;
     519             : 
     520             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11