1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package complex.toolkit.accessibility;
25 
26 import com.sun.star.accessibility.XAccessibleText;
27 // import lib.MultiMethodTest;
28 //import lib.StatusException;
29 //import lib.Status;
30 import com.sun.star.beans.PropertyValue;
31 import com.sun.star.awt.Rectangle;
32 import com.sun.star.awt.Point;
33 import com.sun.star.lang.XMultiServiceFactory;
34 import com.sun.star.accessibility.AccessibleTextType;
35 import com.sun.star.accessibility.TextSegment;
36 import com.sun.star.uno.XInterface;
37 import com.sun.star.uno.UnoRuntime;
38 // import share.LogWriter;
39 
40 /**
41  * Testing <code>com.sun.star.accessibility.XAccessibleText</code>
42  * interface methods :
43  * <ul>
44  *  <li><code> getCaretPosition()</code></li>
45  *  <li><code> setCaretPosition()</code></li>
46  *  <li><code> getCharacter()</code></li>
47  *  <li><code> getCharacterAttributes()</code></li>
48  *  <li><code> getCharacterBounds()</code></li>
49  *  <li><code> getCharacterCount()</code></li>
50  *  <li><code> getIndexAtPoint()</code></li>
51  *  <li><code> getSelectedText()</code></li>
52  *  <li><code> getSelectionStart()</code></li>
53  *  <li><code> getSelectionEnd()</code></li>
54  *  <li><code> setSelection()</code></li>
55  *  <li><code> getText()</code></li>
56  *  <li><code> getTextRange()</code></li>
57  *  <li><code> getTextAtIndex()</code></li>
58  *  <li><code> getTextBeforeIndex()</code></li>
59  *  <li><code> getTextBehindIndex()</code></li>
60  *  <li><code> copyText()</code></li>
61  * </ul> <p>
62  * This test needs the following object relations :
63  * <ul>
64  *  <li> <code>'XAccessibleText.Text'</code> (of type <code>String</code>)
65  *   <b> optional </b> :
66  *   the string presentation of component's text. If the relation
67  *   is not specified, then text from method <code>getText()</code>
68  *   is used.
69  *  </li>
70  *  </ul> <p>
71  * @see com.sun.star.accessibility.XAccessibleText
72  */
73 public class _XAccessibleText {
74 
75     // private LogWriter log;
76 
77     private static final String className =
78         "com.sun.star.accessibility.XAccessibleText" ;
79 
80     public XAccessibleText oObj = null;
81     private XMultiServiceFactory xMSF;
82 
83     Rectangle chBounds = null;
84     int chCount = 0;
85 
86     String text = null;
87     String editOnly = null;
88 
89 
_XAccessibleText(XInterface object, XMultiServiceFactory xMSF, String editOnly)90     public _XAccessibleText(XInterface object, XMultiServiceFactory xMSF, String editOnly) {
91         oObj = UnoRuntime.queryInterface(XAccessibleText.class, object);
92         this.xMSF = xMSF;
93         // this.log = log;
94         this.editOnly = editOnly;
95     }
96 
97 
98     /**
99      * Calls the method and checks returned value.
100      * Has OK status if returned value is equal to <code>chCount - 1</code>.
101      * The following method tests are to be executed before:
102      * <ul>
103      *  <li> <code>setCaretPosition()</code> </li>
104      * </ul>
105      * @return
106      */
_getCaretPosition()107     public boolean _getCaretPosition() {
108 
109         if (editOnly != null) {
110             System.out.println(editOnly);
111             return true;
112         }
113 
114         boolean res = true;
115         if ( chCount > 0 ) {
116             try {
117                 oObj.setCaretPosition(chCount - 1);
118             } catch (com.sun.star.lang.IndexOutOfBoundsException ie) {
119 
120             }
121             int carPos = oObj.getCaretPosition();
122             System.out.println("getCaretPosition: " + carPos);
123             res = carPos == (chCount - 1);
124         }
125         return res;
126     }
127 
128     /**
129      * Calls the method with the wrong index and with the correct index
130      * <code>chCount - 1</code>.
131      * Has OK status if exception was thrown for wrong index and
132      * if exception wasn't thrown for the correct index.
133      * The following method tests are to be executed before:
134      * <ul>
135      *  <li> <code>getCharacterCount()</code> </li>
136      * </ul>
137      * @return
138      */
_setCaretPosition()139     public boolean _setCaretPosition() {
140         boolean res = true;
141 
142         try {
143             System.out.println("setCaretPosition(-1):");
144             oObj.setCaretPosition(-1);
145             res &= false;
146             System.out.println("exception was expected");
147         } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
148             System.out.println("expected exception");
149             res &= true;
150         }
151 
152         try {
153             System.out.println("setCaretPosition(chCount+1):");
154             oObj.setCaretPosition(chCount+1);
155             res &= false;
156             System.out.println("exception was expected");
157         } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
158             System.out.println("expected exception");
159             res &= true;
160         }
161         if ( chCount > 0 ) {
162             try {
163                 System.out.println("setCaretPosition(chCount - 1)");
164                 oObj.setCaretPosition(chCount - 1);
165                 res &= true;
166             } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
167                 System.out.println("unexpected exception");
168                 e.printStackTrace();
169                 res &= false;
170             }
171         }
172 
173         return res;
174     }
175 
176     /**
177      * Calls the method with the wrong index and with the correct indexes.
178      * Checks every character in the text.
179      * Has OK status if exception was thrown for wrong index,
180      * if exception wasn't thrown for the correct index and
181      * if every character is equal to corresponding character in the text.
182      * The following method tests are to be executed before:
183      * <ul>
184      *  <li> <code>getCharacterCount()</code> </li>
185      * </ul>
186      * @return
187      */
_getCharacter()188     public boolean _getCharacter() {
189         boolean res = true;
190 
191         try {
192             System.out.println("getCharacter(-1)");
193             oObj.getCharacter(-1);
194             System.out.println("Exception was expected");
195             res = false;
196         } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
197             System.out.println("Expected exception");
198             res = true;
199         }
200 
201         try {
202             System.out.println("getCharacter(chCount)");
203             oObj.getCharacter(chCount);
204             System.out.println("Exception was expected");
205             res &= false;
206         } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
207             System.out.println("Expected exception");
208             res &= true;
209         }
210 
211         try {
212             System.out.println("Checking of every character in the text...");
213             boolean isEqCh = true;
214             for(int i = 0; i < chCount; i++) {
215                 char ch = oObj.getCharacter(i);
216                 isEqCh = ch == text.charAt(i);
217                 res &= isEqCh;
218                 if (!isEqCh) {
219                     System.out.println("At the position " + i +
220                         "was expected character: " + text.charAt(i));
221                     System.out.println("but was returned: " + ch);
222                     break;
223                 }
224             }
225         } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
226             System.out.println("Unexpected exception");
227             e.printStackTrace();
228             res &= false;
229         }
230 
231         return res;
232     }
233 
234     /**
235      * Calls the method with the wrong indexes and with the correct index,
236      * checks a returned value.
237      * Has OK status if exception was thrown for the wrong indexes,
238      * if exception wasn't thrown for the correct index and
239      * if returned value isn't <code>null</code>.
240      * The following method tests are to be executed before:
241      * <ul>
242      *  <li> <code>getCharacterCount()</code> </li>
243      * </ul>
244      * @return
245      */
_getCharacterAttributes()246     public boolean _getCharacterAttributes() {
247         boolean res = true;
248 
249         try {
250             System.out.println("getCharacterAttributes(-1)");
251             oObj.getCharacterAttributes(-1, new String[0]);
252             System.out.println("Exception was expected");
253             res &= false;
254         } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
255             System.out.println("Expected exception");
256             res &= true;
257         }
258 
259         try {
260             System.out.println("getCharacterAttributes(chCount)");
261             oObj.getCharacterAttributes(chCount, new String[0]);
262             System.out.println("Exception was expected");
263             res &= false;
264         } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
265             System.out.println("Expected exception");
266             res &= true;
267         }
268 
269         try {
270             if ( chCount > 0 ) {
271                 System.out.println("getCharacterAttributes(chCount-1)");
272                 PropertyValue[] props = oObj.getCharacterAttributes(chCount - 1, new String[0]);
273                 res &= props != null;
274             }
275         } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
276             System.out.println("Unexpected exception");
277             e.printStackTrace();
278             res &= false;
279         }
280 
281         return res;
282     }
283 
284 
285     /**
286      * Calls the method with the wrong indexes and with the correct index.
287      * checks and stores a returned value.
288      * Has OK status if exception was thrown for the wrong indexes,
289      * if exception wasn't thrown for the correct index and
290      * if returned value isn't <code>null</code>.
291      * The following method tests are to be executed before:
292      * <ul>
293      *  <li> <code>getCharacterCount()</code> </li>
294      * </ul>
295      * @return
296      */
_getCharacterBounds()297     public boolean _getCharacterBounds() {
298         boolean res = true;
299 
300         try {
301             System.out.println("getCharacterBounds(-1)");
302             oObj.getCharacterBounds(-1);
303             System.out.println("Exception was expected");
304             res &= false;
305         } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
306             System.out.println("Expected exception");
307             res &= true;
308         }
309 
310         try {
311             System.out.println("getCharacterBounds(chCount)");
312             oObj.getCharacterBounds(chCount);
313             System.out.println("Exception was expected");
314             res &= false;
315         } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
316             System.out.println("Expected exception");
317             res &= true;
318         }
319 
320         try {
321             if (chCount > 0) {
322                 System.out.println("getCharacterBounds(chCount-1)");
323             	chBounds = oObj.getCharacterBounds(chCount-1);
324             	res &= chBounds != null;
325             	System.out.println("rect: " + chBounds.X + ", " + chBounds.Y + ", " +
326                 	chBounds.Width + ", " + chBounds.Height);
327             }
328 
329         } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
330             System.out.println("Unexpected exception");
331             e.printStackTrace();
332             res &= false;
333         }
334 
335         return res;
336     }
337 
338 
339     /**
340      * Calls the method and stores a returned value to the variable
341      * <code>chCount</code>.
342      * Has OK status if a returned value is equal to the text length.
343      * @return
344      */
_getCharacterCount()345     public boolean _getCharacterCount() {
346         chCount = oObj.getCharacterCount();
347         System.out.println("Character count:" + chCount);
348         boolean res = chCount == text.length();
349         return res;
350     }
351 
352     /**
353      * Calls the method for an invalid point and for the point of rectangle
354      * returned by the method <code>getCharacterBounds()</code>.
355      * Has OK status if returned value is equal to <code>-1</code> for an
356      * invalid point and if returned value is equal to <code>chCount-1</code>
357      * for a valid point.
358      * The following method tests are to be executed before:
359      * <ul>
360      *  <li> <code>getCharacterBounds()</code> </li>
361      * </ul>
362      * @return
363      */
_getIndexAtPoint()364     public boolean _getIndexAtPoint() {
365 
366         boolean res = true;
367         System.out.println("getIndexAtPoint(-1, -1):");
368         Point pt = new Point(-1, -1);
369         int index = oObj.getIndexAtPoint(pt);
370         System.out.println(Integer.toString(index));
371         res &= index == -1;
372 
373         if (chBounds != null) {
374             pt = new Point(chBounds.X , chBounds.Y );
375         	System.out.println("getIndexAtPoint(" + pt.X + ", " + pt.Y + "):");
376         	index = oObj.getIndexAtPoint(pt);
377         	System.out.println(Integer.toString(index));
378         	res &= index == (chCount - 1);
379 		}
380 
381         return res;
382     }
383 
384     /**
385      * Checks a returned values after different calls of the method
386      * <code>setSelection()</code>.
387      * The following method tests are to be executed before:
388      * <ul>
389      *  <li> <code>setSelection()</code> </li>
390      * </ul>
391      * @return
392      */
_getSelectedText()393     public boolean _getSelectedText() {
394         if (editOnly != null) {
395             System.out.println(editOnly);
396             return true;
397         }
398 
399         boolean res = true;
400 
401         try {
402             System.out.println("setSelection(0, 0)");
403             oObj.setSelection(0, 0);
404             System.out.println("getSelectedText():");
405             String txt = oObj.getSelectedText();
406             System.out.println("'" + txt + "'");
407             res &= txt.length() == 0;
408 
409             System.out.println("setSelection(0, chCount)");
410             oObj.setSelection(0, chCount);
411             System.out.println("getSelectedText():");
412             txt = oObj.getSelectedText();
413             System.out.println("'" + txt + "'");
414             res &= txt.equals(text);
415 
416             if (chCount > 2) {
417                 System.out.println("setSelection(1, chCount-1)");
418                 oObj.setSelection(1, chCount - 1);
419                 System.out.println("getSelectedText():");
420                 txt = oObj.getSelectedText();
421                 System.out.println("'" + txt + "'");
422                 res &= txt.equals(text.substring(1, chCount - 1));
423             }
424         } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
425             System.out.println("Unexpected exception");
426             e.printStackTrace();
427             res &= false;
428         }
429 
430         return res;
431     }
432 
433     /**
434      * Checks a returned values after different calls of the method
435      * <code>setSelection()</code>.
436      * The following method tests are to be executed before:
437      * <ul>
438      *  <li> <code>setSelection()</code> </li>
439      * </ul>
440      * @return
441      */
_getSelectionStart()442     public boolean _getSelectionStart() {
443         if (editOnly != null) {
444             System.out.println(editOnly);
445             return true;
446         }
447 
448         boolean res = true;
449 
450         try {
451             System.out.println("setSelection(0, chCount)");
452             oObj.setSelection(0, chCount);
453             int start = oObj.getSelectionStart();
454             System.out.println("getSelectionStart():" + start);
455             res &= start == 0;
456 
457             if (chCount > 2) {
458                 System.out.println("setSelection(1, chCount-1)");
459                 oObj.setSelection(1, chCount - 1);
460                 start = oObj.getSelectionStart();
461                 System.out.println("getSelectionStart():" + start);
462                 res &= start == 1;
463             }
464         } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
465             System.out.println("Unexpected exception");
466             e.printStackTrace();
467             res &= false;
468         }
469 
470         return res;
471     }
472 
473     /**
474      * Checks a returned values after different calls of the method
475      * <code>setSelection()</code>.
476      * The following method tests are to be executed before:
477      * <ul>
478      *  <li> <code>setSelection()</code> </li>
479      * </ul>
480      * @return
481      */
_getSelectionEnd()482     public boolean _getSelectionEnd() {
483         if (editOnly != null) {
484             System.out.println(editOnly);
485             return true;
486         }
487 
488         boolean res = true;
489 
490         try {
491             System.out.println("setSelection(0, chCount)");
492             oObj.setSelection(0, chCount);
493             int end = oObj.getSelectionEnd();
494             System.out.println("getSelectionEnd():" + end);
495             res &= end == chCount;
496 
497             if (chCount > 2) {
498                 System.out.println("setSelection(1, chCount-1)");
499                 oObj.setSelection(1, chCount - 1);
500                 end = oObj.getSelectionEnd();
501                 System.out.println("getSelectionEnd():" + end);
502                 res &= end == chCount - 1;
503             }
504         } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
505             System.out.println("Unexpected exception");
506             e.printStackTrace();
507             res &= false;
508         }
509 
510         return res;
511     }
512 
513     /**
514      * Calls the method with invalid parameters an with valid parameters.
515      * Has OK status if exception was thrown for invalid parameters,
516      * if exception wasn't thrown for valid parameters.
517      * The following method tests are to be executed before:
518      * <ul>
519      *  <li> <code>getCharacterCount()</code> </li>
520      * </ul>
521      * @return
522      */
_setSelection()523     public boolean _setSelection() {
524         boolean res = true;
525         boolean locRes = true;
526 
527         if (editOnly != null) {
528             System.out.println(editOnly);
529             return true;
530         }
531 
532         try {
533             System.out.println("setSelection(-1, chCount-1):");
534             locRes = oObj.setSelection(-1, chCount - 1);
535             System.out.println(locRes + " exception was expected");
536             res &= !locRes;
537         } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
538             System.out.println("Expected exception");
539             res &= true;
540         }
541 
542         try {
543             System.out.println("setSelection(0, chCount+1):");
544             locRes = oObj.setSelection(0, chCount + 1);
545             System.out.println(locRes + " excepion was expected");
546             res &= !locRes;
547         } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
548             System.out.println("Expected exception");
549             res &= true;
550         }
551 
552         try {
553             if (chCount > 2) {
554                 System.out.println("setSelection(1, chCount-1):");
555                 locRes = oObj.setSelection(1, chCount - 1);
556                 System.out.println(Boolean.toString(locRes));
557                 res &= locRes;
558 
559                 System.out.println("setSelection(chCount-1, 1):");
560                 locRes = oObj.setSelection(chCount - 1, 1);
561                 System.out.println(Boolean.toString(locRes));
562                 res &= locRes;
563             }
564 
565             if (chCount > 1) {
566                 System.out.println("setSelection(0, chCount-1):");
567                 locRes = oObj.setSelection(0, chCount-1);
568                 System.out.println(Boolean.toString(locRes));
569                 res &= locRes;
570 
571                 System.out.println("setSelection(chCount-1, 0):");
572                 locRes = oObj.setSelection(chCount-1, 0);
573                 System.out.println(Boolean.toString(locRes));
574                 res &= locRes;
575             }
576 
577             System.out.println("setSelection(0, 0):");
578             locRes = oObj.setSelection(0, 0);
579             System.out.println(Boolean.toString(locRes));
580             res &= locRes;
581         } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
582             System.out.println("Unexpected exception");
583             e.printStackTrace();
584             res &= false;
585         }
586 
587         return res;
588     }
589 
590     /**
591      * Calls the method and checks returned value.
592      * Has OK status if returned string is not null
593      * received from relation.
594      * @return
595      */
_getText()596     public boolean _getText() {
597         text = oObj.getText();
598         System.out.println("getText: '" + text + "'");
599         return (text != null);
600     }
601 
602     /**
603      * Calls the method with invalid parameters an with valid parameters,
604      * checks returned values.
605      * Has OK status if exception was thrown for invalid parameters,
606      * if exception wasn't thrown for valid parameters and if returned values
607      * are equal to corresponding substrings of the text received by relation.
608      * The following method tests are to be executed before:
609      * <ul>
610      *  <li> <code>getCharacterCount()</code> </li>
611      * </ul>
612      * @return
613      */
_getTextRange()614     public boolean _getTextRange() {
615         boolean res = true;
616         boolean locRes = true;
617 
618         try {
619             if (chCount > 3) {
620                 System.out.println("getTextRange(1, chCount - 2): ");
621                 String txtRange = oObj.getTextRange(1, chCount - 2);
622                 System.out.println(txtRange);
623                 locRes = txtRange.equals(text.substring(1, chCount - 2));
624                 res &= locRes;
625                 if (!locRes) {
626                     System.out.println("Was expected: " +
627                         text.substring(1, chCount - 2));
628                 }
629             }
630 
631             if (chCount > 0) {
632                 System.out.println("getTextRange(0, chCount-1): ");
633                 String txtRange = oObj.getTextRange(0, chCount-1);
634                 System.out.println(txtRange);
635                 locRes = txtRange.equals(text.substring(0, chCount - 1));
636                 res &= locRes;
637                 if (!locRes) {
638                     System.out.println("Was expected: " +
639                         text.substring(0, chCount - 1));
640                 }
641 
642                 System.out.println("getTextRange(chCount, 0): ");
643                 txtRange = oObj.getTextRange(chCount, 0);
644                 System.out.println(txtRange);
645                 res &= txtRange.equals(text);
646 
647                 System.out.println("getTextRange(0, 0): ");
648                 txtRange = oObj.getTextRange(0, 0);
649                 System.out.println(txtRange);
650                 locRes = txtRange.equals("");
651                 res &= locRes;
652                 if (!locRes) {
653                     System.out.println("Empty string was expected");
654                 }
655             }
656         } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
657             System.out.println("Unexpected exception");
658             e.printStackTrace();
659             res &= false;
660         }
661 
662         try {
663             System.out.println("getTextRange(-1, chCount - 1): ");
664             String txtRange = oObj.getTextRange(-1, chCount - 1);
665             System.out.println("Exception was expected");
666             res &= false;
667         } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
668             System.out.println("Expected exception");
669             res &= true;
670         }
671 
672         try {
673             System.out.println("getTextRange(0, chCount + 1): ");
674             String txtRange = oObj.getTextRange(0, chCount + 1);
675             System.out.println("Exception was expected");
676             res &= false;
677         } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
678             System.out.println("Expected exception");
679             res &= true;
680         }
681 
682         try {
683             System.out.println("getTextRange(chCount+1, -1): ");
684             String txtRange = oObj.getTextRange(chCount+1, -1);
685             System.out.println("Exception was expected");
686             res &= false;
687         } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
688             System.out.println("Expected exception");
689             res &= true;
690         }
691 
692         return res;
693     }
694 
695     /**
696      * Calls the method with invalid parameters an with valid parameters,
697      * checks returned values.
698      * Has OK status if exception was thrown for invalid parameters,
699      * if exception wasn't thrown for valid parameters and if returned values
700      * are equal to corresponding substrings of the text received by relation.
701      * The following method tests are to be executed before:
702      * <ul>
703      *  <li> <code>getCharacterCount()</code> </li>
704      * </ul>
705      * @return
706      */
_getTextAtIndex()707     public boolean _getTextAtIndex() {
708         boolean res = true;
709 
710         try {
711             System.out.println("getTextAtIndex(-1, AccessibleTextType.PARAGRAPH):");
712             TextSegment txt =
713                 oObj.getTextAtIndex(-1, AccessibleTextType.PARAGRAPH);
714             System.out.println("Exception was expected");
715             res &= false;
716         } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
717             System.out.println("Expected exception");
718             res &= true;
719         } catch(com.sun.star.lang.IllegalArgumentException e) {
720             System.out.println("Expected exception");
721             res &= true;
722         }
723 
724         try {
725             System.out.println("getTextAtIndex(chCount+1," +
726                 " AccessibleTextType.PARAGRAPH):");
727             TextSegment txt = oObj.getTextAtIndex(chCount + 1,
728                  AccessibleTextType.PARAGRAPH);
729             System.out.println("Exception was expected");
730             res &= false;
731         } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
732             System.out.println("Expected exception");
733             res &= true;
734         }  catch(com.sun.star.lang.IllegalArgumentException e) {
735             System.out.println("Expected exception");
736             res &= true;
737         }
738 
739 
740         try {
741             if ( chCount > 0 ) {
742                 System.out.println("getTextAtIndex(chCount," +
743                     " AccessibleTextType.PARAGRAPH):");
744                 TextSegment txt = oObj.getTextAtIndex(chCount,
745                     AccessibleTextType.PARAGRAPH);
746                 System.out.println("'" + txt.SegmentText + "'");
747                 res &= txt.SegmentText.length() == 0;
748 
749                 System.out.println("getTextAtIndex(1," +
750                     " AccessibleTextType.PARAGRAPH):");
751                 txt = oObj.getTextAtIndex(1,
752                     AccessibleTextType.PARAGRAPH);
753                 System.out.println("'" + txt.SegmentText + "'");
754                 res &= txt.SegmentText.equals(text);
755             }
756         } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
757             System.out.println("Unexpected exception");
758             e.printStackTrace();
759             res &= false;
760         }  catch(com.sun.star.lang.IllegalArgumentException e) {
761             System.out.println("Unexpected exception");
762             res &= false;
763         }
764 
765 
766         return res;
767     }
768 
769     /**
770      * Calls the method with invalid parameters an with valid parameters,
771      * checks returned values.
772      * Has OK status if exception was thrown for invalid parameters,
773      * if exception wasn't thrown for valid parameters and if returned values
774      * are equal to corresponding substrings of the text received by relation.
775      * The following method tests are to be executed before:
776      * <ul>
777      *  <li> <code>getCharacterCount()</code> </li>
778      * </ul>
779      * @return
780      */
_getTextBeforeIndex()781     public boolean _getTextBeforeIndex() {
782         boolean res = true;
783 
784         try {
785             System.out.println("getTextBeforeIndex(-1, AccessibleTextType.PARAGRAPH):");
786             TextSegment txt = oObj.getTextBeforeIndex(-1,
787                 AccessibleTextType.PARAGRAPH);
788             System.out.println("Exception was expected");
789             res &= false;
790         } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
791             System.out.println("Expected exception");
792             res &= true;
793         }  catch(com.sun.star.lang.IllegalArgumentException e) {
794             System.out.println("Expected exception");
795             res &= true;
796         }
797 
798 
799         try {
800             System.out.println("getTextBeforeIndex(chCount+1, " +
801                 "AccessibleTextType.PARAGRAPH):");
802             TextSegment txt = oObj.getTextBeforeIndex(chCount + 1,
803                 AccessibleTextType.PARAGRAPH);
804             System.out.println("Exception was expected");
805             res &= false;
806         } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
807             System.out.println("Expected exception");
808             res &= true;
809         } catch(com.sun.star.lang.IllegalArgumentException e) {
810             System.out.println("Expected exception");
811             res &= true;
812         }
813 
814         TextSegment txt = null;
815         try {
816             if (chCount > 0) {
817                 System.out.println("getTextBeforeIndex(chCount," +
818                     " AccessibleTextType.PARAGRAPH):");
819                 txt = oObj.getTextBeforeIndex(chCount,
820                     AccessibleTextType.PARAGRAPH);
821                 System.out.println("'" + txt.SegmentText + "'");
822                 res &= txt.SegmentText.length() == chCount ;
823 
824                 System.out.println("getTextBeforeIndex(1," +
825                     " AccessibleTextType.PARAGRAPH):");
826                 txt = oObj.getTextBeforeIndex(1,
827                     AccessibleTextType.PARAGRAPH);
828                 System.out.println("'" + txt.SegmentText + "'");
829                 res &= txt.SegmentText.length() == 0;
830             }
831 
832             if (chCount > 2) {
833                 System.out.println("getTextBeforeIndex(chCount-1," +
834                     " AccessibleTextType.CHARACTER):");
835                 txt = oObj.getTextBeforeIndex(chCount - 1,
836                     AccessibleTextType.CHARACTER);
837                 System.out.println("'" + txt.SegmentText + "'");
838                 res &= txt.SegmentText.equals(text.substring(chCount - 2, chCount - 1));
839                 System.out.println("getTextBeforeIndex(2," +
840                     " AccessibleTextType.CHARACTER):");
841                 txt = oObj.getTextBeforeIndex(2,
842                      AccessibleTextType.CHARACTER);
843                 System.out.println("'" + txt.SegmentText + "'");
844                 res &= txt.SegmentText.equals(text.substring(1, 2));
845             }
846         } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
847             System.out.println("Unexpected exception");
848             e.printStackTrace();
849             res &= false;
850         }  catch(com.sun.star.lang.IllegalArgumentException e) {
851             System.out.println("Unexpected exception");
852             res &= false;
853         }
854 
855 
856         return res;
857     }
858 
859     /**
860      * Calls the method with invalid parameters an with valid parameters,
861      * checks returned values.
862      * Has OK status if exception was thrown for invalid parameters,
863      * if exception wasn't thrown for valid parameters and if returned values
864      * are equal to corresponding substrings of the text received by relation.
865      * The following method tests are to be executed before:
866      * <ul>
867      *  <li> <code>getCharacterCount()</code> </li>
868      * </ul>
869      * @return
870      */
_getTextBehindIndex()871     public boolean _getTextBehindIndex() {
872         boolean res = true;
873 
874         try {
875             System.out.println("getTextBehindIndex(-1, AccessibleTextType.PARAGRAPH):");
876             TextSegment txt = oObj.getTextBehindIndex(-1,
877                 AccessibleTextType.PARAGRAPH);
878             System.out.println("Exception was expected");
879             res &= false;
880         } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
881             System.out.println("Expected exception");
882             res &= true;
883         } catch(com.sun.star.lang.IllegalArgumentException e) {
884             System.out.println("Expected exception");
885             res &= true;
886         }
887 
888 
889         try {
890             System.out.println("getTextBehindIndex(chCount+1, " +
891                 "AccessibleTextType.PARAGRAPH):");
892             TextSegment txt = oObj.getTextBehindIndex(chCount + 1,
893                 AccessibleTextType.PARAGRAPH);
894             System.out.println("Exception was expected");
895             res &= false;
896         } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
897             System.out.println("Expected exception");
898             res &= true;
899         }  catch(com.sun.star.lang.IllegalArgumentException e) {
900             System.out.println("Expected exception");
901             res &= true;
902         }
903 
904 
905         try {
906             if ( chCount > 0 ) {
907                 System.out.println("getTextBehindIndex(chCount," +
908                     " AccessibleTextType.PARAGRAPH):");
909                 TextSegment txt = oObj.getTextBehindIndex(chCount,
910                     AccessibleTextType.PARAGRAPH);
911                 System.out.println("'" + txt.SegmentText + "'");
912                 res &= txt.SegmentText.length() == 0;
913 
914                 System.out.println("getTextBehindIndex(chCount-1," +
915                     " AccessibleTextType.PARAGRAPH):");
916                 txt = oObj.getTextBehindIndex(chCount - 1,
917                     AccessibleTextType.PARAGRAPH);
918                 System.out.println("'" + txt.SegmentText + "'");
919                 res &= txt.SegmentText.length() == 0;
920             }
921             if ( chCount > 1 ) {
922                 System.out.println("getTextBehindIndex(1," +
923                     " AccessibleTextType.CHARACTER):");
924                 TextSegment txt = oObj.getTextBehindIndex(1,
925                     AccessibleTextType.CHARACTER);
926                 System.out.println("'" + txt.SegmentText + "'");
927                 res &= txt.SegmentText.equals(text.substring(2, 3));
928             }
929             if (chCount > 2) {
930                 System.out.println("getTextBehindIndex(chCount-2," +
931                     " AccessibleTextType.CHARACTER):");
932                 TextSegment txt = oObj.getTextBehindIndex(chCount - 2,
933                      AccessibleTextType.CHARACTER);
934                 System.out.println("'" + txt.SegmentText + "'");
935                 res &= txt.SegmentText.equals(text.substring(chCount - 1, chCount));
936             }
937         } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
938             System.out.println("Unexpected exception");
939             e.printStackTrace();
940             res &= false;
941         }  catch(com.sun.star.lang.IllegalArgumentException e) {
942             System.out.println("Unexpected exception");
943             res &= false;
944         }
945 
946 
947         return res;
948     }
949 
950     /**
951      * Calls the method with invalid parameters an with valid parameter,
952      * checks returned values.
953      * Has OK status if exception was thrown for invalid parameters,
954      * if exception wasn't thrown for valid parameter and if returned value for
955      * valid parameter is equal to <code>true</code>.
956      * @return
957      */
_copyText()958     public boolean _copyText() {
959         boolean res = true;
960         boolean locRes = true;
961 
962         if (editOnly != null) {
963             System.out.println(editOnly);
964             return true;
965         }
966 
967         try {
968             System.out.println("copyText(-1,chCount):");
969             oObj.copyText(-1, chCount);
970             System.out.println("Exception was expected");
971             res &= false;
972         } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
973             System.out.println("Expected exception");
974             res &= true;
975         }
976 
977         try {
978             System.out.println("copyText(0,chCount+1):");
979             oObj.copyText(0, chCount + 1);
980             System.out.println("Exception was expected");
981             res &= false;
982         } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
983             System.out.println("Expected exception");
984             res &= true;
985         }
986 
987         try {
988             System.out.println("copyText(0,chCount):");
989             locRes = oObj.copyText(0, chCount);
990             System.out.println(""+locRes);
991             res &= locRes;
992 
993             String cbText = null;
994             try {
995                 cbText =
996                     util.SysUtils.getSysClipboardText(xMSF);
997             } catch (com.sun.star.uno.Exception e) {
998                 System.out.println("Couldn't access system clipboard :");
999                 e.printStackTrace();
1000             }
1001             System.out.println("Clipboard: '" + cbText + "'");
1002             res &= text.equals(cbText);
1003 
1004             if (chCount > 2) {
1005                 System.out.println("copyText(1,chCount-1):");
1006                 locRes = oObj.copyText(1, chCount - 1);
1007                 System.out.println(""+locRes);
1008                 res &= locRes;
1009 
1010                 try {
1011                     cbText = util.SysUtils.getSysClipboardText(xMSF);
1012                 } catch (com.sun.star.uno.Exception e) {
1013                     System.out.println("Couldn't access system clipboard :");
1014                     e.printStackTrace();
1015                 }
1016 
1017                 System.out.println("Clipboard: '" + cbText + "'");
1018                 res &= text.substring(1, chCount - 1).equals(cbText);
1019             }
1020 
1021         } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
1022             System.out.println("Unexpected exception");
1023             e.printStackTrace();
1024             res &= false;
1025         }
1026 
1027         return res;
1028     }
1029 }
1030