1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XAccessibleText.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 package ifc
.accessibility
;
32 import lib
.MultiMethodTest
;
34 import lib
.StatusException
;
36 import com
.sun
.star
.accessibility
.AccessibleTextType
;
37 import com
.sun
.star
.accessibility
.TextSegment
;
38 import com
.sun
.star
.accessibility
.XAccessibleComponent
;
39 import com
.sun
.star
.accessibility
.XAccessibleText
;
40 import com
.sun
.star
.awt
.Point
;
41 import com
.sun
.star
.awt
.Rectangle
;
42 import com
.sun
.star
.beans
.PropertyValue
;
43 import com
.sun
.star
.lang
.XMultiServiceFactory
;
44 import com
.sun
.star
.uno
.UnoRuntime
;
48 * Testing <code>com.sun.star.accessibility.XAccessibleText</code>
51 * <li><code> getCaretPosition()</code></li>
52 * <li><code> setCaretPosition()</code></li>
53 * <li><code> getCharacter()</code></li>
54 * <li><code> getCharacterAttributes()</code></li>
55 * <li><code> getCharacterBounds()</code></li>
56 * <li><code> getCharacterCount()</code></li>
57 * <li><code> getIndexAtPoint()</code></li>
58 * <li><code> getSelectedText()</code></li>
59 * <li><code> getSelectionStart()</code></li>
60 * <li><code> getSelectionEnd()</code></li>
61 * <li><code> setSelection()</code></li>
62 * <li><code> getText()</code></li>
63 * <li><code> getTextRange()</code></li>
64 * <li><code> getTextAtIndex()</code></li>
65 * <li><code> getTextBeforeIndex()</code></li>
66 * <li><code> getTextBehindIndex()</code></li>
67 * <li><code> copyText()</code></li>
69 * This test needs the following object relations :
71 * <li> <code>'XAccessibleText.Text'</code> (of type <code>String</code>)
73 * the string presentation of component's text. If the relation
74 * is not specified, then text from method <code>getText()</code>
78 * @see com.sun.star.accessibility.XAccessibleText
80 public class _XAccessibleText
extends MultiMethodTest
{
82 public XAccessibleText oObj
= null;
83 protected com
.sun
.star
.awt
.Rectangle bounds
= null;
85 String editOnly
= null;
86 Object LimitedBounds
= null;
87 Rectangle chBounds
= null;
92 * Retrieves a string representation of the component's text.
93 * The length of retrieved string must be greater than zero.
95 protected void before() {
96 Object xat
= tEnv
.getObjRelation("XAccessibleText");
98 XAccessibleComponent component
= null;
101 oObj
= (XAccessibleText
) UnoRuntime
.queryInterface(
102 XAccessibleText
.class, xat
);
103 component
= (XAccessibleComponent
) UnoRuntime
.queryInterface(
104 XAccessibleComponent
.class, xat
);
107 text
= (String
) tEnv
.getObjRelation("XAccessibleText.Text");
110 text
= oObj
.getText();
113 if (text
.length() == 0) {
114 throw new StatusException(Status
.failed(
115 "The length of text must be greater than zero"));
118 editOnly
= (String
) tEnv
.getObjRelation("EditOnly");
119 LimitedBounds
= tEnv
.getObjRelation("LimitedBounds");
121 if (component
== null) {
122 component
= (XAccessibleComponent
) UnoRuntime
.queryInterface(
123 XAccessibleComponent
.class,
124 tEnv
.getTestObject());
127 bounds
= component
.getBounds();
129 log
.println("Text is '" + text
+ "'");
130 System
.out
.println("############################");
134 * Calls the method and checks returned value.
135 * Has OK status if returned value is equal to <code>chCount - 1</code>.
136 * The following method tests are to be executed before:
138 * <li> <code>setCaretPosition()</code> </li>
141 public void _getCaretPosition() {
142 requiredMethod("getCharacterCount()");
144 if (editOnly
!= null) {
145 log
.println(editOnly
);
146 throw new StatusException(Status
.skipped(true));
153 oObj
.setCaretPosition(chCount
- 1);
154 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException ie
) {
157 int carPos
= oObj
.getCaretPosition();
158 log
.println("getCaretPosition: " + carPos
);
161 res
= carPos
== (chCount
- 1);
164 "Object is read only and Caret position couldn't be set");
168 tRes
.tested("getCaretPosition()", res
);
172 * Calls the method with the wrong index and with the correct index
173 * <code>chCount - 1</code>.
174 * Has OK status if exception was thrown for wrong index and
175 * if exception wasn't thrown for the correct index.
176 * The following method tests are to be executed before:
178 * <li> <code>getCharacterCount()</code> </li>
181 public void _setCaretPosition() {
182 requiredMethod("getCharacterCount()");
187 log
.print("setCaretPosition(-1):");
188 oObj
.setCaretPosition(-1);
190 log
.println("exception was expected ... FAILED");
191 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
192 log
.println("expected exception");
197 log
.print("setCaretPosition(chCount+1):");
198 oObj
.setCaretPosition(chCount
+ 1);
200 log
.println("exception was expected ... FAILED");
201 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
202 log
.println("expected exception");
207 log
.println("setCaretPosition(chCount - 1)");
208 oObj
.setCaretPosition(chCount
- 1);
210 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
211 log
.println("unexpected exception ... FAILED");
212 e
.printStackTrace(log
);
216 tRes
.tested("setCaretPosition()", res
);
220 * Calls the method with the wrong index and with the correct indexes.
221 * Checks every character in the text.
222 * Has OK status if exception was thrown for wrong index,
223 * if exception wasn't thrown for the correct index and
224 * if every character is equal to corresponding character in the text.
225 * The following method tests are to be executed before:
227 * <li> <code>getCharacterCount()</code> </li>
230 public void _getCharacter() {
231 requiredMethod("getCharacterCount()");
236 log
.println("getCharacter(-1)");
237 oObj
.getCharacter(-1);
238 log
.println("Exception was expected");
240 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
241 log
.println("Expected exception");
246 log
.println("getCharacter(chCount)");
247 oObj
.getCharacter(chCount
);
248 log
.println("Exception was expected");
250 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
251 log
.println("Expected exception");
256 log
.println("Checking of every character in the text...");
258 boolean isEqCh
= true;
260 for (int i
= 0; i
< chCount
; i
++) {
261 char ch
= oObj
.getCharacter(i
);
262 isEqCh
= ch
== text
.charAt(i
);
266 log
.println("At the position " + i
+
267 "was expected character: " + text
.charAt(i
));
268 log
.println("but was returned: " + ch
);
273 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
274 log
.println("Unexpected exception");
275 e
.printStackTrace(log
);
279 tRes
.tested("getCharacter()", res
);
283 * Calls the method with the wrong indexes and with the correct index,
284 * checks a returned value.
285 * Has OK status if exception was thrown for the wrong indexes,
286 * if exception wasn't thrown for the correct index and
287 * if returned value isn't <code>null</code>.
288 * The following method tests are to be executed before:
290 * <li> <code>getCharacterCount()</code> </li>
293 public void _getCharacterAttributes() {
294 requiredMethod("getCharacterCount()");
297 String
[] attr
= new String
[] { "" };
300 log
.println("getCharacterAttributes(-1)");
301 oObj
.getCharacterAttributes(-1, attr
);
302 log
.println("Exception was expected");
304 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
305 log
.println("Expected exception");
310 log
.println("getCharacterAttributes(chCount)");
311 oObj
.getCharacterAttributes(chCount
, attr
);
312 log
.println("Exception was expected");
314 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
315 log
.println("Expected exception");
320 log
.println("getCharacterAttributes(chCount-1)");
322 PropertyValue
[] props
= oObj
.getCharacterAttributes(chCount
- 1,
324 res
&= (props
!= null);
325 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
326 log
.println("Unexpected exception");
327 e
.printStackTrace(log
);
331 tRes
.tested("getCharacterAttributes()", res
);
335 * Calls the method with the wrong indexes and with the correct index.
336 * checks and stores a returned value.
337 * Has OK status if exception was thrown for the wrong indexes,
338 * if exception wasn't thrown for the correct index and
339 * if returned value isn't <code>null</code>.
340 * The following method tests are to be executed before:
342 * <li> <code>getCharacterCount()</code> </li>
345 public void _getCharacterBounds() {
346 requiredMethod("getCharacterCount()");
350 int lastIndex
= chCount
;
352 if (LimitedBounds
!= null) {
353 if (LimitedBounds
instanceof Integer
) {
354 lastIndex
= ((Integer
) LimitedBounds
).intValue();
356 lastIndex
= chCount
- 1;
359 log
.println(LimitedBounds
);
363 log
.println("getCharacterBounds(-1)");
364 oObj
.getCharacterBounds(-1);
365 log
.println("Exception was expected");
367 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
368 log
.println("Expected exception");
373 log
.println("getCharacterBounds(" + (lastIndex
+ 1) + ")");
374 oObj
.getCharacterBounds(lastIndex
+ 1);
375 log
.println("Exception was expected");
377 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
378 log
.println("Expected exception");
383 for (int i
= 0; i
< lastIndex
; i
++) {
384 log
.println("getCharacterBounds(" + i
+ ")");
385 chBounds
= oObj
.getCharacterBounds(i
);
387 boolean localres
= true;
388 localres
= chBounds
.X
>= 0;
389 localres
&= (chBounds
.Y
>= 0);
390 localres
&= ((chBounds
.X
+ chBounds
.Width
) <= bounds
.Width
);
391 localres
&= ((chBounds
.X
+ chBounds
.Width
) > 0);
392 localres
&= ((chBounds
.Y
+ chBounds
.Height
) <= bounds
.Height
);
393 localres
&= ((chBounds
.Y
+ chBounds
.Height
) > 0);
396 log
.println("Text at this place: "+oObj
.getCharacter(i
));
397 log
.println("Character bounds outside component");
398 log
.println("Character rect: " + chBounds
.X
+ ", " +
399 chBounds
.Y
+ ", " + chBounds
.Width
+ ", " +
401 log
.println("Component rect: " + bounds
.X
+ ", " +
402 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
) {
473 int x
= aRect
.X
+ (aRect
.Width
/ 2);
474 int y
= aRect
.Y
+ (aRect
.Height
/ 2);
475 Point aPoint
= new Point(x
, y
);
476 int nIndex
= oObj
.getIndexAtPoint(aPoint
);
479 y
= aRect
.Y
+ (aRect
.Height
/ 2);
480 aPoint
= new Point(x
, y
);
481 int left
= oObj
.getIndexAtPoint(aPoint
);
485 int[] previous
= (int[]) tEnv
.getObjRelation("PreviousUsed");
487 if (previous
!= null) {
488 for (int k
= 0; k
< previous
.length
; k
++) {
489 if (i
== previous
[k
]) {
496 // for some letters the center of the rectangle isn't recognised
497 // in this case we are happy if the left border of the rectangle
498 // returns the correct value.
500 log
.println("## Method didn't work for Point (" + x
+ "," + y
+
502 log
.println("Expected Index " + i
);
503 log
.println("Gained Index: " + nIndex
);
504 log
.println("Left Border: "+left
);
505 log
.println("CharacterAtIndex: " + text
);
511 tRes
.tested("getIndexAtPoint()", res
);
515 * Checks a returned values after different calls of the method
516 * <code>setSelection()</code>.
517 * The following method tests are to be executed before:
519 * <li> <code>setSelection()</code> </li>
522 public void _getSelectedText() {
523 if (editOnly
!= null) {
524 log
.println(editOnly
);
525 throw new StatusException(Status
.skipped(true));
528 requiredMethod("setSelection()");
533 log
.println("setSelection(0, 0)");
534 oObj
.setSelection(0, 0);
535 log
.print("getSelectedText():");
537 String txt
= oObj
.getSelectedText();
538 log
.println("'" + txt
+ "'");
539 res
&= (txt
.length() == 0);
541 log
.println("setSelection(0, chCount)");
542 oObj
.setSelection(0, chCount
);
543 log
.print("getSelectedText():");
544 txt
= oObj
.getSelectedText();
545 log
.println("'" + txt
+ "'");
546 res
&= txt
.equals(text
);
549 log
.println("setSelection(1, chCount-1)");
550 oObj
.setSelection(1, chCount
- 1);
551 log
.print("getSelectedText():");
552 txt
= oObj
.getSelectedText();
553 log
.println("'" + txt
+ "'");
554 res
&= txt
.equals(text
.substring(1, chCount
- 1));
556 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
557 log
.println("Unexpected exception");
558 e
.printStackTrace(log
);
562 tRes
.tested("getSelectedText()", res
);
566 * Checks a returned values after different calls of the method
567 * <code>setSelection()</code>.
568 * The following method tests are to be executed before:
570 * <li> <code>setSelection()</code> </li>
573 public void _getSelectionStart() {
574 if (editOnly
!= null) {
575 log
.println(editOnly
);
576 throw new StatusException(Status
.skipped(true));
579 requiredMethod("setSelection()");
584 log
.println("setSelection(0, chCount)");
585 oObj
.setSelection(0, chCount
);
587 int start
= oObj
.getSelectionStart();
588 log
.println("getSelectionStart():" + start
);
592 log
.println("setSelection(1, chCount-1)");
593 oObj
.setSelection(1, chCount
- 1);
594 start
= oObj
.getSelectionStart();
595 log
.println("getSelectionStart():" + start
);
598 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
599 log
.println("Unexpected exception");
600 e
.printStackTrace(log
);
604 tRes
.tested("getSelectionStart()", res
);
608 * Checks a returned values after different calls of the method
609 * <code>setSelection()</code>.
610 * The following method tests are to be executed before:
612 * <li> <code>setSelection()</code> </li>
615 public void _getSelectionEnd() {
616 if (editOnly
!= null) {
617 log
.println(editOnly
);
618 throw new StatusException(Status
.skipped(true));
621 requiredMethod("setSelection()");
626 log
.println("setSelection(0, chCount)");
627 oObj
.setSelection(0, chCount
);
629 int end
= oObj
.getSelectionEnd();
630 log
.println("getSelectionEnd():" + end
);
631 res
&= (end
== chCount
);
634 log
.println("setSelection(1, chCount-1)");
635 oObj
.setSelection(1, chCount
- 1);
636 end
= oObj
.getSelectionEnd();
637 log
.println("getSelectionEnd():" + end
);
638 res
&= (end
== (chCount
- 1));
640 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
641 log
.println("Unexpected exception");
642 e
.printStackTrace(log
);
646 tRes
.tested("getSelectionEnd()", res
);
650 * Calls the method with invalid parameters an with valid parameters.
651 * Has OK status if exception was thrown for invalid parameters,
652 * if exception wasn't thrown for valid parameters.
653 * The following method tests are to be executed before:
655 * <li> <code>getCharacterCount()</code> </li>
658 public void _setSelection() {
659 requiredMethod("getCharacterCount()");
662 boolean locRes
= true;
664 if (editOnly
!= null) {
665 log
.println(editOnly
);
666 throw new StatusException(Status
.skipped(true));
670 log
.print("setSelection(-1, chCount-1):");
671 locRes
= oObj
.setSelection(-1, chCount
- 1);
672 log
.println(locRes
+ " excepion was expected");
674 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
675 log
.println("Expected exception");
680 log
.print("setSelection(0, chCount+1):");
681 locRes
= oObj
.setSelection(0, chCount
+ 1);
682 log
.println(locRes
+ " excepion was expected");
684 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
685 log
.println("Expected exception");
691 log
.print("setSelection(1, chCount-1):");
692 locRes
= oObj
.setSelection(1, chCount
- 1);
696 log
.print("setSelection(chCount-1, 1):");
697 locRes
= oObj
.setSelection(chCount
- 1, 1);
702 log
.print("setSelection(0, chCount-1):");
703 locRes
= oObj
.setSelection(0, chCount
- 1);
707 log
.print("setSelection(chCount-1, 0):");
708 locRes
= oObj
.setSelection(chCount
- 1, 0);
712 log
.print("setSelection(0, 0):");
713 locRes
= oObj
.setSelection(0, 0);
716 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
717 log
.println("Unexpected exception");
718 e
.printStackTrace(log
);
722 tRes
.tested("setSelection()", res
);
726 * Calls the method and checks returned value.
727 * Has OK status if returned string is equal to string
728 * received from relation.
730 public void _getText() {
731 String txt
= oObj
.getText();
732 log
.println("getText: " + txt
);
734 boolean res
= txt
.equals(text
);
735 tRes
.tested("getText()", res
);
739 * Calls the method with invalid parameters an with valid parameters,
740 * checks returned values.
741 * Has OK status if exception was thrown for invalid parameters,
742 * if exception wasn't thrown for valid parameters and if returned values
743 * are equal to corresponding substrings of the text received by relation.
744 * The following method tests are to be executed before:
746 * <li> <code>getCharacterCount()</code> </li>
749 public void _getTextRange() {
750 requiredMethod("getCharacterCount()");
753 boolean locRes
= true;
755 String txtRange
= "";
759 log
.print("getTextRange(1, chCount - 2): ");
761 txtRange
= oObj
.getTextRange(1, chCount
- 2);
762 log
.println(txtRange
);
763 locRes
= txtRange
.equals(text
.substring(1, chCount
- 2));
767 log
.println("Was expected: " +
768 text
.substring(1, chCount
- 2));
772 log
.print("getTextRange(0, chCount-1): ");
774 txtRange
= oObj
.getTextRange(0, chCount
- 1);
775 log
.println(txtRange
);
776 locRes
= txtRange
.equals(text
.substring(0, chCount
- 1));
780 log
.println("Was expected: " +
781 text
.substring(0, chCount
- 1));
784 log
.print("getTextRange(chCount, 0): ");
785 txtRange
= oObj
.getTextRange(chCount
, 0);
786 log
.println(txtRange
);
787 res
&= txtRange
.equals(text
);
789 log
.print("getTextRange(0, 0): ");
790 txtRange
= oObj
.getTextRange(0, 0);
791 log
.println(txtRange
);
792 locRes
= txtRange
.equals("");
796 log
.println("Empty string was expected");
798 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
799 log
.println("Unexpected exception");
800 e
.printStackTrace(log
);
805 log
.print("getTextRange(-1, chCount - 1): ");
807 txtRange
= oObj
.getTextRange(-1, chCount
- 1);
808 log
.println("Exception was expected");
810 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
811 log
.println("Expected exception");
816 log
.print("getTextRange(0, chCount + 1): ");
818 txtRange
= oObj
.getTextRange(0, chCount
+ 1);
819 log
.println("Exception was expected");
821 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
822 log
.println("Expected exception");
827 log
.print("getTextRange(chCount+1, -1): ");
829 txtRange
= oObj
.getTextRange(chCount
+ 1, -1);
830 log
.println("Exception was expected");
832 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
833 log
.println("Expected exception");
837 tRes
.tested("getTextRange()", res
);
841 * Calls the method with invalid parameters an with valid parameters,
842 * checks returned values.
843 * Has OK status if exception was thrown for invalid parameters,
844 * if exception wasn't thrown for valid parameters and if returned values
845 * are equal to corresponding substrings of the text received by relation.
846 * The following method tests are to be executed before:
848 * <li> <code>getCharacterCount()</code> </li>
851 public void _getTextAtIndex() {
852 requiredMethod("getCharacterCount()");
853 TextSegment txt
= null;
857 log
.print("getTextAtIndex(-1, AccessibleTextType.PARAGRAPH):");
859 txt
= oObj
.getTextAtIndex(-1,
860 AccessibleTextType
.PARAGRAPH
);
861 log
.println("Exception was expected");
863 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
864 log
.println("Expected exception");
866 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
867 log
.println("UnExpected exception");
872 log
.print("getTextAtIndex(chCount+1," +
873 " AccessibleTextType.PARAGRAPH):");
875 txt
= oObj
.getTextAtIndex(chCount
+ 1,
876 AccessibleTextType
.PARAGRAPH
);
877 log
.println("Exception was expected");
879 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
880 log
.println("Expected exception");
882 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
883 log
.println("UnExpected exception");
888 log
.print("getTextAtIndex(chCount," +
889 " AccessibleTextType.WORD):");
891 txt
= oObj
.getTextAtIndex(chCount
, AccessibleTextType
.WORD
);
892 log
.println("'" + txt
.SegmentText
+ "'");
893 res
&= compareLength(0,txt
.SegmentText
);
894 if (!tEnv
.getTestCase().getObjectName().equals("SmGraphicAccessible")) {
895 log
.print("getTextAtIndex(1," +
896 " AccessibleTextType.PARAGRAPH):");
897 txt
= oObj
.getTextAtIndex(1, AccessibleTextType
.PARAGRAPH
);
898 log
.println("'" + txt
.SegmentText
+ "'");
899 res
&= compareStrings(text
,txt
.SegmentText
);
901 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
902 log
.println("Unexpected exception");
903 e
.printStackTrace(log
);
905 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
906 log
.println("Unexpected exception");
907 e
.printStackTrace(log
);
911 tRes
.tested("getTextAtIndex()", res
);
915 * Calls the method with invalid parameters an with valid parameters,
916 * checks returned values.
917 * Has OK status if exception was thrown for invalid parameters,
918 * if exception wasn't thrown for valid parameters and if returned values
919 * are equal to corresponding substrings of the text received by relation.
920 * The following method tests are to be executed before:
922 * <li> <code>getCharacterCount()</code> </li>
925 public void _getTextBeforeIndex() {
926 requiredMethod("getCharacterCount()");
927 TextSegment txt
= null;
931 log
.print("getTextBeforeIndex(-1, AccessibleTextType.PARAGRAPH):");
933 txt
= oObj
.getTextBeforeIndex(-1,
934 AccessibleTextType
.PARAGRAPH
);
935 log
.println("Exception was expected");
937 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
938 log
.println("Expected exception");
940 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
941 log
.println("UnExpected exception");
946 log
.print("getTextBeforeIndex(chCount+1, " +
947 "AccessibleTextType.PARAGRAPH):");
949 txt
= oObj
.getTextBeforeIndex(chCount
+ 1,
950 AccessibleTextType
.PARAGRAPH
);
951 log
.println("Exception was expected");
953 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
954 log
.println("Expected exception");
956 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
957 log
.println("UnExpected exception");
962 if (!tEnv
.getTestCase().getObjectName().equals("SmGraphicAccessible")) {
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
);