update dev300-m57
[ooovba.git] / sal / qa / rtl / ostring / rtl_str.cxx
blobed1cff89f5021c4e74b1e3fafa718f9834b62b21
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: rtl_str.cxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_sal.hxx"
34 #include <cppunit/simpleheader.hxx>
36 namespace rtl_str
39 class compare : public CppUnit::TestFixture
41 public:
43 void compare_000()
45 rtl_str_compare( NULL, NULL);
48 void compare_000_1()
50 rtl::OString aStr1 = "Line must be equal.";
51 rtl_str_compare( aStr1.getStr(), NULL);
53 void compare_001()
55 rtl::OString aStr1 = "";
56 rtl::OString aStr2 = "";
58 sal_Int32 nValue = rtl_str_compare( aStr1.getStr(), aStr2.getStr());
59 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
62 void compare_002()
64 rtl::OString aStr1 = "Line must be equal.";
65 rtl::OString aStr2 = "Line must be equal.";
67 sal_Int32 nValue = rtl_str_compare( aStr1.getStr(), aStr2.getStr());
68 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
71 void compare_003()
73 rtl::OString aStr1 = "Line must differ.";
74 rtl::OString aStr2 = "Line foo bar, ok, differ.";
76 sal_Int32 nValue = rtl_str_compare( aStr1.getStr(), aStr2.getStr());
77 CPPUNIT_ASSERT_MESSAGE("compare failed, strings differ.", nValue != 0);
80 // Change the following lines only, if you add, remove or rename
81 // member functions of the current class,
82 // because these macros are need by auto register mechanism.
84 CPPUNIT_TEST_SUITE(compare);
85 CPPUNIT_TEST(compare_000);
86 CPPUNIT_TEST(compare_000_1);
87 CPPUNIT_TEST(compare_001);
88 CPPUNIT_TEST(compare_002);
89 CPPUNIT_TEST(compare_003);
90 CPPUNIT_TEST_SUITE_END();
91 }; // class compare
94 class compareIgnoreAsciiCase : public CppUnit::TestFixture
96 public:
98 void compare_000()
100 rtl_str_compareIgnoreAsciiCase( NULL, NULL);
103 void compare_000_1()
105 rtl::OString aStr1 = "Line must be equal.";
106 rtl_str_compareIgnoreAsciiCase( aStr1.getStr(), NULL);
108 void compare_001()
110 rtl::OString aStr1 = "";
111 rtl::OString aStr2 = "";
113 sal_Int32 nValue = rtl_str_compareIgnoreAsciiCase( aStr1.getStr(), aStr2.getStr());
114 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
117 void compare_002()
119 rtl::OString aStr1 = "Line must be equal.";
120 rtl::OString aStr2 = "Line must be equal.";
122 sal_Int32 nValue = rtl_str_compareIgnoreAsciiCase( aStr1.getStr(), aStr2.getStr());
123 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
126 void compare_002_1()
128 rtl::OString aStr1 = "Line must be equal.";
129 rtl::OString aStr2 = "LINE MUST BE EQUAL.";
131 sal_Int32 nValue = rtl_str_compareIgnoreAsciiCase( aStr1.getStr(), aStr2.getStr());
132 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal (if case insensitve).", nValue == 0);
135 void compare_003()
137 rtl::OString aStr1 = "Line must differ.";
138 rtl::OString aStr2 = "Line foo bar, ok, differ.";
140 sal_Int32 nValue = rtl_str_compareIgnoreAsciiCase( aStr1.getStr(), aStr2.getStr());
141 CPPUNIT_ASSERT_MESSAGE("compare failed, strings differ.", nValue != 0);
144 // Change the following lines only, if you add, remove or rename
145 // member functions of the current class,
146 // because these macros are need by auto register mechanism.
148 CPPUNIT_TEST_SUITE(compareIgnoreAsciiCase);
149 CPPUNIT_TEST(compare_000);
150 CPPUNIT_TEST(compare_000_1);
151 CPPUNIT_TEST(compare_001);
152 CPPUNIT_TEST(compare_002);
153 CPPUNIT_TEST(compare_002_1);
154 CPPUNIT_TEST(compare_003);
155 CPPUNIT_TEST_SUITE_END();
156 }; // class compareIgnoreAsciiCase
158 // -----------------------------------------------------------------------------
160 class shortenedCompareIgnoreAsciiCase_WithLength : public CppUnit::TestFixture
162 public:
164 void compare_000()
166 rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( NULL, 0, NULL, 0, 0);
169 void compare_000_1()
171 rtl::OString aStr1 = "Line must be equal.";
172 rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(), NULL, 0, 1);
174 void compare_001()
176 rtl::OString aStr1 = "";
177 rtl::OString aStr2 = "";
179 sal_Int32 nValue = rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(), aStr2.getStr(), aStr2.getLength(), aStr1.getLength());
180 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
183 void compare_002()
185 rtl::OString aStr1 = "Line must be equal.";
186 rtl::OString aStr2 = "Line must be equal.";
188 sal_Int32 nValue = rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(),
189 aStr2.getStr(), aStr2.getLength(),
190 aStr1.getLength());
191 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
194 void compare_002_1()
196 rtl::OString aStr1 = "Line must be equal.";
197 rtl::OString aStr2 = "LINE MUST BE EQUAL.";
199 sal_Int32 nValue = rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(),
200 aStr2.getStr(), aStr2.getLength(),
201 aStr1.getLength());
202 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal (if case insensitve).", nValue == 0);
205 void compare_003()
207 rtl::OString aStr1 = "Line must differ.";
208 rtl::OString aStr2 = "Line foo bar, ok, differ.";
210 sal_Int32 nValue = rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(),
211 aStr2.getStr(), aStr2.getLength(),
213 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal first 5 characters.", nValue == 0);
216 void compare_004()
218 rtl::OString aStr1 = "Line must differ.";
219 rtl::OString aStr2 = "Line foo bar, ok, differ.";
221 sal_Int32 nValue = rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(),
222 aStr2.getStr(), aStr2.getLength(),
223 aStr1.getLength());
224 CPPUNIT_ASSERT_MESSAGE("compare failed, strings differ.", nValue != 0);
227 // Change the following lines only, if you add, remove or rename
228 // member functions of the current class,
229 // because these macros are need by auto register mechanism.
231 CPPUNIT_TEST_SUITE(shortenedCompareIgnoreAsciiCase_WithLength);
232 CPPUNIT_TEST(compare_000);
233 CPPUNIT_TEST(compare_000_1);
234 CPPUNIT_TEST(compare_001);
235 CPPUNIT_TEST(compare_002);
236 CPPUNIT_TEST(compare_002_1);
237 CPPUNIT_TEST(compare_003);
238 CPPUNIT_TEST(compare_004);
239 CPPUNIT_TEST_SUITE_END();
240 }; // class compare
243 // -----------------------------------------------------------------------------
245 class hashCode : public CppUnit::TestFixture
247 public:
249 void hashCode_000()
251 rtl_str_hashCode( NULL );
254 void hashCode_001()
256 rtl::OString aStr1 = "Line for a hashCode.";
257 sal_Int32 nHashCode = rtl_str_hashCode( aStr1.getStr() );
258 t_print("hashcode: %d\n", nHashCode);
259 // CPPUNIT_ASSERT_MESSAGE("failed.", nValue == 0);
262 void hashCode_002()
264 rtl::OString aStr1 = "Line for a hashCode.";
265 sal_Int32 nHashCode1 = rtl_str_hashCode( aStr1.getStr() );
267 rtl::OString aStr2 = "Line for a hashCode.";
268 sal_Int32 nHashCode2 = rtl_str_hashCode( aStr2.getStr() );
270 CPPUNIT_ASSERT_MESSAGE("hashcodes must be equal.", nHashCode1 == nHashCode2 );
273 void hashCode_003()
275 rtl::OString aStr1 = "Line for a hashCode.";
276 sal_Int32 nHashCode1 = rtl_str_hashCode( aStr1.getStr() );
278 rtl::OString aStr2 = "Line for an other hashcode.";
279 sal_Int32 nHashCode2 = rtl_str_hashCode( aStr2.getStr() );
281 CPPUNIT_ASSERT_MESSAGE("hashcodes must differ.", nHashCode1 != nHashCode2 );
284 // Change the following lines only, if you add, remove or rename
285 // member functions of the current class,
286 // because these macros are need by auto register mechanism.
288 CPPUNIT_TEST_SUITE(hashCode);
289 CPPUNIT_TEST(hashCode_000);
290 CPPUNIT_TEST(hashCode_001);
291 CPPUNIT_TEST(hashCode_002);
292 CPPUNIT_TEST(hashCode_003);
293 CPPUNIT_TEST_SUITE_END();
294 }; // class compare
297 // -----------------------------------------------------------------------------
299 class indexOfChar : public CppUnit::TestFixture
301 public:
303 void indexOfChar_000()
305 rtl_str_indexOfChar( NULL, 0 );
308 void indexOfChar_001()
310 rtl::OString aStr1 = "Line for a indexOfChar.";
312 sal_Int32 nIndex = rtl_str_indexOfChar( aStr1.getStr(), 'L' );
313 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 0);
315 /* sal_Int32 */ nIndex = rtl_str_indexOfChar( aStr1.getStr(), 'i' );
316 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 1);
318 /* sal_Int32 */ nIndex = rtl_str_indexOfChar( aStr1.getStr(), 'n' );
319 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 2);
321 /* sal_Int32 */ nIndex = rtl_str_indexOfChar( aStr1.getStr(), 'e' );
322 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 3);
325 void indexOfChar_002()
327 rtl::OString aStr1 = "Line for a indexOfChar.";
328 sal_Int32 nIndex = rtl_str_indexOfChar( aStr1.getStr(), 'y' );
330 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == -1 );
333 // Change the following lines only, if you add, remove or rename
334 // member functions of the current class,
335 // because these macros are need by auto register mechanism.
337 CPPUNIT_TEST_SUITE(indexOfChar);
338 CPPUNIT_TEST(indexOfChar_000);
339 CPPUNIT_TEST(indexOfChar_001);
340 CPPUNIT_TEST(indexOfChar_002);
341 CPPUNIT_TEST_SUITE_END();
342 }; // class compare
344 // -----------------------------------------------------------------------------
345 class lastIndexOfChar : public CppUnit::TestFixture
347 public:
349 void lastIndexOfChar_000()
351 rtl_str_lastIndexOfChar( NULL, 0 );
354 void lastIndexOfChar_001()
356 rtl::OString aStr1 = "Line for a lastIndexOfChar.";
358 sal_Int32 nIndex = rtl_str_lastIndexOfChar( aStr1.getStr(), 'C' );
359 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 22);
361 /* sal_Int32 */ nIndex = rtl_str_lastIndexOfChar( aStr1.getStr(), 'h' );
362 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 23);
364 /* sal_Int32 */ nIndex = rtl_str_lastIndexOfChar( aStr1.getStr(), 'a' );
365 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 24);
367 /* sal_Int32 */ nIndex = rtl_str_lastIndexOfChar( aStr1.getStr(), 'r' );
368 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 25);
371 void lastIndexOfChar_002()
373 rtl::OString aStr1 = "Line for a lastIndexOfChar.";
374 sal_Int32 nIndex = rtl_str_lastIndexOfChar( aStr1.getStr(), 'y' );
376 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == -1 );
379 // Change the following lines only, if you add, remove or rename
380 // member functions of the current class,
381 // because these macros are need by auto register mechanism.
383 CPPUNIT_TEST_SUITE(lastIndexOfChar);
384 CPPUNIT_TEST(lastIndexOfChar_000);
385 CPPUNIT_TEST(lastIndexOfChar_001);
386 CPPUNIT_TEST(lastIndexOfChar_002);
387 CPPUNIT_TEST_SUITE_END();
388 }; // class lastIndexOfChar
391 // -----------------------------------------------------------------------------
393 class indexOfStr : public CppUnit::TestFixture
395 public:
397 void indexOfStr_000()
399 rtl_str_indexOfStr( NULL, 0 );
402 void indexOfStr_000_1()
404 rtl::OString aStr1 = "Line for a indexOfStr.";
405 rtl_str_indexOfStr( aStr1.getStr(), 0 );
408 void indexOfStr_001()
410 rtl::OString aStr1 = "Line for a indexOfStr.";
412 sal_Int32 nIndex = rtl_str_indexOfStr( aStr1.getStr(), "Line" );
413 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 0);
415 /* sal_Int32 */ nIndex = rtl_str_indexOfStr( aStr1.getStr(), "for" );
416 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 5);
418 /* sal_Int32 */ nIndex = rtl_str_indexOfStr( aStr1.getStr(), "a" );
419 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 9);
421 /* sal_Int32 */ nIndex = rtl_str_indexOfStr( aStr1.getStr(), "a index" );
422 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex ==9);
425 void indexOfStr_002()
427 rtl::OString aStr1 = "Line for a indexOfStr.";
428 sal_Int32 nIndex = rtl_str_indexOfStr( aStr1.getStr(), "not exist" );
430 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == -1 );
433 // Change the following lines only, if you add, remove or rename
434 // member functions of the current class,
435 // because these macros are need by auto register mechanism.
437 CPPUNIT_TEST_SUITE(indexOfStr);
438 CPPUNIT_TEST(indexOfStr_000);
439 CPPUNIT_TEST(indexOfStr_001);
440 CPPUNIT_TEST(indexOfStr_002);
441 CPPUNIT_TEST_SUITE_END();
442 }; // class compare
443 // -----------------------------------------------------------------------------
446 class lastIndexOfStr : public CppUnit::TestFixture
448 public:
450 void lastIndexOfStr_000()
452 rtl_str_lastIndexOfStr( NULL, NULL );
455 void lastIndexOfStr_000_1()
457 rtl::OString aStr1 = "Line for a lastIndexOfStr.";
458 rtl_str_lastIndexOfStr( aStr1.getStr(), NULL );
461 void lastIndexOfStr_001()
463 rtl::OString aStr1 = "Line for a lastIndexOfStr.";
464 rtl::OString aSearchStr = "Index";
466 sal_Int32 nIndex = rtl_str_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() );
467 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 15);
469 /* rtl::OString */ aSearchStr = "Line";
470 /* sal_Int32 */ nIndex = rtl_str_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() );
471 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 0);
473 /* rtl::OString */ aSearchStr = "";
474 /* sal_Int32 */ nIndex = rtl_str_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() );
475 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == -1);
478 void lastIndexOfStr_002()
480 rtl::OString aStr1 = "Line for a lastIndexOfStr.";
481 rtl::OString aSearchStr = "foo";
482 sal_Int32 nIndex = rtl_str_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() );
484 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == -1 );
487 void lastIndexOfStr_003()
489 rtl::OString aStr1 = "Line for a lastIndexOfStr.";
490 rtl::OString aSearchStr = "O";
491 sal_Int32 nIndex = rtl_str_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() );
493 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 20 );
496 // Change the following lines only, if you add, remove or rename
497 // member functions of the current class,
498 // because these macros are need by auto register mechanism.
500 CPPUNIT_TEST_SUITE(lastIndexOfStr);
501 CPPUNIT_TEST(lastIndexOfStr_000);
502 CPPUNIT_TEST(lastIndexOfStr_001);
503 CPPUNIT_TEST(lastIndexOfStr_002);
504 CPPUNIT_TEST(lastIndexOfStr_003);
505 CPPUNIT_TEST_SUITE_END();
506 }; // class lastIndexOfStr
508 // -----------------------------------------------------------------------------
510 class replaceChar : public CppUnit::TestFixture
512 public:
514 void replaceChar_000()
516 rtl_str_replaceChar( NULL, 0, 0 );
519 void replaceChar_001()
521 rtl::OString aStr1 = "replace char.";
522 rtl::OString aShouldStr1 = "ruplacu char.";
524 sal_Char* pStr = (sal_Char*) malloc(aStr1.getLength() + 1);
525 CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL);
526 strcpy(pStr, aStr1.getStr());
528 rtl_str_replaceChar( pStr, 'e', 'u' );
530 CPPUNIT_ASSERT_MESSAGE("replace failed", aShouldStr1.equals(rtl::OString(pStr)) == sal_True);
531 free(pStr);
534 // Change the following lines only, if you add, remove or rename
535 // member functions of the current class,
536 // because these macros are need by auto register mechanism.
538 CPPUNIT_TEST_SUITE(replaceChar);
539 CPPUNIT_TEST(replaceChar_000);
540 CPPUNIT_TEST(replaceChar_001);
541 CPPUNIT_TEST_SUITE_END();
542 }; // class replaceChar
544 // -----------------------------------------------------------------------------
546 class replaceChar_WithLength : public CppUnit::TestFixture
548 public:
550 void replaceChar_WithLength_000()
552 rtl_str_replaceChar_WithLength( NULL, 0, 0, 0 );
555 void replaceChar_WithLength_000_1()
557 rtl_str_replaceChar_WithLength( NULL, 1, 0, 0 );
559 void replaceChar_WithLength_001()
561 rtl::OString aStr1 = "replace char.";
562 rtl::OString aShouldStr1 = "ruplace char.";
564 sal_Char* pStr = (sal_Char*) malloc(aStr1.getLength() + 1);
565 CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL);
566 strcpy(pStr, aStr1.getStr());
568 rtl_str_replaceChar_WithLength( pStr, 6, 'e', 'u' );
570 CPPUNIT_ASSERT_MESSAGE("replace failed", aShouldStr1.equals(rtl::OString(pStr)) == sal_True);
571 free(pStr);
574 // Change the following lines only, if you add, remove or rename
575 // member functions of the current class,
576 // because these macros are need by auto register mechanism.
578 CPPUNIT_TEST_SUITE(replaceChar_WithLength);
579 CPPUNIT_TEST(replaceChar_WithLength_000);
580 CPPUNIT_TEST(replaceChar_WithLength_000_1);
581 CPPUNIT_TEST(replaceChar_WithLength_001);
582 CPPUNIT_TEST_SUITE_END();
583 }; // class replaceChar
586 // -----------------------------------------------------------------------------
588 class toAsciiLowerCase : public CppUnit::TestFixture
590 public:
592 void toAsciiLowerCase_000()
594 rtl_str_toAsciiLowerCase( NULL );
597 void toAsciiLowerCase_001()
599 rtl::OString aStr1 = "CHANGE THIS TO ASCII LOWER CASE.";
600 rtl::OString aShouldStr1 = "change this to ascii lower case.";
602 sal_Char* pStr = (sal_Char*) malloc(aStr1.getLength() + 1);
603 CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL);
604 strcpy(pStr, aStr1.getStr());
606 rtl_str_toAsciiLowerCase( pStr );
608 CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1.equals(rtl::OString(pStr)) == sal_True);
609 free(pStr);
612 // Change the following lines only, if you add, remove or rename
613 // member functions of the current class,
614 // because these macros are need by auto register mechanism.
616 CPPUNIT_TEST_SUITE(toAsciiLowerCase);
617 CPPUNIT_TEST(toAsciiLowerCase_000);
618 CPPUNIT_TEST(toAsciiLowerCase_001);
619 CPPUNIT_TEST_SUITE_END();
620 }; // class replaceChar
623 class toAsciiLowerCase_WithLength : public CppUnit::TestFixture
625 public:
627 void toAsciiLowerCase_WithLength_000()
629 rtl_str_toAsciiLowerCase_WithLength( NULL, 0 );
632 void toAsciiLowerCase_WithLength_001()
634 rtl::OString aStr1 = "CHANGE THIS TO ASCII LOWER CASE.";
635 rtl::OString aShouldStr1 = "change thiS TO ASCII LOWER CASE.";
637 sal_Char* pStr = (sal_Char*) malloc(aStr1.getLength() + 1);
638 CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL);
639 strcpy(pStr, aStr1.getStr());
641 rtl_str_toAsciiLowerCase_WithLength( pStr, 10 );
643 t_print("Lowercase with length: '%s'\n", pStr);
644 CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1.equals(rtl::OString(pStr)) == sal_True);
645 free(pStr);
648 // Change the following lines only, if you add, remove or rename
649 // member functions of the current class,
650 // because these macros are need by auto register mechanism.
652 CPPUNIT_TEST_SUITE(toAsciiLowerCase_WithLength);
653 CPPUNIT_TEST(toAsciiLowerCase_WithLength_000);
654 CPPUNIT_TEST(toAsciiLowerCase_WithLength_001);
655 CPPUNIT_TEST_SUITE_END();
656 }; // class replaceChar
658 // -----------------------------------------------------------------------------
660 class toAsciiUpperCase : public CppUnit::TestFixture
662 public:
664 void toAsciiUpperCase_000()
666 rtl_str_toAsciiUpperCase( NULL );
669 void toAsciiUpperCase_001()
671 rtl::OString aStr1 = "change this to ascii upper case.";
672 rtl::OString aShouldStr1 = "CHANGE THIS TO ASCII UPPER CASE.";
674 sal_Char* pStr = (sal_Char*) malloc(aStr1.getLength() + 1);
675 CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL);
676 strcpy(pStr, aStr1.getStr());
678 rtl_str_toAsciiUpperCase( pStr );
680 CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1.equals(rtl::OString(pStr)) == sal_True);
681 free(pStr);
684 // Change the following lines only, if you add, remove or rename
685 // member functions of the current class,
686 // because these macros are need by auto register mechanism.
688 CPPUNIT_TEST_SUITE(toAsciiUpperCase);
689 CPPUNIT_TEST(toAsciiUpperCase_000);
690 CPPUNIT_TEST(toAsciiUpperCase_001);
691 CPPUNIT_TEST_SUITE_END();
692 }; // class replaceChar
695 class toAsciiUpperCase_WithLength : public CppUnit::TestFixture
697 public:
699 void toAsciiUpperCase_WithLength_000()
701 rtl_str_toAsciiUpperCase_WithLength( NULL, 0 );
704 void toAsciiUpperCase_WithLength_001()
706 rtl::OString aStr1 = "change this to ascii lower case.";
707 rtl::OString aShouldStr1 = "CHANGE THIs to ascii lower case.";
709 sal_Char* pStr = (sal_Char*) malloc(aStr1.getLength() + 1);
710 CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL);
712 strcpy(pStr, aStr1.getStr());
713 rtl_str_toAsciiUpperCase_WithLength( pStr, 10 );
715 t_print("Uppercase with length: '%s'\n", aStr1.getStr());
716 CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1.equals(rtl::OString(pStr)) == sal_True);
717 free(pStr);
720 // Change the following lines only, if you add, remove or rename
721 // member functions of the current class,
722 // because these macros are need by auto register mechanism.
724 CPPUNIT_TEST_SUITE(toAsciiUpperCase_WithLength);
725 CPPUNIT_TEST(toAsciiUpperCase_WithLength_000);
726 CPPUNIT_TEST(toAsciiUpperCase_WithLength_001);
727 CPPUNIT_TEST_SUITE_END();
728 }; // class replaceChar
731 // -----------------------------------------------------------------------------
733 class trim_WithLength : public CppUnit::TestFixture
735 public:
736 void trim_WithLength_000()
738 rtl_str_trim_WithLength(NULL, 0);
739 // should not GPF
742 void trim_WithLength_000_1()
744 char pStr[] = { " trim this" };
745 rtl_str_trim_WithLength( pStr, 0 );
748 void trim_WithLength_001()
750 char const *pStr = " trim this";
751 sal_Char *pStr2 = (sal_Char*)malloc(strlen(pStr) + 1);
752 if (pStr2)
754 strcpy(pStr2, pStr);
755 rtl_str_trim_WithLength( pStr2, 2 );
757 CPPUNIT_ASSERT_MESSAGE("string should be empty", strlen(pStr2) == 0);
758 free(pStr2);
762 void trim_WithLength_002()
764 char const *pStr = "trim this";
765 sal_Char *pStr2 = (sal_Char*)malloc(strlen(pStr) + 1);
766 if (pStr2)
768 strcpy(pStr2, pStr);
769 rtl_str_trim_WithLength( pStr2, 5 );
771 CPPUNIT_ASSERT_MESSAGE("string should contain 'trim'", strlen(pStr2) == 4);
772 free(pStr2);
776 void trim_WithLength_003()
778 char const *pStr = " trim this";
779 sal_Char *pStr2 = (sal_Char*)malloc(strlen(pStr) + 1);
780 if (pStr2)
782 strcpy(pStr2, pStr);
783 rtl_str_trim_WithLength( pStr2, 11 );
785 CPPUNIT_ASSERT_MESSAGE("string should contain 'trim'", strlen(pStr2) == 4);
786 free(pStr2);
790 void trim_WithLength_004()
792 char const *pStr = "\r\n\t \n\r trim \n this";
793 sal_Char *pStr2 = (sal_Char*)malloc(strlen(pStr) + 1);
794 if (pStr2)
796 strcpy(pStr2, pStr);
797 rtl_str_trim_WithLength( pStr2, 17 );
799 CPPUNIT_ASSERT_MESSAGE("string should contain 'trim'", strlen(pStr2) == 4);
800 free(pStr2);
804 void trim_WithLength_005()
806 char const *pStr = "\r\n\t \n\r trim \t this \n\r\t\t ";
807 sal_Char *pStr2 = (sal_Char*)malloc(strlen(pStr) + 1);
808 if (pStr2)
810 strcpy(pStr2, pStr);
811 rtl_str_trim_WithLength( pStr2, strlen(pStr2) );
813 CPPUNIT_ASSERT_MESSAGE("string should contain 'trim'", strlen(pStr2) == 11);
814 free(pStr2);
818 // Change the following lines only, if you add, remove or rename
819 // member functions of the current class,
820 // because these macros are need by auto register mechanism.
822 CPPUNIT_TEST_SUITE(trim_WithLength);
823 CPPUNIT_TEST(trim_WithLength_000);
824 CPPUNIT_TEST(trim_WithLength_000_1);
825 CPPUNIT_TEST(trim_WithLength_001);
826 CPPUNIT_TEST(trim_WithLength_002);
827 CPPUNIT_TEST(trim_WithLength_003);
828 CPPUNIT_TEST(trim_WithLength_004);
829 CPPUNIT_TEST(trim_WithLength_005);
830 CPPUNIT_TEST_SUITE_END();
833 // -----------------------------------------------------------------------------
835 class valueOfChar : public CppUnit::TestFixture
837 public:
838 void valueOfChar_000()
840 rtl_str_valueOfChar(NULL, 0);
841 // should not GPF
843 void valueOfChar_001()
845 sal_Char *pStr = (sal_Char*)malloc(RTL_STR_MAX_VALUEOFCHAR);
846 if (pStr)
848 rtl_str_valueOfChar(pStr, 'A');
850 CPPUNIT_ASSERT_MESSAGE("string should contain 'A'", pStr[0] == 'A');
851 free(pStr);
855 // Change the following lines only, if you add, remove or rename
856 // member functions of the current class,
857 // because these macros are need by auto register mechanism.
859 CPPUNIT_TEST_SUITE(valueOfChar);
860 CPPUNIT_TEST(valueOfChar_000);
861 CPPUNIT_TEST(valueOfChar_001);
862 CPPUNIT_TEST_SUITE_END();
865 // -----------------------------------------------------------------------------
866 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::compare, "rtl_str");
867 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::compareIgnoreAsciiCase, "rtl_str");
868 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::shortenedCompareIgnoreAsciiCase_WithLength, "rtl_str");
869 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::hashCode, "rtl_str");
871 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::indexOfChar, "rtl_str");
872 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::lastIndexOfChar, "rtl_str");
873 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::indexOfStr, "rtl_str");
874 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::lastIndexOfStr, "rtl_str");
876 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::replaceChar, "rtl_str");
877 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::replaceChar_WithLength, "rtl_str");
879 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::toAsciiLowerCase, "rtl_str");
880 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::toAsciiLowerCase_WithLength, "rtl_str");
881 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::toAsciiUpperCase, "rtl_str");
882 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::toAsciiUpperCase_WithLength, "rtl_str");
884 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::trim_WithLength, "rtl_str");
885 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::valueOfChar, "rtl_str");
887 } // namespace rtl_str
889 // -----------------------------------------------------------------------------
891 // this macro creates an empty function, which will called by the RegisterAllFunctions()
892 // to let the user the possibility to also register some functions by hand.
893 NOADDITIONAL;