bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / ifc / accessibility / _XAccessibleEditableText.java
blob654cb7af295a32a24a18a8439f4f8df947fa7ce2
1 /*
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;
27 /**
28 * Testing <code>com.sun.star.accessibility.XAccessibleEditableText</code>
29 * interface methods :
30 * <ul>
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>
38 * </ul> <p>
40 * This test needs the following object relations :
41 * <ul>
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
47 * attributes. <p>
48 * If the relation is <code>false</code> then the component
49 * has fixed text attributes. </li>
50 * </ul> <p>
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 = "";
63 /**
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
67 * attributes.
69 private boolean changeableAttr = true;
71 /**
72 * Retrieves object relation. Stores initial component text
73 * for restoding it in <code>after</code>.
75 protected void before() {
76 Boolean b = (Boolean)
77 tEnv.getObjRelation("XAccessibleEditableText.hasAttr");
78 if (b != null) {
79 changeableAttr = b.booleanValue();
82 initialText = oObj.getText();
85 /**
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() {
92 boolean res = true;
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);
101 try {
102 log.print("cutText(-1," + (length-1) + "): ");
103 locRes = oObj.cutText(-1, length - 1);
104 log.println(locRes);
105 log.println("exception was expected => FAILED");
106 res &= false;
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);
114 try {
115 log.print("cutText(0," + (length+1) + "): ");
116 locRes = oObj.cutText(0, length + 1);
117 log.println(locRes);
118 log.println("exception was expected => FAILED");
119 res &= false;
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);
127 try {
128 pasteText = oldText;
129 log.print("cutText(0," + length + "): ");
130 locRes = oObj.cutText(0, length);
131 log.println(locRes);
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);
138 res &= false;
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
148 * pasted.
149 * The following method tests are to be executed before:
150 * <ul>
151 * <li> <code>cutText()</code> </li>
152 * </ul>
154 public void _pasteText() {
155 requiredMethod("cutText()");
156 boolean res = true;
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);
165 try {
166 log.print("pasteText(-1): ");
167 locRes = oObj.pasteText(-1);
168 log.println(locRes);
169 log.println("exception was expected => FAILED");
170 res &= false;
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);
178 try {
179 log.print("pasteText(" + (length+1) + "): ");
180 locRes = oObj.pasteText(length + 1);
181 log.println(locRes);
182 log.println("exception was expected => FAILED");
183 res &= false;
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);
191 try {
192 log.print("pasteText(" + (length) + "): ");
193 locRes = oObj.pasteText(length);
194 log.println(locRes);
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);
202 res &= false;
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:
215 * <ul>
216 * <li> <code>insertText()</code> </li>
217 * </ul>
219 public void _deleteText() {
220 executeMethod("insertText()");
221 boolean res = true;
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);
230 try {
231 log.print("deleteText(-1," + length + "): ");
232 locRes = oObj.deleteText(-1, length);
233 log.println(locRes);
234 log.println("exception was expected => FAILED");
235 res &= false;
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);
243 try {
244 log.print("deleteText(0," + (length+1) + "): ");
245 locRes = oObj.deleteText(0, length + 1);
246 log.println(locRes);
247 log.println("exception was expected => FAILED");
248 res &= false;
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);
256 try {
257 if (length >= 1) {
258 log.print("deleteText(" + (length-1) + "," + (length) + "): ");
259 locRes = oObj.deleteText(length - 1, length);
260 log.println(locRes);
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);
270 res &= false;
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:
283 * <ul>
284 * <li> <code>pasteText()</code> </li>
285 * </ul>
287 public void _insertText() {
288 executeMethod("pasteText()");
289 boolean res = true;
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";
300 try {
301 log.print("insertText(insStr, -1): ");
302 locRes = oObj.insertText(insStr, -1);
303 log.println(locRes);
304 log.println("exception was expected=> FAILED");
305 res &= false;
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);
313 try {
314 log.print("insertText(insStr," + (length+1) + "): ");
315 locRes = oObj.insertText(insStr, length+1);
316 log.println(locRes);
317 log.println("exception was expected => FAILED");
318 res &= false;
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);
326 try {
327 log.print("insertText(insStr," + length + "): ");
328 locRes = oObj.insertText(insStr, length);
329 log.println(locRes);
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);
337 res &= false;
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:
350 * <ul>
351 * <li> <code>deleteText()</code> </li>
352 * </ul>
354 public void _replaceText() {
355 executeMethod("deleteText()");
356 boolean res = true;
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);
370 try {
371 log.print("replaceText(-1," + length + "): ");
372 locRes = oObj.replaceText(-1, length, sReplacement);
373 log.println(locRes);
374 log.println("exception was expected => FAILED");
375 res &= false;
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);
383 try {
384 log.print("replaceText(0," + (length+1) + "): ");
385 locRes = oObj.replaceText(0, length + 1, sReplacement);
386 log.println(locRes);
387 log.println("exception was expected => FAILED");
388 res &= false;
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);
396 try {
397 log.print("replaceText(" + startIndx + "," + length + "): ");
398 locRes = oObj.replaceText(startIndx, length, sReplacement);
399 log.println(locRes);
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);
407 res &= false;
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:
420 * <ul>
421 * <li> <code>replaceText()</code> </li>
422 * </ul>
424 public void _setAttributes() {
425 executeMethod("replaceText()");
426 boolean res = true;
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;
436 try {
437 attrs = oObj.getCharacterAttributes(0, new String[]{""});
438 log.print("setAttributes(-1," + (length - 1) + "):");
439 locRes = oObj.setAttributes(-1, length - 1, attrs);
440 log.println(locRes);
441 log.println("exception was expected => FAILED");
442 res &= false;
443 } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
444 log.println("expected exception => OK");
445 res &= true;
448 try {
449 log.print("setAttributes(0," + (length+1) + "):");
450 locRes = oObj.setAttributes(0, length + 1, attrs);
451 log.println(locRes);
452 log.println("exception was expected => FAILED");
453 res &= false;
454 } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
455 log.println("expected exception => OK");
456 res &= true;
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);
466 try {
467 log.print("setAttributes(0," + length + "):");
468 locRes = oObj.setAttributes(0, length, attrs);
469 log.println(locRes);
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);
476 log.println(locRes);
477 res &= locRes;
478 } else {
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);
484 res &= false;
487 tRes.tested("setAttributes()", res);
491 * Calls the method with different parameters and checks text.
493 public void _setText() {
494 executeMethod("setAttributes()");
495 boolean res = true;
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);
504 log.println(locRes);
505 String newCurText = oObj.getText();
506 log.println("getText(): '" + newCurText + "'");
507 res &= locRes && newCurText.equals(newText);
509 newText = "";
510 log.print("setText('" + newText + "'): ");
511 locRes = oObj.setText(newText);
512 log.println(locRes);
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);
519 log.println(locRes);
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);