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 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_sal.hxx" 30 #include <sal/types.h> 31 32 //# #ifndef _RTL_TRES_H_ 33 //# #include <rtl/tres.h> 34 //# #endif 35 #include <testshl/tresstatewrapper.hxx> 36 #include "stringhelper.hxx" 37 #include <rtl/string.hxx> 38 #include <rtl/ustring.h> 39 #include <rtl/ustring.hxx> 40 41 //------------------------------------------------------------------------ 42 //------------------------------------------------------------------------ 43 #include <osl/thread.h> 44 #include <rtl_String_Const.h> 45 #include <rtl_String_Utils.hxx> 46 47 48 49 using namespace rtl; 50 51 //------------------------------------------------------------------------ 52 // test classes 53 //------------------------------------------------------------------------ 54 const int MAXBUFLENGTH = 255; 55 //------------------------------------------------------------------------ 56 // helper functions 57 //------------------------------------------------------------------------ 58 static void unused() 59 { 60 // NEVER CALL SUCH FUNCTION!!! 61 (void)input1StrLastDefault; 62 (void)input1StrLastNormal; 63 unused(); 64 } 65 66 //------------------------------------------------------------------------ 67 // testing constructors 68 //------------------------------------------------------------------------ 69 static sal_Bool test_rtl_OUString_ctor_001( hTestResult hRtlTestResult ) 70 { 71 72 ::rtl::OUString aUStr; 73 rtl_uString * pData = aUStr.pData; 74 75 return 76 ( 77 c_rtl_tres_state 78 ( 79 hRtlTestResult, 80 pData->length == 0 && 81 ! *pData->buffer, 82 "New OUString containing no characters", 83 "ctor_001" 84 ) 85 ); 86 } 87 88 //------------------------------------------------------------------------ 89 90 static sal_Bool SAL_CALL test_rtl_OUString_ctor_002( 91 hTestResult hRtlTestResult ) 92 { 93 ::rtl::OUString aUStr( kTestStr1, 94 kTestStr1Len, 95 kEncodingRTLTextUSASCII, 96 kConvertFlagsOStringToOUString 97 ); 98 99 return 100 ( 101 c_rtl_tres_state 102 ( 103 hRtlTestResult, 104 aUStr == aUStr1, 105 "OUString from an ascii string", 106 "ctor_002" 107 ) 108 ); 109 } 110 //------------------------------------------------------------------------ 111 112 static sal_Bool SAL_CALL test_rtl_OUString_ctor_003( 113 hTestResult hRtlTestResult ) 114 { 115 rtl_uString *rtlUStr =NULL ; 116 rtl_uString_newFromAscii( &rtlUStr, kTestStr1 ); 117 ::rtl::OUString aUStr( rtlUStr ); 118 119 return 120 ( 121 c_rtl_tres_state 122 ( 123 hRtlTestResult, 124 aUStr == aUStr1, 125 "New OUString from a rtl_uString", 126 "ctor_003" 127 ) 128 ); 129 } 130 131 //------------------------------------------------------------------------ 132 133 static sal_Bool SAL_CALL test_rtl_OUString_ctor_004( 134 hTestResult hRtlTestResult) 135 { 136 ::rtl::OUString aUStr( aUStr1 ); 137 138 return 139 ( 140 c_rtl_tres_state 141 ( 142 hRtlTestResult, 143 aUStr == aUStr1, 144 "New OUString from unicode string", 145 "ctor_004" 146 ) 147 ); 148 } 149 //------------------------------------------------------------------------ 150 151 static sal_Bool test_rtl_OUString_ctor_005( hTestResult hRtlTestResult ) 152 { 153 ::rtl::OUString aUStr( aUStr2, kTestStr1Len ); 154 155 return 156 ( 157 c_rtl_tres_state 158 ( 159 hRtlTestResult, 160 aUStr == aUStr1, 161 "New OUString from the first n characters of unicode string", 162 "ctor_004" 163 ) 164 ); 165 166 } 167 168 169 //------------------------------------------------------------------------ 170 171 static sal_Bool test_rtl_OUString_ctor_006( hTestResult hRtlTestResult ) 172 { 173 ::rtl::OUString aUStrtmp( aUStr1 ); 174 ::rtl::OUString aUStr( aUStrtmp ); 175 176 return 177 ( 178 c_rtl_tres_state 179 ( 180 hRtlTestResult, 181 aUStr==aUStrtmp, 182 "New OUString from another OUString", 183 "ctor_006" 184 ) 185 ); 186 } 187 188 extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_ctors( 189 hTestResult hRtlTestResult ) 190 { 191 c_rtl_tres_state_start( hRtlTestResult, "ctors"); 192 sal_Bool DCState = test_ini_uString(); 193 (void)DCState; 194 sal_Bool bTSState = test_rtl_OUString_ctor_001( hRtlTestResult ); 195 bTSState &= test_rtl_OUString_ctor_002( hRtlTestResult); 196 bTSState &= test_rtl_OUString_ctor_003( hRtlTestResult); 197 bTSState &= test_rtl_OUString_ctor_004( hRtlTestResult); 198 bTSState &= test_rtl_OUString_ctor_005( hRtlTestResult); 199 bTSState &= test_rtl_OUString_ctor_006( hRtlTestResult); 200 c_rtl_tres_state_end( hRtlTestResult, "ctors"); 201 // return( bTSState ); 202 } 203 204 205 206 //------------------------------------------------------------------------ 207 // testing the method getLength 208 //------------------------------------------------------------------------ 209 210 extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_getLength( 211 hTestResult hRtlTestResult) 212 { 213 c_rtl_tres_state_start( hRtlTestResult, "getLength"); 214 sal_Char methName[MAXBUFLENGTH]; 215 sal_Char* pMeth = methName; 216 217 typedef struct TestCase 218 { 219 sal_Char* comments; 220 sal_Int32 expVal; 221 OUString* input; 222 ~TestCase() { delete input;} 223 } TestCase; 224 225 TestCase arrTestCase[]={ 226 227 {"length of ascii string", kTestStr1Len, 228 new OUString( kTestStr1, 229 kTestStr1Len, 230 kEncodingRTLTextUSASCII, 231 kConvertFlagsOStringToOUString)}, 232 {"length of ascci string of size 1", 1, 233 new OUString( "1", 234 1, 235 kEncodingRTLTextUSASCII, 236 kConvertFlagsOStringToOUString)}, 237 {"length of empty string (default constructor)", 0, new OUString()}, 238 {"length of empty string (empty ascii string arg)",0, 239 new OUString( "", 240 0, 241 kEncodingRTLTextUSASCII, 242 kConvertFlagsOStringToOUString)}, 243 {"length of empty string (string arg = '\\0')", 0, 244 new OUString( "\0", 245 0, 246 kEncodingRTLTextUSASCII, 247 kConvertFlagsOStringToOUString)} 248 }; 249 250 251 sal_Bool res = sal_True; 252 sal_uInt32 i; 253 254 for (i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) 255 { 256 sal_Int32 length = arrTestCase[i].input->getLength(); 257 sal_Bool lastRes = (length == arrTestCase[i].expVal); 258 c_rtl_tres_state 259 ( 260 hRtlTestResult, 261 lastRes, 262 arrTestCase[i].comments, 263 createName( pMeth, "getLength", i ) 264 265 ); 266 res &= lastRes; 267 } 268 c_rtl_tres_state_end( hRtlTestResult, "getLength"); 269 // return ( res ); 270 } 271 272 //------------------------------------------------------------------------ 273 // testing the method equals( const OString & aStr ) 274 //------------------------------------------------------------------------ 275 extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_equals( 276 hTestResult hRtlTestResult ) 277 { 278 c_rtl_tres_state_start( hRtlTestResult, "equals"); 279 sal_Char methName[MAXBUFLENGTH]; 280 sal_Char* pMeth = methName; 281 282 typedef struct TestCase 283 { 284 sal_Char* comments; 285 sal_Bool expVal; 286 OUString* input1; 287 OUString* input2; 288 ~TestCase() { delete input1;delete input2;} 289 } TestCase; 290 291 TestCase arrTestCase[]={ 292 293 {"same size", sal_True, new OUString(aUStr1), new OUString(aUStr1)}, 294 {"different size", sal_False, new OUString(aUStr1), 295 new OUString(aUStr2) 296 }, 297 {"same size, no case match", sal_False, new OUString(aUStr1), 298 new OUString(aUStr3) 299 }, 300 {"two empty strings(def. constructor)", sal_True, new OUString(), 301 new OUString() 302 }, 303 {"empty(def.constructor) and non empty", sal_False, new OUString(), 304 new OUString(aUStr2) 305 }, 306 {"non empty and empty(def. constructor)", sal_False, 307 new OUString(aUStr1), 308 new OUString() 309 }, 310 {"two empty strings(string arg = '\\0')", sal_True, 311 new OUString( "", 312 0, 313 kEncodingRTLTextUSASCII, 314 kConvertFlagsOStringToOUString), 315 new OUString( "", 316 0, 317 kEncodingRTLTextUSASCII, 318 kConvertFlagsOStringToOUString) 319 }, 320 {"empty(string arg = '\\0') and non empty", sal_False, 321 new OUString( "", 322 0, 323 kEncodingRTLTextUSASCII, 324 kConvertFlagsOStringToOUString), 325 new OUString(aUStr2) 326 }, 327 {"non empty and empty(string arg = '\\0')", sal_False, 328 new OUString(aUStr1), 329 new OUString( "", 330 0, 331 kEncodingRTLTextUSASCII, 332 kConvertFlagsOStringToOUString) 333 } 334 }; 335 336 sal_Bool res = sal_True; 337 sal_uInt32 i; 338 339 for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) 340 { 341 sal_Bool lastRes = 342 ( arrTestCase[i].input1->equals(*(arrTestCase[i].input2)) == 343 arrTestCase[i].expVal ); 344 345 c_rtl_tres_state 346 ( 347 hRtlTestResult, 348 lastRes, 349 arrTestCase[i].comments, 350 createName( pMeth, "equals", i ) 351 ); 352 353 res &= lastRes; 354 } 355 c_rtl_tres_state_end( hRtlTestResult, "equals"); 356 // return (res); 357 } 358 359 //------------------------------------------------------------------------ 360 // testing the method equalsIgnoreAsciiCase( const OString & aStr ) 361 //------------------------------------------------------------------------ 362 363 extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_equalsIgnoreAsciiCase( 364 hTestResult hRtlTestResult ) 365 { 366 c_rtl_tres_state_start( hRtlTestResult, "equalsIgnoreAsciiCase"); 367 sal_Char methName[MAXBUFLENGTH]; 368 sal_Char* pMeth = methName; 369 370 typedef struct TestCase 371 { 372 sal_Char* comments; 373 sal_Bool expVal; 374 OUString* input1; 375 OUString* input2; 376 ~TestCase() { delete input1;delete input2;} 377 } TestCase; 378 379 TestCase arrTestCase[]={ 380 {"same strings but different cases",sal_True,new OUString(aUStr4), 381 new OUString(aUStr5) 382 }, 383 {"same strings",sal_True,new OUString(aUStr4), 384 new OUString(aUStr4)}, 385 {"with equal beginning",sal_False,new OUString(aUStr2), 386 new OUString(aUStr4) 387 }, 388 {"empty(def.constructor) and non empty",sal_False,new OUString(), 389 new OUString(aUStr5) 390 }, 391 {"non empty and empty(def.constructor)",sal_False, 392 new OUString(aUStr4), 393 new OUString() 394 }, 395 {"two empty strings(def.constructor)",sal_True,new OUString(), 396 new OUString() 397 }, 398 {"different strings with equal length",sal_False, 399 new OUString(aUStr10), 400 new OUString(aUStr11) 401 } 402 }; 403 404 sal_Bool res = sal_True; 405 sal_uInt32 i; 406 407 for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) 408 { 409 sal_Bool lastRes = 410 (arrTestCase[i].input1->equalsIgnoreAsciiCase(*arrTestCase[i].input2) == 411 arrTestCase[i].expVal); 412 413 c_rtl_tres_state 414 ( 415 hRtlTestResult, 416 lastRes, 417 arrTestCase[i].comments, 418 createName( pMeth, "equalsIgnoreAsciiCase", i ) 419 ); 420 421 res &= lastRes; 422 } 423 c_rtl_tres_state_end( hRtlTestResult, "equalsIgnoreAsciiCase"); 424 // return (res); 425 } 426 427 428 static sal_Bool SAL_CALL test_rtl_OUString_compareTo_001( 429 hTestResult hRtlTestResult ) 430 { 431 sal_Char methName[MAXBUFLENGTH]; 432 sal_Char* pMeth = methName; 433 434 typedef struct TestCase 435 { 436 sal_Char* comments; 437 sal_Int32 expVal; 438 OUString* input1; 439 OUString* input2; 440 ~TestCase() { delete input1;delete input2;} 441 } TestCase; 442 443 TestCase arrTestCase[]={ 444 445 {"simple compare, str1 to str5",-1,new OUString(aUStr1), 446 new OUString(aUStr5) 447 }, 448 {"simple compare, str2 to str5",-1,new OUString(aUStr2), 449 new OUString(aUStr5) 450 }, 451 {"simple compare, str1 to str9",-1,new OUString(aUStr1), 452 new OUString(aUStr9) 453 }, 454 {"simple compare, str1 to str2",-1,new OUString(aUStr1), 455 new OUString(aUStr2) 456 }, 457 {"simple compare, str4 to str5",-1,new OUString(aUStr4), 458 new OUString(aUStr5) 459 }, 460 {"simple compare, str1 to str3",-1,new OUString(aUStr1), 461 new OUString(aUStr3) 462 }, 463 {"simple compare, str5 to str1",+1,new OUString(aUStr5), 464 new OUString(aUStr1) 465 }, 466 {"simple compare, str2 to str1",+1,new OUString(aUStr2), 467 new OUString(aUStr1) 468 }, 469 {"simple compare, str9 to str5",+1,new OUString(aUStr9), 470 new OUString(aUStr5) 471 }, 472 {"simple compare, str5 to str4",+1,new OUString(aUStr5), 473 new OUString(aUStr4) 474 }, 475 {"simple compare, str1 to str1",0,new OUString(aUStr1), 476 new OUString(aUStr1) 477 }, 478 {"simple compare, nullString to nullString",0,new OUString(), 479 new OUString() 480 }, 481 {"simple compare, nullString to str2",-1,new OUString(), 482 new OUString(aUStr2) 483 }, 484 {"simple compare, str1 to nullString",+1,new OUString(aUStr1), 485 new OUString() 486 } 487 }; 488 489 sal_Bool res = sal_True; 490 sal_uInt32 i; 491 492 for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) 493 { 494 sal_Int32 cmpRes = arrTestCase[i].input1->compareTo 495 (*arrTestCase[i].input2); 496 cmpRes = ( cmpRes == 0 ) ? 0 : ( cmpRes > 0 ) ? +1 : -1 ; 497 sal_Bool lastRes = ( cmpRes == arrTestCase[i].expVal); 498 499 500 c_rtl_tres_state 501 ( 502 hRtlTestResult, 503 lastRes, 504 arrTestCase[i].comments, 505 createName( pMeth, "compareTo_001(const OString&)", i ) 506 ); 507 508 res &= lastRes; 509 } 510 511 return (res); 512 } 513 514 515 //------------------------------------------------------------------------ 516 // testing the method compareTo( const OString & rObj, sal_Int32 length ) 517 //------------------------------------------------------------------------ 518 static sal_Bool SAL_CALL test_rtl_OUString_compareTo_002( 519 hTestResult hRtlTestResult ) 520 { 521 sal_Char methName[MAXBUFLENGTH]; 522 sal_Char* pMeth = methName; 523 524 typedef struct TestCase 525 { 526 sal_Char* comments; 527 sal_Int32 expVal; 528 sal_Int32 maxLength; 529 OUString* input1; 530 OUString* input2; 531 ~TestCase() { delete input1;delete input2;} 532 } TestCase; 533 534 TestCase arrTestCase[] = 535 { 536 {"compare with maxlength, str1 to str9, 16",-1,16, 537 new OUString(aUStr1), new OUString(aUStr9)}, 538 {"compare with maxlength, str2 to str9, 32",-1,32, 539 new OUString(aUStr2), new OUString(aUStr9)}, 540 {"compare with maxlength, str9 to str4, 16",+1,16, 541 new OUString(aUStr9), new OUString(aUStr4)}, 542 {"compare with maxlength, str9 to str22, 32",+1,32, 543 new OUString(aUStr9), new OUString(aUStr22)}, 544 {"compare with maxlength, str9 to str5, 16",0,16, 545 new OUString(aUStr9), new OUString(aUStr5)}, 546 {"compare with maxlength, str9 to str9, 32",0,32, 547 new OUString(aUStr9), new OUString(aUStr9)}, 548 {"compare with maxlength, str1 to str2, 32",-1,32, 549 new OUString(aUStr1), new OUString(aUStr2)}, 550 {"compare with maxlength, str1 to str2, 32",-1,32, 551 new OUString(aUStr1), new OUString(aUStr2)}, 552 {"compare with maxlength, str1 to str2", 0,-1, 553 new OUString(aUStr1), new OUString(aUStr2)} 554 }; 555 556 sal_Bool res = sal_True; 557 sal_uInt32 i; 558 559 for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) 560 { 561 sal_Int32 cmpRes = arrTestCase[i].input1->compareTo 562 (*arrTestCase[i].input2, arrTestCase[i].maxLength); 563 cmpRes = (cmpRes == 0) ? 0 : (cmpRes > 0) ? +1 : -1 ; 564 sal_Bool lastRes = (cmpRes == arrTestCase[i].expVal); 565 566 c_rtl_tres_state 567 ( 568 hRtlTestResult, 569 lastRes, 570 arrTestCase[i].comments, 571 createName( pMeth, "compareTo_002(const OString&, sal_Int32)", i ) 572 ); 573 574 res &= lastRes; 575 } 576 577 return (res); 578 } 579 580 extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_compareTo( 581 hTestResult hRtlTestResult ) 582 { 583 c_rtl_tres_state_start( hRtlTestResult, "compareTo"); 584 sal_Bool res = test_rtl_OUString_compareTo_001(hRtlTestResult); 585 res &= test_rtl_OUString_compareTo_002(hRtlTestResult); 586 c_rtl_tres_state_end( hRtlTestResult, "compareTo"); 587 // return (res); 588 } 589 590 //------------------------------------------------------------------------ 591 // testing the method match( const OUString & str, sal_Int32 fromIndex = 0 ) 592 //------------------------------------------------------------------------ 593 static sal_Bool SAL_CALL test_rtl_OUString_match_001( 594 hTestResult hRtlTestResult) 595 596 { 597 sal_Char methName[MAXBUFLENGTH]; 598 sal_Char* pMeth = methName; 599 600 typedef struct TestCase 601 { 602 sal_Char* comments; 603 sal_Bool expVal; 604 OUString* input1; 605 OUString* input2; 606 ~TestCase() { delete input1;delete input2;} 607 } TestCase; 608 609 TestCase arrTestCase[]={ 610 611 {"aUStr2 and aUStr1", sal_True, new OUString(aUStr2), 612 new OUString(aUStr1)}, 613 {"aUStr1 and aUStr2", sal_False, new OUString(aUStr1), 614 new OUString(aUStr2)}, 615 {"aUStr5 and aUStr6", sal_False, new OUString(aUStr5), 616 new OUString(aUStr6)}, 617 {"null and aUStr1", sal_False, new OUString( "", 618 0, 619 kEncodingRTLTextUSASCII, 620 kConvertFlagsOStringToOUString), 621 new OUString(aUStr1)} 622 623 }; 624 625 sal_Bool res = sal_True; 626 sal_uInt32 i; 627 628 for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) 629 { 630 sal_Bool lastRes = ( arrTestCase[i].input1->match( 631 *(arrTestCase[i].input2)) == arrTestCase[i].expVal ); 632 633 c_rtl_tres_state 634 ( 635 hRtlTestResult, 636 lastRes, 637 arrTestCase[i].comments, 638 createName( pMeth, "match(const OUString & str)", i ) 639 ); 640 641 res &= lastRes; 642 } 643 return (res); 644 } 645 646 static sal_Bool SAL_CALL test_rtl_OUString_match_002( 647 hTestResult hRtlTestResult ) 648 649 { 650 sal_Char methName[MAXBUFLENGTH]; 651 sal_Char* pMeth = methName; 652 653 typedef struct TestCase 654 { 655 sal_Char* comments; 656 sal_Bool expVal; 657 sal_Int32 fromIndex; 658 OUString* input1; 659 OUString* input2; 660 ~TestCase() { delete input1;delete input2;} 661 } TestCase; 662 663 TestCase arrTestCase[]={ 664 665 {"aUStr2 from 17 and aUStr6", sal_True, 17, 666 new OUString(aUStr2),new OUString(aUStr6)}, 667 {"aUStr2 from 5 and aUStr6", sal_False, 5, 668 new OUString(aUStr2),new OUString(aUStr6)}, 669 {"aUStr2 from 0 and aUStr1", sal_True, 0, 670 new OUString(aUStr2),new OUString(aUStr1)}, 671 {"aUStr1 from 16 and null", sal_True, 16, 672 new OUString(aUStr1), 673 new OUString( "", 674 0, 675 kEncodingRTLTextUSASCII, 676 kConvertFlagsOStringToOUString 677 ) 678 }, 679 {"aUStr1 from 5 and null", sal_True, 5, 680 new OUString(aUStr1), 681 new OUString( "", 682 0, 683 kEncodingRTLTextUSASCII, 684 kConvertFlagsOStringToOUString 685 ) 686 }, 687 {"aUStr2 from -1 and aUStr1", sal_False, -1, 688 new OUString(aUStr2),new OUString(aUStr1)}, 689 {"aUStr5 from 2 and aUStr4", sal_False, 2, 690 new OUString(aUStr5),new OUString(aUStr4)}, 691 {"aUStr2 from 18 and aUStr1", sal_False, 18, 692 new OUString(aUStr2),new OUString(aUStr1)} 693 }; 694 695 sal_Bool res = sal_True; 696 sal_uInt32 i; 697 698 for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) 699 { 700 sal_Bool lastRes = ( arrTestCase[i].input1->match 701 (*(arrTestCase[i].input2),arrTestCase[i].fromIndex) == 702 arrTestCase[i].expVal ); 703 704 c_rtl_tres_state 705 ( 706 hRtlTestResult, 707 lastRes, 708 arrTestCase[i].comments, 709 createName( pMeth, 710 "match(const OUString & str,sal_Int32 fromIndex = 0)", i ) 711 712 ); 713 714 res &= lastRes; 715 } 716 return (res); 717 } 718 719 extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_match( 720 hTestResult hRtlTestResult ) 721 { 722 c_rtl_tres_state_start( hRtlTestResult, "match"); 723 sal_Bool res = test_rtl_OUString_match_001(hRtlTestResult); 724 res &= test_rtl_OUString_match_002(hRtlTestResult); 725 c_rtl_tres_state_end( hRtlTestResult, "match"); 726 // return (res); 727 } 728 729 //------------------------------------------------------------------------ 730 // testing the operator += 731 //------------------------------------------------------------------------ 732 extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_op_eq( 733 hTestResult hRtlTestResult) 734 { 735 c_rtl_tres_state_start( hRtlTestResult, "eq"); 736 sal_Char methName[MAXBUFLENGTH]; 737 sal_Char* pMeth = methName; 738 739 typedef struct TestCase 740 { 741 sal_Char* comments; 742 OUString* input1; 743 OUString* input2; 744 ~TestCase() { delete input1; delete input2;} 745 } TestCase; 746 747 TestCase arrTestCase[]={ 748 {"null and Ustr1", new OUString, new OUString(aUStr1)}, 749 {"Ustr2 and Ustr1", new OUString(aUStr2), 750 new OUString(aUStr1)}, 751 {""" and Ustr1 from bit charactor buffer", 752 new OUString(aUStr1), 753 new OUString( "", 754 0, 755 kEncodingRTLTextUSASCII, 756 kConvertFlagsOStringToOUString 757 )}, 758 {"Ustr1 and Ustr2 from value and length", 759 new OUString( aUStr2, kTestStr2Len ), 760 new OUString(aUStr1)} 761 }; 762 763 764 sal_Bool res = sal_True; 765 sal_uInt32 i; 766 767 for (i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) 768 { 769 *(arrTestCase[i].input1) = *(arrTestCase[i].input2); 770 sal_Bool lastRes = (*(arrTestCase[i].input1) == 771 *(arrTestCase[i].input2)); 772 c_rtl_tres_state 773 ( 774 hRtlTestResult, 775 lastRes, 776 arrTestCase[i].comments, 777 createName( pMeth, "op_eq", i ) 778 779 ); 780 res &= lastRes; 781 } 782 c_rtl_tres_state_end( hRtlTestResult, "eq"); 783 // return ( res ); 784 } 785 786 //------------------------------------------------------------------------ 787 // testing the operator += 788 //------------------------------------------------------------------------ 789 extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_op_peq( 790 hTestResult hRtlTestResult) 791 { 792 c_rtl_tres_state_start( hRtlTestResult, "peq"); 793 sal_Char methName[MAXBUFLENGTH]; 794 sal_Char* pMeth = methName; 795 796 typedef struct TestCase 797 { 798 sal_Char* comments; 799 OUString* expVal; 800 OUString* input1; 801 OUString* input2; 802 ~TestCase() { delete input1; delete input2;} 803 } TestCase; 804 805 TestCase arrTestCase[]={ 806 {" ' '= ''+='' ", new OUString( "", 807 0, 808 kEncodingRTLTextUSASCII, 809 kConvertFlagsOStringToOUString 810 ), 811 new OUString( "", 812 0, 813 kEncodingRTLTextUSASCII, 814 kConvertFlagsOStringToOUString 815 ), 816 new OUString( "", 817 0, 818 kEncodingRTLTextUSASCII, 819 kConvertFlagsOStringToOUString 820 )}, 821 {"Ustr1= null += Ustr1", new OUString(aUStr1), 822 new OUString(), new OUString(aUStr1)}, 823 {"Ustr1= '' += Ustr1", new OUString(aUStr1), 824 /*new OUString( "", 825 0, 826 kEncodingRTLTextUSASCII, 827 kConvertFlagsOStringToOUString 828 )*/ 829 new OUString(), 830 new OUString(aUStr1)}, 831 {"Ustr1PlusUStr6 = Ustr1 += Ustr6", 832 new OUString(aUStr1PlusUStr6), new OUString(aUStr1), 833 new OUString(aUStr6)}, 834 }; 835 836 837 sal_Bool res = sal_True; 838 sal_uInt32 i; 839 840 for (i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) 841 { 842 *(arrTestCase[i].input1) += *(arrTestCase[i].input2); 843 sal_Bool lastRes = (*(arrTestCase[i].expVal) == 844 *(arrTestCase[i].input1)); 845 c_rtl_tres_state 846 ( 847 hRtlTestResult, 848 lastRes, 849 arrTestCase[i].comments, 850 createName( pMeth, "op_peq", i ) 851 852 ); 853 res &= lastRes; 854 } 855 c_rtl_tres_state_end( hRtlTestResult, "peq"); 856 // return ( res ); 857 } 858 859 //------------------------------------------------------------------------ 860 // testing the operator const sal_Unicode * (csuc for short) 861 //------------------------------------------------------------------------ 862 extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_csuc( 863 hTestResult hRtlTestResult) 864 { 865 c_rtl_tres_state_start( hRtlTestResult, "csuc"); 866 sal_Char methName[MAXBUFLENGTH]; 867 sal_Char* pMeth = methName; 868 869 const sal_Unicode tmpUC=0x0; 870 rtl_uString* tmpUstring = NULL; 871 const sal_Char *tmpStr=kTestStr1; 872 sal_Int32 tmpLen=(sal_Int32) kTestStr1Len; 873 // sal_Int32 cmpLen = 0; 874 875 rtl_string2UString( &tmpUstring, tmpStr, tmpLen, 876 osl_getThreadTextEncoding(), OSTRING_TO_OUSTRING_CVTFLAGS ); 877 OSL_ASSERT(tmpUstring != NULL); 878 879 880 typedef struct TestCase 881 { 882 sal_Char* comments; 883 const sal_Unicode* expVal; 884 sal_Int32 cmpLen; 885 OUString* input1; 886 ~TestCase() { delete input1;} 887 } TestCase; 888 889 TestCase arrTestCase[] = 890 { 891 {"test normal ustring",(*tmpUstring).buffer,kTestStr1Len, 892 new OUString(aUStr1)}, 893 {"test empty ustring",&tmpUC, 1, new OUString()} 894 }; 895 896 sal_Bool res = sal_True; 897 sal_uInt32 i; 898 for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) 899 { 900 const sal_Unicode* pstr = *arrTestCase[i].input1; 901 902 res &= c_rtl_tres_state 903 ( 904 hRtlTestResult, 905 cmpstr((sal_Char*)pstr, 906 (sal_Char*)arrTestCase[i].expVal, 907 arrTestCase[i].cmpLen), 908 arrTestCase[i].comments, 909 createName( pMeth, "const sal_Unicode*", i ) 910 ); 911 } 912 c_rtl_tres_state_end( hRtlTestResult, "csuc"); 913 // return ( res ); 914 } 915 916 //------------------------------------------------------------------------ 917 // testing the method const sal_Unicode * getStr() 918 //------------------------------------------------------------------------ 919 extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_getStr( 920 hTestResult hRtlTestResult) 921 { 922 c_rtl_tres_state_start( hRtlTestResult, "getStr"); 923 sal_Char methName[MAXBUFLENGTH]; 924 sal_Char* pMeth = methName; 925 926 const sal_Unicode tmpUC=0x0; 927 rtl_uString* tmpUstring = NULL; 928 const sal_Char *tmpStr=kTestStr1; 929 sal_Int32 tmpLen=(sal_Int32) kTestStr1Len; 930 // sal_Int32 cmpLen = 0; 931 932 rtl_string2UString( &tmpUstring, tmpStr, tmpLen, 933 osl_getThreadTextEncoding(), OSTRING_TO_OUSTRING_CVTFLAGS ); 934 OSL_ASSERT(tmpUstring != NULL); 935 936 937 typedef struct TestCase 938 { 939 sal_Char* comments; 940 const sal_Unicode* expVal; 941 sal_Int32 cmpLen; 942 OUString* input1; 943 ~TestCase() { delete input1;} 944 } TestCase; 945 946 TestCase arrTestCase[] = 947 { 948 {"test normal ustring",(*tmpUstring).buffer,kTestStr1Len, 949 new OUString(aUStr1)}, 950 {"test empty ustring",&tmpUC, 1, new OUString()} 951 }; 952 953 sal_Bool res = sal_True; 954 sal_uInt32 i; 955 for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) 956 { 957 const sal_Unicode* pstr = arrTestCase[i].input1->getStr(); 958 959 res &= c_rtl_tres_state 960 ( 961 hRtlTestResult, 962 cmpstr((sal_Char*)pstr, 963 (sal_Char*)arrTestCase[i].expVal, 964 arrTestCase[i].cmpLen), 965 arrTestCase[i].comments, 966 createName( pMeth, "getStr", i ) 967 ); 968 } 969 c_rtl_tres_state_end( hRtlTestResult, "getStr"); 970 // return ( res ); 971 } 972 973 974 //------------------------------------------------------------------------ 975 // testing the method sal_Int32 reverseCompareTo( const OUString & str ) 976 //------------------------------------------------------------------------- 977 extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_reverseCompareTo( 978 hTestResult hRtlTestResult ) 979 { 980 c_rtl_tres_state_start( hRtlTestResult, "reverseCompareTo"); 981 sal_Char methName[MAXBUFLENGTH]; 982 sal_Char* pMeth = methName; 983 984 typedef struct TestCase 985 { 986 sal_Char* comments; 987 sal_Int32 expVal; 988 OUString* input1; 989 OUString* input2; 990 ~TestCase() { delete input1;delete input2;} 991 } TestCase; 992 993 TestCase arrTestCase[]={ 994 995 {"simple compare, str1 to str5",-1,new OUString(aUStr1), 996 new OUString(aUStr5) 997 }, 998 {"simple compare, str2 to str5",1,new OUString(aUStr2), 999 new OUString(aUStr5) 1000 }, 1001 {"simple compare, str1 to str9",-1,new OUString(aUStr1), 1002 new OUString(aUStr9) 1003 }, 1004 {"simple compare, str4 to str5",-1,new OUString(aUStr4), 1005 new OUString(aUStr5) 1006 }, 1007 {"simple compare, str5 to str1",+1,new OUString(aUStr5), 1008 new OUString(aUStr1) 1009 }, 1010 {"simple compare, str2 to str1",+1,new OUString(aUStr2), 1011 new OUString(aUStr1) 1012 }, 1013 {"simple compare, str1 to str1",0,new OUString(aUStr1), 1014 new OUString(aUStr1) 1015 }, 1016 {"simple compare, nullString to nullString",0,new OUString(), 1017 new OUString() 1018 }, 1019 {"simple compare, nullString to str2",-1,new OUString(), 1020 new OUString(aUStr2) 1021 }, 1022 {"simple compare, str1 to nullString",+1,new OUString(aUStr1), 1023 new OUString() 1024 } 1025 }; 1026 1027 sal_Bool res = sal_True; 1028 sal_uInt32 i; 1029 1030 for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) 1031 { 1032 sal_Int32 cmpRes = arrTestCase[i].input1->reverseCompareTo 1033 (*arrTestCase[i].input2); 1034 cmpRes = ( cmpRes == 0 ) ? 0 : ( cmpRes > 0 ) ? +1 : -1 ; 1035 sal_Bool lastRes = ( cmpRes == arrTestCase[i].expVal); 1036 1037 1038 c_rtl_tres_state 1039 ( 1040 hRtlTestResult, 1041 lastRes, 1042 arrTestCase[i].comments, 1043 createName( pMeth, "compareTo(const OString&)", i ) 1044 ); 1045 1046 res &= lastRes; 1047 } 1048 c_rtl_tres_state_end( hRtlTestResult, "reverseCompareTo"); 1049 // return (res); 1050 } 1051 1052 //------------------------------------------------------------------------ 1053 // testing the method sal_Bool equalsAscii( const sal_Char* asciiStr ) 1054 //------------------------------------------------------------------------ 1055 extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_equalsAscii( 1056 hTestResult hRtlTestResult) 1057 { 1058 c_rtl_tres_state_start( hRtlTestResult, "equalsAscii"); 1059 sal_Char methName[MAXBUFLENGTH]; 1060 sal_Char* pMeth = methName; 1061 1062 const sal_Char *tmpAstr1="Sun Microsystems\0"; 1063 const sal_Char *tmpAstr2="\0"; 1064 1065 1066 1067 typedef struct TestCase 1068 { 1069 sal_Char* comments; 1070 sal_Bool expVal; 1071 OUString* input1; 1072 const sal_Char* input2; 1073 ~TestCase() { delete input1;} 1074 } TestCase; 1075 1076 TestCase arrTestCase[]={ 1077 {"str1 with str1 ", sal_True, new OUString( kTestStr1, 1078 kTestStr1Len, 1079 kEncodingRTLTextUSASCII, 1080 kConvertFlagsOStringToOUString 1081 ), tmpAstr1}, 1082 {"str2 with str1 ", sal_False,new OUString( kTestStr2, 1083 kTestStr2Len, 1084 kEncodingRTLTextUSASCII, 1085 kConvertFlagsOStringToOUString 1086 ), tmpAstr1}, 1087 {"null with str1 ", sal_False, new OUString(), tmpAstr1}, 1088 {"null with '' ", sal_True, new OUString(), tmpAstr2}, 1089 {"'' with ''", sal_True, new OUString( "", 1090 0, 1091 kEncodingRTLTextUSASCII, 1092 kConvertFlagsOStringToOUString 1093 ), 1094 tmpAstr2} 1095 1096 }; 1097 1098 1099 sal_Bool res = sal_True; 1100 sal_uInt32 i; 1101 1102 for (i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) 1103 { 1104 1105 sal_Bool lastRes = (arrTestCase[i].expVal == 1106 arrTestCase[i].input1->equalsAscii(arrTestCase[i].input2)); 1107 c_rtl_tres_state 1108 ( 1109 hRtlTestResult, 1110 lastRes, 1111 arrTestCase[i].comments, 1112 createName( pMeth, "equalsAscii", i ) 1113 1114 ); 1115 res &= lastRes; 1116 } 1117 c_rtl_tres_state_end( hRtlTestResult, "equalsAscii"); 1118 // return ( res ); 1119 } 1120 1121 1122 1123 //------------------------------------------------------------------------ 1124 // testing the method sal_Bool equalsAsciiL( 1125 // const sal_Char* asciiStr, sal_Int32 asciiStrLength ) 1126 //------------------------------------------------------------------------ 1127 extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_equalsAsciiL( 1128 hTestResult hRtlTestResult) 1129 { 1130 c_rtl_tres_state_start( hRtlTestResult, "equalsAsciiL"); 1131 sal_Char methName[MAXBUFLENGTH]; 1132 sal_Char* pMeth = methName; 1133 1134 const sal_Char *tmpAstr1="Sun Microsystems\0"; 1135 const sal_Char *tmpAstr2="\0"; 1136 const sal_Char *tmpAstr3="Sun Microsystems Java Technology\0"; 1137 1138 1139 1140 typedef struct TestCase 1141 { 1142 sal_Char* comments; 1143 sal_Bool expVal; 1144 OUString* input1; 1145 const sal_Char* input2; 1146 sal_Int32 cmpLen; 1147 ~TestCase() { delete input1;} 1148 } TestCase; 1149 1150 TestCase arrTestCase[]={ 1151 {"str1 with str1,str1Len ", sal_True, new OUString( kTestStr1, 1152 kTestStr1Len, 1153 kEncodingRTLTextUSASCII, 1154 kConvertFlagsOStringToOUString 1155 ), tmpAstr1, kTestStr1Len}, 1156 {"str2 with str1,str1Len", sal_False,new OUString( kTestStr2, 1157 kTestStr2Len, 1158 kEncodingRTLTextUSASCII, 1159 kConvertFlagsOStringToOUString 1160 ), tmpAstr1, kTestStr1Len}, 1161 {"str1 with str2,str1Len", sal_True,new OUString( kTestStr1, 1162 kTestStr1Len, 1163 kEncodingRTLTextUSASCII, 1164 kConvertFlagsOStringToOUString 1165 ), tmpAstr3, kTestStr1Len}, 1166 {"null with str1,1 ", sal_False, new OUString(), tmpAstr1, 1}, 1167 {"null with '',1 ", sal_False, new OUString(), tmpAstr2, 1}, 1168 {"'' with '', 1", sal_False, new OUString( "", 1169 0, 1170 kEncodingRTLTextUSASCII, 1171 kConvertFlagsOStringToOUString 1172 ), 1173 tmpAstr2, 1} 1174 1175 }; 1176 1177 1178 sal_Bool res = sal_True; 1179 sal_uInt32 i; 1180 1181 for (i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) 1182 { 1183 1184 sal_Bool lastRes = (arrTestCase[i].expVal == 1185 arrTestCase[i].input1->equalsAsciiL(arrTestCase[i].input2, 1186 arrTestCase[i].cmpLen) 1187 ); 1188 c_rtl_tres_state 1189 ( 1190 hRtlTestResult, 1191 lastRes, 1192 arrTestCase[i].comments, 1193 createName( pMeth, "equalsAsciiL", i ) 1194 1195 ); 1196 res &= lastRes; 1197 } 1198 c_rtl_tres_state_end( hRtlTestResult, "equalsAsciiL"); 1199 // return ( res ); 1200 } 1201 1202 //------------------------------------------------------------------------ 1203 // testing the method sal_Int32 compareToAscii( const sal_Char* asciiStr ) 1204 //------------------------------------------------------------------------ 1205 extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_compareToAscii( 1206 hTestResult hRtlTestResult) 1207 { 1208 c_rtl_tres_state_start( hRtlTestResult, "compareToAscii"); 1209 sal_Char methName[MAXBUFLENGTH]; 1210 sal_Char* pMeth = methName; 1211 1212 const sal_Char *tmpAstr1="Sun Microsystems\0"; 1213 const sal_Char *tmpAstr2="\0"; 1214 const sal_Char *tmpAstr3="sun microsystems java technology\0"; 1215 const sal_Char *tmpAstr4="Sun Microsystems Java Technology\0"; 1216 1217 1218 typedef struct TestCase 1219 { 1220 sal_Char* comments; 1221 sal_Int32 expVal; 1222 OUString* input1; 1223 const sal_Char* input2; 1224 ~TestCase() { delete input1;} 1225 } TestCase; 1226 1227 TestCase arrTestCase[]={ 1228 {"str1 with str1 ", 0, new OUString( kTestStr1, 1229 kTestStr1Len, 1230 kEncodingRTLTextUSASCII, 1231 kConvertFlagsOStringToOUString 1232 ), tmpAstr1}, 1233 {"str1 with '' ", 83, new OUString( kTestStr1, 1234 kTestStr1Len, 1235 kEncodingRTLTextUSASCII, 1236 kConvertFlagsOStringToOUString 1237 ), tmpAstr2}, 1238 {"null with str1 ", -83 , new OUString(), tmpAstr1}, 1239 {"null with '' ", 0, new OUString(), tmpAstr2}, 1240 {"str1 with str9", -32, new OUString( kTestStr1, 1241 kTestStr1Len, 1242 kEncodingRTLTextUSASCII, 1243 kConvertFlagsOStringToOUString 1244 ), 1245 tmpAstr3}, 1246 {"str1 with str2", -32, new OUString( kTestStr1, 1247 kTestStr1Len, 1248 kEncodingRTLTextUSASCII, 1249 kConvertFlagsOStringToOUString 1250 ), 1251 tmpAstr4} 1252 1253 }; 1254 1255 1256 sal_Bool res = sal_True; 1257 sal_uInt32 i; 1258 1259 for (i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) 1260 { 1261 sal_Bool lastRes = (arrTestCase[i].expVal == 1262 arrTestCase[i].input1->compareToAscii(arrTestCase[i].input2)); 1263 1264 c_rtl_tres_state 1265 ( 1266 hRtlTestResult, 1267 lastRes, 1268 arrTestCase[i].comments, 1269 createName( pMeth, "equalsAscii", i ) 1270 1271 ); 1272 res &= lastRes; 1273 } 1274 c_rtl_tres_state_end( hRtlTestResult, "compareToAscii"); 1275 // return ( res ); 1276 } 1277 1278 1279 //------------------------------------------------------------------------ 1280 // testing the method valueOf( sal_Bool b ) 1281 //------------------------------------------------------------------------ 1282 extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_valueOf_sal_Bool( 1283 hTestResult hRtlTestResult ) 1284 { 1285 c_rtl_tres_state_start( hRtlTestResult, "Bool"); 1286 sal_Char methName[MAXBUFLENGTH]; 1287 sal_Char* pMeth = methName; 1288 1289 typedef struct TestCase 1290 { 1291 sal_Char* comments; 1292 OUString* expVal; 1293 sal_Bool input1; 1294 1295 ~TestCase() {delete expVal;} 1296 }TestCase; 1297 1298 TestCase arrTestCase[]= 1299 { 1300 {"input Bool 'true' and return OUString 'true'", 1301 new OUString("true",4,kEncodingRTLTextUSASCII, 1302 kConvertFlagsOStringToOUString), 1303 sal_True 1304 }, 1305 {"input Bool 'false' and return OUString 'false'", 1306 new OUString("false",5,kEncodingRTLTextUSASCII, 1307 kConvertFlagsOStringToOUString), 1308 sal_False 1309 } 1310 }; 1311 1312 sal_Bool res; 1313 sal_uInt32 i; 1314 1315 for(i=0;i<(sizeof(arrTestCase))/(sizeof(TestCase));i++) 1316 { 1317 sal_Bool lastRes=(*arrTestCase[i].expVal== 1318 OUString::valueOf(arrTestCase[i].input1) 1319 1320 ); 1321 1322 c_rtl_tres_state(hRtlTestResult, 1323 lastRes, 1324 arrTestCase[i].comments, 1325 createName( pMeth, "valueOf( sal_Bool b )", i ) 1326 ); 1327 1328 res &= lastRes; 1329 } 1330 c_rtl_tres_state_end( hRtlTestResult, "Bool"); 1331 // return(res); 1332 } 1333 1334 //------------------------------------------------------------------------ 1335 extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_valueOf_sal_Unicode( 1336 hTestResult hRtlTestResult ) 1337 { 1338 c_rtl_tres_state_start( hRtlTestResult, "Unicode"); 1339 sal_Char methName[MAXBUFLENGTH]; 1340 sal_Char* pMeth = methName; 1341 1342 sal_Unicode tmpchar1=97; 1343 sal_Unicode tmpchar2=53; 1344 sal_Unicode tmpchar3=0; 1345 sal_Unicode tmpchar4=32; 1346 sal_Unicode tmpchar5=47; 1347 1348 typedef struct TestCase 1349 { 1350 sal_Char* comments; 1351 OUString* expVal; 1352 sal_Unicode input1; 1353 1354 ~TestCase() {delete expVal;} 1355 }TestCase; 1356 1357 TestCase arrTestCase[]= 1358 { 1359 {"input Unicode 'a' and return OUString 'a'", 1360 new OUString(&tmpchar1,1),tmpchar1 1361 }, 1362 {"input Unicode '5' and return OUString '5'", 1363 new OUString(&tmpchar2,1), tmpchar2 1364 }, 1365 {"input Unicode 0 and return OUString 0", 1366 new OUString(&tmpchar3,1),tmpchar3 1367 }, 1368 {"input Unicode ' ' and return OUString ' '", 1369 new OUString(&tmpchar4,1),tmpchar4 1370 }, 1371 {"input Unicode '/' and return OUString ' '", 1372 new OUString(&tmpchar5,1),tmpchar5 1373 } 1374 }; 1375 1376 sal_Bool res=sal_True; 1377 sal_uInt32 i; 1378 1379 for(i=0;i<(sizeof(arrTestCase))/(sizeof(TestCase));i++) 1380 { 1381 sal_Bool lastRes=(*(arrTestCase[i].expVal)== 1382 OUString::valueOf(arrTestCase[i].input1)); 1383 1384 c_rtl_tres_state(hRtlTestResult, 1385 lastRes, 1386 arrTestCase[i].comments, 1387 createName( pMeth, "valueOf( sal_Unicode c )", i ) 1388 ); 1389 1390 res &= lastRes; 1391 } 1392 c_rtl_tres_state_end( hRtlTestResult, "Unicode"); 1393 // return(res); 1394 } 1395 1396 1397 /** 1398 * Calls the method valueOf(T, radix) and compares 1399 * returned ustrings with ustrings that passed in the array resArray. 1400 * 1401 * @param T, type of argument, passed to valueOf 1402 * @param resArray, array of result ustrings to compare to 1403 * @param n the number of elements in the array resArray (testcases) 1404 * @param pTestResult the instance of the class TestResult 1405 * @param inArray [optional], array of value that is passed as first argument 1406 * to valueOf 1407 * 1408 * @return true, if all returned ustrings are equal to corresponding ustring in 1409 * resArray else, false. 1410 */ 1411 template <class T> 1412 sal_Bool test_valueOf( const char** resArray, int n, sal_Int16 radix, 1413 hTestResult hRtlTestResult, const T *inArray ) 1414 { 1415 sal_Bool bRes = sal_True; 1416 1417 sal_Char methName[MAXBUFLENGTH]; 1418 sal_Char* pMeth = methName; 1419 sal_Int32 i; 1420 // static sal_Unicode aUchar[50]={0x12}; 1421 1422 for (i = 0; i < n; i++) 1423 { 1424 ::rtl::OUString aStr1; 1425 1426 OSL_ENSURE( i < 50, "ERROR: leave aUchar bound"); 1427 1428 // AStringToUStringCopy(aUchar,resArray[i]); 1429 // ::rtl::OUString aStr2(aUchar); 1430 rtl::OUString aStr2; 1431 aStr2 = OUString::createFromAscii(resArray[i]); 1432 1433 ::rtl::OUString aStr3( "-",1,kEncodingRTLTextUSASCII, 1434 kConvertFlagsOStringToOUString); 1435 1436 if (inArray == 0) 1437 { 1438 aStr1 = ::rtl::OUString::valueOf((T)i, radix); 1439 } 1440 else 1441 { 1442 if ( inArray[i] < 0 ) 1443 { 1444 sal_Unicode aStr4[100]; 1445 OSL_ASSERT(strlen(resArray[i]) < 100); 1446 1447 if(AStringToUStringCopy(aStr4,resArray[i])) 1448 { 1449 aStr2 = aStr3; 1450 aStr2 += aStr4; 1451 } 1452 1453 } 1454 aStr1 = ::rtl::OUString::valueOf((T)inArray[i], radix); 1455 } 1456 1457 bRes &= c_rtl_tres_state 1458 ( 1459 hRtlTestResult, 1460 aStr2.compareTo(aStr1) == 0, 1461 (sal_Char*)resArray[i], 1462 createName( pMeth, "valueOf", i ) 1463 ); 1464 } 1465 1466 return (bRes); 1467 } 1468 1469 1470 #define test_valueOf_Int32 test_valueOf<sal_Int32> 1471 #define test_valueOf_Int64 test_valueOf<sal_Int64> 1472 // LLA: #define test_valueOf_float test_valueOf<float> 1473 // LLA: #define test_valueOf_double test_valueOf<double> 1474 1475 //------------------------------------------------------------------------ 1476 // testing the method valueOf( sal_Int32 i, sal_Int16 radix=2 ) 1477 // testing the method valueOf( sal_Int32 i, sal_Int16 radix=8 ) 1478 // testing the method valueOf( sal_Int32 i, sal_Int16 radix=10 ) 1479 // testing the method valueOf( sal_Int32 i, sal_Int16 radix=16 ) 1480 // testing the method valueOf( sal_Int32 i, sal_Int16 radix=36 ) 1481 //------------------------------------------------------------------------ 1482 sal_Bool SAL_CALL test_rtl_OUString_valueOf_Int32( 1483 hTestResult hRtlTestResult ) 1484 { 1485 sal_Bool bRes = sal_False; 1486 1487 bRes = c_rtl_tres_state 1488 ( 1489 hRtlTestResult, 1490 test_valueOf_Int32((const char**)kBinaryNumsStr, 1491 kBinaryNumsCount, kRadixBinary, hRtlTestResult, 0 ), 1492 "kRadixBinary", 1493 "valueOf(sal_Int32, radix 2)" 1494 ); 1495 1496 1497 bRes &= c_rtl_tres_state 1498 ( 1499 hRtlTestResult, 1500 test_valueOf_Int32((const char**)kOctolNumsStr, 1501 kOctolNumsCount, kRadixOctol, hRtlTestResult, 0), 1502 "kRadixOctol", 1503 "valueOf(sal_Int32, radix 8)" 1504 ); 1505 1506 bRes &= c_rtl_tres_state 1507 ( 1508 hRtlTestResult, 1509 test_valueOf_Int32((const char**)kDecimalNumsStr, 1510 kDecimalNumsCount, kRadixDecimal, hRtlTestResult, 0), 1511 "kRadixDecimal", 1512 "valueOf(sal_Int32, radix 10)" 1513 ); 1514 1515 bRes &= c_rtl_tres_state 1516 ( 1517 hRtlTestResult, 1518 test_valueOf_Int32((const char**)kHexDecimalNumsStr, 1519 kHexDecimalNumsCount, kRadixHexdecimal, hRtlTestResult, 0), 1520 "kRadixHexdecimal", 1521 "valueOf(sal_Int32, radix 16)" 1522 ); 1523 1524 bRes &= c_rtl_tres_state 1525 ( 1526 hRtlTestResult, 1527 test_valueOf_Int32((const char**)kBase36NumsStr, 1528 kBase36NumsCount, kRadixBase36, hRtlTestResult, 0), 1529 "kRadixBase36", 1530 "valueOf(sal_Int32, radix 36)" 1531 ); 1532 1533 1534 return ( bRes ); 1535 } 1536 1537 //------------------------------------------------------------------------ 1538 // testing the method valueOf( sal_Int32 l, sal_Int32 radix=2 ) 1539 // where l = large constants 1540 // testing the method valueOf( sal_Int32 l, sal_Int32 radix=8 ) 1541 // where l = large constants 1542 // testing the method valueOf( sal_Int32 l, sal_Int32 radix=10 ) 1543 // where l = large constants 1544 // testing the method valueOf( sal_Int32 l, sal_Int32 radix=16 ) 1545 // where l = large constants 1546 // testing the method valueOf( sal_Int32 l, sal_Int32 radix=36 ) 1547 // where l = large constants 1548 //------------------------------------------------------------------------ 1549 sal_Bool SAL_CALL test_rtl_OUString_valueOf_Int32_Bounderies( 1550 hTestResult hRtlTestResult ) 1551 { 1552 sal_Bool bRes = sal_False; 1553 1554 bRes = c_rtl_tres_state 1555 ( 1556 hRtlTestResult, 1557 test_valueOf_Int32((const char**)kBinaryMaxNumsStr, 1558 kInt32MaxNumsCount, kRadixBinary, 1559 hRtlTestResult, kInt32MaxNums), 1560 "kRadixBinary", 1561 "valueOf(salInt32, radix 2) Bounderies" 1562 ); 1563 1564 bRes &= c_rtl_tres_state 1565 ( 1566 hRtlTestResult, 1567 test_valueOf_Int32((const char**)kOctolMaxNumsStr, 1568 kInt32MaxNumsCount, kRadixOctol, 1569 hRtlTestResult, kInt32MaxNums), 1570 "kRadixOctol", 1571 "valueOf(salInt32, radix 8) Bounderies" 1572 ); 1573 1574 bRes &= c_rtl_tres_state 1575 ( 1576 hRtlTestResult, 1577 test_valueOf_Int32((const char**)kDecimalMaxNumsStr, 1578 kInt32MaxNumsCount, kRadixDecimal, 1579 hRtlTestResult, kInt32MaxNums), 1580 "kRadixDecimal", 1581 "valueOf(salInt32, radix 10) Bounderies" 1582 ); 1583 1584 bRes &= c_rtl_tres_state 1585 ( 1586 hRtlTestResult, 1587 test_valueOf_Int32((const char**)kHexDecimalMaxNumsStr, 1588 kInt32MaxNumsCount, kRadixHexdecimal, 1589 hRtlTestResult, kInt32MaxNums), 1590 "kRadixHexdecimal", 1591 "valueOf(salInt32, radix 16) Bounderies" 1592 ); 1593 1594 bRes &= c_rtl_tres_state 1595 ( 1596 hRtlTestResult, 1597 test_valueOf_Int32((const char**)kBase36MaxNumsStr, 1598 kInt32MaxNumsCount, kRadixBase36, 1599 hRtlTestResult, kInt32MaxNums), 1600 "kRadixBase36", 1601 "valueOf(salInt32, radix 36) Bounderies" 1602 ); 1603 1604 return ( bRes ); 1605 } 1606 1607 //------------------------------------------------------------------------ 1608 // testing the method valueOf( sal_Int32 i, sal_Int16 radix=2 ) 1609 // for negative value 1610 // testing the method valueOf( sal_Int32 i, sal_Int16 radix=8 ) 1611 // for negative value 1612 // testing the method valueOf( sal_Int32 i, sal_Int16 radix=10 ) 1613 // for negative value 1614 // testing the method valueOf( sal_Int32 i, sal_Int16 radix=16 ) 1615 // for negative value 1616 // testing the method valueOf( sal_Int32 i, sal_Int16 radix=36 ) 1617 // for negative value 1618 //------------------------------------------------------------------------ 1619 sal_Bool SAL_CALL test_rtl_OUString_valueOf_Int32_Negative( 1620 hTestResult hRtlTestResult ) 1621 { 1622 sal_Bool bRes = sal_False; 1623 sal_Int32 inArr[kBase36NumsCount]; 1624 sal_Int32 i; 1625 1626 for (i = 0; i < kBase36NumsCount; i++ ) 1627 inArr[i] = -i; 1628 1629 bRes = c_rtl_tres_state 1630 ( 1631 hRtlTestResult, 1632 test_valueOf_Int32( kBinaryNumsStr, kBinaryNumsCount, 1633 kRadixBinary, hRtlTestResult, inArr ), 1634 "negative Int32, kRadixBinary", 1635 "valueOf( negative Int32, radix 2 )" 1636 ); 1637 1638 bRes &= c_rtl_tres_state 1639 ( 1640 hRtlTestResult, 1641 test_valueOf_Int32( kOctolNumsStr, kOctolNumsCount, 1642 kRadixOctol, hRtlTestResult, inArr ), 1643 "negative Int32, kRadixOctol", 1644 "valueOf( negative Int32, radix 8 )" 1645 ); 1646 1647 1648 bRes &= c_rtl_tres_state 1649 ( 1650 hRtlTestResult, 1651 test_valueOf_Int32( kDecimalNumsStr, kDecimalNumsCount, 1652 kRadixDecimal, hRtlTestResult, inArr ), 1653 "negative Int32, kRadixDecimal", 1654 "valueOf( negative Int32, radix 10 )" 1655 ); 1656 1657 bRes &= c_rtl_tres_state 1658 ( 1659 hRtlTestResult, 1660 test_valueOf_Int32( kHexDecimalNumsStr, kHexDecimalNumsCount, 1661 kRadixHexdecimal, hRtlTestResult, inArr ), 1662 "negative Int32, kRadixHexdecimal", 1663 "valueOf( negative Int32, radix 16 )" 1664 ); 1665 1666 1667 bRes &= c_rtl_tres_state 1668 ( 1669 hRtlTestResult, 1670 test_valueOf_Int32( kBase36NumsStr, kBase36NumsCount, 1671 kRadixBase36, hRtlTestResult, inArr ), 1672 "negative Int32, kRadixBase36", 1673 "valueOf( negative Int32, radix 36 )" 1674 ); 1675 1676 return ( bRes ); 1677 } 1678 //------------------------------------------------------------------------ 1679 // testing the method valueOf( sal_Int32 l, sal_Int32 radix ) where radix = -5 1680 //------------------------------------------------------------------------ 1681 sal_Bool SAL_CALL test_rtl_OUString_valueOf_Int32_WrongRadix( 1682 hTestResult hRtlTestResult ) 1683 { 1684 sal_Bool bRes = sal_False; 1685 1686 sal_Int32 intVal = 11; 1687 1688 ::rtl::OUString aStr1; 1689 ::rtl::OUString aStr2("11",2,kEncodingRTLTextUSASCII, 1690 kConvertFlagsOStringToOUString); 1691 1692 aStr1 = aStr1.valueOf( intVal, -5 ); 1693 1694 bRes = c_rtl_tres_state 1695 ( 1696 hRtlTestResult, 1697 aStr2.compareTo( aStr1 ) == 0, 1698 "if radix not valid then radix must be 10", 1699 "valueOf(sal_Int32, sal_Int32 radix): radix = -5" 1700 ); 1701 1702 return (bRes); 1703 } 1704 1705 1706 //------------------------------------------------------------------------ 1707 static sal_Bool SAL_CALL test_rtl_OUString_valueOf_Int32_defaultParam( 1708 hTestResult hRtlTestResult ) 1709 { 1710 sal_Char methName[MAXBUFLENGTH]; 1711 sal_Char* pMeth = methName; 1712 1713 sal_Char* newUChar1="15"; 1714 sal_Char* newUChar2="0"; 1715 sal_Char* newUChar3="-15"; 1716 sal_Char* newUChar4="2147483647"; 1717 sal_Char* newUChar5="-2147483648"; 1718 1719 typedef struct TestCase 1720 { 1721 sal_Char* comments; 1722 sal_Int32 input1; 1723 OUString* expVal; 1724 ~TestCase() {delete expVal;} 1725 }TestCase; 1726 1727 TestCase arrTestCase[]= 1728 { 1729 {"input Int32 15 and return OUString 15",15, 1730 new OUString(newUChar1,2,kEncodingRTLTextUSASCII, 1731 kConvertFlagsOStringToOUString) 1732 }, 1733 {"input Int32 0 and return OUString 0",0, 1734 new OUString(newUChar2,1,kEncodingRTLTextUSASCII, 1735 kConvertFlagsOStringToOUString) 1736 }, 1737 {"input Int32 -15 and return OUString -15",-15, 1738 new OUString(newUChar3,3,kEncodingRTLTextUSASCII, 1739 kConvertFlagsOStringToOUString) 1740 }, 1741 {"input Int32 2147483647 and return OUString 2147483647", SAL_MAX_INT32 /* 2147483647 */, 1742 new OUString(newUChar4,10,kEncodingRTLTextUSASCII, 1743 kConvertFlagsOStringToOUString) 1744 }, 1745 {"input Int32 -2147483648 and return OUString -2147483648", 1746 SAL_MIN_INT32 /* 2-2147483648 */, 1747 new OUString(newUChar5,11,kEncodingRTLTextUSASCII, 1748 kConvertFlagsOStringToOUString) 1749 } 1750 }; 1751 1752 sal_Bool res=sal_True; 1753 sal_uInt32 i; 1754 1755 for(i=0;i<(sizeof(arrTestCase))/(sizeof(TestCase));i++) 1756 { 1757 sal_Bool lastRes=(*(arrTestCase[i].expVal)== 1758 OUString::valueOf(arrTestCase[i].input1)); 1759 1760 c_rtl_tres_state(hRtlTestResult, 1761 lastRes, 1762 arrTestCase[i].comments, 1763 createName( pMeth, 1764 "valueOf( sal_Int32 i, sal_Int16 radix = 10 )", i ) 1765 ); 1766 1767 res &= lastRes; 1768 } 1769 1770 return(res); 1771 1772 } 1773 //------------------------------------------------------------------------ 1774 // testing the method valueOf( sal_Int64 l, sal_Int16 radix=2 ) 1775 // testing the method valueOf( sal_Int64 l, sal_Int16 radix=8 ) 1776 // testing the method valueOf( sal_Int64 l, sal_Int16 radix=10 ) 1777 // testing the method valueOf( sal_Int64 l, sal_Int16 radix=16 ) 1778 // testing the method valueOf( sal_Int64 l, sal_Int16 radix=36 ) 1779 //------------------------------------------------------------------------ 1780 sal_Bool SAL_CALL test_rtl_OUString_valueOf_Int64( 1781 hTestResult hRtlTestResult ) 1782 { 1783 sal_Bool bRes = sal_False; 1784 1785 bRes = c_rtl_tres_state 1786 ( 1787 hRtlTestResult, 1788 test_valueOf_Int64((const char**)kBinaryNumsStr, 1789 kBinaryNumsCount, kRadixBinary, hRtlTestResult, 0), 1790 "kRadixBinary", 1791 "valueOf(sal_Int64, radix 2)_" 1792 ); 1793 1794 bRes &= c_rtl_tres_state 1795 ( 1796 hRtlTestResult, 1797 test_valueOf_Int64((const char**)kOctolNumsStr, 1798 kOctolNumsCount, kRadixOctol, hRtlTestResult, 0), 1799 "kRadixOctol", 1800 "valueOf(sal_Int64, radix 8)_" 1801 ); 1802 1803 bRes &= c_rtl_tres_state 1804 ( 1805 hRtlTestResult, 1806 test_valueOf_Int64((const char**)kDecimalNumsStr, 1807 kDecimalNumsCount, kRadixDecimal, hRtlTestResult, 0), 1808 "kRadixDecimal", 1809 "valueOf(sal_Int64, radix 10)_" 1810 ); 1811 bRes &= c_rtl_tres_state 1812 ( 1813 hRtlTestResult, 1814 test_valueOf_Int64((const char**)kHexDecimalNumsStr, 1815 kHexDecimalNumsCount, kRadixHexdecimal, hRtlTestResult, 0), 1816 "kRadixHexdecimal", 1817 "valueOf(sal_Int64, radix 16)_" 1818 ); 1819 1820 bRes &= c_rtl_tres_state 1821 ( 1822 hRtlTestResult, 1823 test_valueOf_Int64((const char**)kBase36NumsStr, 1824 kBase36NumsCount, kRadixBase36, hRtlTestResult, 0), 1825 "kRadixBase36", 1826 "valueOf(sal_Int64, radix 36)_" 1827 ); 1828 1829 return (bRes); 1830 } 1831 1832 //------------------------------------------------------------------------ 1833 // testing the method valueOf( sal_Int64 l, sal_Int32 radix=2 ) 1834 // where l = large constants 1835 // testing the method valueOf( sal_Int64 l, sal_Int32 radix=8 ) 1836 // where l = large constants 1837 // testing the method valueOf( sal_Int64 l, sal_Int32 radix=10 ) 1838 // where l = large constants 1839 // testing the method valueOf( sal_Int64 l, sal_Int32 radix=16 ) 1840 // where l = large constants 1841 // testing the method valueOf( sal_Int64 l, sal_Int32 radix=36 ) 1842 // where l = large constants 1843 //------------------------------------------------------------------------ 1844 sal_Bool SAL_CALL test_rtl_OUString_valueOf_Int64_Bounderies( 1845 hTestResult hRtlTestResult ) 1846 { 1847 sal_Bool bRes = sal_False; 1848 1849 bRes = c_rtl_tres_state 1850 ( 1851 hRtlTestResult, 1852 test_valueOf_Int64((const char**)kBinaryMaxNumsStr, 1853 kInt64MaxNumsCount, kRadixBinary, 1854 hRtlTestResult, kInt64MaxNums), 1855 "kRadixBinary", 1856 "valueOf(salInt64, radix 2) Bounderies" 1857 ); 1858 1859 bRes &= c_rtl_tres_state 1860 ( 1861 hRtlTestResult, 1862 test_valueOf_Int64((const char**)kOctolMaxNumsStr, 1863 kInt64MaxNumsCount, kRadixOctol, 1864 hRtlTestResult, kInt64MaxNums), 1865 "kRadixOctol", 1866 "valueOf(salInt64, radix 8) Bounderies" 1867 ); 1868 1869 bRes &= c_rtl_tres_state 1870 ( 1871 hRtlTestResult, 1872 test_valueOf_Int64((const char**)kDecimalMaxNumsStr, 1873 kInt64MaxNumsCount, kRadixDecimal, 1874 hRtlTestResult, kInt64MaxNums), 1875 "kRadixDecimal", 1876 "valueOf(salInt64, radix 10) Bounderies" 1877 ); 1878 1879 bRes &= c_rtl_tres_state 1880 ( 1881 hRtlTestResult, 1882 test_valueOf_Int64((const char**)kHexDecimalMaxNumsStr, 1883 kInt64MaxNumsCount, kRadixHexdecimal, 1884 hRtlTestResult, kInt64MaxNums), 1885 "kRadixHexdecimal", 1886 "valueOf(salInt64, radix 16) Bounderies" 1887 ); 1888 1889 bRes &= c_rtl_tres_state 1890 ( 1891 hRtlTestResult, 1892 test_valueOf_Int64((const char**)kBase36MaxNumsStr, 1893 kInt64MaxNumsCount, kRadixBase36, 1894 hRtlTestResult, kInt64MaxNums), 1895 "kRadixBase36", 1896 "valueOf(salInt64, radix 36) Bounderies" 1897 ); 1898 1899 return ( bRes ); 1900 } 1901 1902 //------------------------------------------------------------------------ 1903 // testing the method valueOf( sal_Int64 l, sal_Int16 radix=2 ) 1904 // for negative value 1905 // testing the method valueOf( sal_Int64 l, sal_Int16 radix=8 ) 1906 // for negative value 1907 // testing the method valueOf( sal_Int64 l, sal_Int16 radix=10 ) 1908 // for negative value 1909 // testing the method valueOf( sal_Int64 l, sal_Int16 radix=16 ) 1910 // for negative value 1911 // testing the method valueOf( sal_Int64 l, sal_Int16 radix=36 ) 1912 // for negative value 1913 //------------------------------------------------------------------------ 1914 sal_Bool SAL_CALL test_rtl_OUString_valueOf_Int64_Negative( 1915 hTestResult hRtlTestResult ) 1916 { 1917 sal_Bool bRes = sal_False; 1918 1919 sal_Int64 inArr[36]; 1920 sal_Int32 i; 1921 1922 for (i = 0; i < 36; i++) { 1923 inArr[i] = -i; 1924 } 1925 1926 1927 bRes = c_rtl_tres_state 1928 ( 1929 hRtlTestResult, 1930 test_valueOf_Int64( kBinaryNumsStr, kBinaryNumsCount, 1931 kRadixBinary, hRtlTestResult, inArr ), 1932 "negative Int64, kRadixBinary", 1933 "valueOf( negative Int64, radix 2 )" 1934 ); 1935 1936 bRes &= c_rtl_tres_state 1937 ( 1938 hRtlTestResult, 1939 test_valueOf_Int64( kOctolNumsStr, kOctolNumsCount, 1940 kRadixOctol, hRtlTestResult, inArr ), 1941 "negative Int64, kRadixOctol", 1942 "valueOf( negative Int64, radix 8 )" 1943 ); 1944 1945 bRes &= c_rtl_tres_state 1946 ( 1947 hRtlTestResult, 1948 test_valueOf_Int64( kDecimalNumsStr, kDecimalNumsCount, 1949 kRadixDecimal, hRtlTestResult, inArr ), 1950 "negative Int64, kRadixDecimal", 1951 "valueOf( negative Int64, radix 10 )" 1952 ); 1953 1954 bRes &= c_rtl_tres_state 1955 ( 1956 hRtlTestResult, 1957 test_valueOf_Int64( kHexDecimalNumsStr, kHexDecimalNumsCount, 1958 kRadixHexdecimal, hRtlTestResult, inArr ), 1959 "negative Int64, kRadixHexDecimal", 1960 "valueOf( negative Int64, radix 16 )" 1961 ); 1962 1963 bRes &= c_rtl_tres_state 1964 ( 1965 hRtlTestResult, 1966 test_valueOf_Int64( kBase36NumsStr, kBase36NumsCount, 1967 kRadixBase36, hRtlTestResult, inArr), 1968 "negative Int64, kRadixBase36", 1969 "valueOf( negative Int64, radix 36 )" 1970 ); 1971 1972 return (bRes); 1973 } 1974 //------------------------------------------------------------------------ 1975 // testing the method valueOf( sal_Int64 l, sal_Int32 radix ) 1976 // where radix = -5 1977 //------------------------------------------------------------------------ 1978 sal_Bool SAL_CALL test_rtl_OUString_valueOf_Int64_WrongRadix( 1979 hTestResult hRtlTestResult ) 1980 { 1981 sal_Bool bRes = sal_False; 1982 1983 sal_Int64 intVal = 11; 1984 1985 ::rtl::OUString aStr1; 1986 ::rtl::OUString aStr2("11",2,kEncodingRTLTextUSASCII, 1987 kConvertFlagsOStringToOUString); 1988 1989 aStr1 = aStr1.valueOf( intVal, -5 ); 1990 1991 bRes = c_rtl_tres_state 1992 ( 1993 hRtlTestResult, 1994 aStr2.compareTo(aStr1) == 0, 1995 "if radix not valid then radix must be 10", 1996 "valueOf(sal_Int64, sal_Int32 radix): radix = -5" 1997 ); 1998 1999 return (bRes); 2000 } 2001 2002 //------------------------------------------------------------------------ 2003 static sal_Bool SAL_CALL test_rtl_OUString_valueOf_Int64_defaultParam( 2004 hTestResult hRtlTestResult ) 2005 { 2006 sal_Char methName[MAXBUFLENGTH]; 2007 sal_Char* pMeth = methName; 2008 2009 sal_Char* newUChar1="15"; 2010 sal_Char* newUChar2="0"; 2011 sal_Char* newUChar3="-15"; 2012 sal_Char* newUChar4= "9223372036854775807"; 2013 sal_Char* newUChar5="-9223372036854775808"; 2014 2015 typedef struct TestCase 2016 { 2017 sal_Char* comments; 2018 sal_Int64 input1; 2019 OUString* expVal; 2020 ~TestCase() {delete expVal;} 2021 }TestCase; 2022 2023 TestCase arrTestCase[]= 2024 { 2025 {"input Int64 15 and return OUString 15",15, 2026 new OUString(newUChar1,2,kEncodingRTLTextUSASCII, 2027 kConvertFlagsOStringToOUString) 2028 }, 2029 {"input Int64 0 and return OUString 0",0, 2030 new OUString(newUChar2,1,kEncodingRTLTextUSASCII, 2031 kConvertFlagsOStringToOUString) 2032 }, 2033 {"input Int64 -15 and return OUString -15",-15, 2034 new OUString(newUChar3,3,kEncodingRTLTextUSASCII, 2035 kConvertFlagsOStringToOUString) 2036 }, 2037 {"input Int64 9223372036854775807 and return 9223372036854775807", 2038 SAL_MAX_INT64 /* 9223372036854775807*/, 2039 new OUString(newUChar4,19,kEncodingRTLTextUSASCII, 2040 kConvertFlagsOStringToOUString) 2041 }, 2042 {"input Int64 -9223372036854775808 and return -9223372036854775808", 2043 SAL_MIN_INT64 /* 9223372036854775808*/, 2044 new OUString(newUChar5,20,kEncodingRTLTextUSASCII, 2045 kConvertFlagsOStringToOUString) 2046 } 2047 }; 2048 2049 sal_Bool res=sal_True; 2050 sal_uInt32 i; 2051 2052 for(i=0;i<(sizeof(arrTestCase))/(sizeof(TestCase));i++) 2053 { 2054 sal_Bool lastRes=(*(arrTestCase[i].expVal)== 2055 OUString::valueOf(arrTestCase[i].input1)); 2056 2057 c_rtl_tres_state(hRtlTestResult, 2058 lastRes, 2059 arrTestCase[i].comments, 2060 createName( pMeth, 2061 "valueOf( sal_Int64 i, sal_Int16 radix = 10 )", i ) 2062 ); 2063 2064 res &= lastRes; 2065 } 2066 2067 return(res); 2068 2069 } 2070 //------------------------------------------------------------------------ 2071 // testing the method valueOf( float f ) 2072 //------------------------------------------------------------------------ 2073 // LLA: sal_Bool SAL_CALL test_rtl_OUString_valueOf_float( 2074 // LLA: hTestResult hRtlTestResult ) 2075 // LLA: { 2076 // LLA: sal_Char methName[MAXBUFLENGTH]; 2077 // LLA: sal_Char* pMeth =methName; 2078 // LLA: 2079 // LLA: typedef struct TestCase 2080 // LLA: { 2081 // LLA: sal_Char* comments; 2082 // LLA: float input1; 2083 // LLA: OUString* expVal; 2084 // LLA: 2085 // LLA: ~TestCase() {delete expVal;} 2086 // LLA: } TestCase; 2087 // LLA: 2088 // LLA: TestCase arrTestCase[] = 2089 // LLA: { 2090 // LLA: { "3.0", 3.0, new OUString("3.0",3,kEncodingRTLTextUSASCII, 2091 // LLA: kConvertFlagsOStringToOUString) }, 2092 // LLA: { "3.5", 3.5f, new OUString("3.5",3,kEncodingRTLTextUSASCII, 2093 // LLA: kConvertFlagsOStringToOUString)}, 2094 // LLA: { "3.0625", 3.0625f, new OUString("3.0625",6,kEncodingRTLTextUSASCII, 2095 // LLA: kConvertFlagsOStringToOUString)}, 2096 // LLA: { "3.502525", 3.502525f, new OUString("3.502525",8, 2097 // LLA: kEncodingRTLTextUSASCII,kConvertFlagsOStringToOUString) }, 2098 // LLA: { "3.141592", 3.141592f, new OUString("3.141592",8, 2099 // LLA: kEncodingRTLTextUSASCII,kConvertFlagsOStringToOUString) }, 2100 // LLA: { "3.5025255", 3.5025255f, new OUString("3.5025255",9, 2101 // LLA: kEncodingRTLTextUSASCII,kConvertFlagsOStringToOUString) }, 2102 // LLA: { "3.0039062", 3.00390625f, new OUString("3.0039062",9, 2103 // LLA: kEncodingRTLTextUSASCII,kConvertFlagsOStringToOUString) } 2104 // LLA: }; 2105 // LLA: 2106 // LLA: sal_Bool res = sal_True; 2107 // LLA: sal_Int32 i; 2108 // LLA: 2109 // LLA: for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) 2110 // LLA: { 2111 // LLA: ::rtl::OUString aStr1; 2112 // LLA: aStr1 = aStr1.valueOf( arrTestCase[i].input1 ); 2113 // LLA: sal_Bool lastRes = (arrTestCase[i].expVal->compareTo(aStr1) == 0); 2114 // LLA: 2115 // LLA: c_rtl_tres_state 2116 // LLA: ( 2117 // LLA: hRtlTestResult, 2118 // LLA: lastRes, 2119 // LLA: arrTestCase[i].comments, 2120 // LLA: createName( pMeth, "valueof_float", i) 2121 // LLA: ); 2122 // LLA: 2123 // LLA: res &= lastRes; 2124 // LLA: 2125 // LLA: } 2126 // LLA: 2127 // LLA: return ( res ); 2128 // LLA: } 2129 2130 //------------------------------------------------------------------------ 2131 // testing the method valueOf( float f ) for negative value 2132 //------------------------------------------------------------------------ 2133 // LLA: sal_Bool SAL_CALL test_rtl_OUString_valueOf_Float_Negative( 2134 // LLA: hTestResult hRtlTestResult ) 2135 // LLA: { 2136 // LLA: sal_Char methName[MAXBUFLENGTH]; 2137 // LLA: sal_Char* pMeth =methName; 2138 // LLA: 2139 // LLA: typedef struct TestCase 2140 // LLA: { 2141 // LLA: sal_Char* comments; 2142 // LLA: float input1; 2143 // LLA: OUString* expVal; 2144 // LLA: 2145 // LLA: ~TestCase() {delete expVal;} 2146 // LLA: } TestCase; 2147 // LLA: 2148 // LLA: TestCase arrTestCase[] = 2149 // LLA: { 2150 // LLA: { "-3.0", -3.0, new OUString("-3.0",4,kEncodingRTLTextUSASCII, 2151 // LLA: kConvertFlagsOStringToOUString) }, 2152 // LLA: { "-3.5", -3.5f, new OUString("-3.5",4,kEncodingRTLTextUSASCII, 2153 // LLA: kConvertFlagsOStringToOUString)}, 2154 // LLA: { "-3.0625", -3.0625f, new OUString("-3.0625",7, 2155 // LLA: kEncodingRTLTextUSASCII,kConvertFlagsOStringToOUString)}, 2156 // LLA: { "-3.502525", -3.502525f, new OUString("-3.502525",9, 2157 // LLA: kEncodingRTLTextUSASCII,kConvertFlagsOStringToOUString) }, 2158 // LLA: { "-3.141592", -3.141592f, new OUString("-3.141592",9, 2159 // LLA: kEncodingRTLTextUSASCII,kConvertFlagsOStringToOUString) }, 2160 // LLA: { "-3.5025255", -3.5025255f, new OUString("-3.5025255",10, 2161 // LLA: kEncodingRTLTextUSASCII,kConvertFlagsOStringToOUString) }, 2162 // LLA: { "-3.0039062", -3.00390625f, new OUString("-3.0039062",10, 2163 // LLA: kEncodingRTLTextUSASCII,kConvertFlagsOStringToOUString) } 2164 // LLA: }; 2165 // LLA: 2166 // LLA: sal_Bool res = sal_True; 2167 // LLA: sal_Int32 i; 2168 // LLA: 2169 // LLA: for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) 2170 // LLA: { 2171 // LLA: ::rtl::OUString aStr1; 2172 // LLA: aStr1 = aStr1.valueOf( arrTestCase[i].input1 ); 2173 // LLA: sal_Bool lastRes = (arrTestCase[i].expVal->compareTo(aStr1) == 0); 2174 // LLA: 2175 // LLA: c_rtl_tres_state 2176 // LLA: ( 2177 // LLA: hRtlTestResult, 2178 // LLA: lastRes, 2179 // LLA: arrTestCase[i].comments, 2180 // LLA: createName( pMeth, "valueof_negative float", i) 2181 // LLA: ); 2182 // LLA: 2183 // LLA: res &= lastRes; 2184 // LLA: 2185 // LLA: } 2186 // LLA: 2187 // LLA: return ( res ); 2188 // LLA: } 2189 2190 //------------------------------------------------------------------------ 2191 // testing the method valueOf( double f ) 2192 //------------------------------------------------------------------------ 2193 // LLA: sal_Bool SAL_CALL test_rtl_OUString_valueOf_double( 2194 // LLA: hTestResult hRtlTestResult ) 2195 // LLA: { 2196 // LLA: sal_Char methName[MAXBUFLENGTH]; 2197 // LLA: sal_Char* pMeth =methName; 2198 // LLA: 2199 // LLA: typedef struct TestCase 2200 // LLA: { 2201 // LLA: sal_Char* comments; 2202 // LLA: double input1; 2203 // LLA: OUString* expVal; 2204 // LLA: 2205 // LLA: ~TestCase() {delete expVal;} 2206 // LLA: } TestCase; 2207 // LLA: 2208 // LLA: TestCase arrTestCase[] = 2209 // LLA: { 2210 // LLA: {"3.0", 3.0, new OUString("3.0",3,kEncodingRTLTextUSASCII, 2211 // LLA: kConvertFlagsOStringToOUString)}, 2212 // LLA: {"3.5", 3.5, new OUString("3.5",3,kEncodingRTLTextUSASCII, 2213 // LLA: kConvertFlagsOStringToOUString)}, 2214 // LLA: {"3.0625", 3.0625, new OUString("3.0625",6,kEncodingRTLTextUSASCII, 2215 // LLA: kConvertFlagsOStringToOUString)}, 2216 // LLA: {"3.1415926535", 3.1415926535, new OUString("3.1415926535",12, 2217 // LLA: kEncodingRTLTextUSASCII,kConvertFlagsOStringToOUString)}, 2218 // LLA: {"3.1415926535897931", 3.141592653589793, 2219 // LLA: new OUString("3.1415926535897931",18,kEncodingRTLTextUSASCII, 2220 // LLA: kConvertFlagsOStringToOUString)}, 2221 // LLA: {"3.1415926535897931", 3.1415926535897932, 2222 // LLA: new OUString("3.1415926535897931",18,kEncodingRTLTextUSASCII, 2223 // LLA: kConvertFlagsOStringToOUString)}, 2224 // LLA: {"3.1415926535897931", 3.14159265358979323, 2225 // LLA: new OUString("3.1415926535897931",18,kEncodingRTLTextUSASCII, 2226 // LLA: kConvertFlagsOStringToOUString)}, 2227 // LLA: {"3.1415926535897931", 3.141592653589793238462643, 2228 // LLA: new OUString("3.1415926535897931",18,kEncodingRTLTextUSASCII, 2229 // LLA: kConvertFlagsOStringToOUString)} 2230 // LLA: }; 2231 // LLA: 2232 // LLA: sal_Bool res = sal_True; 2233 // LLA: sal_Int32 i; 2234 // LLA: 2235 // LLA: for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) 2236 // LLA: { 2237 // LLA: ::rtl::OUString aStr1; 2238 // LLA: aStr1 = aStr1.valueOf( arrTestCase[i].input1 ); 2239 // LLA: sal_Bool lastRes = (arrTestCase[i].expVal->compareTo(aStr1) == 0); 2240 // LLA: 2241 // LLA: c_rtl_tres_state 2242 // LLA: ( 2243 // LLA: hRtlTestResult, 2244 // LLA: lastRes, 2245 // LLA: arrTestCase[i].comments, 2246 // LLA: createName( pMeth, "valueof_double", i) 2247 // LLA: ); 2248 // LLA: 2249 // LLA: res &= lastRes; 2250 // LLA: 2251 // LLA: } 2252 // LLA: 2253 // LLA: return ( res ); 2254 // LLA: } 2255 2256 2257 //------------------------------------------------------------------------ 2258 // testing the method valueOf( double f ) for negative value 2259 //------------------------------------------------------------------------ 2260 // LLA: sal_Bool SAL_CALL test_rtl_OUString_valueOf_Double_Negative( 2261 // LLA: hTestResult hRtlTestResult ) 2262 // LLA: { 2263 // LLA: sal_Char methName[MAXBUFLENGTH]; 2264 // LLA: sal_Char* pMeth =methName; 2265 // LLA: 2266 // LLA: typedef struct TestCase 2267 // LLA: { 2268 // LLA: sal_Char* comments; 2269 // LLA: double input1; 2270 // LLA: OUString* expVal; 2271 // LLA: 2272 // LLA: ~TestCase() {delete expVal;} 2273 // LLA: } TestCase; 2274 // LLA: 2275 // LLA: TestCase arrTestCase[] = 2276 // LLA: { 2277 // LLA: {"-3.0", -3.0, new OUString("-3.0",4,kEncodingRTLTextUSASCII, 2278 // LLA: kConvertFlagsOStringToOUString)}, 2279 // LLA: {"-3.5", -3.5, new OUString("-3.5",4,kEncodingRTLTextUSASCII, 2280 // LLA: kConvertFlagsOStringToOUString)}, 2281 // LLA: {"-3.0625", -3.0625, new OUString("-3.0625",7,kEncodingRTLTextUSASCII, 2282 // LLA: kConvertFlagsOStringToOUString)}, 2283 // LLA: {"-3.1415926535", -3.1415926535, 2284 // LLA: new OUString("-3.1415926535",13,kEncodingRTLTextUSASCII, 2285 // LLA: kConvertFlagsOStringToOUString)}, 2286 // LLA: {"-3.1415926535897931", -3.141592653589793, 2287 // LLA: new OUString("-3.1415926535897931",19,kEncodingRTLTextUSASCII, 2288 // LLA: kConvertFlagsOStringToOUString)}, 2289 // LLA: {"-3.1415926535897931", -3.1415926535897932, 2290 // LLA: new OUString("-3.1415926535897931",19,kEncodingRTLTextUSASCII, 2291 // LLA: kConvertFlagsOStringToOUString)}, 2292 // LLA: {"-3.1415926535897931", -3.14159265358979323, 2293 // LLA: new OUString("-3.1415926535897931",19,kEncodingRTLTextUSASCII, 2294 // LLA: kConvertFlagsOStringToOUString)}, 2295 // LLA: {"-3.1415926535897931", -3.141592653589793238462643, 2296 // LLA: new OUString("-3.1415926535897931",19,kEncodingRTLTextUSASCII, 2297 // LLA: kConvertFlagsOStringToOUString)} 2298 // LLA: }; 2299 // LLA: 2300 // LLA: sal_Bool res = sal_True; 2301 // LLA: sal_Int32 i; 2302 // LLA: 2303 // LLA: for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) 2304 // LLA: { 2305 // LLA: ::rtl::OUString aStr1; 2306 // LLA: aStr1 = aStr1.valueOf( arrTestCase[i].input1 ); 2307 // LLA: sal_Bool lastRes = (arrTestCase[i].expVal->compareTo(aStr1) == 0); 2308 // LLA: 2309 // LLA: c_rtl_tres_state 2310 // LLA: ( 2311 // LLA: hRtlTestResult, 2312 // LLA: lastRes, 2313 // LLA: arrTestCase[i].comments, 2314 // LLA: createName( pMeth, "valueof_nagative double", i) 2315 // LLA: ); 2316 // LLA: 2317 // LLA: res &= lastRes; 2318 // LLA: 2319 // LLA: } 2320 // LLA: 2321 // LLA: return ( res ); 2322 // LLA: } 2323 2324 //------------------------------------------------------------------------ 2325 // testing the method valueOf() 2326 //------------------------------------------------------------------------ 2327 extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_valueOf( 2328 hTestResult hRtlTestResult ) 2329 { 2330 c_rtl_tres_state_start( hRtlTestResult, "valueOf"); 2331 sal_Bool bTState = test_rtl_OUString_valueOf_Int32( hRtlTestResult ); 2332 bTState &= test_rtl_OUString_valueOf_Int32_Bounderies( hRtlTestResult ); 2333 bTState &= test_rtl_OUString_valueOf_Int32_Negative( hRtlTestResult ); 2334 bTState &= test_rtl_OUString_valueOf_Int32_WrongRadix( hRtlTestResult ); 2335 bTState &= test_rtl_OUString_valueOf_Int32_defaultParam( 2336 hRtlTestResult ); 2337 bTState &= test_rtl_OUString_valueOf_Int64( hRtlTestResult ); 2338 bTState &= test_rtl_OUString_valueOf_Int64_Bounderies( hRtlTestResult ); 2339 bTState &= test_rtl_OUString_valueOf_Int64_Negative( hRtlTestResult ); 2340 bTState &= test_rtl_OUString_valueOf_Int64_WrongRadix( hRtlTestResult ); 2341 bTState &= test_rtl_OUString_valueOf_Int64_defaultParam( 2342 hRtlTestResult ); 2343 // LLA: bTState &= test_rtl_OUString_valueOf_float( hRtlTestResult ); 2344 // LLA: bTState &= test_rtl_OUString_valueOf_Float_Negative( hRtlTestResult ); 2345 2346 // LLA: bTState &= test_rtl_OUString_valueOf_double( hRtlTestResult ); 2347 // LLA: bTState &= test_rtl_OUString_valueOf_Double_Negative( hRtlTestResult ); 2348 c_rtl_tres_state_end( hRtlTestResult, "valueOf"); 2349 // return ( bTState ); 2350 } 2351 //------------------------------------------------------------------------ 2352 // this is my testing code 2353 // testing the method createFromAscii( const sal_Char * value ) 2354 //------------------------------------------------------------------------ 2355 2356 extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_createFromAscii( 2357 hTestResult hRtlTestResult ) 2358 { 2359 c_rtl_tres_state_start( hRtlTestResult, "createFromAscii"); 2360 sal_Char methName[MAXBUFLENGTH]; 2361 sal_Char* pMeth = methName; 2362 2363 2364 typedef struct TestCase 2365 { 2366 sal_Char* comments; 2367 const sal_Char* input1; 2368 OUString* expVal; 2369 ~TestCase() {delete expVal;} 2370 2371 }TestCase; 2372 2373 TestCase arrTestCase[]= 2374 { 2375 2376 { "create OUString from sal_Char" ,kTestStr1, 2377 new OUString(kTestStr1,kTestStr1Len,kEncodingRTLTextUSASCII, 2378 kConvertFlagsOStringToOUString) 2379 }, 2380 { 2381 "create OUString from empty", "", 2382 new OUString() 2383 }, 2384 { 2385 "create OUString from empty(string arg = '\\0')","", 2386 new OUString("",0,kEncodingRTLTextUSASCII, 2387 kConvertFlagsOStringToOUString) 2388 } 2389 2390 }; 2391 2392 sal_Bool res; 2393 sal_uInt32 i; 2394 2395 for(i=0;i<(sizeof(arrTestCase))/(sizeof(TestCase));i++) 2396 { 2397 sal_Bool lastRes=(*(arrTestCase[i].expVal)== 2398 OUString::createFromAscii(arrTestCase[i].input1)); 2399 2400 2401 { 2402 c_rtl_tres_state(hRtlTestResult, 2403 lastRes, 2404 arrTestCase[i].comments, 2405 createName( pMeth, "createFromAscii", i ) 2406 ); 2407 } 2408 2409 res&=lastRes; 2410 2411 } 2412 2413 c_rtl_tres_state_end( hRtlTestResult, "createFromAscii"); 2414 // return(res); 2415 } 2416 //------------------------------------------------------------------------ 2417 // testing the method index( ) 2418 //------------------------------------------------------------------------ 2419 template <class T> 2420 sal_Bool test_index( const T* input1, int num,const sal_Int32* input2, 2421 const sal_Int32* expVal,int base,rtlTestResult hRtlTestResult) 2422 { 2423 sal_Bool res=sal_True; 2424 sal_Char methName[MAXBUFLENGTH]; 2425 sal_Char *meth = '\0'; 2426 sal_Char* pMeth=methName; 2427 sal_Int32 i; 2428 sal_Bool lastRes=sal_False; 2429 2430 for(i=0;i<num;i++) 2431 { 2432 OUString str(aUStr2); 2433 2434 if(base==0) 2435 { 2436 lastRes=(str.indexOf(input1[i])==expVal[i]); 2437 meth="indexOf_001"; 2438 } 2439 if(base==1) 2440 { 2441 lastRes=(str.indexOf(input1[i],input2[i])==expVal[i]); 2442 meth="indexOf_002"; 2443 } 2444 // LLA: if(base==2) 2445 // LLA: { 2446 // LLA: lastRes=(str.lastIndexOf(input1[i])==expVal[i]); 2447 // LLA: meth="lastIndexOf_001(sal_Unicode)"; 2448 // LLA: } 2449 // LLA: if(base==3) 2450 // LLA: { 2451 // LLA: /* 2452 // LLA: OUString s4(&input1[i]); 2453 // LLA: rtl::OString sStr; 2454 // LLA: sStr <<= str; 2455 // LLA: t_print("str = %s\n", sStr.getStr()); 2456 // LLA: rtl::OString sInput1; 2457 // LLA: sInput1 <<= s4; // rtl::OUString((sal_Unicode*)input1[i]); 2458 // LLA: t_print("%d = lastIndexOf(\"%s\", %d) =? %d\n", str.lastIndexOf(input1[i], input2[i]), sInput1.getStr(), input2[i], expVal[i]); 2459 // LLA: */ 2460 // LLA: lastRes=(str.lastIndexOf(input1[i],input2[i])==expVal[i]); 2461 // LLA: meth="lastIndexOf_002(sal_Unicode , sal_Int32 )"; 2462 // LLA: } 2463 2464 c_rtl_tres_state 2465 ( 2466 hRtlTestResult, 2467 lastRes, 2468 "index", 2469 createName( pMeth,meth, i ) 2470 ); 2471 2472 res &= lastRes; 2473 } 2474 2475 return( res ); 2476 } 2477 template <class T> 2478 sal_Bool test_indexStr( const T** input1, int num,const sal_Int32* input2, 2479 const sal_Int32* expVal,int base,rtlTestResult hRtlTestResult) 2480 { 2481 sal_Bool res=sal_True; 2482 sal_Char methName[MAXBUFLENGTH]; 2483 sal_Char *meth = '\0'; 2484 sal_Char* pMeth=methName; 2485 sal_Int32 i; 2486 sal_Bool lastRes=sal_False; 2487 2488 for(i=0;i<num;i++) 2489 { 2490 OUString str(aUStr2); 2491 2492 2493 if(base==0) 2494 { 2495 OUString s1(input1[i]); 2496 lastRes=(str.indexOf(s1)==expVal[i]); 2497 meth="indexOf_003"; 2498 } 2499 if(base==1) 2500 { 2501 OUString s2(input1[i]); 2502 lastRes=(str.indexOf(s2,input2[i])==expVal[i]); 2503 meth="indexOf_004"; 2504 } 2505 // LLA: if(base==2) 2506 // LLA: { 2507 // LLA: OUString s3(input1[i]); 2508 // LLA: lastRes=(str.lastIndexOf(s3)==expVal[i]); 2509 // LLA: meth="lastIndexOf_003(const OUString)"; 2510 // LLA: } 2511 // LLA: if(base==3) 2512 // LLA: { 2513 // LLA: OUString s4(input1[i]); 2514 // LLA: 2515 // LLA: rtl::OString sStr; 2516 // LLA: sStr <<= str; 2517 // LLA: t_print("str = \"%s\"\n", sStr.getStr()); 2518 // LLA: rtl::OString sInput1; 2519 // LLA: sInput1 <<= s4; // rtl::OUString((sal_Unicode*)input1[i]); 2520 // LLA: t_print("%d = lastIndexOf(\"%s\", %d) =? %d\n", str.lastIndexOf(input1[i], input2[i]), sInput1.getStr(), input2[i], expVal[i]); 2521 // LLA: 2522 // LLA: lastRes=(str.lastIndexOf(s4,input2[i])==expVal[i]); 2523 // LLA: meth="lastIndexOf_004(const OUString,sal_Int32)"; 2524 // LLA: } 2525 2526 c_rtl_tres_state 2527 ( 2528 hRtlTestResult, 2529 lastRes, 2530 "index", 2531 createName( pMeth,meth, i ) 2532 ); 2533 2534 res &= lastRes; 2535 } 2536 2537 return( res ); 2538 } 2539 //------------------------------------------------------------------------ 2540 // testing the method indexOf( ) 2541 //------------------------------------------------------------------------ 2542 sal_Bool SAL_CALL test_rtl_OUString_indexOf_001( 2543 hTestResult hRtlTestResult ) 2544 { 2545 sal_Bool bRes=sal_False; 2546 2547 bRes=c_rtl_tres_state 2548 ( 2549 hRtlTestResult, 2550 test_index<sal_Unicode>((const sal_Unicode*)input1Default, 2551 nDefaultCount,input2Default, 2552 expValDefault,0,hRtlTestResult), 2553 "index", 2554 "indexDefault(sal_Unicode ch, sal_Int32 fromIndex = 0)" 2555 ); 2556 2557 return ( bRes ); 2558 } 2559 //------------------------------------------------------------------------ 2560 // testing the method indexOf( ) 2561 //------------------------------------------------------------------------ 2562 sal_Bool SAL_CALL test_rtl_OUString_indexOf_002( 2563 hTestResult hRtlTestResult ) 2564 { 2565 sal_Bool bRes=sal_False; 2566 2567 bRes=c_rtl_tres_state 2568 ( 2569 hRtlTestResult, 2570 test_index<sal_Unicode>((const sal_Unicode*)input1Normal, 2571 nNormalCount,input2Normal, 2572 expValNormal,1,hRtlTestResult), 2573 "index", 2574 "indexNormal(sal_Unicode ch, sal_Int32 fromIndex)" 2575 ); 2576 2577 return ( bRes ); 2578 } 2579 //------------------------------------------------------------------------ 2580 // testing the method indexOf( OUString ch, sal_Int32 fromIndex = 0 ) 2581 //------------------------------------------------------------------------ 2582 sal_Bool SAL_CALL test_rtl_OUString_indexOf_003( 2583 hTestResult hRtlTestResult ) 2584 { 2585 sal_Bool bRes=sal_False; 2586 2587 bRes=c_rtl_tres_state 2588 ( 2589 hRtlTestResult, 2590 test_indexStr<sal_Unicode>((const sal_Unicode**)input1StrDefault, 2591 nStrDefaultCount,input2StrDefault, 2592 expValStrDefault,0,hRtlTestResult), 2593 "index", 2594 "indexDefault(OUString ch, sal_Int32 fromIndex = 0)" 2595 ); 2596 2597 return ( bRes ); 2598 } 2599 //------------------------------------------------------------------------ 2600 // testing the method indexOf( OUString ch, sal_Int32 fromIndex ) 2601 //------------------------------------------------------------------------ 2602 sal_Bool SAL_CALL test_rtl_OUString_indexOf_004( 2603 hTestResult hRtlTestResult ) 2604 { 2605 sal_Bool bRes=sal_False; 2606 2607 bRes=c_rtl_tres_state 2608 ( 2609 hRtlTestResult, 2610 test_indexStr<sal_Unicode>((const sal_Unicode**)input1StrNormal, 2611 nStrNormalCount,input2StrNormal, 2612 expValStrNormal,1,hRtlTestResult), 2613 "indexOf", 2614 "indexOf(OUString ch, sal_Int32 fromIndex)" 2615 ); 2616 2617 return ( bRes ); 2618 } 2619 // LLA: //------------------------------------------------------------------------ 2620 // LLA: // testing the method lastIndexOf( sal_Unicode ch ) 2621 // LLA: //------------------------------------------------------------------------ 2622 // LLA: sal_Bool SAL_CALL test_rtl_OUString_lastIndexOf_001( 2623 // LLA: hTestResult hRtlTestResult ) 2624 // LLA: { 2625 // LLA: sal_Bool bRes=sal_False; 2626 // LLA: 2627 // LLA: bRes=c_rtl_tres_state 2628 // LLA: ( 2629 // LLA: hRtlTestResult, 2630 // LLA: test_index<sal_Unicode>((const sal_Unicode*)input1lastDefault, 2631 // LLA: nlastDefaultCount,input2lastDefault, 2632 // LLA: expVallastDefault,2,hRtlTestResult), 2633 // LLA: "lastIndex", 2634 // LLA: "lastIndexDefault(sal_Unicode ch)" 2635 // LLA: ); 2636 // LLA: 2637 // LLA: return ( bRes ); 2638 // LLA: } 2639 // LLA: //------------------------------------------------------------------------ 2640 // LLA: // testing the method lastIndexOf( sal_Unicode ch, sal_Int32 fromIndex ) 2641 // LLA: //------------------------------------------------------------------------ 2642 // LLA: sal_Bool SAL_CALL test_rtl_OUString_lastIndexOf_002( 2643 // LLA: hTestResult hRtlTestResult ) 2644 // LLA: { 2645 // LLA: sal_Bool bRes=sal_False; 2646 // LLA: 2647 // LLA: bRes=c_rtl_tres_state 2648 // LLA: ( 2649 // LLA: hRtlTestResult, 2650 // LLA: test_index<sal_Unicode>((const sal_Unicode*)input1lastNormal, 2651 // LLA: nlastNormalCount,input2lastNormal, 2652 // LLA: expVallastNormal,3,hRtlTestResult), 2653 // LLA: "lastIndex", 2654 // LLA: "lastIndexNormal(sal_Unicode ch, sal_Int32 fromIndex)" 2655 // LLA: ); 2656 // LLA: 2657 // LLA: return ( bRes ); 2658 // LLA: } 2659 // LLA: //------------------------------------------------------------------------ 2660 // LLA: // testing the method lastIndexOf( OUString ch ) 2661 // LLA: //------------------------------------------------------------------------ 2662 // LLA: sal_Bool SAL_CALL test_rtl_OUString_lastIndexOf_003( 2663 // LLA: hTestResult hRtlTestResult ) 2664 // LLA: { 2665 // LLA: sal_Bool bRes=sal_False; 2666 // LLA: 2667 // LLA: bRes=c_rtl_tres_state 2668 // LLA: ( 2669 // LLA: hRtlTestResult, 2670 // LLA: test_indexStr<sal_Unicode>((const sal_Unicode**)input1StrLastDefault, 2671 // LLA: nStrLastDefaultCount,input2StrLastDefault, 2672 // LLA: expValStrLastDefault,2,hRtlTestResult), 2673 // LLA: "lastIndexOf", 2674 // LLA: "lastIndexOf(OUString ch)" 2675 // LLA: ); 2676 // LLA: 2677 // LLA: return ( bRes ); 2678 // LLA: } 2679 // LLA: //------------------------------------------------------------------------ 2680 // LLA: // testing the method lastIndexOf( OUString ch, sal_Int32 fromIndex ) 2681 // LLA: //------------------------------------------------------------------------ 2682 // LLA: sal_Bool SAL_CALL test_rtl_OUString_lastIndexOf_004( 2683 // LLA: hTestResult hRtlTestResult ) 2684 // LLA: { 2685 // LLA: sal_Bool bRes=sal_False; 2686 // LLA: 2687 // LLA: for (int i=0;i<nStrLastNormalCount;i++) 2688 // LLA: { 2689 // LLA: rtl::OUString aStr = rtl::OUString(input1StrLastNormal[i]); 2690 // LLA: volatile int dummy = 0; 2691 // LLA: } 2692 // LLA: 2693 // LLA: bRes=c_rtl_tres_state 2694 // LLA: ( 2695 // LLA: hRtlTestResult, 2696 // LLA: test_indexStr<sal_Unicode>((const sal_Unicode**)input1StrLastNormal, 2697 // LLA: nStrLastNormalCount,input2StrLastNormal, 2698 // LLA: expValStrLastNormal,3,hRtlTestResult), 2699 // LLA: "lastIndexOf", 2700 // LLA: "lastIndexOf(OUString ch, sal_Int32 fromIndex)" 2701 // LLA: ); 2702 // LLA: 2703 // LLA: return ( bRes ); 2704 // LLA: } 2705 //------------------------------------------------------------------------ 2706 extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_indexOf( 2707 hTestResult hRtlTestResult ) 2708 { 2709 c_rtl_tres_state_start( hRtlTestResult, "indexOf"); 2710 sal_Bool res = test_rtl_OUString_indexOf_001(hRtlTestResult); 2711 res &= test_rtl_OUString_indexOf_002(hRtlTestResult); 2712 res &= test_rtl_OUString_indexOf_003(hRtlTestResult); 2713 res &= test_rtl_OUString_indexOf_004(hRtlTestResult); 2714 c_rtl_tres_state_end( hRtlTestResult, "indexOf"); 2715 // return ( res ); 2716 } 2717 //------------------------------------------------------------------------ 2718 // LLA: extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_lastIndexOf( 2719 // LLA: hTestResult hRtlTestResult ) 2720 // LLA: { 2721 // LLA: c_rtl_tres_state_start( hRtlTestResult, "lastIndexOf"); 2722 // LLA: sal_Bool res = test_rtl_OUString_lastIndexOf_001(hRtlTestResult); 2723 // LLA: res &= test_rtl_OUString_lastIndexOf_002(hRtlTestResult); 2724 // LLA: res &= test_rtl_OUString_lastIndexOf_003(hRtlTestResult); 2725 // LLA: res &= test_rtl_OUString_lastIndexOf_004(hRtlTestResult); 2726 // LLA: c_rtl_tres_state_end( hRtlTestResult, "lastIndexOf"); 2727 // LLA: // return ( res ); 2728 // LLA: } 2729 //------------------------------------------------------------------------ 2730 // testing the method concat( const OString & aStr ) 2731 //------------------------------------------------------------------------ 2732 extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_concat( 2733 hTestResult hRtlTestResult ) 2734 { 2735 c_rtl_tres_state_start( hRtlTestResult, "concat"); 2736 sal_Char methName[MAXBUFLENGTH]; 2737 sal_Char* pMeth =methName; 2738 2739 typedef struct TestCase 2740 { 2741 sal_Char* comments; 2742 OUString* expVal; 2743 OUString* input1; 2744 OUString* input2; 2745 ~TestCase() { delete input1;delete input2; delete expVal;} 2746 } TestCase; 2747 2748 TestCase arrTestCase[] = 2749 { 2750 {"concatenates two ustrings",new OUString(aUStr1), 2751 new OUString(aUStr7), new OUString(aUStr8)}, 2752 {"concatenates empty ustring",new OUString(aUStr1), 2753 new OUString(aUStr1), new OUString("",0, 2754 kEncodingRTLTextUSASCII,kConvertFlagsOStringToOUString)}, 2755 {"concatenates to empty ustring",new OUString(aUStr1),new OUString("", 2756 0,kEncodingRTLTextUSASCII,kConvertFlagsOStringToOUString), 2757 new OUString(aUStr1)}, 2758 {"concatenates two empty ustrings",new OUString("",0, 2759 kEncodingRTLTextUSASCII,kConvertFlagsOStringToOUString), 2760 new OUString("",0, 2761 kEncodingRTLTextUSASCII,kConvertFlagsOStringToOUString), 2762 new OUString("",0, 2763 kEncodingRTLTextUSASCII,kConvertFlagsOStringToOUString)}, 2764 {"concatenates ustring constructed by default constructor", 2765 new OUString(aUStr1),new OUString(aUStr1), new OUString()}, 2766 {"concatenates to ustring constructed by default constructor", 2767 new OUString(aUStr1),new OUString(), new OUString(aUStr1)}, 2768 {"concatenates two ustrings constructed by default constructor", 2769 new OUString(),new OUString(), new OUString()} 2770 }; 2771 2772 sal_Bool res = sal_True; 2773 sal_uInt32 i; 2774 for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) 2775 { 2776 OUString str = arrTestCase[i].input1->concat(*arrTestCase[i].input2); 2777 sal_Bool lastRes = (str == *arrTestCase[i].expVal); 2778 2779 c_rtl_tres_state 2780 ( 2781 hRtlTestResult, 2782 lastRes, 2783 arrTestCase[i].comments, 2784 createName( pMeth, "concat", i) 2785 ); 2786 2787 res &= lastRes; 2788 2789 } 2790 c_rtl_tres_state_end( hRtlTestResult, "concat"); 2791 // return ( res ); 2792 } 2793 //------------------------------------------------------------------------ 2794 // testing the method replaceAt( sal_Int32 index, sal_Int32 count, 2795 // const OUString& newStr ) 2796 //------------------------------------------------------------------------ 2797 extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_replaceAt( 2798 rtlTestResult hRtlTestResult) 2799 { 2800 c_rtl_tres_state_start( hRtlTestResult, "replaceAt"); 2801 sal_Char methName[MAXBUFLENGTH]; 2802 sal_Char* pMeth = methName; 2803 2804 typedef struct TestCase 2805 { 2806 sal_Char* comments; 2807 OUString* expVal; 2808 OUString* input; 2809 OUString* newStr; 2810 sal_Int32 index; 2811 sal_Int32 count; 2812 2813 ~TestCase() { delete input; delete expVal; delete newStr;} 2814 } TestCase; 2815 2816 TestCase arrTestCase[]= 2817 { 2818 2819 { "string differs", new OUString(aUStr2), new OUString(aUStr22), 2820 new OUString(aUStr2), 0, kTestStr22Len }, 2821 2822 { "larger index", new OUString(aUStr1), new OUString(aUStr7), 2823 new OUString(aUStr8), 64, kTestStr8Len }, 2824 2825 { "larger count", new OUString(aUStr2), new OUString(aUStr22), 2826 new OUString(aUStr2),0, 64 }, 2827 2828 { "navigate index", new OUString(aUStr2), new OUString(aUStr22), 2829 new OUString(aUStr2), -64, 64 }, 2830 2831 { "null ustring", 2832 new OUString("",0, 2833 kEncodingRTLTextUSASCII,kConvertFlagsOStringToOUString), 2834 new OUString(aUStr14), 2835 new OUString("",0, 2836 kEncodingRTLTextUSASCII,kConvertFlagsOStringToOUString), 2837 0, kTestStr14Len } 2838 }; 2839 2840 sal_Bool res = sal_True; 2841 sal_uInt32 i; 2842 2843 for (i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) 2844 { 2845 ::rtl::OUString aStr1; 2846 aStr1 = arrTestCase[i].input->replaceAt( arrTestCase[i].index, 2847 arrTestCase[i].count, *arrTestCase[i].newStr ); 2848 2849 sal_Bool lastRes = ( arrTestCase[i].expVal->compareTo(aStr1) == 0 ); 2850 2851 c_rtl_tres_state 2852 ( 2853 hRtlTestResult, 2854 lastRes, 2855 arrTestCase[i].comments, 2856 createName( pMeth, "replaceAt", i ) 2857 2858 ); 2859 res &= lastRes; 2860 } 2861 2862 c_rtl_tres_state_end( hRtlTestResult, "replaceAt"); 2863 // return ( res ); 2864 } 2865 //------------------------------------------------------------------------ 2866 // this is my testing code 2867 // testing the method replace( sal_Unicode oldChar, sal_Unicode newChar ) 2868 //------------------------------------------------------------------------ 2869 extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_replace( 2870 hTestResult hRtlTestResult) 2871 { 2872 c_rtl_tres_state_start( hRtlTestResult, "replace"); 2873 sal_Char methName[MAXBUFLENGTH]; 2874 sal_Char* pMeth = methName; 2875 2876 typedef struct TestCase 2877 { 2878 sal_Char* comments; 2879 OUString* expVal; 2880 OUString* input; 2881 sal_Unicode oldChar; 2882 sal_Unicode newChar; 2883 2884 ~TestCase() { delete input; delete expVal;} 2885 } TestCase; 2886 2887 TestCase arrTestCase[]= 2888 { 2889 {"ustring differs", new OUString(aUStr18), new OUString(aUStr4),83,115}, 2890 {"ustring differs", new OUString(aUStr19), new OUString(aUStr17),32,45}, 2891 {"ustring must be empty", new OUString("",0, 2892 kEncodingRTLTextUSASCII,kConvertFlagsOStringToOUString), 2893 new OUString("",0, 2894 kEncodingRTLTextUSASCII,kConvertFlagsOStringToOUString),83,23}, 2895 {"ustring must be empty", new OUString(), 2896 new OUString("",0, 2897 kEncodingRTLTextUSASCII,kConvertFlagsOStringToOUString),83,23}, 2898 {"same ustring, no replace ", new OUString(aUStr22), 2899 new OUString(aUStr22),42,56} 2900 }; 2901 2902 2903 sal_Bool res = sal_True; 2904 sal_uInt32 i; 2905 2906 for (i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) 2907 { 2908 ::rtl::OUString aStr1; 2909 aStr1= arrTestCase[i].input->replace(arrTestCase[i].oldChar,arrTestCase[i].newChar); 2910 res &= c_rtl_tres_state 2911 ( 2912 hRtlTestResult, 2913 (arrTestCase[i].expVal->compareTo(aStr1) == 0), 2914 arrTestCase[i].comments, 2915 createName( pMeth, "replace", i ) 2916 2917 ); 2918 } 2919 c_rtl_tres_state_end( hRtlTestResult, "replace"); 2920 // return ( res ); 2921 } 2922 //------------------------------------------------------------------------ 2923 // testing the method toAsciiLowerCase() 2924 //----------------------------------------------------------------------- 2925 extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_toAsciiLowerCase( 2926 hTestResult hRtlTestResult ) 2927 { 2928 c_rtl_tres_state_start( hRtlTestResult, "toAsciiLowerCase"); 2929 sal_Char methName[MAXBUFLENGTH]; 2930 sal_Char* pMeth =methName; 2931 2932 typedef struct TestCase 2933 { 2934 sal_Char* comments; 2935 OUString* expVal; 2936 OUString* input1; 2937 ~TestCase() { delete input1; delete expVal;} 2938 } TestCase; 2939 2940 TestCase arrTestCase[] = 2941 { 2942 2943 {"only uppercase",new OUString(aUStr5),new OUString(aUStr4)}, 2944 {"different cases",new OUString(aUStr5),new OUString(aUStr1)}, 2945 {"different cases",new OUString(aUStr5),new OUString(aUStr3)}, 2946 {"only lowercase",new OUString(aUStr5),new OUString(aUStr5)}, 2947 {"empty ustring",new OUString("",0, 2948 kEncodingRTLTextUSASCII,kConvertFlagsOStringToOUString), 2949 new OUString("",0, 2950 kEncodingRTLTextUSASCII,kConvertFlagsOStringToOUString)}, 2951 {"ustring constructed by default constructor",new OUString(), 2952 new OUString()}, 2953 {"have special Unicode",new OUString("\23\12\34sun\13\45",6, 2954 kEncodingRTLTextUSASCII,kConvertFlagsOStringToOUString), 2955 new OUString("\23\12\34sun\13\45",6, 2956 kEncodingRTLTextUSASCII,kConvertFlagsOStringToOUString)} 2957 }; 2958 2959 sal_Bool res = sal_True; 2960 sal_uInt32 i; 2961 sal_Bool lastRes=sal_False; 2962 2963 for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) 2964 { 2965 OUString str = arrTestCase[i].input1->toAsciiLowerCase(); 2966 if(i<=5) 2967 { 2968 lastRes = (str ==* arrTestCase[i].expVal); 2969 2970 c_rtl_tres_state 2971 ( 2972 hRtlTestResult, 2973 lastRes, 2974 arrTestCase[i].comments, 2975 createName( pMeth, "toAsciiLowerCase", i) 2976 ); 2977 } 2978 else 2979 { 2980 c_rtl_tres_state 2981 ( 2982 hRtlTestResult, 2983 sal_True, 2984 arrTestCase[i].comments, 2985 createName( pMeth, "toAsciiLowerCase", i) 2986 ); 2987 } 2988 res &= lastRes; 2989 } 2990 c_rtl_tres_state_end( hRtlTestResult, "toAsciiLowerCase"); 2991 // return ( res ); 2992 } 2993 //------------------------------------------------------------------------ 2994 // testing the method toAsciiUpperCase() 2995 //------------------------------------------------------------------------ 2996 extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_toAsciiUpperCase( 2997 hTestResult hRtlTestResult ) 2998 { 2999 c_rtl_tres_state_start( hRtlTestResult, "toAsciiUpperCase"); 3000 sal_Char methName[MAXBUFLENGTH]; 3001 sal_Char* pMeth =methName; 3002 3003 typedef struct TestCase 3004 { 3005 sal_Char* comments; 3006 OUString* expVal; 3007 OUString* input1; 3008 ~TestCase() { delete input1; delete expVal;} 3009 } TestCase; 3010 3011 TestCase arrTestCase[] = 3012 { 3013 {"only lowercase",new OUString(aUStr4),new OUString(aUStr5)}, 3014 {"mixed cases",new OUString(aUStr4),new OUString(aUStr3)}, 3015 {"mixed cases",new OUString(aUStr4),new OUString(aUStr1)}, 3016 {"only uppercase",new OUString(aUStr4),new OUString(aUStr4)}, 3017 {"empty ustring",new OUString("",0, 3018 kEncodingRTLTextUSASCII,kConvertFlagsOStringToOUString), 3019 new OUString("",0, 3020 kEncodingRTLTextUSASCII,kConvertFlagsOStringToOUString)}, 3021 {"ustring constructed by default constructor",new OUString(), 3022 new OUString()}, 3023 {"have special Unicode",new OUString("\23\12\34SUN\13\45",6, 3024 kEncodingRTLTextUSASCII,kConvertFlagsOStringToOUString), 3025 new OUString("\23\12\34sun\13\45",6, 3026 kEncodingRTLTextUSASCII,kConvertFlagsOStringToOUString)} 3027 }; 3028 3029 sal_Bool res = sal_True; 3030 sal_uInt32 i; 3031 sal_Bool lastRes=sal_False; 3032 3033 for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) 3034 { 3035 OUString str = arrTestCase[i].input1->toAsciiUpperCase(); 3036 if(i<=5) 3037 { 3038 lastRes = (str == *arrTestCase[i].expVal); 3039 3040 c_rtl_tres_state 3041 ( 3042 hRtlTestResult, 3043 lastRes, 3044 arrTestCase[i].comments, 3045 createName( pMeth, "toAsciiUpperCase", i) 3046 ); 3047 } 3048 else 3049 { 3050 c_rtl_tres_state 3051 ( 3052 hRtlTestResult, 3053 sal_True, 3054 arrTestCase[i].comments, 3055 createName( pMeth, "toAsciiUpperCase", i) 3056 ); 3057 } 3058 3059 res &= lastRes; 3060 } 3061 c_rtl_tres_state_end( hRtlTestResult, "toAsciiUpperCase"); 3062 // return ( res ); 3063 } 3064 3065 //------------------------------------------------------------------------ 3066 // testing the method trim() 3067 //------------------------------------------------------------------------ 3068 extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_trim( 3069 hTestResult hRtlTestResult ) 3070 { 3071 c_rtl_tres_state_start( hRtlTestResult, "trim"); 3072 sal_Char methName[MAXBUFLENGTH]; 3073 sal_Char* pMeth =methName; 3074 3075 typedef struct TestCase 3076 { 3077 sal_Char* comments; 3078 OUString* expVal; 3079 OUString* input1; 3080 ~TestCase() { delete input1; delete expVal;} 3081 } TestCase; 3082 3083 TestCase arrTestCase[] = 3084 { 3085 {"removes space from the front",new OUString(aUStr1), 3086 new OUString(aUStr10)}, 3087 {"removes space from the end",new OUString(aUStr1), 3088 new OUString(aUStr11)}, 3089 {"removes space from the front and end",new OUString(aUStr1), 3090 new OUString(aUStr12)}, 3091 {"removes several spaces from the end",new OUString(aUStr1), 3092 new OUString(aUStr13)}, 3093 {"removes several spaces from the front",new OUString(aUStr1), 3094 new OUString(aUStr14)}, 3095 {"removes several spaces from the front and one from the end", 3096 new OUString(aUStr1), 3097 new OUString(aUStr15)}, 3098 {"removes one space from the front and several from the end", 3099 new OUString(aUStr1), 3100 new OUString(aUStr16)}, 3101 {"removes several spaces from the front and end", 3102 new OUString(aUStr1), 3103 new OUString(aUStr17)}, 3104 {"removes characters that have codes <= 32",new OUString(aUStr30), 3105 new OUString("\1\3\5\7\11\13\15\17sun\21\23\25\27\31\33\50", 3106 18,kEncodingRTLTextUSASCII, 3107 kConvertFlagsOStringToOUString)}, 3108 {"removes characters that have codes <= 32",new OUString(aUStr28), 3109 new OUString("\50\3\5\7\11\13\15\17sun\21\23\25\27\31\33\1", 3110 18,kEncodingRTLTextUSASCII, 3111 kConvertFlagsOStringToOUString)}, 3112 {"removes characters that have codes <= 32",new OUString(aUStr29), 3113 new OUString("\50\3\5\7\11\13\15\17sun\21\23\25\27\31\33\50", 3114 18,kEncodingRTLTextUSASCII, 3115 kConvertFlagsOStringToOUString)}, 3116 {"removes characters that have codes <= 32",new OUString(aUStr20), 3117 new OUString("\1\3\5\7\11\13\15\17sun\21\23\25\27\31\23\20", 3118 18,kEncodingRTLTextUSASCII, 3119 kConvertFlagsOStringToOUString)}, 3120 {"no spaces",new OUString(aUStr8), 3121 new OUString(aUStr8)} 3122 }; 3123 3124 sal_Bool res = sal_True; 3125 sal_uInt32 i; 3126 3127 for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) 3128 { 3129 OUString strRes = arrTestCase[i].input1->trim(); 3130 sal_Bool lastRes = (strRes == *arrTestCase[i].expVal); 3131 3132 c_rtl_tres_state 3133 ( 3134 hRtlTestResult, 3135 lastRes, 3136 arrTestCase[i].comments, 3137 createName( pMeth, "trim", i) 3138 ); 3139 3140 res &= lastRes; 3141 3142 } 3143 c_rtl_tres_state_end( hRtlTestResult, "trim"); 3144 // return ( res ); 3145 } 3146 //------------------------------------------------------------------------ 3147 // testing the method toData() 3148 //------------------------------------------------------------------------ 3149 3150 template <class T> 3151 sal_Bool test_toData( const char** input, int num, sal_Int16 radix, 3152 const T* expVal,int base, 3153 const T* _fPrecision, 3154 rtlTestResult hRtlTestResult) 3155 { 3156 (void)_fPrecision; 3157 sal_Bool res=sal_True; 3158 sal_Char methName[MAXBUFLENGTH]; 3159 sal_Char *meth = '\0'; 3160 sal_Char* pMeth=methName; 3161 sal_Int32 i; 3162 // static sal_Unicode aUchar[60]={0x00}; 3163 T intRes; 3164 sal_Bool lastRes=sal_False; 3165 3166 for(i=0;i<num;i++) 3167 { 3168 OSL_ENSURE( i < 60, "ERROR: leave aUchar bound"); 3169 3170 // LLA: stored for the posterity 3171 // AStringToUStringCopy(aUchar,input[i]); 3172 // OUString str(aUchar); 3173 3174 OUString str; 3175 str = OUString::createFromAscii(input[i]); 3176 3177 3178 if(base==0) 3179 { 3180 intRes=static_cast<T>(str.toInt32()); 3181 lastRes=(intRes==expVal[i]); 3182 meth="toInt32default"; 3183 } 3184 if(base==1) 3185 { 3186 intRes=static_cast<T>(str.toInt32(radix)); 3187 lastRes=(intRes==expVal[i]); 3188 meth="toInt32normal"; 3189 } 3190 if(base==2) 3191 { 3192 intRes=static_cast<T>(str.toInt64()); 3193 lastRes=(intRes==expVal[i]); 3194 meth="toInt64default"; 3195 } 3196 if(base==3) 3197 { 3198 intRes=static_cast<T>(str.toInt64(radix)); 3199 lastRes=(intRes==expVal[i]); 3200 meth="toInt64normal"; 3201 } 3202 // LLA: does no longer exist, moved to rtl/oustring 3203 // LLA: if(base==4) 3204 // LLA: { 3205 // LLA: intRes=str.toDouble(); 3206 // LLA: lastRes=(fabs(intRes-expVal[i])<=1e-35); 3207 // LLA: meth="toDouble"; 3208 // LLA: } 3209 3210 // LLA: dt:20040802 create compile problems within wntmsci10 3211 // if(base==5) 3212 // { 3213 // intRes=str.toFloat(); 3214 // T nPrec = _fPrecision[i]; 3215 // lastRes=(fabs((T)(intRes-expVal[i])) <= nPrec /* 1e-35 */ ); 3216 // meth="toFloat"; 3217 // } 3218 if(base==6) 3219 { 3220 intRes=str.toChar(); 3221 lastRes=(intRes==expVal[i]); 3222 meth="toChar"; 3223 } 3224 3225 char buf[MAXBUFLENGTH]; 3226 buf[0] = '\''; 3227 cpynstr( buf + 1, input[i], MAXBUFLENGTH ); 3228 int length = AStringLen( input[i] ); 3229 buf[length + 1] = '\''; 3230 buf[length + 2] = 0; 3231 3232 c_rtl_tres_state 3233 ( 3234 hRtlTestResult, 3235 lastRes, 3236 buf, 3237 createName( pMeth,meth, i ) 3238 ); 3239 3240 res &= lastRes; 3241 } 3242 3243 return( res ); 3244 } 3245 //------------------------------------------------------------------------ 3246 // testing the method toDouble() 3247 //------------------------------------------------------------------------ 3248 3249 // LLA: extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_toDouble( 3250 // LLA: hTestResult hRtlTestResult ) 3251 // LLA: { 3252 // LLA: c_rtl_tres_state_start( hRtlTestResult, "toDouble"); 3253 // LLA: sal_Bool bRes=sal_False; 3254 // LLA: 3255 // LLA: bRes=c_rtl_tres_state 3256 // LLA: ( 3257 // LLA: hRtlTestResult, 3258 // LLA: test_toData<double>((const char**)inputDouble,nDoubleCount,10, 3259 // LLA: expValDouble,4,hRtlTestResult), 3260 // LLA: "toDouble", 3261 // LLA: "toDouble()" 3262 // LLA: ); 3263 // LLA: c_rtl_tres_state_end( hRtlTestResult, "toDouble"); 3264 // LLA: // return ( bRes ); 3265 // LLA: } 3266 3267 //------------------------------------------------------------------------ 3268 // testing the method toFloat() 3269 //------------------------------------------------------------------------ 3270 // LLA: dt:20040802 the test_toData() has compile problems. 3271 // LLA: extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_toFloat( 3272 // LLA: hTestResult hRtlTestResult ) 3273 // LLA: { 3274 // LLA: c_rtl_tres_state_start( hRtlTestResult, "toFloat"); 3275 // LLA: sal_Bool bRes=sal_False; 3276 // LLA: 3277 // LLA: bRes=c_rtl_tres_state 3278 // LLA: ( 3279 // LLA: hRtlTestResult, 3280 // LLA: test_toData<float>((const char**)inputFloat, 3281 // LLA: nFloatCount, 3282 // LLA: 10, /* radix */ 3283 // LLA: expValFloat, 3284 // LLA: 5, /* float */ 3285 // LLA: fPrecision, 3286 // LLA: hRtlTestResult), 3287 // LLA: "toFloat", 3288 // LLA: "toFloat()" 3289 // LLA: ); 3290 // LLA: 3291 // LLA: c_rtl_tres_state_end( hRtlTestResult, "toFloat"); 3292 // LLA: // return ( bRes ); 3293 // LLA: 3294 // LLA: } 3295 //------------------------------------------------------------------------ 3296 // testing the method toChar() 3297 //------------------------------------------------------------------------ 3298 extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_toChar( 3299 hTestResult hRtlTestResult ) 3300 { 3301 c_rtl_tres_state_start( hRtlTestResult, "toChar"); 3302 sal_Bool bRes=sal_False; 3303 3304 bRes=c_rtl_tres_state 3305 ( 3306 hRtlTestResult, 3307 test_toData<sal_Unicode>((const char**)inputChar,nCharCount, 3308 10,expValChar,6,NULL,hRtlTestResult), 3309 "toChar", 3310 "toChar()" 3311 ); 3312 3313 c_rtl_tres_state_end( hRtlTestResult, "toChar"); 3314 // return ( bRes ); 3315 3316 } 3317 //------------------------------------------------------------------------ 3318 // testing the method toBoolean() 3319 //------------------------------------------------------------------------ 3320 extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_toBoolean( 3321 hTestResult hRtlTestResult) 3322 { 3323 c_rtl_tres_state_start( hRtlTestResult, "toBoolean"); 3324 sal_Char methName[MAXBUFLENGTH]; 3325 sal_Char* pMeth = methName; 3326 3327 typedef struct TestCase 3328 { 3329 sal_Char* comments; 3330 sal_Bool expVal; 3331 OUString* input; 3332 3333 ~TestCase() {delete input;} 3334 }TestCase; 3335 3336 TestCase arrTestCase[]={ 3337 3338 {"expected true", sal_True, new OUString("True",4,kEncodingRTLTextUSASCII, 3339 kConvertFlagsOStringToOUString)}, 3340 {"expected false", sal_False, new OUString("False",5, 3341 kEncodingRTLTextUSASCII, 3342 kConvertFlagsOStringToOUString)}, 3343 {"expected true", sal_True, new OUString("1",1,kEncodingRTLTextUSASCII, 3344 kConvertFlagsOStringToOUString)} 3345 }; 3346 3347 sal_Bool res = sal_True; 3348 sal_uInt32 i; 3349 3350 for (i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++) 3351 { 3352 sal_Bool bRes = arrTestCase[i].input->toBoolean(); 3353 sal_Bool lastRes = (bRes == arrTestCase[i].expVal); 3354 c_rtl_tres_state 3355 ( 3356 hRtlTestResult, 3357 lastRes, 3358 arrTestCase[i].comments, 3359 createName( pMeth, "toBoolean", i ) 3360 3361 ); 3362 res &= lastRes; 3363 } 3364 c_rtl_tres_state_end( hRtlTestResult, "toBoolean"); 3365 // return ( res ); 3366 } 3367 //------------------------------------------------------------------------ 3368 // testing the method toInt32() 3369 //------------------------------------------------------------------------ 3370 3371 sal_Bool SAL_CALL test_rtl_OUString_toInt32_normal( 3372 hTestResult hRtlTestResult ) 3373 { 3374 sal_Int32 expValues[kBase36NumsCount]; 3375 sal_Int32 i; 3376 3377 for ( i = 0; i < kBase36NumsCount; i++ ) 3378 expValues[i] = i; 3379 3380 sal_Bool res = c_rtl_tres_state 3381 ( 3382 hRtlTestResult, 3383 test_toData<sal_Int32>( kBinaryNumsStr,kBinaryNumsCount, 3384 kRadixBinary,expValues,1,NULL,hRtlTestResult ), 3385 "kBinaryNumsStr", 3386 "toInt32( radix 2 )" 3387 ); 3388 res &= c_rtl_tres_state 3389 ( 3390 hRtlTestResult, 3391 test_toData<sal_Int32>( kBinaryMaxNumsStr,kInt32MaxNumsCount, 3392 kRadixBinary,kInt32MaxNums,1,NULL,hRtlTestResult ), 3393 "kBinaryMaxNumsStr", 3394 "toInt32_Boundaries( radix 2 )" 3395 ); 3396 3397 res &= c_rtl_tres_state 3398 ( 3399 hRtlTestResult, 3400 test_toData<sal_Int32>( kOctolNumsStr,kOctolNumsCount, 3401 kRadixOctol,expValues,1,NULL,hRtlTestResult ), 3402 "kOctolNumsStr", 3403 "toInt32( radix 8 )" 3404 ); 3405 3406 res &= c_rtl_tres_state 3407 ( 3408 hRtlTestResult, 3409 test_toData<sal_Int32>( kOctolMaxNumsStr,kInt32MaxNumsCount, 3410 kRadixOctol,(sal_Int32*)kInt32MaxNums,1,NULL,hRtlTestResult ), 3411 "kOctolMaxNumsStr", 3412 "toInt32_Boundaries( radix 8 )" 3413 ); 3414 3415 res &= c_rtl_tres_state 3416 ( 3417 hRtlTestResult, 3418 test_toData<sal_Int32>( kDecimalNumsStr,kDecimalNumsCount, 3419 kRadixDecimal,expValues,1,NULL,hRtlTestResult ), 3420 "kDecimalNumsStr", 3421 "toInt32( radix 10 )" 3422 ); 3423 3424 res &= c_rtl_tres_state 3425 ( 3426 hRtlTestResult, 3427 test_toData<sal_Int32>( kDecimalMaxNumsStr,kInt32MaxNumsCount, 3428 kRadixDecimal,(sal_Int32*)kInt32MaxNums,1,NULL,hRtlTestResult ), 3429 "kDecimalMaxNumsStr", 3430 "toInt32_Boundaries( radix 10 )" 3431 ); 3432 3433 res &= c_rtl_tres_state 3434 ( 3435 hRtlTestResult, 3436 test_toData<sal_Int32>( kHexDecimalNumsStr,kHexDecimalNumsCount, 3437 kRadixHexdecimal,expValues,1,NULL,hRtlTestResult ), 3438 "kHexDecimalNumsStr", 3439 "toInt32( radix 16 )" 3440 ); 3441 3442 res &= c_rtl_tres_state 3443 ( 3444 hRtlTestResult, 3445 test_toData<sal_Int32>( kHexDecimalMaxNumsStr,kInt32MaxNumsCount, 3446 kRadixHexdecimal,(sal_Int32*)kInt32MaxNums,1,NULL,hRtlTestResult ), 3447 "kHexDecimalMaxNumsStr", 3448 "toInt32_Boundaries( radix 16 )" 3449 ); 3450 3451 res &= c_rtl_tres_state 3452 ( 3453 hRtlTestResult, 3454 test_toData<sal_Int32>( kBase36NumsStr,kBase36NumsCount, 3455 kRadixBase36, expValues,1,NULL,hRtlTestResult ), 3456 "kBase36NumsStr", 3457 "toInt32( radix 36 )" 3458 ); 3459 3460 res &= c_rtl_tres_state 3461 ( 3462 hRtlTestResult, 3463 test_toData<sal_Int32>( kBase36MaxNumsStr,kInt32MaxNumsCount, 3464 kRadixBase36,(sal_Int32*)kInt32MaxNums,1,NULL,hRtlTestResult ), 3465 "kBase36MaxNumsStr", 3466 "toInt32_Boundaries( radix 36 )" 3467 ); 3468 3469 const sal_Int16 nSpecCases = 5; 3470 static const sal_Char *spString[nSpecCases] = 3471 { 3472 "-1", 3473 "+1", 3474 " 1", 3475 " -1", 3476 "001" 3477 }; 3478 3479 sal_Int32 expSpecVal[nSpecCases] = 3480 { 3481 -1, 3482 1, 3483 1, 3484 -1, 3485 1 3486 }; 3487 3488 res &= c_rtl_tres_state 3489 ( 3490 hRtlTestResult, 3491 test_toData<sal_Int32>( spString,nSpecCases, 3492 kRadixDecimal,expSpecVal,1,NULL,hRtlTestResult ), 3493 "special cases", 3494 "toInt32( specialcases )" 3495 ); 3496 3497 return ( res ); 3498 } 3499 sal_Bool SAL_CALL test_rtl_OUString_toInt32_wrongRadix( 3500 hTestResult hRtlTestResult ) 3501 { 3502 ::rtl::OUString str("0",1,kEncodingRTLTextUSASCII, 3503 kConvertFlagsOStringToOUString); 3504 3505 sal_Int32 iRes =str.toInt32(-1); 3506 3507 return 3508 ( 3509 c_rtl_tres_state 3510 ( 3511 hRtlTestResult, 3512 iRes == 0, 3513 "wrong radix -1", 3514 "toInt32( 0, wrong radix -1 )" 3515 ) 3516 ); 3517 } 3518 sal_Bool SAL_CALL test_rtl_OUString_toInt32_defaultParam( 3519 hTestResult hRtlTestResult ) 3520 { 3521 sal_Int32 expValues[kBase36NumsCount]; 3522 sal_Int32 i; 3523 3524 for ( i = 0; i < kBase36NumsCount; i++ ) 3525 expValues[i] = i; 3526 3527 sal_Bool res = c_rtl_tres_state 3528 ( 3529 hRtlTestResult, 3530 test_toData<sal_Int32>( kDecimalNumsStr,kDecimalNumsCount, 3531 kRadixDecimal,expValues,0,NULL,hRtlTestResult ), 3532 "kBinaryNumsStr", 3533 "toInt32( radix 2 )" 3534 ); 3535 res &= c_rtl_tres_state 3536 ( 3537 hRtlTestResult, 3538 test_toData<sal_Int32>( kDecimalMaxNumsStr,kInt32MaxNumsCount, 3539 kRadixDecimal,(sal_Int32*)kInt32MaxNums,0,NULL,hRtlTestResult ), 3540 "kDecimalMaxNumsStr", 3541 "toInt32_Boundaries( radix 10 )" 3542 ); 3543 const sal_Int16 nSpecCases = 5; 3544 static const sal_Char *spString[nSpecCases] = 3545 { 3546 "-1", 3547 "+1", 3548 " 1", 3549 " -1", 3550 "001" 3551 }; 3552 3553 sal_Int32 expSpecVal[nSpecCases] = 3554 { 3555 -1, 3556 1, 3557 1, 3558 -1, 3559 1 3560 }; 3561 3562 res &= c_rtl_tres_state 3563 ( 3564 hRtlTestResult, 3565 test_toData<sal_Int32>( spString,nSpecCases, 3566 kRadixDecimal,expSpecVal,0,NULL,hRtlTestResult ), 3567 "special cases", 3568 "toInt32( specialcases )" 3569 ); 3570 3571 return ( res ); 3572 } 3573 3574 //------------------------------------------------------------------------ 3575 // testing the method toInt32() 3576 //------------------------------------------------------------------------ 3577 extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_toInt32( 3578 hTestResult hRtlTestResult ) 3579 { 3580 c_rtl_tres_state_start( hRtlTestResult, "toInt32"); 3581 sal_Bool bTState = test_rtl_OUString_toInt32_normal( hRtlTestResult ); 3582 bTState &= test_rtl_OUString_toInt32_defaultParam( hRtlTestResult ); 3583 bTState &= test_rtl_OUString_toInt32_wrongRadix( hRtlTestResult ); 3584 c_rtl_tres_state_end( hRtlTestResult, "toInt32"); 3585 // return ( bTState ); 3586 } 3587 //------------------------------------------------------------------------ 3588 // testing the method toInt64( sal_Int16 radix = 2,8,10,16,36 ) 3589 //------------------------------------------------------------------------ 3590 3591 sal_Bool SAL_CALL test_rtl_OUString_toInt64_normal( 3592 hTestResult hRtlTestResult ) 3593 { 3594 sal_Int64 expValues[kBase36NumsCount]; 3595 sal_Int32 i; 3596 3597 for (i = 0; i < kBase36NumsCount; expValues[i] = i, i++); 3598 3599 sal_Bool res = c_rtl_tres_state 3600 ( 3601 hRtlTestResult, 3602 test_toData<sal_Int64>( kBinaryNumsStr,kBinaryNumsCount, 3603 kRadixBinary,expValues,3,NULL,hRtlTestResult ), 3604 "kBinaryNumsStr", 3605 "toInt64( radix 2 )" 3606 ); 3607 3608 /* LLA: does not work within wntmsci8.pro 3609 res &= c_rtl_tres_state 3610 ( 3611 hRtlTestResult, 3612 test_toData<sal_Int64>( kBinaryMaxNumsStr,kInt64MaxNumsCount, 3613 kRadixBinary,kInt64MaxNums,3,hRtlTestResult ), 3614 "kBinaryMaxNumsStr", 3615 "toInt64_Boundaries( radix 2 )" 3616 ); 3617 */ 3618 3619 res &= c_rtl_tres_state 3620 ( 3621 hRtlTestResult, 3622 test_toData<sal_Int64>( kOctolNumsStr,kOctolNumsCount, 3623 kRadixOctol,expValues,3,NULL,hRtlTestResult ), 3624 "kOctolNumsStr", 3625 "toInt64( radix 8 )" 3626 ); 3627 3628 res &= c_rtl_tres_state 3629 ( 3630 hRtlTestResult, 3631 test_toData<sal_Int64>( kOctolMaxNumsStr,kInt64MaxNumsCount, 3632 kRadixOctol,(sal_Int64*)kInt64MaxNums,3,NULL,hRtlTestResult ), 3633 "kOctolMaxNumsStr", 3634 "toInt64_Boundaries( radix 8 )" 3635 ); 3636 3637 res &= c_rtl_tres_state 3638 ( 3639 hRtlTestResult, 3640 test_toData<sal_Int64>( kDecimalNumsStr,kDecimalNumsCount, 3641 kRadixDecimal,expValues,3,NULL,hRtlTestResult ), 3642 "kDecimalNumsStr", 3643 "toInt64( radix 10 )" 3644 ); 3645 3646 res &= c_rtl_tres_state 3647 ( 3648 hRtlTestResult, 3649 test_toData<sal_Int64>( kDecimalMaxNumsStr,kInt64MaxNumsCount, 3650 kRadixDecimal,(sal_Int64*)kInt64MaxNums,3,NULL,hRtlTestResult ), 3651 "kDecimalMaxNumsStr", 3652 "toInt64_Boundaries( radix 10 )" 3653 ); 3654 3655 res &= c_rtl_tres_state 3656 ( 3657 hRtlTestResult, 3658 test_toData<sal_Int64>( kHexDecimalNumsStr,kHexDecimalNumsCount, 3659 kRadixHexdecimal,expValues,3,NULL,hRtlTestResult ), 3660 "kHexDecimalNumsStr", 3661 "toInt64( radix 16 )" 3662 ); 3663 3664 res &= c_rtl_tres_state 3665 ( 3666 hRtlTestResult, 3667 test_toData<sal_Int64>( kHexDecimalMaxNumsStr,kInt64MaxNumsCount, 3668 kRadixHexdecimal,(sal_Int64*)kInt64MaxNums,3,NULL,hRtlTestResult ), 3669 "kHexDecimalMaxNumsStr", 3670 "toInt64_Boundaries( radix 16 )" 3671 ); 3672 3673 res &= c_rtl_tres_state 3674 ( 3675 hRtlTestResult, 3676 test_toData<sal_Int64>( kBase36NumsStr,kBase36NumsCount, 3677 kRadixBase36, expValues,3,NULL,hRtlTestResult ), 3678 "kBase36NumsStr", 3679 "toInt64( radix 36 )" 3680 ); 3681 3682 res &= c_rtl_tres_state 3683 ( 3684 hRtlTestResult, 3685 test_toData<sal_Int64>( kBase36MaxNumsStr,kInt64MaxNumsCount, 3686 kRadixBase36,(sal_Int64*)kInt64MaxNums,3,NULL,hRtlTestResult ), 3687 "kBase36MaxNumsStr", 3688 "toInt64_Boundaries( radix 36 )" 3689 ); 3690 3691 3692 3693 const sal_Int16 nSpecCases = 5; 3694 static const sal_Char *spString[nSpecCases] = 3695 { 3696 "-1", 3697 "+1", 3698 " 1", 3699 " -1", 3700 "001" 3701 }; 3702 3703 sal_Int64 expSpecVal[nSpecCases] = 3704 { 3705 -1, 3706 1, 3707 1, 3708 -1, 3709 1 3710 }; 3711 3712 res &= c_rtl_tres_state 3713 ( 3714 hRtlTestResult, 3715 test_toData<sal_Int64>( spString,nSpecCases, 3716 kRadixDecimal,expSpecVal,3,NULL,hRtlTestResult ), 3717 "special cases", 3718 "toInt64( specialcases )" 3719 ); 3720 3721 return (res); 3722 } 3723 3724 sal_Bool SAL_CALL test_rtl_OUString_toInt64_wrongRadix( 3725 hTestResult hRtlTestResult ) 3726 { 3727 ::rtl::OUString str("0",1,kEncodingRTLTextUSASCII, 3728 kConvertFlagsOStringToOUString); 3729 3730 sal_Int64 iRes = str.toInt64(-1); 3731 3732 return ( 3733 c_rtl_tres_state 3734 ( 3735 hRtlTestResult, 3736 iRes == 0, 3737 "wrong radix -1", 3738 "toInt64( wrong radix -1)" 3739 ) 3740 ); 3741 } 3742 sal_Bool SAL_CALL test_rtl_OUString_toInt64_defaultParam( 3743 hTestResult hRtlTestResult ) 3744 { 3745 sal_Int64 expValues[kBase36NumsCount]; 3746 sal_Int32 i; 3747 3748 for ( i = 0; i < kBase36NumsCount; i++ ) 3749 expValues[i] = i; 3750 3751 sal_Bool res = c_rtl_tres_state 3752 ( 3753 hRtlTestResult, 3754 test_toData<sal_Int64>( kDecimalNumsStr,kDecimalNumsCount, 3755 kRadixDecimal,expValues,2,NULL,hRtlTestResult ), 3756 "kBinaryNumsStr", 3757 "toInt64( radix 10 )" 3758 ); 3759 res &= c_rtl_tres_state 3760 ( 3761 hRtlTestResult, 3762 test_toData<sal_Int64>( kDecimalMaxNumsStr,kInt64MaxNumsCount, 3763 kRadixDecimal,(sal_Int64*)kInt64MaxNums,2,NULL,hRtlTestResult ), 3764 "kDecimalMaxNumsStr", 3765 "toInt64_Boundaries( radix 10 )" 3766 ); 3767 const sal_Int16 nSpecCases = 5; 3768 static const sal_Char *spString[nSpecCases] = 3769 { 3770 "-1", 3771 "+1", 3772 " 1", 3773 " -1", 3774 "001" 3775 }; 3776 3777 sal_Int64 expSpecVal[nSpecCases] = 3778 { 3779 -1, 3780 1, 3781 1, 3782 -1, 3783 1 3784 }; 3785 3786 res &= c_rtl_tres_state 3787 ( 3788 hRtlTestResult, 3789 test_toData<sal_Int64>( spString,nSpecCases, 3790 kRadixDecimal,expSpecVal,2,NULL,hRtlTestResult ), 3791 "special cases", 3792 "toInt64( specialcases )" 3793 ); 3794 3795 return ( res ); 3796 } 3797 3798 //------------------------------------------------------------------------ 3799 // testing the method toInt64() 3800 //------------------------------------------------------------------------ 3801 extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_toInt64( 3802 hTestResult hRtlTestResult ) 3803 { 3804 c_rtl_tres_state_start( hRtlTestResult, "toInt64"); 3805 sal_Bool bTState = test_rtl_OUString_toInt64_normal( hRtlTestResult ); 3806 bTState &= test_rtl_OUString_toInt64_defaultParam (hRtlTestResult ); 3807 bTState &= test_rtl_OUString_toInt64_wrongRadix( hRtlTestResult ); 3808 c_rtl_tres_state_end( hRtlTestResult, "toInt64"); 3809 // return ( bTState ); 3810 } 3811 extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString( hTestResult hRtlTestResult ) 3812 { 3813 3814 c_rtl_tres_state_start(hRtlTestResult, "rtl_OUString" ); 3815 3816 test_rtl_OUString_ctors( hRtlTestResult ); 3817 test_rtl_OUString_getLength( hRtlTestResult ); 3818 test_rtl_OUString_equals( hRtlTestResult ); 3819 test_rtl_OUString_equalsIgnoreAsciiCase( hRtlTestResult ); 3820 test_rtl_OUString_compareTo( hRtlTestResult ); 3821 test_rtl_OUString_match( hRtlTestResult ); 3822 test_rtl_OUString_op_eq( hRtlTestResult ); 3823 test_rtl_OUString_op_peq( hRtlTestResult ); 3824 test_rtl_OUString_csuc( hRtlTestResult ); 3825 test_rtl_OUString_getStr( hRtlTestResult ); 3826 test_rtl_OUString_reverseCompareTo( hRtlTestResult ); 3827 test_rtl_OUString_equalsAscii( hRtlTestResult ); 3828 test_rtl_OUString_equalsAsciiL( hRtlTestResult ); 3829 test_rtl_OUString_compareToAscii( hRtlTestResult ); 3830 test_rtl_OUString_valueOf_sal_Bool( hRtlTestResult ); 3831 test_rtl_OUString_valueOf_sal_Unicode( hRtlTestResult ); 3832 test_rtl_OUString_valueOf( hRtlTestResult ); 3833 test_rtl_OUString_createFromAscii( hRtlTestResult ); 3834 test_rtl_OUString_indexOf( hRtlTestResult ); 3835 // LLA: removed, it is in a new test in rtl/oustring. test_rtl_OUString_lastIndexOf( hRtlTestResult ); 3836 test_rtl_OUString_concat( hRtlTestResult ); 3837 test_rtl_OUString_replaceAt( hRtlTestResult ); 3838 test_rtl_OUString_replace( hRtlTestResult ); 3839 test_rtl_OUString_toAsciiLowerCase( hRtlTestResult ); 3840 test_rtl_OUString_toAsciiUpperCase( hRtlTestResult ); 3841 test_rtl_OUString_trim( hRtlTestResult ); 3842 // LLA: removed, it is in a new test in rtl/oustring. test_rtl_OUString_toDouble( hRtlTestResult ); 3843 // LLA: removed, has compile problems. test_rtl_OUString_toFloat( hRtlTestResult ); 3844 test_rtl_OUString_toChar( hRtlTestResult ); 3845 test_rtl_OUString_toBoolean( hRtlTestResult ); 3846 test_rtl_OUString_toInt32( hRtlTestResult ); 3847 test_rtl_OUString_toInt64( hRtlTestResult ); 3848 3849 c_rtl_tres_state_end(hRtlTestResult, "rtl_OUString"); 3850 } 3851 // ----------------------------------------------------------------------------- 3852 void RegisterAdditionalFunctions(FktRegFuncPtr _pFunc) 3853 { 3854 if (_pFunc) 3855 { 3856 (_pFunc)(&test_rtl_OUString, ""); 3857 } 3858 } 3859