LCOV - code coverage report
Current view: top level - cppuhelper/qa/unourl - cppu_unourl.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 110 117 94.0 %
Date: 2012-08-25 Functions: 18 19 94.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 288 568 50.7 %

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

Generated by: LCOV version 1.10