LCOV - code coverage report
Current view: top level - libreoffice/comphelper/qa/string - test_string.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 175 225 77.8 %
Date: 2012-12-27 Functions: 29 54 53.7 %
Legend: Lines: hit not hit

          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          33 : 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           2 :     CPPUNIT_TEST_SUITE(TestString);
      49           1 :     CPPUNIT_TEST(testNatural);
      50           1 :     CPPUNIT_TEST(testRemove);
      51           1 :     CPPUNIT_TEST(testStripStart);
      52           1 :     CPPUNIT_TEST(testStripEnd);
      53           1 :     CPPUNIT_TEST(testStrip);
      54           1 :     CPPUNIT_TEST(testToken);
      55           1 :     CPPUNIT_TEST(testTokenCount);
      56           1 :     CPPUNIT_TEST(testDecimalStringToNumber);
      57           1 :     CPPUNIT_TEST(testIsdigitAsciiString);
      58           1 :     CPPUNIT_TEST(testReverseString);
      59           1 :     CPPUNIT_TEST(testEqualsString);
      60           2 :     CPPUNIT_TEST_SUITE_END();
      61             : };
      62             : 
      63           1 : void TestString::testDecimalStringToNumber()
      64             : {
      65           1 :     rtl::OUString s1(RTL_CONSTASCII_USTRINGPARAM("1234"));
      66           1 :     CPPUNIT_ASSERT_EQUAL((sal_uInt32)1234, comphelper::string::decimalStringToNumber(s1));
      67           1 :     s1 += rtl::OUString(static_cast<sal_Unicode>(0x07C6));
      68           1 :     CPPUNIT_ASSERT_EQUAL((sal_uInt32)12346, comphelper::string::decimalStringToNumber(s1));
      69             :     // Codepoints on 2 16bits words
      70           1 :     sal_uInt32 utf16String[] = { 0x1D7FE /* 8 */, 0x1D7F7 /* 1 */};
      71           1 :     s1 = rtl::OUString(utf16String, 2);
      72           1 :     CPPUNIT_ASSERT_EQUAL((sal_uInt32)81, comphelper::string::decimalStringToNumber(s1));
      73           1 : }
      74             : 
      75           1 : void TestString::testIsdigitAsciiString()
      76             : {
      77           1 :     rtl::OString s1(RTL_CONSTASCII_STRINGPARAM("1234"));
      78           1 :     CPPUNIT_ASSERT_EQUAL(comphelper::string::isdigitAsciiString(s1), true);
      79             : 
      80           1 :     rtl::OString s2(RTL_CONSTASCII_STRINGPARAM("1A34"));
      81           1 :     CPPUNIT_ASSERT_EQUAL(comphelper::string::isdigitAsciiString(s2), false);
      82             : 
      83           1 :     rtl::OString s3;
      84           1 :     CPPUNIT_ASSERT_EQUAL(comphelper::string::isdigitAsciiString(s3), true);
      85           1 : }
      86             : 
      87             : using namespace ::com::sun::star;
      88             : 
      89           3 : class testCollator : public cppu::WeakImplHelper1< i18n::XCollator >
      90             : {
      91             : public:
      92          13 :     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          13 :         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           3 : 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          18 :     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          18 :         const sal_Unicode *pStr = rText.getStr()+nStartPos;
     188          44 :         for (sal_Int32 nI = nStartPos; nI < rText.getLength(); ++nI)
     189             :         {
     190          32 :             if (CharType == i18n::CharType::DECIMAL_DIGIT_NUMBER && !IS_DIGIT(*pStr))
     191           6 :                 return nI;
     192          26 :             else if (CharType != i18n::CharType::DECIMAL_DIGIT_NUMBER && IS_DIGIT(*pStr))
     193           0 :                 return nI;
     194          26 :             ++pStr;
     195             :         }
     196          12 :         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          26 :     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          26 :         const sal_Unicode *pStr = rText.getStr()+nStartPos;
     204         196 :         for (sal_Int32 nI = nStartPos; nI < rText.getLength(); ++nI)
     205             :         {
     206         184 :             if (CharType == i18n::CharType::DECIMAL_DIGIT_NUMBER && IS_DIGIT(*pStr))
     207          14 :                 return nI;
     208         170 :             else if (CharType != i18n::CharType::DECIMAL_DIGIT_NUMBER && !IS_DIGIT(*pStr))
     209           0 :                 return nI;
     210         170 :             ++pStr;
     211             :         }
     212          12 :         return -1;
     213             :     }
     214             : };
     215             : 
     216           1 : void TestString::testNatural()
     217             : {
     218             :     using namespace comphelper::string;
     219             : 
     220           1 :     uno::Reference< i18n::XCollator > xCollator(new testCollator);
     221           1 :     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           2 :     CPPUNIT_ASSERT(
     226             :         compareNatural(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("ABC"))), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("ABC"))), xCollator, xBI, lang::Locale()) == 0
     227           1 :     );
     228             :     // Case sensitivity
     229           2 :     CPPUNIT_ASSERT(
     230             :         compareNatural(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("ABC"))), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("abc"))), xCollator, xBI, lang::Locale()) < 0
     231           1 :     );
     232             :     // Reverse
     233           2 :     CPPUNIT_ASSERT(
     234             :         compareNatural(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("abc"))), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("ABC"))), xCollator, xBI, lang::Locale()) > 0
     235           1 :     );
     236             :     // First shorter
     237           2 :     CPPUNIT_ASSERT(
     238             :         compareNatural(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("alongstring"))), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("alongerstring"))), xCollator, xBI, lang::Locale()) > 0
     239           1 :     );
     240             :     // Second shorter
     241           2 :     CPPUNIT_ASSERT(
     242             :         compareNatural(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("alongerstring"))), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("alongstring"))), xCollator, xBI, lang::Locale()) < 0
     243           1 :     );
     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           2 :     CPPUNIT_ASSERT(
     247             :         compareNatural(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("Heading 9"))), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("Heading 10"))), xCollator, xBI, lang::Locale()) < 0
     248           1 :     );
     249             :     // Original behavior
     250           2 :     CPPUNIT_ASSERT(
     251             :         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("Heading 9"))).compareTo(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("Heading 10")))) > 0
     252           1 :     );
     253           2 :     CPPUNIT_ASSERT(
     254             :         compareNatural(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("Heading 10"))), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("Heading 9"))), xCollator, xBI, lang::Locale()) > 0
     255           1 :     );
     256             :     // Harder
     257           2 :     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           1 :     );
     260           2 :     CPPUNIT_ASSERT(
     261             :         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("July, the 4th"))).compareTo(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("July, the 10th")))) > 0
     262           1 :     );
     263           2 :     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           1 :     );
     266             :     // Hardest
     267           2 :     CPPUNIT_ASSERT(
     268             :         compareNatural(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("abc08"))), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("abc010"))), xCollator, xBI, lang::Locale()) < 0
     269           1 :     );
     270           2 :     CPPUNIT_ASSERT(
     271             :         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("abc08"))).compareTo(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("abc010")))) > 0
     272           1 :     );
     273           2 :     CPPUNIT_ASSERT(
     274             :         compareNatural(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("abc010"))), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("abc08"))), xCollator, xBI, lang::Locale()) > 0
     275           1 :     );
     276           2 :     CPPUNIT_ASSERT(
     277             :         compareNatural(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("apple10apple"))), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(("apple10apple"))), xCollator, xBI, lang::Locale()) == 0
     278           2 :     );
     279           1 : }
     280             : 
     281           1 : void TestString::testRemove()
     282             : {
     283           1 :     ::rtl::OString aIn(RTL_CONSTASCII_STRINGPARAM("abc"));
     284           1 :     ::rtl::OString aOut;
     285             : 
     286           1 :     aOut = ::comphelper::string::remove(aIn, 'b');
     287           1 :     CPPUNIT_ASSERT(aOut.equalsL(RTL_CONSTASCII_STRINGPARAM("ac")));
     288             : 
     289           1 :     aIn = rtl::OString(RTL_CONSTASCII_STRINGPARAM("aaa"));
     290             : 
     291           1 :     aOut = ::comphelper::string::remove(aIn, 'a');
     292           1 :     CPPUNIT_ASSERT(aOut.isEmpty());
     293           1 : }
     294             : 
     295           1 : void TestString::testStripStart()
     296             : {
     297           1 :     ::rtl::OString aIn(RTL_CONSTASCII_STRINGPARAM("abc"));
     298           1 :     ::rtl::OString aOut;
     299             : 
     300           1 :     aOut = ::comphelper::string::stripStart(aIn, 'b');
     301           1 :     CPPUNIT_ASSERT(aOut.equalsL(RTL_CONSTASCII_STRINGPARAM("abc")));
     302             : 
     303           1 :     aOut = ::comphelper::string::stripStart(aIn, 'a');
     304           1 :     CPPUNIT_ASSERT(aOut.equalsL(RTL_CONSTASCII_STRINGPARAM("bc")));
     305             : 
     306           1 :     aIn = rtl::OString(RTL_CONSTASCII_STRINGPARAM("aaa"));
     307           1 :     aOut = ::comphelper::string::stripStart(aIn, 'a');
     308           1 :     CPPUNIT_ASSERT(aOut.isEmpty());
     309             : 
     310           1 :     aIn = rtl::OString(RTL_CONSTASCII_STRINGPARAM("aba"));
     311           1 :     aOut = ::comphelper::string::stripStart(aIn, 'a');
     312           1 :     CPPUNIT_ASSERT(aOut.equalsL(RTL_CONSTASCII_STRINGPARAM("ba")));
     313           1 : }
     314             : 
     315           1 : void TestString::testStripEnd()
     316             : {
     317           1 :     ::rtl::OString aIn(RTL_CONSTASCII_STRINGPARAM("abc"));
     318           1 :     ::rtl::OString aOut;
     319             : 
     320           1 :     aOut = ::comphelper::string::stripEnd(aIn, 'b');
     321           1 :     CPPUNIT_ASSERT(aOut.equalsL(RTL_CONSTASCII_STRINGPARAM("abc")));
     322             : 
     323           1 :     aOut = ::comphelper::string::stripEnd(aIn, 'c');
     324           1 :     CPPUNIT_ASSERT(aOut.equalsL(RTL_CONSTASCII_STRINGPARAM("ab")));
     325             : 
     326           1 :     aIn = rtl::OString(RTL_CONSTASCII_STRINGPARAM("aaa"));
     327           1 :     aOut = ::comphelper::string::stripEnd(aIn, 'a');
     328           1 :     CPPUNIT_ASSERT(aOut.isEmpty());
     329             : 
     330           1 :     aIn = rtl::OString(RTL_CONSTASCII_STRINGPARAM("aba"));
     331           1 :     aOut = ::comphelper::string::stripEnd(aIn, 'a');
     332           1 :     CPPUNIT_ASSERT(aOut.equalsL(RTL_CONSTASCII_STRINGPARAM("ab")));
     333           1 : }
     334             : 
     335           1 : void TestString::testStrip()
     336             : {
     337           1 :     ::rtl::OString aIn(RTL_CONSTASCII_STRINGPARAM("abc"));
     338           1 :     ::rtl::OString aOut;
     339             : 
     340           1 :     aOut = ::comphelper::string::strip(aIn, 'b');
     341           1 :     CPPUNIT_ASSERT(aOut.equalsL(RTL_CONSTASCII_STRINGPARAM("abc")));
     342             : 
     343           1 :     aOut = ::comphelper::string::strip(aIn, 'c');
     344           1 :     CPPUNIT_ASSERT(aOut.equalsL(RTL_CONSTASCII_STRINGPARAM("ab")));
     345             : 
     346           1 :     aIn = rtl::OString(RTL_CONSTASCII_STRINGPARAM("aaa"));
     347           1 :     aOut = ::comphelper::string::strip(aIn, 'a');
     348           1 :     CPPUNIT_ASSERT(aOut.isEmpty());
     349             : 
     350           1 :     aIn = rtl::OString(RTL_CONSTASCII_STRINGPARAM("aba"));
     351           1 :     aOut = ::comphelper::string::strip(aIn, 'a');
     352           1 :     CPPUNIT_ASSERT(aOut.equalsL(RTL_CONSTASCII_STRINGPARAM("b")));
     353           1 : }
     354             : 
     355           1 : void TestString::testToken()
     356             : {
     357           1 :     ::rtl::OString aIn(RTL_CONSTASCII_STRINGPARAM("10.11.12"));
     358           1 :     ::rtl::OString aOut;
     359             : 
     360           1 :     aOut = ::comphelper::string::getToken(aIn, -1, '.');
     361           1 :     CPPUNIT_ASSERT(aOut.isEmpty());
     362             : 
     363           1 :     aOut = ::comphelper::string::getToken(aIn, 0, '.');
     364           1 :     CPPUNIT_ASSERT(aOut.equalsL(RTL_CONSTASCII_STRINGPARAM("10")));
     365             : 
     366           1 :     aOut = ::comphelper::string::getToken(aIn, 1, '.');
     367           1 :     CPPUNIT_ASSERT(aOut.equalsL(RTL_CONSTASCII_STRINGPARAM("11")));
     368             : 
     369           1 :     aOut = ::comphelper::string::getToken(aIn, 2, '.');
     370           1 :     CPPUNIT_ASSERT(aOut.equalsL(RTL_CONSTASCII_STRINGPARAM("12")));
     371             : 
     372           1 :     aOut = ::comphelper::string::getToken(aIn, 3, '.');
     373           1 :     CPPUNIT_ASSERT(aOut.isEmpty());
     374           1 : }
     375             : 
     376           1 : void TestString::testTokenCount()
     377             : {
     378           1 :     ::rtl::OString aIn(RTL_CONSTASCII_STRINGPARAM("10.11.12"));
     379             :     sal_Int32 nOut;
     380             : 
     381           1 :     nOut = ::comphelper::string::getTokenCount(aIn, '.');
     382           1 :     CPPUNIT_ASSERT(nOut == 3);
     383             : 
     384           1 :     nOut = ::comphelper::string::getTokenCount(aIn, 'X');
     385           1 :     CPPUNIT_ASSERT(nOut == 1);
     386             : 
     387           1 :     nOut = ::comphelper::string::getTokenCount(rtl::OString(), 'X');
     388           1 :     CPPUNIT_ASSERT(nOut == 0);
     389           1 : }
     390             : 
     391           1 : void TestString::testReverseString()
     392             : {
     393           1 :     ::rtl::OString aIn("ABC");
     394           1 :     ::rtl::OString aOut = ::comphelper::string::reverseString(aIn);
     395             : 
     396           1 :     CPPUNIT_ASSERT(aOut == "CBA");
     397           1 : }
     398             : 
     399           1 : void TestString::testEqualsString()
     400             : {
     401           1 :     ::rtl::OString aIn("A");
     402           1 :     CPPUNIT_ASSERT(::comphelper::string::equals(aIn, 'A'));
     403           1 :     CPPUNIT_ASSERT(!::comphelper::string::equals(aIn, 'B'));
     404           1 :     aIn = ::rtl::OString("AA");
     405           1 :     CPPUNIT_ASSERT(!::comphelper::string::equals(aIn, 'A'));
     406           1 :     aIn = ::rtl::OString();
     407           1 :     CPPUNIT_ASSERT(!::comphelper::string::equals(aIn, 'A'));
     408           1 : }
     409             : 
     410           1 : CPPUNIT_TEST_SUITE_REGISTRATION(TestString);
     411             : 
     412             : }
     413             : 
     414           4 : CPPUNIT_PLUGIN_IMPLEMENT();
     415             : 
     416             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10