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