Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / ifc / accessibility / _XAccessibleText.java
blob9f4f5c090450c0e17493caee4807733e8df5c38d
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);
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")) {
408 res &= localres;
412 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
413 log.println("Unexpected exception");
414 e.printStackTrace(log);
415 res &= false;
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>
439 * for a valid point.
440 * The following method tests are to be executed before:
441 * <ul>
442 * <li> <code>getCharacterBounds()</code> </li>
443 * </ul>
445 public void _getIndexAtPoint() {
446 //requiredMethod("getCharacterBounds()");
447 boolean res = true;
448 log.print("getIndexAtPoint(-1, -1):");
450 Point pt = new Point(-1, -1);
451 int index = oObj.getIndexAtPoint(pt);
452 log.println(index);
453 res &= (index == -1);
455 int lastIndex = chCount;
457 if (LimitedBounds != null) {
458 if (LimitedBounds instanceof Integer) {
459 lastIndex = ((Integer) LimitedBounds).intValue();
460 } else {
461 lastIndex = chCount - 1;
464 log.println(LimitedBounds);
467 for (int i = 0; i < lastIndex; i++) {
468 Rectangle aRect = null;
469 String text = "empty";
471 try {
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);
483 x = aRect.X;
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]) {
495 nIndex++;
500 if (nIndex != i) {
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.
504 if (left !=i) {
505 log.println("## Method didn't work for Point (" + x + "," + y +
506 ")");
507 log.println("Expected Index " + i);
508 log.println("Gained Index: " + nIndex);
509 log.println("Left Border: "+left);
510 log.println("CharacterAtIndex: " + text);
511 res &= false;
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:
523 * <ul>
524 * <li> <code>setSelection()</code> </li>
525 * </ul>
527 public void _getSelectedText() {
528 if (editOnly != null) {
529 log.println(editOnly);
530 throw new StatusException(Status.skipped(true));
533 requiredMethod("setSelection()");
535 boolean res = true;
537 try {
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);
553 if (chCount > 2) {
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);
564 res &= false;
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:
574 * <ul>
575 * <li> <code>setSelection()</code> </li>
576 * </ul>
578 public void _getSelectionStart() {
579 if (editOnly != null) {
580 log.println(editOnly);
581 throw new StatusException(Status.skipped(true));
584 requiredMethod("setSelection()");
586 boolean res = true;
588 try {
589 log.println("setSelection(0, chCount)");
590 oObj.setSelection(0, chCount);
592 int start = oObj.getSelectionStart();
593 log.println("getSelectionStart():" + start);
594 res &= (start == 0);
596 if (chCount > 2) {
597 log.println("setSelection(1, chCount-1)");
598 oObj.setSelection(1, chCount - 1);
599 start = oObj.getSelectionStart();
600 log.println("getSelectionStart():" + start);
601 res &= (start == 1);
603 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
604 log.println("Unexpected exception");
605 e.printStackTrace(log);
606 res &= false;
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:
616 * <ul>
617 * <li> <code>setSelection()</code> </li>
618 * </ul>
620 public void _getSelectionEnd() {
621 if (editOnly != null) {
622 log.println(editOnly);
623 throw new StatusException(Status.skipped(true));
626 requiredMethod("setSelection()");
628 boolean res = true;
630 try {
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);
638 if (chCount > 2) {
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);
648 res &= false;
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:
659 * <ul>
660 * <li> <code>getCharacterCount()</code> </li>
661 * </ul>
663 public void _setSelection() {
664 requiredMethod("getCharacterCount()");
666 boolean res = true;
667 boolean locRes = true;
669 if (editOnly != null) {
670 log.println(editOnly);
671 throw new StatusException(Status.skipped(true));
674 try {
675 log.print("setSelection(-1, chCount-1):");
676 locRes = oObj.setSelection(-1, chCount - 1);
677 log.println(locRes + " excepion was expected");
678 res &= !locRes;
679 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
680 log.println("Expected exception");
681 res &= true;
684 try {
685 log.print("setSelection(0, chCount+1):");
686 locRes = oObj.setSelection(0, chCount + 1);
687 log.println(locRes + " excepion was expected");
688 res &= !locRes;
689 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
690 log.println("Expected exception");
691 res &= true;
694 try {
695 if (chCount > 2) {
696 log.print("setSelection(1, chCount-1):");
697 locRes = oObj.setSelection(1, chCount - 1);
698 log.println(locRes);
699 res &= locRes;
701 log.print("setSelection(chCount-1, 1):");
702 locRes = oObj.setSelection(chCount - 1, 1);
703 log.println(locRes);
704 res &= locRes;
707 log.print("setSelection(0, chCount-1):");
708 locRes = oObj.setSelection(0, chCount - 1);
709 log.println(locRes);
710 res &= locRes;
712 log.print("setSelection(chCount-1, 0):");
713 locRes = oObj.setSelection(chCount - 1, 0);
714 log.println(locRes);
715 res &= locRes;
717 log.print("setSelection(0, 0):");
718 locRes = oObj.setSelection(0, 0);
719 log.println(locRes);
720 res &= locRes;
721 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
722 log.println("Unexpected exception");
723 e.printStackTrace(log);
724 res &= false;
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:
750 * <ul>
751 * <li> <code>getCharacterCount()</code> </li>
752 * </ul>
754 public void _getTextRange() {
755 requiredMethod("getCharacterCount()");
757 boolean res = true;
758 boolean locRes = true;
760 String txtRange = "";
762 try {
763 if (chCount > 3) {
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));
769 res &= locRes;
771 if (!locRes) {
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));
782 res &= locRes;
784 if (!locRes) {
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("");
798 res &= locRes;
800 if (!locRes) {
801 log.println("Empty string was expected");
803 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
804 log.println("Unexpected exception");
805 e.printStackTrace(log);
806 res &= false;
809 try {
810 log.print("getTextRange(-1, chCount - 1): ");
812 txtRange = oObj.getTextRange(-1, chCount - 1);
813 log.println("Exception was expected");
814 res &= false;
815 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
816 log.println("Expected exception");
817 res &= true;
820 try {
821 log.print("getTextRange(0, chCount + 1): ");
823 txtRange = oObj.getTextRange(0, chCount + 1);
824 log.println("Exception was expected");
825 res &= false;
826 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
827 log.println("Expected exception");
828 res &= true;
831 try {
832 log.print("getTextRange(chCount+1, -1): ");
834 txtRange = oObj.getTextRange(chCount + 1, -1);
835 log.println("Exception was expected");
836 res &= false;
837 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
838 log.println("Expected exception");
839 res &= true;
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:
852 * <ul>
853 * <li> <code>getCharacterCount()</code> </li>
854 * </ul>
856 public void _getTextAtIndex() {
857 requiredMethod("getCharacterCount()");
858 TextSegment txt = null;
859 boolean res = true;
861 try {
862 log.print("getTextAtIndex(-1, AccessibleTextType.PARAGRAPH):");
864 txt = oObj.getTextAtIndex(-1,
865 AccessibleTextType.PARAGRAPH);
866 log.println("Exception was expected");
867 res &= false;
868 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
869 log.println("Expected exception");
870 res &= true;
871 } catch (com.sun.star.lang.IllegalArgumentException e) {
872 log.println("UnExpected exception");
873 res &= false;
876 try {
877 log.print("getTextAtIndex(chCount+1," +
878 " AccessibleTextType.PARAGRAPH):");
880 txt = oObj.getTextAtIndex(chCount + 1,
881 AccessibleTextType.PARAGRAPH);
882 log.println("Exception was expected");
883 res &= false;
884 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
885 log.println("Expected exception");
886 res &= true;
887 } catch (com.sun.star.lang.IllegalArgumentException e) {
888 log.println("UnExpected exception");
889 res &= false;
892 try {
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);
909 res &= false;
910 } catch (com.sun.star.lang.IllegalArgumentException e) {
911 log.println("Unexpected exception");
912 e.printStackTrace(log);
913 res &= false;
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:
926 * <ul>
927 * <li> <code>getCharacterCount()</code> </li>
928 * </ul>
930 public void _getTextBeforeIndex() {
931 requiredMethod("getCharacterCount()");
932 TextSegment txt = null;
933 boolean res = true;
935 try {
936 log.print("getTextBeforeIndex(-1, AccessibleTextType.PARAGRAPH):");
938 txt = oObj.getTextBeforeIndex(-1,
939 AccessibleTextType.PARAGRAPH);
940 log.println("Exception was expected");
941 res &= false;
942 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
943 log.println("Expected exception");
944 res &= true;
945 } catch (com.sun.star.lang.IllegalArgumentException e) {
946 log.println("UnExpected exception");
947 res &= false;
950 try {
951 log.print("getTextBeforeIndex(chCount+1, " +
952 "AccessibleTextType.PARAGRAPH):");
954 txt = oObj.getTextBeforeIndex(chCount + 1,
955 AccessibleTextType.PARAGRAPH);
956 log.println("Exception was expected");
957 res &= false;
958 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
959 log.println("Expected exception");
960 res &= true;
961 } catch (com.sun.star.lang.IllegalArgumentException e) {
962 log.println("UnExpected exception");
963 res &= true;
966 try {
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),
992 txt.SegmentText);
994 if (chCount > 2) {
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);
1004 res &= false;
1005 } catch (com.sun.star.lang.IllegalArgumentException e) {
1006 log.println("Unexpected exception");
1007 e.printStackTrace(log);
1008 res &= false;
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:
1021 * <ul>
1022 * <li> <code>getCharacterCount()</code> </li>
1023 * </ul>
1025 public void _getTextBehindIndex() {
1026 requiredMethod("getCharacterCount()");
1027 TextSegment txt = null;
1028 boolean res = true;
1030 try {
1031 log.print("getTextBehindIndex(-1, AccessibleTextType.PARAGRAPH):");
1033 txt = oObj.getTextBehindIndex(-1,
1034 AccessibleTextType.PARAGRAPH);
1035 log.println("Exception was expected");
1036 res &= false;
1037 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
1038 log.println("Expected exception");
1039 res &= true;
1040 } catch (com.sun.star.lang.IllegalArgumentException e) {
1041 log.println("UnExpected exception");
1042 res &= true;
1045 try {
1046 log.print("getTextBehindIndex(chCount+1, " +
1047 "AccessibleTextType.PARAGRAPH):");
1049 txt = oObj.getTextBehindIndex(chCount + 1,
1050 AccessibleTextType.PARAGRAPH);
1051 log.println("Exception was expected");
1052 res &= false;
1053 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
1054 log.println("Expected exception");
1055 res &= true;
1056 } catch (com.sun.star.lang.IllegalArgumentException e) {
1057 log.println("UnExpected exception");
1058 res &= true;
1061 try {
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));
1083 if (chCount > 2) {
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);
1094 res &= false;
1095 } catch (com.sun.star.lang.IllegalArgumentException e) {
1096 log.println("Unexpected exception");
1097 e.printStackTrace(log);
1098 res &= false;
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() {
1112 boolean res = true;
1113 boolean locRes = true;
1115 if (editOnly != null) {
1116 log.println(editOnly);
1117 throw new StatusException(Status.skipped(true));
1120 try {
1121 log.print("copyText(-1,chCount):");
1122 oObj.copyText(-1, chCount);
1123 log.println("Exception was expected");
1124 res &= false;
1125 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
1126 log.println("Expected exception");
1127 res &= true;
1130 try {
1131 log.print("copyText(0,chCount+1):");
1132 oObj.copyText(0, chCount + 1);
1133 log.println("Exception was expected");
1134 res &= false;
1135 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
1136 log.println("Expected exception");
1137 res &= true;
1140 try {
1141 log.print("copyText(0,chCount):");
1142 locRes = oObj.copyText(0, chCount);
1143 log.println(locRes);
1144 res &= locRes;
1146 String cbText = null;
1148 try {
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);
1158 if (chCount > 2) {
1159 log.print("copyText(1,chCount-1):");
1160 locRes = oObj.copyText(1, chCount - 1);
1161 log.println(locRes);
1162 res &= locRes;
1164 try {
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);
1177 res &= false;
1180 tRes.tested("copyText()", res);
1183 public boolean compareStrings(String expected, String getting) {
1184 boolean res = expected.equals(getting);
1186 if (!res) {
1187 log.println("## The result isn't the expected:");
1188 log.println("\tGetting: " + getting);
1189 log.println("\tExpected: " + expected);
1192 return res;
1195 public boolean compareLength(int expected, String getting) {
1196 boolean res = (expected == getting.length());
1198 if (!res) {
1199 log.println("## The result isn't the expected:");
1200 log.println("\tGetting: " + getting.length());
1201 log.println("\tExpected: " + expected);
1204 return res;