2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 import lib
.MultiMethodTest
;
22 import com
.sun
.star
.text
.XText
;
23 import com
.sun
.star
.text
.XTextRange
;
27 * Testing <code>com.sun.star.text.XTextRange</code>
30 * <li><code> getText()</code></li>
31 * <li><code> getStart()</code></li>
32 * <li><code> getEnd()</code></li>
33 * <li><code> getString()</code></li>
34 * <li><code> setString()</code></li>
36 * First the content is set to 'Middle' string value, then
37 * start range is retrieved and its content is set to 'Start'
38 * and end range is set to 'End'. Finally the whole TextRange
39 * is checked and it must be 'StartMiddleEnd'. <p>
40 * Test is <b> NOT </b> multithread compliant. <p>
41 * @see com.sun.star.text.XTextRange
43 public class _XTextRange
extends MultiMethodTest
{
45 public XTextRange oObj
= null; // oObj is filled by setField()
47 XTextRange oStartRange
= null; // startrange of textrang
48 XTextRange oEndRange
= null; // endrange of textrang
49 String startStr
= null; // string in startrange
50 String endStr
= null; // string in endrange
53 * Retrieves the start range and sets its context to
55 * Has <b>OK</b> status if the whole range string starts
56 * with 'Start' substring. <p>
57 * The following method tests are to be completed successfully before :
59 * <li> <code> setString </code> </li>
62 public void _getStart() {
64 XText the_text
= (XText
) tEnv
.getObjRelation("XTEXT");
66 if (the_text
!= null) {
67 the_text
.setString("");
72 oObj
.setString("MiddleEnd");
74 oStartRange
= oObj
.getStart();
75 oStartRange
.setString("Start");
77 if (the_text
!=null) {
78 exp
= the_text
.getString();
79 } else exp
= oObj
.getText().getString();
81 log
.println("Start: "+exp
);
83 tRes
.tested( "getStart()", oStartRange
!= null &&
84 exp
.startsWith("Start"));
87 oStartRange
.setString("");
92 * Retrieves the end range and sets its context to
94 * Has <b>OK</b> status if the whole range string ends
95 * with 'End' substring. <p>
96 * The following method tests are to be completed successfully before :
98 * <li> <code> setString </code> </li>
101 public void _getEnd() {
102 XText the_text
= (XText
) tEnv
.getObjRelation("XTEXT");
104 if (the_text
!= null) {
105 the_text
.setString("");
109 oObj
.setString("StartMiddle");
111 oEndRange
= oObj
.getEnd();
112 oEndRange
.setString("End");
114 if (the_text
!=null) {
115 exp
= the_text
.getString();
116 } else exp
= oObj
.getText().getString();
118 log
.println("End: "+exp
);
120 tRes
.tested( "getEnd()", oEndRange
!= null &&
121 exp
.endsWith("End"));
123 oEndRange
.setString("");
127 * Gets the text of the range and retrieves its String content. <p>
128 * Has <b>OK</b> status if the string returned equals to
129 * 'StartMiddleEnd' value. <p>
130 * The following method tests are to be completed successfully before :
132 * <li> <code> setString </code> to get finally the string expected.</li>
133 * <li> <code> getStart </code> to get finally the string expected.</li>
134 * <li> <code> getEnd </code> to get finally the string expected.</li>
137 public void _getText() {
138 requiredMethod("setString()");
139 requiredMethod("getStart()");
140 requiredMethod("getEnd()");
142 XText txt
= oObj
.getText() ;
144 tRes
.tested( "getText()", txt
!= null &&
145 txt
.getString().equals("StartMiddle"));
149 * Gets the String of the range. <p>
150 * Has <b>OK</b> status if the string returned equals to
151 * 'StartMiddleEnd' value. <p>
153 public void _getString() {
155 oObj
.setString("StartMiddleEnd");
156 String gStr
= oObj
.getString() ;
158 tRes
.tested( "getString()", gStr
!= null &&
159 gStr
.equals("StartMiddleEnd"));
164 * Sets the string content of the range to 'Middle' value. <p>
165 * Has <b>OK</b> status if <code>getString</code> method returns
168 public void _setString() {
169 oObj
.setString("Middle") ;
171 tRes
.tested("setString()", "Middle".equals(oObj
.getString())) ;