1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 package ifc.text; 29 30 import lib.MultiMethodTest; 31 import lib.Status; 32 import lib.StatusException; 33 34 import com.sun.star.text.XTextRange; 35 import com.sun.star.text.XTextRangeMover; 36 37 /** 38 * Testing <code>com.sun.star.text.XTextRangeMover</code> 39 * interface methods : 40 * <ul> 41 * <li><code> moveTextRange()</code></li> 42 * </ul> <p> 43 * This test needs the following object relations : 44 * <ul> 45 * <li> <code>'RangeForMove'</code> (of type <code>XTextRange</code>): 46 * the range to be moved. </li> 47 * <li> <code>'XTextRange'</code> (of type <code>XTextRange</code>): 48 * the range that includes moving range. </li> 49 * <ul> <p> 50 * Test is <b> NOT </b> multithread compilant. <p> 51 * @see com.sun.star.text.XTextRangeMover 52 */ 53 public class _XTextRangeMover extends MultiMethodTest { 54 55 public XTextRangeMover oObj = null; 56 57 XTextRange xTextRange = null; 58 XTextRange oMoveRange = null; 59 60 /** 61 * Moves the range obtained from relation 'RangeForMove' by 1 paragraph 62 * and compares index of moved string in the whole text obtained 63 * from relation 'XTextRange'. <p> 64 * Has <b>OK</b> status if index of moved range is changed after method call. 65 */ 66 public void _moveTextRange(){ 67 oMoveRange = (XTextRange) tEnv.getObjRelation("RangeForMove"); 68 xTextRange = (XTextRange) tEnv.getObjRelation("XTextRange"); 69 70 if (oMoveRange == null) { 71 throw new StatusException( 72 Status.failed("Couldn't get relation 'RangeForMove'")); 73 } 74 75 if (xTextRange == null) { 76 throw new StatusException( 77 Status.failed("Couldn't get relation 'XTextRange'")); 78 } 79 80 log.println("Content before moving:"); 81 log.println(xTextRange.getString()); 82 log.println("Text range for moving:"); 83 log.println(oMoveRange.getString()); 84 int indexBefore = xTextRange.getString().indexOf(oMoveRange.getString()); 85 oObj.moveTextRange(oMoveRange,(short) 1); 86 log.println("Content after moving:"); 87 log.println(xTextRange.getString()); 88 int indexAfter = xTextRange.getString().indexOf(oMoveRange.getString()); 89 90 boolean res = indexBefore != indexAfter; 91 log.println("Index before moving:" + indexBefore); 92 log.println("Index after moving:" + indexAfter); 93 94 tRes.tested("moveTextRange()", res); 95 } 96 } 97 98