2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 package ifc
.accessibility
;
20 import lib
.MultiMethodTest
;
22 import lib
.StatusException
;
24 import com
.sun
.star
.accessibility
.AccessibleTextType
;
25 import com
.sun
.star
.accessibility
.TextSegment
;
26 import com
.sun
.star
.accessibility
.XAccessibleComponent
;
27 import com
.sun
.star
.accessibility
.XAccessibleText
;
28 import com
.sun
.star
.awt
.Point
;
29 import com
.sun
.star
.awt
.Rectangle
;
30 import com
.sun
.star
.beans
.PropertyValue
;
31 import com
.sun
.star
.uno
.UnoRuntime
;
35 * Testing <code>com.sun.star.accessibility.XAccessibleText</code>
38 * <li><code> getCaretPosition()</code></li>
39 * <li><code> setCaretPosition()</code></li>
40 * <li><code> getCharacter()</code></li>
41 * <li><code> getCharacterAttributes()</code></li>
42 * <li><code> getCharacterBounds()</code></li>
43 * <li><code> getCharacterCount()</code></li>
44 * <li><code> getIndexAtPoint()</code></li>
45 * <li><code> getSelectedText()</code></li>
46 * <li><code> getSelectionStart()</code></li>
47 * <li><code> getSelectionEnd()</code></li>
48 * <li><code> setSelection()</code></li>
49 * <li><code> getText()</code></li>
50 * <li><code> getTextRange()</code></li>
51 * <li><code> getTextAtIndex()</code></li>
52 * <li><code> getTextBeforeIndex()</code></li>
53 * <li><code> getTextBehindIndex()</code></li>
54 * <li><code> copyText()</code></li>
56 * This test needs the following object relations :
58 * <li> <code>'XAccessibleText.Text'</code> (of type <code>String</code>)
60 * the string presentation of component's text. If the relation
61 * is not specified, then text from method <code>getText()</code>
65 * @see com.sun.star.accessibility.XAccessibleText
67 public class _XAccessibleText
extends MultiMethodTest
{
69 public XAccessibleText oObj
= null;
70 protected com
.sun
.star
.awt
.Rectangle bounds
= null;
72 String editOnly
= null;
73 Object LimitedBounds
= null;
74 Rectangle chBounds
= null;
79 * Retrieves a string representation of the component's text.
80 * The length of retrieved string must be greater than zero.
83 protected void before() {
84 Object xat
= tEnv
.getObjRelation("XAccessibleText");
86 XAccessibleComponent component
= null;
89 oObj
= UnoRuntime
.queryInterface(
90 XAccessibleText
.class, xat
);
91 component
= UnoRuntime
.queryInterface(
92 XAccessibleComponent
.class, xat
);
95 text
= (String
) tEnv
.getObjRelation("XAccessibleText.Text");
98 text
= oObj
.getText();
101 if (text
.length() == 0) {
102 throw new StatusException(Status
.failed(
103 "The length of text must be greater than zero"));
106 editOnly
= (String
) tEnv
.getObjRelation("EditOnly");
107 LimitedBounds
= tEnv
.getObjRelation("LimitedBounds");
109 if (component
== null) {
110 component
= UnoRuntime
.queryInterface(
111 XAccessibleComponent
.class,
112 tEnv
.getTestObject());
115 bounds
= component
.getBounds();
117 log
.println("Text is '" + text
+ "'");
118 System
.out
.println("############################");
122 * Calls the method and checks returned value.
123 * Has OK status if returned value is equal to <code>chCount - 1</code>.
124 * The following method tests are to be executed before:
126 * <li> <code>setCaretPosition()</code> </li>
129 public void _getCaretPosition() {
130 requiredMethod("getCharacterCount()");
132 if (editOnly
!= null) {
133 log
.println(editOnly
);
134 throw new StatusException(Status
.skipped(true));
141 oObj
.setCaretPosition(chCount
- 1);
142 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException ie
) {
145 int carPos
= oObj
.getCaretPosition();
146 log
.println("getCaretPosition: " + carPos
);
149 res
= carPos
== (chCount
- 1);
152 "Object is read only and Caret position couldn't be set");
156 tRes
.tested("getCaretPosition()", res
);
160 * Calls the method with the wrong index and with the correct index
161 * <code>chCount - 1</code>.
162 * Has OK status if exception was thrown for wrong index and
163 * if exception wasn't thrown for the correct index.
164 * The following method tests are to be executed before:
166 * <li> <code>getCharacterCount()</code> </li>
169 public void _setCaretPosition() {
170 requiredMethod("getCharacterCount()");
175 log
.print("setCaretPosition(-1):");
176 oObj
.setCaretPosition(-1);
178 log
.println("exception was expected ... FAILED");
179 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
180 log
.println("expected exception");
185 log
.print("setCaretPosition(chCount+1):");
186 oObj
.setCaretPosition(chCount
+ 1);
188 log
.println("exception was expected ... FAILED");
189 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
190 log
.println("expected exception");
195 log
.println("setCaretPosition(chCount - 1)");
196 oObj
.setCaretPosition(chCount
- 1);
198 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
199 log
.println("unexpected exception ... FAILED");
200 e
.printStackTrace(log
);
204 tRes
.tested("setCaretPosition()", res
);
208 * Calls the method with the wrong index and with the correct indexes.
209 * Checks every character in the text.
210 * Has OK status if exception was thrown for wrong index,
211 * if exception wasn't thrown for the correct index and
212 * if every character is equal to corresponding character in the text.
213 * The following method tests are to be executed before:
215 * <li> <code>getCharacterCount()</code> </li>
218 public void _getCharacter() {
219 requiredMethod("getCharacterCount()");
224 log
.println("getCharacter(-1)");
225 oObj
.getCharacter(-1);
226 log
.println("Exception was expected");
228 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
229 log
.println("Expected exception");
234 log
.println("getCharacter(chCount)");
235 oObj
.getCharacter(chCount
);
236 log
.println("Exception was expected");
238 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
239 log
.println("Expected exception");
244 log
.println("Checking of every character in the text...");
246 boolean isEqCh
= true;
248 for (int i
= 0; i
< chCount
; i
++) {
249 char ch
= oObj
.getCharacter(i
);
250 isEqCh
= ch
== text
.charAt(i
);
254 log
.println("At the position " + i
+
255 "was expected character: " + text
.charAt(i
));
256 log
.println("but was returned: " + ch
);
261 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
262 log
.println("Unexpected exception");
263 e
.printStackTrace(log
);
267 tRes
.tested("getCharacter()", res
);
271 * Calls the method with the wrong indexes and with the correct index,
272 * checks a returned value.
273 * Has OK status if exception was thrown for the wrong indexes,
274 * if exception wasn't thrown for the correct index and
275 * if returned value isn't <code>null</code>.
276 * The following method tests are to be executed before:
278 * <li> <code>getCharacterCount()</code> </li>
281 public void _getCharacterAttributes() {
282 requiredMethod("getCharacterCount()");
285 String
[] attr
= new String
[] { "" };
288 log
.println("getCharacterAttributes(-1)");
289 oObj
.getCharacterAttributes(-1, attr
);
290 log
.println("Exception was expected");
292 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
293 log
.println("Expected exception");
295 } catch(com
.sun
.star
.beans
.UnknownPropertyException e
) {
296 log
.println("unexpected exception => FAILED");
297 e
.printStackTrace(log
);
302 log
.println("getCharacterAttributes(chCount = " + chCount
+ ")");
303 oObj
.getCharacterAttributes(chCount
, attr
);
304 log
.println("Exception was expected");
306 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
307 log
.println("Expected exception");
309 } catch(com
.sun
.star
.beans
.UnknownPropertyException e
) {
310 log
.println("unexpected exception => FAILED");
311 e
.printStackTrace(log
);
317 "getCharacterAttributes(chCount-1 = " + (chCount
- 1) + ")");
319 PropertyValue
[] props
= oObj
.getCharacterAttributes(chCount
- 1,
321 res
&= (props
!= null);
322 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
323 log
.println("Unexpected exception");
324 e
.printStackTrace(log
);
326 } catch(com
.sun
.star
.beans
.UnknownPropertyException e
) {
327 log
.println("unexpected exception => FAILED");
328 e
.printStackTrace(log
);
332 tRes
.tested("getCharacterAttributes()", res
);
336 * Calls the method with the wrong indexes and with the correct index.
337 * checks and stores a returned value.
338 * Has OK status if exception was thrown for the wrong indexes,
339 * if exception wasn't thrown for the correct index and
340 * if returned value isn't <code>null</code>.
341 * The following method tests are to be executed before:
343 * <li> <code>getCharacterCount()</code> </li>
346 public void _getCharacterBounds() {
347 requiredMethod("getCharacterCount()");
351 int lastIndex
= chCount
;
353 if (LimitedBounds
!= null) {
354 if (LimitedBounds
instanceof Integer
) {
355 lastIndex
= ((Integer
) LimitedBounds
).intValue();
357 lastIndex
= chCount
- 1;
360 log
.println(LimitedBounds
);
364 log
.println("getCharacterBounds(-1)");
365 oObj
.getCharacterBounds(-1);
366 log
.println("Exception was expected");
368 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
369 log
.println("Expected exception");
374 log
.println("getCharacterBounds(" + (lastIndex
+ 1) + ")");
375 oObj
.getCharacterBounds(lastIndex
+ 1);
376 log
.println("Exception was expected");
378 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
379 log
.println("Expected exception");
384 for (int i
= 0; i
< lastIndex
; i
++) {
385 log
.println("getCharacterBounds(" + i
+ ")");
386 chBounds
= oObj
.getCharacterBounds(i
);
388 boolean localres
= true;
389 localres
= chBounds
.X
>= 0;
390 localres
&= (chBounds
.Y
>= 0);
391 localres
&= ((chBounds
.X
+ chBounds
.Width
) <= bounds
.Width
);
392 localres
&= ((chBounds
.X
+ chBounds
.Width
) >= 0);
393 localres
&= ((chBounds
.Y
+ chBounds
.Height
) <= bounds
.Height
);
394 localres
&= ((chBounds
.Y
+ chBounds
.Height
) >= 0);
397 log
.println("Text at this place: "+oObj
.getCharacter(i
));
398 log
.println("Character bounds outside component");
399 log
.println("Character rect: " + chBounds
.X
+ ", " +
400 chBounds
.Y
+ ", " + chBounds
.Width
+ ", " +
402 log
.println("Component rect: " + bounds
.X
+ ", " +
403 bounds
.Y
+ ", " + bounds
.Width
+ ", " +
405 //TODO: For some reason that still needs to be investigated,
406 // the above test keeps failing on Mac OS X:
407 if (!System
.getProperty("os.name").equals("Mac OS X")) {
412 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
413 log
.println("Unexpected exception");
414 e
.printStackTrace(log
);
418 tRes
.tested("getCharacterBounds()", res
);
422 * Calls the method and stores a returned value to the variable
423 * <code>chCount</code>.
424 * Has OK status if a returned value is equal to the text length.
426 public void _getCharacterCount() {
427 chCount
= oObj
.getCharacterCount();
428 log
.println("Character count:" + chCount
);
430 boolean res
= chCount
== text
.length();
431 tRes
.tested("getCharacterCount()", res
);
435 * Calls the method for an invalid point and for the point of rectangle
436 * returned by the method <code>getCharacterBounds()</code>.
437 * Has OK status if returned value is equal to <code>-1</code> for an
438 * invalid point and if returned value is equal to <code>chCount-1</code>
440 * The following method tests are to be executed before:
442 * <li> <code>getCharacterBounds()</code> </li>
445 public void _getIndexAtPoint() {
446 //requiredMethod("getCharacterBounds()");
448 log
.print("getIndexAtPoint(-1, -1):");
450 Point pt
= new Point(-1, -1);
451 int index
= oObj
.getIndexAtPoint(pt
);
453 res
&= (index
== -1);
455 int lastIndex
= chCount
;
457 if (LimitedBounds
!= null) {
458 if (LimitedBounds
instanceof Integer
) {
459 lastIndex
= ((Integer
) LimitedBounds
).intValue();
461 lastIndex
= chCount
- 1;
464 log
.println(LimitedBounds
);
467 for (int i
= 0; i
< lastIndex
; i
++) {
468 Rectangle aRect
= null;
469 String text
= "empty";
472 aRect
= oObj
.getCharacterBounds(i
);
473 text
= oObj
.getTextAtIndex(i
, (short) 1).SegmentText
;
474 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
475 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
478 int x
= aRect
.X
+ (aRect
.Width
/ 2);
479 int y
= aRect
.Y
+ (aRect
.Height
/ 2);
480 Point aPoint
= new Point(x
, y
);
481 int nIndex
= oObj
.getIndexAtPoint(aPoint
);
484 y
= aRect
.Y
+ (aRect
.Height
/ 2);
485 aPoint
= new Point(x
, y
);
486 int left
= oObj
.getIndexAtPoint(aPoint
);
490 int[] previous
= (int[]) tEnv
.getObjRelation("PreviousUsed");
492 if (previous
!= null) {
493 for (int k
= 0; k
< previous
.length
; k
++) {
494 if (i
== previous
[k
]) {
501 // for some letters the center of the rectangle isn't recognised
502 // in this case we are happy if the left border of the rectangle
503 // returns the correct value.
505 log
.println("## Method didn't work for Point (" + x
+ "," + y
+
507 log
.println("Expected Index " + i
);
508 log
.println("Gained Index: " + nIndex
);
509 log
.println("Left Border: "+left
);
510 log
.println("CharacterAtIndex: " + text
);
516 tRes
.tested("getIndexAtPoint()", res
);
520 * Checks a returned values after different calls of the method
521 * <code>setSelection()</code>.
522 * The following method tests are to be executed before:
524 * <li> <code>setSelection()</code> </li>
527 public void _getSelectedText() {
528 if (editOnly
!= null) {
529 log
.println(editOnly
);
530 throw new StatusException(Status
.skipped(true));
533 requiredMethod("setSelection()");
538 log
.println("setSelection(0, 0)");
539 oObj
.setSelection(0, 0);
540 log
.print("getSelectedText():");
542 String txt
= oObj
.getSelectedText();
543 log
.println("'" + txt
+ "'");
544 res
&= (txt
.length() == 0);
546 log
.println("setSelection(0, chCount)");
547 oObj
.setSelection(0, chCount
);
548 log
.print("getSelectedText():");
549 txt
= oObj
.getSelectedText();
550 log
.println("'" + txt
+ "'");
551 res
&= txt
.equals(text
);
554 log
.println("setSelection(1, chCount-1)");
555 oObj
.setSelection(1, chCount
- 1);
556 log
.print("getSelectedText():");
557 txt
= oObj
.getSelectedText();
558 log
.println("'" + txt
+ "'");
559 res
&= txt
.equals(text
.substring(1, chCount
- 1));
561 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
562 log
.println("Unexpected exception");
563 e
.printStackTrace(log
);
567 tRes
.tested("getSelectedText()", res
);
571 * Checks a returned values after different calls of the method
572 * <code>setSelection()</code>.
573 * The following method tests are to be executed before:
575 * <li> <code>setSelection()</code> </li>
578 public void _getSelectionStart() {
579 if (editOnly
!= null) {
580 log
.println(editOnly
);
581 throw new StatusException(Status
.skipped(true));
584 requiredMethod("setSelection()");
589 log
.println("setSelection(0, chCount)");
590 oObj
.setSelection(0, chCount
);
592 int start
= oObj
.getSelectionStart();
593 log
.println("getSelectionStart():" + start
);
597 log
.println("setSelection(1, chCount-1)");
598 oObj
.setSelection(1, chCount
- 1);
599 start
= oObj
.getSelectionStart();
600 log
.println("getSelectionStart():" + start
);
603 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
604 log
.println("Unexpected exception");
605 e
.printStackTrace(log
);
609 tRes
.tested("getSelectionStart()", res
);
613 * Checks a returned values after different calls of the method
614 * <code>setSelection()</code>.
615 * The following method tests are to be executed before:
617 * <li> <code>setSelection()</code> </li>
620 public void _getSelectionEnd() {
621 if (editOnly
!= null) {
622 log
.println(editOnly
);
623 throw new StatusException(Status
.skipped(true));
626 requiredMethod("setSelection()");
631 log
.println("setSelection(0, chCount)");
632 oObj
.setSelection(0, chCount
);
634 int end
= oObj
.getSelectionEnd();
635 log
.println("getSelectionEnd():" + end
);
636 res
&= (end
== chCount
);
639 log
.println("setSelection(1, chCount-1)");
640 oObj
.setSelection(1, chCount
- 1);
641 end
= oObj
.getSelectionEnd();
642 log
.println("getSelectionEnd():" + end
);
643 res
&= (end
== (chCount
- 1));
645 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
646 log
.println("Unexpected exception");
647 e
.printStackTrace(log
);
651 tRes
.tested("getSelectionEnd()", res
);
655 * Calls the method with invalid parameters an with valid parameters.
656 * Has OK status if exception was thrown for invalid parameters,
657 * if exception wasn't thrown for valid parameters.
658 * The following method tests are to be executed before:
660 * <li> <code>getCharacterCount()</code> </li>
663 public void _setSelection() {
664 requiredMethod("getCharacterCount()");
667 boolean locRes
= true;
669 if (editOnly
!= null) {
670 log
.println(editOnly
);
671 throw new StatusException(Status
.skipped(true));
675 log
.print("setSelection(-1, chCount-1):");
676 locRes
= oObj
.setSelection(-1, chCount
- 1);
677 log
.println(locRes
+ " excepion was expected");
679 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
680 log
.println("Expected exception");
685 log
.print("setSelection(0, chCount+1):");
686 locRes
= oObj
.setSelection(0, chCount
+ 1);
687 log
.println(locRes
+ " excepion was expected");
689 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
690 log
.println("Expected exception");
696 log
.print("setSelection(1, chCount-1):");
697 locRes
= oObj
.setSelection(1, chCount
- 1);
701 log
.print("setSelection(chCount-1, 1):");
702 locRes
= oObj
.setSelection(chCount
- 1, 1);
707 log
.print("setSelection(0, chCount-1):");
708 locRes
= oObj
.setSelection(0, chCount
- 1);
712 log
.print("setSelection(chCount-1, 0):");
713 locRes
= oObj
.setSelection(chCount
- 1, 0);
717 log
.print("setSelection(0, 0):");
718 locRes
= oObj
.setSelection(0, 0);
721 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
722 log
.println("Unexpected exception");
723 e
.printStackTrace(log
);
727 tRes
.tested("setSelection()", res
);
731 * Calls the method and checks returned value.
732 * Has OK status if returned string is equal to string
733 * received from relation.
735 public void _getText() {
736 String txt
= oObj
.getText();
737 log
.println("getText: " + txt
);
739 boolean res
= txt
.equals(text
);
740 tRes
.tested("getText()", res
);
744 * Calls the method with invalid parameters an with valid parameters,
745 * checks returned values.
746 * Has OK status if exception was thrown for invalid parameters,
747 * if exception wasn't thrown for valid parameters and if returned values
748 * are equal to corresponding substrings of the text received by relation.
749 * The following method tests are to be executed before:
751 * <li> <code>getCharacterCount()</code> </li>
754 public void _getTextRange() {
755 requiredMethod("getCharacterCount()");
758 boolean locRes
= true;
760 String txtRange
= "";
764 log
.print("getTextRange(1, chCount - 2): ");
766 txtRange
= oObj
.getTextRange(1, chCount
- 2);
767 log
.println(txtRange
);
768 locRes
= txtRange
.equals(text
.substring(1, chCount
- 2));
772 log
.println("Was expected: " +
773 text
.substring(1, chCount
- 2));
777 log
.print("getTextRange(0, chCount-1): ");
779 txtRange
= oObj
.getTextRange(0, chCount
- 1);
780 log
.println(txtRange
);
781 locRes
= txtRange
.equals(text
.substring(0, chCount
- 1));
785 log
.println("Was expected: " +
786 text
.substring(0, chCount
- 1));
789 log
.print("getTextRange(chCount, 0): ");
790 txtRange
= oObj
.getTextRange(chCount
, 0);
791 log
.println(txtRange
);
792 res
&= txtRange
.equals(text
);
794 log
.print("getTextRange(0, 0): ");
795 txtRange
= oObj
.getTextRange(0, 0);
796 log
.println(txtRange
);
797 locRes
= txtRange
.equals("");
801 log
.println("Empty string was expected");
803 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
804 log
.println("Unexpected exception");
805 e
.printStackTrace(log
);
810 log
.print("getTextRange(-1, chCount - 1): ");
812 txtRange
= oObj
.getTextRange(-1, chCount
- 1);
813 log
.println("Exception was expected");
815 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
816 log
.println("Expected exception");
821 log
.print("getTextRange(0, chCount + 1): ");
823 txtRange
= oObj
.getTextRange(0, chCount
+ 1);
824 log
.println("Exception was expected");
826 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
827 log
.println("Expected exception");
832 log
.print("getTextRange(chCount+1, -1): ");
834 txtRange
= oObj
.getTextRange(chCount
+ 1, -1);
835 log
.println("Exception was expected");
837 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
838 log
.println("Expected exception");
842 tRes
.tested("getTextRange()", res
);
846 * Calls the method with invalid parameters an with valid parameters,
847 * checks returned values.
848 * Has OK status if exception was thrown for invalid parameters,
849 * if exception wasn't thrown for valid parameters and if returned values
850 * are equal to corresponding substrings of the text received by relation.
851 * The following method tests are to be executed before:
853 * <li> <code>getCharacterCount()</code> </li>
856 public void _getTextAtIndex() {
857 requiredMethod("getCharacterCount()");
858 TextSegment txt
= null;
862 log
.print("getTextAtIndex(-1, AccessibleTextType.PARAGRAPH):");
864 txt
= oObj
.getTextAtIndex(-1,
865 AccessibleTextType
.PARAGRAPH
);
866 log
.println("Exception was expected");
868 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
869 log
.println("Expected exception");
871 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
872 log
.println("UnExpected exception");
877 log
.print("getTextAtIndex(chCount+1," +
878 " AccessibleTextType.PARAGRAPH):");
880 txt
= oObj
.getTextAtIndex(chCount
+ 1,
881 AccessibleTextType
.PARAGRAPH
);
882 log
.println("Exception was expected");
884 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
885 log
.println("Expected exception");
887 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
888 log
.println("UnExpected exception");
893 log
.print("getTextAtIndex(chCount," +
894 " AccessibleTextType.WORD):");
896 txt
= oObj
.getTextAtIndex(chCount
, AccessibleTextType
.WORD
);
897 log
.println("'" + txt
.SegmentText
+ "'");
898 res
&= compareLength(0,txt
.SegmentText
);
899 if (!tEnv
.getTestCase().getObjectName().equals("SmGraphicAccessible")) {
900 log
.print("getTextAtIndex(1," +
901 " AccessibleTextType.PARAGRAPH):");
902 txt
= oObj
.getTextAtIndex(1, AccessibleTextType
.PARAGRAPH
);
903 log
.println("'" + txt
.SegmentText
+ "'");
904 res
&= compareStrings(text
,txt
.SegmentText
);
906 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
907 log
.println("Unexpected exception");
908 e
.printStackTrace(log
);
910 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
911 log
.println("Unexpected exception");
912 e
.printStackTrace(log
);
916 tRes
.tested("getTextAtIndex()", res
);
920 * Calls the method with invalid parameters an with valid parameters,
921 * checks returned values.
922 * Has OK status if exception was thrown for invalid parameters,
923 * if exception wasn't thrown for valid parameters and if returned values
924 * are equal to corresponding substrings of the text received by relation.
925 * The following method tests are to be executed before:
927 * <li> <code>getCharacterCount()</code> </li>
930 public void _getTextBeforeIndex() {
931 requiredMethod("getCharacterCount()");
932 TextSegment txt
= null;
936 log
.print("getTextBeforeIndex(-1, AccessibleTextType.PARAGRAPH):");
938 txt
= oObj
.getTextBeforeIndex(-1,
939 AccessibleTextType
.PARAGRAPH
);
940 log
.println("Exception was expected");
942 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
943 log
.println("Expected exception");
945 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
946 log
.println("UnExpected exception");
951 log
.print("getTextBeforeIndex(chCount+1, " +
952 "AccessibleTextType.PARAGRAPH):");
954 txt
= oObj
.getTextBeforeIndex(chCount
+ 1,
955 AccessibleTextType
.PARAGRAPH
);
956 log
.println("Exception was expected");
958 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
959 log
.println("Expected exception");
961 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
962 log
.println("UnExpected exception");
967 if (!tEnv
.getTestCase().getObjectName().equals("SmGraphicAccessible")
968 // next one fails because the control actually contains 2 words
969 && !tEnv
.getTestCase().getObjectName().equals("AccessibleStatusBarItem"))
971 log
.print("getTextBeforeIndex(chCount," +
972 " AccessibleTextType.WORD):");
974 txt
= oObj
.getTextBeforeIndex(chCount
,
975 AccessibleTextType
.WORD
);
976 log
.println("'" + txt
.SegmentText
+ "'");
977 res
&= compareLength(chCount
, txt
.SegmentText
);
980 log
.print("getTextBeforeIndex(1," +
981 " AccessibleTextType.PARAGRAPH):");
982 txt
= oObj
.getTextBeforeIndex(1, AccessibleTextType
.PARAGRAPH
);
983 log
.println("'" + txt
.SegmentText
+ "'");
984 res
&= compareLength(0, txt
.SegmentText
);
986 log
.print("getTextBeforeIndex(chCount-1," +
987 " AccessibleTextType.CHARACTER):");
988 txt
= oObj
.getTextBeforeIndex(chCount
- 1,
989 AccessibleTextType
.CHARACTER
);
990 log
.println("'" + txt
.SegmentText
+ "'");
991 res
&= compareStrings(text
.substring(chCount
- 2, chCount
- 1),
995 log
.print("getTextBeforeIndex(2," +
996 " AccessibleTextType.CHARACTER):");
997 txt
= oObj
.getTextBeforeIndex(2, AccessibleTextType
.CHARACTER
);
998 log
.println("'" + txt
.SegmentText
+ "'");
999 res
&= compareStrings(text
.substring(1, 2), txt
.SegmentText
);
1001 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
1002 log
.println("Unexpected exception");
1003 e
.printStackTrace(log
);
1005 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
1006 log
.println("Unexpected exception");
1007 e
.printStackTrace(log
);
1011 tRes
.tested("getTextBeforeIndex()", res
);
1015 * Calls the method with invalid parameters an with valid parameters,
1016 * checks returned values.
1017 * Has OK status if exception was thrown for invalid parameters,
1018 * if exception wasn't thrown for valid parameters and if returned values
1019 * are equal to corresponding substrings of the text received by relation.
1020 * The following method tests are to be executed before:
1022 * <li> <code>getCharacterCount()</code> </li>
1025 public void _getTextBehindIndex() {
1026 requiredMethod("getCharacterCount()");
1027 TextSegment txt
= null;
1031 log
.print("getTextBehindIndex(-1, AccessibleTextType.PARAGRAPH):");
1033 txt
= oObj
.getTextBehindIndex(-1,
1034 AccessibleTextType
.PARAGRAPH
);
1035 log
.println("Exception was expected");
1037 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
1038 log
.println("Expected exception");
1040 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
1041 log
.println("UnExpected exception");
1046 log
.print("getTextBehindIndex(chCount+1, " +
1047 "AccessibleTextType.PARAGRAPH):");
1049 txt
= oObj
.getTextBehindIndex(chCount
+ 1,
1050 AccessibleTextType
.PARAGRAPH
);
1051 log
.println("Exception was expected");
1053 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
1054 log
.println("Expected exception");
1056 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
1057 log
.println("UnExpected exception");
1062 log
.print("getTextBehindIndex(chCount," +
1063 " AccessibleTextType.PARAGRAPH):");
1065 txt
= oObj
.getTextBehindIndex(chCount
,
1066 AccessibleTextType
.PARAGRAPH
);
1067 log
.println("'" + txt
.SegmentText
+ "'");
1068 res
&= (txt
.SegmentText
.length() == 0);
1070 log
.print("getTextBehindIndex(chCount-1," +
1071 " AccessibleTextType.PARAGRAPH):");
1072 txt
= oObj
.getTextBehindIndex(chCount
- 1,
1073 AccessibleTextType
.PARAGRAPH
);
1074 log
.println("'" + txt
.SegmentText
+ "'");
1075 res
&= (txt
.SegmentText
.length() == 0);
1077 log
.print("getTextBehindIndex(1," +
1078 " AccessibleTextType.CHARACTER):");
1079 txt
= oObj
.getTextBehindIndex(1, AccessibleTextType
.CHARACTER
);
1080 log
.println("'" + txt
.SegmentText
+ "'");
1081 res
&= txt
.SegmentText
.equals(text
.substring(2, 3));
1084 log
.print("getTextBehindIndex(chCount-2," +
1085 " AccessibleTextType.CHARACTER):");
1086 txt
= oObj
.getTextBehindIndex(chCount
- 2,
1087 AccessibleTextType
.CHARACTER
);
1088 log
.println("'" + txt
.SegmentText
+ "'");
1089 res
&= txt
.SegmentText
.equals(text
.substring(chCount
- 1, chCount
));
1091 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
1092 log
.println("Unexpected exception");
1093 e
.printStackTrace(log
);
1095 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
1096 log
.println("Unexpected exception");
1097 e
.printStackTrace(log
);
1101 tRes
.tested("getTextBehindIndex()", res
);
1105 * Calls the method with invalid parameters an with valid parameter,
1106 * checks returned values.
1107 * Has OK status if exception was thrown for invalid parameters,
1108 * if exception wasn't thrown for valid parameter and if returned value for
1109 * valid parameter is equal to <code>true</code>.
1111 public void _copyText() {
1113 boolean locRes
= true;
1115 if (editOnly
!= null) {
1116 log
.println(editOnly
);
1117 throw new StatusException(Status
.skipped(true));
1121 log
.print("copyText(-1,chCount):");
1122 oObj
.copyText(-1, chCount
);
1123 log
.println("Exception was expected");
1125 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
1126 log
.println("Expected exception");
1131 log
.print("copyText(0,chCount+1):");
1132 oObj
.copyText(0, chCount
+ 1);
1133 log
.println("Exception was expected");
1135 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
1136 log
.println("Expected exception");
1141 log
.print("copyText(0,chCount):");
1142 locRes
= oObj
.copyText(0, chCount
);
1143 log
.println(locRes
);
1146 String cbText
= null;
1149 cbText
= util
.SysUtils
.getSysClipboardText(tParam
.getMSF());
1150 } catch (com
.sun
.star
.uno
.Exception e
) {
1151 log
.println("Couldn't access system clipboard :");
1152 e
.printStackTrace(log
);
1155 log
.println("Clipboard: '" + cbText
+ "'");
1156 res
&= text
.equals(cbText
);
1159 log
.print("copyText(1,chCount-1):");
1160 locRes
= oObj
.copyText(1, chCount
- 1);
1161 log
.println(locRes
);
1165 cbText
= util
.SysUtils
.getSysClipboardText(tParam
.getMSF());
1166 } catch (com
.sun
.star
.uno
.Exception e
) {
1167 log
.println("Couldn't access system clipboard :");
1168 e
.printStackTrace(log
);
1171 log
.println("Clipboard: '" + cbText
+ "'");
1172 res
&= text
.substring(1, chCount
- 1).equals(cbText
);
1174 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
1175 log
.println("Unexpected exception");
1176 e
.printStackTrace(log
);
1180 tRes
.tested("copyText()", res
);
1183 public boolean compareStrings(String expected
, String getting
) {
1184 boolean res
= expected
.equals(getting
);
1187 log
.println("## The result isn't the expected:");
1188 log
.println("\tGetting: " + getting
);
1189 log
.println("\tExpected: " + expected
);
1195 public boolean compareLength(int expected
, String getting
) {
1196 boolean res
= (expected
== getting
.length());
1199 log
.println("## The result isn't the expected:");
1200 log
.println("\tGetting: " + getting
.length());
1201 log
.println("\tExpected: " + expected
);