1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir package ifc.text; 28*cdf0e10cSrcweir 29*cdf0e10cSrcweir import lib.MultiMethodTest; 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir import com.sun.star.text.XText; 32*cdf0e10cSrcweir import com.sun.star.text.XTextRange; 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir /** 36*cdf0e10cSrcweir * Testing <code>com.sun.star.text.XTextRange</code> 37*cdf0e10cSrcweir * interface methods : 38*cdf0e10cSrcweir * <ul> 39*cdf0e10cSrcweir * <li><code> getText()</code></li> 40*cdf0e10cSrcweir * <li><code> getStart()</code></li> 41*cdf0e10cSrcweir * <li><code> getEnd()</code></li> 42*cdf0e10cSrcweir * <li><code> getString()</code></li> 43*cdf0e10cSrcweir * <li><code> setString()</code></li> 44*cdf0e10cSrcweir * </ul> <p> 45*cdf0e10cSrcweir * First the content is set to 'Middle' string value, then 46*cdf0e10cSrcweir * start range is retrieved and its content is set to 'Start' 47*cdf0e10cSrcweir * and end range is set to 'End'. Finally the whole TextRange 48*cdf0e10cSrcweir * is checked and it must be 'StartMiddleEnd'. <p> 49*cdf0e10cSrcweir * Test is <b> NOT </b> multithread compilant. <p> 50*cdf0e10cSrcweir * @see com.sun.star.text.XTextRange 51*cdf0e10cSrcweir */ 52*cdf0e10cSrcweir public class _XTextRange extends MultiMethodTest { 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir public XTextRange oObj = null; // oObj is filled by setField() 55*cdf0e10cSrcweir // in MultiMethodTest 56*cdf0e10cSrcweir XTextRange oStartRange = null; // startrange of textrang 57*cdf0e10cSrcweir XTextRange oEndRange = null; // endrange of textrang 58*cdf0e10cSrcweir String startStr = null; // string in startrange 59*cdf0e10cSrcweir String endStr = null; // string in endrange 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir /** 62*cdf0e10cSrcweir * Retrieves the start range and sets its context to 63*cdf0e10cSrcweir * 'Start' string. <p> 64*cdf0e10cSrcweir * Has <b>OK</b> status if the whole range string starts 65*cdf0e10cSrcweir * with 'Start' substring. <p> 66*cdf0e10cSrcweir * The following method tests are to be completed successfully before : 67*cdf0e10cSrcweir * <ul> 68*cdf0e10cSrcweir * <li> <code> setString </code> </li> 69*cdf0e10cSrcweir * </ul> 70*cdf0e10cSrcweir */ 71*cdf0e10cSrcweir public void _getStart() { 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir XText the_text = (XText) tEnv.getObjRelation("XTEXT"); 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir if (the_text != null) { 76*cdf0e10cSrcweir the_text.setString(""); 77*cdf0e10cSrcweir } 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir String exp=""; 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir oObj.setString("MiddleEnd"); 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir oStartRange = oObj.getStart(); 84*cdf0e10cSrcweir oStartRange.setString("Start"); 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir if (the_text !=null) { 87*cdf0e10cSrcweir exp = the_text.getString(); 88*cdf0e10cSrcweir } else exp = oObj.getText().getString(); 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir log.println("Start: "+exp); 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir tRes.tested( "getStart()", oStartRange != null && 93*cdf0e10cSrcweir exp.startsWith("Start")); 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir oStartRange.setString(""); 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir /** 101*cdf0e10cSrcweir * Retrieves the end range and sets its context to 102*cdf0e10cSrcweir * 'End' string. <p> 103*cdf0e10cSrcweir * Has <b>OK</b> status if the whole range string ends 104*cdf0e10cSrcweir * with 'End' substring. <p> 105*cdf0e10cSrcweir * The following method tests are to be completed successfully before : 106*cdf0e10cSrcweir * <ul> 107*cdf0e10cSrcweir * <li> <code> setString </code> </li> 108*cdf0e10cSrcweir * </ul> 109*cdf0e10cSrcweir */ 110*cdf0e10cSrcweir public void _getEnd() { 111*cdf0e10cSrcweir XText the_text = (XText) tEnv.getObjRelation("XTEXT"); 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir if (the_text != null) { 114*cdf0e10cSrcweir the_text.setString(""); 115*cdf0e10cSrcweir } 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir String exp=""; 118*cdf0e10cSrcweir oObj.setString("StartMiddle"); 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir oEndRange = oObj.getEnd(); 121*cdf0e10cSrcweir oEndRange.setString("End"); 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir if (the_text !=null) { 124*cdf0e10cSrcweir exp = the_text.getString(); 125*cdf0e10cSrcweir } else exp = oObj.getText().getString(); 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir log.println("End: "+exp); 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir tRes.tested( "getEnd()", oEndRange != null && 130*cdf0e10cSrcweir exp.endsWith("End")); 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir oEndRange.setString(""); 133*cdf0e10cSrcweir } 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir /** 136*cdf0e10cSrcweir * Gets the text of the range and retrieves its String content. <p> 137*cdf0e10cSrcweir * Has <b>OK</b> status if the string returned equals to 138*cdf0e10cSrcweir * 'StartMiddleEnd' value. <p> 139*cdf0e10cSrcweir * The following method tests are to be completed successfully before : 140*cdf0e10cSrcweir * <ul> 141*cdf0e10cSrcweir * <li> <code> setString </code> to get finally the string expected.</li> 142*cdf0e10cSrcweir * <li> <code> getStart </code> to get finally the string expected.</li> 143*cdf0e10cSrcweir * <li> <code> getEnd </code> to get finally the string expected.</li> 144*cdf0e10cSrcweir * </ul> 145*cdf0e10cSrcweir */ 146*cdf0e10cSrcweir public void _getText() { 147*cdf0e10cSrcweir requiredMethod("setString()"); 148*cdf0e10cSrcweir requiredMethod("getStart()"); 149*cdf0e10cSrcweir requiredMethod("getEnd()"); 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir XText txt = oObj.getText() ; 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir tRes.tested( "getText()", txt != null && 154*cdf0e10cSrcweir txt.getString().equals("StartMiddle")); 155*cdf0e10cSrcweir } 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir /** 158*cdf0e10cSrcweir * Gets the String of the range. <p> 159*cdf0e10cSrcweir * Has <b>OK</b> status if the string returned equals to 160*cdf0e10cSrcweir * 'StartMiddleEnd' value. <p> 161*cdf0e10cSrcweir */ 162*cdf0e10cSrcweir public void _getString() { 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir oObj.setString("StartMiddleEnd"); 165*cdf0e10cSrcweir String gStr = oObj.getString() ; 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir tRes.tested( "getString()", gStr != null && 168*cdf0e10cSrcweir gStr.equals("StartMiddleEnd")); 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir } 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir /** 173*cdf0e10cSrcweir * Sets the string content of the range to 'Middle' value. <p> 174*cdf0e10cSrcweir * Has <b>OK</b> status if <code>getString</code> method returns 175*cdf0e10cSrcweir * 'Middle' value. 176*cdf0e10cSrcweir */ 177*cdf0e10cSrcweir public void _setString() { 178*cdf0e10cSrcweir oObj.setString("Middle") ; 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir tRes.tested("setString()", "Middle".equals(oObj.getString())) ; 181*cdf0e10cSrcweir } 182*cdf0e10cSrcweir } 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir 185