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: _XTextComponent.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 ************************************************************************/
33 import lib
.MultiMethodTest
;
34 import util
.ValueComparer
;
36 import com
.sun
.star
.awt
.Selection
;
37 import com
.sun
.star
.awt
.TextEvent
;
38 import com
.sun
.star
.awt
.XTextComponent
;
39 import com
.sun
.star
.awt
.XTextListener
;
40 import com
.sun
.star
.lang
.EventObject
;
43 * Testing <code>com.sun.star.awt.XTextComponent</code>
46 * <li><code> addTextListener() </code></li>
47 * <li><code> removeTextListener() </code></li>
48 * <li><code> setText() </code></li>
49 * <li><code> getText() </code></li>
50 * <li><code> insertText() </code></li>
51 * <li><code> getSelectedText() </code></li>
52 * <li><code> setSelection() </code></li>
53 * <li><code> getSelection() </code></li>
54 * <li><code> setEditable() </code></li>
55 * <li><code> isEditable() </code></li>
56 * <li><code> setMaxTextLen() </code></li>
57 * <li><code> getMaxTextLen() </code></li>
59 * This test needs the following object relations :
61 * <li> <code>'XTextComponent.onlyNumbers'</code> (of type <code>Object</code>):
62 * needed for checking if component can contain only numeric values </li>
64 * Test is <b> NOT </b> multithread compilant. <p>
65 * @see com.sun.star.awt.XTextComponent
67 public class _XTextComponent
extends MultiMethodTest
{
68 public XTextComponent oObj
= null;
69 public boolean textChanged
= false;
70 // indicates that component can contain only numeric values
71 private boolean num
= false ;
74 * Listener implementation which just set flag when listener
77 protected class MyChangeListener
implements XTextListener
{
78 public void disposing ( EventObject oEvent
) {}
79 public void textChanged(TextEvent ev
) {
84 XTextListener listener
= new MyChangeListener();
87 * Retrieves object relation, then sets flag 'num' to 'true'
88 * if relation is not null.
90 public void before() {
91 if (tEnv
.getObjRelation("XTextComponent.onlyNumbers") != null)
96 * After test calls the method, a new text is set to the object. Then
97 * we check if listener was called, and set a new text value
99 * Has <b> OK </b> status if listener was called.
101 public void _addTextListener(){
102 oObj
.addTextListener(listener
);
103 oObj
.setText("Listen");
106 } catch(java
.lang
.InterruptedException e
) {
107 e
.printStackTrace(log
);
110 log
.println("Listener wasn't called after changing Text");
113 tRes
.tested("addTextListener()",textChanged
);
117 * After setting flag 'textChanged' to false, test calls the method.
118 * Then a new text value is set to the object. <p>
119 * Has <b> OK </b> status if listener was not called. <p>
120 * The following method tests are to be completed successfully before :
122 * <li><code> addTextListener() </code>: adds listener to the object.</li>
125 public void _removeTextListener() {
126 requiredMethod("addTextListener()");
128 oObj
.removeTextListener(listener
);
129 oObj
.setText("Do not listen");
130 tRes
.tested("removeTextListener()",!textChanged
);
134 * At first we're setting some string variable 'newText' depending of a kind
135 * of object we are working with. Then test calls the method. <p>
136 * Has <b> OK </b> status if set value is equal to a value obtained after.
138 public void _setText() {
139 String newText
= num ?
"823" : "setText" ;
140 if (tEnv
.getTestCase().getObjectName().equals("OTimeControl")) {
143 log
.println("Setting text to : '" + newText
+ "'") ;
144 oObj
.setText(newText
);
145 log
.println("Getting text : '" + oObj
.getText() + "'") ;
146 tRes
.tested("setText()",oObj
.getText().equals(newText
));
150 * At first we're setting some string variable 'newText' depending of a kind
151 * of object we are working with. Then we set text to the object and call
153 * Has <b> OK </b> status if set value is equal to a value obtained using
156 public void _getText() {
157 String newText
= num ?
"823" : "setText" ;
158 if (tEnv
.getTestCase().getObjectName().equals("OTimeControl")) {
161 oObj
.setText(newText
);
162 tRes
.tested("getText()",oObj
.getText().equals(newText
));
166 * At first we're setting string variables 'text' and 'itext' depending
167 * of a kind of object we are working with. Next, value from 'text' variable
168 * is set to an object using setText(), then the method insertText() is called.
170 * Has <b> OK </b> status if text is inserted to the object.
172 public void _insertText() {
173 String text
= num ?
"753" : "iText" ;
174 String itext
= num ?
"6" : "insert" ;
175 log
.println("Setting text to : '" + text
+ "'") ;
177 log
.println("Iserting text to (0,1) : '" + itext
+ "'") ;
178 oObj
.insertText(new Selection(0,1), itext
);
179 log
.println("getText() returns: " + oObj
.getText());
180 tRes
.tested("insertText()", oObj
.getText().equals
181 (num ?
"653" : "insertText"));
185 * After text is set to the object, test calls the method.<p>
186 * Has <b> OK </b> status if selected text is equal to first three symbols
187 * of text added before.
189 public void _getSelectedText() {
190 String text
= num ?
"753" : "txt" ;
192 oObj
.setSelection(new Selection(0,3));
193 boolean result
= oObj
.getSelectedText().equals(text
);
196 System
.out
.println("Getting '"+oObj
.getSelectedText()+"'");
197 System
.out
.println("Expected '"+text
+"'");
200 tRes
.tested("getSelectedText()",result
);
204 * After setting new text to an object, and defining selection variable,
205 * test calls the method. <p>
206 * Has <b> OK </b> status if selection set before is equal to a selection we
207 * got using getSelection().
209 public void _setSelection() {
210 oObj
.setText("setSelection");
211 Selection sel
= new Selection(0,3);
212 oObj
.setSelection(sel
);
213 tRes
.tested("setSelection()", ValueComparer
.equalValue
214 (oObj
.getSelection(), sel
));
218 * After setting new text to an object, and defining selection variable,
219 * test calls the method. <p>
220 * Has <b> OK </b> status if selection set before is equal to a selection we
221 * got using getSelection().
223 public void _getSelection() {
224 oObj
.setText("getSelection");
225 Selection sel
= new Selection(2,3);
226 oObj
.setSelection(sel
);
227 tRes
.tested("getSelection()", ValueComparer
.equalValue
228 (oObj
.getSelection(), sel
));
232 * Test calls the method. <p>
233 * Has <b> OK </b> status if method has changed a property 'Editable'.
235 public void _setEditable(){
236 oObj
.setEditable(true);
237 tRes
.tested("setEditable()", oObj
.isEditable());
241 * First we set 'Editable' variable to false. Then test calls the method.<p>
242 * Has <b> OK </b> status if method returns value we set before.
244 public void _isEditable(){
245 oObj
.setEditable(false);
246 tRes
.tested("isEditable()", ! oObj
.isEditable());
250 * Test calls the method. Then new text value is set to the object. <p>
251 * Has <b> OK </b> status if text, returned by getText() is a string of
252 * length we set before.
254 public void _setMaxTextLen() {
255 oObj
.setMaxTextLen((short)10);
256 //oObj.setText("0123456789ABCDE");
257 //String get = oObj.getText();
258 //tRes.tested("setMaxTextLen()",get.length() == 10);
259 tRes
.tested("setMaxTextLen()",oObj
.getMaxTextLen()==10);
263 * At first we set MaxTextLen, then test calls the method. <p>
264 * Has <b> OK </b> status if method returns a value we set before.
266 public void _getMaxTextLen() {
267 oObj
.setMaxTextLen((short)15);
268 log
.println("getMaxTextLen() returns: "+oObj
.getMaxTextLen());
269 tRes
.tested("getMaxTextLen()",oObj
.getMaxTextLen()==15);