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