2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 package ifc
.accessibility
;
20 import lib
.MultiMethodTest
;
22 import lib
.StatusException
;
24 import com
.sun
.star
.accessibility
.AccessibleTextType
;
25 import com
.sun
.star
.accessibility
.TextSegment
;
26 import com
.sun
.star
.accessibility
.XAccessibleComponent
;
27 import com
.sun
.star
.accessibility
.XAccessibleText
;
28 import com
.sun
.star
.awt
.Point
;
29 import com
.sun
.star
.awt
.Rectangle
;
30 import com
.sun
.star
.beans
.PropertyValue
;
31 import com
.sun
.star
.uno
.UnoRuntime
;
35 * Testing <code>com.sun.star.accessibility.XAccessibleText</code>
38 * <li><code> getCaretPosition()</code></li>
39 * <li><code> setCaretPosition()</code></li>
40 * <li><code> getCharacter()</code></li>
41 * <li><code> getCharacterAttributes()</code></li>
42 * <li><code> getCharacterBounds()</code></li>
43 * <li><code> getCharacterCount()</code></li>
44 * <li><code> getIndexAtPoint()</code></li>
45 * <li><code> getSelectedText()</code></li>
46 * <li><code> getSelectionStart()</code></li>
47 * <li><code> getSelectionEnd()</code></li>
48 * <li><code> setSelection()</code></li>
49 * <li><code> getText()</code></li>
50 * <li><code> getTextRange()</code></li>
51 * <li><code> getTextAtIndex()</code></li>
52 * <li><code> getTextBeforeIndex()</code></li>
53 * <li><code> getTextBehindIndex()</code></li>
54 * <li><code> copyText()</code></li>
56 * This test needs the following object relations :
58 * <li> <code>'XAccessibleText.Text'</code> (of type <code>String</code>)
60 * the string presentation of component's text. If the relation
61 * is not specified, then text from method <code>getText()</code>
65 * @see com.sun.star.accessibility.XAccessibleText
67 public class _XAccessibleText
extends MultiMethodTest
{
69 public XAccessibleText oObj
= null;
70 protected com
.sun
.star
.awt
.Rectangle bounds
= null;
72 String editOnly
= null;
73 Object LimitedBounds
= null;
74 Rectangle chBounds
= null;
79 * Retrieves a string representation of the component's text.
80 * The length of retrieved string must be greater than zero.
83 protected void before() {
84 Object xat
= tEnv
.getObjRelation("XAccessibleText");
86 XAccessibleComponent component
= null;
89 oObj
= UnoRuntime
.queryInterface(
90 XAccessibleText
.class, xat
);
91 component
= UnoRuntime
.queryInterface(
92 XAccessibleComponent
.class, xat
);
95 text
= (String
) tEnv
.getObjRelation("XAccessibleText.Text");
98 text
= oObj
.getText();
101 if (text
.length() == 0) {
102 throw new StatusException(Status
.failed(
103 "The length of text must be greater than zero"));
106 editOnly
= (String
) tEnv
.getObjRelation("EditOnly");
107 LimitedBounds
= tEnv
.getObjRelation("LimitedBounds");
109 if (component
== null) {
110 component
= UnoRuntime
.queryInterface(
111 XAccessibleComponent
.class,
112 tEnv
.getTestObject());
115 bounds
= component
.getBounds();
117 log
.println("Text is '" + text
+ "'");
118 System
.out
.println("############################");
122 * Calls the method and checks returned value.
123 * Has OK status if returned value is equal to <code>chCount - 1</code>.
124 * The following method tests are to be executed before:
126 * <li> <code>setCaretPosition()</code> </li>
129 public void _getCaretPosition() {
130 requiredMethod("getCharacterCount()");
132 if (editOnly
!= null) {
133 log
.println(editOnly
);
134 throw new StatusException(Status
.skipped(true));
141 oObj
.setCaretPosition(chCount
- 1);
142 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException ie
) {
145 int carPos
= oObj
.getCaretPosition();
146 log
.println("getCaretPosition: " + carPos
);
149 res
= carPos
== (chCount
- 1);
152 "Object is read only and Caret position couldn't be set");
156 tRes
.tested("getCaretPosition()", res
);
160 * Calls the method with the wrong index and with the correct index
161 * <code>chCount - 1</code>.
162 * Has OK status if exception was thrown for wrong index and
163 * if exception wasn't thrown for the correct index.
164 * The following method tests are to be executed before:
166 * <li> <code>getCharacterCount()</code> </li>
169 public void _setCaretPosition() {
170 requiredMethod("getCharacterCount()");
175 log
.print("setCaretPosition(-1):");
176 oObj
.setCaretPosition(-1);
178 log
.println("exception was expected ... FAILED");
179 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
180 log
.println("expected exception");
185 log
.print("setCaretPosition(chCount+1):");
186 oObj
.setCaretPosition(chCount
+ 1);
188 log
.println("exception was expected ... FAILED");
189 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
190 log
.println("expected exception");
195 log
.println("setCaretPosition(chCount - 1)");
196 oObj
.setCaretPosition(chCount
- 1);
198 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
199 log
.println("unexpected exception ... FAILED");
200 e
.printStackTrace(log
);
204 tRes
.tested("setCaretPosition()", res
);
208 * Calls the method with the wrong index and with the correct indexes.
209 * Checks every character in the text.
210 * Has OK status if exception was thrown for wrong index,
211 * if exception wasn't thrown for the correct index and
212 * if every character is equal to corresponding character in the text.
213 * The following method tests are to be executed before:
215 * <li> <code>getCharacterCount()</code> </li>
218 public void _getCharacter() {
219 requiredMethod("getCharacterCount()");
224 log
.println("getCharacter(-1)");
225 oObj
.getCharacter(-1);
226 log
.println("Exception was expected");
228 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
229 log
.println("Expected exception");
234 log
.println("getCharacter(chCount)");
235 oObj
.getCharacter(chCount
);
236 log
.println("Exception was expected");
238 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
239 log
.println("Expected exception");
244 log
.println("Checking of every character in the text...");
246 boolean isEqCh
= true;
248 for (int i
= 0; i
< chCount
; i
++) {
249 char ch
= oObj
.getCharacter(i
);
250 isEqCh
= ch
== text
.charAt(i
);
254 log
.println("At the position " + i
+
255 "was expected character: " + text
.charAt(i
));
256 log
.println("but was returned: " + ch
);
261 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
262 log
.println("Unexpected exception");
263 e
.printStackTrace(log
);
267 tRes
.tested("getCharacter()", res
);
271 * Calls the method with the wrong indexes and with the correct index,
272 * checks a returned value.
273 * Has OK status if exception was thrown for the wrong indexes,
274 * if exception wasn't thrown for the correct index and
275 * if returned value isn't <code>null</code>.
276 * The following method tests are to be executed before:
278 * <li> <code>getCharacterCount()</code> </li>
281 public void _getCharacterAttributes() {
282 requiredMethod("getCharacterCount()");
285 String
[] attr
= new String
[] { "" };
288 log
.println("getCharacterAttributes(-1)");
289 oObj
.getCharacterAttributes(-1, attr
);
290 log
.println("Exception was expected");
292 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
293 log
.println("Expected exception");
295 } catch(com
.sun
.star
.beans
.UnknownPropertyException e
) {
296 log
.println("unexpected exception => FAILED");
297 e
.printStackTrace(log
);
302 log
.println("getCharacterAttributes(chCount = " + chCount
+ ")");
303 oObj
.getCharacterAttributes(chCount
, attr
);
304 log
.println("Exception was expected");
306 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
307 log
.println("Expected exception");
309 } catch(com
.sun
.star
.beans
.UnknownPropertyException e
) {
310 log
.println("unexpected exception => FAILED");
311 e
.printStackTrace(log
);
317 "getCharacterAttributes(chCount-1 = " + (chCount
- 1) + ")");
319 PropertyValue
[] props
= oObj
.getCharacterAttributes(chCount
- 1,
321 res
&= (props
!= null);
322 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
323 log
.println("Unexpected exception");
324 e
.printStackTrace(log
);
326 } catch(com
.sun
.star
.beans
.UnknownPropertyException e
) {
327 log
.println("unexpected exception => FAILED");
328 e
.printStackTrace(log
);
332 tRes
.tested("getCharacterAttributes()", res
);
336 * Calls the method with the wrong indexes and with the correct index.
337 * checks and stores a returned value.
338 * Has OK status if exception was thrown for the wrong indexes,
339 * if exception wasn't thrown for the correct index and
340 * if returned value isn't <code>null</code>.
341 * The following method tests are to be executed before:
343 * <li> <code>getCharacterCount()</code> </li>
346 public void _getCharacterBounds() {
347 requiredMethod("getCharacterCount()");
351 int lastIndex
= chCount
;
353 if (LimitedBounds
!= null) {
354 if (LimitedBounds
instanceof Integer
) {
355 lastIndex
= ((Integer
) LimitedBounds
).intValue();
357 lastIndex
= chCount
- 1;
360 log
.println(LimitedBounds
);
364 log
.println("getCharacterBounds(-1)");
365 oObj
.getCharacterBounds(-1);
366 log
.println("Exception was expected");
368 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
369 log
.println("Expected exception");
374 log
.println("getCharacterBounds(" + (lastIndex
+ 1) + ")");
375 oObj
.getCharacterBounds(lastIndex
+ 1);
376 log
.println("Exception was expected");
378 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
379 log
.println("Expected exception");
384 for (int i
= 0; i
< lastIndex
; i
++) {
385 log
.println("getCharacterBounds(" + i
+ ")");
386 chBounds
= oObj
.getCharacterBounds(i
);
388 boolean localres
= true;
389 localres
= chBounds
.X
>= 0;
390 localres
&= (chBounds
.Y
>= 0);
391 localres
&= ((chBounds
.X
+ chBounds
.Width
) <= bounds
.Width
);
392 localres
&= ((chBounds
.X
+ chBounds
.Width
) >= 0);
393 localres
&= ((chBounds
.Y
+ chBounds
.Height
) <= bounds
.Height
);
394 localres
&= ((chBounds
.Y
+ chBounds
.Height
) >= 0);
397 log
.println("Text at this place: "+oObj
.getCharacter(i
));
398 log
.println("Character bounds outside component");
399 log
.println("Character rect: " + chBounds
.X
+ ", " +
400 chBounds
.Y
+ ", " + chBounds
.Width
+ ", " +
402 log
.println("Component rect: " + bounds
.X
+ ", " +
403 bounds
.Y
+ ", " + bounds
.Width
+ ", " +
407 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
408 log
.println("Unexpected exception");
409 e
.printStackTrace(log
);
413 tRes
.tested("getCharacterBounds()", res
);
417 * Calls the method and stores a returned value to the variable
418 * <code>chCount</code>.
419 * Has OK status if a returned value is equal to the text length.
421 public void _getCharacterCount() {
422 chCount
= oObj
.getCharacterCount();
423 log
.println("Character count:" + chCount
);
425 boolean res
= chCount
== text
.length();
426 tRes
.tested("getCharacterCount()", res
);
430 * Calls the method for an invalid point and for the point of rectangle
431 * returned by the method <code>getCharacterBounds()</code>.
432 * Has OK status if returned value is equal to <code>-1</code> for an
433 * invalid point and if returned value is equal to <code>chCount-1</code>
435 * The following method tests are to be executed before:
437 * <li> <code>getCharacterBounds()</code> </li>
440 public void _getIndexAtPoint() {
441 //requiredMethod("getCharacterBounds()");
443 log
.print("getIndexAtPoint(-1, -1):");
445 Point pt
= new Point(-1, -1);
446 int index
= oObj
.getIndexAtPoint(pt
);
448 res
&= (index
== -1);
450 int lastIndex
= chCount
;
452 if (LimitedBounds
!= null) {
453 if (LimitedBounds
instanceof Integer
) {
454 lastIndex
= ((Integer
) LimitedBounds
).intValue();
456 lastIndex
= chCount
- 1;
459 log
.println(LimitedBounds
);
462 for (int i
= 0; i
< lastIndex
; i
++) {
463 Rectangle aRect
= null;
464 String text
= "empty";
467 aRect
= oObj
.getCharacterBounds(i
);
468 text
= oObj
.getTextAtIndex(i
, (short) 1).SegmentText
;
469 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
470 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
475 log
.print("aRect unexpected null");
479 int x
= aRect
.X
+ (aRect
.Width
/ 2);
480 int y
= aRect
.Y
+ (aRect
.Height
/ 2);
482 Point aPoint
= new Point(x
, y
);
483 int nIndex
= oObj
.getIndexAtPoint(aPoint
);
486 y
= aRect
.Y
+ (aRect
.Height
/ 2);
487 aPoint
= new Point(x
, y
);
488 int left
= oObj
.getIndexAtPoint(aPoint
);
492 int[] previous
= (int[]) tEnv
.getObjRelation("PreviousUsed");
494 if (previous
!= null) {
495 for (int k
= 0; k
< previous
.length
; k
++) {
496 if (i
== previous
[k
]) {
503 // for some letters the center of the rectangle isn't recognised
504 // in this case we are happy if the left border of the rectangle
505 // returns the correct value.
507 log
.println("## Method didn't work for Point (" + x
+ "," + y
+
509 log
.println("Expected Index " + i
);
510 log
.println("Gained Index: " + nIndex
);
511 log
.println("Left Border: "+left
);
512 log
.println("CharacterAtIndex: " + text
);
518 tRes
.tested("getIndexAtPoint()", res
);
522 * Checks a returned values after different calls of the method
523 * <code>setSelection()</code>.
524 * The following method tests are to be executed before:
526 * <li> <code>setSelection()</code> </li>
529 public void _getSelectedText() {
530 if (editOnly
!= null) {
531 log
.println(editOnly
);
532 throw new StatusException(Status
.skipped(true));
535 requiredMethod("setSelection()");
540 log
.println("setSelection(0, 0)");
541 oObj
.setSelection(0, 0);
542 log
.print("getSelectedText():");
544 String txt
= oObj
.getSelectedText();
545 log
.println("'" + txt
+ "'");
546 res
&= (txt
.length() == 0);
548 log
.println("setSelection(0, chCount)");
549 oObj
.setSelection(0, chCount
);
550 log
.print("getSelectedText():");
551 txt
= oObj
.getSelectedText();
552 log
.println("'" + txt
+ "'");
553 res
&= txt
.equals(text
);
556 log
.println("setSelection(1, chCount-1)");
557 oObj
.setSelection(1, chCount
- 1);
558 log
.print("getSelectedText():");
559 txt
= oObj
.getSelectedText();
560 log
.println("'" + txt
+ "'");
561 res
&= txt
.equals(text
.substring(1, chCount
- 1));
563 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
564 log
.println("Unexpected exception");
565 e
.printStackTrace(log
);
569 tRes
.tested("getSelectedText()", res
);
573 * Checks a returned values after different calls of the method
574 * <code>setSelection()</code>.
575 * The following method tests are to be executed before:
577 * <li> <code>setSelection()</code> </li>
580 public void _getSelectionStart() {
581 if (editOnly
!= null) {
582 log
.println(editOnly
);
583 throw new StatusException(Status
.skipped(true));
586 requiredMethod("setSelection()");
591 log
.println("setSelection(0, chCount)");
592 oObj
.setSelection(0, chCount
);
594 int start
= oObj
.getSelectionStart();
595 log
.println("getSelectionStart():" + start
);
599 log
.println("setSelection(1, chCount-1)");
600 oObj
.setSelection(1, chCount
- 1);
601 start
= oObj
.getSelectionStart();
602 log
.println("getSelectionStart():" + start
);
605 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
606 log
.println("Unexpected exception");
607 e
.printStackTrace(log
);
611 tRes
.tested("getSelectionStart()", res
);
615 * Checks a returned values after different calls of the method
616 * <code>setSelection()</code>.
617 * The following method tests are to be executed before:
619 * <li> <code>setSelection()</code> </li>
622 public void _getSelectionEnd() {
623 if (editOnly
!= null) {
624 log
.println(editOnly
);
625 throw new StatusException(Status
.skipped(true));
628 requiredMethod("setSelection()");
633 log
.println("setSelection(0, chCount)");
634 oObj
.setSelection(0, chCount
);
636 int end
= oObj
.getSelectionEnd();
637 log
.println("getSelectionEnd():" + end
);
638 res
&= (end
== chCount
);
641 log
.println("setSelection(1, chCount-1)");
642 oObj
.setSelection(1, chCount
- 1);
643 end
= oObj
.getSelectionEnd();
644 log
.println("getSelectionEnd():" + end
);
645 res
&= (end
== (chCount
- 1));
647 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
648 log
.println("Unexpected exception");
649 e
.printStackTrace(log
);
653 tRes
.tested("getSelectionEnd()", res
);
657 * Calls the method with invalid parameters and with valid parameters.
658 * Has OK status if exception was thrown for invalid parameters,
659 * if exception wasn't thrown for valid parameters.
660 * The following method tests are to be executed before:
662 * <li> <code>getCharacterCount()</code> </li>
665 public void _setSelection() {
666 requiredMethod("getCharacterCount()");
669 boolean locRes
= true;
671 if (editOnly
!= null) {
672 log
.println(editOnly
);
673 throw new StatusException(Status
.skipped(true));
677 log
.print("setSelection(-1, chCount-1):");
678 locRes
= oObj
.setSelection(-1, chCount
- 1);
679 log
.println(locRes
+ " exception was expected");
681 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
682 log
.println("Expected exception");
687 log
.print("setSelection(0, chCount+1):");
688 locRes
= oObj
.setSelection(0, chCount
+ 1);
689 log
.println(locRes
+ " exception was expected");
691 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
692 log
.println("Expected exception");
698 log
.print("setSelection(1, chCount-1):");
699 locRes
= oObj
.setSelection(1, chCount
- 1);
703 log
.print("setSelection(chCount-1, 1):");
704 locRes
= oObj
.setSelection(chCount
- 1, 1);
709 log
.print("setSelection(0, chCount-1):");
710 locRes
= oObj
.setSelection(0, chCount
- 1);
714 log
.print("setSelection(chCount-1, 0):");
715 locRes
= oObj
.setSelection(chCount
- 1, 0);
719 log
.print("setSelection(0, 0):");
720 locRes
= oObj
.setSelection(0, 0);
723 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
724 log
.println("Unexpected exception");
725 e
.printStackTrace(log
);
729 tRes
.tested("setSelection()", res
);
733 * Calls the method and checks returned value.
734 * Has OK status if returned string is equal to string
735 * received from relation.
737 public void _getText() {
738 String txt
= oObj
.getText();
739 log
.println("getText: " + txt
);
741 boolean res
= txt
.equals(text
);
742 tRes
.tested("getText()", res
);
746 * Calls the method with invalid parameters and with valid parameters,
747 * checks returned values.
748 * Has OK status if exception was thrown for invalid parameters,
749 * if exception wasn't thrown for valid parameters and if returned values
750 * are equal to corresponding substrings of the text received by relation.
751 * The following method tests are to be executed before:
753 * <li> <code>getCharacterCount()</code> </li>
756 public void _getTextRange() {
757 requiredMethod("getCharacterCount()");
760 boolean locRes
= true;
762 String txtRange
= "";
766 log
.print("getTextRange(1, chCount - 2): ");
768 txtRange
= oObj
.getTextRange(1, chCount
- 2);
769 log
.println(txtRange
);
770 locRes
= txtRange
.equals(text
.substring(1, chCount
- 2));
774 log
.println("Was expected: " +
775 text
.substring(1, chCount
- 2));
779 log
.print("getTextRange(0, chCount-1): ");
781 txtRange
= oObj
.getTextRange(0, chCount
- 1);
782 log
.println(txtRange
);
783 locRes
= txtRange
.equals(text
.substring(0, chCount
- 1));
787 log
.println("Was expected: " +
788 text
.substring(0, chCount
- 1));
791 log
.print("getTextRange(chCount, 0): ");
792 txtRange
= oObj
.getTextRange(chCount
, 0);
793 log
.println(txtRange
);
794 res
&= txtRange
.equals(text
);
796 log
.print("getTextRange(0, 0): ");
797 txtRange
= oObj
.getTextRange(0, 0);
798 log
.println(txtRange
);
799 locRes
= txtRange
.equals("");
803 log
.println("Empty string was expected");
805 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
806 log
.println("Unexpected exception");
807 e
.printStackTrace(log
);
812 log
.print("getTextRange(-1, chCount - 1): ");
814 txtRange
= oObj
.getTextRange(-1, chCount
- 1);
815 log
.println("Exception was expected");
817 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
818 log
.println("Expected exception");
823 log
.print("getTextRange(0, chCount + 1): ");
825 txtRange
= oObj
.getTextRange(0, chCount
+ 1);
826 log
.println("Exception was expected");
828 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
829 log
.println("Expected exception");
834 log
.print("getTextRange(chCount+1, -1): ");
836 txtRange
= oObj
.getTextRange(chCount
+ 1, -1);
837 log
.println("Exception was expected");
839 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
840 log
.println("Expected exception");
844 tRes
.tested("getTextRange()", res
);
848 * Calls the method with invalid parameters and with valid parameters,
849 * checks returned values.
850 * Has OK status if exception was thrown for invalid parameters,
851 * if exception wasn't thrown for valid parameters and if returned values
852 * are equal to corresponding substrings of the text received by relation.
853 * The following method tests are to be executed before:
855 * <li> <code>getCharacterCount()</code> </li>
858 public void _getTextAtIndex() {
859 requiredMethod("getCharacterCount()");
860 TextSegment txt
= null;
864 log
.print("getTextAtIndex(-1, AccessibleTextType.PARAGRAPH):");
866 txt
= oObj
.getTextAtIndex(-1,
867 AccessibleTextType
.PARAGRAPH
);
868 log
.println("Exception was expected");
870 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
871 log
.println("Expected exception");
873 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
874 log
.println("UnExpected exception");
879 log
.print("getTextAtIndex(chCount+1," +
880 " AccessibleTextType.PARAGRAPH):");
882 txt
= oObj
.getTextAtIndex(chCount
+ 1,
883 AccessibleTextType
.PARAGRAPH
);
884 log
.println("Exception was expected");
886 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
887 log
.println("Expected exception");
889 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
890 log
.println("UnExpected exception");
895 log
.print("getTextAtIndex(chCount," +
896 " AccessibleTextType.WORD):");
898 txt
= oObj
.getTextAtIndex(chCount
, AccessibleTextType
.WORD
);
899 log
.println("'" + txt
.SegmentText
+ "'");
900 res
&= compareLength(0,txt
.SegmentText
);
901 if (!tEnv
.getTestCase().getObjectName().equals("SmGraphicAccessible")) {
902 log
.print("getTextAtIndex(1," +
903 " AccessibleTextType.PARAGRAPH):");
904 txt
= oObj
.getTextAtIndex(1, AccessibleTextType
.PARAGRAPH
);
905 log
.println("'" + txt
.SegmentText
+ "'");
906 res
&= compareStrings(text
,txt
.SegmentText
);
908 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
909 log
.println("Unexpected exception");
910 e
.printStackTrace(log
);
912 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
913 log
.println("Unexpected exception");
914 e
.printStackTrace(log
);
918 tRes
.tested("getTextAtIndex()", res
);
922 * Calls the method with invalid parameters and with valid parameters,
923 * checks returned values.
924 * Has OK status if exception was thrown for invalid parameters,
925 * if exception wasn't thrown for valid parameters and if returned values
926 * are equal to corresponding substrings of the text received by relation.
927 * The following method tests are to be executed before:
929 * <li> <code>getCharacterCount()</code> </li>
932 public void _getTextBeforeIndex() {
933 requiredMethod("getCharacterCount()");
934 TextSegment txt
= null;
938 log
.print("getTextBeforeIndex(-1, AccessibleTextType.PARAGRAPH):");
940 txt
= oObj
.getTextBeforeIndex(-1,
941 AccessibleTextType
.PARAGRAPH
);
942 log
.println("Exception was expected");
944 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
945 log
.println("Expected exception");
947 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
948 log
.println("UnExpected exception");
953 log
.print("getTextBeforeIndex(chCount+1, " +
954 "AccessibleTextType.PARAGRAPH):");
956 txt
= oObj
.getTextBeforeIndex(chCount
+ 1,
957 AccessibleTextType
.PARAGRAPH
);
958 log
.println("Exception was expected");
960 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
961 log
.println("Expected exception");
963 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
964 log
.println("UnExpected exception");
969 if (!tEnv
.getTestCase().getObjectName().equals("SmGraphicAccessible")
970 // next one fails because the control actually contains 2 words
971 && !tEnv
.getTestCase().getObjectName().equals("AccessibleStatusBarItem"))
973 log
.print("getTextBeforeIndex(chCount," +
974 " AccessibleTextType.WORD):");
976 txt
= oObj
.getTextBeforeIndex(chCount
,
977 AccessibleTextType
.WORD
);
978 log
.println("'" + txt
.SegmentText
+ "'");
979 res
&= compareLength(chCount
, txt
.SegmentText
);
982 log
.print("getTextBeforeIndex(1," +
983 " AccessibleTextType.PARAGRAPH):");
984 txt
= oObj
.getTextBeforeIndex(1, AccessibleTextType
.PARAGRAPH
);
985 log
.println("'" + txt
.SegmentText
+ "'");
986 res
&= compareLength(0, txt
.SegmentText
);
988 log
.print("getTextBeforeIndex(chCount-1," +
989 " AccessibleTextType.CHARACTER):");
990 txt
= oObj
.getTextBeforeIndex(chCount
- 1,
991 AccessibleTextType
.CHARACTER
);
992 log
.println("'" + txt
.SegmentText
+ "'");
993 res
&= compareStrings(text
.substring(chCount
- 2, chCount
- 1),
997 log
.print("getTextBeforeIndex(2," +
998 " AccessibleTextType.CHARACTER):");
999 txt
= oObj
.getTextBeforeIndex(2, AccessibleTextType
.CHARACTER
);
1000 log
.println("'" + txt
.SegmentText
+ "'");
1001 res
&= compareStrings(text
.substring(1, 2), txt
.SegmentText
);
1003 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
1004 log
.println("Unexpected exception");
1005 e
.printStackTrace(log
);
1007 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
1008 log
.println("Unexpected exception");
1009 e
.printStackTrace(log
);
1013 tRes
.tested("getTextBeforeIndex()", res
);
1017 * Calls the method with invalid parameters and with valid parameters,
1018 * checks returned values.
1019 * Has OK status if exception was thrown for invalid parameters,
1020 * if exception wasn't thrown for valid parameters and if returned values
1021 * are equal to corresponding substrings of the text received by relation.
1022 * The following method tests are to be executed before:
1024 * <li> <code>getCharacterCount()</code> </li>
1027 public void _getTextBehindIndex() {
1028 requiredMethod("getCharacterCount()");
1029 TextSegment txt
= null;
1033 log
.print("getTextBehindIndex(-1, AccessibleTextType.PARAGRAPH):");
1035 txt
= oObj
.getTextBehindIndex(-1,
1036 AccessibleTextType
.PARAGRAPH
);
1037 log
.println("Exception was expected");
1039 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
1040 log
.println("Expected exception");
1042 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
1043 log
.println("UnExpected exception");
1048 log
.print("getTextBehindIndex(chCount+1, " +
1049 "AccessibleTextType.PARAGRAPH):");
1051 txt
= oObj
.getTextBehindIndex(chCount
+ 1,
1052 AccessibleTextType
.PARAGRAPH
);
1053 log
.println("Exception was expected");
1055 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
1056 log
.println("Expected exception");
1058 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
1059 log
.println("UnExpected exception");
1064 log
.print("getTextBehindIndex(chCount," +
1065 " AccessibleTextType.PARAGRAPH):");
1067 txt
= oObj
.getTextBehindIndex(chCount
,
1068 AccessibleTextType
.PARAGRAPH
);
1069 log
.println("'" + txt
.SegmentText
+ "'");
1070 res
&= (txt
.SegmentText
.length() == 0);
1072 log
.print("getTextBehindIndex(chCount-1," +
1073 " AccessibleTextType.PARAGRAPH):");
1074 txt
= oObj
.getTextBehindIndex(chCount
- 1,
1075 AccessibleTextType
.PARAGRAPH
);
1076 log
.println("'" + txt
.SegmentText
+ "'");
1077 res
&= (txt
.SegmentText
.length() == 0);
1079 log
.print("getTextBehindIndex(1," +
1080 " AccessibleTextType.CHARACTER):");
1081 txt
= oObj
.getTextBehindIndex(1, AccessibleTextType
.CHARACTER
);
1082 log
.println("'" + txt
.SegmentText
+ "'");
1083 res
&= txt
.SegmentText
.equals(text
.substring(2, 3));
1086 log
.print("getTextBehindIndex(chCount-2," +
1087 " AccessibleTextType.CHARACTER):");
1088 txt
= oObj
.getTextBehindIndex(chCount
- 2,
1089 AccessibleTextType
.CHARACTER
);
1090 log
.println("'" + txt
.SegmentText
+ "'");
1091 res
&= txt
.SegmentText
.equals(text
.substring(chCount
- 1, chCount
));
1093 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
1094 log
.println("Unexpected exception");
1095 e
.printStackTrace(log
);
1097 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
1098 log
.println("Unexpected exception");
1099 e
.printStackTrace(log
);
1103 tRes
.tested("getTextBehindIndex()", res
);
1107 * Calls the method with invalid parameters and with valid parameter,
1108 * checks returned values.
1109 * Has OK status if exception was thrown for invalid parameters,
1110 * if exception wasn't thrown for valid parameter and if returned value for
1111 * valid parameter is equal to <code>true</code>.
1113 public void _copyText() {
1115 boolean locRes
= true;
1117 if (editOnly
!= null) {
1118 log
.println(editOnly
);
1119 throw new StatusException(Status
.skipped(true));
1123 log
.print("copyText(-1,chCount):");
1124 oObj
.copyText(-1, chCount
);
1125 log
.println("Exception was expected");
1127 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
1128 log
.println("Expected exception");
1133 log
.print("copyText(0,chCount+1):");
1134 oObj
.copyText(0, chCount
+ 1);
1135 log
.println("Exception was expected");
1137 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
1138 log
.println("Expected exception");
1143 log
.print("copyText(0,chCount):");
1144 locRes
= oObj
.copyText(0, chCount
);
1145 log
.println(locRes
);
1148 String cbText
= null;
1151 cbText
= util
.SysUtils
.getSysClipboardText(tParam
.getMSF());
1152 } catch (com
.sun
.star
.uno
.Exception e
) {
1153 log
.println("Couldn't access system clipboard :");
1154 e
.printStackTrace(log
);
1157 log
.println("Clipboard: '" + cbText
+ "'");
1158 res
&= text
.equals(cbText
);
1161 log
.print("copyText(1,chCount-1):");
1162 locRes
= oObj
.copyText(1, chCount
- 1);
1163 log
.println(locRes
);
1167 cbText
= util
.SysUtils
.getSysClipboardText(tParam
.getMSF());
1168 } catch (com
.sun
.star
.uno
.Exception e
) {
1169 log
.println("Couldn't access system clipboard :");
1170 e
.printStackTrace(log
);
1173 log
.println("Clipboard: '" + cbText
+ "'");
1174 res
&= text
.substring(1, chCount
- 1).equals(cbText
);
1176 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
1177 log
.println("Unexpected exception");
1178 e
.printStackTrace(log
);
1182 tRes
.tested("copyText()", res
);
1185 public boolean compareStrings(String expected
, String getting
) {
1186 boolean res
= expected
.equals(getting
);
1189 log
.println("## The result isn't the expected:");
1190 log
.println("\tGetting: " + getting
);
1191 log
.println("\tExpected: " + expected
);
1197 public boolean compareLength(int expected
, String getting
) {
1198 boolean res
= (expected
== getting
.length());
1201 log
.println("## The result isn't the expected:");
1202 log
.println("\tGetting: " + getting
.length());
1203 log
.println("\tExpected: " + expected
);