Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / qadevOOo / tests / java / ifc / accessibility / _XAccessibleText.java
blob8ccb6fa5093d848e58a1253d4997eb300788e336
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
27 package ifc.accessibility;
29 import lib.MultiMethodTest;
30 import lib.Status;
31 import lib.StatusException;
33 import com.sun.star.accessibility.AccessibleTextType;
34 import com.sun.star.accessibility.TextSegment;
35 import com.sun.star.accessibility.XAccessibleComponent;
36 import com.sun.star.accessibility.XAccessibleText;
37 import com.sun.star.awt.Point;
38 import com.sun.star.awt.Rectangle;
39 import com.sun.star.beans.PropertyValue;
40 import com.sun.star.lang.XMultiServiceFactory;
41 import com.sun.star.uno.UnoRuntime;
44 /**
45 * Testing <code>com.sun.star.accessibility.XAccessibleText</code>
46 * interface methods :
47 * <ul>
48 * <li><code> getCaretPosition()</code></li>
49 * <li><code> setCaretPosition()</code></li>
50 * <li><code> getCharacter()</code></li>
51 * <li><code> getCharacterAttributes()</code></li>
52 * <li><code> getCharacterBounds()</code></li>
53 * <li><code> getCharacterCount()</code></li>
54 * <li><code> getIndexAtPoint()</code></li>
55 * <li><code> getSelectedText()</code></li>
56 * <li><code> getSelectionStart()</code></li>
57 * <li><code> getSelectionEnd()</code></li>
58 * <li><code> setSelection()</code></li>
59 * <li><code> getText()</code></li>
60 * <li><code> getTextRange()</code></li>
61 * <li><code> getTextAtIndex()</code></li>
62 * <li><code> getTextBeforeIndex()</code></li>
63 * <li><code> getTextBehindIndex()</code></li>
64 * <li><code> copyText()</code></li>
65 * </ul> <p>
66 * This test needs the following object relations :
67 * <ul>
68 * <li> <code>'XAccessibleText.Text'</code> (of type <code>String</code>)
69 * <b> optional </b> :
70 * the string presentation of component's text. If the relation
71 * is not specified, then text from method <code>getText()</code>
72 * is used.
73 * </li>
74 * </ul> <p>
75 * @see com.sun.star.accessibility.XAccessibleText
77 public class _XAccessibleText extends MultiMethodTest {
79 public XAccessibleText oObj = null;
80 protected com.sun.star.awt.Rectangle bounds = null;
81 String text = null;
82 String editOnly = null;
83 Object LimitedBounds = null;
84 Rectangle chBounds = null;
85 int chCount = 0;
88 /**
89 * Retrieves a string representation of the component's text.
90 * The length of retrieved string must be greater than zero.
92 protected void before() {
93 Object xat = tEnv.getObjRelation("XAccessibleText");
95 XAccessibleComponent component = null;
97 if (xat != null) {
98 oObj = (XAccessibleText) UnoRuntime.queryInterface(
99 XAccessibleText.class, xat);
100 component = (XAccessibleComponent) UnoRuntime.queryInterface(
101 XAccessibleComponent.class, xat);
104 text = (String) tEnv.getObjRelation("XAccessibleText.Text");
106 if (text == null) {
107 text = oObj.getText();
110 if (text.length() == 0) {
111 throw new StatusException(Status.failed(
112 "The length of text must be greater than zero"));
115 editOnly = (String) tEnv.getObjRelation("EditOnly");
116 LimitedBounds = tEnv.getObjRelation("LimitedBounds");
118 if (component == null) {
119 component = (XAccessibleComponent) UnoRuntime.queryInterface(
120 XAccessibleComponent.class,
121 tEnv.getTestObject());
124 bounds = component.getBounds();
126 log.println("Text is '" + text + "'");
127 System.out.println("############################");
131 * Calls the method and checks returned value.
132 * Has OK status if returned value is equal to <code>chCount - 1</code>.
133 * The following method tests are to be executed before:
134 * <ul>
135 * <li> <code>setCaretPosition()</code> </li>
136 * </ul>
138 public void _getCaretPosition() {
139 requiredMethod("getCharacterCount()");
141 if (editOnly != null) {
142 log.println(editOnly);
143 throw new StatusException(Status.skipped(true));
146 boolean res = true;
147 boolean sc = true;
149 try {
150 oObj.setCaretPosition(chCount - 1);
151 } catch (com.sun.star.lang.IndexOutOfBoundsException ie) {
154 int carPos = oObj.getCaretPosition();
155 log.println("getCaretPosition: " + carPos);
157 if (sc) {
158 res = carPos == (chCount - 1);
159 } else {
160 log.println(
161 "Object is read only and Caret position couldn't be set");
162 res = carPos == -1;
165 tRes.tested("getCaretPosition()", res);
169 * Calls the method with the wrong index and with the correct index
170 * <code>chCount - 1</code>.
171 * Has OK status if exception was thrown for wrong index and
172 * if exception wasn't thrown for the correct index.
173 * The following method tests are to be executed before:
174 * <ul>
175 * <li> <code>getCharacterCount()</code> </li>
176 * </ul>
178 public void _setCaretPosition() {
179 requiredMethod("getCharacterCount()");
181 boolean res = true;
183 try {
184 log.print("setCaretPosition(-1):");
185 oObj.setCaretPosition(-1);
186 res &= false;
187 log.println("exception was expected ... FAILED");
188 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
189 log.println("expected exception");
190 res &= true;
193 try {
194 log.print("setCaretPosition(chCount+1):");
195 oObj.setCaretPosition(chCount + 1);
196 res &= false;
197 log.println("exception was expected ... FAILED");
198 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
199 log.println("expected exception");
200 res &= true;
203 try {
204 log.println("setCaretPosition(chCount - 1)");
205 oObj.setCaretPosition(chCount - 1);
206 res &= true;
207 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
208 log.println("unexpected exception ... FAILED");
209 e.printStackTrace(log);
210 res &= false;
213 tRes.tested("setCaretPosition()", res);
217 * Calls the method with the wrong index and with the correct indexes.
218 * Checks every character in the text.
219 * Has OK status if exception was thrown for wrong index,
220 * if exception wasn't thrown for the correct index and
221 * if every character is equal to corresponding character in the text.
222 * The following method tests are to be executed before:
223 * <ul>
224 * <li> <code>getCharacterCount()</code> </li>
225 * </ul>
227 public void _getCharacter() {
228 requiredMethod("getCharacterCount()");
230 boolean res = true;
232 try {
233 log.println("getCharacter(-1)");
234 oObj.getCharacter(-1);
235 log.println("Exception was expected");
236 res = false;
237 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
238 log.println("Expected exception");
239 res = true;
242 try {
243 log.println("getCharacter(chCount)");
244 oObj.getCharacter(chCount);
245 log.println("Exception was expected");
246 res &= false;
247 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
248 log.println("Expected exception");
249 res &= true;
252 try {
253 log.println("Checking of every character in the text...");
255 boolean isEqCh = true;
257 for (int i = 0; i < chCount; i++) {
258 char ch = oObj.getCharacter(i);
259 isEqCh = ch == text.charAt(i);
260 res &= isEqCh;
262 if (!isEqCh) {
263 log.println("At the position " + i +
264 "was expected character: " + text.charAt(i));
265 log.println("but was returned: " + ch);
267 break;
270 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
271 log.println("Unexpected exception");
272 e.printStackTrace(log);
273 res &= false;
276 tRes.tested("getCharacter()", res);
280 * Calls the method with the wrong indexes and with the correct index,
281 * checks a returned value.
282 * Has OK status if exception was thrown for the wrong indexes,
283 * if exception wasn't thrown for the correct index and
284 * if returned value isn't <code>null</code>.
285 * The following method tests are to be executed before:
286 * <ul>
287 * <li> <code>getCharacterCount()</code> </li>
288 * </ul>
290 public void _getCharacterAttributes() {
291 requiredMethod("getCharacterCount()");
293 boolean res = true;
294 String[] attr = new String[] { "" };
296 try {
297 log.println("getCharacterAttributes(-1)");
298 oObj.getCharacterAttributes(-1, attr);
299 log.println("Exception was expected");
300 res &= false;
301 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
302 log.println("Expected exception");
303 res &= true;
306 try {
307 log.println("getCharacterAttributes(chCount)");
308 oObj.getCharacterAttributes(chCount, attr);
309 log.println("Exception was expected");
310 res &= false;
311 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
312 log.println("Expected exception");
313 res &= true;
316 try {
317 log.println("getCharacterAttributes(chCount-1)");
319 PropertyValue[] props = oObj.getCharacterAttributes(chCount - 1,
320 attr);
321 res &= (props != null);
322 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
323 log.println("Unexpected exception");
324 e.printStackTrace(log);
325 res &= false;
328 tRes.tested("getCharacterAttributes()", res);
332 * Calls the method with the wrong indexes and with the correct index.
333 * checks and stores a returned value.
334 * Has OK status if exception was thrown for the wrong indexes,
335 * if exception wasn't thrown for the correct index and
336 * if returned value isn't <code>null</code>.
337 * The following method tests are to be executed before:
338 * <ul>
339 * <li> <code>getCharacterCount()</code> </li>
340 * </ul>
342 public void _getCharacterBounds() {
343 requiredMethod("getCharacterCount()");
345 boolean res = true;
347 int lastIndex = chCount;
349 if (LimitedBounds != null) {
350 if (LimitedBounds instanceof Integer) {
351 lastIndex = ((Integer) LimitedBounds).intValue();
352 } else {
353 lastIndex = chCount - 1;
356 log.println(LimitedBounds);
359 try {
360 log.println("getCharacterBounds(-1)");
361 oObj.getCharacterBounds(-1);
362 log.println("Exception was expected");
363 res &= false;
364 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
365 log.println("Expected exception");
366 res &= true;
369 try {
370 log.println("getCharacterBounds(" + (lastIndex + 1) + ")");
371 oObj.getCharacterBounds(lastIndex + 1);
372 log.println("Exception was expected");
373 res &= false;
374 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
375 log.println("Expected exception");
376 res &= true;
379 try {
380 for (int i = 0; i < lastIndex; i++) {
381 log.println("getCharacterBounds(" + i + ")");
382 chBounds = oObj.getCharacterBounds(i);
384 boolean localres = true;
385 localres = chBounds.X >= 0;
386 localres &= (chBounds.Y >= 0);
387 localres &= ((chBounds.X + chBounds.Width) <= bounds.Width);
388 localres &= ((chBounds.X + chBounds.Width) >= 0);
389 localres &= ((chBounds.Y + chBounds.Height) <= bounds.Height);
390 localres &= ((chBounds.Y + chBounds.Height) >= 0);
392 if (!localres) {
393 log.println("Text at this place: "+oObj.getCharacter(i));
394 log.println("Character bounds outside component");
395 log.println("Character rect: " + chBounds.X + ", " +
396 chBounds.Y + ", " + chBounds.Width + ", " +
397 chBounds.Height);
398 log.println("Component rect: " + bounds.X + ", " +
399 bounds.Y + ", " + bounds.Width + ", " +
400 bounds.Height);
401 res &= localres;
404 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
405 log.println("Unexpected exception");
406 e.printStackTrace(log);
407 res &= false;
410 tRes.tested("getCharacterBounds()", res);
414 * Calls the method and stores a returned value to the variable
415 * <code>chCount</code>.
416 * Has OK status if a returned value is equal to the text length.
418 public void _getCharacterCount() {
419 chCount = oObj.getCharacterCount();
420 log.println("Character count:" + chCount);
422 boolean res = chCount == text.length();
423 tRes.tested("getCharacterCount()", res);
427 * Calls the method for an invalid point and for the point of rectangle
428 * returned by the method <code>getCharacterBounds()</code>.
429 * Has OK status if returned value is equal to <code>-1</code> for an
430 * invalid point and if returned value is equal to <code>chCount-1</code>
431 * for a valid point.
432 * The following method tests are to be executed before:
433 * <ul>
434 * <li> <code>getCharacterBounds()</code> </li>
435 * </ul>
437 public void _getIndexAtPoint() {
438 //requiredMethod("getCharacterBounds()");
439 boolean res = true;
440 log.print("getIndexAtPoint(-1, -1):");
442 Point pt = new Point(-1, -1);
443 int index = oObj.getIndexAtPoint(pt);
444 log.println(index);
445 res &= (index == -1);
447 int lastIndex = chCount;
449 if (LimitedBounds != null) {
450 if (LimitedBounds instanceof Integer) {
451 lastIndex = ((Integer) LimitedBounds).intValue();
452 } else {
453 lastIndex = chCount - 1;
456 log.println(LimitedBounds);
459 for (int i = 0; i < lastIndex; i++) {
460 Rectangle aRect = null;
461 String text = "empty";
463 try {
464 aRect = oObj.getCharacterBounds(i);
465 text = oObj.getTextAtIndex(i, (short) 1).SegmentText;
466 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
467 } catch (com.sun.star.lang.IllegalArgumentException e) {
470 int x = aRect.X + (aRect.Width / 2);
471 int y = aRect.Y + (aRect.Height / 2);
472 Point aPoint = new Point(x, y);
473 int nIndex = oObj.getIndexAtPoint(aPoint);
475 x = aRect.X;
476 y = aRect.Y + (aRect.Height / 2);
477 aPoint = new Point(x, y);
478 int left = oObj.getIndexAtPoint(aPoint);
482 int[] previous = (int[]) tEnv.getObjRelation("PreviousUsed");
484 if (previous != null) {
485 for (int k = 0; k < previous.length; k++) {
486 if (i == previous[k]) {
487 nIndex++;
492 if (nIndex != i) {
493 // for some letters the center of the rectangle isn't recognised
494 // in this case we are happy if the left border of the rectangle
495 // returns the correct value.
496 if (left !=i) {
497 log.println("## Method didn't work for Point (" + x + "," + y +
498 ")");
499 log.println("Expected Index " + i);
500 log.println("Gained Index: " + nIndex);
501 log.println("Left Border: "+left);
502 log.println("CharacterAtIndex: " + text);
503 res &= false;
508 tRes.tested("getIndexAtPoint()", res);
512 * Checks a returned values after different calls of the method
513 * <code>setSelection()</code>.
514 * The following method tests are to be executed before:
515 * <ul>
516 * <li> <code>setSelection()</code> </li>
517 * </ul>
519 public void _getSelectedText() {
520 if (editOnly != null) {
521 log.println(editOnly);
522 throw new StatusException(Status.skipped(true));
525 requiredMethod("setSelection()");
527 boolean res = true;
529 try {
530 log.println("setSelection(0, 0)");
531 oObj.setSelection(0, 0);
532 log.print("getSelectedText():");
534 String txt = oObj.getSelectedText();
535 log.println("'" + txt + "'");
536 res &= (txt.length() == 0);
538 log.println("setSelection(0, chCount)");
539 oObj.setSelection(0, chCount);
540 log.print("getSelectedText():");
541 txt = oObj.getSelectedText();
542 log.println("'" + txt + "'");
543 res &= txt.equals(text);
545 if (chCount > 2) {
546 log.println("setSelection(1, chCount-1)");
547 oObj.setSelection(1, chCount - 1);
548 log.print("getSelectedText():");
549 txt = oObj.getSelectedText();
550 log.println("'" + txt + "'");
551 res &= txt.equals(text.substring(1, chCount - 1));
553 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
554 log.println("Unexpected exception");
555 e.printStackTrace(log);
556 res &= false;
559 tRes.tested("getSelectedText()", res);
563 * Checks a returned values after different calls of the method
564 * <code>setSelection()</code>.
565 * The following method tests are to be executed before:
566 * <ul>
567 * <li> <code>setSelection()</code> </li>
568 * </ul>
570 public void _getSelectionStart() {
571 if (editOnly != null) {
572 log.println(editOnly);
573 throw new StatusException(Status.skipped(true));
576 requiredMethod("setSelection()");
578 boolean res = true;
580 try {
581 log.println("setSelection(0, chCount)");
582 oObj.setSelection(0, chCount);
584 int start = oObj.getSelectionStart();
585 log.println("getSelectionStart():" + start);
586 res &= (start == 0);
588 if (chCount > 2) {
589 log.println("setSelection(1, chCount-1)");
590 oObj.setSelection(1, chCount - 1);
591 start = oObj.getSelectionStart();
592 log.println("getSelectionStart():" + start);
593 res &= (start == 1);
595 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
596 log.println("Unexpected exception");
597 e.printStackTrace(log);
598 res &= false;
601 tRes.tested("getSelectionStart()", res);
605 * Checks a returned values after different calls of the method
606 * <code>setSelection()</code>.
607 * The following method tests are to be executed before:
608 * <ul>
609 * <li> <code>setSelection()</code> </li>
610 * </ul>
612 public void _getSelectionEnd() {
613 if (editOnly != null) {
614 log.println(editOnly);
615 throw new StatusException(Status.skipped(true));
618 requiredMethod("setSelection()");
620 boolean res = true;
622 try {
623 log.println("setSelection(0, chCount)");
624 oObj.setSelection(0, chCount);
626 int end = oObj.getSelectionEnd();
627 log.println("getSelectionEnd():" + end);
628 res &= (end == chCount);
630 if (chCount > 2) {
631 log.println("setSelection(1, chCount-1)");
632 oObj.setSelection(1, chCount - 1);
633 end = oObj.getSelectionEnd();
634 log.println("getSelectionEnd():" + end);
635 res &= (end == (chCount - 1));
637 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
638 log.println("Unexpected exception");
639 e.printStackTrace(log);
640 res &= false;
643 tRes.tested("getSelectionEnd()", res);
647 * Calls the method with invalid parameters an with valid parameters.
648 * Has OK status if exception was thrown for invalid parameters,
649 * if exception wasn't thrown for valid parameters.
650 * The following method tests are to be executed before:
651 * <ul>
652 * <li> <code>getCharacterCount()</code> </li>
653 * </ul>
655 public void _setSelection() {
656 requiredMethod("getCharacterCount()");
658 boolean res = true;
659 boolean locRes = true;
661 if (editOnly != null) {
662 log.println(editOnly);
663 throw new StatusException(Status.skipped(true));
666 try {
667 log.print("setSelection(-1, chCount-1):");
668 locRes = oObj.setSelection(-1, chCount - 1);
669 log.println(locRes + " excepion was expected");
670 res &= !locRes;
671 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
672 log.println("Expected exception");
673 res &= true;
676 try {
677 log.print("setSelection(0, chCount+1):");
678 locRes = oObj.setSelection(0, chCount + 1);
679 log.println(locRes + " excepion was expected");
680 res &= !locRes;
681 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
682 log.println("Expected exception");
683 res &= true;
686 try {
687 if (chCount > 2) {
688 log.print("setSelection(1, chCount-1):");
689 locRes = oObj.setSelection(1, chCount - 1);
690 log.println(locRes);
691 res &= locRes;
693 log.print("setSelection(chCount-1, 1):");
694 locRes = oObj.setSelection(chCount - 1, 1);
695 log.println(locRes);
696 res &= locRes;
699 log.print("setSelection(0, chCount-1):");
700 locRes = oObj.setSelection(0, chCount - 1);
701 log.println(locRes);
702 res &= locRes;
704 log.print("setSelection(chCount-1, 0):");
705 locRes = oObj.setSelection(chCount - 1, 0);
706 log.println(locRes);
707 res &= locRes;
709 log.print("setSelection(0, 0):");
710 locRes = oObj.setSelection(0, 0);
711 log.println(locRes);
712 res &= locRes;
713 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
714 log.println("Unexpected exception");
715 e.printStackTrace(log);
716 res &= false;
719 tRes.tested("setSelection()", res);
723 * Calls the method and checks returned value.
724 * Has OK status if returned string is equal to string
725 * received from relation.
727 public void _getText() {
728 String txt = oObj.getText();
729 log.println("getText: " + txt);
731 boolean res = txt.equals(text);
732 tRes.tested("getText()", res);
736 * Calls the method with invalid parameters an with valid parameters,
737 * checks returned values.
738 * Has OK status if exception was thrown for invalid parameters,
739 * if exception wasn't thrown for valid parameters and if returned values
740 * are equal to corresponding substrings of the text received by relation.
741 * The following method tests are to be executed before:
742 * <ul>
743 * <li> <code>getCharacterCount()</code> </li>
744 * </ul>
746 public void _getTextRange() {
747 requiredMethod("getCharacterCount()");
749 boolean res = true;
750 boolean locRes = true;
752 String txtRange = "";
754 try {
755 if (chCount > 3) {
756 log.print("getTextRange(1, chCount - 2): ");
758 txtRange = oObj.getTextRange(1, chCount - 2);
759 log.println(txtRange);
760 locRes = txtRange.equals(text.substring(1, chCount - 2));
761 res &= locRes;
763 if (!locRes) {
764 log.println("Was expected: " +
765 text.substring(1, chCount - 2));
769 log.print("getTextRange(0, chCount-1): ");
771 txtRange = oObj.getTextRange(0, chCount - 1);
772 log.println(txtRange);
773 locRes = txtRange.equals(text.substring(0, chCount - 1));
774 res &= locRes;
776 if (!locRes) {
777 log.println("Was expected: " +
778 text.substring(0, chCount - 1));
781 log.print("getTextRange(chCount, 0): ");
782 txtRange = oObj.getTextRange(chCount, 0);
783 log.println(txtRange);
784 res &= txtRange.equals(text);
786 log.print("getTextRange(0, 0): ");
787 txtRange = oObj.getTextRange(0, 0);
788 log.println(txtRange);
789 locRes = txtRange.equals("");
790 res &= locRes;
792 if (!locRes) {
793 log.println("Empty string was expected");
795 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
796 log.println("Unexpected exception");
797 e.printStackTrace(log);
798 res &= false;
801 try {
802 log.print("getTextRange(-1, chCount - 1): ");
804 txtRange = oObj.getTextRange(-1, chCount - 1);
805 log.println("Exception was expected");
806 res &= false;
807 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
808 log.println("Expected exception");
809 res &= true;
812 try {
813 log.print("getTextRange(0, chCount + 1): ");
815 txtRange = oObj.getTextRange(0, chCount + 1);
816 log.println("Exception was expected");
817 res &= false;
818 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
819 log.println("Expected exception");
820 res &= true;
823 try {
824 log.print("getTextRange(chCount+1, -1): ");
826 txtRange = oObj.getTextRange(chCount + 1, -1);
827 log.println("Exception was expected");
828 res &= false;
829 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
830 log.println("Expected exception");
831 res &= true;
834 tRes.tested("getTextRange()", res);
838 * Calls the method with invalid parameters an with valid parameters,
839 * checks returned values.
840 * Has OK status if exception was thrown for invalid parameters,
841 * if exception wasn't thrown for valid parameters and if returned values
842 * are equal to corresponding substrings of the text received by relation.
843 * The following method tests are to be executed before:
844 * <ul>
845 * <li> <code>getCharacterCount()</code> </li>
846 * </ul>
848 public void _getTextAtIndex() {
849 requiredMethod("getCharacterCount()");
850 TextSegment txt = null;
851 boolean res = true;
853 try {
854 log.print("getTextAtIndex(-1, AccessibleTextType.PARAGRAPH):");
856 txt = oObj.getTextAtIndex(-1,
857 AccessibleTextType.PARAGRAPH);
858 log.println("Exception was expected");
859 res &= false;
860 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
861 log.println("Expected exception");
862 res &= true;
863 } catch (com.sun.star.lang.IllegalArgumentException e) {
864 log.println("UnExpected exception");
865 res &= false;
868 try {
869 log.print("getTextAtIndex(chCount+1," +
870 " AccessibleTextType.PARAGRAPH):");
872 txt = oObj.getTextAtIndex(chCount + 1,
873 AccessibleTextType.PARAGRAPH);
874 log.println("Exception was expected");
875 res &= false;
876 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
877 log.println("Expected exception");
878 res &= true;
879 } catch (com.sun.star.lang.IllegalArgumentException e) {
880 log.println("UnExpected exception");
881 res &= false;
884 try {
885 log.print("getTextAtIndex(chCount," +
886 " AccessibleTextType.WORD):");
888 txt = oObj.getTextAtIndex(chCount, AccessibleTextType.WORD);
889 log.println("'" + txt.SegmentText + "'");
890 res &= compareLength(0,txt.SegmentText);
891 if (!tEnv.getTestCase().getObjectName().equals("SmGraphicAccessible")) {
892 log.print("getTextAtIndex(1," +
893 " AccessibleTextType.PARAGRAPH):");
894 txt = oObj.getTextAtIndex(1, AccessibleTextType.PARAGRAPH);
895 log.println("'" + txt.SegmentText + "'");
896 res &= compareStrings(text,txt.SegmentText);
898 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
899 log.println("Unexpected exception");
900 e.printStackTrace(log);
901 res &= false;
902 } catch (com.sun.star.lang.IllegalArgumentException e) {
903 log.println("Unexpected exception");
904 e.printStackTrace(log);
905 res &= false;
908 tRes.tested("getTextAtIndex()", res);
912 * Calls the method with invalid parameters an with valid parameters,
913 * checks returned values.
914 * Has OK status if exception was thrown for invalid parameters,
915 * if exception wasn't thrown for valid parameters and if returned values
916 * are equal to corresponding substrings of the text received by relation.
917 * The following method tests are to be executed before:
918 * <ul>
919 * <li> <code>getCharacterCount()</code> </li>
920 * </ul>
922 public void _getTextBeforeIndex() {
923 requiredMethod("getCharacterCount()");
924 TextSegment txt = null;
925 boolean res = true;
927 try {
928 log.print("getTextBeforeIndex(-1, AccessibleTextType.PARAGRAPH):");
930 txt = oObj.getTextBeforeIndex(-1,
931 AccessibleTextType.PARAGRAPH);
932 log.println("Exception was expected");
933 res &= false;
934 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
935 log.println("Expected exception");
936 res &= true;
937 } catch (com.sun.star.lang.IllegalArgumentException e) {
938 log.println("UnExpected exception");
939 res &= false;
942 try {
943 log.print("getTextBeforeIndex(chCount+1, " +
944 "AccessibleTextType.PARAGRAPH):");
946 txt = oObj.getTextBeforeIndex(chCount + 1,
947 AccessibleTextType.PARAGRAPH);
948 log.println("Exception was expected");
949 res &= false;
950 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
951 log.println("Expected exception");
952 res &= true;
953 } catch (com.sun.star.lang.IllegalArgumentException e) {
954 log.println("UnExpected exception");
955 res &= true;
958 try {
959 if (!tEnv.getTestCase().getObjectName().equals("SmGraphicAccessible")
960 // next one fails because the control actually contains 2 words
961 && !tEnv.getTestCase().getObjectName().equals("AccessibleStatusBarItem"))
963 log.print("getTextBeforeIndex(chCount," +
964 " AccessibleTextType.WORD):");
966 txt = oObj.getTextBeforeIndex(chCount,
967 AccessibleTextType.WORD);
968 log.println("'" + txt.SegmentText + "'");
969 res &= compareLength(chCount, txt.SegmentText);
972 log.print("getTextBeforeIndex(1," +
973 " AccessibleTextType.PARAGRAPH):");
974 txt = oObj.getTextBeforeIndex(1, AccessibleTextType.PARAGRAPH);
975 log.println("'" + txt.SegmentText + "'");
976 res &= compareLength(0, txt.SegmentText);
978 log.print("getTextBeforeIndex(chCount-1," +
979 " AccessibleTextType.CHARACTER):");
980 txt = oObj.getTextBeforeIndex(chCount - 1,
981 AccessibleTextType.CHARACTER);
982 log.println("'" + txt.SegmentText + "'");
983 res &= compareStrings(text.substring(chCount - 2, chCount - 1),
984 txt.SegmentText);
986 if (chCount > 2) {
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);
996 res &= false;
997 } catch (com.sun.star.lang.IllegalArgumentException e) {
998 log.println("Unexpected exception");
999 e.printStackTrace(log);
1000 res &= false;
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:
1013 * <ul>
1014 * <li> <code>getCharacterCount()</code> </li>
1015 * </ul>
1017 public void _getTextBehindIndex() {
1018 requiredMethod("getCharacterCount()");
1019 TextSegment txt = null;
1020 boolean res = true;
1022 try {
1023 log.print("getTextBehindIndex(-1, AccessibleTextType.PARAGRAPH):");
1025 txt = oObj.getTextBehindIndex(-1,
1026 AccessibleTextType.PARAGRAPH);
1027 log.println("Exception was expected");
1028 res &= false;
1029 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
1030 log.println("Expected exception");
1031 res &= true;
1032 } catch (com.sun.star.lang.IllegalArgumentException e) {
1033 log.println("UnExpected exception");
1034 res &= true;
1037 try {
1038 log.print("getTextBehindIndex(chCount+1, " +
1039 "AccessibleTextType.PARAGRAPH):");
1041 txt = oObj.getTextBehindIndex(chCount + 1,
1042 AccessibleTextType.PARAGRAPH);
1043 log.println("Exception was expected");
1044 res &= false;
1045 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
1046 log.println("Expected exception");
1047 res &= true;
1048 } catch (com.sun.star.lang.IllegalArgumentException e) {
1049 log.println("UnExpected exception");
1050 res &= true;
1053 try {
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));
1075 if (chCount > 2) {
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);
1086 res &= false;
1087 } catch (com.sun.star.lang.IllegalArgumentException e) {
1088 log.println("Unexpected exception");
1089 e.printStackTrace(log);
1090 res &= false;
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() {
1104 boolean res = true;
1105 boolean locRes = true;
1107 if (editOnly != null) {
1108 log.println(editOnly);
1109 throw new StatusException(Status.skipped(true));
1112 try {
1113 log.print("copyText(-1,chCount):");
1114 oObj.copyText(-1, chCount);
1115 log.println("Exception was expected");
1116 res &= false;
1117 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
1118 log.println("Expected exception");
1119 res &= true;
1122 try {
1123 log.print("copyText(0,chCount+1):");
1124 oObj.copyText(0, chCount + 1);
1125 log.println("Exception was expected");
1126 res &= false;
1127 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
1128 log.println("Expected exception");
1129 res &= true;
1132 try {
1133 log.print("copyText(0,chCount):");
1134 locRes = oObj.copyText(0, chCount);
1135 log.println(locRes);
1136 res &= locRes;
1138 String cbText = null;
1140 try {
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);
1150 if (chCount > 2) {
1151 log.print("copyText(1,chCount-1):");
1152 locRes = oObj.copyText(1, chCount - 1);
1153 log.println(locRes);
1154 res &= locRes;
1156 try {
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);
1169 res &= false;
1172 tRes.tested("copyText()", res);
1175 public boolean compareStrings(String expected, String getting) {
1176 boolean res = expected.equals(getting);
1178 if (!res) {
1179 log.println("## The result isn't the expected:");
1180 log.println("\tGetting: " + getting);
1181 log.println("\tExpected: " + expected);
1184 return res;
1187 public boolean compareLength(int expected, String getting) {
1188 boolean res = (expected == getting.length());
1190 if (!res) {
1191 log.println("## The result isn't the expected:");
1192 log.println("\tGetting: " + getting.length());
1193 log.println("\tExpected: " + expected);
1196 return res;