rtl_testuri.cxx (87d2adbc) | rtl_testuri.cxx (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 --- 18 unchanged lines hidden (view full) --- 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 | 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 --- 18 unchanged lines hidden (view full) --- 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> | 35#include <cstddef> 36#include <stdio.h> |
37#include "gtest/gtest.h" |
|
39 40namespace { 41 | 38 39namespace { 40 |
42struct Test: public CppUnit::TestFixture { 43 void test_Uri(); 44 45 CPPUNIT_TEST_SUITE(Test); 46 CPPUNIT_TEST(test_Uri); 47 CPPUNIT_TEST_SUITE_END(); | 41class Test: public ::testing::Test { 42public: |
48}; 49 | 43}; 44 |
50void Test::test_Uri() { | 45TEST_F(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: --- 16 unchanged lines hidden (view full) --- 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 { | 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: --- 16 unchanged lines hidden (view full) --- 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 { |
83 CPPUNIT_ASSERT_MESSAGE( 84 "failure 1", 85 (rtl::Uri::decode( | 78 ASSERT_TRUE((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) | 79 rtl::Uri::encode( 80 aText1, eCharClass, rtl_UriEncodeKeepEscapes, 81 RTL_TEXTENCODING_ISO_8859_1), 82 rtl_UriDecodeWithCharset, RTL_TEXTENCODING_ASCII_US) |
90 == aText2)); 91 CPPUNIT_ASSERT_MESSAGE( 92 "failure 2", 93 (rtl::Uri::decode( | 83 == aText2)) << 84 "failure 1"; 85 ASSERT_TRUE((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) | 86 rtl::Uri::encode( 87 aText1, eCharClass, rtl_UriEncodeCheckEscapes, 88 RTL_TEXTENCODING_ISO_8859_1), 89 rtl_UriDecodeWithCharset, RTL_TEXTENCODING_ASCII_US) |
98 == aText2)); 99 CPPUNIT_ASSERT_MESSAGE( 100 "failure 3", 101 (rtl::Uri::decode( | 90 == aText2)) << 91 "failure 2"; 92 ASSERT_TRUE((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) | 93 rtl::Uri::encode( 94 aText1, eCharClass, rtl_UriEncodeKeepEscapes, 95 RTL_TEXTENCODING_ISO_8859_1), 96 rtl_UriDecodeWithCharset, RTL_TEXTENCODING_ISO_8859_1) |
106 == aText2)); 107 CPPUNIT_ASSERT_MESSAGE( 108 "failure 4", 109 (rtl::Uri::decode( | 97 == aText2)) << 98 "failure 3"; 99 ASSERT_TRUE((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) | 100 rtl::Uri::encode( 101 aText1, eCharClass, rtl_UriEncodeCheckEscapes, 102 RTL_TEXTENCODING_ISO_8859_1), 103 rtl_UriDecodeWithCharset, RTL_TEXTENCODING_ISO_8859_1) |
114 == aText2)); 115 CPPUNIT_ASSERT_MESSAGE( 116 "failure 5", 117 (rtl::Uri::decode( | 104 == aText2)) << 105 "failure 4"; 106 ASSERT_TRUE((rtl::Uri::decode( |
118 rtl::Uri::encode( 119 aText1, eCharClass, rtl_UriEncodeKeepEscapes, 120 RTL_TEXTENCODING_ISO_8859_1), 121 rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8) | 107 rtl::Uri::encode( 108 aText1, eCharClass, rtl_UriEncodeKeepEscapes, 109 RTL_TEXTENCODING_ISO_8859_1), 110 rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8) |
122 == aText2)); 123 CPPUNIT_ASSERT_MESSAGE( 124 "failure 6", 125 (rtl::Uri::decode( | 111 == aText2)) << 112 "failure 5"; 113 ASSERT_TRUE((rtl::Uri::decode( |
126 rtl::Uri::encode( 127 aText1, eCharClass, rtl_UriEncodeCheckEscapes, 128 RTL_TEXTENCODING_ISO_8859_1), 129 rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8) | 114 rtl::Uri::encode( 115 aText1, eCharClass, rtl_UriEncodeCheckEscapes, 116 RTL_TEXTENCODING_ISO_8859_1), 117 rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8) |
130 == aText2)); | 118 == aText2)) << 119 "failure 6"; |
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" --- 25 unchanged lines hidden (view full) --- 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 { | 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" --- 25 unchanged lines hidden (view full) --- 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 { |
172 CPPUNIT_ASSERT_MESSAGE( 173 "failure 7", 174 (rtl::Uri::decode( | 161 ASSERT_TRUE((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) | 162 rtl::Uri::encode( 163 aText1, eCharClass, rtl_UriEncodeKeepEscapes, 164 RTL_TEXTENCODING_ISO_8859_1), 165 rtl_UriDecodeWithCharset, RTL_TEXTENCODING_ISO_8859_1) |
179 == aText2)); 180 CPPUNIT_ASSERT_MESSAGE( 181 "failure 8", 182 (rtl::Uri::decode( | 166 == aText2)) << 167 "failure 7"; 168 ASSERT_TRUE((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) | 169 rtl::Uri::encode( 170 aText1, eCharClass, rtl_UriEncodeCheckEscapes, 171 RTL_TEXTENCODING_ISO_8859_1), 172 rtl_UriDecodeWithCharset, RTL_TEXTENCODING_ISO_8859_1) |
187 == aText2)); 188 CPPUNIT_ASSERT_MESSAGE( 189 "failure 9", 190 (rtl::Uri::decode( | 173 == aText2)) << 174 "failure 8"; 175 ASSERT_TRUE((rtl::Uri::decode( |
191 rtl::Uri::encode( 192 aText1, eCharClass, rtl_UriEncodeKeepEscapes, 193 RTL_TEXTENCODING_UTF8), 194 rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8) | 176 rtl::Uri::encode( 177 aText1, eCharClass, rtl_UriEncodeKeepEscapes, 178 RTL_TEXTENCODING_UTF8), 179 rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8) |
195 == aText2)); 196 CPPUNIT_ASSERT_MESSAGE( 197 "failure 10", 198 (rtl::Uri::decode( | 180 == aText2)) << 181 "failure 9"; 182 ASSERT_TRUE((rtl::Uri::decode( |
199 rtl::Uri::encode( 200 aText1, eCharClass, rtl_UriEncodeCheckEscapes, 201 RTL_TEXTENCODING_UTF8), 202 rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8) | 183 rtl::Uri::encode( 184 aText1, eCharClass, rtl_UriEncodeCheckEscapes, 185 RTL_TEXTENCODING_UTF8), 186 rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8) |
203 == aText2)); | 187 == aText2)) << 188 "failure 10"; |
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")); | 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")); |
217 CPPUNIT_ASSERT_MESSAGE( 218 "failure 11", 219 (rtl::Uri::encode( | 202 ASSERT_TRUE((rtl::Uri::encode( |
220 aText1, rtl_UriCharClassUric, rtl_UriEncodeIgnoreEscapes, 221 RTL_TEXTENCODING_UTF8) | 203 aText1, rtl_UriCharClassUric, rtl_UriEncodeIgnoreEscapes, 204 RTL_TEXTENCODING_UTF8) |
222 == aText2)); 223 CPPUNIT_ASSERT_MESSAGE( 224 "failure 12", 225 (rtl::Uri::encode( | 205 == aText2)) << 206 "failure 11"; 207 ASSERT_TRUE((rtl::Uri::encode( |
226 aText1, rtl_UriCharClassUric, rtl_UriEncodeKeepEscapes, 227 RTL_TEXTENCODING_UTF8) | 208 aText1, rtl_UriCharClassUric, rtl_UriEncodeKeepEscapes, 209 RTL_TEXTENCODING_UTF8) |
228 == aText2)); 229 CPPUNIT_ASSERT_MESSAGE( 230 "failure 13", 231 (rtl::Uri::encode( | 210 == aText2)) << 211 "failure 12"; 212 ASSERT_TRUE((rtl::Uri::encode( |
232 aText1, rtl_UriCharClassUric, rtl_UriEncodeCheckEscapes, 233 RTL_TEXTENCODING_UTF8) | 213 aText1, rtl_UriCharClassUric, rtl_UriEncodeCheckEscapes, 214 RTL_TEXTENCODING_UTF8) |
234 == aText2)); | 215 == aText2)) << 216 "failure 13"; |
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(); | 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(); |
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( | 227 ASSERT_TRUE((rtl::Uri::decode(aText1, rtl_UriDecodeToIuri, RTL_TEXTENCODING_UTF8) 228 == aText2)) << 229 "failure 14"; 230 ASSERT_TRUE((rtl::Uri::decode( |
252 aText1, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8) | 231 aText1, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8) |
253 == aText2)); | 232 == aText2)) << 233 "failure 15"; |
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; | 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; |
260 CPPUNIT_ASSERT_MESSAGE( 261 "failure 16", 262 (rtl::Uri::encode( | 240 ASSERT_TRUE((rtl::Uri::encode( |
263 aText1, rtl_UriCharClassUric, rtl_UriEncodeCheckEscapes, 264 RTL_TEXTENCODING_UTF8) | 241 aText1, rtl_UriCharClassUric, rtl_UriEncodeCheckEscapes, 242 RTL_TEXTENCODING_UTF8) |
265 == aText2)); | 243 == aText2)) << 244 "failure 16"; |
266 267 aText1 = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%EF%BF%BF")); 268 // \U+FFFF is no legal character 269 aText2 = aText1; | 245 246 aText1 = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%EF%BF%BF")); 247 // \U+FFFF is no legal character 248 aText2 = aText1; |
270 CPPUNIT_ASSERT_MESSAGE( 271 "failure 17", 272 (rtl::Uri::encode( | 249 ASSERT_TRUE((rtl::Uri::encode( |
273 aText1, rtl_UriCharClassUric, rtl_UriEncodeCheckEscapes, 274 RTL_TEXTENCODING_UTF8) | 250 aText1, rtl_UriCharClassUric, rtl_UriEncodeCheckEscapes, 251 RTL_TEXTENCODING_UTF8) |
275 == aText2)); | 252 == aText2)) << 253 "failure 17"; |
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(); | 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(); |
283 CPPUNIT_ASSERT_MESSAGE( 284 "failure 18", 285 (rtl::Uri::decode(aText1, rtl_UriDecodeToIuri, RTL_TEXTENCODING_UTF8) 286 == aText2)); | 261 ASSERT_TRUE((rtl::Uri::decode(aText1, rtl_UriDecodeToIuri, RTL_TEXTENCODING_UTF8) 262 == aText2)) << 263 "failure 18"; |
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")); | 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")); |
292 CPPUNIT_ASSERT_MESSAGE( 293 "failure 19", 294 (rtl::Uri::encode( | 269 ASSERT_TRUE((rtl::Uri::encode( |
295 aText1, rtl_UriCharClassUnoParamValue, rtl_UriEncodeCheckEscapes, 296 RTL_TEXTENCODING_ASCII_US) | 270 aText1, rtl_UriCharClassUnoParamValue, rtl_UriEncodeCheckEscapes, 271 RTL_TEXTENCODING_ASCII_US) |
297 == aText2)); | 272 == aText2)) << 273 "failure 19"; |
298 299 // Check Uri::convertRelToAbs: 300 301 struct RelToAbsTest 302 { 303 char const * pBase; 304 char const * pRel; 305 char const * pAbs; --- 69 unchanged lines hidden (view full) --- 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)); | 274 275 // Check Uri::convertRelToAbs: 276 277 struct RelToAbsTest 278 { 279 char const * pBase; 280 char const * pRel; 281 char const * pAbs; --- 69 unchanged lines hidden (view full) --- 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)); |
383 CPPUNIT_ASSERT(false); | 359 FAIL(); |
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")); | 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")); |
393 CPPUNIT_ASSERT_MESSAGE( 394 "failure 20", 395 (rtl::Uri::encode( | 369 ASSERT_TRUE((rtl::Uri::encode( |
396 aText1, rtl_UriCharClassUric, rtl_UriEncodeIgnoreEscapes, 397 RTL_TEXTENCODING_ISO_8859_5) | 370 aText1, rtl_UriCharClassUric, rtl_UriEncodeIgnoreEscapes, 371 RTL_TEXTENCODING_ISO_8859_5) |
398 == aText2)); 399 CPPUNIT_ASSERT_MESSAGE( 400 "failure 20a", 401 (rtl::Uri::decode( | 372 == aText2)) << 373 "failure 20"; 374 ASSERT_TRUE((rtl::Uri::decode( |
402 aText2, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_ISO_8859_5) | 375 aText2, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_ISO_8859_5) |
403 == aText1)); | 376 == aText1)) << 377 "failure 20a"; |
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); | 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); |
411 CPPUNIT_ASSERT_MESSAGE( 412 "failure 21", 413 (rtl::Uri::encode( | 385 ASSERT_TRUE((rtl::Uri::encode( |
414 aText1, rtl_UriCharClassUric, rtl_UriEncodeIgnoreEscapes, 415 RTL_TEXTENCODING_ISO_8859_5) | 386 aText1, rtl_UriCharClassUric, rtl_UriEncodeIgnoreEscapes, 387 RTL_TEXTENCODING_ISO_8859_5) |
416 == aText2)); 417 CPPUNIT_ASSERT_MESSAGE( 418 "failure 21a", 419 (rtl::Uri::decode( | 388 == aText2)) << 389 "failure 21"; 390 ASSERT_TRUE((rtl::Uri::decode( |
420 aText2, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_ISO_8859_5) | 391 aText2, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_ISO_8859_5) |
421 == aText1)); | 392 == aText1)) << 393 "failure 21a"; |
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")); | 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")); |
428 CPPUNIT_ASSERT_MESSAGE( 429 "failure 22", 430 (rtl::Uri::encode( | 400 ASSERT_TRUE((rtl::Uri::encode( |
431 aText1, rtl_UriCharClassUric, rtl_UriEncodeIgnoreEscapes, 432 RTL_TEXTENCODING_GB_18030) | 401 aText1, rtl_UriCharClassUric, rtl_UriEncodeIgnoreEscapes, 402 RTL_TEXTENCODING_GB_18030) |
433 == aText2)); 434 CPPUNIT_ASSERT_MESSAGE( 435 "failure 22a", 436 (rtl::Uri::decode( | 403 == aText2)) << 404 "failure 22"; 405 ASSERT_TRUE((rtl::Uri::decode( |
437 aText2, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_GB_18030) | 406 aText2, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_GB_18030) |
438 == aText1)); | 407 == aText1)) << 408 "failure 22a"; |
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(); | 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(); |
447 CPPUNIT_ASSERT_MESSAGE( 448 "failure 23", 449 (rtl::Uri::encode( | 417 ASSERT_TRUE((rtl::Uri::encode( |
450 aText1, rtl_UriCharClassUric, rtl_UriEncodeStrict, 451 RTL_TEXTENCODING_ISO_8859_5) | 418 aText1, rtl_UriCharClassUric, rtl_UriEncodeStrict, 419 RTL_TEXTENCODING_ISO_8859_5) |
452 == aText2)); | 420 == aText2)) << 421 "failure 23"; |
453 } 454 { 455 aText1 = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%20%C4%80%FF")); 456 aText2 = rtl::OUString(); | 422 } 423 { 424 aText1 = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%20%C4%80%FF")); 425 aText2 = rtl::OUString(); |
457 CPPUNIT_ASSERT_MESSAGE( 458 "failure 24", 459 (rtl::Uri::decode( | 426 ASSERT_TRUE((rtl::Uri::decode( |
460 aText1, rtl_UriDecodeStrict, RTL_TEXTENCODING_UTF8) | 427 aText1, rtl_UriDecodeStrict, RTL_TEXTENCODING_UTF8) |
461 == aText2)); | 428 == aText2)) << 429 "failure 24"; |
462 } 463 { 464 aText1 = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%81 ")); 465 aText2 = rtl::OUString(); | 430 } 431 { 432 aText1 = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%81 ")); 433 aText2 = rtl::OUString(); |
466 CPPUNIT_ASSERT_MESSAGE( 467 "failure 25", 468 (rtl::Uri::decode( | 434 ASSERT_TRUE((rtl::Uri::decode( |
469 aText1, rtl_UriDecodeStrict, RTL_TEXTENCODING_GB_18030) | 435 aText1, rtl_UriDecodeStrict, RTL_TEXTENCODING_GB_18030) |
470 == aText2)); | 436 == aText2)) << 437 "failure 25"; |
471 } 472 { 473 aText1 = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%81%20")); 474 aText2 = rtl::OUString(); | 438 } 439 { 440 aText1 = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%81%20")); 441 aText2 = rtl::OUString(); |
475 CPPUNIT_ASSERT_MESSAGE( 476 "failure 26", 477 (rtl::Uri::decode( | 442 ASSERT_TRUE((rtl::Uri::decode( |
478 aText1, rtl_UriDecodeStrict, RTL_TEXTENCODING_GB_18030) | 443 aText1, rtl_UriDecodeStrict, RTL_TEXTENCODING_GB_18030) |
479 == aText2)); | 444 == aText2)) << 445 "failure 26"; |
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); | 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); |
485 CPPUNIT_ASSERT_MESSAGE( 486 "failure 27", 487 (rtl::Uri::decode( | 451 ASSERT_TRUE((rtl::Uri::decode( |
488 aText1, rtl_UriDecodeStrict, RTL_TEXTENCODING_GB_18030) | 452 aText1, rtl_UriDecodeStrict, RTL_TEXTENCODING_GB_18030) |
489 == aText2)); | 453 == aText2)) << 454 "failure 27"; |
490 } 491 { 492 aText1 = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%810%B13")); 493 sal_Unicode const aText2U[] = { 0x028A, 0 }; 494 aText2 = rtl::OUString(aText2U); | 455 } 456 { 457 aText1 = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%810%B13")); 458 sal_Unicode const aText2U[] = { 0x028A, 0 }; 459 aText2 = rtl::OUString(aText2U); |
495 CPPUNIT_ASSERT_MESSAGE( 496 "failure 28", 497 (rtl::Uri::decode( | 460 ASSERT_TRUE((rtl::Uri::decode( |
498 aText1, rtl_UriDecodeStrict, RTL_TEXTENCODING_GB_18030) | 461 aText1, rtl_UriDecodeStrict, RTL_TEXTENCODING_GB_18030) |
499 == aText2)); | 462 == aText2)) << 463 "failure 28"; |
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")); | 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")); |
507 CPPUNIT_ASSERT_MESSAGE( 508 "failure 29", 509 (rtl::Uri::encode( | 471 ASSERT_TRUE((rtl::Uri::encode( |
510 aText1, rtl_UriCharClassUric, rtl_UriEncodeStrictKeepEscapes, 511 RTL_TEXTENCODING_UTF8) | 472 aText1, rtl_UriCharClassUric, rtl_UriEncodeStrictKeepEscapes, 473 RTL_TEXTENCODING_UTF8) |
512 == aText2)); | 474 == aText2)) << 475 "failure 29"; |
513 } 514 { 515 sal_Unicode const aText1U[] = { 0x00EA, 0 }; 516 aText1 = rtl::OUString(aText1U); 517 aText2 = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%C3%AA")); | 476 } 477 { 478 sal_Unicode const aText1U[] = { 0x00EA, 0 }; 479 aText1 = rtl::OUString(aText1U); 480 aText2 = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%C3%AA")); |
518 CPPUNIT_ASSERT_MESSAGE( 519 "failure 30", 520 (rtl::Uri::encode( | 481 ASSERT_TRUE((rtl::Uri::encode( |
521 aText1, rtl_UriCharClassUric, rtl_UriEncodeStrictKeepEscapes, 522 RTL_TEXTENCODING_UTF8) | 482 aText1, rtl_UriCharClassUric, rtl_UriEncodeStrictKeepEscapes, 483 RTL_TEXTENCODING_UTF8) |
523 == aText2)); | 484 == aText2)) << 485 "failure 30"; |
524 } 525 { 526 sal_Unicode const aText1U[] = { ' ', '!', 0x0401, 0x0700, 0x045F, 0 }; 527 aText1 = rtl::OUString(aText1U); 528 aText2 = rtl::OUString(); | 486 } 487 { 488 sal_Unicode const aText1U[] = { ' ', '!', 0x0401, 0x0700, 0x045F, 0 }; 489 aText1 = rtl::OUString(aText1U); 490 aText2 = rtl::OUString(); |
529 CPPUNIT_ASSERT_MESSAGE( 530 "failure 23", 531 (rtl::Uri::encode( | 491 ASSERT_TRUE((rtl::Uri::encode( |
532 aText1, rtl_UriCharClassUric, rtl_UriEncodeStrictKeepEscapes, 533 RTL_TEXTENCODING_ISO_8859_5) | 492 aText1, rtl_UriCharClassUric, rtl_UriEncodeStrictKeepEscapes, 493 RTL_TEXTENCODING_ISO_8859_5) |
534 == aText2)); | 494 == aText2)) << 495 "failure 23"; |
535 } 536} 537 538} 539 | 496 } 497} 498 499} 500 |
540CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(Test, "rtl_testuri"); 541NOADDITIONAL; | 501int main(int argc, char **argv) 502{ 503 ::testing::InitGoogleTest(&argc, argv); 504 return RUN_ALL_TESTS(); 505} |