2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package ifc
.accessibility
;
21 import lib
.MultiMethodTest
;
22 import util
.ValueComparer
;
24 import com
.sun
.star
.accessibility
.XAccessibleEditableText
;
25 import com
.sun
.star
.beans
.PropertyValue
;
28 * Testing <code>com.sun.star.accessibility.XAccessibleEditableText</code>
31 * <li><code> cutText()</code></li>
32 * <li><code> pasteText()</code></li>
33 * <li><code> deleteText()</code></li>
34 * <li><code> insertText()</code></li>
35 * <li><code> replaceText()</code></li>
36 * <li><code> setAttributes()</code></li>
37 * <li><code> setText()</code></li>
40 * This test needs the following object relations :
42 * <li> <code>'XAccessibleEditableText.hasAttr'</code>
43 * (of type <code>Boolean</code>):
44 * Indicates whether or not the text has changeable attributes.
45 * E.g. text within writer document have attributes which can
46 * be changed, while the text within edit field has fixed
48 * If the relation is <code>false</code> then the component
49 * has fixed text attributes. </li>
52 * @see com.sun.star.accessibility.XAccessibleEditableText
54 public class _XAccessibleEditableText
extends MultiMethodTest
{
56 public XAccessibleEditableText oObj
= null;
59 String pasteText
= null;
61 String initialText
= "";
64 * Indicates whether or not the text has changeable attributes.
65 * E.g. text within writer document have attributes which can
66 * be changed, while the text within edit field has fixed
69 private boolean changeableAttr
= true;
72 * Retrieves object relation. Stores initial component text
73 * for restoding it in <code>after</code>.
75 protected void before() {
77 tEnv
.getObjRelation("XAccessibleEditableText.hasAttr");
79 changeableAttr
= b
.booleanValue();
82 initialText
= oObj
.getText();
86 * Calls the method with the wrong indexes and with the correct indexes.
87 * Stores cutted text in the variable <code>pasteText</code>.
88 * Has OK status if exceptions were thrown for the wrong indexes,
89 * if exception wasn't thrown for the correct indexes.
91 public void _cutText() {
93 boolean locRes
= true;
94 String curText
= null;
96 String oldText
= oObj
.getText();
97 log
.println("Text: '" + oldText
+ "'");
98 int length
= oObj
.getCharacterCount();
99 log
.println("Character count: " + length
);
102 log
.print("cutText(-1," + (length
-1) + "): ");
103 locRes
= oObj
.cutText(-1, length
- 1);
105 log
.println("exception was expected => FAILED");
107 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
108 log
.println("expected exception => OK");
109 curText
= oObj
.getText();
110 log
.println("Current text: '" + curText
+ "'");
111 res
&= curText
.equals(oldText
);
115 log
.print("cutText(0," + (length
+1) + "): ");
116 locRes
= oObj
.cutText(0, length
+ 1);
118 log
.println("exception was expected => FAILED");
120 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
121 log
.println("expected exception => OK");
122 curText
= oObj
.getText();
123 log
.println("Current text: '" + curText
+ "'");
124 res
&= curText
.equals(oldText
);
129 log
.print("cutText(0," + length
+ "): ");
130 locRes
= oObj
.cutText(0, length
);
132 curText
= oObj
.getText();
133 log
.println("Current text: '" + curText
+ "'");
134 res
&= curText
.length() == 0 && locRes
;
135 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
136 log
.println("unexpected exception");
137 e
.printStackTrace(log
);
141 tRes
.tested("cutText()", res
);
145 * Calls the method with the wrong indexes and with the correct indexes.
146 * Has OK status if exceptions were thrown for the wrong indexes,
147 * if exception wasn't thrown for the correct indexes and if cutted text was
149 * The following method tests are to be executed before:
151 * <li> <code>cutText()</code> </li>
154 public void _pasteText() {
155 requiredMethod("cutText()");
157 boolean locRes
= true;
158 String curText
= null;
160 String text
= oObj
.getText();
161 log
.println("Text: '" + text
+ "'");
162 int length
= oObj
.getCharacterCount();
163 log
.println("Character count: " + length
);
166 log
.print("pasteText(-1): ");
167 locRes
= oObj
.pasteText(-1);
169 log
.println("exception was expected => FAILED");
171 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
172 log
.println("expected exception => OK");
173 curText
= oObj
.getText();
174 log
.println("Current text: '" + curText
+ "'");
175 res
&= curText
.equals(text
);
179 log
.print("pasteText(" + (length
+1) + "): ");
180 locRes
= oObj
.pasteText(length
+ 1);
182 log
.println("exception was expected => FAILED");
184 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
185 log
.println("expected exception => OK");
186 curText
= oObj
.getText();
187 log
.println("Current text: '" + curText
+ "'");
188 res
&= curText
.equals(text
);
192 log
.print("pasteText(" + (length
) + "): ");
193 locRes
= oObj
.pasteText(length
);
195 curText
= oObj
.getText();
196 log
.println("Current text: '" + curText
+ "'");
197 res
&= curText
.equals(text
+ pasteText
) && locRes
;
198 log
.println("Expected text: '" + text
+ pasteText
+ "'");
199 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
200 log
.println("unexpected exception");
201 e
.printStackTrace(log
);
205 tRes
.tested("pasteText()", res
);
209 * Calls the method with the wrong indexes and with the correct indexes,
210 * checks text after method call.
211 * Has OK status if exceptions were thrown for the wrong indexes,
212 * if exception wasn't thrown for the correct indexes and if deleted string
213 * was really deleted from the text.
214 * The following method tests are to be executed before:
216 * <li> <code>insertText()</code> </li>
219 public void _deleteText() {
220 executeMethod("insertText()");
222 boolean locRes
= true;
223 String curText
= null;
225 String text
= oObj
.getText();
226 log
.println("Text: '" + text
+ "'");
227 int length
= oObj
.getCharacterCount();
228 log
.println("Character count: " + length
);
231 log
.print("deleteText(-1," + length
+ "): ");
232 locRes
= oObj
.deleteText(-1, length
);
234 log
.println("exception was expected => FAILED");
236 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
237 log
.println("expected exception => OK");
238 curText
= oObj
.getText();
239 log
.println("Current text: '" + curText
+ "'");
240 res
&= curText
.equals(text
);
244 log
.print("deleteText(0," + (length
+1) + "): ");
245 locRes
= oObj
.deleteText(0, length
+ 1);
247 log
.println("exception was expected => FAILED");
249 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
250 log
.println("expected exception => OK");
251 curText
= oObj
.getText();
252 log
.println("Current text: '" + curText
+ "'");
253 res
&= curText
.equals(text
);
258 log
.print("deleteText(" + (length
-1) + "," + (length
) + "): ");
259 locRes
= oObj
.deleteText(length
- 1, length
);
261 String expStr
= text
.substring(0, length
- 1);
262 curText
= oObj
.getText();
263 log
.println("Current text: '" + curText
+ "'");
264 res
&= curText
.equals(expStr
);
265 log
.println("Expected text: '" + expStr
+ "'");
267 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
268 log
.println("unexpected exception");
269 e
.printStackTrace(log
);
273 tRes
.tested("deleteText()", res
);
277 * Calls the method with the wrong indexes and with the correct indexes,
278 * checks text after method call.
279 * Has OK status if exceptions were thrown for the wrong indexes,
280 * if exception wasn't thrown for the correct indexes and if inserted string
281 * was really inserted into the text.
282 * The following method tests are to be executed before:
284 * <li> <code>pasteText()</code> </li>
287 public void _insertText() {
288 executeMethod("pasteText()");
290 boolean locRes
= true;
291 String curText
= null;
293 String text
= oObj
.getText();
294 log
.println("Text: '" + text
+ "'");
295 int length
= oObj
.getCharacterCount();
296 log
.println("Character count: " + length
);
298 final String insStr
= "Inserted string";
301 log
.print("insertText(insStr, -1): ");
302 locRes
= oObj
.insertText(insStr
, -1);
304 log
.println("exception was expected=> FAILED");
306 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
307 log
.println("expected exception => OK");
308 curText
= oObj
.getText();
309 log
.println("Current text: '" + curText
+ "'");
310 res
&= curText
.equals(text
);
314 log
.print("insertText(insStr," + (length
+1) + "): ");
315 locRes
= oObj
.insertText(insStr
, length
+1);
317 log
.println("exception was expected => FAILED");
319 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
320 log
.println("expected exception => OK");
321 curText
= oObj
.getText();
322 log
.println("Current text: '" + curText
+ "'");
323 res
&= curText
.equals(text
);
327 log
.print("insertText(insStr," + length
+ "): ");
328 locRes
= oObj
.insertText(insStr
, length
);
330 curText
= oObj
.getText();
331 res
&= curText
.equals(text
+ insStr
);
332 log
.println("Current text: '" + curText
+ "'");
333 log
.println("Expected text: '" + text
+ insStr
+ "'");
334 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
335 log
.println("unexpected exception => FAILED");
336 e
.printStackTrace(log
);
340 tRes
.tested("insertText()", res
);
344 * Calls the method with the wrong indexes and with the correct indexes,
345 * checks text after method call.
346 * Has OK status if exceptions were thrown for the wrong indexes,
347 * if exception wasn't thrown for the correct indexes and if part of text
348 * was really replaced by the specified replacement string.
349 * The following method tests are to be executed before:
351 * <li> <code>deleteText()</code> </li>
354 public void _replaceText() {
355 executeMethod("deleteText()");
357 boolean locRes
= true;
358 String curText
= null;
360 final String sReplacement
= "String for replace";
361 String oldText
= oObj
.getText();
362 int startIndx
= oldText
.length();
363 oObj
.setText(oldText
+ " part of string for replace");
365 String text
= oObj
.getText();
366 log
.println("Text: '" + text
+ "'");
367 int length
= oObj
.getCharacterCount();
368 log
.println("Character count: " + length
);
371 log
.print("replaceText(-1," + length
+ "): ");
372 locRes
= oObj
.replaceText(-1, length
, sReplacement
);
374 log
.println("exception was expected => FAILED");
376 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
377 log
.println("expected exception => OK");
378 curText
= oObj
.getText();
379 log
.println("Current text: '" + curText
+ "'");
380 res
&= curText
.equals(text
);
384 log
.print("replaceText(0," + (length
+1) + "): ");
385 locRes
= oObj
.replaceText(0, length
+ 1, sReplacement
);
387 log
.println("exception was expected => FAILED");
389 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
390 log
.println("expected exception => OK");
391 curText
= oObj
.getText();
392 log
.println("Current text: '" + curText
+ "'");
393 res
&= curText
.equals(text
);
397 log
.print("replaceText(" + startIndx
+ "," + length
+ "): ");
398 locRes
= oObj
.replaceText(startIndx
, length
, sReplacement
);
400 curText
= oObj
.getText();
401 log
.println("Current text: '" + curText
+ "'");
402 log
.println("Expected text: '" + oldText
+ sReplacement
+ "'");
403 res
&= curText
.equals(oldText
+ sReplacement
);
404 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
405 log
.println("unexpected exception");
406 e
.printStackTrace(log
);
410 tRes
.tested("replaceText()", res
);
414 * Calls the method with the wrong indexes and with the correct indexes,
415 * checks attributes after method call.
416 * Has OK status if exceptions were thrown for the wrong indexes,
417 * if exception wasn't thrown for the correct indexes and if attributes
418 * of text was changed.
419 * The following method tests are to be executed before:
421 * <li> <code>replaceText()</code> </li>
424 public void _setAttributes() {
425 executeMethod("replaceText()");
427 boolean locRes
= true;
429 String text
= oObj
.getText();
430 log
.println("Text: '" + text
+ "'");
431 int length
= oObj
.getCharacterCount();
432 log
.println("Length: " + length
);
434 PropertyValue
[] attrs
= null;
437 attrs
= oObj
.getCharacterAttributes(0, new String
[]{""});
438 log
.print("setAttributes(-1," + (length
- 1) + "):");
439 locRes
= oObj
.setAttributes(-1, length
- 1, attrs
);
441 log
.println("exception was expected => FAILED");
443 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
444 log
.println("expected exception => OK");
449 log
.print("setAttributes(0," + (length
+1) + "):");
450 locRes
= oObj
.setAttributes(0, length
+ 1, attrs
);
452 log
.println("exception was expected => FAILED");
454 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
455 log
.println("expected exception => OK");
459 //change old attributes set
460 for(int i
= 0; i
< attrs
.length
; i
++) {
461 if (attrs
[i
].Name
.equals("CharColor")) {
462 attrs
[i
].Value
= new Integer(-2);
467 log
.print("setAttributes(0," + length
+ "):");
468 locRes
= oObj
.setAttributes(0, length
, attrs
);
470 res
&= (changeableAttr
&& locRes
)
471 || (!changeableAttr
&& !locRes
);
472 if (changeableAttr
) {
473 log
.print("checking that new attributes was set...");
474 PropertyValue
[] newAttrs
= oObj
.getCharacterAttributes(0, new String
[]{""});
475 locRes
= ValueComparer
.equalValue(attrs
, newAttrs
);
479 log
.println("Text attributes can't be changed.");
481 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
482 log
.println("unexpected exception => FAILED");
483 e
.printStackTrace(log
);
487 tRes
.tested("setAttributes()", res
);
491 * Calls the method with different parameters and checks text.
493 public void _setText() {
494 executeMethod("setAttributes()");
496 boolean locRes
= true;
498 String oldText
= oObj
.getText();
499 log
.println("Current text: '" + oldText
+ "'");
501 String newText
= "New text";
502 log
.print("setText('" + newText
+ "'): ");
503 locRes
= oObj
.setText(newText
);
505 String newCurText
= oObj
.getText();
506 log
.println("getText(): '" + newCurText
+ "'");
507 res
&= locRes
&& newCurText
.equals(newText
);
510 log
.print("setText('" + newText
+ "'): ");
511 locRes
= oObj
.setText(newText
);
513 newCurText
= oObj
.getText();
514 log
.println("getText(): '" + newCurText
+ "'");
515 res
&= locRes
&& newCurText
.equals(newText
);
517 log
.print("setText('" + oldText
+ "'): ");
518 locRes
= oObj
.setText(oldText
);
520 newCurText
= oObj
.getText();
521 log
.println("getText(): '" + newCurText
+ "'");
522 res
&= locRes
&& newCurText
.equals(oldText
);
524 tRes
.tested("setText()", res
);
528 * Restores initial component text.
530 protected void after() {
531 oObj
.setText(initialText
);