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
.lang
.XMultiServiceFactory
;
32 import com
.sun
.star
.uno
.UnoRuntime
;
36 * Testing <code>com.sun.star.accessibility.XAccessibleText</code>
39 * <li><code> getCaretPosition()</code></li>
40 * <li><code> setCaretPosition()</code></li>
41 * <li><code> getCharacter()</code></li>
42 * <li><code> getCharacterAttributes()</code></li>
43 * <li><code> getCharacterBounds()</code></li>
44 * <li><code> getCharacterCount()</code></li>
45 * <li><code> getIndexAtPoint()</code></li>
46 * <li><code> getSelectedText()</code></li>
47 * <li><code> getSelectionStart()</code></li>
48 * <li><code> getSelectionEnd()</code></li>
49 * <li><code> setSelection()</code></li>
50 * <li><code> getText()</code></li>
51 * <li><code> getTextRange()</code></li>
52 * <li><code> getTextAtIndex()</code></li>
53 * <li><code> getTextBeforeIndex()</code></li>
54 * <li><code> getTextBehindIndex()</code></li>
55 * <li><code> copyText()</code></li>
57 * This test needs the following object relations :
59 * <li> <code>'XAccessibleText.Text'</code> (of type <code>String</code>)
61 * the string presentation of component's text. If the relation
62 * is not specified, then text from method <code>getText()</code>
66 * @see com.sun.star.accessibility.XAccessibleText
68 public class _XAccessibleText
extends MultiMethodTest
{
70 public XAccessibleText oObj
= null;
71 protected com
.sun
.star
.awt
.Rectangle bounds
= null;
73 String editOnly
= null;
74 Object LimitedBounds
= null;
75 Rectangle chBounds
= null;
80 * Retrieves a string representation of the component's text.
81 * 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");
298 log
.println("getCharacterAttributes(chCount)");
299 oObj
.getCharacterAttributes(chCount
, attr
);
300 log
.println("Exception was expected");
302 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
303 log
.println("Expected exception");
308 log
.println("getCharacterAttributes(chCount-1)");
310 PropertyValue
[] props
= oObj
.getCharacterAttributes(chCount
- 1,
312 res
&= (props
!= null);
313 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
314 log
.println("Unexpected exception");
315 e
.printStackTrace(log
);
319 tRes
.tested("getCharacterAttributes()", res
);
323 * Calls the method with the wrong indexes and with the correct index.
324 * checks and stores a returned value.
325 * Has OK status if exception was thrown for the wrong indexes,
326 * if exception wasn't thrown for the correct index and
327 * if returned value isn't <code>null</code>.
328 * The following method tests are to be executed before:
330 * <li> <code>getCharacterCount()</code> </li>
333 public void _getCharacterBounds() {
334 requiredMethod("getCharacterCount()");
338 int lastIndex
= chCount
;
340 if (LimitedBounds
!= null) {
341 if (LimitedBounds
instanceof Integer
) {
342 lastIndex
= ((Integer
) LimitedBounds
).intValue();
344 lastIndex
= chCount
- 1;
347 log
.println(LimitedBounds
);
351 log
.println("getCharacterBounds(-1)");
352 oObj
.getCharacterBounds(-1);
353 log
.println("Exception was expected");
355 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
356 log
.println("Expected exception");
361 log
.println("getCharacterBounds(" + (lastIndex
+ 1) + ")");
362 oObj
.getCharacterBounds(lastIndex
+ 1);
363 log
.println("Exception was expected");
365 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
366 log
.println("Expected exception");
371 for (int i
= 0; i
< lastIndex
; i
++) {
372 log
.println("getCharacterBounds(" + i
+ ")");
373 chBounds
= oObj
.getCharacterBounds(i
);
375 boolean localres
= true;
376 localres
= chBounds
.X
>= 0;
377 localres
&= (chBounds
.Y
>= 0);
378 localres
&= ((chBounds
.X
+ chBounds
.Width
) <= bounds
.Width
);
379 localres
&= ((chBounds
.X
+ chBounds
.Width
) >= 0);
380 localres
&= ((chBounds
.Y
+ chBounds
.Height
) <= bounds
.Height
);
381 localres
&= ((chBounds
.Y
+ chBounds
.Height
) >= 0);
384 log
.println("Text at this place: "+oObj
.getCharacter(i
));
385 log
.println("Character bounds outside component");
386 log
.println("Character rect: " + chBounds
.X
+ ", " +
387 chBounds
.Y
+ ", " + chBounds
.Width
+ ", " +
389 log
.println("Component rect: " + bounds
.X
+ ", " +
390 bounds
.Y
+ ", " + bounds
.Width
+ ", " +
392 //TODO: For some reason that still needs to be investigated,
393 // the above test keeps failing on Mac OS X:
394 if (!System
.getProperty("os.name").equals("Mac OS X")) {
399 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
400 log
.println("Unexpected exception");
401 e
.printStackTrace(log
);
405 tRes
.tested("getCharacterBounds()", res
);
409 * Calls the method and stores a returned value to the variable
410 * <code>chCount</code>.
411 * Has OK status if a returned value is equal to the text length.
413 public void _getCharacterCount() {
414 chCount
= oObj
.getCharacterCount();
415 log
.println("Character count:" + chCount
);
417 boolean res
= chCount
== text
.length();
418 tRes
.tested("getCharacterCount()", res
);
422 * Calls the method for an invalid point and for the point of rectangle
423 * returned by the method <code>getCharacterBounds()</code>.
424 * Has OK status if returned value is equal to <code>-1</code> for an
425 * invalid point and if returned value is equal to <code>chCount-1</code>
427 * The following method tests are to be executed before:
429 * <li> <code>getCharacterBounds()</code> </li>
432 public void _getIndexAtPoint() {
433 //requiredMethod("getCharacterBounds()");
435 log
.print("getIndexAtPoint(-1, -1):");
437 Point pt
= new Point(-1, -1);
438 int index
= oObj
.getIndexAtPoint(pt
);
440 res
&= (index
== -1);
442 int lastIndex
= chCount
;
444 if (LimitedBounds
!= null) {
445 if (LimitedBounds
instanceof Integer
) {
446 lastIndex
= ((Integer
) LimitedBounds
).intValue();
448 lastIndex
= chCount
- 1;
451 log
.println(LimitedBounds
);
454 for (int i
= 0; i
< lastIndex
; i
++) {
455 Rectangle aRect
= null;
456 String text
= "empty";
459 aRect
= oObj
.getCharacterBounds(i
);
460 text
= oObj
.getTextAtIndex(i
, (short) 1).SegmentText
;
461 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
462 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
465 int x
= aRect
.X
+ (aRect
.Width
/ 2);
466 int y
= aRect
.Y
+ (aRect
.Height
/ 2);
467 Point aPoint
= new Point(x
, y
);
468 int nIndex
= oObj
.getIndexAtPoint(aPoint
);
471 y
= aRect
.Y
+ (aRect
.Height
/ 2);
472 aPoint
= new Point(x
, y
);
473 int left
= oObj
.getIndexAtPoint(aPoint
);
477 int[] previous
= (int[]) tEnv
.getObjRelation("PreviousUsed");
479 if (previous
!= null) {
480 for (int k
= 0; k
< previous
.length
; k
++) {
481 if (i
== previous
[k
]) {
488 // for some letters the center of the rectangle isn't recognised
489 // in this case we are happy if the left border of the rectangle
490 // returns the correct value.
492 log
.println("## Method didn't work for Point (" + x
+ "," + y
+
494 log
.println("Expected Index " + i
);
495 log
.println("Gained Index: " + nIndex
);
496 log
.println("Left Border: "+left
);
497 log
.println("CharacterAtIndex: " + text
);
503 tRes
.tested("getIndexAtPoint()", res
);
507 * Checks a returned values after different calls of the method
508 * <code>setSelection()</code>.
509 * The following method tests are to be executed before:
511 * <li> <code>setSelection()</code> </li>
514 public void _getSelectedText() {
515 if (editOnly
!= null) {
516 log
.println(editOnly
);
517 throw new StatusException(Status
.skipped(true));
520 requiredMethod("setSelection()");
525 log
.println("setSelection(0, 0)");
526 oObj
.setSelection(0, 0);
527 log
.print("getSelectedText():");
529 String txt
= oObj
.getSelectedText();
530 log
.println("'" + txt
+ "'");
531 res
&= (txt
.length() == 0);
533 log
.println("setSelection(0, chCount)");
534 oObj
.setSelection(0, chCount
);
535 log
.print("getSelectedText():");
536 txt
= oObj
.getSelectedText();
537 log
.println("'" + txt
+ "'");
538 res
&= txt
.equals(text
);
541 log
.println("setSelection(1, chCount-1)");
542 oObj
.setSelection(1, chCount
- 1);
543 log
.print("getSelectedText():");
544 txt
= oObj
.getSelectedText();
545 log
.println("'" + txt
+ "'");
546 res
&= txt
.equals(text
.substring(1, chCount
- 1));
548 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
549 log
.println("Unexpected exception");
550 e
.printStackTrace(log
);
554 tRes
.tested("getSelectedText()", res
);
558 * Checks a returned values after different calls of the method
559 * <code>setSelection()</code>.
560 * The following method tests are to be executed before:
562 * <li> <code>setSelection()</code> </li>
565 public void _getSelectionStart() {
566 if (editOnly
!= null) {
567 log
.println(editOnly
);
568 throw new StatusException(Status
.skipped(true));
571 requiredMethod("setSelection()");
576 log
.println("setSelection(0, chCount)");
577 oObj
.setSelection(0, chCount
);
579 int start
= oObj
.getSelectionStart();
580 log
.println("getSelectionStart():" + start
);
584 log
.println("setSelection(1, chCount-1)");
585 oObj
.setSelection(1, chCount
- 1);
586 start
= oObj
.getSelectionStart();
587 log
.println("getSelectionStart():" + start
);
590 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
591 log
.println("Unexpected exception");
592 e
.printStackTrace(log
);
596 tRes
.tested("getSelectionStart()", res
);
600 * Checks a returned values after different calls of the method
601 * <code>setSelection()</code>.
602 * The following method tests are to be executed before:
604 * <li> <code>setSelection()</code> </li>
607 public void _getSelectionEnd() {
608 if (editOnly
!= null) {
609 log
.println(editOnly
);
610 throw new StatusException(Status
.skipped(true));
613 requiredMethod("setSelection()");
618 log
.println("setSelection(0, chCount)");
619 oObj
.setSelection(0, chCount
);
621 int end
= oObj
.getSelectionEnd();
622 log
.println("getSelectionEnd():" + end
);
623 res
&= (end
== chCount
);
626 log
.println("setSelection(1, chCount-1)");
627 oObj
.setSelection(1, chCount
- 1);
628 end
= oObj
.getSelectionEnd();
629 log
.println("getSelectionEnd():" + end
);
630 res
&= (end
== (chCount
- 1));
632 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
633 log
.println("Unexpected exception");
634 e
.printStackTrace(log
);
638 tRes
.tested("getSelectionEnd()", res
);
642 * Calls the method with invalid parameters an with valid parameters.
643 * Has OK status if exception was thrown for invalid parameters,
644 * if exception wasn't thrown for valid parameters.
645 * The following method tests are to be executed before:
647 * <li> <code>getCharacterCount()</code> </li>
650 public void _setSelection() {
651 requiredMethod("getCharacterCount()");
654 boolean locRes
= true;
656 if (editOnly
!= null) {
657 log
.println(editOnly
);
658 throw new StatusException(Status
.skipped(true));
662 log
.print("setSelection(-1, chCount-1):");
663 locRes
= oObj
.setSelection(-1, chCount
- 1);
664 log
.println(locRes
+ " excepion was expected");
666 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
667 log
.println("Expected exception");
672 log
.print("setSelection(0, chCount+1):");
673 locRes
= oObj
.setSelection(0, chCount
+ 1);
674 log
.println(locRes
+ " excepion was expected");
676 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
677 log
.println("Expected exception");
683 log
.print("setSelection(1, chCount-1):");
684 locRes
= oObj
.setSelection(1, chCount
- 1);
688 log
.print("setSelection(chCount-1, 1):");
689 locRes
= oObj
.setSelection(chCount
- 1, 1);
694 log
.print("setSelection(0, chCount-1):");
695 locRes
= oObj
.setSelection(0, chCount
- 1);
699 log
.print("setSelection(chCount-1, 0):");
700 locRes
= oObj
.setSelection(chCount
- 1, 0);
704 log
.print("setSelection(0, 0):");
705 locRes
= oObj
.setSelection(0, 0);
708 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
709 log
.println("Unexpected exception");
710 e
.printStackTrace(log
);
714 tRes
.tested("setSelection()", res
);
718 * Calls the method and checks returned value.
719 * Has OK status if returned string is equal to string
720 * received from relation.
722 public void _getText() {
723 String txt
= oObj
.getText();
724 log
.println("getText: " + txt
);
726 boolean res
= txt
.equals(text
);
727 tRes
.tested("getText()", res
);
731 * Calls the method with invalid parameters an with valid parameters,
732 * checks returned values.
733 * Has OK status if exception was thrown for invalid parameters,
734 * if exception wasn't thrown for valid parameters and if returned values
735 * are equal to corresponding substrings of the text received by relation.
736 * The following method tests are to be executed before:
738 * <li> <code>getCharacterCount()</code> </li>
741 public void _getTextRange() {
742 requiredMethod("getCharacterCount()");
745 boolean locRes
= true;
747 String txtRange
= "";
751 log
.print("getTextRange(1, chCount - 2): ");
753 txtRange
= oObj
.getTextRange(1, chCount
- 2);
754 log
.println(txtRange
);
755 locRes
= txtRange
.equals(text
.substring(1, chCount
- 2));
759 log
.println("Was expected: " +
760 text
.substring(1, chCount
- 2));
764 log
.print("getTextRange(0, chCount-1): ");
766 txtRange
= oObj
.getTextRange(0, chCount
- 1);
767 log
.println(txtRange
);
768 locRes
= txtRange
.equals(text
.substring(0, chCount
- 1));
772 log
.println("Was expected: " +
773 text
.substring(0, chCount
- 1));
776 log
.print("getTextRange(chCount, 0): ");
777 txtRange
= oObj
.getTextRange(chCount
, 0);
778 log
.println(txtRange
);
779 res
&= txtRange
.equals(text
);
781 log
.print("getTextRange(0, 0): ");
782 txtRange
= oObj
.getTextRange(0, 0);
783 log
.println(txtRange
);
784 locRes
= txtRange
.equals("");
788 log
.println("Empty string was expected");
790 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
791 log
.println("Unexpected exception");
792 e
.printStackTrace(log
);
797 log
.print("getTextRange(-1, chCount - 1): ");
799 txtRange
= oObj
.getTextRange(-1, chCount
- 1);
800 log
.println("Exception was expected");
802 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
803 log
.println("Expected exception");
808 log
.print("getTextRange(0, chCount + 1): ");
810 txtRange
= oObj
.getTextRange(0, chCount
+ 1);
811 log
.println("Exception was expected");
813 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
814 log
.println("Expected exception");
819 log
.print("getTextRange(chCount+1, -1): ");
821 txtRange
= oObj
.getTextRange(chCount
+ 1, -1);
822 log
.println("Exception was expected");
824 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
825 log
.println("Expected exception");
829 tRes
.tested("getTextRange()", res
);
833 * Calls the method with invalid parameters an with valid parameters,
834 * checks returned values.
835 * Has OK status if exception was thrown for invalid parameters,
836 * if exception wasn't thrown for valid parameters and if returned values
837 * are equal to corresponding substrings of the text received by relation.
838 * The following method tests are to be executed before:
840 * <li> <code>getCharacterCount()</code> </li>
843 public void _getTextAtIndex() {
844 requiredMethod("getCharacterCount()");
845 TextSegment txt
= null;
849 log
.print("getTextAtIndex(-1, AccessibleTextType.PARAGRAPH):");
851 txt
= oObj
.getTextAtIndex(-1,
852 AccessibleTextType
.PARAGRAPH
);
853 log
.println("Exception was expected");
855 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
856 log
.println("Expected exception");
858 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
859 log
.println("UnExpected exception");
864 log
.print("getTextAtIndex(chCount+1," +
865 " AccessibleTextType.PARAGRAPH):");
867 txt
= oObj
.getTextAtIndex(chCount
+ 1,
868 AccessibleTextType
.PARAGRAPH
);
869 log
.println("Exception was expected");
871 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
872 log
.println("Expected exception");
874 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
875 log
.println("UnExpected exception");
880 log
.print("getTextAtIndex(chCount," +
881 " AccessibleTextType.WORD):");
883 txt
= oObj
.getTextAtIndex(chCount
, AccessibleTextType
.WORD
);
884 log
.println("'" + txt
.SegmentText
+ "'");
885 res
&= compareLength(0,txt
.SegmentText
);
886 if (!tEnv
.getTestCase().getObjectName().equals("SmGraphicAccessible")) {
887 log
.print("getTextAtIndex(1," +
888 " AccessibleTextType.PARAGRAPH):");
889 txt
= oObj
.getTextAtIndex(1, AccessibleTextType
.PARAGRAPH
);
890 log
.println("'" + txt
.SegmentText
+ "'");
891 res
&= compareStrings(text
,txt
.SegmentText
);
893 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
894 log
.println("Unexpected exception");
895 e
.printStackTrace(log
);
897 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
898 log
.println("Unexpected exception");
899 e
.printStackTrace(log
);
903 tRes
.tested("getTextAtIndex()", res
);
907 * Calls the method with invalid parameters an with valid parameters,
908 * checks returned values.
909 * Has OK status if exception was thrown for invalid parameters,
910 * if exception wasn't thrown for valid parameters and if returned values
911 * are equal to corresponding substrings of the text received by relation.
912 * The following method tests are to be executed before:
914 * <li> <code>getCharacterCount()</code> </li>
917 public void _getTextBeforeIndex() {
918 requiredMethod("getCharacterCount()");
919 TextSegment txt
= null;
923 log
.print("getTextBeforeIndex(-1, AccessibleTextType.PARAGRAPH):");
925 txt
= oObj
.getTextBeforeIndex(-1,
926 AccessibleTextType
.PARAGRAPH
);
927 log
.println("Exception was expected");
929 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
930 log
.println("Expected exception");
932 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
933 log
.println("UnExpected exception");
938 log
.print("getTextBeforeIndex(chCount+1, " +
939 "AccessibleTextType.PARAGRAPH):");
941 txt
= oObj
.getTextBeforeIndex(chCount
+ 1,
942 AccessibleTextType
.PARAGRAPH
);
943 log
.println("Exception was expected");
945 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
946 log
.println("Expected exception");
948 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
949 log
.println("UnExpected exception");
954 if (!tEnv
.getTestCase().getObjectName().equals("SmGraphicAccessible")
955 // next one fails because the control actually contains 2 words
956 && !tEnv
.getTestCase().getObjectName().equals("AccessibleStatusBarItem"))
958 log
.print("getTextBeforeIndex(chCount," +
959 " AccessibleTextType.WORD):");
961 txt
= oObj
.getTextBeforeIndex(chCount
,
962 AccessibleTextType
.WORD
);
963 log
.println("'" + txt
.SegmentText
+ "'");
964 res
&= compareLength(chCount
, txt
.SegmentText
);
967 log
.print("getTextBeforeIndex(1," +
968 " AccessibleTextType.PARAGRAPH):");
969 txt
= oObj
.getTextBeforeIndex(1, AccessibleTextType
.PARAGRAPH
);
970 log
.println("'" + txt
.SegmentText
+ "'");
971 res
&= compareLength(0, txt
.SegmentText
);
973 log
.print("getTextBeforeIndex(chCount-1," +
974 " AccessibleTextType.CHARACTER):");
975 txt
= oObj
.getTextBeforeIndex(chCount
- 1,
976 AccessibleTextType
.CHARACTER
);
977 log
.println("'" + txt
.SegmentText
+ "'");
978 res
&= compareStrings(text
.substring(chCount
- 2, chCount
- 1),
982 log
.print("getTextBeforeIndex(2," +
983 " AccessibleTextType.CHARACTER):");
984 txt
= oObj
.getTextBeforeIndex(2, AccessibleTextType
.CHARACTER
);
985 log
.println("'" + txt
.SegmentText
+ "'");
986 res
&= compareStrings(text
.substring(1, 2), txt
.SegmentText
);
988 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
989 log
.println("Unexpected exception");
990 e
.printStackTrace(log
);
992 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
993 log
.println("Unexpected exception");
994 e
.printStackTrace(log
);
998 tRes
.tested("getTextBeforeIndex()", res
);
1002 * Calls the method with invalid parameters an with valid parameters,
1003 * checks returned values.
1004 * Has OK status if exception was thrown for invalid parameters,
1005 * if exception wasn't thrown for valid parameters and if returned values
1006 * are equal to corresponding substrings of the text received by relation.
1007 * The following method tests are to be executed before:
1009 * <li> <code>getCharacterCount()</code> </li>
1012 public void _getTextBehindIndex() {
1013 requiredMethod("getCharacterCount()");
1014 TextSegment txt
= null;
1018 log
.print("getTextBehindIndex(-1, AccessibleTextType.PARAGRAPH):");
1020 txt
= oObj
.getTextBehindIndex(-1,
1021 AccessibleTextType
.PARAGRAPH
);
1022 log
.println("Exception was expected");
1024 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
1025 log
.println("Expected exception");
1027 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
1028 log
.println("UnExpected exception");
1033 log
.print("getTextBehindIndex(chCount+1, " +
1034 "AccessibleTextType.PARAGRAPH):");
1036 txt
= oObj
.getTextBehindIndex(chCount
+ 1,
1037 AccessibleTextType
.PARAGRAPH
);
1038 log
.println("Exception was expected");
1040 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
1041 log
.println("Expected exception");
1043 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
1044 log
.println("UnExpected exception");
1049 log
.print("getTextBehindIndex(chCount," +
1050 " AccessibleTextType.PARAGRAPH):");
1052 txt
= oObj
.getTextBehindIndex(chCount
,
1053 AccessibleTextType
.PARAGRAPH
);
1054 log
.println("'" + txt
.SegmentText
+ "'");
1055 res
&= (txt
.SegmentText
.length() == 0);
1057 log
.print("getTextBehindIndex(chCount-1," +
1058 " AccessibleTextType.PARAGRAPH):");
1059 txt
= oObj
.getTextBehindIndex(chCount
- 1,
1060 AccessibleTextType
.PARAGRAPH
);
1061 log
.println("'" + txt
.SegmentText
+ "'");
1062 res
&= (txt
.SegmentText
.length() == 0);
1064 log
.print("getTextBehindIndex(1," +
1065 " AccessibleTextType.CHARACTER):");
1066 txt
= oObj
.getTextBehindIndex(1, AccessibleTextType
.CHARACTER
);
1067 log
.println("'" + txt
.SegmentText
+ "'");
1068 res
&= txt
.SegmentText
.equals(text
.substring(2, 3));
1071 log
.print("getTextBehindIndex(chCount-2," +
1072 " AccessibleTextType.CHARACTER):");
1073 txt
= oObj
.getTextBehindIndex(chCount
- 2,
1074 AccessibleTextType
.CHARACTER
);
1075 log
.println("'" + txt
.SegmentText
+ "'");
1076 res
&= txt
.SegmentText
.equals(text
.substring(chCount
- 1, chCount
));
1078 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
1079 log
.println("Unexpected exception");
1080 e
.printStackTrace(log
);
1082 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
1083 log
.println("Unexpected exception");
1084 e
.printStackTrace(log
);
1088 tRes
.tested("getTextBehindIndex()", res
);
1092 * Calls the method with invalid parameters an with valid parameter,
1093 * checks returned values.
1094 * Has OK status if exception was thrown for invalid parameters,
1095 * if exception wasn't thrown for valid parameter and if returned value for
1096 * valid parameter is equal to <code>true</code>.
1098 public void _copyText() {
1100 boolean locRes
= true;
1102 if (editOnly
!= null) {
1103 log
.println(editOnly
);
1104 throw new StatusException(Status
.skipped(true));
1108 log
.print("copyText(-1,chCount):");
1109 oObj
.copyText(-1, chCount
);
1110 log
.println("Exception was expected");
1112 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
1113 log
.println("Expected exception");
1118 log
.print("copyText(0,chCount+1):");
1119 oObj
.copyText(0, chCount
+ 1);
1120 log
.println("Exception was expected");
1122 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
1123 log
.println("Expected exception");
1128 log
.print("copyText(0,chCount):");
1129 locRes
= oObj
.copyText(0, chCount
);
1130 log
.println(locRes
);
1133 String cbText
= null;
1136 cbText
= util
.SysUtils
.getSysClipboardText((XMultiServiceFactory
)tParam
.getMSF());
1137 } catch (com
.sun
.star
.uno
.Exception e
) {
1138 log
.println("Couldn't access system clipboard :");
1139 e
.printStackTrace(log
);
1142 log
.println("Clipboard: '" + cbText
+ "'");
1143 res
&= text
.equals(cbText
);
1146 log
.print("copyText(1,chCount-1):");
1147 locRes
= oObj
.copyText(1, chCount
- 1);
1148 log
.println(locRes
);
1152 cbText
= util
.SysUtils
.getSysClipboardText((XMultiServiceFactory
)tParam
.getMSF());
1153 } catch (com
.sun
.star
.uno
.Exception e
) {
1154 log
.println("Couldn't access system clipboard :");
1155 e
.printStackTrace(log
);
1158 log
.println("Clipboard: '" + cbText
+ "'");
1159 res
&= text
.substring(1, chCount
- 1).equals(cbText
);
1161 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
1162 log
.println("Unexpected exception");
1163 e
.printStackTrace(log
);
1167 tRes
.tested("copyText()", res
);
1170 public boolean compareStrings(String expected
, String getting
) {
1171 boolean res
= expected
.equals(getting
);
1174 log
.println("## The result isn't the expected:");
1175 log
.println("\tGetting: " + getting
);
1176 log
.println("\tExpected: " + expected
);
1182 public boolean compareLength(int expected
, String getting
) {
1183 boolean res
= (expected
== getting
.length());
1186 log
.println("## The result isn't the expected:");
1187 log
.println("\tGetting: " + getting
.length());
1188 log
.println("\tExpected: " + expected
);