xref: /trunk/main/sal/qa/rtl/ostring/rtl_str.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
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.
14  *
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).
20  *
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.
25  *
26  ************************************************************************/
27 
28 
29 // MARKER(update_precomp.py): autogen include statement, do not remove
30 #include "precompiled_sal.hxx"
31 #include <testshl/simpleheader.hxx>
32 
33 namespace rtl_str
34 {
35 
36     class compare : public CppUnit::TestFixture
37     {
38     public:
39 
40         void compare_000()
41             {
42                 rtl_str_compare( NULL, NULL);
43             }
44 
45         void compare_000_1()
46             {
47                 rtl::OString aStr1 = "Line must be equal.";
48                 rtl_str_compare( aStr1.getStr(), NULL);
49             }
50         void compare_001()
51             {
52                 rtl::OString aStr1 = "";
53                 rtl::OString aStr2 = "";
54 
55                 sal_Int32 nValue = rtl_str_compare( aStr1.getStr(), aStr2.getStr());
56                 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
57             }
58 
59         void compare_002()
60             {
61                 rtl::OString aStr1 = "Line must be equal.";
62                 rtl::OString aStr2 = "Line must be equal.";
63 
64                 sal_Int32 nValue = rtl_str_compare( aStr1.getStr(), aStr2.getStr());
65                 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
66             }
67 
68         void compare_003()
69             {
70                 rtl::OString aStr1 = "Line must differ.";
71                 rtl::OString aStr2 = "Line foo bar, ok, differ.";
72 
73                 sal_Int32 nValue = rtl_str_compare( aStr1.getStr(), aStr2.getStr());
74                 CPPUNIT_ASSERT_MESSAGE("compare failed, strings differ.", nValue != 0);
75             }
76 
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.
80 
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
89 
90 
91     class compareIgnoreAsciiCase : public CppUnit::TestFixture
92     {
93     public:
94 
95         void compare_000()
96             {
97                 rtl_str_compareIgnoreAsciiCase( NULL, NULL);
98             }
99 
100         void compare_000_1()
101             {
102                 rtl::OString aStr1 = "Line must be equal.";
103                 rtl_str_compareIgnoreAsciiCase( aStr1.getStr(), NULL);
104             }
105         void compare_001()
106             {
107                 rtl::OString aStr1 = "";
108                 rtl::OString aStr2 = "";
109 
110                 sal_Int32 nValue = rtl_str_compareIgnoreAsciiCase( aStr1.getStr(), aStr2.getStr());
111                 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
112             }
113 
114         void compare_002()
115             {
116                 rtl::OString aStr1 = "Line must be equal.";
117                 rtl::OString aStr2 = "Line must be equal.";
118 
119                 sal_Int32 nValue = rtl_str_compareIgnoreAsciiCase( aStr1.getStr(), aStr2.getStr());
120                 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
121             }
122 
123         void compare_002_1()
124             {
125                 rtl::OString aStr1 = "Line must be equal.";
126                 rtl::OString aStr2 = "LINE MUST BE EQUAL.";
127 
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);
130             }
131 
132         void compare_003()
133             {
134                 rtl::OString aStr1 = "Line must differ.";
135                 rtl::OString aStr2 = "Line foo bar, ok, differ.";
136 
137                 sal_Int32 nValue = rtl_str_compareIgnoreAsciiCase( aStr1.getStr(), aStr2.getStr());
138                 CPPUNIT_ASSERT_MESSAGE("compare failed, strings differ.", nValue != 0);
139             }
140 
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.
144 
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
154 
155 // -----------------------------------------------------------------------------
156 
157     class shortenedCompareIgnoreAsciiCase_WithLength : public CppUnit::TestFixture
158     {
159     public:
160 
161         void compare_000()
162             {
163                 rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( NULL, 0, NULL, 0, 0);
164             }
165 
166         void compare_000_1()
167             {
168                 rtl::OString aStr1 = "Line must be equal.";
169                 rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(), NULL, 0, 1);
170             }
171         void compare_001()
172             {
173                 rtl::OString aStr1 = "";
174                 rtl::OString aStr2 = "";
175 
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);
178             }
179 
180         void compare_002()
181             {
182                 rtl::OString aStr1 = "Line must be equal.";
183                 rtl::OString aStr2 = "Line must be equal.";
184 
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);
189             }
190 
191         void compare_002_1()
192             {
193                 rtl::OString aStr1 = "Line must be equal.";
194                 rtl::OString aStr2 = "LINE MUST BE EQUAL.";
195 
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);
200             }
201 
202         void compare_003()
203             {
204                 rtl::OString aStr1 = "Line must differ.";
205                 rtl::OString aStr2 = "Line foo bar, ok, differ.";
206 
207                 sal_Int32 nValue = rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(),
208                                                                                        aStr2.getStr(), aStr2.getLength(),
209                                                                                        5);
210                 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal first 5 characters.", nValue == 0);
211             }
212 
213         void compare_004()
214             {
215                 rtl::OString aStr1 = "Line must differ.";
216                 rtl::OString aStr2 = "Line foo bar, ok, differ.";
217 
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);
222             }
223 
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.
227 
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
238 
239 
240 // -----------------------------------------------------------------------------
241 
242     class hashCode : public CppUnit::TestFixture
243     {
244     public:
245 
246         void hashCode_000()
247             {
248                 rtl_str_hashCode( NULL );
249             }
250 
251         void hashCode_001()
252             {
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);
257             }
258 
259         void hashCode_002()
260             {
261                 rtl::OString aStr1 = "Line for a hashCode.";
262                 sal_Int32 nHashCode1 = rtl_str_hashCode( aStr1.getStr() );
263 
264                 rtl::OString aStr2 = "Line for a hashCode.";
265                 sal_Int32 nHashCode2 = rtl_str_hashCode( aStr2.getStr() );
266 
267                 CPPUNIT_ASSERT_MESSAGE("hashcodes must be equal.", nHashCode1 == nHashCode2 );
268             }
269 
270         void hashCode_003()
271             {
272                 rtl::OString aStr1 = "Line for a hashCode.";
273                 sal_Int32 nHashCode1 = rtl_str_hashCode( aStr1.getStr() );
274 
275                 rtl::OString aStr2 = "Line for an other hashcode.";
276                 sal_Int32 nHashCode2 = rtl_str_hashCode( aStr2.getStr() );
277 
278                 CPPUNIT_ASSERT_MESSAGE("hashcodes must differ.", nHashCode1 != nHashCode2 );
279             }
280 
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.
284 
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
292 
293 
294 // -----------------------------------------------------------------------------
295 
296     class indexOfChar : public CppUnit::TestFixture
297     {
298     public:
299 
300         void indexOfChar_000()
301             {
302                 rtl_str_indexOfChar( NULL, 0 );
303             }
304 
305         void indexOfChar_001()
306             {
307                 rtl::OString aStr1 = "Line for a indexOfChar.";
308 
309                 sal_Int32 nIndex = rtl_str_indexOfChar( aStr1.getStr(), 'L' );
310                 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 0);
311 
312                 /* sal_Int32 */ nIndex = rtl_str_indexOfChar( aStr1.getStr(), 'i' );
313                 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 1);
314 
315                 /* sal_Int32 */ nIndex = rtl_str_indexOfChar( aStr1.getStr(), 'n' );
316                 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 2);
317 
318                 /* sal_Int32 */ nIndex = rtl_str_indexOfChar( aStr1.getStr(), 'e' );
319                 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 3);
320             }
321 
322         void indexOfChar_002()
323             {
324                 rtl::OString aStr1 = "Line for a indexOfChar.";
325                 sal_Int32 nIndex = rtl_str_indexOfChar( aStr1.getStr(), 'y' );
326 
327                 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == -1 );
328             }
329 
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.
333 
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
340 
341 // -----------------------------------------------------------------------------
342     class lastIndexOfChar : public CppUnit::TestFixture
343     {
344     public:
345 
346         void lastIndexOfChar_000()
347             {
348                 rtl_str_lastIndexOfChar( NULL, 0 );
349             }
350 
351         void lastIndexOfChar_001()
352             {
353                 rtl::OString aStr1 = "Line for a lastIndexOfChar.";
354 
355                 sal_Int32 nIndex = rtl_str_lastIndexOfChar( aStr1.getStr(), 'C' );
356                 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 22);
357 
358                 /* sal_Int32 */ nIndex = rtl_str_lastIndexOfChar( aStr1.getStr(), 'h' );
359                 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 23);
360 
361                 /* sal_Int32 */ nIndex = rtl_str_lastIndexOfChar( aStr1.getStr(), 'a' );
362                 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 24);
363 
364                 /* sal_Int32 */ nIndex = rtl_str_lastIndexOfChar( aStr1.getStr(), 'r' );
365                 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 25);
366             }
367 
368         void lastIndexOfChar_002()
369             {
370                 rtl::OString aStr1 = "Line for a lastIndexOfChar.";
371                 sal_Int32 nIndex = rtl_str_lastIndexOfChar( aStr1.getStr(), 'y' );
372 
373                 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == -1 );
374             }
375 
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.
379 
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
386 
387 
388 // -----------------------------------------------------------------------------
389 
390     class indexOfStr : public CppUnit::TestFixture
391     {
392     public:
393 
394         void indexOfStr_000()
395             {
396                 rtl_str_indexOfStr( NULL, 0 );
397             }
398 
399         void indexOfStr_000_1()
400             {
401                 rtl::OString aStr1 = "Line for a indexOfStr.";
402                 rtl_str_indexOfStr( aStr1.getStr(), 0 );
403             }
404 
405         void indexOfStr_001()
406             {
407                 rtl::OString aStr1 = "Line for a indexOfStr.";
408 
409                 sal_Int32 nIndex = rtl_str_indexOfStr( aStr1.getStr(), "Line" );
410                 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 0);
411 
412                 /* sal_Int32 */ nIndex = rtl_str_indexOfStr( aStr1.getStr(), "for" );
413                 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 5);
414 
415                 /* sal_Int32 */ nIndex = rtl_str_indexOfStr( aStr1.getStr(), "a" );
416                 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 9);
417 
418                 /* sal_Int32 */ nIndex = rtl_str_indexOfStr( aStr1.getStr(), "a index" );
419                 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex ==9);
420             }
421 
422         void indexOfStr_002()
423             {
424                 rtl::OString aStr1 = "Line for a indexOfStr.";
425                 sal_Int32 nIndex = rtl_str_indexOfStr( aStr1.getStr(), "not exist" );
426 
427                 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == -1 );
428             }
429 
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.
433 
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 // -----------------------------------------------------------------------------
441 
442 
443     class lastIndexOfStr : public CppUnit::TestFixture
444     {
445     public:
446 
447         void lastIndexOfStr_000()
448             {
449                 rtl_str_lastIndexOfStr( NULL, NULL );
450             }
451 
452         void lastIndexOfStr_000_1()
453             {
454                 rtl::OString aStr1 = "Line for a lastIndexOfStr.";
455                 rtl_str_lastIndexOfStr( aStr1.getStr(), NULL );
456             }
457 
458         void lastIndexOfStr_001()
459             {
460                 rtl::OString aStr1 = "Line for a lastIndexOfStr.";
461                 rtl::OString aSearchStr = "Index";
462 
463                 sal_Int32 nIndex = rtl_str_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() );
464                 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 15);
465 
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);
469 
470                 /* rtl::OString */ aSearchStr = "";
471                 /* sal_Int32 */ nIndex = rtl_str_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() );
472                 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == -1);
473             }
474 
475         void lastIndexOfStr_002()
476             {
477                 rtl::OString aStr1 = "Line for a lastIndexOfStr.";
478                 rtl::OString aSearchStr = "foo";
479                 sal_Int32 nIndex = rtl_str_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() );
480 
481                 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == -1 );
482             }
483 
484         void lastIndexOfStr_003()
485             {
486                 rtl::OString aStr1 = "Line for a lastIndexOfStr.";
487                 rtl::OString aSearchStr = "O";
488                 sal_Int32 nIndex = rtl_str_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() );
489 
490                 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 20 );
491             }
492 
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.
496 
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
504 
505 // -----------------------------------------------------------------------------
506 
507     class replaceChar : public CppUnit::TestFixture
508     {
509     public:
510 
511         void replaceChar_000()
512             {
513                 rtl_str_replaceChar( NULL, 0, 0 );
514             }
515 
516         void replaceChar_001()
517             {
518                 rtl::OString aStr1 = "replace char.";
519                 rtl::OString aShouldStr1 = "ruplacu char.";
520 
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());
524 
525                 rtl_str_replaceChar( pStr, 'e', 'u' );
526 
527                 CPPUNIT_ASSERT_MESSAGE("replace failed", aShouldStr1.equals(rtl::OString(pStr)) == sal_True);
528                 free(pStr);
529             }
530 
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.
534 
535         CPPUNIT_TEST_SUITE(replaceChar);
536         CPPUNIT_TEST(replaceChar_000);
537         CPPUNIT_TEST(replaceChar_001);
538         CPPUNIT_TEST_SUITE_END();
539     }; // class replaceChar
540 
541 // -----------------------------------------------------------------------------
542 
543     class replaceChar_WithLength : public CppUnit::TestFixture
544     {
545     public:
546 
547         void replaceChar_WithLength_000()
548             {
549                 rtl_str_replaceChar_WithLength( NULL, 0, 0, 0 );
550             }
551 
552         void replaceChar_WithLength_000_1()
553             {
554                 rtl_str_replaceChar_WithLength( NULL, 1, 0, 0 );
555             }
556         void replaceChar_WithLength_001()
557             {
558                 rtl::OString aStr1 = "replace char.";
559                 rtl::OString aShouldStr1 = "ruplace char.";
560 
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());
564 
565                 rtl_str_replaceChar_WithLength( pStr, 6, 'e', 'u' );
566 
567                 CPPUNIT_ASSERT_MESSAGE("replace failed", aShouldStr1.equals(rtl::OString(pStr)) == sal_True);
568                 free(pStr);
569             }
570 
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.
574 
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
581 
582 
583 // -----------------------------------------------------------------------------
584 
585     class toAsciiLowerCase : public CppUnit::TestFixture
586     {
587     public:
588 
589         void toAsciiLowerCase_000()
590             {
591                 rtl_str_toAsciiLowerCase( NULL );
592             }
593 
594         void toAsciiLowerCase_001()
595             {
596                 rtl::OString aStr1 = "CHANGE THIS TO ASCII LOWER CASE.";
597                 rtl::OString aShouldStr1 = "change this to ascii lower case.";
598 
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());
602 
603                 rtl_str_toAsciiLowerCase( pStr );
604 
605                 CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1.equals(rtl::OString(pStr)) == sal_True);
606                 free(pStr);
607             }
608 
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.
612 
613         CPPUNIT_TEST_SUITE(toAsciiLowerCase);
614         CPPUNIT_TEST(toAsciiLowerCase_000);
615         CPPUNIT_TEST(toAsciiLowerCase_001);
616         CPPUNIT_TEST_SUITE_END();
617     }; // class replaceChar
618 
619 
620     class toAsciiLowerCase_WithLength : public CppUnit::TestFixture
621     {
622     public:
623 
624         void toAsciiLowerCase_WithLength_000()
625             {
626                 rtl_str_toAsciiLowerCase_WithLength( NULL, 0 );
627             }
628 
629         void toAsciiLowerCase_WithLength_001()
630             {
631                 rtl::OString aStr1 = "CHANGE THIS TO ASCII LOWER CASE.";
632                 rtl::OString aShouldStr1 = "change thiS TO ASCII LOWER CASE.";
633 
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());
637 
638                 rtl_str_toAsciiLowerCase_WithLength( pStr, 10 );
639 
640                 t_print("Lowercase with length: '%s'\n", pStr);
641                 CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1.equals(rtl::OString(pStr)) == sal_True);
642                 free(pStr);
643             }
644 
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.
648 
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
654 
655 // -----------------------------------------------------------------------------
656 
657     class toAsciiUpperCase : public CppUnit::TestFixture
658     {
659     public:
660 
661         void toAsciiUpperCase_000()
662             {
663                 rtl_str_toAsciiUpperCase( NULL );
664             }
665 
666         void toAsciiUpperCase_001()
667             {
668                 rtl::OString aStr1 = "change this to ascii upper case.";
669                 rtl::OString aShouldStr1 = "CHANGE THIS TO ASCII UPPER CASE.";
670 
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());
674 
675                 rtl_str_toAsciiUpperCase( pStr );
676 
677                 CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1.equals(rtl::OString(pStr)) == sal_True);
678                 free(pStr);
679             }
680 
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.
684 
685         CPPUNIT_TEST_SUITE(toAsciiUpperCase);
686         CPPUNIT_TEST(toAsciiUpperCase_000);
687         CPPUNIT_TEST(toAsciiUpperCase_001);
688         CPPUNIT_TEST_SUITE_END();
689     }; // class replaceChar
690 
691 
692     class toAsciiUpperCase_WithLength : public CppUnit::TestFixture
693     {
694     public:
695 
696         void toAsciiUpperCase_WithLength_000()
697             {
698                 rtl_str_toAsciiUpperCase_WithLength( NULL, 0 );
699             }
700 
701         void toAsciiUpperCase_WithLength_001()
702             {
703                 rtl::OString aStr1 = "change this to ascii lower case.";
704                 rtl::OString aShouldStr1 = "CHANGE THIs to ascii lower case.";
705 
706                 sal_Char* pStr = (sal_Char*) malloc(aStr1.getLength() + 1);
707                 CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL);
708 
709                 strcpy(pStr, aStr1.getStr());
710                 rtl_str_toAsciiUpperCase_WithLength( pStr, 10 );
711 
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);
715             }
716 
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.
720 
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
726 
727 
728     // -----------------------------------------------------------------------------
729 
730     class trim_WithLength : public CppUnit::TestFixture
731     {
732       public:
733         void trim_WithLength_000()
734         {
735             rtl_str_trim_WithLength(NULL, 0);
736             // should not GPF
737         }
738 
739         void trim_WithLength_000_1()
740         {
741             char pStr[] = { "  trim this" };
742             rtl_str_trim_WithLength( pStr, 0 );
743         }
744 
745         void trim_WithLength_001()
746         {
747             char const *pStr = "  trim this";
748             sal_Char *pStr2 = (sal_Char*)malloc(strlen(pStr) + 1);
749             if (pStr2)
750             {
751                 strcpy(pStr2, pStr);
752                 rtl_str_trim_WithLength( pStr2, 2 );
753 
754                 CPPUNIT_ASSERT_MESSAGE("string should be empty", strlen(pStr2) == 0);
755                 free(pStr2);
756             }
757         }
758 
759         void trim_WithLength_002()
760         {
761             char const *pStr = "trim this";
762             sal_Char *pStr2 = (sal_Char*)malloc(strlen(pStr) + 1);
763             if (pStr2)
764             {
765                 strcpy(pStr2, pStr);
766                 rtl_str_trim_WithLength( pStr2, 5 );
767 
768                 CPPUNIT_ASSERT_MESSAGE("string should contain 'trim'", strlen(pStr2) == 4);
769                 free(pStr2);
770             }
771         }
772 
773         void trim_WithLength_003()
774         {
775             char const *pStr = "     trim   this";
776             sal_Char *pStr2 = (sal_Char*)malloc(strlen(pStr) + 1);
777             if (pStr2)
778             {
779                 strcpy(pStr2, pStr);
780                 rtl_str_trim_WithLength( pStr2, 11 );
781 
782                 CPPUNIT_ASSERT_MESSAGE("string should contain 'trim'", strlen(pStr2) == 4);
783                 free(pStr2);
784             }
785         }
786 
787         void trim_WithLength_004()
788         {
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)
792             {
793                 strcpy(pStr2, pStr);
794                 rtl_str_trim_WithLength( pStr2, 17 );
795 
796                 CPPUNIT_ASSERT_MESSAGE("string should contain 'trim'", strlen(pStr2) == 4);
797                 free(pStr2);
798             }
799         }
800 
801         void trim_WithLength_005()
802         {
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)
806             {
807                 strcpy(pStr2, pStr);
808                 rtl_str_trim_WithLength( pStr2, strlen(pStr2) );
809 
810                 CPPUNIT_ASSERT_MESSAGE("string should contain 'trim'", strlen(pStr2) == 11);
811                 free(pStr2);
812             }
813         }
814 
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.
818 
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();
828     };
829 
830     // -----------------------------------------------------------------------------
831 
832     class valueOfChar : public CppUnit::TestFixture
833     {
834       public:
835         void valueOfChar_000()
836             {
837                 rtl_str_valueOfChar(NULL, 0);
838                 // should not GPF
839             }
840         void valueOfChar_001()
841             {
842                 sal_Char *pStr = (sal_Char*)malloc(RTL_STR_MAX_VALUEOFCHAR);
843                 if (pStr)
844                 {
845                     rtl_str_valueOfChar(pStr, 'A');
846 
847                     CPPUNIT_ASSERT_MESSAGE("string should contain 'A'", pStr[0] == 'A');
848                     free(pStr);
849                 }
850             }
851 
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.
855 
856         CPPUNIT_TEST_SUITE(valueOfChar);
857         CPPUNIT_TEST(valueOfChar_000);
858         CPPUNIT_TEST(valueOfChar_001);
859         CPPUNIT_TEST_SUITE_END();
860     };
861 
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");
867 
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");
872 
873 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::replaceChar, "rtl_str");
874 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::replaceChar_WithLength, "rtl_str");
875 
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");
880 
881 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::trim_WithLength, "rtl_str");
882 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::valueOfChar, "rtl_str");
883 
884 } // namespace rtl_str
885 
886 // -----------------------------------------------------------------------------
887 
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;
891