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