1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 // autogenerated file with codegen.pl
26 #include <algorithm> // STL
28 #include <testshl/simpleheader.hxx>
29 #include "stringhelper.hxx"
30 #include "valueequal.hxx"
32 inline void printOUString( ::rtl::OUString
const & _suStr
)
36 t_print( "OUString: " );
37 aString
= ::rtl::OUStringToOString( _suStr
, RTL_TEXTENCODING_ASCII_US
);
38 t_print( "'%s'\n", aString
.getStr( ) );
41 namespace rtl_OUString
44 class ctors_rtl_uString
: public CppUnit::TestFixture
48 /// test of OUString(rtl_uString*)
51 rtl::OUString
*pStr
= new rtl::OUString( "a String" );
53 rtl::OUString
aStrToTest(pStr
->pData
);
56 // maybe here should we do something with current memory
57 char* pBuffer
= (char*) malloc(2 * 8);
58 memset(pBuffer
, 0, 2 * 8);
61 sal_Bool bResult
= aStrToTest
== "a String";
62 CPPUNIT_ASSERT_MESSAGE("String must not be empty", bResult
== sal_True
);
65 // Change the following lines only, if you add, remove or rename
66 // member functions of the current class,
67 // because these macros are need by auto register mechanism.
69 CPPUNIT_TEST_SUITE(ctors_rtl_uString
);
70 CPPUNIT_TEST(ctors_001
);
71 CPPUNIT_TEST_SUITE_END();
74 // -----------------------------------------------------------------------------
75 class valueOf
: public CppUnit::TestFixture
77 void valueOf_float_test_impl(float _nValue
)
79 rtl::OUString suValue
;
80 suValue
= rtl::OUString::valueOf( _nValue
);
83 t_print(T_VERBOSE
, "nFloat := %.9f sValue := %s\n", _nValue
, sValue
.getStr());
85 float nValueATOF
= static_cast<float>(atof( sValue
.getStr() ));
87 bool bEqualResult
= is_float_equal(_nValue
, nValueATOF
);
88 CPPUNIT_ASSERT_MESSAGE("Values are not equal.", bEqualResult
== true);
91 void valueOf_float_test(float _nValue
)
93 valueOf_float_test_impl(_nValue
);
95 // test also the negative part.
96 float nNegativeValue
= -_nValue
;
97 valueOf_float_test_impl(nNegativeValue
);
101 // insert your test code here.
102 void valueOf_float_test_001()
104 // this is demonstration code
105 // CPPUNIT_ASSERT_MESSAGE("a message", 1 == 1);
107 valueOf_float_test(nValue
);
110 void valueOf_float_test_002()
113 valueOf_float_test(nValue
);
116 void valueOf_float_test_003()
118 float nValue
= 3.0625f
;
119 valueOf_float_test(nValue
);
122 void valueOf_float_test_004()
124 float nValue
= 3.502525f
;
125 valueOf_float_test(nValue
);
128 void valueOf_float_test_005()
130 float nValue
= 3.141592f
;
131 valueOf_float_test(nValue
);
134 void valueOf_float_test_006()
136 float nValue
= 3.5025255f
;
137 valueOf_float_test(nValue
);
140 void valueOf_float_test_007()
142 float nValue
= 3.0039062f
;
143 valueOf_float_test(nValue
);
148 void valueOf_double_test_impl(double _nValue
)
150 rtl::OUString suValue
;
151 suValue
= rtl::OUString::valueOf( _nValue
);
154 t_print(T_VERBOSE
, "nDouble := %.20f sValue := %s\n", _nValue
, sValue
.getStr());
156 double nValueATOF
= atof( sValue
.getStr() );
158 bool bEqualResult
= is_double_equal(_nValue
, nValueATOF
);
159 CPPUNIT_ASSERT_MESSAGE("Values are not equal.", bEqualResult
== true);
162 void valueOf_double_test(double _nValue
)
164 valueOf_double_test_impl(_nValue
);
166 // test also the negative part.
167 double nNegativeValue
= -_nValue
;
168 valueOf_double_test_impl(nNegativeValue
);
173 void valueOf_double_test_001()
176 valueOf_double_test(nValue
);
178 void valueOf_double_test_002()
181 valueOf_double_test(nValue
);
183 void valueOf_double_test_003()
185 double nValue
= 3.0625;
186 valueOf_double_test(nValue
);
188 void valueOf_double_test_004()
190 double nValue
= 3.1415926535;
191 valueOf_double_test(nValue
);
193 void valueOf_double_test_005()
195 double nValue
= 3.141592653589793;
196 valueOf_double_test(nValue
);
198 void valueOf_double_test_006()
200 double nValue
= 3.1415926535897932;
201 valueOf_double_test(nValue
);
203 void valueOf_double_test_007()
205 double nValue
= 3.14159265358979323;
206 valueOf_double_test(nValue
);
208 void valueOf_double_test_008()
210 double nValue
= 3.141592653589793238462643;
211 valueOf_double_test(nValue
);
215 // Change the following lines only, if you add, remove or rename
216 // member functions of the current class,
217 // because these macros are need by auto register mechanism.
219 CPPUNIT_TEST_SUITE(valueOf
);
220 CPPUNIT_TEST(valueOf_float_test_001
);
221 CPPUNIT_TEST(valueOf_float_test_002
);
222 CPPUNIT_TEST(valueOf_float_test_003
);
223 CPPUNIT_TEST(valueOf_float_test_004
);
224 CPPUNIT_TEST(valueOf_float_test_005
);
225 CPPUNIT_TEST(valueOf_float_test_006
);
226 CPPUNIT_TEST(valueOf_float_test_007
);
228 CPPUNIT_TEST(valueOf_double_test_001
);
229 CPPUNIT_TEST(valueOf_double_test_002
);
230 CPPUNIT_TEST(valueOf_double_test_003
);
231 CPPUNIT_TEST(valueOf_double_test_004
);
232 CPPUNIT_TEST(valueOf_double_test_005
);
233 CPPUNIT_TEST(valueOf_double_test_006
);
234 CPPUNIT_TEST(valueOf_double_test_007
);
235 CPPUNIT_TEST(valueOf_double_test_008
);
236 CPPUNIT_TEST_SUITE_END();
239 //------------------------------------------------------------------------
240 // testing the method toDouble()
241 //------------------------------------------------------------------------
243 sal_Int16 SAL_CALL
checkPrecisionSize()
245 // sal_Int16 nSize = sizeof(T);
246 volatile T nCalcValue
= 1.0;
249 // (i + 1) is the current precision
261 volatile T nValue
= nCalcValue
+ static_cast<T
>(0.1);
262 volatile T dSub
= nValue
- nCalcValue
;
263 // ----- 0.11 ---- 0.1 ---- 0.09 -----
264 if (0.11 > dSub
&& dSub
> 0.09)
266 // due to the fact, that the value is break down we sub 1 from the precision value
267 // but to suppress this, we start at zero, precision is i+1 till here --i;
285 volatile T nValue
= nCalcValue
+ static_cast<T
>(1.0);
286 volatile T dSub
= nValue
- static_cast<T
>(1.0);
287 // ---- 0.02 ----- 0.01 ---- 0 --- -0.99 ---- -0.98 ----
288 // volatile T dSubAbsolut = fabs(dSub);
289 // ---- 0.02 ----- 0.01 ---- 0 (cut)
296 // imho i +- 1 == j is a good value
301 return std::min(i
,j
);
305 t_print("warning: presision differs more than 1!\n");
312 // -----------------------------------------------------------------------------
319 sal_Int16 nPrecision
;
320 nPrecision
= checkPrecisionSize
<float>();
321 t_print("precision of float: %d sizeof()=%d \n", nPrecision
, sizeof(float));
323 nPrecision
= checkPrecisionSize
<double>();
324 t_print("precision of double: %d sizeof()=%d \n", nPrecision
, sizeof(double));
326 nPrecision
= checkPrecisionSize
<long double>();
327 t_print("precision of long double: %d sizeof()=%d \n", nPrecision
, sizeof(long double));
333 class toInt
: public CppUnit::TestFixture
{
336 CPPUNIT_ASSERT_EQUAL(
337 static_cast< sal_Int32
>(-0x76543210),
338 (rtl::OUString("-76543210").
340 CPPUNIT_ASSERT_EQUAL(
341 static_cast< sal_Int32
>(0xFEDCBA98),
342 (rtl::OUString("+FEDCBA98").
344 CPPUNIT_ASSERT_EQUAL(
345 static_cast< sal_Int64
>(-SAL_CONST_INT64(0x76543210FEDCBA98)),
347 "-76543210FEDCBA98").
349 CPPUNIT_ASSERT_EQUAL(
350 static_cast< sal_Int64
>(SAL_CONST_INT64(0xFEDCBA9876543210)),
352 "+FEDCBA9876543210").
356 CPPUNIT_TEST_SUITE(toInt
);
358 CPPUNIT_TEST_SUITE_END();
361 // -----------------------------------------------------------------------------
362 // - toDouble (tests)
363 // -----------------------------------------------------------------------------
364 class toDouble
: public CppUnit::TestFixture
367 void toDouble_test_impl(rtl::OString
const& _sValue
)
369 //t_print("the original str is %s\n", _sValue.getStr());
370 double nValueATOF
= atof( _sValue
.getStr() );
371 //t_print("original data is %e\n", nValueATOF);
372 rtl::OUString suValue
= rtl::OUString::createFromAscii( _sValue
.getStr() );
373 double nValueToDouble
= suValue
.toDouble();
374 //t_print("result data is %e\n", nValueToDouble);
376 bool bEqualResult
= is_double_equal(nValueToDouble
, nValueATOF
);
377 CPPUNIT_ASSERT_MESSAGE("Values are not equal.", bEqualResult
== true);
380 void toDouble_test(rtl::OString
const& _sValue
)
382 toDouble_test_impl(_sValue
);
384 // test also the negativ part.
385 rtl::OString
sNegativValue("-");
386 sNegativValue
+= _sValue
;
387 toDouble_test_impl(sNegativValue
);
390 // insert your test code here.
391 void toDouble_selftest()
393 t_print("Start selftest:\n");
394 CPPUNIT_ASSERT (is_double_equal(1.0, 1.01) == false);
395 CPPUNIT_ASSERT (is_double_equal(1.0, 1.001) == false);
396 CPPUNIT_ASSERT (is_double_equal(1.0, 1.0001) == false);
397 CPPUNIT_ASSERT (is_double_equal(1.0, 1.00001) == false);
398 CPPUNIT_ASSERT (is_double_equal(1.0, 1.000001) == false);
399 CPPUNIT_ASSERT (is_double_equal(1.0, 1.0000001) == false);
400 CPPUNIT_ASSERT (is_double_equal(1.0, 1.00000001) == false);
401 CPPUNIT_ASSERT (is_double_equal(1.0, 1.000000001) == false);
402 CPPUNIT_ASSERT (is_double_equal(1.0, 1.0000000001) == false);
403 CPPUNIT_ASSERT (is_double_equal(1.0, 1.00000000001) == false);
404 CPPUNIT_ASSERT (is_double_equal(1.0, 1.000000000001) == false);
405 CPPUNIT_ASSERT (is_double_equal(1.0, 1.0000000000001) == false);
406 // we check til 15 values after comma
407 CPPUNIT_ASSERT (is_double_equal(1.0, 1.00000000000001) == true);
408 CPPUNIT_ASSERT (is_double_equal(1.0, 1.000000000000001) == true);
409 CPPUNIT_ASSERT (is_double_equal(1.0, 1.0000000000000001) == true);
410 t_print("Selftest done.\n");
413 void toDouble_test_3()
415 rtl::OString
sValue("3");
416 toDouble_test(sValue
);
418 void toDouble_test_3_5()
420 rtl::OString
sValue("3.5");
421 toDouble_test(sValue
);
423 void toDouble_test_3_0625()
425 rtl::OString
sValue("3.0625");
426 toDouble_test(sValue
);
428 void toDouble_test_pi()
430 // value from http://www.angio.net/pi/digits/50.txt
431 rtl::OString
sValue("3.141592653589793238462643383279502884197169399375");
432 toDouble_test(sValue
);
435 void toDouble_test_1()
437 rtl::OString
sValue("1");
438 toDouble_test(sValue
);
440 void toDouble_test_10()
442 rtl::OString
sValue("10");
443 toDouble_test(sValue
);
445 void toDouble_test_100()
447 rtl::OString
sValue("100");
448 toDouble_test(sValue
);
450 void toDouble_test_1000()
452 rtl::OString
sValue("1000");
453 toDouble_test(sValue
);
455 void toDouble_test_10000()
457 rtl::OString
sValue("10000");
458 toDouble_test(sValue
);
460 void toDouble_test_1e99()
462 rtl::OString
sValue("1e99");
463 toDouble_test(sValue
);
465 void toDouble_test_1e_n99()
467 rtl::OString
sValue("1e-99");
468 toDouble_test(sValue
);
470 void toDouble_test_1e308()
472 rtl::OString
sValue("1e308");
473 toDouble_test(sValue
);
476 // Change the following lines only, if you add, remove or rename
477 // member functions of the current class,
478 // because these macros are need by auto register mechanism.
480 CPPUNIT_TEST_SUITE(toDouble
);
481 CPPUNIT_TEST(toDouble_selftest
);
483 CPPUNIT_TEST(toDouble_test_3
);
484 CPPUNIT_TEST(toDouble_test_3_5
);
485 CPPUNIT_TEST(toDouble_test_3_0625
);
486 CPPUNIT_TEST(toDouble_test_pi
);
487 CPPUNIT_TEST(toDouble_test_1
);
488 CPPUNIT_TEST(toDouble_test_10
);
489 CPPUNIT_TEST(toDouble_test_100
);
490 CPPUNIT_TEST(toDouble_test_1000
);
491 CPPUNIT_TEST(toDouble_test_10000
);
492 CPPUNIT_TEST(toDouble_test_1e99
);
493 CPPUNIT_TEST(toDouble_test_1e_n99
);
494 CPPUNIT_TEST(toDouble_test_1e308
);
495 CPPUNIT_TEST_SUITE_END();
498 // -----------------------------------------------------------------------------
500 // -----------------------------------------------------------------------------
501 class toFloat
: public CppUnit::TestFixture
504 void toFloat_test_impl(rtl::OString
const& _sValue
)
506 //t_print("the original str is %s\n", _sValue.getStr());
507 float nValueATOF
= static_cast<float>(atof( _sValue
.getStr() ));
508 //t_print("the original str is %.10f\n", nValueATOF);
509 rtl::OUString suValue
= rtl::OUString::createFromAscii( _sValue
.getStr() );
510 float nValueToFloat
= suValue
.toFloat();
511 //t_print("the result str is %.10f\n", nValueToFloat);
513 bool bEqualResult
= is_float_equal(nValueToFloat
, nValueATOF
);
514 CPPUNIT_ASSERT_MESSAGE("Values are not equal.", bEqualResult
== true);
517 void toFloat_test(rtl::OString
const& _sValue
)
519 toFloat_test_impl(_sValue
);
521 // test also the negativ part.
522 rtl::OString
sNegativValue("-");
523 sNegativValue
+= _sValue
;
524 toFloat_test_impl(sNegativValue
);
527 // insert your test code here.
528 void toFloat_selftest()
530 t_print("Start selftest:\n");
531 CPPUNIT_ASSERT (is_float_equal(1.0f
, 1.01f
) == false);
532 CPPUNIT_ASSERT (is_float_equal(1.0f
, 1.001f
) == false);
533 CPPUNIT_ASSERT (is_float_equal(1.0f
, 1.0001f
) == false);
534 CPPUNIT_ASSERT (is_float_equal(1.0f
, 1.00001f
) == false);
535 CPPUNIT_ASSERT (is_float_equal(1.0f
, 1.000002f
) == false);
536 CPPUNIT_ASSERT (is_float_equal(1.0f
, 1.0000001f
) == true);
537 CPPUNIT_ASSERT (is_float_equal(1.0f
, 1.00000001f
) == true);
538 CPPUNIT_ASSERT (is_float_equal(1.0f
, 1.000000001f
) == true);
540 t_print("Selftest done.\n");
543 void toFloat_test_3()
545 rtl::OString
sValue("3");
546 toFloat_test(sValue
);
548 void toFloat_test_3_5()
550 rtl::OString
sValue("3.5");
551 toFloat_test(sValue
);
553 void toFloat_test_3_0625()
555 rtl::OString
sValue("3.0625");
556 toFloat_test(sValue
);
558 void toFloat_test_3_0625_e()
560 rtl::OString
sValue("3.0625e-4");
561 toFloat_test(sValue
);
563 void toFloat_test_pi()
565 // value from http://www.angio.net/pi/digits/50.txt
566 rtl::OString
sValue("3.141592653589793238462643383279502884197169399375");
567 toFloat_test(sValue
);
570 void toFloat_test_1()
572 rtl::OString
sValue("1");
573 toFloat_test(sValue
);
575 void toFloat_test_10()
577 rtl::OString
sValue("10");
578 toFloat_test(sValue
);
580 void toFloat_test_100()
582 rtl::OString
sValue("100");
583 toFloat_test(sValue
);
585 void toFloat_test_1000()
587 rtl::OString
sValue("1000");
588 toFloat_test(sValue
);
590 void toFloat_test_10000()
592 rtl::OString
sValue("10000");
593 toFloat_test(sValue
);
595 void toFloat_test_mix()
597 rtl::OString
sValue("456789321455.123456789012");
598 toFloat_test(sValue
);
600 void toFloat_test_1e99()
602 rtl::OString
sValue("1e99");
603 toFloat_test(sValue
);
605 void toFloat_test_1e_n99()
607 rtl::OString
sValue("1e-9");
608 toFloat_test(sValue
);
610 void toFloat_test_1e308()
612 rtl::OString
sValue("1e308");
613 toFloat_test(sValue
);
616 // Change the following lines only, if you add, remove or rename
617 // member functions of the current class,
618 // because these macros are need by auto register mechanism.
620 CPPUNIT_TEST_SUITE(toFloat
);
621 CPPUNIT_TEST(toFloat_selftest
);
623 CPPUNIT_TEST(toFloat_test_3
);
624 CPPUNIT_TEST(toFloat_test_3_5
);
625 CPPUNIT_TEST(toFloat_test_3_0625
);
626 CPPUNIT_TEST(toFloat_test_3_0625_e
);
627 CPPUNIT_TEST(toFloat_test_pi
);
628 CPPUNIT_TEST(toFloat_test_1
);
629 CPPUNIT_TEST(toFloat_test_10
);
630 CPPUNIT_TEST(toFloat_test_100
);
631 CPPUNIT_TEST(toFloat_test_1000
);
632 CPPUNIT_TEST(toFloat_test_10000
);
633 CPPUNIT_TEST(toFloat_test_mix
);
634 CPPUNIT_TEST(toFloat_test_1e99
);
635 CPPUNIT_TEST(toFloat_test_1e_n99
);
636 CPPUNIT_TEST(toFloat_test_1e308
);
637 CPPUNIT_TEST_SUITE_END();
640 // -----------------------------------------------------------------------------
641 // - lastIndexOf (tests)
642 // -----------------------------------------------------------------------------
643 class lastIndexOf
: public CppUnit::TestFixture
647 void lastIndexOf_oustring(rtl::OUString
const& _suStr
, rtl::OUString
const& _suSearchStr
, sal_Int32 _nExpectedResultPos
)
650 // search the string _suSearchStr (rtl::OUString) in the string _suStr.
651 // check if the _nExpectedResultPos occurs.
653 sal_Int32 nPos
= _suStr
.lastIndexOf(_suSearchStr
);
654 CPPUNIT_ASSERT_MESSAGE("expected position is wrong", nPos
== _nExpectedResultPos
);
657 void lastIndexOf_salunicode(rtl::OUString
const& _suStr
, sal_Unicode _cuSearchChar
, sal_Int32 _nExpectedResultPos
)
660 // search the unicode char _suSearchChar (sal_Unicode) in the string _suStr.
661 // check if the _nExpectedResultPos occurs.
663 sal_Int32 nPos
= _suStr
.lastIndexOf(_cuSearchChar
);
664 CPPUNIT_ASSERT_MESSAGE("expected position is wrong", nPos
== _nExpectedResultPos
);
667 void lastIndexOf_oustring_offset(rtl::OUString
const& _suStr
, rtl::OUString
const& _suSearchStr
, sal_Int32 _nExpectedResultPos
, sal_Int32 _nStartOffset
)
669 sal_Int32 nPos
= _suStr
.lastIndexOf(_suSearchStr
, _nStartOffset
);
670 CPPUNIT_ASSERT_MESSAGE("expected position is wrong", nPos
== _nExpectedResultPos
);
673 void lastIndexOf_salunicode_offset(rtl::OUString
const& _suStr
, sal_Unicode _cuSearchChar
, sal_Int32 _nExpectedResultPos
, sal_Int32 _nStartOffset
)
675 sal_Int32 nPos
= _suStr
.lastIndexOf(_cuSearchChar
, _nStartOffset
);
676 CPPUNIT_ASSERT_MESSAGE("expected position is wrong", nPos
== _nExpectedResultPos
);
679 // -----------------------------------------------------------------------------
681 void lastIndexOf_test_oustring_offset_001()
683 // search for sun, start at the end, found (pos==0)
684 rtl::OUString
aStr("sun java system");
685 rtl::OUString
aSearchStr("sun");
686 lastIndexOf_oustring_offset(aStr
, aSearchStr
, 0, aStr
.getLength());
689 void lastIndexOf_test_oustring_offset_002()
691 // search for sun, start at pos = 3, found (pos==0)
692 rtl::OUString
aStr("sun java system");
693 rtl::OUString
aSearchStr("sun");
694 lastIndexOf_oustring_offset(aStr
, aSearchStr
, 0, 3);
697 void lastIndexOf_test_oustring_offset_003()
699 // search for sun, start at pos = 2, found (pos==-1)
700 rtl::OUString
aStr("sun java system");
701 rtl::OUString
aSearchStr("sun");
702 lastIndexOf_oustring_offset(aStr
, aSearchStr
, -1, 2);
705 void lastIndexOf_test_oustring_offset_004()
707 // search for sun, start at the end, found (pos==0)
708 rtl::OUString
aStr("sun java system");
709 rtl::OUString
aSearchStr("sun");
710 lastIndexOf_oustring_offset(aStr
, aSearchStr
, -1, -1);
713 void lastIndexOf_test_oustring_001()
715 // search for sun, found (pos==0)
716 rtl::OUString
aStr("sun java system");
717 rtl::OUString
aSearchStr("sun");
718 lastIndexOf_oustring(aStr
, aSearchStr
, 0);
721 void lastIndexOf_test_oustring_002()
723 // search for sun, found (pos==4)
724 rtl::OUString
aStr("the sun java system");
725 rtl::OUString
aSearchStr("sun");
726 lastIndexOf_oustring(aStr
, aSearchStr
, 4);
729 void lastIndexOf_test_oustring_003()
731 // search for sun, found (pos==8)
732 rtl::OUString
aStr("the sun sun java system");
733 rtl::OUString
aSearchStr("sun");
734 lastIndexOf_oustring(aStr
, aSearchStr
, 8);
737 void lastIndexOf_test_oustring_004()
739 // search for sun, found (pos==8)
740 rtl::OUString
aStr("the sun sun");
741 rtl::OUString
aSearchStr("sun");
742 lastIndexOf_oustring(aStr
, aSearchStr
, 8);
745 void lastIndexOf_test_oustring_005()
747 // search for sun, found (pos==4)
748 rtl::OUString
aStr("the sun su");
749 rtl::OUString
aSearchStr("sun");
750 lastIndexOf_oustring(aStr
, aSearchStr
, 4);
753 void lastIndexOf_test_oustring_006()
755 // search for sun, found (pos==-1)
756 rtl::OUString
aStr("the su su");
757 rtl::OUString
aSearchStr("sun");
758 lastIndexOf_oustring(aStr
, aSearchStr
, -1);
761 void lastIndexOf_test_oustring_007()
763 // search for earth, not found (-1)
764 rtl::OUString
aStr("the su su");
765 rtl::OUString
aSearchStr("earth");
766 lastIndexOf_oustring(aStr
, aSearchStr
, -1);
769 void lastIndexOf_test_oustring_008()
771 // search for earth, not found (-1)
772 rtl::OUString aStr
= rtl::OUString();
773 rtl::OUString
aSearchStr("earth");
774 lastIndexOf_oustring(aStr
, aSearchStr
, -1);
777 void lastIndexOf_test_oustring_009()
779 // search for earth, not found (-1)
780 rtl::OUString aStr
= rtl::OUString();
781 rtl::OUString aSearchStr
= rtl::OUString();
782 lastIndexOf_oustring(aStr
, aSearchStr
, -1);
786 void lastIndexOf_test_salunicode_001()
788 // search for 's', found (19)
789 rtl::OUString
aStr("the sun sun java system");
790 sal_Unicode suChar
= L
's';
791 lastIndexOf_salunicode(aStr
, suChar
, 19);
794 void lastIndexOf_test_salunicode_002()
796 // search for 'x', not found (-1)
797 rtl::OUString
aStr("the sun sun java system");
798 sal_Unicode suChar
= L
'x';
799 lastIndexOf_salunicode(aStr
, suChar
, -1);
802 void lastIndexOf_test_salunicode_offset_001()
804 // search for 's', start from pos last char, found (19)
805 rtl::OUString
aStr("the sun sun java system");
806 sal_Unicode cuChar
= L
's';
807 lastIndexOf_salunicode_offset(aStr
, cuChar
, 19, aStr
.getLength());
809 void lastIndexOf_test_salunicode_offset_002()
811 // search for 's', start pos is last occur from search behind, found (17)
812 rtl::OUString
aStr("the sun sun java system");
813 sal_Unicode cuChar
= L
's';
814 lastIndexOf_salunicode_offset(aStr
, cuChar
, 17, 19);
816 void lastIndexOf_test_salunicode_offset_003()
818 // search for 't', start pos is 1, found (0)
819 rtl::OUString
aStr("the sun sun java system");
820 sal_Unicode cuChar
= L
't';
821 lastIndexOf_salunicode_offset(aStr
, cuChar
, 0, 1);
824 // Change the following lines only, if you add, remove or rename
825 // member functions of the current class,
826 // because these macros are need by auto register mechanism.
828 CPPUNIT_TEST_SUITE(lastIndexOf
);
829 CPPUNIT_TEST(lastIndexOf_test_oustring_001
);
830 CPPUNIT_TEST(lastIndexOf_test_oustring_002
);
831 CPPUNIT_TEST(lastIndexOf_test_oustring_003
);
832 CPPUNIT_TEST(lastIndexOf_test_oustring_004
);
833 CPPUNIT_TEST(lastIndexOf_test_oustring_005
);
834 CPPUNIT_TEST(lastIndexOf_test_oustring_006
);
835 CPPUNIT_TEST(lastIndexOf_test_oustring_007
);
836 CPPUNIT_TEST(lastIndexOf_test_oustring_008
);
837 CPPUNIT_TEST(lastIndexOf_test_oustring_009
);
839 CPPUNIT_TEST(lastIndexOf_test_oustring_offset_001
);
840 CPPUNIT_TEST(lastIndexOf_test_oustring_offset_002
);
841 CPPUNIT_TEST(lastIndexOf_test_oustring_offset_003
);
842 CPPUNIT_TEST(lastIndexOf_test_oustring_offset_004
);
844 CPPUNIT_TEST(lastIndexOf_test_salunicode_001
);
845 CPPUNIT_TEST(lastIndexOf_test_salunicode_002
);
847 CPPUNIT_TEST(lastIndexOf_test_salunicode_offset_001
);
848 CPPUNIT_TEST(lastIndexOf_test_salunicode_offset_002
);
849 CPPUNIT_TEST(lastIndexOf_test_salunicode_offset_003
);
851 CPPUNIT_TEST_SUITE_END();
852 }; // class lastIndexOf
855 // -----------------------------------------------------------------------------
856 // - getToken (tests)
857 // -----------------------------------------------------------------------------
858 class getToken
: public CppUnit::TestFixture
864 rtl::OUString suTokenStr
;
866 sal_Int32 nIndex
= 0;
869 rtl::OUString suToken
= suTokenStr
.getToken( 0, ';', nIndex
);
871 while ( nIndex
>= 0 );
872 t_print("Index %d\n", nIndex
);
878 rtl::OUString
suTokenStr("a;b");
880 sal_Int32 nIndex
= 0;
882 rtl::OUString suToken
= suTokenStr
.getToken( 0, ';', nIndex
);
883 CPPUNIT_ASSERT_MESSAGE( "Token should be a 'a'", suToken
== "a" );
885 /* rtl::OUString */ suToken
= suTokenStr
.getToken( 0, ';', nIndex
);
886 CPPUNIT_ASSERT_MESSAGE( "Token should be a 'b'", suToken
== "b" );
887 CPPUNIT_ASSERT_MESSAGE("index should be negative", nIndex
== -1);
892 rtl::OUString
suTokenStr("a;b.c");
894 sal_Int32 nIndex
= 0;
896 rtl::OUString suToken
= suTokenStr
.getToken( 0, ';', nIndex
);
897 CPPUNIT_ASSERT_MESSAGE( "Token should be a 'a'", suToken
== "a" );
899 /* rtl::OUString */ suToken
= suTokenStr
.getToken( 0, '.', nIndex
);
900 CPPUNIT_ASSERT_MESSAGE( "Token should be a 'b'", suToken
== "b" );
902 /* rtl::OUString */ suToken
= suTokenStr
.getToken( 0, '.', nIndex
);
903 CPPUNIT_ASSERT_MESSAGE( "Token should be a 'c'", suToken
== "c" );
904 CPPUNIT_ASSERT_MESSAGE("index should be negative", nIndex
== -1);
909 rtl::OUString
suTokenStr("a;;b");
911 sal_Int32 nIndex
= 0;
913 rtl::OUString suToken
= suTokenStr
.getToken( 0, ';', nIndex
);
914 CPPUNIT_ASSERT_MESSAGE( "Token should be a 'a'", suToken
== "a" );
916 /* rtl::OUString */ suToken
= suTokenStr
.getToken( 0, ';', nIndex
);
917 CPPUNIT_ASSERT_MESSAGE("Token should be empty", suToken
.isEmpty());
919 /* rtl::OUString */ suToken
= suTokenStr
.getToken( 0, ';', nIndex
);
920 CPPUNIT_ASSERT_MESSAGE( "Token should be a 'b'", suToken
== "b" );
921 CPPUNIT_ASSERT_MESSAGE("index should be negative", nIndex
== -1);
926 rtl::OUString
suTokenStr("longer.then.ever.");
928 sal_Int32 nIndex
= 0;
930 rtl::OUString suToken
= suTokenStr
.getToken( 0, '.', nIndex
);
931 CPPUNIT_ASSERT_MESSAGE( "Token should be 'longer'", suToken
== "longer" );
933 /* rtl::OUString */ suToken
= suTokenStr
.getToken( 0, '.', nIndex
);
934 CPPUNIT_ASSERT_MESSAGE( "Token should be 'then'", suToken
== "then" );
936 /* rtl::OUString */ suToken
= suTokenStr
.getToken( 0, '.', nIndex
);
937 CPPUNIT_ASSERT_MESSAGE( "Token should be 'ever'", suToken
== "ever" );
939 /* rtl::OUString */ suToken
= suTokenStr
.getToken( 0, '.', nIndex
);
940 CPPUNIT_ASSERT_MESSAGE("Token should be empty", suToken
.isEmpty());
942 CPPUNIT_ASSERT_MESSAGE("index should be negative", nIndex
== -1);
945 void getToken_005() {
946 rtl::OUString
ab("ab");
948 CPPUNIT_ASSERT_MESSAGE(
949 "token should be 'ab'", ab
.getToken(0, '-', n
) == ab
);
950 CPPUNIT_ASSERT_MESSAGE("n should be -1", n
== -1);
951 CPPUNIT_ASSERT_MESSAGE(
952 "token should be empty", ab
.getToken(0, '-', n
).isEmpty());
955 CPPUNIT_TEST_SUITE(getToken
);
956 CPPUNIT_TEST(getToken_000
);
957 CPPUNIT_TEST(getToken_001
);
958 CPPUNIT_TEST(getToken_002
);
959 CPPUNIT_TEST(getToken_003
);
960 CPPUNIT_TEST(getToken_004
);
961 CPPUNIT_TEST(getToken_005
);
962 CPPUNIT_TEST_SUITE_END();
965 class convertToString
: public CppUnit::TestFixture
{
969 CPPUNIT_TEST_SUITE(convertToString
);
971 CPPUNIT_TEST_SUITE_END();
974 void convertToString::test() {
975 static sal_Unicode
const utf16
[] = { 0x0041, 0x00E4, 0x0061 };
978 rtl::OUString(utf16
, SAL_N_ELEMENTS(utf16
)).convertToString(
979 &s
, RTL_TEXTENCODING_UTF7
,
980 (RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR
|
981 RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR
)));
982 CPPUNIT_ASSERT_EQUAL(
983 rtl::OString(RTL_CONSTASCII_STRINGPARAM("A+AOQ-a")), s
);
986 // -----------------------------------------------------------------------------
987 // - string construction & interning (tests)
988 // -----------------------------------------------------------------------------
989 class construction
: public CppUnit::TestFixture
994 #ifdef RTL_INLINE_STRINGS
995 ::rtl::OUString
aFoo( "foo" );
996 CPPUNIT_ASSERT_MESSAGE("string contents", aFoo
[0] == 'f');
997 CPPUNIT_ASSERT_MESSAGE("string contents", aFoo
[1] == 'o');
998 CPPUNIT_ASSERT_MESSAGE("string contents", aFoo
[2] == 'o');
999 CPPUNIT_ASSERT_MESSAGE("string length", aFoo
.getLength() == 3);
1001 ::rtl::OUString
aBaa( "this is a very long string with a lot of long things inside it and it goes on and on and on forever etc." );
1002 CPPUNIT_ASSERT_MESSAGE("string length", aBaa
.getLength() == 104);
1003 // Dig at the internals ... FIXME: should we have the bit-flag defines public ?
1004 CPPUNIT_ASSERT_MESSAGE("string static flags", (aBaa
.pData
->refCount
& 1<<30) != 0);
1010 // The empty string is 'static' a special case ...
1011 rtl::OUString aEmpty
= rtl::OUString().intern();
1012 rtl::OUString aEmpty2
= rtl::OUString::intern( "" );
1014 ::rtl::OUString
aFoo( "foo" );
1015 ::rtl::OUString aFooIntern
= aFoo
.intern();
1016 CPPUNIT_ASSERT_MESSAGE( "string contents", aFooIntern
== "foo" );
1017 CPPUNIT_ASSERT_MESSAGE("string length", aFooIntern
.getLength() == 3);
1018 // We have to dup due to no atomic 'intern' bit-set operation
1019 CPPUNIT_ASSERT_MESSAGE("intern dups", aFoo
.pData
!= aFooIntern
.pData
);
1021 // Test interning lots of things
1023 static const int nSequence
= 4096;
1024 rtl::OUString
*pStrs
;
1025 sal_uIntPtr
*pValues
;
1027 pStrs
= new rtl::OUString
[nSequence
];
1028 pValues
= new sal_uIntPtr
[nSequence
];
1029 for (i
= 0; i
< nSequence
; i
++)
1031 pStrs
[i
] = rtl::OUString::valueOf( sqrt( static_cast<double>(i
) ) ).intern();
1032 pValues
[i
] = reinterpret_cast<sal_uIntPtr
>( pStrs
[i
].pData
);
1034 for (i
= 0; i
< nSequence
; i
++)
1036 rtl::OUString aNew
= rtl::OUString::valueOf( sqrt( static_cast<double>(i
) ) ).intern();
1037 CPPUNIT_ASSERT_MESSAGE("double intern failed",
1038 aNew
.pData
== pStrs
[i
].pData
);
1041 // Free strings to check for leaks
1042 for (i
= 0; i
< nSequence
; i
++)
1044 // Overwrite - hopefully this re-uses the memory
1045 pStrs
[i
] = rtl::OUString();
1046 pStrs
[i
] = rtl::OUString::valueOf( sqrt( static_cast<double>(i
) ) );
1049 for (i
= 0; i
< nSequence
; i
++)
1051 rtl::OUString aIntern
;
1053 aIntern
= rtl::OUString::valueOf( sqrt( static_cast<double>(i
) ) ).intern();
1055 nValue
= reinterpret_cast<sal_uIntPtr
>( aIntern
.pData
);
1056 // This may not be 100% reliable: memory may
1057 // have been re-used, but it's worth checking.
1058 CPPUNIT_ASSERT_MESSAGE("intern leaking", nValue
!= pValues
[i
]);
1064 CPPUNIT_TEST_SUITE(construction
);
1065 CPPUNIT_TEST(construct
);
1066 CPPUNIT_TEST(intern
);
1067 CPPUNIT_TEST_SUITE_END();
1070 class indexOfAscii
: public CppUnit::TestFixture
{
1074 CPPUNIT_TEST_SUITE(indexOfAscii
);
1076 CPPUNIT_TEST_SUITE_END();
1079 void indexOfAscii::test() {
1080 CPPUNIT_ASSERT_EQUAL(
1082 rtl::OUString().indexOfAsciiL(RTL_CONSTASCII_STRINGPARAM("")));
1083 CPPUNIT_ASSERT_EQUAL(
1085 rtl::OUString().lastIndexOfAsciiL(RTL_CONSTASCII_STRINGPARAM("")));
1086 CPPUNIT_ASSERT_EQUAL(
1088 rtl::OUString("foo").indexOfAsciiL(
1089 RTL_CONSTASCII_STRINGPARAM("foo")));
1090 CPPUNIT_ASSERT_EQUAL(
1092 rtl::OUString("foo").lastIndexOfAsciiL(
1093 RTL_CONSTASCII_STRINGPARAM("foo")));
1094 CPPUNIT_ASSERT_EQUAL(
1096 rtl::OUString("fofoobar").indexOfAsciiL(
1097 RTL_CONSTASCII_STRINGPARAM("foo")));
1098 CPPUNIT_ASSERT_EQUAL(
1100 rtl::OUString("foofoofob").
1101 lastIndexOfAsciiL(RTL_CONSTASCII_STRINGPARAM("foo")));
1102 CPPUNIT_ASSERT_EQUAL(
1104 rtl::OUString("foofoobar").indexOfAsciiL(
1105 RTL_CONSTASCII_STRINGPARAM("foo"), 1));
1108 class endsWith
: public CppUnit::TestFixture
{
1112 CPPUNIT_TEST_SUITE(endsWith
);
1114 CPPUNIT_TEST_SUITE_END();
1117 void endsWith::test() {
1118 CPPUNIT_ASSERT_EQUAL(
1120 rtl::OUString().endsWithAsciiL(RTL_CONSTASCII_STRINGPARAM("")));
1121 CPPUNIT_ASSERT_EQUAL(
1123 rtl::OUString().endsWithAsciiL(RTL_CONSTASCII_STRINGPARAM("foo")));
1124 CPPUNIT_ASSERT_EQUAL(
1126 rtl::OUString("bar").endsWithAsciiL(
1127 RTL_CONSTASCII_STRINGPARAM("bar")));
1128 CPPUNIT_ASSERT_EQUAL(
1130 rtl::OUString("foobar").endsWithAsciiL(
1131 RTL_CONSTASCII_STRINGPARAM("bar")));
1132 CPPUNIT_ASSERT_EQUAL(
1134 rtl::OUString("FOOBAR").endsWithAsciiL(
1135 RTL_CONSTASCII_STRINGPARAM("bar")));
1138 class createFromCodePoints
: public CppUnit::TestFixture
{
1142 CPPUNIT_TEST_SUITE(createFromCodePoints
);
1144 CPPUNIT_TEST_SUITE_END();
1147 void createFromCodePoints::test() {
1148 CPPUNIT_ASSERT_EQUAL(
1150 rtl::OUString(static_cast< sal_uInt32
const * >(NULL
), 0).getLength());
1151 static sal_uInt32
const cp
[] = { 0, 0xD800, 0xFFFF, 0x10000, 0x10FFFF };
1152 rtl::OUString
s(cp
, sizeof cp
/ sizeof (sal_uInt32
));
1153 CPPUNIT_ASSERT_EQUAL(sal_Int32(7), s
.getLength());
1154 CPPUNIT_ASSERT_EQUAL(sal_Unicode(0), s
[0]);
1155 CPPUNIT_ASSERT_EQUAL(sal_Unicode(0xD800), s
[1]);
1156 CPPUNIT_ASSERT_EQUAL(sal_Unicode(0xFFFF), s
[2]);
1157 CPPUNIT_ASSERT_EQUAL(sal_Unicode(0xD800), s
[3]);
1158 CPPUNIT_ASSERT_EQUAL(sal_Unicode(0xDC00), s
[4]);
1159 CPPUNIT_ASSERT_EQUAL(sal_Unicode(0xDBFF), s
[5]);
1160 CPPUNIT_ASSERT_EQUAL(sal_Unicode(0xDFFF), s
[6]);
1163 class iterateCodePoints
: public CppUnit::TestFixture
{
1165 void testNotWellFormed();
1167 CPPUNIT_TEST_SUITE(iterateCodePoints
);
1168 CPPUNIT_TEST(testNotWellFormed
);
1169 CPPUNIT_TEST_SUITE_END();
1172 void iterateCodePoints::testNotWellFormed() {
1173 static sal_Unicode
const utf16
[] =
1174 { 0xD800, 0xDC00, 0x0041, 0xDBFF, 0xDFFF, 0xDDEF, 0xD9AB };
1175 rtl::OUString
s(utf16
, sizeof utf16
/ sizeof (sal_Unicode
));
1177 CPPUNIT_ASSERT_EQUAL(sal_uInt32(0x10000), s
.iterateCodePoints(&i
));
1178 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), i
);
1179 CPPUNIT_ASSERT_EQUAL(sal_uInt32(0x0041), s
.iterateCodePoints(&i
));
1180 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), i
);
1181 CPPUNIT_ASSERT_EQUAL(sal_uInt32(0x10FFFF), s
.iterateCodePoints(&i
));
1182 CPPUNIT_ASSERT_EQUAL(sal_Int32(5), i
);
1183 CPPUNIT_ASSERT_EQUAL(sal_uInt32(0xDDEF), s
.iterateCodePoints(&i
));
1184 CPPUNIT_ASSERT_EQUAL(sal_Int32(6), i
);
1185 CPPUNIT_ASSERT_EQUAL(sal_uInt32(0xD9AB), s
.iterateCodePoints(&i
));
1186 CPPUNIT_ASSERT_EQUAL(sal_Int32(7), i
);
1187 CPPUNIT_ASSERT_EQUAL(sal_uInt32(0xD9AB), s
.iterateCodePoints(&i
, -1));
1188 CPPUNIT_ASSERT_EQUAL(sal_Int32(6), i
);
1189 CPPUNIT_ASSERT_EQUAL(sal_uInt32(0xDDEF), s
.iterateCodePoints(&i
, -1));
1190 CPPUNIT_ASSERT_EQUAL(sal_Int32(5), i
);
1191 CPPUNIT_ASSERT_EQUAL(sal_uInt32(0x10FFFF), s
.iterateCodePoints(&i
, -1));
1192 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), i
);
1193 CPPUNIT_ASSERT_EQUAL(sal_uInt32(0x0041), s
.iterateCodePoints(&i
, -1));
1194 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), i
);
1195 CPPUNIT_ASSERT_EQUAL(sal_uInt32(0x10000), s
.iterateCodePoints(&i
, -1));
1196 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), i
);
1198 CPPUNIT_ASSERT_EQUAL(sal_uInt32(0xDC00), s
.iterateCodePoints(&i
, 2));
1199 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), i
);
1201 CPPUNIT_ASSERT_EQUAL(sal_uInt32(0x10000), s
.iterateCodePoints(&i
, -3));
1202 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), i
);
1205 class convertFromString
: public CppUnit::TestFixture
{
1209 CPPUNIT_TEST_SUITE(createFromCodePoints
);
1211 CPPUNIT_TEST_SUITE_END();
1214 void convertFromString::test() {
1217 !rtl_convertStringToUString(
1218 &t
.pData
, RTL_CONSTASCII_STRINGPARAM("\x80"), RTL_TEXTENCODING_UTF8
,
1219 (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR
|
1220 RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR
|
1221 RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR
)));
1223 !rtl_convertStringToUString(
1224 &t
.pData
, RTL_CONSTASCII_STRINGPARAM("\xC0"), RTL_TEXTENCODING_UTF8
,
1225 (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR
|
1226 RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR
|
1227 RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR
)));
1229 !rtl_convertStringToUString(
1230 &t
.pData
, RTL_CONSTASCII_STRINGPARAM("\xFF"), RTL_TEXTENCODING_UTF8
,
1231 (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR
|
1232 RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR
|
1233 RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR
)));
1235 rtl_convertStringToUString(
1236 &t
.pData
, RTL_CONSTASCII_STRINGPARAM("abc"), RTL_TEXTENCODING_UTF8
,
1237 (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR
|
1238 RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR
|
1239 RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR
)));
1240 CPPUNIT_ASSERT( t
== "abc" );
1243 // -----------------------------------------------------------------------------
1244 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OUString::valueOf
, "rtl_OUString");
1245 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OUString::toInt
, "rtl_OUString");
1246 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OUString::toDouble
, "rtl_OUString");
1247 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OUString::toFloat
, "rtl_OUString");
1248 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OUString::lastIndexOf
, "rtl_OUString");
1249 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OUString::getToken
, "rtl_OUString");
1250 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(
1251 rtl_OUString::convertToString
, "rtl_OUString");
1252 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OUString::construction
, "rtl_OUString");
1253 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(
1254 rtl_OUString::indexOfAscii
, "rtl_OUString");
1255 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OUString::endsWith
, "rtl_OUString");
1256 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(
1257 rtl_OUString::createFromCodePoints
, "rtl_OUString");
1258 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(
1259 rtl_OUString::iterateCodePoints
, "rtl_OUString");
1260 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(
1261 rtl_OUString::convertFromString
, "rtl_OUString");
1263 } // namespace rtl_OUString
1266 // -----------------------------------------------------------------------------
1268 // this macro creates an empty function, which will called by the RegisterAllFunctions()
1269 // to let the user the possibility to also register some functions by hand.
1272 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */