1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #include <testshl/simpleheader.hxx> 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir #include "cppuhelper/unourl.hxx" 31*cdf0e10cSrcweir #include "rtl/malformeduriexception.hxx" 32*cdf0e10cSrcweir #include "rtl/strbuf.hxx" 33*cdf0e10cSrcweir #include "rtl/string.h" 34*cdf0e10cSrcweir #include "rtl/textenc.h" 35*cdf0e10cSrcweir #include "rtl/ustring.hxx" 36*cdf0e10cSrcweir #include "sal/types.h" 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir namespace cppu_unourl 39*cdf0e10cSrcweir { 40*cdf0e10cSrcweir class UrlTest : public CppUnit::TestFixture 41*cdf0e10cSrcweir { 42*cdf0e10cSrcweir public: 43*cdf0e10cSrcweir void testDescriptorParsing() 44*cdf0e10cSrcweir { 45*cdf0e10cSrcweir struct Test 46*cdf0e10cSrcweir { 47*cdf0e10cSrcweir char const * pInput; 48*cdf0e10cSrcweir bool bValid; 49*cdf0e10cSrcweir }; 50*cdf0e10cSrcweir static Test const aTests[] 51*cdf0e10cSrcweir = { { "", false }, 52*cdf0e10cSrcweir { "abc", true }, 53*cdf0e10cSrcweir { "Abc", true }, 54*cdf0e10cSrcweir { "aBC", true }, 55*cdf0e10cSrcweir { "ABC", true }, 56*cdf0e10cSrcweir { "1abc", true }, 57*cdf0e10cSrcweir { "123", true }, 58*cdf0e10cSrcweir { "abc-1", false }, 59*cdf0e10cSrcweir { "ab%63", false }, 60*cdf0e10cSrcweir { "abc,", false }, 61*cdf0e10cSrcweir { "abc,def=", true }, 62*cdf0e10cSrcweir { "abc,Def=", true }, 63*cdf0e10cSrcweir { "abc,DEF=", true }, 64*cdf0e10cSrcweir { "abc,1def=", true }, 65*cdf0e10cSrcweir { "abc,123=", true }, 66*cdf0e10cSrcweir { "abc,def-1=", false }, 67*cdf0e10cSrcweir { "abc,def", false }, 68*cdf0e10cSrcweir { "abc,def=xxx,def=xxx", false }, 69*cdf0e10cSrcweir { "abc,def=xxx,ghi=xxx", true }, 70*cdf0e10cSrcweir { "abc,,def=xxx", false }, 71*cdf0e10cSrcweir { "abc,def=xxx,,ghi=xxx", false }, 72*cdf0e10cSrcweir { "abc,def=xxx,ghi=xxx,", false }, 73*cdf0e10cSrcweir { "abc,def=%", true }, 74*cdf0e10cSrcweir { "abc,def=%1", true }, 75*cdf0e10cSrcweir { "abc,def=%00", true }, 76*cdf0e10cSrcweir { "abc,def=%22", true }, 77*cdf0e10cSrcweir { "abc,def=\"", true }, 78*cdf0e10cSrcweir { "abc,def=%ed%a0%80", true } }; 79*cdf0e10cSrcweir for (int i = 0; i < sizeof aTests / sizeof (Test); ++i) 80*cdf0e10cSrcweir { 81*cdf0e10cSrcweir bool bValid = false; 82*cdf0e10cSrcweir try 83*cdf0e10cSrcweir { 84*cdf0e10cSrcweir cppu::UnoUrlDescriptor aDescriptor(rtl::OUString::createFromAscii( 85*cdf0e10cSrcweir aTests[i].pInput)); 86*cdf0e10cSrcweir bValid = true; 87*cdf0e10cSrcweir } 88*cdf0e10cSrcweir catch (rtl::MalformedUriException &) 89*cdf0e10cSrcweir {} 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir if (aTests[i].bValid) 92*cdf0e10cSrcweir { 93*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("Valid uri parsed as invalid", bValid); 94*cdf0e10cSrcweir } 95*cdf0e10cSrcweir else 96*cdf0e10cSrcweir { 97*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("Invalid uri parsed as valid", !bValid); 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir } 100*cdf0e10cSrcweir } 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir void testDescriptorDescriptor() 103*cdf0e10cSrcweir { 104*cdf0e10cSrcweir struct Test 105*cdf0e10cSrcweir { 106*cdf0e10cSrcweir char const * pInput; 107*cdf0e10cSrcweir char const * pDescriptor; 108*cdf0e10cSrcweir }; 109*cdf0e10cSrcweir static Test const aTests[] 110*cdf0e10cSrcweir = {{ "abc", "abc" }, 111*cdf0e10cSrcweir { "Abc", "Abc" }, 112*cdf0e10cSrcweir { "aBC", "aBC" }, 113*cdf0e10cSrcweir { "ABC", "ABC" }, 114*cdf0e10cSrcweir { "1abc", "1abc" }, 115*cdf0e10cSrcweir { "123", "123" }, 116*cdf0e10cSrcweir { "abc,def=", "abc,def=" }, 117*cdf0e10cSrcweir { "abc,Def=", "abc,Def=" }, 118*cdf0e10cSrcweir { "abc,DEF=", "abc,DEF=" }, 119*cdf0e10cSrcweir { "abc,1def=", "abc,1def=" }, 120*cdf0e10cSrcweir { "abc,123=", "abc,123=" }, 121*cdf0e10cSrcweir { "abc,def=xxx,ghi=xxx", "abc,def=xxx,ghi=xxx" }, 122*cdf0e10cSrcweir { "abc,def=%", "abc,def=%" }, 123*cdf0e10cSrcweir { "abc,def=%1", "abc,def=%1" }, 124*cdf0e10cSrcweir { "abc,def=%00", "abc,def=%00" }, 125*cdf0e10cSrcweir { "abc,def=%22", "abc,def=%22" }, 126*cdf0e10cSrcweir { "abc,def=\"", "abc,def=\"" }, 127*cdf0e10cSrcweir { "abc,def=%ed%a0%80", "abc,def=%ed%a0%80" } }; 128*cdf0e10cSrcweir bool bResult = true; 129*cdf0e10cSrcweir for (int i = 0; i < sizeof aTests / sizeof (Test); ++i) 130*cdf0e10cSrcweir { 131*cdf0e10cSrcweir bool bValid = false; 132*cdf0e10cSrcweir rtl::OUString aDescriptor; 133*cdf0e10cSrcweir try 134*cdf0e10cSrcweir { 135*cdf0e10cSrcweir aDescriptor = cppu::UnoUrlDescriptor(rtl::OUString::createFromAscii( 136*cdf0e10cSrcweir aTests[i].pInput)). 137*cdf0e10cSrcweir getDescriptor(); 138*cdf0e10cSrcweir bValid = true; 139*cdf0e10cSrcweir } 140*cdf0e10cSrcweir catch (rtl::MalformedUriException &) 141*cdf0e10cSrcweir {} 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("Failed to parse URI", bValid); 144*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("Failed to parse URI correctly", 145*cdf0e10cSrcweir aDescriptor.equalsAscii( 146*cdf0e10cSrcweir aTests[i].pDescriptor)); 147*cdf0e10cSrcweir } 148*cdf0e10cSrcweir } 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir void testDescriptorName() 152*cdf0e10cSrcweir { 153*cdf0e10cSrcweir struct Test 154*cdf0e10cSrcweir { 155*cdf0e10cSrcweir char const * pInput; 156*cdf0e10cSrcweir char const * pName; 157*cdf0e10cSrcweir }; 158*cdf0e10cSrcweir static Test const aTests[] 159*cdf0e10cSrcweir = { { "abc", "abc" }, 160*cdf0e10cSrcweir { "Abc", "abc" }, 161*cdf0e10cSrcweir { "aBC", "abc" }, 162*cdf0e10cSrcweir { "ABC", "abc" }, 163*cdf0e10cSrcweir { "1abc", "1abc" }, 164*cdf0e10cSrcweir { "123", "123" }, 165*cdf0e10cSrcweir { "abc,def=", "abc" }, 166*cdf0e10cSrcweir { "abc,Def=", "abc" }, 167*cdf0e10cSrcweir { "abc,DEF=", "abc" }, 168*cdf0e10cSrcweir { "abc,1def=", "abc" }, 169*cdf0e10cSrcweir { "abc,123=", "abc" }, 170*cdf0e10cSrcweir { "abc,def=xxx,ghi=xxx", "abc" }, 171*cdf0e10cSrcweir { "abc,def=%", "abc" }, 172*cdf0e10cSrcweir { "abc,def=%1", "abc" }, 173*cdf0e10cSrcweir { "abc,def=%00", "abc" }, 174*cdf0e10cSrcweir { "abc,def=%22", "abc" }, 175*cdf0e10cSrcweir { "abc,def=\"", "abc" }, 176*cdf0e10cSrcweir { "abc,def=%ed%a0%80", "abc" } }; 177*cdf0e10cSrcweir for (int i = 0; i < sizeof aTests / sizeof (Test); ++i) 178*cdf0e10cSrcweir { 179*cdf0e10cSrcweir bool bValid = false; 180*cdf0e10cSrcweir rtl::OUString aName; 181*cdf0e10cSrcweir try 182*cdf0e10cSrcweir { 183*cdf0e10cSrcweir aName = cppu::UnoUrlDescriptor(rtl::OUString::createFromAscii( 184*cdf0e10cSrcweir aTests[i].pInput)).getName(); 185*cdf0e10cSrcweir bValid = true; 186*cdf0e10cSrcweir } 187*cdf0e10cSrcweir catch (rtl::MalformedUriException &) 188*cdf0e10cSrcweir {} 189*cdf0e10cSrcweir 190*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("Failed to parse URI", bValid); 191*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("Failed to parse URI correctly", 192*cdf0e10cSrcweir aName.equalsAscii(aTests[i].pName)); 193*cdf0e10cSrcweir } 194*cdf0e10cSrcweir } 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir void testDescriptorKey(void) 197*cdf0e10cSrcweir { 198*cdf0e10cSrcweir struct Test 199*cdf0e10cSrcweir { 200*cdf0e10cSrcweir char const * pInput; 201*cdf0e10cSrcweir char const * pKey; 202*cdf0e10cSrcweir bool bPresent; 203*cdf0e10cSrcweir }; 204*cdf0e10cSrcweir static Test const aTests[] 205*cdf0e10cSrcweir = { { "abc", "abc", false }, 206*cdf0e10cSrcweir { "abc", "def", false }, 207*cdf0e10cSrcweir { "1abc", "def", false }, 208*cdf0e10cSrcweir { "123", "def", false }, 209*cdf0e10cSrcweir { "abc,def=", "abc", false }, 210*cdf0e10cSrcweir { "abc,def=", "def", true }, 211*cdf0e10cSrcweir { "abc,def=", "defg", false }, 212*cdf0e10cSrcweir { "abc,def=", "de", false }, 213*cdf0e10cSrcweir { "abc,def=", "ghi", false }, 214*cdf0e10cSrcweir { "abc,Def=", "def", true }, 215*cdf0e10cSrcweir { "abc,Def=", "Def", true }, 216*cdf0e10cSrcweir { "abc,Def=", "dEF", true }, 217*cdf0e10cSrcweir { "abc,Def=", "DEF", true }, 218*cdf0e10cSrcweir { "abc,def=xxx,ghi=xxx", "abc", false }, 219*cdf0e10cSrcweir { "abc,def=xxx,ghi=xxx", "def", true }, 220*cdf0e10cSrcweir { "abc,def=xxx,ghi=xxx", "ghi", true }, 221*cdf0e10cSrcweir { "abc,def=xxx,ghi=xxx", "jkl", false } }; 222*cdf0e10cSrcweir for (int i = 0; i < sizeof aTests / sizeof (Test); ++i) 223*cdf0e10cSrcweir { 224*cdf0e10cSrcweir bool bValid = false; 225*cdf0e10cSrcweir bool bPresent = false; 226*cdf0e10cSrcweir try 227*cdf0e10cSrcweir { 228*cdf0e10cSrcweir bPresent = cppu::UnoUrlDescriptor(rtl::OUString::createFromAscii( 229*cdf0e10cSrcweir aTests[i].pInput)). 230*cdf0e10cSrcweir hasParameter(rtl::OUString::createFromAscii(aTests[i].pKey)); 231*cdf0e10cSrcweir bValid = true; 232*cdf0e10cSrcweir } 233*cdf0e10cSrcweir catch (rtl::MalformedUriException &) 234*cdf0e10cSrcweir {} 235*cdf0e10cSrcweir 236*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("Failed to parse URI", bValid); 237*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("Failed to detect parameter correctly", 238*cdf0e10cSrcweir bPresent == aTests[i].bPresent); 239*cdf0e10cSrcweir } 240*cdf0e10cSrcweir } 241*cdf0e10cSrcweir 242*cdf0e10cSrcweir void testDescriptorValue() 243*cdf0e10cSrcweir { 244*cdf0e10cSrcweir struct Test 245*cdf0e10cSrcweir { 246*cdf0e10cSrcweir char const * pInput; 247*cdf0e10cSrcweir char const * pKey; 248*cdf0e10cSrcweir char const * pValue; 249*cdf0e10cSrcweir }; 250*cdf0e10cSrcweir static Test const aTests[] 251*cdf0e10cSrcweir = { { "abc", "abc", "" }, 252*cdf0e10cSrcweir { "abc", "def", "" }, 253*cdf0e10cSrcweir { "1abc", "def", "" }, 254*cdf0e10cSrcweir { "123", "def", "" }, 255*cdf0e10cSrcweir { "abc,def=", "abc", "" }, 256*cdf0e10cSrcweir { "abc,def=", "def", "" }, 257*cdf0e10cSrcweir { "abc,def=", "defg", "" }, 258*cdf0e10cSrcweir { "abc,def=", "de", "" }, 259*cdf0e10cSrcweir { "abc,def=", "ghi", "" }, 260*cdf0e10cSrcweir { "abc,Def=", "def", "" }, 261*cdf0e10cSrcweir { "abc,Def=", "Def", "" }, 262*cdf0e10cSrcweir { "abc,Def=", "dEF", "" }, 263*cdf0e10cSrcweir { "abc,Def=", "DEF", "" }, 264*cdf0e10cSrcweir { "abc,def=xxx,ghi=xxx", "abc", "" }, 265*cdf0e10cSrcweir { "abc,def=xxx,ghi=xxx", "def", "xxx" }, 266*cdf0e10cSrcweir { "abc,def=xxx,ghi=xxx", "ghi", "xxx" }, 267*cdf0e10cSrcweir { "abc,def=xxx,ghi=xxx", "jkl", "" }, 268*cdf0e10cSrcweir { "abc,def=%", "def", "%" }, 269*cdf0e10cSrcweir { "abc,def=%1", "def", "%1" }, 270*cdf0e10cSrcweir { "abc,def=%22", "def", "\"" }, 271*cdf0e10cSrcweir { "abc,def=\"", "def", "\"" }, 272*cdf0e10cSrcweir { "abc,def=abc", "def", "abc" }, 273*cdf0e10cSrcweir { "abc,def=Abc", "def", "Abc" }, 274*cdf0e10cSrcweir { "abc,def=aBC", "def", "aBC" }, 275*cdf0e10cSrcweir { "abc,def=ABC", "def", "ABC" }, 276*cdf0e10cSrcweir { "abc,def=%,ghi=", "def", "%" }, 277*cdf0e10cSrcweir { "abc,def=%1,ghi=", "def", "%1" }, 278*cdf0e10cSrcweir { "abc,def=%22,ghi=", "def", "\"" }, 279*cdf0e10cSrcweir { "abc,def=\",ghi=", "def", "\"" }, 280*cdf0e10cSrcweir { "abc,def=abc,ghi=", "def", "abc" }, 281*cdf0e10cSrcweir { "abc,def=Abc,ghi=", "def", "Abc" }, 282*cdf0e10cSrcweir { "abc,def=aBC,ghi=", "def", "aBC" }, 283*cdf0e10cSrcweir { "abc,def=ABC,ghi=", "def", "ABC" }, 284*cdf0e10cSrcweir { "abc,abc=,def=%", "def", "%" }, 285*cdf0e10cSrcweir { "abc,abc=,def=%1", "def", "%1" }, 286*cdf0e10cSrcweir { "abc,abc=,def=%22", "def", "\"" }, 287*cdf0e10cSrcweir { "abc,abc=,def=\"", "def", "\"" }, 288*cdf0e10cSrcweir { "abc,abc=,def=abc", "def", "abc" }, 289*cdf0e10cSrcweir { "abc,abc=,def=Abc", "def", "Abc" }, 290*cdf0e10cSrcweir { "abc,abc=,def=aBC", "def", "aBC" }, 291*cdf0e10cSrcweir { "abc,abc=,def=ABC", "def", "ABC" } }; 292*cdf0e10cSrcweir for (int i = 0; i < sizeof aTests / sizeof (Test); ++i) 293*cdf0e10cSrcweir { 294*cdf0e10cSrcweir bool bValid = false; 295*cdf0e10cSrcweir rtl::OUString aValue; 296*cdf0e10cSrcweir try 297*cdf0e10cSrcweir { 298*cdf0e10cSrcweir aValue = cppu::UnoUrlDescriptor(rtl::OUString::createFromAscii( 299*cdf0e10cSrcweir aTests[i].pInput)). 300*cdf0e10cSrcweir getParameter(rtl::OUString::createFromAscii(aTests[i].pKey)); 301*cdf0e10cSrcweir bValid = true; 302*cdf0e10cSrcweir } 303*cdf0e10cSrcweir catch (rtl::MalformedUriException &) 304*cdf0e10cSrcweir {} 305*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("Failed to parse URI", bValid); 306*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("Failed to get param correctly", 307*cdf0e10cSrcweir aValue.equalsAscii(aTests[i].pValue)); 308*cdf0e10cSrcweir } 309*cdf0e10cSrcweir } 310*cdf0e10cSrcweir 311*cdf0e10cSrcweir void testUrlParsing() 312*cdf0e10cSrcweir { 313*cdf0e10cSrcweir struct Test 314*cdf0e10cSrcweir { 315*cdf0e10cSrcweir char const * pInput; 316*cdf0e10cSrcweir bool bValid; 317*cdf0e10cSrcweir }; 318*cdf0e10cSrcweir static Test const aTests[] 319*cdf0e10cSrcweir = { { "", false }, 320*cdf0e10cSrcweir { "abc", false }, 321*cdf0e10cSrcweir { "uno", false }, 322*cdf0e10cSrcweir { "uno:", false }, 323*cdf0e10cSrcweir { "uno:abc;def;ghi", true }, 324*cdf0e10cSrcweir { "Uno:abc;def;ghi", true }, 325*cdf0e10cSrcweir { "uNO:abc;def;ghi", true }, 326*cdf0e10cSrcweir { "UNO:abc;def;ghi", true }, 327*cdf0e10cSrcweir { "uno:abc,def=xxx,ghi=xxx;def,ghi=xxx,jkl=xxx;ghi", true }, 328*cdf0e10cSrcweir { "uno:abc,def=xxx,ghi=xxx;def,ghi=xxx,jkl=xxx,;ghi", false }, 329*cdf0e10cSrcweir { "uno:abc;def;", false }, 330*cdf0e10cSrcweir { "uno:abc;def;a", true }, 331*cdf0e10cSrcweir { "uno:abc;def;A", true }, 332*cdf0e10cSrcweir { "uno:abc;def;1", true }, 333*cdf0e10cSrcweir { "uno:abc;def;$&+,/:=?@", true }, 334*cdf0e10cSrcweir { "uno:abc;def;%24&+,/:=?@", false } }; 335*cdf0e10cSrcweir for (int i = 0; i < sizeof aTests / sizeof (Test); ++i) 336*cdf0e10cSrcweir { 337*cdf0e10cSrcweir bool bValid = false; 338*cdf0e10cSrcweir try 339*cdf0e10cSrcweir { 340*cdf0e10cSrcweir cppu::UnoUrl aUrl(rtl::OUString::createFromAscii(aTests[i].pInput)); 341*cdf0e10cSrcweir bValid = true; 342*cdf0e10cSrcweir } 343*cdf0e10cSrcweir catch (rtl::MalformedUriException &) 344*cdf0e10cSrcweir {} 345*cdf0e10cSrcweir 346*cdf0e10cSrcweir if (aTests[i].bValid) 347*cdf0e10cSrcweir { 348*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("Valid uri parsed as invalid", bValid); 349*cdf0e10cSrcweir } 350*cdf0e10cSrcweir else 351*cdf0e10cSrcweir { 352*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("Invalid uri parsed as valid", !bValid); 353*cdf0e10cSrcweir } 354*cdf0e10cSrcweir 355*cdf0e10cSrcweir } 356*cdf0e10cSrcweir } 357*cdf0e10cSrcweir 358*cdf0e10cSrcweir void testUrlConnection() 359*cdf0e10cSrcweir { 360*cdf0e10cSrcweir struct Test 361*cdf0e10cSrcweir { 362*cdf0e10cSrcweir char const * pInput; 363*cdf0e10cSrcweir char const * pConnection; 364*cdf0e10cSrcweir }; 365*cdf0e10cSrcweir static Test const aTests[] 366*cdf0e10cSrcweir = { { "uno:abc;def;ghi", "abc" }, 367*cdf0e10cSrcweir { "uno:Abc;def;ghi", "Abc" }, 368*cdf0e10cSrcweir { "uno:aBC;def;ghi", "aBC" }, 369*cdf0e10cSrcweir { "uno:ABC;def;ghi", "ABC" }, 370*cdf0e10cSrcweir { "uno:abc,def=xxx,ghi=xxx;def,ghi=xxx,jkl=xxx;ghi", 371*cdf0e10cSrcweir "abc,def=xxx,ghi=xxx" } }; 372*cdf0e10cSrcweir for (int i = 0; i < sizeof aTests / sizeof (Test); ++i) 373*cdf0e10cSrcweir { 374*cdf0e10cSrcweir bool bValid = false; 375*cdf0e10cSrcweir rtl::OUString aConnection; 376*cdf0e10cSrcweir try 377*cdf0e10cSrcweir { 378*cdf0e10cSrcweir aConnection = cppu::UnoUrl(rtl::OUString::createFromAscii( 379*cdf0e10cSrcweir aTests[i].pInput)). 380*cdf0e10cSrcweir getConnection().getDescriptor(); 381*cdf0e10cSrcweir bValid = true; 382*cdf0e10cSrcweir } 383*cdf0e10cSrcweir catch (rtl::MalformedUriException &) 384*cdf0e10cSrcweir {} 385*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("Failed to parse URI", bValid); 386*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("Failed to get param correctly", 387*cdf0e10cSrcweir aConnection.equalsAscii( 388*cdf0e10cSrcweir aTests[i].pConnection)); 389*cdf0e10cSrcweir } 390*cdf0e10cSrcweir } 391*cdf0e10cSrcweir 392*cdf0e10cSrcweir void testUrlProtocol() 393*cdf0e10cSrcweir { 394*cdf0e10cSrcweir struct Test 395*cdf0e10cSrcweir { 396*cdf0e10cSrcweir char const * pInput; 397*cdf0e10cSrcweir char const * pProtocol; 398*cdf0e10cSrcweir }; 399*cdf0e10cSrcweir static Test const aTests[] 400*cdf0e10cSrcweir = { { "uno:abc;def;ghi", "def" }, 401*cdf0e10cSrcweir { "uno:abc;Def;ghi", "Def" }, 402*cdf0e10cSrcweir { "uno:abc;dEF;ghi", "dEF" }, 403*cdf0e10cSrcweir { "uno:abc;DEF;ghi", "DEF" }, 404*cdf0e10cSrcweir { "uno:abc,def=xxx,ghi=xxx;def,ghi=xxx,jkl=xxx;ghi", 405*cdf0e10cSrcweir "def,ghi=xxx,jkl=xxx" } }; 406*cdf0e10cSrcweir for (int i = 0; i < sizeof aTests / sizeof (Test); ++i) 407*cdf0e10cSrcweir { 408*cdf0e10cSrcweir bool bValid = false; 409*cdf0e10cSrcweir rtl::OUString aProtocol; 410*cdf0e10cSrcweir try 411*cdf0e10cSrcweir { 412*cdf0e10cSrcweir aProtocol = cppu::UnoUrl(rtl::OUString::createFromAscii( 413*cdf0e10cSrcweir aTests[i].pInput)). 414*cdf0e10cSrcweir getProtocol().getDescriptor(); 415*cdf0e10cSrcweir bValid = true; 416*cdf0e10cSrcweir } 417*cdf0e10cSrcweir catch (rtl::MalformedUriException &) 418*cdf0e10cSrcweir {} 419*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("Failed to parse URI", bValid); 420*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("Failed to get protocol correctly", 421*cdf0e10cSrcweir aProtocol.equalsAscii( 422*cdf0e10cSrcweir aTests[i].pProtocol)); 423*cdf0e10cSrcweir } 424*cdf0e10cSrcweir } 425*cdf0e10cSrcweir 426*cdf0e10cSrcweir void testUrlObjectName() 427*cdf0e10cSrcweir { 428*cdf0e10cSrcweir struct Test 429*cdf0e10cSrcweir { 430*cdf0e10cSrcweir char const * pInput; 431*cdf0e10cSrcweir char const * pObjectName; 432*cdf0e10cSrcweir }; 433*cdf0e10cSrcweir static Test const aTests[] 434*cdf0e10cSrcweir = { { "uno:abc;def;ghi", "ghi" }, 435*cdf0e10cSrcweir { "uno:abc;def;Ghi", "Ghi" }, 436*cdf0e10cSrcweir { "uno:abc;def;gHI", "gHI" }, 437*cdf0e10cSrcweir { "uno:abc;def;GHI", "GHI" }, 438*cdf0e10cSrcweir { "uno:abc,def=xxx,ghi=xxx;def,ghi=xxx,jkl=xxx;ghi", "ghi" }, 439*cdf0e10cSrcweir { "uno:abc;def;a", "a" }, 440*cdf0e10cSrcweir { "uno:abc;def;A", "A" }, 441*cdf0e10cSrcweir { "uno:abc;def;1", "1" }, 442*cdf0e10cSrcweir { "uno:abc;def;$&+,/:=?@", "$&+,/:=?@" } }; 443*cdf0e10cSrcweir for (int i = 0; i < sizeof aTests / sizeof (Test); ++i) 444*cdf0e10cSrcweir { 445*cdf0e10cSrcweir bool bValid = false; 446*cdf0e10cSrcweir rtl::OUString aObjectName; 447*cdf0e10cSrcweir try 448*cdf0e10cSrcweir { 449*cdf0e10cSrcweir aObjectName = cppu::UnoUrl(rtl::OUString::createFromAscii( 450*cdf0e10cSrcweir aTests[i].pInput)).getObjectName(); 451*cdf0e10cSrcweir bValid = true; 452*cdf0e10cSrcweir } 453*cdf0e10cSrcweir catch (rtl::MalformedUriException &) 454*cdf0e10cSrcweir {} 455*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("Failed to parse URI", bValid); 456*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("Failed to get protocol correctly", 457*cdf0e10cSrcweir aObjectName.equalsAscii( 458*cdf0e10cSrcweir aTests[i].pObjectName)); 459*cdf0e10cSrcweir } 460*cdf0e10cSrcweir } 461*cdf0e10cSrcweir 462*cdf0e10cSrcweir // Automatic registration code 463*cdf0e10cSrcweir CPPUNIT_TEST_SUITE(UrlTest); 464*cdf0e10cSrcweir CPPUNIT_TEST(testDescriptorParsing); 465*cdf0e10cSrcweir CPPUNIT_TEST(testDescriptorDescriptor); 466*cdf0e10cSrcweir CPPUNIT_TEST(testDescriptorName); 467*cdf0e10cSrcweir CPPUNIT_TEST(testDescriptorKey); 468*cdf0e10cSrcweir CPPUNIT_TEST(testDescriptorValue); 469*cdf0e10cSrcweir CPPUNIT_TEST(testUrlParsing); 470*cdf0e10cSrcweir CPPUNIT_TEST(testUrlConnection); 471*cdf0e10cSrcweir CPPUNIT_TEST(testUrlProtocol); 472*cdf0e10cSrcweir CPPUNIT_TEST(testUrlObjectName); 473*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_END(); 474*cdf0e10cSrcweir }; 475*cdf0e10cSrcweir } // namespace cppu_ifcontainer 476*cdf0e10cSrcweir 477*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(cppu_unourl::UrlTest, 478*cdf0e10cSrcweir "cppu_unourl"); 479*cdf0e10cSrcweir 480*cdf0e10cSrcweir NOADDITIONAL; 481*cdf0e10cSrcweir 482