1*ef39d40dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ef39d40dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ef39d40dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ef39d40dSAndrew Rist  * distributed with this work for additional information
6*ef39d40dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ef39d40dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ef39d40dSAndrew Rist  * "License"); you may not use this file except in compliance
9*ef39d40dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*ef39d40dSAndrew Rist  *
11*ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*ef39d40dSAndrew Rist  *
13*ef39d40dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ef39d40dSAndrew Rist  * software distributed under the License is distributed on an
15*ef39d40dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ef39d40dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*ef39d40dSAndrew Rist  * specific language governing permissions and limitations
18*ef39d40dSAndrew Rist  * under the License.
19*ef39d40dSAndrew Rist  *
20*ef39d40dSAndrew Rist  *************************************************************/
21*ef39d40dSAndrew Rist 
22*ef39d40dSAndrew Rist 
23cdf0e10cSrcweir package ifc.text;
24cdf0e10cSrcweir 
25cdf0e10cSrcweir import lib.MultiMethodTest;
26cdf0e10cSrcweir 
27cdf0e10cSrcweir import com.sun.star.text.XText;
28cdf0e10cSrcweir import com.sun.star.text.XTextRange;
29cdf0e10cSrcweir 
30cdf0e10cSrcweir 
31cdf0e10cSrcweir /**
32cdf0e10cSrcweir * Testing <code>com.sun.star.text.XTextRange</code>
33cdf0e10cSrcweir * interface methods :
34cdf0e10cSrcweir * <ul>
35cdf0e10cSrcweir *  <li><code> getText()</code></li>
36cdf0e10cSrcweir *  <li><code> getStart()</code></li>
37cdf0e10cSrcweir *  <li><code> getEnd()</code></li>
38cdf0e10cSrcweir *  <li><code> getString()</code></li>
39cdf0e10cSrcweir *  <li><code> setString()</code></li>
40cdf0e10cSrcweir * </ul> <p>
41cdf0e10cSrcweir * First the content is set to 'Middle' string value, then
42cdf0e10cSrcweir * start range is retrieved and its content is set to 'Start'
43cdf0e10cSrcweir * and end range is set to 'End'. Finally the whole TextRange
44cdf0e10cSrcweir * is checked and it must be 'StartMiddleEnd'. <p>
45cdf0e10cSrcweir * Test is <b> NOT </b> multithread compilant. <p>
46cdf0e10cSrcweir * @see com.sun.star.text.XTextRange
47cdf0e10cSrcweir */
48cdf0e10cSrcweir public class _XTextRange extends MultiMethodTest {
49cdf0e10cSrcweir 
50cdf0e10cSrcweir     public XTextRange oObj = null;            // oObj is filled by setField()
51cdf0e10cSrcweir                                             // in MultiMethodTest
52cdf0e10cSrcweir     XTextRange oStartRange = null;          // startrange of textrang
53cdf0e10cSrcweir     XTextRange oEndRange = null;            // endrange of textrang
54cdf0e10cSrcweir     String startStr = null;                 // string in startrange
55cdf0e10cSrcweir     String endStr = null;                   // string in endrange
56cdf0e10cSrcweir 
57cdf0e10cSrcweir     /**
58cdf0e10cSrcweir     * Retrieves the start range and sets its context to
59cdf0e10cSrcweir     * 'Start' string. <p>
60cdf0e10cSrcweir     * Has <b>OK</b> status if the whole range string starts
61cdf0e10cSrcweir     * with 'Start' substring. <p>
62cdf0e10cSrcweir     * The following method tests are to be completed successfully before :
63cdf0e10cSrcweir     * <ul>
64cdf0e10cSrcweir     *  <li> <code> setString </code>  </li>
65cdf0e10cSrcweir     * </ul>
66cdf0e10cSrcweir     */
_getStart()67cdf0e10cSrcweir     public void _getStart() {
68cdf0e10cSrcweir 
69cdf0e10cSrcweir         XText the_text = (XText) tEnv.getObjRelation("XTEXT");
70cdf0e10cSrcweir 
71cdf0e10cSrcweir         if (the_text != null) {
72cdf0e10cSrcweir             the_text.setString("");
73cdf0e10cSrcweir         }
74cdf0e10cSrcweir 
75cdf0e10cSrcweir         String exp="";
76cdf0e10cSrcweir 
77cdf0e10cSrcweir         oObj.setString("MiddleEnd");
78cdf0e10cSrcweir 
79cdf0e10cSrcweir         oStartRange = oObj.getStart();
80cdf0e10cSrcweir         oStartRange.setString("Start");
81cdf0e10cSrcweir 
82cdf0e10cSrcweir         if (the_text !=null)  {
83cdf0e10cSrcweir             exp = the_text.getString();
84cdf0e10cSrcweir         } else exp = oObj.getText().getString();
85cdf0e10cSrcweir 
86cdf0e10cSrcweir         log.println("Start: "+exp);
87cdf0e10cSrcweir 
88cdf0e10cSrcweir         tRes.tested( "getStart()", oStartRange != null &&
89cdf0e10cSrcweir             exp.startsWith("Start"));
90cdf0e10cSrcweir 
91cdf0e10cSrcweir 
92cdf0e10cSrcweir         oStartRange.setString("");
93cdf0e10cSrcweir 
94cdf0e10cSrcweir     }
95cdf0e10cSrcweir 
96cdf0e10cSrcweir     /**
97cdf0e10cSrcweir     * Retrieves the end range and sets its context to
98cdf0e10cSrcweir     * 'End' string. <p>
99cdf0e10cSrcweir     * Has <b>OK</b> status if the whole range string ends
100cdf0e10cSrcweir     * with 'End' substring. <p>
101cdf0e10cSrcweir     * The following method tests are to be completed successfully before :
102cdf0e10cSrcweir     * <ul>
103cdf0e10cSrcweir     *  <li> <code> setString </code>  </li>
104cdf0e10cSrcweir     * </ul>
105cdf0e10cSrcweir     */
_getEnd()106cdf0e10cSrcweir     public void _getEnd() {
107cdf0e10cSrcweir         XText the_text = (XText) tEnv.getObjRelation("XTEXT");
108cdf0e10cSrcweir 
109cdf0e10cSrcweir         if (the_text != null) {
110cdf0e10cSrcweir             the_text.setString("");
111cdf0e10cSrcweir         }
112cdf0e10cSrcweir 
113cdf0e10cSrcweir         String exp="";
114cdf0e10cSrcweir         oObj.setString("StartMiddle");
115cdf0e10cSrcweir 
116cdf0e10cSrcweir         oEndRange = oObj.getEnd();
117cdf0e10cSrcweir         oEndRange.setString("End");
118cdf0e10cSrcweir 
119cdf0e10cSrcweir         if (the_text !=null)  {
120cdf0e10cSrcweir             exp = the_text.getString();
121cdf0e10cSrcweir         } else exp = oObj.getText().getString();
122cdf0e10cSrcweir 
123cdf0e10cSrcweir         log.println("End: "+exp);
124cdf0e10cSrcweir 
125cdf0e10cSrcweir         tRes.tested( "getEnd()", oEndRange != null &&
126cdf0e10cSrcweir             exp.endsWith("End"));
127cdf0e10cSrcweir 
128cdf0e10cSrcweir         oEndRange.setString("");
129cdf0e10cSrcweir     }
130cdf0e10cSrcweir 
131cdf0e10cSrcweir     /**
132cdf0e10cSrcweir     * Gets the text of the range and retrieves its String content. <p>
133cdf0e10cSrcweir     * Has <b>OK</b> status if the string returned equals to
134cdf0e10cSrcweir     * 'StartMiddleEnd' value. <p>
135cdf0e10cSrcweir     * The following method tests are to be completed successfully before :
136cdf0e10cSrcweir     * <ul>
137cdf0e10cSrcweir     *  <li> <code> setString </code> to get finally the string expected.</li>
138cdf0e10cSrcweir     *  <li> <code> getStart </code> to get finally the string expected.</li>
139cdf0e10cSrcweir     *  <li> <code> getEnd </code> to get finally the string expected.</li>
140cdf0e10cSrcweir     * </ul>
141cdf0e10cSrcweir     */
_getText()142cdf0e10cSrcweir     public void _getText() {
143cdf0e10cSrcweir         requiredMethod("setString()");
144cdf0e10cSrcweir         requiredMethod("getStart()");
145cdf0e10cSrcweir         requiredMethod("getEnd()");
146cdf0e10cSrcweir 
147cdf0e10cSrcweir         XText txt = oObj.getText() ;
148cdf0e10cSrcweir 
149cdf0e10cSrcweir         tRes.tested( "getText()", txt != null &&
150cdf0e10cSrcweir             txt.getString().equals("StartMiddle"));
151cdf0e10cSrcweir     }
152cdf0e10cSrcweir 
153cdf0e10cSrcweir     /**
154cdf0e10cSrcweir     * Gets the String of the range. <p>
155cdf0e10cSrcweir     * Has <b>OK</b> status if the string returned equals to
156cdf0e10cSrcweir     * 'StartMiddleEnd' value. <p>
157cdf0e10cSrcweir     */
_getString()158cdf0e10cSrcweir     public void _getString() {
159cdf0e10cSrcweir 
160cdf0e10cSrcweir         oObj.setString("StartMiddleEnd");
161cdf0e10cSrcweir         String gStr = oObj.getString() ;
162cdf0e10cSrcweir 
163cdf0e10cSrcweir         tRes.tested( "getString()", gStr != null &&
164cdf0e10cSrcweir             gStr.equals("StartMiddleEnd"));
165cdf0e10cSrcweir 
166cdf0e10cSrcweir     }
167cdf0e10cSrcweir 
168cdf0e10cSrcweir     /**
169cdf0e10cSrcweir     * Sets the string content of the range to 'Middle' value. <p>
170cdf0e10cSrcweir     * Has <b>OK</b> status if <code>getString</code> method returns
171cdf0e10cSrcweir     * 'Middle' value.
172cdf0e10cSrcweir     */
_setString()173cdf0e10cSrcweir     public void _setString() {
174cdf0e10cSrcweir         oObj.setString("Middle") ;
175cdf0e10cSrcweir 
176cdf0e10cSrcweir         tRes.tested("setString()", "Middle".equals(oObj.getString())) ;
177cdf0e10cSrcweir     }
178cdf0e10cSrcweir }
179cdf0e10cSrcweir 
180cdf0e10cSrcweir 
181