1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
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.
14  *
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).
20  *
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.
25  *
26  ************************************************************************/
27 package ifc.text;
28 
29 import lib.MultiMethodTest;
30 
31 import com.sun.star.text.XText;
32 import com.sun.star.text.XTextRange;
33 
34 
35 /**
36 * Testing <code>com.sun.star.text.XTextRange</code>
37 * interface methods :
38 * <ul>
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>
44 * </ul> <p>
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
51 */
52 public class _XTextRange extends MultiMethodTest {
53 
54     public XTextRange oObj = null;            // oObj is filled by setField()
55                                             // in MultiMethodTest
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
60 
61     /**
62     * Retrieves the start range and sets its context to
63     * 'Start' string. <p>
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 :
67     * <ul>
68     *  <li> <code> setString </code>  </li>
69     * </ul>
70     */
71     public void _getStart() {
72 
73         XText the_text = (XText) tEnv.getObjRelation("XTEXT");
74 
75         if (the_text != null) {
76             the_text.setString("");
77         }
78 
79         String exp="";
80 
81         oObj.setString("MiddleEnd");
82 
83         oStartRange = oObj.getStart();
84         oStartRange.setString("Start");
85 
86         if (the_text !=null)  {
87             exp = the_text.getString();
88         } else exp = oObj.getText().getString();
89 
90         log.println("Start: "+exp);
91 
92         tRes.tested( "getStart()", oStartRange != null &&
93             exp.startsWith("Start"));
94 
95 
96         oStartRange.setString("");
97 
98     }
99 
100     /**
101     * Retrieves the end range and sets its context to
102     * 'End' string. <p>
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 :
106     * <ul>
107     *  <li> <code> setString </code>  </li>
108     * </ul>
109     */
110     public void _getEnd() {
111         XText the_text = (XText) tEnv.getObjRelation("XTEXT");
112 
113         if (the_text != null) {
114             the_text.setString("");
115         }
116 
117         String exp="";
118         oObj.setString("StartMiddle");
119 
120         oEndRange = oObj.getEnd();
121         oEndRange.setString("End");
122 
123         if (the_text !=null)  {
124             exp = the_text.getString();
125         } else exp = oObj.getText().getString();
126 
127         log.println("End: "+exp);
128 
129         tRes.tested( "getEnd()", oEndRange != null &&
130             exp.endsWith("End"));
131 
132         oEndRange.setString("");
133     }
134 
135     /**
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 :
140     * <ul>
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>
144     * </ul>
145     */
146     public void _getText() {
147         requiredMethod("setString()");
148         requiredMethod("getStart()");
149         requiredMethod("getEnd()");
150 
151         XText txt = oObj.getText() ;
152 
153         tRes.tested( "getText()", txt != null &&
154             txt.getString().equals("StartMiddle"));
155     }
156 
157     /**
158     * Gets the String of the range. <p>
159     * Has <b>OK</b> status if the string returned equals to
160     * 'StartMiddleEnd' value. <p>
161     */
162     public void _getString() {
163 
164         oObj.setString("StartMiddleEnd");
165         String gStr = oObj.getString() ;
166 
167         tRes.tested( "getString()", gStr != null &&
168             gStr.equals("StartMiddleEnd"));
169 
170     }
171 
172     /**
173     * Sets the string content of the range to 'Middle' value. <p>
174     * Has <b>OK</b> status if <code>getString</code> method returns
175     * 'Middle' value.
176     */
177     public void _setString() {
178         oObj.setString("Middle") ;
179 
180         tRes.tested("setString()", "Middle".equals(oObj.getString())) ;
181     }
182 }
183 
184 
185