Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / qadevOOo / tests / java / ifc / accessibility / _XAccessibleText.java
blobb4dd7d67455a21d237912f97e6ccde98246b790b
1 /*
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;
21 import lib.Status;
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;
34 /**
35 * Testing <code>com.sun.star.accessibility.XAccessibleText</code>
36 * interface methods :
37 * <ul>
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>
55 * </ul> <p>
56 * This test needs the following object relations :
57 * <ul>
58 * <li> <code>'XAccessibleText.Text'</code> (of type <code>String</code>)
59 * <b> optional </b> :
60 * the string presentation of component's text. If the relation
61 * is not specified, then text from method <code>getText()</code>
62 * is used.
63 * </li>
64 * </ul> <p>
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;
71 String text = null;
72 String editOnly = null;
73 Object LimitedBounds = null;
74 Rectangle chBounds = null;
75 int chCount = 0;
78 /**
79 * Retrieves a string representation of the component's text.
80 * The length of retrieved string must be greater than zero.
82 @Override
83 protected void before() {
84 Object xat = tEnv.getObjRelation("XAccessibleText");
86 XAccessibleComponent component = null;
88 if (xat != null) {
89 oObj = UnoRuntime.queryInterface(
90 XAccessibleText.class, xat);
91 component = UnoRuntime.queryInterface(
92 XAccessibleComponent.class, xat);
95 text = (String) tEnv.getObjRelation("XAccessibleText.Text");
97 if (text == null) {
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:
125 * <ul>
126 * <li> <code>setCaretPosition()</code> </li>
127 * </ul>
129 public void _getCaretPosition() {
130 requiredMethod("getCharacterCount()");
132 if (editOnly != null) {
133 log.println(editOnly);
134 throw new StatusException(Status.skipped(true));
137 boolean res = true;
138 boolean sc = true;
140 try {
141 oObj.setCaretPosition(chCount - 1);
142 } catch (com.sun.star.lang.IndexOutOfBoundsException ie) {
145 int carPos = oObj.getCaretPosition();
146 log.println("getCaretPosition: " + carPos);
148 if (sc) {
149 res = carPos == (chCount - 1);
150 } else {
151 log.println(
152 "Object is read only and Caret position couldn't be set");
153 res = carPos == -1;
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:
165 * <ul>
166 * <li> <code>getCharacterCount()</code> </li>
167 * </ul>
169 public void _setCaretPosition() {
170 requiredMethod("getCharacterCount()");
172 boolean res = true;
174 try {
175 log.print("setCaretPosition(-1):");
176 oObj.setCaretPosition(-1);
177 res &= false;
178 log.println("exception was expected ... FAILED");
179 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
180 log.println("expected exception");
181 res &= true;
184 try {
185 log.print("setCaretPosition(chCount+1):");
186 oObj.setCaretPosition(chCount + 1);
187 res &= false;
188 log.println("exception was expected ... FAILED");
189 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
190 log.println("expected exception");
191 res &= true;
194 try {
195 log.println("setCaretPosition(chCount - 1)");
196 oObj.setCaretPosition(chCount - 1);
197 res &= true;
198 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
199 log.println("unexpected exception ... FAILED");
200 e.printStackTrace(log);
201 res &= false;
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:
214 * <ul>
215 * <li> <code>getCharacterCount()</code> </li>
216 * </ul>
218 public void _getCharacter() {
219 requiredMethod("getCharacterCount()");
221 boolean res = true;
223 try {
224 log.println("getCharacter(-1)");
225 oObj.getCharacter(-1);
226 log.println("Exception was expected");
227 res = false;
228 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
229 log.println("Expected exception");
230 res = true;
233 try {
234 log.println("getCharacter(chCount)");
235 oObj.getCharacter(chCount);
236 log.println("Exception was expected");
237 res &= false;
238 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
239 log.println("Expected exception");
240 res &= true;
243 try {
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);
251 res &= isEqCh;
253 if (!isEqCh) {
254 log.println("At the position " + i +
255 "was expected character: " + text.charAt(i));
256 log.println("but was returned: " + ch);
258 break;
261 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
262 log.println("Unexpected exception");
263 e.printStackTrace(log);
264 res &= false;
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:
277 * <ul>
278 * <li> <code>getCharacterCount()</code> </li>
279 * </ul>
281 public void _getCharacterAttributes() {
282 requiredMethod("getCharacterCount()");
284 boolean res = true;
285 String[] attr = new String[] { "" };
287 try {
288 log.println("getCharacterAttributes(-1)");
289 oObj.getCharacterAttributes(-1, attr);
290 log.println("Exception was expected");
291 res &= false;
292 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
293 log.println("Expected exception");
294 res &= true;
295 } catch(com.sun.star.beans.UnknownPropertyException e) {
296 log.println("unexpected exception => FAILED");
297 e.printStackTrace(log);
298 res &= false;
301 try {
302 log.println("getCharacterAttributes(chCount = " + chCount + ")");
303 oObj.getCharacterAttributes(chCount, attr);
304 log.println("Exception was expected");
305 res &= false;
306 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
307 log.println("Expected exception");
308 res &= true;
309 } catch(com.sun.star.beans.UnknownPropertyException e) {
310 log.println("unexpected exception => FAILED");
311 e.printStackTrace(log);
312 res &= false;
315 try {
316 log.println(
317 "getCharacterAttributes(chCount-1 = " + (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;
326 } catch(com.sun.star.beans.UnknownPropertyException e) {
327 log.println("unexpected exception => FAILED");
328 e.printStackTrace(log);
329 res &= false;
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:
342 * <ul>
343 * <li> <code>getCharacterCount()</code> </li>
344 * </ul>
346 public void _getCharacterBounds() {
347 requiredMethod("getCharacterCount()");
349 boolean res = true;
351 int lastIndex = chCount;
353 if (LimitedBounds != null) {
354 if (LimitedBounds instanceof Integer) {
355 lastIndex = ((Integer) LimitedBounds).intValue();
356 } else {
357 lastIndex = chCount - 1;
360 log.println(LimitedBounds);
363 try {
364 log.println("getCharacterBounds(-1)");
365 oObj.getCharacterBounds(-1);
366 log.println("Exception was expected");
367 res &= false;
368 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
369 log.println("Expected exception");
370 res &= true;
373 try {
374 log.println("getCharacterBounds(" + (lastIndex + 1) + ")");
375 oObj.getCharacterBounds(lastIndex + 1);
376 log.println("Exception was expected");
377 res &= false;
378 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
379 log.println("Expected exception");
380 res &= true;
383 try {
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);
396 if (!localres) {
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 + ", " +
401 chBounds.Height);
402 log.println("Component rect: " + bounds.X + ", " +
403 bounds.Y + ", " + bounds.Width + ", " +
404 bounds.Height);
407 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
408 log.println("Unexpected exception");
409 e.printStackTrace(log);
410 res &= false;
413 tRes.tested("getCharacterBounds()", res);
417 * Calls the method and stores a returned value to the variable
418 * <code>chCount</code>.
419 * Has OK status if a returned value is equal to the text length.
421 public void _getCharacterCount() {
422 chCount = oObj.getCharacterCount();
423 log.println("Character count:" + chCount);
425 boolean res = chCount == text.length();
426 tRes.tested("getCharacterCount()", res);
430 * Calls the method for an invalid point and for the point of rectangle
431 * returned by the method <code>getCharacterBounds()</code>.
432 * Has OK status if returned value is equal to <code>-1</code> for an
433 * invalid point and if returned value is equal to <code>chCount-1</code>
434 * for a valid point.
435 * The following method tests are to be executed before:
436 * <ul>
437 * <li> <code>getCharacterBounds()</code> </li>
438 * </ul>
440 public void _getIndexAtPoint() {
441 //requiredMethod("getCharacterBounds()");
442 boolean res = true;
443 log.print("getIndexAtPoint(-1, -1):");
445 Point pt = new Point(-1, -1);
446 int index = oObj.getIndexAtPoint(pt);
447 log.println(index);
448 res &= (index == -1);
450 int lastIndex = chCount;
452 if (LimitedBounds != null) {
453 if (LimitedBounds instanceof Integer) {
454 lastIndex = ((Integer) LimitedBounds).intValue();
455 } else {
456 lastIndex = chCount - 1;
459 log.println(LimitedBounds);
462 for (int i = 0; i < lastIndex; i++) {
463 Rectangle aRect = null;
464 String text = "empty";
466 try {
467 aRect = oObj.getCharacterBounds(i);
468 text = oObj.getTextAtIndex(i, (short) 1).SegmentText;
469 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
470 } catch (com.sun.star.lang.IllegalArgumentException e) {
473 if (aRect == null) {
474 res = false;
475 log.print("aRect unexpected null");
476 break;
479 int x = aRect.X + (aRect.Width / 2);
480 int y = aRect.Y + (aRect.Height / 2);
482 Point aPoint = new Point(x, y);
483 int nIndex = oObj.getIndexAtPoint(aPoint);
485 x = aRect.X;
486 y = aRect.Y + (aRect.Height / 2);
487 aPoint = new Point(x, y);
488 int left = oObj.getIndexAtPoint(aPoint);
492 int[] previous = (int[]) tEnv.getObjRelation("PreviousUsed");
494 if (previous != null) {
495 for (int k = 0; k < previous.length; k++) {
496 if (i == previous[k]) {
497 nIndex++;
502 if (nIndex != i) {
503 // for some letters the center of the rectangle isn't recognised
504 // in this case we are happy if the left border of the rectangle
505 // returns the correct value.
506 if (left !=i) {
507 log.println("## Method didn't work for Point (" + x + "," + y +
508 ")");
509 log.println("Expected Index " + i);
510 log.println("Gained Index: " + nIndex);
511 log.println("Left Border: "+left);
512 log.println("CharacterAtIndex: " + text);
513 res &= false;
518 tRes.tested("getIndexAtPoint()", res);
522 * Checks a returned values after different calls of the method
523 * <code>setSelection()</code>.
524 * The following method tests are to be executed before:
525 * <ul>
526 * <li> <code>setSelection()</code> </li>
527 * </ul>
529 public void _getSelectedText() {
530 if (editOnly != null) {
531 log.println(editOnly);
532 throw new StatusException(Status.skipped(true));
535 requiredMethod("setSelection()");
537 boolean res = true;
539 try {
540 log.println("setSelection(0, 0)");
541 oObj.setSelection(0, 0);
542 log.print("getSelectedText():");
544 String txt = oObj.getSelectedText();
545 log.println("'" + txt + "'");
546 res &= (txt.length() == 0);
548 log.println("setSelection(0, chCount)");
549 oObj.setSelection(0, chCount);
550 log.print("getSelectedText():");
551 txt = oObj.getSelectedText();
552 log.println("'" + txt + "'");
553 res &= txt.equals(text);
555 if (chCount > 2) {
556 log.println("setSelection(1, chCount-1)");
557 oObj.setSelection(1, chCount - 1);
558 log.print("getSelectedText():");
559 txt = oObj.getSelectedText();
560 log.println("'" + txt + "'");
561 res &= txt.equals(text.substring(1, chCount - 1));
563 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
564 log.println("Unexpected exception");
565 e.printStackTrace(log);
566 res &= false;
569 tRes.tested("getSelectedText()", res);
573 * Checks a returned values after different calls of the method
574 * <code>setSelection()</code>.
575 * The following method tests are to be executed before:
576 * <ul>
577 * <li> <code>setSelection()</code> </li>
578 * </ul>
580 public void _getSelectionStart() {
581 if (editOnly != null) {
582 log.println(editOnly);
583 throw new StatusException(Status.skipped(true));
586 requiredMethod("setSelection()");
588 boolean res = true;
590 try {
591 log.println("setSelection(0, chCount)");
592 oObj.setSelection(0, chCount);
594 int start = oObj.getSelectionStart();
595 log.println("getSelectionStart():" + start);
596 res &= (start == 0);
598 if (chCount > 2) {
599 log.println("setSelection(1, chCount-1)");
600 oObj.setSelection(1, chCount - 1);
601 start = oObj.getSelectionStart();
602 log.println("getSelectionStart():" + start);
603 res &= (start == 1);
605 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
606 log.println("Unexpected exception");
607 e.printStackTrace(log);
608 res &= false;
611 tRes.tested("getSelectionStart()", res);
615 * Checks a returned values after different calls of the method
616 * <code>setSelection()</code>.
617 * The following method tests are to be executed before:
618 * <ul>
619 * <li> <code>setSelection()</code> </li>
620 * </ul>
622 public void _getSelectionEnd() {
623 if (editOnly != null) {
624 log.println(editOnly);
625 throw new StatusException(Status.skipped(true));
628 requiredMethod("setSelection()");
630 boolean res = true;
632 try {
633 log.println("setSelection(0, chCount)");
634 oObj.setSelection(0, chCount);
636 int end = oObj.getSelectionEnd();
637 log.println("getSelectionEnd():" + end);
638 res &= (end == chCount);
640 if (chCount > 2) {
641 log.println("setSelection(1, chCount-1)");
642 oObj.setSelection(1, chCount - 1);
643 end = oObj.getSelectionEnd();
644 log.println("getSelectionEnd():" + end);
645 res &= (end == (chCount - 1));
647 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
648 log.println("Unexpected exception");
649 e.printStackTrace(log);
650 res &= false;
653 tRes.tested("getSelectionEnd()", res);
657 * Calls the method with invalid parameters and with valid parameters.
658 * Has OK status if exception was thrown for invalid parameters,
659 * if exception wasn't thrown for valid parameters.
660 * The following method tests are to be executed before:
661 * <ul>
662 * <li> <code>getCharacterCount()</code> </li>
663 * </ul>
665 public void _setSelection() {
666 requiredMethod("getCharacterCount()");
668 boolean res = true;
669 boolean locRes = true;
671 if (editOnly != null) {
672 log.println(editOnly);
673 throw new StatusException(Status.skipped(true));
676 try {
677 log.print("setSelection(-1, chCount-1):");
678 locRes = oObj.setSelection(-1, chCount - 1);
679 log.println(locRes + " exception was expected");
680 res &= !locRes;
681 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
682 log.println("Expected exception");
683 res &= true;
686 try {
687 log.print("setSelection(0, chCount+1):");
688 locRes = oObj.setSelection(0, chCount + 1);
689 log.println(locRes + " exception was expected");
690 res &= !locRes;
691 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
692 log.println("Expected exception");
693 res &= true;
696 try {
697 if (chCount > 2) {
698 log.print("setSelection(1, chCount-1):");
699 locRes = oObj.setSelection(1, chCount - 1);
700 log.println(locRes);
701 res &= locRes;
703 log.print("setSelection(chCount-1, 1):");
704 locRes = oObj.setSelection(chCount - 1, 1);
705 log.println(locRes);
706 res &= locRes;
709 log.print("setSelection(0, chCount-1):");
710 locRes = oObj.setSelection(0, chCount - 1);
711 log.println(locRes);
712 res &= locRes;
714 log.print("setSelection(chCount-1, 0):");
715 locRes = oObj.setSelection(chCount - 1, 0);
716 log.println(locRes);
717 res &= locRes;
719 log.print("setSelection(0, 0):");
720 locRes = oObj.setSelection(0, 0);
721 log.println(locRes);
722 res &= locRes;
723 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
724 log.println("Unexpected exception");
725 e.printStackTrace(log);
726 res &= false;
729 tRes.tested("setSelection()", res);
733 * Calls the method and checks returned value.
734 * Has OK status if returned string is equal to string
735 * received from relation.
737 public void _getText() {
738 String txt = oObj.getText();
739 log.println("getText: " + txt);
741 boolean res = txt.equals(text);
742 tRes.tested("getText()", res);
746 * Calls the method with invalid parameters and with valid parameters,
747 * checks returned values.
748 * Has OK status if exception was thrown for invalid parameters,
749 * if exception wasn't thrown for valid parameters and if returned values
750 * are equal to corresponding substrings of the text received by relation.
751 * The following method tests are to be executed before:
752 * <ul>
753 * <li> <code>getCharacterCount()</code> </li>
754 * </ul>
756 public void _getTextRange() {
757 requiredMethod("getCharacterCount()");
759 boolean res = true;
760 boolean locRes = true;
762 String txtRange = "";
764 try {
765 if (chCount > 3) {
766 log.print("getTextRange(1, chCount - 2): ");
768 txtRange = oObj.getTextRange(1, chCount - 2);
769 log.println(txtRange);
770 locRes = txtRange.equals(text.substring(1, chCount - 2));
771 res &= locRes;
773 if (!locRes) {
774 log.println("Was expected: " +
775 text.substring(1, chCount - 2));
779 log.print("getTextRange(0, chCount-1): ");
781 txtRange = oObj.getTextRange(0, chCount - 1);
782 log.println(txtRange);
783 locRes = txtRange.equals(text.substring(0, chCount - 1));
784 res &= locRes;
786 if (!locRes) {
787 log.println("Was expected: " +
788 text.substring(0, chCount - 1));
791 log.print("getTextRange(chCount, 0): ");
792 txtRange = oObj.getTextRange(chCount, 0);
793 log.println(txtRange);
794 res &= txtRange.equals(text);
796 log.print("getTextRange(0, 0): ");
797 txtRange = oObj.getTextRange(0, 0);
798 log.println(txtRange);
799 locRes = txtRange.equals("");
800 res &= locRes;
802 if (!locRes) {
803 log.println("Empty string was expected");
805 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
806 log.println("Unexpected exception");
807 e.printStackTrace(log);
808 res &= false;
811 try {
812 log.print("getTextRange(-1, chCount - 1): ");
814 txtRange = oObj.getTextRange(-1, chCount - 1);
815 log.println("Exception was expected");
816 res &= false;
817 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
818 log.println("Expected exception");
819 res &= true;
822 try {
823 log.print("getTextRange(0, chCount + 1): ");
825 txtRange = oObj.getTextRange(0, chCount + 1);
826 log.println("Exception was expected");
827 res &= false;
828 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
829 log.println("Expected exception");
830 res &= true;
833 try {
834 log.print("getTextRange(chCount+1, -1): ");
836 txtRange = oObj.getTextRange(chCount + 1, -1);
837 log.println("Exception was expected");
838 res &= false;
839 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
840 log.println("Expected exception");
841 res &= true;
844 tRes.tested("getTextRange()", res);
848 * Calls the method with invalid parameters and with valid parameters,
849 * checks returned values.
850 * Has OK status if exception was thrown for invalid parameters,
851 * if exception wasn't thrown for valid parameters and if returned values
852 * are equal to corresponding substrings of the text received by relation.
853 * The following method tests are to be executed before:
854 * <ul>
855 * <li> <code>getCharacterCount()</code> </li>
856 * </ul>
858 public void _getTextAtIndex() {
859 requiredMethod("getCharacterCount()");
860 TextSegment txt = null;
861 boolean res = true;
863 try {
864 log.print("getTextAtIndex(-1, AccessibleTextType.PARAGRAPH):");
866 txt = oObj.getTextAtIndex(-1,
867 AccessibleTextType.PARAGRAPH);
868 log.println("Exception was expected");
869 res &= false;
870 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
871 log.println("Expected exception");
872 res &= true;
873 } catch (com.sun.star.lang.IllegalArgumentException e) {
874 log.println("UnExpected exception");
875 res &= false;
878 try {
879 log.print("getTextAtIndex(chCount+1," +
880 " AccessibleTextType.PARAGRAPH):");
882 txt = oObj.getTextAtIndex(chCount + 1,
883 AccessibleTextType.PARAGRAPH);
884 log.println("Exception was expected");
885 res &= false;
886 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
887 log.println("Expected exception");
888 res &= true;
889 } catch (com.sun.star.lang.IllegalArgumentException e) {
890 log.println("UnExpected exception");
891 res &= false;
894 try {
895 log.print("getTextAtIndex(chCount," +
896 " AccessibleTextType.WORD):");
898 txt = oObj.getTextAtIndex(chCount, AccessibleTextType.WORD);
899 log.println("'" + txt.SegmentText + "'");
900 res &= compareLength(0,txt.SegmentText);
901 if (!tEnv.getTestCase().getObjectName().equals("SmGraphicAccessible")) {
902 log.print("getTextAtIndex(1," +
903 " AccessibleTextType.PARAGRAPH):");
904 txt = oObj.getTextAtIndex(1, AccessibleTextType.PARAGRAPH);
905 log.println("'" + txt.SegmentText + "'");
906 res &= compareStrings(text,txt.SegmentText);
908 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
909 log.println("Unexpected exception");
910 e.printStackTrace(log);
911 res &= false;
912 } catch (com.sun.star.lang.IllegalArgumentException e) {
913 log.println("Unexpected exception");
914 e.printStackTrace(log);
915 res &= false;
918 tRes.tested("getTextAtIndex()", res);
922 * Calls the method with invalid parameters and with valid parameters,
923 * checks returned values.
924 * Has OK status if exception was thrown for invalid parameters,
925 * if exception wasn't thrown for valid parameters and if returned values
926 * are equal to corresponding substrings of the text received by relation.
927 * The following method tests are to be executed before:
928 * <ul>
929 * <li> <code>getCharacterCount()</code> </li>
930 * </ul>
932 public void _getTextBeforeIndex() {
933 requiredMethod("getCharacterCount()");
934 TextSegment txt = null;
935 boolean res = true;
937 try {
938 log.print("getTextBeforeIndex(-1, AccessibleTextType.PARAGRAPH):");
940 txt = oObj.getTextBeforeIndex(-1,
941 AccessibleTextType.PARAGRAPH);
942 log.println("Exception was expected");
943 res &= false;
944 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
945 log.println("Expected exception");
946 res &= true;
947 } catch (com.sun.star.lang.IllegalArgumentException e) {
948 log.println("UnExpected exception");
949 res &= false;
952 try {
953 log.print("getTextBeforeIndex(chCount+1, " +
954 "AccessibleTextType.PARAGRAPH):");
956 txt = oObj.getTextBeforeIndex(chCount + 1,
957 AccessibleTextType.PARAGRAPH);
958 log.println("Exception was expected");
959 res &= false;
960 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
961 log.println("Expected exception");
962 res &= true;
963 } catch (com.sun.star.lang.IllegalArgumentException e) {
964 log.println("UnExpected exception");
965 res &= true;
968 try {
969 if (!tEnv.getTestCase().getObjectName().equals("SmGraphicAccessible")
970 // next one fails because the control actually contains 2 words
971 && !tEnv.getTestCase().getObjectName().equals("AccessibleStatusBarItem"))
973 log.print("getTextBeforeIndex(chCount," +
974 " AccessibleTextType.WORD):");
976 txt = oObj.getTextBeforeIndex(chCount,
977 AccessibleTextType.WORD);
978 log.println("'" + txt.SegmentText + "'");
979 res &= compareLength(chCount, txt.SegmentText);
982 log.print("getTextBeforeIndex(1," +
983 " AccessibleTextType.PARAGRAPH):");
984 txt = oObj.getTextBeforeIndex(1, AccessibleTextType.PARAGRAPH);
985 log.println("'" + txt.SegmentText + "'");
986 res &= compareLength(0, txt.SegmentText);
988 log.print("getTextBeforeIndex(chCount-1," +
989 " AccessibleTextType.CHARACTER):");
990 txt = oObj.getTextBeforeIndex(chCount - 1,
991 AccessibleTextType.CHARACTER);
992 log.println("'" + txt.SegmentText + "'");
993 res &= compareStrings(text.substring(chCount - 2, chCount - 1),
994 txt.SegmentText);
996 if (chCount > 2) {
997 log.print("getTextBeforeIndex(2," +
998 " AccessibleTextType.CHARACTER):");
999 txt = oObj.getTextBeforeIndex(2, AccessibleTextType.CHARACTER);
1000 log.println("'" + txt.SegmentText + "'");
1001 res &= compareStrings(text.substring(1, 2), txt.SegmentText);
1003 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
1004 log.println("Unexpected exception");
1005 e.printStackTrace(log);
1006 res &= false;
1007 } catch (com.sun.star.lang.IllegalArgumentException e) {
1008 log.println("Unexpected exception");
1009 e.printStackTrace(log);
1010 res &= false;
1013 tRes.tested("getTextBeforeIndex()", res);
1017 * Calls the method with invalid parameters and with valid parameters,
1018 * checks returned values.
1019 * Has OK status if exception was thrown for invalid parameters,
1020 * if exception wasn't thrown for valid parameters and if returned values
1021 * are equal to corresponding substrings of the text received by relation.
1022 * The following method tests are to be executed before:
1023 * <ul>
1024 * <li> <code>getCharacterCount()</code> </li>
1025 * </ul>
1027 public void _getTextBehindIndex() {
1028 requiredMethod("getCharacterCount()");
1029 TextSegment txt = null;
1030 boolean res = true;
1032 try {
1033 log.print("getTextBehindIndex(-1, AccessibleTextType.PARAGRAPH):");
1035 txt = oObj.getTextBehindIndex(-1,
1036 AccessibleTextType.PARAGRAPH);
1037 log.println("Exception was expected");
1038 res &= false;
1039 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
1040 log.println("Expected exception");
1041 res &= true;
1042 } catch (com.sun.star.lang.IllegalArgumentException e) {
1043 log.println("UnExpected exception");
1044 res &= true;
1047 try {
1048 log.print("getTextBehindIndex(chCount+1, " +
1049 "AccessibleTextType.PARAGRAPH):");
1051 txt = oObj.getTextBehindIndex(chCount + 1,
1052 AccessibleTextType.PARAGRAPH);
1053 log.println("Exception was expected");
1054 res &= false;
1055 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
1056 log.println("Expected exception");
1057 res &= true;
1058 } catch (com.sun.star.lang.IllegalArgumentException e) {
1059 log.println("UnExpected exception");
1060 res &= true;
1063 try {
1064 log.print("getTextBehindIndex(chCount," +
1065 " AccessibleTextType.PARAGRAPH):");
1067 txt = oObj.getTextBehindIndex(chCount,
1068 AccessibleTextType.PARAGRAPH);
1069 log.println("'" + txt.SegmentText + "'");
1070 res &= (txt.SegmentText.length() == 0);
1072 log.print("getTextBehindIndex(chCount-1," +
1073 " AccessibleTextType.PARAGRAPH):");
1074 txt = oObj.getTextBehindIndex(chCount - 1,
1075 AccessibleTextType.PARAGRAPH);
1076 log.println("'" + txt.SegmentText + "'");
1077 res &= (txt.SegmentText.length() == 0);
1079 log.print("getTextBehindIndex(1," +
1080 " AccessibleTextType.CHARACTER):");
1081 txt = oObj.getTextBehindIndex(1, AccessibleTextType.CHARACTER);
1082 log.println("'" + txt.SegmentText + "'");
1083 res &= txt.SegmentText.equals(text.substring(2, 3));
1085 if (chCount > 2) {
1086 log.print("getTextBehindIndex(chCount-2," +
1087 " AccessibleTextType.CHARACTER):");
1088 txt = oObj.getTextBehindIndex(chCount - 2,
1089 AccessibleTextType.CHARACTER);
1090 log.println("'" + txt.SegmentText + "'");
1091 res &= txt.SegmentText.equals(text.substring(chCount - 1, chCount));
1093 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
1094 log.println("Unexpected exception");
1095 e.printStackTrace(log);
1096 res &= false;
1097 } catch (com.sun.star.lang.IllegalArgumentException e) {
1098 log.println("Unexpected exception");
1099 e.printStackTrace(log);
1100 res &= false;
1103 tRes.tested("getTextBehindIndex()", res);
1107 * Calls the method with invalid parameters and with valid parameter,
1108 * checks returned values.
1109 * Has OK status if exception was thrown for invalid parameters,
1110 * if exception wasn't thrown for valid parameter and if returned value for
1111 * valid parameter is equal to <code>true</code>.
1113 public void _copyText() {
1114 boolean res = true;
1115 boolean locRes = true;
1117 if (editOnly != null) {
1118 log.println(editOnly);
1119 throw new StatusException(Status.skipped(true));
1122 try {
1123 log.print("copyText(-1,chCount):");
1124 oObj.copyText(-1, chCount);
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+1):");
1134 oObj.copyText(0, chCount + 1);
1135 log.println("Exception was expected");
1136 res &= false;
1137 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
1138 log.println("Expected exception");
1139 res &= true;
1142 try {
1143 log.print("copyText(0,chCount):");
1144 locRes = oObj.copyText(0, chCount);
1145 log.println(locRes);
1146 res &= locRes;
1148 String cbText = null;
1150 try {
1151 cbText = util.SysUtils.getSysClipboardText(tParam.getMSF());
1152 } catch (com.sun.star.uno.Exception e) {
1153 log.println("Couldn't access system clipboard :");
1154 e.printStackTrace(log);
1157 log.println("Clipboard: '" + cbText + "'");
1158 res &= text.equals(cbText);
1160 if (chCount > 2) {
1161 log.print("copyText(1,chCount-1):");
1162 locRes = oObj.copyText(1, chCount - 1);
1163 log.println(locRes);
1164 res &= locRes;
1166 try {
1167 cbText = util.SysUtils.getSysClipboardText(tParam.getMSF());
1168 } catch (com.sun.star.uno.Exception e) {
1169 log.println("Couldn't access system clipboard :");
1170 e.printStackTrace(log);
1173 log.println("Clipboard: '" + cbText + "'");
1174 res &= text.substring(1, chCount - 1).equals(cbText);
1176 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
1177 log.println("Unexpected exception");
1178 e.printStackTrace(log);
1179 res &= false;
1182 tRes.tested("copyText()", res);
1185 public boolean compareStrings(String expected, String getting) {
1186 boolean res = expected.equals(getting);
1188 if (!res) {
1189 log.println("## The result isn't the expected:");
1190 log.println("\tGetting: " + getting);
1191 log.println("\tExpected: " + expected);
1194 return res;
1197 public boolean compareLength(int expected, String getting) {
1198 boolean res = (expected == getting.length());
1200 if (!res) {
1201 log.println("## The result isn't the expected:");
1202 log.println("\tGetting: " + getting.length());
1203 log.println("\tExpected: " + expected);
1206 return res;