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