1*1b0aaa91SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*1b0aaa91SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*1b0aaa91SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*1b0aaa91SAndrew Rist * distributed with this work for additional information 6*1b0aaa91SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*1b0aaa91SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*1b0aaa91SAndrew Rist * "License"); you may not use this file except in compliance 9*1b0aaa91SAndrew Rist * with the License. You may obtain a copy of the License at 10*1b0aaa91SAndrew Rist * 11*1b0aaa91SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*1b0aaa91SAndrew Rist * 13*1b0aaa91SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*1b0aaa91SAndrew Rist * software distributed under the License is distributed on an 15*1b0aaa91SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*1b0aaa91SAndrew Rist * KIND, either express or implied. See the License for the 17*1b0aaa91SAndrew Rist * specific language governing permissions and limitations 18*1b0aaa91SAndrew Rist * under the License. 19*1b0aaa91SAndrew Rist * 20*1b0aaa91SAndrew Rist *************************************************************/ 21*1b0aaa91SAndrew Rist 22*1b0aaa91SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir package complex.toolkit.accessibility; 25cdf0e10cSrcweir 26cdf0e10cSrcweir import com.sun.star.accessibility.XAccessibleText; 27cdf0e10cSrcweir // import lib.MultiMethodTest; 28cdf0e10cSrcweir //import lib.StatusException; 29cdf0e10cSrcweir //import lib.Status; 30cdf0e10cSrcweir import com.sun.star.beans.PropertyValue; 31cdf0e10cSrcweir import com.sun.star.awt.Rectangle; 32cdf0e10cSrcweir import com.sun.star.awt.Point; 33cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 34cdf0e10cSrcweir import com.sun.star.accessibility.AccessibleTextType; 35cdf0e10cSrcweir import com.sun.star.accessibility.TextSegment; 36cdf0e10cSrcweir import com.sun.star.uno.XInterface; 37cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 38cdf0e10cSrcweir // import share.LogWriter; 39cdf0e10cSrcweir 40cdf0e10cSrcweir /** 41cdf0e10cSrcweir * Testing <code>com.sun.star.accessibility.XAccessibleText</code> 42cdf0e10cSrcweir * interface methods : 43cdf0e10cSrcweir * <ul> 44cdf0e10cSrcweir * <li><code> getCaretPosition()</code></li> 45cdf0e10cSrcweir * <li><code> setCaretPosition()</code></li> 46cdf0e10cSrcweir * <li><code> getCharacter()</code></li> 47cdf0e10cSrcweir * <li><code> getCharacterAttributes()</code></li> 48cdf0e10cSrcweir * <li><code> getCharacterBounds()</code></li> 49cdf0e10cSrcweir * <li><code> getCharacterCount()</code></li> 50cdf0e10cSrcweir * <li><code> getIndexAtPoint()</code></li> 51cdf0e10cSrcweir * <li><code> getSelectedText()</code></li> 52cdf0e10cSrcweir * <li><code> getSelectionStart()</code></li> 53cdf0e10cSrcweir * <li><code> getSelectionEnd()</code></li> 54cdf0e10cSrcweir * <li><code> setSelection()</code></li> 55cdf0e10cSrcweir * <li><code> getText()</code></li> 56cdf0e10cSrcweir * <li><code> getTextRange()</code></li> 57cdf0e10cSrcweir * <li><code> getTextAtIndex()</code></li> 58cdf0e10cSrcweir * <li><code> getTextBeforeIndex()</code></li> 59cdf0e10cSrcweir * <li><code> getTextBehindIndex()</code></li> 60cdf0e10cSrcweir * <li><code> copyText()</code></li> 61cdf0e10cSrcweir * </ul> <p> 62cdf0e10cSrcweir * This test needs the following object relations : 63cdf0e10cSrcweir * <ul> 64cdf0e10cSrcweir * <li> <code>'XAccessibleText.Text'</code> (of type <code>String</code>) 65cdf0e10cSrcweir * <b> optional </b> : 66cdf0e10cSrcweir * the string presentation of component's text. If the relation 67cdf0e10cSrcweir * is not specified, then text from method <code>getText()</code> 68cdf0e10cSrcweir * is used. 69cdf0e10cSrcweir * </li> 70cdf0e10cSrcweir * </ul> <p> 71cdf0e10cSrcweir * @see com.sun.star.accessibility.XAccessibleText 72cdf0e10cSrcweir */ 73cdf0e10cSrcweir public class _XAccessibleText { 74cdf0e10cSrcweir 75cdf0e10cSrcweir // private LogWriter log; 76cdf0e10cSrcweir 77cdf0e10cSrcweir private static final String className = 78cdf0e10cSrcweir "com.sun.star.accessibility.XAccessibleText" ; 79cdf0e10cSrcweir 80cdf0e10cSrcweir public XAccessibleText oObj = null; 81cdf0e10cSrcweir private XMultiServiceFactory xMSF; 82cdf0e10cSrcweir 83cdf0e10cSrcweir Rectangle chBounds = null; 84cdf0e10cSrcweir int chCount = 0; 85cdf0e10cSrcweir 86cdf0e10cSrcweir String text = null; 87cdf0e10cSrcweir String editOnly = null; 88cdf0e10cSrcweir 89cdf0e10cSrcweir _XAccessibleText(XInterface object, XMultiServiceFactory xMSF, String editOnly)90cdf0e10cSrcweir public _XAccessibleText(XInterface object, XMultiServiceFactory xMSF, String editOnly) { 91cdf0e10cSrcweir oObj = UnoRuntime.queryInterface(XAccessibleText.class, object); 92cdf0e10cSrcweir this.xMSF = xMSF; 93cdf0e10cSrcweir // this.log = log; 94cdf0e10cSrcweir this.editOnly = editOnly; 95cdf0e10cSrcweir } 96cdf0e10cSrcweir 97cdf0e10cSrcweir 98cdf0e10cSrcweir /** 99cdf0e10cSrcweir * Calls the method and checks returned value. 100cdf0e10cSrcweir * Has OK status if returned value is equal to <code>chCount - 1</code>. 101cdf0e10cSrcweir * The following method tests are to be executed before: 102cdf0e10cSrcweir * <ul> 103cdf0e10cSrcweir * <li> <code>setCaretPosition()</code> </li> 104cdf0e10cSrcweir * </ul> 105cdf0e10cSrcweir * @return 106cdf0e10cSrcweir */ _getCaretPosition()107cdf0e10cSrcweir public boolean _getCaretPosition() { 108cdf0e10cSrcweir 109cdf0e10cSrcweir if (editOnly != null) { 110cdf0e10cSrcweir System.out.println(editOnly); 111cdf0e10cSrcweir return true; 112cdf0e10cSrcweir } 113cdf0e10cSrcweir 114cdf0e10cSrcweir boolean res = true; 115cdf0e10cSrcweir if ( chCount > 0 ) { 116cdf0e10cSrcweir try { 117cdf0e10cSrcweir oObj.setCaretPosition(chCount - 1); 118cdf0e10cSrcweir } catch (com.sun.star.lang.IndexOutOfBoundsException ie) { 119cdf0e10cSrcweir 120cdf0e10cSrcweir } 121cdf0e10cSrcweir int carPos = oObj.getCaretPosition(); 122cdf0e10cSrcweir System.out.println("getCaretPosition: " + carPos); 123cdf0e10cSrcweir res = carPos == (chCount - 1); 124cdf0e10cSrcweir } 125cdf0e10cSrcweir return res; 126cdf0e10cSrcweir } 127cdf0e10cSrcweir 128cdf0e10cSrcweir /** 129cdf0e10cSrcweir * Calls the method with the wrong index and with the correct index 130cdf0e10cSrcweir * <code>chCount - 1</code>. 131cdf0e10cSrcweir * Has OK status if exception was thrown for wrong index and 132cdf0e10cSrcweir * if exception wasn't thrown for the correct index. 133cdf0e10cSrcweir * The following method tests are to be executed before: 134cdf0e10cSrcweir * <ul> 135cdf0e10cSrcweir * <li> <code>getCharacterCount()</code> </li> 136cdf0e10cSrcweir * </ul> 137cdf0e10cSrcweir * @return 138cdf0e10cSrcweir */ _setCaretPosition()139cdf0e10cSrcweir public boolean _setCaretPosition() { 140cdf0e10cSrcweir boolean res = true; 141cdf0e10cSrcweir 142cdf0e10cSrcweir try { 143cdf0e10cSrcweir System.out.println("setCaretPosition(-1):"); 144cdf0e10cSrcweir oObj.setCaretPosition(-1); 145cdf0e10cSrcweir res &= false; 146cdf0e10cSrcweir System.out.println("exception was expected"); 147cdf0e10cSrcweir } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 148cdf0e10cSrcweir System.out.println("expected exception"); 149cdf0e10cSrcweir res &= true; 150cdf0e10cSrcweir } 151cdf0e10cSrcweir 152cdf0e10cSrcweir try { 153cdf0e10cSrcweir System.out.println("setCaretPosition(chCount+1):"); 154cdf0e10cSrcweir oObj.setCaretPosition(chCount+1); 155cdf0e10cSrcweir res &= false; 156cdf0e10cSrcweir System.out.println("exception was expected"); 157cdf0e10cSrcweir } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 158cdf0e10cSrcweir System.out.println("expected exception"); 159cdf0e10cSrcweir res &= true; 160cdf0e10cSrcweir } 161cdf0e10cSrcweir if ( chCount > 0 ) { 162cdf0e10cSrcweir try { 163cdf0e10cSrcweir System.out.println("setCaretPosition(chCount - 1)"); 164cdf0e10cSrcweir oObj.setCaretPosition(chCount - 1); 165cdf0e10cSrcweir res &= true; 166cdf0e10cSrcweir } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 167cdf0e10cSrcweir System.out.println("unexpected exception"); 168cdf0e10cSrcweir e.printStackTrace(); 169cdf0e10cSrcweir res &= false; 170cdf0e10cSrcweir } 171cdf0e10cSrcweir } 172cdf0e10cSrcweir 173cdf0e10cSrcweir return res; 174cdf0e10cSrcweir } 175cdf0e10cSrcweir 176cdf0e10cSrcweir /** 177cdf0e10cSrcweir * Calls the method with the wrong index and with the correct indexes. 178cdf0e10cSrcweir * Checks every character in the text. 179cdf0e10cSrcweir * Has OK status if exception was thrown for wrong index, 180cdf0e10cSrcweir * if exception wasn't thrown for the correct index and 181cdf0e10cSrcweir * if every character is equal to corresponding character in the text. 182cdf0e10cSrcweir * The following method tests are to be executed before: 183cdf0e10cSrcweir * <ul> 184cdf0e10cSrcweir * <li> <code>getCharacterCount()</code> </li> 185cdf0e10cSrcweir * </ul> 186cdf0e10cSrcweir * @return 187cdf0e10cSrcweir */ _getCharacter()188cdf0e10cSrcweir public boolean _getCharacter() { 189cdf0e10cSrcweir boolean res = true; 190cdf0e10cSrcweir 191cdf0e10cSrcweir try { 192cdf0e10cSrcweir System.out.println("getCharacter(-1)"); 193cdf0e10cSrcweir oObj.getCharacter(-1); 194cdf0e10cSrcweir System.out.println("Exception was expected"); 195cdf0e10cSrcweir res = false; 196cdf0e10cSrcweir } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 197cdf0e10cSrcweir System.out.println("Expected exception"); 198cdf0e10cSrcweir res = true; 199cdf0e10cSrcweir } 200cdf0e10cSrcweir 201cdf0e10cSrcweir try { 202cdf0e10cSrcweir System.out.println("getCharacter(chCount)"); 203cdf0e10cSrcweir oObj.getCharacter(chCount); 204cdf0e10cSrcweir System.out.println("Exception was expected"); 205cdf0e10cSrcweir res &= false; 206cdf0e10cSrcweir } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 207cdf0e10cSrcweir System.out.println("Expected exception"); 208cdf0e10cSrcweir res &= true; 209cdf0e10cSrcweir } 210cdf0e10cSrcweir 211cdf0e10cSrcweir try { 212cdf0e10cSrcweir System.out.println("Checking of every character in the text..."); 213cdf0e10cSrcweir boolean isEqCh = true; 214cdf0e10cSrcweir for(int i = 0; i < chCount; i++) { 215cdf0e10cSrcweir char ch = oObj.getCharacter(i); 216cdf0e10cSrcweir isEqCh = ch == text.charAt(i); 217cdf0e10cSrcweir res &= isEqCh; 218cdf0e10cSrcweir if (!isEqCh) { 219cdf0e10cSrcweir System.out.println("At the position " + i + 220cdf0e10cSrcweir "was expected character: " + text.charAt(i)); 221cdf0e10cSrcweir System.out.println("but was returned: " + ch); 222cdf0e10cSrcweir break; 223cdf0e10cSrcweir } 224cdf0e10cSrcweir } 225cdf0e10cSrcweir } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 226cdf0e10cSrcweir System.out.println("Unexpected exception"); 227cdf0e10cSrcweir e.printStackTrace(); 228cdf0e10cSrcweir res &= false; 229cdf0e10cSrcweir } 230cdf0e10cSrcweir 231cdf0e10cSrcweir return res; 232cdf0e10cSrcweir } 233cdf0e10cSrcweir 234cdf0e10cSrcweir /** 235cdf0e10cSrcweir * Calls the method with the wrong indexes and with the correct index, 236cdf0e10cSrcweir * checks a returned value. 237cdf0e10cSrcweir * Has OK status if exception was thrown for the wrong indexes, 238cdf0e10cSrcweir * if exception wasn't thrown for the correct index and 239cdf0e10cSrcweir * if returned value isn't <code>null</code>. 240cdf0e10cSrcweir * The following method tests are to be executed before: 241cdf0e10cSrcweir * <ul> 242cdf0e10cSrcweir * <li> <code>getCharacterCount()</code> </li> 243cdf0e10cSrcweir * </ul> 244cdf0e10cSrcweir * @return 245cdf0e10cSrcweir */ _getCharacterAttributes()246cdf0e10cSrcweir public boolean _getCharacterAttributes() { 247cdf0e10cSrcweir boolean res = true; 248cdf0e10cSrcweir 249cdf0e10cSrcweir try { 250cdf0e10cSrcweir System.out.println("getCharacterAttributes(-1)"); 251cdf0e10cSrcweir oObj.getCharacterAttributes(-1, new String[0]); 252cdf0e10cSrcweir System.out.println("Exception was expected"); 253cdf0e10cSrcweir res &= false; 254cdf0e10cSrcweir } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 255cdf0e10cSrcweir System.out.println("Expected exception"); 256cdf0e10cSrcweir res &= true; 257cdf0e10cSrcweir } 258cdf0e10cSrcweir 259cdf0e10cSrcweir try { 260cdf0e10cSrcweir System.out.println("getCharacterAttributes(chCount)"); 261cdf0e10cSrcweir oObj.getCharacterAttributes(chCount, new String[0]); 262cdf0e10cSrcweir System.out.println("Exception was expected"); 263cdf0e10cSrcweir res &= false; 264cdf0e10cSrcweir } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 265cdf0e10cSrcweir System.out.println("Expected exception"); 266cdf0e10cSrcweir res &= true; 267cdf0e10cSrcweir } 268cdf0e10cSrcweir 269cdf0e10cSrcweir try { 270cdf0e10cSrcweir if ( chCount > 0 ) { 271cdf0e10cSrcweir System.out.println("getCharacterAttributes(chCount-1)"); 272cdf0e10cSrcweir PropertyValue[] props = oObj.getCharacterAttributes(chCount - 1, new String[0]); 273cdf0e10cSrcweir res &= props != null; 274cdf0e10cSrcweir } 275cdf0e10cSrcweir } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 276cdf0e10cSrcweir System.out.println("Unexpected exception"); 277cdf0e10cSrcweir e.printStackTrace(); 278cdf0e10cSrcweir res &= false; 279cdf0e10cSrcweir } 280cdf0e10cSrcweir 281cdf0e10cSrcweir return res; 282cdf0e10cSrcweir } 283cdf0e10cSrcweir 284cdf0e10cSrcweir 285cdf0e10cSrcweir /** 286cdf0e10cSrcweir * Calls the method with the wrong indexes and with the correct index. 287cdf0e10cSrcweir * checks and stores a returned value. 288cdf0e10cSrcweir * Has OK status if exception was thrown for the wrong indexes, 289cdf0e10cSrcweir * if exception wasn't thrown for the correct index and 290cdf0e10cSrcweir * if returned value isn't <code>null</code>. 291cdf0e10cSrcweir * The following method tests are to be executed before: 292cdf0e10cSrcweir * <ul> 293cdf0e10cSrcweir * <li> <code>getCharacterCount()</code> </li> 294cdf0e10cSrcweir * </ul> 295cdf0e10cSrcweir * @return 296cdf0e10cSrcweir */ _getCharacterBounds()297cdf0e10cSrcweir public boolean _getCharacterBounds() { 298cdf0e10cSrcweir boolean res = true; 299cdf0e10cSrcweir 300cdf0e10cSrcweir try { 301cdf0e10cSrcweir System.out.println("getCharacterBounds(-1)"); 302cdf0e10cSrcweir oObj.getCharacterBounds(-1); 303cdf0e10cSrcweir System.out.println("Exception was expected"); 304cdf0e10cSrcweir res &= false; 305cdf0e10cSrcweir } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 306cdf0e10cSrcweir System.out.println("Expected exception"); 307cdf0e10cSrcweir res &= true; 308cdf0e10cSrcweir } 309cdf0e10cSrcweir 310cdf0e10cSrcweir try { 311cdf0e10cSrcweir System.out.println("getCharacterBounds(chCount)"); 312cdf0e10cSrcweir oObj.getCharacterBounds(chCount); 313cdf0e10cSrcweir System.out.println("Exception was expected"); 314cdf0e10cSrcweir res &= false; 315cdf0e10cSrcweir } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 316cdf0e10cSrcweir System.out.println("Expected exception"); 317cdf0e10cSrcweir res &= true; 318cdf0e10cSrcweir } 319cdf0e10cSrcweir 320cdf0e10cSrcweir try { 321cdf0e10cSrcweir if (chCount > 0) { 322cdf0e10cSrcweir System.out.println("getCharacterBounds(chCount-1)"); 323cdf0e10cSrcweir chBounds = oObj.getCharacterBounds(chCount-1); 324cdf0e10cSrcweir res &= chBounds != null; 325cdf0e10cSrcweir System.out.println("rect: " + chBounds.X + ", " + chBounds.Y + ", " + 326cdf0e10cSrcweir chBounds.Width + ", " + chBounds.Height); 327cdf0e10cSrcweir } 328cdf0e10cSrcweir 329cdf0e10cSrcweir } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 330cdf0e10cSrcweir System.out.println("Unexpected exception"); 331cdf0e10cSrcweir e.printStackTrace(); 332cdf0e10cSrcweir res &= false; 333cdf0e10cSrcweir } 334cdf0e10cSrcweir 335cdf0e10cSrcweir return res; 336cdf0e10cSrcweir } 337cdf0e10cSrcweir 338cdf0e10cSrcweir 339cdf0e10cSrcweir /** 340cdf0e10cSrcweir * Calls the method and stores a returned value to the variable 341cdf0e10cSrcweir * <code>chCount</code>. 342cdf0e10cSrcweir * Has OK status if a returned value is equal to the text length. 343cdf0e10cSrcweir * @return 344cdf0e10cSrcweir */ _getCharacterCount()345cdf0e10cSrcweir public boolean _getCharacterCount() { 346cdf0e10cSrcweir chCount = oObj.getCharacterCount(); 347cdf0e10cSrcweir System.out.println("Character count:" + chCount); 348cdf0e10cSrcweir boolean res = chCount == text.length(); 349cdf0e10cSrcweir return res; 350cdf0e10cSrcweir } 351cdf0e10cSrcweir 352cdf0e10cSrcweir /** 353cdf0e10cSrcweir * Calls the method for an invalid point and for the point of rectangle 354cdf0e10cSrcweir * returned by the method <code>getCharacterBounds()</code>. 355cdf0e10cSrcweir * Has OK status if returned value is equal to <code>-1</code> for an 356cdf0e10cSrcweir * invalid point and if returned value is equal to <code>chCount-1</code> 357cdf0e10cSrcweir * for a valid point. 358cdf0e10cSrcweir * The following method tests are to be executed before: 359cdf0e10cSrcweir * <ul> 360cdf0e10cSrcweir * <li> <code>getCharacterBounds()</code> </li> 361cdf0e10cSrcweir * </ul> 362cdf0e10cSrcweir * @return 363cdf0e10cSrcweir */ _getIndexAtPoint()364cdf0e10cSrcweir public boolean _getIndexAtPoint() { 365cdf0e10cSrcweir 366cdf0e10cSrcweir boolean res = true; 367cdf0e10cSrcweir System.out.println("getIndexAtPoint(-1, -1):"); 368cdf0e10cSrcweir Point pt = new Point(-1, -1); 369cdf0e10cSrcweir int index = oObj.getIndexAtPoint(pt); 370cdf0e10cSrcweir System.out.println(Integer.toString(index)); 371cdf0e10cSrcweir res &= index == -1; 372cdf0e10cSrcweir 373cdf0e10cSrcweir if (chBounds != null) { 374cdf0e10cSrcweir pt = new Point(chBounds.X , chBounds.Y ); 375cdf0e10cSrcweir System.out.println("getIndexAtPoint(" + pt.X + ", " + pt.Y + "):"); 376cdf0e10cSrcweir index = oObj.getIndexAtPoint(pt); 377cdf0e10cSrcweir System.out.println(Integer.toString(index)); 378cdf0e10cSrcweir res &= index == (chCount - 1); 379cdf0e10cSrcweir } 380cdf0e10cSrcweir 381cdf0e10cSrcweir return res; 382cdf0e10cSrcweir } 383cdf0e10cSrcweir 384cdf0e10cSrcweir /** 385cdf0e10cSrcweir * Checks a returned values after different calls of the method 386cdf0e10cSrcweir * <code>setSelection()</code>. 387cdf0e10cSrcweir * The following method tests are to be executed before: 388cdf0e10cSrcweir * <ul> 389cdf0e10cSrcweir * <li> <code>setSelection()</code> </li> 390cdf0e10cSrcweir * </ul> 391cdf0e10cSrcweir * @return 392cdf0e10cSrcweir */ _getSelectedText()393cdf0e10cSrcweir public boolean _getSelectedText() { 394cdf0e10cSrcweir if (editOnly != null) { 395cdf0e10cSrcweir System.out.println(editOnly); 396cdf0e10cSrcweir return true; 397cdf0e10cSrcweir } 398cdf0e10cSrcweir 399cdf0e10cSrcweir boolean res = true; 400cdf0e10cSrcweir 401cdf0e10cSrcweir try { 402cdf0e10cSrcweir System.out.println("setSelection(0, 0)"); 403cdf0e10cSrcweir oObj.setSelection(0, 0); 404cdf0e10cSrcweir System.out.println("getSelectedText():"); 405cdf0e10cSrcweir String txt = oObj.getSelectedText(); 406cdf0e10cSrcweir System.out.println("'" + txt + "'"); 407cdf0e10cSrcweir res &= txt.length() == 0; 408cdf0e10cSrcweir 409cdf0e10cSrcweir System.out.println("setSelection(0, chCount)"); 410cdf0e10cSrcweir oObj.setSelection(0, chCount); 411cdf0e10cSrcweir System.out.println("getSelectedText():"); 412cdf0e10cSrcweir txt = oObj.getSelectedText(); 413cdf0e10cSrcweir System.out.println("'" + txt + "'"); 414cdf0e10cSrcweir res &= txt.equals(text); 415cdf0e10cSrcweir 416cdf0e10cSrcweir if (chCount > 2) { 417cdf0e10cSrcweir System.out.println("setSelection(1, chCount-1)"); 418cdf0e10cSrcweir oObj.setSelection(1, chCount - 1); 419cdf0e10cSrcweir System.out.println("getSelectedText():"); 420cdf0e10cSrcweir txt = oObj.getSelectedText(); 421cdf0e10cSrcweir System.out.println("'" + txt + "'"); 422cdf0e10cSrcweir res &= txt.equals(text.substring(1, chCount - 1)); 423cdf0e10cSrcweir } 424cdf0e10cSrcweir } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 425cdf0e10cSrcweir System.out.println("Unexpected exception"); 426cdf0e10cSrcweir e.printStackTrace(); 427cdf0e10cSrcweir res &= false; 428cdf0e10cSrcweir } 429cdf0e10cSrcweir 430cdf0e10cSrcweir return res; 431cdf0e10cSrcweir } 432cdf0e10cSrcweir 433cdf0e10cSrcweir /** 434cdf0e10cSrcweir * Checks a returned values after different calls of the method 435cdf0e10cSrcweir * <code>setSelection()</code>. 436cdf0e10cSrcweir * The following method tests are to be executed before: 437cdf0e10cSrcweir * <ul> 438cdf0e10cSrcweir * <li> <code>setSelection()</code> </li> 439cdf0e10cSrcweir * </ul> 440cdf0e10cSrcweir * @return 441cdf0e10cSrcweir */ _getSelectionStart()442cdf0e10cSrcweir public boolean _getSelectionStart() { 443cdf0e10cSrcweir if (editOnly != null) { 444cdf0e10cSrcweir System.out.println(editOnly); 445cdf0e10cSrcweir return true; 446cdf0e10cSrcweir } 447cdf0e10cSrcweir 448cdf0e10cSrcweir boolean res = true; 449cdf0e10cSrcweir 450cdf0e10cSrcweir try { 451cdf0e10cSrcweir System.out.println("setSelection(0, chCount)"); 452cdf0e10cSrcweir oObj.setSelection(0, chCount); 453cdf0e10cSrcweir int start = oObj.getSelectionStart(); 454cdf0e10cSrcweir System.out.println("getSelectionStart():" + start); 455cdf0e10cSrcweir res &= start == 0; 456cdf0e10cSrcweir 457cdf0e10cSrcweir if (chCount > 2) { 458cdf0e10cSrcweir System.out.println("setSelection(1, chCount-1)"); 459cdf0e10cSrcweir oObj.setSelection(1, chCount - 1); 460cdf0e10cSrcweir start = oObj.getSelectionStart(); 461cdf0e10cSrcweir System.out.println("getSelectionStart():" + start); 462cdf0e10cSrcweir res &= start == 1; 463cdf0e10cSrcweir } 464cdf0e10cSrcweir } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 465cdf0e10cSrcweir System.out.println("Unexpected exception"); 466cdf0e10cSrcweir e.printStackTrace(); 467cdf0e10cSrcweir res &= false; 468cdf0e10cSrcweir } 469cdf0e10cSrcweir 470cdf0e10cSrcweir return res; 471cdf0e10cSrcweir } 472cdf0e10cSrcweir 473cdf0e10cSrcweir /** 474cdf0e10cSrcweir * Checks a returned values after different calls of the method 475cdf0e10cSrcweir * <code>setSelection()</code>. 476cdf0e10cSrcweir * The following method tests are to be executed before: 477cdf0e10cSrcweir * <ul> 478cdf0e10cSrcweir * <li> <code>setSelection()</code> </li> 479cdf0e10cSrcweir * </ul> 480cdf0e10cSrcweir * @return 481cdf0e10cSrcweir */ _getSelectionEnd()482cdf0e10cSrcweir public boolean _getSelectionEnd() { 483cdf0e10cSrcweir if (editOnly != null) { 484cdf0e10cSrcweir System.out.println(editOnly); 485cdf0e10cSrcweir return true; 486cdf0e10cSrcweir } 487cdf0e10cSrcweir 488cdf0e10cSrcweir boolean res = true; 489cdf0e10cSrcweir 490cdf0e10cSrcweir try { 491cdf0e10cSrcweir System.out.println("setSelection(0, chCount)"); 492cdf0e10cSrcweir oObj.setSelection(0, chCount); 493cdf0e10cSrcweir int end = oObj.getSelectionEnd(); 494cdf0e10cSrcweir System.out.println("getSelectionEnd():" + end); 495cdf0e10cSrcweir res &= end == chCount; 496cdf0e10cSrcweir 497cdf0e10cSrcweir if (chCount > 2) { 498cdf0e10cSrcweir System.out.println("setSelection(1, chCount-1)"); 499cdf0e10cSrcweir oObj.setSelection(1, chCount - 1); 500cdf0e10cSrcweir end = oObj.getSelectionEnd(); 501cdf0e10cSrcweir System.out.println("getSelectionEnd():" + end); 502cdf0e10cSrcweir res &= end == chCount - 1; 503cdf0e10cSrcweir } 504cdf0e10cSrcweir } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 505cdf0e10cSrcweir System.out.println("Unexpected exception"); 506cdf0e10cSrcweir e.printStackTrace(); 507cdf0e10cSrcweir res &= false; 508cdf0e10cSrcweir } 509cdf0e10cSrcweir 510cdf0e10cSrcweir return res; 511cdf0e10cSrcweir } 512cdf0e10cSrcweir 513cdf0e10cSrcweir /** 514cdf0e10cSrcweir * Calls the method with invalid parameters an with valid parameters. 515cdf0e10cSrcweir * Has OK status if exception was thrown for invalid parameters, 516cdf0e10cSrcweir * if exception wasn't thrown for valid parameters. 517cdf0e10cSrcweir * The following method tests are to be executed before: 518cdf0e10cSrcweir * <ul> 519cdf0e10cSrcweir * <li> <code>getCharacterCount()</code> </li> 520cdf0e10cSrcweir * </ul> 521cdf0e10cSrcweir * @return 522cdf0e10cSrcweir */ _setSelection()523cdf0e10cSrcweir public boolean _setSelection() { 524cdf0e10cSrcweir boolean res = true; 525cdf0e10cSrcweir boolean locRes = true; 526cdf0e10cSrcweir 527cdf0e10cSrcweir if (editOnly != null) { 528cdf0e10cSrcweir System.out.println(editOnly); 529cdf0e10cSrcweir return true; 530cdf0e10cSrcweir } 531cdf0e10cSrcweir 532cdf0e10cSrcweir try { 533cdf0e10cSrcweir System.out.println("setSelection(-1, chCount-1):"); 534cdf0e10cSrcweir locRes = oObj.setSelection(-1, chCount - 1); 535cdf0e10cSrcweir System.out.println(locRes + " exception was expected"); 536cdf0e10cSrcweir res &= !locRes; 537cdf0e10cSrcweir } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 538cdf0e10cSrcweir System.out.println("Expected exception"); 539cdf0e10cSrcweir res &= true; 540cdf0e10cSrcweir } 541cdf0e10cSrcweir 542cdf0e10cSrcweir try { 543cdf0e10cSrcweir System.out.println("setSelection(0, chCount+1):"); 544cdf0e10cSrcweir locRes = oObj.setSelection(0, chCount + 1); 545cdf0e10cSrcweir System.out.println(locRes + " excepion was expected"); 546cdf0e10cSrcweir res &= !locRes; 547cdf0e10cSrcweir } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 548cdf0e10cSrcweir System.out.println("Expected exception"); 549cdf0e10cSrcweir res &= true; 550cdf0e10cSrcweir } 551cdf0e10cSrcweir 552cdf0e10cSrcweir try { 553cdf0e10cSrcweir if (chCount > 2) { 554cdf0e10cSrcweir System.out.println("setSelection(1, chCount-1):"); 555cdf0e10cSrcweir locRes = oObj.setSelection(1, chCount - 1); 556cdf0e10cSrcweir System.out.println(Boolean.toString(locRes)); 557cdf0e10cSrcweir res &= locRes; 558cdf0e10cSrcweir 559cdf0e10cSrcweir System.out.println("setSelection(chCount-1, 1):"); 560cdf0e10cSrcweir locRes = oObj.setSelection(chCount - 1, 1); 561cdf0e10cSrcweir System.out.println(Boolean.toString(locRes)); 562cdf0e10cSrcweir res &= locRes; 563cdf0e10cSrcweir } 564cdf0e10cSrcweir 565cdf0e10cSrcweir if (chCount > 1) { 566cdf0e10cSrcweir System.out.println("setSelection(0, chCount-1):"); 567cdf0e10cSrcweir locRes = oObj.setSelection(0, chCount-1); 568cdf0e10cSrcweir System.out.println(Boolean.toString(locRes)); 569cdf0e10cSrcweir res &= locRes; 570cdf0e10cSrcweir 571cdf0e10cSrcweir System.out.println("setSelection(chCount-1, 0):"); 572cdf0e10cSrcweir locRes = oObj.setSelection(chCount-1, 0); 573cdf0e10cSrcweir System.out.println(Boolean.toString(locRes)); 574cdf0e10cSrcweir res &= locRes; 575cdf0e10cSrcweir } 576cdf0e10cSrcweir 577cdf0e10cSrcweir System.out.println("setSelection(0, 0):"); 578cdf0e10cSrcweir locRes = oObj.setSelection(0, 0); 579cdf0e10cSrcweir System.out.println(Boolean.toString(locRes)); 580cdf0e10cSrcweir res &= locRes; 581cdf0e10cSrcweir } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 582cdf0e10cSrcweir System.out.println("Unexpected exception"); 583cdf0e10cSrcweir e.printStackTrace(); 584cdf0e10cSrcweir res &= false; 585cdf0e10cSrcweir } 586cdf0e10cSrcweir 587cdf0e10cSrcweir return res; 588cdf0e10cSrcweir } 589cdf0e10cSrcweir 590cdf0e10cSrcweir /** 591cdf0e10cSrcweir * Calls the method and checks returned value. 592cdf0e10cSrcweir * Has OK status if returned string is not null 593cdf0e10cSrcweir * received from relation. 594cdf0e10cSrcweir * @return 595cdf0e10cSrcweir */ _getText()596cdf0e10cSrcweir public boolean _getText() { 597cdf0e10cSrcweir text = oObj.getText(); 598cdf0e10cSrcweir System.out.println("getText: '" + text + "'"); 599cdf0e10cSrcweir return (text != null); 600cdf0e10cSrcweir } 601cdf0e10cSrcweir 602cdf0e10cSrcweir /** 603cdf0e10cSrcweir * Calls the method with invalid parameters an with valid parameters, 604cdf0e10cSrcweir * checks returned values. 605cdf0e10cSrcweir * Has OK status if exception was thrown for invalid parameters, 606cdf0e10cSrcweir * if exception wasn't thrown for valid parameters and if returned values 607cdf0e10cSrcweir * are equal to corresponding substrings of the text received by relation. 608cdf0e10cSrcweir * The following method tests are to be executed before: 609cdf0e10cSrcweir * <ul> 610cdf0e10cSrcweir * <li> <code>getCharacterCount()</code> </li> 611cdf0e10cSrcweir * </ul> 612cdf0e10cSrcweir * @return 613cdf0e10cSrcweir */ _getTextRange()614cdf0e10cSrcweir public boolean _getTextRange() { 615cdf0e10cSrcweir boolean res = true; 616cdf0e10cSrcweir boolean locRes = true; 617cdf0e10cSrcweir 618cdf0e10cSrcweir try { 619cdf0e10cSrcweir if (chCount > 3) { 620cdf0e10cSrcweir System.out.println("getTextRange(1, chCount - 2): "); 621cdf0e10cSrcweir String txtRange = oObj.getTextRange(1, chCount - 2); 622cdf0e10cSrcweir System.out.println(txtRange); 623cdf0e10cSrcweir locRes = txtRange.equals(text.substring(1, chCount - 2)); 624cdf0e10cSrcweir res &= locRes; 625cdf0e10cSrcweir if (!locRes) { 626cdf0e10cSrcweir System.out.println("Was expected: " + 627cdf0e10cSrcweir text.substring(1, chCount - 2)); 628cdf0e10cSrcweir } 629cdf0e10cSrcweir } 630cdf0e10cSrcweir 631cdf0e10cSrcweir if (chCount > 0) { 632cdf0e10cSrcweir System.out.println("getTextRange(0, chCount-1): "); 633cdf0e10cSrcweir String txtRange = oObj.getTextRange(0, chCount-1); 634cdf0e10cSrcweir System.out.println(txtRange); 635cdf0e10cSrcweir locRes = txtRange.equals(text.substring(0, chCount - 1)); 636cdf0e10cSrcweir res &= locRes; 637cdf0e10cSrcweir if (!locRes) { 638cdf0e10cSrcweir System.out.println("Was expected: " + 639cdf0e10cSrcweir text.substring(0, chCount - 1)); 640cdf0e10cSrcweir } 641cdf0e10cSrcweir 642cdf0e10cSrcweir System.out.println("getTextRange(chCount, 0): "); 643cdf0e10cSrcweir txtRange = oObj.getTextRange(chCount, 0); 644cdf0e10cSrcweir System.out.println(txtRange); 645cdf0e10cSrcweir res &= txtRange.equals(text); 646cdf0e10cSrcweir 647cdf0e10cSrcweir System.out.println("getTextRange(0, 0): "); 648cdf0e10cSrcweir txtRange = oObj.getTextRange(0, 0); 649cdf0e10cSrcweir System.out.println(txtRange); 650cdf0e10cSrcweir locRes = txtRange.equals(""); 651cdf0e10cSrcweir res &= locRes; 652cdf0e10cSrcweir if (!locRes) { 653cdf0e10cSrcweir System.out.println("Empty string was expected"); 654cdf0e10cSrcweir } 655cdf0e10cSrcweir } 656cdf0e10cSrcweir } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 657cdf0e10cSrcweir System.out.println("Unexpected exception"); 658cdf0e10cSrcweir e.printStackTrace(); 659cdf0e10cSrcweir res &= false; 660cdf0e10cSrcweir } 661cdf0e10cSrcweir 662cdf0e10cSrcweir try { 663cdf0e10cSrcweir System.out.println("getTextRange(-1, chCount - 1): "); 664cdf0e10cSrcweir String txtRange = oObj.getTextRange(-1, chCount - 1); 665cdf0e10cSrcweir System.out.println("Exception was expected"); 666cdf0e10cSrcweir res &= false; 667cdf0e10cSrcweir } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 668cdf0e10cSrcweir System.out.println("Expected exception"); 669cdf0e10cSrcweir res &= true; 670cdf0e10cSrcweir } 671cdf0e10cSrcweir 672cdf0e10cSrcweir try { 673cdf0e10cSrcweir System.out.println("getTextRange(0, chCount + 1): "); 674cdf0e10cSrcweir String txtRange = oObj.getTextRange(0, chCount + 1); 675cdf0e10cSrcweir System.out.println("Exception was expected"); 676cdf0e10cSrcweir res &= false; 677cdf0e10cSrcweir } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 678cdf0e10cSrcweir System.out.println("Expected exception"); 679cdf0e10cSrcweir res &= true; 680cdf0e10cSrcweir } 681cdf0e10cSrcweir 682cdf0e10cSrcweir try { 683cdf0e10cSrcweir System.out.println("getTextRange(chCount+1, -1): "); 684cdf0e10cSrcweir String txtRange = oObj.getTextRange(chCount+1, -1); 685cdf0e10cSrcweir System.out.println("Exception was expected"); 686cdf0e10cSrcweir res &= false; 687cdf0e10cSrcweir } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 688cdf0e10cSrcweir System.out.println("Expected exception"); 689cdf0e10cSrcweir res &= true; 690cdf0e10cSrcweir } 691cdf0e10cSrcweir 692cdf0e10cSrcweir return res; 693cdf0e10cSrcweir } 694cdf0e10cSrcweir 695cdf0e10cSrcweir /** 696cdf0e10cSrcweir * Calls the method with invalid parameters an with valid parameters, 697cdf0e10cSrcweir * checks returned values. 698cdf0e10cSrcweir * Has OK status if exception was thrown for invalid parameters, 699cdf0e10cSrcweir * if exception wasn't thrown for valid parameters and if returned values 700cdf0e10cSrcweir * are equal to corresponding substrings of the text received by relation. 701cdf0e10cSrcweir * The following method tests are to be executed before: 702cdf0e10cSrcweir * <ul> 703cdf0e10cSrcweir * <li> <code>getCharacterCount()</code> </li> 704cdf0e10cSrcweir * </ul> 705cdf0e10cSrcweir * @return 706cdf0e10cSrcweir */ _getTextAtIndex()707cdf0e10cSrcweir public boolean _getTextAtIndex() { 708cdf0e10cSrcweir boolean res = true; 709cdf0e10cSrcweir 710cdf0e10cSrcweir try { 711cdf0e10cSrcweir System.out.println("getTextAtIndex(-1, AccessibleTextType.PARAGRAPH):"); 712cdf0e10cSrcweir TextSegment txt = 713cdf0e10cSrcweir oObj.getTextAtIndex(-1, AccessibleTextType.PARAGRAPH); 714cdf0e10cSrcweir System.out.println("Exception was expected"); 715cdf0e10cSrcweir res &= false; 716cdf0e10cSrcweir } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 717cdf0e10cSrcweir System.out.println("Expected exception"); 718cdf0e10cSrcweir res &= true; 719cdf0e10cSrcweir } catch(com.sun.star.lang.IllegalArgumentException e) { 720cdf0e10cSrcweir System.out.println("Expected exception"); 721cdf0e10cSrcweir res &= true; 722cdf0e10cSrcweir } 723cdf0e10cSrcweir 724cdf0e10cSrcweir try { 725cdf0e10cSrcweir System.out.println("getTextAtIndex(chCount+1," + 726cdf0e10cSrcweir " AccessibleTextType.PARAGRAPH):"); 727cdf0e10cSrcweir TextSegment txt = oObj.getTextAtIndex(chCount + 1, 728cdf0e10cSrcweir AccessibleTextType.PARAGRAPH); 729cdf0e10cSrcweir System.out.println("Exception was expected"); 730cdf0e10cSrcweir res &= false; 731cdf0e10cSrcweir } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 732cdf0e10cSrcweir System.out.println("Expected exception"); 733cdf0e10cSrcweir res &= true; 734cdf0e10cSrcweir } catch(com.sun.star.lang.IllegalArgumentException e) { 735cdf0e10cSrcweir System.out.println("Expected exception"); 736cdf0e10cSrcweir res &= true; 737cdf0e10cSrcweir } 738cdf0e10cSrcweir 739cdf0e10cSrcweir 740cdf0e10cSrcweir try { 741cdf0e10cSrcweir if ( chCount > 0 ) { 742cdf0e10cSrcweir System.out.println("getTextAtIndex(chCount," + 743cdf0e10cSrcweir " AccessibleTextType.PARAGRAPH):"); 744cdf0e10cSrcweir TextSegment txt = oObj.getTextAtIndex(chCount, 745cdf0e10cSrcweir AccessibleTextType.PARAGRAPH); 746cdf0e10cSrcweir System.out.println("'" + txt.SegmentText + "'"); 747cdf0e10cSrcweir res &= txt.SegmentText.length() == 0; 748cdf0e10cSrcweir 749cdf0e10cSrcweir System.out.println("getTextAtIndex(1," + 750cdf0e10cSrcweir " AccessibleTextType.PARAGRAPH):"); 751cdf0e10cSrcweir txt = oObj.getTextAtIndex(1, 752cdf0e10cSrcweir AccessibleTextType.PARAGRAPH); 753cdf0e10cSrcweir System.out.println("'" + txt.SegmentText + "'"); 754cdf0e10cSrcweir res &= txt.SegmentText.equals(text); 755cdf0e10cSrcweir } 756cdf0e10cSrcweir } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 757cdf0e10cSrcweir System.out.println("Unexpected exception"); 758cdf0e10cSrcweir e.printStackTrace(); 759cdf0e10cSrcweir res &= false; 760cdf0e10cSrcweir } catch(com.sun.star.lang.IllegalArgumentException e) { 761cdf0e10cSrcweir System.out.println("Unexpected exception"); 762cdf0e10cSrcweir res &= false; 763cdf0e10cSrcweir } 764cdf0e10cSrcweir 765cdf0e10cSrcweir 766cdf0e10cSrcweir return res; 767cdf0e10cSrcweir } 768cdf0e10cSrcweir 769cdf0e10cSrcweir /** 770cdf0e10cSrcweir * Calls the method with invalid parameters an with valid parameters, 771cdf0e10cSrcweir * checks returned values. 772cdf0e10cSrcweir * Has OK status if exception was thrown for invalid parameters, 773cdf0e10cSrcweir * if exception wasn't thrown for valid parameters and if returned values 774cdf0e10cSrcweir * are equal to corresponding substrings of the text received by relation. 775cdf0e10cSrcweir * The following method tests are to be executed before: 776cdf0e10cSrcweir * <ul> 777cdf0e10cSrcweir * <li> <code>getCharacterCount()</code> </li> 778cdf0e10cSrcweir * </ul> 779cdf0e10cSrcweir * @return 780cdf0e10cSrcweir */ _getTextBeforeIndex()781cdf0e10cSrcweir public boolean _getTextBeforeIndex() { 782cdf0e10cSrcweir boolean res = true; 783cdf0e10cSrcweir 784cdf0e10cSrcweir try { 785cdf0e10cSrcweir System.out.println("getTextBeforeIndex(-1, AccessibleTextType.PARAGRAPH):"); 786cdf0e10cSrcweir TextSegment txt = oObj.getTextBeforeIndex(-1, 787cdf0e10cSrcweir AccessibleTextType.PARAGRAPH); 788cdf0e10cSrcweir System.out.println("Exception was expected"); 789cdf0e10cSrcweir res &= false; 790cdf0e10cSrcweir } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 791cdf0e10cSrcweir System.out.println("Expected exception"); 792cdf0e10cSrcweir res &= true; 793cdf0e10cSrcweir } catch(com.sun.star.lang.IllegalArgumentException e) { 794cdf0e10cSrcweir System.out.println("Expected exception"); 795cdf0e10cSrcweir res &= true; 796cdf0e10cSrcweir } 797cdf0e10cSrcweir 798cdf0e10cSrcweir 799cdf0e10cSrcweir try { 800cdf0e10cSrcweir System.out.println("getTextBeforeIndex(chCount+1, " + 801cdf0e10cSrcweir "AccessibleTextType.PARAGRAPH):"); 802cdf0e10cSrcweir TextSegment txt = oObj.getTextBeforeIndex(chCount + 1, 803cdf0e10cSrcweir AccessibleTextType.PARAGRAPH); 804cdf0e10cSrcweir System.out.println("Exception was expected"); 805cdf0e10cSrcweir res &= false; 806cdf0e10cSrcweir } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 807cdf0e10cSrcweir System.out.println("Expected exception"); 808cdf0e10cSrcweir res &= true; 809cdf0e10cSrcweir } catch(com.sun.star.lang.IllegalArgumentException e) { 810cdf0e10cSrcweir System.out.println("Expected exception"); 811cdf0e10cSrcweir res &= true; 812cdf0e10cSrcweir } 813cdf0e10cSrcweir 814cdf0e10cSrcweir TextSegment txt = null; 815cdf0e10cSrcweir try { 816cdf0e10cSrcweir if (chCount > 0) { 817cdf0e10cSrcweir System.out.println("getTextBeforeIndex(chCount," + 818cdf0e10cSrcweir " AccessibleTextType.PARAGRAPH):"); 819cdf0e10cSrcweir txt = oObj.getTextBeforeIndex(chCount, 820cdf0e10cSrcweir AccessibleTextType.PARAGRAPH); 821cdf0e10cSrcweir System.out.println("'" + txt.SegmentText + "'"); 822cdf0e10cSrcweir res &= txt.SegmentText.length() == chCount ; 823cdf0e10cSrcweir 824cdf0e10cSrcweir System.out.println("getTextBeforeIndex(1," + 825cdf0e10cSrcweir " AccessibleTextType.PARAGRAPH):"); 826cdf0e10cSrcweir txt = oObj.getTextBeforeIndex(1, 827cdf0e10cSrcweir AccessibleTextType.PARAGRAPH); 828cdf0e10cSrcweir System.out.println("'" + txt.SegmentText + "'"); 829cdf0e10cSrcweir res &= txt.SegmentText.length() == 0; 830cdf0e10cSrcweir } 831cdf0e10cSrcweir 832cdf0e10cSrcweir if (chCount > 2) { 833cdf0e10cSrcweir System.out.println("getTextBeforeIndex(chCount-1," + 834cdf0e10cSrcweir " AccessibleTextType.CHARACTER):"); 835cdf0e10cSrcweir txt = oObj.getTextBeforeIndex(chCount - 1, 836cdf0e10cSrcweir AccessibleTextType.CHARACTER); 837cdf0e10cSrcweir System.out.println("'" + txt.SegmentText + "'"); 838cdf0e10cSrcweir res &= txt.SegmentText.equals(text.substring(chCount - 2, chCount - 1)); 839cdf0e10cSrcweir System.out.println("getTextBeforeIndex(2," + 840cdf0e10cSrcweir " AccessibleTextType.CHARACTER):"); 841cdf0e10cSrcweir txt = oObj.getTextBeforeIndex(2, 842cdf0e10cSrcweir AccessibleTextType.CHARACTER); 843cdf0e10cSrcweir System.out.println("'" + txt.SegmentText + "'"); 844cdf0e10cSrcweir res &= txt.SegmentText.equals(text.substring(1, 2)); 845cdf0e10cSrcweir } 846cdf0e10cSrcweir } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 847cdf0e10cSrcweir System.out.println("Unexpected exception"); 848cdf0e10cSrcweir e.printStackTrace(); 849cdf0e10cSrcweir res &= false; 850cdf0e10cSrcweir } catch(com.sun.star.lang.IllegalArgumentException e) { 851cdf0e10cSrcweir System.out.println("Unexpected exception"); 852cdf0e10cSrcweir res &= false; 853cdf0e10cSrcweir } 854cdf0e10cSrcweir 855cdf0e10cSrcweir 856cdf0e10cSrcweir return res; 857cdf0e10cSrcweir } 858cdf0e10cSrcweir 859cdf0e10cSrcweir /** 860cdf0e10cSrcweir * Calls the method with invalid parameters an with valid parameters, 861cdf0e10cSrcweir * checks returned values. 862cdf0e10cSrcweir * Has OK status if exception was thrown for invalid parameters, 863cdf0e10cSrcweir * if exception wasn't thrown for valid parameters and if returned values 864cdf0e10cSrcweir * are equal to corresponding substrings of the text received by relation. 865cdf0e10cSrcweir * The following method tests are to be executed before: 866cdf0e10cSrcweir * <ul> 867cdf0e10cSrcweir * <li> <code>getCharacterCount()</code> </li> 868cdf0e10cSrcweir * </ul> 869cdf0e10cSrcweir * @return 870cdf0e10cSrcweir */ _getTextBehindIndex()871cdf0e10cSrcweir public boolean _getTextBehindIndex() { 872cdf0e10cSrcweir boolean res = true; 873cdf0e10cSrcweir 874cdf0e10cSrcweir try { 875cdf0e10cSrcweir System.out.println("getTextBehindIndex(-1, AccessibleTextType.PARAGRAPH):"); 876cdf0e10cSrcweir TextSegment txt = oObj.getTextBehindIndex(-1, 877cdf0e10cSrcweir AccessibleTextType.PARAGRAPH); 878cdf0e10cSrcweir System.out.println("Exception was expected"); 879cdf0e10cSrcweir res &= false; 880cdf0e10cSrcweir } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 881cdf0e10cSrcweir System.out.println("Expected exception"); 882cdf0e10cSrcweir res &= true; 883cdf0e10cSrcweir } catch(com.sun.star.lang.IllegalArgumentException e) { 884cdf0e10cSrcweir System.out.println("Expected exception"); 885cdf0e10cSrcweir res &= true; 886cdf0e10cSrcweir } 887cdf0e10cSrcweir 888cdf0e10cSrcweir 889cdf0e10cSrcweir try { 890cdf0e10cSrcweir System.out.println("getTextBehindIndex(chCount+1, " + 891cdf0e10cSrcweir "AccessibleTextType.PARAGRAPH):"); 892cdf0e10cSrcweir TextSegment txt = oObj.getTextBehindIndex(chCount + 1, 893cdf0e10cSrcweir AccessibleTextType.PARAGRAPH); 894cdf0e10cSrcweir System.out.println("Exception was expected"); 895cdf0e10cSrcweir res &= false; 896cdf0e10cSrcweir } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 897cdf0e10cSrcweir System.out.println("Expected exception"); 898cdf0e10cSrcweir res &= true; 899cdf0e10cSrcweir } catch(com.sun.star.lang.IllegalArgumentException e) { 900cdf0e10cSrcweir System.out.println("Expected exception"); 901cdf0e10cSrcweir res &= true; 902cdf0e10cSrcweir } 903cdf0e10cSrcweir 904cdf0e10cSrcweir 905cdf0e10cSrcweir try { 906cdf0e10cSrcweir if ( chCount > 0 ) { 907cdf0e10cSrcweir System.out.println("getTextBehindIndex(chCount," + 908cdf0e10cSrcweir " AccessibleTextType.PARAGRAPH):"); 909cdf0e10cSrcweir TextSegment txt = oObj.getTextBehindIndex(chCount, 910cdf0e10cSrcweir AccessibleTextType.PARAGRAPH); 911cdf0e10cSrcweir System.out.println("'" + txt.SegmentText + "'"); 912cdf0e10cSrcweir res &= txt.SegmentText.length() == 0; 913cdf0e10cSrcweir 914cdf0e10cSrcweir System.out.println("getTextBehindIndex(chCount-1," + 915cdf0e10cSrcweir " AccessibleTextType.PARAGRAPH):"); 916cdf0e10cSrcweir txt = oObj.getTextBehindIndex(chCount - 1, 917cdf0e10cSrcweir AccessibleTextType.PARAGRAPH); 918cdf0e10cSrcweir System.out.println("'" + txt.SegmentText + "'"); 919cdf0e10cSrcweir res &= txt.SegmentText.length() == 0; 920cdf0e10cSrcweir } 921cdf0e10cSrcweir if ( chCount > 1 ) { 922cdf0e10cSrcweir System.out.println("getTextBehindIndex(1," + 923cdf0e10cSrcweir " AccessibleTextType.CHARACTER):"); 924cdf0e10cSrcweir TextSegment txt = oObj.getTextBehindIndex(1, 925cdf0e10cSrcweir AccessibleTextType.CHARACTER); 926cdf0e10cSrcweir System.out.println("'" + txt.SegmentText + "'"); 927cdf0e10cSrcweir res &= txt.SegmentText.equals(text.substring(2, 3)); 928cdf0e10cSrcweir } 929cdf0e10cSrcweir if (chCount > 2) { 930cdf0e10cSrcweir System.out.println("getTextBehindIndex(chCount-2," + 931cdf0e10cSrcweir " AccessibleTextType.CHARACTER):"); 932cdf0e10cSrcweir TextSegment txt = oObj.getTextBehindIndex(chCount - 2, 933cdf0e10cSrcweir AccessibleTextType.CHARACTER); 934cdf0e10cSrcweir System.out.println("'" + txt.SegmentText + "'"); 935cdf0e10cSrcweir res &= txt.SegmentText.equals(text.substring(chCount - 1, chCount)); 936cdf0e10cSrcweir } 937cdf0e10cSrcweir } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 938cdf0e10cSrcweir System.out.println("Unexpected exception"); 939cdf0e10cSrcweir e.printStackTrace(); 940cdf0e10cSrcweir res &= false; 941cdf0e10cSrcweir } catch(com.sun.star.lang.IllegalArgumentException e) { 942cdf0e10cSrcweir System.out.println("Unexpected exception"); 943cdf0e10cSrcweir res &= false; 944cdf0e10cSrcweir } 945cdf0e10cSrcweir 946cdf0e10cSrcweir 947cdf0e10cSrcweir return res; 948cdf0e10cSrcweir } 949cdf0e10cSrcweir 950cdf0e10cSrcweir /** 951cdf0e10cSrcweir * Calls the method with invalid parameters an with valid parameter, 952cdf0e10cSrcweir * checks returned values. 953cdf0e10cSrcweir * Has OK status if exception was thrown for invalid parameters, 954cdf0e10cSrcweir * if exception wasn't thrown for valid parameter and if returned value for 955cdf0e10cSrcweir * valid parameter is equal to <code>true</code>. 956cdf0e10cSrcweir * @return 957cdf0e10cSrcweir */ _copyText()958cdf0e10cSrcweir public boolean _copyText() { 959cdf0e10cSrcweir boolean res = true; 960cdf0e10cSrcweir boolean locRes = true; 961cdf0e10cSrcweir 962cdf0e10cSrcweir if (editOnly != null) { 963cdf0e10cSrcweir System.out.println(editOnly); 964cdf0e10cSrcweir return true; 965cdf0e10cSrcweir } 966cdf0e10cSrcweir 967cdf0e10cSrcweir try { 968cdf0e10cSrcweir System.out.println("copyText(-1,chCount):"); 969cdf0e10cSrcweir oObj.copyText(-1, chCount); 970cdf0e10cSrcweir System.out.println("Exception was expected"); 971cdf0e10cSrcweir res &= false; 972cdf0e10cSrcweir } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 973cdf0e10cSrcweir System.out.println("Expected exception"); 974cdf0e10cSrcweir res &= true; 975cdf0e10cSrcweir } 976cdf0e10cSrcweir 977cdf0e10cSrcweir try { 978cdf0e10cSrcweir System.out.println("copyText(0,chCount+1):"); 979cdf0e10cSrcweir oObj.copyText(0, chCount + 1); 980cdf0e10cSrcweir System.out.println("Exception was expected"); 981cdf0e10cSrcweir res &= false; 982cdf0e10cSrcweir } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 983cdf0e10cSrcweir System.out.println("Expected exception"); 984cdf0e10cSrcweir res &= true; 985cdf0e10cSrcweir } 986cdf0e10cSrcweir 987cdf0e10cSrcweir try { 988cdf0e10cSrcweir System.out.println("copyText(0,chCount):"); 989cdf0e10cSrcweir locRes = oObj.copyText(0, chCount); 990cdf0e10cSrcweir System.out.println(""+locRes); 991cdf0e10cSrcweir res &= locRes; 992cdf0e10cSrcweir 993cdf0e10cSrcweir String cbText = null; 994cdf0e10cSrcweir try { 995cdf0e10cSrcweir cbText = 996cdf0e10cSrcweir util.SysUtils.getSysClipboardText(xMSF); 997cdf0e10cSrcweir } catch (com.sun.star.uno.Exception e) { 998cdf0e10cSrcweir System.out.println("Couldn't access system clipboard :"); 999cdf0e10cSrcweir e.printStackTrace(); 1000cdf0e10cSrcweir } 1001cdf0e10cSrcweir System.out.println("Clipboard: '" + cbText + "'"); 1002cdf0e10cSrcweir res &= text.equals(cbText); 1003cdf0e10cSrcweir 1004cdf0e10cSrcweir if (chCount > 2) { 1005cdf0e10cSrcweir System.out.println("copyText(1,chCount-1):"); 1006cdf0e10cSrcweir locRes = oObj.copyText(1, chCount - 1); 1007cdf0e10cSrcweir System.out.println(""+locRes); 1008cdf0e10cSrcweir res &= locRes; 1009cdf0e10cSrcweir 1010cdf0e10cSrcweir try { 1011cdf0e10cSrcweir cbText = util.SysUtils.getSysClipboardText(xMSF); 1012cdf0e10cSrcweir } catch (com.sun.star.uno.Exception e) { 1013cdf0e10cSrcweir System.out.println("Couldn't access system clipboard :"); 1014cdf0e10cSrcweir e.printStackTrace(); 1015cdf0e10cSrcweir } 1016cdf0e10cSrcweir 1017cdf0e10cSrcweir System.out.println("Clipboard: '" + cbText + "'"); 1018cdf0e10cSrcweir res &= text.substring(1, chCount - 1).equals(cbText); 1019cdf0e10cSrcweir } 1020cdf0e10cSrcweir 1021cdf0e10cSrcweir } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 1022cdf0e10cSrcweir System.out.println("Unexpected exception"); 1023cdf0e10cSrcweir e.printStackTrace(); 1024cdf0e10cSrcweir res &= false; 1025cdf0e10cSrcweir } 1026cdf0e10cSrcweir 1027cdf0e10cSrcweir return res; 1028cdf0e10cSrcweir } 1029cdf0e10cSrcweir } 1030