1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
27 package ifc
.accessibility
;
29 import lib
.MultiMethodTest
;
31 import lib
.StatusException
;
33 import com
.sun
.star
.accessibility
.AccessibleTextType
;
34 import com
.sun
.star
.accessibility
.TextSegment
;
35 import com
.sun
.star
.accessibility
.XAccessibleComponent
;
36 import com
.sun
.star
.accessibility
.XAccessibleText
;
37 import com
.sun
.star
.awt
.Point
;
38 import com
.sun
.star
.awt
.Rectangle
;
39 import com
.sun
.star
.beans
.PropertyValue
;
40 import com
.sun
.star
.lang
.XMultiServiceFactory
;
41 import com
.sun
.star
.uno
.UnoRuntime
;
45 * Testing <code>com.sun.star.accessibility.XAccessibleText</code>
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>
66 * This test needs the following object relations :
68 * <li> <code>'XAccessibleText.Text'</code> (of type <code>String</code>)
70 * the string presentation of component's text. If the relation
71 * is not specified, then text from method <code>getText()</code>
75 * @see com.sun.star.accessibility.XAccessibleText
77 public class _XAccessibleText
extends MultiMethodTest
{
79 public XAccessibleText oObj
= null;
80 protected com
.sun
.star
.awt
.Rectangle bounds
= null;
82 String editOnly
= null;
83 Object LimitedBounds
= null;
84 Rectangle chBounds
= null;
89 * Retrieves a string representation of the component's text.
90 * The length of retrieved string must be greater than zero.
92 protected void before() {
93 Object xat
= tEnv
.getObjRelation("XAccessibleText");
95 XAccessibleComponent component
= null;
98 oObj
= (XAccessibleText
) UnoRuntime
.queryInterface(
99 XAccessibleText
.class, xat
);
100 component
= (XAccessibleComponent
) UnoRuntime
.queryInterface(
101 XAccessibleComponent
.class, xat
);
104 text
= (String
) tEnv
.getObjRelation("XAccessibleText.Text");
107 text
= oObj
.getText();
110 if (text
.length() == 0) {
111 throw new StatusException(Status
.failed(
112 "The length of text must be greater than zero"));
115 editOnly
= (String
) tEnv
.getObjRelation("EditOnly");
116 LimitedBounds
= tEnv
.getObjRelation("LimitedBounds");
118 if (component
== null) {
119 component
= (XAccessibleComponent
) UnoRuntime
.queryInterface(
120 XAccessibleComponent
.class,
121 tEnv
.getTestObject());
124 bounds
= component
.getBounds();
126 log
.println("Text is '" + text
+ "'");
127 System
.out
.println("############################");
131 * Calls the method and checks returned value.
132 * Has OK status if returned value is equal to <code>chCount - 1</code>.
133 * The following method tests are to be executed before:
135 * <li> <code>setCaretPosition()</code> </li>
138 public void _getCaretPosition() {
139 requiredMethod("getCharacterCount()");
141 if (editOnly
!= null) {
142 log
.println(editOnly
);
143 throw new StatusException(Status
.skipped(true));
150 oObj
.setCaretPosition(chCount
- 1);
151 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException ie
) {
154 int carPos
= oObj
.getCaretPosition();
155 log
.println("getCaretPosition: " + carPos
);
158 res
= carPos
== (chCount
- 1);
161 "Object is read only and Caret position couldn't be set");
165 tRes
.tested("getCaretPosition()", res
);
169 * Calls the method with the wrong index and with the correct index
170 * <code>chCount - 1</code>.
171 * Has OK status if exception was thrown for wrong index and
172 * if exception wasn't thrown for the correct index.
173 * The following method tests are to be executed before:
175 * <li> <code>getCharacterCount()</code> </li>
178 public void _setCaretPosition() {
179 requiredMethod("getCharacterCount()");
184 log
.print("setCaretPosition(-1):");
185 oObj
.setCaretPosition(-1);
187 log
.println("exception was expected ... FAILED");
188 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
189 log
.println("expected exception");
194 log
.print("setCaretPosition(chCount+1):");
195 oObj
.setCaretPosition(chCount
+ 1);
197 log
.println("exception was expected ... FAILED");
198 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
199 log
.println("expected exception");
204 log
.println("setCaretPosition(chCount - 1)");
205 oObj
.setCaretPosition(chCount
- 1);
207 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
208 log
.println("unexpected exception ... FAILED");
209 e
.printStackTrace(log
);
213 tRes
.tested("setCaretPosition()", res
);
217 * Calls the method with the wrong index and with the correct indexes.
218 * Checks every character in the text.
219 * Has OK status if exception was thrown for wrong index,
220 * if exception wasn't thrown for the correct index and
221 * if every character is equal to corresponding character in the text.
222 * The following method tests are to be executed before:
224 * <li> <code>getCharacterCount()</code> </li>
227 public void _getCharacter() {
228 requiredMethod("getCharacterCount()");
233 log
.println("getCharacter(-1)");
234 oObj
.getCharacter(-1);
235 log
.println("Exception was expected");
237 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
238 log
.println("Expected exception");
243 log
.println("getCharacter(chCount)");
244 oObj
.getCharacter(chCount
);
245 log
.println("Exception was expected");
247 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
248 log
.println("Expected exception");
253 log
.println("Checking of every character in the text...");
255 boolean isEqCh
= true;
257 for (int i
= 0; i
< chCount
; i
++) {
258 char ch
= oObj
.getCharacter(i
);
259 isEqCh
= ch
== text
.charAt(i
);
263 log
.println("At the position " + i
+
264 "was expected character: " + text
.charAt(i
));
265 log
.println("but was returned: " + ch
);
270 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
271 log
.println("Unexpected exception");
272 e
.printStackTrace(log
);
276 tRes
.tested("getCharacter()", res
);
280 * Calls the method with the wrong indexes and with the correct index,
281 * checks a returned value.
282 * Has OK status if exception was thrown for the wrong indexes,
283 * if exception wasn't thrown for the correct index and
284 * if returned value isn't <code>null</code>.
285 * The following method tests are to be executed before:
287 * <li> <code>getCharacterCount()</code> </li>
290 public void _getCharacterAttributes() {
291 requiredMethod("getCharacterCount()");
294 String
[] attr
= new String
[] { "" };
297 log
.println("getCharacterAttributes(-1)");
298 oObj
.getCharacterAttributes(-1, attr
);
299 log
.println("Exception was expected");
301 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
302 log
.println("Expected exception");
307 log
.println("getCharacterAttributes(chCount)");
308 oObj
.getCharacterAttributes(chCount
, attr
);
309 log
.println("Exception was expected");
311 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
312 log
.println("Expected exception");
317 log
.println("getCharacterAttributes(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
);
328 tRes
.tested("getCharacterAttributes()", res
);
332 * Calls the method with the wrong indexes and with the correct index.
333 * checks and stores a returned value.
334 * Has OK status if exception was thrown for the wrong indexes,
335 * if exception wasn't thrown for the correct index and
336 * if returned value isn't <code>null</code>.
337 * The following method tests are to be executed before:
339 * <li> <code>getCharacterCount()</code> </li>
342 public void _getCharacterBounds() {
343 requiredMethod("getCharacterCount()");
347 int lastIndex
= chCount
;
349 if (LimitedBounds
!= null) {
350 if (LimitedBounds
instanceof Integer
) {
351 lastIndex
= ((Integer
) LimitedBounds
).intValue();
353 lastIndex
= chCount
- 1;
356 log
.println(LimitedBounds
);
360 log
.println("getCharacterBounds(-1)");
361 oObj
.getCharacterBounds(-1);
362 log
.println("Exception was expected");
364 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
365 log
.println("Expected exception");
370 log
.println("getCharacterBounds(" + (lastIndex
+ 1) + ")");
371 oObj
.getCharacterBounds(lastIndex
+ 1);
372 log
.println("Exception was expected");
374 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
375 log
.println("Expected exception");
380 for (int i
= 0; i
< lastIndex
; i
++) {
381 log
.println("getCharacterBounds(" + i
+ ")");
382 chBounds
= oObj
.getCharacterBounds(i
);
384 boolean localres
= true;
385 localres
= chBounds
.X
>= 0;
386 localres
&= (chBounds
.Y
>= 0);
387 localres
&= ((chBounds
.X
+ chBounds
.Width
) <= bounds
.Width
);
388 localres
&= ((chBounds
.X
+ chBounds
.Width
) >= 0);
389 localres
&= ((chBounds
.Y
+ chBounds
.Height
) <= bounds
.Height
);
390 localres
&= ((chBounds
.Y
+ chBounds
.Height
) >= 0);
393 log
.println("Text at this place: "+oObj
.getCharacter(i
));
394 log
.println("Character bounds outside component");
395 log
.println("Character rect: " + chBounds
.X
+ ", " +
396 chBounds
.Y
+ ", " + chBounds
.Width
+ ", " +
398 log
.println("Component rect: " + bounds
.X
+ ", " +
399 bounds
.Y
+ ", " + bounds
.Width
+ ", " +
404 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
405 log
.println("Unexpected exception");
406 e
.printStackTrace(log
);
410 tRes
.tested("getCharacterBounds()", res
);
414 * Calls the method and stores a returned value to the variable
415 * <code>chCount</code>.
416 * Has OK status if a returned value is equal to the text length.
418 public void _getCharacterCount() {
419 chCount
= oObj
.getCharacterCount();
420 log
.println("Character count:" + chCount
);
422 boolean res
= chCount
== text
.length();
423 tRes
.tested("getCharacterCount()", res
);
427 * Calls the method for an invalid point and for the point of rectangle
428 * returned by the method <code>getCharacterBounds()</code>.
429 * Has OK status if returned value is equal to <code>-1</code> for an
430 * invalid point and if returned value is equal to <code>chCount-1</code>
432 * The following method tests are to be executed before:
434 * <li> <code>getCharacterBounds()</code> </li>
437 public void _getIndexAtPoint() {
438 //requiredMethod("getCharacterBounds()");
440 log
.print("getIndexAtPoint(-1, -1):");
442 Point pt
= new Point(-1, -1);
443 int index
= oObj
.getIndexAtPoint(pt
);
445 res
&= (index
== -1);
447 int lastIndex
= chCount
;
449 if (LimitedBounds
!= null) {
450 if (LimitedBounds
instanceof Integer
) {
451 lastIndex
= ((Integer
) LimitedBounds
).intValue();
453 lastIndex
= chCount
- 1;
456 log
.println(LimitedBounds
);
459 for (int i
= 0; i
< lastIndex
; i
++) {
460 Rectangle aRect
= null;
461 String text
= "empty";
464 aRect
= oObj
.getCharacterBounds(i
);
465 text
= oObj
.getTextAtIndex(i
, (short) 1).SegmentText
;
466 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
467 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
470 int x
= aRect
.X
+ (aRect
.Width
/ 2);
471 int y
= aRect
.Y
+ (aRect
.Height
/ 2);
472 Point aPoint
= new Point(x
, y
);
473 int nIndex
= oObj
.getIndexAtPoint(aPoint
);
476 y
= aRect
.Y
+ (aRect
.Height
/ 2);
477 aPoint
= new Point(x
, y
);
478 int left
= oObj
.getIndexAtPoint(aPoint
);
482 int[] previous
= (int[]) tEnv
.getObjRelation("PreviousUsed");
484 if (previous
!= null) {
485 for (int k
= 0; k
< previous
.length
; k
++) {
486 if (i
== previous
[k
]) {
493 // for some letters the center of the rectangle isn't recognised
494 // in this case we are happy if the left border of the rectangle
495 // returns the correct value.
497 log
.println("## Method didn't work for Point (" + x
+ "," + y
+
499 log
.println("Expected Index " + i
);
500 log
.println("Gained Index: " + nIndex
);
501 log
.println("Left Border: "+left
);
502 log
.println("CharacterAtIndex: " + text
);
508 tRes
.tested("getIndexAtPoint()", res
);
512 * Checks a returned values after different calls of the method
513 * <code>setSelection()</code>.
514 * The following method tests are to be executed before:
516 * <li> <code>setSelection()</code> </li>
519 public void _getSelectedText() {
520 if (editOnly
!= null) {
521 log
.println(editOnly
);
522 throw new StatusException(Status
.skipped(true));
525 requiredMethod("setSelection()");
530 log
.println("setSelection(0, 0)");
531 oObj
.setSelection(0, 0);
532 log
.print("getSelectedText():");
534 String txt
= oObj
.getSelectedText();
535 log
.println("'" + txt
+ "'");
536 res
&= (txt
.length() == 0);
538 log
.println("setSelection(0, chCount)");
539 oObj
.setSelection(0, chCount
);
540 log
.print("getSelectedText():");
541 txt
= oObj
.getSelectedText();
542 log
.println("'" + txt
+ "'");
543 res
&= txt
.equals(text
);
546 log
.println("setSelection(1, chCount-1)");
547 oObj
.setSelection(1, chCount
- 1);
548 log
.print("getSelectedText():");
549 txt
= oObj
.getSelectedText();
550 log
.println("'" + txt
+ "'");
551 res
&= txt
.equals(text
.substring(1, chCount
- 1));
553 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
554 log
.println("Unexpected exception");
555 e
.printStackTrace(log
);
559 tRes
.tested("getSelectedText()", res
);
563 * Checks a returned values after different calls of the method
564 * <code>setSelection()</code>.
565 * The following method tests are to be executed before:
567 * <li> <code>setSelection()</code> </li>
570 public void _getSelectionStart() {
571 if (editOnly
!= null) {
572 log
.println(editOnly
);
573 throw new StatusException(Status
.skipped(true));
576 requiredMethod("setSelection()");
581 log
.println("setSelection(0, chCount)");
582 oObj
.setSelection(0, chCount
);
584 int start
= oObj
.getSelectionStart();
585 log
.println("getSelectionStart():" + start
);
589 log
.println("setSelection(1, chCount-1)");
590 oObj
.setSelection(1, chCount
- 1);
591 start
= oObj
.getSelectionStart();
592 log
.println("getSelectionStart():" + start
);
595 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
596 log
.println("Unexpected exception");
597 e
.printStackTrace(log
);
601 tRes
.tested("getSelectionStart()", res
);
605 * Checks a returned values after different calls of the method
606 * <code>setSelection()</code>.
607 * The following method tests are to be executed before:
609 * <li> <code>setSelection()</code> </li>
612 public void _getSelectionEnd() {
613 if (editOnly
!= null) {
614 log
.println(editOnly
);
615 throw new StatusException(Status
.skipped(true));
618 requiredMethod("setSelection()");
623 log
.println("setSelection(0, chCount)");
624 oObj
.setSelection(0, chCount
);
626 int end
= oObj
.getSelectionEnd();
627 log
.println("getSelectionEnd():" + end
);
628 res
&= (end
== chCount
);
631 log
.println("setSelection(1, chCount-1)");
632 oObj
.setSelection(1, chCount
- 1);
633 end
= oObj
.getSelectionEnd();
634 log
.println("getSelectionEnd():" + end
);
635 res
&= (end
== (chCount
- 1));
637 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
638 log
.println("Unexpected exception");
639 e
.printStackTrace(log
);
643 tRes
.tested("getSelectionEnd()", res
);
647 * Calls the method with invalid parameters an with valid parameters.
648 * Has OK status if exception was thrown for invalid parameters,
649 * if exception wasn't thrown for valid parameters.
650 * The following method tests are to be executed before:
652 * <li> <code>getCharacterCount()</code> </li>
655 public void _setSelection() {
656 requiredMethod("getCharacterCount()");
659 boolean locRes
= true;
661 if (editOnly
!= null) {
662 log
.println(editOnly
);
663 throw new StatusException(Status
.skipped(true));
667 log
.print("setSelection(-1, chCount-1):");
668 locRes
= oObj
.setSelection(-1, chCount
- 1);
669 log
.println(locRes
+ " excepion was expected");
671 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
672 log
.println("Expected exception");
677 log
.print("setSelection(0, chCount+1):");
678 locRes
= oObj
.setSelection(0, chCount
+ 1);
679 log
.println(locRes
+ " excepion was expected");
681 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
682 log
.println("Expected exception");
688 log
.print("setSelection(1, chCount-1):");
689 locRes
= oObj
.setSelection(1, chCount
- 1);
693 log
.print("setSelection(chCount-1, 1):");
694 locRes
= oObj
.setSelection(chCount
- 1, 1);
699 log
.print("setSelection(0, chCount-1):");
700 locRes
= oObj
.setSelection(0, chCount
- 1);
704 log
.print("setSelection(chCount-1, 0):");
705 locRes
= oObj
.setSelection(chCount
- 1, 0);
709 log
.print("setSelection(0, 0):");
710 locRes
= oObj
.setSelection(0, 0);
713 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
714 log
.println("Unexpected exception");
715 e
.printStackTrace(log
);
719 tRes
.tested("setSelection()", res
);
723 * Calls the method and checks returned value.
724 * Has OK status if returned string is equal to string
725 * received from relation.
727 public void _getText() {
728 String txt
= oObj
.getText();
729 log
.println("getText: " + txt
);
731 boolean res
= txt
.equals(text
);
732 tRes
.tested("getText()", res
);
736 * Calls the method with invalid parameters an with valid parameters,
737 * checks returned values.
738 * Has OK status if exception was thrown for invalid parameters,
739 * if exception wasn't thrown for valid parameters and if returned values
740 * are equal to corresponding substrings of the text received by relation.
741 * The following method tests are to be executed before:
743 * <li> <code>getCharacterCount()</code> </li>
746 public void _getTextRange() {
747 requiredMethod("getCharacterCount()");
750 boolean locRes
= true;
752 String txtRange
= "";
756 log
.print("getTextRange(1, chCount - 2): ");
758 txtRange
= oObj
.getTextRange(1, chCount
- 2);
759 log
.println(txtRange
);
760 locRes
= txtRange
.equals(text
.substring(1, chCount
- 2));
764 log
.println("Was expected: " +
765 text
.substring(1, chCount
- 2));
769 log
.print("getTextRange(0, chCount-1): ");
771 txtRange
= oObj
.getTextRange(0, chCount
- 1);
772 log
.println(txtRange
);
773 locRes
= txtRange
.equals(text
.substring(0, chCount
- 1));
777 log
.println("Was expected: " +
778 text
.substring(0, chCount
- 1));
781 log
.print("getTextRange(chCount, 0): ");
782 txtRange
= oObj
.getTextRange(chCount
, 0);
783 log
.println(txtRange
);
784 res
&= txtRange
.equals(text
);
786 log
.print("getTextRange(0, 0): ");
787 txtRange
= oObj
.getTextRange(0, 0);
788 log
.println(txtRange
);
789 locRes
= txtRange
.equals("");
793 log
.println("Empty string was expected");
795 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
796 log
.println("Unexpected exception");
797 e
.printStackTrace(log
);
802 log
.print("getTextRange(-1, chCount - 1): ");
804 txtRange
= oObj
.getTextRange(-1, chCount
- 1);
805 log
.println("Exception was expected");
807 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
808 log
.println("Expected exception");
813 log
.print("getTextRange(0, chCount + 1): ");
815 txtRange
= oObj
.getTextRange(0, chCount
+ 1);
816 log
.println("Exception was expected");
818 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
819 log
.println("Expected exception");
824 log
.print("getTextRange(chCount+1, -1): ");
826 txtRange
= oObj
.getTextRange(chCount
+ 1, -1);
827 log
.println("Exception was expected");
829 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
830 log
.println("Expected exception");
834 tRes
.tested("getTextRange()", res
);
838 * Calls the method with invalid parameters an with valid parameters,
839 * checks returned values.
840 * Has OK status if exception was thrown for invalid parameters,
841 * if exception wasn't thrown for valid parameters and if returned values
842 * are equal to corresponding substrings of the text received by relation.
843 * The following method tests are to be executed before:
845 * <li> <code>getCharacterCount()</code> </li>
848 public void _getTextAtIndex() {
849 requiredMethod("getCharacterCount()");
850 TextSegment txt
= null;
854 log
.print("getTextAtIndex(-1, AccessibleTextType.PARAGRAPH):");
856 txt
= oObj
.getTextAtIndex(-1,
857 AccessibleTextType
.PARAGRAPH
);
858 log
.println("Exception was expected");
860 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
861 log
.println("Expected exception");
863 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
864 log
.println("UnExpected exception");
869 log
.print("getTextAtIndex(chCount+1," +
870 " AccessibleTextType.PARAGRAPH):");
872 txt
= oObj
.getTextAtIndex(chCount
+ 1,
873 AccessibleTextType
.PARAGRAPH
);
874 log
.println("Exception was expected");
876 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
877 log
.println("Expected exception");
879 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
880 log
.println("UnExpected exception");
885 log
.print("getTextAtIndex(chCount," +
886 " AccessibleTextType.WORD):");
888 txt
= oObj
.getTextAtIndex(chCount
, AccessibleTextType
.WORD
);
889 log
.println("'" + txt
.SegmentText
+ "'");
890 res
&= compareLength(0,txt
.SegmentText
);
891 if (!tEnv
.getTestCase().getObjectName().equals("SmGraphicAccessible")) {
892 log
.print("getTextAtIndex(1," +
893 " AccessibleTextType.PARAGRAPH):");
894 txt
= oObj
.getTextAtIndex(1, AccessibleTextType
.PARAGRAPH
);
895 log
.println("'" + txt
.SegmentText
+ "'");
896 res
&= compareStrings(text
,txt
.SegmentText
);
898 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
899 log
.println("Unexpected exception");
900 e
.printStackTrace(log
);
902 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
903 log
.println("Unexpected exception");
904 e
.printStackTrace(log
);
908 tRes
.tested("getTextAtIndex()", res
);
912 * Calls the method with invalid parameters an with valid parameters,
913 * checks returned values.
914 * Has OK status if exception was thrown for invalid parameters,
915 * if exception wasn't thrown for valid parameters and if returned values
916 * are equal to corresponding substrings of the text received by relation.
917 * The following method tests are to be executed before:
919 * <li> <code>getCharacterCount()</code> </li>
922 public void _getTextBeforeIndex() {
923 requiredMethod("getCharacterCount()");
924 TextSegment txt
= null;
928 log
.print("getTextBeforeIndex(-1, AccessibleTextType.PARAGRAPH):");
930 txt
= oObj
.getTextBeforeIndex(-1,
931 AccessibleTextType
.PARAGRAPH
);
932 log
.println("Exception was expected");
934 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
935 log
.println("Expected exception");
937 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
938 log
.println("UnExpected exception");
943 log
.print("getTextBeforeIndex(chCount+1, " +
944 "AccessibleTextType.PARAGRAPH):");
946 txt
= oObj
.getTextBeforeIndex(chCount
+ 1,
947 AccessibleTextType
.PARAGRAPH
);
948 log
.println("Exception was expected");
950 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
951 log
.println("Expected exception");
953 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
954 log
.println("UnExpected exception");
959 if (!tEnv
.getTestCase().getObjectName().equals("SmGraphicAccessible")
960 // next one fails because the control actually contains 2 words
961 && !tEnv
.getTestCase().getObjectName().equals("AccessibleStatusBarItem"))
963 log
.print("getTextBeforeIndex(chCount," +
964 " AccessibleTextType.WORD):");
966 txt
= oObj
.getTextBeforeIndex(chCount
,
967 AccessibleTextType
.WORD
);
968 log
.println("'" + txt
.SegmentText
+ "'");
969 res
&= compareLength(chCount
, txt
.SegmentText
);
972 log
.print("getTextBeforeIndex(1," +
973 " AccessibleTextType.PARAGRAPH):");
974 txt
= oObj
.getTextBeforeIndex(1, AccessibleTextType
.PARAGRAPH
);
975 log
.println("'" + txt
.SegmentText
+ "'");
976 res
&= compareLength(0, txt
.SegmentText
);
978 log
.print("getTextBeforeIndex(chCount-1," +
979 " AccessibleTextType.CHARACTER):");
980 txt
= oObj
.getTextBeforeIndex(chCount
- 1,
981 AccessibleTextType
.CHARACTER
);
982 log
.println("'" + txt
.SegmentText
+ "'");
983 res
&= compareStrings(text
.substring(chCount
- 2, chCount
- 1),
987 log
.print("getTextBeforeIndex(2," +
988 " AccessibleTextType.CHARACTER):");
989 txt
= oObj
.getTextBeforeIndex(2, AccessibleTextType
.CHARACTER
);
990 log
.println("'" + txt
.SegmentText
+ "'");
991 res
&= compareStrings(text
.substring(1, 2), txt
.SegmentText
);
993 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
994 log
.println("Unexpected exception");
995 e
.printStackTrace(log
);
997 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
998 log
.println("Unexpected exception");
999 e
.printStackTrace(log
);
1003 tRes
.tested("getTextBeforeIndex()", res
);
1007 * Calls the method with invalid parameters an with valid parameters,
1008 * checks returned values.
1009 * Has OK status if exception was thrown for invalid parameters,
1010 * if exception wasn't thrown for valid parameters and if returned values
1011 * are equal to corresponding substrings of the text received by relation.
1012 * The following method tests are to be executed before:
1014 * <li> <code>getCharacterCount()</code> </li>
1017 public void _getTextBehindIndex() {
1018 requiredMethod("getCharacterCount()");
1019 TextSegment txt
= null;
1023 log
.print("getTextBehindIndex(-1, AccessibleTextType.PARAGRAPH):");
1025 txt
= oObj
.getTextBehindIndex(-1,
1026 AccessibleTextType
.PARAGRAPH
);
1027 log
.println("Exception was expected");
1029 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
1030 log
.println("Expected exception");
1032 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
1033 log
.println("UnExpected exception");
1038 log
.print("getTextBehindIndex(chCount+1, " +
1039 "AccessibleTextType.PARAGRAPH):");
1041 txt
= oObj
.getTextBehindIndex(chCount
+ 1,
1042 AccessibleTextType
.PARAGRAPH
);
1043 log
.println("Exception was expected");
1045 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
1046 log
.println("Expected exception");
1048 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
1049 log
.println("UnExpected exception");
1054 log
.print("getTextBehindIndex(chCount," +
1055 " AccessibleTextType.PARAGRAPH):");
1057 txt
= oObj
.getTextBehindIndex(chCount
,
1058 AccessibleTextType
.PARAGRAPH
);
1059 log
.println("'" + txt
.SegmentText
+ "'");
1060 res
&= (txt
.SegmentText
.length() == 0);
1062 log
.print("getTextBehindIndex(chCount-1," +
1063 " AccessibleTextType.PARAGRAPH):");
1064 txt
= oObj
.getTextBehindIndex(chCount
- 1,
1065 AccessibleTextType
.PARAGRAPH
);
1066 log
.println("'" + txt
.SegmentText
+ "'");
1067 res
&= (txt
.SegmentText
.length() == 0);
1069 log
.print("getTextBehindIndex(1," +
1070 " AccessibleTextType.CHARACTER):");
1071 txt
= oObj
.getTextBehindIndex(1, AccessibleTextType
.CHARACTER
);
1072 log
.println("'" + txt
.SegmentText
+ "'");
1073 res
&= txt
.SegmentText
.equals(text
.substring(2, 3));
1076 log
.print("getTextBehindIndex(chCount-2," +
1077 " AccessibleTextType.CHARACTER):");
1078 txt
= oObj
.getTextBehindIndex(chCount
- 2,
1079 AccessibleTextType
.CHARACTER
);
1080 log
.println("'" + txt
.SegmentText
+ "'");
1081 res
&= txt
.SegmentText
.equals(text
.substring(chCount
- 1, chCount
));
1083 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
1084 log
.println("Unexpected exception");
1085 e
.printStackTrace(log
);
1087 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
1088 log
.println("Unexpected exception");
1089 e
.printStackTrace(log
);
1093 tRes
.tested("getTextBehindIndex()", res
);
1097 * Calls the method with invalid parameters an with valid parameter,
1098 * checks returned values.
1099 * Has OK status if exception was thrown for invalid parameters,
1100 * if exception wasn't thrown for valid parameter and if returned value for
1101 * valid parameter is equal to <code>true</code>.
1103 public void _copyText() {
1105 boolean locRes
= true;
1107 if (editOnly
!= null) {
1108 log
.println(editOnly
);
1109 throw new StatusException(Status
.skipped(true));
1113 log
.print("copyText(-1,chCount):");
1114 oObj
.copyText(-1, chCount
);
1115 log
.println("Exception was expected");
1117 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
1118 log
.println("Expected exception");
1123 log
.print("copyText(0,chCount+1):");
1124 oObj
.copyText(0, chCount
+ 1);
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):");
1134 locRes
= oObj
.copyText(0, chCount
);
1135 log
.println(locRes
);
1138 String cbText
= null;
1141 cbText
= util
.SysUtils
.getSysClipboardText((XMultiServiceFactory
)tParam
.getMSF());
1142 } catch (com
.sun
.star
.uno
.Exception e
) {
1143 log
.println("Couldn't access system clipboard :");
1144 e
.printStackTrace(log
);
1147 log
.println("Clipboard: '" + cbText
+ "'");
1148 res
&= text
.equals(cbText
);
1151 log
.print("copyText(1,chCount-1):");
1152 locRes
= oObj
.copyText(1, chCount
- 1);
1153 log
.println(locRes
);
1157 cbText
= util
.SysUtils
.getSysClipboardText((XMultiServiceFactory
)tParam
.getMSF());
1158 } catch (com
.sun
.star
.uno
.Exception e
) {
1159 log
.println("Couldn't access system clipboard :");
1160 e
.printStackTrace(log
);
1163 log
.println("Clipboard: '" + cbText
+ "'");
1164 res
&= text
.substring(1, chCount
- 1).equals(cbText
);
1166 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
1167 log
.println("Unexpected exception");
1168 e
.printStackTrace(log
);
1172 tRes
.tested("copyText()", res
);
1175 public boolean compareStrings(String expected
, String getting
) {
1176 boolean res
= expected
.equals(getting
);
1179 log
.println("## The result isn't the expected:");
1180 log
.println("\tGetting: " + getting
);
1181 log
.println("\tExpected: " + expected
);
1187 public boolean compareLength(int expected
, String getting
) {
1188 boolean res
= (expected
== getting
.length());
1191 log
.println("## The result isn't the expected:");
1192 log
.println("\tGetting: " + getting
.length());
1193 log
.println("\tExpected: " + expected
);