Update ooo320-m1
[ooovba.git] / qadevOOo / tests / java / ifc / accessibility / _XAccessibleText.java
blob6e5fec406ee0848b460cc869f6f8722aec7bdecf
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XAccessibleText.java,v $
10 * $Revision: 1.18 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 package ifc.accessibility;
32 import lib.MultiMethodTest;
33 import lib.Status;
34 import lib.StatusException;
36 import com.sun.star.accessibility.AccessibleTextType;
37 import com.sun.star.accessibility.TextSegment;
38 import com.sun.star.accessibility.XAccessibleComponent;
39 import com.sun.star.accessibility.XAccessibleText;
40 import com.sun.star.awt.Point;
41 import com.sun.star.awt.Rectangle;
42 import com.sun.star.beans.PropertyValue;
43 import com.sun.star.lang.XMultiServiceFactory;
44 import com.sun.star.uno.UnoRuntime;
47 /**
48 * Testing <code>com.sun.star.accessibility.XAccessibleText</code>
49 * interface methods :
50 * <ul>
51 * <li><code> getCaretPosition()</code></li>
52 * <li><code> setCaretPosition()</code></li>
53 * <li><code> getCharacter()</code></li>
54 * <li><code> getCharacterAttributes()</code></li>
55 * <li><code> getCharacterBounds()</code></li>
56 * <li><code> getCharacterCount()</code></li>
57 * <li><code> getIndexAtPoint()</code></li>
58 * <li><code> getSelectedText()</code></li>
59 * <li><code> getSelectionStart()</code></li>
60 * <li><code> getSelectionEnd()</code></li>
61 * <li><code> setSelection()</code></li>
62 * <li><code> getText()</code></li>
63 * <li><code> getTextRange()</code></li>
64 * <li><code> getTextAtIndex()</code></li>
65 * <li><code> getTextBeforeIndex()</code></li>
66 * <li><code> getTextBehindIndex()</code></li>
67 * <li><code> copyText()</code></li>
68 * </ul> <p>
69 * This test needs the following object relations :
70 * <ul>
71 * <li> <code>'XAccessibleText.Text'</code> (of type <code>String</code>)
72 * <b> optional </b> :
73 * the string presentation of component's text. If the relation
74 * is not specified, then text from method <code>getText()</code>
75 * is used.
76 * </li>
77 * </ul> <p>
78 * @see com.sun.star.accessibility.XAccessibleText
80 public class _XAccessibleText extends MultiMethodTest {
82 public XAccessibleText oObj = null;
83 protected com.sun.star.awt.Rectangle bounds = null;
84 String text = null;
85 String editOnly = null;
86 Object LimitedBounds = null;
87 Rectangle chBounds = null;
88 int chCount = 0;
91 /**
92 * Retrieves a string representation of the component's text.
93 * The length of retrieved string must be greater than zero.
95 protected void before() {
96 Object xat = tEnv.getObjRelation("XAccessibleText");
98 XAccessibleComponent component = null;
100 if (xat != null) {
101 oObj = (XAccessibleText) UnoRuntime.queryInterface(
102 XAccessibleText.class, xat);
103 component = (XAccessibleComponent) UnoRuntime.queryInterface(
104 XAccessibleComponent.class, xat);
107 text = (String) tEnv.getObjRelation("XAccessibleText.Text");
109 if (text == null) {
110 text = oObj.getText();
113 if (text.length() == 0) {
114 throw new StatusException(Status.failed(
115 "The length of text must be greater than zero"));
118 editOnly = (String) tEnv.getObjRelation("EditOnly");
119 LimitedBounds = tEnv.getObjRelation("LimitedBounds");
121 if (component == null) {
122 component = (XAccessibleComponent) UnoRuntime.queryInterface(
123 XAccessibleComponent.class,
124 tEnv.getTestObject());
127 bounds = component.getBounds();
129 log.println("Text is '" + text + "'");
130 System.out.println("############################");
134 * Calls the method and checks returned value.
135 * Has OK status if returned value is equal to <code>chCount - 1</code>.
136 * The following method tests are to be executed before:
137 * <ul>
138 * <li> <code>setCaretPosition()</code> </li>
139 * </ul>
141 public void _getCaretPosition() {
142 requiredMethod("getCharacterCount()");
144 if (editOnly != null) {
145 log.println(editOnly);
146 throw new StatusException(Status.skipped(true));
149 boolean res = true;
150 boolean sc = true;
152 try {
153 oObj.setCaretPosition(chCount - 1);
154 } catch (com.sun.star.lang.IndexOutOfBoundsException ie) {
157 int carPos = oObj.getCaretPosition();
158 log.println("getCaretPosition: " + carPos);
160 if (sc) {
161 res = carPos == (chCount - 1);
162 } else {
163 log.println(
164 "Object is read only and Caret position couldn't be set");
165 res = carPos == -1;
168 tRes.tested("getCaretPosition()", res);
172 * Calls the method with the wrong index and with the correct index
173 * <code>chCount - 1</code>.
174 * Has OK status if exception was thrown for wrong index and
175 * if exception wasn't thrown for the correct index.
176 * The following method tests are to be executed before:
177 * <ul>
178 * <li> <code>getCharacterCount()</code> </li>
179 * </ul>
181 public void _setCaretPosition() {
182 requiredMethod("getCharacterCount()");
184 boolean res = true;
186 try {
187 log.print("setCaretPosition(-1):");
188 oObj.setCaretPosition(-1);
189 res &= false;
190 log.println("exception was expected ... FAILED");
191 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
192 log.println("expected exception");
193 res &= true;
196 try {
197 log.print("setCaretPosition(chCount+1):");
198 oObj.setCaretPosition(chCount + 1);
199 res &= false;
200 log.println("exception was expected ... FAILED");
201 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
202 log.println("expected exception");
203 res &= true;
206 try {
207 log.println("setCaretPosition(chCount - 1)");
208 oObj.setCaretPosition(chCount - 1);
209 res &= true;
210 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
211 log.println("unexpected exception ... FAILED");
212 e.printStackTrace(log);
213 res &= false;
216 tRes.tested("setCaretPosition()", res);
220 * Calls the method with the wrong index and with the correct indexes.
221 * Checks every character in the text.
222 * Has OK status if exception was thrown for wrong index,
223 * if exception wasn't thrown for the correct index and
224 * if every character is equal to corresponding character in the text.
225 * The following method tests are to be executed before:
226 * <ul>
227 * <li> <code>getCharacterCount()</code> </li>
228 * </ul>
230 public void _getCharacter() {
231 requiredMethod("getCharacterCount()");
233 boolean res = true;
235 try {
236 log.println("getCharacter(-1)");
237 oObj.getCharacter(-1);
238 log.println("Exception was expected");
239 res = false;
240 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
241 log.println("Expected exception");
242 res = true;
245 try {
246 log.println("getCharacter(chCount)");
247 oObj.getCharacter(chCount);
248 log.println("Exception was expected");
249 res &= false;
250 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
251 log.println("Expected exception");
252 res &= true;
255 try {
256 log.println("Checking of every character in the text...");
258 boolean isEqCh = true;
260 for (int i = 0; i < chCount; i++) {
261 char ch = oObj.getCharacter(i);
262 isEqCh = ch == text.charAt(i);
263 res &= isEqCh;
265 if (!isEqCh) {
266 log.println("At the position " + i +
267 "was expected character: " + text.charAt(i));
268 log.println("but was returned: " + ch);
270 break;
273 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
274 log.println("Unexpected exception");
275 e.printStackTrace(log);
276 res &= false;
279 tRes.tested("getCharacter()", res);
283 * Calls the method with the wrong indexes and with the correct index,
284 * checks a returned value.
285 * Has OK status if exception was thrown for the wrong indexes,
286 * if exception wasn't thrown for the correct index and
287 * if returned value isn't <code>null</code>.
288 * The following method tests are to be executed before:
289 * <ul>
290 * <li> <code>getCharacterCount()</code> </li>
291 * </ul>
293 public void _getCharacterAttributes() {
294 requiredMethod("getCharacterCount()");
296 boolean res = true;
297 String[] attr = new String[] { "" };
299 try {
300 log.println("getCharacterAttributes(-1)");
301 oObj.getCharacterAttributes(-1, attr);
302 log.println("Exception was expected");
303 res &= false;
304 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
305 log.println("Expected exception");
306 res &= true;
309 try {
310 log.println("getCharacterAttributes(chCount)");
311 oObj.getCharacterAttributes(chCount, attr);
312 log.println("Exception was expected");
313 res &= false;
314 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
315 log.println("Expected exception");
316 res &= true;
319 try {
320 log.println("getCharacterAttributes(chCount-1)");
322 PropertyValue[] props = oObj.getCharacterAttributes(chCount - 1,
323 attr);
324 res &= (props != null);
325 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
326 log.println("Unexpected exception");
327 e.printStackTrace(log);
328 res &= false;
331 tRes.tested("getCharacterAttributes()", res);
335 * Calls the method with the wrong indexes and with the correct index.
336 * checks and stores a returned value.
337 * Has OK status if exception was thrown for the wrong indexes,
338 * if exception wasn't thrown for the correct index and
339 * if returned value isn't <code>null</code>.
340 * The following method tests are to be executed before:
341 * <ul>
342 * <li> <code>getCharacterCount()</code> </li>
343 * </ul>
345 public void _getCharacterBounds() {
346 requiredMethod("getCharacterCount()");
348 boolean res = true;
350 int lastIndex = chCount;
352 if (LimitedBounds != null) {
353 if (LimitedBounds instanceof Integer) {
354 lastIndex = ((Integer) LimitedBounds).intValue();
355 } else {
356 lastIndex = chCount - 1;
359 log.println(LimitedBounds);
362 try {
363 log.println("getCharacterBounds(-1)");
364 oObj.getCharacterBounds(-1);
365 log.println("Exception was expected");
366 res &= false;
367 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
368 log.println("Expected exception");
369 res &= true;
372 try {
373 log.println("getCharacterBounds(" + (lastIndex + 1) + ")");
374 oObj.getCharacterBounds(lastIndex + 1);
375 log.println("Exception was expected");
376 res &= false;
377 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
378 log.println("Expected exception");
379 res &= true;
382 try {
383 for (int i = 0; i < lastIndex; i++) {
384 log.println("getCharacterBounds(" + i + ")");
385 chBounds = oObj.getCharacterBounds(i);
387 boolean localres = true;
388 localres = chBounds.X >= 0;
389 localres &= (chBounds.Y >= 0);
390 localres &= ((chBounds.X + chBounds.Width) <= bounds.Width);
391 localres &= ((chBounds.X + chBounds.Width) > 0);
392 localres &= ((chBounds.Y + chBounds.Height) <= bounds.Height);
393 localres &= ((chBounds.Y + chBounds.Height) > 0);
395 if (!localres) {
396 log.println("Text at this place: "+oObj.getCharacter(i));
397 log.println("Character bounds outside component");
398 log.println("Character rect: " + chBounds.X + ", " +
399 chBounds.Y + ", " + chBounds.Width + ", " +
400 chBounds.Height);
401 log.println("Component rect: " + bounds.X + ", " +
402 bounds.Y + ", " + bounds.Width + ", " +
403 bounds.Height);
404 res &= localres;
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 int x = aRect.X + (aRect.Width / 2);
474 int y = aRect.Y + (aRect.Height / 2);
475 Point aPoint = new Point(x, y);
476 int nIndex = oObj.getIndexAtPoint(aPoint);
478 x = aRect.X;
479 y = aRect.Y + (aRect.Height / 2);
480 aPoint = new Point(x, y);
481 int left = oObj.getIndexAtPoint(aPoint);
485 int[] previous = (int[]) tEnv.getObjRelation("PreviousUsed");
487 if (previous != null) {
488 for (int k = 0; k < previous.length; k++) {
489 if (i == previous[k]) {
490 nIndex++;
495 if (nIndex != i) {
496 // for some letters the center of the rectangle isn't recognised
497 // in this case we are happy if the left border of the rectangle
498 // returns the correct value.
499 if (left !=i) {
500 log.println("## Method didn't work for Point (" + x + "," + y +
501 ")");
502 log.println("Expected Index " + i);
503 log.println("Gained Index: " + nIndex);
504 log.println("Left Border: "+left);
505 log.println("CharacterAtIndex: " + text);
506 res &= false;
511 tRes.tested("getIndexAtPoint()", res);
515 * Checks a returned values after different calls of the method
516 * <code>setSelection()</code>.
517 * The following method tests are to be executed before:
518 * <ul>
519 * <li> <code>setSelection()</code> </li>
520 * </ul>
522 public void _getSelectedText() {
523 if (editOnly != null) {
524 log.println(editOnly);
525 throw new StatusException(Status.skipped(true));
528 requiredMethod("setSelection()");
530 boolean res = true;
532 try {
533 log.println("setSelection(0, 0)");
534 oObj.setSelection(0, 0);
535 log.print("getSelectedText():");
537 String txt = oObj.getSelectedText();
538 log.println("'" + txt + "'");
539 res &= (txt.length() == 0);
541 log.println("setSelection(0, chCount)");
542 oObj.setSelection(0, chCount);
543 log.print("getSelectedText():");
544 txt = oObj.getSelectedText();
545 log.println("'" + txt + "'");
546 res &= txt.equals(text);
548 if (chCount > 2) {
549 log.println("setSelection(1, chCount-1)");
550 oObj.setSelection(1, chCount - 1);
551 log.print("getSelectedText():");
552 txt = oObj.getSelectedText();
553 log.println("'" + txt + "'");
554 res &= txt.equals(text.substring(1, chCount - 1));
556 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
557 log.println("Unexpected exception");
558 e.printStackTrace(log);
559 res &= false;
562 tRes.tested("getSelectedText()", res);
566 * Checks a returned values after different calls of the method
567 * <code>setSelection()</code>.
568 * The following method tests are to be executed before:
569 * <ul>
570 * <li> <code>setSelection()</code> </li>
571 * </ul>
573 public void _getSelectionStart() {
574 if (editOnly != null) {
575 log.println(editOnly);
576 throw new StatusException(Status.skipped(true));
579 requiredMethod("setSelection()");
581 boolean res = true;
583 try {
584 log.println("setSelection(0, chCount)");
585 oObj.setSelection(0, chCount);
587 int start = oObj.getSelectionStart();
588 log.println("getSelectionStart():" + start);
589 res &= (start == 0);
591 if (chCount > 2) {
592 log.println("setSelection(1, chCount-1)");
593 oObj.setSelection(1, chCount - 1);
594 start = oObj.getSelectionStart();
595 log.println("getSelectionStart():" + start);
596 res &= (start == 1);
598 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
599 log.println("Unexpected exception");
600 e.printStackTrace(log);
601 res &= false;
604 tRes.tested("getSelectionStart()", res);
608 * Checks a returned values after different calls of the method
609 * <code>setSelection()</code>.
610 * The following method tests are to be executed before:
611 * <ul>
612 * <li> <code>setSelection()</code> </li>
613 * </ul>
615 public void _getSelectionEnd() {
616 if (editOnly != null) {
617 log.println(editOnly);
618 throw new StatusException(Status.skipped(true));
621 requiredMethod("setSelection()");
623 boolean res = true;
625 try {
626 log.println("setSelection(0, chCount)");
627 oObj.setSelection(0, chCount);
629 int end = oObj.getSelectionEnd();
630 log.println("getSelectionEnd():" + end);
631 res &= (end == chCount);
633 if (chCount > 2) {
634 log.println("setSelection(1, chCount-1)");
635 oObj.setSelection(1, chCount - 1);
636 end = oObj.getSelectionEnd();
637 log.println("getSelectionEnd():" + end);
638 res &= (end == (chCount - 1));
640 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
641 log.println("Unexpected exception");
642 e.printStackTrace(log);
643 res &= false;
646 tRes.tested("getSelectionEnd()", res);
650 * Calls the method with invalid parameters an with valid parameters.
651 * Has OK status if exception was thrown for invalid parameters,
652 * if exception wasn't thrown for valid parameters.
653 * The following method tests are to be executed before:
654 * <ul>
655 * <li> <code>getCharacterCount()</code> </li>
656 * </ul>
658 public void _setSelection() {
659 requiredMethod("getCharacterCount()");
661 boolean res = true;
662 boolean locRes = true;
664 if (editOnly != null) {
665 log.println(editOnly);
666 throw new StatusException(Status.skipped(true));
669 try {
670 log.print("setSelection(-1, chCount-1):");
671 locRes = oObj.setSelection(-1, chCount - 1);
672 log.println(locRes + " excepion was expected");
673 res &= !locRes;
674 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
675 log.println("Expected exception");
676 res &= true;
679 try {
680 log.print("setSelection(0, chCount+1):");
681 locRes = oObj.setSelection(0, chCount + 1);
682 log.println(locRes + " excepion was expected");
683 res &= !locRes;
684 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
685 log.println("Expected exception");
686 res &= true;
689 try {
690 if (chCount > 2) {
691 log.print("setSelection(1, chCount-1):");
692 locRes = oObj.setSelection(1, chCount - 1);
693 log.println(locRes);
694 res &= locRes;
696 log.print("setSelection(chCount-1, 1):");
697 locRes = oObj.setSelection(chCount - 1, 1);
698 log.println(locRes);
699 res &= locRes;
702 log.print("setSelection(0, chCount-1):");
703 locRes = oObj.setSelection(0, chCount - 1);
704 log.println(locRes);
705 res &= locRes;
707 log.print("setSelection(chCount-1, 0):");
708 locRes = oObj.setSelection(chCount - 1, 0);
709 log.println(locRes);
710 res &= locRes;
712 log.print("setSelection(0, 0):");
713 locRes = oObj.setSelection(0, 0);
714 log.println(locRes);
715 res &= locRes;
716 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
717 log.println("Unexpected exception");
718 e.printStackTrace(log);
719 res &= false;
722 tRes.tested("setSelection()", res);
726 * Calls the method and checks returned value.
727 * Has OK status if returned string is equal to string
728 * received from relation.
730 public void _getText() {
731 String txt = oObj.getText();
732 log.println("getText: " + txt);
734 boolean res = txt.equals(text);
735 tRes.tested("getText()", res);
739 * Calls the method with invalid parameters an with valid parameters,
740 * checks returned values.
741 * Has OK status if exception was thrown for invalid parameters,
742 * if exception wasn't thrown for valid parameters and if returned values
743 * are equal to corresponding substrings of the text received by relation.
744 * The following method tests are to be executed before:
745 * <ul>
746 * <li> <code>getCharacterCount()</code> </li>
747 * </ul>
749 public void _getTextRange() {
750 requiredMethod("getCharacterCount()");
752 boolean res = true;
753 boolean locRes = true;
755 String txtRange = "";
757 try {
758 if (chCount > 3) {
759 log.print("getTextRange(1, chCount - 2): ");
761 txtRange = oObj.getTextRange(1, chCount - 2);
762 log.println(txtRange);
763 locRes = txtRange.equals(text.substring(1, chCount - 2));
764 res &= locRes;
766 if (!locRes) {
767 log.println("Was expected: " +
768 text.substring(1, chCount - 2));
772 log.print("getTextRange(0, chCount-1): ");
774 txtRange = oObj.getTextRange(0, chCount - 1);
775 log.println(txtRange);
776 locRes = txtRange.equals(text.substring(0, chCount - 1));
777 res &= locRes;
779 if (!locRes) {
780 log.println("Was expected: " +
781 text.substring(0, chCount - 1));
784 log.print("getTextRange(chCount, 0): ");
785 txtRange = oObj.getTextRange(chCount, 0);
786 log.println(txtRange);
787 res &= txtRange.equals(text);
789 log.print("getTextRange(0, 0): ");
790 txtRange = oObj.getTextRange(0, 0);
791 log.println(txtRange);
792 locRes = txtRange.equals("");
793 res &= locRes;
795 if (!locRes) {
796 log.println("Empty string was expected");
798 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
799 log.println("Unexpected exception");
800 e.printStackTrace(log);
801 res &= false;
804 try {
805 log.print("getTextRange(-1, chCount - 1): ");
807 txtRange = oObj.getTextRange(-1, chCount - 1);
808 log.println("Exception was expected");
809 res &= false;
810 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
811 log.println("Expected exception");
812 res &= true;
815 try {
816 log.print("getTextRange(0, chCount + 1): ");
818 txtRange = oObj.getTextRange(0, chCount + 1);
819 log.println("Exception was expected");
820 res &= false;
821 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
822 log.println("Expected exception");
823 res &= true;
826 try {
827 log.print("getTextRange(chCount+1, -1): ");
829 txtRange = oObj.getTextRange(chCount + 1, -1);
830 log.println("Exception was expected");
831 res &= false;
832 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
833 log.println("Expected exception");
834 res &= true;
837 tRes.tested("getTextRange()", res);
841 * Calls the method with invalid parameters an with valid parameters,
842 * checks returned values.
843 * Has OK status if exception was thrown for invalid parameters,
844 * if exception wasn't thrown for valid parameters and if returned values
845 * are equal to corresponding substrings of the text received by relation.
846 * The following method tests are to be executed before:
847 * <ul>
848 * <li> <code>getCharacterCount()</code> </li>
849 * </ul>
851 public void _getTextAtIndex() {
852 requiredMethod("getCharacterCount()");
853 TextSegment txt = null;
854 boolean res = true;
856 try {
857 log.print("getTextAtIndex(-1, AccessibleTextType.PARAGRAPH):");
859 txt = oObj.getTextAtIndex(-1,
860 AccessibleTextType.PARAGRAPH);
861 log.println("Exception was expected");
862 res &= false;
863 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
864 log.println("Expected exception");
865 res &= true;
866 } catch (com.sun.star.lang.IllegalArgumentException e) {
867 log.println("UnExpected exception");
868 res &= false;
871 try {
872 log.print("getTextAtIndex(chCount+1," +
873 " AccessibleTextType.PARAGRAPH):");
875 txt = oObj.getTextAtIndex(chCount + 1,
876 AccessibleTextType.PARAGRAPH);
877 log.println("Exception was expected");
878 res &= false;
879 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
880 log.println("Expected exception");
881 res &= true;
882 } catch (com.sun.star.lang.IllegalArgumentException e) {
883 log.println("UnExpected exception");
884 res &= false;
887 try {
888 log.print("getTextAtIndex(chCount," +
889 " AccessibleTextType.WORD):");
891 txt = oObj.getTextAtIndex(chCount, AccessibleTextType.WORD);
892 log.println("'" + txt.SegmentText + "'");
893 res &= compareLength(0,txt.SegmentText);
894 if (!tEnv.getTestCase().getObjectName().equals("SmGraphicAccessible")) {
895 log.print("getTextAtIndex(1," +
896 " AccessibleTextType.PARAGRAPH):");
897 txt = oObj.getTextAtIndex(1, AccessibleTextType.PARAGRAPH);
898 log.println("'" + txt.SegmentText + "'");
899 res &= compareStrings(text,txt.SegmentText);
901 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
902 log.println("Unexpected exception");
903 e.printStackTrace(log);
904 res &= false;
905 } catch (com.sun.star.lang.IllegalArgumentException e) {
906 log.println("Unexpected exception");
907 e.printStackTrace(log);
908 res &= false;
911 tRes.tested("getTextAtIndex()", res);
915 * Calls the method with invalid parameters an with valid parameters,
916 * checks returned values.
917 * Has OK status if exception was thrown for invalid parameters,
918 * if exception wasn't thrown for valid parameters and if returned values
919 * are equal to corresponding substrings of the text received by relation.
920 * The following method tests are to be executed before:
921 * <ul>
922 * <li> <code>getCharacterCount()</code> </li>
923 * </ul>
925 public void _getTextBeforeIndex() {
926 requiredMethod("getCharacterCount()");
927 TextSegment txt = null;
928 boolean res = true;
930 try {
931 log.print("getTextBeforeIndex(-1, AccessibleTextType.PARAGRAPH):");
933 txt = oObj.getTextBeforeIndex(-1,
934 AccessibleTextType.PARAGRAPH);
935 log.println("Exception was expected");
936 res &= false;
937 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
938 log.println("Expected exception");
939 res &= true;
940 } catch (com.sun.star.lang.IllegalArgumentException e) {
941 log.println("UnExpected exception");
942 res &= false;
945 try {
946 log.print("getTextBeforeIndex(chCount+1, " +
947 "AccessibleTextType.PARAGRAPH):");
949 txt = oObj.getTextBeforeIndex(chCount + 1,
950 AccessibleTextType.PARAGRAPH);
951 log.println("Exception was expected");
952 res &= false;
953 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
954 log.println("Expected exception");
955 res &= true;
956 } catch (com.sun.star.lang.IllegalArgumentException e) {
957 log.println("UnExpected exception");
958 res &= true;
961 try {
962 if (!tEnv.getTestCase().getObjectName().equals("SmGraphicAccessible")) {
963 log.print("getTextBeforeIndex(chCount," +
964 " AccessibleTextType.WORD):");
966 txt = oObj.getTextBeforeIndex(chCount,
967 AccessibleTextType.WORD);
968 log.println("'" + txt.SegmentText + "'");
969 res &= compareLength(chCount, txt.SegmentText);
972 log.print("getTextBeforeIndex(1," +
973 " AccessibleTextType.PARAGRAPH):");
974 txt = oObj.getTextBeforeIndex(1, AccessibleTextType.PARAGRAPH);
975 log.println("'" + txt.SegmentText + "'");
976 res &= compareLength(0, txt.SegmentText);
978 log.print("getTextBeforeIndex(chCount-1," +
979 " AccessibleTextType.CHARACTER):");
980 txt = oObj.getTextBeforeIndex(chCount - 1,
981 AccessibleTextType.CHARACTER);
982 log.println("'" + txt.SegmentText + "'");
983 res &= compareStrings(text.substring(chCount - 2, chCount - 1),
984 txt.SegmentText);
986 if (chCount > 2) {
987 log.print("getTextBeforeIndex(2," +
988 " AccessibleTextType.CHARACTER):");
989 txt = oObj.getTextBeforeIndex(2, AccessibleTextType.CHARACTER);
990 log.println("'" + txt.SegmentText + "'");
991 res &= compareStrings(text.substring(1, 2), txt.SegmentText);
993 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
994 log.println("Unexpected exception");
995 e.printStackTrace(log);
996 res &= false;
997 } catch (com.sun.star.lang.IllegalArgumentException e) {
998 log.println("Unexpected exception");
999 e.printStackTrace(log);
1000 res &= false;
1003 tRes.tested("getTextBeforeIndex()", res);
1007 * Calls the method with invalid parameters an with valid parameters,
1008 * checks returned values.
1009 * Has OK status if exception was thrown for invalid parameters,
1010 * if exception wasn't thrown for valid parameters and if returned values
1011 * are equal to corresponding substrings of the text received by relation.
1012 * The following method tests are to be executed before:
1013 * <ul>
1014 * <li> <code>getCharacterCount()</code> </li>
1015 * </ul>
1017 public void _getTextBehindIndex() {
1018 requiredMethod("getCharacterCount()");
1019 TextSegment txt = null;
1020 boolean res = true;
1022 try {
1023 log.print("getTextBehindIndex(-1, AccessibleTextType.PARAGRAPH):");
1025 txt = oObj.getTextBehindIndex(-1,
1026 AccessibleTextType.PARAGRAPH);
1027 log.println("Exception was expected");
1028 res &= false;
1029 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
1030 log.println("Expected exception");
1031 res &= true;
1032 } catch (com.sun.star.lang.IllegalArgumentException e) {
1033 log.println("UnExpected exception");
1034 res &= true;
1037 try {
1038 log.print("getTextBehindIndex(chCount+1, " +
1039 "AccessibleTextType.PARAGRAPH):");
1041 txt = oObj.getTextBehindIndex(chCount + 1,
1042 AccessibleTextType.PARAGRAPH);
1043 log.println("Exception was expected");
1044 res &= false;
1045 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
1046 log.println("Expected exception");
1047 res &= true;
1048 } catch (com.sun.star.lang.IllegalArgumentException e) {
1049 log.println("UnExpected exception");
1050 res &= true;
1053 try {
1054 log.print("getTextBehindIndex(chCount," +
1055 " AccessibleTextType.PARAGRAPH):");
1057 txt = oObj.getTextBehindIndex(chCount,
1058 AccessibleTextType.PARAGRAPH);
1059 log.println("'" + txt.SegmentText + "'");
1060 res &= (txt.SegmentText.length() == 0);
1062 log.print("getTextBehindIndex(chCount-1," +
1063 " AccessibleTextType.PARAGRAPH):");
1064 txt = oObj.getTextBehindIndex(chCount - 1,
1065 AccessibleTextType.PARAGRAPH);
1066 log.println("'" + txt.SegmentText + "'");
1067 res &= (txt.SegmentText.length() == 0);
1069 log.print("getTextBehindIndex(1," +
1070 " AccessibleTextType.CHARACTER):");
1071 txt = oObj.getTextBehindIndex(1, AccessibleTextType.CHARACTER);
1072 log.println("'" + txt.SegmentText + "'");
1073 res &= txt.SegmentText.equals(text.substring(2, 3));
1075 if (chCount > 2) {
1076 log.print("getTextBehindIndex(chCount-2," +
1077 " AccessibleTextType.CHARACTER):");
1078 txt = oObj.getTextBehindIndex(chCount - 2,
1079 AccessibleTextType.CHARACTER);
1080 log.println("'" + txt.SegmentText + "'");
1081 res &= txt.SegmentText.equals(text.substring(chCount - 1, chCount));
1083 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
1084 log.println("Unexpected exception");
1085 e.printStackTrace(log);
1086 res &= false;
1087 } catch (com.sun.star.lang.IllegalArgumentException e) {
1088 log.println("Unexpected exception");
1089 e.printStackTrace(log);
1090 res &= false;
1093 tRes.tested("getTextBehindIndex()", res);
1097 * Calls the method with invalid parameters an with valid parameter,
1098 * checks returned values.
1099 * Has OK status if exception was thrown for invalid parameters,
1100 * if exception wasn't thrown for valid parameter and if returned value for
1101 * valid parameter is equal to <code>true</code>.
1103 public void _copyText() {
1104 boolean res = true;
1105 boolean locRes = true;
1107 if (editOnly != null) {
1108 log.println(editOnly);
1109 throw new StatusException(Status.skipped(true));
1112 try {
1113 log.print("copyText(-1,chCount):");
1114 oObj.copyText(-1, chCount);
1115 log.println("Exception was expected");
1116 res &= false;
1117 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
1118 log.println("Expected exception");
1119 res &= true;
1122 try {
1123 log.print("copyText(0,chCount+1):");
1124 oObj.copyText(0, chCount + 1);
1125 log.println("Exception was expected");
1126 res &= false;
1127 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
1128 log.println("Expected exception");
1129 res &= true;
1132 try {
1133 log.print("copyText(0,chCount):");
1134 locRes = oObj.copyText(0, chCount);
1135 log.println(locRes);
1136 res &= locRes;
1138 String cbText = null;
1140 try {
1141 cbText = util.SysUtils.getSysClipboardText((XMultiServiceFactory)tParam.getMSF());
1142 } catch (com.sun.star.uno.Exception e) {
1143 log.println("Couldn't access system clipboard :");
1144 e.printStackTrace(log);
1147 log.println("Clipboard: '" + cbText + "'");
1148 res &= text.equals(cbText);
1150 if (chCount > 2) {
1151 log.print("copyText(1,chCount-1):");
1152 locRes = oObj.copyText(1, chCount - 1);
1153 log.println(locRes);
1154 res &= locRes;
1156 try {
1157 cbText = util.SysUtils.getSysClipboardText((XMultiServiceFactory)tParam.getMSF());
1158 } catch (com.sun.star.uno.Exception e) {
1159 log.println("Couldn't access system clipboard :");
1160 e.printStackTrace(log);
1163 log.println("Clipboard: '" + cbText + "'");
1164 res &= text.substring(1, chCount - 1).equals(cbText);
1166 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
1167 log.println("Unexpected exception");
1168 e.printStackTrace(log);
1169 res &= false;
1172 tRes.tested("copyText()", res);
1175 public boolean compareStrings(String expected, String getting) {
1176 boolean res = expected.equals(getting);
1178 if (!res) {
1179 log.println("## The result isn't the expected:");
1180 log.println("\tGetting: " + getting);
1181 log.println("\tExpected: " + expected);
1184 return res;
1187 public boolean compareLength(int expected, String getting) {
1188 boolean res = (expected == getting.length());
1190 if (!res) {
1191 log.println("## The result isn't the expected:");
1192 log.println("\tGetting: " + getting.length());
1193 log.println("\tExpected: " + expected);
1196 return res;