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