1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XTextRange.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 import lib
.MultiMethodTest
;
34 import com
.sun
.star
.text
.XText
;
35 import com
.sun
.star
.text
.XTextRange
;
39 * Testing <code>com.sun.star.text.XTextRange</code>
42 * <li><code> getText()</code></li>
43 * <li><code> getStart()</code></li>
44 * <li><code> getEnd()</code></li>
45 * <li><code> getString()</code></li>
46 * <li><code> setString()</code></li>
48 * First the content is set to 'Middle' string value, then
49 * start range is retrieved and its content is set to 'Start'
50 * and end range is set to 'End'. Finally the whole TextRange
51 * is checked and it must be 'StartMiddleEnd'. <p>
52 * Test is <b> NOT </b> multithread compilant. <p>
53 * @see com.sun.star.text.XTextRange
55 public class _XTextRange
extends MultiMethodTest
{
57 public XTextRange oObj
= null; // oObj is filled by setField()
59 XTextRange oStartRange
= null; // startrange of textrang
60 XTextRange oEndRange
= null; // endrange of textrang
61 String startStr
= null; // string in startrange
62 String endStr
= null; // string in endrange
65 * Retrieves the start range and sets its context to
67 * Has <b>OK</b> status if the whole range string starts
68 * with 'Start' substring. <p>
69 * The following method tests are to be completed successfully before :
71 * <li> <code> setString </code> </li>
74 public void _getStart() {
76 XText the_text
= (XText
) tEnv
.getObjRelation("XTEXT");
78 if (the_text
!= null) {
79 the_text
.setString("");
84 oObj
.setString("MiddleEnd");
86 oStartRange
= oObj
.getStart();
87 oStartRange
.setString("Start");
89 if (the_text
!=null) {
90 exp
= the_text
.getString();
91 } else exp
= oObj
.getText().getString();
93 log
.println("Start: "+exp
);
95 tRes
.tested( "getStart()", oStartRange
!= null &&
96 exp
.startsWith("Start"));
99 oStartRange
.setString("");
104 * Retrieves the end range and sets its context to
106 * Has <b>OK</b> status if the whole range string ends
107 * with 'End' substring. <p>
108 * The following method tests are to be completed successfully before :
110 * <li> <code> setString </code> </li>
113 public void _getEnd() {
114 XText the_text
= (XText
) tEnv
.getObjRelation("XTEXT");
116 if (the_text
!= null) {
117 the_text
.setString("");
121 oObj
.setString("StartMiddle");
123 oEndRange
= oObj
.getEnd();
124 oEndRange
.setString("End");
126 if (the_text
!=null) {
127 exp
= the_text
.getString();
128 } else exp
= oObj
.getText().getString();
130 log
.println("End: "+exp
);
132 tRes
.tested( "getEnd()", oEndRange
!= null &&
133 exp
.endsWith("End"));
135 oEndRange
.setString("");
139 * Gets the text of the range and retrieves its String content. <p>
140 * Has <b>OK</b> status if the string returned equals to
141 * 'StartMiddleEnd' value. <p>
142 * The following method tests are to be completed successfully before :
144 * <li> <code> setString </code> to get finally the string expected.</li>
145 * <li> <code> getStart </code> to get finally the string expected.</li>
146 * <li> <code> getEnd </code> to get finally the string expected.</li>
149 public void _getText() {
150 requiredMethod("setString()");
151 requiredMethod("getStart()");
152 requiredMethod("getEnd()");
154 XText txt
= oObj
.getText() ;
156 tRes
.tested( "getText()", txt
!= null &&
157 txt
.getString().equals("StartMiddle"));
161 * Gets the String of the range. <p>
162 * Has <b>OK</b> status if the string returned equals to
163 * 'StartMiddleEnd' value. <p>
165 public void _getString() {
167 oObj
.setString("StartMiddleEnd");
168 String gStr
= oObj
.getString() ;
170 tRes
.tested( "getString()", gStr
!= null &&
171 gStr
.equals("StartMiddleEnd"));
176 * Sets the string content of the range to 'Middle' value. <p>
177 * Has <b>OK</b> status if <code>getString</code> method returns
180 public void _setString() {
181 oObj
.setString("Middle") ;
183 tRes
.tested("setString()", "Middle".equals(oObj
.getString())) ;