update dev300-m57
[ooovba.git] / sal / qa / rtl / oustring / rtl_ustr.cxx
blobffaa87f1f1798ebf82b347d4fd2f07d9a436340a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: rtl_ustr.cxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_sal.hxx"
34 #include <cppunit/simpleheader.hxx>
36 /** print a UNI_CODE file name.
38 inline void printOUString( ::rtl::OUString const & _suStr )
40 rtl::OString aString;
42 t_print( "OUString: " );
43 aString = ::rtl::OUStringToOString( _suStr, RTL_TEXTENCODING_ASCII_US );
44 t_print( "%s\n", aString.getStr( ) );
48 namespace rtl_ustr
51 class compare : public CppUnit::TestFixture
53 public:
56 void compare_000()
58 rtl_ustr_compare( NULL, NULL);
59 // should not GPF
62 void compare_000_1()
64 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal.");
65 rtl_ustr_compare( aStr1.getStr(), NULL);
66 // should not GPF
68 void compare_001()
70 rtl::OUString aStr1;
71 rtl::OUString aStr2;
73 sal_Int32 nValue = rtl_ustr_compare( aStr1.getStr(), aStr2.getStr());
74 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
77 void compare_002()
79 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal.");
80 rtl::OUString aStr2 = rtl::OUString::createFromAscii("Line must be equal.");
82 sal_Int32 nValue = rtl_ustr_compare( aStr1.getStr(), aStr2.getStr());
83 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
86 void compare_003()
88 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must differ.");
89 rtl::OUString aStr2 = rtl::OUString::createFromAscii("Line foo bar, ok, differ.");
91 sal_Int32 nValue = rtl_ustr_compare( aStr1.getStr(), aStr2.getStr());
92 CPPUNIT_ASSERT_MESSAGE("compare failed, strings differ.", nValue != 0);
95 // Change the following lines only, if you add, remove or rename
96 // member functions of the current class,
97 // because these macros are need by auto register mechanism.
99 CPPUNIT_TEST_SUITE(compare);
100 CPPUNIT_TEST(compare_000);
101 CPPUNIT_TEST(compare_000_1);
102 CPPUNIT_TEST(compare_001);
103 CPPUNIT_TEST(compare_002);
104 CPPUNIT_TEST(compare_003);
105 CPPUNIT_TEST_SUITE_END();
106 }; // class compare
109 class compareIgnoreAsciiCase : public CppUnit::TestFixture
111 public:
113 void compare_000()
115 rtl_ustr_compareIgnoreAsciiCase( NULL, NULL);
118 void compare_000_1()
120 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal.");
121 rtl_ustr_compareIgnoreAsciiCase( aStr1.getStr(), NULL);
123 void compare_001()
125 rtl::OUString aStr1;
126 rtl::OUString aStr2;
128 sal_Int32 nValue = rtl_ustr_compareIgnoreAsciiCase( aStr1.getStr(), aStr2.getStr());
129 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
132 void compare_002()
134 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal.");
135 rtl::OUString aStr2 = rtl::OUString::createFromAscii("Line must be equal.");
137 sal_Int32 nValue = rtl_ustr_compareIgnoreAsciiCase( aStr1.getStr(), aStr2.getStr());
138 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
141 void compare_002_1()
143 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal.");
144 rtl::OUString aStr2 = rtl::OUString::createFromAscii("LINE MUST BE EQUAL.");
146 sal_Int32 nValue = rtl_ustr_compareIgnoreAsciiCase( aStr1.getStr(), aStr2.getStr());
147 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal (if case insensitve).", nValue == 0);
150 void compare_003()
152 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must differ.");
153 rtl::OUString aStr2 = rtl::OUString::createFromAscii("Line foo bar, ok, differ.");
155 sal_Int32 nValue = rtl_ustr_compareIgnoreAsciiCase( aStr1.getStr(), aStr2.getStr());
156 CPPUNIT_ASSERT_MESSAGE("compare failed, strings differ.", nValue != 0);
159 // Change the following lines only, if you add, remove or rename
160 // member functions of the current class,
161 // because these macros are need by auto register mechanism.
163 CPPUNIT_TEST_SUITE(compareIgnoreAsciiCase);
164 CPPUNIT_TEST(compare_000);
165 CPPUNIT_TEST(compare_000_1);
166 CPPUNIT_TEST(compare_001);
167 CPPUNIT_TEST(compare_002);
168 CPPUNIT_TEST(compare_002_1);
169 CPPUNIT_TEST(compare_003);
170 CPPUNIT_TEST_SUITE_END();
171 }; // class compareIgnoreAsciiCase
173 // -----------------------------------------------------------------------------
175 class shortenedCompareIgnoreAsciiCase_WithLength : public CppUnit::TestFixture
177 public:
179 void compare_000()
181 rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( NULL, 0, NULL, 0, 0);
184 void compare_000_1()
186 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal.");
187 rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(), NULL, 0, 1);
189 void compare_001()
191 rtl::OUString aStr1;
192 rtl::OUString aStr2;
194 sal_Int32 nValue = rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(), aStr2.getStr(), aStr2.getLength(), aStr1.getLength());
195 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
198 void compare_002()
200 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal.");
201 rtl::OUString aStr2 = rtl::OUString::createFromAscii("Line must be equal.");
203 sal_Int32 nValue = rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(),
204 aStr2.getStr(), aStr2.getLength(),
205 aStr1.getLength());
206 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
209 void compare_002_1()
211 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal.");
212 rtl::OUString aStr2 = rtl::OUString::createFromAscii("LINE MUST BE EQUAL.");
214 sal_Int32 nValue = rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(),
215 aStr2.getStr(), aStr2.getLength(),
216 aStr1.getLength());
217 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal (if case insensitve).", nValue == 0);
220 void compare_003()
222 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must differ.");
223 rtl::OUString aStr2 = rtl::OUString::createFromAscii("Line foo bar, ok, differ.");
225 sal_Int32 nValue = rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(),
226 aStr2.getStr(), aStr2.getLength(),
228 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal first 5 characters.", nValue == 0);
231 void compare_004()
233 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must differ.");
234 rtl::OUString aStr2 = rtl::OUString::createFromAscii("Line foo bar, ok, differ.");
236 sal_Int32 nValue = rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(),
237 aStr2.getStr(), aStr2.getLength(),
238 aStr1.getLength());
239 CPPUNIT_ASSERT_MESSAGE("compare failed, strings differ.", nValue != 0);
242 // Change the following lines only, if you add, remove or rename
243 // member functions of the current class,
244 // because these macros are need by auto register mechanism.
246 CPPUNIT_TEST_SUITE(shortenedCompareIgnoreAsciiCase_WithLength);
247 CPPUNIT_TEST(compare_000);
248 CPPUNIT_TEST(compare_000_1);
249 CPPUNIT_TEST(compare_001);
250 CPPUNIT_TEST(compare_002);
251 CPPUNIT_TEST(compare_002_1);
252 CPPUNIT_TEST(compare_003);
253 CPPUNIT_TEST(compare_004);
254 CPPUNIT_TEST_SUITE_END();
255 }; // class compare
258 // // -----------------------------------------------------------------------------
260 // class hashCode : public CppUnit::TestFixture
261 // {
262 // public:
264 // void hashCode_000()
265 // {
266 // sal_Int32 nHashCode = rtl_ustr_hashCode( NULL );
267 // volatile int dummy = 0;
268 // }
270 // void hashCode_001()
271 // {
272 // rtl::OString aStr1 = "Line for a hashCode.";
273 // sal_Int32 nHashCode = rtl_ustr_hashCode( aStr1.getStr() );
274 // t_print("hashcode: %d\n", nHashCode);
275 // // CPPUNIT_ASSERT_MESSAGE("failed.", nValue == 0);
276 // }
278 // void hashCode_002()
279 // {
280 // rtl::OString aStr1 = "Line for a hashCode.";
281 // sal_Int32 nHashCode1 = rtl_ustr_hashCode( aStr1.getStr() );
283 // rtl::OString aStr2 = "Line for a hashCode.";
284 // sal_Int32 nHashCode2 = rtl_ustr_hashCode( aStr2.getStr() );
286 // CPPUNIT_ASSERT_MESSAGE("hashcodes must be equal.", nHashCode1 == nHashCode2 );
287 // }
289 // void hashCode_003()
290 // {
291 // rtl::OString aStr1 = "Line for a hashCode.";
292 // sal_Int32 nHashCode1 = rtl_ustr_hashCode( aStr1.getStr() );
294 // rtl::OString aStr2 = "Line for an other hashcode.";
295 // sal_Int32 nHashCode2 = rtl_ustr_hashCode( aStr2.getStr() );
297 // CPPUNIT_ASSERT_MESSAGE("hashcodes must differ.", nHashCode1 != nHashCode2 );
298 // }
300 // // Change the following lines only, if you add, remove or rename
301 // // member functions of the current class,
302 // // because these macros are need by auto register mechanism.
304 // CPPUNIT_TEST_SUITE(hashCode);
305 // CPPUNIT_TEST(hashCode_000);
306 // CPPUNIT_TEST(hashCode_001);
307 // CPPUNIT_TEST(hashCode_002);
308 // CPPUNIT_TEST(hashCode_003);
309 // CPPUNIT_TEST_SUITE_END();
310 // }; // class compare
313 // // -----------------------------------------------------------------------------
315 class indexOfChar : public CppUnit::TestFixture
317 public:
319 void indexOfChar_000()
321 rtl_ustr_indexOfChar( NULL, 0 );
324 void indexOfChar_001()
326 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a indexOfChar.");
328 sal_Int32 nIndex = rtl_ustr_indexOfChar( aStr1.getStr(), 'L' );
329 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 0);
331 /* sal_Int32 */ nIndex = rtl_ustr_indexOfChar( aStr1.getStr(), 'i' );
332 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 1);
334 /* sal_Int32 */ nIndex = rtl_ustr_indexOfChar( aStr1.getStr(), 'n' );
335 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 2);
337 /* sal_Int32 */ nIndex = rtl_ustr_indexOfChar( aStr1.getStr(), 'e' );
338 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 3);
341 void indexOfChar_002()
343 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a indexOfChar.");
344 sal_Int32 nIndex = rtl_ustr_indexOfChar( aStr1.getStr(), 'y' );
346 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == -1 );
349 // Change the following lines only, if you add, remove or rename
350 // member functions of the current class,
351 // because these macros are need by auto register mechanism.
353 CPPUNIT_TEST_SUITE(indexOfChar);
354 CPPUNIT_TEST(indexOfChar_000);
355 CPPUNIT_TEST(indexOfChar_001);
356 CPPUNIT_TEST(indexOfChar_002);
357 CPPUNIT_TEST_SUITE_END();
358 }; // class indexOfChar
360 // // -----------------------------------------------------------------------------
361 class lastIndexOfChar : public CppUnit::TestFixture
363 public:
365 void lastIndexOfChar_000()
367 rtl_ustr_lastIndexOfChar( NULL, 0 );
370 void lastIndexOfChar_001()
372 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a lastIndexOfChar.");
374 sal_Int32 nIndex = rtl_ustr_lastIndexOfChar( aStr1.getStr(), 'C' );
375 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 22);
377 /* sal_Int32 */ nIndex = rtl_ustr_lastIndexOfChar( aStr1.getStr(), 'h' );
378 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 23);
380 /* sal_Int32 */ nIndex = rtl_ustr_lastIndexOfChar( aStr1.getStr(), 'a' );
381 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 24);
383 /* sal_Int32 */ nIndex = rtl_ustr_lastIndexOfChar( aStr1.getStr(), 'r' );
384 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 25);
387 void lastIndexOfChar_002()
389 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a lastIndexOfChar.");
390 sal_Int32 nIndex = rtl_ustr_lastIndexOfChar( aStr1.getStr(), 'y' );
392 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == -1 );
395 // Change the following lines only, if you add, remove or rename
396 // member functions of the current class,
397 // because these macros are need by auto register mechanism.
399 CPPUNIT_TEST_SUITE(lastIndexOfChar);
400 CPPUNIT_TEST(lastIndexOfChar_000);
401 CPPUNIT_TEST(lastIndexOfChar_001);
402 CPPUNIT_TEST(lastIndexOfChar_002);
403 CPPUNIT_TEST_SUITE_END();
404 }; // class lastIndexOfChar
407 // -----------------------------------------------------------------------------
409 class indexOfStr : public CppUnit::TestFixture
411 public:
413 void indexOfStr_000()
415 rtl_ustr_indexOfStr( NULL, 0 );
418 void indexOfStr_000_1()
420 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a indexOfStr.");
421 rtl_ustr_indexOfStr( aStr1.getStr(), 0 );
424 void indexOfStr_001()
426 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a indexOfStr.");
428 rtl::OUString suSearch = rtl::OUString::createFromAscii("Line");
429 sal_Int32 nIndex = rtl_ustr_indexOfStr( aStr1.getStr(), suSearch );
430 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 0);
432 /* rtl::OUString */ suSearch = rtl::OUString::createFromAscii("for");
433 /* sal_Int32 */ nIndex = rtl_ustr_indexOfStr( aStr1.getStr(), suSearch );
434 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 5);
436 /* rtl::OUString */ suSearch = rtl::OUString::createFromAscii("a");
437 /* sal_Int32 */ nIndex = rtl_ustr_indexOfStr( aStr1.getStr(), suSearch );
438 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 9);
440 /* rtl::OUString */ suSearch = rtl::OUString::createFromAscii("a index");
441 /* sal_Int32 */ nIndex = rtl_ustr_indexOfStr( aStr1.getStr(), suSearch );
442 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex ==9);
445 void indexOfStr_002()
447 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a indexOfStr.");
448 rtl::OUString suSearch = rtl::OUString::createFromAscii("not exist");
449 sal_Int32 nIndex = rtl_ustr_indexOfStr( aStr1.getStr(), suSearch );
451 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == -1 );
454 // Change the following lines only, if you add, remove or rename
455 // member functions of the current class,
456 // because these macros are need by auto register mechanism.
458 CPPUNIT_TEST_SUITE(indexOfStr);
459 CPPUNIT_TEST(indexOfStr_000);
460 CPPUNIT_TEST(indexOfStr_001);
461 CPPUNIT_TEST(indexOfStr_002);
462 CPPUNIT_TEST_SUITE_END();
463 }; // class compare
464 // -----------------------------------------------------------------------------
467 class lastIndexOfStr : public CppUnit::TestFixture
469 public:
471 void lastIndexOfStr_000()
473 rtl_ustr_lastIndexOfStr( NULL, NULL );
476 void lastIndexOfStr_000_1()
478 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a lastIndexOfStr.");
479 rtl_ustr_lastIndexOfStr( aStr1.getStr(), NULL );
482 void lastIndexOfStr_001()
484 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a lastIndexOfStr.");
485 rtl::OUString aSearchStr = rtl::OUString::createFromAscii("Index");
487 sal_Int32 nIndex = rtl_ustr_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() );
488 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 15);
490 /* rtl::OString */ aSearchStr = rtl::OUString::createFromAscii("Line");
491 /* sal_Int32 */ nIndex = rtl_ustr_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() );
492 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 0);
494 /* rtl::OString */ aSearchStr = rtl::OUString::createFromAscii("");
495 /* sal_Int32 */ nIndex = rtl_ustr_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() );
496 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == -1);
499 void lastIndexOfStr_002()
501 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a lastIndexOfStr.");
502 rtl::OUString aSearchStr = rtl::OUString::createFromAscii("foo");
503 sal_Int32 nIndex = rtl_ustr_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() );
505 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == -1 );
508 void lastIndexOfStr_003()
510 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a lastIndexOfStr.");
511 rtl::OUString aSearchStr = rtl::OUString::createFromAscii("O");
512 sal_Int32 nIndex = rtl_ustr_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() );
514 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 20 );
517 // Change the following lines only, if you add, remove or rename
518 // member functions of the current class,
519 // because these macros are need by auto register mechanism.
521 CPPUNIT_TEST_SUITE(lastIndexOfStr);
522 CPPUNIT_TEST(lastIndexOfStr_000);
523 CPPUNIT_TEST(lastIndexOfStr_001);
524 CPPUNIT_TEST(lastIndexOfStr_002);
525 CPPUNIT_TEST(lastIndexOfStr_003);
526 CPPUNIT_TEST_SUITE_END();
527 }; // class lastIndexOfStr
529 // -----------------------------------------------------------------------------
531 class replaceChar : public CppUnit::TestFixture
533 public:
535 void replaceChar_000()
537 rtl_ustr_replaceChar( NULL, 0, 0 );
540 void replaceChar_001()
542 rtl::OUString aStr1 = rtl::OUString::createFromAscii("replace char.");
543 rtl::OUString aShouldStr1 = rtl::OUString::createFromAscii("ruplacu char.");
545 sal_uInt32 nLength = aStr1.getLength() * sizeof(sal_Unicode);
546 sal_Unicode* pStr = (sal_Unicode*) malloc( nLength + sizeof(sal_Unicode)); // length + 1 (null terminator)
547 CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL);
548 memset(pStr, 0, nLength + sizeof(sal_Unicode));
549 memcpy(pStr, aStr1.getStr(), nLength);
551 rtl_ustr_replaceChar( pStr, 'e', 'u' );
552 rtl::OUString suStr(pStr, aStr1.getLength());
554 CPPUNIT_ASSERT_MESSAGE("replace failed", aShouldStr1.equals(suStr) == sal_True);
555 free(pStr);
558 // Change the following lines only, if you add, remove or rename
559 // member functions of the current class,
560 // because these macros are need by auto register mechanism.
562 CPPUNIT_TEST_SUITE(replaceChar);
563 CPPUNIT_TEST(replaceChar_000);
564 CPPUNIT_TEST(replaceChar_001);
565 CPPUNIT_TEST_SUITE_END();
566 }; // class replaceChar
568 // -----------------------------------------------------------------------------
570 class replaceChar_WithLength : public CppUnit::TestFixture
572 public:
574 void replaceChar_WithLength_000()
576 rtl_ustr_replaceChar_WithLength( NULL, 0, 0, 0 );
579 void replaceChar_WithLength_000_1()
581 rtl_ustr_replaceChar_WithLength( NULL, 1, 0, 0 );
583 void replaceChar_WithLength_001()
585 rtl::OUString aStr1 = rtl::OUString::createFromAscii("replace char.");
586 rtl::OUString aShouldStr1 = rtl::OUString::createFromAscii("ruplace char.");
588 sal_uInt32 nLength = aStr1.getLength() * sizeof(sal_Unicode);
589 sal_Unicode* pStr = (sal_Unicode*) malloc(nLength);
590 CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL);
591 memcpy(pStr, aStr1.getStr(), nLength);
593 rtl_ustr_replaceChar_WithLength( pStr, 6, 'e', 'u' );
594 rtl::OUString suStr(pStr, aStr1.getLength());
596 CPPUNIT_ASSERT_MESSAGE("replace failed", aShouldStr1.equals(suStr) == sal_True);
597 free(pStr);
600 void replaceChar_WithLength_002()
602 rtl::OUString aStr1 = rtl::OUString::createFromAscii("eeeeeeeeeeeee");
603 rtl::OUString aShouldStr1 = rtl::OUString::createFromAscii("uuuuuueeeeeee");
605 sal_uInt32 nLength = aStr1.getLength() * sizeof(sal_Unicode);
606 sal_Unicode* pStr = (sal_Unicode*) malloc(nLength); // no null terminator is need
607 CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL);
608 memcpy(pStr, aStr1.getStr(), nLength);
610 rtl_ustr_replaceChar_WithLength( pStr, 6, 'e', 'u' );
611 rtl::OUString suStr(pStr, aStr1.getLength());
613 CPPUNIT_ASSERT_MESSAGE("replace failed", aShouldStr1.equals(suStr) == sal_True);
614 free(pStr);
617 // Change the following lines only, if you add, remove or rename
618 // member functions of the current class,
619 // because these macros are need by auto register mechanism.
621 CPPUNIT_TEST_SUITE(replaceChar_WithLength);
622 CPPUNIT_TEST(replaceChar_WithLength_000);
623 CPPUNIT_TEST(replaceChar_WithLength_000_1);
624 CPPUNIT_TEST(replaceChar_WithLength_001);
625 CPPUNIT_TEST(replaceChar_WithLength_002);
626 CPPUNIT_TEST_SUITE_END();
627 }; // class replaceChar
630 // -----------------------------------------------------------------------------
632 class toAsciiLowerCase : public CppUnit::TestFixture
634 public:
636 void toAsciiLowerCase_000()
638 rtl_ustr_toAsciiLowerCase( NULL );
641 void toAsciiLowerCase_001()
643 rtl::OUString aStr1 = rtl::OUString::createFromAscii("CHANGE THIS TO ASCII LOWER CASE.");
644 rtl::OUString aShouldStr1 = rtl::OUString::createFromAscii("change this to ascii lower case.");
646 sal_uInt32 nLength = aStr1.getLength() * sizeof(sal_Unicode);
647 sal_Unicode* pStr = (sal_Unicode*) malloc(nLength + sizeof(sal_Unicode) ); // we need to add '\0' so one more
648 CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL);
649 memset(pStr, 0, nLength + sizeof(sal_Unicode)); // empty the sal_Unicode array
650 memcpy(pStr, aStr1.getStr(), nLength);
652 rtl_ustr_toAsciiLowerCase( pStr );
653 rtl::OUString suStr(pStr, aStr1.getLength());
655 CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1.equals(suStr) == sal_True);
656 free(pStr);
659 // Change the following lines only, if you add, remove or rename
660 // member functions of the current class,
661 // because these macros are need by auto register mechanism.
663 CPPUNIT_TEST_SUITE(toAsciiLowerCase);
664 CPPUNIT_TEST(toAsciiLowerCase_000);
665 CPPUNIT_TEST(toAsciiLowerCase_001);
666 CPPUNIT_TEST_SUITE_END();
667 }; // class replaceChar
670 class toAsciiLowerCase_WithLength : public CppUnit::TestFixture
672 public:
674 void toAsciiLowerCase_WithLength_000()
676 rtl_ustr_toAsciiLowerCase_WithLength( NULL, 0 );
679 void toAsciiLowerCase_WithLength_001()
681 rtl::OUString aStr1 = rtl::OUString::createFromAscii("CHANGE THIS TO ASCII LOWER CASE.");
682 rtl::OUString aShouldStr1 = rtl::OUString::createFromAscii("change thiS TO ASCII LOWER CASE.");
684 sal_uInt32 nLength = aStr1.getLength() * sizeof(sal_Unicode);
685 sal_Unicode* pStr = (sal_Unicode*) malloc(nLength);
686 CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL);
687 memcpy(pStr, aStr1.getStr(), nLength);
689 rtl_ustr_toAsciiLowerCase_WithLength( pStr, 10 );
691 rtl::OUString suStr(pStr, aStr1.getLength());
692 sal_Bool bResult = aShouldStr1.equals(suStr);
694 printOUString(suStr);
695 t_print("Result length: %d\n", suStr.getLength() );
696 t_print("Result: %d\n", bResult);
698 CPPUNIT_ASSERT_MESSAGE("failed", bResult == sal_True);
699 free(pStr);
702 // Change the following lines only, if you add, remove or rename
703 // member functions of the current class,
704 // because these macros are need by auto register mechanism.
706 CPPUNIT_TEST_SUITE(toAsciiLowerCase_WithLength);
707 CPPUNIT_TEST(toAsciiLowerCase_WithLength_000);
708 CPPUNIT_TEST(toAsciiLowerCase_WithLength_001);
709 CPPUNIT_TEST_SUITE_END();
710 }; // class replaceChar
712 // -----------------------------------------------------------------------------
714 class toAsciiUpperCase : public CppUnit::TestFixture
716 public:
718 void toAsciiUpperCase_000()
720 rtl_ustr_toAsciiUpperCase( NULL );
723 void toAsciiUpperCase_001()
725 rtl::OUString aStr1 = rtl::OUString::createFromAscii("change this to ascii upper case.");
726 rtl::OUString aShouldStr1 = rtl::OUString::createFromAscii("CHANGE THIS TO ASCII UPPER CASE.");
728 sal_uInt32 nLength = aStr1.getLength() * sizeof(sal_Unicode);
729 sal_Unicode* pStr = (sal_Unicode*) malloc(nLength + sizeof(sal_Unicode)); // length + null terminator
730 CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL);
731 memset(pStr, 0, nLength + sizeof(sal_Unicode));
732 memcpy(pStr, aStr1.getStr(), nLength);
734 rtl_ustr_toAsciiUpperCase( pStr );
735 rtl::OUString suStr(pStr, aStr1.getLength());
737 CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1.equals(suStr) == sal_True);
738 free(pStr);
741 // Change the following lines only, if you add, remove or rename
742 // member functions of the current class,
743 // because these macros are need by auto register mechanism.
745 CPPUNIT_TEST_SUITE(toAsciiUpperCase);
746 CPPUNIT_TEST(toAsciiUpperCase_000);
747 CPPUNIT_TEST(toAsciiUpperCase_001);
748 CPPUNIT_TEST_SUITE_END();
749 }; // class replaceChar
752 class toAsciiUpperCase_WithLength : public CppUnit::TestFixture
754 public:
756 void toAsciiUpperCase_WithLength_000()
758 rtl_ustr_toAsciiUpperCase_WithLength( NULL, 0 );
761 void toAsciiUpperCase_WithLength_001()
763 rtl::OUString aStr1 = rtl::OUString::createFromAscii("change this to ascii lower case.");
764 rtl::OUString aShouldStr1 = rtl::OUString::createFromAscii("CHANGE THIs to ascii lower case.");
766 sal_uInt32 nLength = aStr1.getLength() * sizeof(sal_Unicode);
767 sal_Unicode* pStr = (sal_Unicode*) malloc(nLength);
768 CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL);
770 memcpy(pStr, aStr1.getStr(), nLength);
771 rtl_ustr_toAsciiUpperCase_WithLength( pStr, 10 );
772 rtl::OUString suStr(pStr, aStr1.getLength());
774 // t_print("Uppercase with length: '%s'\n", aStr1.getStr());
775 CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1.equals(suStr) == sal_True);
776 free(pStr);
779 // Change the following lines only, if you add, remove or rename
780 // member functions of the current class,
781 // because these macros are need by auto register mechanism.
783 CPPUNIT_TEST_SUITE(toAsciiUpperCase_WithLength);
784 CPPUNIT_TEST(toAsciiUpperCase_WithLength_000);
785 CPPUNIT_TEST(toAsciiUpperCase_WithLength_001);
786 CPPUNIT_TEST_SUITE_END();
787 }; // class replaceChar
790 // -----------------------------------------------------------------------------
792 class trim_WithLength : public CppUnit::TestFixture
794 public:
795 void trim_WithLength_000()
797 rtl_ustr_trim_WithLength(NULL, 0);
798 // should not GPF
801 void trim_WithLength_000_1()
803 rtl::OUString suStr = rtl::OUString::createFromAscii(" trim this");
805 sal_uInt32 nLength = suStr.getLength() * sizeof(sal_Unicode);
806 sal_Unicode *pStr = (sal_Unicode*)malloc(nLength);
807 memcpy(pStr, suStr.getStr(), nLength);
809 rtl_ustr_trim_WithLength( pStr, 0 );
810 free(pStr);
813 void trim_WithLength_001()
815 rtl::OUString suStr = rtl::OUString::createFromAscii(" trim this");
816 sal_uInt32 nLength = suStr.getLength() * sizeof(sal_Unicode);
817 sal_Unicode *pStr = (sal_Unicode*)malloc(nLength);
818 memcpy(pStr, suStr.getStr(), nLength);
820 rtl_ustr_trim_WithLength( pStr, 2 );
822 CPPUNIT_ASSERT_MESSAGE("string should be empty", rtl::OUString(pStr).getLength() == 0);
823 free(pStr);
827 void trim_WithLength_002()
829 rtl::OUString suStr = rtl::OUString::createFromAscii("trim this");
831 sal_uInt32 nLength = suStr.getLength() * sizeof(sal_Unicode);
832 sal_Unicode *pStr = (sal_Unicode*)malloc(nLength);
833 memcpy(pStr, suStr.getStr(), nLength);
835 rtl_ustr_trim_WithLength( pStr, 5 );
837 CPPUNIT_ASSERT_MESSAGE("string should contain 'trim'", rtl::OUString(pStr).getLength() == 4);
838 free(pStr);
842 void trim_WithLength_003()
844 rtl::OUString suStr = rtl::OUString::createFromAscii(" trim this");
846 sal_uInt32 nLength = suStr.getLength() * sizeof(sal_Unicode);
847 sal_Unicode *pStr = (sal_Unicode*)malloc(nLength);
848 memcpy(pStr, suStr.getStr(), nLength);
850 rtl_ustr_trim_WithLength( pStr, 11 );
852 CPPUNIT_ASSERT_MESSAGE("string should contain 'trim'", rtl::OUString(pStr).getLength() == 4);
853 free(pStr);
856 void trim_WithLength_004()
858 rtl::OUString suStr = rtl::OUString::createFromAscii("\r\n\t \n\r trim \n this");
860 sal_uInt32 nLength = suStr.getLength() * sizeof(sal_Unicode);
861 sal_Unicode *pStr = (sal_Unicode*)malloc(nLength);
862 memcpy(pStr, suStr.getStr(), nLength);
864 rtl_ustr_trim_WithLength( pStr, 17 );
866 CPPUNIT_ASSERT_MESSAGE("string should contain 'trim'", rtl::OUString(pStr).getLength() == 4);
867 free(pStr);
870 void trim_WithLength_005()
872 rtl::OUString suStr = rtl::OUString::createFromAscii("\r\n\t \n\r trim \t this \n\r\t\t ");
874 sal_uInt32 nLength = suStr.getLength() * sizeof(sal_Unicode);
875 sal_Unicode *pStr = (sal_Unicode*)malloc(nLength);
876 memcpy(pStr, suStr.getStr(), nLength);
878 rtl_ustr_trim_WithLength( pStr, suStr.getLength() );
880 CPPUNIT_ASSERT_MESSAGE("string should contain 'trim \\t this'", rtl::OUString(pStr).getLength() == 11);
881 free(pStr);
884 // Change the following lines only, if you add, remove or rename
885 // member functions of the current class,
886 // because these macros are need by auto register mechanism.
888 CPPUNIT_TEST_SUITE(trim_WithLength);
889 CPPUNIT_TEST(trim_WithLength_000);
890 CPPUNIT_TEST(trim_WithLength_000_1);
891 CPPUNIT_TEST(trim_WithLength_001);
892 CPPUNIT_TEST(trim_WithLength_002);
893 CPPUNIT_TEST(trim_WithLength_003);
894 CPPUNIT_TEST(trim_WithLength_004);
895 CPPUNIT_TEST(trim_WithLength_005);
896 CPPUNIT_TEST_SUITE_END();
899 // -----------------------------------------------------------------------------
901 class valueOfChar : public CppUnit::TestFixture
903 public:
904 void valueOfChar_000()
906 rtl_ustr_valueOfChar(NULL, 0);
907 // should not GPF
909 void valueOfChar_001()
911 sal_Unicode *pStr = (sal_Unicode*)malloc(RTL_USTR_MAX_VALUEOFCHAR);
912 if (pStr)
914 rtl_ustr_valueOfChar(pStr, 'A');
916 CPPUNIT_ASSERT_MESSAGE("string should contain 'A'", pStr[0] == L'A');
917 free(pStr);
921 // Change the following lines only, if you add, remove or rename
922 // member functions of the current class,
923 // because these macros are need by auto register mechanism.
925 CPPUNIT_TEST_SUITE(valueOfChar);
926 CPPUNIT_TEST(valueOfChar_000);
927 CPPUNIT_TEST(valueOfChar_001);
928 CPPUNIT_TEST_SUITE_END();
934 class ascii_compare_WithLength : public CppUnit::TestFixture
936 public:
937 void zero_length()
939 sal_Unicode pUnicode[] = {0xffff, 0xffff};
940 char const * pAscii = "reference";
942 sal_Int32 value = rtl_ustr_ascii_compare_WithLength(pUnicode, 0, pAscii);
943 CPPUNIT_ASSERT_MESSAGE("ref string is empty, compare failed, needs to be <0.", value < 0);
946 void equal_ascii_shorter()
948 rtl::OUString refStr(RTL_CONSTASCII_USTRINGPARAM("referenceString"));
949 char const * pAscii = "reference";
951 sal_Int32 value = rtl_ustr_ascii_compare_WithLength(refStr.pData->buffer, refStr.pData->length, pAscii);
952 CPPUNIT_ASSERT_MESSAGE("ref string is bigger, compare failed, needs to be >0.", value > 0);
955 void equal_ascii_shorter_asciiLength()
957 rtl::OUString refStr(RTL_CONSTASCII_USTRINGPARAM("referenceString"));
958 char const * pAscii = "reference";
960 sal_Int32 value = rtl_ustr_ascii_compare_WithLength(refStr.pData->buffer, rtl_str_getLength(pAscii), pAscii);
961 CPPUNIT_ASSERT_MESSAGE("ref string is bigger despite ascii length, compare failed, needs to be == 0.", value == 0);
964 void equal_ref_shorter()
966 rtl::OUString refStr(RTL_CONSTASCII_USTRINGPARAM("reference"));
967 char const * pAscii = "referenceString";
969 sal_Int32 value = rtl_ustr_ascii_compare_WithLength(refStr.pData->buffer, refStr.pData->length, pAscii);
970 CPPUNIT_ASSERT_MESSAGE("ascii string is bigger, but only compared to ref length, needs to be 0.", value < 0);
973 void equal()
975 rtl::OUString refStr(RTL_CONSTASCII_USTRINGPARAM("reference"));
976 char const * pAscii = "reference";
978 sal_Int32 value = rtl_ustr_ascii_compare_WithLength(refStr.pData->buffer, refStr.pData->length, pAscii);
979 CPPUNIT_ASSERT_MESSAGE("strings are equal, compare failed, needs to be 0.", value == 0);
982 void unequal_reference_bigger()
984 rtl::OUString refStr(RTL_CONSTASCII_USTRINGPARAM("defghi"));
985 char const * pAscii = "abc";
987 sal_Int32 value = rtl_ustr_ascii_compare_WithLength(refStr.pData->buffer, refStr.pData->length, pAscii);
988 CPPUNIT_ASSERT_MESSAGE("strings are unequal and ref is bigger, needs to be >0.", value > 0);
991 void unequal_ascii_bigger()
993 rtl::OUString refStr(RTL_CONSTASCII_USTRINGPARAM("abc"));
994 char const * pAscii = "defghi";
996 sal_Int32 value = rtl_ustr_ascii_compare_WithLength(refStr.pData->buffer, refStr.pData->length, pAscii);
998 CPPUNIT_ASSERT_MESSAGE("strings are unequal and ascii is bigger, needs to be <0.", value < 0);
1001 CPPUNIT_TEST_SUITE(ascii_compare_WithLength);
1002 CPPUNIT_TEST(zero_length);
1003 CPPUNIT_TEST(equal_ascii_shorter);
1004 CPPUNIT_TEST(equal_ascii_shorter_asciiLength);
1005 CPPUNIT_TEST(equal_ref_shorter);
1006 CPPUNIT_TEST(equal);
1007 CPPUNIT_TEST(unequal_reference_bigger);
1008 CPPUNIT_TEST(unequal_ascii_bigger);
1009 CPPUNIT_TEST_SUITE_END();
1015 class ascii_shortenedCompareIgnoreAsciiCase_WithLength : public CppUnit::TestFixture
1017 public:
1019 void ascii_shortenedCompareIgnoreAsciiCase_WithLength_000()
1021 rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( NULL, 0, NULL, 0);
1022 // should not GPF
1025 void ascii_shortenedCompareIgnoreAsciiCase_WithLength_000_1()
1027 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal.");
1028 rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(), NULL, 0);
1029 // should not GPF
1031 void ascii_shortenedCompareIgnoreAsciiCase_WithLength_000_2()
1033 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal.");
1034 rtl::OString sStr2 = "Line is shorter.";
1035 rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), sStr2.getLength(), sStr2.getStr(), 0);
1036 // should not GPF
1038 void ascii_shortenedCompareIgnoreAsciiCase_WithLength_001()
1040 rtl::OUString suStr1;
1041 rtl::OString sStr2;
1043 sal_Int32 nValue = rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( suStr1, 0, sStr2.getStr(), 0);
1044 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
1047 void ascii_shortenedCompareIgnoreAsciiCase_WithLength_002()
1049 rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must be equal.");
1050 rtl::OString sStr2 = "Line must be equal.";
1052 sal_Int32 nValue = rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( suStr1.getStr(), suStr1.getLength(), sStr2.getStr(), sStr2.getLength());
1053 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
1056 void ascii_shortenedCompareIgnoreAsciiCase_WithLength_003()
1058 rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must differ.");
1059 rtl::OString sStr2 = "Line must be differ and longer.";
1061 sal_Int32 nValue = rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( suStr1.getStr(), suStr1.getLength(), sStr2.getStr(), sStr2.getLength());
1062 CPPUNIT_ASSERT_MESSAGE("compare failed, strings differ.", nValue != 0);
1065 // Change the following lines only, if you add, remove or rename
1066 // member functions of the current class,
1067 // because these macros are need by auto register mechanism.
1069 CPPUNIT_TEST_SUITE(ascii_shortenedCompareIgnoreAsciiCase_WithLength);
1070 CPPUNIT_TEST(ascii_shortenedCompareIgnoreAsciiCase_WithLength_000);
1071 CPPUNIT_TEST(ascii_shortenedCompareIgnoreAsciiCase_WithLength_000_1);
1072 CPPUNIT_TEST(ascii_shortenedCompareIgnoreAsciiCase_WithLength_000_2);
1073 CPPUNIT_TEST(ascii_shortenedCompareIgnoreAsciiCase_WithLength_001);
1074 CPPUNIT_TEST(ascii_shortenedCompareIgnoreAsciiCase_WithLength_002);
1075 CPPUNIT_TEST(ascii_shortenedCompareIgnoreAsciiCase_WithLength_003);
1076 CPPUNIT_TEST_SUITE_END();
1077 }; // class ascii_shortenedCompareIgnoreAsciiCase_WithLength
1079 // -----------------------------------------------------------------------------
1081 class ascii_compareIgnoreAsciiCase_WithLength : public CppUnit::TestFixture
1083 public:
1085 void ascii_compareIgnoreAsciiCase_WithLength_000()
1087 rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( NULL, 0, NULL);
1088 // should not GPF
1091 void ascii_compareIgnoreAsciiCase_WithLength_000_1()
1093 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal.");
1094 rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( aStr1.getStr(), 0, NULL);
1095 // should not GPF
1097 void ascii_compareIgnoreAsciiCase_WithLength_000_2()
1099 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal.");
1100 rtl::OString sStr2 = "Line is shorter.";
1101 rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( aStr1.getStr(), sStr2.getLength(), sStr2.getStr());
1102 // should not GPF
1104 void ascii_compareIgnoreAsciiCase_WithLength_001()
1106 rtl::OUString suStr1;
1107 rtl::OString sStr2;
1109 sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( suStr1, 0, sStr2.getStr());
1110 CPPUNIT_ASSERT_MESSAGE("compareIgnoreAsciiCase_WithLength failed, strings are equal.", nValue == 0);
1113 void ascii_compareIgnoreAsciiCase_WithLength_002()
1115 rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must be equal.");
1116 rtl::OString sStr2 = "Line must be equal.";
1118 sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( suStr1.getStr(), suStr1.getLength(), sStr2.getStr());
1119 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
1122 void ascii_compareIgnoreAsciiCase_WithLength_003()
1124 rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must differ.");
1125 rtl::OString sStr2 = "Line must be differ and longer.";
1127 sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( suStr1.getStr(), suStr1.getLength(), sStr2.getStr());
1128 CPPUNIT_ASSERT_MESSAGE("compare failed, strings differ.", nValue != 0);
1131 // Change the following lines only, if you add, remove or rename
1132 // member functions of the current class,
1133 // because these macros are need by auto register mechanism.
1135 CPPUNIT_TEST_SUITE(ascii_compareIgnoreAsciiCase_WithLength);
1136 CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_WithLength_000);
1137 CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_WithLength_000_1);
1138 CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_WithLength_000_2);
1139 CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_WithLength_001);
1140 CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_WithLength_002);
1141 CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_WithLength_003);
1142 CPPUNIT_TEST_SUITE_END();
1143 }; // class ascii_compareIgnoreAsciiCase_WithLength
1145 // -----------------------------------------------------------------------------
1147 class ascii_compare : public CppUnit::TestFixture
1149 public:
1151 void ascii_compare_000()
1153 rtl_ustr_ascii_compare( NULL, NULL);
1154 // should not GPF
1157 void ascii_compare_000_1()
1159 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal.");
1160 rtl_ustr_ascii_compare( aStr1.getStr(), NULL);
1161 // should not GPF
1163 void ascii_compare_001()
1165 rtl::OUString suStr1;
1166 rtl::OString sStr2;
1168 sal_Int32 nValue = rtl_ustr_ascii_compare( suStr1, sStr2.getStr());
1169 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
1172 void ascii_compare_002()
1174 rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must be equal.");
1175 rtl::OString sStr2 = "Line must be equal.";
1177 sal_Int32 nValue = rtl_ustr_ascii_compare( suStr1.getStr(), sStr2.getStr());
1178 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
1181 void ascii_compare_003()
1183 rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must differ.");
1184 rtl::OString sStr2 = "Line foo bar, ok, differ.";
1186 sal_Int32 nValue = rtl_ustr_ascii_compare( suStr1.getStr(), sStr2.getStr());
1187 CPPUNIT_ASSERT_MESSAGE("compare failed, strings differ.", nValue != 0);
1190 // Change the following lines only, if you add, remove or rename
1191 // member functions of the current class,
1192 // because these macros are need by auto register mechanism.
1194 CPPUNIT_TEST_SUITE(ascii_compare);
1195 CPPUNIT_TEST(ascii_compare_000);
1196 CPPUNIT_TEST(ascii_compare_000_1);
1197 CPPUNIT_TEST(ascii_compare_001);
1198 CPPUNIT_TEST(ascii_compare_002);
1199 CPPUNIT_TEST(ascii_compare_003);
1200 CPPUNIT_TEST_SUITE_END();
1201 }; // class ascii_compare
1203 // -----------------------------------------------------------------------------
1205 class ascii_compareIgnoreAsciiCase : public CppUnit::TestFixture
1207 public:
1209 void ascii_compareIgnoreAsciiCase_000()
1211 rtl_ustr_ascii_compareIgnoreAsciiCase( NULL, NULL);
1212 // should not GPF
1215 void ascii_compareIgnoreAsciiCase_000_1()
1217 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal.");
1218 rtl_ustr_ascii_compareIgnoreAsciiCase( aStr1.getStr(), NULL);
1219 // should not GPF
1221 void ascii_compareIgnoreAsciiCase_001()
1223 rtl::OUString suStr1;
1224 rtl::OString sStr2;
1226 sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase( suStr1, sStr2.getStr());
1227 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
1230 void ascii_compareIgnoreAsciiCase_002()
1232 rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must be equal.");
1233 rtl::OString sStr2 = "Line must be equal.";
1235 sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase( suStr1.getStr(), sStr2.getStr());
1236 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
1239 void ascii_compareIgnoreAsciiCase_002_1()
1241 rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must be equal, when ignore case.");
1242 rtl::OString sStr2 = "LINE MUST BE EQUAL, WHEN IGNORE CASE.";
1244 sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase( suStr1.getStr(), sStr2.getStr());
1245 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal (if case insensitve).", nValue == 0);
1248 void ascii_compareIgnoreAsciiCase_003()
1250 rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must differ.");
1251 rtl::OString sStr2 = "Line foo bar, ok, differ.";
1253 sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase( suStr1.getStr(), sStr2.getStr());
1254 CPPUNIT_ASSERT_MESSAGE("compare failed, strings differ.", nValue != 0);
1257 //! LLA: some more tests with some high level strings
1259 // void ascii_compareIgnoreAsciiCase_001()
1260 // {
1261 // rtl::OUString suStr1 = rtl::OUString::createFromAscii("change this to ascii upper case.");
1262 // rtl::OUString aShouldStr1 = rtl::OUString::createFromAscii("CHANGE THIS TO ASCII UPPER CASE.");
1264 // sal_uInt32 nLength = suStr1.getLength() * sizeof(sal_Unicode);
1265 // sal_Unicode* pStr = (sal_Unicode*) malloc(nLength + sizeof(sal_Unicode)); // length + null terminator
1266 // CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL);
1267 // memset(pStr, 0, nLength + sizeof(sal_Unicode));
1268 // memcpy(pStr, suStr1.getStr(), nLength);
1270 // rtl_ustr_ascii_compareIgnoreAsciiCase( pStr );
1271 // rtl::OUString suStr(pStr, suStr1.getLength());
1273 // CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1.equals(suStr) == sal_True);
1274 // free(pStr);
1275 // }
1277 // Change the following lines only, if you add, remove or rename
1278 // member functions of the current class,
1279 // because these macros are need by auto register mechanism.
1281 CPPUNIT_TEST_SUITE(ascii_compareIgnoreAsciiCase);
1282 CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_000);
1283 CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_000_1);
1284 CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_001);
1285 CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_002);
1286 CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_002_1);
1287 CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_003);
1288 CPPUNIT_TEST_SUITE_END();
1289 }; // class ascii_compareIgnoreAsciiCase
1292 // sample out of inc/rtl/ustring.hxx
1293 // rtl_uString * pToken = NULL;
1294 // sal_Int32 nIndex = 0;
1295 // do
1296 // {
1297 // ...
1298 // nIndex = rtl_uString_getToken(&pToken, pStr, 0, ';', nIndex);
1299 // ...
1300 // }
1301 // while (nIndex >= 0);
1303 class getToken : public CppUnit::TestFixture
1305 public:
1307 void getToken_000()
1309 rtl_ustr_ascii_compareIgnoreAsciiCase( NULL, NULL);
1310 // should not GPF
1313 void ascii_compareIgnoreAsciiCase_000_1()
1315 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal.");
1316 rtl_ustr_ascii_compareIgnoreAsciiCase( aStr1.getStr(), NULL);
1317 // should not GPF
1319 void ascii_compareIgnoreAsciiCase_001()
1321 rtl::OUString suStr1;
1322 rtl::OString sStr2;
1324 sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase( suStr1, sStr2.getStr());
1325 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
1328 void ascii_compareIgnoreAsciiCase_002()
1330 rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must be equal.");
1331 rtl::OString sStr2 = "Line must be equal.";
1333 sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase( suStr1.getStr(), sStr2.getStr());
1334 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0);
1337 void ascii_compareIgnoreAsciiCase_002_1()
1339 rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must be equal, when ignore case.");
1340 rtl::OString sStr2 = "LINE MUST BE EQUAL, WHEN IGNORE CASE.";
1342 sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase( suStr1.getStr(), sStr2.getStr());
1343 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal (if case insensitve).", nValue == 0);
1346 void ascii_compareIgnoreAsciiCase_003()
1348 rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must differ.");
1349 rtl::OString sStr2 = "Line foo bar, ok, differ.";
1351 sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase( suStr1.getStr(), sStr2.getStr());
1352 CPPUNIT_ASSERT_MESSAGE("compare failed, strings differ.", nValue != 0);
1355 //! LLA: some more tests with some high level strings
1357 // void ascii_compareIgnoreAsciiCase_001()
1358 // {
1359 // rtl::OUString suStr1 = rtl::OUString::createFromAscii("change this to ascii upper case.");
1360 // rtl::OUString aShouldStr1 = rtl::OUString::createFromAscii("CHANGE THIS TO ASCII UPPER CASE.");
1362 // sal_uInt32 nLength = suStr1.getLength() * sizeof(sal_Unicode);
1363 // sal_Unicode* pStr = (sal_Unicode*) malloc(nLength + sizeof(sal_Unicode)); // length + null terminator
1364 // CPPUNIT_ASSERT_MESSAGE("can't get memory for test", pStr != NULL);
1365 // memset(pStr, 0, nLength + sizeof(sal_Unicode));
1366 // memcpy(pStr, suStr1.getStr(), nLength);
1368 // rtl_ustr_ascii_compareIgnoreAsciiCase( pStr );
1369 // rtl::OUString suStr(pStr, suStr1.getLength());
1371 // CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1.equals(suStr) == sal_True);
1372 // free(pStr);
1373 // }
1375 // Change the following lines only, if you add, remove or rename
1376 // member functions of the current class,
1377 // because these macros are need by auto register mechanism.
1379 CPPUNIT_TEST_SUITE(ascii_compareIgnoreAsciiCase);
1380 CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_000);
1381 CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_000_1);
1382 CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_001);
1383 CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_002);
1384 CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_002_1);
1385 CPPUNIT_TEST(ascii_compareIgnoreAsciiCase_003);
1386 CPPUNIT_TEST_SUITE_END();
1387 }; // class ascii_compareIgnoreAsciiCase
1389 // -----------------------------------------------------------------------------
1390 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::compare, "rtl_ustr");
1391 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::compareIgnoreAsciiCase, "rtl_ustr");
1393 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::ascii_compare_WithLength, "rtl_ustr");
1395 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::shortenedCompareIgnoreAsciiCase_WithLength, "rtl_ustr");
1396 // CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::hashCode, "rtl_ustr");
1398 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::indexOfChar, "rtl_ustr");
1399 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::lastIndexOfChar, "rtl_ustr");
1400 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::indexOfStr, "rtl_ustr");
1401 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::lastIndexOfStr, "rtl_ustr");
1403 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::replaceChar, "rtl_ustr");
1404 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::replaceChar_WithLength, "rtl_ustr");
1406 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::toAsciiLowerCase, "rtl_ustr");
1407 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::toAsciiLowerCase_WithLength, "rtl_ustr");
1408 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::toAsciiUpperCase, "rtl_ustr");
1409 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::toAsciiUpperCase_WithLength, "rtl_ustr");
1411 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::trim_WithLength, "rtl_ustr");
1412 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::valueOfChar, "rtl_ustr");
1414 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::ascii_compare, "rtl_ustr");
1415 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::ascii_compareIgnoreAsciiCase, "rtl_ustr");
1416 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::ascii_compareIgnoreAsciiCase_WithLength, "rtl_ustr");
1417 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::ascii_shortenedCompareIgnoreAsciiCase_WithLength, "rtl_ustr");
1419 } // namespace rtl_ustr
1421 // -----------------------------------------------------------------------------
1423 // this macro creates an empty function, which will called by the RegisterAllFunctions()
1424 // to let the user the possibility to also register some functions by hand.
1425 NOADDITIONAL;