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