LCOV - code coverage report
Current view: top level - sal/qa/rtl/uri - rtl_testuri.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 165 169 97.6 %
Date: 2014-04-11 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 "rtl/strbuf.hxx"
      21             : #include "rtl/uri.hxx"
      22             : #include "rtl/ustrbuf.hxx"
      23             : 
      24             : #include <cppunit/TestFixture.h>
      25             : #include <cppunit/extensions/HelperMacros.h>
      26             : #include <cppunit/plugin/TestPlugIn.h>
      27             : 
      28             : #include <cstddef>
      29             : #include <stdio.h>
      30             : 
      31             : namespace {
      32             : 
      33           3 : struct Test: public CppUnit::TestFixture {
      34             :     void test_Uri();
      35             : 
      36           2 :     CPPUNIT_TEST_SUITE(Test);
      37           1 :     CPPUNIT_TEST(test_Uri);
      38           2 :     CPPUNIT_TEST_SUITE_END();
      39             : };
      40             : 
      41           1 : void Test::test_Uri() {
      42           1 :     rtl_UriCharClass const eFirstCharClass = rtl_UriCharClassNone;
      43           1 :     rtl_UriCharClass const eLastCharClass = rtl_UriCharClassUnoParamValue;
      44             : 
      45           1 :     rtl::OUStringBuffer aBuffer;
      46           2 :     rtl::OUString aText1;
      47           2 :     rtl::OUString aText2;
      48             : 
      49             :     // Check that all characters map back to themselves when encoded/decoded:
      50             : 
      51           2 :     aText1 = rtl::OUString(
      52           1 :         RTL_CONSTASCII_USTRINGPARAM(
      53             :             "\x00\x01\x02\x03\x04\x05\x06\x07"
      54             :             "\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F"
      55             :             "\x10\x11\x12\x13\x14\x15\x16\x17"
      56             :             "\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"
      57             :             "\x20\x21\x22\x23\x24\x25\x26\x27"
      58             :             "\x28\x29\x2A\x2B\x2C\x2D\x2E\x2F"
      59             :             "\x30\x31\x32\x33\x34\x35\x36\x37"
      60             :             "\x38\x39\x3A\x3B\x3C\x3D\x3E\x3F"
      61             :             "\x40\x41\x42\x43\x44\x45\x46\x47"
      62             :             "\x48\x49\x4A\x4B\x4C\x4D\x4E\x4F"
      63             :             "\x50\x51\x52\x53\x54\x55\x56\x57"
      64             :             "\x58\x59\x5A\x5B\x5C\x5D\x5E\x5F"
      65             :             "\x60\x61\x62\x63\x64\x65\x66\x67"
      66             :             "\x68\x69\x6A\x6B\x6C\x6D\x6E\x6F"
      67             :             "\x70\x71\x72\x73\x74\x75\x76\x77"
      68           1 :             "\x78\x79\x7A\x7B\x7C\x7D\x7E\x7F"));
      69           1 :     aText2 = aText1;
      70          18 :     for (rtl_UriCharClass eCharClass = eFirstCharClass;
      71           9 :          eCharClass <= eLastCharClass;
      72           8 :          eCharClass = static_cast< rtl_UriCharClass >(eCharClass + 1))
      73             :     {
      74          16 :         CPPUNIT_ASSERT_MESSAGE(
      75             :             "failure 1",
      76             :             (rtl::Uri::decode(
      77             :                 rtl::Uri::encode(
      78             :                     aText1, eCharClass, rtl_UriEncodeKeepEscapes,
      79             :                     RTL_TEXTENCODING_ISO_8859_1),
      80             :                 rtl_UriDecodeWithCharset, RTL_TEXTENCODING_ASCII_US)
      81           8 :              == aText2));
      82          16 :         CPPUNIT_ASSERT_MESSAGE(
      83             :             "failure 2",
      84             :             (rtl::Uri::decode(
      85             :                 rtl::Uri::encode(
      86             :                     aText1, eCharClass, rtl_UriEncodeCheckEscapes,
      87             :                     RTL_TEXTENCODING_ISO_8859_1),
      88             :                 rtl_UriDecodeWithCharset, RTL_TEXTENCODING_ASCII_US)
      89           8 :              == aText2));
      90          16 :         CPPUNIT_ASSERT_MESSAGE(
      91             :             "failure 3",
      92             :             (rtl::Uri::decode(
      93             :                 rtl::Uri::encode(
      94             :                     aText1, eCharClass, rtl_UriEncodeKeepEscapes,
      95             :                     RTL_TEXTENCODING_ISO_8859_1),
      96             :                 rtl_UriDecodeWithCharset, RTL_TEXTENCODING_ISO_8859_1)
      97           8 :              == aText2));
      98          16 :         CPPUNIT_ASSERT_MESSAGE(
      99             :             "failure 4",
     100             :             (rtl::Uri::decode(
     101             :                 rtl::Uri::encode(
     102             :                     aText1, eCharClass, rtl_UriEncodeCheckEscapes,
     103             :                     RTL_TEXTENCODING_ISO_8859_1),
     104             :                 rtl_UriDecodeWithCharset, RTL_TEXTENCODING_ISO_8859_1)
     105           8 :              == aText2));
     106          16 :         CPPUNIT_ASSERT_MESSAGE(
     107             :             "failure 5",
     108             :             (rtl::Uri::decode(
     109             :                 rtl::Uri::encode(
     110             :                     aText1, eCharClass, rtl_UriEncodeKeepEscapes,
     111             :                     RTL_TEXTENCODING_ISO_8859_1),
     112             :                 rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8)
     113           8 :              == aText2));
     114          16 :         CPPUNIT_ASSERT_MESSAGE(
     115             :             "failure 6",
     116             :             (rtl::Uri::decode(
     117             :                 rtl::Uri::encode(
     118             :                     aText1, eCharClass, rtl_UriEncodeCheckEscapes,
     119             :                     RTL_TEXTENCODING_ISO_8859_1),
     120             :                 rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8)
     121           8 :              == aText2));
     122             :     }
     123             : 
     124           2 :     aText1 = rtl::OUString(
     125             :         ("\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F"
     126             :          "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"
     127             :          "\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2A\x2B\x2C\x2D\x2E\x2F"
     128             :          "\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3A\x3B\x3C\x3D\x3E\x3F"
     129             :          "\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4A\x4B\x4C\x4D\x4E\x4F"
     130             :          "\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5A\x5B\x5C\x5D\x5E\x5F"
     131             :          "\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6A\x6B\x6C\x6D\x6E\x6F"
     132             :          "\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7A\x7B\x7C\x7D\x7E\x7F"
     133             :          "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x8D\x8E\x8F"
     134             :          "\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9D\x9E\x9F"
     135             :          "\xA0\xA1\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xAA\xAB\xAC\xAD\xAE\xAF"
     136             :          "\xB0\xB1\xB2\xB3\xB4\xB5\xB6\xB7\xB8\xB9\xBA\xBB\xBC\xBD\xBE\xBF"
     137             :          "\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF"
     138             :          "\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD7\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF"
     139             :          "\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF"
     140             :          "\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xFF"),
     141           1 :         256, RTL_TEXTENCODING_ISO_8859_1);
     142           1 :     aText2 = aText1;
     143          18 :     for (rtl_UriCharClass eCharClass = eFirstCharClass;
     144           9 :          eCharClass <= eLastCharClass;
     145           8 :          eCharClass = static_cast< rtl_UriCharClass >(eCharClass + 1))
     146             :     {
     147          16 :         CPPUNIT_ASSERT_MESSAGE(
     148             :             "failure 7",
     149             :             (rtl::Uri::decode(
     150             :                 rtl::Uri::encode(
     151             :                     aText1, eCharClass, rtl_UriEncodeKeepEscapes,
     152             :                     RTL_TEXTENCODING_ISO_8859_1),
     153             :                 rtl_UriDecodeWithCharset, RTL_TEXTENCODING_ISO_8859_1)
     154           8 :              == aText2));
     155          16 :         CPPUNIT_ASSERT_MESSAGE(
     156             :             "failure 8",
     157             :             (rtl::Uri::decode(
     158             :                 rtl::Uri::encode(
     159             :                     aText1, eCharClass, rtl_UriEncodeCheckEscapes,
     160             :                     RTL_TEXTENCODING_ISO_8859_1),
     161             :                 rtl_UriDecodeWithCharset, RTL_TEXTENCODING_ISO_8859_1)
     162           8 :              == aText2));
     163          16 :         CPPUNIT_ASSERT_MESSAGE(
     164             :             "failure 9",
     165             :             (rtl::Uri::decode(
     166             :                 rtl::Uri::encode(
     167             :                     aText1, eCharClass, rtl_UriEncodeKeepEscapes,
     168             :                     RTL_TEXTENCODING_UTF8),
     169             :                 rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8)
     170           8 :              == aText2));
     171          16 :         CPPUNIT_ASSERT_MESSAGE(
     172             :             "failure 10",
     173             :             (rtl::Uri::decode(
     174             :                 rtl::Uri::encode(
     175             :                     aText1, eCharClass, rtl_UriEncodeCheckEscapes,
     176             :                     RTL_TEXTENCODING_UTF8),
     177             :                 rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8)
     178           8 :              == aText2));
     179             :     }
     180             : 
     181             :     // Check surrogate handling:
     182             : 
     183           1 :     aBuffer.append(static_cast< sal_Unicode >(0xD800)); // %ED%A0%80
     184           1 :     aBuffer.append(static_cast< sal_Unicode >(0xD800)); // %F0%90%8F%BF
     185           1 :     aBuffer.append(static_cast< sal_Unicode >(0xDFFF));
     186           1 :     aBuffer.append(static_cast< sal_Unicode >(0xDFFF)); // %ED%BF%BF
     187           1 :     aBuffer.append('A'); // A
     188           1 :     aText1 = aBuffer.makeStringAndClear();
     189           2 :     aText2 = rtl::OUString(
     190           1 :             "%ED%A0%80" "%F0%90%8F%BF" "%ED%BF%BF" "A");
     191           2 :     CPPUNIT_ASSERT_MESSAGE(
     192             :         "failure 11",
     193             :         (rtl::Uri::encode(
     194             :             aText1, rtl_UriCharClassUric, rtl_UriEncodeIgnoreEscapes,
     195             :             RTL_TEXTENCODING_UTF8)
     196           1 :          == aText2));
     197           2 :     CPPUNIT_ASSERT_MESSAGE(
     198             :         "failure 12",
     199             :         (rtl::Uri::encode(
     200             :             aText1, rtl_UriCharClassUric, rtl_UriEncodeKeepEscapes,
     201             :             RTL_TEXTENCODING_UTF8)
     202           1 :          == aText2));
     203           2 :     CPPUNIT_ASSERT_MESSAGE(
     204             :         "failure 13",
     205             :         (rtl::Uri::encode(
     206             :             aText1, rtl_UriCharClassUric, rtl_UriEncodeCheckEscapes,
     207             :             RTL_TEXTENCODING_UTF8)
     208           1 :          == aText2));
     209             : 
     210           2 :     aText1 = rtl::OUString(
     211           1 :             "%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 = rtl::OUString("%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 = rtl::OUString("%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 = rtl::OUString("%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 = rtl::OUString("[]%5B%5D");
     264           1 :     aText2 = rtl::OUString("%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          51 :     for (std::size_t i = 0; i < sizeof aRelToAbsTest / sizeof (RelToAbsTest); ++i)
     334             :     {
     335          50 :         rtl::OUString aAbs;
     336          50 :         bool bMalformed = false;
     337             :         try {
     338         100 :             aAbs = rtl::Uri::convertRelToAbs(
     339             :                 rtl::OUString::createFromAscii(aRelToAbsTest[i].pBase),
     340          49 :                 rtl::OUString::createFromAscii(aRelToAbsTest[i].pRel));
     341           2 :         } catch (const rtl::MalformedUriException &) {
     342           1 :             bMalformed = true;
     343             :         }
     344         100 :         if (bMalformed
     345           1 :             ? aRelToAbsTest[i].pAbs != 0
     346          49 :             : (aRelToAbsTest[i].pAbs == 0
     347          49 :                || !aAbs.equalsAscii(aRelToAbsTest[i].pAbs)))
     348             :         {
     349             :             printf(
     350             :                 "FAILED convertRelToAbs(%s, %s) -> %s != %s\n",
     351             :                 aRelToAbsTest[i].pBase, aRelToAbsTest[i].pRel,
     352             :                 (bMalformed
     353             :                  ? "<MALFORMED>"
     354             :                  : rtl::OUStringToOString(
     355           0 :                      aAbs, RTL_TEXTENCODING_UTF8).getStr()),
     356           0 :                 (aRelToAbsTest[i].pAbs == 0
     357           0 :                  ? "<MALFORMED>" : aRelToAbsTest[i].pAbs));
     358           0 :             CPPUNIT_ASSERT(false);
     359             :         }
     360          50 :     }
     361             : 
     362             :     // Check encode with unusual text encodings:
     363             : 
     364             :     {
     365           1 :         sal_Unicode const aText1U[] = { ' ', '!', 0x0401, 0x045F, 0 };
     366           1 :         aText1 = rtl::OUString(aText1U);
     367           1 :         aText2 = rtl::OUString("%20!%A1%FF");
     368           2 :         CPPUNIT_ASSERT_MESSAGE(
     369             :             "failure 20",
     370             :             (rtl::Uri::encode(
     371             :                 aText1, rtl_UriCharClassUric, rtl_UriEncodeIgnoreEscapes,
     372             :                 RTL_TEXTENCODING_ISO_8859_5)
     373           1 :              == aText2));
     374           2 :         CPPUNIT_ASSERT_MESSAGE(
     375             :             "failure 20a",
     376             :             (rtl::Uri::decode(
     377             :                 aText2, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_ISO_8859_5)
     378           1 :              == aText1));
     379             :     }
     380             :     {
     381           1 :         sal_Unicode const aText1U[] = { ' ', '!', 0x0401, 0x0700, 0x045F, 0 };
     382           1 :         aText1 = rtl::OUString(aText1U);
     383             :         sal_Unicode const aText2U[] = {
     384           1 :             '%', '2', '0', '!', '%', 'A', '1', 0x0700, '%', 'F', 'F', 0 };
     385           1 :         aText2 = rtl::OUString(aText2U);
     386           2 :         CPPUNIT_ASSERT_MESSAGE(
     387             :             "failure 21",
     388             :             (rtl::Uri::encode(
     389             :                 aText1, rtl_UriCharClassUric, rtl_UriEncodeIgnoreEscapes,
     390             :                 RTL_TEXTENCODING_ISO_8859_5)
     391           1 :              == aText2));
     392           2 :         CPPUNIT_ASSERT_MESSAGE(
     393             :             "failure 21a",
     394             :             (rtl::Uri::decode(
     395             :                 aText2, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_ISO_8859_5)
     396           1 :              == aText1));
     397             :     }
     398             :     {
     399           1 :         sal_Unicode const aText1U[] = { ' ', '!', 0x028A, 0xD849, 0xDD13, 0 };
     400           1 :         aText1 = rtl::OUString(aText1U);
     401           1 :         aText2 = rtl::OUString("%20!%81%30%B1%33%95%39%C5%37");
     402           2 :         CPPUNIT_ASSERT_MESSAGE(
     403             :             "failure 22",
     404             :             (rtl::Uri::encode(
     405             :                 aText1, rtl_UriCharClassUric, rtl_UriEncodeIgnoreEscapes,
     406             :                 RTL_TEXTENCODING_GB_18030)
     407           1 :              == aText2));
     408           2 :         CPPUNIT_ASSERT_MESSAGE(
     409             :             "failure 22a",
     410             :             (rtl::Uri::decode(
     411             :                 aText2, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_GB_18030)
     412           1 :              == aText1));
     413             :     }
     414             : 
     415             :     // Check strict mode:
     416             : 
     417             :     {
     418           1 :         sal_Unicode const aText1U[] = { ' ', '!', 0x0401, 0x0700, 0x045F, 0 };
     419           1 :         aText1 = rtl::OUString(aText1U);
     420           1 :         aText2 = rtl::OUString();
     421           2 :         CPPUNIT_ASSERT_MESSAGE(
     422             :             "failure 23",
     423             :             (rtl::Uri::encode(
     424             :                 aText1, rtl_UriCharClassUric, rtl_UriEncodeStrict,
     425             :                 RTL_TEXTENCODING_ISO_8859_5)
     426           1 :              == aText2));
     427             :     }
     428             :     {
     429           1 :         aText1 = rtl::OUString("%20%C4%80%FF");
     430           1 :         aText2 = rtl::OUString();
     431           2 :         CPPUNIT_ASSERT_MESSAGE(
     432             :             "failure 24",
     433             :             (rtl::Uri::decode(
     434             :                 aText1, rtl_UriDecodeStrict, RTL_TEXTENCODING_UTF8)
     435           1 :              == aText2));
     436             :     }
     437             :     {
     438           1 :         aText1 = rtl::OUString("%81 ");
     439           1 :         aText2 = rtl::OUString();
     440           2 :         CPPUNIT_ASSERT_MESSAGE(
     441             :             "failure 25",
     442             :             (rtl::Uri::decode(
     443             :                 aText1, rtl_UriDecodeStrict, RTL_TEXTENCODING_GB_18030)
     444           1 :              == aText2));
     445             :     }
     446             :     {
     447           1 :         aText1 = rtl::OUString("%81%20");
     448           1 :         aText2 = rtl::OUString();
     449           2 :         CPPUNIT_ASSERT_MESSAGE(
     450             :             "failure 26",
     451             :             (rtl::Uri::decode(
     452             :                 aText1, rtl_UriDecodeStrict, RTL_TEXTENCODING_GB_18030)
     453           1 :              == aText2));
     454             :     }
     455             :     {
     456           1 :         aText1 = rtl::OUString("%81%30%B1%33");
     457           1 :         sal_Unicode const aText2U[] = { 0x028A, 0 };
     458           1 :         aText2 = rtl::OUString(aText2U);
     459           2 :         CPPUNIT_ASSERT_MESSAGE(
     460             :             "failure 27",
     461             :             (rtl::Uri::decode(
     462             :                 aText1, rtl_UriDecodeStrict, RTL_TEXTENCODING_GB_18030)
     463           1 :              == aText2));
     464             :     }
     465             :     {
     466           1 :         aText1 = rtl::OUString("%810%B13");
     467           1 :         sal_Unicode const aText2U[] = { 0x028A, 0 };
     468           1 :         aText2 = rtl::OUString(aText2U);
     469           2 :         CPPUNIT_ASSERT_MESSAGE(
     470             :             "failure 28",
     471             :             (rtl::Uri::decode(
     472             :                 aText1, rtl_UriDecodeStrict, RTL_TEXTENCODING_GB_18030)
     473           1 :              == aText2));
     474             :     }
     475             : 
     476             :     // Check rtl_UriEncodeStrictKeepEscapes mode:
     477             : 
     478             :     {
     479           1 :         aText1 = rtl::OUString("%%ea%c3%aa");
     480           1 :         aText2 = rtl::OUString("%25%EA%C3%AA");
     481           2 :         CPPUNIT_ASSERT_MESSAGE(
     482             :             "failure 29",
     483             :             (rtl::Uri::encode(
     484             :                 aText1, rtl_UriCharClassUric, rtl_UriEncodeStrictKeepEscapes,
     485             :                 RTL_TEXTENCODING_UTF8)
     486           1 :              == aText2));
     487             :     }
     488             :     {
     489           1 :         sal_Unicode const aText1U[] = { 0x00EA, 0 };
     490           1 :         aText1 = rtl::OUString(aText1U);
     491           1 :         aText2 = rtl::OUString("%C3%AA");
     492           2 :         CPPUNIT_ASSERT_MESSAGE(
     493             :             "failure 30",
     494             :             (rtl::Uri::encode(
     495             :                 aText1, rtl_UriCharClassUric, rtl_UriEncodeStrictKeepEscapes,
     496             :                 RTL_TEXTENCODING_UTF8)
     497           1 :              == aText2));
     498             :     }
     499             :     {
     500           1 :         sal_Unicode const aText1U[] = { ' ', '!', 0x0401, 0x0700, 0x045F, 0 };
     501           1 :         aText1 = rtl::OUString(aText1U);
     502           1 :         aText2 = rtl::OUString();
     503           2 :         CPPUNIT_ASSERT_MESSAGE(
     504             :             "failure 23",
     505             :             (rtl::Uri::encode(
     506             :                 aText1, rtl_UriCharClassUric, rtl_UriEncodeStrictKeepEscapes,
     507             :                 RTL_TEXTENCODING_ISO_8859_5)
     508           1 :              == aText2));
     509           1 :     }
     510           1 : }
     511             : 
     512             : }
     513             : 
     514           3 : CPPUNIT_TEST_SUITE_REGISTRATION(Test);
     515             : // NOADDITIONAL;
     516             : 
     517             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10