merged tag ooo/DEV300_m102
[LibreOffice.git] / sal / qa / rtl / oustring / rtl_ustr.cxx
blobfd207ef0778c35672308798773b5c1cb54072ed2
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
29 // MARKER(update_precomp.py): autogen include statement, do not remove
30 #include "precompiled_sal.hxx"
31 #include <testshl/simpleheader.hxx>
33 /** print a UNI_CODE file name.
35 inline void printOUString( ::rtl::OUString const & _suStr )
37 rtl::OString aString;
39 t_print( "OUString: " );
40 aString = ::rtl::OUStringToOString( _suStr, RTL_TEXTENCODING_ASCII_US );
41 t_print( "%s\n", aString.getStr( ) );
45 namespace rtl_ustr
48 class compare : public CppUnit::TestFixture
50 public:
53 void compare_000()
55 rtl_ustr_compare( NULL, NULL);
56 // should not GPF
59 void compare_000_1()
61 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal.");
62 rtl_ustr_compare( aStr1.getStr(), NULL);
63 // should not GPF
65 void compare_001()
67 rtl::OUString aStr1;
68 rtl::OUString aStr2;
70 sal_Int32 nValue = rtl_ustr_compare( aStr1.getStr(), aStr2.getStr());
71 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
74 void compare_002()
76 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal.");
77 rtl::OUString aStr2 = rtl::OUString::createFromAscii("Line must be equal.");
79 sal_Int32 nValue = rtl_ustr_compare( aStr1.getStr(), aStr2.getStr());
80 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
83 void compare_003()
85 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must differ.");
86 rtl::OUString aStr2 = rtl::OUString::createFromAscii("Line foo bar, ok, differ.");
88 sal_Int32 nValue = rtl_ustr_compare( aStr1.getStr(), aStr2.getStr());
89 CPPUNIT_ASSERT_MESSAGE("compare failed, strings differ.", nValue != 0);
92 // Change the following lines only, if you add, remove or rename
93 // member functions of the current class,
94 // because these macros are need by auto register mechanism.
96 CPPUNIT_TEST_SUITE(compare);
97 CPPUNIT_TEST(compare_000);
98 CPPUNIT_TEST(compare_000_1);
99 CPPUNIT_TEST(compare_001);
100 CPPUNIT_TEST(compare_002);
101 CPPUNIT_TEST(compare_003);
102 CPPUNIT_TEST_SUITE_END();
103 }; // class compare
106 class compareIgnoreAsciiCase : public CppUnit::TestFixture
108 public:
110 void compare_000()
112 rtl_ustr_compareIgnoreAsciiCase( NULL, NULL);
115 void compare_000_1()
117 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal.");
118 rtl_ustr_compareIgnoreAsciiCase( aStr1.getStr(), NULL);
120 void compare_001()
122 rtl::OUString aStr1;
123 rtl::OUString aStr2;
125 sal_Int32 nValue = rtl_ustr_compareIgnoreAsciiCase( aStr1.getStr(), aStr2.getStr());
126 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
129 void compare_002()
131 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal.");
132 rtl::OUString aStr2 = rtl::OUString::createFromAscii("Line must be equal.");
134 sal_Int32 nValue = rtl_ustr_compareIgnoreAsciiCase( aStr1.getStr(), aStr2.getStr());
135 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
138 void compare_002_1()
140 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal.");
141 rtl::OUString aStr2 = rtl::OUString::createFromAscii("LINE MUST BE EQUAL.");
143 sal_Int32 nValue = rtl_ustr_compareIgnoreAsciiCase( aStr1.getStr(), aStr2.getStr());
144 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal (if case insensitve).", nValue == 0);
147 void compare_003()
149 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must differ.");
150 rtl::OUString aStr2 = rtl::OUString::createFromAscii("Line foo bar, ok, differ.");
152 sal_Int32 nValue = rtl_ustr_compareIgnoreAsciiCase( aStr1.getStr(), aStr2.getStr());
153 CPPUNIT_ASSERT_MESSAGE("compare failed, strings differ.", nValue != 0);
156 // Change the following lines only, if you add, remove or rename
157 // member functions of the current class,
158 // because these macros are need by auto register mechanism.
160 CPPUNIT_TEST_SUITE(compareIgnoreAsciiCase);
161 CPPUNIT_TEST(compare_000);
162 CPPUNIT_TEST(compare_000_1);
163 CPPUNIT_TEST(compare_001);
164 CPPUNIT_TEST(compare_002);
165 CPPUNIT_TEST(compare_002_1);
166 CPPUNIT_TEST(compare_003);
167 CPPUNIT_TEST_SUITE_END();
168 }; // class compareIgnoreAsciiCase
170 // -----------------------------------------------------------------------------
172 class shortenedCompareIgnoreAsciiCase_WithLength : public CppUnit::TestFixture
174 public:
176 void compare_000()
178 rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( NULL, 0, NULL, 0, 0);
181 void compare_000_1()
183 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal.");
184 rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(), NULL, 0, 1);
186 void compare_001()
188 rtl::OUString aStr1;
189 rtl::OUString aStr2;
191 sal_Int32 nValue = rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(), aStr2.getStr(), aStr2.getLength(), aStr1.getLength());
192 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
195 void compare_002()
197 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal.");
198 rtl::OUString aStr2 = rtl::OUString::createFromAscii("Line must be equal.");
200 sal_Int32 nValue = rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(),
201 aStr2.getStr(), aStr2.getLength(),
202 aStr1.getLength());
203 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
206 void compare_002_1()
208 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal.");
209 rtl::OUString aStr2 = rtl::OUString::createFromAscii("LINE MUST BE EQUAL.");
211 sal_Int32 nValue = rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(),
212 aStr2.getStr(), aStr2.getLength(),
213 aStr1.getLength());
214 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal (if case insensitve).", nValue == 0);
217 void compare_003()
219 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must differ.");
220 rtl::OUString aStr2 = rtl::OUString::createFromAscii("Line foo bar, ok, differ.");
222 sal_Int32 nValue = rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(),
223 aStr2.getStr(), aStr2.getLength(),
225 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal first 5 characters.", nValue == 0);
228 void compare_004()
230 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must differ.");
231 rtl::OUString aStr2 = rtl::OUString::createFromAscii("Line foo bar, ok, differ.");
233 sal_Int32 nValue = rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(),
234 aStr2.getStr(), aStr2.getLength(),
235 aStr1.getLength());
236 CPPUNIT_ASSERT_MESSAGE("compare failed, strings differ.", nValue != 0);
239 // Change the following lines only, if you add, remove or rename
240 // member functions of the current class,
241 // because these macros are need by auto register mechanism.
243 CPPUNIT_TEST_SUITE(shortenedCompareIgnoreAsciiCase_WithLength);
244 CPPUNIT_TEST(compare_000);
245 CPPUNIT_TEST(compare_000_1);
246 CPPUNIT_TEST(compare_001);
247 CPPUNIT_TEST(compare_002);
248 CPPUNIT_TEST(compare_002_1);
249 CPPUNIT_TEST(compare_003);
250 CPPUNIT_TEST(compare_004);
251 CPPUNIT_TEST_SUITE_END();
252 }; // class compare
255 // // -----------------------------------------------------------------------------
257 // class hashCode : public CppUnit::TestFixture
258 // {
259 // public:
261 // void hashCode_000()
262 // {
263 // sal_Int32 nHashCode = rtl_ustr_hashCode( NULL );
264 // volatile int dummy = 0;
265 // }
267 // void hashCode_001()
268 // {
269 // rtl::OString aStr1 = "Line for a hashCode.";
270 // sal_Int32 nHashCode = rtl_ustr_hashCode( aStr1.getStr() );
271 // t_print("hashcode: %d\n", nHashCode);
272 // // CPPUNIT_ASSERT_MESSAGE("failed.", nValue == 0);
273 // }
275 // void hashCode_002()
276 // {
277 // rtl::OString aStr1 = "Line for a hashCode.";
278 // sal_Int32 nHashCode1 = rtl_ustr_hashCode( aStr1.getStr() );
280 // rtl::OString aStr2 = "Line for a hashCode.";
281 // sal_Int32 nHashCode2 = rtl_ustr_hashCode( aStr2.getStr() );
283 // CPPUNIT_ASSERT_MESSAGE("hashcodes must be equal.", nHashCode1 == nHashCode2 );
284 // }
286 // void hashCode_003()
287 // {
288 // rtl::OString aStr1 = "Line for a hashCode.";
289 // sal_Int32 nHashCode1 = rtl_ustr_hashCode( aStr1.getStr() );
291 // rtl::OString aStr2 = "Line for an other hashcode.";
292 // sal_Int32 nHashCode2 = rtl_ustr_hashCode( aStr2.getStr() );
294 // CPPUNIT_ASSERT_MESSAGE("hashcodes must differ.", nHashCode1 != nHashCode2 );
295 // }
297 // // Change the following lines only, if you add, remove or rename
298 // // member functions of the current class,
299 // // because these macros are need by auto register mechanism.
301 // CPPUNIT_TEST_SUITE(hashCode);
302 // CPPUNIT_TEST(hashCode_000);
303 // CPPUNIT_TEST(hashCode_001);
304 // CPPUNIT_TEST(hashCode_002);
305 // CPPUNIT_TEST(hashCode_003);
306 // CPPUNIT_TEST_SUITE_END();
307 // }; // class compare
310 // // -----------------------------------------------------------------------------
312 class indexOfChar : public CppUnit::TestFixture
314 public:
316 void indexOfChar_000()
318 rtl_ustr_indexOfChar( NULL, 0 );
321 void indexOfChar_001()
323 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a indexOfChar.");
325 sal_Int32 nIndex = rtl_ustr_indexOfChar( aStr1.getStr(), 'L' );
326 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 0);
328 /* sal_Int32 */ nIndex = rtl_ustr_indexOfChar( aStr1.getStr(), 'i' );
329 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 1);
331 /* sal_Int32 */ nIndex = rtl_ustr_indexOfChar( aStr1.getStr(), 'n' );
332 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 2);
334 /* sal_Int32 */ nIndex = rtl_ustr_indexOfChar( aStr1.getStr(), 'e' );
335 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 3);
338 void indexOfChar_002()
340 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a indexOfChar.");
341 sal_Int32 nIndex = rtl_ustr_indexOfChar( aStr1.getStr(), 'y' );
343 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == -1 );
346 // Change the following lines only, if you add, remove or rename
347 // member functions of the current class,
348 // because these macros are need by auto register mechanism.
350 CPPUNIT_TEST_SUITE(indexOfChar);
351 CPPUNIT_TEST(indexOfChar_000);
352 CPPUNIT_TEST(indexOfChar_001);
353 CPPUNIT_TEST(indexOfChar_002);
354 CPPUNIT_TEST_SUITE_END();
355 }; // class indexOfChar
357 // // -----------------------------------------------------------------------------
358 class lastIndexOfChar : public CppUnit::TestFixture
360 public:
362 void lastIndexOfChar_000()
364 rtl_ustr_lastIndexOfChar( NULL, 0 );
367 void lastIndexOfChar_001()
369 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a lastIndexOfChar.");
371 sal_Int32 nIndex = rtl_ustr_lastIndexOfChar( aStr1.getStr(), 'C' );
372 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 22);
374 /* sal_Int32 */ nIndex = rtl_ustr_lastIndexOfChar( aStr1.getStr(), 'h' );
375 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 23);
377 /* sal_Int32 */ nIndex = rtl_ustr_lastIndexOfChar( aStr1.getStr(), 'a' );
378 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 24);
380 /* sal_Int32 */ nIndex = rtl_ustr_lastIndexOfChar( aStr1.getStr(), 'r' );
381 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 25);
384 void lastIndexOfChar_002()
386 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a lastIndexOfChar.");
387 sal_Int32 nIndex = rtl_ustr_lastIndexOfChar( aStr1.getStr(), 'y' );
389 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == -1 );
392 // Change the following lines only, if you add, remove or rename
393 // member functions of the current class,
394 // because these macros are need by auto register mechanism.
396 CPPUNIT_TEST_SUITE(lastIndexOfChar);
397 CPPUNIT_TEST(lastIndexOfChar_000);
398 CPPUNIT_TEST(lastIndexOfChar_001);
399 CPPUNIT_TEST(lastIndexOfChar_002);
400 CPPUNIT_TEST_SUITE_END();
401 }; // class lastIndexOfChar
404 // -----------------------------------------------------------------------------
406 class indexOfStr : public CppUnit::TestFixture
408 public:
410 void indexOfStr_000()
412 rtl_ustr_indexOfStr( NULL, 0 );
415 void indexOfStr_000_1()
417 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a indexOfStr.");
418 rtl_ustr_indexOfStr( aStr1.getStr(), 0 );
421 void indexOfStr_001()
423 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a indexOfStr.");
425 rtl::OUString suSearch = rtl::OUString::createFromAscii("Line");
426 sal_Int32 nIndex = rtl_ustr_indexOfStr( aStr1.getStr(), suSearch );
427 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 0);
429 /* rtl::OUString */ suSearch = rtl::OUString::createFromAscii("for");
430 /* sal_Int32 */ nIndex = rtl_ustr_indexOfStr( aStr1.getStr(), suSearch );
431 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 5);
433 /* rtl::OUString */ suSearch = rtl::OUString::createFromAscii("a");
434 /* sal_Int32 */ nIndex = rtl_ustr_indexOfStr( aStr1.getStr(), suSearch );
435 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 9);
437 /* rtl::OUString */ suSearch = rtl::OUString::createFromAscii("a index");
438 /* sal_Int32 */ nIndex = rtl_ustr_indexOfStr( aStr1.getStr(), suSearch );
439 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex ==9);
442 void indexOfStr_002()
444 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a indexOfStr.");
445 rtl::OUString suSearch = rtl::OUString::createFromAscii("not exist");
446 sal_Int32 nIndex = rtl_ustr_indexOfStr( aStr1.getStr(), suSearch );
448 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == -1 );
451 // Change the following lines only, if you add, remove or rename
452 // member functions of the current class,
453 // because these macros are need by auto register mechanism.
455 CPPUNIT_TEST_SUITE(indexOfStr);
456 CPPUNIT_TEST(indexOfStr_000);
457 CPPUNIT_TEST(indexOfStr_001);
458 CPPUNIT_TEST(indexOfStr_002);
459 CPPUNIT_TEST_SUITE_END();
460 }; // class compare
461 // -----------------------------------------------------------------------------
464 class lastIndexOfStr : public CppUnit::TestFixture
466 public:
468 void lastIndexOfStr_000()
470 rtl_ustr_lastIndexOfStr( NULL, NULL );
473 void lastIndexOfStr_000_1()
475 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a lastIndexOfStr.");
476 rtl_ustr_lastIndexOfStr( aStr1.getStr(), NULL );
479 void lastIndexOfStr_001()
481 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a lastIndexOfStr.");
482 rtl::OUString aSearchStr = rtl::OUString::createFromAscii("Index");
484 sal_Int32 nIndex = rtl_ustr_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() );
485 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 15);
487 /* rtl::OString */ aSearchStr = rtl::OUString::createFromAscii("Line");
488 /* sal_Int32 */ nIndex = rtl_ustr_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() );
489 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 0);
491 /* rtl::OString */ aSearchStr = rtl::OUString::createFromAscii("");
492 /* sal_Int32 */ nIndex = rtl_ustr_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() );
493 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == -1);
496 void lastIndexOfStr_002()
498 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a lastIndexOfStr.");
499 rtl::OUString aSearchStr = rtl::OUString::createFromAscii("foo");
500 sal_Int32 nIndex = rtl_ustr_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() );
502 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == -1 );
505 void lastIndexOfStr_003()
507 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a lastIndexOfStr.");
508 rtl::OUString aSearchStr = rtl::OUString::createFromAscii("O");
509 sal_Int32 nIndex = rtl_ustr_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() );
511 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 20 );
514 // Change the following lines only, if you add, remove or rename
515 // member functions of the current class,
516 // because these macros are need by auto register mechanism.
518 CPPUNIT_TEST_SUITE(lastIndexOfStr);
519 CPPUNIT_TEST(lastIndexOfStr_000);
520 CPPUNIT_TEST(lastIndexOfStr_001);
521 CPPUNIT_TEST(lastIndexOfStr_002);
522 CPPUNIT_TEST(lastIndexOfStr_003);
523 CPPUNIT_TEST_SUITE_END();
524 }; // class lastIndexOfStr
526 // -----------------------------------------------------------------------------
528 class replaceChar : public CppUnit::TestFixture
530 public:
532 void replaceChar_000()
534 rtl_ustr_replaceChar( NULL, 0, 0 );
537 void replaceChar_001()
539 rtl::OUString aStr1 = rtl::OUString::createFromAscii("replace char.");
540 rtl::OUString aShouldStr1 = rtl::OUString::createFromAscii("ruplacu char.");
542 sal_uInt32 nLength = aStr1.getLength() * sizeof(sal_Unicode);
543 sal_Unicode* pStr = (sal_Unicode*) malloc( nLength + sizeof(sal_Unicode)); // length + 1 (null terminator)
544 CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL);
545 memset(pStr, 0, nLength + sizeof(sal_Unicode));
546 memcpy(pStr, aStr1.getStr(), nLength);
548 rtl_ustr_replaceChar( pStr, 'e', 'u' );
549 rtl::OUString suStr(pStr, aStr1.getLength());
551 CPPUNIT_ASSERT_MESSAGE("replace failed", aShouldStr1.equals(suStr) == sal_True);
552 free(pStr);
555 // Change the following lines only, if you add, remove or rename
556 // member functions of the current class,
557 // because these macros are need by auto register mechanism.
559 CPPUNIT_TEST_SUITE(replaceChar);
560 CPPUNIT_TEST(replaceChar_000);
561 CPPUNIT_TEST(replaceChar_001);
562 CPPUNIT_TEST_SUITE_END();
563 }; // class replaceChar
565 // -----------------------------------------------------------------------------
567 class replaceChar_WithLength : public CppUnit::TestFixture
569 public:
571 void replaceChar_WithLength_000()
573 rtl_ustr_replaceChar_WithLength( NULL, 0, 0, 0 );
576 void replaceChar_WithLength_000_1()
578 rtl_ustr_replaceChar_WithLength( NULL, 1, 0, 0 );
580 void replaceChar_WithLength_001()
582 rtl::OUString aStr1 = rtl::OUString::createFromAscii("replace char.");
583 rtl::OUString aShouldStr1 = rtl::OUString::createFromAscii("ruplace char.");
585 sal_uInt32 nLength = aStr1.getLength() * sizeof(sal_Unicode);
586 sal_Unicode* pStr = (sal_Unicode*) malloc(nLength);
587 CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL);
588 memcpy(pStr, aStr1.getStr(), nLength);
590 rtl_ustr_replaceChar_WithLength( pStr, 6, 'e', 'u' );
591 rtl::OUString suStr(pStr, aStr1.getLength());
593 CPPUNIT_ASSERT_MESSAGE("replace failed", aShouldStr1.equals(suStr) == sal_True);
594 free(pStr);
597 void replaceChar_WithLength_002()
599 rtl::OUString aStr1 = rtl::OUString::createFromAscii("eeeeeeeeeeeee");
600 rtl::OUString aShouldStr1 = rtl::OUString::createFromAscii("uuuuuueeeeeee");
602 sal_uInt32 nLength = aStr1.getLength() * sizeof(sal_Unicode);
603 sal_Unicode* pStr = (sal_Unicode*) malloc(nLength); // no null terminator is need
604 CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL);
605 memcpy(pStr, aStr1.getStr(), nLength);
607 rtl_ustr_replaceChar_WithLength( pStr, 6, 'e', 'u' );
608 rtl::OUString suStr(pStr, aStr1.getLength());
610 CPPUNIT_ASSERT_MESSAGE("replace failed", aShouldStr1.equals(suStr) == sal_True);
611 free(pStr);
614 // Change the following lines only, if you add, remove or rename
615 // member functions of the current class,
616 // because these macros are need by auto register mechanism.
618 CPPUNIT_TEST_SUITE(replaceChar_WithLength);
619 CPPUNIT_TEST(replaceChar_WithLength_000);
620 CPPUNIT_TEST(replaceChar_WithLength_000_1);
621 CPPUNIT_TEST(replaceChar_WithLength_001);
622 CPPUNIT_TEST(replaceChar_WithLength_002);
623 CPPUNIT_TEST_SUITE_END();
624 }; // class replaceChar
627 // -----------------------------------------------------------------------------
629 class toAsciiLowerCase : public CppUnit::TestFixture
631 public:
633 void toAsciiLowerCase_000()
635 rtl_ustr_toAsciiLowerCase( NULL );
638 void toAsciiLowerCase_001()
640 rtl::OUString aStr1 = rtl::OUString::createFromAscii("CHANGE THIS TO ASCII LOWER CASE.");
641 rtl::OUString aShouldStr1 = rtl::OUString::createFromAscii("change this to ascii lower case.");
643 sal_uInt32 nLength = aStr1.getLength() * sizeof(sal_Unicode);
644 sal_Unicode* pStr = (sal_Unicode*) malloc(nLength + sizeof(sal_Unicode) ); // we need to add '\0' so one more
645 CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL);
646 memset(pStr, 0, nLength + sizeof(sal_Unicode)); // empty the sal_Unicode array
647 memcpy(pStr, aStr1.getStr(), nLength);
649 rtl_ustr_toAsciiLowerCase( pStr );
650 rtl::OUString suStr(pStr, aStr1.getLength());
652 CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1.equals(suStr) == sal_True);
653 free(pStr);
656 // Change the following lines only, if you add, remove or rename
657 // member functions of the current class,
658 // because these macros are need by auto register mechanism.
660 CPPUNIT_TEST_SUITE(toAsciiLowerCase);
661 CPPUNIT_TEST(toAsciiLowerCase_000);
662 CPPUNIT_TEST(toAsciiLowerCase_001);
663 CPPUNIT_TEST_SUITE_END();
664 }; // class replaceChar
667 class toAsciiLowerCase_WithLength : public CppUnit::TestFixture
669 public:
671 void toAsciiLowerCase_WithLength_000()
673 rtl_ustr_toAsciiLowerCase_WithLength( NULL, 0 );
676 void toAsciiLowerCase_WithLength_001()
678 rtl::OUString aStr1 = rtl::OUString::createFromAscii("CHANGE THIS TO ASCII LOWER CASE.");
679 rtl::OUString aShouldStr1 = rtl::OUString::createFromAscii("change thiS TO ASCII LOWER CASE.");
681 sal_uInt32 nLength = aStr1.getLength() * sizeof(sal_Unicode);
682 sal_Unicode* pStr = (sal_Unicode*) malloc(nLength);
683 CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL);
684 memcpy(pStr, aStr1.getStr(), nLength);
686 rtl_ustr_toAsciiLowerCase_WithLength( pStr, 10 );
688 rtl::OUString suStr(pStr, aStr1.getLength());
689 sal_Bool bResult = aShouldStr1.equals(suStr);
691 printOUString(suStr);
692 t_print("Result length: %d\n", suStr.getLength() );
693 t_print("Result: %d\n", bResult);
695 CPPUNIT_ASSERT_MESSAGE("failed", bResult == sal_True);
696 free(pStr);
699 // Change the following lines only, if you add, remove or rename
700 // member functions of the current class,
701 // because these macros are need by auto register mechanism.
703 CPPUNIT_TEST_SUITE(toAsciiLowerCase_WithLength);
704 CPPUNIT_TEST(toAsciiLowerCase_WithLength_000);
705 CPPUNIT_TEST(toAsciiLowerCase_WithLength_001);
706 CPPUNIT_TEST_SUITE_END();
707 }; // class replaceChar
709 // -----------------------------------------------------------------------------
711 class toAsciiUpperCase : public CppUnit::TestFixture
713 public:
715 void toAsciiUpperCase_000()
717 rtl_ustr_toAsciiUpperCase( NULL );
720 void toAsciiUpperCase_001()
722 rtl::OUString aStr1 = rtl::OUString::createFromAscii("change this to ascii upper case.");
723 rtl::OUString aShouldStr1 = rtl::OUString::createFromAscii("CHANGE THIS TO ASCII UPPER CASE.");
725 sal_uInt32 nLength = aStr1.getLength() * sizeof(sal_Unicode);
726 sal_Unicode* pStr = (sal_Unicode*) malloc(nLength + sizeof(sal_Unicode)); // length + null terminator
727 CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL);
728 memset(pStr, 0, nLength + sizeof(sal_Unicode));
729 memcpy(pStr, aStr1.getStr(), nLength);
731 rtl_ustr_toAsciiUpperCase( pStr );
732 rtl::OUString suStr(pStr, aStr1.getLength());
734 CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1.equals(suStr) == sal_True);
735 free(pStr);
738 // Change the following lines only, if you add, remove or rename
739 // member functions of the current class,
740 // because these macros are need by auto register mechanism.
742 CPPUNIT_TEST_SUITE(toAsciiUpperCase);
743 CPPUNIT_TEST(toAsciiUpperCase_000);
744 CPPUNIT_TEST(toAsciiUpperCase_001);
745 CPPUNIT_TEST_SUITE_END();
746 }; // class replaceChar
749 class toAsciiUpperCase_WithLength : public CppUnit::TestFixture
751 public:
753 void toAsciiUpperCase_WithLength_000()
755 rtl_ustr_toAsciiUpperCase_WithLength( NULL, 0 );
758 void toAsciiUpperCase_WithLength_001()
760 rtl::OUString aStr1 = rtl::OUString::createFromAscii("change this to ascii lower case.");
761 rtl::OUString aShouldStr1 = rtl::OUString::createFromAscii("CHANGE THIs to ascii lower case.");
763 sal_uInt32 nLength = aStr1.getLength() * sizeof(sal_Unicode);
764 sal_Unicode* pStr = (sal_Unicode*) malloc(nLength);
765 CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL);
767 memcpy(pStr, aStr1.getStr(), nLength);
768 rtl_ustr_toAsciiUpperCase_WithLength( pStr, 10 );
769 rtl::OUString suStr(pStr, aStr1.getLength());
771 // t_print("Uppercase with length: '%s'\n", aStr1.getStr());
772 CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1.equals(suStr) == sal_True);
773 free(pStr);
776 // Change the following lines only, if you add, remove or rename
777 // member functions of the current class,
778 // because these macros are need by auto register mechanism.
780 CPPUNIT_TEST_SUITE(toAsciiUpperCase_WithLength);
781 CPPUNIT_TEST(toAsciiUpperCase_WithLength_000);
782 CPPUNIT_TEST(toAsciiUpperCase_WithLength_001);
783 CPPUNIT_TEST_SUITE_END();
784 }; // class replaceChar
787 // -----------------------------------------------------------------------------
789 class trim_WithLength : public CppUnit::TestFixture
791 public:
792 void trim_WithLength_000()
794 rtl_ustr_trim_WithLength(NULL, 0);
795 // should not GPF
798 void trim_WithLength_000_1()
800 rtl::OUString suStr = rtl::OUString::createFromAscii(" trim this");
802 sal_uInt32 nLength = suStr.getLength() * sizeof(sal_Unicode);
803 sal_Unicode *pStr = (sal_Unicode*)malloc(nLength);
804 memcpy(pStr, suStr.getStr(), nLength);
806 rtl_ustr_trim_WithLength( pStr, 0 );
807 free(pStr);
810 void trim_WithLength_001()
812 rtl::OUString suStr = rtl::OUString::createFromAscii(" trim this");
813 sal_uInt32 nLength = suStr.getLength() * sizeof(sal_Unicode);
814 sal_Unicode *pStr = (sal_Unicode*)malloc(nLength);
815 memcpy(pStr, suStr.getStr(), nLength);
817 rtl_ustr_trim_WithLength( pStr, 2 );
819 CPPUNIT_ASSERT_MESSAGE("string should be empty", rtl::OUString(pStr).getLength() == 0);
820 free(pStr);
824 void trim_WithLength_002()
826 rtl::OUString suStr = rtl::OUString::createFromAscii("trim this");
828 sal_uInt32 nLength = suStr.getLength() * sizeof(sal_Unicode);
829 sal_Unicode *pStr = (sal_Unicode*)malloc(nLength);
830 memcpy(pStr, suStr.getStr(), nLength);
832 rtl_ustr_trim_WithLength( pStr, 5 );
834 CPPUNIT_ASSERT_MESSAGE("string should contain 'trim'", rtl::OUString(pStr).getLength() == 4);
835 free(pStr);
839 void trim_WithLength_003()
841 rtl::OUString suStr = rtl::OUString::createFromAscii(" trim this");
843 sal_uInt32 nLength = suStr.getLength() * sizeof(sal_Unicode);
844 sal_Unicode *pStr = (sal_Unicode*)malloc(nLength);
845 memcpy(pStr, suStr.getStr(), nLength);
847 rtl_ustr_trim_WithLength( pStr, 11 );
849 CPPUNIT_ASSERT_MESSAGE("string should contain 'trim'", rtl::OUString(pStr).getLength() == 4);
850 free(pStr);
853 void trim_WithLength_004()
855 rtl::OUString suStr = rtl::OUString::createFromAscii("\r\n\t \n\r trim \n this");
857 sal_uInt32 nLength = suStr.getLength() * sizeof(sal_Unicode);
858 sal_Unicode *pStr = (sal_Unicode*)malloc(nLength);
859 memcpy(pStr, suStr.getStr(), nLength);
861 rtl_ustr_trim_WithLength( pStr, 17 );
863 CPPUNIT_ASSERT_MESSAGE("string should contain 'trim'", rtl::OUString(pStr).getLength() == 4);
864 free(pStr);
867 void trim_WithLength_005()
869 rtl::OUString suStr = rtl::OUString::createFromAscii("\r\n\t \n\r trim \t this \n\r\t\t ");
871 sal_uInt32 nLength = suStr.getLength() * sizeof(sal_Unicode);
872 sal_Unicode *pStr = (sal_Unicode*)malloc(nLength);
873 memcpy(pStr, suStr.getStr(), nLength);
875 rtl_ustr_trim_WithLength( pStr, suStr.getLength() );
877 CPPUNIT_ASSERT_MESSAGE("string should contain 'trim \\t this'", rtl::OUString(pStr).getLength() == 11);
878 free(pStr);
881 // Change the following lines only, if you add, remove or rename
882 // member functions of the current class,
883 // because these macros are need by auto register mechanism.
885 CPPUNIT_TEST_SUITE(trim_WithLength);
886 CPPUNIT_TEST(trim_WithLength_000);
887 CPPUNIT_TEST(trim_WithLength_000_1);
888 CPPUNIT_TEST(trim_WithLength_001);
889 CPPUNIT_TEST(trim_WithLength_002);
890 CPPUNIT_TEST(trim_WithLength_003);
891 CPPUNIT_TEST(trim_WithLength_004);
892 CPPUNIT_TEST(trim_WithLength_005);
893 CPPUNIT_TEST_SUITE_END();
896 // -----------------------------------------------------------------------------
898 class valueOfChar : public CppUnit::TestFixture
900 public:
901 void valueOfChar_000()
903 rtl_ustr_valueOfChar(NULL, 0);
904 // should not GPF
906 void valueOfChar_001()
908 sal_Unicode *pStr = (sal_Unicode*)malloc(RTL_USTR_MAX_VALUEOFCHAR);
909 if (pStr)
911 rtl_ustr_valueOfChar(pStr, 'A');
913 CPPUNIT_ASSERT_MESSAGE("string should contain 'A'", pStr[0] == L'A');
914 free(pStr);
918 // Change the following lines only, if you add, remove or rename
919 // member functions of the current class,
920 // because these macros are need by auto register mechanism.
922 CPPUNIT_TEST_SUITE(valueOfChar);
923 CPPUNIT_TEST(valueOfChar_000);
924 CPPUNIT_TEST(valueOfChar_001);
925 CPPUNIT_TEST_SUITE_END();
931 class ascii_compare_WithLength : public CppUnit::TestFixture
933 public:
934 void zero_length()
936 sal_Unicode pUnicode[] = {0xffff, 0xffff};
937 char const * pAscii = "reference";
939 sal_Int32 value = rtl_ustr_ascii_compare_WithLength(pUnicode, 0, pAscii);
940 CPPUNIT_ASSERT_MESSAGE("ref string is empty, compare failed, needs to be <0.", value < 0);
943 void equal_ascii_shorter()
945 rtl::OUString refStr(RTL_CONSTASCII_USTRINGPARAM("referenceString"));
946 char const * pAscii = "reference";
948 sal_Int32 value = rtl_ustr_ascii_compare_WithLength(refStr.pData->buffer, refStr.pData->length, pAscii);
949 CPPUNIT_ASSERT_MESSAGE("ref string is bigger, compare failed, needs to be >0.", value > 0);
952 void equal_ascii_shorter_asciiLength()
954 rtl::OUString refStr(RTL_CONSTASCII_USTRINGPARAM("referenceString"));
955 char const * pAscii = "reference";
957 sal_Int32 value = rtl_ustr_ascii_compare_WithLength(refStr.pData->buffer, rtl_str_getLength(pAscii), pAscii);
958 CPPUNIT_ASSERT_MESSAGE("ref string is bigger despite ascii length, compare failed, needs to be == 0.", value == 0);
961 void equal_ref_shorter()
963 rtl::OUString refStr(RTL_CONSTASCII_USTRINGPARAM("reference"));
964 char const * pAscii = "referenceString";
966 sal_Int32 value = rtl_ustr_ascii_compare_WithLength(refStr.pData->buffer, refStr.pData->length, pAscii);
967 CPPUNIT_ASSERT_MESSAGE("ascii string is bigger, but only compared to ref length, needs to be 0.", value < 0);
970 void equal()
972 rtl::OUString refStr(RTL_CONSTASCII_USTRINGPARAM("reference"));
973 char const * pAscii = "reference";
975 sal_Int32 value = rtl_ustr_ascii_compare_WithLength(refStr.pData->buffer, refStr.pData->length, pAscii);
976 CPPUNIT_ASSERT_MESSAGE("strings are equal, compare failed, needs to be 0.", value == 0);
979 void unequal_reference_bigger()
981 rtl::OUString refStr(RTL_CONSTASCII_USTRINGPARAM("defghi"));
982 char const * pAscii = "abc";
984 sal_Int32 value = rtl_ustr_ascii_compare_WithLength(refStr.pData->buffer, refStr.pData->length, pAscii);
985 CPPUNIT_ASSERT_MESSAGE("strings are unequal and ref is bigger, needs to be >0.", value > 0);
988 void unequal_ascii_bigger()
990 rtl::OUString refStr(RTL_CONSTASCII_USTRINGPARAM("abc"));
991 char const * pAscii = "defghi";
993 sal_Int32 value = rtl_ustr_ascii_compare_WithLength(refStr.pData->buffer, refStr.pData->length, pAscii);
995 CPPUNIT_ASSERT_MESSAGE("strings are unequal and ascii is bigger, needs to be <0.", value < 0);
998 CPPUNIT_TEST_SUITE(ascii_compare_WithLength);
999 CPPUNIT_TEST(zero_length);
1000 CPPUNIT_TEST(equal_ascii_shorter);
1001 CPPUNIT_TEST(equal_ascii_shorter_asciiLength);
1002 CPPUNIT_TEST(equal_ref_shorter);
1003 CPPUNIT_TEST(equal);
1004 CPPUNIT_TEST(unequal_reference_bigger);
1005 CPPUNIT_TEST(unequal_ascii_bigger);
1006 CPPUNIT_TEST_SUITE_END();
1012 class ascii_shortenedCompareIgnoreAsciiCase_WithLength : public CppUnit::TestFixture
1014 public:
1016 void ascii_shortenedCompareIgnoreAsciiCase_WithLength_000()
1018 rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( NULL, 0, NULL, 0);
1019 // should not GPF
1022 void ascii_shortenedCompareIgnoreAsciiCase_WithLength_000_1()
1024 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal.");
1025 rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(), NULL, 0);
1026 // should not GPF
1028 void ascii_shortenedCompareIgnoreAsciiCase_WithLength_000_2()
1030 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal.");
1031 rtl::OString sStr2 = "Line is shorter.";
1032 rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), sStr2.getLength(), sStr2.getStr(), 0);
1033 // should not GPF
1035 void ascii_shortenedCompareIgnoreAsciiCase_WithLength_001()
1037 rtl::OUString suStr1;
1038 rtl::OString sStr2;
1040 sal_Int32 nValue = rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( suStr1, 0, sStr2.getStr(), 0);
1041 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
1044 void ascii_shortenedCompareIgnoreAsciiCase_WithLength_002()
1046 rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must be equal.");
1047 rtl::OString sStr2 = "Line must be equal.";
1049 sal_Int32 nValue = rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( suStr1.getStr(), suStr1.getLength(), sStr2.getStr(), sStr2.getLength());
1050 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
1053 void ascii_shortenedCompareIgnoreAsciiCase_WithLength_003()
1055 rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must differ.");
1056 rtl::OString sStr2 = "Line must be differ and longer.";
1058 sal_Int32 nValue = rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( suStr1.getStr(), suStr1.getLength(), sStr2.getStr(), sStr2.getLength());
1059 CPPUNIT_ASSERT_MESSAGE("compare failed, strings differ.", nValue != 0);
1062 // Change the following lines only, if you add, remove or rename
1063 // member functions of the current class,
1064 // because these macros are need by auto register mechanism.
1066 CPPUNIT_TEST_SUITE(ascii_shortenedCompareIgnoreAsciiCase_WithLength);
1067 CPPUNIT_TEST(ascii_shortenedCompareIgnoreAsciiCase_WithLength_000);
1068 CPPUNIT_TEST(ascii_shortenedCompareIgnoreAsciiCase_WithLength_000_1);
1069 CPPUNIT_TEST(ascii_shortenedCompareIgnoreAsciiCase_WithLength_000_2);
1070 CPPUNIT_TEST(ascii_shortenedCompareIgnoreAsciiCase_WithLength_001);
1071 CPPUNIT_TEST(ascii_shortenedCompareIgnoreAsciiCase_WithLength_002);
1072 CPPUNIT_TEST(ascii_shortenedCompareIgnoreAsciiCase_WithLength_003);
1073 CPPUNIT_TEST_SUITE_END();
1074 }; // class ascii_shortenedCompareIgnoreAsciiCase_WithLength
1076 // -----------------------------------------------------------------------------
1078 class ascii_compareIgnoreAsciiCase_WithLength : public CppUnit::TestFixture
1080 public:
1082 void ascii_compareIgnoreAsciiCase_WithLength_000()
1084 rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( NULL, 0, NULL);
1085 // should not GPF
1088 void ascii_compareIgnoreAsciiCase_WithLength_000_1()
1090 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal.");
1091 rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( aStr1.getStr(), 0, NULL);
1092 // should not GPF
1094 void ascii_compareIgnoreAsciiCase_WithLength_000_2()
1096 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal.");
1097 rtl::OString sStr2 = "Line is shorter.";
1098 rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( aStr1.getStr(), sStr2.getLength(), sStr2.getStr());
1099 // should not GPF
1101 void ascii_compareIgnoreAsciiCase_WithLength_001()
1103 rtl::OUString suStr1;
1104 rtl::OString sStr2;
1106 sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( suStr1, 0, sStr2.getStr());
1107 CPPUNIT_ASSERT_MESSAGE("compareIgnoreAsciiCase_WithLength failed, strings are equal.", nValue == 0);
1110 void ascii_compareIgnoreAsciiCase_WithLength_002()
1112 rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must be equal.");
1113 rtl::OString sStr2 = "Line must be equal.";
1115 sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( suStr1.getStr(), suStr1.getLength(), sStr2.getStr());
1116 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
1119 void ascii_compareIgnoreAsciiCase_WithLength_003()
1121 rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must differ.");
1122 rtl::OString sStr2 = "Line must be differ and longer.";
1124 sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( suStr1.getStr(), suStr1.getLength(), sStr2.getStr());
1125 CPPUNIT_ASSERT_MESSAGE("compare failed, strings differ.", nValue != 0);
1128 // Change the following lines only, if you add, remove or rename
1129 // member functions of the current class,
1130 // because these macros are need by auto register mechanism.
1132 CPPUNIT_TEST_SUITE(ascii_compareIgnoreAsciiCase_WithLength);
1133 CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_WithLength_000);
1134 CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_WithLength_000_1);
1135 CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_WithLength_000_2);
1136 CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_WithLength_001);
1137 CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_WithLength_002);
1138 CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_WithLength_003);
1139 CPPUNIT_TEST_SUITE_END();
1140 }; // class ascii_compareIgnoreAsciiCase_WithLength
1142 // -----------------------------------------------------------------------------
1144 class ascii_compare : public CppUnit::TestFixture
1146 public:
1148 void ascii_compare_000()
1150 rtl_ustr_ascii_compare( NULL, NULL);
1151 // should not GPF
1154 void ascii_compare_000_1()
1156 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal.");
1157 rtl_ustr_ascii_compare( aStr1.getStr(), NULL);
1158 // should not GPF
1160 void ascii_compare_001()
1162 rtl::OUString suStr1;
1163 rtl::OString sStr2;
1165 sal_Int32 nValue = rtl_ustr_ascii_compare( suStr1, sStr2.getStr());
1166 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
1169 void ascii_compare_002()
1171 rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must be equal.");
1172 rtl::OString sStr2 = "Line must be equal.";
1174 sal_Int32 nValue = rtl_ustr_ascii_compare( suStr1.getStr(), sStr2.getStr());
1175 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
1178 void ascii_compare_003()
1180 rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must differ.");
1181 rtl::OString sStr2 = "Line foo bar, ok, differ.";
1183 sal_Int32 nValue = rtl_ustr_ascii_compare( suStr1.getStr(), sStr2.getStr());
1184 CPPUNIT_ASSERT_MESSAGE("compare failed, strings differ.", nValue != 0);
1187 // Change the following lines only, if you add, remove or rename
1188 // member functions of the current class,
1189 // because these macros are need by auto register mechanism.
1191 CPPUNIT_TEST_SUITE(ascii_compare);
1192 CPPUNIT_TEST(ascii_compare_000);
1193 CPPUNIT_TEST(ascii_compare_000_1);
1194 CPPUNIT_TEST(ascii_compare_001);
1195 CPPUNIT_TEST(ascii_compare_002);
1196 CPPUNIT_TEST(ascii_compare_003);
1197 CPPUNIT_TEST_SUITE_END();
1198 }; // class ascii_compare
1200 // -----------------------------------------------------------------------------
1202 class ascii_compareIgnoreAsciiCase : public CppUnit::TestFixture
1204 public:
1206 void ascii_compareIgnoreAsciiCase_000()
1208 rtl_ustr_ascii_compareIgnoreAsciiCase( NULL, NULL);
1209 // should not GPF
1212 void ascii_compareIgnoreAsciiCase_000_1()
1214 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal.");
1215 rtl_ustr_ascii_compareIgnoreAsciiCase( aStr1.getStr(), NULL);
1216 // should not GPF
1218 void ascii_compareIgnoreAsciiCase_001()
1220 rtl::OUString suStr1;
1221 rtl::OString sStr2;
1223 sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase( suStr1, sStr2.getStr());
1224 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
1227 void ascii_compareIgnoreAsciiCase_002()
1229 rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must be equal.");
1230 rtl::OString sStr2 = "Line must be equal.";
1232 sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase( suStr1.getStr(), sStr2.getStr());
1233 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
1236 void ascii_compareIgnoreAsciiCase_002_1()
1238 rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must be equal, when ignore case.");
1239 rtl::OString sStr2 = "LINE MUST BE EQUAL, WHEN IGNORE CASE.";
1241 sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase( suStr1.getStr(), sStr2.getStr());
1242 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal (if case insensitve).", nValue == 0);
1245 void ascii_compareIgnoreAsciiCase_003()
1247 rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must differ.");
1248 rtl::OString sStr2 = "Line foo bar, ok, differ.";
1250 sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase( suStr1.getStr(), sStr2.getStr());
1251 CPPUNIT_ASSERT_MESSAGE("compare failed, strings differ.", nValue != 0);
1254 //! LLA: some more tests with some high level strings
1256 // void ascii_compareIgnoreAsciiCase_001()
1257 // {
1258 // rtl::OUString suStr1 = rtl::OUString::createFromAscii("change this to ascii upper case.");
1259 // rtl::OUString aShouldStr1 = rtl::OUString::createFromAscii("CHANGE THIS TO ASCII UPPER CASE.");
1261 // sal_uInt32 nLength = suStr1.getLength() * sizeof(sal_Unicode);
1262 // sal_Unicode* pStr = (sal_Unicode*) malloc(nLength + sizeof(sal_Unicode)); // length + null terminator
1263 // CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL);
1264 // memset(pStr, 0, nLength + sizeof(sal_Unicode));
1265 // memcpy(pStr, suStr1.getStr(), nLength);
1267 // rtl_ustr_ascii_compareIgnoreAsciiCase( pStr );
1268 // rtl::OUString suStr(pStr, suStr1.getLength());
1270 // CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1.equals(suStr) == sal_True);
1271 // free(pStr);
1272 // }
1274 // Change the following lines only, if you add, remove or rename
1275 // member functions of the current class,
1276 // because these macros are need by auto register mechanism.
1278 CPPUNIT_TEST_SUITE(ascii_compareIgnoreAsciiCase);
1279 CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_000);
1280 CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_000_1);
1281 CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_001);
1282 CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_002);
1283 CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_002_1);
1284 CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_003);
1285 CPPUNIT_TEST_SUITE_END();
1286 }; // class ascii_compareIgnoreAsciiCase
1289 // sample out of inc/rtl/ustring.hxx
1290 // rtl_uString * pToken = NULL;
1291 // sal_Int32 nIndex = 0;
1292 // do
1293 // {
1294 // ...
1295 // nIndex = rtl_uString_getToken(&pToken, pStr, 0, ';', nIndex);
1296 // ...
1297 // }
1298 // while (nIndex >= 0);
1300 class getToken : public CppUnit::TestFixture
1302 public:
1304 void getToken_000()
1306 rtl_ustr_ascii_compareIgnoreAsciiCase( NULL, NULL);
1307 // should not GPF
1310 void ascii_compareIgnoreAsciiCase_000_1()
1312 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal.");
1313 rtl_ustr_ascii_compareIgnoreAsciiCase( aStr1.getStr(), NULL);
1314 // should not GPF
1316 void ascii_compareIgnoreAsciiCase_001()
1318 rtl::OUString suStr1;
1319 rtl::OString sStr2;
1321 sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase( suStr1, sStr2.getStr());
1322 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
1325 void ascii_compareIgnoreAsciiCase_002()
1327 rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must be equal.");
1328 rtl::OString sStr2 = "Line must be equal.";
1330 sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase( suStr1.getStr(), sStr2.getStr());
1331 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
1334 void ascii_compareIgnoreAsciiCase_002_1()
1336 rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must be equal, when ignore case.");
1337 rtl::OString sStr2 = "LINE MUST BE EQUAL, WHEN IGNORE CASE.";
1339 sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase( suStr1.getStr(), sStr2.getStr());
1340 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal (if case insensitve).", nValue == 0);
1343 void ascii_compareIgnoreAsciiCase_003()
1345 rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must differ.");
1346 rtl::OString sStr2 = "Line foo bar, ok, differ.";
1348 sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase( suStr1.getStr(), sStr2.getStr());
1349 CPPUNIT_ASSERT_MESSAGE("compare failed, strings differ.", nValue != 0);
1352 //! LLA: some more tests with some high level strings
1354 // void ascii_compareIgnoreAsciiCase_001()
1355 // {
1356 // rtl::OUString suStr1 = rtl::OUString::createFromAscii("change this to ascii upper case.");
1357 // rtl::OUString aShouldStr1 = rtl::OUString::createFromAscii("CHANGE THIS TO ASCII UPPER CASE.");
1359 // sal_uInt32 nLength = suStr1.getLength() * sizeof(sal_Unicode);
1360 // sal_Unicode* pStr = (sal_Unicode*) malloc(nLength + sizeof(sal_Unicode)); // length + null terminator
1361 // CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL);
1362 // memset(pStr, 0, nLength + sizeof(sal_Unicode));
1363 // memcpy(pStr, suStr1.getStr(), nLength);
1365 // rtl_ustr_ascii_compareIgnoreAsciiCase( pStr );
1366 // rtl::OUString suStr(pStr, suStr1.getLength());
1368 // CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1.equals(suStr) == sal_True);
1369 // free(pStr);
1370 // }
1372 // Change the following lines only, if you add, remove or rename
1373 // member functions of the current class,
1374 // because these macros are need by auto register mechanism.
1376 CPPUNIT_TEST_SUITE(ascii_compareIgnoreAsciiCase);
1377 CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_000);
1378 CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_000_1);
1379 CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_001);
1380 CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_002);
1381 CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_002_1);
1382 CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_003);
1383 CPPUNIT_TEST_SUITE_END();
1384 }; // class ascii_compareIgnoreAsciiCase
1386 // -----------------------------------------------------------------------------
1387 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::compare, "rtl_ustr");
1388 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::compareIgnoreAsciiCase, "rtl_ustr");
1390 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::ascii_compare_WithLength, "rtl_ustr");
1392 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::shortenedCompareIgnoreAsciiCase_WithLength, "rtl_ustr");
1393 // CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::hashCode, "rtl_ustr");
1395 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::indexOfChar, "rtl_ustr");
1396 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::lastIndexOfChar, "rtl_ustr");
1397 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::indexOfStr, "rtl_ustr");
1398 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::lastIndexOfStr, "rtl_ustr");
1400 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::replaceChar, "rtl_ustr");
1401 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::replaceChar_WithLength, "rtl_ustr");
1403 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::toAsciiLowerCase, "rtl_ustr");
1404 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::toAsciiLowerCase_WithLength, "rtl_ustr");
1405 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::toAsciiUpperCase, "rtl_ustr");
1406 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::toAsciiUpperCase_WithLength, "rtl_ustr");
1408 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::trim_WithLength, "rtl_ustr");
1409 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::valueOfChar, "rtl_ustr");
1411 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::ascii_compare, "rtl_ustr");
1412 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::ascii_compareIgnoreAsciiCase, "rtl_ustr");
1413 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::ascii_compareIgnoreAsciiCase_WithLength, "rtl_ustr");
1414 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::ascii_shortenedCompareIgnoreAsciiCase_WithLength, "rtl_ustr");
1416 } // namespace rtl_ustr
1418 // -----------------------------------------------------------------------------
1420 // this macro creates an empty function, which will called by the RegisterAllFunctions()
1421 // to let the user the possibility to also register some functions by hand.
1422 NOADDITIONAL;