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