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