1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir package ifc.accessibility; 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir import lib.MultiMethodTest; 31*cdf0e10cSrcweir import util.ValueComparer; 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir import com.sun.star.accessibility.XAccessibleEditableText; 34*cdf0e10cSrcweir import com.sun.star.beans.PropertyValue; 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir /** 37*cdf0e10cSrcweir * Testing <code>com.sun.star.accessibility.XAccessibleEditableText</code> 38*cdf0e10cSrcweir * interface methods : 39*cdf0e10cSrcweir * <ul> 40*cdf0e10cSrcweir * <li><code> cutText()</code></li> 41*cdf0e10cSrcweir * <li><code> pasteText()</code></li> 42*cdf0e10cSrcweir * <li><code> deleteText()</code></li> 43*cdf0e10cSrcweir * <li><code> insertText()</code></li> 44*cdf0e10cSrcweir * <li><code> replaceText()</code></li> 45*cdf0e10cSrcweir * <li><code> setAttributes()</code></li> 46*cdf0e10cSrcweir * <li><code> setText()</code></li> 47*cdf0e10cSrcweir * </ul> <p> 48*cdf0e10cSrcweir * 49*cdf0e10cSrcweir * This test needs the following object relations : 50*cdf0e10cSrcweir * <ul> 51*cdf0e10cSrcweir * <li> <code>'XAccessibleEditableText.hasAttr'</code> 52*cdf0e10cSrcweir * (of type <code>Boolean</code>): 53*cdf0e10cSrcweir * Indicates whether or not the text has changeable attributes. 54*cdf0e10cSrcweir * E.g. text within writer document have attributes which can 55*cdf0e10cSrcweir * be changed, while the text within edit field has fixed 56*cdf0e10cSrcweir * attributes. <p> 57*cdf0e10cSrcweir * If the relation is <code>false</code> then the component 58*cdf0e10cSrcweir * has fixed text attributes. </li> 59*cdf0e10cSrcweir * </ul> <p> 60*cdf0e10cSrcweir * 61*cdf0e10cSrcweir * @see com.sun.star.accessibility.XAccessibleEditableText 62*cdf0e10cSrcweir */ 63*cdf0e10cSrcweir public class _XAccessibleEditableText extends MultiMethodTest { 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir public XAccessibleEditableText oObj = null; 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir String pasteText = null; 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir String initialText = ""; 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir /** 73*cdf0e10cSrcweir * Indicates whether or not the text has changeable attributes. 74*cdf0e10cSrcweir * E.g. text within writer document have attributes which can 75*cdf0e10cSrcweir * be changed, while the text within edit field has fixed 76*cdf0e10cSrcweir * attributes. 77*cdf0e10cSrcweir */ 78*cdf0e10cSrcweir private boolean changeableAttr = true; 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir /** 81*cdf0e10cSrcweir * Retrieves object relation. Stores initial component text 82*cdf0e10cSrcweir * for restoding it in <code>after</code>. 83*cdf0e10cSrcweir */ 84*cdf0e10cSrcweir protected void before() { 85*cdf0e10cSrcweir Boolean b = (Boolean) 86*cdf0e10cSrcweir tEnv.getObjRelation("XAccessibleEditableText.hasAttr"); 87*cdf0e10cSrcweir if (b != null) { 88*cdf0e10cSrcweir changeableAttr = b.booleanValue(); 89*cdf0e10cSrcweir } 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir initialText = oObj.getText(); 92*cdf0e10cSrcweir } 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir /** 95*cdf0e10cSrcweir * Calls the method with the wrong indexes and with the correct indexes. 96*cdf0e10cSrcweir * Stores cutted text in the variable <code>pasteText</code>. 97*cdf0e10cSrcweir * Has OK status if exceptions were thrown for the wrong indexes, 98*cdf0e10cSrcweir * if exception wasn't thrown for the correct indexes. 99*cdf0e10cSrcweir */ 100*cdf0e10cSrcweir public void _cutText() { 101*cdf0e10cSrcweir boolean res = true; 102*cdf0e10cSrcweir boolean locRes = true; 103*cdf0e10cSrcweir String curText = null; 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir String oldText = oObj.getText(); 106*cdf0e10cSrcweir log.println("Text: '" + oldText + "'"); 107*cdf0e10cSrcweir int length = oObj.getCharacterCount(); 108*cdf0e10cSrcweir log.println("Character count: " + length); 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir try { 111*cdf0e10cSrcweir log.print("cutText(-1," + (length-1) + "): "); 112*cdf0e10cSrcweir locRes = oObj.cutText(-1, length - 1); 113*cdf0e10cSrcweir log.println(locRes); 114*cdf0e10cSrcweir log.println("exception was expected => FAILED"); 115*cdf0e10cSrcweir res &= false; 116*cdf0e10cSrcweir } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 117*cdf0e10cSrcweir log.println("expected exception => OK"); 118*cdf0e10cSrcweir curText = oObj.getText(); 119*cdf0e10cSrcweir log.println("Current text: '" + curText + "'"); 120*cdf0e10cSrcweir res &= curText.equals(oldText); 121*cdf0e10cSrcweir } 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir try { 124*cdf0e10cSrcweir log.print("cutText(0," + (length+1) + "): "); 125*cdf0e10cSrcweir locRes = oObj.cutText(0, length + 1); 126*cdf0e10cSrcweir log.println(locRes); 127*cdf0e10cSrcweir log.println("exception was expected => FAILED"); 128*cdf0e10cSrcweir res &= false; 129*cdf0e10cSrcweir } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 130*cdf0e10cSrcweir log.println("expected exception => OK"); 131*cdf0e10cSrcweir curText = oObj.getText(); 132*cdf0e10cSrcweir log.println("Current text: '" + curText + "'"); 133*cdf0e10cSrcweir res &= curText.equals(oldText); 134*cdf0e10cSrcweir } 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir try { 137*cdf0e10cSrcweir pasteText = oldText; 138*cdf0e10cSrcweir log.print("cutText(0," + length + "): "); 139*cdf0e10cSrcweir locRes = oObj.cutText(0, length); 140*cdf0e10cSrcweir log.println(locRes); 141*cdf0e10cSrcweir curText = oObj.getText(); 142*cdf0e10cSrcweir log.println("Current text: '" + curText + "'"); 143*cdf0e10cSrcweir res &= curText.length() == 0 && locRes; 144*cdf0e10cSrcweir } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 145*cdf0e10cSrcweir log.println("unexpected exception"); 146*cdf0e10cSrcweir e.printStackTrace(log); 147*cdf0e10cSrcweir res &= false; 148*cdf0e10cSrcweir } 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir tRes.tested("cutText()", res); 151*cdf0e10cSrcweir } 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir /** 154*cdf0e10cSrcweir * Calls the method with the wrong indexes and with the correct indexes. 155*cdf0e10cSrcweir * Has OK status if exceptions were thrown for the wrong indexes, 156*cdf0e10cSrcweir * if exception wasn't thrown for the correct indexes and if cutted text was 157*cdf0e10cSrcweir * pasted. 158*cdf0e10cSrcweir * The following method tests are to be executed before: 159*cdf0e10cSrcweir * <ul> 160*cdf0e10cSrcweir * <li> <code>cutText()</code> </li> 161*cdf0e10cSrcweir * </ul> 162*cdf0e10cSrcweir */ 163*cdf0e10cSrcweir public void _pasteText() { 164*cdf0e10cSrcweir requiredMethod("cutText()"); 165*cdf0e10cSrcweir boolean res = true; 166*cdf0e10cSrcweir boolean locRes = true; 167*cdf0e10cSrcweir String curText = null; 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir String text = oObj.getText(); 170*cdf0e10cSrcweir log.println("Text: '" + text + "'"); 171*cdf0e10cSrcweir int length = oObj.getCharacterCount(); 172*cdf0e10cSrcweir log.println("Character count: " + length); 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir try { 175*cdf0e10cSrcweir log.print("pasteText(-1): "); 176*cdf0e10cSrcweir locRes = oObj.pasteText(-1); 177*cdf0e10cSrcweir log.println(locRes); 178*cdf0e10cSrcweir log.println("exception was expected => FAILED"); 179*cdf0e10cSrcweir res &= false; 180*cdf0e10cSrcweir } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 181*cdf0e10cSrcweir log.println("expected exception => OK"); 182*cdf0e10cSrcweir curText = oObj.getText(); 183*cdf0e10cSrcweir log.println("Current text: '" + curText + "'"); 184*cdf0e10cSrcweir res &= curText.equals(text); 185*cdf0e10cSrcweir } 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir try { 188*cdf0e10cSrcweir log.print("pasteText(" + (length+1) + "): "); 189*cdf0e10cSrcweir locRes = oObj.pasteText(length + 1); 190*cdf0e10cSrcweir log.println(locRes); 191*cdf0e10cSrcweir log.println("exception was expected => FAILED"); 192*cdf0e10cSrcweir res &= false; 193*cdf0e10cSrcweir } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 194*cdf0e10cSrcweir log.println("expected exception => OK"); 195*cdf0e10cSrcweir curText = oObj.getText(); 196*cdf0e10cSrcweir log.println("Current text: '" + curText + "'"); 197*cdf0e10cSrcweir res &= curText.equals(text); 198*cdf0e10cSrcweir } 199*cdf0e10cSrcweir 200*cdf0e10cSrcweir try { 201*cdf0e10cSrcweir log.print("pasteText(" + (length) + "): "); 202*cdf0e10cSrcweir locRes = oObj.pasteText(length); 203*cdf0e10cSrcweir log.println(locRes); 204*cdf0e10cSrcweir curText = oObj.getText(); 205*cdf0e10cSrcweir log.println("Current text: '" + curText + "'"); 206*cdf0e10cSrcweir res &= curText.equals(text + pasteText) && locRes; 207*cdf0e10cSrcweir log.println("Expected text: '" + text + pasteText + "'"); 208*cdf0e10cSrcweir } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 209*cdf0e10cSrcweir log.println("unexpected exception"); 210*cdf0e10cSrcweir e.printStackTrace(log); 211*cdf0e10cSrcweir res &= false; 212*cdf0e10cSrcweir } 213*cdf0e10cSrcweir 214*cdf0e10cSrcweir tRes.tested("pasteText()", res); 215*cdf0e10cSrcweir } 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir /** 218*cdf0e10cSrcweir * Calls the method with the wrong indexes and with the correct indexes, 219*cdf0e10cSrcweir * checks text after method call. 220*cdf0e10cSrcweir * Has OK status if exceptions were thrown for the wrong indexes, 221*cdf0e10cSrcweir * if exception wasn't thrown for the correct indexes and if deleted string 222*cdf0e10cSrcweir * was really deleted from the text. 223*cdf0e10cSrcweir * The following method tests are to be executed before: 224*cdf0e10cSrcweir * <ul> 225*cdf0e10cSrcweir * <li> <code>insertText()</code> </li> 226*cdf0e10cSrcweir * </ul> 227*cdf0e10cSrcweir */ 228*cdf0e10cSrcweir public void _deleteText() { 229*cdf0e10cSrcweir executeMethod("insertText()"); 230*cdf0e10cSrcweir boolean res = true; 231*cdf0e10cSrcweir boolean locRes = true; 232*cdf0e10cSrcweir String curText = null; 233*cdf0e10cSrcweir 234*cdf0e10cSrcweir String text = oObj.getText(); 235*cdf0e10cSrcweir log.println("Text: '" + text + "'"); 236*cdf0e10cSrcweir int length = oObj.getCharacterCount(); 237*cdf0e10cSrcweir log.println("Character count: " + length); 238*cdf0e10cSrcweir 239*cdf0e10cSrcweir try { 240*cdf0e10cSrcweir log.print("deleteText(-1," + length + "): "); 241*cdf0e10cSrcweir locRes = oObj.deleteText(-1, length); 242*cdf0e10cSrcweir log.println(locRes); 243*cdf0e10cSrcweir log.println("exception was expected => FAILED"); 244*cdf0e10cSrcweir res &= false; 245*cdf0e10cSrcweir } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 246*cdf0e10cSrcweir log.println("expected exception => OK"); 247*cdf0e10cSrcweir curText = oObj.getText(); 248*cdf0e10cSrcweir log.println("Current text: '" + curText + "'"); 249*cdf0e10cSrcweir res &= curText.equals(text); 250*cdf0e10cSrcweir } 251*cdf0e10cSrcweir 252*cdf0e10cSrcweir try { 253*cdf0e10cSrcweir log.print("deleteText(0," + (length+1) + "): "); 254*cdf0e10cSrcweir locRes = oObj.deleteText(0, length + 1); 255*cdf0e10cSrcweir log.println(locRes); 256*cdf0e10cSrcweir log.println("exception was expected => FAILED"); 257*cdf0e10cSrcweir res &= false; 258*cdf0e10cSrcweir } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 259*cdf0e10cSrcweir log.println("expected exception => OK"); 260*cdf0e10cSrcweir curText = oObj.getText(); 261*cdf0e10cSrcweir log.println("Current text: '" + curText + "'"); 262*cdf0e10cSrcweir res &= curText.equals(text); 263*cdf0e10cSrcweir } 264*cdf0e10cSrcweir 265*cdf0e10cSrcweir try { 266*cdf0e10cSrcweir if (length >= 1) { 267*cdf0e10cSrcweir log.print("deleteText(" + (length-1) + "," + (length) + "): "); 268*cdf0e10cSrcweir locRes = oObj.deleteText(length - 1, length); 269*cdf0e10cSrcweir log.println(locRes); 270*cdf0e10cSrcweir String expStr = expStr = text.substring(0, length - 1); 271*cdf0e10cSrcweir curText = oObj.getText(); 272*cdf0e10cSrcweir log.println("Current text: '" + curText + "'"); 273*cdf0e10cSrcweir res &= curText.equals(expStr); 274*cdf0e10cSrcweir log.println("Expected text: '" + expStr + "'"); 275*cdf0e10cSrcweir } 276*cdf0e10cSrcweir } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 277*cdf0e10cSrcweir log.println("unexpected exception"); 278*cdf0e10cSrcweir e.printStackTrace(log); 279*cdf0e10cSrcweir res &= false; 280*cdf0e10cSrcweir } 281*cdf0e10cSrcweir 282*cdf0e10cSrcweir tRes.tested("deleteText()", res); 283*cdf0e10cSrcweir } 284*cdf0e10cSrcweir 285*cdf0e10cSrcweir /** 286*cdf0e10cSrcweir * Calls the method with the wrong indexes and with the correct indexes, 287*cdf0e10cSrcweir * checks text after method call. 288*cdf0e10cSrcweir * Has OK status if exceptions were thrown for the wrong indexes, 289*cdf0e10cSrcweir * if exception wasn't thrown for the correct indexes and if inserted string 290*cdf0e10cSrcweir * was really inserted into the text. 291*cdf0e10cSrcweir * The following method tests are to be executed before: 292*cdf0e10cSrcweir * <ul> 293*cdf0e10cSrcweir * <li> <code>pasteText()</code> </li> 294*cdf0e10cSrcweir * </ul> 295*cdf0e10cSrcweir */ 296*cdf0e10cSrcweir public void _insertText() { 297*cdf0e10cSrcweir executeMethod("pasteText()"); 298*cdf0e10cSrcweir boolean res = true; 299*cdf0e10cSrcweir boolean locRes = true; 300*cdf0e10cSrcweir String curText = null; 301*cdf0e10cSrcweir 302*cdf0e10cSrcweir String text = oObj.getText(); 303*cdf0e10cSrcweir log.println("Text: '" + text + "'"); 304*cdf0e10cSrcweir int length = oObj.getCharacterCount(); 305*cdf0e10cSrcweir log.println("Character count: " + length); 306*cdf0e10cSrcweir 307*cdf0e10cSrcweir final String insStr = "Inserted string"; 308*cdf0e10cSrcweir 309*cdf0e10cSrcweir try { 310*cdf0e10cSrcweir log.print("insertText(insStr, -1): "); 311*cdf0e10cSrcweir locRes = oObj.insertText(insStr, -1); 312*cdf0e10cSrcweir log.println(locRes); 313*cdf0e10cSrcweir log.println("exception was expected=> FAILED"); 314*cdf0e10cSrcweir res &= false; 315*cdf0e10cSrcweir } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 316*cdf0e10cSrcweir log.println("expected exception => OK"); 317*cdf0e10cSrcweir curText = oObj.getText(); 318*cdf0e10cSrcweir log.println("Current text: '" + curText + "'"); 319*cdf0e10cSrcweir res &= curText.equals(text); 320*cdf0e10cSrcweir } 321*cdf0e10cSrcweir 322*cdf0e10cSrcweir try { 323*cdf0e10cSrcweir log.print("insertText(insStr," + (length+1) + "): "); 324*cdf0e10cSrcweir locRes = oObj.insertText(insStr, length+1); 325*cdf0e10cSrcweir log.println(locRes); 326*cdf0e10cSrcweir log.println("exception was expected => FAILED"); 327*cdf0e10cSrcweir res &= false; 328*cdf0e10cSrcweir } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 329*cdf0e10cSrcweir log.println("expected exception => OK"); 330*cdf0e10cSrcweir curText = oObj.getText(); 331*cdf0e10cSrcweir log.println("Current text: '" + curText + "'"); 332*cdf0e10cSrcweir res &= curText.equals(text); 333*cdf0e10cSrcweir } 334*cdf0e10cSrcweir 335*cdf0e10cSrcweir try { 336*cdf0e10cSrcweir log.print("insertText(insStr," + length + "): "); 337*cdf0e10cSrcweir locRes = oObj.insertText(insStr, length); 338*cdf0e10cSrcweir log.println(locRes); 339*cdf0e10cSrcweir curText = oObj.getText(); 340*cdf0e10cSrcweir res &= curText.equals(text + insStr); 341*cdf0e10cSrcweir log.println("Current text: '" + curText + "'"); 342*cdf0e10cSrcweir log.println("Expected text: '" + text + insStr + "'"); 343*cdf0e10cSrcweir } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 344*cdf0e10cSrcweir log.println("unexpected exception => FAILED"); 345*cdf0e10cSrcweir e.printStackTrace(log); 346*cdf0e10cSrcweir res &= false; 347*cdf0e10cSrcweir } 348*cdf0e10cSrcweir 349*cdf0e10cSrcweir tRes.tested("insertText()", res); 350*cdf0e10cSrcweir } 351*cdf0e10cSrcweir 352*cdf0e10cSrcweir /** 353*cdf0e10cSrcweir * Calls the method with the wrong indexes and with the correct indexes, 354*cdf0e10cSrcweir * checks text after method call. 355*cdf0e10cSrcweir * Has OK status if exceptions were thrown for the wrong indexes, 356*cdf0e10cSrcweir * if exception wasn't thrown for the correct indexes and if part of text 357*cdf0e10cSrcweir * was really replaced by the specified replacement string. 358*cdf0e10cSrcweir * The following method tests are to be executed before: 359*cdf0e10cSrcweir * <ul> 360*cdf0e10cSrcweir * <li> <code>deleteText()</code> </li> 361*cdf0e10cSrcweir * </ul> 362*cdf0e10cSrcweir */ 363*cdf0e10cSrcweir public void _replaceText() { 364*cdf0e10cSrcweir executeMethod("deleteText()"); 365*cdf0e10cSrcweir boolean res = true; 366*cdf0e10cSrcweir boolean locRes = true; 367*cdf0e10cSrcweir String curText = null; 368*cdf0e10cSrcweir 369*cdf0e10cSrcweir final String sReplacement = "String for replace"; 370*cdf0e10cSrcweir String oldText = oObj.getText(); 371*cdf0e10cSrcweir int startIndx = oldText.length(); 372*cdf0e10cSrcweir oObj.setText(oldText + " part of string for replace"); 373*cdf0e10cSrcweir 374*cdf0e10cSrcweir String text = oObj.getText(); 375*cdf0e10cSrcweir log.println("Text: '" + text + "'"); 376*cdf0e10cSrcweir int length = oObj.getCharacterCount(); 377*cdf0e10cSrcweir log.println("Character count: " + length); 378*cdf0e10cSrcweir 379*cdf0e10cSrcweir try { 380*cdf0e10cSrcweir log.print("replaceText(-1," + length + "): "); 381*cdf0e10cSrcweir locRes = oObj.replaceText(-1, length, sReplacement); 382*cdf0e10cSrcweir log.println(locRes); 383*cdf0e10cSrcweir log.println("exception was expected => FAILED"); 384*cdf0e10cSrcweir res &= false; 385*cdf0e10cSrcweir } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 386*cdf0e10cSrcweir log.println("expected exception => OK"); 387*cdf0e10cSrcweir curText = oObj.getText(); 388*cdf0e10cSrcweir log.println("Current text: '" + curText + "'"); 389*cdf0e10cSrcweir res &= curText.equals(text); 390*cdf0e10cSrcweir } 391*cdf0e10cSrcweir 392*cdf0e10cSrcweir try { 393*cdf0e10cSrcweir log.print("replaceText(0," + (length+1) + "): "); 394*cdf0e10cSrcweir locRes = oObj.replaceText(0, length + 1, sReplacement); 395*cdf0e10cSrcweir log.println(locRes); 396*cdf0e10cSrcweir log.println("exception was expected => FAILED"); 397*cdf0e10cSrcweir res &= false; 398*cdf0e10cSrcweir } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 399*cdf0e10cSrcweir log.println("expected exception => OK"); 400*cdf0e10cSrcweir curText = oObj.getText(); 401*cdf0e10cSrcweir log.println("Current text: '" + curText + "'"); 402*cdf0e10cSrcweir res &= curText.equals(text); 403*cdf0e10cSrcweir } 404*cdf0e10cSrcweir 405*cdf0e10cSrcweir try { 406*cdf0e10cSrcweir log.print("replaceText(" + startIndx + "," + length + "): "); 407*cdf0e10cSrcweir locRes = oObj.replaceText(startIndx, length, sReplacement); 408*cdf0e10cSrcweir log.println(locRes); 409*cdf0e10cSrcweir curText = oObj.getText(); 410*cdf0e10cSrcweir log.println("Current text: '" + curText + "'"); 411*cdf0e10cSrcweir log.println("Expected text: '" + oldText + sReplacement + "'"); 412*cdf0e10cSrcweir res &= curText.equals(oldText + sReplacement); 413*cdf0e10cSrcweir } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 414*cdf0e10cSrcweir log.println("unexpected exception"); 415*cdf0e10cSrcweir e.printStackTrace(log); 416*cdf0e10cSrcweir res &= false; 417*cdf0e10cSrcweir } 418*cdf0e10cSrcweir 419*cdf0e10cSrcweir tRes.tested("replaceText()", res); 420*cdf0e10cSrcweir } 421*cdf0e10cSrcweir 422*cdf0e10cSrcweir /** 423*cdf0e10cSrcweir * Calls the method with the wrong indexes and with the correct indexes, 424*cdf0e10cSrcweir * checks attributes after method call. 425*cdf0e10cSrcweir * Has OK status if exceptions were thrown for the wrong indexes, 426*cdf0e10cSrcweir * if exception wasn't thrown for the correct indexes and if attributes 427*cdf0e10cSrcweir * of text was changed. 428*cdf0e10cSrcweir * The following method tests are to be executed before: 429*cdf0e10cSrcweir * <ul> 430*cdf0e10cSrcweir * <li> <code>replaceText()</code> </li> 431*cdf0e10cSrcweir * </ul> 432*cdf0e10cSrcweir */ 433*cdf0e10cSrcweir public void _setAttributes() { 434*cdf0e10cSrcweir executeMethod("replaceText()"); 435*cdf0e10cSrcweir boolean res = true; 436*cdf0e10cSrcweir boolean locRes = true; 437*cdf0e10cSrcweir 438*cdf0e10cSrcweir String text = oObj.getText(); 439*cdf0e10cSrcweir log.println("Text: '" + text + "'"); 440*cdf0e10cSrcweir int length = oObj.getCharacterCount(); 441*cdf0e10cSrcweir log.println("Length: " + length); 442*cdf0e10cSrcweir 443*cdf0e10cSrcweir PropertyValue[] attrs = null; 444*cdf0e10cSrcweir 445*cdf0e10cSrcweir try { 446*cdf0e10cSrcweir attrs = oObj.getCharacterAttributes(0, new String[]{""}); 447*cdf0e10cSrcweir log.print("setAttributes(-1," + (length - 1) + "):"); 448*cdf0e10cSrcweir locRes = oObj.setAttributes(-1, length - 1, attrs); 449*cdf0e10cSrcweir log.println(locRes); 450*cdf0e10cSrcweir log.println("exception was expected => FAILED"); 451*cdf0e10cSrcweir res &= false; 452*cdf0e10cSrcweir } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 453*cdf0e10cSrcweir log.println("expected exception => OK"); 454*cdf0e10cSrcweir res &= true; 455*cdf0e10cSrcweir } 456*cdf0e10cSrcweir 457*cdf0e10cSrcweir try { 458*cdf0e10cSrcweir log.print("setAttributes(0," + (length+1) + "):"); 459*cdf0e10cSrcweir locRes = oObj.setAttributes(0, length + 1, attrs); 460*cdf0e10cSrcweir log.println(locRes); 461*cdf0e10cSrcweir log.println("exception was expected => FAILED"); 462*cdf0e10cSrcweir res &= false; 463*cdf0e10cSrcweir } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 464*cdf0e10cSrcweir log.println("expected exception => OK"); 465*cdf0e10cSrcweir res &= true; 466*cdf0e10cSrcweir } 467*cdf0e10cSrcweir 468*cdf0e10cSrcweir //change old attributes set 469*cdf0e10cSrcweir for(int i = 0; i < attrs.length; i++) { 470*cdf0e10cSrcweir if (attrs[i].Name.equals("CharColor")) { 471*cdf0e10cSrcweir attrs[i].Value = new Integer(-2); 472*cdf0e10cSrcweir } 473*cdf0e10cSrcweir } 474*cdf0e10cSrcweir 475*cdf0e10cSrcweir try { 476*cdf0e10cSrcweir log.print("setAttributes(0," + length + "):"); 477*cdf0e10cSrcweir locRes = oObj.setAttributes(0, length, attrs); 478*cdf0e10cSrcweir log.println(locRes); 479*cdf0e10cSrcweir res &= (changeableAttr && locRes) 480*cdf0e10cSrcweir || (!changeableAttr && !locRes); 481*cdf0e10cSrcweir if (changeableAttr) { 482*cdf0e10cSrcweir log.print("checking that new attributes was set..."); 483*cdf0e10cSrcweir PropertyValue[] newAttrs = oObj.getCharacterAttributes(0, new String[]{""}); 484*cdf0e10cSrcweir locRes = ValueComparer.equalValue(attrs, newAttrs); 485*cdf0e10cSrcweir log.println(locRes); 486*cdf0e10cSrcweir res &= locRes; 487*cdf0e10cSrcweir } else { 488*cdf0e10cSrcweir log.println("Text attributes can't be changed."); 489*cdf0e10cSrcweir } 490*cdf0e10cSrcweir } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 491*cdf0e10cSrcweir log.println("unexpected exception => FAILED"); 492*cdf0e10cSrcweir e.printStackTrace(log); 493*cdf0e10cSrcweir res &= false; 494*cdf0e10cSrcweir } 495*cdf0e10cSrcweir 496*cdf0e10cSrcweir tRes.tested("setAttributes()", res); 497*cdf0e10cSrcweir } 498*cdf0e10cSrcweir 499*cdf0e10cSrcweir /** 500*cdf0e10cSrcweir * Calls the method with different parameters and checks text. 501*cdf0e10cSrcweir */ 502*cdf0e10cSrcweir public void _setText() { 503*cdf0e10cSrcweir executeMethod("setAttributes()"); 504*cdf0e10cSrcweir boolean res = true; 505*cdf0e10cSrcweir boolean locRes = true; 506*cdf0e10cSrcweir 507*cdf0e10cSrcweir String oldText = oObj.getText(); 508*cdf0e10cSrcweir log.println("Current text: '" + oldText + "'"); 509*cdf0e10cSrcweir 510*cdf0e10cSrcweir String newText = "New text"; 511*cdf0e10cSrcweir log.print("setText('" + newText + "'): "); 512*cdf0e10cSrcweir locRes = oObj.setText(newText); 513*cdf0e10cSrcweir log.println(locRes); 514*cdf0e10cSrcweir String newCurText = oObj.getText(); 515*cdf0e10cSrcweir log.println("getText(): '" + newCurText + "'"); 516*cdf0e10cSrcweir res &= locRes && newCurText.equals(newText); 517*cdf0e10cSrcweir 518*cdf0e10cSrcweir newText = ""; 519*cdf0e10cSrcweir log.print("setText('" + newText + "'): "); 520*cdf0e10cSrcweir locRes = oObj.setText(newText); 521*cdf0e10cSrcweir log.println(locRes); 522*cdf0e10cSrcweir newCurText = oObj.getText(); 523*cdf0e10cSrcweir log.println("getText(): '" + newCurText + "'"); 524*cdf0e10cSrcweir res &= locRes && newCurText.equals(newText); 525*cdf0e10cSrcweir 526*cdf0e10cSrcweir log.print("setText('" + oldText + "'): "); 527*cdf0e10cSrcweir locRes = oObj.setText(oldText); 528*cdf0e10cSrcweir log.println(locRes); 529*cdf0e10cSrcweir newCurText = oObj.getText(); 530*cdf0e10cSrcweir log.println("getText(): '" + newCurText + "'"); 531*cdf0e10cSrcweir res &= locRes && newCurText.equals(oldText); 532*cdf0e10cSrcweir 533*cdf0e10cSrcweir tRes.tested("setText()", res); 534*cdf0e10cSrcweir } 535*cdf0e10cSrcweir 536*cdf0e10cSrcweir /** 537*cdf0e10cSrcweir * Restores initial component text. 538*cdf0e10cSrcweir */ 539*cdf0e10cSrcweir protected void after() { 540*cdf0e10cSrcweir oObj.setText(initialText); 541*cdf0e10cSrcweir } 542*cdf0e10cSrcweir }