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 .
21 import lib
.MultiMethodTest
;
22 import util
.ValueComparer
;
24 import com
.sun
.star
.awt
.Selection
;
25 import com
.sun
.star
.awt
.TextEvent
;
26 import com
.sun
.star
.awt
.XTextComponent
;
27 import com
.sun
.star
.awt
.XTextListener
;
28 import com
.sun
.star
.lang
.EventObject
;
31 * Testing <code>com.sun.star.awt.XTextComponent</code>
34 * <li><code> addTextListener() </code></li>
35 * <li><code> removeTextListener() </code></li>
36 * <li><code> setText() </code></li>
37 * <li><code> getText() </code></li>
38 * <li><code> insertText() </code></li>
39 * <li><code> getSelectedText() </code></li>
40 * <li><code> setSelection() </code></li>
41 * <li><code> getSelection() </code></li>
42 * <li><code> setEditable() </code></li>
43 * <li><code> isEditable() </code></li>
44 * <li><code> setMaxTextLen() </code></li>
45 * <li><code> getMaxTextLen() </code></li>
47 * This test needs the following object relations :
49 * <li> <code>'XTextComponent.onlyNumbers'</code> (of type <code>Object</code>):
50 * needed for checking if component can contain only numeric values </li>
52 * Test is <b> NOT </b> multithread compliant. <p>
53 * @see com.sun.star.awt.XTextComponent
55 public class _XTextComponent
extends MultiMethodTest
{
56 public XTextComponent oObj
= null;
57 public boolean textChanged
= false;
58 // indicates that component can contain only numeric values
59 private boolean num
= false ;
62 * Listener implementation which just set flag when listener
65 protected class MyChangeListener
implements XTextListener
{
66 public void disposing ( EventObject oEvent
) {}
67 public void textChanged(TextEvent ev
) {
72 XTextListener listener
= new MyChangeListener();
75 * Retrieves object relation, then sets flag 'num' to 'true'
76 * if relation is not null.
79 public void before() {
80 if (tEnv
.getObjRelation("XTextComponent.onlyNumbers") != null)
85 * After test calls the method, a new text is set to the object. Then
86 * we check if listener was called, and set a new text value
88 * Has <b> OK </b> status if listener was called.
90 public void _addTextListener(){
91 oObj
.addTextListener(listener
);
92 oObj
.setText("Listen");
93 util
.utils
.shortWait();
95 log
.println("Listener wasn't called after changing Text");
98 tRes
.tested("addTextListener()",textChanged
);
102 * After setting flag 'textChanged' to false, test calls the method.
103 * Then a new text value is set to the object. <p>
104 * Has <b> OK </b> status if listener was not called. <p>
105 * The following method tests are to be completed successfully before :
107 * <li><code> addTextListener() </code>: adds listener to the object.</li>
110 public void _removeTextListener() {
111 requiredMethod("addTextListener()");
113 oObj
.removeTextListener(listener
);
114 oObj
.setText("Do not listen");
115 tRes
.tested("removeTextListener()",!textChanged
);
119 * At first we're setting some string variable 'newText' depending of a kind
120 * of object we are working with. Then test calls the method. <p>
121 * Has <b> OK </b> status if set value is equal to a value obtained after.
123 public void _setText() {
124 String newText
= num ?
"823" : "setText" ;
125 if (tEnv
.getTestCase().getObjectName().equals("OTimeControl")) {
128 log
.println("Setting text to : '" + newText
+ "'") ;
129 oObj
.setText(newText
);
130 log
.println("Getting text : '" + oObj
.getText() + "'") ;
131 tRes
.tested("setText()",oObj
.getText().equals(newText
));
135 * At first we're setting some string variable 'newText' depending of a kind
136 * of object we are working with. Then we set text to the object and call
138 * Has <b> OK </b> status if set value is equal to a value obtained using
141 public void _getText() {
142 String newText
= num ?
"823" : "setText" ;
143 if (tEnv
.getTestCase().getObjectName().equals("OTimeControl")) {
146 oObj
.setText(newText
);
147 tRes
.tested("getText()",oObj
.getText().equals(newText
));
151 * At first we're setting string variables 'text' and 'itext' depending
152 * of a kind of object we are working with. Next, value from 'text' variable
153 * is set to an object using setText(), then the method insertText() is called.
155 * Has <b> OK </b> status if text is inserted to the object.
157 public void _insertText() {
158 String text
= num ?
"753" : "iText" ;
159 String itext
= num ?
"6" : "insert" ;
160 log
.println("Setting text to : '" + text
+ "'") ;
162 log
.println("Iserting text to (0,1) : '" + itext
+ "'") ;
163 oObj
.insertText(new Selection(0,1), itext
);
164 log
.println("getText() returns: " + oObj
.getText());
165 tRes
.tested("insertText()", oObj
.getText().equals
166 (num ?
"653" : "insertText"));
170 * After text is set to the object, test calls the method.<p>
171 * Has <b> OK </b> status if selected text is equal to first three symbols
172 * of text added before.
174 public void _getSelectedText() {
175 String text
= num ?
"753" : "txt" ;
177 oObj
.setSelection(new Selection(0,3));
178 boolean result
= oObj
.getSelectedText().equals(text
);
181 System
.out
.println("Getting '"+oObj
.getSelectedText()+"'");
182 System
.out
.println("Expected '"+text
+"'");
185 tRes
.tested("getSelectedText()",result
);
189 * After setting new text to an object, and defining selection variable,
190 * test calls the method. <p>
191 * Has <b> OK </b> status if selection set before is equal to a selection we
192 * got using getSelection().
194 public void _setSelection() {
195 oObj
.setText("setSelection");
196 Selection sel
= new Selection(0,3);
197 oObj
.setSelection(sel
);
198 tRes
.tested("setSelection()", ValueComparer
.equalValue
199 (oObj
.getSelection(), sel
));
203 * After setting new text to an object, and defining selection variable,
204 * test calls the method. <p>
205 * Has <b> OK </b> status if selection set before is equal to a selection we
206 * got using getSelection().
208 public void _getSelection() {
209 oObj
.setText("getSelection");
210 Selection sel
= new Selection(2,3);
211 oObj
.setSelection(sel
);
212 tRes
.tested("getSelection()", ValueComparer
.equalValue
213 (oObj
.getSelection(), sel
));
217 * Test calls the method. <p>
218 * Has <b> OK </b> status if method has changed a property 'Editable'.
220 public void _setEditable(){
221 oObj
.setEditable(true);
222 tRes
.tested("setEditable()", oObj
.isEditable());
226 * First we set 'Editable' variable to false. Then test calls the method.<p>
227 * Has <b> OK </b> status if method returns value we set before.
229 public void _isEditable(){
230 oObj
.setEditable(false);
231 tRes
.tested("isEditable()", ! oObj
.isEditable());
235 * Test calls the method. Then new text value is set to the object. <p>
236 * Has <b> OK </b> status if text, returned by getText() is a string of
237 * length we set before.
239 public void _setMaxTextLen() {
240 oObj
.setMaxTextLen((short)10);
241 tRes
.tested("setMaxTextLen()",oObj
.getMaxTextLen()==10);
245 * At first we set MaxTextLen, then test calls the method. <p>
246 * Has <b> OK </b> status if method returns a value we set before.
248 public void _getMaxTextLen() {
249 oObj
.setMaxTextLen((short)15);
250 log
.println("getMaxTextLen() returns: "+oObj
.getMaxTextLen());
251 tRes
.tested("getMaxTextLen()",oObj
.getMaxTextLen()==15);