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