merged tag ooo/DEV300_m102
[LibreOffice.git] / sal / qa / rtl / ostring / rtl_str.cxx
blobb513c6cb1398312faab8e68a026fb5aa5c44f52b
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 #include <testshl/simpleheader.hxx>
33 namespace rtl_str
36 class compare : public CppUnit::TestFixture
38 public:
40 void compare_000()
42 rtl_str_compare( NULL, NULL);
45 void compare_000_1()
47 rtl::OString aStr1 = "Line must be equal.";
48 rtl_str_compare( aStr1.getStr(), NULL);
50 void compare_001()
52 rtl::OString aStr1 = "";
53 rtl::OString aStr2 = "";
55 sal_Int32 nValue = rtl_str_compare( aStr1.getStr(), aStr2.getStr());
56 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
59 void compare_002()
61 rtl::OString aStr1 = "Line must be equal.";
62 rtl::OString aStr2 = "Line must be equal.";
64 sal_Int32 nValue = rtl_str_compare( aStr1.getStr(), aStr2.getStr());
65 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
68 void compare_003()
70 rtl::OString aStr1 = "Line must differ.";
71 rtl::OString aStr2 = "Line foo bar, ok, differ.";
73 sal_Int32 nValue = rtl_str_compare( aStr1.getStr(), aStr2.getStr());
74 CPPUNIT_ASSERT_MESSAGE("compare failed, strings differ.", nValue != 0);
77 // Change the following lines only, if you add, remove or rename
78 // member functions of the current class,
79 // because these macros are need by auto register mechanism.
81 CPPUNIT_TEST_SUITE(compare);
82 CPPUNIT_TEST(compare_000);
83 CPPUNIT_TEST(compare_000_1);
84 CPPUNIT_TEST(compare_001);
85 CPPUNIT_TEST(compare_002);
86 CPPUNIT_TEST(compare_003);
87 CPPUNIT_TEST_SUITE_END();
88 }; // class compare
91 class compareIgnoreAsciiCase : public CppUnit::TestFixture
93 public:
95 void compare_000()
97 rtl_str_compareIgnoreAsciiCase( NULL, NULL);
100 void compare_000_1()
102 rtl::OString aStr1 = "Line must be equal.";
103 rtl_str_compareIgnoreAsciiCase( aStr1.getStr(), NULL);
105 void compare_001()
107 rtl::OString aStr1 = "";
108 rtl::OString aStr2 = "";
110 sal_Int32 nValue = rtl_str_compareIgnoreAsciiCase( aStr1.getStr(), aStr2.getStr());
111 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
114 void compare_002()
116 rtl::OString aStr1 = "Line must be equal.";
117 rtl::OString aStr2 = "Line must be equal.";
119 sal_Int32 nValue = rtl_str_compareIgnoreAsciiCase( aStr1.getStr(), aStr2.getStr());
120 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
123 void compare_002_1()
125 rtl::OString aStr1 = "Line must be equal.";
126 rtl::OString aStr2 = "LINE MUST BE EQUAL.";
128 sal_Int32 nValue = rtl_str_compareIgnoreAsciiCase( aStr1.getStr(), aStr2.getStr());
129 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal (if case insensitve).", nValue == 0);
132 void compare_003()
134 rtl::OString aStr1 = "Line must differ.";
135 rtl::OString aStr2 = "Line foo bar, ok, differ.";
137 sal_Int32 nValue = rtl_str_compareIgnoreAsciiCase( aStr1.getStr(), aStr2.getStr());
138 CPPUNIT_ASSERT_MESSAGE("compare failed, strings differ.", nValue != 0);
141 // Change the following lines only, if you add, remove or rename
142 // member functions of the current class,
143 // because these macros are need by auto register mechanism.
145 CPPUNIT_TEST_SUITE(compareIgnoreAsciiCase);
146 CPPUNIT_TEST(compare_000);
147 CPPUNIT_TEST(compare_000_1);
148 CPPUNIT_TEST(compare_001);
149 CPPUNIT_TEST(compare_002);
150 CPPUNIT_TEST(compare_002_1);
151 CPPUNIT_TEST(compare_003);
152 CPPUNIT_TEST_SUITE_END();
153 }; // class compareIgnoreAsciiCase
155 // -----------------------------------------------------------------------------
157 class shortenedCompareIgnoreAsciiCase_WithLength : public CppUnit::TestFixture
159 public:
161 void compare_000()
163 rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( NULL, 0, NULL, 0, 0);
166 void compare_000_1()
168 rtl::OString aStr1 = "Line must be equal.";
169 rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(), NULL, 0, 1);
171 void compare_001()
173 rtl::OString aStr1 = "";
174 rtl::OString aStr2 = "";
176 sal_Int32 nValue = rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(), aStr2.getStr(), aStr2.getLength(), aStr1.getLength());
177 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
180 void compare_002()
182 rtl::OString aStr1 = "Line must be equal.";
183 rtl::OString aStr2 = "Line must be equal.";
185 sal_Int32 nValue = rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(),
186 aStr2.getStr(), aStr2.getLength(),
187 aStr1.getLength());
188 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
191 void compare_002_1()
193 rtl::OString aStr1 = "Line must be equal.";
194 rtl::OString aStr2 = "LINE MUST BE EQUAL.";
196 sal_Int32 nValue = rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(),
197 aStr2.getStr(), aStr2.getLength(),
198 aStr1.getLength());
199 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal (if case insensitve).", nValue == 0);
202 void compare_003()
204 rtl::OString aStr1 = "Line must differ.";
205 rtl::OString aStr2 = "Line foo bar, ok, differ.";
207 sal_Int32 nValue = rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(),
208 aStr2.getStr(), aStr2.getLength(),
210 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal first 5 characters.", nValue == 0);
213 void compare_004()
215 rtl::OString aStr1 = "Line must differ.";
216 rtl::OString aStr2 = "Line foo bar, ok, differ.";
218 sal_Int32 nValue = rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(),
219 aStr2.getStr(), aStr2.getLength(),
220 aStr1.getLength());
221 CPPUNIT_ASSERT_MESSAGE("compare failed, strings differ.", nValue != 0);
224 // Change the following lines only, if you add, remove or rename
225 // member functions of the current class,
226 // because these macros are need by auto register mechanism.
228 CPPUNIT_TEST_SUITE(shortenedCompareIgnoreAsciiCase_WithLength);
229 CPPUNIT_TEST(compare_000);
230 CPPUNIT_TEST(compare_000_1);
231 CPPUNIT_TEST(compare_001);
232 CPPUNIT_TEST(compare_002);
233 CPPUNIT_TEST(compare_002_1);
234 CPPUNIT_TEST(compare_003);
235 CPPUNIT_TEST(compare_004);
236 CPPUNIT_TEST_SUITE_END();
237 }; // class compare
240 // -----------------------------------------------------------------------------
242 class hashCode : public CppUnit::TestFixture
244 public:
246 void hashCode_000()
248 rtl_str_hashCode( NULL );
251 void hashCode_001()
253 rtl::OString aStr1 = "Line for a hashCode.";
254 sal_Int32 nHashCode = rtl_str_hashCode( aStr1.getStr() );
255 t_print("hashcode: %d\n", nHashCode);
256 // CPPUNIT_ASSERT_MESSAGE("failed.", nValue == 0);
259 void hashCode_002()
261 rtl::OString aStr1 = "Line for a hashCode.";
262 sal_Int32 nHashCode1 = rtl_str_hashCode( aStr1.getStr() );
264 rtl::OString aStr2 = "Line for a hashCode.";
265 sal_Int32 nHashCode2 = rtl_str_hashCode( aStr2.getStr() );
267 CPPUNIT_ASSERT_MESSAGE("hashcodes must be equal.", nHashCode1 == nHashCode2 );
270 void hashCode_003()
272 rtl::OString aStr1 = "Line for a hashCode.";
273 sal_Int32 nHashCode1 = rtl_str_hashCode( aStr1.getStr() );
275 rtl::OString aStr2 = "Line for an other hashcode.";
276 sal_Int32 nHashCode2 = rtl_str_hashCode( aStr2.getStr() );
278 CPPUNIT_ASSERT_MESSAGE("hashcodes must differ.", nHashCode1 != nHashCode2 );
281 // Change the following lines only, if you add, remove or rename
282 // member functions of the current class,
283 // because these macros are need by auto register mechanism.
285 CPPUNIT_TEST_SUITE(hashCode);
286 CPPUNIT_TEST(hashCode_000);
287 CPPUNIT_TEST(hashCode_001);
288 CPPUNIT_TEST(hashCode_002);
289 CPPUNIT_TEST(hashCode_003);
290 CPPUNIT_TEST_SUITE_END();
291 }; // class compare
294 // -----------------------------------------------------------------------------
296 class indexOfChar : public CppUnit::TestFixture
298 public:
300 void indexOfChar_000()
302 rtl_str_indexOfChar( NULL, 0 );
305 void indexOfChar_001()
307 rtl::OString aStr1 = "Line for a indexOfChar.";
309 sal_Int32 nIndex = rtl_str_indexOfChar( aStr1.getStr(), 'L' );
310 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 0);
312 /* sal_Int32 */ nIndex = rtl_str_indexOfChar( aStr1.getStr(), 'i' );
313 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 1);
315 /* sal_Int32 */ nIndex = rtl_str_indexOfChar( aStr1.getStr(), 'n' );
316 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 2);
318 /* sal_Int32 */ nIndex = rtl_str_indexOfChar( aStr1.getStr(), 'e' );
319 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 3);
322 void indexOfChar_002()
324 rtl::OString aStr1 = "Line for a indexOfChar.";
325 sal_Int32 nIndex = rtl_str_indexOfChar( aStr1.getStr(), 'y' );
327 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == -1 );
330 // Change the following lines only, if you add, remove or rename
331 // member functions of the current class,
332 // because these macros are need by auto register mechanism.
334 CPPUNIT_TEST_SUITE(indexOfChar);
335 CPPUNIT_TEST(indexOfChar_000);
336 CPPUNIT_TEST(indexOfChar_001);
337 CPPUNIT_TEST(indexOfChar_002);
338 CPPUNIT_TEST_SUITE_END();
339 }; // class compare
341 // -----------------------------------------------------------------------------
342 class lastIndexOfChar : public CppUnit::TestFixture
344 public:
346 void lastIndexOfChar_000()
348 rtl_str_lastIndexOfChar( NULL, 0 );
351 void lastIndexOfChar_001()
353 rtl::OString aStr1 = "Line for a lastIndexOfChar.";
355 sal_Int32 nIndex = rtl_str_lastIndexOfChar( aStr1.getStr(), 'C' );
356 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 22);
358 /* sal_Int32 */ nIndex = rtl_str_lastIndexOfChar( aStr1.getStr(), 'h' );
359 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 23);
361 /* sal_Int32 */ nIndex = rtl_str_lastIndexOfChar( aStr1.getStr(), 'a' );
362 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 24);
364 /* sal_Int32 */ nIndex = rtl_str_lastIndexOfChar( aStr1.getStr(), 'r' );
365 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 25);
368 void lastIndexOfChar_002()
370 rtl::OString aStr1 = "Line for a lastIndexOfChar.";
371 sal_Int32 nIndex = rtl_str_lastIndexOfChar( aStr1.getStr(), 'y' );
373 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == -1 );
376 // Change the following lines only, if you add, remove or rename
377 // member functions of the current class,
378 // because these macros are need by auto register mechanism.
380 CPPUNIT_TEST_SUITE(lastIndexOfChar);
381 CPPUNIT_TEST(lastIndexOfChar_000);
382 CPPUNIT_TEST(lastIndexOfChar_001);
383 CPPUNIT_TEST(lastIndexOfChar_002);
384 CPPUNIT_TEST_SUITE_END();
385 }; // class lastIndexOfChar
388 // -----------------------------------------------------------------------------
390 class indexOfStr : public CppUnit::TestFixture
392 public:
394 void indexOfStr_000()
396 rtl_str_indexOfStr( NULL, 0 );
399 void indexOfStr_000_1()
401 rtl::OString aStr1 = "Line for a indexOfStr.";
402 rtl_str_indexOfStr( aStr1.getStr(), 0 );
405 void indexOfStr_001()
407 rtl::OString aStr1 = "Line for a indexOfStr.";
409 sal_Int32 nIndex = rtl_str_indexOfStr( aStr1.getStr(), "Line" );
410 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 0);
412 /* sal_Int32 */ nIndex = rtl_str_indexOfStr( aStr1.getStr(), "for" );
413 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 5);
415 /* sal_Int32 */ nIndex = rtl_str_indexOfStr( aStr1.getStr(), "a" );
416 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 9);
418 /* sal_Int32 */ nIndex = rtl_str_indexOfStr( aStr1.getStr(), "a index" );
419 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex ==9);
422 void indexOfStr_002()
424 rtl::OString aStr1 = "Line for a indexOfStr.";
425 sal_Int32 nIndex = rtl_str_indexOfStr( aStr1.getStr(), "not exist" );
427 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == -1 );
430 // Change the following lines only, if you add, remove or rename
431 // member functions of the current class,
432 // because these macros are need by auto register mechanism.
434 CPPUNIT_TEST_SUITE(indexOfStr);
435 CPPUNIT_TEST(indexOfStr_000);
436 CPPUNIT_TEST(indexOfStr_001);
437 CPPUNIT_TEST(indexOfStr_002);
438 CPPUNIT_TEST_SUITE_END();
439 }; // class compare
440 // -----------------------------------------------------------------------------
443 class lastIndexOfStr : public CppUnit::TestFixture
445 public:
447 void lastIndexOfStr_000()
449 rtl_str_lastIndexOfStr( NULL, NULL );
452 void lastIndexOfStr_000_1()
454 rtl::OString aStr1 = "Line for a lastIndexOfStr.";
455 rtl_str_lastIndexOfStr( aStr1.getStr(), NULL );
458 void lastIndexOfStr_001()
460 rtl::OString aStr1 = "Line for a lastIndexOfStr.";
461 rtl::OString aSearchStr = "Index";
463 sal_Int32 nIndex = rtl_str_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() );
464 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 15);
466 /* rtl::OString */ aSearchStr = "Line";
467 /* sal_Int32 */ nIndex = rtl_str_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() );
468 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 0);
470 /* rtl::OString */ aSearchStr = "";
471 /* sal_Int32 */ nIndex = rtl_str_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() );
472 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == -1);
475 void lastIndexOfStr_002()
477 rtl::OString aStr1 = "Line for a lastIndexOfStr.";
478 rtl::OString aSearchStr = "foo";
479 sal_Int32 nIndex = rtl_str_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() );
481 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == -1 );
484 void lastIndexOfStr_003()
486 rtl::OString aStr1 = "Line for a lastIndexOfStr.";
487 rtl::OString aSearchStr = "O";
488 sal_Int32 nIndex = rtl_str_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() );
490 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 20 );
493 // Change the following lines only, if you add, remove or rename
494 // member functions of the current class,
495 // because these macros are need by auto register mechanism.
497 CPPUNIT_TEST_SUITE(lastIndexOfStr);
498 CPPUNIT_TEST(lastIndexOfStr_000);
499 CPPUNIT_TEST(lastIndexOfStr_001);
500 CPPUNIT_TEST(lastIndexOfStr_002);
501 CPPUNIT_TEST(lastIndexOfStr_003);
502 CPPUNIT_TEST_SUITE_END();
503 }; // class lastIndexOfStr
505 // -----------------------------------------------------------------------------
507 class replaceChar : public CppUnit::TestFixture
509 public:
511 void replaceChar_000()
513 rtl_str_replaceChar( NULL, 0, 0 );
516 void replaceChar_001()
518 rtl::OString aStr1 = "replace char.";
519 rtl::OString aShouldStr1 = "ruplacu char.";
521 sal_Char* pStr = (sal_Char*) malloc(aStr1.getLength() + 1);
522 CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL);
523 strcpy(pStr, aStr1.getStr());
525 rtl_str_replaceChar( pStr, 'e', 'u' );
527 CPPUNIT_ASSERT_MESSAGE("replace failed", aShouldStr1.equals(rtl::OString(pStr)) == sal_True);
528 free(pStr);
531 // Change the following lines only, if you add, remove or rename
532 // member functions of the current class,
533 // because these macros are need by auto register mechanism.
535 CPPUNIT_TEST_SUITE(replaceChar);
536 CPPUNIT_TEST(replaceChar_000);
537 CPPUNIT_TEST(replaceChar_001);
538 CPPUNIT_TEST_SUITE_END();
539 }; // class replaceChar
541 // -----------------------------------------------------------------------------
543 class replaceChar_WithLength : public CppUnit::TestFixture
545 public:
547 void replaceChar_WithLength_000()
549 rtl_str_replaceChar_WithLength( NULL, 0, 0, 0 );
552 void replaceChar_WithLength_000_1()
554 rtl_str_replaceChar_WithLength( NULL, 1, 0, 0 );
556 void replaceChar_WithLength_001()
558 rtl::OString aStr1 = "replace char.";
559 rtl::OString aShouldStr1 = "ruplace char.";
561 sal_Char* pStr = (sal_Char*) malloc(aStr1.getLength() + 1);
562 CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL);
563 strcpy(pStr, aStr1.getStr());
565 rtl_str_replaceChar_WithLength( pStr, 6, 'e', 'u' );
567 CPPUNIT_ASSERT_MESSAGE("replace failed", aShouldStr1.equals(rtl::OString(pStr)) == sal_True);
568 free(pStr);
571 // Change the following lines only, if you add, remove or rename
572 // member functions of the current class,
573 // because these macros are need by auto register mechanism.
575 CPPUNIT_TEST_SUITE(replaceChar_WithLength);
576 CPPUNIT_TEST(replaceChar_WithLength_000);
577 CPPUNIT_TEST(replaceChar_WithLength_000_1);
578 CPPUNIT_TEST(replaceChar_WithLength_001);
579 CPPUNIT_TEST_SUITE_END();
580 }; // class replaceChar
583 // -----------------------------------------------------------------------------
585 class toAsciiLowerCase : public CppUnit::TestFixture
587 public:
589 void toAsciiLowerCase_000()
591 rtl_str_toAsciiLowerCase( NULL );
594 void toAsciiLowerCase_001()
596 rtl::OString aStr1 = "CHANGE THIS TO ASCII LOWER CASE.";
597 rtl::OString aShouldStr1 = "change this to ascii lower case.";
599 sal_Char* pStr = (sal_Char*) malloc(aStr1.getLength() + 1);
600 CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL);
601 strcpy(pStr, aStr1.getStr());
603 rtl_str_toAsciiLowerCase( pStr );
605 CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1.equals(rtl::OString(pStr)) == sal_True);
606 free(pStr);
609 // Change the following lines only, if you add, remove or rename
610 // member functions of the current class,
611 // because these macros are need by auto register mechanism.
613 CPPUNIT_TEST_SUITE(toAsciiLowerCase);
614 CPPUNIT_TEST(toAsciiLowerCase_000);
615 CPPUNIT_TEST(toAsciiLowerCase_001);
616 CPPUNIT_TEST_SUITE_END();
617 }; // class replaceChar
620 class toAsciiLowerCase_WithLength : public CppUnit::TestFixture
622 public:
624 void toAsciiLowerCase_WithLength_000()
626 rtl_str_toAsciiLowerCase_WithLength( NULL, 0 );
629 void toAsciiLowerCase_WithLength_001()
631 rtl::OString aStr1 = "CHANGE THIS TO ASCII LOWER CASE.";
632 rtl::OString aShouldStr1 = "change thiS TO ASCII LOWER CASE.";
634 sal_Char* pStr = (sal_Char*) malloc(aStr1.getLength() + 1);
635 CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL);
636 strcpy(pStr, aStr1.getStr());
638 rtl_str_toAsciiLowerCase_WithLength( pStr, 10 );
640 t_print("Lowercase with length: '%s'\n", pStr);
641 CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1.equals(rtl::OString(pStr)) == sal_True);
642 free(pStr);
645 // Change the following lines only, if you add, remove or rename
646 // member functions of the current class,
647 // because these macros are need by auto register mechanism.
649 CPPUNIT_TEST_SUITE(toAsciiLowerCase_WithLength);
650 CPPUNIT_TEST(toAsciiLowerCase_WithLength_000);
651 CPPUNIT_TEST(toAsciiLowerCase_WithLength_001);
652 CPPUNIT_TEST_SUITE_END();
653 }; // class replaceChar
655 // -----------------------------------------------------------------------------
657 class toAsciiUpperCase : public CppUnit::TestFixture
659 public:
661 void toAsciiUpperCase_000()
663 rtl_str_toAsciiUpperCase( NULL );
666 void toAsciiUpperCase_001()
668 rtl::OString aStr1 = "change this to ascii upper case.";
669 rtl::OString aShouldStr1 = "CHANGE THIS TO ASCII UPPER CASE.";
671 sal_Char* pStr = (sal_Char*) malloc(aStr1.getLength() + 1);
672 CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL);
673 strcpy(pStr, aStr1.getStr());
675 rtl_str_toAsciiUpperCase( pStr );
677 CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1.equals(rtl::OString(pStr)) == sal_True);
678 free(pStr);
681 // Change the following lines only, if you add, remove or rename
682 // member functions of the current class,
683 // because these macros are need by auto register mechanism.
685 CPPUNIT_TEST_SUITE(toAsciiUpperCase);
686 CPPUNIT_TEST(toAsciiUpperCase_000);
687 CPPUNIT_TEST(toAsciiUpperCase_001);
688 CPPUNIT_TEST_SUITE_END();
689 }; // class replaceChar
692 class toAsciiUpperCase_WithLength : public CppUnit::TestFixture
694 public:
696 void toAsciiUpperCase_WithLength_000()
698 rtl_str_toAsciiUpperCase_WithLength( NULL, 0 );
701 void toAsciiUpperCase_WithLength_001()
703 rtl::OString aStr1 = "change this to ascii lower case.";
704 rtl::OString aShouldStr1 = "CHANGE THIs to ascii lower case.";
706 sal_Char* pStr = (sal_Char*) malloc(aStr1.getLength() + 1);
707 CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL);
709 strcpy(pStr, aStr1.getStr());
710 rtl_str_toAsciiUpperCase_WithLength( pStr, 10 );
712 t_print("Uppercase with length: '%s'\n", aStr1.getStr());
713 CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1.equals(rtl::OString(pStr)) == sal_True);
714 free(pStr);
717 // Change the following lines only, if you add, remove or rename
718 // member functions of the current class,
719 // because these macros are need by auto register mechanism.
721 CPPUNIT_TEST_SUITE(toAsciiUpperCase_WithLength);
722 CPPUNIT_TEST(toAsciiUpperCase_WithLength_000);
723 CPPUNIT_TEST(toAsciiUpperCase_WithLength_001);
724 CPPUNIT_TEST_SUITE_END();
725 }; // class replaceChar
728 // -----------------------------------------------------------------------------
730 class trim_WithLength : public CppUnit::TestFixture
732 public:
733 void trim_WithLength_000()
735 rtl_str_trim_WithLength(NULL, 0);
736 // should not GPF
739 void trim_WithLength_000_1()
741 char pStr[] = { " trim this" };
742 rtl_str_trim_WithLength( pStr, 0 );
745 void trim_WithLength_001()
747 char const *pStr = " trim this";
748 sal_Char *pStr2 = (sal_Char*)malloc(strlen(pStr) + 1);
749 if (pStr2)
751 strcpy(pStr2, pStr);
752 rtl_str_trim_WithLength( pStr2, 2 );
754 CPPUNIT_ASSERT_MESSAGE("string should be empty", strlen(pStr2) == 0);
755 free(pStr2);
759 void trim_WithLength_002()
761 char const *pStr = "trim this";
762 sal_Char *pStr2 = (sal_Char*)malloc(strlen(pStr) + 1);
763 if (pStr2)
765 strcpy(pStr2, pStr);
766 rtl_str_trim_WithLength( pStr2, 5 );
768 CPPUNIT_ASSERT_MESSAGE("string should contain 'trim'", strlen(pStr2) == 4);
769 free(pStr2);
773 void trim_WithLength_003()
775 char const *pStr = " trim this";
776 sal_Char *pStr2 = (sal_Char*)malloc(strlen(pStr) + 1);
777 if (pStr2)
779 strcpy(pStr2, pStr);
780 rtl_str_trim_WithLength( pStr2, 11 );
782 CPPUNIT_ASSERT_MESSAGE("string should contain 'trim'", strlen(pStr2) == 4);
783 free(pStr2);
787 void trim_WithLength_004()
789 char const *pStr = "\r\n\t \n\r trim \n this";
790 sal_Char *pStr2 = (sal_Char*)malloc(strlen(pStr) + 1);
791 if (pStr2)
793 strcpy(pStr2, pStr);
794 rtl_str_trim_WithLength( pStr2, 17 );
796 CPPUNIT_ASSERT_MESSAGE("string should contain 'trim'", strlen(pStr2) == 4);
797 free(pStr2);
801 void trim_WithLength_005()
803 char const *pStr = "\r\n\t \n\r trim \t this \n\r\t\t ";
804 sal_Char *pStr2 = (sal_Char*)malloc(strlen(pStr) + 1);
805 if (pStr2)
807 strcpy(pStr2, pStr);
808 rtl_str_trim_WithLength( pStr2, strlen(pStr2) );
810 CPPUNIT_ASSERT_MESSAGE("string should contain 'trim'", strlen(pStr2) == 11);
811 free(pStr2);
815 // Change the following lines only, if you add, remove or rename
816 // member functions of the current class,
817 // because these macros are need by auto register mechanism.
819 CPPUNIT_TEST_SUITE(trim_WithLength);
820 CPPUNIT_TEST(trim_WithLength_000);
821 CPPUNIT_TEST(trim_WithLength_000_1);
822 CPPUNIT_TEST(trim_WithLength_001);
823 CPPUNIT_TEST(trim_WithLength_002);
824 CPPUNIT_TEST(trim_WithLength_003);
825 CPPUNIT_TEST(trim_WithLength_004);
826 CPPUNIT_TEST(trim_WithLength_005);
827 CPPUNIT_TEST_SUITE_END();
830 // -----------------------------------------------------------------------------
832 class valueOfChar : public CppUnit::TestFixture
834 public:
835 void valueOfChar_000()
837 rtl_str_valueOfChar(NULL, 0);
838 // should not GPF
840 void valueOfChar_001()
842 sal_Char *pStr = (sal_Char*)malloc(RTL_STR_MAX_VALUEOFCHAR);
843 if (pStr)
845 rtl_str_valueOfChar(pStr, 'A');
847 CPPUNIT_ASSERT_MESSAGE("string should contain 'A'", pStr[0] == 'A');
848 free(pStr);
852 // Change the following lines only, if you add, remove or rename
853 // member functions of the current class,
854 // because these macros are need by auto register mechanism.
856 CPPUNIT_TEST_SUITE(valueOfChar);
857 CPPUNIT_TEST(valueOfChar_000);
858 CPPUNIT_TEST(valueOfChar_001);
859 CPPUNIT_TEST_SUITE_END();
862 // -----------------------------------------------------------------------------
863 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::compare, "rtl_str");
864 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::compareIgnoreAsciiCase, "rtl_str");
865 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::shortenedCompareIgnoreAsciiCase_WithLength, "rtl_str");
866 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::hashCode, "rtl_str");
868 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::indexOfChar, "rtl_str");
869 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::lastIndexOfChar, "rtl_str");
870 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::indexOfStr, "rtl_str");
871 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::lastIndexOfStr, "rtl_str");
873 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::replaceChar, "rtl_str");
874 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::replaceChar_WithLength, "rtl_str");
876 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::toAsciiLowerCase, "rtl_str");
877 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::toAsciiLowerCase_WithLength, "rtl_str");
878 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::toAsciiUpperCase, "rtl_str");
879 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::toAsciiUpperCase_WithLength, "rtl_str");
881 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::trim_WithLength, "rtl_str");
882 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::valueOfChar, "rtl_str");
884 } // namespace rtl_str
886 // -----------------------------------------------------------------------------
888 // this macro creates an empty function, which will called by the RegisterAllFunctions()
889 // to let the user the possibility to also register some functions by hand.
890 NOADDITIONAL;