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