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

Generated by: LCOV version 1.10