merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / ifc / accessibility / _XAccessibleEditableText.java
blobd40dfdb6aa22e589b4e62bc98b09336eb0706cd6
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XAccessibleEditableText.java,v $
10 * $Revision: 1.6 $
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;
39 /**
40 * Testing <code>com.sun.star.accessibility.XAccessibleEditableText</code>
41 * interface methods :
42 * <ul>
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>
50 * </ul> <p>
52 * This test needs the following object relations :
53 * <ul>
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
59 * attributes. <p>
60 * If the relation is <code>false</code> then the component
61 * has fixed text attributes. </li>
62 * </ul> <p>
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 = "";
75 /**
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
79 * attributes.
81 private boolean changeableAttr = true;
83 /**
84 * Retrieves object relation. Stores initial component text
85 * for restoding it in <code>after</code>.
87 protected void before() {
88 Boolean b = (Boolean)
89 tEnv.getObjRelation("XAccessibleEditableText.hasAttr");
90 if (b != null) {
91 changeableAttr = b.booleanValue();
94 initialText = oObj.getText();
97 /**
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() {
104 boolean res = true;
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);
113 try {
114 log.print("cutText(-1," + (length-1) + "): ");
115 locRes = oObj.cutText(-1, length - 1);
116 log.println(locRes);
117 log.println("exception was expected => FAILED");
118 res &= false;
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);
126 try {
127 log.print("cutText(0," + (length+1) + "): ");
128 locRes = oObj.cutText(0, length + 1);
129 log.println(locRes);
130 log.println("exception was expected => FAILED");
131 res &= false;
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);
139 try {
140 pasteText = oldText;
141 log.print("cutText(0," + length + "): ");
142 locRes = oObj.cutText(0, length);
143 log.println(locRes);
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);
150 res &= false;
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
160 * pasted.
161 * The following method tests are to be executed before:
162 * <ul>
163 * <li> <code>cutText()</code> </li>
164 * </ul>
166 public void _pasteText() {
167 requiredMethod("cutText()");
168 boolean res = true;
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);
177 try {
178 log.print("pasteText(-1): ");
179 locRes = oObj.pasteText(-1);
180 log.println(locRes);
181 log.println("exception was expected => FAILED");
182 res &= false;
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);
190 try {
191 log.print("pasteText(" + (length+1) + "): ");
192 locRes = oObj.pasteText(length + 1);
193 log.println(locRes);
194 log.println("exception was expected => FAILED");
195 res &= false;
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);
203 try {
204 log.print("pasteText(" + (length) + "): ");
205 locRes = oObj.pasteText(length);
206 log.println(locRes);
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);
214 res &= false;
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:
227 * <ul>
228 * <li> <code>insertText()</code> </li>
229 * </ul>
231 public void _deleteText() {
232 executeMethod("insertText()");
233 boolean res = true;
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);
242 try {
243 log.print("deleteText(-1," + length + "): ");
244 locRes = oObj.deleteText(-1, length);
245 log.println(locRes);
246 log.println("exception was expected => FAILED");
247 res &= false;
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);
255 try {
256 log.print("deleteText(0," + (length+1) + "): ");
257 locRes = oObj.deleteText(0, length + 1);
258 log.println(locRes);
259 log.println("exception was expected => FAILED");
260 res &= false;
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);
268 try {
269 if (length >= 1) {
270 log.print("deleteText(" + (length-1) + "," + (length) + "): ");
271 locRes = oObj.deleteText(length - 1, length);
272 log.println(locRes);
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);
282 res &= false;
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:
295 * <ul>
296 * <li> <code>pasteText()</code> </li>
297 * </ul>
299 public void _insertText() {
300 executeMethod("pasteText()");
301 boolean res = true;
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";
312 try {
313 log.print("insertText(insStr, -1): ");
314 locRes = oObj.insertText(insStr, -1);
315 log.println(locRes);
316 log.println("exception was expected=> FAILED");
317 res &= false;
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);
325 try {
326 log.print("insertText(insStr," + (length+1) + "): ");
327 locRes = oObj.insertText(insStr, length+1);
328 log.println(locRes);
329 log.println("exception was expected => FAILED");
330 res &= false;
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);
338 try {
339 log.print("insertText(insStr," + length + "): ");
340 locRes = oObj.insertText(insStr, length);
341 log.println(locRes);
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);
349 res &= false;
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:
362 * <ul>
363 * <li> <code>deleteText()</code> </li>
364 * </ul>
366 public void _replaceText() {
367 executeMethod("deleteText()");
368 boolean res = true;
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);
382 try {
383 log.print("replaceText(-1," + length + "): ");
384 locRes = oObj.replaceText(-1, length, sReplacement);
385 log.println(locRes);
386 log.println("exception was expected => FAILED");
387 res &= false;
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);
395 try {
396 log.print("replaceText(0," + (length+1) + "): ");
397 locRes = oObj.replaceText(0, length + 1, sReplacement);
398 log.println(locRes);
399 log.println("exception was expected => FAILED");
400 res &= false;
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);
408 try {
409 log.print("replaceText(" + startIndx + "," + length + "): ");
410 locRes = oObj.replaceText(startIndx, length, sReplacement);
411 log.println(locRes);
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);
419 res &= false;
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:
432 * <ul>
433 * <li> <code>replaceText()</code> </li>
434 * </ul>
436 public void _setAttributes() {
437 executeMethod("replaceText()");
438 boolean res = true;
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;
448 try {
449 attrs = oObj.getCharacterAttributes(0, new String[]{""});
450 log.print("setAttributes(-1," + (length - 1) + "):");
451 locRes = oObj.setAttributes(-1, length - 1, attrs);
452 log.println(locRes);
453 log.println("exception was expected => FAILED");
454 res &= false;
455 } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
456 log.println("expected exception => OK");
457 res &= true;
460 try {
461 log.print("setAttributes(0," + (length+1) + "):");
462 locRes = oObj.setAttributes(0, length + 1, attrs);
463 log.println(locRes);
464 log.println("exception was expected => FAILED");
465 res &= false;
466 } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
467 log.println("expected exception => OK");
468 res &= true;
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);
478 try {
479 log.print("setAttributes(0," + length + "):");
480 locRes = oObj.setAttributes(0, length, attrs);
481 log.println(locRes);
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);
488 log.println(locRes);
489 res &= locRes;
490 } else {
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);
496 res &= false;
499 tRes.tested("setAttributes()", res);
503 * Calls the method with different parameters and checks text.
505 public void _setText() {
506 executeMethod("setAttributes()");
507 boolean res = true;
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);
516 log.println(locRes);
517 String newCurText = oObj.getText();
518 log.println("getText(): '" + newCurText + "'");
519 res &= locRes && newCurText.equals(newText);
521 newText = "";
522 log.print("setText('" + newText + "'): ");
523 locRes = oObj.setText(newText);
524 log.println(locRes);
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);
531 log.println(locRes);
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);