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>.
76 protected void before() {
78 tEnv
.getObjRelation("XAccessibleEditableText.hasAttr");
80 changeableAttr
= b
.booleanValue();
83 initialText
= oObj
.getText();
87 * Calls the method with the wrong indexes and with the correct indexes.
88 * Stores cutted text in the variable <code>pasteText</code>.
89 * Has OK status if exceptions were thrown for the wrong indexes,
90 * if exception wasn't thrown for the correct indexes.
92 public void _cutText() {
94 boolean locRes
= true;
95 String curText
= null;
97 String oldText
= oObj
.getText();
98 log
.println("Text: '" + oldText
+ "'");
99 int length
= oObj
.getCharacterCount();
100 log
.println("Character count: " + length
);
103 log
.print("cutText(-1," + (length
-1) + "): ");
104 locRes
= oObj
.cutText(-1, length
- 1);
106 log
.println("exception was expected => FAILED");
108 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
109 log
.println("expected exception => OK");
110 curText
= oObj
.getText();
111 log
.println("Current text: '" + curText
+ "'");
112 res
&= curText
.equals(oldText
);
116 log
.print("cutText(0," + (length
+1) + "): ");
117 locRes
= oObj
.cutText(0, length
+ 1);
119 log
.println("exception was expected => FAILED");
121 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
122 log
.println("expected exception => OK");
123 curText
= oObj
.getText();
124 log
.println("Current text: '" + curText
+ "'");
125 res
&= curText
.equals(oldText
);
130 log
.print("cutText(0," + length
+ "): ");
131 locRes
= oObj
.cutText(0, length
);
133 curText
= oObj
.getText();
134 log
.println("Current text: '" + curText
+ "'");
135 res
&= curText
.length() == 0 && locRes
;
136 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
137 log
.println("unexpected exception");
138 e
.printStackTrace(log
);
142 tRes
.tested("cutText()", res
);
146 * Calls the method with the wrong indexes and with the correct indexes.
147 * Has OK status if exceptions were thrown for the wrong indexes,
148 * if exception wasn't thrown for the correct indexes and if cutted text was
150 * The following method tests are to be executed before:
152 * <li> <code>cutText()</code> </li>
155 public void _pasteText() {
156 requiredMethod("cutText()");
158 boolean locRes
= true;
159 String curText
= null;
161 String text
= oObj
.getText();
162 log
.println("Text: '" + text
+ "'");
163 int length
= oObj
.getCharacterCount();
164 log
.println("Character count: " + length
);
167 log
.print("pasteText(-1): ");
168 locRes
= oObj
.pasteText(-1);
170 log
.println("exception was expected => FAILED");
172 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
173 log
.println("expected exception => OK");
174 curText
= oObj
.getText();
175 log
.println("Current text: '" + curText
+ "'");
176 res
&= curText
.equals(text
);
180 log
.print("pasteText(" + (length
+1) + "): ");
181 locRes
= oObj
.pasteText(length
+ 1);
183 log
.println("exception was expected => FAILED");
185 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
186 log
.println("expected exception => OK");
187 curText
= oObj
.getText();
188 log
.println("Current text: '" + curText
+ "'");
189 res
&= curText
.equals(text
);
193 log
.print("pasteText(" + (length
) + "): ");
194 locRes
= oObj
.pasteText(length
);
196 curText
= oObj
.getText();
197 log
.println("Current text: '" + curText
+ "'");
198 res
&= curText
.equals(text
+ pasteText
) && locRes
;
199 log
.println("Expected text: '" + text
+ pasteText
+ "'");
200 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
201 log
.println("unexpected exception");
202 e
.printStackTrace(log
);
206 tRes
.tested("pasteText()", res
);
210 * Calls the method with the wrong indexes and with the correct indexes,
211 * checks text after method call.
212 * Has OK status if exceptions were thrown for the wrong indexes,
213 * if exception wasn't thrown for the correct indexes and if deleted string
214 * was really deleted from the text.
215 * The following method tests are to be executed before:
217 * <li> <code>insertText()</code> </li>
220 public void _deleteText() {
221 executeMethod("insertText()");
223 boolean locRes
= true;
224 String curText
= null;
226 String text
= oObj
.getText();
227 log
.println("Text: '" + text
+ "'");
228 int length
= oObj
.getCharacterCount();
229 log
.println("Character count: " + length
);
232 log
.print("deleteText(-1," + length
+ "): ");
233 locRes
= oObj
.deleteText(-1, length
);
235 log
.println("exception was expected => FAILED");
237 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
238 log
.println("expected exception => OK");
239 curText
= oObj
.getText();
240 log
.println("Current text: '" + curText
+ "'");
241 res
&= curText
.equals(text
);
245 log
.print("deleteText(0," + (length
+1) + "): ");
246 locRes
= oObj
.deleteText(0, length
+ 1);
248 log
.println("exception was expected => FAILED");
250 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
251 log
.println("expected exception => OK");
252 curText
= oObj
.getText();
253 log
.println("Current text: '" + curText
+ "'");
254 res
&= curText
.equals(text
);
259 log
.print("deleteText(" + (length
-1) + "," + (length
) + "): ");
260 locRes
= oObj
.deleteText(length
- 1, length
);
262 String expStr
= text
.substring(0, length
- 1);
263 curText
= oObj
.getText();
264 log
.println("Current text: '" + curText
+ "'");
265 res
&= curText
.equals(expStr
);
266 log
.println("Expected text: '" + expStr
+ "'");
268 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
269 log
.println("unexpected exception");
270 e
.printStackTrace(log
);
274 tRes
.tested("deleteText()", res
);
278 * Calls the method with the wrong indexes and with the correct indexes,
279 * checks text after method call.
280 * Has OK status if exceptions were thrown for the wrong indexes,
281 * if exception wasn't thrown for the correct indexes and if inserted string
282 * was really inserted into the text.
283 * The following method tests are to be executed before:
285 * <li> <code>pasteText()</code> </li>
288 public void _insertText() {
289 executeMethod("pasteText()");
291 boolean locRes
= true;
292 String curText
= null;
294 String text
= oObj
.getText();
295 log
.println("Text: '" + text
+ "'");
296 int length
= oObj
.getCharacterCount();
297 log
.println("Character count: " + length
);
299 final String insStr
= "Inserted string";
302 log
.print("insertText(insStr, -1): ");
303 locRes
= oObj
.insertText(insStr
, -1);
305 log
.println("exception was expected=> FAILED");
307 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
308 log
.println("expected exception => OK");
309 curText
= oObj
.getText();
310 log
.println("Current text: '" + curText
+ "'");
311 res
&= curText
.equals(text
);
315 log
.print("insertText(insStr," + (length
+1) + "): ");
316 locRes
= oObj
.insertText(insStr
, length
+1);
318 log
.println("exception was expected => FAILED");
320 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
321 log
.println("expected exception => OK");
322 curText
= oObj
.getText();
323 log
.println("Current text: '" + curText
+ "'");
324 res
&= curText
.equals(text
);
328 log
.print("insertText(insStr," + length
+ "): ");
329 locRes
= oObj
.insertText(insStr
, length
);
331 curText
= oObj
.getText();
332 res
&= curText
.equals(text
+ insStr
);
333 log
.println("Current text: '" + curText
+ "'");
334 log
.println("Expected text: '" + text
+ insStr
+ "'");
335 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
336 log
.println("unexpected exception => FAILED");
337 e
.printStackTrace(log
);
341 tRes
.tested("insertText()", res
);
345 * Calls the method with the wrong indexes and with the correct indexes,
346 * checks text after method call.
347 * Has OK status if exceptions were thrown for the wrong indexes,
348 * if exception wasn't thrown for the correct indexes and if part of text
349 * was really replaced by the specified replacement string.
350 * The following method tests are to be executed before:
352 * <li> <code>deleteText()</code> </li>
355 public void _replaceText() {
356 executeMethod("deleteText()");
358 boolean locRes
= true;
359 String curText
= null;
361 final String sReplacement
= "String for replace";
362 String oldText
= oObj
.getText();
363 int startIndx
= oldText
.length();
364 oObj
.setText(oldText
+ " part of string for replace");
366 String text
= oObj
.getText();
367 log
.println("Text: '" + text
+ "'");
368 int length
= oObj
.getCharacterCount();
369 log
.println("Character count: " + length
);
372 log
.print("replaceText(-1," + length
+ "): ");
373 locRes
= oObj
.replaceText(-1, length
, sReplacement
);
375 log
.println("exception was expected => FAILED");
377 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
378 log
.println("expected exception => OK");
379 curText
= oObj
.getText();
380 log
.println("Current text: '" + curText
+ "'");
381 res
&= curText
.equals(text
);
385 log
.print("replaceText(0," + (length
+1) + "): ");
386 locRes
= oObj
.replaceText(0, length
+ 1, sReplacement
);
388 log
.println("exception was expected => FAILED");
390 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
391 log
.println("expected exception => OK");
392 curText
= oObj
.getText();
393 log
.println("Current text: '" + curText
+ "'");
394 res
&= curText
.equals(text
);
398 log
.print("replaceText(" + startIndx
+ "," + length
+ "): ");
399 locRes
= oObj
.replaceText(startIndx
, length
, sReplacement
);
401 curText
= oObj
.getText();
402 log
.println("Current text: '" + curText
+ "'");
403 log
.println("Expected text: '" + oldText
+ sReplacement
+ "'");
404 res
&= curText
.equals(oldText
+ sReplacement
);
405 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
406 log
.println("unexpected exception");
407 e
.printStackTrace(log
);
411 tRes
.tested("replaceText()", res
);
415 * Calls the method with the wrong indexes and with the correct indexes,
416 * checks attributes after method call.
417 * Has OK status if exceptions were thrown for the wrong indexes,
418 * if exception wasn't thrown for the correct indexes and if attributes
419 * of text was changed.
420 * The following method tests are to be executed before:
422 * <li> <code>replaceText()</code> </li>
425 public void _setAttributes() {
426 executeMethod("replaceText()");
428 boolean locRes
= true;
430 String text
= oObj
.getText();
431 log
.println("Text: '" + text
+ "'");
432 int length
= oObj
.getCharacterCount();
433 log
.println("Length: " + length
);
435 PropertyValue
[] attrs
= null;
438 attrs
= oObj
.getCharacterAttributes(0, new String
[]{""});
439 log
.print("setAttributes(-1," + (length
- 1) + "):");
440 locRes
= oObj
.setAttributes(-1, length
- 1, attrs
);
442 log
.println("exception was expected => FAILED");
444 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
445 log
.println("expected exception => OK");
447 } catch(com
.sun
.star
.beans
.UnknownPropertyException e
) {
448 log
.println("unexpected exception => FAILED");
449 e
.printStackTrace(log
);
454 log
.print("setAttributes(0," + (length
+1) + "):");
455 locRes
= oObj
.setAttributes(0, length
+ 1, attrs
);
457 log
.println("exception was expected => FAILED");
459 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
460 log
.println("expected exception => OK");
464 //change old attributes set
465 for(int i
= 0; i
< attrs
.length
; i
++) {
466 if (attrs
[i
].Name
.equals("CharColor")) {
467 attrs
[i
].Value
= Integer
.valueOf(-2);
472 log
.print("setAttributes(0," + length
+ "):");
473 locRes
= oObj
.setAttributes(0, length
, attrs
);
475 res
&= (changeableAttr
&& locRes
)
476 || (!changeableAttr
&& !locRes
);
477 if (changeableAttr
) {
478 log
.print("checking that new attributes was set...");
479 PropertyValue
[] newAttrs
= oObj
.getCharacterAttributes(0, new String
[]{""});
480 locRes
= ValueComparer
.equalValue(attrs
, newAttrs
);
484 log
.println("Text attributes can't be changed.");
486 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
487 log
.println("unexpected exception => FAILED");
488 e
.printStackTrace(log
);
490 } catch(com
.sun
.star
.beans
.UnknownPropertyException e
) {
491 log
.println("unexpected exception => FAILED");
492 e
.printStackTrace(log
);
496 tRes
.tested("setAttributes()", res
);
500 * Calls the method with different parameters and checks text.
502 public void _setText() {
503 executeMethod("setAttributes()");
505 boolean locRes
= true;
507 String oldText
= oObj
.getText();
508 log
.println("Current text: '" + oldText
+ "'");
510 String newText
= "New text";
511 log
.print("setText('" + newText
+ "'): ");
512 locRes
= oObj
.setText(newText
);
514 String newCurText
= oObj
.getText();
515 log
.println("getText(): '" + newCurText
+ "'");
516 res
&= locRes
&& newCurText
.equals(newText
);
519 log
.print("setText('" + newText
+ "'): ");
520 locRes
= oObj
.setText(newText
);
522 newCurText
= oObj
.getText();
523 log
.println("getText(): '" + newCurText
+ "'");
524 res
&= locRes
&& newCurText
.equals(newText
);
526 log
.print("setText('" + oldText
+ "'): ");
527 locRes
= oObj
.setText(oldText
);
529 newCurText
= oObj
.getText();
530 log
.println("getText(): '" + newCurText
+ "'");
531 res
&= locRes
&& newCurText
.equals(oldText
);
533 tRes
.tested("setText()", res
);
537 * Restores initial component text.
540 protected void after() {
541 oObj
.setText(initialText
);