1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 29 // MARKER(update_precomp.py): autogen include statement, do not remove 30 #include "precompiled_sal.hxx" 31 #include <testshl/simpleheader.hxx> 32 33 /** print a UNI_CODE file name. 34 */ 35 inline void printOUString( ::rtl::OUString const & _suStr ) 36 { 37 rtl::OString aString; 38 39 t_print( "OUString: " ); 40 aString = ::rtl::OUStringToOString( _suStr, RTL_TEXTENCODING_ASCII_US ); 41 t_print( "%s\n", aString.getStr( ) ); 42 } 43 44 45 namespace rtl_ustr 46 { 47 48 class compare : public CppUnit::TestFixture 49 { 50 public: 51 52 53 void compare_000() 54 { 55 rtl_ustr_compare( NULL, NULL); 56 // should not GPF 57 } 58 59 void compare_000_1() 60 { 61 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal."); 62 rtl_ustr_compare( aStr1.getStr(), NULL); 63 // should not GPF 64 } 65 void compare_001() 66 { 67 rtl::OUString aStr1; 68 rtl::OUString aStr2; 69 70 sal_Int32 nValue = rtl_ustr_compare( aStr1.getStr(), aStr2.getStr()); 71 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0); 72 } 73 74 void compare_002() 75 { 76 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal."); 77 rtl::OUString aStr2 = rtl::OUString::createFromAscii("Line must be equal."); 78 79 sal_Int32 nValue = rtl_ustr_compare( aStr1.getStr(), aStr2.getStr()); 80 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0); 81 } 82 83 void compare_003() 84 { 85 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must differ."); 86 rtl::OUString aStr2 = rtl::OUString::createFromAscii("Line foo bar, ok, differ."); 87 88 sal_Int32 nValue = rtl_ustr_compare( aStr1.getStr(), aStr2.getStr()); 89 CPPUNIT_ASSERT_MESSAGE("compare failed, strings differ.", nValue != 0); 90 } 91 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. 95 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 104 105 106 class compareIgnoreAsciiCase : public CppUnit::TestFixture 107 { 108 public: 109 110 void compare_000() 111 { 112 rtl_ustr_compareIgnoreAsciiCase( NULL, NULL); 113 } 114 115 void compare_000_1() 116 { 117 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal."); 118 rtl_ustr_compareIgnoreAsciiCase( aStr1.getStr(), NULL); 119 } 120 void compare_001() 121 { 122 rtl::OUString aStr1; 123 rtl::OUString aStr2; 124 125 sal_Int32 nValue = rtl_ustr_compareIgnoreAsciiCase( aStr1.getStr(), aStr2.getStr()); 126 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0); 127 } 128 129 void compare_002() 130 { 131 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal."); 132 rtl::OUString aStr2 = rtl::OUString::createFromAscii("Line must be equal."); 133 134 sal_Int32 nValue = rtl_ustr_compareIgnoreAsciiCase( aStr1.getStr(), aStr2.getStr()); 135 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0); 136 } 137 138 void compare_002_1() 139 { 140 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal."); 141 rtl::OUString aStr2 = rtl::OUString::createFromAscii("LINE MUST BE EQUAL."); 142 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); 145 } 146 147 void compare_003() 148 { 149 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must differ."); 150 rtl::OUString aStr2 = rtl::OUString::createFromAscii("Line foo bar, ok, differ."); 151 152 sal_Int32 nValue = rtl_ustr_compareIgnoreAsciiCase( aStr1.getStr(), aStr2.getStr()); 153 CPPUNIT_ASSERT_MESSAGE("compare failed, strings differ.", nValue != 0); 154 } 155 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. 159 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 169 170 // ----------------------------------------------------------------------------- 171 172 class shortenedCompareIgnoreAsciiCase_WithLength : public CppUnit::TestFixture 173 { 174 public: 175 176 void compare_000() 177 { 178 rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( NULL, 0, NULL, 0, 0); 179 } 180 181 void compare_000_1() 182 { 183 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal."); 184 rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(), NULL, 0, 1); 185 } 186 void compare_001() 187 { 188 rtl::OUString aStr1; 189 rtl::OUString aStr2; 190 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); 193 } 194 195 void compare_002() 196 { 197 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal."); 198 rtl::OUString aStr2 = rtl::OUString::createFromAscii("Line must be equal."); 199 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); 204 } 205 206 void compare_002_1() 207 { 208 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal."); 209 rtl::OUString aStr2 = rtl::OUString::createFromAscii("LINE MUST BE EQUAL."); 210 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); 215 } 216 217 void compare_003() 218 { 219 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must differ."); 220 rtl::OUString aStr2 = rtl::OUString::createFromAscii("Line foo bar, ok, differ."); 221 222 sal_Int32 nValue = rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( aStr1.getStr(), aStr1.getLength(), 223 aStr2.getStr(), aStr2.getLength(), 224 5); 225 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal first 5 characters.", nValue == 0); 226 } 227 228 void compare_004() 229 { 230 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must differ."); 231 rtl::OUString aStr2 = rtl::OUString::createFromAscii("Line foo bar, ok, differ."); 232 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); 237 } 238 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. 242 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 253 254 255 // // ----------------------------------------------------------------------------- 256 // 257 // class hashCode : public CppUnit::TestFixture 258 // { 259 // public: 260 // 261 // void hashCode_000() 262 // { 263 // sal_Int32 nHashCode = rtl_ustr_hashCode( NULL ); 264 // volatile int dummy = 0; 265 // } 266 // 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 // } 274 // 275 // void hashCode_002() 276 // { 277 // rtl::OString aStr1 = "Line for a hashCode."; 278 // sal_Int32 nHashCode1 = rtl_ustr_hashCode( aStr1.getStr() ); 279 // 280 // rtl::OString aStr2 = "Line for a hashCode."; 281 // sal_Int32 nHashCode2 = rtl_ustr_hashCode( aStr2.getStr() ); 282 // 283 // CPPUNIT_ASSERT_MESSAGE("hashcodes must be equal.", nHashCode1 == nHashCode2 ); 284 // } 285 // 286 // void hashCode_003() 287 // { 288 // rtl::OString aStr1 = "Line for a hashCode."; 289 // sal_Int32 nHashCode1 = rtl_ustr_hashCode( aStr1.getStr() ); 290 // 291 // rtl::OString aStr2 = "Line for an other hashcode."; 292 // sal_Int32 nHashCode2 = rtl_ustr_hashCode( aStr2.getStr() ); 293 // 294 // CPPUNIT_ASSERT_MESSAGE("hashcodes must differ.", nHashCode1 != nHashCode2 ); 295 // } 296 // 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. 300 // 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 308 // 309 // 310 // // ----------------------------------------------------------------------------- 311 // 312 class indexOfChar : public CppUnit::TestFixture 313 { 314 public: 315 316 void indexOfChar_000() 317 { 318 rtl_ustr_indexOfChar( NULL, 0 ); 319 } 320 321 void indexOfChar_001() 322 { 323 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a indexOfChar."); 324 325 sal_Int32 nIndex = rtl_ustr_indexOfChar( aStr1.getStr(), 'L' ); 326 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 0); 327 328 /* sal_Int32 */ nIndex = rtl_ustr_indexOfChar( aStr1.getStr(), 'i' ); 329 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 1); 330 331 /* sal_Int32 */ nIndex = rtl_ustr_indexOfChar( aStr1.getStr(), 'n' ); 332 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 2); 333 334 /* sal_Int32 */ nIndex = rtl_ustr_indexOfChar( aStr1.getStr(), 'e' ); 335 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 3); 336 } 337 338 void indexOfChar_002() 339 { 340 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a indexOfChar."); 341 sal_Int32 nIndex = rtl_ustr_indexOfChar( aStr1.getStr(), 'y' ); 342 343 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == -1 ); 344 } 345 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. 349 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 356 357 // // ----------------------------------------------------------------------------- 358 class lastIndexOfChar : public CppUnit::TestFixture 359 { 360 public: 361 362 void lastIndexOfChar_000() 363 { 364 rtl_ustr_lastIndexOfChar( NULL, 0 ); 365 } 366 367 void lastIndexOfChar_001() 368 { 369 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a lastIndexOfChar."); 370 371 sal_Int32 nIndex = rtl_ustr_lastIndexOfChar( aStr1.getStr(), 'C' ); 372 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 22); 373 374 /* sal_Int32 */ nIndex = rtl_ustr_lastIndexOfChar( aStr1.getStr(), 'h' ); 375 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 23); 376 377 /* sal_Int32 */ nIndex = rtl_ustr_lastIndexOfChar( aStr1.getStr(), 'a' ); 378 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 24); 379 380 /* sal_Int32 */ nIndex = rtl_ustr_lastIndexOfChar( aStr1.getStr(), 'r' ); 381 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 25); 382 } 383 384 void lastIndexOfChar_002() 385 { 386 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a lastIndexOfChar."); 387 sal_Int32 nIndex = rtl_ustr_lastIndexOfChar( aStr1.getStr(), 'y' ); 388 389 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == -1 ); 390 } 391 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. 395 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 402 403 404 // ----------------------------------------------------------------------------- 405 406 class indexOfStr : public CppUnit::TestFixture 407 { 408 public: 409 410 void indexOfStr_000() 411 { 412 rtl_ustr_indexOfStr( NULL, 0 ); 413 } 414 415 void indexOfStr_000_1() 416 { 417 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a indexOfStr."); 418 rtl_ustr_indexOfStr( aStr1.getStr(), 0 ); 419 } 420 421 void indexOfStr_001() 422 { 423 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a indexOfStr."); 424 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); 428 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); 432 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); 436 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); 440 } 441 442 void indexOfStr_002() 443 { 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 ); 447 448 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == -1 ); 449 } 450 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. 454 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 // ----------------------------------------------------------------------------- 462 463 464 class lastIndexOfStr : public CppUnit::TestFixture 465 { 466 public: 467 468 void lastIndexOfStr_000() 469 { 470 rtl_ustr_lastIndexOfStr( NULL, NULL ); 471 } 472 473 void lastIndexOfStr_000_1() 474 { 475 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a lastIndexOfStr."); 476 rtl_ustr_lastIndexOfStr( aStr1.getStr(), NULL ); 477 } 478 479 void lastIndexOfStr_001() 480 { 481 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line for a lastIndexOfStr."); 482 rtl::OUString aSearchStr = rtl::OUString::createFromAscii("Index"); 483 484 sal_Int32 nIndex = rtl_ustr_lastIndexOfStr( aStr1.getStr(), aSearchStr.getStr() ); 485 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 15); 486 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); 490 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); 494 } 495 496 void lastIndexOfStr_002() 497 { 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() ); 501 502 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == -1 ); 503 } 504 505 void lastIndexOfStr_003() 506 { 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() ); 510 511 CPPUNIT_ASSERT_MESSAGE("index is wrong.", nIndex == 20 ); 512 } 513 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. 517 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 525 526 // ----------------------------------------------------------------------------- 527 528 class replaceChar : public CppUnit::TestFixture 529 { 530 public: 531 532 void replaceChar_000() 533 { 534 rtl_ustr_replaceChar( NULL, 0, 0 ); 535 } 536 537 void replaceChar_001() 538 { 539 rtl::OUString aStr1 = rtl::OUString::createFromAscii("replace char."); 540 rtl::OUString aShouldStr1 = rtl::OUString::createFromAscii("ruplacu char."); 541 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); 547 548 rtl_ustr_replaceChar( pStr, 'e', 'u' ); 549 rtl::OUString suStr(pStr, aStr1.getLength()); 550 551 CPPUNIT_ASSERT_MESSAGE("replace failed", aShouldStr1.equals(suStr) == sal_True); 552 free(pStr); 553 } 554 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. 558 559 CPPUNIT_TEST_SUITE(replaceChar); 560 CPPUNIT_TEST(replaceChar_000); 561 CPPUNIT_TEST(replaceChar_001); 562 CPPUNIT_TEST_SUITE_END(); 563 }; // class replaceChar 564 565 // ----------------------------------------------------------------------------- 566 567 class replaceChar_WithLength : public CppUnit::TestFixture 568 { 569 public: 570 571 void replaceChar_WithLength_000() 572 { 573 rtl_ustr_replaceChar_WithLength( NULL, 0, 0, 0 ); 574 } 575 576 void replaceChar_WithLength_000_1() 577 { 578 rtl_ustr_replaceChar_WithLength( NULL, 1, 0, 0 ); 579 } 580 void replaceChar_WithLength_001() 581 { 582 rtl::OUString aStr1 = rtl::OUString::createFromAscii("replace char."); 583 rtl::OUString aShouldStr1 = rtl::OUString::createFromAscii("ruplace char."); 584 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); 589 590 rtl_ustr_replaceChar_WithLength( pStr, 6, 'e', 'u' ); 591 rtl::OUString suStr(pStr, aStr1.getLength()); 592 593 CPPUNIT_ASSERT_MESSAGE("replace failed", aShouldStr1.equals(suStr) == sal_True); 594 free(pStr); 595 } 596 597 void replaceChar_WithLength_002() 598 { 599 rtl::OUString aStr1 = rtl::OUString::createFromAscii("eeeeeeeeeeeee"); 600 rtl::OUString aShouldStr1 = rtl::OUString::createFromAscii("uuuuuueeeeeee"); 601 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); 606 607 rtl_ustr_replaceChar_WithLength( pStr, 6, 'e', 'u' ); 608 rtl::OUString suStr(pStr, aStr1.getLength()); 609 610 CPPUNIT_ASSERT_MESSAGE("replace failed", aShouldStr1.equals(suStr) == sal_True); 611 free(pStr); 612 } 613 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. 617 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 625 626 627 // ----------------------------------------------------------------------------- 628 629 class toAsciiLowerCase : public CppUnit::TestFixture 630 { 631 public: 632 633 void toAsciiLowerCase_000() 634 { 635 rtl_ustr_toAsciiLowerCase( NULL ); 636 } 637 638 void toAsciiLowerCase_001() 639 { 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."); 642 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); 648 649 rtl_ustr_toAsciiLowerCase( pStr ); 650 rtl::OUString suStr(pStr, aStr1.getLength()); 651 652 CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1.equals(suStr) == sal_True); 653 free(pStr); 654 } 655 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. 659 660 CPPUNIT_TEST_SUITE(toAsciiLowerCase); 661 CPPUNIT_TEST(toAsciiLowerCase_000); 662 CPPUNIT_TEST(toAsciiLowerCase_001); 663 CPPUNIT_TEST_SUITE_END(); 664 }; // class replaceChar 665 666 667 class toAsciiLowerCase_WithLength : public CppUnit::TestFixture 668 { 669 public: 670 671 void toAsciiLowerCase_WithLength_000() 672 { 673 rtl_ustr_toAsciiLowerCase_WithLength( NULL, 0 ); 674 } 675 676 void toAsciiLowerCase_WithLength_001() 677 { 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."); 680 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); 685 686 rtl_ustr_toAsciiLowerCase_WithLength( pStr, 10 ); 687 688 rtl::OUString suStr(pStr, aStr1.getLength()); 689 sal_Bool bResult = aShouldStr1.equals(suStr); 690 691 printOUString(suStr); 692 t_print("Result length: %d\n", suStr.getLength() ); 693 t_print("Result: %d\n", bResult); 694 695 CPPUNIT_ASSERT_MESSAGE("failed", bResult == sal_True); 696 free(pStr); 697 } 698 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. 702 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 708 709 // ----------------------------------------------------------------------------- 710 711 class toAsciiUpperCase : public CppUnit::TestFixture 712 { 713 public: 714 715 void toAsciiUpperCase_000() 716 { 717 rtl_ustr_toAsciiUpperCase( NULL ); 718 } 719 720 void toAsciiUpperCase_001() 721 { 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."); 724 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); 730 731 rtl_ustr_toAsciiUpperCase( pStr ); 732 rtl::OUString suStr(pStr, aStr1.getLength()); 733 734 CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1.equals(suStr) == sal_True); 735 free(pStr); 736 } 737 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. 741 742 CPPUNIT_TEST_SUITE(toAsciiUpperCase); 743 CPPUNIT_TEST(toAsciiUpperCase_000); 744 CPPUNIT_TEST(toAsciiUpperCase_001); 745 CPPUNIT_TEST_SUITE_END(); 746 }; // class replaceChar 747 748 749 class toAsciiUpperCase_WithLength : public CppUnit::TestFixture 750 { 751 public: 752 753 void toAsciiUpperCase_WithLength_000() 754 { 755 rtl_ustr_toAsciiUpperCase_WithLength( NULL, 0 ); 756 } 757 758 void toAsciiUpperCase_WithLength_001() 759 { 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."); 762 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); 766 767 memcpy(pStr, aStr1.getStr(), nLength); 768 rtl_ustr_toAsciiUpperCase_WithLength( pStr, 10 ); 769 rtl::OUString suStr(pStr, aStr1.getLength()); 770 771 // t_print("Uppercase with length: '%s'\n", aStr1.getStr()); 772 CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1.equals(suStr) == sal_True); 773 free(pStr); 774 } 775 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. 779 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 785 786 787 // ----------------------------------------------------------------------------- 788 789 class trim_WithLength : public CppUnit::TestFixture 790 { 791 public: 792 void trim_WithLength_000() 793 { 794 rtl_ustr_trim_WithLength(NULL, 0); 795 // should not GPF 796 } 797 798 void trim_WithLength_000_1() 799 { 800 rtl::OUString suStr = rtl::OUString::createFromAscii(" trim this"); 801 802 sal_uInt32 nLength = suStr.getLength() * sizeof(sal_Unicode); 803 sal_Unicode *pStr = (sal_Unicode*)malloc(nLength); 804 memcpy(pStr, suStr.getStr(), nLength); 805 806 rtl_ustr_trim_WithLength( pStr, 0 ); 807 free(pStr); 808 } 809 810 void trim_WithLength_001() 811 { 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); 816 817 rtl_ustr_trim_WithLength( pStr, 2 ); 818 819 CPPUNIT_ASSERT_MESSAGE("string should be empty", rtl::OUString(pStr).getLength() == 0); 820 free(pStr); 821 } 822 823 824 void trim_WithLength_002() 825 { 826 rtl::OUString suStr = rtl::OUString::createFromAscii("trim this"); 827 828 sal_uInt32 nLength = suStr.getLength() * sizeof(sal_Unicode); 829 sal_Unicode *pStr = (sal_Unicode*)malloc(nLength); 830 memcpy(pStr, suStr.getStr(), nLength); 831 832 rtl_ustr_trim_WithLength( pStr, 5 ); 833 834 CPPUNIT_ASSERT_MESSAGE("string should contain 'trim'", rtl::OUString(pStr).getLength() == 4); 835 free(pStr); 836 } 837 838 839 void trim_WithLength_003() 840 { 841 rtl::OUString suStr = rtl::OUString::createFromAscii(" trim this"); 842 843 sal_uInt32 nLength = suStr.getLength() * sizeof(sal_Unicode); 844 sal_Unicode *pStr = (sal_Unicode*)malloc(nLength); 845 memcpy(pStr, suStr.getStr(), nLength); 846 847 rtl_ustr_trim_WithLength( pStr, 11 ); 848 849 CPPUNIT_ASSERT_MESSAGE("string should contain 'trim'", rtl::OUString(pStr).getLength() == 4); 850 free(pStr); 851 } 852 853 void trim_WithLength_004() 854 { 855 rtl::OUString suStr = rtl::OUString::createFromAscii("\r\n\t \n\r trim \n this"); 856 857 sal_uInt32 nLength = suStr.getLength() * sizeof(sal_Unicode); 858 sal_Unicode *pStr = (sal_Unicode*)malloc(nLength); 859 memcpy(pStr, suStr.getStr(), nLength); 860 861 rtl_ustr_trim_WithLength( pStr, 17 ); 862 863 CPPUNIT_ASSERT_MESSAGE("string should contain 'trim'", rtl::OUString(pStr).getLength() == 4); 864 free(pStr); 865 } 866 867 void trim_WithLength_005() 868 { 869 rtl::OUString suStr = rtl::OUString::createFromAscii("\r\n\t \n\r trim \t this \n\r\t\t "); 870 871 sal_uInt32 nLength = suStr.getLength() * sizeof(sal_Unicode); 872 sal_Unicode *pStr = (sal_Unicode*)malloc(nLength); 873 memcpy(pStr, suStr.getStr(), nLength); 874 875 rtl_ustr_trim_WithLength( pStr, suStr.getLength() ); 876 877 CPPUNIT_ASSERT_MESSAGE("string should contain 'trim \\t this'", rtl::OUString(pStr).getLength() == 11); 878 free(pStr); 879 } 880 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. 884 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(); 894 }; 895 896 // ----------------------------------------------------------------------------- 897 898 class valueOfChar : public CppUnit::TestFixture 899 { 900 public: 901 void valueOfChar_000() 902 { 903 rtl_ustr_valueOfChar(NULL, 0); 904 // should not GPF 905 } 906 void valueOfChar_001() 907 { 908 sal_Unicode *pStr = (sal_Unicode*)malloc(RTL_USTR_MAX_VALUEOFCHAR); 909 if (pStr) 910 { 911 rtl_ustr_valueOfChar(pStr, 'A'); 912 913 CPPUNIT_ASSERT_MESSAGE("string should contain 'A'", pStr[0] == L'A'); 914 free(pStr); 915 } 916 } 917 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. 921 922 CPPUNIT_TEST_SUITE(valueOfChar); 923 CPPUNIT_TEST(valueOfChar_000); 924 CPPUNIT_TEST(valueOfChar_001); 925 CPPUNIT_TEST_SUITE_END(); 926 }; 927 928 929 930 931 class ascii_compare_WithLength : public CppUnit::TestFixture 932 { 933 public: 934 void zero_length() 935 { 936 sal_Unicode pUnicode[] = {0xffff, 0xffff}; 937 char const * pAscii = "reference"; 938 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); 941 } 942 943 void equal_ascii_shorter() 944 { 945 rtl::OUString refStr(RTL_CONSTASCII_USTRINGPARAM("referenceString")); 946 char const * pAscii = "reference"; 947 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); 950 } 951 952 void equal_ascii_shorter_asciiLength() 953 { 954 rtl::OUString refStr(RTL_CONSTASCII_USTRINGPARAM("referenceString")); 955 char const * pAscii = "reference"; 956 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); 959 } 960 961 void equal_ref_shorter() 962 { 963 rtl::OUString refStr(RTL_CONSTASCII_USTRINGPARAM("reference")); 964 char const * pAscii = "referenceString"; 965 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); 968 } 969 970 void equal() 971 { 972 rtl::OUString refStr(RTL_CONSTASCII_USTRINGPARAM("reference")); 973 char const * pAscii = "reference"; 974 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); 977 } 978 979 void unequal_reference_bigger() 980 { 981 rtl::OUString refStr(RTL_CONSTASCII_USTRINGPARAM("defghi")); 982 char const * pAscii = "abc"; 983 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); 986 } 987 988 void unequal_ascii_bigger() 989 { 990 rtl::OUString refStr(RTL_CONSTASCII_USTRINGPARAM("abc")); 991 char const * pAscii = "defghi"; 992 993 sal_Int32 value = rtl_ustr_ascii_compare_WithLength(refStr.pData->buffer, refStr.pData->length, pAscii); 994 995 CPPUNIT_ASSERT_MESSAGE("strings are unequal and ascii is bigger, needs to be <0.", value < 0); 996 } 997 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(); 1007 }; 1008 1009 1010 1011 1012 class ascii_shortenedCompareIgnoreAsciiCase_WithLength : public CppUnit::TestFixture 1013 { 1014 public: 1015 1016 void ascii_shortenedCompareIgnoreAsciiCase_WithLength_000() 1017 { 1018 rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( NULL, 0, NULL, 0); 1019 // should not GPF 1020 } 1021 1022 void ascii_shortenedCompareIgnoreAsciiCase_WithLength_000_1() 1023 { 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 1027 } 1028 void ascii_shortenedCompareIgnoreAsciiCase_WithLength_000_2() 1029 { 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 1034 } 1035 void ascii_shortenedCompareIgnoreAsciiCase_WithLength_001() 1036 { 1037 rtl::OUString suStr1; 1038 rtl::OString sStr2; 1039 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); 1042 } 1043 1044 void ascii_shortenedCompareIgnoreAsciiCase_WithLength_002() 1045 { 1046 rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must be equal."); 1047 rtl::OString sStr2 = "Line must be equal."; 1048 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); 1051 } 1052 1053 void ascii_shortenedCompareIgnoreAsciiCase_WithLength_003() 1054 { 1055 rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must differ."); 1056 rtl::OString sStr2 = "Line must be differ and longer."; 1057 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); 1060 } 1061 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. 1065 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 1075 1076 // ----------------------------------------------------------------------------- 1077 1078 class ascii_compareIgnoreAsciiCase_WithLength : public CppUnit::TestFixture 1079 { 1080 public: 1081 1082 void ascii_compareIgnoreAsciiCase_WithLength_000() 1083 { 1084 rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( NULL, 0, NULL); 1085 // should not GPF 1086 } 1087 1088 void ascii_compareIgnoreAsciiCase_WithLength_000_1() 1089 { 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 1093 } 1094 void ascii_compareIgnoreAsciiCase_WithLength_000_2() 1095 { 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 1100 } 1101 void ascii_compareIgnoreAsciiCase_WithLength_001() 1102 { 1103 rtl::OUString suStr1; 1104 rtl::OString sStr2; 1105 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); 1108 } 1109 1110 void ascii_compareIgnoreAsciiCase_WithLength_002() 1111 { 1112 rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must be equal."); 1113 rtl::OString sStr2 = "Line must be equal."; 1114 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); 1117 } 1118 1119 void ascii_compareIgnoreAsciiCase_WithLength_003() 1120 { 1121 rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must differ."); 1122 rtl::OString sStr2 = "Line must be differ and longer."; 1123 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); 1126 } 1127 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. 1131 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 1141 1142 // ----------------------------------------------------------------------------- 1143 1144 class ascii_compare : public CppUnit::TestFixture 1145 { 1146 public: 1147 1148 void ascii_compare_000() 1149 { 1150 rtl_ustr_ascii_compare( NULL, NULL); 1151 // should not GPF 1152 } 1153 1154 void ascii_compare_000_1() 1155 { 1156 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal."); 1157 rtl_ustr_ascii_compare( aStr1.getStr(), NULL); 1158 // should not GPF 1159 } 1160 void ascii_compare_001() 1161 { 1162 rtl::OUString suStr1; 1163 rtl::OString sStr2; 1164 1165 sal_Int32 nValue = rtl_ustr_ascii_compare( suStr1, sStr2.getStr()); 1166 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0); 1167 } 1168 1169 void ascii_compare_002() 1170 { 1171 rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must be equal."); 1172 rtl::OString sStr2 = "Line must be equal."; 1173 1174 sal_Int32 nValue = rtl_ustr_ascii_compare( suStr1.getStr(), sStr2.getStr()); 1175 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0); 1176 } 1177 1178 void ascii_compare_003() 1179 { 1180 rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must differ."); 1181 rtl::OString sStr2 = "Line foo bar, ok, differ."; 1182 1183 sal_Int32 nValue = rtl_ustr_ascii_compare( suStr1.getStr(), sStr2.getStr()); 1184 CPPUNIT_ASSERT_MESSAGE("compare failed, strings differ.", nValue != 0); 1185 } 1186 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. 1190 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 1199 1200 // ----------------------------------------------------------------------------- 1201 1202 class ascii_compareIgnoreAsciiCase : public CppUnit::TestFixture 1203 { 1204 public: 1205 1206 void ascii_compareIgnoreAsciiCase_000() 1207 { 1208 rtl_ustr_ascii_compareIgnoreAsciiCase( NULL, NULL); 1209 // should not GPF 1210 } 1211 1212 void ascii_compareIgnoreAsciiCase_000_1() 1213 { 1214 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal."); 1215 rtl_ustr_ascii_compareIgnoreAsciiCase( aStr1.getStr(), NULL); 1216 // should not GPF 1217 } 1218 void ascii_compareIgnoreAsciiCase_001() 1219 { 1220 rtl::OUString suStr1; 1221 rtl::OString sStr2; 1222 1223 sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase( suStr1, sStr2.getStr()); 1224 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0); 1225 } 1226 1227 void ascii_compareIgnoreAsciiCase_002() 1228 { 1229 rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must be equal."); 1230 rtl::OString sStr2 = "Line must be equal."; 1231 1232 sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase( suStr1.getStr(), sStr2.getStr()); 1233 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0); 1234 } 1235 1236 void ascii_compareIgnoreAsciiCase_002_1() 1237 { 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."; 1240 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); 1243 } 1244 1245 void ascii_compareIgnoreAsciiCase_003() 1246 { 1247 rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must differ."); 1248 rtl::OString sStr2 = "Line foo bar, ok, differ."; 1249 1250 sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase( suStr1.getStr(), sStr2.getStr()); 1251 CPPUNIT_ASSERT_MESSAGE("compare failed, strings differ.", nValue != 0); 1252 } 1253 1254 //! LLA: some more tests with some high level strings 1255 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."); 1260 // 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); 1266 // 1267 // rtl_ustr_ascii_compareIgnoreAsciiCase( pStr ); 1268 // rtl::OUString suStr(pStr, suStr1.getLength()); 1269 // 1270 // CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1.equals(suStr) == sal_True); 1271 // free(pStr); 1272 // } 1273 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. 1277 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 1287 1288 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); 1299 1300 class getToken : public CppUnit::TestFixture 1301 { 1302 public: 1303 1304 void getToken_000() 1305 { 1306 rtl_ustr_ascii_compareIgnoreAsciiCase( NULL, NULL); 1307 // should not GPF 1308 } 1309 1310 void ascii_compareIgnoreAsciiCase_000_1() 1311 { 1312 rtl::OUString aStr1 = rtl::OUString::createFromAscii("Line must be equal."); 1313 rtl_ustr_ascii_compareIgnoreAsciiCase( aStr1.getStr(), NULL); 1314 // should not GPF 1315 } 1316 void ascii_compareIgnoreAsciiCase_001() 1317 { 1318 rtl::OUString suStr1; 1319 rtl::OString sStr2; 1320 1321 sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase( suStr1, sStr2.getStr()); 1322 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0); 1323 } 1324 1325 void ascii_compareIgnoreAsciiCase_002() 1326 { 1327 rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must be equal."); 1328 rtl::OString sStr2 = "Line must be equal."; 1329 1330 sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase( suStr1.getStr(), sStr2.getStr()); 1331 CPPUNIT_ASSERT_MESSAGE("compare failed, strings are equal.", nValue == 0); 1332 } 1333 1334 void ascii_compareIgnoreAsciiCase_002_1() 1335 { 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."; 1338 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); 1341 } 1342 1343 void ascii_compareIgnoreAsciiCase_003() 1344 { 1345 rtl::OUString suStr1 = rtl::OUString::createFromAscii("Line must differ."); 1346 rtl::OString sStr2 = "Line foo bar, ok, differ."; 1347 1348 sal_Int32 nValue = rtl_ustr_ascii_compareIgnoreAsciiCase( suStr1.getStr(), sStr2.getStr()); 1349 CPPUNIT_ASSERT_MESSAGE("compare failed, strings differ.", nValue != 0); 1350 } 1351 1352 //! LLA: some more tests with some high level strings 1353 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."); 1358 // 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); 1364 // 1365 // rtl_ustr_ascii_compareIgnoreAsciiCase( pStr ); 1366 // rtl::OUString suStr(pStr, suStr1.getLength()); 1367 // 1368 // CPPUNIT_ASSERT_MESSAGE("failed", aShouldStr1.equals(suStr) == sal_True); 1369 // free(pStr); 1370 // } 1371 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. 1375 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 1385 1386 // ----------------------------------------------------------------------------- 1387 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::compare, "rtl_ustr"); 1388 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::compareIgnoreAsciiCase, "rtl_ustr"); 1389 1390 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::ascii_compare_WithLength, "rtl_ustr"); 1391 1392 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::shortenedCompareIgnoreAsciiCase_WithLength, "rtl_ustr"); 1393 // CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::hashCode, "rtl_ustr"); 1394 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"); 1399 1400 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::replaceChar, "rtl_ustr"); 1401 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::replaceChar_WithLength, "rtl_ustr"); 1402 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"); 1407 1408 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::trim_WithLength, "rtl_ustr"); 1409 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_ustr::valueOfChar, "rtl_ustr"); 1410 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"); 1415 1416 } // namespace rtl_ustr 1417 1418 // ----------------------------------------------------------------------------- 1419 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; 1423 1424 1425