1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 package complex.toolkit.accessibility; 29 30 import com.sun.star.accessibility.XAccessibleText; 31 // import lib.MultiMethodTest; 32 //import lib.StatusException; 33 //import lib.Status; 34 import com.sun.star.beans.PropertyValue; 35 import com.sun.star.awt.Rectangle; 36 import com.sun.star.awt.Point; 37 import com.sun.star.lang.XMultiServiceFactory; 38 import com.sun.star.accessibility.AccessibleTextType; 39 import com.sun.star.accessibility.TextSegment; 40 import com.sun.star.uno.XInterface; 41 import com.sun.star.uno.UnoRuntime; 42 // import share.LogWriter; 43 44 /** 45 * Testing <code>com.sun.star.accessibility.XAccessibleText</code> 46 * interface methods : 47 * <ul> 48 * <li><code> getCaretPosition()</code></li> 49 * <li><code> setCaretPosition()</code></li> 50 * <li><code> getCharacter()</code></li> 51 * <li><code> getCharacterAttributes()</code></li> 52 * <li><code> getCharacterBounds()</code></li> 53 * <li><code> getCharacterCount()</code></li> 54 * <li><code> getIndexAtPoint()</code></li> 55 * <li><code> getSelectedText()</code></li> 56 * <li><code> getSelectionStart()</code></li> 57 * <li><code> getSelectionEnd()</code></li> 58 * <li><code> setSelection()</code></li> 59 * <li><code> getText()</code></li> 60 * <li><code> getTextRange()</code></li> 61 * <li><code> getTextAtIndex()</code></li> 62 * <li><code> getTextBeforeIndex()</code></li> 63 * <li><code> getTextBehindIndex()</code></li> 64 * <li><code> copyText()</code></li> 65 * </ul> <p> 66 * This test needs the following object relations : 67 * <ul> 68 * <li> <code>'XAccessibleText.Text'</code> (of type <code>String</code>) 69 * <b> optional </b> : 70 * the string presentation of component's text. If the relation 71 * is not specified, then text from method <code>getText()</code> 72 * is used. 73 * </li> 74 * </ul> <p> 75 * @see com.sun.star.accessibility.XAccessibleText 76 */ 77 public class _XAccessibleText { 78 79 // private LogWriter log; 80 81 private static final String className = 82 "com.sun.star.accessibility.XAccessibleText" ; 83 84 public XAccessibleText oObj = null; 85 private XMultiServiceFactory xMSF; 86 87 Rectangle chBounds = null; 88 int chCount = 0; 89 90 String text = null; 91 String editOnly = null; 92 93 94 public _XAccessibleText(XInterface object, XMultiServiceFactory xMSF, String editOnly) { 95 oObj = UnoRuntime.queryInterface(XAccessibleText.class, object); 96 this.xMSF = xMSF; 97 // this.log = log; 98 this.editOnly = editOnly; 99 } 100 101 102 /** 103 * Calls the method and checks returned value. 104 * Has OK status if returned value is equal to <code>chCount - 1</code>. 105 * The following method tests are to be executed before: 106 * <ul> 107 * <li> <code>setCaretPosition()</code> </li> 108 * </ul> 109 * @return 110 */ 111 public boolean _getCaretPosition() { 112 113 if (editOnly != null) { 114 System.out.println(editOnly); 115 return true; 116 } 117 118 boolean res = true; 119 if ( chCount > 0 ) { 120 try { 121 oObj.setCaretPosition(chCount - 1); 122 } catch (com.sun.star.lang.IndexOutOfBoundsException ie) { 123 124 } 125 int carPos = oObj.getCaretPosition(); 126 System.out.println("getCaretPosition: " + carPos); 127 res = carPos == (chCount - 1); 128 } 129 return res; 130 } 131 132 /** 133 * Calls the method with the wrong index and with the correct index 134 * <code>chCount - 1</code>. 135 * Has OK status if exception was thrown for wrong index and 136 * if exception wasn't thrown for the correct index. 137 * The following method tests are to be executed before: 138 * <ul> 139 * <li> <code>getCharacterCount()</code> </li> 140 * </ul> 141 * @return 142 */ 143 public boolean _setCaretPosition() { 144 boolean res = true; 145 146 try { 147 System.out.println("setCaretPosition(-1):"); 148 oObj.setCaretPosition(-1); 149 res &= false; 150 System.out.println("exception was expected"); 151 } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 152 System.out.println("expected exception"); 153 res &= true; 154 } 155 156 try { 157 System.out.println("setCaretPosition(chCount+1):"); 158 oObj.setCaretPosition(chCount+1); 159 res &= false; 160 System.out.println("exception was expected"); 161 } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 162 System.out.println("expected exception"); 163 res &= true; 164 } 165 if ( chCount > 0 ) { 166 try { 167 System.out.println("setCaretPosition(chCount - 1)"); 168 oObj.setCaretPosition(chCount - 1); 169 res &= true; 170 } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 171 System.out.println("unexpected exception"); 172 e.printStackTrace(); 173 res &= false; 174 } 175 } 176 177 return res; 178 } 179 180 /** 181 * Calls the method with the wrong index and with the correct indexes. 182 * Checks every character in the text. 183 * Has OK status if exception was thrown for wrong index, 184 * if exception wasn't thrown for the correct index and 185 * if every character is equal to corresponding character in the text. 186 * The following method tests are to be executed before: 187 * <ul> 188 * <li> <code>getCharacterCount()</code> </li> 189 * </ul> 190 * @return 191 */ 192 public boolean _getCharacter() { 193 boolean res = true; 194 195 try { 196 System.out.println("getCharacter(-1)"); 197 oObj.getCharacter(-1); 198 System.out.println("Exception was expected"); 199 res = false; 200 } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 201 System.out.println("Expected exception"); 202 res = true; 203 } 204 205 try { 206 System.out.println("getCharacter(chCount)"); 207 oObj.getCharacter(chCount); 208 System.out.println("Exception was expected"); 209 res &= false; 210 } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 211 System.out.println("Expected exception"); 212 res &= true; 213 } 214 215 try { 216 System.out.println("Checking of every character in the text..."); 217 boolean isEqCh = true; 218 for(int i = 0; i < chCount; i++) { 219 char ch = oObj.getCharacter(i); 220 isEqCh = ch == text.charAt(i); 221 res &= isEqCh; 222 if (!isEqCh) { 223 System.out.println("At the position " + i + 224 "was expected character: " + text.charAt(i)); 225 System.out.println("but was returned: " + ch); 226 break; 227 } 228 } 229 } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 230 System.out.println("Unexpected exception"); 231 e.printStackTrace(); 232 res &= false; 233 } 234 235 return res; 236 } 237 238 /** 239 * Calls the method with the wrong indexes and with the correct index, 240 * checks a returned value. 241 * Has OK status if exception was thrown for the wrong indexes, 242 * if exception wasn't thrown for the correct index and 243 * if returned value isn't <code>null</code>. 244 * The following method tests are to be executed before: 245 * <ul> 246 * <li> <code>getCharacterCount()</code> </li> 247 * </ul> 248 * @return 249 */ 250 public boolean _getCharacterAttributes() { 251 boolean res = true; 252 253 try { 254 System.out.println("getCharacterAttributes(-1)"); 255 oObj.getCharacterAttributes(-1, new String[0]); 256 System.out.println("Exception was expected"); 257 res &= false; 258 } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 259 System.out.println("Expected exception"); 260 res &= true; 261 } 262 263 try { 264 System.out.println("getCharacterAttributes(chCount)"); 265 oObj.getCharacterAttributes(chCount, new String[0]); 266 System.out.println("Exception was expected"); 267 res &= false; 268 } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 269 System.out.println("Expected exception"); 270 res &= true; 271 } 272 273 try { 274 if ( chCount > 0 ) { 275 System.out.println("getCharacterAttributes(chCount-1)"); 276 PropertyValue[] props = oObj.getCharacterAttributes(chCount - 1, new String[0]); 277 res &= props != null; 278 } 279 } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 280 System.out.println("Unexpected exception"); 281 e.printStackTrace(); 282 res &= false; 283 } 284 285 return res; 286 } 287 288 289 /** 290 * Calls the method with the wrong indexes and with the correct index. 291 * checks and stores a returned value. 292 * Has OK status if exception was thrown for the wrong indexes, 293 * if exception wasn't thrown for the correct index and 294 * if returned value isn't <code>null</code>. 295 * The following method tests are to be executed before: 296 * <ul> 297 * <li> <code>getCharacterCount()</code> </li> 298 * </ul> 299 * @return 300 */ 301 public boolean _getCharacterBounds() { 302 boolean res = true; 303 304 try { 305 System.out.println("getCharacterBounds(-1)"); 306 oObj.getCharacterBounds(-1); 307 System.out.println("Exception was expected"); 308 res &= false; 309 } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 310 System.out.println("Expected exception"); 311 res &= true; 312 } 313 314 try { 315 System.out.println("getCharacterBounds(chCount)"); 316 oObj.getCharacterBounds(chCount); 317 System.out.println("Exception was expected"); 318 res &= false; 319 } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 320 System.out.println("Expected exception"); 321 res &= true; 322 } 323 324 try { 325 if (chCount > 0) { 326 System.out.println("getCharacterBounds(chCount-1)"); 327 chBounds = oObj.getCharacterBounds(chCount-1); 328 res &= chBounds != null; 329 System.out.println("rect: " + chBounds.X + ", " + chBounds.Y + ", " + 330 chBounds.Width + ", " + chBounds.Height); 331 } 332 333 } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 334 System.out.println("Unexpected exception"); 335 e.printStackTrace(); 336 res &= false; 337 } 338 339 return res; 340 } 341 342 343 /** 344 * Calls the method and stores a returned value to the variable 345 * <code>chCount</code>. 346 * Has OK status if a returned value is equal to the text length. 347 * @return 348 */ 349 public boolean _getCharacterCount() { 350 chCount = oObj.getCharacterCount(); 351 System.out.println("Character count:" + chCount); 352 boolean res = chCount == text.length(); 353 return res; 354 } 355 356 /** 357 * Calls the method for an invalid point and for the point of rectangle 358 * returned by the method <code>getCharacterBounds()</code>. 359 * Has OK status if returned value is equal to <code>-1</code> for an 360 * invalid point and if returned value is equal to <code>chCount-1</code> 361 * for a valid point. 362 * The following method tests are to be executed before: 363 * <ul> 364 * <li> <code>getCharacterBounds()</code> </li> 365 * </ul> 366 * @return 367 */ 368 public boolean _getIndexAtPoint() { 369 370 boolean res = true; 371 System.out.println("getIndexAtPoint(-1, -1):"); 372 Point pt = new Point(-1, -1); 373 int index = oObj.getIndexAtPoint(pt); 374 System.out.println(Integer.toString(index)); 375 res &= index == -1; 376 377 if (chBounds != null) { 378 pt = new Point(chBounds.X , chBounds.Y ); 379 System.out.println("getIndexAtPoint(" + pt.X + ", " + pt.Y + "):"); 380 index = oObj.getIndexAtPoint(pt); 381 System.out.println(Integer.toString(index)); 382 res &= index == (chCount - 1); 383 } 384 385 return res; 386 } 387 388 /** 389 * Checks a returned values after different calls of the method 390 * <code>setSelection()</code>. 391 * The following method tests are to be executed before: 392 * <ul> 393 * <li> <code>setSelection()</code> </li> 394 * </ul> 395 * @return 396 */ 397 public boolean _getSelectedText() { 398 if (editOnly != null) { 399 System.out.println(editOnly); 400 return true; 401 } 402 403 boolean res = true; 404 405 try { 406 System.out.println("setSelection(0, 0)"); 407 oObj.setSelection(0, 0); 408 System.out.println("getSelectedText():"); 409 String txt = oObj.getSelectedText(); 410 System.out.println("'" + txt + "'"); 411 res &= txt.length() == 0; 412 413 System.out.println("setSelection(0, chCount)"); 414 oObj.setSelection(0, chCount); 415 System.out.println("getSelectedText():"); 416 txt = oObj.getSelectedText(); 417 System.out.println("'" + txt + "'"); 418 res &= txt.equals(text); 419 420 if (chCount > 2) { 421 System.out.println("setSelection(1, chCount-1)"); 422 oObj.setSelection(1, chCount - 1); 423 System.out.println("getSelectedText():"); 424 txt = oObj.getSelectedText(); 425 System.out.println("'" + txt + "'"); 426 res &= txt.equals(text.substring(1, chCount - 1)); 427 } 428 } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 429 System.out.println("Unexpected exception"); 430 e.printStackTrace(); 431 res &= false; 432 } 433 434 return res; 435 } 436 437 /** 438 * Checks a returned values after different calls of the method 439 * <code>setSelection()</code>. 440 * The following method tests are to be executed before: 441 * <ul> 442 * <li> <code>setSelection()</code> </li> 443 * </ul> 444 * @return 445 */ 446 public boolean _getSelectionStart() { 447 if (editOnly != null) { 448 System.out.println(editOnly); 449 return true; 450 } 451 452 boolean res = true; 453 454 try { 455 System.out.println("setSelection(0, chCount)"); 456 oObj.setSelection(0, chCount); 457 int start = oObj.getSelectionStart(); 458 System.out.println("getSelectionStart():" + start); 459 res &= start == 0; 460 461 if (chCount > 2) { 462 System.out.println("setSelection(1, chCount-1)"); 463 oObj.setSelection(1, chCount - 1); 464 start = oObj.getSelectionStart(); 465 System.out.println("getSelectionStart():" + start); 466 res &= start == 1; 467 } 468 } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 469 System.out.println("Unexpected exception"); 470 e.printStackTrace(); 471 res &= false; 472 } 473 474 return res; 475 } 476 477 /** 478 * Checks a returned values after different calls of the method 479 * <code>setSelection()</code>. 480 * The following method tests are to be executed before: 481 * <ul> 482 * <li> <code>setSelection()</code> </li> 483 * </ul> 484 * @return 485 */ 486 public boolean _getSelectionEnd() { 487 if (editOnly != null) { 488 System.out.println(editOnly); 489 return true; 490 } 491 492 boolean res = true; 493 494 try { 495 System.out.println("setSelection(0, chCount)"); 496 oObj.setSelection(0, chCount); 497 int end = oObj.getSelectionEnd(); 498 System.out.println("getSelectionEnd():" + end); 499 res &= end == chCount; 500 501 if (chCount > 2) { 502 System.out.println("setSelection(1, chCount-1)"); 503 oObj.setSelection(1, chCount - 1); 504 end = oObj.getSelectionEnd(); 505 System.out.println("getSelectionEnd():" + end); 506 res &= end == chCount - 1; 507 } 508 } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 509 System.out.println("Unexpected exception"); 510 e.printStackTrace(); 511 res &= false; 512 } 513 514 return res; 515 } 516 517 /** 518 * Calls the method with invalid parameters an with valid parameters. 519 * Has OK status if exception was thrown for invalid parameters, 520 * if exception wasn't thrown for valid parameters. 521 * The following method tests are to be executed before: 522 * <ul> 523 * <li> <code>getCharacterCount()</code> </li> 524 * </ul> 525 * @return 526 */ 527 public boolean _setSelection() { 528 boolean res = true; 529 boolean locRes = true; 530 531 if (editOnly != null) { 532 System.out.println(editOnly); 533 return true; 534 } 535 536 try { 537 System.out.println("setSelection(-1, chCount-1):"); 538 locRes = oObj.setSelection(-1, chCount - 1); 539 System.out.println(locRes + " exception was expected"); 540 res &= !locRes; 541 } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 542 System.out.println("Expected exception"); 543 res &= true; 544 } 545 546 try { 547 System.out.println("setSelection(0, chCount+1):"); 548 locRes = oObj.setSelection(0, chCount + 1); 549 System.out.println(locRes + " excepion was expected"); 550 res &= !locRes; 551 } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 552 System.out.println("Expected exception"); 553 res &= true; 554 } 555 556 try { 557 if (chCount > 2) { 558 System.out.println("setSelection(1, chCount-1):"); 559 locRes = oObj.setSelection(1, chCount - 1); 560 System.out.println(Boolean.toString(locRes)); 561 res &= locRes; 562 563 System.out.println("setSelection(chCount-1, 1):"); 564 locRes = oObj.setSelection(chCount - 1, 1); 565 System.out.println(Boolean.toString(locRes)); 566 res &= locRes; 567 } 568 569 if (chCount > 1) { 570 System.out.println("setSelection(0, chCount-1):"); 571 locRes = oObj.setSelection(0, chCount-1); 572 System.out.println(Boolean.toString(locRes)); 573 res &= locRes; 574 575 System.out.println("setSelection(chCount-1, 0):"); 576 locRes = oObj.setSelection(chCount-1, 0); 577 System.out.println(Boolean.toString(locRes)); 578 res &= locRes; 579 } 580 581 System.out.println("setSelection(0, 0):"); 582 locRes = oObj.setSelection(0, 0); 583 System.out.println(Boolean.toString(locRes)); 584 res &= locRes; 585 } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 586 System.out.println("Unexpected exception"); 587 e.printStackTrace(); 588 res &= false; 589 } 590 591 return res; 592 } 593 594 /** 595 * Calls the method and checks returned value. 596 * Has OK status if returned string is not null 597 * received from relation. 598 * @return 599 */ 600 public boolean _getText() { 601 text = oObj.getText(); 602 System.out.println("getText: '" + text + "'"); 603 return (text != null); 604 } 605 606 /** 607 * Calls the method with invalid parameters an with valid parameters, 608 * checks returned values. 609 * Has OK status if exception was thrown for invalid parameters, 610 * if exception wasn't thrown for valid parameters and if returned values 611 * are equal to corresponding substrings of the text received by relation. 612 * The following method tests are to be executed before: 613 * <ul> 614 * <li> <code>getCharacterCount()</code> </li> 615 * </ul> 616 * @return 617 */ 618 public boolean _getTextRange() { 619 boolean res = true; 620 boolean locRes = true; 621 622 try { 623 if (chCount > 3) { 624 System.out.println("getTextRange(1, chCount - 2): "); 625 String txtRange = oObj.getTextRange(1, chCount - 2); 626 System.out.println(txtRange); 627 locRes = txtRange.equals(text.substring(1, chCount - 2)); 628 res &= locRes; 629 if (!locRes) { 630 System.out.println("Was expected: " + 631 text.substring(1, chCount - 2)); 632 } 633 } 634 635 if (chCount > 0) { 636 System.out.println("getTextRange(0, chCount-1): "); 637 String txtRange = oObj.getTextRange(0, chCount-1); 638 System.out.println(txtRange); 639 locRes = txtRange.equals(text.substring(0, chCount - 1)); 640 res &= locRes; 641 if (!locRes) { 642 System.out.println("Was expected: " + 643 text.substring(0, chCount - 1)); 644 } 645 646 System.out.println("getTextRange(chCount, 0): "); 647 txtRange = oObj.getTextRange(chCount, 0); 648 System.out.println(txtRange); 649 res &= txtRange.equals(text); 650 651 System.out.println("getTextRange(0, 0): "); 652 txtRange = oObj.getTextRange(0, 0); 653 System.out.println(txtRange); 654 locRes = txtRange.equals(""); 655 res &= locRes; 656 if (!locRes) { 657 System.out.println("Empty string was expected"); 658 } 659 } 660 } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 661 System.out.println("Unexpected exception"); 662 e.printStackTrace(); 663 res &= false; 664 } 665 666 try { 667 System.out.println("getTextRange(-1, chCount - 1): "); 668 String txtRange = oObj.getTextRange(-1, chCount - 1); 669 System.out.println("Exception was expected"); 670 res &= false; 671 } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 672 System.out.println("Expected exception"); 673 res &= true; 674 } 675 676 try { 677 System.out.println("getTextRange(0, chCount + 1): "); 678 String txtRange = oObj.getTextRange(0, chCount + 1); 679 System.out.println("Exception was expected"); 680 res &= false; 681 } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 682 System.out.println("Expected exception"); 683 res &= true; 684 } 685 686 try { 687 System.out.println("getTextRange(chCount+1, -1): "); 688 String txtRange = oObj.getTextRange(chCount+1, -1); 689 System.out.println("Exception was expected"); 690 res &= false; 691 } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 692 System.out.println("Expected exception"); 693 res &= true; 694 } 695 696 return res; 697 } 698 699 /** 700 * Calls the method with invalid parameters an with valid parameters, 701 * checks returned values. 702 * Has OK status if exception was thrown for invalid parameters, 703 * if exception wasn't thrown for valid parameters and if returned values 704 * are equal to corresponding substrings of the text received by relation. 705 * The following method tests are to be executed before: 706 * <ul> 707 * <li> <code>getCharacterCount()</code> </li> 708 * </ul> 709 * @return 710 */ 711 public boolean _getTextAtIndex() { 712 boolean res = true; 713 714 try { 715 System.out.println("getTextAtIndex(-1, AccessibleTextType.PARAGRAPH):"); 716 TextSegment txt = 717 oObj.getTextAtIndex(-1, AccessibleTextType.PARAGRAPH); 718 System.out.println("Exception was expected"); 719 res &= false; 720 } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 721 System.out.println("Expected exception"); 722 res &= true; 723 } catch(com.sun.star.lang.IllegalArgumentException e) { 724 System.out.println("Expected exception"); 725 res &= true; 726 } 727 728 try { 729 System.out.println("getTextAtIndex(chCount+1," + 730 " AccessibleTextType.PARAGRAPH):"); 731 TextSegment txt = oObj.getTextAtIndex(chCount + 1, 732 AccessibleTextType.PARAGRAPH); 733 System.out.println("Exception was expected"); 734 res &= false; 735 } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 736 System.out.println("Expected exception"); 737 res &= true; 738 } catch(com.sun.star.lang.IllegalArgumentException e) { 739 System.out.println("Expected exception"); 740 res &= true; 741 } 742 743 744 try { 745 if ( chCount > 0 ) { 746 System.out.println("getTextAtIndex(chCount," + 747 " AccessibleTextType.PARAGRAPH):"); 748 TextSegment txt = oObj.getTextAtIndex(chCount, 749 AccessibleTextType.PARAGRAPH); 750 System.out.println("'" + txt.SegmentText + "'"); 751 res &= txt.SegmentText.length() == 0; 752 753 System.out.println("getTextAtIndex(1," + 754 " AccessibleTextType.PARAGRAPH):"); 755 txt = oObj.getTextAtIndex(1, 756 AccessibleTextType.PARAGRAPH); 757 System.out.println("'" + txt.SegmentText + "'"); 758 res &= txt.SegmentText.equals(text); 759 } 760 } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 761 System.out.println("Unexpected exception"); 762 e.printStackTrace(); 763 res &= false; 764 } catch(com.sun.star.lang.IllegalArgumentException e) { 765 System.out.println("Unexpected exception"); 766 res &= false; 767 } 768 769 770 return res; 771 } 772 773 /** 774 * Calls the method with invalid parameters an with valid parameters, 775 * checks returned values. 776 * Has OK status if exception was thrown for invalid parameters, 777 * if exception wasn't thrown for valid parameters and if returned values 778 * are equal to corresponding substrings of the text received by relation. 779 * The following method tests are to be executed before: 780 * <ul> 781 * <li> <code>getCharacterCount()</code> </li> 782 * </ul> 783 * @return 784 */ 785 public boolean _getTextBeforeIndex() { 786 boolean res = true; 787 788 try { 789 System.out.println("getTextBeforeIndex(-1, AccessibleTextType.PARAGRAPH):"); 790 TextSegment txt = oObj.getTextBeforeIndex(-1, 791 AccessibleTextType.PARAGRAPH); 792 System.out.println("Exception was expected"); 793 res &= false; 794 } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 795 System.out.println("Expected exception"); 796 res &= true; 797 } catch(com.sun.star.lang.IllegalArgumentException e) { 798 System.out.println("Expected exception"); 799 res &= true; 800 } 801 802 803 try { 804 System.out.println("getTextBeforeIndex(chCount+1, " + 805 "AccessibleTextType.PARAGRAPH):"); 806 TextSegment txt = oObj.getTextBeforeIndex(chCount + 1, 807 AccessibleTextType.PARAGRAPH); 808 System.out.println("Exception was expected"); 809 res &= false; 810 } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 811 System.out.println("Expected exception"); 812 res &= true; 813 } catch(com.sun.star.lang.IllegalArgumentException e) { 814 System.out.println("Expected exception"); 815 res &= true; 816 } 817 818 TextSegment txt = null; 819 try { 820 if (chCount > 0) { 821 System.out.println("getTextBeforeIndex(chCount," + 822 " AccessibleTextType.PARAGRAPH):"); 823 txt = oObj.getTextBeforeIndex(chCount, 824 AccessibleTextType.PARAGRAPH); 825 System.out.println("'" + txt.SegmentText + "'"); 826 res &= txt.SegmentText.length() == chCount ; 827 828 System.out.println("getTextBeforeIndex(1," + 829 " AccessibleTextType.PARAGRAPH):"); 830 txt = oObj.getTextBeforeIndex(1, 831 AccessibleTextType.PARAGRAPH); 832 System.out.println("'" + txt.SegmentText + "'"); 833 res &= txt.SegmentText.length() == 0; 834 } 835 836 if (chCount > 2) { 837 System.out.println("getTextBeforeIndex(chCount-1," + 838 " AccessibleTextType.CHARACTER):"); 839 txt = oObj.getTextBeforeIndex(chCount - 1, 840 AccessibleTextType.CHARACTER); 841 System.out.println("'" + txt.SegmentText + "'"); 842 res &= txt.SegmentText.equals(text.substring(chCount - 2, chCount - 1)); 843 System.out.println("getTextBeforeIndex(2," + 844 " AccessibleTextType.CHARACTER):"); 845 txt = oObj.getTextBeforeIndex(2, 846 AccessibleTextType.CHARACTER); 847 System.out.println("'" + txt.SegmentText + "'"); 848 res &= txt.SegmentText.equals(text.substring(1, 2)); 849 } 850 } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 851 System.out.println("Unexpected exception"); 852 e.printStackTrace(); 853 res &= false; 854 } catch(com.sun.star.lang.IllegalArgumentException e) { 855 System.out.println("Unexpected exception"); 856 res &= false; 857 } 858 859 860 return res; 861 } 862 863 /** 864 * Calls the method with invalid parameters an with valid parameters, 865 * checks returned values. 866 * Has OK status if exception was thrown for invalid parameters, 867 * if exception wasn't thrown for valid parameters and if returned values 868 * are equal to corresponding substrings of the text received by relation. 869 * The following method tests are to be executed before: 870 * <ul> 871 * <li> <code>getCharacterCount()</code> </li> 872 * </ul> 873 * @return 874 */ 875 public boolean _getTextBehindIndex() { 876 boolean res = true; 877 878 try { 879 System.out.println("getTextBehindIndex(-1, AccessibleTextType.PARAGRAPH):"); 880 TextSegment txt = oObj.getTextBehindIndex(-1, 881 AccessibleTextType.PARAGRAPH); 882 System.out.println("Exception was expected"); 883 res &= false; 884 } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 885 System.out.println("Expected exception"); 886 res &= true; 887 } catch(com.sun.star.lang.IllegalArgumentException e) { 888 System.out.println("Expected exception"); 889 res &= true; 890 } 891 892 893 try { 894 System.out.println("getTextBehindIndex(chCount+1, " + 895 "AccessibleTextType.PARAGRAPH):"); 896 TextSegment txt = oObj.getTextBehindIndex(chCount + 1, 897 AccessibleTextType.PARAGRAPH); 898 System.out.println("Exception was expected"); 899 res &= false; 900 } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 901 System.out.println("Expected exception"); 902 res &= true; 903 } catch(com.sun.star.lang.IllegalArgumentException e) { 904 System.out.println("Expected exception"); 905 res &= true; 906 } 907 908 909 try { 910 if ( chCount > 0 ) { 911 System.out.println("getTextBehindIndex(chCount," + 912 " AccessibleTextType.PARAGRAPH):"); 913 TextSegment txt = oObj.getTextBehindIndex(chCount, 914 AccessibleTextType.PARAGRAPH); 915 System.out.println("'" + txt.SegmentText + "'"); 916 res &= txt.SegmentText.length() == 0; 917 918 System.out.println("getTextBehindIndex(chCount-1," + 919 " AccessibleTextType.PARAGRAPH):"); 920 txt = oObj.getTextBehindIndex(chCount - 1, 921 AccessibleTextType.PARAGRAPH); 922 System.out.println("'" + txt.SegmentText + "'"); 923 res &= txt.SegmentText.length() == 0; 924 } 925 if ( chCount > 1 ) { 926 System.out.println("getTextBehindIndex(1," + 927 " AccessibleTextType.CHARACTER):"); 928 TextSegment txt = oObj.getTextBehindIndex(1, 929 AccessibleTextType.CHARACTER); 930 System.out.println("'" + txt.SegmentText + "'"); 931 res &= txt.SegmentText.equals(text.substring(2, 3)); 932 } 933 if (chCount > 2) { 934 System.out.println("getTextBehindIndex(chCount-2," + 935 " AccessibleTextType.CHARACTER):"); 936 TextSegment txt = oObj.getTextBehindIndex(chCount - 2, 937 AccessibleTextType.CHARACTER); 938 System.out.println("'" + txt.SegmentText + "'"); 939 res &= txt.SegmentText.equals(text.substring(chCount - 1, chCount)); 940 } 941 } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 942 System.out.println("Unexpected exception"); 943 e.printStackTrace(); 944 res &= false; 945 } catch(com.sun.star.lang.IllegalArgumentException e) { 946 System.out.println("Unexpected exception"); 947 res &= false; 948 } 949 950 951 return res; 952 } 953 954 /** 955 * Calls the method with invalid parameters an with valid parameter, 956 * checks returned values. 957 * Has OK status if exception was thrown for invalid parameters, 958 * if exception wasn't thrown for valid parameter and if returned value for 959 * valid parameter is equal to <code>true</code>. 960 * @return 961 */ 962 public boolean _copyText() { 963 boolean res = true; 964 boolean locRes = true; 965 966 if (editOnly != null) { 967 System.out.println(editOnly); 968 return true; 969 } 970 971 try { 972 System.out.println("copyText(-1,chCount):"); 973 oObj.copyText(-1, chCount); 974 System.out.println("Exception was expected"); 975 res &= false; 976 } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 977 System.out.println("Expected exception"); 978 res &= true; 979 } 980 981 try { 982 System.out.println("copyText(0,chCount+1):"); 983 oObj.copyText(0, chCount + 1); 984 System.out.println("Exception was expected"); 985 res &= false; 986 } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 987 System.out.println("Expected exception"); 988 res &= true; 989 } 990 991 try { 992 System.out.println("copyText(0,chCount):"); 993 locRes = oObj.copyText(0, chCount); 994 System.out.println(""+locRes); 995 res &= locRes; 996 997 String cbText = null; 998 try { 999 cbText = 1000 util.SysUtils.getSysClipboardText(xMSF); 1001 } catch (com.sun.star.uno.Exception e) { 1002 System.out.println("Couldn't access system clipboard :"); 1003 e.printStackTrace(); 1004 } 1005 System.out.println("Clipboard: '" + cbText + "'"); 1006 res &= text.equals(cbText); 1007 1008 if (chCount > 2) { 1009 System.out.println("copyText(1,chCount-1):"); 1010 locRes = oObj.copyText(1, chCount - 1); 1011 System.out.println(""+locRes); 1012 res &= locRes; 1013 1014 try { 1015 cbText = util.SysUtils.getSysClipboardText(xMSF); 1016 } catch (com.sun.star.uno.Exception e) { 1017 System.out.println("Couldn't access system clipboard :"); 1018 e.printStackTrace(); 1019 } 1020 1021 System.out.println("Clipboard: '" + cbText + "'"); 1022 res &= text.substring(1, chCount - 1).equals(cbText); 1023 } 1024 1025 } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 1026 System.out.println("Unexpected exception"); 1027 e.printStackTrace(); 1028 res &= false; 1029 } 1030 1031 return res; 1032 } 1033 } 1034