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