1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
|
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
package ifc.awt;
import lib.MultiMethodTest;
import util.ValueComparer;
import com.sun.star.awt.Selection;
import com.sun.star.awt.TextEvent;
import com.sun.star.awt.XTextComponent;
import com.sun.star.awt.XTextListener;
import com.sun.star.lang.EventObject;
/**
* Testing <code>com.sun.star.awt.XTextComponent</code>
* interface methods:
* <ul>
* <li><code> addTextListener() </code></li>
* <li><code> removeTextListener() </code></li>
* <li><code> setText() </code></li>
* <li><code> getText() </code></li>
* <li><code> insertText() </code></li>
* <li><code> getSelectedText() </code></li>
* <li><code> setSelection() </code></li>
* <li><code> getSelection() </code></li>
* <li><code> setEditable() </code></li>
* <li><code> isEditable() </code></li>
* <li><code> setMaxTextLen() </code></li>
* <li><code> getMaxTextLen() </code></li>
* </ul><p>
* This test needs the following object relations :
* <ul>
* <li> <code>'XTextComponent.onlyNumbers'</code> (of type <code>Object</code>):
* needed for checking if component can contain only numeric values </li>
* </ul><p>
* Test is <b> NOT </b> multithread compilant. <p>
* @see com.sun.star.awt.XTextComponent
*/
public class _XTextComponent extends MultiMethodTest {
public XTextComponent oObj = null;
public boolean textChanged = false;
// indicates that component can contain only numeric values
private boolean num = false ;
/**
* Listener implementation which just set flag when listener
* method is called.
*/
protected class MyChangeListener implements XTextListener {
public void disposing ( EventObject oEvent ) {}
public void textChanged(TextEvent ev) {
textChanged = true;
}
}
XTextListener listener = new MyChangeListener();
/**
* Retrieves object relation, then sets flag 'num' to 'true'
* if relation is not null.
*/
public void before() {
if (tEnv.getObjRelation("XTextComponent.onlyNumbers") != null)
num = true;
}
/**
* After test calls the method, a new text is set to the object. Then
* we check if listener was called, and set a new text value
* to the object.<p>
* Has <b> OK </b> status if listener was called.
*/
public void _addTextListener(){
oObj.addTextListener(listener);
oObj.setText("Listen");
try {
Thread.sleep(500);
} catch(java.lang.InterruptedException e) {
e.printStackTrace(log);
}
if (!textChanged) {
log.println("Listener wasn't called after changing Text");
}
tRes.tested("addTextListener()",textChanged);
}
/**
* After setting flag 'textChanged' to false, test calls the method.
* Then a new text value is set to the object. <p>
* Has <b> OK </b> status if listener was not called. <p>
* The following method tests are to be completed successfully before :
* <ul>
* <li><code> addTextListener() </code>: adds listener to the object.</li>
* </ul>
*/
public void _removeTextListener() {
requiredMethod("addTextListener()");
textChanged = false;
oObj.removeTextListener(listener);
oObj.setText("Do not listen");
tRes.tested("removeTextListener()",!textChanged);
}
/**
* At first we're setting some string variable 'newText' depending of a kind
* of object we are working with. Then test calls the method. <p>
* Has <b> OK </b> status if set value is equal to a value obtained after.
*/
public void _setText() {
String newText = num ? "823" : "setText" ;
if (tEnv.getTestCase().getObjectName().equals("OTimeControl")) {
newText = "8:15";
}
log.println("Setting text to : '" + newText + "'") ;
oObj.setText(newText);
log.println("Getting text : '" + oObj.getText() + "'") ;
tRes.tested("setText()",oObj.getText().equals(newText));
}
/**
* At first we're setting some string variable 'newText' depending of a kind
* of object we are working with. Then we set text to the object and call
* the method. <p>
* Has <b> OK </b> status if set value is equal to a value obtained using
* getText() method.
*/
public void _getText() {
String newText = num ? "823" : "setText" ;
if (tEnv.getTestCase().getObjectName().equals("OTimeControl")) {
newText = "8:15";
}
oObj.setText(newText);
tRes.tested("getText()",oObj.getText().equals(newText));
}
/**
* At first we're setting string variables 'text' and 'itext' depending
* of a kind of object we are working with. Next, value from 'text' variable
* is set to an object using setText(), then the method insertText() is called.
* <p>
* Has <b> OK </b> status if text is inserted to the object.
*/
public void _insertText() {
String text = num ? "753" : "iText" ;
String itext = num ? "6" : "insert" ;
log.println("Setting text to : '" + text + "'") ;
oObj.setText(text);
log.println("Iserting text to (0,1) : '" + itext + "'") ;
oObj.insertText(new Selection(0,1), itext);
log.println("getText() returns: " + oObj.getText());
tRes.tested("insertText()", oObj.getText().equals
(num ? "653" : "insertText"));
}
/**
* After text is set to the object, test calls the method.<p>
* Has <b> OK </b> status if selected text is equal to first three symbols
* of text added before.
*/
public void _getSelectedText() {
String text = num ? "753" : "txt" ;
oObj.setText(text);
oObj.setSelection(new Selection(0,3));
boolean result = oObj.getSelectedText().equals(text);
if (! result) {
System.out.println("Getting '"+oObj.getSelectedText()+"'");
System.out.println("Expected '"+text+"'");
}
tRes.tested("getSelectedText()",result);
}
/**
* After setting new text to an object, and defining selection variable,
* test calls the method. <p>
* Has <b> OK </b> status if selection set before is equal to a selection we
* got using getSelection().
*/
public void _setSelection() {
oObj.setText("setSelection");
Selection sel = new Selection(0,3);
oObj.setSelection(sel);
tRes.tested("setSelection()", ValueComparer.equalValue
(oObj.getSelection(), sel));
}
/**
* After setting new text to an object, and defining selection variable,
* test calls the method. <p>
* Has <b> OK </b> status if selection set before is equal to a selection we
* got using getSelection().
*/
public void _getSelection() {
oObj.setText("getSelection");
Selection sel = new Selection(2,3);
oObj.setSelection(sel);
tRes.tested("getSelection()", ValueComparer.equalValue
(oObj.getSelection(), sel));
}
/**
* Test calls the method. <p>
* Has <b> OK </b> status if method has changed a property 'Editable'.
*/
public void _setEditable(){
oObj.setEditable(true);
tRes.tested("setEditable()", oObj.isEditable());
}
/**
* First we set 'Editable' variable to false. Then test calls the method.<p>
* Has <b> OK </b> status if method returns value we set before.
*/
public void _isEditable(){
oObj.setEditable(false);
tRes.tested("isEditable()", ! oObj.isEditable());
}
/**
* Test calls the method. Then new text value is set to the object. <p>
* Has <b> OK </b> status if text, returned by getText() is a string of
* length we set before.
*/
public void _setMaxTextLen() {
oObj.setMaxTextLen((short)10);
//oObj.setText("0123456789ABCDE");
//String get = oObj.getText();
//tRes.tested("setMaxTextLen()",get.length() == 10);
tRes.tested("setMaxTextLen()",oObj.getMaxTextLen()==10);
}
/**
* At first we set MaxTextLen, then test calls the method. <p>
* Has <b> OK </b> status if method returns a value we set before.
*/
public void _getMaxTextLen() {
oObj.setMaxTextLen((short)15);
log.println("getMaxTextLen() returns: "+oObj.getMaxTextLen());
tRes.tested("getMaxTextLen()",oObj.getMaxTextLen()==15);
}
}
|