1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package ifc.text; 25 26 import lib.MultiMethodTest; 27 import lib.Status; 28 import lib.StatusException; 29 30 import com.sun.star.text.XTextRange; 31 import com.sun.star.text.XTextRangeMover; 32 33 /** 34 * Testing <code>com.sun.star.text.XTextRangeMover</code> 35 * interface methods : 36 * <ul> 37 * <li><code> moveTextRange()</code></li> 38 * </ul> <p> 39 * This test needs the following object relations : 40 * <ul> 41 * <li> <code>'RangeForMove'</code> (of type <code>XTextRange</code>): 42 * the range to be moved. </li> 43 * <li> <code>'XTextRange'</code> (of type <code>XTextRange</code>): 44 * the range that includes moving range. </li> 45 * <ul> <p> 46 * Test is <b> NOT </b> multithread compilant. <p> 47 * @see com.sun.star.text.XTextRangeMover 48 */ 49 public class _XTextRangeMover extends MultiMethodTest { 50 51 public XTextRangeMover oObj = null; 52 53 XTextRange xTextRange = null; 54 XTextRange oMoveRange = null; 55 56 /** 57 * Moves the range obtained from relation 'RangeForMove' by 1 paragraph 58 * and compares index of moved string in the whole text obtained 59 * from relation 'XTextRange'. <p> 60 * Has <b>OK</b> status if index of moved range is changed after method call. 61 */ _moveTextRange()62 public void _moveTextRange(){ 63 oMoveRange = (XTextRange) tEnv.getObjRelation("RangeForMove"); 64 xTextRange = (XTextRange) tEnv.getObjRelation("XTextRange"); 65 66 if (oMoveRange == null) { 67 throw new StatusException( 68 Status.failed("Couldn't get relation 'RangeForMove'")); 69 } 70 71 if (xTextRange == null) { 72 throw new StatusException( 73 Status.failed("Couldn't get relation 'XTextRange'")); 74 } 75 76 log.println("Content before moving:"); 77 log.println(xTextRange.getString()); 78 log.println("Text range for moving:"); 79 log.println(oMoveRange.getString()); 80 int indexBefore = xTextRange.getString().indexOf(oMoveRange.getString()); 81 oObj.moveTextRange(oMoveRange,(short) 1); 82 log.println("Content after moving:"); 83 log.println(xTextRange.getString()); 84 int indexAfter = xTextRange.getString().indexOf(oMoveRange.getString()); 85 86 boolean res = indexBefore != indexAfter; 87 log.println("Index before moving:" + indexBefore); 88 log.println("Index after moving:" + indexAfter); 89 90 tRes.tested("moveTextRange()", res); 91 } 92 } 93 94