LCOV - code coverage report
Current view: top level - sal/qa/rtl/oustring - rtl_OUString2.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 683 683 100.0 %
Date: 2014-11-03 Functions: 170 171 99.4 %
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             : // autogenerated file with codegen.pl
      21             : 
      22             : #include <math.h>
      23             : #include <stdio.h>
      24             : 
      25             : #include <algorithm>
      26             : #include <limits>
      27             : 
      28             : #include <cppunit/TestFixture.h>
      29             : #include <cppunit/extensions/HelperMacros.h>
      30             : #include <cppunit/plugin/TestPlugIn.h>
      31             : 
      32             : #include "stringhelper.hxx"
      33             : #include "valueequal.hxx"
      34             : 
      35             : namespace rtl_OUString
      36             : {
      37             : 
      38             : namespace {
      39             : 
      40             : // Avoid -fsanitize=undefined warning e.g. "runtime error: value 1e+99 is
      41             : // outside the range of representable values of type 'float'":
      42          84 : float doubleToFloat(double x) {
      43             :     return
      44          84 :         x < -std::numeric_limits<float>::max()
      45           4 :         ? -std::numeric_limits<float>::infinity()
      46          80 :         : x > std::numeric_limits<float>::max()
      47             :         ? std::numeric_limits<float>::infinity()
      48         168 :         : static_cast<float>(x);
      49             : }
      50             : 
      51             : }
      52             : 
      53          90 : class number : public CppUnit::TestFixture
      54             : {
      55          28 :     void number_float_test_impl(float _nValue)
      56             :         {
      57          28 :             rtl::OUString suValue(rtl::OUString::number(_nValue));
      58          56 :             rtl::OString sValue;
      59          28 :             sValue <<= suValue;
      60          28 :             printf("nFloat := %.9f  sValue := %s\n", _nValue, sValue.getStr());
      61             : 
      62          28 :             double nValueATOF = doubleToFloat(atof( sValue.getStr() ));
      63             : 
      64          28 :             bool bEqualResult = is_float_equal(_nValue, nValueATOF);
      65          56 :             CPPUNIT_ASSERT_MESSAGE("Values are not equal.", bEqualResult == true);
      66          28 :         }
      67             : 
      68          14 :     void number_float_test(float _nValue)
      69             :         {
      70          14 :             number_float_test_impl(_nValue);
      71             : 
      72             :             // test also the negative part.
      73          14 :             float nNegativeValue = -_nValue;
      74          14 :             number_float_test_impl(nNegativeValue);
      75          14 :         }
      76             : 
      77             : public:
      78             :     // insert your test code here.
      79           2 :     void number_float_test_001()
      80             :     {
      81             :         // this is demonstration code
      82             :         // CPPUNIT_ASSERT_MESSAGE("a message", 1 == 1);
      83           2 :         float nValue = 3.0f;
      84           2 :         number_float_test(nValue);
      85           2 :     }
      86             : 
      87           2 :     void number_float_test_002()
      88             :     {
      89           2 :         float nValue = 3.5f;
      90           2 :         number_float_test(nValue);
      91           2 :     }
      92             : 
      93           2 :     void number_float_test_003()
      94             :     {
      95           2 :         float nValue = 3.0625f;
      96           2 :         number_float_test(nValue);
      97           2 :     }
      98             : 
      99           2 :     void number_float_test_004()
     100             :     {
     101           2 :         float nValue = 3.502525f;
     102           2 :         number_float_test(nValue);
     103           2 :     }
     104             : 
     105           2 :     void number_float_test_005()
     106             :     {
     107           2 :         float nValue = 3.141592f;
     108           2 :         number_float_test(nValue);
     109           2 :     }
     110             : 
     111           2 :     void number_float_test_006()
     112             :     {
     113           2 :         float nValue = 3.5025255f;
     114           2 :         number_float_test(nValue);
     115           2 :     }
     116             : 
     117           2 :     void number_float_test_007()
     118             :     {
     119           2 :         float nValue = 3.0039062f;
     120           2 :         number_float_test(nValue);
     121           2 :     }
     122             : 
     123             : private:
     124             : 
     125          32 :     void number_double_test_impl(double _nValue)
     126             :         {
     127          32 :             rtl::OUString suValue;
     128          32 :             suValue = rtl::OUString::number( _nValue );
     129          64 :             rtl::OString sValue;
     130          32 :             sValue <<= suValue;
     131          32 :             printf("nDouble := %.20f  sValue := %s\n", _nValue, sValue.getStr());
     132             : 
     133          32 :             double nValueATOF = atof( sValue.getStr() );
     134             : 
     135          32 :             bool bEqualResult = is_double_equal(_nValue, nValueATOF);
     136          64 :             CPPUNIT_ASSERT_MESSAGE("Values are not equal.", bEqualResult == true);
     137          32 :         }
     138             : 
     139          16 :     void number_double_test(double _nValue)
     140             :         {
     141          16 :             number_double_test_impl(_nValue);
     142             : 
     143             :             // test also the negative part.
     144          16 :             double nNegativeValue = -_nValue;
     145          16 :             number_double_test_impl(nNegativeValue);
     146          16 :         }
     147             : public:
     148             : 
     149             :     // number double
     150           2 :     void number_double_test_001()
     151             :         {
     152           2 :             double nValue = 3.0;
     153           2 :             number_double_test(nValue);
     154           2 :         }
     155           2 :     void number_double_test_002()
     156             :         {
     157           2 :             double nValue = 3.5;
     158           2 :             number_double_test(nValue);
     159           2 :         }
     160           2 :     void number_double_test_003()
     161             :         {
     162           2 :             double nValue = 3.0625;
     163           2 :             number_double_test(nValue);
     164           2 :         }
     165           2 :     void number_double_test_004()
     166             :         {
     167           2 :             double nValue = 3.1415926535;
     168           2 :             number_double_test(nValue);
     169           2 :         }
     170           2 :     void number_double_test_005()
     171             :         {
     172           2 :             double nValue = 3.141592653589793;
     173           2 :             number_double_test(nValue);
     174           2 :         }
     175           2 :     void number_double_test_006()
     176             :         {
     177           2 :             double nValue = 3.1415926535897932;
     178           2 :             number_double_test(nValue);
     179           2 :         }
     180           2 :     void number_double_test_007()
     181             :         {
     182           2 :             double nValue = 3.14159265358979323;
     183           2 :             number_double_test(nValue);
     184           2 :         }
     185           2 :     void number_double_test_008()
     186             :         {
     187           2 :             double nValue = 3.141592653589793238462643;
     188           2 :             number_double_test(nValue);
     189           2 :         }
     190             : 
     191             :     // Change the following lines only, if you add, remove or rename
     192             :     // member functions of the current class,
     193             :     // because these macros are need by auto register mechanism.
     194             : 
     195           4 :     CPPUNIT_TEST_SUITE(number);
     196           2 :     CPPUNIT_TEST(number_float_test_001);
     197           2 :     CPPUNIT_TEST(number_float_test_002);
     198           2 :     CPPUNIT_TEST(number_float_test_003);
     199           2 :     CPPUNIT_TEST(number_float_test_004);
     200           2 :     CPPUNIT_TEST(number_float_test_005);
     201           2 :     CPPUNIT_TEST(number_float_test_006);
     202           2 :     CPPUNIT_TEST(number_float_test_007);
     203             : 
     204           2 :     CPPUNIT_TEST(number_double_test_001);
     205           2 :     CPPUNIT_TEST(number_double_test_002);
     206           2 :     CPPUNIT_TEST(number_double_test_003);
     207           2 :     CPPUNIT_TEST(number_double_test_004);
     208           2 :     CPPUNIT_TEST(number_double_test_005);
     209           2 :     CPPUNIT_TEST(number_double_test_006);
     210           2 :     CPPUNIT_TEST(number_double_test_007);
     211           2 :     CPPUNIT_TEST(number_double_test_008);
     212           4 :     CPPUNIT_TEST_SUITE_END();
     213             : }; // class number
     214             : 
     215           6 :     class toInt: public CppUnit::TestFixture {
     216             :     public:
     217           2 :         void test() {
     218           4 :             CPPUNIT_ASSERT_EQUAL(
     219             :                 static_cast< sal_Int32 >(-0x76543210),
     220             :                 (rtl::OUString("-76543210").
     221           2 :                  toInt32(16)));
     222             :             // @return 0 if this string represents no number or one of too large magnitude
     223           4 :             CPPUNIT_ASSERT_EQUAL(
     224             :                 static_cast< sal_Int32 >(0),
     225             :                 (rtl::OUString("+FEDCBA98").
     226           2 :                  toInt32(16)));
     227           4 :             CPPUNIT_ASSERT_EQUAL(
     228             :                 static_cast< sal_Int64 >(-SAL_CONST_INT64(0x76543210FEDCBA98)),
     229             :                 (rtl::OUString(
     230             :                     "-76543210FEDCBA98").
     231           2 :                  toInt64(16)));
     232             :             // @return 0 if this string represents no number or one of too large magnitude
     233           4 :             CPPUNIT_ASSERT_EQUAL(
     234             :                 static_cast< sal_Int64 >(SAL_CONST_INT64(0)),
     235             :                 (rtl::OUString(
     236             :                     "+FEDCBA9876543210").
     237           2 :                  toInt64(16)));
     238           2 :         }
     239             : 
     240           4 :         CPPUNIT_TEST_SUITE(toInt);
     241           2 :         CPPUNIT_TEST(test);
     242           4 :         CPPUNIT_TEST_SUITE_END();
     243             :     };
     244             : 
     245             :     // - toDouble (tests)
     246          78 :     class toDouble : public CppUnit::TestFixture
     247             :     {
     248             :     public:
     249          48 :         void toDouble_test_impl(rtl::OString const& _sValue)
     250             :             {
     251             :                 //printf("the original str is %s\n", _sValue.getStr());
     252          48 :                 double nValueATOF = atof( _sValue.getStr() );
     253             :         //printf("original data is %e\n", nValueATOF);
     254          48 :                 rtl::OUString suValue = rtl::OUString::createFromAscii( _sValue.getStr() );
     255          48 :                 double nValueToDouble = suValue.toDouble();
     256             :                 //printf("result data is %e\n", nValueToDouble);
     257             : 
     258          48 :                 bool bEqualResult = is_double_equal(nValueToDouble, nValueATOF);
     259          48 :                 CPPUNIT_ASSERT_MESSAGE("Values are not equal.", bEqualResult == true);
     260          48 :             }
     261             : 
     262          24 :         void toDouble_test(rtl::OString const& _sValue)
     263             :             {
     264          24 :                 toDouble_test_impl(_sValue);
     265             : 
     266             :                 // test also the negativ part.
     267          24 :                 rtl::OString sNegativValue("-");
     268          24 :                 sNegativValue += _sValue;
     269          24 :                 toDouble_test_impl(sNegativValue);
     270          24 :             }
     271             : 
     272             :         // insert your test code here.
     273           2 :         void toDouble_selftest()
     274             :             {
     275           2 :                 printf("Start selftest:\n");
     276           2 :                 CPPUNIT_ASSERT (is_double_equal(1.0, 1.01) == false);
     277           2 :                 CPPUNIT_ASSERT (is_double_equal(1.0, 1.001) == false);
     278           2 :                 CPPUNIT_ASSERT (is_double_equal(1.0, 1.0001) == false);
     279           2 :                 CPPUNIT_ASSERT (is_double_equal(1.0, 1.00001) == false);
     280           2 :                 CPPUNIT_ASSERT (is_double_equal(1.0, 1.000001) == false);
     281           2 :                 CPPUNIT_ASSERT (is_double_equal(1.0, 1.0000001) == false);
     282           2 :                 CPPUNIT_ASSERT (is_double_equal(1.0, 1.00000001) == false);
     283           2 :                 CPPUNIT_ASSERT (is_double_equal(1.0, 1.000000001) == false);
     284           2 :                 CPPUNIT_ASSERT (is_double_equal(1.0, 1.0000000001) == false);
     285           2 :                 CPPUNIT_ASSERT (is_double_equal(1.0, 1.00000000001) == false);
     286           2 :                 CPPUNIT_ASSERT (is_double_equal(1.0, 1.000000000001) == false);
     287           2 :                 CPPUNIT_ASSERT (is_double_equal(1.0, 1.0000000000001) == false);
     288             :                 // we check til 15 values after comma
     289           2 :                 CPPUNIT_ASSERT (is_double_equal(1.0, 1.00000000000001) == true);
     290           2 :                 CPPUNIT_ASSERT (is_double_equal(1.0, 1.000000000000001) == true);
     291           2 :                 CPPUNIT_ASSERT (is_double_equal(1.0, 1.0000000000000001) == true);
     292           2 :                 printf("Selftest done.\n");
     293           2 :             }
     294             : 
     295           2 :         void toDouble_test_3()
     296             :             {
     297           2 :                 rtl::OString sValue("3");
     298           2 :                 toDouble_test(sValue);
     299           2 :             }
     300           2 :         void toDouble_test_3_5()
     301             :             {
     302           2 :                 rtl::OString sValue("3.5");
     303           2 :                 toDouble_test(sValue);
     304           2 :             }
     305           2 :         void toDouble_test_3_0625()
     306             :             {
     307           2 :                 rtl::OString sValue("3.0625");
     308           2 :                 toDouble_test(sValue);
     309           2 :             }
     310           2 :         void toDouble_test_pi()
     311             :             {
     312             :                 // value from http://www.angio.net/pi/digits/50.txt
     313           2 :                 rtl::OString sValue("3.141592653589793238462643383279502884197169399375");
     314           2 :                 toDouble_test(sValue);
     315           2 :             }
     316             : 
     317           2 :         void toDouble_test_1()
     318             :             {
     319           2 :                 rtl::OString sValue("1");
     320           2 :                 toDouble_test(sValue);
     321           2 :             }
     322           2 :         void toDouble_test_10()
     323             :             {
     324           2 :                 rtl::OString sValue("10");
     325           2 :                 toDouble_test(sValue);
     326           2 :             }
     327           2 :         void toDouble_test_100()
     328             :             {
     329           2 :                 rtl::OString sValue("100");
     330           2 :                 toDouble_test(sValue);
     331           2 :             }
     332           2 :         void toDouble_test_1000()
     333             :             {
     334           2 :                 rtl::OString sValue("1000");
     335           2 :                 toDouble_test(sValue);
     336           2 :             }
     337           2 :         void toDouble_test_10000()
     338             :             {
     339           2 :                 rtl::OString sValue("10000");
     340           2 :                 toDouble_test(sValue);
     341           2 :             }
     342           2 :         void toDouble_test_1e99()
     343             :             {
     344           2 :                 rtl::OString sValue("1e99");
     345           2 :                 toDouble_test(sValue);
     346           2 :             }
     347           2 :         void toDouble_test_1e_n99()
     348             :             {
     349           2 :                 rtl::OString sValue("1e-99");
     350           2 :                 toDouble_test(sValue);
     351           2 :             }
     352           2 :         void toDouble_test_1e308()
     353             :             {
     354           2 :                 rtl::OString sValue("1e308");
     355           2 :                 toDouble_test(sValue);
     356           2 :             }
     357             : 
     358             :         // Change the following lines only, if you add, remove or rename
     359             :         // member functions of the current class,
     360             :         // because these macros are need by auto register mechanism.
     361             : 
     362           4 :         CPPUNIT_TEST_SUITE(toDouble);
     363           2 :         CPPUNIT_TEST(toDouble_selftest);
     364             : 
     365           2 :         CPPUNIT_TEST(toDouble_test_3);
     366           2 :         CPPUNIT_TEST(toDouble_test_3_5);
     367           2 :         CPPUNIT_TEST(toDouble_test_3_0625);
     368           2 :         CPPUNIT_TEST(toDouble_test_pi);
     369           2 :         CPPUNIT_TEST(toDouble_test_1);
     370           2 :         CPPUNIT_TEST(toDouble_test_10);
     371           2 :         CPPUNIT_TEST(toDouble_test_100);
     372           2 :         CPPUNIT_TEST(toDouble_test_1000);
     373           2 :         CPPUNIT_TEST(toDouble_test_10000);
     374           2 :         CPPUNIT_TEST(toDouble_test_1e99);
     375           2 :         CPPUNIT_TEST(toDouble_test_1e_n99);
     376           2 :         CPPUNIT_TEST(toDouble_test_1e308);
     377           4 :         CPPUNIT_TEST_SUITE_END();
     378             :     }; // class toDouble
     379             : 
     380             :     // - toFloat (tests)
     381          90 :     class toFloat : public CppUnit::TestFixture
     382             :     {
     383             :     public:
     384          56 :         void toFloat_test_impl(rtl::OString const& _sValue)
     385             :             {
     386             :                 //printf("the original str is %s\n", _sValue.getStr());
     387          56 :                 float nValueATOF = doubleToFloat(atof( _sValue.getStr() ));
     388             :         //printf("the original str is %.10f\n", nValueATOF);
     389          56 :                 rtl::OUString suValue = rtl::OUString::createFromAscii( _sValue.getStr() );
     390          56 :                 float nValueToFloat = suValue.toFloat();
     391             :                 //printf("the result str is %.10f\n", nValueToFloat);
     392             : 
     393          56 :                 bool bEqualResult = is_float_equal(nValueToFloat, nValueATOF);
     394          56 :                 CPPUNIT_ASSERT_MESSAGE("Values are not equal.", bEqualResult == true);
     395          56 :             }
     396             : 
     397          28 :         void toFloat_test(rtl::OString const& _sValue)
     398             :             {
     399          28 :                 toFloat_test_impl(_sValue);
     400             : 
     401             :                 // test also the negativ part.
     402          28 :                 rtl::OString sNegativValue("-");
     403          28 :                 sNegativValue += _sValue;
     404          28 :                 toFloat_test_impl(sNegativValue);
     405          28 :             }
     406             : 
     407             :         // insert your test code here.
     408           2 :         void toFloat_selftest()
     409             :             {
     410           2 :                 printf("Start selftest:\n");
     411           2 :                 CPPUNIT_ASSERT (is_float_equal(1.0f, 1.01f) == false);
     412           2 :                 CPPUNIT_ASSERT (is_float_equal(1.0f, 1.001f) == false);
     413           2 :                 CPPUNIT_ASSERT (is_float_equal(1.0f, 1.0001f) == false);
     414           2 :                 CPPUNIT_ASSERT (is_float_equal(1.0f, 1.00001f) == false);
     415           2 :                 CPPUNIT_ASSERT (is_float_equal(1.0f, 1.000002f) == false);
     416           2 :                 CPPUNIT_ASSERT (is_float_equal(1.0f, 1.0000001f) == true);
     417           2 :                 CPPUNIT_ASSERT (is_float_equal(1.0f, 1.00000001f) == true);
     418           2 :                 CPPUNIT_ASSERT (is_float_equal(1.0f, 1.000000001f) == true);
     419             : 
     420           2 :                 printf("Selftest done.\n");
     421           2 :             }
     422             : 
     423           2 :         void toFloat_test_3()
     424             :             {
     425           2 :                 rtl::OString sValue("3");
     426           2 :                 toFloat_test(sValue);
     427           2 :             }
     428           2 :         void toFloat_test_3_5()
     429             :             {
     430           2 :                 rtl::OString sValue("3.5");
     431           2 :                 toFloat_test(sValue);
     432           2 :             }
     433           2 :         void toFloat_test_3_0625()
     434             :             {
     435           2 :                 rtl::OString sValue("3.0625");
     436           2 :                 toFloat_test(sValue);
     437           2 :             }
     438           2 :         void toFloat_test_3_0625_e()
     439             :             {
     440           2 :                 rtl::OString sValue("3.0625e-4");
     441           2 :                 toFloat_test(sValue);
     442           2 :             }
     443           2 :         void toFloat_test_pi()
     444             :             {
     445             :                 // value from http://www.angio.net/pi/digits/50.txt
     446           2 :                 rtl::OString sValue("3.141592653589793238462643383279502884197169399375");
     447           2 :                 toFloat_test(sValue);
     448           2 :             }
     449             : 
     450           2 :         void toFloat_test_1()
     451             :             {
     452           2 :                 rtl::OString sValue("1");
     453           2 :                 toFloat_test(sValue);
     454           2 :             }
     455           2 :         void toFloat_test_10()
     456             :             {
     457           2 :                 rtl::OString sValue("10");
     458           2 :                 toFloat_test(sValue);
     459           2 :             }
     460           2 :         void toFloat_test_100()
     461             :             {
     462           2 :                 rtl::OString sValue("100");
     463           2 :                 toFloat_test(sValue);
     464           2 :             }
     465           2 :         void toFloat_test_1000()
     466             :             {
     467           2 :                 rtl::OString sValue("1000");
     468           2 :                 toFloat_test(sValue);
     469           2 :             }
     470           2 :         void toFloat_test_10000()
     471             :             {
     472           2 :                 rtl::OString sValue("10000");
     473           2 :                 toFloat_test(sValue);
     474           2 :             }
     475           2 :         void toFloat_test_mix()
     476             :             {
     477           2 :                 rtl::OString sValue("456789321455.123456789012");
     478           2 :                 toFloat_test(sValue);
     479           2 :             }
     480           2 :         void toFloat_test_1e99()
     481             :             {
     482           2 :                 rtl::OString sValue("1e99");
     483           2 :                 toFloat_test(sValue);
     484           2 :             }
     485           2 :         void toFloat_test_1e_n99()
     486             :             {
     487           2 :                 rtl::OString sValue("1e-9");
     488           2 :                 toFloat_test(sValue);
     489           2 :             }
     490           2 :         void toFloat_test_1e308()
     491             :             {
     492           2 :                 rtl::OString sValue("1e308");
     493           2 :                 toFloat_test(sValue);
     494           2 :             }
     495             : 
     496             :         // Change the following lines only, if you add, remove or rename
     497             :         // member functions of the current class,
     498             :         // because these macros are need by auto register mechanism.
     499             : 
     500           4 :         CPPUNIT_TEST_SUITE(toFloat);
     501           2 :         CPPUNIT_TEST(toFloat_selftest);
     502             : 
     503           2 :         CPPUNIT_TEST(toFloat_test_3);
     504           2 :         CPPUNIT_TEST(toFloat_test_3_5);
     505           2 :         CPPUNIT_TEST(toFloat_test_3_0625);
     506           2 :         CPPUNIT_TEST(toFloat_test_3_0625_e);
     507           2 :         CPPUNIT_TEST(toFloat_test_pi);
     508           2 :         CPPUNIT_TEST(toFloat_test_1);
     509           2 :         CPPUNIT_TEST(toFloat_test_10);
     510           2 :         CPPUNIT_TEST(toFloat_test_100);
     511           2 :         CPPUNIT_TEST(toFloat_test_1000);
     512           2 :         CPPUNIT_TEST(toFloat_test_10000);
     513           2 :         CPPUNIT_TEST(toFloat_test_mix);
     514           2 :         CPPUNIT_TEST(toFloat_test_1e99);
     515           2 :         CPPUNIT_TEST(toFloat_test_1e_n99);
     516           2 :         CPPUNIT_TEST(toFloat_test_1e308);
     517           4 :         CPPUNIT_TEST_SUITE_END();
     518             :     }; // class toFloat
     519             : 
     520             : // - lastIndexOf (tests)
     521         108 : class lastIndexOf : public CppUnit::TestFixture
     522             : {
     523             : 
     524             : public:
     525          18 :     void lastIndexOf_oustring(rtl::OUString const& _suStr, rtl::OUString const& _suSearchStr, sal_Int32 _nExpectedResultPos)
     526             :         {
     527             :             // Algorithm
     528             :             // search the string _suSearchStr (rtl::OUString) in the string _suStr.
     529             :             // check if the _nExpectedResultPos occurs.
     530             : 
     531          18 :             sal_Int32 nPos = _suStr.lastIndexOf(_suSearchStr);
     532          18 :             CPPUNIT_ASSERT_MESSAGE("expected position is wrong", nPos == _nExpectedResultPos);
     533          18 :         }
     534             : 
     535           4 :     void lastIndexOf_salunicode(rtl::OUString const& _suStr, sal_Unicode _cuSearchChar, sal_Int32 _nExpectedResultPos)
     536             :         {
     537             :             // Algorithm
     538             :             // search the unicode char _suSearchChar (sal_Unicode) in the string _suStr.
     539             :             // check if the _nExpectedResultPos occurs.
     540             : 
     541           4 :             sal_Int32 nPos = _suStr.lastIndexOf(_cuSearchChar);
     542           4 :             CPPUNIT_ASSERT_MESSAGE("expected position is wrong", nPos == _nExpectedResultPos);
     543           4 :         }
     544             : 
     545           8 :     void lastIndexOf_oustring_offset(rtl::OUString const& _suStr, rtl::OUString const& _suSearchStr, sal_Int32 _nExpectedResultPos, sal_Int32 _nStartOffset)
     546             :         {
     547           8 :             sal_Int32 nPos = _suStr.lastIndexOf(_suSearchStr, _nStartOffset);
     548           8 :             CPPUNIT_ASSERT_MESSAGE("expected position is wrong", nPos == _nExpectedResultPos);
     549           8 :         }
     550             : 
     551           6 :     void lastIndexOf_salunicode_offset(rtl::OUString const& _suStr, sal_Unicode _cuSearchChar, sal_Int32 _nExpectedResultPos, sal_Int32 _nStartOffset)
     552             :         {
     553           6 :             sal_Int32 nPos = _suStr.lastIndexOf(_cuSearchChar, _nStartOffset);
     554           6 :             CPPUNIT_ASSERT_MESSAGE("expected position is wrong", nPos == _nExpectedResultPos);
     555           6 :         }
     556             : 
     557           2 :     void lastIndexOf_test_oustring_offset_001()
     558             :         {
     559             :             // search for sun, start at the end, found (pos==0)
     560           2 :             rtl::OUString aStr("sun java system");
     561           4 :             rtl::OUString aSearchStr("sun");
     562           4 :             lastIndexOf_oustring_offset(aStr, aSearchStr, 0, aStr.getLength());
     563           2 :         }
     564             : 
     565           2 :     void lastIndexOf_test_oustring_offset_002()
     566             :         {
     567             :             // search for sun, start at pos = 3, found (pos==0)
     568           2 :             rtl::OUString aStr("sun java system");
     569           4 :             rtl::OUString aSearchStr("sun");
     570           4 :             lastIndexOf_oustring_offset(aStr, aSearchStr, 0, 3);
     571           2 :         }
     572             : 
     573           2 :     void lastIndexOf_test_oustring_offset_003()
     574             :         {
     575             :             // search for sun, start at pos = 2, found (pos==-1)
     576           2 :             rtl::OUString aStr("sun java system");
     577           4 :             rtl::OUString aSearchStr("sun");
     578           4 :             lastIndexOf_oustring_offset(aStr, aSearchStr, -1, 2);
     579           2 :         }
     580             : 
     581           2 :     void lastIndexOf_test_oustring_offset_004()
     582             :         {
     583             :             // search for sun, start at the end, found (pos==0)
     584           2 :             rtl::OUString aStr("sun java system");
     585           4 :             rtl::OUString aSearchStr("sun");
     586           4 :             lastIndexOf_oustring_offset(aStr, aSearchStr, -1, -1);
     587           2 :         }
     588             : 
     589           2 :     void lastIndexOf_test_oustring_001()
     590             :         {
     591             :             // search for sun, found (pos==0)
     592           2 :             rtl::OUString aStr("sun java system");
     593           4 :             rtl::OUString aSearchStr("sun");
     594           4 :             lastIndexOf_oustring(aStr, aSearchStr, 0);
     595           2 :         }
     596             : 
     597           2 :     void lastIndexOf_test_oustring_002()
     598             :         {
     599             :             // search for sun, found (pos==4)
     600           2 :             rtl::OUString aStr("the sun java system");
     601           4 :             rtl::OUString aSearchStr("sun");
     602           4 :             lastIndexOf_oustring(aStr, aSearchStr, 4);
     603           2 :         }
     604             : 
     605           2 :     void lastIndexOf_test_oustring_003()
     606             :         {
     607             :             // search for sun, found (pos==8)
     608           2 :             rtl::OUString aStr("the sun sun java system");
     609           4 :             rtl::OUString aSearchStr("sun");
     610           4 :             lastIndexOf_oustring(aStr, aSearchStr, 8);
     611           2 :         }
     612             : 
     613           2 :     void lastIndexOf_test_oustring_004()
     614             :         {
     615             :             // search for sun, found (pos==8)
     616           2 :             rtl::OUString aStr("the sun sun");
     617           4 :             rtl::OUString aSearchStr("sun");
     618           4 :             lastIndexOf_oustring(aStr, aSearchStr, 8);
     619           2 :         }
     620             : 
     621           2 :     void lastIndexOf_test_oustring_005()
     622             :         {
     623             :             // search for sun, found (pos==4)
     624           2 :             rtl::OUString aStr("the sun su");
     625           4 :             rtl::OUString aSearchStr("sun");
     626           4 :             lastIndexOf_oustring(aStr, aSearchStr, 4);
     627           2 :         }
     628             : 
     629           2 :     void lastIndexOf_test_oustring_006()
     630             :         {
     631             :             // search for sun, found (pos==-1)
     632           2 :             rtl::OUString aStr("the su su");
     633           4 :             rtl::OUString aSearchStr("sun");
     634           4 :             lastIndexOf_oustring(aStr, aSearchStr, -1);
     635           2 :         }
     636             : 
     637           2 :     void lastIndexOf_test_oustring_007()
     638             :         {
     639             :             // search for earth, not found (-1)
     640           2 :             rtl::OUString aStr("the su su");
     641           4 :             rtl::OUString aSearchStr("earth");
     642           4 :             lastIndexOf_oustring(aStr, aSearchStr, -1);
     643           2 :         }
     644             : 
     645           2 :     void lastIndexOf_test_oustring_008()
     646             :         {
     647             :             // search for earth, not found (-1)
     648           2 :             rtl::OUString aStr = rtl::OUString();
     649           4 :             rtl::OUString aSearchStr("earth");
     650           4 :             lastIndexOf_oustring(aStr, aSearchStr, -1);
     651           2 :         }
     652             : 
     653           2 :     void lastIndexOf_test_oustring_009()
     654             :         {
     655             :             // search for earth, not found (-1)
     656           2 :             rtl::OUString aStr = rtl::OUString();
     657           4 :             rtl::OUString aSearchStr = rtl::OUString();
     658           4 :             lastIndexOf_oustring(aStr, aSearchStr, -1);
     659             : 
     660           2 :         }
     661             : 
     662           2 :     void lastIndexOf_test_salunicode_001()
     663             :         {
     664             :             // search for 's', found (19)
     665           2 :             rtl::OUString aStr("the sun sun java system");
     666           2 :             sal_Unicode suChar = L's';
     667           2 :             lastIndexOf_salunicode(aStr, suChar, 19);
     668           2 :         }
     669             : 
     670           2 :     void lastIndexOf_test_salunicode_002()
     671             :         {
     672             :             // search for 'x', not found (-1)
     673           2 :             rtl::OUString aStr("the sun sun java system");
     674           2 :             sal_Unicode suChar = L'x';
     675           2 :             lastIndexOf_salunicode(aStr, suChar, -1);
     676           2 :         }
     677             : 
     678           2 :     void lastIndexOf_test_salunicode_offset_001()
     679             :         {
     680             :             // search for 's', start from pos last char, found (19)
     681           2 :             rtl::OUString aStr("the sun sun java system");
     682           2 :             sal_Unicode cuChar = L's';
     683           2 :             lastIndexOf_salunicode_offset(aStr, cuChar, 19, aStr.getLength());
     684           2 :         }
     685           2 :     void lastIndexOf_test_salunicode_offset_002()
     686             :         {
     687             :             // search for 's', start pos is last occur from search behind, found (17)
     688           2 :             rtl::OUString aStr("the sun sun java system");
     689           2 :             sal_Unicode cuChar = L's';
     690           2 :             lastIndexOf_salunicode_offset(aStr, cuChar, 17, 19);
     691           2 :         }
     692           2 :     void lastIndexOf_test_salunicode_offset_003()
     693             :         {
     694             :             // search for 't', start pos is 1, found (0)
     695           2 :             rtl::OUString aStr("the sun sun java system");
     696           2 :             sal_Unicode cuChar = L't';
     697           2 :             lastIndexOf_salunicode_offset(aStr, cuChar, 0, 1);
     698           2 :         }
     699             : 
     700             :     // Change the following lines only, if you add, remove or rename
     701             :     // member functions of the current class,
     702             :     // because these macros are need by auto register mechanism.
     703             : 
     704           4 :     CPPUNIT_TEST_SUITE(lastIndexOf);
     705           2 :     CPPUNIT_TEST(lastIndexOf_test_oustring_001);
     706           2 :     CPPUNIT_TEST(lastIndexOf_test_oustring_002);
     707           2 :     CPPUNIT_TEST(lastIndexOf_test_oustring_003);
     708           2 :     CPPUNIT_TEST(lastIndexOf_test_oustring_004);
     709           2 :     CPPUNIT_TEST(lastIndexOf_test_oustring_005);
     710           2 :     CPPUNIT_TEST(lastIndexOf_test_oustring_006);
     711           2 :     CPPUNIT_TEST(lastIndexOf_test_oustring_007);
     712           2 :     CPPUNIT_TEST(lastIndexOf_test_oustring_008);
     713           2 :     CPPUNIT_TEST(lastIndexOf_test_oustring_009);
     714             : 
     715           2 :     CPPUNIT_TEST(lastIndexOf_test_oustring_offset_001);
     716           2 :     CPPUNIT_TEST(lastIndexOf_test_oustring_offset_002);
     717           2 :     CPPUNIT_TEST(lastIndexOf_test_oustring_offset_003);
     718           2 :     CPPUNIT_TEST(lastIndexOf_test_oustring_offset_004);
     719             : 
     720           2 :     CPPUNIT_TEST(lastIndexOf_test_salunicode_001);
     721           2 :     CPPUNIT_TEST(lastIndexOf_test_salunicode_002);
     722             : 
     723           2 :     CPPUNIT_TEST(lastIndexOf_test_salunicode_offset_001);
     724           2 :     CPPUNIT_TEST(lastIndexOf_test_salunicode_offset_002);
     725           2 :     CPPUNIT_TEST(lastIndexOf_test_salunicode_offset_003);
     726             : 
     727           4 :     CPPUNIT_TEST_SUITE_END();
     728             : }; // class lastIndexOf
     729             : 
     730             : // - getToken (tests)
     731          36 : class getToken : public CppUnit::TestFixture
     732             : {
     733             : 
     734             : public:
     735           2 :     void getToken_000()
     736             :         {
     737           2 :             rtl::OUString suTokenStr;
     738             : 
     739           2 :             sal_Int32 nIndex = 0;
     740           2 :             do
     741             :             {
     742           2 :                 suTokenStr.getToken( 0, ';', nIndex );
     743             :             }
     744           2 :             while ( nIndex >= 0 );
     745           2 :             printf("Index %" SAL_PRIdINT32 "\n", nIndex);
     746             :             // should not GPF
     747           2 :         }
     748             : 
     749           2 :     void getToken_001()
     750             :         {
     751           2 :             rtl::OUString suTokenStr("a;b");
     752             : 
     753           2 :             sal_Int32 nIndex = 0;
     754             : 
     755           4 :             rtl::OUString suToken = suTokenStr.getToken( 0, ';', nIndex );
     756           2 :             CPPUNIT_ASSERT_MESSAGE( "Token should be a 'a'", suToken == "a" );
     757             : 
     758           2 :             /* rtl::OUString */ suToken = suTokenStr.getToken( 0, ';', nIndex );
     759           2 :             CPPUNIT_ASSERT_MESSAGE( "Token should be a 'b'", suToken == "b" );
     760           4 :             CPPUNIT_ASSERT_MESSAGE("index should be negative", nIndex == -1);
     761           2 :         }
     762             : 
     763           2 :     void getToken_002()
     764             :         {
     765           2 :             rtl::OUString suTokenStr("a;b.c");
     766             : 
     767           2 :             sal_Int32 nIndex = 0;
     768             : 
     769           4 :             rtl::OUString suToken = suTokenStr.getToken( 0, ';', nIndex );
     770           2 :             CPPUNIT_ASSERT_MESSAGE( "Token should be a 'a'", suToken == "a" );
     771             : 
     772           2 :             /* rtl::OUString */ suToken = suTokenStr.getToken( 0, '.', nIndex );
     773           2 :             CPPUNIT_ASSERT_MESSAGE( "Token should be a 'b'", suToken == "b" );
     774             : 
     775           2 :             /* rtl::OUString */ suToken = suTokenStr.getToken( 0, '.', nIndex );
     776           2 :             CPPUNIT_ASSERT_MESSAGE( "Token should be a 'c'", suToken == "c" );
     777           4 :             CPPUNIT_ASSERT_MESSAGE("index should be negative", nIndex == -1);
     778           2 :         }
     779             : 
     780           2 :     void getToken_003()
     781             :         {
     782           2 :             rtl::OUString suTokenStr("a;;b");
     783             : 
     784           2 :             sal_Int32 nIndex = 0;
     785             : 
     786           4 :             rtl::OUString suToken = suTokenStr.getToken( 0, ';', nIndex );
     787           2 :             CPPUNIT_ASSERT_MESSAGE( "Token should be a 'a'", suToken == "a" );
     788             : 
     789           2 :             /* rtl::OUString */ suToken = suTokenStr.getToken( 0, ';', nIndex );
     790           2 :             CPPUNIT_ASSERT_MESSAGE("Token should be empty", suToken.isEmpty());
     791             : 
     792           2 :             /* rtl::OUString */ suToken = suTokenStr.getToken( 0, ';', nIndex );
     793           2 :             CPPUNIT_ASSERT_MESSAGE( "Token should be a 'b'", suToken == "b" );
     794           4 :             CPPUNIT_ASSERT_MESSAGE("index should be negative", nIndex == -1);
     795           2 :         }
     796             : 
     797           2 :     void getToken_004()
     798             :         {
     799           2 :             rtl::OUString suTokenStr("longer.then.ever.");
     800             : 
     801           2 :             sal_Int32 nIndex = 0;
     802             : 
     803           4 :             rtl::OUString suToken = suTokenStr.getToken( 0, '.', nIndex );
     804           2 :             CPPUNIT_ASSERT_MESSAGE( "Token should be 'longer'", suToken == "longer" );
     805             : 
     806           2 :             /* rtl::OUString */ suToken = suTokenStr.getToken( 0, '.', nIndex );
     807           2 :             CPPUNIT_ASSERT_MESSAGE( "Token should be 'then'", suToken == "then" );
     808             : 
     809           2 :             /* rtl::OUString */ suToken = suTokenStr.getToken( 0, '.', nIndex );
     810           2 :             CPPUNIT_ASSERT_MESSAGE( "Token should be 'ever'", suToken == "ever" );
     811             : 
     812           2 :             /* rtl::OUString */ suToken = suTokenStr.getToken( 0, '.', nIndex );
     813           2 :             CPPUNIT_ASSERT_MESSAGE("Token should be empty", suToken.isEmpty());
     814             : 
     815           4 :             CPPUNIT_ASSERT_MESSAGE("index should be negative", nIndex == -1);
     816           2 :         }
     817             : 
     818           2 :     void getToken_005() {
     819           2 :         rtl::OUString ab("ab");
     820           2 :         sal_Int32 n = 0;
     821           4 :         CPPUNIT_ASSERT_MESSAGE(
     822           2 :             "token should be 'ab'", ab.getToken(0, '-', n) == ab);
     823           2 :         CPPUNIT_ASSERT_MESSAGE("n should be -1", n == -1);
     824           4 :         CPPUNIT_ASSERT_MESSAGE(
     825           4 :             "token should be empty", ab.getToken(0, '-', n).isEmpty());
     826           2 :     }
     827             : 
     828           4 :     CPPUNIT_TEST_SUITE(getToken);
     829           2 :     CPPUNIT_TEST(getToken_000);
     830           2 :     CPPUNIT_TEST(getToken_001);
     831           2 :     CPPUNIT_TEST(getToken_002);
     832           2 :     CPPUNIT_TEST(getToken_003);
     833           2 :     CPPUNIT_TEST(getToken_004);
     834           2 :     CPPUNIT_TEST(getToken_005);
     835           4 :     CPPUNIT_TEST_SUITE_END();
     836             : }; // class getToken
     837             : 
     838           6 : class convertToString: public CppUnit::TestFixture {
     839             : public:
     840             :     void test();
     841             : 
     842           4 :     CPPUNIT_TEST_SUITE(convertToString);
     843           2 :     CPPUNIT_TEST(test);
     844           4 :     CPPUNIT_TEST_SUITE_END();
     845             : };
     846             : 
     847           2 : void convertToString::test() {
     848             :     static sal_Unicode const utf16[] = { 0x0041, 0x00E4, 0x0061 };
     849           2 :     rtl::OString s;
     850           4 :     CPPUNIT_ASSERT(
     851             :         rtl::OUString(utf16, SAL_N_ELEMENTS(utf16)).convertToString(
     852             :             &s, RTL_TEXTENCODING_UTF7,
     853             :             (RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR |
     854           2 :              RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR)));
     855           4 :     CPPUNIT_ASSERT_EQUAL(
     856           4 :         rtl::OString(RTL_CONSTASCII_STRINGPARAM("A+AOQ-a")), s);
     857           2 : }
     858             : 
     859             : // - string construction & interning (tests)
     860             : 
     861          12 : class construction : public CppUnit::TestFixture
     862             : {
     863             : public:
     864           2 :     void construct()
     865             :     {
     866             : #ifdef RTL_INLINE_STRINGS
     867             :         ::rtl::OUString aFoo( "foo" );
     868             :         CPPUNIT_ASSERT_MESSAGE("string contents", aFoo[0] == 'f');
     869             :         CPPUNIT_ASSERT_MESSAGE("string contents", aFoo[1] == 'o');
     870             :         CPPUNIT_ASSERT_MESSAGE("string contents", aFoo[2] == 'o');
     871             :         CPPUNIT_ASSERT_MESSAGE("string length", aFoo.getLength() == 3);
     872             : 
     873             :         ::rtl::OUString aBaa( "this is a very long string with a lot of long things inside it and it goes on and on and on forever etc." );
     874             :         CPPUNIT_ASSERT_MESSAGE("string length", aBaa.getLength() == 104);
     875             :         // Dig at the internals ... FIXME: should we have the bit-flag defines public ?
     876             :         CPPUNIT_ASSERT_MESSAGE("string static flags", (aBaa.pData->refCount & 1<<30) != 0);
     877             : #endif
     878           2 :     }
     879             : 
     880           2 :     void intern()
     881             :     {
     882             :         // The empty string is 'static' a special case ...
     883           2 :         rtl::OUString().intern();
     884           2 :         rtl::OUString::intern( "",strlen(""),RTL_TEXTENCODING_ASCII_US );
     885             : 
     886           2 :         ::rtl::OUString aFoo( "foo" );
     887           4 :         ::rtl::OUString aFooIntern = aFoo.intern();
     888           2 :         CPPUNIT_ASSERT_MESSAGE( "string contents", aFooIntern == "foo" );
     889           2 :         CPPUNIT_ASSERT_MESSAGE("string length", aFooIntern.getLength() == 3);
     890             :         // We have to dup due to no atomic 'intern' bit-set operation
     891           2 :         CPPUNIT_ASSERT_MESSAGE("intern dups", aFoo.pData != aFooIntern.pData);
     892             : 
     893             :         // Test interning lots of things
     894             :         int i;
     895             :         static const int nSequence = 4096;
     896             :         rtl::OUString *pStrs;
     897             :         sal_uIntPtr   *pValues;
     898             : 
     899           2 :         pStrs = new rtl::OUString[nSequence];
     900           2 :         pValues = new sal_uIntPtr[nSequence];
     901        8194 :         for (i = 0; i < nSequence; i++)
     902             :         {
     903        8192 :             pStrs[i] = rtl::OUString::number( sqrt( static_cast<double>(i) ) ).intern();
     904        8192 :             pValues[i] = reinterpret_cast<sal_uIntPtr>( pStrs[i].pData );
     905             :         }
     906        8194 :         for (i = 0; i < nSequence; i++)
     907             :         {
     908        8192 :             rtl::OUString aNew = rtl::OUString::number( sqrt( static_cast<double>(i) ) ).intern();
     909       16384 :             CPPUNIT_ASSERT_MESSAGE("double intern failed",
     910        8192 :                                    aNew.pData == pStrs[i].pData);
     911        8192 :         }
     912             : 
     913             :         // Free strings to check for leaks
     914        8194 :         for (i = 0; i < nSequence; i++)
     915             :         {
     916             :             // Overwrite - hopefully this re-uses the memory
     917        8192 :             pStrs[i] = rtl::OUString();
     918        8192 :             pStrs[i] = rtl::OUString::number( sqrt( static_cast<double>(i) ) );
     919             :         }
     920             : 
     921        8194 :         for (i = 0; i < nSequence; i++)
     922             :         {
     923        8192 :             rtl::OUString aIntern;
     924             :             sal_uIntPtr nValue;
     925        8192 :             aIntern = rtl::OUString::number( sqrt( static_cast<double>(i) ) ).intern();
     926             : 
     927        8192 :             nValue = reinterpret_cast<sal_uIntPtr>( aIntern.pData );
     928             :             // This may not be 100% reliable: memory may
     929             :             // have been re-used, but it's worth checking.
     930        8192 :             CPPUNIT_ASSERT_MESSAGE("intern leaking", nValue != pValues[i]);
     931        8192 :         }
     932           2 :         delete [] pValues;
     933           4 :         delete [] pStrs;
     934           2 :     }
     935             : 
     936           4 :     CPPUNIT_TEST_SUITE(construction);
     937           2 :     CPPUNIT_TEST(construct);
     938           2 :     CPPUNIT_TEST(intern);
     939           4 :     CPPUNIT_TEST_SUITE_END();
     940             : };
     941             : 
     942           6 : class indexOfAscii: public CppUnit::TestFixture {
     943             : public:
     944             :     void test();
     945             : 
     946           4 :     CPPUNIT_TEST_SUITE(indexOfAscii);
     947           2 :     CPPUNIT_TEST(test);
     948           4 :     CPPUNIT_TEST_SUITE_END();
     949             : };
     950             : 
     951           2 : void indexOfAscii::test() {
     952           4 :     CPPUNIT_ASSERT_EQUAL(
     953             :         sal_Int32(-1),
     954           2 :         rtl::OUString().indexOfAsciiL(RTL_CONSTASCII_STRINGPARAM("")));
     955           4 :     CPPUNIT_ASSERT_EQUAL(
     956             :         sal_Int32(-1),
     957           2 :         rtl::OUString().lastIndexOfAsciiL(RTL_CONSTASCII_STRINGPARAM("")));
     958           4 :     CPPUNIT_ASSERT_EQUAL(
     959             :         sal_Int32(0),
     960             :         rtl::OUString("foo").indexOfAsciiL(
     961           2 :             RTL_CONSTASCII_STRINGPARAM("foo")));
     962           4 :     CPPUNIT_ASSERT_EQUAL(
     963             :         sal_Int32(0),
     964             :         rtl::OUString("foo").lastIndexOfAsciiL(
     965           2 :             RTL_CONSTASCII_STRINGPARAM("foo")));
     966           4 :     CPPUNIT_ASSERT_EQUAL(
     967             :         sal_Int32(2),
     968             :         rtl::OUString("fofoobar").indexOfAsciiL(
     969           2 :             RTL_CONSTASCII_STRINGPARAM("foo")));
     970           4 :     CPPUNIT_ASSERT_EQUAL(
     971             :         sal_Int32(3),
     972             :         rtl::OUString("foofoofob").
     973           2 :         lastIndexOfAsciiL(RTL_CONSTASCII_STRINGPARAM("foo")));
     974           4 :     CPPUNIT_ASSERT_EQUAL(
     975             :         sal_Int32(3),
     976             :         rtl::OUString("foofoobar").indexOfAsciiL(
     977           2 :             RTL_CONSTASCII_STRINGPARAM("foo"), 1));
     978           2 : }
     979             : 
     980           6 : class endsWith: public CppUnit::TestFixture {
     981             : public:
     982             :     void test();
     983             : 
     984           4 :     CPPUNIT_TEST_SUITE(endsWith);
     985           2 :     CPPUNIT_TEST(test);
     986           4 :     CPPUNIT_TEST_SUITE_END();
     987             : };
     988             : 
     989           2 : void endsWith::test() {
     990           4 :     CPPUNIT_ASSERT_EQUAL(
     991             :         true,
     992           2 :         rtl::OUString().endsWithAsciiL(RTL_CONSTASCII_STRINGPARAM("")));
     993           4 :     CPPUNIT_ASSERT_EQUAL(
     994             :         false,
     995           2 :         rtl::OUString().endsWithAsciiL(RTL_CONSTASCII_STRINGPARAM("foo")));
     996           4 :     CPPUNIT_ASSERT_EQUAL(
     997             :         true,
     998             :         rtl::OUString("bar").endsWithAsciiL(
     999           2 :             RTL_CONSTASCII_STRINGPARAM("bar")));
    1000           4 :     CPPUNIT_ASSERT_EQUAL(
    1001             :         true,
    1002             :         rtl::OUString("foobar").endsWithAsciiL(
    1003           2 :             RTL_CONSTASCII_STRINGPARAM("bar")));
    1004           4 :     CPPUNIT_ASSERT_EQUAL(
    1005             :         false,
    1006             :         rtl::OUString("FOOBAR").endsWithAsciiL(
    1007           2 :             RTL_CONSTASCII_STRINGPARAM("bar")));
    1008           2 : }
    1009             : 
    1010           6 : class createFromCodePoints: public CppUnit::TestFixture {
    1011             : public:
    1012             :     void test();
    1013             : 
    1014           4 :     CPPUNIT_TEST_SUITE(createFromCodePoints);
    1015           2 :     CPPUNIT_TEST(test);
    1016           4 :     CPPUNIT_TEST_SUITE_END();
    1017             : };
    1018             : 
    1019           2 : void createFromCodePoints::test() {
    1020           4 :     CPPUNIT_ASSERT_EQUAL(
    1021             :         sal_Int32(0),
    1022           2 :         rtl::OUString(static_cast< sal_uInt32 const * >(NULL), 0).getLength());
    1023             :     static sal_uInt32 const cp[] = { 0, 0xD800, 0xFFFF, 0x10000, 0x10FFFF };
    1024           2 :     rtl::OUString s(cp, sizeof cp / sizeof (sal_uInt32));
    1025           2 :     CPPUNIT_ASSERT_EQUAL(sal_Int32(7), s.getLength());
    1026           2 :     CPPUNIT_ASSERT_EQUAL(sal_Unicode(0), s[0]);
    1027           2 :     CPPUNIT_ASSERT_EQUAL(sal_Unicode(0xD800), s[1]);
    1028           2 :     CPPUNIT_ASSERT_EQUAL(sal_Unicode(0xFFFF), s[2]);
    1029           2 :     CPPUNIT_ASSERT_EQUAL(sal_Unicode(0xD800), s[3]);
    1030           2 :     CPPUNIT_ASSERT_EQUAL(sal_Unicode(0xDC00), s[4]);
    1031           2 :     CPPUNIT_ASSERT_EQUAL(sal_Unicode(0xDBFF), s[5]);
    1032           2 :     CPPUNIT_ASSERT_EQUAL(sal_Unicode(0xDFFF), s[6]);
    1033           2 : }
    1034             : 
    1035           6 : class iterateCodePoints: public CppUnit::TestFixture {
    1036             : public:
    1037             :     void testNotWellFormed();
    1038             : 
    1039           4 :     CPPUNIT_TEST_SUITE(iterateCodePoints);
    1040           2 :     CPPUNIT_TEST(testNotWellFormed);
    1041           4 :     CPPUNIT_TEST_SUITE_END();
    1042             : };
    1043             : 
    1044           2 : void iterateCodePoints::testNotWellFormed() {
    1045             :     static sal_Unicode const utf16[] =
    1046             :         { 0xD800, 0xDC00, 0x0041, 0xDBFF, 0xDFFF, 0xDDEF, 0xD9AB };
    1047           2 :     rtl::OUString s(utf16, sizeof utf16 / sizeof (sal_Unicode));
    1048           2 :     sal_Int32 i = 0;
    1049           2 :     CPPUNIT_ASSERT_EQUAL(sal_uInt32(0x10000), s.iterateCodePoints(&i));
    1050           2 :     CPPUNIT_ASSERT_EQUAL(sal_Int32(2), i);
    1051           2 :     CPPUNIT_ASSERT_EQUAL(sal_uInt32(0x0041), s.iterateCodePoints(&i));
    1052           2 :     CPPUNIT_ASSERT_EQUAL(sal_Int32(3), i);
    1053           2 :     CPPUNIT_ASSERT_EQUAL(sal_uInt32(0x10FFFF), s.iterateCodePoints(&i));
    1054           2 :     CPPUNIT_ASSERT_EQUAL(sal_Int32(5), i);
    1055           2 :     CPPUNIT_ASSERT_EQUAL(sal_uInt32(0xDDEF), s.iterateCodePoints(&i));
    1056           2 :     CPPUNIT_ASSERT_EQUAL(sal_Int32(6), i);
    1057           2 :     CPPUNIT_ASSERT_EQUAL(sal_uInt32(0xD9AB), s.iterateCodePoints(&i));
    1058           2 :     CPPUNIT_ASSERT_EQUAL(sal_Int32(7), i);
    1059           2 :     CPPUNIT_ASSERT_EQUAL(sal_uInt32(0xD9AB), s.iterateCodePoints(&i, -1));
    1060           2 :     CPPUNIT_ASSERT_EQUAL(sal_Int32(6), i);
    1061           2 :     CPPUNIT_ASSERT_EQUAL(sal_uInt32(0xDDEF), s.iterateCodePoints(&i, -1));
    1062           2 :     CPPUNIT_ASSERT_EQUAL(sal_Int32(5), i);
    1063           2 :     CPPUNIT_ASSERT_EQUAL(sal_uInt32(0x10FFFF), s.iterateCodePoints(&i, -1));
    1064           2 :     CPPUNIT_ASSERT_EQUAL(sal_Int32(3), i);
    1065           2 :     CPPUNIT_ASSERT_EQUAL(sal_uInt32(0x0041), s.iterateCodePoints(&i, -1));
    1066           2 :     CPPUNIT_ASSERT_EQUAL(sal_Int32(2), i);
    1067           2 :     CPPUNIT_ASSERT_EQUAL(sal_uInt32(0x10000), s.iterateCodePoints(&i, -1));
    1068           2 :     CPPUNIT_ASSERT_EQUAL(sal_Int32(0), i);
    1069           2 :     i = 1;
    1070           2 :     CPPUNIT_ASSERT_EQUAL(sal_uInt32(0xDC00), s.iterateCodePoints(&i, 2));
    1071           2 :     CPPUNIT_ASSERT_EQUAL(sal_Int32(3), i);
    1072           2 :     i = 4;
    1073           2 :     CPPUNIT_ASSERT_EQUAL(sal_uInt32(0x10000), s.iterateCodePoints(&i, -3));
    1074           2 :     CPPUNIT_ASSERT_EQUAL(sal_Int32(0), i);
    1075           2 : }
    1076             : 
    1077           6 : class convertFromString: public CppUnit::TestFixture {
    1078             : public:
    1079             :     void test();
    1080             : 
    1081           4 :     CPPUNIT_TEST_SUITE(convertFromString);
    1082           2 :     CPPUNIT_TEST(test);
    1083           4 :     CPPUNIT_TEST_SUITE_END();
    1084             : };
    1085             : 
    1086           2 : void convertFromString::test() {
    1087           2 :     rtl::OUString t;
    1088           4 :     CPPUNIT_ASSERT(
    1089             :         !rtl_convertStringToUString(
    1090             :             &t.pData, RTL_CONSTASCII_STRINGPARAM("\x80"), RTL_TEXTENCODING_UTF8,
    1091             :             (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR |
    1092             :              RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR |
    1093           2 :              RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR)));
    1094           4 :     CPPUNIT_ASSERT(
    1095             :         !rtl_convertStringToUString(
    1096             :             &t.pData, RTL_CONSTASCII_STRINGPARAM("\xC0"), RTL_TEXTENCODING_UTF8,
    1097             :             (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR |
    1098             :              RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR |
    1099           2 :              RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR)));
    1100           4 :     CPPUNIT_ASSERT(
    1101             :         !rtl_convertStringToUString(
    1102             :             &t.pData, RTL_CONSTASCII_STRINGPARAM("\xFF"), RTL_TEXTENCODING_UTF8,
    1103             :             (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR |
    1104             :              RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR |
    1105           2 :              RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR)));
    1106           4 :     CPPUNIT_ASSERT(
    1107             :         rtl_convertStringToUString(
    1108             :             &t.pData, RTL_CONSTASCII_STRINGPARAM("abc"), RTL_TEXTENCODING_UTF8,
    1109             :             (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR |
    1110             :              RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR |
    1111           2 :              RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR)));
    1112           2 :     CPPUNIT_ASSERT( t == "abc" );
    1113           2 : }
    1114             : 
    1115           2 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OUString::number);
    1116           2 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OUString::toInt);
    1117           2 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OUString::toDouble);
    1118           2 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OUString::toFloat);
    1119           2 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OUString::lastIndexOf);
    1120           2 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OUString::getToken);
    1121           2 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OUString::convertToString);
    1122           2 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OUString::construction);
    1123           2 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OUString::indexOfAscii);
    1124           2 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OUString::endsWith);
    1125           2 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OUString::createFromCodePoints);
    1126           2 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OUString::iterateCodePoints);
    1127           2 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OUString::convertFromString);
    1128             : 
    1129             : } // namespace rtl_OUString
    1130             : 
    1131             : // this macro creates an empty function, which will called by the RegisterAllFunctions()
    1132             : // to let the user the possibility to also register some functions by hand.
    1133           8 : CPPUNIT_PLUGIN_IMPLEMENT();
    1134             : 
    1135             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10