merge the formfield patch from ooo-build
[ooovba.git] / sal / qa / rtl / oustring / rtl_OUString2.cxx
blob8f755bcdc7b3b0bd9ecf9af5892a50894c076236
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: rtl_OUString2.cxx,v $
10 * $Revision: 1.16 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_sal.hxx"
34 // autogenerated file with codegen.pl
36 #include <math.h>
37 #include <stdio.h>
39 #include <algorithm> // STL
41 #include <cppunit/simpleheader.hxx>
42 #include "stringhelper.hxx"
43 #include "valueequal.hxx"
45 inline void printOUString( ::rtl::OUString const & _suStr )
47 rtl::OString aString;
49 t_print( "OUString: " );
50 aString = ::rtl::OUStringToOString( _suStr, RTL_TEXTENCODING_ASCII_US );
51 t_print( "'%s'\n", aString.getStr( ) );
54 namespace rtl_OUString
57 class ctors_rtl_uString : public CppUnit::TestFixture
60 public:
61 /// test of OUString(rtl_uString*)
62 void ctors_001()
64 rtl::OUString *pStr = new rtl::OUString( rtl::OUString::createFromAscii("a String") );
66 rtl::OUString aStrToTest(pStr->pData);
67 delete pStr;
69 // maybe here should we do something with current memory
70 char* pBuffer = (char*) malloc(2 * 8);
71 memset(pBuffer, 0, 2 * 8);
72 free(pBuffer);
74 sal_Bool bResult = aStrToTest.equals(rtl::OUString::createFromAscii("a String"));
75 CPPUNIT_ASSERT_MESSAGE("String must not be empty", bResult == sal_True);
78 // Change the following lines only, if you add, remove or rename
79 // member functions of the current class,
80 // because these macros are need by auto register mechanism.
82 CPPUNIT_TEST_SUITE(ctors_rtl_uString);
83 CPPUNIT_TEST(ctors_001);
84 CPPUNIT_TEST_SUITE_END();
87 // -----------------------------------------------------------------------------
88 class valueOf : public CppUnit::TestFixture
90 void valueOf_float_test_impl(float _nValue)
92 rtl::OUString suValue;
93 suValue = rtl::OUString::valueOf( _nValue );
94 rtl::OString sValue;
95 sValue <<= suValue;
96 t_print(T_VERBOSE, "nFloat := %.9f sValue := %s\n", _nValue, sValue.getStr());
98 float nValueATOF = static_cast<float>(atof( sValue.getStr() ));
100 bool bEqualResult = is_float_equal(_nValue, nValueATOF);
101 CPPUNIT_ASSERT_MESSAGE("Values are not equal.", bEqualResult == true);
104 void valueOf_float_test(float _nValue)
106 valueOf_float_test_impl(_nValue);
108 // test also the negative part.
109 float nNegativeValue = -_nValue;
110 valueOf_float_test_impl(nNegativeValue);
113 public:
114 // insert your test code here.
115 void valueOf_float_test_001()
117 // this is demonstration code
118 // CPPUNIT_ASSERT_MESSAGE("a message", 1 == 1);
119 float nValue = 3.0f;
120 valueOf_float_test(nValue);
123 void valueOf_float_test_002()
125 float nValue = 3.5f;
126 valueOf_float_test(nValue);
129 void valueOf_float_test_003()
131 float nValue = 3.0625f;
132 valueOf_float_test(nValue);
135 void valueOf_float_test_004()
137 float nValue = 3.502525f;
138 valueOf_float_test(nValue);
141 void valueOf_float_test_005()
143 float nValue = 3.141592f;
144 valueOf_float_test(nValue);
147 void valueOf_float_test_006()
149 float nValue = 3.5025255f;
150 valueOf_float_test(nValue);
153 void valueOf_float_test_007()
155 float nValue = 3.0039062f;
156 valueOf_float_test(nValue);
159 private:
161 void valueOf_double_test_impl(double _nValue)
163 rtl::OUString suValue;
164 suValue = rtl::OUString::valueOf( _nValue );
165 rtl::OString sValue;
166 sValue <<= suValue;
167 t_print(T_VERBOSE, "nDouble := %.20f sValue := %s\n", _nValue, sValue.getStr());
169 double nValueATOF = atof( sValue.getStr() );
171 bool bEqualResult = is_double_equal(_nValue, nValueATOF);
172 CPPUNIT_ASSERT_MESSAGE("Values are not equal.", bEqualResult == true);
175 void valueOf_double_test(double _nValue)
177 valueOf_double_test_impl(_nValue);
179 // test also the negative part.
180 double nNegativeValue = -_nValue;
181 valueOf_double_test_impl(nNegativeValue);
183 public:
185 // valueOf double
186 void valueOf_double_test_001()
188 double nValue = 3.0;
189 valueOf_double_test(nValue);
191 void valueOf_double_test_002()
193 double nValue = 3.5;
194 valueOf_double_test(nValue);
196 void valueOf_double_test_003()
198 double nValue = 3.0625;
199 valueOf_double_test(nValue);
201 void valueOf_double_test_004()
203 double nValue = 3.1415926535;
204 valueOf_double_test(nValue);
206 void valueOf_double_test_005()
208 double nValue = 3.141592653589793;
209 valueOf_double_test(nValue);
211 void valueOf_double_test_006()
213 double nValue = 3.1415926535897932;
214 valueOf_double_test(nValue);
216 void valueOf_double_test_007()
218 double nValue = 3.14159265358979323;
219 valueOf_double_test(nValue);
221 void valueOf_double_test_008()
223 double nValue = 3.141592653589793238462643;
224 valueOf_double_test(nValue);
228 // Change the following lines only, if you add, remove or rename
229 // member functions of the current class,
230 // because these macros are need by auto register mechanism.
232 CPPUNIT_TEST_SUITE(valueOf);
233 CPPUNIT_TEST(valueOf_float_test_001);
234 CPPUNIT_TEST(valueOf_float_test_002);
235 CPPUNIT_TEST(valueOf_float_test_003);
236 CPPUNIT_TEST(valueOf_float_test_004);
237 CPPUNIT_TEST(valueOf_float_test_005);
238 CPPUNIT_TEST(valueOf_float_test_006);
239 CPPUNIT_TEST(valueOf_float_test_007);
241 CPPUNIT_TEST(valueOf_double_test_001);
242 CPPUNIT_TEST(valueOf_double_test_002);
243 CPPUNIT_TEST(valueOf_double_test_003);
244 CPPUNIT_TEST(valueOf_double_test_004);
245 CPPUNIT_TEST(valueOf_double_test_005);
246 CPPUNIT_TEST(valueOf_double_test_006);
247 CPPUNIT_TEST(valueOf_double_test_007);
248 CPPUNIT_TEST(valueOf_double_test_008);
249 CPPUNIT_TEST_SUITE_END();
250 }; // class valueOf
252 //------------------------------------------------------------------------
253 // testing the method toDouble()
254 //------------------------------------------------------------------------
255 template<class T>
256 sal_Int16 SAL_CALL checkPrecisionSize()
258 // sal_Int16 nSize = sizeof(T);
259 volatile T nCalcValue = 1.0;
262 // (i + 1) is the current precision
263 // numerical series
264 // 1.1
265 // 10.1
266 // 100.1
267 // ...
268 // 1000...0.1
270 sal_Int16 i = 0;
271 for (i=0;i<50;i++)
273 nCalcValue *= 10;
274 volatile T nValue = nCalcValue + static_cast<T>(0.1);
275 volatile T dSub = nValue - nCalcValue;
276 // ----- 0.11 ---- 0.1 ---- 0.09 -----
277 if (0.11 > dSub && dSub < 0.09)
279 // due to the fact, that the value is break down we sub 1 from the precision value
280 // but to suppress this, we start at zero, precision is i+1 till here --i;
281 break;
285 sal_Int16 j= 0;
286 nCalcValue = 1.0;
288 // numerical series
289 // 1.1
290 // 1.01
291 // 1.001
292 // ...
293 // 1.000...001
295 for (j=0;j<50;j++)
297 nCalcValue /= 10;
298 volatile T nValue = nCalcValue + static_cast<T>(1.0);
299 volatile T dSub = nValue - static_cast<T>(1.0);
300 // ---- 0.02 ----- 0.01 ---- 0 --- -0.99 ---- -0.98 ----
301 // volatile T dSubAbsolut = fabs(dSub);
302 // ---- 0.02 ----- 0.01 ---- 0 (cut)
303 if ( dSub == 0)
304 break;
306 if (i != j)
308 // hmmm....
309 // imho i +- 1 == j is a good value
310 int n = i - j;
311 if (n < 0) n = -n;
312 if (n <= 1)
314 return std::min(i,j);
316 else
318 t_print("warning: presision differs more than 1!\n");
322 return i;
325 // -----------------------------------------------------------------------------
327 class testPrecision
329 public:
330 testPrecision()
332 sal_Int16 nPrecision;
333 nPrecision = checkPrecisionSize<float>();
334 t_print("precision of float: %d sizeof()=%d \n", nPrecision, sizeof(float));
336 nPrecision = checkPrecisionSize<double>();
337 t_print("precision of double: %d sizeof()=%d \n", nPrecision, sizeof(double));
339 nPrecision = checkPrecisionSize<long double>();
340 t_print("precision of long double: %d sizeof()=%d \n", nPrecision, sizeof(long double));
346 class toInt: public CppUnit::TestFixture {
347 public:
348 void test() {
349 CPPUNIT_ASSERT_EQUAL(
350 static_cast< sal_Int32 >(-0x76543210),
351 (rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("-76543210")).
352 toInt32(16)));
353 CPPUNIT_ASSERT_EQUAL(
354 static_cast< sal_Int32 >(0xFEDCBA98),
355 (rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("+FEDCBA98")).
356 toInt32(16)));
357 CPPUNIT_ASSERT_EQUAL(
358 static_cast< sal_Int64 >(-SAL_CONST_INT64(0x76543210FEDCBA98)),
359 (rtl::OUString(
360 RTL_CONSTASCII_USTRINGPARAM("-76543210FEDCBA98")).
361 toInt64(16)));
362 CPPUNIT_ASSERT_EQUAL(
363 static_cast< sal_Int64 >(SAL_CONST_INT64(0xFEDCBA9876543210)),
364 (rtl::OUString(
365 RTL_CONSTASCII_USTRINGPARAM("+FEDCBA9876543210")).
366 toInt64(16)));
369 CPPUNIT_TEST_SUITE(toInt);
370 CPPUNIT_TEST(test);
371 CPPUNIT_TEST_SUITE_END();
374 // -----------------------------------------------------------------------------
375 // - toDouble (tests)
376 // -----------------------------------------------------------------------------
377 class toDouble : public CppUnit::TestFixture
379 public:
380 void toDouble_test_impl(rtl::OString const& _sValue)
382 //t_print("the original str is %s\n", _sValue.getStr());
383 double nValueATOF = atof( _sValue.getStr() );
384 //t_print("original data is %e\n", nValueATOF);
385 rtl::OUString suValue = rtl::OUString::createFromAscii( _sValue.getStr() );
386 double nValueToDouble = suValue.toDouble();
387 //t_print("result data is %e\n", nValueToDouble);
389 bool bEqualResult = is_double_equal(nValueToDouble, nValueATOF);
390 CPPUNIT_ASSERT_MESSAGE("Values are not equal.", bEqualResult == true);
393 void toDouble_test(rtl::OString const& _sValue)
395 toDouble_test_impl(_sValue);
397 // test also the negativ part.
398 rtl::OString sNegativValue("-");
399 sNegativValue += _sValue;
400 toDouble_test_impl(sNegativValue);
403 // insert your test code here.
404 void toDouble_selftest()
406 t_print("Start selftest:\n");
407 CPPUNIT_ASSERT (is_double_equal(1.0, 1.01) == false);
408 CPPUNIT_ASSERT (is_double_equal(1.0, 1.001) == false);
409 CPPUNIT_ASSERT (is_double_equal(1.0, 1.0001) == false);
410 CPPUNIT_ASSERT (is_double_equal(1.0, 1.00001) == false);
411 CPPUNIT_ASSERT (is_double_equal(1.0, 1.000001) == false);
412 CPPUNIT_ASSERT (is_double_equal(1.0, 1.0000001) == false);
413 CPPUNIT_ASSERT (is_double_equal(1.0, 1.00000001) == false);
414 CPPUNIT_ASSERT (is_double_equal(1.0, 1.000000001) == false);
415 CPPUNIT_ASSERT (is_double_equal(1.0, 1.0000000001) == false);
416 CPPUNIT_ASSERT (is_double_equal(1.0, 1.00000000001) == false);
417 CPPUNIT_ASSERT (is_double_equal(1.0, 1.000000000001) == false);
418 CPPUNIT_ASSERT (is_double_equal(1.0, 1.0000000000001) == false);
419 // we check til 15 values after comma
420 CPPUNIT_ASSERT (is_double_equal(1.0, 1.00000000000001) == true);
421 CPPUNIT_ASSERT (is_double_equal(1.0, 1.000000000000001) == true);
422 CPPUNIT_ASSERT (is_double_equal(1.0, 1.0000000000000001) == true);
423 t_print("Selftest done.\n");
426 void toDouble_test_3()
428 rtl::OString sValue("3");
429 toDouble_test(sValue);
431 void toDouble_test_3_5()
433 rtl::OString sValue("3.5");
434 toDouble_test(sValue);
436 void toDouble_test_3_0625()
438 rtl::OString sValue("3.0625");
439 toDouble_test(sValue);
441 void toDouble_test_pi()
443 // value from http://www.angio.net/pi/digits/50.txt
444 rtl::OString sValue("3.141592653589793238462643383279502884197169399375");
445 toDouble_test(sValue);
448 void toDouble_test_1()
450 rtl::OString sValue("1");
451 toDouble_test(sValue);
453 void toDouble_test_10()
455 rtl::OString sValue("10");
456 toDouble_test(sValue);
458 void toDouble_test_100()
460 rtl::OString sValue("100");
461 toDouble_test(sValue);
463 void toDouble_test_1000()
465 rtl::OString sValue("1000");
466 toDouble_test(sValue);
468 void toDouble_test_10000()
470 rtl::OString sValue("10000");
471 toDouble_test(sValue);
473 void toDouble_test_1e99()
475 rtl::OString sValue("1e99");
476 toDouble_test(sValue);
478 void toDouble_test_1e_n99()
480 rtl::OString sValue("1e-99");
481 toDouble_test(sValue);
483 void toDouble_test_1e308()
485 rtl::OString sValue("1e308");
486 toDouble_test(sValue);
489 // Change the following lines only, if you add, remove or rename
490 // member functions of the current class,
491 // because these macros are need by auto register mechanism.
493 CPPUNIT_TEST_SUITE(toDouble);
494 CPPUNIT_TEST(toDouble_selftest);
496 CPPUNIT_TEST(toDouble_test_3);
497 CPPUNIT_TEST(toDouble_test_3_5);
498 CPPUNIT_TEST(toDouble_test_3_0625);
499 CPPUNIT_TEST(toDouble_test_pi);
500 CPPUNIT_TEST(toDouble_test_1);
501 CPPUNIT_TEST(toDouble_test_10);
502 CPPUNIT_TEST(toDouble_test_100);
503 CPPUNIT_TEST(toDouble_test_1000);
504 CPPUNIT_TEST(toDouble_test_10000);
505 CPPUNIT_TEST(toDouble_test_1e99);
506 CPPUNIT_TEST(toDouble_test_1e_n99);
507 CPPUNIT_TEST(toDouble_test_1e308);
508 CPPUNIT_TEST_SUITE_END();
509 }; // class toDouble
511 // -----------------------------------------------------------------------------
512 // - toFloat (tests)
513 // -----------------------------------------------------------------------------
514 class toFloat : public CppUnit::TestFixture
516 public:
517 void toFloat_test_impl(rtl::OString const& _sValue)
519 //t_print("the original str is %s\n", _sValue.getStr());
520 float nValueATOF = static_cast<float>(atof( _sValue.getStr() ));
521 //t_print("the original str is %.10f\n", nValueATOF);
522 rtl::OUString suValue = rtl::OUString::createFromAscii( _sValue.getStr() );
523 float nValueToFloat = suValue.toFloat();
524 //t_print("the result str is %.10f\n", nValueToFloat);
526 bool bEqualResult = is_float_equal(nValueToFloat, nValueATOF);
527 CPPUNIT_ASSERT_MESSAGE("Values are not equal.", bEqualResult == true);
530 void toFloat_test(rtl::OString const& _sValue)
532 toFloat_test_impl(_sValue);
534 // test also the negativ part.
535 rtl::OString sNegativValue("-");
536 sNegativValue += _sValue;
537 toFloat_test_impl(sNegativValue);
540 // insert your test code here.
541 void toFloat_selftest()
543 t_print("Start selftest:\n");
544 CPPUNIT_ASSERT (is_float_equal(1.0f, 1.01f) == false);
545 CPPUNIT_ASSERT (is_float_equal(1.0f, 1.001f) == false);
546 CPPUNIT_ASSERT (is_float_equal(1.0f, 1.0001f) == false);
547 CPPUNIT_ASSERT (is_float_equal(1.0f, 1.00001f) == false);
548 CPPUNIT_ASSERT (is_float_equal(1.0f, 1.000002f) == false);
549 CPPUNIT_ASSERT (is_float_equal(1.0f, 1.0000001f) == true);
550 CPPUNIT_ASSERT (is_float_equal(1.0f, 1.00000001f) == true);
551 CPPUNIT_ASSERT (is_float_equal(1.0f, 1.000000001f) == true);
553 t_print("Selftest done.\n");
556 void toFloat_test_3()
558 rtl::OString sValue("3");
559 toFloat_test(sValue);
561 void toFloat_test_3_5()
563 rtl::OString sValue("3.5");
564 toFloat_test(sValue);
566 void toFloat_test_3_0625()
568 rtl::OString sValue("3.0625");
569 toFloat_test(sValue);
571 void toFloat_test_3_0625_e()
573 rtl::OString sValue("3.0625e-4");
574 toFloat_test(sValue);
576 void toFloat_test_pi()
578 // value from http://www.angio.net/pi/digits/50.txt
579 rtl::OString sValue("3.141592653589793238462643383279502884197169399375");
580 toFloat_test(sValue);
583 void toFloat_test_1()
585 rtl::OString sValue("1");
586 toFloat_test(sValue);
588 void toFloat_test_10()
590 rtl::OString sValue("10");
591 toFloat_test(sValue);
593 void toFloat_test_100()
595 rtl::OString sValue("100");
596 toFloat_test(sValue);
598 void toFloat_test_1000()
600 rtl::OString sValue("1000");
601 toFloat_test(sValue);
603 void toFloat_test_10000()
605 rtl::OString sValue("10000");
606 toFloat_test(sValue);
608 void toFloat_test_mix()
610 rtl::OString sValue("456789321455.123456789012");
611 toFloat_test(sValue);
613 void toFloat_test_1e99()
615 rtl::OString sValue("1e99");
616 toFloat_test(sValue);
618 void toFloat_test_1e_n99()
620 rtl::OString sValue("1e-9");
621 toFloat_test(sValue);
623 void toFloat_test_1e308()
625 rtl::OString sValue("1e308");
626 toFloat_test(sValue);
629 // Change the following lines only, if you add, remove or rename
630 // member functions of the current class,
631 // because these macros are need by auto register mechanism.
633 CPPUNIT_TEST_SUITE(toFloat);
634 CPPUNIT_TEST(toFloat_selftest);
636 CPPUNIT_TEST(toFloat_test_3);
637 CPPUNIT_TEST(toFloat_test_3_5);
638 CPPUNIT_TEST(toFloat_test_3_0625);
639 CPPUNIT_TEST(toFloat_test_3_0625_e);
640 CPPUNIT_TEST(toFloat_test_pi);
641 CPPUNIT_TEST(toFloat_test_1);
642 CPPUNIT_TEST(toFloat_test_10);
643 CPPUNIT_TEST(toFloat_test_100);
644 CPPUNIT_TEST(toFloat_test_1000);
645 CPPUNIT_TEST(toFloat_test_10000);
646 CPPUNIT_TEST(toFloat_test_mix);
647 CPPUNIT_TEST(toFloat_test_1e99);
648 CPPUNIT_TEST(toFloat_test_1e_n99);
649 CPPUNIT_TEST(toFloat_test_1e308);
650 CPPUNIT_TEST_SUITE_END();
651 }; // class toFloat
653 // -----------------------------------------------------------------------------
654 // - lastIndexOf (tests)
655 // -----------------------------------------------------------------------------
656 class lastIndexOf : public CppUnit::TestFixture
659 public:
660 void lastIndexOf_oustring(rtl::OUString const& _suStr, rtl::OUString const& _suSearchStr, sal_Int32 _nExpectedResultPos)
662 // Algorithm
663 // search the string _suSearchStr (rtl::OUString) in the string _suStr.
664 // check if the _nExpectedResultPos occurs.
666 sal_Int32 nPos = _suStr.lastIndexOf(_suSearchStr);
667 CPPUNIT_ASSERT_MESSAGE("expected position is wrong", nPos == _nExpectedResultPos);
670 void lastIndexOf_salunicode(rtl::OUString const& _suStr, sal_Unicode _cuSearchChar, sal_Int32 _nExpectedResultPos)
672 // Algorithm
673 // search the unicode char _suSearchChar (sal_Unicode) in the string _suStr.
674 // check if the _nExpectedResultPos occurs.
676 sal_Int32 nPos = _suStr.lastIndexOf(_cuSearchChar);
677 CPPUNIT_ASSERT_MESSAGE("expected position is wrong", nPos == _nExpectedResultPos);
680 void lastIndexOf_oustring_offset(rtl::OUString const& _suStr, rtl::OUString const& _suSearchStr, sal_Int32 _nExpectedResultPos, sal_Int32 _nStartOffset)
682 sal_Int32 nPos = _suStr.lastIndexOf(_suSearchStr, _nStartOffset);
683 CPPUNIT_ASSERT_MESSAGE("expected position is wrong", nPos == _nExpectedResultPos);
686 void lastIndexOf_salunicode_offset(rtl::OUString const& _suStr, sal_Unicode _cuSearchChar, sal_Int32 _nExpectedResultPos, sal_Int32 _nStartOffset)
688 sal_Int32 nPos = _suStr.lastIndexOf(_cuSearchChar, _nStartOffset);
689 CPPUNIT_ASSERT_MESSAGE("expected position is wrong", nPos == _nExpectedResultPos);
692 // -----------------------------------------------------------------------------
694 void lastIndexOf_test_oustring_offset_001()
696 // search for sun, start at the end, found (pos==0)
697 rtl::OUString aStr = rtl::OUString::createFromAscii("sun java system");
698 rtl::OUString aSearchStr = rtl::OUString::createFromAscii("sun");
699 lastIndexOf_oustring_offset(aStr, aSearchStr, 0, aStr.getLength());
702 void lastIndexOf_test_oustring_offset_002()
704 // search for sun, start at pos = 3, found (pos==0)
705 rtl::OUString aStr = rtl::OUString::createFromAscii("sun java system");
706 rtl::OUString aSearchStr = rtl::OUString::createFromAscii("sun");
707 lastIndexOf_oustring_offset(aStr, aSearchStr, 0, 3);
710 void lastIndexOf_test_oustring_offset_003()
712 // search for sun, start at pos = 2, found (pos==-1)
713 rtl::OUString aStr = rtl::OUString::createFromAscii("sun java system");
714 rtl::OUString aSearchStr = rtl::OUString::createFromAscii("sun");
715 lastIndexOf_oustring_offset(aStr, aSearchStr, -1, 2);
718 void lastIndexOf_test_oustring_offset_004()
720 // search for sun, start at the end, found (pos==0)
721 rtl::OUString aStr = rtl::OUString::createFromAscii("sun java system");
722 rtl::OUString aSearchStr = rtl::OUString::createFromAscii("sun");
723 lastIndexOf_oustring_offset(aStr, aSearchStr, -1, -1);
726 void lastIndexOf_test_oustring_001()
728 // search for sun, found (pos==0)
729 rtl::OUString aStr = rtl::OUString::createFromAscii("sun java system");
730 rtl::OUString aSearchStr = rtl::OUString::createFromAscii("sun");
731 lastIndexOf_oustring(aStr, aSearchStr, 0);
734 void lastIndexOf_test_oustring_002()
736 // search for sun, found (pos==4)
737 rtl::OUString aStr = rtl::OUString::createFromAscii("the sun java system");
738 rtl::OUString aSearchStr = rtl::OUString::createFromAscii("sun");
739 lastIndexOf_oustring(aStr, aSearchStr, 4);
742 void lastIndexOf_test_oustring_003()
744 // search for sun, found (pos==8)
745 rtl::OUString aStr = rtl::OUString::createFromAscii("the sun sun java system");
746 rtl::OUString aSearchStr = rtl::OUString::createFromAscii("sun");
747 lastIndexOf_oustring(aStr, aSearchStr, 8);
750 void lastIndexOf_test_oustring_004()
752 // search for sun, found (pos==8)
753 rtl::OUString aStr = rtl::OUString::createFromAscii("the sun sun");
754 rtl::OUString aSearchStr = rtl::OUString::createFromAscii("sun");
755 lastIndexOf_oustring(aStr, aSearchStr, 8);
758 void lastIndexOf_test_oustring_005()
760 // search for sun, found (pos==4)
761 rtl::OUString aStr = rtl::OUString::createFromAscii("the sun su");
762 rtl::OUString aSearchStr = rtl::OUString::createFromAscii("sun");
763 lastIndexOf_oustring(aStr, aSearchStr, 4);
766 void lastIndexOf_test_oustring_006()
768 // search for sun, found (pos==-1)
769 rtl::OUString aStr = rtl::OUString::createFromAscii("the su su");
770 rtl::OUString aSearchStr = rtl::OUString::createFromAscii("sun");
771 lastIndexOf_oustring(aStr, aSearchStr, -1);
774 void lastIndexOf_test_oustring_007()
776 // search for earth, not found (-1)
777 rtl::OUString aStr = rtl::OUString::createFromAscii("the su su");
778 rtl::OUString aSearchStr = rtl::OUString::createFromAscii("earth");
779 lastIndexOf_oustring(aStr, aSearchStr, -1);
782 void lastIndexOf_test_oustring_008()
784 // search for earth, not found (-1)
785 rtl::OUString aStr = rtl::OUString();
786 rtl::OUString aSearchStr = rtl::OUString::createFromAscii("earth");
787 lastIndexOf_oustring(aStr, aSearchStr, -1);
790 void lastIndexOf_test_oustring_009()
792 // search for earth, not found (-1)
793 rtl::OUString aStr = rtl::OUString();
794 rtl::OUString aSearchStr = rtl::OUString();
795 lastIndexOf_oustring(aStr, aSearchStr, -1);
799 void lastIndexOf_test_salunicode_001()
801 // search for 's', found (19)
802 rtl::OUString aStr = rtl::OUString::createFromAscii("the sun sun java system");
803 sal_Unicode suChar = L's';
804 lastIndexOf_salunicode(aStr, suChar, 19);
807 void lastIndexOf_test_salunicode_002()
809 // search for 'x', not found (-1)
810 rtl::OUString aStr = rtl::OUString::createFromAscii("the sun sun java system");
811 sal_Unicode suChar = L'x';
812 lastIndexOf_salunicode(aStr, suChar, -1);
815 void lastIndexOf_test_salunicode_offset_001()
817 // search for 's', start from pos last char, found (19)
818 rtl::OUString aStr = rtl::OUString::createFromAscii("the sun sun java system");
819 sal_Unicode cuChar = L's';
820 lastIndexOf_salunicode_offset(aStr, cuChar, 19, aStr.getLength());
822 void lastIndexOf_test_salunicode_offset_002()
824 // search for 's', start pos is last occur from search behind, found (17)
825 rtl::OUString aStr = rtl::OUString::createFromAscii("the sun sun java system");
826 sal_Unicode cuChar = L's';
827 lastIndexOf_salunicode_offset(aStr, cuChar, 17, 19);
829 void lastIndexOf_test_salunicode_offset_003()
831 // search for 't', start pos is 1, found (0)
832 rtl::OUString aStr = rtl::OUString::createFromAscii("the sun sun java system");
833 sal_Unicode cuChar = L't';
834 lastIndexOf_salunicode_offset(aStr, cuChar, 0, 1);
837 // Change the following lines only, if you add, remove or rename
838 // member functions of the current class,
839 // because these macros are need by auto register mechanism.
841 CPPUNIT_TEST_SUITE(lastIndexOf);
842 CPPUNIT_TEST(lastIndexOf_test_oustring_001);
843 CPPUNIT_TEST(lastIndexOf_test_oustring_002);
844 CPPUNIT_TEST(lastIndexOf_test_oustring_003);
845 CPPUNIT_TEST(lastIndexOf_test_oustring_004);
846 CPPUNIT_TEST(lastIndexOf_test_oustring_005);
847 CPPUNIT_TEST(lastIndexOf_test_oustring_006);
848 CPPUNIT_TEST(lastIndexOf_test_oustring_007);
849 CPPUNIT_TEST(lastIndexOf_test_oustring_008);
850 CPPUNIT_TEST(lastIndexOf_test_oustring_009);
852 CPPUNIT_TEST(lastIndexOf_test_oustring_offset_001);
853 CPPUNIT_TEST(lastIndexOf_test_oustring_offset_002);
854 CPPUNIT_TEST(lastIndexOf_test_oustring_offset_003);
855 CPPUNIT_TEST(lastIndexOf_test_oustring_offset_004);
857 CPPUNIT_TEST(lastIndexOf_test_salunicode_001);
858 CPPUNIT_TEST(lastIndexOf_test_salunicode_002);
860 CPPUNIT_TEST(lastIndexOf_test_salunicode_offset_001);
861 CPPUNIT_TEST(lastIndexOf_test_salunicode_offset_002);
862 CPPUNIT_TEST(lastIndexOf_test_salunicode_offset_003);
864 CPPUNIT_TEST_SUITE_END();
865 }; // class lastIndexOf
868 // -----------------------------------------------------------------------------
869 // - getToken (tests)
870 // -----------------------------------------------------------------------------
871 class getToken : public CppUnit::TestFixture
874 public:
875 void getToken_000()
877 rtl::OUString suTokenStr;
879 sal_Int32 nIndex = 0;
882 rtl::OUString suToken = suTokenStr.getToken( 0, ';', nIndex );
884 while ( nIndex >= 0 );
885 t_print("Index %d\n", nIndex);
886 // should not GPF
889 void getToken_001()
891 rtl::OUString suTokenStr = rtl::OUString::createFromAscii("a;b");
893 sal_Int32 nIndex = 0;
895 rtl::OUString suToken = suTokenStr.getToken( 0, ';', nIndex );
896 CPPUNIT_ASSERT_MESSAGE("Token should be a 'a'", suToken.equals(rtl::OUString::createFromAscii("a")) == sal_True);
898 /* rtl::OUString */ suToken = suTokenStr.getToken( 0, ';', nIndex );
899 CPPUNIT_ASSERT_MESSAGE("Token should be a 'b'", suToken.equals(rtl::OUString::createFromAscii("b")) == sal_True);
900 CPPUNIT_ASSERT_MESSAGE("index should be negative", nIndex == -1);
903 void getToken_002()
905 rtl::OUString suTokenStr = rtl::OUString::createFromAscii("a;b.c");
907 sal_Int32 nIndex = 0;
909 rtl::OUString suToken = suTokenStr.getToken( 0, ';', nIndex );
910 CPPUNIT_ASSERT_MESSAGE("Token should be a 'a'", suToken.equals(rtl::OUString::createFromAscii("a")) == sal_True);
912 /* rtl::OUString */ suToken = suTokenStr.getToken( 0, '.', nIndex );
913 CPPUNIT_ASSERT_MESSAGE("Token should be a 'b'", suToken.equals(rtl::OUString::createFromAscii("b")) == sal_True);
915 /* rtl::OUString */ suToken = suTokenStr.getToken( 0, '.', nIndex );
916 CPPUNIT_ASSERT_MESSAGE("Token should be a 'c'", suToken.equals(rtl::OUString::createFromAscii("c")) == sal_True);
917 CPPUNIT_ASSERT_MESSAGE("index should be negative", nIndex == -1);
920 void getToken_003()
922 rtl::OUString suTokenStr = rtl::OUString::createFromAscii("a;;b");
924 sal_Int32 nIndex = 0;
926 rtl::OUString suToken = suTokenStr.getToken( 0, ';', nIndex );
927 CPPUNIT_ASSERT_MESSAGE("Token should be a 'a'", suToken.equals(rtl::OUString::createFromAscii("a")) == sal_True);
929 /* rtl::OUString */ suToken = suTokenStr.getToken( 0, ';', nIndex );
930 CPPUNIT_ASSERT_MESSAGE("Token should be empty", suToken.getLength() == 0);
932 /* rtl::OUString */ suToken = suTokenStr.getToken( 0, ';', nIndex );
933 CPPUNIT_ASSERT_MESSAGE("Token should be a 'b'", suToken.equals(rtl::OUString::createFromAscii("b")) == sal_True);
934 CPPUNIT_ASSERT_MESSAGE("index should be negative", nIndex == -1);
937 void getToken_004()
939 rtl::OUString suTokenStr = rtl::OUString::createFromAscii("longer.then.ever.");
941 sal_Int32 nIndex = 0;
943 rtl::OUString suToken = suTokenStr.getToken( 0, '.', nIndex );
944 CPPUNIT_ASSERT_MESSAGE("Token should be 'longer'", suToken.equals(rtl::OUString::createFromAscii("longer")) == sal_True);
946 /* rtl::OUString */ suToken = suTokenStr.getToken( 0, '.', nIndex );
947 CPPUNIT_ASSERT_MESSAGE("Token should be 'then'", suToken.equals(rtl::OUString::createFromAscii("then")) == sal_True);
949 /* rtl::OUString */ suToken = suTokenStr.getToken( 0, '.', nIndex );
950 CPPUNIT_ASSERT_MESSAGE("Token should be 'ever'", suToken.equals(rtl::OUString::createFromAscii("ever")) == sal_True);
952 /* rtl::OUString */ suToken = suTokenStr.getToken( 0, '.', nIndex );
953 CPPUNIT_ASSERT_MESSAGE("Token should be empty", suToken.getLength() == 0);
955 CPPUNIT_ASSERT_MESSAGE("index should be negative", nIndex == -1);
958 void getToken_005() {
959 rtl::OUString ab(RTL_CONSTASCII_USTRINGPARAM("ab"));
960 sal_Int32 n = 0;
961 CPPUNIT_ASSERT_MESSAGE(
962 "token should be 'ab'", ab.getToken(0, '-', n) == ab);
963 CPPUNIT_ASSERT_MESSAGE("n should be -1", n == -1);
964 CPPUNIT_ASSERT_MESSAGE(
965 "token should be empty", ab.getToken(0, '-', n).getLength() == 0);
968 CPPUNIT_TEST_SUITE(getToken);
969 CPPUNIT_TEST(getToken_000);
970 CPPUNIT_TEST(getToken_001);
971 CPPUNIT_TEST(getToken_002);
972 CPPUNIT_TEST(getToken_003);
973 CPPUNIT_TEST(getToken_004);
974 CPPUNIT_TEST(getToken_005);
975 CPPUNIT_TEST_SUITE_END();
976 }; // class getToken
978 class convertToString: public CppUnit::TestFixture {
979 public:
980 void test();
982 CPPUNIT_TEST_SUITE(convertToString);
983 CPPUNIT_TEST(test);
984 CPPUNIT_TEST_SUITE_END();
987 void convertToString::test() {
988 static sal_Unicode const utf16[] = { 0x0041, 0x00E4, 0x0061 };
989 rtl::OString s;
990 CPPUNIT_ASSERT(
991 rtl::OUString(utf16, sizeof utf16 / sizeof utf16[0]).convertToString(
992 &s, RTL_TEXTENCODING_UTF7,
993 (RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR |
994 RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR)));
995 CPPUNIT_ASSERT_EQUAL(
996 rtl::OString(RTL_CONSTASCII_STRINGPARAM("A+AOQ-a")), s);
999 // -----------------------------------------------------------------------------
1000 // - string construction & interning (tests)
1001 // -----------------------------------------------------------------------------
1002 class construction : public CppUnit::TestFixture
1004 public:
1005 void construct()
1007 #ifdef RTL_INLINE_STRINGS
1008 ::rtl::OUString aFoo( RTL_CONSTASCII_USTRINGPARAM("foo") );
1009 CPPUNIT_ASSERT_MESSAGE("string contents", aFoo[0] == 'f');
1010 CPPUNIT_ASSERT_MESSAGE("string contents", aFoo[1] == 'o');
1011 CPPUNIT_ASSERT_MESSAGE("string contents", aFoo[2] == 'o');
1012 CPPUNIT_ASSERT_MESSAGE("string length", aFoo.getLength() == 3);
1014 ::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.") );
1015 CPPUNIT_ASSERT_MESSAGE("string length", aBaa.getLength() == 104);
1016 // Dig at the internals ... FIXME: should we have the bit-flag defines public ?
1017 CPPUNIT_ASSERT_MESSAGE("string static flags", (aBaa.pData->refCount & 1<<30) != 0);
1018 #endif
1021 void intern()
1023 // The empty string is 'static' a special case ...
1024 rtl::OUString aEmpty = rtl::OUString().intern();
1025 rtl::OUString aEmpty2 = rtl::OUString::intern( RTL_CONSTASCII_USTRINGPARAM( "" ) );
1027 ::rtl::OUString aFoo( RTL_CONSTASCII_USTRINGPARAM("foo") );
1028 ::rtl::OUString aFooIntern = aFoo.intern();
1029 CPPUNIT_ASSERT_MESSAGE("string contents", aFooIntern.equalsAscii("foo"));
1030 CPPUNIT_ASSERT_MESSAGE("string length", aFooIntern.getLength() == 3);
1031 // We have to dup due to no atomic 'intern' bit-set operation
1032 CPPUNIT_ASSERT_MESSAGE("intern dups", aFoo.pData != aFooIntern.pData);
1034 // Test interning lots of things
1035 int i;
1036 static const int nSequence = 4096;
1037 rtl::OUString *pStrs;
1038 sal_uIntPtr *pValues;
1040 pStrs = new rtl::OUString[nSequence];
1041 pValues = new sal_uIntPtr[nSequence];
1042 for (i = 0; i < nSequence; i++)
1044 pStrs[i] = rtl::OUString::valueOf( sqrt( static_cast<double>(i) ) ).intern();
1045 pValues[i] = reinterpret_cast<sal_uIntPtr>( pStrs[i].pData );
1047 for (i = 0; i < nSequence; i++)
1049 rtl::OUString aNew = rtl::OUString::valueOf( sqrt( static_cast<double>(i) ) ).intern();
1050 CPPUNIT_ASSERT_MESSAGE("double intern failed",
1051 aNew.pData == pStrs[i].pData);
1054 // Free strings to check for leaks
1055 for (i = 0; i < nSequence; i++)
1057 // Overwrite - hopefully this re-uses the memory
1058 pStrs[i] = rtl::OUString();
1059 pStrs[i] = rtl::OUString::valueOf( sqrt( static_cast<double>(i) ) );
1062 for (i = 0; i < nSequence; i++)
1064 rtl::OUString aIntern;
1065 sal_uIntPtr nValue;
1066 aIntern = rtl::OUString::valueOf( sqrt( static_cast<double>(i) ) ).intern();
1068 nValue = reinterpret_cast<sal_uIntPtr>( aIntern.pData );
1069 // This may not be 100% reliable: memory may
1070 // have been re-used, but it's worth checking.
1071 CPPUNIT_ASSERT_MESSAGE("intern leaking", nValue != pValues[i]);
1073 delete [] pValues;
1074 delete [] pStrs;
1077 CPPUNIT_TEST_SUITE(construction);
1078 CPPUNIT_TEST(construct);
1079 CPPUNIT_TEST(intern);
1080 CPPUNIT_TEST_SUITE_END();
1083 class indexOfAscii: public CppUnit::TestFixture {
1084 public:
1085 void test();
1087 CPPUNIT_TEST_SUITE(indexOfAscii);
1088 CPPUNIT_TEST(test);
1089 CPPUNIT_TEST_SUITE_END();
1092 void indexOfAscii::test() {
1093 CPPUNIT_ASSERT_EQUAL(
1094 sal_Int32(-1),
1095 rtl::OUString().indexOfAsciiL(RTL_CONSTASCII_STRINGPARAM("")));
1096 CPPUNIT_ASSERT_EQUAL(
1097 sal_Int32(-1),
1098 rtl::OUString().lastIndexOfAsciiL(RTL_CONSTASCII_STRINGPARAM("")));
1099 CPPUNIT_ASSERT_EQUAL(
1100 sal_Int32(0),
1101 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foo")).indexOfAsciiL(
1102 RTL_CONSTASCII_STRINGPARAM("foo")));
1103 CPPUNIT_ASSERT_EQUAL(
1104 sal_Int32(0),
1105 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foo")).lastIndexOfAsciiL(
1106 RTL_CONSTASCII_STRINGPARAM("foo")));
1107 CPPUNIT_ASSERT_EQUAL(
1108 sal_Int32(2),
1109 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("fofoobar")).indexOfAsciiL(
1110 RTL_CONSTASCII_STRINGPARAM("foo")));
1111 CPPUNIT_ASSERT_EQUAL(
1112 sal_Int32(3),
1113 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foofoofob")).
1114 lastIndexOfAsciiL(RTL_CONSTASCII_STRINGPARAM("foo")));
1115 CPPUNIT_ASSERT_EQUAL(
1116 sal_Int32(3),
1117 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foofoobar")).indexOfAsciiL(
1118 RTL_CONSTASCII_STRINGPARAM("foo"), 1));
1121 class endsWith: public CppUnit::TestFixture {
1122 public:
1123 void test();
1125 CPPUNIT_TEST_SUITE(endsWith);
1126 CPPUNIT_TEST(test);
1127 CPPUNIT_TEST_SUITE_END();
1130 void endsWith::test() {
1131 CPPUNIT_ASSERT_EQUAL(
1132 true,
1133 rtl::OUString().endsWithAsciiL(RTL_CONSTASCII_STRINGPARAM("")));
1134 CPPUNIT_ASSERT_EQUAL(
1135 false,
1136 rtl::OUString().endsWithAsciiL(RTL_CONSTASCII_STRINGPARAM("foo")));
1137 CPPUNIT_ASSERT_EQUAL(
1138 true,
1139 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("bar")).endsWithAsciiL(
1140 RTL_CONSTASCII_STRINGPARAM("bar")));
1141 CPPUNIT_ASSERT_EQUAL(
1142 true,
1143 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foobar")).endsWithAsciiL(
1144 RTL_CONSTASCII_STRINGPARAM("bar")));
1145 CPPUNIT_ASSERT_EQUAL(
1146 false,
1147 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FOOBAR")).endsWithAsciiL(
1148 RTL_CONSTASCII_STRINGPARAM("bar")));
1151 class createFromCodePoints: public CppUnit::TestFixture {
1152 public:
1153 void test();
1155 CPPUNIT_TEST_SUITE(createFromCodePoints);
1156 CPPUNIT_TEST(test);
1157 CPPUNIT_TEST_SUITE_END();
1160 void createFromCodePoints::test() {
1161 CPPUNIT_ASSERT_EQUAL(
1162 sal_Int32(0),
1163 rtl::OUString(static_cast< sal_uInt32 const * >(NULL), 0).getLength());
1164 static sal_uInt32 const cp[] = { 0, 0xD800, 0xFFFF, 0x10000, 0x10FFFF };
1165 rtl::OUString s(cp, sizeof cp / sizeof (sal_uInt32));
1166 CPPUNIT_ASSERT_EQUAL(sal_Int32(7), s.getLength());
1167 CPPUNIT_ASSERT_EQUAL(sal_Unicode(0), s[0]);
1168 CPPUNIT_ASSERT_EQUAL(sal_Unicode(0xD800), s[1]);
1169 CPPUNIT_ASSERT_EQUAL(sal_Unicode(0xFFFF), s[2]);
1170 CPPUNIT_ASSERT_EQUAL(sal_Unicode(0xD800), s[3]);
1171 CPPUNIT_ASSERT_EQUAL(sal_Unicode(0xDC00), s[4]);
1172 CPPUNIT_ASSERT_EQUAL(sal_Unicode(0xDBFF), s[5]);
1173 CPPUNIT_ASSERT_EQUAL(sal_Unicode(0xDFFF), s[6]);
1176 class iterateCodePoints: public CppUnit::TestFixture {
1177 public:
1178 void testNotWellFormed();
1180 CPPUNIT_TEST_SUITE(iterateCodePoints);
1181 CPPUNIT_TEST(testNotWellFormed);
1182 CPPUNIT_TEST_SUITE_END();
1185 void iterateCodePoints::testNotWellFormed() {
1186 static sal_Unicode const utf16[] =
1187 { 0xD800, 0xDC00, 0x0041, 0xDBFF, 0xDFFF, 0xDDEF, 0xD9AB };
1188 rtl::OUString s(utf16, sizeof utf16 / sizeof (sal_Unicode));
1189 sal_Int32 i = 0;
1190 CPPUNIT_ASSERT_EQUAL(sal_uInt32(0x10000), s.iterateCodePoints(&i));
1191 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), i);
1192 CPPUNIT_ASSERT_EQUAL(sal_uInt32(0x0041), s.iterateCodePoints(&i));
1193 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), i);
1194 CPPUNIT_ASSERT_EQUAL(sal_uInt32(0x10FFFF), s.iterateCodePoints(&i));
1195 CPPUNIT_ASSERT_EQUAL(sal_Int32(5), i);
1196 CPPUNIT_ASSERT_EQUAL(sal_uInt32(0xDDEF), s.iterateCodePoints(&i));
1197 CPPUNIT_ASSERT_EQUAL(sal_Int32(6), i);
1198 CPPUNIT_ASSERT_EQUAL(sal_uInt32(0xD9AB), s.iterateCodePoints(&i));
1199 CPPUNIT_ASSERT_EQUAL(sal_Int32(7), i);
1200 CPPUNIT_ASSERT_EQUAL(sal_uInt32(0xD9AB), s.iterateCodePoints(&i, -1));
1201 CPPUNIT_ASSERT_EQUAL(sal_Int32(6), i);
1202 CPPUNIT_ASSERT_EQUAL(sal_uInt32(0xDDEF), s.iterateCodePoints(&i, -1));
1203 CPPUNIT_ASSERT_EQUAL(sal_Int32(5), i);
1204 CPPUNIT_ASSERT_EQUAL(sal_uInt32(0x10FFFF), s.iterateCodePoints(&i, -1));
1205 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), i);
1206 CPPUNIT_ASSERT_EQUAL(sal_uInt32(0x0041), s.iterateCodePoints(&i, -1));
1207 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), i);
1208 CPPUNIT_ASSERT_EQUAL(sal_uInt32(0x10000), s.iterateCodePoints(&i, -1));
1209 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), i);
1210 i = 1;
1211 CPPUNIT_ASSERT_EQUAL(sal_uInt32(0xDC00), s.iterateCodePoints(&i, 2));
1212 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), i);
1213 i = 4;
1214 CPPUNIT_ASSERT_EQUAL(sal_uInt32(0x10000), s.iterateCodePoints(&i, -3));
1215 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), i);
1218 class convertFromString: public CppUnit::TestFixture {
1219 public:
1220 void test();
1222 CPPUNIT_TEST_SUITE(createFromCodePoints);
1223 CPPUNIT_TEST(test);
1224 CPPUNIT_TEST_SUITE_END();
1227 void convertFromString::test() {
1228 rtl::OUString t;
1229 CPPUNIT_ASSERT(
1230 !rtl_convertStringToUString(
1231 &t.pData, RTL_CONSTASCII_STRINGPARAM("\x80"), RTL_TEXTENCODING_UTF8,
1232 (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR |
1233 RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR |
1234 RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR)));
1235 CPPUNIT_ASSERT(
1236 !rtl_convertStringToUString(
1237 &t.pData, RTL_CONSTASCII_STRINGPARAM("\xC0"), RTL_TEXTENCODING_UTF8,
1238 (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR |
1239 RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR |
1240 RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR)));
1241 CPPUNIT_ASSERT(
1242 !rtl_convertStringToUString(
1243 &t.pData, RTL_CONSTASCII_STRINGPARAM("\xFF"), RTL_TEXTENCODING_UTF8,
1244 (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR |
1245 RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR |
1246 RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR)));
1247 CPPUNIT_ASSERT(
1248 rtl_convertStringToUString(
1249 &t.pData, RTL_CONSTASCII_STRINGPARAM("abc"), RTL_TEXTENCODING_UTF8,
1250 (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR |
1251 RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR |
1252 RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR)));
1253 CPPUNIT_ASSERT(t.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("abc")));
1256 // -----------------------------------------------------------------------------
1257 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OUString::valueOf, "rtl_OUString");
1258 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OUString::toInt, "rtl_OUString");
1259 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OUString::toDouble, "rtl_OUString");
1260 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OUString::toFloat, "rtl_OUString");
1261 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OUString::lastIndexOf, "rtl_OUString");
1262 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OUString::getToken, "rtl_OUString");
1263 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(
1264 rtl_OUString::convertToString, "rtl_OUString");
1265 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OUString::construction, "rtl_OUString");
1266 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(
1267 rtl_OUString::indexOfAscii, "rtl_OUString");
1268 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OUString::endsWith, "rtl_OUString");
1269 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(
1270 rtl_OUString::createFromCodePoints, "rtl_OUString");
1271 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(
1272 rtl_OUString::iterateCodePoints, "rtl_OUString");
1273 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(
1274 rtl_OUString::convertFromString, "rtl_OUString");
1276 } // namespace rtl_OUString
1279 // -----------------------------------------------------------------------------
1281 // this macro creates an empty function, which will called by the RegisterAllFunctions()
1282 // to let the user the possibility to also register some functions by hand.
1283 NOADDITIONAL;