xref: /aoo41x/main/sal/qa/rtl/ostring/rtl_str.cxx (revision 87d2adbc)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 
25 // MARKER(update_precomp.py): autogen include statement, do not remove
26 #include "precompiled_sal.hxx"
27 #include <testshl/simpleheader.hxx>
28 
29 namespace rtl_str
30 {
31 
32     class compare : public CppUnit::TestFixture
33     {
34     public:
35 
compare_000()36         void compare_000()
37             {
38                 rtl_str_compare( NULL, NULL);
39             }
40 
compare_000_1()41         void compare_000_1()
42             {
43                 rtl::OString aStr1 = "Line must be equal.";
44                 rtl_str_compare( aStr1.getStr(), NULL);
45             }
compare_001()46         void compare_001()
47             {
48                 rtl::OString aStr1 = "";
49                 rtl::OString aStr2 = "";
50 
51                 sal_Int32 nValue = rtl_str_compare( aStr1.getStr(), aStr2.getStr());
52                 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
53             }
54 
compare_002()55         void compare_002()
56             {
57                 rtl::OString aStr1 = "Line must be equal.";
58                 rtl::OString aStr2 = "Line must be equal.";
59 
60                 sal_Int32 nValue = rtl_str_compare( aStr1.getStr(), aStr2.getStr());
61                 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
62             }
63 
compare_003()64         void compare_003()
65             {
66                 rtl::OString aStr1 = "Line must differ.";
67                 rtl::OString aStr2 = "Line foo bar, ok, differ.";
68 
69                 sal_Int32 nValue = rtl_str_compare( aStr1.getStr(), aStr2.getStr());
70                 CPPUNIT_ASSERT_MESSAGE("compare failed, strings differ.", nValue != 0);
71             }
72 
73     // Change the following lines only, if you add, remove or rename
74     // member functions of the current class,
75     // because these macros are need by auto register mechanism.
76 
77     CPPUNIT_TEST_SUITE(compare);
78     CPPUNIT_TEST(compare_000);
79     CPPUNIT_TEST(compare_000_1);
80     CPPUNIT_TEST(compare_001);
81     CPPUNIT_TEST(compare_002);
82     CPPUNIT_TEST(compare_003);
83     CPPUNIT_TEST_SUITE_END();
84 }; // class compare
85 
86 
87     class compareIgnoreAsciiCase : public CppUnit::TestFixture
88     {
89     public:
90 
compare_000()91         void compare_000()
92             {
93                 rtl_str_compareIgnoreAsciiCase( NULL, NULL);
94             }
95 
compare_000_1()96         void compare_000_1()
97             {
98                 rtl::OString aStr1 = "Line must be equal.";
99                 rtl_str_compareIgnoreAsciiCase( aStr1.getStr(), NULL);
100             }
compare_001()101         void compare_001()
102             {
103                 rtl::OString aStr1 = "";
104                 rtl::OString aStr2 = "";
105 
106                 sal_Int32 nValue = rtl_str_compareIgnoreAsciiCase( aStr1.getStr(), aStr2.getStr());
107                 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
108             }
109 
compare_002()110         void compare_002()
111             {
112                 rtl::OString aStr1 = "Line must be equal.";
113                 rtl::OString aStr2 = "Line must be equal.";
114 
115                 sal_Int32 nValue = rtl_str_compareIgnoreAsciiCase( aStr1.getStr(), aStr2.getStr());
116                 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
117             }
118 
compare_002_1()119         void compare_002_1()
120             {
121                 rtl::OString aStr1 = "Line must be equal.";
122                 rtl::OString aStr2 = "LINE MUST BE EQUAL.";
123 
124                 sal_Int32 nValue = rtl_str_compareIgnoreAsciiCase( aStr1.getStr(), aStr2.getStr());
125                 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal (if case insensitve).", nValue == 0);
126             }
127 
compare_003()128         void compare_003()
129             {
130                 rtl::OString aStr1 = "Line must differ.";
131                 rtl::OString aStr2 = "Line foo bar, ok, differ.";
132 
133                 sal_Int32 nValue = rtl_str_compareIgnoreAsciiCase( aStr1.getStr(), aStr2.getStr());
134                 CPPUNIT_ASSERT_MESSAGE("compare failed, strings differ.", nValue != 0);
135             }
136 
137     // Change the following lines only, if you add, remove or rename
138     // member functions of the current class,
139     // because these macros are need by auto register mechanism.
140 
141     CPPUNIT_TEST_SUITE(compareIgnoreAsciiCase);
142     CPPUNIT_TEST(compare_000);
143     CPPUNIT_TEST(compare_000_1);
144     CPPUNIT_TEST(compare_001);
145     CPPUNIT_TEST(compare_002);
146     CPPUNIT_TEST(compare_002_1);
147     CPPUNIT_TEST(compare_003);
148     CPPUNIT_TEST_SUITE_END();
149     }; // class compareIgnoreAsciiCase
150 
151 // -----------------------------------------------------------------------------
152 
153     class shortenedCompareIgnoreAsciiCase_WithLength : public CppUnit::TestFixture
154     {
155     public:
156 
compare_000()157         void compare_000()
158             {
159                 rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( NULL, 0, NULL, 0, 0);
160             }
161 
compare_000_1()162         void compare_000_1()
163             {
164                 rtl::OString aStr1 = "Line must be equal.";
165                 rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(), NULL, 0, 1);
166             }
compare_001()167         void compare_001()
168             {
169                 rtl::OString aStr1 = "";
170                 rtl::OString aStr2 = "";
171 
172                 sal_Int32 nValue = rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(), aStr2.getStr(), aStr2.getLength(), aStr1.getLength());
173                 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
174             }
175 
compare_002()176         void compare_002()
177             {
178                 rtl::OString aStr1 = "Line must be equal.";
179                 rtl::OString aStr2 = "Line must be equal.";
180 
181                 sal_Int32 nValue = rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(),
182                                                                                        aStr2.getStr(), aStr2.getLength(),
183                                                                                        aStr1.getLength());
184                 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
185             }
186 
compare_002_1()187         void compare_002_1()
188             {
189                 rtl::OString aStr1 = "Line must be equal.";
190                 rtl::OString aStr2 = "LINE MUST BE EQUAL.";
191 
192                 sal_Int32 nValue = rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(),
193                                                                                        aStr2.getStr(), aStr2.getLength(),
194                                                                                        aStr1.getLength());
195                 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal (if case insensitve).", nValue == 0);
196             }
197 
compare_003()198         void compare_003()
199             {
200                 rtl::OString aStr1 = "Line must differ.";
201                 rtl::OString aStr2 = "Line foo bar, ok, differ.";
202 
203                 sal_Int32 nValue = rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(),
204                                                                                        aStr2.getStr(), aStr2.getLength(),
205                                                                                        5);
206                 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal first 5 characters.", nValue == 0);
207             }
208 
compare_004()209         void compare_004()
210             {
211                 rtl::OString aStr1 = "Line must differ.";
212                 rtl::OString aStr2 = "Line foo bar, ok, differ.";
213 
214                 sal_Int32 nValue = rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(),
215                                                                                        aStr2.getStr(), aStr2.getLength(),
216                                                                                        aStr1.getLength());
217                 CPPUNIT_ASSERT_MESSAGE("compare failed, strings differ.", nValue != 0);
218             }
219 
220     // Change the following lines only, if you add, remove or rename
221     // member functions of the current class,
222     // because these macros are need by auto register mechanism.
223 
224     CPPUNIT_TEST_SUITE(shortenedCompareIgnoreAsciiCase_WithLength);
225     CPPUNIT_TEST(compare_000);
226     CPPUNIT_TEST(compare_000_1);
227     CPPUNIT_TEST(compare_001);
228     CPPUNIT_TEST(compare_002);
229     CPPUNIT_TEST(compare_002_1);
230     CPPUNIT_TEST(compare_003);
231     CPPUNIT_TEST(compare_004);
232     CPPUNIT_TEST_SUITE_END();
233 }; // class compare
234 
235 
236 // -----------------------------------------------------------------------------
237 
238     class hashCode : public CppUnit::TestFixture
239     {
240     public:
241 
hashCode_000()242         void hashCode_000()
243             {
244                 rtl_str_hashCode( NULL );
245             }
246 
hashCode_001()247         void hashCode_001()
248             {
249                 rtl::OString aStr1 = "Line for a hashCode.";
250                 sal_Int32 nHashCode = rtl_str_hashCode( aStr1.getStr() );
251                 t_print("hashcode: %d\n", nHashCode);
252                 // CPPUNIT_ASSERT_MESSAGE("failed.", nValue == 0);
253             }
254 
hashCode_002()255         void hashCode_002()
256             {
257                 rtl::OString aStr1 = "Line for a hashCode.";
258                 sal_Int32 nHashCode1 = rtl_str_hashCode( aStr1.getStr() );
259 
260                 rtl::OString aStr2 = "Line for a hashCode.";
261                 sal_Int32 nHashCode2 = rtl_str_hashCode( aStr2.getStr() );
262 
263                 CPPUNIT_ASSERT_MESSAGE("hashcodes must be equal.", nHashCode1 == nHashCode2 );
264             }
265 
hashCode_003()266         void hashCode_003()
267             {
268                 rtl::OString aStr1 = "Line for a hashCode.";
269                 sal_Int32 nHashCode1 = rtl_str_hashCode( aStr1.getStr() );
270 
271                 rtl::OString aStr2 = "Line for an other hashcode.";
272                 sal_Int32 nHashCode2 = rtl_str_hashCode( aStr2.getStr() );
273 
274                 CPPUNIT_ASSERT_MESSAGE("hashcodes must differ.", nHashCode1 != nHashCode2 );
275             }
276 
277         // Change the following lines only, if you add, remove or rename
278         // member functions of the current class,
279         // because these macros are need by auto register mechanism.
280 
281         CPPUNIT_TEST_SUITE(hashCode);
282         CPPUNIT_TEST(hashCode_000);
283         CPPUNIT_TEST(hashCode_001);
284         CPPUNIT_TEST(hashCode_002);
285         CPPUNIT_TEST(hashCode_003);
286         CPPUNIT_TEST_SUITE_END();
287     }; // class compare
288 
289 
290 // -----------------------------------------------------------------------------
291 
292     class indexOfChar : public CppUnit::TestFixture
293     {
294     public:
295 
indexOfChar_000()296         void indexOfChar_000()
297             {
298                 rtl_str_indexOfChar( NULL, 0 );
299             }
300 
indexOfChar_001()301         void indexOfChar_001()
302             {
303                 rtl::OString aStr1 = "Line for a indexOfChar.";
304 
305                 sal_Int32 nIndex = rtl_str_indexOfChar( aStr1.getStr(), 'L' );
306                 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 0);
307 
308                 /* sal_Int32 */ nIndex = rtl_str_indexOfChar( aStr1.getStr(), 'i' );
309                 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 1);
310 
311                 /* sal_Int32 */ nIndex = rtl_str_indexOfChar( aStr1.getStr(), 'n' );
312                 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 2);
313 
314                 /* sal_Int32 */ nIndex = rtl_str_indexOfChar( aStr1.getStr(), 'e' );
315                 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 3);
316             }
317 
indexOfChar_002()318         void indexOfChar_002()
319             {
320                 rtl::OString aStr1 = "Line for a indexOfChar.";
321                 sal_Int32 nIndex = rtl_str_indexOfChar( aStr1.getStr(), 'y' );
322 
323                 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == -1 );
324             }
325 
326         // Change the following lines only, if you add, remove or rename
327         // member functions of the current class,
328         // because these macros are need by auto register mechanism.
329 
330         CPPUNIT_TEST_SUITE(indexOfChar);
331         CPPUNIT_TEST(indexOfChar_000);
332         CPPUNIT_TEST(indexOfChar_001);
333         CPPUNIT_TEST(indexOfChar_002);
334         CPPUNIT_TEST_SUITE_END();
335     }; // class compare
336 
337 // -----------------------------------------------------------------------------
338     class lastIndexOfChar : public CppUnit::TestFixture
339     {
340     public:
341 
lastIndexOfChar_000()342         void lastIndexOfChar_000()
343             {
344                 rtl_str_lastIndexOfChar( NULL, 0 );
345             }
346 
lastIndexOfChar_001()347         void lastIndexOfChar_001()
348             {
349                 rtl::OString aStr1 = "Line for a lastIndexOfChar.";
350 
351                 sal_Int32 nIndex = rtl_str_lastIndexOfChar( aStr1.getStr(), 'C' );
352                 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 22);
353 
354                 /* sal_Int32 */ nIndex = rtl_str_lastIndexOfChar( aStr1.getStr(), 'h' );
355                 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 23);
356 
357                 /* sal_Int32 */ nIndex = rtl_str_lastIndexOfChar( aStr1.getStr(), 'a' );
358                 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 24);
359 
360                 /* sal_Int32 */ nIndex = rtl_str_lastIndexOfChar( aStr1.getStr(), 'r' );
361                 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 25);
362             }
363 
lastIndexOfChar_002()364         void lastIndexOfChar_002()
365             {
366                 rtl::OString aStr1 = "Line for a lastIndexOfChar.";
367                 sal_Int32 nIndex = rtl_str_lastIndexOfChar( aStr1.getStr(), 'y' );
368 
369                 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == -1 );
370             }
371 
372         // Change the following lines only, if you add, remove or rename
373         // member functions of the current class,
374         // because these macros are need by auto register mechanism.
375 
376         CPPUNIT_TEST_SUITE(lastIndexOfChar);
377         CPPUNIT_TEST(lastIndexOfChar_000);
378         CPPUNIT_TEST(lastIndexOfChar_001);
379         CPPUNIT_TEST(lastIndexOfChar_002);
380         CPPUNIT_TEST_SUITE_END();
381     }; // class lastIndexOfChar
382 
383 
384 // -----------------------------------------------------------------------------
385 
386     class indexOfStr : public CppUnit::TestFixture
387     {
388     public:
389 
indexOfStr_000()390         void indexOfStr_000()
391             {
392                 rtl_str_indexOfStr( NULL, 0 );
393             }
394 
indexOfStr_000_1()395         void indexOfStr_000_1()
396             {
397                 rtl::OString aStr1 = "Line for a indexOfStr.";
398                 rtl_str_indexOfStr( aStr1.getStr(), 0 );
399             }
400 
indexOfStr_001()401         void indexOfStr_001()
402             {
403                 rtl::OString aStr1 = "Line for a indexOfStr.";
404 
405                 sal_Int32 nIndex = rtl_str_indexOfStr( aStr1.getStr(), "Line" );
406                 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 0);
407 
408                 /* sal_Int32 */ nIndex = rtl_str_indexOfStr( aStr1.getStr(), "for" );
409                 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 5);
410 
411                 /* sal_Int32 */ nIndex = rtl_str_indexOfStr( aStr1.getStr(), "a" );
412                 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 9);
413 
414                 /* sal_Int32 */ nIndex = rtl_str_indexOfStr( aStr1.getStr(), "a index" );
415                 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex ==9);
416             }
417 
indexOfStr_002()418         void indexOfStr_002()
419             {
420                 rtl::OString aStr1 = "Line for a indexOfStr.";
421                 sal_Int32 nIndex = rtl_str_indexOfStr( aStr1.getStr(), "not exist" );
422 
423                 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == -1 );
424             }
425 
426         // Change the following lines only, if you add, remove or rename
427         // member functions of the current class,
428         // because these macros are need by auto register mechanism.
429 
430         CPPUNIT_TEST_SUITE(indexOfStr);
431         CPPUNIT_TEST(indexOfStr_000);
432         CPPUNIT_TEST(indexOfStr_001);
433         CPPUNIT_TEST(indexOfStr_002);
434         CPPUNIT_TEST_SUITE_END();
435     }; // class compare
436 // -----------------------------------------------------------------------------
437 
438 
439     class lastIndexOfStr : public CppUnit::TestFixture
440     {
441     public:
442 
lastIndexOfStr_000()443         void lastIndexOfStr_000()
444             {
445                 rtl_str_lastIndexOfStr( NULL, NULL );
446             }
447 
lastIndexOfStr_000_1()448         void lastIndexOfStr_000_1()
449             {
450                 rtl::OString aStr1 = "Line for a lastIndexOfStr.";
451                 rtl_str_lastIndexOfStr( aStr1.getStr(), NULL );
452             }
453 
lastIndexOfStr_001()454         void lastIndexOfStr_001()
455             {
456                 rtl::OString aStr1 = "Line for a lastIndexOfStr.";
457                 rtl::OString aSearchStr = "Index";
458 
459                 sal_Int32 nIndex = rtl_str_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() );
460                 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 15);
461 
462                 /* rtl::OString */ aSearchStr = "Line";
463                 /* sal_Int32 */ nIndex = rtl_str_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() );
464                 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 0);
465 
466                 /* rtl::OString */ aSearchStr = "";
467                 /* sal_Int32 */ nIndex = rtl_str_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() );
468                 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == -1);
469             }
470 
lastIndexOfStr_002()471         void lastIndexOfStr_002()
472             {
473                 rtl::OString aStr1 = "Line for a lastIndexOfStr.";
474                 rtl::OString aSearchStr = "foo";
475                 sal_Int32 nIndex = rtl_str_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() );
476 
477                 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == -1 );
478             }
479 
lastIndexOfStr_003()480         void lastIndexOfStr_003()
481             {
482                 rtl::OString aStr1 = "Line for a lastIndexOfStr.";
483                 rtl::OString aSearchStr = "O";
484                 sal_Int32 nIndex = rtl_str_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() );
485 
486                 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 20 );
487             }
488 
489         // Change the following lines only, if you add, remove or rename
490         // member functions of the current class,
491         // because these macros are need by auto register mechanism.
492 
493         CPPUNIT_TEST_SUITE(lastIndexOfStr);
494         CPPUNIT_TEST(lastIndexOfStr_000);
495         CPPUNIT_TEST(lastIndexOfStr_001);
496         CPPUNIT_TEST(lastIndexOfStr_002);
497         CPPUNIT_TEST(lastIndexOfStr_003);
498         CPPUNIT_TEST_SUITE_END();
499     }; // class lastIndexOfStr
500 
501 // -----------------------------------------------------------------------------
502 
503     class replaceChar : public CppUnit::TestFixture
504     {
505     public:
506 
replaceChar_000()507         void replaceChar_000()
508             {
509                 rtl_str_replaceChar( NULL, 0, 0 );
510             }
511 
replaceChar_001()512         void replaceChar_001()
513             {
514                 rtl::OString aStr1 = "replace char.";
515                 rtl::OString aShouldStr1 = "ruplacu char.";
516 
517                 sal_Char* pStr = (sal_Char*) malloc(aStr1.getLength() + 1);
518                 CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL);
519                 strcpy(pStr, aStr1.getStr());
520 
521                 rtl_str_replaceChar( pStr, 'e', 'u' );
522 
523                 CPPUNIT_ASSERT_MESSAGE("replace failed", aShouldStr1.equals(rtl::OString(pStr)) == sal_True);
524                 free(pStr);
525             }
526 
527         // Change the following lines only, if you add, remove or rename
528         // member functions of the current class,
529         // because these macros are need by auto register mechanism.
530 
531         CPPUNIT_TEST_SUITE(replaceChar);
532         CPPUNIT_TEST(replaceChar_000);
533         CPPUNIT_TEST(replaceChar_001);
534         CPPUNIT_TEST_SUITE_END();
535     }; // class replaceChar
536 
537 // -----------------------------------------------------------------------------
538 
539     class replaceChar_WithLength : public CppUnit::TestFixture
540     {
541     public:
542 
replaceChar_WithLength_000()543         void replaceChar_WithLength_000()
544             {
545                 rtl_str_replaceChar_WithLength( NULL, 0, 0, 0 );
546             }
547 
replaceChar_WithLength_000_1()548         void replaceChar_WithLength_000_1()
549             {
550                 rtl_str_replaceChar_WithLength( NULL, 1, 0, 0 );
551             }
replaceChar_WithLength_001()552         void replaceChar_WithLength_001()
553             {
554                 rtl::OString aStr1 = "replace char.";
555                 rtl::OString aShouldStr1 = "ruplace char.";
556 
557                 sal_Char* pStr = (sal_Char*) malloc(aStr1.getLength() + 1);
558                 CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL);
559                 strcpy(pStr, aStr1.getStr());
560 
561                 rtl_str_replaceChar_WithLength( pStr, 6, 'e', 'u' );
562 
563                 CPPUNIT_ASSERT_MESSAGE("replace failed", aShouldStr1.equals(rtl::OString(pStr)) == sal_True);
564                 free(pStr);
565             }
566 
567         // Change the following lines only, if you add, remove or rename
568         // member functions of the current class,
569         // because these macros are need by auto register mechanism.
570 
571         CPPUNIT_TEST_SUITE(replaceChar_WithLength);
572         CPPUNIT_TEST(replaceChar_WithLength_000);
573         CPPUNIT_TEST(replaceChar_WithLength_000_1);
574         CPPUNIT_TEST(replaceChar_WithLength_001);
575         CPPUNIT_TEST_SUITE_END();
576     }; // class replaceChar
577 
578 
579 // -----------------------------------------------------------------------------
580 
581     class toAsciiLowerCase : public CppUnit::TestFixture
582     {
583     public:
584 
toAsciiLowerCase_000()585         void toAsciiLowerCase_000()
586             {
587                 rtl_str_toAsciiLowerCase( NULL );
588             }
589 
toAsciiLowerCase_001()590         void toAsciiLowerCase_001()
591             {
592                 rtl::OString aStr1 = "CHANGE THIS TO ASCII LOWER CASE.";
593                 rtl::OString aShouldStr1 = "change this to ascii lower case.";
594 
595                 sal_Char* pStr = (sal_Char*) malloc(aStr1.getLength() + 1);
596                 CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL);
597                 strcpy(pStr, aStr1.getStr());
598 
599                 rtl_str_toAsciiLowerCase( pStr );
600 
601                 CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1.equals(rtl::OString(pStr)) == sal_True);
602                 free(pStr);
603             }
604 
605         // Change the following lines only, if you add, remove or rename
606         // member functions of the current class,
607         // because these macros are need by auto register mechanism.
608 
609         CPPUNIT_TEST_SUITE(toAsciiLowerCase);
610         CPPUNIT_TEST(toAsciiLowerCase_000);
611         CPPUNIT_TEST(toAsciiLowerCase_001);
612         CPPUNIT_TEST_SUITE_END();
613     }; // class replaceChar
614 
615 
616     class toAsciiLowerCase_WithLength : public CppUnit::TestFixture
617     {
618     public:
619 
toAsciiLowerCase_WithLength_000()620         void toAsciiLowerCase_WithLength_000()
621             {
622                 rtl_str_toAsciiLowerCase_WithLength( NULL, 0 );
623             }
624 
toAsciiLowerCase_WithLength_001()625         void toAsciiLowerCase_WithLength_001()
626             {
627                 rtl::OString aStr1 = "CHANGE THIS TO ASCII LOWER CASE.";
628                 rtl::OString aShouldStr1 = "change thiS TO ASCII LOWER CASE.";
629 
630                 sal_Char* pStr = (sal_Char*) malloc(aStr1.getLength() + 1);
631                 CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL);
632                 strcpy(pStr, aStr1.getStr());
633 
634                 rtl_str_toAsciiLowerCase_WithLength( pStr, 10 );
635 
636                 t_print("Lowercase with length: '%s'\n", pStr);
637                 CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1.equals(rtl::OString(pStr)) == sal_True);
638                 free(pStr);
639             }
640 
641         // Change the following lines only, if you add, remove or rename
642         // member functions of the current class,
643         // because these macros are need by auto register mechanism.
644 
645         CPPUNIT_TEST_SUITE(toAsciiLowerCase_WithLength);
646         CPPUNIT_TEST(toAsciiLowerCase_WithLength_000);
647         CPPUNIT_TEST(toAsciiLowerCase_WithLength_001);
648         CPPUNIT_TEST_SUITE_END();
649     }; // class replaceChar
650 
651 // -----------------------------------------------------------------------------
652 
653     class toAsciiUpperCase : public CppUnit::TestFixture
654     {
655     public:
656 
toAsciiUpperCase_000()657         void toAsciiUpperCase_000()
658             {
659                 rtl_str_toAsciiUpperCase( NULL );
660             }
661 
toAsciiUpperCase_001()662         void toAsciiUpperCase_001()
663             {
664                 rtl::OString aStr1 = "change this to ascii upper case.";
665                 rtl::OString aShouldStr1 = "CHANGE THIS TO ASCII UPPER CASE.";
666 
667                 sal_Char* pStr = (sal_Char*) malloc(aStr1.getLength() + 1);
668                 CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL);
669                 strcpy(pStr, aStr1.getStr());
670 
671                 rtl_str_toAsciiUpperCase( pStr );
672 
673                 CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1.equals(rtl::OString(pStr)) == sal_True);
674                 free(pStr);
675             }
676 
677         // Change the following lines only, if you add, remove or rename
678         // member functions of the current class,
679         // because these macros are need by auto register mechanism.
680 
681         CPPUNIT_TEST_SUITE(toAsciiUpperCase);
682         CPPUNIT_TEST(toAsciiUpperCase_000);
683         CPPUNIT_TEST(toAsciiUpperCase_001);
684         CPPUNIT_TEST_SUITE_END();
685     }; // class replaceChar
686 
687 
688     class toAsciiUpperCase_WithLength : public CppUnit::TestFixture
689     {
690     public:
691 
toAsciiUpperCase_WithLength_000()692         void toAsciiUpperCase_WithLength_000()
693             {
694                 rtl_str_toAsciiUpperCase_WithLength( NULL, 0 );
695             }
696 
toAsciiUpperCase_WithLength_001()697         void toAsciiUpperCase_WithLength_001()
698             {
699                 rtl::OString aStr1 = "change this to ascii lower case.";
700                 rtl::OString aShouldStr1 = "CHANGE THIs to ascii lower case.";
701 
702                 sal_Char* pStr = (sal_Char*) malloc(aStr1.getLength() + 1);
703                 CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL);
704 
705                 strcpy(pStr, aStr1.getStr());
706                 rtl_str_toAsciiUpperCase_WithLength( pStr, 10 );
707 
708                 t_print("Uppercase with length: '%s'\n", aStr1.getStr());
709                 CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1.equals(rtl::OString(pStr)) == sal_True);
710                 free(pStr);
711             }
712 
713         // Change the following lines only, if you add, remove or rename
714         // member functions of the current class,
715         // because these macros are need by auto register mechanism.
716 
717         CPPUNIT_TEST_SUITE(toAsciiUpperCase_WithLength);
718         CPPUNIT_TEST(toAsciiUpperCase_WithLength_000);
719         CPPUNIT_TEST(toAsciiUpperCase_WithLength_001);
720         CPPUNIT_TEST_SUITE_END();
721     }; // class replaceChar
722 
723 
724     // -----------------------------------------------------------------------------
725 
726     class trim_WithLength : public CppUnit::TestFixture
727     {
728       public:
trim_WithLength_000()729         void trim_WithLength_000()
730         {
731             rtl_str_trim_WithLength(NULL, 0);
732             // should not GPF
733         }
734 
trim_WithLength_000_1()735         void trim_WithLength_000_1()
736         {
737             char pStr[] = { "  trim this" };
738             rtl_str_trim_WithLength( pStr, 0 );
739         }
740 
trim_WithLength_001()741         void trim_WithLength_001()
742         {
743             char const *pStr = "  trim this";
744             sal_Char *pStr2 = (sal_Char*)malloc(strlen(pStr) + 1);
745             if (pStr2)
746             {
747                 strcpy(pStr2, pStr);
748                 rtl_str_trim_WithLength( pStr2, 2 );
749 
750                 CPPUNIT_ASSERT_MESSAGE("string should be empty", strlen(pStr2) == 0);
751                 free(pStr2);
752             }
753         }
754 
trim_WithLength_002()755         void trim_WithLength_002()
756         {
757             char const *pStr = "trim this";
758             sal_Char *pStr2 = (sal_Char*)malloc(strlen(pStr) + 1);
759             if (pStr2)
760             {
761                 strcpy(pStr2, pStr);
762                 rtl_str_trim_WithLength( pStr2, 5 );
763 
764                 CPPUNIT_ASSERT_MESSAGE("string should contain 'trim'", strlen(pStr2) == 4);
765                 free(pStr2);
766             }
767         }
768 
trim_WithLength_003()769         void trim_WithLength_003()
770         {
771             char const *pStr = "     trim   this";
772             sal_Char *pStr2 = (sal_Char*)malloc(strlen(pStr) + 1);
773             if (pStr2)
774             {
775                 strcpy(pStr2, pStr);
776                 rtl_str_trim_WithLength( pStr2, 11 );
777 
778                 CPPUNIT_ASSERT_MESSAGE("string should contain 'trim'", strlen(pStr2) == 4);
779                 free(pStr2);
780             }
781         }
782 
trim_WithLength_004()783         void trim_WithLength_004()
784         {
785             char const *pStr = "\r\n\t \n\r    trim  \n this";
786             sal_Char *pStr2 = (sal_Char*)malloc(strlen(pStr) + 1);
787             if (pStr2)
788             {
789                 strcpy(pStr2, pStr);
790                 rtl_str_trim_WithLength( pStr2, 17 );
791 
792                 CPPUNIT_ASSERT_MESSAGE("string should contain 'trim'", strlen(pStr2) == 4);
793                 free(pStr2);
794             }
795         }
796 
trim_WithLength_005()797         void trim_WithLength_005()
798         {
799             char const *pStr = "\r\n\t \n\r    trim \t this \n\r\t\t     ";
800             sal_Char *pStr2 = (sal_Char*)malloc(strlen(pStr) + 1);
801             if (pStr2)
802             {
803                 strcpy(pStr2, pStr);
804                 rtl_str_trim_WithLength( pStr2, strlen(pStr2) );
805 
806                 CPPUNIT_ASSERT_MESSAGE("string should contain 'trim'", strlen(pStr2) == 11);
807                 free(pStr2);
808             }
809         }
810 
811         // Change the following lines only, if you add, remove or rename
812         // member functions of the current class,
813         // because these macros are need by auto register mechanism.
814 
815         CPPUNIT_TEST_SUITE(trim_WithLength);
816         CPPUNIT_TEST(trim_WithLength_000);
817         CPPUNIT_TEST(trim_WithLength_000_1);
818         CPPUNIT_TEST(trim_WithLength_001);
819         CPPUNIT_TEST(trim_WithLength_002);
820         CPPUNIT_TEST(trim_WithLength_003);
821         CPPUNIT_TEST(trim_WithLength_004);
822         CPPUNIT_TEST(trim_WithLength_005);
823         CPPUNIT_TEST_SUITE_END();
824     };
825 
826     // -----------------------------------------------------------------------------
827 
828     class valueOfChar : public CppUnit::TestFixture
829     {
830       public:
valueOfChar_000()831         void valueOfChar_000()
832             {
833                 rtl_str_valueOfChar(NULL, 0);
834                 // should not GPF
835             }
valueOfChar_001()836         void valueOfChar_001()
837             {
838                 sal_Char *pStr = (sal_Char*)malloc(RTL_STR_MAX_VALUEOFCHAR);
839                 if (pStr)
840                 {
841                     rtl_str_valueOfChar(pStr, 'A');
842 
843                     CPPUNIT_ASSERT_MESSAGE("string should contain 'A'", pStr[0] == 'A');
844                     free(pStr);
845                 }
846             }
847 
848         // Change the following lines only, if you add, remove or rename
849         // member functions of the current class,
850         // because these macros are need by auto register mechanism.
851 
852         CPPUNIT_TEST_SUITE(valueOfChar);
853         CPPUNIT_TEST(valueOfChar_000);
854         CPPUNIT_TEST(valueOfChar_001);
855         CPPUNIT_TEST_SUITE_END();
856     };
857 
858 // -----------------------------------------------------------------------------
859 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::compare, "rtl_str");
860 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::compareIgnoreAsciiCase, "rtl_str");
861 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::shortenedCompareIgnoreAsciiCase_WithLength, "rtl_str");
862 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::hashCode, "rtl_str");
863 
864 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::indexOfChar, "rtl_str");
865 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::lastIndexOfChar, "rtl_str");
866 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::indexOfStr, "rtl_str");
867 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::lastIndexOfStr, "rtl_str");
868 
869 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::replaceChar, "rtl_str");
870 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::replaceChar_WithLength, "rtl_str");
871 
872 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::toAsciiLowerCase, "rtl_str");
873 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::toAsciiLowerCase_WithLength, "rtl_str");
874 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::toAsciiUpperCase, "rtl_str");
875 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::toAsciiUpperCase_WithLength, "rtl_str");
876 
877 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::trim_WithLength, "rtl_str");
878 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_str::valueOfChar, "rtl_str");
879 
880 } // namespace rtl_str
881 
882 // -----------------------------------------------------------------------------
883 
884 // this macro creates an empty function, which will called by the RegisterAllFunctions()
885 // to let the user the possibility to also register some functions by hand.
886 NOADDITIONAL;
887