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 .
20 #include <sal/types.h>
21 #include <cppunit/TestFixture.h>
22 #include <cppunit/extensions/HelperMacros.h>
23 #include <cppunit/plugin/TestPlugIn.h>
25 #include <rtl/string.hxx>
31 class compare
: public CppUnit::TestFixture
37 rtl_str_compare( NULL
, NULL
);
42 OString aStr1
= "Line must be equal.";
43 rtl_str_compare( aStr1
.getStr(), NULL
);
50 sal_Int32 nValue
= rtl_str_compare( aStr1
.getStr(), aStr2
.getStr());
51 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue
== 0);
56 OString aStr1
= "Line must be equal.";
57 OString aStr2
= "Line must be equal.";
59 sal_Int32 nValue
= rtl_str_compare( aStr1
.getStr(), aStr2
.getStr());
60 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue
== 0);
65 OString aStr1
= "Line must differ.";
66 OString aStr2
= "Line foo bar, ok, differ.";
68 sal_Int32 nValue
= rtl_str_compare( aStr1
.getStr(), aStr2
.getStr());
69 CPPUNIT_ASSERT_MESSAGE("compare failed, strings differ.", nValue
!= 0);
72 // Change the following lines only, if you add, remove or rename
73 // member functions of the current class,
74 // because these macros are need by auto register mechanism.
76 CPPUNIT_TEST_SUITE(compare
);
77 CPPUNIT_TEST(compare_000
);
78 CPPUNIT_TEST(compare_000_1
);
79 CPPUNIT_TEST(compare_001
);
80 CPPUNIT_TEST(compare_002
);
81 CPPUNIT_TEST(compare_003
);
82 CPPUNIT_TEST_SUITE_END();
85 class compareIgnoreAsciiCase
: public CppUnit::TestFixture
91 rtl_str_compareIgnoreAsciiCase( NULL
, NULL
);
96 OString aStr1
= "Line must be equal.";
97 rtl_str_compareIgnoreAsciiCase( aStr1
.getStr(), NULL
);
104 sal_Int32 nValue
= rtl_str_compareIgnoreAsciiCase( aStr1
.getStr(), aStr2
.getStr());
105 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue
== 0);
110 OString aStr1
= "Line must be equal.";
111 OString aStr2
= "Line must be equal.";
113 sal_Int32 nValue
= rtl_str_compareIgnoreAsciiCase( aStr1
.getStr(), aStr2
.getStr());
114 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue
== 0);
119 OString aStr1
= "Line must be equal.";
120 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 (if case insensitive).", nValue
== 0);
128 OString aStr1
= "Line must differ.";
129 OString aStr2
= "Line foo bar, ok, differ.";
131 sal_Int32 nValue
= rtl_str_compareIgnoreAsciiCase( aStr1
.getStr(), aStr2
.getStr());
132 CPPUNIT_ASSERT_MESSAGE("compare failed, strings differ.", nValue
!= 0);
135 // Change the following lines only, if you add, remove or rename
136 // member functions of the current class,
137 // because these macros are need by auto register mechanism.
139 CPPUNIT_TEST_SUITE(compareIgnoreAsciiCase
);
140 CPPUNIT_TEST(compare_000
);
141 CPPUNIT_TEST(compare_000_1
);
142 CPPUNIT_TEST(compare_001
);
143 CPPUNIT_TEST(compare_002
);
144 CPPUNIT_TEST(compare_002_1
);
145 CPPUNIT_TEST(compare_003
);
146 CPPUNIT_TEST_SUITE_END();
147 }; // class compareIgnoreAsciiCase
149 class shortenedCompareIgnoreAsciiCase_WithLength
: public CppUnit::TestFixture
155 rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( NULL
, 0, NULL
, 0, 0);
160 OString aStr1
= "Line must be equal.";
161 rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( aStr1
.getStr(), aStr1
.getLength(), NULL
, 0, 1);
168 sal_Int32 nValue
= rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( aStr1
.getStr(), aStr1
.getLength(), aStr2
.getStr(), aStr2
.getLength(), aStr1
.getLength());
169 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue
== 0);
174 OString aStr1
= "Line must be equal.";
175 OString aStr2
= "Line must be equal.";
177 sal_Int32 nValue
= rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( aStr1
.getStr(), aStr1
.getLength(),
178 aStr2
.getStr(), aStr2
.getLength(),
180 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue
== 0);
185 OString aStr1
= "Line must be equal.";
186 OString aStr2
= "LINE MUST BE EQUAL.";
188 sal_Int32 nValue
= rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( aStr1
.getStr(), aStr1
.getLength(),
189 aStr2
.getStr(), aStr2
.getLength(),
191 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal (if case insensitive).", nValue
== 0);
196 OString aStr1
= "Line must differ.";
197 OString aStr2
= "Line foo bar, ok, differ.";
199 sal_Int32 nValue
= rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( aStr1
.getStr(), aStr1
.getLength(),
200 aStr2
.getStr(), aStr2
.getLength(),
202 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal first 5 characters.", nValue
== 0);
207 OString aStr1
= "Line must differ.";
208 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 differ.", nValue
!= 0);
216 // Change the following lines only, if you add, remove or rename
217 // member functions of the current class,
218 // because these macros are need by auto register mechanism.
220 CPPUNIT_TEST_SUITE(shortenedCompareIgnoreAsciiCase_WithLength
);
221 CPPUNIT_TEST(compare_000
);
222 CPPUNIT_TEST(compare_000_1
);
223 CPPUNIT_TEST(compare_001
);
224 CPPUNIT_TEST(compare_002
);
225 CPPUNIT_TEST(compare_002_1
);
226 CPPUNIT_TEST(compare_003
);
227 CPPUNIT_TEST(compare_004
);
228 CPPUNIT_TEST_SUITE_END();
231 class hashCode
: public CppUnit::TestFixture
237 rtl_str_hashCode( NULL
);
242 OString aStr1
= "Line for a hashCode.";
243 sal_Int32 nHashCode
= rtl_str_hashCode( aStr1
.getStr() );
244 printf("hashcode: %d\n", nHashCode
);
245 // CPPUNIT_ASSERT_MESSAGE("failed.", nValue == 0);
250 OString aStr1
= "Line for a hashCode.";
251 sal_Int32 nHashCode1
= rtl_str_hashCode( aStr1
.getStr() );
253 OString aStr2
= "Line for a hashCode.";
254 sal_Int32 nHashCode2
= rtl_str_hashCode( aStr2
.getStr() );
256 CPPUNIT_ASSERT_MESSAGE("hashcodes must be equal.", nHashCode1
== nHashCode2
);
261 OString aStr1
= "Line for a hashCode.";
262 sal_Int32 nHashCode1
= rtl_str_hashCode( aStr1
.getStr() );
264 OString aStr2
= "Line for another hashcode.";
265 sal_Int32 nHashCode2
= rtl_str_hashCode( aStr2
.getStr() );
267 CPPUNIT_ASSERT_MESSAGE("hashcodes must differ.", nHashCode1
!= nHashCode2
);
270 // Change the following lines only, if you add, remove or rename
271 // member functions of the current class,
272 // because these macros are need by auto register mechanism.
274 CPPUNIT_TEST_SUITE(hashCode
);
275 CPPUNIT_TEST(hashCode_000
);
276 CPPUNIT_TEST(hashCode_001
);
277 CPPUNIT_TEST(hashCode_002
);
278 CPPUNIT_TEST(hashCode_003
);
279 CPPUNIT_TEST_SUITE_END();
282 class indexOfChar
: public CppUnit::TestFixture
286 void indexOfChar_000()
288 rtl_str_indexOfChar( NULL
, 0 );
291 void indexOfChar_001()
293 OString aStr1
= "Line for an indexOfChar.";
295 sal_Int32 nIndex
= rtl_str_indexOfChar( aStr1
.getStr(), 'L' );
296 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex
== 0);
298 /* sal_Int32 */ nIndex
= rtl_str_indexOfChar( aStr1
.getStr(), 'i' );
299 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex
== 1);
301 /* sal_Int32 */ nIndex
= rtl_str_indexOfChar( aStr1
.getStr(), 'n' );
302 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex
== 2);
304 /* sal_Int32 */ nIndex
= rtl_str_indexOfChar( aStr1
.getStr(), 'e' );
305 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex
== 3);
308 void indexOfChar_002()
310 OString aStr1
= "Line for an indexOfChar.";
311 sal_Int32 nIndex
= rtl_str_indexOfChar( aStr1
.getStr(), 'y' );
313 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex
== -1 );
316 // Change the following lines only, if you add, remove or rename
317 // member functions of the current class,
318 // because these macros are need by auto register mechanism.
320 CPPUNIT_TEST_SUITE(indexOfChar
);
321 CPPUNIT_TEST(indexOfChar_000
);
322 CPPUNIT_TEST(indexOfChar_001
);
323 CPPUNIT_TEST(indexOfChar_002
);
324 CPPUNIT_TEST_SUITE_END();
327 class lastIndexOfChar
: public CppUnit::TestFixture
331 void lastIndexOfChar_000()
333 rtl_str_lastIndexOfChar( NULL
, 0 );
336 void lastIndexOfChar_001()
338 OString aStr1
= "Line for a lastIndexOfChar.";
340 sal_Int32 nIndex
= rtl_str_lastIndexOfChar( aStr1
.getStr(), 'C' );
341 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex
== 22);
343 /* sal_Int32 */ nIndex
= rtl_str_lastIndexOfChar( aStr1
.getStr(), 'h' );
344 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex
== 23);
346 /* sal_Int32 */ nIndex
= rtl_str_lastIndexOfChar( aStr1
.getStr(), 'a' );
347 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex
== 24);
349 /* sal_Int32 */ nIndex
= rtl_str_lastIndexOfChar( aStr1
.getStr(), 'r' );
350 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex
== 25);
353 void lastIndexOfChar_002()
355 OString aStr1
= "Line for a lastIndexOfChar.";
356 sal_Int32 nIndex
= rtl_str_lastIndexOfChar( aStr1
.getStr(), 'y' );
358 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex
== -1 );
361 // Change the following lines only, if you add, remove or rename
362 // member functions of the current class,
363 // because these macros are need by auto register mechanism.
365 CPPUNIT_TEST_SUITE(lastIndexOfChar
);
366 CPPUNIT_TEST(lastIndexOfChar_000
);
367 CPPUNIT_TEST(lastIndexOfChar_001
);
368 CPPUNIT_TEST(lastIndexOfChar_002
);
369 CPPUNIT_TEST_SUITE_END();
370 }; // class lastIndexOfChar
372 class indexOfStr
: public CppUnit::TestFixture
376 void indexOfStr_000()
378 rtl_str_indexOfStr( NULL
, 0 );
381 void indexOfStr_000_1()
383 OString aStr1
= "Line for an indexOfStr.";
384 rtl_str_indexOfStr( aStr1
.getStr(), 0 );
387 void indexOfStr_001()
389 OString aStr1
= "Line for an indexOfStr.";
391 sal_Int32 nIndex
= rtl_str_indexOfStr( aStr1
.getStr(), "Line" );
392 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex
== 0);
394 /* sal_Int32 */ nIndex
= rtl_str_indexOfStr( aStr1
.getStr(), "for" );
395 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex
== 5);
397 /* sal_Int32 */ nIndex
= rtl_str_indexOfStr( aStr1
.getStr(), "a" );
398 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex
== 9);
400 /* sal_Int32 */ nIndex
= rtl_str_indexOfStr( aStr1
.getStr(), "an index" );
401 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex
==9);
404 void indexOfStr_002()
406 OString aStr1
= "Line for an indexOfStr.";
407 sal_Int32 nIndex
= rtl_str_indexOfStr( aStr1
.getStr(), "not exist" );
409 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex
== -1 );
412 // Change the following lines only, if you add, remove or rename
413 // member functions of the current class,
414 // because these macros are need by auto register mechanism.
416 CPPUNIT_TEST_SUITE(indexOfStr
);
417 CPPUNIT_TEST(indexOfStr_000
);
418 CPPUNIT_TEST(indexOfStr_001
);
419 CPPUNIT_TEST(indexOfStr_002
);
420 CPPUNIT_TEST_SUITE_END();
423 class lastIndexOfStr
: public CppUnit::TestFixture
427 void lastIndexOfStr_000()
429 rtl_str_lastIndexOfStr( NULL
, NULL
);
432 void lastIndexOfStr_000_1()
434 OString aStr1
= "Line for a lastIndexOfStr.";
435 rtl_str_lastIndexOfStr( aStr1
.getStr(), NULL
);
438 void lastIndexOfStr_001()
440 OString aStr1
= "Line for a lastIndexOfStr.";
441 OString aSearchStr
= "Index";
443 sal_Int32 nIndex
= rtl_str_lastIndexOfStr( aStr1
.getStr(), aSearchStr
.getStr() );
444 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex
== 15);
446 /* OString */ aSearchStr
= "Line";
447 /* sal_Int32 */ nIndex
= rtl_str_lastIndexOfStr( aStr1
.getStr(), aSearchStr
.getStr() );
448 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex
== 0);
450 /* OString */ aSearchStr
= "";
451 /* sal_Int32 */ nIndex
= rtl_str_lastIndexOfStr( aStr1
.getStr(), aSearchStr
.getStr() );
452 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex
== -1);
455 void lastIndexOfStr_002()
457 OString aStr1
= "Line for a lastIndexOfStr.";
458 OString aSearchStr
= "foo";
459 sal_Int32 nIndex
= rtl_str_lastIndexOfStr( aStr1
.getStr(), aSearchStr
.getStr() );
461 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex
== -1 );
464 void lastIndexOfStr_003()
466 OString aStr1
= "Line for a lastIndexOfStr.";
467 OString aSearchStr
= "O";
468 sal_Int32 nIndex
= rtl_str_lastIndexOfStr( aStr1
.getStr(), aSearchStr
.getStr() );
470 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex
== 20 );
473 // Change the following lines only, if you add, remove or rename
474 // member functions of the current class,
475 // because these macros are need by auto register mechanism.
477 CPPUNIT_TEST_SUITE(lastIndexOfStr
);
478 CPPUNIT_TEST(lastIndexOfStr_000
);
479 CPPUNIT_TEST(lastIndexOfStr_001
);
480 CPPUNIT_TEST(lastIndexOfStr_002
);
481 CPPUNIT_TEST(lastIndexOfStr_003
);
482 CPPUNIT_TEST_SUITE_END();
483 }; // class lastIndexOfStr
485 class replaceChar
: public CppUnit::TestFixture
489 void replaceChar_000()
491 rtl_str_replaceChar( NULL
, 0, 0 );
494 void replaceChar_001()
496 OString aStr1
= "replace char.";
497 OString aShouldStr1
= "ruplacu char.";
499 sal_Char
* pStr
= (sal_Char
*) malloc(aStr1
.getLength() + 1);
500 CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr
!= NULL
);
501 strcpy(pStr
, aStr1
.getStr());
503 rtl_str_replaceChar( pStr
, 'e', 'u' );
505 CPPUNIT_ASSERT_MESSAGE("replace failed", aShouldStr1
.equals(OString(pStr
)) == sal_True
);
509 // Change the following lines only, if you add, remove or rename
510 // member functions of the current class,
511 // because these macros are need by auto register mechanism.
513 CPPUNIT_TEST_SUITE(replaceChar
);
514 CPPUNIT_TEST(replaceChar_000
);
515 CPPUNIT_TEST(replaceChar_001
);
516 CPPUNIT_TEST_SUITE_END();
517 }; // class replaceChar
519 class replaceChar_WithLength
: public CppUnit::TestFixture
523 void replaceChar_WithLength_000()
525 rtl_str_replaceChar_WithLength( NULL
, 0, 0, 0 );
528 void replaceChar_WithLength_000_1()
530 rtl_str_replaceChar_WithLength( NULL
, 1, 0, 0 );
532 void replaceChar_WithLength_001()
534 OString aStr1
= "replace char.";
535 OString aShouldStr1
= "ruplace char.";
537 sal_Char
* pStr
= (sal_Char
*) malloc(aStr1
.getLength() + 1);
538 CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr
!= NULL
);
539 strcpy(pStr
, aStr1
.getStr());
541 rtl_str_replaceChar_WithLength( pStr
, 6, 'e', 'u' );
543 CPPUNIT_ASSERT_MESSAGE("replace failed", aShouldStr1
.equals(OString(pStr
)) == sal_True
);
547 // Change the following lines only, if you add, remove or rename
548 // member functions of the current class,
549 // because these macros are need by auto register mechanism.
551 CPPUNIT_TEST_SUITE(replaceChar_WithLength
);
552 CPPUNIT_TEST(replaceChar_WithLength_000
);
553 CPPUNIT_TEST(replaceChar_WithLength_000_1
);
554 CPPUNIT_TEST(replaceChar_WithLength_001
);
555 CPPUNIT_TEST_SUITE_END();
556 }; // class replaceChar
558 class toAsciiLowerCase
: public CppUnit::TestFixture
562 void toAsciiLowerCase_000()
564 rtl_str_toAsciiLowerCase( NULL
);
567 void toAsciiLowerCase_001()
569 OString aStr1
= "CHANGE THIS TO ASCII LOWER CASE.";
570 OString aShouldStr1
= "change this to ascii lower case.";
572 sal_Char
* pStr
= (sal_Char
*) malloc(aStr1
.getLength() + 1);
573 CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr
!= NULL
);
574 strcpy(pStr
, aStr1
.getStr());
576 rtl_str_toAsciiLowerCase( pStr
);
578 CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1
.equals(OString(pStr
)) == sal_True
);
582 // Change the following lines only, if you add, remove or rename
583 // member functions of the current class,
584 // because these macros are need by auto register mechanism.
586 CPPUNIT_TEST_SUITE(toAsciiLowerCase
);
587 CPPUNIT_TEST(toAsciiLowerCase_000
);
588 CPPUNIT_TEST(toAsciiLowerCase_001
);
589 CPPUNIT_TEST_SUITE_END();
590 }; // class replaceChar
592 class toAsciiLowerCase_WithLength
: public CppUnit::TestFixture
596 void toAsciiLowerCase_WithLength_000()
598 rtl_str_toAsciiLowerCase_WithLength( NULL
, 0 );
601 void toAsciiLowerCase_WithLength_001()
603 OString aStr1
= "CHANGE THIS TO ASCII LOWER CASE.";
604 OString aShouldStr1
= "change thiS TO ASCII LOWER CASE.";
606 sal_Char
* pStr
= (sal_Char
*) malloc(aStr1
.getLength() + 1);
607 CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr
!= NULL
);
608 strcpy(pStr
, aStr1
.getStr());
610 rtl_str_toAsciiLowerCase_WithLength( pStr
, 10 );
612 printf("Lowercase with length: '%s'\n", pStr
);
613 CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1
.equals(OString(pStr
)) == sal_True
);
617 // Change the following lines only, if you add, remove or rename
618 // member functions of the current class,
619 // because these macros are need by auto register mechanism.
621 CPPUNIT_TEST_SUITE(toAsciiLowerCase_WithLength
);
622 CPPUNIT_TEST(toAsciiLowerCase_WithLength_000
);
623 CPPUNIT_TEST(toAsciiLowerCase_WithLength_001
);
624 CPPUNIT_TEST_SUITE_END();
625 }; // class replaceChar
627 class toAsciiUpperCase
: public CppUnit::TestFixture
631 void toAsciiUpperCase_000()
633 rtl_str_toAsciiUpperCase( NULL
);
636 void toAsciiUpperCase_001()
638 OString aStr1
= "change this to ascii upper case.";
639 OString aShouldStr1
= "CHANGE THIS TO ASCII UPPER CASE.";
641 sal_Char
* pStr
= (sal_Char
*) malloc(aStr1
.getLength() + 1);
642 CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr
!= NULL
);
643 strcpy(pStr
, aStr1
.getStr());
645 rtl_str_toAsciiUpperCase( pStr
);
647 CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1
.equals(OString(pStr
)) == sal_True
);
651 // Change the following lines only, if you add, remove or rename
652 // member functions of the current class,
653 // because these macros are need by auto register mechanism.
655 CPPUNIT_TEST_SUITE(toAsciiUpperCase
);
656 CPPUNIT_TEST(toAsciiUpperCase_000
);
657 CPPUNIT_TEST(toAsciiUpperCase_001
);
658 CPPUNIT_TEST_SUITE_END();
659 }; // class replaceChar
661 class toAsciiUpperCase_WithLength
: public CppUnit::TestFixture
665 void toAsciiUpperCase_WithLength_000()
667 rtl_str_toAsciiUpperCase_WithLength( NULL
, 0 );
670 void toAsciiUpperCase_WithLength_001()
672 OString aStr1
= "change this to ascii lower case.";
673 OString aShouldStr1
= "CHANGE THIs to ascii lower case.";
675 sal_Char
* pStr
= (sal_Char
*) malloc(aStr1
.getLength() + 1);
676 CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr
!= NULL
);
678 strcpy(pStr
, aStr1
.getStr());
679 rtl_str_toAsciiUpperCase_WithLength( pStr
, 10 );
681 printf("Uppercase with length: '%s'\n", aStr1
.getStr());
682 CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1
.equals(OString(pStr
)) == sal_True
);
686 // Change the following lines only, if you add, remove or rename
687 // member functions of the current class,
688 // because these macros are need by auto register mechanism.
690 CPPUNIT_TEST_SUITE(toAsciiUpperCase_WithLength
);
691 CPPUNIT_TEST(toAsciiUpperCase_WithLength_000
);
692 CPPUNIT_TEST(toAsciiUpperCase_WithLength_001
);
693 CPPUNIT_TEST_SUITE_END();
694 }; // class replaceChar
696 class trim_WithLength
: public CppUnit::TestFixture
699 void trim_WithLength_000()
701 rtl_str_trim_WithLength(NULL
, 0);
705 void trim_WithLength_000_1()
707 char pStr
[] = { " trim this" };
708 rtl_str_trim_WithLength( pStr
, 0 );
711 void trim_WithLength_001()
713 char const *pStr
= " trim this";
714 sal_Char
*pStr2
= strdup(pStr
);
717 rtl_str_trim_WithLength( pStr2
, 2 );
719 CPPUNIT_ASSERT_MESSAGE("string should be empty", strlen(pStr2
) == 0);
724 void trim_WithLength_002()
726 char const *pStr
= "trim this";
727 sal_Char
*pStr2
= strdup(pStr
);
730 rtl_str_trim_WithLength( pStr2
, 5 );
732 CPPUNIT_ASSERT_MESSAGE("string should contain 'trim'", strlen(pStr2
) == 4);
737 void trim_WithLength_003()
739 char const *pStr
= " trim this";
740 sal_Char
*pStr2
= strdup(pStr
);
744 rtl_str_trim_WithLength( pStr2
, 11 );
746 CPPUNIT_ASSERT_MESSAGE("string should contain 'trim'", strlen(pStr2
) == 4);
751 void trim_WithLength_004()
753 char const *pStr
= "\r\n\t \n\r trim \n this";
754 sal_Char
*pStr2
= strdup(pStr
);
757 rtl_str_trim_WithLength( pStr2
, 17 );
759 CPPUNIT_ASSERT_MESSAGE("string should contain 'trim'", strlen(pStr2
) == 4);
764 void trim_WithLength_005()
766 char const *pStr
= "\r\n\t \n\r trim \t this \n\r\t\t ";
767 sal_Char
*pStr2
= strdup(pStr
);
770 rtl_str_trim_WithLength( pStr2
, strlen(pStr2
) );
772 CPPUNIT_ASSERT_MESSAGE("string should contain 'trim'", strlen(pStr2
) == 11);
777 // Change the following lines only, if you add, remove or rename
778 // member functions of the current class,
779 // because these macros are need by auto register mechanism.
781 CPPUNIT_TEST_SUITE(trim_WithLength
);
782 CPPUNIT_TEST(trim_WithLength_000
);
783 CPPUNIT_TEST(trim_WithLength_000_1
);
784 CPPUNIT_TEST(trim_WithLength_001
);
785 CPPUNIT_TEST(trim_WithLength_002
);
786 CPPUNIT_TEST(trim_WithLength_003
);
787 CPPUNIT_TEST(trim_WithLength_004
);
788 CPPUNIT_TEST(trim_WithLength_005
);
789 CPPUNIT_TEST_SUITE_END();
792 class valueOfChar
: public CppUnit::TestFixture
795 void valueOfChar_000()
797 rtl_str_valueOfChar(NULL
, 0);
800 void valueOfChar_001()
802 sal_Char
*pStr
= (sal_Char
*)malloc(RTL_STR_MAX_VALUEOFCHAR
);
805 rtl_str_valueOfChar(pStr
, 'A');
807 CPPUNIT_ASSERT_MESSAGE("string should contain 'A'", pStr
[0] == 'A');
812 // Change the following lines only, if you add, remove or rename
813 // member functions of the current class,
814 // because these macros are need by auto register mechanism.
816 CPPUNIT_TEST_SUITE(valueOfChar
);
817 CPPUNIT_TEST(valueOfChar_000
);
818 CPPUNIT_TEST(valueOfChar_001
);
819 CPPUNIT_TEST_SUITE_END();
822 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::compare
);
823 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::compareIgnoreAsciiCase
);
824 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::shortenedCompareIgnoreAsciiCase_WithLength
);
825 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::hashCode
);
827 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::indexOfChar
);
828 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::lastIndexOfChar
);
829 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::indexOfStr
);
830 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::lastIndexOfStr
);
832 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::replaceChar
);
833 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::replaceChar_WithLength
);
835 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::toAsciiLowerCase
);
836 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::toAsciiLowerCase_WithLength
);
837 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::toAsciiUpperCase
);
838 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::toAsciiUpperCase_WithLength
);
840 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::trim_WithLength
);
841 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_str::valueOfChar
);
843 } // namespace rtl_str
845 // this macro creates an empty function, which will called by the RegisterAllFunctions()
846 // to let the user the possibility to also register some functions by hand.
847 CPPUNIT_PLUGIN_IMPLEMENT();
849 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */