xref: /AOO41X/main/qadevOOo/tests/java/ifc/accessibility/_XAccessibleText.java (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 package ifc.accessibility;
28 
29 import lib.MultiMethodTest;
30 import lib.Status;
31 import lib.StatusException;
32 
33 import com.sun.star.accessibility.AccessibleTextType;
34 import com.sun.star.accessibility.TextSegment;
35 import com.sun.star.accessibility.XAccessibleComponent;
36 import com.sun.star.accessibility.XAccessibleText;
37 import com.sun.star.awt.Point;
38 import com.sun.star.awt.Rectangle;
39 import com.sun.star.beans.PropertyValue;
40 import com.sun.star.lang.XMultiServiceFactory;
41 import com.sun.star.uno.UnoRuntime;
42 
43 
44 /**
45  * Testing <code>com.sun.star.accessibility.XAccessibleText</code>
46  * interface methods :
47  * <ul>
48  *  <li><code> getCaretPosition()</code></li>
49  *  <li><code> setCaretPosition()</code></li>
50  *  <li><code> getCharacter()</code></li>
51  *  <li><code> getCharacterAttributes()</code></li>
52  *  <li><code> getCharacterBounds()</code></li>
53  *  <li><code> getCharacterCount()</code></li>
54  *  <li><code> getIndexAtPoint()</code></li>
55  *  <li><code> getSelectedText()</code></li>
56  *  <li><code> getSelectionStart()</code></li>
57  *  <li><code> getSelectionEnd()</code></li>
58  *  <li><code> setSelection()</code></li>
59  *  <li><code> getText()</code></li>
60  *  <li><code> getTextRange()</code></li>
61  *  <li><code> getTextAtIndex()</code></li>
62  *  <li><code> getTextBeforeIndex()</code></li>
63  *  <li><code> getTextBehindIndex()</code></li>
64  *  <li><code> copyText()</code></li>
65  * </ul> <p>
66  * This test needs the following object relations :
67  * <ul>
68  *  <li> <code>'XAccessibleText.Text'</code> (of type <code>String</code>)
69  *   <b> optional </b> :
70  *   the string presentation of component's text. If the relation
71  *   is not specified, then text from method <code>getText()</code>
72  *   is used.
73  *  </li>
74  *  </ul> <p>
75  * @see com.sun.star.accessibility.XAccessibleText
76  */
77 public class _XAccessibleText extends MultiMethodTest {
78 
79     public XAccessibleText oObj = null;
80     protected com.sun.star.awt.Rectangle bounds = null;
81     String text = null;
82     String editOnly = null;
83     Object LimitedBounds = null;
84     Rectangle chBounds = null;
85     int chCount = 0;
86 
87 
88     /**
89      * Retrieves a string representation of the component's text.
90      * The length of retrieved string must be greater than zero.
91      */
92     protected void before() {
93         Object xat = tEnv.getObjRelation("XAccessibleText");
94 
95         XAccessibleComponent component = null;
96 
97         if (xat != null) {
98             oObj = (XAccessibleText) UnoRuntime.queryInterface(
99                            XAccessibleText.class, xat);
100             component = (XAccessibleComponent) UnoRuntime.queryInterface(
101                                 XAccessibleComponent.class, xat);
102         }
103 
104         text = (String) tEnv.getObjRelation("XAccessibleText.Text");
105 
106         if (text == null) {
107             text = oObj.getText();
108         }
109 
110         if (text.length() == 0) {
111             throw new StatusException(Status.failed(
112                                               "The length of text must be greater than zero"));
113         }
114 
115         editOnly = (String) tEnv.getObjRelation("EditOnly");
116         LimitedBounds = tEnv.getObjRelation("LimitedBounds");
117 
118         if (component == null) {
119             component = (XAccessibleComponent) UnoRuntime.queryInterface(
120                                 XAccessibleComponent.class,
121                                 tEnv.getTestObject());
122         }
123 
124         bounds = component.getBounds();
125 
126         log.println("Text is '" + text + "'");
127         System.out.println("############################");
128     }
129 
130     /**
131      * Calls the method and checks returned value.
132      * Has OK status if returned value is equal to <code>chCount - 1</code>.
133      * The following method tests are to be executed before:
134      * <ul>
135      *  <li> <code>setCaretPosition()</code> </li>
136      * </ul>
137      */
138     public void _getCaretPosition() {
139         requiredMethod("getCharacterCount()");
140 
141         if (editOnly != null) {
142             log.println(editOnly);
143             throw new StatusException(Status.skipped(true));
144         }
145 
146         boolean res = true;
147         boolean sc = true;
148 
149         try {
150             oObj.setCaretPosition(chCount - 1);
151         } catch (com.sun.star.lang.IndexOutOfBoundsException ie) {
152         }
153 
154         int carPos = oObj.getCaretPosition();
155         log.println("getCaretPosition: " + carPos);
156 
157         if (sc) {
158             res = carPos == (chCount - 1);
159         } else {
160             log.println(
161                     "Object is read only and Caret position couldn't be set");
162             res = carPos == -1;
163         }
164 
165         tRes.tested("getCaretPosition()", res);
166     }
167 
168     /**
169      * Calls the method with the wrong index and with the correct index
170      * <code>chCount - 1</code>.
171      * Has OK status if exception was thrown for wrong index and
172      * if exception wasn't thrown for the correct index.
173      * The following method tests are to be executed before:
174      * <ul>
175      *  <li> <code>getCharacterCount()</code> </li>
176      * </ul>
177      */
178     public void _setCaretPosition() {
179         requiredMethod("getCharacterCount()");
180 
181         boolean res = true;
182 
183         try {
184             log.print("setCaretPosition(-1):");
185             oObj.setCaretPosition(-1);
186             res &= false;
187             log.println("exception was expected ... FAILED");
188         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
189             log.println("expected exception");
190             res &= true;
191         }
192 
193         try {
194             log.print("setCaretPosition(chCount+1):");
195             oObj.setCaretPosition(chCount + 1);
196             res &= false;
197             log.println("exception was expected  ... FAILED");
198         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
199             log.println("expected exception");
200             res &= true;
201         }
202 
203         try {
204             log.println("setCaretPosition(chCount - 1)");
205             oObj.setCaretPosition(chCount - 1);
206             res &= true;
207         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
208             log.println("unexpected exception  ... FAILED");
209             e.printStackTrace(log);
210             res &= false;
211         }
212 
213         tRes.tested("setCaretPosition()", res);
214     }
215 
216     /**
217      * Calls the method with the wrong index and with the correct indexes.
218      * Checks every character in the text.
219      * Has OK status if exception was thrown for wrong index,
220      * if exception wasn't thrown for the correct index and
221      * if every character is equal to corresponding character in the text.
222      * The following method tests are to be executed before:
223      * <ul>
224      *  <li> <code>getCharacterCount()</code> </li>
225      * </ul>
226      */
227     public void _getCharacter() {
228         requiredMethod("getCharacterCount()");
229 
230         boolean res = true;
231 
232         try {
233             log.println("getCharacter(-1)");
234             oObj.getCharacter(-1);
235             log.println("Exception was expected");
236             res = false;
237         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
238             log.println("Expected exception");
239             res = true;
240         }
241 
242         try {
243             log.println("getCharacter(chCount)");
244             oObj.getCharacter(chCount);
245             log.println("Exception was expected");
246             res &= false;
247         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
248             log.println("Expected exception");
249             res &= true;
250         }
251 
252         try {
253             log.println("Checking of every character in the text...");
254 
255             boolean isEqCh = true;
256 
257             for (int i = 0; i < chCount; i++) {
258                 char ch = oObj.getCharacter(i);
259                 isEqCh = ch == text.charAt(i);
260                 res &= isEqCh;
261 
262                 if (!isEqCh) {
263                     log.println("At the position " + i +
264                                 "was expected character: " + text.charAt(i));
265                     log.println("but was returned: " + ch);
266 
267                     break;
268                 }
269             }
270         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
271             log.println("Unexpected exception");
272             e.printStackTrace(log);
273             res &= false;
274         }
275 
276         tRes.tested("getCharacter()", res);
277     }
278 
279     /**
280      * Calls the method with the wrong indexes and with the correct index,
281      * checks a returned value.
282      * Has OK status if exception was thrown for the wrong indexes,
283      * if exception wasn't thrown for the correct index and
284      * if returned value isn't <code>null</code>.
285      * The following method tests are to be executed before:
286      * <ul>
287      *  <li> <code>getCharacterCount()</code> </li>
288      * </ul>
289      */
290     public void _getCharacterAttributes() {
291         requiredMethod("getCharacterCount()");
292 
293         boolean res = true;
294         String[] attr = new String[] { "" };
295 
296         try {
297             log.println("getCharacterAttributes(-1)");
298             oObj.getCharacterAttributes(-1, attr);
299             log.println("Exception was expected");
300             res &= false;
301         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
302             log.println("Expected exception");
303             res &= true;
304         }
305 
306         try {
307             log.println("getCharacterAttributes(chCount)");
308             oObj.getCharacterAttributes(chCount, attr);
309             log.println("Exception was expected");
310             res &= false;
311         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
312             log.println("Expected exception");
313             res &= true;
314         }
315 
316         try {
317             log.println("getCharacterAttributes(chCount-1)");
318 
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         }
327 
328         tRes.tested("getCharacterAttributes()", res);
329     }
330 
331     /**
332      * Calls the method with the wrong indexes and with the correct index.
333      * checks and stores a returned value.
334      * Has OK status if exception was thrown for the wrong indexes,
335      * if exception wasn't thrown for the correct index and
336      * if returned value isn't <code>null</code>.
337      * The following method tests are to be executed before:
338      * <ul>
339      *  <li> <code>getCharacterCount()</code> </li>
340      * </ul>
341      */
342     public void _getCharacterBounds() {
343         requiredMethod("getCharacterCount()");
344 
345         boolean res = true;
346 
347         int lastIndex = chCount;
348 
349         if (LimitedBounds != null) {
350             if (LimitedBounds instanceof Integer) {
351                 lastIndex = ((Integer) LimitedBounds).intValue();
352             } else {
353                 lastIndex = chCount - 1;
354             }
355 
356             log.println(LimitedBounds);
357         }
358 
359         try {
360             log.println("getCharacterBounds(-1)");
361             oObj.getCharacterBounds(-1);
362             log.println("Exception was expected");
363             res &= false;
364         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
365             log.println("Expected exception");
366             res &= true;
367         }
368 
369         try {
370             log.println("getCharacterBounds(" + (lastIndex + 1) + ")");
371             oObj.getCharacterBounds(lastIndex + 1);
372             log.println("Exception was expected");
373             res &= false;
374         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
375             log.println("Expected exception");
376             res &= true;
377         }
378 
379         try {
380             for (int i = 0; i < lastIndex; i++) {
381                 log.println("getCharacterBounds(" + i + ")");
382                 chBounds = oObj.getCharacterBounds(i);
383 
384                 boolean localres = true;
385                 localres = chBounds.X >= 0;
386                 localres &= (chBounds.Y >= 0);
387                 localres &= ((chBounds.X + chBounds.Width) <= bounds.Width);
388                 localres &= ((chBounds.X + chBounds.Width) > 0);
389                 localres &= ((chBounds.Y + chBounds.Height) <= bounds.Height);
390                 localres &= ((chBounds.Y + chBounds.Height) > 0);
391 
392                 if (!localres) {
393                     log.println("Text at this place: "+oObj.getCharacter(i));
394                     log.println("Character bounds outside component");
395                     log.println("Character rect: " + chBounds.X + ", " +
396                                 chBounds.Y + ", " + chBounds.Width + ", " +
397                                 chBounds.Height);
398                     log.println("Component rect: " + bounds.X + ", " +
399                                 bounds.Y + ", " + bounds.Width + ", " +
400                                 bounds.Height);
401                     res &= localres;
402                 }
403             }
404         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
405             log.println("Unexpected exception");
406             e.printStackTrace(log);
407             res &= false;
408         }
409 
410         tRes.tested("getCharacterBounds()", res);
411     }
412 
413     /**
414      * Calls the method and stores a returned value to the variable
415      * <code>chCount</code>.
416      * Has OK status if a returned value is equal to the text length.
417      */
418     public void _getCharacterCount() {
419         chCount = oObj.getCharacterCount();
420         log.println("Character count:" + chCount);
421 
422         boolean res = chCount == text.length();
423         tRes.tested("getCharacterCount()", res);
424     }
425 
426     /**
427      * Calls the method for an invalid point and for the point of rectangle
428      * returned by the method <code>getCharacterBounds()</code>.
429      * Has OK status if returned value is equal to <code>-1</code> for an
430      * invalid point and if returned value is equal to <code>chCount-1</code>
431      * for a valid point.
432      * The following method tests are to be executed before:
433      * <ul>
434      *  <li> <code>getCharacterBounds()</code> </li>
435      * </ul>
436      */
437     public void _getIndexAtPoint() {
438         //requiredMethod("getCharacterBounds()");
439         boolean res = true;
440         log.print("getIndexAtPoint(-1, -1):");
441 
442         Point pt = new Point(-1, -1);
443         int index = oObj.getIndexAtPoint(pt);
444         log.println(index);
445         res &= (index == -1);
446 
447         int lastIndex = chCount;
448 
449         if (LimitedBounds != null) {
450             if (LimitedBounds instanceof Integer) {
451                 lastIndex = ((Integer) LimitedBounds).intValue();
452             } else {
453                 lastIndex = chCount - 1;
454             }
455 
456             log.println(LimitedBounds);
457         }
458 
459         for (int i = 0; i < lastIndex; i++) {
460             Rectangle aRect = null;
461             String text = "empty";
462 
463             try {
464                 aRect = oObj.getCharacterBounds(i);
465                 text = oObj.getTextAtIndex(i, (short) 1).SegmentText;
466             } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
467             } catch (com.sun.star.lang.IllegalArgumentException e) {
468             }
469 
470             int x = aRect.X + (aRect.Width / 2);
471             int y = aRect.Y + (aRect.Height / 2);
472             Point aPoint = new Point(x, y);
473             int nIndex = oObj.getIndexAtPoint(aPoint);
474 
475             x = aRect.X;
476             y = aRect.Y + (aRect.Height / 2);
477             aPoint = new Point(x, y);
478             int left = oObj.getIndexAtPoint(aPoint);
479 
480 
481 
482             int[] previous = (int[]) tEnv.getObjRelation("PreviousUsed");
483 
484             if (previous != null) {
485                 for (int k = 0; k < previous.length; k++) {
486                     if (i == previous[k]) {
487                         nIndex++;
488                     }
489                 }
490             }
491 
492             if (nIndex != i) {
493                 // for some letters the center of the rectangle isn't recognised
494                 // in this case we are happy if the left border of the rectangle
495                 // returns the correct value.
496                 if (left !=i) {
497                     log.println("## Method didn't work for Point (" + x + "," + y +
498                             ")");
499                     log.println("Expected Index " + i);
500                     log.println("Gained Index: " + nIndex);
501                     log.println("Left Border: "+left);
502                     log.println("CharacterAtIndex: " + text);
503                     res &= false;
504                 }
505             }
506         }
507 
508         tRes.tested("getIndexAtPoint()", res);
509     }
510 
511     /**
512      * Checks a returned values after different calls of the method
513      * <code>setSelection()</code>.
514      * The following method tests are to be executed before:
515      * <ul>
516      *  <li> <code>setSelection()</code> </li>
517      * </ul>
518      */
519     public void _getSelectedText() {
520         if (editOnly != null) {
521             log.println(editOnly);
522             throw new StatusException(Status.skipped(true));
523         }
524 
525         requiredMethod("setSelection()");
526 
527         boolean res = true;
528 
529         try {
530             log.println("setSelection(0, 0)");
531             oObj.setSelection(0, 0);
532             log.print("getSelectedText():");
533 
534             String txt = oObj.getSelectedText();
535             log.println("'" + txt + "'");
536             res &= (txt.length() == 0);
537 
538             log.println("setSelection(0, chCount)");
539             oObj.setSelection(0, chCount);
540             log.print("getSelectedText():");
541             txt = oObj.getSelectedText();
542             log.println("'" + txt + "'");
543             res &= txt.equals(text);
544 
545             if (chCount > 2) {
546                 log.println("setSelection(1, chCount-1)");
547                 oObj.setSelection(1, chCount - 1);
548                 log.print("getSelectedText():");
549                 txt = oObj.getSelectedText();
550                 log.println("'" + txt + "'");
551                 res &= txt.equals(text.substring(1, chCount - 1));
552             }
553         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
554             log.println("Unexpected exception");
555             e.printStackTrace(log);
556             res &= false;
557         }
558 
559         tRes.tested("getSelectedText()", res);
560     }
561 
562     /**
563      * Checks a returned values after different calls of the method
564      * <code>setSelection()</code>.
565      * The following method tests are to be executed before:
566      * <ul>
567      *  <li> <code>setSelection()</code> </li>
568      * </ul>
569      */
570     public void _getSelectionStart() {
571         if (editOnly != null) {
572             log.println(editOnly);
573             throw new StatusException(Status.skipped(true));
574         }
575 
576         requiredMethod("setSelection()");
577 
578         boolean res = true;
579 
580         try {
581             log.println("setSelection(0, chCount)");
582             oObj.setSelection(0, chCount);
583 
584             int start = oObj.getSelectionStart();
585             log.println("getSelectionStart():" + start);
586             res &= (start == 0);
587 
588             if (chCount > 2) {
589                 log.println("setSelection(1, chCount-1)");
590                 oObj.setSelection(1, chCount - 1);
591                 start = oObj.getSelectionStart();
592                 log.println("getSelectionStart():" + start);
593                 res &= (start == 1);
594             }
595         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
596             log.println("Unexpected exception");
597             e.printStackTrace(log);
598             res &= false;
599         }
600 
601         tRes.tested("getSelectionStart()", res);
602     }
603 
604     /**
605      * Checks a returned values after different calls of the method
606      * <code>setSelection()</code>.
607      * The following method tests are to be executed before:
608      * <ul>
609      *  <li> <code>setSelection()</code> </li>
610      * </ul>
611      */
612     public void _getSelectionEnd() {
613         if (editOnly != null) {
614             log.println(editOnly);
615             throw new StatusException(Status.skipped(true));
616         }
617 
618         requiredMethod("setSelection()");
619 
620         boolean res = true;
621 
622         try {
623             log.println("setSelection(0, chCount)");
624             oObj.setSelection(0, chCount);
625 
626             int end = oObj.getSelectionEnd();
627             log.println("getSelectionEnd():" + end);
628             res &= (end == chCount);
629 
630             if (chCount > 2) {
631                 log.println("setSelection(1, chCount-1)");
632                 oObj.setSelection(1, chCount - 1);
633                 end = oObj.getSelectionEnd();
634                 log.println("getSelectionEnd():" + end);
635                 res &= (end == (chCount - 1));
636             }
637         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
638             log.println("Unexpected exception");
639             e.printStackTrace(log);
640             res &= false;
641         }
642 
643         tRes.tested("getSelectionEnd()", res);
644     }
645 
646     /**
647      * Calls the method with invalid parameters an with valid parameters.
648      * Has OK status if exception was thrown for invalid parameters,
649      * if exception wasn't thrown for valid parameters.
650      * The following method tests are to be executed before:
651      * <ul>
652      *  <li> <code>getCharacterCount()</code> </li>
653      * </ul>
654      */
655     public void _setSelection() {
656         requiredMethod("getCharacterCount()");
657 
658         boolean res = true;
659         boolean locRes = true;
660 
661         if (editOnly != null) {
662             log.println(editOnly);
663             throw new StatusException(Status.skipped(true));
664         }
665 
666         try {
667             log.print("setSelection(-1, chCount-1):");
668             locRes = oObj.setSelection(-1, chCount - 1);
669             log.println(locRes + " excepion was expected");
670             res &= !locRes;
671         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
672             log.println("Expected exception");
673             res &= true;
674         }
675 
676         try {
677             log.print("setSelection(0, chCount+1):");
678             locRes = oObj.setSelection(0, chCount + 1);
679             log.println(locRes + " excepion was expected");
680             res &= !locRes;
681         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
682             log.println("Expected exception");
683             res &= true;
684         }
685 
686         try {
687             if (chCount > 2) {
688                 log.print("setSelection(1, chCount-1):");
689                 locRes = oObj.setSelection(1, chCount - 1);
690                 log.println(locRes);
691                 res &= locRes;
692 
693                 log.print("setSelection(chCount-1, 1):");
694                 locRes = oObj.setSelection(chCount - 1, 1);
695                 log.println(locRes);
696                 res &= locRes;
697             }
698 
699             log.print("setSelection(0, chCount-1):");
700             locRes = oObj.setSelection(0, chCount - 1);
701             log.println(locRes);
702             res &= locRes;
703 
704             log.print("setSelection(chCount-1, 0):");
705             locRes = oObj.setSelection(chCount - 1, 0);
706             log.println(locRes);
707             res &= locRes;
708 
709             log.print("setSelection(0, 0):");
710             locRes = oObj.setSelection(0, 0);
711             log.println(locRes);
712             res &= locRes;
713         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
714             log.println("Unexpected exception");
715             e.printStackTrace(log);
716             res &= false;
717         }
718 
719         tRes.tested("setSelection()", res);
720     }
721 
722     /**
723      * Calls the method and checks returned value.
724      * Has OK status if returned string is equal to string
725      * received from relation.
726      */
727     public void _getText() {
728         String txt = oObj.getText();
729         log.println("getText: " + txt);
730 
731         boolean res = txt.equals(text);
732         tRes.tested("getText()", res);
733     }
734 
735     /**
736      * Calls the method with invalid parameters an with valid parameters,
737      * checks returned values.
738      * Has OK status if exception was thrown for invalid parameters,
739      * if exception wasn't thrown for valid parameters and if returned values
740      * are equal to corresponding substrings of the text received by relation.
741      * The following method tests are to be executed before:
742      * <ul>
743      *  <li> <code>getCharacterCount()</code> </li>
744      * </ul>
745      */
746     public void _getTextRange() {
747         requiredMethod("getCharacterCount()");
748 
749         boolean res = true;
750         boolean locRes = true;
751 
752 		String txtRange = "";
753 
754         try {
755             if (chCount > 3) {
756                 log.print("getTextRange(1, chCount - 2): ");
757 
758                 txtRange = oObj.getTextRange(1, chCount - 2);
759                 log.println(txtRange);
760                 locRes = txtRange.equals(text.substring(1, chCount - 2));
761                 res &= locRes;
762 
763                 if (!locRes) {
764                     log.println("Was expected: " +
765                                 text.substring(1, chCount - 2));
766                 }
767             }
768 
769             log.print("getTextRange(0, chCount-1): ");
770 
771             txtRange = oObj.getTextRange(0, chCount - 1);
772             log.println(txtRange);
773             locRes = txtRange.equals(text.substring(0, chCount - 1));
774             res &= locRes;
775 
776             if (!locRes) {
777                 log.println("Was expected: " +
778                             text.substring(0, chCount - 1));
779             }
780 
781             log.print("getTextRange(chCount, 0): ");
782             txtRange = oObj.getTextRange(chCount, 0);
783             log.println(txtRange);
784             res &= txtRange.equals(text);
785 
786             log.print("getTextRange(0, 0): ");
787             txtRange = oObj.getTextRange(0, 0);
788             log.println(txtRange);
789             locRes = txtRange.equals("");
790             res &= locRes;
791 
792             if (!locRes) {
793                 log.println("Empty string was expected");
794             }
795         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
796             log.println("Unexpected exception");
797             e.printStackTrace(log);
798             res &= false;
799         }
800 
801         try {
802             log.print("getTextRange(-1, chCount - 1): ");
803 
804             txtRange = oObj.getTextRange(-1, chCount - 1);
805             log.println("Exception was expected");
806             res &= false;
807         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
808             log.println("Expected exception");
809             res &= true;
810         }
811 
812         try {
813             log.print("getTextRange(0, chCount + 1): ");
814 
815             txtRange = oObj.getTextRange(0, chCount + 1);
816             log.println("Exception was expected");
817             res &= false;
818         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
819             log.println("Expected exception");
820             res &= true;
821         }
822 
823         try {
824             log.print("getTextRange(chCount+1, -1): ");
825 
826             txtRange = oObj.getTextRange(chCount + 1, -1);
827             log.println("Exception was expected");
828             res &= false;
829         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
830             log.println("Expected exception");
831             res &= true;
832         }
833 
834         tRes.tested("getTextRange()", res);
835     }
836 
837     /**
838      * Calls the method with invalid parameters an with valid parameters,
839      * checks returned values.
840      * Has OK status if exception was thrown for invalid parameters,
841      * if exception wasn't thrown for valid parameters and if returned values
842      * are equal to corresponding substrings of the text received by relation.
843      * The following method tests are to be executed before:
844      * <ul>
845      *  <li> <code>getCharacterCount()</code> </li>
846      * </ul>
847      */
848     public void _getTextAtIndex() {
849         requiredMethod("getCharacterCount()");
850 		TextSegment txt = null;
851         boolean res = true;
852 
853         try {
854             log.print("getTextAtIndex(-1, AccessibleTextType.PARAGRAPH):");
855 
856             txt = oObj.getTextAtIndex(-1,
857                                                   AccessibleTextType.PARAGRAPH);
858             log.println("Exception was expected");
859             res &= false;
860         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
861             log.println("Expected exception");
862             res &= true;
863         } catch (com.sun.star.lang.IllegalArgumentException e) {
864             log.println("UnExpected exception");
865             res &= false;
866         }
867 
868         try {
869             log.print("getTextAtIndex(chCount+1," +
870                       " AccessibleTextType.PARAGRAPH):");
871 
872             txt = oObj.getTextAtIndex(chCount + 1,
873                                                   AccessibleTextType.PARAGRAPH);
874             log.println("Exception was expected");
875             res &= false;
876         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
877             log.println("Expected exception");
878             res &= true;
879         } catch (com.sun.star.lang.IllegalArgumentException e) {
880             log.println("UnExpected exception");
881             res &= false;
882         }
883 
884         try {
885             log.print("getTextAtIndex(chCount," +
886                       " AccessibleTextType.WORD):");
887 
888             txt = oObj.getTextAtIndex(chCount, AccessibleTextType.WORD);
889             log.println("'" + txt.SegmentText + "'");
890             res &= compareLength(0,txt.SegmentText);
891             if (!tEnv.getTestCase().getObjectName().equals("SmGraphicAccessible")) {
892                 log.print("getTextAtIndex(1," +
893                           " AccessibleTextType.PARAGRAPH):");
894                 txt = oObj.getTextAtIndex(1, AccessibleTextType.PARAGRAPH);
895                 log.println("'" + txt.SegmentText + "'");
896                 res &= compareStrings(text,txt.SegmentText);
897             }
898         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
899             log.println("Unexpected exception");
900             e.printStackTrace(log);
901             res &= false;
902         } catch (com.sun.star.lang.IllegalArgumentException e) {
903             log.println("Unexpected exception");
904             e.printStackTrace(log);
905             res &= false;
906         }
907 
908         tRes.tested("getTextAtIndex()", res);
909     }
910 
911     /**
912      * Calls the method with invalid parameters an with valid parameters,
913      * checks returned values.
914      * Has OK status if exception was thrown for invalid parameters,
915      * if exception wasn't thrown for valid parameters and if returned values
916      * are equal to corresponding substrings of the text received by relation.
917      * The following method tests are to be executed before:
918      * <ul>
919      *  <li> <code>getCharacterCount()</code> </li>
920      * </ul>
921      */
922     public void _getTextBeforeIndex() {
923         requiredMethod("getCharacterCount()");
924 		TextSegment txt = null;
925         boolean res = true;
926 
927         try {
928             log.print("getTextBeforeIndex(-1, AccessibleTextType.PARAGRAPH):");
929 
930             txt = oObj.getTextBeforeIndex(-1,
931                                                       AccessibleTextType.PARAGRAPH);
932             log.println("Exception was expected");
933             res &= false;
934         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
935             log.println("Expected exception");
936             res &= true;
937         } catch (com.sun.star.lang.IllegalArgumentException e) {
938             log.println("UnExpected exception");
939             res &= false;
940         }
941 
942         try {
943             log.print("getTextBeforeIndex(chCount+1, " +
944                       "AccessibleTextType.PARAGRAPH):");
945 
946             txt = oObj.getTextBeforeIndex(chCount + 1,
947                                                       AccessibleTextType.PARAGRAPH);
948             log.println("Exception was expected");
949             res &= false;
950         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
951             log.println("Expected exception");
952             res &= true;
953         } catch (com.sun.star.lang.IllegalArgumentException e) {
954             log.println("UnExpected exception");
955             res &= true;
956         }
957 
958         try {
959             if (!tEnv.getTestCase().getObjectName().equals("SmGraphicAccessible")) {
960                 log.print("getTextBeforeIndex(chCount," +
961                           " AccessibleTextType.WORD):");
962 
963                 txt = oObj.getTextBeforeIndex(chCount,
964                                                      AccessibleTextType.WORD);
965                 log.println("'" + txt.SegmentText + "'");
966                 res &= compareLength(chCount, txt.SegmentText);
967             }
968 
969             log.print("getTextBeforeIndex(1," +
970                       " AccessibleTextType.PARAGRAPH):");
971             txt = oObj.getTextBeforeIndex(1, AccessibleTextType.PARAGRAPH);
972             log.println("'" + txt.SegmentText + "'");
973             res &= compareLength(0, txt.SegmentText);
974 
975             log.print("getTextBeforeIndex(chCount-1," +
976                       " AccessibleTextType.CHARACTER):");
977             txt = oObj.getTextBeforeIndex(chCount - 1,
978                                           AccessibleTextType.CHARACTER);
979             log.println("'" + txt.SegmentText + "'");
980             res &= compareStrings(text.substring(chCount - 2, chCount - 1),
981                                   txt.SegmentText);
982 
983             if (chCount > 2) {
984                 log.print("getTextBeforeIndex(2," +
985                           " AccessibleTextType.CHARACTER):");
986                 txt = oObj.getTextBeforeIndex(2, AccessibleTextType.CHARACTER);
987                 log.println("'" + txt.SegmentText + "'");
988                 res &= compareStrings(text.substring(1, 2), txt.SegmentText);
989             }
990         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
991             log.println("Unexpected exception");
992             e.printStackTrace(log);
993             res &= false;
994         } catch (com.sun.star.lang.IllegalArgumentException e) {
995             log.println("Unexpected exception");
996             e.printStackTrace(log);
997             res &= false;
998         }
999 
1000         tRes.tested("getTextBeforeIndex()", res);
1001     }
1002 
1003     /**
1004      * Calls the method with invalid parameters an with valid parameters,
1005      * checks returned values.
1006      * Has OK status if exception was thrown for invalid parameters,
1007      * if exception wasn't thrown for valid parameters and if returned values
1008      * are equal to corresponding substrings of the text received by relation.
1009      * The following method tests are to be executed before:
1010      * <ul>
1011      *  <li> <code>getCharacterCount()</code> </li>
1012      * </ul>
1013      */
1014     public void _getTextBehindIndex() {
1015         requiredMethod("getCharacterCount()");
1016 		TextSegment txt = null;
1017         boolean res = true;
1018 
1019         try {
1020             log.print("getTextBehindIndex(-1, AccessibleTextType.PARAGRAPH):");
1021 
1022             txt = oObj.getTextBehindIndex(-1,
1023                                                       AccessibleTextType.PARAGRAPH);
1024             log.println("Exception was expected");
1025             res &= false;
1026         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
1027             log.println("Expected exception");
1028             res &= true;
1029         } catch (com.sun.star.lang.IllegalArgumentException e) {
1030             log.println("UnExpected exception");
1031             res &= true;
1032         }
1033 
1034         try {
1035             log.print("getTextBehindIndex(chCount+1, " +
1036                       "AccessibleTextType.PARAGRAPH):");
1037 
1038             txt = oObj.getTextBehindIndex(chCount + 1,
1039                                                       AccessibleTextType.PARAGRAPH);
1040             log.println("Exception was expected");
1041             res &= false;
1042         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
1043             log.println("Expected exception");
1044             res &= true;
1045         } catch (com.sun.star.lang.IllegalArgumentException e) {
1046             log.println("UnExpected exception");
1047             res &= true;
1048         }
1049 
1050         try {
1051             log.print("getTextBehindIndex(chCount," +
1052                       " AccessibleTextType.PARAGRAPH):");
1053 
1054             txt = oObj.getTextBehindIndex(chCount,
1055                                                  AccessibleTextType.PARAGRAPH);
1056             log.println("'" + txt.SegmentText + "'");
1057             res &= (txt.SegmentText.length() == 0);
1058 
1059             log.print("getTextBehindIndex(chCount-1," +
1060                       " AccessibleTextType.PARAGRAPH):");
1061             txt = oObj.getTextBehindIndex(chCount - 1,
1062                                           AccessibleTextType.PARAGRAPH);
1063             log.println("'" + txt.SegmentText + "'");
1064             res &= (txt.SegmentText.length() == 0);
1065 
1066             log.print("getTextBehindIndex(1," +
1067                       " AccessibleTextType.CHARACTER):");
1068             txt = oObj.getTextBehindIndex(1, AccessibleTextType.CHARACTER);
1069             log.println("'" + txt.SegmentText + "'");
1070             res &= txt.SegmentText.equals(text.substring(2, 3));
1071 
1072             if (chCount > 2) {
1073                 log.print("getTextBehindIndex(chCount-2," +
1074                           " AccessibleTextType.CHARACTER):");
1075                 txt = oObj.getTextBehindIndex(chCount - 2,
1076                                               AccessibleTextType.CHARACTER);
1077                 log.println("'" + txt.SegmentText + "'");
1078                 res &= txt.SegmentText.equals(text.substring(chCount - 1, chCount));
1079             }
1080         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
1081             log.println("Unexpected exception");
1082             e.printStackTrace(log);
1083             res &= false;
1084         } catch (com.sun.star.lang.IllegalArgumentException e) {
1085             log.println("Unexpected exception");
1086             e.printStackTrace(log);
1087             res &= false;
1088         }
1089 
1090         tRes.tested("getTextBehindIndex()", res);
1091     }
1092 
1093     /**
1094      * Calls the method with invalid parameters an with valid parameter,
1095      * checks returned values.
1096      * Has OK status if exception was thrown for invalid parameters,
1097      * if exception wasn't thrown for valid parameter and if returned value for
1098      * valid parameter is equal to <code>true</code>.
1099      */
1100     public void _copyText() {
1101         boolean res = true;
1102         boolean locRes = true;
1103 
1104         if (editOnly != null) {
1105             log.println(editOnly);
1106             throw new StatusException(Status.skipped(true));
1107         }
1108 
1109         try {
1110             log.print("copyText(-1,chCount):");
1111             oObj.copyText(-1, chCount);
1112             log.println("Exception was expected");
1113             res &= false;
1114         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
1115             log.println("Expected exception");
1116             res &= true;
1117         }
1118 
1119         try {
1120             log.print("copyText(0,chCount+1):");
1121             oObj.copyText(0, chCount + 1);
1122             log.println("Exception was expected");
1123             res &= false;
1124         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
1125             log.println("Expected exception");
1126             res &= true;
1127         }
1128 
1129         try {
1130             log.print("copyText(0,chCount):");
1131             locRes = oObj.copyText(0, chCount);
1132             log.println(locRes);
1133             res &= locRes;
1134 
1135             String cbText = null;
1136 
1137             try {
1138                 cbText = util.SysUtils.getSysClipboardText((XMultiServiceFactory)tParam.getMSF());
1139             } catch (com.sun.star.uno.Exception e) {
1140                 log.println("Couldn't access system clipboard :");
1141                 e.printStackTrace(log);
1142             }
1143 
1144             log.println("Clipboard: '" + cbText + "'");
1145             res &= text.equals(cbText);
1146 
1147             if (chCount > 2) {
1148                 log.print("copyText(1,chCount-1):");
1149                 locRes = oObj.copyText(1, chCount - 1);
1150                 log.println(locRes);
1151                 res &= locRes;
1152 
1153                 try {
1154                     cbText = util.SysUtils.getSysClipboardText((XMultiServiceFactory)tParam.getMSF());
1155                 } catch (com.sun.star.uno.Exception e) {
1156                     log.println("Couldn't access system clipboard :");
1157                     e.printStackTrace(log);
1158                 }
1159 
1160                 log.println("Clipboard: '" + cbText + "'");
1161                 res &= text.substring(1, chCount - 1).equals(cbText);
1162             }
1163         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
1164             log.println("Unexpected exception");
1165             e.printStackTrace(log);
1166             res &= false;
1167         }
1168 
1169         tRes.tested("copyText()", res);
1170     }
1171 
1172     public boolean compareStrings(String expected, String getting) {
1173         boolean res = expected.equals(getting);
1174 
1175         if (!res) {
1176             log.println("## The result isn't the expected:");
1177             log.println("\tGetting: " + getting);
1178             log.println("\tExpected: " + expected);
1179         }
1180 
1181         return res;
1182     }
1183 
1184     public boolean compareLength(int expected, String getting) {
1185         boolean res = (expected == getting.length());
1186 
1187         if (!res) {
1188             log.println("## The result isn't the expected:");
1189             log.println("\tGetting: " + getting.length());
1190             log.println("\tExpected: " + expected);
1191         }
1192 
1193         return res;
1194     }
1195 }