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
51 * Retrieves the start range and sets its context to
53 * Has <b>OK</b> status if the whole range string starts
54 * with 'Start' substring. <p>
55 * The following method tests are to be completed successfully before :
57 * <li> <code> setString </code> </li>
60 public void _getStart() {
62 XText the_text
= (XText
) tEnv
.getObjRelation("XTEXT");
64 if (the_text
!= null) {
65 the_text
.setString("");
70 oObj
.setString("MiddleEnd");
72 oStartRange
= oObj
.getStart();
73 oStartRange
.setString("Start");
75 if (the_text
!=null) {
76 exp
= the_text
.getString();
77 } else exp
= oObj
.getText().getString();
79 log
.println("Start: "+exp
);
81 tRes
.tested( "getStart()", exp
.startsWith("Start"));
83 oStartRange
.setString("");
88 * Retrieves the end range and sets its context to
90 * Has <b>OK</b> status if the whole range string ends
91 * with 'End' substring. <p>
92 * The following method tests are to be completed successfully before :
94 * <li> <code> setString </code> </li>
97 public void _getEnd() {
98 XText the_text
= (XText
) tEnv
.getObjRelation("XTEXT");
100 if (the_text
!= null) {
101 the_text
.setString("");
105 oObj
.setString("StartMiddle");
107 oEndRange
= oObj
.getEnd();
108 oEndRange
.setString("End");
110 if (the_text
!=null) {
111 exp
= the_text
.getString();
112 } else exp
= oObj
.getText().getString();
114 log
.println("End: "+exp
);
116 tRes
.tested( "getEnd()", exp
.endsWith("End"));
118 oEndRange
.setString("");
122 * Gets the text of the range and retrieves its String content. <p>
123 * Has <b>OK</b> status if the string returned equals to
124 * 'StartMiddleEnd' value. <p>
125 * The following method tests are to be completed successfully before :
127 * <li> <code> setString </code> to get finally the string expected.</li>
128 * <li> <code> getStart </code> to get finally the string expected.</li>
129 * <li> <code> getEnd </code> to get finally the string expected.</li>
132 public void _getText() {
133 requiredMethod("setString()");
134 requiredMethod("getStart()");
135 requiredMethod("getEnd()");
137 XText txt
= oObj
.getText() ;
139 tRes
.tested( "getText()", txt
!= null &&
140 txt
.getString().equals("StartMiddle"));
144 * Gets the String of the range. <p>
145 * Has <b>OK</b> status if the string returned equals to
146 * 'StartMiddleEnd' value. <p>
148 public void _getString() {
150 oObj
.setString("StartMiddleEnd");
151 String gStr
= oObj
.getString() ;
153 tRes
.tested( "getString()", gStr
!= null &&
154 gStr
.equals("StartMiddleEnd"));
159 * Sets the string content of the range to 'Middle' value. <p>
160 * Has <b>OK</b> status if <code>getString</code> method returns
163 public void _setString() {
164 oObj
.setString("Middle") ;
166 tRes
.tested("setString()", "Middle".equals(oObj
.getString())) ;