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

Generated by: LCOV version 1.11