1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
29 import lib
.MultiMethodTest
;
31 import com
.sun
.star
.text
.XText
;
32 import com
.sun
.star
.text
.XTextRange
;
36 * Testing <code>com.sun.star.text.XTextRange</code>
39 * <li><code> getText()</code></li>
40 * <li><code> getStart()</code></li>
41 * <li><code> getEnd()</code></li>
42 * <li><code> getString()</code></li>
43 * <li><code> setString()</code></li>
45 * First the content is set to 'Middle' string value, then
46 * start range is retrieved and its content is set to 'Start'
47 * and end range is set to 'End'. Finally the whole TextRange
48 * is checked and it must be 'StartMiddleEnd'. <p>
49 * Test is <b> NOT </b> multithread compilant. <p>
50 * @see com.sun.star.text.XTextRange
52 public class _XTextRange
extends MultiMethodTest
{
54 public XTextRange oObj
= null; // oObj is filled by setField()
56 XTextRange oStartRange
= null; // startrange of textrang
57 XTextRange oEndRange
= null; // endrange of textrang
58 String startStr
= null; // string in startrange
59 String endStr
= null; // string in endrange
62 * Retrieves the start range and sets its context to
64 * Has <b>OK</b> status if the whole range string starts
65 * with 'Start' substring. <p>
66 * The following method tests are to be completed successfully before :
68 * <li> <code> setString </code> </li>
71 public void _getStart() {
73 XText the_text
= (XText
) tEnv
.getObjRelation("XTEXT");
75 if (the_text
!= null) {
76 the_text
.setString("");
81 oObj
.setString("MiddleEnd");
83 oStartRange
= oObj
.getStart();
84 oStartRange
.setString("Start");
86 if (the_text
!=null) {
87 exp
= the_text
.getString();
88 } else exp
= oObj
.getText().getString();
90 log
.println("Start: "+exp
);
92 tRes
.tested( "getStart()", oStartRange
!= null &&
93 exp
.startsWith("Start"));
96 oStartRange
.setString("");
101 * Retrieves the end range and sets its context to
103 * Has <b>OK</b> status if the whole range string ends
104 * with 'End' substring. <p>
105 * The following method tests are to be completed successfully before :
107 * <li> <code> setString </code> </li>
110 public void _getEnd() {
111 XText the_text
= (XText
) tEnv
.getObjRelation("XTEXT");
113 if (the_text
!= null) {
114 the_text
.setString("");
118 oObj
.setString("StartMiddle");
120 oEndRange
= oObj
.getEnd();
121 oEndRange
.setString("End");
123 if (the_text
!=null) {
124 exp
= the_text
.getString();
125 } else exp
= oObj
.getText().getString();
127 log
.println("End: "+exp
);
129 tRes
.tested( "getEnd()", oEndRange
!= null &&
130 exp
.endsWith("End"));
132 oEndRange
.setString("");
136 * Gets the text of the range and retrieves its String content. <p>
137 * Has <b>OK</b> status if the string returned equals to
138 * 'StartMiddleEnd' value. <p>
139 * The following method tests are to be completed successfully before :
141 * <li> <code> setString </code> to get finally the string expected.</li>
142 * <li> <code> getStart </code> to get finally the string expected.</li>
143 * <li> <code> getEnd </code> to get finally the string expected.</li>
146 public void _getText() {
147 requiredMethod("setString()");
148 requiredMethod("getStart()");
149 requiredMethod("getEnd()");
151 XText txt
= oObj
.getText() ;
153 tRes
.tested( "getText()", txt
!= null &&
154 txt
.getString().equals("StartMiddle"));
158 * Gets the String of the range. <p>
159 * Has <b>OK</b> status if the string returned equals to
160 * 'StartMiddleEnd' value. <p>
162 public void _getString() {
164 oObj
.setString("StartMiddleEnd");
165 String gStr
= oObj
.getString() ;
167 tRes
.tested( "getString()", gStr
!= null &&
168 gStr
.equals("StartMiddleEnd"));
173 * Sets the string content of the range to 'Middle' value. <p>
174 * Has <b>OK</b> status if <code>getString</code> method returns
177 public void _setString() {
178 oObj
.setString("Middle") ;
180 tRes
.tested("setString()", "Middle".equals(oObj
.getString())) ;