1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XAccessibleEditableText.java,v $
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 ************************************************************************/
31 package ifc
.accessibility
;
33 import lib
.MultiMethodTest
;
34 import util
.ValueComparer
;
36 import com
.sun
.star
.accessibility
.XAccessibleEditableText
;
37 import com
.sun
.star
.beans
.PropertyValue
;
40 * Testing <code>com.sun.star.accessibility.XAccessibleEditableText</code>
43 * <li><code> cutText()</code></li>
44 * <li><code> pasteText()</code></li>
45 * <li><code> deleteText()</code></li>
46 * <li><code> insertText()</code></li>
47 * <li><code> replaceText()</code></li>
48 * <li><code> setAttributes()</code></li>
49 * <li><code> setText()</code></li>
52 * This test needs the following object relations :
54 * <li> <code>'XAccessibleEditableText.hasAttr'</code>
55 * (of type <code>Boolean</code>):
56 * Indicates whether or not the text has changeable attributes.
57 * E.g. text within writer document have attributes which can
58 * be changed, while the text within edit field has fixed
60 * If the relation is <code>false</code> then the component
61 * has fixed text attributes. </li>
64 * @see com.sun.star.accessibility.XAccessibleEditableText
66 public class _XAccessibleEditableText
extends MultiMethodTest
{
68 public XAccessibleEditableText oObj
= null;
71 String pasteText
= null;
73 String initialText
= "";
76 * Indicates whether or not the text has changeable attributes.
77 * E.g. text within writer document have attributes which can
78 * be changed, while the text within edit field has fixed
81 private boolean changeableAttr
= true;
84 * Retrieves object relation. Stores initial component text
85 * for restoding it in <code>after</code>.
87 protected void before() {
89 tEnv
.getObjRelation("XAccessibleEditableText.hasAttr");
91 changeableAttr
= b
.booleanValue();
94 initialText
= oObj
.getText();
98 * Calls the method with the wrong indexes and with the correct indexes.
99 * Stores cutted text in the variable <code>pasteText</code>.
100 * Has OK status if exceptions were thrown for the wrong indexes,
101 * if exception wasn't thrown for the correct indexes.
103 public void _cutText() {
105 boolean locRes
= true;
106 String curText
= null;
108 String oldText
= oObj
.getText();
109 log
.println("Text: '" + oldText
+ "'");
110 int length
= oObj
.getCharacterCount();
111 log
.println("Character count: " + length
);
114 log
.print("cutText(-1," + (length
-1) + "): ");
115 locRes
= oObj
.cutText(-1, length
- 1);
117 log
.println("exception was expected => FAILED");
119 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
120 log
.println("expected exception => OK");
121 curText
= oObj
.getText();
122 log
.println("Current text: '" + curText
+ "'");
123 res
&= curText
.equals(oldText
);
127 log
.print("cutText(0," + (length
+1) + "): ");
128 locRes
= oObj
.cutText(0, length
+ 1);
130 log
.println("exception was expected => FAILED");
132 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
133 log
.println("expected exception => OK");
134 curText
= oObj
.getText();
135 log
.println("Current text: '" + curText
+ "'");
136 res
&= curText
.equals(oldText
);
141 log
.print("cutText(0," + length
+ "): ");
142 locRes
= oObj
.cutText(0, length
);
144 curText
= oObj
.getText();
145 log
.println("Current text: '" + curText
+ "'");
146 res
&= curText
.length() == 0 && locRes
;
147 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
148 log
.println("unexpected exception");
149 e
.printStackTrace(log
);
153 tRes
.tested("cutText()", res
);
157 * Calls the method with the wrong indexes and with the correct indexes.
158 * Has OK status if exceptions were thrown for the wrong indexes,
159 * if exception wasn't thrown for the correct indexes and if cutted text was
161 * The following method tests are to be executed before:
163 * <li> <code>cutText()</code> </li>
166 public void _pasteText() {
167 requiredMethod("cutText()");
169 boolean locRes
= true;
170 String curText
= null;
172 String text
= oObj
.getText();
173 log
.println("Text: '" + text
+ "'");
174 int length
= oObj
.getCharacterCount();
175 log
.println("Character count: " + length
);
178 log
.print("pasteText(-1): ");
179 locRes
= oObj
.pasteText(-1);
181 log
.println("exception was expected => FAILED");
183 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
184 log
.println("expected exception => OK");
185 curText
= oObj
.getText();
186 log
.println("Current text: '" + curText
+ "'");
187 res
&= curText
.equals(text
);
191 log
.print("pasteText(" + (length
+1) + "): ");
192 locRes
= oObj
.pasteText(length
+ 1);
194 log
.println("exception was expected => FAILED");
196 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
197 log
.println("expected exception => OK");
198 curText
= oObj
.getText();
199 log
.println("Current text: '" + curText
+ "'");
200 res
&= curText
.equals(text
);
204 log
.print("pasteText(" + (length
) + "): ");
205 locRes
= oObj
.pasteText(length
);
207 curText
= oObj
.getText();
208 log
.println("Current text: '" + curText
+ "'");
209 res
&= curText
.equals(text
+ pasteText
) && locRes
;
210 log
.println("Expected text: '" + text
+ pasteText
+ "'");
211 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
212 log
.println("unexpected exception");
213 e
.printStackTrace(log
);
217 tRes
.tested("pasteText()", res
);
221 * Calls the method with the wrong indexes and with the correct indexes,
222 * checks text after method call.
223 * Has OK status if exceptions were thrown for the wrong indexes,
224 * if exception wasn't thrown for the correct indexes and if deleted string
225 * was really deleted from the text.
226 * The following method tests are to be executed before:
228 * <li> <code>insertText()</code> </li>
231 public void _deleteText() {
232 executeMethod("insertText()");
234 boolean locRes
= true;
235 String curText
= null;
237 String text
= oObj
.getText();
238 log
.println("Text: '" + text
+ "'");
239 int length
= oObj
.getCharacterCount();
240 log
.println("Character count: " + length
);
243 log
.print("deleteText(-1," + length
+ "): ");
244 locRes
= oObj
.deleteText(-1, length
);
246 log
.println("exception was expected => FAILED");
248 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
249 log
.println("expected exception => OK");
250 curText
= oObj
.getText();
251 log
.println("Current text: '" + curText
+ "'");
252 res
&= curText
.equals(text
);
256 log
.print("deleteText(0," + (length
+1) + "): ");
257 locRes
= oObj
.deleteText(0, length
+ 1);
259 log
.println("exception was expected => FAILED");
261 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
262 log
.println("expected exception => OK");
263 curText
= oObj
.getText();
264 log
.println("Current text: '" + curText
+ "'");
265 res
&= curText
.equals(text
);
270 log
.print("deleteText(" + (length
-1) + "," + (length
) + "): ");
271 locRes
= oObj
.deleteText(length
- 1, length
);
273 String expStr
= expStr
= text
.substring(0, length
- 1);
274 curText
= oObj
.getText();
275 log
.println("Current text: '" + curText
+ "'");
276 res
&= curText
.equals(expStr
);
277 log
.println("Expected text: '" + expStr
+ "'");
279 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
280 log
.println("unexpected exception");
281 e
.printStackTrace(log
);
285 tRes
.tested("deleteText()", res
);
289 * Calls the method with the wrong indexes and with the correct indexes,
290 * checks text after method call.
291 * Has OK status if exceptions were thrown for the wrong indexes,
292 * if exception wasn't thrown for the correct indexes and if inserted string
293 * was really inserted into the text.
294 * The following method tests are to be executed before:
296 * <li> <code>pasteText()</code> </li>
299 public void _insertText() {
300 executeMethod("pasteText()");
302 boolean locRes
= true;
303 String curText
= null;
305 String text
= oObj
.getText();
306 log
.println("Text: '" + text
+ "'");
307 int length
= oObj
.getCharacterCount();
308 log
.println("Character count: " + length
);
310 final String insStr
= "Inserted string";
313 log
.print("insertText(insStr, -1): ");
314 locRes
= oObj
.insertText(insStr
, -1);
316 log
.println("exception was expected=> FAILED");
318 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
319 log
.println("expected exception => OK");
320 curText
= oObj
.getText();
321 log
.println("Current text: '" + curText
+ "'");
322 res
&= curText
.equals(text
);
326 log
.print("insertText(insStr," + (length
+1) + "): ");
327 locRes
= oObj
.insertText(insStr
, length
+1);
329 log
.println("exception was expected => FAILED");
331 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
332 log
.println("expected exception => OK");
333 curText
= oObj
.getText();
334 log
.println("Current text: '" + curText
+ "'");
335 res
&= curText
.equals(text
);
339 log
.print("insertText(insStr," + length
+ "): ");
340 locRes
= oObj
.insertText(insStr
, length
);
342 curText
= oObj
.getText();
343 res
&= curText
.equals(text
+ insStr
);
344 log
.println("Current text: '" + curText
+ "'");
345 log
.println("Expected text: '" + text
+ insStr
+ "'");
346 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
347 log
.println("unexpected exception => FAILED");
348 e
.printStackTrace(log
);
352 tRes
.tested("insertText()", res
);
356 * Calls the method with the wrong indexes and with the correct indexes,
357 * checks text after method call.
358 * Has OK status if exceptions were thrown for the wrong indexes,
359 * if exception wasn't thrown for the correct indexes and if part of text
360 * was really replaced by the specified replacement string.
361 * The following method tests are to be executed before:
363 * <li> <code>deleteText()</code> </li>
366 public void _replaceText() {
367 executeMethod("deleteText()");
369 boolean locRes
= true;
370 String curText
= null;
372 final String sReplacement
= "String for replace";
373 String oldText
= oObj
.getText();
374 int startIndx
= oldText
.length();
375 oObj
.setText(oldText
+ " part of string for replace");
377 String text
= oObj
.getText();
378 log
.println("Text: '" + text
+ "'");
379 int length
= oObj
.getCharacterCount();
380 log
.println("Character count: " + length
);
383 log
.print("replaceText(-1," + length
+ "): ");
384 locRes
= oObj
.replaceText(-1, length
, sReplacement
);
386 log
.println("exception was expected => FAILED");
388 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
389 log
.println("expected exception => OK");
390 curText
= oObj
.getText();
391 log
.println("Current text: '" + curText
+ "'");
392 res
&= curText
.equals(text
);
396 log
.print("replaceText(0," + (length
+1) + "): ");
397 locRes
= oObj
.replaceText(0, length
+ 1, sReplacement
);
399 log
.println("exception was expected => FAILED");
401 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
402 log
.println("expected exception => OK");
403 curText
= oObj
.getText();
404 log
.println("Current text: '" + curText
+ "'");
405 res
&= curText
.equals(text
);
409 log
.print("replaceText(" + startIndx
+ "," + length
+ "): ");
410 locRes
= oObj
.replaceText(startIndx
, length
, sReplacement
);
412 curText
= oObj
.getText();
413 log
.println("Current text: '" + curText
+ "'");
414 log
.println("Expected text: '" + oldText
+ sReplacement
+ "'");
415 res
&= curText
.equals(oldText
+ sReplacement
);
416 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
417 log
.println("unexpected exception");
418 e
.printStackTrace(log
);
422 tRes
.tested("replaceText()", res
);
426 * Calls the method with the wrong indexes and with the correct indexes,
427 * checks attributes after method call.
428 * Has OK status if exceptions were thrown for the wrong indexes,
429 * if exception wasn't thrown for the correct indexes and if attributes
430 * of text was changed.
431 * The following method tests are to be executed before:
433 * <li> <code>replaceText()</code> </li>
436 public void _setAttributes() {
437 executeMethod("replaceText()");
439 boolean locRes
= true;
441 String text
= oObj
.getText();
442 log
.println("Text: '" + text
+ "'");
443 int length
= oObj
.getCharacterCount();
444 log
.println("Length: " + length
);
446 PropertyValue
[] attrs
= null;
449 attrs
= oObj
.getCharacterAttributes(0, new String
[]{""});
450 log
.print("setAttributes(-1," + (length
- 1) + "):");
451 locRes
= oObj
.setAttributes(-1, length
- 1, attrs
);
453 log
.println("exception was expected => FAILED");
455 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
456 log
.println("expected exception => OK");
461 log
.print("setAttributes(0," + (length
+1) + "):");
462 locRes
= oObj
.setAttributes(0, length
+ 1, attrs
);
464 log
.println("exception was expected => FAILED");
466 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
467 log
.println("expected exception => OK");
471 //change old attributes set
472 for(int i
= 0; i
< attrs
.length
; i
++) {
473 if (attrs
[i
].Name
.equals("CharColor")) {
474 attrs
[i
].Value
= new Integer(-2);
479 log
.print("setAttributes(0," + length
+ "):");
480 locRes
= oObj
.setAttributes(0, length
, attrs
);
482 res
&= (changeableAttr
&& locRes
)
483 || (!changeableAttr
&& !locRes
);
484 if (changeableAttr
) {
485 log
.print("checking that new attributes was set...");
486 PropertyValue
[] newAttrs
= oObj
.getCharacterAttributes(0, new String
[]{""});
487 locRes
= ValueComparer
.equalValue(attrs
, newAttrs
);
491 log
.println("Text attributes can't be changed.");
493 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
494 log
.println("unexpected exception => FAILED");
495 e
.printStackTrace(log
);
499 tRes
.tested("setAttributes()", res
);
503 * Calls the method with different parameters and checks text.
505 public void _setText() {
506 executeMethod("setAttributes()");
508 boolean locRes
= true;
510 String oldText
= oObj
.getText();
511 log
.println("Current text: '" + oldText
+ "'");
513 String newText
= "New text";
514 log
.print("setText('" + newText
+ "'): ");
515 locRes
= oObj
.setText(newText
);
517 String newCurText
= oObj
.getText();
518 log
.println("getText(): '" + newCurText
+ "'");
519 res
&= locRes
&& newCurText
.equals(newText
);
522 log
.print("setText('" + newText
+ "'): ");
523 locRes
= oObj
.setText(newText
);
525 newCurText
= oObj
.getText();
526 log
.println("getText(): '" + newCurText
+ "'");
527 res
&= locRes
&& newCurText
.equals(newText
);
529 log
.print("setText('" + oldText
+ "'): ");
530 locRes
= oObj
.setText(oldText
);
532 newCurText
= oObj
.getText();
533 log
.println("getText(): '" + newCurText
+ "'");
534 res
&= locRes
&& newCurText
.equals(oldText
);
536 tRes
.tested("setText()", res
);
540 * Restores initial component text.
542 protected void after() {
543 oObj
.setText(initialText
);