merged tag ooo/DEV300_m102
[LibreOffice.git] / sal / qa / rtl / oustring / rtl_OUString2.cxx
blob878f427132789b4255d71a2c0938715385c94fe0
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
29 // MARKER(update_precomp.py): autogen include statement, do not remove
30 #include "precompiled_sal.hxx"
31 // autogenerated file with codegen.pl
33 #include <math.h>
34 #include <stdio.h>
36 #include <algorithm> // STL
38 #include <testshl/simpleheader.hxx>
39 #include "stringhelper.hxx"
40 #include "valueequal.hxx"
42 inline void printOUString( ::rtl::OUString const & _suStr )
44 rtl::OString aString;
46 t_print( "OUString: " );
47 aString = ::rtl::OUStringToOString( _suStr, RTL_TEXTENCODING_ASCII_US );
48 t_print( "'%s'\n", aString.getStr( ) );
51 namespace rtl_OUString
54 class ctors_rtl_uString : public CppUnit::TestFixture
57 public:
58 /// test of OUString(rtl_uString*)
59 void ctors_001()
61 rtl::OUString *pStr = new rtl::OUString( rtl::OUString::createFromAscii("a String") );
63 rtl::OUString aStrToTest(pStr->pData);
64 delete pStr;
66 // maybe here should we do something with current memory
67 char* pBuffer = (char*) malloc(2 * 8);
68 memset(pBuffer, 0, 2 * 8);
69 free(pBuffer);
71 sal_Bool bResult = aStrToTest.equals(rtl::OUString::createFromAscii("a String"));
72 CPPUNIT_ASSERT_MESSAGE("String must not be empty", bResult == sal_True);
75 // Change the following lines only, if you add, remove or rename
76 // member functions of the current class,
77 // because these macros are need by auto register mechanism.
79 CPPUNIT_TEST_SUITE(ctors_rtl_uString);
80 CPPUNIT_TEST(ctors_001);
81 CPPUNIT_TEST_SUITE_END();
84 // -----------------------------------------------------------------------------
85 class valueOf : public CppUnit::TestFixture
87 void valueOf_float_test_impl(float _nValue)
89 rtl::OUString suValue;
90 suValue = rtl::OUString::valueOf( _nValue );
91 rtl::OString sValue;
92 sValue <<= suValue;
93 t_print(T_VERBOSE, "nFloat := %.9f sValue := %s\n", _nValue, sValue.getStr());
95 float nValueATOF = static_cast<float>(atof( sValue.getStr() ));
97 bool bEqualResult = is_float_equal(_nValue, nValueATOF);
98 CPPUNIT_ASSERT_MESSAGE("Values are not equal.", bEqualResult == true);
101 void valueOf_float_test(float _nValue)
103 valueOf_float_test_impl(_nValue);
105 // test also the negative part.
106 float nNegativeValue = -_nValue;
107 valueOf_float_test_impl(nNegativeValue);
110 public:
111 // insert your test code here.
112 void valueOf_float_test_001()
114 // this is demonstration code
115 // CPPUNIT_ASSERT_MESSAGE("a message", 1 == 1);
116 float nValue = 3.0f;
117 valueOf_float_test(nValue);
120 void valueOf_float_test_002()
122 float nValue = 3.5f;
123 valueOf_float_test(nValue);
126 void valueOf_float_test_003()
128 float nValue = 3.0625f;
129 valueOf_float_test(nValue);
132 void valueOf_float_test_004()
134 float nValue = 3.502525f;
135 valueOf_float_test(nValue);
138 void valueOf_float_test_005()
140 float nValue = 3.141592f;
141 valueOf_float_test(nValue);
144 void valueOf_float_test_006()
146 float nValue = 3.5025255f;
147 valueOf_float_test(nValue);
150 void valueOf_float_test_007()
152 float nValue = 3.0039062f;
153 valueOf_float_test(nValue);
156 private:
158 void valueOf_double_test_impl(double _nValue)
160 rtl::OUString suValue;
161 suValue = rtl::OUString::valueOf( _nValue );
162 rtl::OString sValue;
163 sValue <<= suValue;
164 t_print(T_VERBOSE, "nDouble := %.20f sValue := %s\n", _nValue, sValue.getStr());
166 double nValueATOF = atof( sValue.getStr() );
168 bool bEqualResult = is_double_equal(_nValue, nValueATOF);
169 CPPUNIT_ASSERT_MESSAGE("Values are not equal.", bEqualResult == true);
172 void valueOf_double_test(double _nValue)
174 valueOf_double_test_impl(_nValue);
176 // test also the negative part.
177 double nNegativeValue = -_nValue;
178 valueOf_double_test_impl(nNegativeValue);
180 public:
182 // valueOf double
183 void valueOf_double_test_001()
185 double nValue = 3.0;
186 valueOf_double_test(nValue);
188 void valueOf_double_test_002()
190 double nValue = 3.5;
191 valueOf_double_test(nValue);
193 void valueOf_double_test_003()
195 double nValue = 3.0625;
196 valueOf_double_test(nValue);
198 void valueOf_double_test_004()
200 double nValue = 3.1415926535;
201 valueOf_double_test(nValue);
203 void valueOf_double_test_005()
205 double nValue = 3.141592653589793;
206 valueOf_double_test(nValue);
208 void valueOf_double_test_006()
210 double nValue = 3.1415926535897932;
211 valueOf_double_test(nValue);
213 void valueOf_double_test_007()
215 double nValue = 3.14159265358979323;
216 valueOf_double_test(nValue);
218 void valueOf_double_test_008()
220 double nValue = 3.141592653589793238462643;
221 valueOf_double_test(nValue);
225 // Change the following lines only, if you add, remove or rename
226 // member functions of the current class,
227 // because these macros are need by auto register mechanism.
229 CPPUNIT_TEST_SUITE(valueOf);
230 CPPUNIT_TEST(valueOf_float_test_001);
231 CPPUNIT_TEST(valueOf_float_test_002);
232 CPPUNIT_TEST(valueOf_float_test_003);
233 CPPUNIT_TEST(valueOf_float_test_004);
234 CPPUNIT_TEST(valueOf_float_test_005);
235 CPPUNIT_TEST(valueOf_float_test_006);
236 CPPUNIT_TEST(valueOf_float_test_007);
238 CPPUNIT_TEST(valueOf_double_test_001);
239 CPPUNIT_TEST(valueOf_double_test_002);
240 CPPUNIT_TEST(valueOf_double_test_003);
241 CPPUNIT_TEST(valueOf_double_test_004);
242 CPPUNIT_TEST(valueOf_double_test_005);
243 CPPUNIT_TEST(valueOf_double_test_006);
244 CPPUNIT_TEST(valueOf_double_test_007);
245 CPPUNIT_TEST(valueOf_double_test_008);
246 CPPUNIT_TEST_SUITE_END();
247 }; // class valueOf
249 //------------------------------------------------------------------------
250 // testing the method toDouble()
251 //------------------------------------------------------------------------
252 template<class T>
253 sal_Int16 SAL_CALL checkPrecisionSize()
255 // sal_Int16 nSize = sizeof(T);
256 volatile T nCalcValue = 1.0;
259 // (i + 1) is the current precision
260 // numerical series
261 // 1.1
262 // 10.1
263 // 100.1
264 // ...
265 // 1000...0.1
267 sal_Int16 i = 0;
268 for (i=0;i<50;i++)
270 nCalcValue *= 10;
271 volatile T nValue = nCalcValue + static_cast<T>(0.1);
272 volatile T dSub = nValue - nCalcValue;
273 // ----- 0.11 ---- 0.1 ---- 0.09 -----
274 if (0.11 > dSub && dSub < 0.09)
276 // due to the fact, that the value is break down we sub 1 from the precision value
277 // but to suppress this, we start at zero, precision is i+1 till here --i;
278 break;
282 sal_Int16 j= 0;
283 nCalcValue = 1.0;
285 // numerical series
286 // 1.1
287 // 1.01
288 // 1.001
289 // ...
290 // 1.000...001
292 for (j=0;j<50;j++)
294 nCalcValue /= 10;
295 volatile T nValue = nCalcValue + static_cast<T>(1.0);
296 volatile T dSub = nValue - static_cast<T>(1.0);
297 // ---- 0.02 ----- 0.01 ---- 0 --- -0.99 ---- -0.98 ----
298 // volatile T dSubAbsolut = fabs(dSub);
299 // ---- 0.02 ----- 0.01 ---- 0 (cut)
300 if ( dSub == 0)
301 break;
303 if (i != j)
305 // hmmm....
306 // imho i +- 1 == j is a good value
307 int n = i - j;
308 if (n < 0) n = -n;
309 if (n <= 1)
311 return std::min(i,j);
313 else
315 t_print("warning: presision differs more than 1!\n");
319 return i;
322 // -----------------------------------------------------------------------------
324 class testPrecision
326 public:
327 testPrecision()
329 sal_Int16 nPrecision;
330 nPrecision = checkPrecisionSize<float>();
331 t_print("precision of float: %d sizeof()=%d \n", nPrecision, sizeof(float));
333 nPrecision = checkPrecisionSize<double>();
334 t_print("precision of double: %d sizeof()=%d \n", nPrecision, sizeof(double));
336 nPrecision = checkPrecisionSize<long double>();
337 t_print("precision of long double: %d sizeof()=%d \n", nPrecision, sizeof(long double));
343 class toInt: public CppUnit::TestFixture {
344 public:
345 void test() {
346 CPPUNIT_ASSERT_EQUAL(
347 static_cast< sal_Int32 >(-0x76543210),
348 (rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("-76543210")).
349 toInt32(16)));
350 CPPUNIT_ASSERT_EQUAL(
351 static_cast< sal_Int32 >(0xFEDCBA98),
352 (rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("+FEDCBA98")).
353 toInt32(16)));
354 CPPUNIT_ASSERT_EQUAL(
355 static_cast< sal_Int64 >(-SAL_CONST_INT64(0x76543210FEDCBA98)),
356 (rtl::OUString(
357 RTL_CONSTASCII_USTRINGPARAM("-76543210FEDCBA98")).
358 toInt64(16)));
359 CPPUNIT_ASSERT_EQUAL(
360 static_cast< sal_Int64 >(SAL_CONST_INT64(0xFEDCBA9876543210)),
361 (rtl::OUString(
362 RTL_CONSTASCII_USTRINGPARAM("+FEDCBA9876543210")).
363 toInt64(16)));
366 CPPUNIT_TEST_SUITE(toInt);
367 CPPUNIT_TEST(test);
368 CPPUNIT_TEST_SUITE_END();
371 // -----------------------------------------------------------------------------
372 // - toDouble (tests)
373 // -----------------------------------------------------------------------------
374 class toDouble : public CppUnit::TestFixture
376 public:
377 void toDouble_test_impl(rtl::OString const& _sValue)
379 //t_print("the original str is %s\n", _sValue.getStr());
380 double nValueATOF = atof( _sValue.getStr() );
381 //t_print("original data is %e\n", nValueATOF);
382 rtl::OUString suValue = rtl::OUString::createFromAscii( _sValue.getStr() );
383 double nValueToDouble = suValue.toDouble();
384 //t_print("result data is %e\n", nValueToDouble);
386 bool bEqualResult = is_double_equal(nValueToDouble, nValueATOF);
387 CPPUNIT_ASSERT_MESSAGE("Values are not equal.", bEqualResult == true);
390 void toDouble_test(rtl::OString const& _sValue)
392 toDouble_test_impl(_sValue);
394 // test also the negativ part.
395 rtl::OString sNegativValue("-");
396 sNegativValue += _sValue;
397 toDouble_test_impl(sNegativValue);
400 // insert your test code here.
401 void toDouble_selftest()
403 t_print("Start selftest:\n");
404 CPPUNIT_ASSERT (is_double_equal(1.0, 1.01) == false);
405 CPPUNIT_ASSERT (is_double_equal(1.0, 1.001) == false);
406 CPPUNIT_ASSERT (is_double_equal(1.0, 1.0001) == false);
407 CPPUNIT_ASSERT (is_double_equal(1.0, 1.00001) == false);
408 CPPUNIT_ASSERT (is_double_equal(1.0, 1.000001) == false);
409 CPPUNIT_ASSERT (is_double_equal(1.0, 1.0000001) == false);
410 CPPUNIT_ASSERT (is_double_equal(1.0, 1.00000001) == false);
411 CPPUNIT_ASSERT (is_double_equal(1.0, 1.000000001) == false);
412 CPPUNIT_ASSERT (is_double_equal(1.0, 1.0000000001) == false);
413 CPPUNIT_ASSERT (is_double_equal(1.0, 1.00000000001) == false);
414 CPPUNIT_ASSERT (is_double_equal(1.0, 1.000000000001) == false);
415 CPPUNIT_ASSERT (is_double_equal(1.0, 1.0000000000001) == false);
416 // we check til 15 values after comma
417 CPPUNIT_ASSERT (is_double_equal(1.0, 1.00000000000001) == true);
418 CPPUNIT_ASSERT (is_double_equal(1.0, 1.000000000000001) == true);
419 CPPUNIT_ASSERT (is_double_equal(1.0, 1.0000000000000001) == true);
420 t_print("Selftest done.\n");
423 void toDouble_test_3()
425 rtl::OString sValue("3");
426 toDouble_test(sValue);
428 void toDouble_test_3_5()
430 rtl::OString sValue("3.5");
431 toDouble_test(sValue);
433 void toDouble_test_3_0625()
435 rtl::OString sValue("3.0625");
436 toDouble_test(sValue);
438 void toDouble_test_pi()
440 // value from http://www.angio.net/pi/digits/50.txt
441 rtl::OString sValue("3.141592653589793238462643383279502884197169399375");
442 toDouble_test(sValue);
445 void toDouble_test_1()
447 rtl::OString sValue("1");
448 toDouble_test(sValue);
450 void toDouble_test_10()
452 rtl::OString sValue("10");
453 toDouble_test(sValue);
455 void toDouble_test_100()
457 rtl::OString sValue("100");
458 toDouble_test(sValue);
460 void toDouble_test_1000()
462 rtl::OString sValue("1000");
463 toDouble_test(sValue);
465 void toDouble_test_10000()
467 rtl::OString sValue("10000");
468 toDouble_test(sValue);
470 void toDouble_test_1e99()
472 rtl::OString sValue("1e99");
473 toDouble_test(sValue);
475 void toDouble_test_1e_n99()
477 rtl::OString sValue("1e-99");
478 toDouble_test(sValue);
480 void toDouble_test_1e308()
482 rtl::OString sValue("1e308");
483 toDouble_test(sValue);
486 // Change the following lines only, if you add, remove or rename
487 // member functions of the current class,
488 // because these macros are need by auto register mechanism.
490 CPPUNIT_TEST_SUITE(toDouble);
491 CPPUNIT_TEST(toDouble_selftest);
493 CPPUNIT_TEST(toDouble_test_3);
494 CPPUNIT_TEST(toDouble_test_3_5);
495 CPPUNIT_TEST(toDouble_test_3_0625);
496 CPPUNIT_TEST(toDouble_test_pi);
497 CPPUNIT_TEST(toDouble_test_1);
498 CPPUNIT_TEST(toDouble_test_10);
499 CPPUNIT_TEST(toDouble_test_100);
500 CPPUNIT_TEST(toDouble_test_1000);
501 CPPUNIT_TEST(toDouble_test_10000);
502 CPPUNIT_TEST(toDouble_test_1e99);
503 CPPUNIT_TEST(toDouble_test_1e_n99);
504 CPPUNIT_TEST(toDouble_test_1e308);
505 CPPUNIT_TEST_SUITE_END();
506 }; // class toDouble
508 // -----------------------------------------------------------------------------
509 // - toFloat (tests)
510 // -----------------------------------------------------------------------------
511 class toFloat : public CppUnit::TestFixture
513 public:
514 void toFloat_test_impl(rtl::OString const& _sValue)
516 //t_print("the original str is %s\n", _sValue.getStr());
517 float nValueATOF = static_cast<float>(atof( _sValue.getStr() ));
518 //t_print("the original str is %.10f\n", nValueATOF);
519 rtl::OUString suValue = rtl::OUString::createFromAscii( _sValue.getStr() );
520 float nValueToFloat = suValue.toFloat();
521 //t_print("the result str is %.10f\n", nValueToFloat);
523 bool bEqualResult = is_float_equal(nValueToFloat, nValueATOF);
524 CPPUNIT_ASSERT_MESSAGE("Values are not equal.", bEqualResult == true);
527 void toFloat_test(rtl::OString const& _sValue)
529 toFloat_test_impl(_sValue);
531 // test also the negativ part.
532 rtl::OString sNegativValue("-");
533 sNegativValue += _sValue;
534 toFloat_test_impl(sNegativValue);
537 // insert your test code here.
538 void toFloat_selftest()
540 t_print("Start selftest:\n");
541 CPPUNIT_ASSERT (is_float_equal(1.0f, 1.01f) == false);
542 CPPUNIT_ASSERT (is_float_equal(1.0f, 1.001f) == false);
543 CPPUNIT_ASSERT (is_float_equal(1.0f, 1.0001f) == false);
544 CPPUNIT_ASSERT (is_float_equal(1.0f, 1.00001f) == false);
545 CPPUNIT_ASSERT (is_float_equal(1.0f, 1.000002f) == false);
546 CPPUNIT_ASSERT (is_float_equal(1.0f, 1.0000001f) == true);
547 CPPUNIT_ASSERT (is_float_equal(1.0f, 1.00000001f) == true);
548 CPPUNIT_ASSERT (is_float_equal(1.0f, 1.000000001f) == true);
550 t_print("Selftest done.\n");
553 void toFloat_test_3()
555 rtl::OString sValue("3");
556 toFloat_test(sValue);
558 void toFloat_test_3_5()
560 rtl::OString sValue("3.5");
561 toFloat_test(sValue);
563 void toFloat_test_3_0625()
565 rtl::OString sValue("3.0625");
566 toFloat_test(sValue);
568 void toFloat_test_3_0625_e()
570 rtl::OString sValue("3.0625e-4");
571 toFloat_test(sValue);
573 void toFloat_test_pi()
575 // value from http://www.angio.net/pi/digits/50.txt
576 rtl::OString sValue("3.141592653589793238462643383279502884197169399375");
577 toFloat_test(sValue);
580 void toFloat_test_1()
582 rtl::OString sValue("1");
583 toFloat_test(sValue);
585 void toFloat_test_10()
587 rtl::OString sValue("10");
588 toFloat_test(sValue);
590 void toFloat_test_100()
592 rtl::OString sValue("100");
593 toFloat_test(sValue);
595 void toFloat_test_1000()
597 rtl::OString sValue("1000");
598 toFloat_test(sValue);
600 void toFloat_test_10000()
602 rtl::OString sValue("10000");
603 toFloat_test(sValue);
605 void toFloat_test_mix()
607 rtl::OString sValue("456789321455.123456789012");
608 toFloat_test(sValue);
610 void toFloat_test_1e99()
612 rtl::OString sValue("1e99");
613 toFloat_test(sValue);
615 void toFloat_test_1e_n99()
617 rtl::OString sValue("1e-9");
618 toFloat_test(sValue);
620 void toFloat_test_1e308()
622 rtl::OString sValue("1e308");
623 toFloat_test(sValue);
626 // Change the following lines only, if you add, remove or rename
627 // member functions of the current class,
628 // because these macros are need by auto register mechanism.
630 CPPUNIT_TEST_SUITE(toFloat);
631 CPPUNIT_TEST(toFloat_selftest);
633 CPPUNIT_TEST(toFloat_test_3);
634 CPPUNIT_TEST(toFloat_test_3_5);
635 CPPUNIT_TEST(toFloat_test_3_0625);
636 CPPUNIT_TEST(toFloat_test_3_0625_e);
637 CPPUNIT_TEST(toFloat_test_pi);
638 CPPUNIT_TEST(toFloat_test_1);
639 CPPUNIT_TEST(toFloat_test_10);
640 CPPUNIT_TEST(toFloat_test_100);
641 CPPUNIT_TEST(toFloat_test_1000);
642 CPPUNIT_TEST(toFloat_test_10000);
643 CPPUNIT_TEST(toFloat_test_mix);
644 CPPUNIT_TEST(toFloat_test_1e99);
645 CPPUNIT_TEST(toFloat_test_1e_n99);
646 CPPUNIT_TEST(toFloat_test_1e308);
647 CPPUNIT_TEST_SUITE_END();
648 }; // class toFloat
650 // -----------------------------------------------------------------------------
651 // - lastIndexOf (tests)
652 // -----------------------------------------------------------------------------
653 class lastIndexOf : public CppUnit::TestFixture
656 public:
657 void lastIndexOf_oustring(rtl::OUString const& _suStr, rtl::OUString const& _suSearchStr, sal_Int32 _nExpectedResultPos)
659 // Algorithm
660 // search the string _suSearchStr (rtl::OUString) in the string _suStr.
661 // check if the _nExpectedResultPos occurs.
663 sal_Int32 nPos = _suStr.lastIndexOf(_suSearchStr);
664 CPPUNIT_ASSERT_MESSAGE("expected position is wrong", nPos == _nExpectedResultPos);
667 void lastIndexOf_salunicode(rtl::OUString const& _suStr, sal_Unicode _cuSearchChar, sal_Int32 _nExpectedResultPos)
669 // Algorithm
670 // search the unicode char _suSearchChar (sal_Unicode) in the string _suStr.
671 // check if the _nExpectedResultPos occurs.
673 sal_Int32 nPos = _suStr.lastIndexOf(_cuSearchChar);
674 CPPUNIT_ASSERT_MESSAGE("expected position is wrong", nPos == _nExpectedResultPos);
677 void lastIndexOf_oustring_offset(rtl::OUString const& _suStr, rtl::OUString const& _suSearchStr, sal_Int32 _nExpectedResultPos, sal_Int32 _nStartOffset)
679 sal_Int32 nPos = _suStr.lastIndexOf(_suSearchStr, _nStartOffset);
680 CPPUNIT_ASSERT_MESSAGE("expected position is wrong", nPos == _nExpectedResultPos);
683 void lastIndexOf_salunicode_offset(rtl::OUString const& _suStr, sal_Unicode _cuSearchChar, sal_Int32 _nExpectedResultPos, sal_Int32 _nStartOffset)
685 sal_Int32 nPos = _suStr.lastIndexOf(_cuSearchChar, _nStartOffset);
686 CPPUNIT_ASSERT_MESSAGE("expected position is wrong", nPos == _nExpectedResultPos);
689 // -----------------------------------------------------------------------------
691 void lastIndexOf_test_oustring_offset_001()
693 // search for sun, start at the end, found (pos==0)
694 rtl::OUString aStr = rtl::OUString::createFromAscii("sun java system");
695 rtl::OUString aSearchStr = rtl::OUString::createFromAscii("sun");
696 lastIndexOf_oustring_offset(aStr, aSearchStr, 0, aStr.getLength());
699 void lastIndexOf_test_oustring_offset_002()
701 // search for sun, start at pos = 3, found (pos==0)
702 rtl::OUString aStr = rtl::OUString::createFromAscii("sun java system");
703 rtl::OUString aSearchStr = rtl::OUString::createFromAscii("sun");
704 lastIndexOf_oustring_offset(aStr, aSearchStr, 0, 3);
707 void lastIndexOf_test_oustring_offset_003()
709 // search for sun, start at pos = 2, found (pos==-1)
710 rtl::OUString aStr = rtl::OUString::createFromAscii("sun java system");
711 rtl::OUString aSearchStr = rtl::OUString::createFromAscii("sun");
712 lastIndexOf_oustring_offset(aStr, aSearchStr, -1, 2);
715 void lastIndexOf_test_oustring_offset_004()
717 // search for sun, start at the end, found (pos==0)
718 rtl::OUString aStr = rtl::OUString::createFromAscii("sun java system");
719 rtl::OUString aSearchStr = rtl::OUString::createFromAscii("sun");
720 lastIndexOf_oustring_offset(aStr, aSearchStr, -1, -1);
723 void lastIndexOf_test_oustring_001()
725 // search for sun, found (pos==0)
726 rtl::OUString aStr = rtl::OUString::createFromAscii("sun java system");
727 rtl::OUString aSearchStr = rtl::OUString::createFromAscii("sun");
728 lastIndexOf_oustring(aStr, aSearchStr, 0);
731 void lastIndexOf_test_oustring_002()
733 // search for sun, found (pos==4)
734 rtl::OUString aStr = rtl::OUString::createFromAscii("the sun java system");
735 rtl::OUString aSearchStr = rtl::OUString::createFromAscii("sun");
736 lastIndexOf_oustring(aStr, aSearchStr, 4);
739 void lastIndexOf_test_oustring_003()
741 // search for sun, found (pos==8)
742 rtl::OUString aStr = rtl::OUString::createFromAscii("the sun sun java system");
743 rtl::OUString aSearchStr = rtl::OUString::createFromAscii("sun");
744 lastIndexOf_oustring(aStr, aSearchStr, 8);
747 void lastIndexOf_test_oustring_004()
749 // search for sun, found (pos==8)
750 rtl::OUString aStr = rtl::OUString::createFromAscii("the sun sun");
751 rtl::OUString aSearchStr = rtl::OUString::createFromAscii("sun");
752 lastIndexOf_oustring(aStr, aSearchStr, 8);
755 void lastIndexOf_test_oustring_005()
757 // search for sun, found (pos==4)
758 rtl::OUString aStr = rtl::OUString::createFromAscii("the sun su");
759 rtl::OUString aSearchStr = rtl::OUString::createFromAscii("sun");
760 lastIndexOf_oustring(aStr, aSearchStr, 4);
763 void lastIndexOf_test_oustring_006()
765 // search for sun, found (pos==-1)
766 rtl::OUString aStr = rtl::OUString::createFromAscii("the su su");
767 rtl::OUString aSearchStr = rtl::OUString::createFromAscii("sun");
768 lastIndexOf_oustring(aStr, aSearchStr, -1);
771 void lastIndexOf_test_oustring_007()
773 // search for earth, not found (-1)
774 rtl::OUString aStr = rtl::OUString::createFromAscii("the su su");
775 rtl::OUString aSearchStr = rtl::OUString::createFromAscii("earth");
776 lastIndexOf_oustring(aStr, aSearchStr, -1);
779 void lastIndexOf_test_oustring_008()
781 // search for earth, not found (-1)
782 rtl::OUString aStr = rtl::OUString();
783 rtl::OUString aSearchStr = rtl::OUString::createFromAscii("earth");
784 lastIndexOf_oustring(aStr, aSearchStr, -1);
787 void lastIndexOf_test_oustring_009()
789 // search for earth, not found (-1)
790 rtl::OUString aStr = rtl::OUString();
791 rtl::OUString aSearchStr = rtl::OUString();
792 lastIndexOf_oustring(aStr, aSearchStr, -1);
796 void lastIndexOf_test_salunicode_001()
798 // search for 's', found (19)
799 rtl::OUString aStr = rtl::OUString::createFromAscii("the sun sun java system");
800 sal_Unicode suChar = L's';
801 lastIndexOf_salunicode(aStr, suChar, 19);
804 void lastIndexOf_test_salunicode_002()
806 // search for 'x', not found (-1)
807 rtl::OUString aStr = rtl::OUString::createFromAscii("the sun sun java system");
808 sal_Unicode suChar = L'x';
809 lastIndexOf_salunicode(aStr, suChar, -1);
812 void lastIndexOf_test_salunicode_offset_001()
814 // search for 's', start from pos last char, found (19)
815 rtl::OUString aStr = rtl::OUString::createFromAscii("the sun sun java system");
816 sal_Unicode cuChar = L's';
817 lastIndexOf_salunicode_offset(aStr, cuChar, 19, aStr.getLength());
819 void lastIndexOf_test_salunicode_offset_002()
821 // search for 's', start pos is last occur from search behind, found (17)
822 rtl::OUString aStr = rtl::OUString::createFromAscii("the sun sun java system");
823 sal_Unicode cuChar = L's';
824 lastIndexOf_salunicode_offset(aStr, cuChar, 17, 19);
826 void lastIndexOf_test_salunicode_offset_003()
828 // search for 't', start pos is 1, found (0)
829 rtl::OUString aStr = rtl::OUString::createFromAscii("the sun sun java system");
830 sal_Unicode cuChar = L't';
831 lastIndexOf_salunicode_offset(aStr, cuChar, 0, 1);
834 // Change the following lines only, if you add, remove or rename
835 // member functions of the current class,
836 // because these macros are need by auto register mechanism.
838 CPPUNIT_TEST_SUITE(lastIndexOf);
839 CPPUNIT_TEST(lastIndexOf_test_oustring_001);
840 CPPUNIT_TEST(lastIndexOf_test_oustring_002);
841 CPPUNIT_TEST(lastIndexOf_test_oustring_003);
842 CPPUNIT_TEST(lastIndexOf_test_oustring_004);
843 CPPUNIT_TEST(lastIndexOf_test_oustring_005);
844 CPPUNIT_TEST(lastIndexOf_test_oustring_006);
845 CPPUNIT_TEST(lastIndexOf_test_oustring_007);
846 CPPUNIT_TEST(lastIndexOf_test_oustring_008);
847 CPPUNIT_TEST(lastIndexOf_test_oustring_009);
849 CPPUNIT_TEST(lastIndexOf_test_oustring_offset_001);
850 CPPUNIT_TEST(lastIndexOf_test_oustring_offset_002);
851 CPPUNIT_TEST(lastIndexOf_test_oustring_offset_003);
852 CPPUNIT_TEST(lastIndexOf_test_oustring_offset_004);
854 CPPUNIT_TEST(lastIndexOf_test_salunicode_001);
855 CPPUNIT_TEST(lastIndexOf_test_salunicode_002);
857 CPPUNIT_TEST(lastIndexOf_test_salunicode_offset_001);
858 CPPUNIT_TEST(lastIndexOf_test_salunicode_offset_002);
859 CPPUNIT_TEST(lastIndexOf_test_salunicode_offset_003);
861 CPPUNIT_TEST_SUITE_END();
862 }; // class lastIndexOf
865 // -----------------------------------------------------------------------------
866 // - getToken (tests)
867 // -----------------------------------------------------------------------------
868 class getToken : public CppUnit::TestFixture
871 public:
872 void getToken_000()
874 rtl::OUString suTokenStr;
876 sal_Int32 nIndex = 0;
879 rtl::OUString suToken = suTokenStr.getToken( 0, ';', nIndex );
881 while ( nIndex >= 0 );
882 t_print("Index %d\n", nIndex);
883 // should not GPF
886 void getToken_001()
888 rtl::OUString suTokenStr = rtl::OUString::createFromAscii("a;b");
890 sal_Int32 nIndex = 0;
892 rtl::OUString suToken = suTokenStr.getToken( 0, ';', nIndex );
893 CPPUNIT_ASSERT_MESSAGE("Token should be a 'a'", suToken.equals(rtl::OUString::createFromAscii("a")) == sal_True);
895 /* rtl::OUString */ suToken = suTokenStr.getToken( 0, ';', nIndex );
896 CPPUNIT_ASSERT_MESSAGE("Token should be a 'b'", suToken.equals(rtl::OUString::createFromAscii("b")) == sal_True);
897 CPPUNIT_ASSERT_MESSAGE("index should be negative", nIndex == -1);
900 void getToken_002()
902 rtl::OUString suTokenStr = rtl::OUString::createFromAscii("a;b.c");
904 sal_Int32 nIndex = 0;
906 rtl::OUString suToken = suTokenStr.getToken( 0, ';', nIndex );
907 CPPUNIT_ASSERT_MESSAGE("Token should be a 'a'", suToken.equals(rtl::OUString::createFromAscii("a")) == sal_True);
909 /* rtl::OUString */ suToken = suTokenStr.getToken( 0, '.', nIndex );
910 CPPUNIT_ASSERT_MESSAGE("Token should be a 'b'", suToken.equals(rtl::OUString::createFromAscii("b")) == sal_True);
912 /* rtl::OUString */ suToken = suTokenStr.getToken( 0, '.', nIndex );
913 CPPUNIT_ASSERT_MESSAGE("Token should be a 'c'", suToken.equals(rtl::OUString::createFromAscii("c")) == sal_True);
914 CPPUNIT_ASSERT_MESSAGE("index should be negative", nIndex == -1);
917 void getToken_003()
919 rtl::OUString suTokenStr = rtl::OUString::createFromAscii("a;;b");
921 sal_Int32 nIndex = 0;
923 rtl::OUString suToken = suTokenStr.getToken( 0, ';', nIndex );
924 CPPUNIT_ASSERT_MESSAGE("Token should be a 'a'", suToken.equals(rtl::OUString::createFromAscii("a")) == sal_True);
926 /* rtl::OUString */ suToken = suTokenStr.getToken( 0, ';', nIndex );
927 CPPUNIT_ASSERT_MESSAGE("Token should be empty", suToken.getLength() == 0);
929 /* rtl::OUString */ suToken = suTokenStr.getToken( 0, ';', nIndex );
930 CPPUNIT_ASSERT_MESSAGE("Token should be a 'b'", suToken.equals(rtl::OUString::createFromAscii("b")) == sal_True);
931 CPPUNIT_ASSERT_MESSAGE("index should be negative", nIndex == -1);
934 void getToken_004()
936 rtl::OUString suTokenStr = rtl::OUString::createFromAscii("longer.then.ever.");
938 sal_Int32 nIndex = 0;
940 rtl::OUString suToken = suTokenStr.getToken( 0, '.', nIndex );
941 CPPUNIT_ASSERT_MESSAGE("Token should be 'longer'", suToken.equals(rtl::OUString::createFromAscii("longer")) == sal_True);
943 /* rtl::OUString */ suToken = suTokenStr.getToken( 0, '.', nIndex );
944 CPPUNIT_ASSERT_MESSAGE("Token should be 'then'", suToken.equals(rtl::OUString::createFromAscii("then")) == sal_True);
946 /* rtl::OUString */ suToken = suTokenStr.getToken( 0, '.', nIndex );
947 CPPUNIT_ASSERT_MESSAGE("Token should be 'ever'", suToken.equals(rtl::OUString::createFromAscii("ever")) == sal_True);
949 /* rtl::OUString */ suToken = suTokenStr.getToken( 0, '.', nIndex );
950 CPPUNIT_ASSERT_MESSAGE("Token should be empty", suToken.getLength() == 0);
952 CPPUNIT_ASSERT_MESSAGE("index should be negative", nIndex == -1);
955 void getToken_005() {
956 rtl::OUString ab(RTL_CONSTASCII_USTRINGPARAM("ab"));
957 sal_Int32 n = 0;
958 CPPUNIT_ASSERT_MESSAGE(
959 "token should be 'ab'", ab.getToken(0, '-', n) == ab);
960 CPPUNIT_ASSERT_MESSAGE("n should be -1", n == -1);
961 CPPUNIT_ASSERT_MESSAGE(
962 "token should be empty", ab.getToken(0, '-', n).getLength() == 0);
965 CPPUNIT_TEST_SUITE(getToken);
966 CPPUNIT_TEST(getToken_000);
967 CPPUNIT_TEST(getToken_001);
968 CPPUNIT_TEST(getToken_002);
969 CPPUNIT_TEST(getToken_003);
970 CPPUNIT_TEST(getToken_004);
971 CPPUNIT_TEST(getToken_005);
972 CPPUNIT_TEST_SUITE_END();
973 }; // class getToken
975 class convertToString: public CppUnit::TestFixture {
976 public:
977 void test();
979 CPPUNIT_TEST_SUITE(convertToString);
980 CPPUNIT_TEST(test);
981 CPPUNIT_TEST_SUITE_END();
984 void convertToString::test() {
985 static sal_Unicode const utf16[] = { 0x0041, 0x00E4, 0x0061 };
986 rtl::OString s;
987 CPPUNIT_ASSERT(
988 rtl::OUString(utf16, sizeof utf16 / sizeof utf16[0]).convertToString(
989 &s, RTL_TEXTENCODING_UTF7,
990 (RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR |
991 RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR)));
992 CPPUNIT_ASSERT_EQUAL(
993 rtl::OString(RTL_CONSTASCII_STRINGPARAM("A+AOQ-a")), s);
996 // -----------------------------------------------------------------------------
997 // - string construction & interning (tests)
998 // -----------------------------------------------------------------------------
999 class construction : public CppUnit::TestFixture
1001 public:
1002 void construct()
1004 #ifdef RTL_INLINE_STRINGS
1005 ::rtl::OUString aFoo( RTL_CONSTASCII_USTRINGPARAM("foo") );
1006 CPPUNIT_ASSERT_MESSAGE("string contents", aFoo[0] == 'f');
1007 CPPUNIT_ASSERT_MESSAGE("string contents", aFoo[1] == 'o');
1008 CPPUNIT_ASSERT_MESSAGE("string contents", aFoo[2] == 'o');
1009 CPPUNIT_ASSERT_MESSAGE("string length", aFoo.getLength() == 3);
1011 ::rtl::OUString aBaa( RTL_CONSTASCII_USTRINGPARAM("this is a very long string with a lot of long things inside it and it goes on and on and on forever etc.") );
1012 CPPUNIT_ASSERT_MESSAGE("string length", aBaa.getLength() == 104);
1013 // Dig at the internals ... FIXME: should we have the bit-flag defines public ?
1014 CPPUNIT_ASSERT_MESSAGE("string static flags", (aBaa.pData->refCount & 1<<30) != 0);
1015 #endif
1018 void intern()
1020 // The empty string is 'static' a special case ...
1021 rtl::OUString aEmpty = rtl::OUString().intern();
1022 rtl::OUString aEmpty2 = rtl::OUString::intern( RTL_CONSTASCII_USTRINGPARAM( "" ) );
1024 ::rtl::OUString aFoo( RTL_CONSTASCII_USTRINGPARAM("foo") );
1025 ::rtl::OUString aFooIntern = aFoo.intern();
1026 CPPUNIT_ASSERT_MESSAGE("string contents", aFooIntern.equalsAscii("foo"));
1027 CPPUNIT_ASSERT_MESSAGE("string length", aFooIntern.getLength() == 3);
1028 // We have to dup due to no atomic 'intern' bit-set operation
1029 CPPUNIT_ASSERT_MESSAGE("intern dups", aFoo.pData != aFooIntern.pData);
1031 // Test interning lots of things
1032 int i;
1033 static const int nSequence = 4096;
1034 rtl::OUString *pStrs;
1035 sal_uIntPtr *pValues;
1037 pStrs = new rtl::OUString[nSequence];
1038 pValues = new sal_uIntPtr[nSequence];
1039 for (i = 0; i < nSequence; i++)
1041 pStrs[i] = rtl::OUString::valueOf( sqrt( static_cast<double>(i) ) ).intern();
1042 pValues[i] = reinterpret_cast<sal_uIntPtr>( pStrs[i].pData );
1044 for (i = 0; i < nSequence; i++)
1046 rtl::OUString aNew = rtl::OUString::valueOf( sqrt( static_cast<double>(i) ) ).intern();
1047 CPPUNIT_ASSERT_MESSAGE("double intern failed",
1048 aNew.pData == pStrs[i].pData);
1051 // Free strings to check for leaks
1052 for (i = 0; i < nSequence; i++)
1054 // Overwrite - hopefully this re-uses the memory
1055 pStrs[i] = rtl::OUString();
1056 pStrs[i] = rtl::OUString::valueOf( sqrt( static_cast<double>(i) ) );
1059 for (i = 0; i < nSequence; i++)
1061 rtl::OUString aIntern;
1062 sal_uIntPtr nValue;
1063 aIntern = rtl::OUString::valueOf( sqrt( static_cast<double>(i) ) ).intern();
1065 nValue = reinterpret_cast<sal_uIntPtr>( aIntern.pData );
1066 // This may not be 100% reliable: memory may
1067 // have been re-used, but it's worth checking.
1068 CPPUNIT_ASSERT_MESSAGE("intern leaking", nValue != pValues[i]);
1070 delete [] pValues;
1071 delete [] pStrs;
1074 CPPUNIT_TEST_SUITE(construction);
1075 CPPUNIT_TEST(construct);
1076 CPPUNIT_TEST(intern);
1077 CPPUNIT_TEST_SUITE_END();
1080 class indexOfAscii: public CppUnit::TestFixture {
1081 public:
1082 void test();
1084 CPPUNIT_TEST_SUITE(indexOfAscii);
1085 CPPUNIT_TEST(test);
1086 CPPUNIT_TEST_SUITE_END();
1089 void indexOfAscii::test() {
1090 CPPUNIT_ASSERT_EQUAL(
1091 sal_Int32(-1),
1092 rtl::OUString().indexOfAsciiL(RTL_CONSTASCII_STRINGPARAM("")));
1093 CPPUNIT_ASSERT_EQUAL(
1094 sal_Int32(-1),
1095 rtl::OUString().lastIndexOfAsciiL(RTL_CONSTASCII_STRINGPARAM("")));
1096 CPPUNIT_ASSERT_EQUAL(
1097 sal_Int32(0),
1098 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foo")).indexOfAsciiL(
1099 RTL_CONSTASCII_STRINGPARAM("foo")));
1100 CPPUNIT_ASSERT_EQUAL(
1101 sal_Int32(0),
1102 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foo")).lastIndexOfAsciiL(
1103 RTL_CONSTASCII_STRINGPARAM("foo")));
1104 CPPUNIT_ASSERT_EQUAL(
1105 sal_Int32(2),
1106 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("fofoobar")).indexOfAsciiL(
1107 RTL_CONSTASCII_STRINGPARAM("foo")));
1108 CPPUNIT_ASSERT_EQUAL(
1109 sal_Int32(3),
1110 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foofoofob")).
1111 lastIndexOfAsciiL(RTL_CONSTASCII_STRINGPARAM("foo")));
1112 CPPUNIT_ASSERT_EQUAL(
1113 sal_Int32(3),
1114 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foofoobar")).indexOfAsciiL(
1115 RTL_CONSTASCII_STRINGPARAM("foo"), 1));
1118 class endsWith: public CppUnit::TestFixture {
1119 public:
1120 void test();
1122 CPPUNIT_TEST_SUITE(endsWith);
1123 CPPUNIT_TEST(test);
1124 CPPUNIT_TEST_SUITE_END();
1127 void endsWith::test() {
1128 CPPUNIT_ASSERT_EQUAL(
1129 true,
1130 rtl::OUString().endsWithAsciiL(RTL_CONSTASCII_STRINGPARAM("")));
1131 CPPUNIT_ASSERT_EQUAL(
1132 false,
1133 rtl::OUString().endsWithAsciiL(RTL_CONSTASCII_STRINGPARAM("foo")));
1134 CPPUNIT_ASSERT_EQUAL(
1135 true,
1136 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("bar")).endsWithAsciiL(
1137 RTL_CONSTASCII_STRINGPARAM("bar")));
1138 CPPUNIT_ASSERT_EQUAL(
1139 true,
1140 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foobar")).endsWithAsciiL(
1141 RTL_CONSTASCII_STRINGPARAM("bar")));
1142 CPPUNIT_ASSERT_EQUAL(
1143 false,
1144 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FOOBAR")).endsWithAsciiL(
1145 RTL_CONSTASCII_STRINGPARAM("bar")));
1148 class createFromCodePoints: public CppUnit::TestFixture {
1149 public:
1150 void test();
1152 CPPUNIT_TEST_SUITE(createFromCodePoints);
1153 CPPUNIT_TEST(test);
1154 CPPUNIT_TEST_SUITE_END();
1157 void createFromCodePoints::test() {
1158 CPPUNIT_ASSERT_EQUAL(
1159 sal_Int32(0),
1160 rtl::OUString(static_cast< sal_uInt32 const * >(NULL), 0).getLength());
1161 static sal_uInt32 const cp[] = { 0, 0xD800, 0xFFFF, 0x10000, 0x10FFFF };
1162 rtl::OUString s(cp, sizeof cp / sizeof (sal_uInt32));
1163 CPPUNIT_ASSERT_EQUAL(sal_Int32(7), s.getLength());
1164 CPPUNIT_ASSERT_EQUAL(sal_Unicode(0), s[0]);
1165 CPPUNIT_ASSERT_EQUAL(sal_Unicode(0xD800), s[1]);
1166 CPPUNIT_ASSERT_EQUAL(sal_Unicode(0xFFFF), s[2]);
1167 CPPUNIT_ASSERT_EQUAL(sal_Unicode(0xD800), s[3]);
1168 CPPUNIT_ASSERT_EQUAL(sal_Unicode(0xDC00), s[4]);
1169 CPPUNIT_ASSERT_EQUAL(sal_Unicode(0xDBFF), s[5]);
1170 CPPUNIT_ASSERT_EQUAL(sal_Unicode(0xDFFF), s[6]);
1173 class iterateCodePoints: public CppUnit::TestFixture {
1174 public:
1175 void testNotWellFormed();
1177 CPPUNIT_TEST_SUITE(iterateCodePoints);
1178 CPPUNIT_TEST(testNotWellFormed);
1179 CPPUNIT_TEST_SUITE_END();
1182 void iterateCodePoints::testNotWellFormed() {
1183 static sal_Unicode const utf16[] =
1184 { 0xD800, 0xDC00, 0x0041, 0xDBFF, 0xDFFF, 0xDDEF, 0xD9AB };
1185 rtl::OUString s(utf16, sizeof utf16 / sizeof (sal_Unicode));
1186 sal_Int32 i = 0;
1187 CPPUNIT_ASSERT_EQUAL(sal_uInt32(0x10000), s.iterateCodePoints(&i));
1188 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), i);
1189 CPPUNIT_ASSERT_EQUAL(sal_uInt32(0x0041), s.iterateCodePoints(&i));
1190 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), i);
1191 CPPUNIT_ASSERT_EQUAL(sal_uInt32(0x10FFFF), s.iterateCodePoints(&i));
1192 CPPUNIT_ASSERT_EQUAL(sal_Int32(5), i);
1193 CPPUNIT_ASSERT_EQUAL(sal_uInt32(0xDDEF), s.iterateCodePoints(&i));
1194 CPPUNIT_ASSERT_EQUAL(sal_Int32(6), i);
1195 CPPUNIT_ASSERT_EQUAL(sal_uInt32(0xD9AB), s.iterateCodePoints(&i));
1196 CPPUNIT_ASSERT_EQUAL(sal_Int32(7), i);
1197 CPPUNIT_ASSERT_EQUAL(sal_uInt32(0xD9AB), s.iterateCodePoints(&i, -1));
1198 CPPUNIT_ASSERT_EQUAL(sal_Int32(6), i);
1199 CPPUNIT_ASSERT_EQUAL(sal_uInt32(0xDDEF), s.iterateCodePoints(&i, -1));
1200 CPPUNIT_ASSERT_EQUAL(sal_Int32(5), i);
1201 CPPUNIT_ASSERT_EQUAL(sal_uInt32(0x10FFFF), s.iterateCodePoints(&i, -1));
1202 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), i);
1203 CPPUNIT_ASSERT_EQUAL(sal_uInt32(0x0041), s.iterateCodePoints(&i, -1));
1204 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), i);
1205 CPPUNIT_ASSERT_EQUAL(sal_uInt32(0x10000), s.iterateCodePoints(&i, -1));
1206 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), i);
1207 i = 1;
1208 CPPUNIT_ASSERT_EQUAL(sal_uInt32(0xDC00), s.iterateCodePoints(&i, 2));
1209 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), i);
1210 i = 4;
1211 CPPUNIT_ASSERT_EQUAL(sal_uInt32(0x10000), s.iterateCodePoints(&i, -3));
1212 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), i);
1215 class convertFromString: public CppUnit::TestFixture {
1216 public:
1217 void test();
1219 CPPUNIT_TEST_SUITE(createFromCodePoints);
1220 CPPUNIT_TEST(test);
1221 CPPUNIT_TEST_SUITE_END();
1224 void convertFromString::test() {
1225 rtl::OUString t;
1226 CPPUNIT_ASSERT(
1227 !rtl_convertStringToUString(
1228 &t.pData, RTL_CONSTASCII_STRINGPARAM("\x80"), RTL_TEXTENCODING_UTF8,
1229 (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR |
1230 RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR |
1231 RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR)));
1232 CPPUNIT_ASSERT(
1233 !rtl_convertStringToUString(
1234 &t.pData, RTL_CONSTASCII_STRINGPARAM("\xC0"), RTL_TEXTENCODING_UTF8,
1235 (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR |
1236 RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR |
1237 RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR)));
1238 CPPUNIT_ASSERT(
1239 !rtl_convertStringToUString(
1240 &t.pData, RTL_CONSTASCII_STRINGPARAM("\xFF"), RTL_TEXTENCODING_UTF8,
1241 (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR |
1242 RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR |
1243 RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR)));
1244 CPPUNIT_ASSERT(
1245 rtl_convertStringToUString(
1246 &t.pData, RTL_CONSTASCII_STRINGPARAM("abc"), RTL_TEXTENCODING_UTF8,
1247 (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR |
1248 RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR |
1249 RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR)));
1250 CPPUNIT_ASSERT(t.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("abc")));
1253 // -----------------------------------------------------------------------------
1254 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OUString::valueOf, "rtl_OUString");
1255 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OUString::toInt, "rtl_OUString");
1256 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OUString::toDouble, "rtl_OUString");
1257 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OUString::toFloat, "rtl_OUString");
1258 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OUString::lastIndexOf, "rtl_OUString");
1259 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OUString::getToken, "rtl_OUString");
1260 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(
1261 rtl_OUString::convertToString, "rtl_OUString");
1262 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OUString::construction, "rtl_OUString");
1263 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(
1264 rtl_OUString::indexOfAscii, "rtl_OUString");
1265 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OUString::endsWith, "rtl_OUString");
1266 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(
1267 rtl_OUString::createFromCodePoints, "rtl_OUString");
1268 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(
1269 rtl_OUString::iterateCodePoints, "rtl_OUString");
1270 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(
1271 rtl_OUString::convertFromString, "rtl_OUString");
1273 } // namespace rtl_OUString
1276 // -----------------------------------------------------------------------------
1278 // this macro creates an empty function, which will called by the RegisterAllFunctions()
1279 // to let the user the possibility to also register some functions by hand.
1280 NOADDITIONAL;