xref: /aoo4110/main/sal/qa/rtl/oustring/rtl_ustr.cxx (revision b1cdbd2c)
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 /** print a UNI_CODE file name.
30 */
printOUString(::rtl::OUString const & _suStr)31 inline void printOUString( ::rtl::OUString const & _suStr )
32 {
33     rtl::OString aString;
34 
35     t_print( "OUString: " );
36     aString = ::rtl::OUStringToOString( _suStr, RTL_TEXTENCODING_ASCII_US );
37     t_print( "%s\n", aString.getStr( ) );
38 }
39 
40 
41 namespace rtl_ustr
42 {
43 
44     class compare : public CppUnit::TestFixture
45     {
46     public:
47 
48 
compare_000()49         void compare_000()
50             {
51                 rtl_ustr_compare( NULL, NULL);
52                 // should not GPF
53             }
54 
compare_000_1()55         void compare_000_1()
56             {
57                 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal.");
58                 rtl_ustr_compare( aStr1.getStr(), NULL);
59                 // should not GPF
60             }
compare_001()61         void compare_001()
62             {
63                 rtl::OUString aStr1;
64                 rtl::OUString aStr2;
65 
66                 sal_Int32 nValue = rtl_ustr_compare( aStr1.getStr(), aStr2.getStr());
67                 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
68             }
69 
compare_002()70         void compare_002()
71             {
72                 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal.");
73                 rtl::OUString aStr2 = rtl::OUString::createFromAscii("Line must be equal.");
74 
75                 sal_Int32 nValue = rtl_ustr_compare( aStr1.getStr(), aStr2.getStr());
76                 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
77             }
78 
compare_003()79         void compare_003()
80             {
81                 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must differ.");
82                 rtl::OUString aStr2 = rtl::OUString::createFromAscii("Line foo bar, ok, differ.");
83 
84                 sal_Int32 nValue = rtl_ustr_compare( aStr1.getStr(), aStr2.getStr());
85                 CPPUNIT_ASSERT_MESSAGE("compare failed, strings differ.", nValue != 0);
86             }
87 
88     // Change the following lines only, if you add, remove or rename
89     // member functions of the current class,
90     // because these macros are need by auto register mechanism.
91 
92     CPPUNIT_TEST_SUITE(compare);
93     CPPUNIT_TEST(compare_000);
94     CPPUNIT_TEST(compare_000_1);
95     CPPUNIT_TEST(compare_001);
96     CPPUNIT_TEST(compare_002);
97     CPPUNIT_TEST(compare_003);
98     CPPUNIT_TEST_SUITE_END();
99 }; // class compare
100 
101 
102     class compareIgnoreAsciiCase : public CppUnit::TestFixture
103     {
104     public:
105 
compare_000()106         void compare_000()
107             {
108                 rtl_ustr_compareIgnoreAsciiCase( NULL, NULL);
109             }
110 
compare_000_1()111         void compare_000_1()
112             {
113                 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal.");
114                 rtl_ustr_compareIgnoreAsciiCase( aStr1.getStr(), NULL);
115             }
compare_001()116         void compare_001()
117             {
118                 rtl::OUString aStr1;
119                 rtl::OUString aStr2;
120 
121                 sal_Int32 nValue = rtl_ustr_compareIgnoreAsciiCase( aStr1.getStr(), aStr2.getStr());
122                 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
123             }
124 
compare_002()125         void compare_002()
126             {
127                 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal.");
128                 rtl::OUString aStr2 = rtl::OUString::createFromAscii("Line must be equal.");
129 
130                 sal_Int32 nValue = rtl_ustr_compareIgnoreAsciiCase( aStr1.getStr(), aStr2.getStr());
131                 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
132             }
133 
compare_002_1()134         void compare_002_1()
135             {
136                 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal.");
137                 rtl::OUString aStr2 = rtl::OUString::createFromAscii("LINE MUST BE EQUAL.");
138 
139                 sal_Int32 nValue = rtl_ustr_compareIgnoreAsciiCase( aStr1.getStr(), aStr2.getStr());
140                 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal (if case insensitve).", nValue == 0);
141             }
142 
compare_003()143         void compare_003()
144             {
145                 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must differ.");
146                 rtl::OUString aStr2 = rtl::OUString::createFromAscii("Line foo bar, ok, differ.");
147 
148                 sal_Int32 nValue = rtl_ustr_compareIgnoreAsciiCase( aStr1.getStr(), aStr2.getStr());
149                 CPPUNIT_ASSERT_MESSAGE("compare failed, strings differ.", nValue != 0);
150             }
151 
152     // Change the following lines only, if you add, remove or rename
153     // member functions of the current class,
154     // because these macros are need by auto register mechanism.
155 
156     CPPUNIT_TEST_SUITE(compareIgnoreAsciiCase);
157     CPPUNIT_TEST(compare_000);
158     CPPUNIT_TEST(compare_000_1);
159     CPPUNIT_TEST(compare_001);
160     CPPUNIT_TEST(compare_002);
161     CPPUNIT_TEST(compare_002_1);
162     CPPUNIT_TEST(compare_003);
163     CPPUNIT_TEST_SUITE_END();
164     }; // class compareIgnoreAsciiCase
165 
166 // -----------------------------------------------------------------------------
167 
168     class shortenedCompareIgnoreAsciiCase_WithLength : public CppUnit::TestFixture
169     {
170     public:
171 
compare_000()172         void compare_000()
173             {
174                 rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( NULL, 0, NULL, 0, 0);
175             }
176 
compare_000_1()177         void compare_000_1()
178             {
179                 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal.");
180                 rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(), NULL, 0, 1);
181             }
compare_001()182         void compare_001()
183             {
184                 rtl::OUString aStr1;
185                 rtl::OUString aStr2;
186 
187                 sal_Int32 nValue = rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(), aStr2.getStr(), aStr2.getLength(), aStr1.getLength());
188                 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
189             }
190 
compare_002()191         void compare_002()
192             {
193                 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal.");
194                 rtl::OUString aStr2 = rtl::OUString::createFromAscii("Line must be equal.");
195 
196                 sal_Int32 nValue = rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(),
197                                                                                        aStr2.getStr(), aStr2.getLength(),
198                                                                                        aStr1.getLength());
199                 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
200             }
201 
compare_002_1()202         void compare_002_1()
203             {
204                 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal.");
205                 rtl::OUString aStr2 = rtl::OUString::createFromAscii("LINE MUST BE EQUAL.");
206 
207                 sal_Int32 nValue = rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(),
208                                                                                        aStr2.getStr(), aStr2.getLength(),
209                                                                                        aStr1.getLength());
210                 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal (if case insensitve).", nValue == 0);
211             }
212 
compare_003()213         void compare_003()
214             {
215                 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must differ.");
216                 rtl::OUString aStr2 = rtl::OUString::createFromAscii("Line foo bar, ok, differ.");
217 
218                 sal_Int32 nValue = rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(),
219                                                                                        aStr2.getStr(), aStr2.getLength(),
220                                                                                        5);
221                 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal first 5 characters.", nValue == 0);
222             }
223 
compare_004()224         void compare_004()
225             {
226                 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must differ.");
227                 rtl::OUString aStr2 = rtl::OUString::createFromAscii("Line foo bar, ok, differ.");
228 
229                 sal_Int32 nValue = rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(),
230                                                                                        aStr2.getStr(), aStr2.getLength(),
231                                                                                        aStr1.getLength());
232                 CPPUNIT_ASSERT_MESSAGE("compare failed, strings differ.", nValue != 0);
233             }
234 
235     // Change the following lines only, if you add, remove or rename
236     // member functions of the current class,
237     // because these macros are need by auto register mechanism.
238 
239     CPPUNIT_TEST_SUITE(shortenedCompareIgnoreAsciiCase_WithLength);
240     CPPUNIT_TEST(compare_000);
241     CPPUNIT_TEST(compare_000_1);
242     CPPUNIT_TEST(compare_001);
243     CPPUNIT_TEST(compare_002);
244     CPPUNIT_TEST(compare_002_1);
245     CPPUNIT_TEST(compare_003);
246     CPPUNIT_TEST(compare_004);
247     CPPUNIT_TEST_SUITE_END();
248 }; // class compare
249 
250 
251 // // -----------------------------------------------------------------------------
252 //
253 //     class hashCode : public CppUnit::TestFixture
254 //     {
255 //     public:
256 //
257 //         void hashCode_000()
258 //             {
259 //                 sal_Int32 nHashCode = rtl_ustr_hashCode( NULL );
260 //                 volatile int dummy = 0;
261 //             }
262 //
263 //         void hashCode_001()
264 //             {
265 //                 rtl::OString aStr1 = "Line for a hashCode.";
266 //                 sal_Int32 nHashCode = rtl_ustr_hashCode( aStr1.getStr() );
267 //                 t_print("hashcode: %d\n", nHashCode);
268 //                 // CPPUNIT_ASSERT_MESSAGE("failed.", nValue == 0);
269 //             }
270 //
271 //         void hashCode_002()
272 //             {
273 //                 rtl::OString aStr1 = "Line for a hashCode.";
274 //                 sal_Int32 nHashCode1 = rtl_ustr_hashCode( aStr1.getStr() );
275 //
276 //                 rtl::OString aStr2 = "Line for a hashCode.";
277 //                 sal_Int32 nHashCode2 = rtl_ustr_hashCode( aStr2.getStr() );
278 //
279 //                 CPPUNIT_ASSERT_MESSAGE("hashcodes must be equal.", nHashCode1 == nHashCode2 );
280 //             }
281 //
282 //         void hashCode_003()
283 //             {
284 //                 rtl::OString aStr1 = "Line for a hashCode.";
285 //                 sal_Int32 nHashCode1 = rtl_ustr_hashCode( aStr1.getStr() );
286 //
287 //                 rtl::OString aStr2 = "Line for an other hashcode.";
288 //                 sal_Int32 nHashCode2 = rtl_ustr_hashCode( aStr2.getStr() );
289 //
290 //                 CPPUNIT_ASSERT_MESSAGE("hashcodes must differ.", nHashCode1 != nHashCode2 );
291 //             }
292 //
293 //         // Change the following lines only, if you add, remove or rename
294 //         // member functions of the current class,
295 //         // because these macros are need by auto register mechanism.
296 //
297 //         CPPUNIT_TEST_SUITE(hashCode);
298 //         CPPUNIT_TEST(hashCode_000);
299 //         CPPUNIT_TEST(hashCode_001);
300 //         CPPUNIT_TEST(hashCode_002);
301 //         CPPUNIT_TEST(hashCode_003);
302 //         CPPUNIT_TEST_SUITE_END();
303 //     }; // class compare
304 //
305 //
306 // // -----------------------------------------------------------------------------
307 //
308     class indexOfChar : public CppUnit::TestFixture
309     {
310     public:
311 
indexOfChar_000()312         void indexOfChar_000()
313             {
314                 rtl_ustr_indexOfChar( NULL, 0 );
315             }
316 
indexOfChar_001()317         void indexOfChar_001()
318             {
319                 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a indexOfChar.");
320 
321                 sal_Int32 nIndex = rtl_ustr_indexOfChar( aStr1.getStr(), 'L' );
322                 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 0);
323 
324                 /* sal_Int32 */ nIndex = rtl_ustr_indexOfChar( aStr1.getStr(), 'i' );
325                 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 1);
326 
327                 /* sal_Int32 */ nIndex = rtl_ustr_indexOfChar( aStr1.getStr(), 'n' );
328                 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 2);
329 
330                 /* sal_Int32 */ nIndex = rtl_ustr_indexOfChar( aStr1.getStr(), 'e' );
331                 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 3);
332             }
333 
indexOfChar_002()334         void indexOfChar_002()
335             {
336                 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a indexOfChar.");
337                 sal_Int32 nIndex = rtl_ustr_indexOfChar( aStr1.getStr(), 'y' );
338 
339                 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == -1 );
340             }
341 
342         // Change the following lines only, if you add, remove or rename
343         // member functions of the current class,
344         // because these macros are need by auto register mechanism.
345 
346         CPPUNIT_TEST_SUITE(indexOfChar);
347         CPPUNIT_TEST(indexOfChar_000);
348         CPPUNIT_TEST(indexOfChar_001);
349         CPPUNIT_TEST(indexOfChar_002);
350         CPPUNIT_TEST_SUITE_END();
351     }; // class indexOfChar
352 
353 // // -----------------------------------------------------------------------------
354     class lastIndexOfChar : public CppUnit::TestFixture
355     {
356     public:
357 
lastIndexOfChar_000()358         void lastIndexOfChar_000()
359             {
360                 rtl_ustr_lastIndexOfChar( NULL, 0 );
361             }
362 
lastIndexOfChar_001()363         void lastIndexOfChar_001()
364             {
365                 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a lastIndexOfChar.");
366 
367                 sal_Int32 nIndex = rtl_ustr_lastIndexOfChar( aStr1.getStr(), 'C' );
368                 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 22);
369 
370                 /* sal_Int32 */ nIndex = rtl_ustr_lastIndexOfChar( aStr1.getStr(), 'h' );
371                 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 23);
372 
373                 /* sal_Int32 */ nIndex = rtl_ustr_lastIndexOfChar( aStr1.getStr(), 'a' );
374                 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 24);
375 
376                 /* sal_Int32 */ nIndex = rtl_ustr_lastIndexOfChar( aStr1.getStr(), 'r' );
377                 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 25);
378             }
379 
lastIndexOfChar_002()380         void lastIndexOfChar_002()
381             {
382                 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a lastIndexOfChar.");
383                 sal_Int32 nIndex = rtl_ustr_lastIndexOfChar( aStr1.getStr(), 'y' );
384 
385                 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == -1 );
386             }
387 
388         // Change the following lines only, if you add, remove or rename
389         // member functions of the current class,
390         // because these macros are need by auto register mechanism.
391 
392         CPPUNIT_TEST_SUITE(lastIndexOfChar);
393         CPPUNIT_TEST(lastIndexOfChar_000);
394         CPPUNIT_TEST(lastIndexOfChar_001);
395         CPPUNIT_TEST(lastIndexOfChar_002);
396         CPPUNIT_TEST_SUITE_END();
397     }; // class lastIndexOfChar
398 
399 
400 // -----------------------------------------------------------------------------
401 
402     class indexOfStr : public CppUnit::TestFixture
403     {
404     public:
405 
indexOfStr_000()406         void indexOfStr_000()
407             {
408                 rtl_ustr_indexOfStr( NULL, 0 );
409             }
410 
indexOfStr_000_1()411         void indexOfStr_000_1()
412             {
413                 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a indexOfStr.");
414                 rtl_ustr_indexOfStr( aStr1.getStr(), 0 );
415             }
416 
indexOfStr_001()417         void indexOfStr_001()
418             {
419                 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a indexOfStr.");
420 
421                 rtl::OUString suSearch = rtl::OUString::createFromAscii("Line");
422                 sal_Int32 nIndex = rtl_ustr_indexOfStr( aStr1.getStr(), suSearch );
423                 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 0);
424 
425                 /* rtl::OUString */ suSearch = rtl::OUString::createFromAscii("for");
426                 /* sal_Int32 */ nIndex = rtl_ustr_indexOfStr( aStr1.getStr(), suSearch );
427                 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 5);
428 
429                 /* rtl::OUString */ suSearch = rtl::OUString::createFromAscii("a");
430                 /* sal_Int32 */ nIndex = rtl_ustr_indexOfStr( aStr1.getStr(), suSearch );
431                 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 9);
432 
433                 /* rtl::OUString */ suSearch = rtl::OUString::createFromAscii("a index");
434                 /* sal_Int32 */ nIndex = rtl_ustr_indexOfStr( aStr1.getStr(), suSearch );
435                 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex ==9);
436             }
437 
indexOfStr_002()438         void indexOfStr_002()
439             {
440                 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a indexOfStr.");
441                 rtl::OUString suSearch = rtl::OUString::createFromAscii("not exist");
442                 sal_Int32 nIndex = rtl_ustr_indexOfStr( aStr1.getStr(), suSearch );
443 
444                 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == -1 );
445             }
446 
447         // Change the following lines only, if you add, remove or rename
448         // member functions of the current class,
449         // because these macros are need by auto register mechanism.
450 
451         CPPUNIT_TEST_SUITE(indexOfStr);
452         CPPUNIT_TEST(indexOfStr_000);
453         CPPUNIT_TEST(indexOfStr_001);
454         CPPUNIT_TEST(indexOfStr_002);
455         CPPUNIT_TEST_SUITE_END();
456     }; // class compare
457 // -----------------------------------------------------------------------------
458 
459 
460     class lastIndexOfStr : public CppUnit::TestFixture
461     {
462     public:
463 
lastIndexOfStr_000()464         void lastIndexOfStr_000()
465             {
466                 rtl_ustr_lastIndexOfStr( NULL, NULL );
467             }
468 
lastIndexOfStr_000_1()469         void lastIndexOfStr_000_1()
470             {
471                 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a lastIndexOfStr.");
472                 rtl_ustr_lastIndexOfStr( aStr1.getStr(), NULL );
473             }
474 
lastIndexOfStr_001()475         void lastIndexOfStr_001()
476             {
477                 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a lastIndexOfStr.");
478                 rtl::OUString aSearchStr = rtl::OUString::createFromAscii("Index");
479 
480                 sal_Int32 nIndex = rtl_ustr_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() );
481                 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 15);
482 
483                 /* rtl::OString */ aSearchStr = rtl::OUString::createFromAscii("Line");
484                 /* sal_Int32 */ nIndex = rtl_ustr_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() );
485                 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 0);
486 
487                 /* rtl::OString */ aSearchStr = rtl::OUString::createFromAscii("");
488                 /* sal_Int32 */ nIndex = rtl_ustr_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() );
489                 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == -1);
490             }
491 
lastIndexOfStr_002()492         void lastIndexOfStr_002()
493             {
494                 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a lastIndexOfStr.");
495                 rtl::OUString aSearchStr = rtl::OUString::createFromAscii("foo");
496                 sal_Int32 nIndex = rtl_ustr_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() );
497 
498                 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == -1 );
499             }
500 
lastIndexOfStr_003()501         void lastIndexOfStr_003()
502             {
503                 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a lastIndexOfStr.");
504                 rtl::OUString aSearchStr = rtl::OUString::createFromAscii("O");
505                 sal_Int32 nIndex = rtl_ustr_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() );
506 
507                 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 20 );
508             }
509 
510         // Change the following lines only, if you add, remove or rename
511         // member functions of the current class,
512         // because these macros are need by auto register mechanism.
513 
514         CPPUNIT_TEST_SUITE(lastIndexOfStr);
515         CPPUNIT_TEST(lastIndexOfStr_000);
516         CPPUNIT_TEST(lastIndexOfStr_001);
517         CPPUNIT_TEST(lastIndexOfStr_002);
518         CPPUNIT_TEST(lastIndexOfStr_003);
519         CPPUNIT_TEST_SUITE_END();
520     }; // class lastIndexOfStr
521 
522 // -----------------------------------------------------------------------------
523 
524     class replaceChar : public CppUnit::TestFixture
525     {
526     public:
527 
replaceChar_000()528         void replaceChar_000()
529             {
530                 rtl_ustr_replaceChar( NULL, 0, 0 );
531             }
532 
replaceChar_001()533         void replaceChar_001()
534             {
535                 rtl::OUString aStr1 = rtl::OUString::createFromAscii("replace char.");
536                 rtl::OUString aShouldStr1 = rtl::OUString::createFromAscii("ruplacu char.");
537 
538                 sal_uInt32 nLength = aStr1.getLength() * sizeof(sal_Unicode);
539                 sal_Unicode* pStr = (sal_Unicode*) malloc( nLength + sizeof(sal_Unicode)); // length + 1 (null terminator)
540                 CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL);
541                 memset(pStr, 0, nLength + sizeof(sal_Unicode));
542                 memcpy(pStr, aStr1.getStr(), nLength);
543 
544                 rtl_ustr_replaceChar( pStr, 'e', 'u' );
545                 rtl::OUString suStr(pStr, aStr1.getLength());
546 
547                 CPPUNIT_ASSERT_MESSAGE("replace failed", aShouldStr1.equals(suStr) == sal_True);
548                 free(pStr);
549             }
550 
551         // Change the following lines only, if you add, remove or rename
552         // member functions of the current class,
553         // because these macros are need by auto register mechanism.
554 
555         CPPUNIT_TEST_SUITE(replaceChar);
556         CPPUNIT_TEST(replaceChar_000);
557         CPPUNIT_TEST(replaceChar_001);
558         CPPUNIT_TEST_SUITE_END();
559     }; // class replaceChar
560 
561 // -----------------------------------------------------------------------------
562 
563     class replaceChar_WithLength : public CppUnit::TestFixture
564     {
565     public:
566 
replaceChar_WithLength_000()567         void replaceChar_WithLength_000()
568             {
569                 rtl_ustr_replaceChar_WithLength( NULL, 0, 0, 0 );
570             }
571 
replaceChar_WithLength_000_1()572         void replaceChar_WithLength_000_1()
573             {
574                 rtl_ustr_replaceChar_WithLength( NULL, 1, 0, 0 );
575             }
replaceChar_WithLength_001()576         void replaceChar_WithLength_001()
577             {
578                 rtl::OUString aStr1 = rtl::OUString::createFromAscii("replace char.");
579                 rtl::OUString aShouldStr1 = rtl::OUString::createFromAscii("ruplace char.");
580 
581                 sal_uInt32 nLength = aStr1.getLength() * sizeof(sal_Unicode);
582                 sal_Unicode* pStr = (sal_Unicode*) malloc(nLength);
583                 CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL);
584                 memcpy(pStr, aStr1.getStr(), nLength);
585 
586                 rtl_ustr_replaceChar_WithLength( pStr, 6, 'e', 'u' );
587                 rtl::OUString suStr(pStr, aStr1.getLength());
588 
589                 CPPUNIT_ASSERT_MESSAGE("replace failed", aShouldStr1.equals(suStr) == sal_True);
590                 free(pStr);
591             }
592 
replaceChar_WithLength_002()593         void replaceChar_WithLength_002()
594             {
595                 rtl::OUString aStr1       = rtl::OUString::createFromAscii("eeeeeeeeeeeee");
596                 rtl::OUString aShouldStr1 = rtl::OUString::createFromAscii("uuuuuueeeeeee");
597 
598                 sal_uInt32 nLength = aStr1.getLength() * sizeof(sal_Unicode);
599                 sal_Unicode* pStr = (sal_Unicode*) malloc(nLength);                 // no null terminator is need
600                 CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL);
601                 memcpy(pStr, aStr1.getStr(), nLength);
602 
603                 rtl_ustr_replaceChar_WithLength( pStr, 6, 'e', 'u' );
604                 rtl::OUString suStr(pStr, aStr1.getLength());
605 
606                 CPPUNIT_ASSERT_MESSAGE("replace failed", aShouldStr1.equals(suStr) == sal_True);
607                 free(pStr);
608             }
609 
610         // Change the following lines only, if you add, remove or rename
611         // member functions of the current class,
612         // because these macros are need by auto register mechanism.
613 
614         CPPUNIT_TEST_SUITE(replaceChar_WithLength);
615         CPPUNIT_TEST(replaceChar_WithLength_000);
616         CPPUNIT_TEST(replaceChar_WithLength_000_1);
617         CPPUNIT_TEST(replaceChar_WithLength_001);
618         CPPUNIT_TEST(replaceChar_WithLength_002);
619         CPPUNIT_TEST_SUITE_END();
620     }; // class replaceChar
621 
622 
623 // -----------------------------------------------------------------------------
624 
625     class toAsciiLowerCase : public CppUnit::TestFixture
626     {
627     public:
628 
toAsciiLowerCase_000()629         void toAsciiLowerCase_000()
630             {
631                 rtl_ustr_toAsciiLowerCase( NULL );
632             }
633 
toAsciiLowerCase_001()634         void toAsciiLowerCase_001()
635             {
636                 rtl::OUString aStr1 = rtl::OUString::createFromAscii("CHANGE THIS TO ASCII LOWER CASE.");
637                 rtl::OUString aShouldStr1 = rtl::OUString::createFromAscii("change this to ascii lower case.");
638 
639                 sal_uInt32 nLength = aStr1.getLength() * sizeof(sal_Unicode);
640                 sal_Unicode* pStr = (sal_Unicode*) malloc(nLength + sizeof(sal_Unicode) );  // we need to add '\0' so one more
641                 CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL);
642                 memset(pStr, 0, nLength + sizeof(sal_Unicode));                             // empty the sal_Unicode array
643                 memcpy(pStr, aStr1.getStr(), nLength);
644 
645                 rtl_ustr_toAsciiLowerCase( pStr );
646                 rtl::OUString suStr(pStr, aStr1.getLength());
647 
648                 CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1.equals(suStr) == sal_True);
649                 free(pStr);
650             }
651 
652         // Change the following lines only, if you add, remove or rename
653         // member functions of the current class,
654         // because these macros are need by auto register mechanism.
655 
656         CPPUNIT_TEST_SUITE(toAsciiLowerCase);
657         CPPUNIT_TEST(toAsciiLowerCase_000);
658         CPPUNIT_TEST(toAsciiLowerCase_001);
659         CPPUNIT_TEST_SUITE_END();
660     }; // class replaceChar
661 
662 
663     class toAsciiLowerCase_WithLength : public CppUnit::TestFixture
664     {
665     public:
666 
toAsciiLowerCase_WithLength_000()667         void toAsciiLowerCase_WithLength_000()
668             {
669                 rtl_ustr_toAsciiLowerCase_WithLength( NULL, 0 );
670             }
671 
toAsciiLowerCase_WithLength_001()672         void toAsciiLowerCase_WithLength_001()
673             {
674                 rtl::OUString aStr1 = rtl::OUString::createFromAscii("CHANGE THIS TO ASCII LOWER CASE.");
675                 rtl::OUString aShouldStr1 = rtl::OUString::createFromAscii("change thiS TO ASCII LOWER CASE.");
676 
677                 sal_uInt32 nLength = aStr1.getLength() * sizeof(sal_Unicode);
678                 sal_Unicode* pStr = (sal_Unicode*) malloc(nLength);
679                 CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL);
680                 memcpy(pStr, aStr1.getStr(), nLength);
681 
682                 rtl_ustr_toAsciiLowerCase_WithLength( pStr, 10 );
683 
684                 rtl::OUString suStr(pStr, aStr1.getLength());
685                 sal_Bool bResult = aShouldStr1.equals(suStr);
686 
687                 printOUString(suStr);
688                 t_print("Result length: %d\n", suStr.getLength() );
689                 t_print("Result: %d\n", bResult);
690 
691                 CPPUNIT_ASSERT_MESSAGE("failed", bResult == sal_True);
692                 free(pStr);
693             }
694 
695         // Change the following lines only, if you add, remove or rename
696         // member functions of the current class,
697         // because these macros are need by auto register mechanism.
698 
699         CPPUNIT_TEST_SUITE(toAsciiLowerCase_WithLength);
700         CPPUNIT_TEST(toAsciiLowerCase_WithLength_000);
701         CPPUNIT_TEST(toAsciiLowerCase_WithLength_001);
702         CPPUNIT_TEST_SUITE_END();
703     }; // class replaceChar
704 
705 // -----------------------------------------------------------------------------
706 
707     class toAsciiUpperCase : public CppUnit::TestFixture
708     {
709     public:
710 
toAsciiUpperCase_000()711         void toAsciiUpperCase_000()
712             {
713                 rtl_ustr_toAsciiUpperCase( NULL );
714             }
715 
toAsciiUpperCase_001()716         void toAsciiUpperCase_001()
717             {
718                 rtl::OUString aStr1 = rtl::OUString::createFromAscii("change this to ascii upper case.");
719                 rtl::OUString aShouldStr1 = rtl::OUString::createFromAscii("CHANGE THIS TO ASCII UPPER CASE.");
720 
721                 sal_uInt32 nLength = aStr1.getLength() * sizeof(sal_Unicode);
722                 sal_Unicode* pStr = (sal_Unicode*) malloc(nLength + sizeof(sal_Unicode)); // length + null terminator
723                 CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL);
724                 memset(pStr, 0, nLength + sizeof(sal_Unicode));
725                 memcpy(pStr, aStr1.getStr(), nLength);
726 
727                 rtl_ustr_toAsciiUpperCase( pStr );
728                 rtl::OUString suStr(pStr, aStr1.getLength());
729 
730                 CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1.equals(suStr) == sal_True);
731                 free(pStr);
732             }
733 
734         // Change the following lines only, if you add, remove or rename
735         // member functions of the current class,
736         // because these macros are need by auto register mechanism.
737 
738         CPPUNIT_TEST_SUITE(toAsciiUpperCase);
739         CPPUNIT_TEST(toAsciiUpperCase_000);
740         CPPUNIT_TEST(toAsciiUpperCase_001);
741         CPPUNIT_TEST_SUITE_END();
742     }; // class replaceChar
743 
744 
745     class toAsciiUpperCase_WithLength : public CppUnit::TestFixture
746     {
747     public:
748 
toAsciiUpperCase_WithLength_000()749         void toAsciiUpperCase_WithLength_000()
750             {
751                 rtl_ustr_toAsciiUpperCase_WithLength( NULL, 0 );
752             }
753 
toAsciiUpperCase_WithLength_001()754         void toAsciiUpperCase_WithLength_001()
755             {
756                 rtl::OUString aStr1 = rtl::OUString::createFromAscii("change this to ascii lower case.");
757                 rtl::OUString aShouldStr1 = rtl::OUString::createFromAscii("CHANGE THIs to ascii lower case.");
758 
759                 sal_uInt32 nLength = aStr1.getLength() * sizeof(sal_Unicode);
760                 sal_Unicode* pStr = (sal_Unicode*) malloc(nLength);
761                 CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL);
762 
763                 memcpy(pStr, aStr1.getStr(), nLength);
764                 rtl_ustr_toAsciiUpperCase_WithLength( pStr, 10 );
765                 rtl::OUString suStr(pStr, aStr1.getLength());
766 
767                 // t_print("Uppercase with length: '%s'\n", aStr1.getStr());
768                 CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1.equals(suStr) == sal_True);
769                 free(pStr);
770             }
771 
772         // Change the following lines only, if you add, remove or rename
773         // member functions of the current class,
774         // because these macros are need by auto register mechanism.
775 
776         CPPUNIT_TEST_SUITE(toAsciiUpperCase_WithLength);
777         CPPUNIT_TEST(toAsciiUpperCase_WithLength_000);
778         CPPUNIT_TEST(toAsciiUpperCase_WithLength_001);
779         CPPUNIT_TEST_SUITE_END();
780     }; // class replaceChar
781 
782 
783     // -----------------------------------------------------------------------------
784 
785     class trim_WithLength : public CppUnit::TestFixture
786     {
787       public:
trim_WithLength_000()788         void trim_WithLength_000()
789         {
790             rtl_ustr_trim_WithLength(NULL, 0);
791             // should not GPF
792         }
793 
trim_WithLength_000_1()794         void trim_WithLength_000_1()
795         {
796             rtl::OUString suStr = rtl::OUString::createFromAscii("  trim this");
797 
798             sal_uInt32 nLength = suStr.getLength() * sizeof(sal_Unicode);
799             sal_Unicode *pStr = (sal_Unicode*)malloc(nLength);
800             memcpy(pStr, suStr.getStr(), nLength);
801 
802             rtl_ustr_trim_WithLength( pStr, 0 );
803             free(pStr);
804         }
805 
trim_WithLength_001()806         void trim_WithLength_001()
807         {
808             rtl::OUString suStr = rtl::OUString::createFromAscii("  trim this");
809             sal_uInt32 nLength = suStr.getLength() * sizeof(sal_Unicode);
810             sal_Unicode *pStr = (sal_Unicode*)malloc(nLength);
811             memcpy(pStr, suStr.getStr(), nLength);
812 
813             rtl_ustr_trim_WithLength( pStr, 2 );
814 
815             CPPUNIT_ASSERT_MESSAGE("string should be empty", rtl::OUString(pStr).getLength() == 0);
816             free(pStr);
817         }
818 
819 
trim_WithLength_002()820         void trim_WithLength_002()
821         {
822             rtl::OUString suStr = rtl::OUString::createFromAscii("trim this");
823 
824             sal_uInt32 nLength = suStr.getLength() * sizeof(sal_Unicode);
825             sal_Unicode *pStr = (sal_Unicode*)malloc(nLength);
826             memcpy(pStr, suStr.getStr(), nLength);
827 
828             rtl_ustr_trim_WithLength( pStr, 5 );
829 
830             CPPUNIT_ASSERT_MESSAGE("string should contain 'trim'", rtl::OUString(pStr).getLength() == 4);
831             free(pStr);
832         }
833 
834 
trim_WithLength_003()835         void trim_WithLength_003()
836         {
837             rtl::OUString suStr = rtl::OUString::createFromAscii("     trim   this");
838 
839             sal_uInt32 nLength = suStr.getLength() * sizeof(sal_Unicode);
840             sal_Unicode *pStr = (sal_Unicode*)malloc(nLength);
841             memcpy(pStr, suStr.getStr(), nLength);
842 
843             rtl_ustr_trim_WithLength( pStr, 11 );
844 
845             CPPUNIT_ASSERT_MESSAGE("string should contain 'trim'", rtl::OUString(pStr).getLength() == 4);
846             free(pStr);
847         }
848 
trim_WithLength_004()849         void trim_WithLength_004()
850         {
851             rtl::OUString suStr = rtl::OUString::createFromAscii("\r\n\t \n\r    trim  \n this");
852 
853             sal_uInt32 nLength = suStr.getLength() * sizeof(sal_Unicode);
854             sal_Unicode *pStr = (sal_Unicode*)malloc(nLength);
855             memcpy(pStr, suStr.getStr(), nLength);
856 
857             rtl_ustr_trim_WithLength( pStr, 17 );
858 
859             CPPUNIT_ASSERT_MESSAGE("string should contain 'trim'", rtl::OUString(pStr).getLength() == 4);
860             free(pStr);
861         }
862 
trim_WithLength_005()863         void trim_WithLength_005()
864         {
865             rtl::OUString suStr = rtl::OUString::createFromAscii("\r\n\t \n\r    trim \t this \n\r\t\t     ");
866 
867             sal_uInt32 nLength = suStr.getLength() * sizeof(sal_Unicode);
868             sal_Unicode *pStr = (sal_Unicode*)malloc(nLength);
869             memcpy(pStr, suStr.getStr(), nLength);
870 
871             rtl_ustr_trim_WithLength( pStr, suStr.getLength() );
872 
873             CPPUNIT_ASSERT_MESSAGE("string should contain 'trim \\t this'", rtl::OUString(pStr).getLength() == 11);
874             free(pStr);
875         }
876 
877         // Change the following lines only, if you add, remove or rename
878         // member functions of the current class,
879         // because these macros are need by auto register mechanism.
880 
881         CPPUNIT_TEST_SUITE(trim_WithLength);
882         CPPUNIT_TEST(trim_WithLength_000);
883         CPPUNIT_TEST(trim_WithLength_000_1);
884         CPPUNIT_TEST(trim_WithLength_001);
885         CPPUNIT_TEST(trim_WithLength_002);
886         CPPUNIT_TEST(trim_WithLength_003);
887         CPPUNIT_TEST(trim_WithLength_004);
888         CPPUNIT_TEST(trim_WithLength_005);
889         CPPUNIT_TEST_SUITE_END();
890     };
891 
892     // -----------------------------------------------------------------------------
893 
894     class valueOfChar : public CppUnit::TestFixture
895     {
896       public:
valueOfChar_000()897         void valueOfChar_000()
898             {
899                 rtl_ustr_valueOfChar(NULL, 0);
900                 // should not GPF
901             }
valueOfChar_001()902         void valueOfChar_001()
903             {
904                 sal_Unicode *pStr = (sal_Unicode*)malloc(RTL_USTR_MAX_VALUEOFCHAR);
905                 if (pStr)
906                 {
907                     rtl_ustr_valueOfChar(pStr, 'A');
908 
909                     CPPUNIT_ASSERT_MESSAGE("string should contain 'A'", pStr[0] == L'A');
910                     free(pStr);
911                 }
912             }
913 
914         // Change the following lines only, if you add, remove or rename
915         // member functions of the current class,
916         // because these macros are need by auto register mechanism.
917 
918         CPPUNIT_TEST_SUITE(valueOfChar);
919         CPPUNIT_TEST(valueOfChar_000);
920         CPPUNIT_TEST(valueOfChar_001);
921         CPPUNIT_TEST_SUITE_END();
922     };
923 
924 
925 
926 
927     class ascii_compare_WithLength : public CppUnit::TestFixture
928     {
929     public:
zero_length()930 		void zero_length()
931         {
932 			sal_Unicode pUnicode[] = {0xffff, 0xffff};
933 			char const * pAscii = "reference";
934 
935 			sal_Int32 value = rtl_ustr_ascii_compare_WithLength(pUnicode, 0, pAscii);
936 			CPPUNIT_ASSERT_MESSAGE("ref string is empty, compare failed, needs to be <0.", value < 0);
937 		}
938 
equal_ascii_shorter()939         void equal_ascii_shorter()
940 		{
941 			rtl::OUString refStr(RTL_CONSTASCII_USTRINGPARAM("referenceString"));
942 			char const * pAscii = "reference";
943 
944 			sal_Int32 value = rtl_ustr_ascii_compare_WithLength(refStr.pData->buffer, refStr.pData->length, pAscii);
945 			CPPUNIT_ASSERT_MESSAGE("ref string is bigger, compare failed, needs to be >0.", value > 0);
946 		}
947 
equal_ascii_shorter_asciiLength()948         void equal_ascii_shorter_asciiLength()
949 		{
950 			rtl::OUString refStr(RTL_CONSTASCII_USTRINGPARAM("referenceString"));
951 			char const * pAscii = "reference";
952 
953 			sal_Int32 value = rtl_ustr_ascii_compare_WithLength(refStr.pData->buffer, rtl_str_getLength(pAscii), pAscii);
954 			CPPUNIT_ASSERT_MESSAGE("ref string is bigger despite ascii length, compare failed, needs to be == 0.", value == 0);
955 		}
956 
equal_ref_shorter()957         void equal_ref_shorter()
958 		{
959 			rtl::OUString refStr(RTL_CONSTASCII_USTRINGPARAM("reference"));
960 			char const * pAscii = "referenceString";
961 
962 			sal_Int32 value = rtl_ustr_ascii_compare_WithLength(refStr.pData->buffer, refStr.pData->length, pAscii);
963 			CPPUNIT_ASSERT_MESSAGE("ascii string is bigger, but only compared to ref length, needs to be 0.", value < 0);
964 		}
965 
equal()966         void equal()
967 		{
968 			rtl::OUString refStr(RTL_CONSTASCII_USTRINGPARAM("reference"));
969 			char const * pAscii = "reference";
970 
971 			sal_Int32 value = rtl_ustr_ascii_compare_WithLength(refStr.pData->buffer, refStr.pData->length, pAscii);
972 			CPPUNIT_ASSERT_MESSAGE("strings are equal, compare failed, needs to be 0.", value == 0);
973 		}
974 
unequal_reference_bigger()975         void unequal_reference_bigger()
976        {
977 			rtl::OUString refStr(RTL_CONSTASCII_USTRINGPARAM("defghi"));
978 			char const * pAscii = "abc";
979 
980 			sal_Int32 value = rtl_ustr_ascii_compare_WithLength(refStr.pData->buffer, refStr.pData->length, pAscii);
981 			CPPUNIT_ASSERT_MESSAGE("strings are unequal and ref is bigger, needs to be >0.", value > 0);
982 		}
983 
unequal_ascii_bigger()984         void unequal_ascii_bigger()
985 		{
986 			rtl::OUString refStr(RTL_CONSTASCII_USTRINGPARAM("abc"));
987 			char const * pAscii = "defghi";
988 
989 			sal_Int32 value = rtl_ustr_ascii_compare_WithLength(refStr.pData->buffer, refStr.pData->length, pAscii);
990 
991 			CPPUNIT_ASSERT_MESSAGE("strings are unequal and ascii is bigger, needs to be <0.", value < 0);
992 		}
993 
994         CPPUNIT_TEST_SUITE(ascii_compare_WithLength);
995         CPPUNIT_TEST(zero_length);
996         CPPUNIT_TEST(equal_ascii_shorter);
997         CPPUNIT_TEST(equal_ascii_shorter_asciiLength);
998         CPPUNIT_TEST(equal_ref_shorter);
999         CPPUNIT_TEST(equal);
1000         CPPUNIT_TEST(unequal_reference_bigger);
1001         CPPUNIT_TEST(unequal_ascii_bigger);
1002         CPPUNIT_TEST_SUITE_END();
1003 	};
1004 
1005 
1006 
1007 
1008     class ascii_shortenedCompareIgnoreAsciiCase_WithLength : public CppUnit::TestFixture
1009     {
1010     public:
1011 
ascii_shortenedCompareIgnoreAsciiCase_WithLength_000()1012         void ascii_shortenedCompareIgnoreAsciiCase_WithLength_000()
1013             {
1014                 rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( NULL, 0, NULL, 0);
1015                 // should not GPF
1016             }
1017 
ascii_shortenedCompareIgnoreAsciiCase_WithLength_000_1()1018         void ascii_shortenedCompareIgnoreAsciiCase_WithLength_000_1()
1019             {
1020                 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal.");
1021                 rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(), NULL, 0);
1022                 // should not GPF
1023             }
ascii_shortenedCompareIgnoreAsciiCase_WithLength_000_2()1024         void ascii_shortenedCompareIgnoreAsciiCase_WithLength_000_2()
1025             {
1026                 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal.");
1027                 rtl::OString sStr2 =                                 "Line is shorter.";
1028                 rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), sStr2.getLength(), sStr2.getStr(), 0);
1029                 // should not GPF
1030             }
ascii_shortenedCompareIgnoreAsciiCase_WithLength_001()1031         void ascii_shortenedCompareIgnoreAsciiCase_WithLength_001()
1032             {
1033                 rtl::OUString suStr1;
1034                 rtl::OString sStr2;
1035 
1036                 sal_Int32 nValue = rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( suStr1, 0, sStr2.getStr(), 0);
1037                 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
1038             }
1039 
ascii_shortenedCompareIgnoreAsciiCase_WithLength_002()1040         void ascii_shortenedCompareIgnoreAsciiCase_WithLength_002()
1041             {
1042                 rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must be equal.");
1043                 rtl::OString sStr2 =                                  "Line must be equal.";
1044 
1045                 sal_Int32 nValue = rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( suStr1.getStr(), suStr1.getLength(), sStr2.getStr(), sStr2.getLength());
1046                 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
1047             }
1048 
ascii_shortenedCompareIgnoreAsciiCase_WithLength_003()1049         void ascii_shortenedCompareIgnoreAsciiCase_WithLength_003()
1050             {
1051                 rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must differ.");
1052                 rtl::OString sStr2 =                                  "Line must be differ and longer.";
1053 
1054                 sal_Int32 nValue = rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( suStr1.getStr(), suStr1.getLength(), sStr2.getStr(), sStr2.getLength());
1055                 CPPUNIT_ASSERT_MESSAGE("compare failed, strings differ.", nValue != 0);
1056             }
1057 
1058         // Change the following lines only, if you add, remove or rename
1059         // member functions of the current class,
1060         // because these macros are need by auto register mechanism.
1061 
1062         CPPUNIT_TEST_SUITE(ascii_shortenedCompareIgnoreAsciiCase_WithLength);
1063         CPPUNIT_TEST(ascii_shortenedCompareIgnoreAsciiCase_WithLength_000);
1064         CPPUNIT_TEST(ascii_shortenedCompareIgnoreAsciiCase_WithLength_000_1);
1065         CPPUNIT_TEST(ascii_shortenedCompareIgnoreAsciiCase_WithLength_000_2);
1066         CPPUNIT_TEST(ascii_shortenedCompareIgnoreAsciiCase_WithLength_001);
1067         CPPUNIT_TEST(ascii_shortenedCompareIgnoreAsciiCase_WithLength_002);
1068         CPPUNIT_TEST(ascii_shortenedCompareIgnoreAsciiCase_WithLength_003);
1069         CPPUNIT_TEST_SUITE_END();
1070     }; // class ascii_shortenedCompareIgnoreAsciiCase_WithLength
1071 
1072 // -----------------------------------------------------------------------------
1073 
1074     class ascii_compareIgnoreAsciiCase_WithLength : public CppUnit::TestFixture
1075     {
1076     public:
1077 
ascii_compareIgnoreAsciiCase_WithLength_000()1078         void ascii_compareIgnoreAsciiCase_WithLength_000()
1079             {
1080                 rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( NULL, 0, NULL);
1081                 // should not GPF
1082             }
1083 
ascii_compareIgnoreAsciiCase_WithLength_000_1()1084         void ascii_compareIgnoreAsciiCase_WithLength_000_1()
1085             {
1086                 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal.");
1087                 rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( aStr1.getStr(), 0, NULL);
1088                 // should not GPF
1089             }
ascii_compareIgnoreAsciiCase_WithLength_000_2()1090         void ascii_compareIgnoreAsciiCase_WithLength_000_2()
1091             {
1092                 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal.");
1093                 rtl::OString sStr2 =                                 "Line is shorter.";
1094                 rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( aStr1.getStr(), sStr2.getLength(), sStr2.getStr());
1095                 // should not GPF
1096             }
ascii_compareIgnoreAsciiCase_WithLength_001()1097         void ascii_compareIgnoreAsciiCase_WithLength_001()
1098             {
1099                 rtl::OUString suStr1;
1100                 rtl::OString sStr2;
1101 
1102                 sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( suStr1, 0, sStr2.getStr());
1103                 CPPUNIT_ASSERT_MESSAGE("compareIgnoreAsciiCase_WithLength failed, strings are equal.", nValue == 0);
1104             }
1105 
ascii_compareIgnoreAsciiCase_WithLength_002()1106         void ascii_compareIgnoreAsciiCase_WithLength_002()
1107             {
1108                 rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must be equal.");
1109                 rtl::OString sStr2 =                                  "Line must be equal.";
1110 
1111                 sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( suStr1.getStr(), suStr1.getLength(), sStr2.getStr());
1112                 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
1113             }
1114 
ascii_compareIgnoreAsciiCase_WithLength_003()1115         void ascii_compareIgnoreAsciiCase_WithLength_003()
1116             {
1117                 rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must differ.");
1118                 rtl::OString sStr2 =                                  "Line must be differ and longer.";
1119 
1120                 sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( suStr1.getStr(), suStr1.getLength(), sStr2.getStr());
1121                 CPPUNIT_ASSERT_MESSAGE("compare failed, strings differ.", nValue != 0);
1122             }
1123 
1124         // Change the following lines only, if you add, remove or rename
1125         // member functions of the current class,
1126         // because these macros are need by auto register mechanism.
1127 
1128         CPPUNIT_TEST_SUITE(ascii_compareIgnoreAsciiCase_WithLength);
1129         CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_WithLength_000);
1130         CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_WithLength_000_1);
1131         CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_WithLength_000_2);
1132         CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_WithLength_001);
1133         CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_WithLength_002);
1134         CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_WithLength_003);
1135         CPPUNIT_TEST_SUITE_END();
1136     }; // class ascii_compareIgnoreAsciiCase_WithLength
1137 
1138 // -----------------------------------------------------------------------------
1139 
1140     class ascii_compare : public CppUnit::TestFixture
1141     {
1142     public:
1143 
ascii_compare_000()1144         void ascii_compare_000()
1145             {
1146                 rtl_ustr_ascii_compare( NULL, NULL);
1147                 // should not GPF
1148             }
1149 
ascii_compare_000_1()1150         void ascii_compare_000_1()
1151             {
1152                 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal.");
1153                 rtl_ustr_ascii_compare( aStr1.getStr(), NULL);
1154                 // should not GPF
1155             }
ascii_compare_001()1156         void ascii_compare_001()
1157             {
1158                 rtl::OUString suStr1;
1159                 rtl::OString sStr2;
1160 
1161                 sal_Int32 nValue = rtl_ustr_ascii_compare( suStr1, sStr2.getStr());
1162                 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
1163             }
1164 
ascii_compare_002()1165         void ascii_compare_002()
1166             {
1167                 rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must be equal.");
1168                 rtl::OString sStr2 =                                  "Line must be equal.";
1169 
1170                 sal_Int32 nValue = rtl_ustr_ascii_compare( suStr1.getStr(), sStr2.getStr());
1171                 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
1172             }
1173 
ascii_compare_003()1174         void ascii_compare_003()
1175             {
1176                 rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must differ.");
1177                 rtl::OString sStr2 = "Line foo bar, ok, differ.";
1178 
1179                 sal_Int32 nValue = rtl_ustr_ascii_compare( suStr1.getStr(), sStr2.getStr());
1180                 CPPUNIT_ASSERT_MESSAGE("compare failed, strings differ.", nValue != 0);
1181             }
1182 
1183         // Change the following lines only, if you add, remove or rename
1184         // member functions of the current class,
1185         // because these macros are need by auto register mechanism.
1186 
1187         CPPUNIT_TEST_SUITE(ascii_compare);
1188         CPPUNIT_TEST(ascii_compare_000);
1189         CPPUNIT_TEST(ascii_compare_000_1);
1190         CPPUNIT_TEST(ascii_compare_001);
1191         CPPUNIT_TEST(ascii_compare_002);
1192         CPPUNIT_TEST(ascii_compare_003);
1193         CPPUNIT_TEST_SUITE_END();
1194     }; // class ascii_compare
1195 
1196 // -----------------------------------------------------------------------------
1197 
1198     class ascii_compareIgnoreAsciiCase : public CppUnit::TestFixture
1199     {
1200     public:
1201 
ascii_compareIgnoreAsciiCase_000()1202         void ascii_compareIgnoreAsciiCase_000()
1203             {
1204                 rtl_ustr_ascii_compareIgnoreAsciiCase( NULL, NULL);
1205                 // should not GPF
1206             }
1207 
ascii_compareIgnoreAsciiCase_000_1()1208         void ascii_compareIgnoreAsciiCase_000_1()
1209             {
1210                 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal.");
1211                 rtl_ustr_ascii_compareIgnoreAsciiCase( aStr1.getStr(), NULL);
1212                 // should not GPF
1213             }
ascii_compareIgnoreAsciiCase_001()1214         void ascii_compareIgnoreAsciiCase_001()
1215             {
1216                 rtl::OUString suStr1;
1217                 rtl::OString sStr2;
1218 
1219                 sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase( suStr1, sStr2.getStr());
1220                 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
1221             }
1222 
ascii_compareIgnoreAsciiCase_002()1223         void ascii_compareIgnoreAsciiCase_002()
1224             {
1225                 rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must be equal.");
1226                 rtl::OString sStr2 =                                  "Line must be equal.";
1227 
1228                 sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase( suStr1.getStr(), sStr2.getStr());
1229                 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
1230             }
1231 
ascii_compareIgnoreAsciiCase_002_1()1232         void ascii_compareIgnoreAsciiCase_002_1()
1233             {
1234                 rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must be equal, when ignore case.");
1235                 rtl::OString sStr2 =                                 "LINE MUST BE EQUAL, WHEN IGNORE CASE.";
1236 
1237                 sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase( suStr1.getStr(), sStr2.getStr());
1238                 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal (if case insensitve).", nValue == 0);
1239             }
1240 
ascii_compareIgnoreAsciiCase_003()1241         void ascii_compareIgnoreAsciiCase_003()
1242             {
1243                 rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must differ.");
1244                 rtl::OString sStr2 = "Line foo bar, ok, differ.";
1245 
1246                 sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase( suStr1.getStr(), sStr2.getStr());
1247                 CPPUNIT_ASSERT_MESSAGE("compare failed, strings differ.", nValue != 0);
1248             }
1249 
1250         //! LLA: some more tests with some high level strings
1251 
1252         // void ascii_compareIgnoreAsciiCase_001()
1253         //     {
1254         //         rtl::OUString suStr1 = rtl::OUString::createFromAscii("change this to ascii upper case.");
1255         //         rtl::OUString aShouldStr1 = rtl::OUString::createFromAscii("CHANGE THIS TO ASCII UPPER CASE.");
1256         //
1257         //         sal_uInt32 nLength = suStr1.getLength() * sizeof(sal_Unicode);
1258         //         sal_Unicode* pStr = (sal_Unicode*) malloc(nLength + sizeof(sal_Unicode)); // length + null terminator
1259         //         CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL);
1260         //         memset(pStr, 0, nLength + sizeof(sal_Unicode));
1261         //         memcpy(pStr, suStr1.getStr(), nLength);
1262         //
1263         //         rtl_ustr_ascii_compareIgnoreAsciiCase( pStr );
1264         //         rtl::OUString suStr(pStr, suStr1.getLength());
1265         //
1266         //         CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1.equals(suStr) == sal_True);
1267         //         free(pStr);
1268         //     }
1269 
1270         // Change the following lines only, if you add, remove or rename
1271         // member functions of the current class,
1272         // because these macros are need by auto register mechanism.
1273 
1274         CPPUNIT_TEST_SUITE(ascii_compareIgnoreAsciiCase);
1275         CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_000);
1276         CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_000_1);
1277         CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_001);
1278         CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_002);
1279         CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_002_1);
1280         CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_003);
1281         CPPUNIT_TEST_SUITE_END();
1282     }; // class ascii_compareIgnoreAsciiCase
1283 
1284 
1285     // sample out of inc/rtl/ustring.hxx
1286     // rtl_uString * pToken = NULL;
1287     // sal_Int32 nIndex = 0;
1288     // do
1289     // {
1290     //       ...
1291     //       nIndex = rtl_uString_getToken(&pToken, pStr, 0, ';', nIndex);
1292     //       ...
1293     // }
1294     // while (nIndex >= 0);
1295 
1296     class getToken : public CppUnit::TestFixture
1297     {
1298     public:
1299 
getToken_000()1300         void getToken_000()
1301             {
1302                 rtl_ustr_ascii_compareIgnoreAsciiCase( NULL, NULL);
1303                 // should not GPF
1304             }
1305 
ascii_compareIgnoreAsciiCase_000_1()1306         void ascii_compareIgnoreAsciiCase_000_1()
1307             {
1308                 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal.");
1309                 rtl_ustr_ascii_compareIgnoreAsciiCase( aStr1.getStr(), NULL);
1310                 // should not GPF
1311             }
ascii_compareIgnoreAsciiCase_001()1312         void ascii_compareIgnoreAsciiCase_001()
1313             {
1314                 rtl::OUString suStr1;
1315                 rtl::OString sStr2;
1316 
1317                 sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase( suStr1, sStr2.getStr());
1318                 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
1319             }
1320 
ascii_compareIgnoreAsciiCase_002()1321         void ascii_compareIgnoreAsciiCase_002()
1322             {
1323                 rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must be equal.");
1324                 rtl::OString sStr2 =                                  "Line must be equal.";
1325 
1326                 sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase( suStr1.getStr(), sStr2.getStr());
1327                 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
1328             }
1329 
ascii_compareIgnoreAsciiCase_002_1()1330         void ascii_compareIgnoreAsciiCase_002_1()
1331             {
1332                 rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must be equal, when ignore case.");
1333                 rtl::OString sStr2 =                                 "LINE MUST BE EQUAL, WHEN IGNORE CASE.";
1334 
1335                 sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase( suStr1.getStr(), sStr2.getStr());
1336                 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal (if case insensitve).", nValue == 0);
1337             }
1338 
ascii_compareIgnoreAsciiCase_003()1339         void ascii_compareIgnoreAsciiCase_003()
1340             {
1341                 rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must differ.");
1342                 rtl::OString sStr2 = "Line foo bar, ok, differ.";
1343 
1344                 sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase( suStr1.getStr(), sStr2.getStr());
1345                 CPPUNIT_ASSERT_MESSAGE("compare failed, strings differ.", nValue != 0);
1346             }
1347 
1348         //! LLA: some more tests with some high level strings
1349 
1350         // void ascii_compareIgnoreAsciiCase_001()
1351         //     {
1352         //         rtl::OUString suStr1 = rtl::OUString::createFromAscii("change this to ascii upper case.");
1353         //         rtl::OUString aShouldStr1 = rtl::OUString::createFromAscii("CHANGE THIS TO ASCII UPPER CASE.");
1354         //
1355         //         sal_uInt32 nLength = suStr1.getLength() * sizeof(sal_Unicode);
1356         //         sal_Unicode* pStr = (sal_Unicode*) malloc(nLength + sizeof(sal_Unicode)); // length + null terminator
1357         //         CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL);
1358         //         memset(pStr, 0, nLength + sizeof(sal_Unicode));
1359         //         memcpy(pStr, suStr1.getStr(), nLength);
1360         //
1361         //         rtl_ustr_ascii_compareIgnoreAsciiCase( pStr );
1362         //         rtl::OUString suStr(pStr, suStr1.getLength());
1363         //
1364         //         CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1.equals(suStr) == sal_True);
1365         //         free(pStr);
1366         //     }
1367 
1368         // Change the following lines only, if you add, remove or rename
1369         // member functions of the current class,
1370         // because these macros are need by auto register mechanism.
1371 
1372         CPPUNIT_TEST_SUITE(ascii_compareIgnoreAsciiCase);
1373         CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_000);
1374         CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_000_1);
1375         CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_001);
1376         CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_002);
1377         CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_002_1);
1378         CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_003);
1379         CPPUNIT_TEST_SUITE_END();
1380     }; // class ascii_compareIgnoreAsciiCase
1381 
1382 // -----------------------------------------------------------------------------
1383 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::compare, "rtl_ustr");
1384 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::compareIgnoreAsciiCase, "rtl_ustr");
1385 
1386 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::ascii_compare_WithLength, "rtl_ustr");
1387 
1388 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::shortenedCompareIgnoreAsciiCase_WithLength, "rtl_ustr");
1389 // CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::hashCode, "rtl_ustr");
1390 
1391 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::indexOfChar, "rtl_ustr");
1392 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::lastIndexOfChar, "rtl_ustr");
1393 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::indexOfStr, "rtl_ustr");
1394 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::lastIndexOfStr, "rtl_ustr");
1395 
1396 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::replaceChar, "rtl_ustr");
1397 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::replaceChar_WithLength, "rtl_ustr");
1398 
1399 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::toAsciiLowerCase, "rtl_ustr");
1400 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::toAsciiLowerCase_WithLength, "rtl_ustr");
1401 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::toAsciiUpperCase, "rtl_ustr");
1402 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::toAsciiUpperCase_WithLength, "rtl_ustr");
1403 
1404 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::trim_WithLength, "rtl_ustr");
1405 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::valueOfChar, "rtl_ustr");
1406 
1407 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::ascii_compare, "rtl_ustr");
1408 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::ascii_compareIgnoreAsciiCase, "rtl_ustr");
1409 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::ascii_compareIgnoreAsciiCase_WithLength, "rtl_ustr");
1410 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::ascii_shortenedCompareIgnoreAsciiCase_WithLength, "rtl_ustr");
1411 
1412 } // namespace rtl_ustr
1413 
1414 // -----------------------------------------------------------------------------
1415 
1416 // this macro creates an empty function, which will called by the RegisterAllFunctions()
1417 // to let the user the possibility to also register some functions by hand.
1418 NOADDITIONAL;
1419 
1420 
1421