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