LCOV - code coverage report
Current view: top level - comphelper/qa/string - test_string.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 175 225 77.8 %
Date: 2012-08-25 Functions: 29 54 53.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 540 1082 49.9 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*
       3                 :            :  * This file is part of the LibreOffice project.
       4                 :            :  *
       5                 :            :  * This Source Code Form is subject to the terms of the Mozilla Public
       6                 :            :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7                 :            :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8                 :            :  *
       9                 :            :  * This file incorporates work covered by the following license notice:
      10                 :            :  *
      11                 :            :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12                 :            :  *   contributor license agreements. See the NOTICE file distributed
      13                 :            :  *   with this work for additional information regarding copyright
      14                 :            :  *   ownership. The ASF licenses this file to you under the Apache
      15                 :            :  *   License, Version 2.0 (the "License"); you may not use this file
      16                 :            :  *   except in compliance with the License. You may obtain a copy of
      17                 :            :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18                 :            :  */
      19                 :            : 
      20                 :            : #include <comphelper/string.hxx>
      21                 :            : #include <cppuhelper/implbase1.hxx>
      22                 :            : #include <com/sun/star/i18n/CharType.hpp>
      23                 :            : 
      24                 :            : #include "cppunit/TestAssert.h"
      25                 :            : #include "cppunit/TestFixture.h"
      26                 :            : #include "cppunit/extensions/HelperMacros.h"
      27                 :            : #include "cppunit/plugin/TestPlugIn.h"
      28                 :            : #include "rtl/string.hxx"
      29                 :            : #include "rtl/ustring.hxx"
      30                 :            : 
      31                 :            : namespace {
      32                 :            : 
      33         [ -  + ]:         99 : class TestString: public CppUnit::TestFixture
      34                 :            : {
      35                 :            : public:
      36                 :            :     void testNatural();
      37                 :            :     void testRemove();
      38                 :            :     void testStripStart();
      39                 :            :     void testStripEnd();
      40                 :            :     void testStrip();
      41                 :            :     void testToken();
      42                 :            :     void testTokenCount();
      43                 :            :     void testDecimalStringToNumber();
      44                 :            :     void testIsdigitAsciiString();
      45                 :            :     void testReverseString();
      46                 :            :     void testEqualsString();
      47                 :            : 
      48 [ +  - ][ +  - ]:          6 :     CPPUNIT_TEST_SUITE(TestString);
         [ +  - ][ +  - ]
                 [ #  # ]
      49 [ +  - ][ +  - ]:          3 :     CPPUNIT_TEST(testNatural);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
      50 [ +  - ][ +  - ]:          3 :     CPPUNIT_TEST(testRemove);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
      51 [ +  - ][ +  - ]:          3 :     CPPUNIT_TEST(testStripStart);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
      52 [ +  - ][ +  - ]:          3 :     CPPUNIT_TEST(testStripEnd);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
      53 [ +  - ][ +  - ]:          3 :     CPPUNIT_TEST(testStrip);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
      54 [ +  - ][ +  - ]:          3 :     CPPUNIT_TEST(testToken);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
      55 [ +  - ][ +  - ]:          3 :     CPPUNIT_TEST(testTokenCount);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
      56 [ +  - ][ +  - ]:          3 :     CPPUNIT_TEST(testDecimalStringToNumber);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
      57 [ +  - ][ +  - ]:          3 :     CPPUNIT_TEST(testIsdigitAsciiString);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
      58 [ +  - ][ +  - ]:          3 :     CPPUNIT_TEST(testReverseString);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
      59 [ +  - ][ +  - ]:          3 :     CPPUNIT_TEST(testEqualsString);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
      60 [ +  - ][ +  - ]:          6 :     CPPUNIT_TEST_SUITE_END();
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
      61                 :            : };
      62                 :            : 
      63                 :          3 : void TestString::testDecimalStringToNumber()
      64                 :            : {
      65         [ +  - ]:          3 :     rtl::OUString s1(RTL_CONSTASCII_USTRINGPARAM("1234"));
      66 [ +  - ][ +  - ]:          3 :     CPPUNIT_ASSERT_EQUAL((sal_uInt32)1234, comphelper::string::decimalStringToNumber(s1));
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
      67                 :          3 :     s1 += rtl::OUString(static_cast<sal_Unicode>(0x07C6));
      68 [ +  - ][ +  - ]:          3 :     CPPUNIT_ASSERT_EQUAL((sal_uInt32)12346, comphelper::string::decimalStringToNumber(s1));
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
      69                 :            :     // Codepoints on 2 16bits words
      70                 :          3 :     sal_uInt32 utf16String[] = { 0x1D7FE /* 8 */, 0x1D7F7 /* 1 */};
      71         [ +  - ]:          3 :     s1 = rtl::OUString(utf16String, 2);
      72 [ +  - ][ +  - ]:          3 :     CPPUNIT_ASSERT_EQUAL((sal_uInt32)81, comphelper::string::decimalStringToNumber(s1));
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
      73                 :          3 : }
      74                 :            : 
      75                 :          3 : void TestString::testIsdigitAsciiString()
      76                 :            : {
      77                 :          3 :     rtl::OString s1(RTL_CONSTASCII_STRINGPARAM("1234"));
      78 [ +  - ][ +  - ]:          3 :     CPPUNIT_ASSERT_EQUAL(comphelper::string::isdigitAsciiString(s1), true);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
      79                 :            : 
      80                 :          3 :     rtl::OString s2(RTL_CONSTASCII_STRINGPARAM("1A34"));
      81 [ +  - ][ +  - ]:          3 :     CPPUNIT_ASSERT_EQUAL(comphelper::string::isdigitAsciiString(s2), false);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
      82                 :            : 
      83                 :          3 :     rtl::OString s3;
      84 [ +  - ][ +  - ]:          3 :     CPPUNIT_ASSERT_EQUAL(comphelper::string::isdigitAsciiString(s3), true);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
      85                 :          3 : }
      86                 :            : 
      87                 :            : using namespace ::com::sun::star;
      88                 :            : 
      89         [ -  + ]:          9 : class testCollator : public cppu::WeakImplHelper1< i18n::XCollator >
      90                 :            : {
      91                 :            : public:
      92                 :         39 :     virtual sal_Int32 SAL_CALL compareSubstring(
      93                 :            :         const rtl::OUString& str1, sal_Int32 off1, sal_Int32 len1,
      94                 :            :         const rtl::OUString& str2, sal_Int32 off2, sal_Int32 len2) throw(uno::RuntimeException)
      95                 :            :     {
      96                 :         39 :         return str1.copy(off1, len1).compareTo(str2.copy(off2, len2));
      97                 :            :     }
      98                 :          0 :     virtual sal_Int32 SAL_CALL compareString(
      99                 :            :         const rtl::OUString& str1,
     100                 :            :         const rtl::OUString& str2) throw(uno::RuntimeException)
     101                 :            :     {
     102                 :          0 :         return str1.compareTo(str2);
     103                 :            :     }
     104                 :          0 :     virtual sal_Int32 SAL_CALL loadDefaultCollator(const lang::Locale&, sal_Int32)
     105                 :          0 :         throw(uno::RuntimeException) {return 0;}
     106                 :          0 :     virtual sal_Int32 SAL_CALL loadCollatorAlgorithm(const rtl::OUString&,
     107                 :          0 :         const lang::Locale&, sal_Int32) throw(uno::RuntimeException) {return 0;}
     108                 :          0 :     virtual void SAL_CALL loadCollatorAlgorithmWithEndUserOption(const rtl::OUString&,
     109                 :          0 :         const lang::Locale&, const uno::Sequence< sal_Int32 >&) throw(uno::RuntimeException) {}
     110                 :          0 :     virtual uno::Sequence< rtl::OUString > SAL_CALL listCollatorAlgorithms(const lang::Locale&)
     111                 :            :         throw(uno::RuntimeException)
     112                 :            :     {
     113                 :          0 :         return uno::Sequence< rtl::OUString >();
     114                 :            :     }
     115                 :          0 :     virtual uno::Sequence< sal_Int32 > SAL_CALL listCollatorOptions(const rtl::OUString&)
     116                 :            :         throw(uno::RuntimeException)
     117                 :            :     {
     118                 :          0 :         return uno::Sequence< sal_Int32 >();
     119                 :            :     }
     120                 :            : };
     121                 :            : 
     122                 :            : #define IS_DIGIT(CHAR) (((CHAR) >= 48) && ((CHAR <= 57)))
     123                 :            : 
     124         [ -  + ]:          9 : class testBreakIterator : public cppu::WeakImplHelper1< i18n::XBreakIterator >
     125                 :            : {
     126                 :            : public:
     127                 :          0 :     virtual sal_Int32 SAL_CALL nextCharacters( const rtl::OUString&, sal_Int32,
     128                 :            :         const lang::Locale&, sal_Int16, sal_Int32, sal_Int32& )
     129                 :          0 :             throw(uno::RuntimeException) {return -1;}
     130                 :          0 :     virtual sal_Int32 SAL_CALL previousCharacters( const rtl::OUString&, sal_Int32,
     131                 :            :         const lang::Locale&, sal_Int16, sal_Int32, sal_Int32& )
     132                 :          0 :             throw(uno::RuntimeException) {return -1;}
     133                 :            : 
     134                 :          0 :     virtual i18n::Boundary SAL_CALL previousWord( const rtl::OUString&, sal_Int32,
     135                 :            :         const lang::Locale&, sal_Int16) throw(uno::RuntimeException)
     136                 :          0 :         { return i18n::Boundary(); }
     137                 :          0 :     virtual i18n::Boundary SAL_CALL nextWord( const rtl::OUString&, sal_Int32,
     138                 :            :         const lang::Locale&, sal_Int16) throw(uno::RuntimeException)
     139                 :          0 :         { return i18n::Boundary(); }
     140                 :          0 :     virtual i18n::Boundary SAL_CALL getWordBoundary( const rtl::OUString&, sal_Int32,
     141                 :            :         const lang::Locale&, sal_Int16, sal_Bool )
     142                 :            :         throw(uno::RuntimeException)
     143                 :          0 :         { return i18n::Boundary(); }
     144                 :            : 
     145                 :          0 :     virtual sal_Bool SAL_CALL isBeginWord( const rtl::OUString&, sal_Int32,
     146                 :            :         const lang::Locale&, sal_Int16 ) throw(uno::RuntimeException)
     147                 :          0 :         { return false; }
     148                 :          0 :     virtual sal_Bool SAL_CALL isEndWord( const rtl::OUString&, sal_Int32,
     149                 :            :         const lang::Locale& , sal_Int16 ) throw(uno::RuntimeException)
     150                 :          0 :         { return false; }
     151                 :          0 :     virtual sal_Int16 SAL_CALL getWordType( const rtl::OUString&, sal_Int32,
     152                 :            :         const lang::Locale& ) throw(uno::RuntimeException)
     153                 :          0 :         { return 0; }
     154                 :            : 
     155                 :          0 :     virtual sal_Int32 SAL_CALL beginOfSentence( const rtl::OUString&, sal_Int32,
     156                 :            :         const lang::Locale& ) throw(uno::RuntimeException)
     157                 :          0 :         { return 0; }
     158                 :          0 :     virtual sal_Int32 SAL_CALL endOfSentence( const rtl::OUString& rText, sal_Int32,
     159                 :            :         const lang::Locale& ) throw(uno::RuntimeException)
     160                 :          0 :         { return rText.getLength(); }
     161                 :            : 
     162                 :          0 :     virtual i18n::LineBreakResults SAL_CALL getLineBreak( const rtl::OUString&, sal_Int32,
     163                 :            :         const lang::Locale&, sal_Int32,
     164                 :            :         const i18n::LineBreakHyphenationOptions&,
     165                 :            :         const i18n::LineBreakUserOptions&)
     166                 :            :         throw(uno::RuntimeException)
     167                 :            :     {
     168                 :          0 :         return i18n::LineBreakResults();
     169                 :            :     }
     170                 :            : 
     171                 :          0 :     virtual sal_Int16 SAL_CALL getScriptType( const rtl::OUString&, sal_Int32 )
     172                 :          0 :         throw(uno::RuntimeException) { return -1; }
     173                 :          0 :     virtual sal_Int32 SAL_CALL beginOfScript( const rtl::OUString&, sal_Int32,
     174                 :          0 :         sal_Int16 ) throw(uno::RuntimeException) { return -1; }
     175                 :          0 :     virtual sal_Int32 SAL_CALL endOfScript( const rtl::OUString&, sal_Int32,
     176                 :          0 :         sal_Int16 ) throw(uno::RuntimeException) { return -1; }
     177                 :          0 :     virtual sal_Int32 SAL_CALL previousScript( const rtl::OUString&, sal_Int32,
     178                 :          0 :         sal_Int16 ) throw(uno::RuntimeException) { return -1; }
     179                 :          0 :     virtual sal_Int32 SAL_CALL nextScript( const rtl::OUString&, sal_Int32,
     180                 :          0 :         sal_Int16 ) throw(uno::RuntimeException) { return -1; }
     181                 :            : 
     182                 :          0 :     virtual sal_Int32 SAL_CALL beginOfCharBlock( const rtl::OUString&, sal_Int32,
     183                 :          0 :         const lang::Locale&, sal_Int16 ) throw(uno::RuntimeException) { return -1; }
     184                 :         54 :     virtual sal_Int32 SAL_CALL endOfCharBlock( const rtl::OUString& rText, sal_Int32 nStartPos,
     185                 :            :         const lang::Locale&, sal_Int16 CharType ) throw(uno::RuntimeException)
     186                 :            :     {
     187                 :         54 :         const sal_Unicode *pStr = rText.getStr()+nStartPos;
     188         [ +  + ]:        132 :         for (sal_Int32 nI = nStartPos; nI < rText.getLength(); ++nI)
     189                 :            :         {
     190 [ +  - ][ +  - ]:         96 :             if (CharType == i18n::CharType::DECIMAL_DIGIT_NUMBER && !IS_DIGIT(*pStr))
                 [ +  + ]
     191                 :         18 :                 return nI;
     192 [ -  + ][ #  # ]:         78 :             else if (CharType != i18n::CharType::DECIMAL_DIGIT_NUMBER && IS_DIGIT(*pStr))
                 [ #  # ]
     193                 :          0 :                 return nI;
     194                 :         78 :             ++pStr;
     195                 :            :         }
     196                 :         54 :         return -1;
     197                 :            :     }
     198                 :          0 :     virtual sal_Int32 SAL_CALL previousCharBlock( const rtl::OUString&, sal_Int32,
     199                 :          0 :         const lang::Locale&, sal_Int16 ) throw(uno::RuntimeException) { return -1; }
     200                 :         78 :     virtual sal_Int32 SAL_CALL nextCharBlock( const rtl::OUString& rText, sal_Int32 nStartPos,
     201                 :            :         const lang::Locale&, sal_Int16 CharType ) throw(uno::RuntimeException)
     202                 :            :     {
     203                 :         78 :         const sal_Unicode *pStr = rText.getStr()+nStartPos;
     204         [ +  + ]:        588 :         for (sal_Int32 nI = nStartPos; nI < rText.getLength(); ++nI)
     205                 :            :         {
     206 [ +  - ][ +  + ]:        552 :             if (CharType == i18n::CharType::DECIMAL_DIGIT_NUMBER && IS_DIGIT(*pStr))
                 [ +  + ]
     207                 :         42 :                 return nI;
     208 [ -  + ][ #  # ]:        510 :             else if (CharType != i18n::CharType::DECIMAL_DIGIT_NUMBER && !IS_DIGIT(*pStr))
                 [ #  # ]
     209                 :          0 :                 return nI;
     210                 :        510 :             ++pStr;
     211                 :            :         }
     212                 :         78 :         return -1;
     213                 :            :     }
     214                 :            : };
     215                 :            : 
     216                 :          3 : void TestString::testNatural()
     217                 :            : {
     218                 :            :     using namespace comphelper::string;
     219                 :            : 
     220 [ +  - ][ +  - ]:          3 :     uno::Reference< i18n::XCollator > xCollator(new testCollator);
                 [ +  - ]
     221 [ +  - ][ +  - ]:          3 :     uno::Reference< i18n::XBreakIterator > xBI(new testBreakIterator);
                 [ +  - ]
     222                 :            : 
     223                 :            : // --- Some generic tests to ensure we do not alter original behavior
     224                 :            : // outside what we want
     225 [ +  - ][ +  - ]:          6 :     CPPUNIT_ASSERT(
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     226                 :            :         compareNatural(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("ABC"))), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("ABC"))), xCollator, xBI, lang::Locale()) == 0
     227         [ +  - ]:          3 :     );
     228                 :            :     // Case sensitivity
     229 [ +  - ][ +  - ]:          6 :     CPPUNIT_ASSERT(
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     230                 :            :         compareNatural(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("ABC"))), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("abc"))), xCollator, xBI, lang::Locale()) < 0
     231         [ +  - ]:          3 :     );
     232                 :            :     // Reverse
     233 [ +  - ][ +  - ]:          6 :     CPPUNIT_ASSERT(
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     234                 :            :         compareNatural(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("abc"))), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("ABC"))), xCollator, xBI, lang::Locale()) > 0
     235         [ +  - ]:          3 :     );
     236                 :            :     // First shorter
     237 [ +  - ][ +  - ]:          6 :     CPPUNIT_ASSERT(
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     238                 :            :         compareNatural(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("alongstring"))), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("alongerstring"))), xCollator, xBI, lang::Locale()) > 0
     239         [ +  - ]:          3 :     );
     240                 :            :     // Second shorter
     241 [ +  - ][ +  - ]:          6 :     CPPUNIT_ASSERT(
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     242                 :            :         compareNatural(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("alongerstring"))), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("alongstring"))), xCollator, xBI, lang::Locale()) < 0
     243         [ +  - ]:          3 :     );
     244                 :            : // -- Here we go on natural order, each one is followed by classic compare and the reverse comparison
     245                 :            :     // That's why we originally made the patch
     246 [ +  - ][ +  - ]:          6 :     CPPUNIT_ASSERT(
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     247                 :            :         compareNatural(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("Heading 9"))), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("Heading 10"))), xCollator, xBI, lang::Locale()) < 0
     248         [ +  - ]:          3 :     );
     249                 :            :     // Original behavior
     250 [ +  - ][ +  - ]:          6 :     CPPUNIT_ASSERT(
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     251                 :            :         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("Heading 9"))).compareTo(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("Heading 10")))) > 0
     252         [ +  - ]:          3 :     );
     253 [ +  - ][ +  - ]:          6 :     CPPUNIT_ASSERT(
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     254                 :            :         compareNatural(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("Heading 10"))), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("Heading 9"))), xCollator, xBI, lang::Locale()) > 0
     255         [ +  - ]:          3 :     );
     256                 :            :     // Harder
     257 [ +  - ][ +  - ]:          6 :     CPPUNIT_ASSERT(
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     258                 :            :         compareNatural(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("July, the 4th"))), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("July, the 10th"))), xCollator, xBI, lang::Locale()) < 0
     259         [ +  - ]:          3 :     );
     260 [ +  - ][ +  - ]:          6 :     CPPUNIT_ASSERT(
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     261                 :            :         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("July, the 4th"))).compareTo(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("July, the 10th")))) > 0
     262         [ +  - ]:          3 :     );
     263 [ +  - ][ +  - ]:          6 :     CPPUNIT_ASSERT(
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     264                 :            :         compareNatural(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("July, the 10th"))), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("July, the 4th"))), xCollator, xBI, lang::Locale()) > 0
     265         [ +  - ]:          3 :     );
     266                 :            :     // Hardest
     267 [ +  - ][ +  - ]:          6 :     CPPUNIT_ASSERT(
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     268                 :            :         compareNatural(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("abc08"))), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("abc010"))), xCollator, xBI, lang::Locale()) < 0
     269         [ +  - ]:          3 :     );
     270 [ +  - ][ +  - ]:          6 :     CPPUNIT_ASSERT(
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     271                 :            :         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("abc08"))).compareTo(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("abc010")))) > 0
     272         [ +  - ]:          3 :     );
     273 [ +  - ][ +  - ]:          6 :     CPPUNIT_ASSERT(
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     274                 :            :         compareNatural(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("abc010"))), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("abc08"))), xCollator, xBI, lang::Locale()) > 0
     275         [ +  - ]:          3 :     );
     276 [ +  - ][ +  - ]:          6 :     CPPUNIT_ASSERT(
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     277                 :            :         compareNatural(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("apple10apple"))), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("apple10apple"))), xCollator, xBI, lang::Locale()) == 0
     278         [ +  - ]:          6 :     );
     279                 :          3 : }
     280                 :            : 
     281                 :          3 : void TestString::testRemove()
     282                 :            : {
     283                 :          3 :     ::rtl::OString aIn(RTL_CONSTASCII_STRINGPARAM("abc"));
     284                 :          3 :     ::rtl::OString aOut;
     285                 :            : 
     286                 :          3 :     aOut = ::comphelper::string::remove(aIn, 'b');
     287 [ +  - ][ +  - ]:          3 :     CPPUNIT_ASSERT(aOut.equalsL(RTL_CONSTASCII_STRINGPARAM("ac")));
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     288                 :            : 
     289                 :          3 :     aIn = rtl::OString(RTL_CONSTASCII_STRINGPARAM("aaa"));
     290                 :            : 
     291                 :          3 :     aOut = ::comphelper::string::remove(aIn, 'a');
     292 [ +  - ][ +  - ]:          3 :     CPPUNIT_ASSERT(aOut.isEmpty());
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     293                 :          3 : }
     294                 :            : 
     295                 :          3 : void TestString::testStripStart()
     296                 :            : {
     297                 :          3 :     ::rtl::OString aIn(RTL_CONSTASCII_STRINGPARAM("abc"));
     298                 :          3 :     ::rtl::OString aOut;
     299                 :            : 
     300         [ +  - ]:          3 :     aOut = ::comphelper::string::stripStart(aIn, 'b');
     301 [ +  - ][ +  - ]:          3 :     CPPUNIT_ASSERT(aOut.equalsL(RTL_CONSTASCII_STRINGPARAM("abc")));
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     302                 :            : 
     303         [ +  - ]:          3 :     aOut = ::comphelper::string::stripStart(aIn, 'a');
     304 [ +  - ][ +  - ]:          3 :     CPPUNIT_ASSERT(aOut.equalsL(RTL_CONSTASCII_STRINGPARAM("bc")));
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     305                 :            : 
     306                 :          3 :     aIn = rtl::OString(RTL_CONSTASCII_STRINGPARAM("aaa"));
     307         [ +  - ]:          3 :     aOut = ::comphelper::string::stripStart(aIn, 'a');
     308 [ +  - ][ +  - ]:          3 :     CPPUNIT_ASSERT(aOut.isEmpty());
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     309                 :            : 
     310                 :          3 :     aIn = rtl::OString(RTL_CONSTASCII_STRINGPARAM("aba"));
     311         [ +  - ]:          3 :     aOut = ::comphelper::string::stripStart(aIn, 'a');
     312 [ +  - ][ +  - ]:          3 :     CPPUNIT_ASSERT(aOut.equalsL(RTL_CONSTASCII_STRINGPARAM("ba")));
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     313                 :          3 : }
     314                 :            : 
     315                 :          3 : void TestString::testStripEnd()
     316                 :            : {
     317                 :          3 :     ::rtl::OString aIn(RTL_CONSTASCII_STRINGPARAM("abc"));
     318                 :          3 :     ::rtl::OString aOut;
     319                 :            : 
     320         [ +  - ]:          3 :     aOut = ::comphelper::string::stripEnd(aIn, 'b');
     321 [ +  - ][ +  - ]:          3 :     CPPUNIT_ASSERT(aOut.equalsL(RTL_CONSTASCII_STRINGPARAM("abc")));
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     322                 :            : 
     323         [ +  - ]:          3 :     aOut = ::comphelper::string::stripEnd(aIn, 'c');
     324 [ +  - ][ +  - ]:          3 :     CPPUNIT_ASSERT(aOut.equalsL(RTL_CONSTASCII_STRINGPARAM("ab")));
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     325                 :            : 
     326                 :          3 :     aIn = rtl::OString(RTL_CONSTASCII_STRINGPARAM("aaa"));
     327         [ +  - ]:          3 :     aOut = ::comphelper::string::stripEnd(aIn, 'a');
     328 [ +  - ][ +  - ]:          3 :     CPPUNIT_ASSERT(aOut.isEmpty());
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     329                 :            : 
     330                 :          3 :     aIn = rtl::OString(RTL_CONSTASCII_STRINGPARAM("aba"));
     331         [ +  - ]:          3 :     aOut = ::comphelper::string::stripEnd(aIn, 'a');
     332 [ +  - ][ +  - ]:          3 :     CPPUNIT_ASSERT(aOut.equalsL(RTL_CONSTASCII_STRINGPARAM("ab")));
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     333                 :          3 : }
     334                 :            : 
     335                 :          3 : void TestString::testStrip()
     336                 :            : {
     337                 :          3 :     ::rtl::OString aIn(RTL_CONSTASCII_STRINGPARAM("abc"));
     338                 :          3 :     ::rtl::OString aOut;
     339                 :            : 
     340         [ +  - ]:          3 :     aOut = ::comphelper::string::strip(aIn, 'b');
     341 [ +  - ][ +  - ]:          3 :     CPPUNIT_ASSERT(aOut.equalsL(RTL_CONSTASCII_STRINGPARAM("abc")));
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     342                 :            : 
     343         [ +  - ]:          3 :     aOut = ::comphelper::string::strip(aIn, 'c');
     344 [ +  - ][ +  - ]:          3 :     CPPUNIT_ASSERT(aOut.equalsL(RTL_CONSTASCII_STRINGPARAM("ab")));
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     345                 :            : 
     346                 :          3 :     aIn = rtl::OString(RTL_CONSTASCII_STRINGPARAM("aaa"));
     347         [ +  - ]:          3 :     aOut = ::comphelper::string::strip(aIn, 'a');
     348 [ +  - ][ +  - ]:          3 :     CPPUNIT_ASSERT(aOut.isEmpty());
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     349                 :            : 
     350                 :          3 :     aIn = rtl::OString(RTL_CONSTASCII_STRINGPARAM("aba"));
     351         [ +  - ]:          3 :     aOut = ::comphelper::string::strip(aIn, 'a');
     352 [ +  - ][ +  - ]:          3 :     CPPUNIT_ASSERT(aOut.equalsL(RTL_CONSTASCII_STRINGPARAM("b")));
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     353                 :          3 : }
     354                 :            : 
     355                 :          3 : void TestString::testToken()
     356                 :            : {
     357                 :          3 :     ::rtl::OString aIn(RTL_CONSTASCII_STRINGPARAM("10.11.12"));
     358                 :          3 :     ::rtl::OString aOut;
     359                 :            : 
     360                 :          3 :     aOut = ::comphelper::string::getToken(aIn, -1, '.');
     361 [ +  - ][ +  - ]:          3 :     CPPUNIT_ASSERT(aOut.isEmpty());
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     362                 :            : 
     363                 :          3 :     aOut = ::comphelper::string::getToken(aIn, 0, '.');
     364 [ +  - ][ +  - ]:          3 :     CPPUNIT_ASSERT(aOut.equalsL(RTL_CONSTASCII_STRINGPARAM("10")));
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     365                 :            : 
     366                 :          3 :     aOut = ::comphelper::string::getToken(aIn, 1, '.');
     367 [ +  - ][ +  - ]:          3 :     CPPUNIT_ASSERT(aOut.equalsL(RTL_CONSTASCII_STRINGPARAM("11")));
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     368                 :            : 
     369                 :          3 :     aOut = ::comphelper::string::getToken(aIn, 2, '.');
     370 [ +  - ][ +  - ]:          3 :     CPPUNIT_ASSERT(aOut.equalsL(RTL_CONSTASCII_STRINGPARAM("12")));
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     371                 :            : 
     372                 :          3 :     aOut = ::comphelper::string::getToken(aIn, 3, '.');
     373 [ +  - ][ +  - ]:          3 :     CPPUNIT_ASSERT(aOut.isEmpty());
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     374                 :          3 : }
     375                 :            : 
     376                 :          3 : void TestString::testTokenCount()
     377                 :            : {
     378                 :          3 :     ::rtl::OString aIn(RTL_CONSTASCII_STRINGPARAM("10.11.12"));
     379                 :            :     sal_Int32 nOut;
     380                 :            : 
     381         [ +  - ]:          3 :     nOut = ::comphelper::string::getTokenCount(aIn, '.');
     382 [ +  - ][ +  - ]:          3 :     CPPUNIT_ASSERT(nOut == 3);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     383                 :            : 
     384         [ +  - ]:          3 :     nOut = ::comphelper::string::getTokenCount(aIn, 'X');
     385 [ +  - ][ +  - ]:          3 :     CPPUNIT_ASSERT(nOut == 1);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     386                 :            : 
     387         [ +  - ]:          3 :     nOut = ::comphelper::string::getTokenCount(rtl::OString(), 'X');
     388 [ +  - ][ +  - ]:          3 :     CPPUNIT_ASSERT(nOut == 0);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     389                 :          3 : }
     390                 :            : 
     391                 :          3 : void TestString::testReverseString()
     392                 :            : {
     393                 :          3 :     ::rtl::OString aIn("ABC");
     394         [ +  - ]:          3 :     ::rtl::OString aOut = ::comphelper::string::reverseString(aIn);
     395                 :            : 
     396 [ +  - ][ +  - ]:          3 :     CPPUNIT_ASSERT(aOut == "CBA");
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     397                 :          3 : }
     398                 :            : 
     399                 :          3 : void TestString::testEqualsString()
     400                 :            : {
     401                 :          3 :     ::rtl::OString aIn("A");
     402 [ +  - ][ +  - ]:          3 :     CPPUNIT_ASSERT(::comphelper::string::equals(aIn, 'A'));
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     403 [ +  - ][ +  - ]:          3 :     CPPUNIT_ASSERT(!::comphelper::string::equals(aIn, 'B'));
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     404                 :          3 :     aIn = ::rtl::OString("AA");
     405 [ +  - ][ +  - ]:          3 :     CPPUNIT_ASSERT(!::comphelper::string::equals(aIn, 'A'));
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     406                 :          3 :     aIn = ::rtl::OString();
     407 [ +  - ][ +  - ]:          3 :     CPPUNIT_ASSERT(!::comphelper::string::equals(aIn, 'A'));
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     408                 :          3 : }
     409                 :            : 
     410                 :          3 : CPPUNIT_TEST_SUITE_REGISTRATION(TestString);
     411                 :            : 
     412                 :            : }
     413                 :            : 
     414 [ +  - ][ +  - ]:         12 : CPPUNIT_PLUGIN_IMPLEMENT();
         [ +  - ][ +  - ]
         [ +  - ][ #  # ]
     415                 :            : 
     416                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10