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 package ifc.text; 24 25 import lib.MultiMethodTest; 26 27 import com.sun.star.text.XText; 28 import com.sun.star.text.XTextRange; 29 30 31 /** 32 * Testing <code>com.sun.star.text.XTextRange</code> 33 * interface methods : 34 * <ul> 35 * <li><code> getText()</code></li> 36 * <li><code> getStart()</code></li> 37 * <li><code> getEnd()</code></li> 38 * <li><code> getString()</code></li> 39 * <li><code> setString()</code></li> 40 * </ul> <p> 41 * First the content is set to 'Middle' string value, then 42 * start range is retrieved and its content is set to 'Start' 43 * and end range is set to 'End'. Finally the whole TextRange 44 * is checked and it must be 'StartMiddleEnd'. <p> 45 * Test is <b> NOT </b> multithread compilant. <p> 46 * @see com.sun.star.text.XTextRange 47 */ 48 public class _XTextRange extends MultiMethodTest { 49 50 public XTextRange oObj = null; // oObj is filled by setField() 51 // in MultiMethodTest 52 XTextRange oStartRange = null; // startrange of textrang 53 XTextRange oEndRange = null; // endrange of textrang 54 String startStr = null; // string in startrange 55 String endStr = null; // string in endrange 56 57 /** 58 * Retrieves the start range and sets its context to 59 * 'Start' string. <p> 60 * Has <b>OK</b> status if the whole range string starts 61 * with 'Start' substring. <p> 62 * The following method tests are to be completed successfully before : 63 * <ul> 64 * <li> <code> setString </code> </li> 65 * </ul> 66 */ _getStart()67 public void _getStart() { 68 69 XText the_text = (XText) tEnv.getObjRelation("XTEXT"); 70 71 if (the_text != null) { 72 the_text.setString(""); 73 } 74 75 String exp=""; 76 77 oObj.setString("MiddleEnd"); 78 79 oStartRange = oObj.getStart(); 80 oStartRange.setString("Start"); 81 82 if (the_text !=null) { 83 exp = the_text.getString(); 84 } else exp = oObj.getText().getString(); 85 86 log.println("Start: "+exp); 87 88 tRes.tested( "getStart()", oStartRange != null && 89 exp.startsWith("Start")); 90 91 92 oStartRange.setString(""); 93 94 } 95 96 /** 97 * Retrieves the end range and sets its context to 98 * 'End' string. <p> 99 * Has <b>OK</b> status if the whole range string ends 100 * with 'End' substring. <p> 101 * The following method tests are to be completed successfully before : 102 * <ul> 103 * <li> <code> setString </code> </li> 104 * </ul> 105 */ _getEnd()106 public void _getEnd() { 107 XText the_text = (XText) tEnv.getObjRelation("XTEXT"); 108 109 if (the_text != null) { 110 the_text.setString(""); 111 } 112 113 String exp=""; 114 oObj.setString("StartMiddle"); 115 116 oEndRange = oObj.getEnd(); 117 oEndRange.setString("End"); 118 119 if (the_text !=null) { 120 exp = the_text.getString(); 121 } else exp = oObj.getText().getString(); 122 123 log.println("End: "+exp); 124 125 tRes.tested( "getEnd()", oEndRange != null && 126 exp.endsWith("End")); 127 128 oEndRange.setString(""); 129 } 130 131 /** 132 * Gets the text of the range and retrieves its String content. <p> 133 * Has <b>OK</b> status if the string returned equals to 134 * 'StartMiddleEnd' value. <p> 135 * The following method tests are to be completed successfully before : 136 * <ul> 137 * <li> <code> setString </code> to get finally the string expected.</li> 138 * <li> <code> getStart </code> to get finally the string expected.</li> 139 * <li> <code> getEnd </code> to get finally the string expected.</li> 140 * </ul> 141 */ _getText()142 public void _getText() { 143 requiredMethod("setString()"); 144 requiredMethod("getStart()"); 145 requiredMethod("getEnd()"); 146 147 XText txt = oObj.getText() ; 148 149 tRes.tested( "getText()", txt != null && 150 txt.getString().equals("StartMiddle")); 151 } 152 153 /** 154 * Gets the String of the range. <p> 155 * Has <b>OK</b> status if the string returned equals to 156 * 'StartMiddleEnd' value. <p> 157 */ _getString()158 public void _getString() { 159 160 oObj.setString("StartMiddleEnd"); 161 String gStr = oObj.getString() ; 162 163 tRes.tested( "getString()", gStr != null && 164 gStr.equals("StartMiddleEnd")); 165 166 } 167 168 /** 169 * Sets the string content of the range to 'Middle' value. <p> 170 * Has <b>OK</b> status if <code>getString</code> method returns 171 * 'Middle' value. 172 */ _setString()173 public void _setString() { 174 oObj.setString("Middle") ; 175 176 tRes.tested("setString()", "Middle".equals(oObj.getString())) ; 177 } 178 } 179 180 181